License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* SPARC64 Huge TLB page support.
|
|
|
|
*
|
2006-03-20 09:17:17 +00:00
|
|
|
* Copyright (C) 2002, 2003, 2006 David S. Miller (davem@davemloft.net)
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mm.h>
|
2017-02-08 17:51:31 +00:00
|
|
|
#include <linux/sched/mm.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/hugetlb.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/sysctl.h>
|
|
|
|
|
|
|
|
#include <asm/mman.h>
|
|
|
|
#include <asm/pgalloc.h>
|
2016-07-29 07:54:21 +00:00
|
|
|
#include <asm/pgtable.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/tlb.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/mmu_context.h>
|
|
|
|
|
2006-03-20 09:17:17 +00:00
|
|
|
/* Slightly simplified from the non-hugepage variant because by
|
|
|
|
* definition we don't have to worry about any page coloring stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
|
|
|
|
unsigned long addr,
|
|
|
|
unsigned long len,
|
|
|
|
unsigned long pgoff,
|
|
|
|
unsigned long flags)
|
|
|
|
{
|
2017-02-02 00:16:36 +00:00
|
|
|
struct hstate *h = hstate_file(filp);
|
2006-03-20 09:17:17 +00:00
|
|
|
unsigned long task_size = TASK_SIZE;
|
2012-12-12 00:02:25 +00:00
|
|
|
struct vm_unmapped_area_info info;
|
2006-03-20 09:17:17 +00:00
|
|
|
|
|
|
|
if (test_thread_flag(TIF_32BIT))
|
|
|
|
task_size = STACK_TOP32;
|
|
|
|
|
2012-12-12 00:02:25 +00:00
|
|
|
info.flags = 0;
|
|
|
|
info.length = len;
|
|
|
|
info.low_limit = TASK_UNMAPPED_BASE;
|
|
|
|
info.high_limit = min(task_size, VA_EXCLUDE_START);
|
2017-02-02 00:16:36 +00:00
|
|
|
info.align_mask = PAGE_MASK & ~huge_page_mask(h);
|
2012-12-12 00:02:25 +00:00
|
|
|
info.align_offset = 0;
|
|
|
|
addr = vm_unmapped_area(&info);
|
|
|
|
|
|
|
|
if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
|
|
|
|
VM_BUG_ON(addr != -ENOMEM);
|
|
|
|
info.low_limit = VA_EXCLUDE_END;
|
|
|
|
info.high_limit = task_size;
|
|
|
|
addr = vm_unmapped_area(&info);
|
2006-03-20 09:17:17 +00:00
|
|
|
}
|
|
|
|
|
2012-12-12 00:02:25 +00:00
|
|
|
return addr;
|
2006-03-20 09:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
|
|
|
|
const unsigned long len,
|
|
|
|
const unsigned long pgoff,
|
|
|
|
const unsigned long flags)
|
|
|
|
{
|
2017-02-02 00:16:36 +00:00
|
|
|
struct hstate *h = hstate_file(filp);
|
2006-03-20 09:17:17 +00:00
|
|
|
struct mm_struct *mm = current->mm;
|
|
|
|
unsigned long addr = addr0;
|
2012-12-12 00:02:25 +00:00
|
|
|
struct vm_unmapped_area_info info;
|
2006-03-20 09:17:17 +00:00
|
|
|
|
|
|
|
/* This should only ever run for 32-bit processes. */
|
|
|
|
BUG_ON(!test_thread_flag(TIF_32BIT));
|
|
|
|
|
2012-12-12 00:02:25 +00:00
|
|
|
info.flags = VM_UNMAPPED_AREA_TOPDOWN;
|
|
|
|
info.length = len;
|
|
|
|
info.low_limit = PAGE_SIZE;
|
|
|
|
info.high_limit = mm->mmap_base;
|
2017-02-02 00:16:36 +00:00
|
|
|
info.align_mask = PAGE_MASK & ~huge_page_mask(h);
|
2012-12-12 00:02:25 +00:00
|
|
|
info.align_offset = 0;
|
|
|
|
addr = vm_unmapped_area(&info);
|
2006-03-20 09:17:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A failed mmap() very likely causes application failure,
|
|
|
|
* so fall back to the bottom-up function here. This scenario
|
|
|
|
* can happen with large stack limits and large mmap()
|
|
|
|
* allocations.
|
|
|
|
*/
|
2012-12-12 00:02:25 +00:00
|
|
|
if (addr & ~PAGE_MASK) {
|
|
|
|
VM_BUG_ON(addr != -ENOMEM);
|
|
|
|
info.flags = 0;
|
|
|
|
info.low_limit = TASK_UNMAPPED_BASE;
|
|
|
|
info.high_limit = STACK_TOP32;
|
|
|
|
addr = vm_unmapped_area(&info);
|
|
|
|
}
|
2006-03-20 09:17:17 +00:00
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long
|
|
|
|
hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
|
|
|
|
unsigned long len, unsigned long pgoff, unsigned long flags)
|
|
|
|
{
|
2017-02-02 00:16:36 +00:00
|
|
|
struct hstate *h = hstate_file(file);
|
2006-03-20 09:17:17 +00:00
|
|
|
struct mm_struct *mm = current->mm;
|
|
|
|
struct vm_area_struct *vma;
|
|
|
|
unsigned long task_size = TASK_SIZE;
|
|
|
|
|
|
|
|
if (test_thread_flag(TIF_32BIT))
|
|
|
|
task_size = STACK_TOP32;
|
|
|
|
|
2017-02-02 00:16:36 +00:00
|
|
|
if (len & ~huge_page_mask(h))
|
2006-03-20 09:17:17 +00:00
|
|
|
return -EINVAL;
|
|
|
|
if (len > task_size)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2007-05-06 21:50:10 +00:00
|
|
|
if (flags & MAP_FIXED) {
|
2008-07-24 04:27:41 +00:00
|
|
|
if (prepare_hugepage_range(file, addr, len))
|
2007-05-06 21:50:10 +00:00
|
|
|
return -EINVAL;
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2006-03-20 09:17:17 +00:00
|
|
|
if (addr) {
|
2017-02-02 00:16:36 +00:00
|
|
|
addr = ALIGN(addr, huge_page_size(h));
|
2006-03-20 09:17:17 +00:00
|
|
|
vma = find_vma(mm, addr);
|
|
|
|
if (task_size - len >= addr &&
|
mm: larger stack guard gap, between vmas
Stack guard page is a useful feature to reduce a risk of stack smashing
into a different mapping. We have been using a single page gap which
is sufficient to prevent having stack adjacent to a different mapping.
But this seems to be insufficient in the light of the stack usage in
userspace. E.g. glibc uses as large as 64kB alloca() in many commonly
used functions. Others use constructs liks gid_t buffer[NGROUPS_MAX]
which is 256kB or stack strings with MAX_ARG_STRLEN.
This will become especially dangerous for suid binaries and the default
no limit for the stack size limit because those applications can be
tricked to consume a large portion of the stack and a single glibc call
could jump over the guard page. These attacks are not theoretical,
unfortunatelly.
Make those attacks less probable by increasing the stack guard gap
to 1MB (on systems with 4k pages; but make it depend on the page size
because systems with larger base pages might cap stack allocations in
the PAGE_SIZE units) which should cover larger alloca() and VLA stack
allocations. It is obviously not a full fix because the problem is
somehow inherent, but it should reduce attack space a lot.
One could argue that the gap size should be configurable from userspace,
but that can be done later when somebody finds that the new 1MB is wrong
for some special case applications. For now, add a kernel command line
option (stack_guard_gap) to specify the stack gap size (in page units).
Implementation wise, first delete all the old code for stack guard page:
because although we could get away with accounting one extra page in a
stack vma, accounting a larger gap can break userspace - case in point,
a program run with "ulimit -S -v 20000" failed when the 1MB gap was
counted for RLIMIT_AS; similar problems could come with RLIMIT_MLOCK
and strict non-overcommit mode.
Instead of keeping gap inside the stack vma, maintain the stack guard
gap as a gap between vmas: using vm_start_gap() in place of vm_start
(or vm_end_gap() in place of vm_end if VM_GROWSUP) in just those few
places which need to respect the gap - mainly arch_get_unmapped_area(),
and and the vma tree's subtree_gap support for that.
Original-patch-by: Oleg Nesterov <oleg@redhat.com>
Original-patch-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Tested-by: Helge Deller <deller@gmx.de> # parisc
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-19 11:03:24 +00:00
|
|
|
(!vma || addr + len <= vm_start_gap(vma)))
|
2006-03-20 09:17:17 +00:00
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
if (mm->get_unmapped_area == arch_get_unmapped_area)
|
|
|
|
return hugetlb_get_unmapped_area_bottomup(file, addr, len,
|
|
|
|
pgoff, flags);
|
|
|
|
else
|
|
|
|
return hugetlb_get_unmapped_area_topdown(file, addr, len,
|
|
|
|
pgoff, flags);
|
|
|
|
}
|
|
|
|
|
2017-02-02 00:16:36 +00:00
|
|
|
static pte_t sun4u_hugepage_shift_to_tte(pte_t entry, unsigned int shift)
|
|
|
|
{
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pte_t sun4v_hugepage_shift_to_tte(pte_t entry, unsigned int shift)
|
|
|
|
{
|
|
|
|
unsigned long hugepage_size = _PAGE_SZ4MB_4V;
|
|
|
|
|
|
|
|
pte_val(entry) = pte_val(entry) & ~_PAGE_SZALL_4V;
|
|
|
|
|
|
|
|
switch (shift) {
|
2017-08-11 23:46:50 +00:00
|
|
|
case HPAGE_16GB_SHIFT:
|
|
|
|
hugepage_size = _PAGE_SZ16GB_4V;
|
|
|
|
pte_val(entry) |= _PAGE_PUD_HUGE;
|
|
|
|
break;
|
2017-03-09 22:22:23 +00:00
|
|
|
case HPAGE_2GB_SHIFT:
|
|
|
|
hugepage_size = _PAGE_SZ2GB_4V;
|
|
|
|
pte_val(entry) |= _PAGE_PMD_HUGE;
|
|
|
|
break;
|
2017-02-02 00:16:36 +00:00
|
|
|
case HPAGE_256MB_SHIFT:
|
|
|
|
hugepage_size = _PAGE_SZ256MB_4V;
|
|
|
|
pte_val(entry) |= _PAGE_PMD_HUGE;
|
|
|
|
break;
|
|
|
|
case HPAGE_SHIFT:
|
|
|
|
pte_val(entry) |= _PAGE_PMD_HUGE;
|
|
|
|
break;
|
2017-02-06 20:33:26 +00:00
|
|
|
case HPAGE_64K_SHIFT:
|
|
|
|
hugepage_size = _PAGE_SZ64K_4V;
|
|
|
|
break;
|
2017-02-02 00:16:36 +00:00
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "unsupported hugepage shift=%u\n", shift);
|
|
|
|
}
|
|
|
|
|
|
|
|
pte_val(entry) = pte_val(entry) | hugepage_size;
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pte_t hugepage_shift_to_tte(pte_t entry, unsigned int shift)
|
|
|
|
{
|
|
|
|
if (tlb_type == hypervisor)
|
|
|
|
return sun4v_hugepage_shift_to_tte(entry, shift);
|
|
|
|
else
|
|
|
|
return sun4u_hugepage_shift_to_tte(entry, shift);
|
|
|
|
}
|
|
|
|
|
|
|
|
pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,
|
|
|
|
struct page *page, int writeable)
|
|
|
|
{
|
|
|
|
unsigned int shift = huge_page_shift(hstate_vma(vma));
|
|
|
|
|
|
|
|
return hugepage_shift_to_tte(entry, shift);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int sun4v_huge_tte_to_shift(pte_t entry)
|
|
|
|
{
|
|
|
|
unsigned long tte_szbits = pte_val(entry) & _PAGE_SZALL_4V;
|
|
|
|
unsigned int shift;
|
|
|
|
|
|
|
|
switch (tte_szbits) {
|
2017-08-11 23:46:50 +00:00
|
|
|
case _PAGE_SZ16GB_4V:
|
|
|
|
shift = HPAGE_16GB_SHIFT;
|
|
|
|
break;
|
2017-03-09 22:22:23 +00:00
|
|
|
case _PAGE_SZ2GB_4V:
|
|
|
|
shift = HPAGE_2GB_SHIFT;
|
|
|
|
break;
|
2017-02-02 00:16:36 +00:00
|
|
|
case _PAGE_SZ256MB_4V:
|
|
|
|
shift = HPAGE_256MB_SHIFT;
|
|
|
|
break;
|
|
|
|
case _PAGE_SZ4MB_4V:
|
|
|
|
shift = REAL_HPAGE_SHIFT;
|
|
|
|
break;
|
2017-02-06 20:33:26 +00:00
|
|
|
case _PAGE_SZ64K_4V:
|
|
|
|
shift = HPAGE_64K_SHIFT;
|
|
|
|
break;
|
2017-02-02 00:16:36 +00:00
|
|
|
default:
|
|
|
|
shift = PAGE_SHIFT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int sun4u_huge_tte_to_shift(pte_t entry)
|
|
|
|
{
|
|
|
|
unsigned long tte_szbits = pte_val(entry) & _PAGE_SZALL_4U;
|
|
|
|
unsigned int shift;
|
|
|
|
|
|
|
|
switch (tte_szbits) {
|
|
|
|
case _PAGE_SZ256MB_4U:
|
|
|
|
shift = HPAGE_256MB_SHIFT;
|
|
|
|
break;
|
|
|
|
case _PAGE_SZ4MB_4U:
|
|
|
|
shift = REAL_HPAGE_SHIFT;
|
|
|
|
break;
|
2017-02-06 20:33:26 +00:00
|
|
|
case _PAGE_SZ64K_4U:
|
|
|
|
shift = HPAGE_64K_SHIFT;
|
|
|
|
break;
|
2017-02-02 00:16:36 +00:00
|
|
|
default:
|
|
|
|
shift = PAGE_SHIFT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int huge_tte_to_shift(pte_t entry)
|
|
|
|
{
|
|
|
|
unsigned long shift;
|
|
|
|
|
|
|
|
if (tlb_type == hypervisor)
|
|
|
|
shift = sun4v_huge_tte_to_shift(entry);
|
|
|
|
else
|
|
|
|
shift = sun4u_huge_tte_to_shift(entry);
|
|
|
|
|
|
|
|
if (shift == PAGE_SHIFT)
|
|
|
|
WARN_ONCE(1, "tto_to_shift: invalid hugepage tte=0x%lx\n",
|
|
|
|
pte_val(entry));
|
|
|
|
|
|
|
|
return shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long huge_tte_to_size(pte_t pte)
|
|
|
|
{
|
|
|
|
unsigned long size = 1UL << huge_tte_to_shift(pte);
|
|
|
|
|
|
|
|
if (size == REAL_HPAGE_SIZE)
|
|
|
|
size = HPAGE_SIZE;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2008-07-24 04:27:41 +00:00
|
|
|
pte_t *huge_pte_alloc(struct mm_struct *mm,
|
|
|
|
unsigned long addr, unsigned long sz)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
pgd_t *pgd;
|
|
|
|
pud_t *pud;
|
2017-02-06 20:33:26 +00:00
|
|
|
pmd_t *pmd;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
pgd = pgd_offset(mm, addr);
|
2006-03-22 08:49:59 +00:00
|
|
|
pud = pud_alloc(mm, pgd, addr);
|
2017-08-11 23:46:50 +00:00
|
|
|
if (!pud)
|
|
|
|
return NULL;
|
|
|
|
if (sz >= PUD_SIZE)
|
2017-08-11 23:46:51 +00:00
|
|
|
return (pte_t *)pud;
|
|
|
|
pmd = pmd_alloc(mm, pud, addr);
|
|
|
|
if (!pmd)
|
|
|
|
return NULL;
|
|
|
|
if (sz >= PMD_SIZE)
|
|
|
|
return (pte_t *)pmd;
|
|
|
|
return pte_alloc_map(mm, pmd, addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 22:39:42 +00:00
|
|
|
pte_t *huge_pte_offset(struct mm_struct *mm,
|
|
|
|
unsigned long addr, unsigned long sz)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
pgd_t *pgd;
|
|
|
|
pud_t *pud;
|
2017-02-06 20:33:26 +00:00
|
|
|
pmd_t *pmd;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
pgd = pgd_offset(mm, addr);
|
2017-08-11 23:46:51 +00:00
|
|
|
if (pgd_none(*pgd))
|
|
|
|
return NULL;
|
|
|
|
pud = pud_offset(pgd, addr);
|
|
|
|
if (pud_none(*pud))
|
|
|
|
return NULL;
|
|
|
|
if (is_hugetlb_pud(*pud))
|
|
|
|
return (pte_t *)pud;
|
|
|
|
pmd = pmd_offset(pud, addr);
|
|
|
|
if (pmd_none(*pmd))
|
|
|
|
return NULL;
|
|
|
|
if (is_hugetlb_pmd(*pmd))
|
|
|
|
return (pte_t *)pmd;
|
|
|
|
return pte_offset_map(pmd, addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-06-22 00:14:44 +00:00
|
|
|
void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
|
|
|
|
pte_t *ptep, pte_t entry)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2017-08-11 23:46:50 +00:00
|
|
|
unsigned int nptes, orig_shift, shift;
|
|
|
|
unsigned long i, size;
|
2016-07-29 07:54:21 +00:00
|
|
|
pte_t orig;
|
2005-06-22 00:14:44 +00:00
|
|
|
|
2017-02-02 00:16:36 +00:00
|
|
|
size = huge_tte_to_size(entry);
|
2017-08-11 23:46:50 +00:00
|
|
|
|
|
|
|
shift = PAGE_SHIFT;
|
|
|
|
if (size >= PUD_SIZE)
|
|
|
|
shift = PUD_SHIFT;
|
|
|
|
else if (size >= PMD_SIZE)
|
|
|
|
shift = PMD_SHIFT;
|
|
|
|
else
|
|
|
|
shift = PAGE_SHIFT;
|
|
|
|
|
2017-02-06 20:33:26 +00:00
|
|
|
nptes = size >> shift;
|
2017-02-02 00:16:36 +00:00
|
|
|
|
2006-03-22 08:49:59 +00:00
|
|
|
if (!pte_present(*ptep) && pte_present(entry))
|
2017-02-02 00:16:36 +00:00
|
|
|
mm->context.hugetlb_pte_count += nptes;
|
2006-03-22 08:49:59 +00:00
|
|
|
|
2017-02-02 00:16:36 +00:00
|
|
|
addr &= ~(size - 1);
|
2016-07-29 07:54:21 +00:00
|
|
|
orig = *ptep;
|
2017-02-24 11:03:16 +00:00
|
|
|
orig_shift = pte_none(orig) ? PAGE_SHIFT : huge_tte_to_shift(orig);
|
2016-03-30 18:17:13 +00:00
|
|
|
|
2017-02-02 00:16:36 +00:00
|
|
|
for (i = 0; i < nptes; i++)
|
2017-02-06 20:33:26 +00:00
|
|
|
ptep[i] = __pte(pte_val(entry) + (i << shift));
|
2017-02-02 00:16:36 +00:00
|
|
|
|
2017-02-06 20:33:26 +00:00
|
|
|
maybe_tlb_batch_add(mm, addr, ptep, orig, 0, orig_shift);
|
2017-02-02 00:16:36 +00:00
|
|
|
/* An HPAGE_SIZE'ed page is composed of two REAL_HPAGE_SIZE'ed pages */
|
|
|
|
if (size == HPAGE_SIZE)
|
|
|
|
maybe_tlb_batch_add(mm, addr + REAL_HPAGE_SIZE, ptep, orig, 0,
|
2017-02-06 20:33:26 +00:00
|
|
|
orig_shift);
|
2005-06-22 00:14:44 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-22 00:14:44 +00:00
|
|
|
pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
|
|
|
|
pte_t *ptep)
|
|
|
|
{
|
2017-08-11 23:46:50 +00:00
|
|
|
unsigned int i, nptes, orig_shift, shift;
|
2017-02-02 00:16:36 +00:00
|
|
|
unsigned long size;
|
2005-06-22 00:14:44 +00:00
|
|
|
pte_t entry;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-22 00:14:44 +00:00
|
|
|
entry = *ptep;
|
2017-02-02 00:16:36 +00:00
|
|
|
size = huge_tte_to_size(entry);
|
2017-08-11 23:46:50 +00:00
|
|
|
|
|
|
|
shift = PAGE_SHIFT;
|
|
|
|
if (size >= PUD_SIZE)
|
|
|
|
shift = PUD_SHIFT;
|
|
|
|
else if (size >= PMD_SIZE)
|
|
|
|
shift = PMD_SHIFT;
|
2017-02-06 20:33:26 +00:00
|
|
|
else
|
2017-08-11 23:46:50 +00:00
|
|
|
shift = PAGE_SHIFT;
|
2017-02-06 20:33:26 +00:00
|
|
|
|
2017-08-11 23:46:50 +00:00
|
|
|
nptes = size >> shift;
|
|
|
|
orig_shift = pte_none(entry) ? PAGE_SHIFT : huge_tte_to_shift(entry);
|
2017-02-02 00:16:36 +00:00
|
|
|
|
2006-03-22 08:49:59 +00:00
|
|
|
if (pte_present(entry))
|
2017-02-02 00:16:36 +00:00
|
|
|
mm->context.hugetlb_pte_count -= nptes;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-02-02 00:16:36 +00:00
|
|
|
addr &= ~(size - 1);
|
|
|
|
for (i = 0; i < nptes; i++)
|
|
|
|
ptep[i] = __pte(0UL);
|
2005-06-22 00:14:44 +00:00
|
|
|
|
2017-08-11 23:46:50 +00:00
|
|
|
maybe_tlb_batch_add(mm, addr, ptep, entry, 0, orig_shift);
|
2017-02-02 00:16:36 +00:00
|
|
|
/* An HPAGE_SIZE'ed page is composed of two REAL_HPAGE_SIZE'ed pages */
|
|
|
|
if (size == HPAGE_SIZE)
|
|
|
|
maybe_tlb_batch_add(mm, addr + REAL_HPAGE_SIZE, ptep, entry, 0,
|
2017-08-11 23:46:50 +00:00
|
|
|
orig_shift);
|
2016-03-30 18:17:13 +00:00
|
|
|
|
2005-06-22 00:14:44 +00:00
|
|
|
return entry;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int pmd_huge(pmd_t pmd)
|
|
|
|
{
|
2016-07-29 07:54:21 +00:00
|
|
|
return !pmd_none(pmd) &&
|
|
|
|
(pmd_val(pmd) & (_PAGE_VALID|_PAGE_PMD_HUGE)) != _PAGE_VALID;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-07-24 04:27:50 +00:00
|
|
|
int pud_huge(pud_t pud)
|
|
|
|
{
|
2017-08-11 23:46:50 +00:00
|
|
|
return !pud_none(pud) &&
|
|
|
|
(pud_val(pud) & (_PAGE_VALID|_PAGE_PUD_HUGE)) != _PAGE_VALID;
|
2008-07-24 04:27:50 +00:00
|
|
|
}
|
2016-07-29 07:54:21 +00:00
|
|
|
|
|
|
|
static void hugetlb_free_pte_range(struct mmu_gather *tlb, pmd_t *pmd,
|
|
|
|
unsigned long addr)
|
|
|
|
{
|
|
|
|
pgtable_t token = pmd_pgtable(*pmd);
|
|
|
|
|
|
|
|
pmd_clear(pmd);
|
|
|
|
pte_free_tlb(tlb, token, addr);
|
|
|
|
atomic_long_dec(&tlb->mm->nr_ptes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hugetlb_free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
|
|
|
|
unsigned long addr, unsigned long end,
|
|
|
|
unsigned long floor, unsigned long ceiling)
|
|
|
|
{
|
|
|
|
pmd_t *pmd;
|
|
|
|
unsigned long next;
|
|
|
|
unsigned long start;
|
|
|
|
|
|
|
|
start = addr;
|
|
|
|
pmd = pmd_offset(pud, addr);
|
|
|
|
do {
|
|
|
|
next = pmd_addr_end(addr, end);
|
|
|
|
if (pmd_none(*pmd))
|
|
|
|
continue;
|
|
|
|
if (is_hugetlb_pmd(*pmd))
|
|
|
|
pmd_clear(pmd);
|
|
|
|
else
|
|
|
|
hugetlb_free_pte_range(tlb, pmd, addr);
|
|
|
|
} while (pmd++, addr = next, addr != end);
|
|
|
|
|
|
|
|
start &= PUD_MASK;
|
|
|
|
if (start < floor)
|
|
|
|
return;
|
|
|
|
if (ceiling) {
|
|
|
|
ceiling &= PUD_MASK;
|
|
|
|
if (!ceiling)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (end - 1 > ceiling - 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pmd = pmd_offset(pud, start);
|
|
|
|
pud_clear(pud);
|
|
|
|
pmd_free_tlb(tlb, pmd, start);
|
|
|
|
mm_dec_nr_pmds(tlb->mm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hugetlb_free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
|
|
|
|
unsigned long addr, unsigned long end,
|
|
|
|
unsigned long floor, unsigned long ceiling)
|
|
|
|
{
|
|
|
|
pud_t *pud;
|
|
|
|
unsigned long next;
|
|
|
|
unsigned long start;
|
|
|
|
|
|
|
|
start = addr;
|
|
|
|
pud = pud_offset(pgd, addr);
|
|
|
|
do {
|
|
|
|
next = pud_addr_end(addr, end);
|
|
|
|
if (pud_none_or_clear_bad(pud))
|
|
|
|
continue;
|
2017-08-11 23:46:50 +00:00
|
|
|
if (is_hugetlb_pud(*pud))
|
|
|
|
pud_clear(pud);
|
|
|
|
else
|
|
|
|
hugetlb_free_pmd_range(tlb, pud, addr, next, floor,
|
|
|
|
ceiling);
|
2016-07-29 07:54:21 +00:00
|
|
|
} while (pud++, addr = next, addr != end);
|
|
|
|
|
|
|
|
start &= PGDIR_MASK;
|
|
|
|
if (start < floor)
|
|
|
|
return;
|
|
|
|
if (ceiling) {
|
|
|
|
ceiling &= PGDIR_MASK;
|
|
|
|
if (!ceiling)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (end - 1 > ceiling - 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pud = pud_offset(pgd, start);
|
|
|
|
pgd_clear(pgd);
|
|
|
|
pud_free_tlb(tlb, pud, start);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hugetlb_free_pgd_range(struct mmu_gather *tlb,
|
|
|
|
unsigned long addr, unsigned long end,
|
|
|
|
unsigned long floor, unsigned long ceiling)
|
|
|
|
{
|
|
|
|
pgd_t *pgd;
|
|
|
|
unsigned long next;
|
|
|
|
|
2017-04-17 22:46:41 +00:00
|
|
|
addr &= PMD_MASK;
|
|
|
|
if (addr < floor) {
|
|
|
|
addr += PMD_SIZE;
|
|
|
|
if (!addr)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ceiling) {
|
|
|
|
ceiling &= PMD_MASK;
|
|
|
|
if (!ceiling)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (end - 1 > ceiling - 1)
|
|
|
|
end -= PMD_SIZE;
|
|
|
|
if (addr > end - 1)
|
|
|
|
return;
|
|
|
|
|
2016-07-29 07:54:21 +00:00
|
|
|
pgd = pgd_offset(tlb->mm, addr);
|
|
|
|
do {
|
|
|
|
next = pgd_addr_end(addr, end);
|
|
|
|
if (pgd_none_or_clear_bad(pgd))
|
|
|
|
continue;
|
|
|
|
hugetlb_free_pud_range(tlb, pgd, addr, next, floor, ceiling);
|
|
|
|
} while (pgd++, addr = next, addr != end);
|
|
|
|
}
|