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 15:07:57 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* SPARC64 Huge TLB page support.
|
|
|
|
*
|
2006-03-20 01:17:17 -08:00
|
|
|
* Copyright (C) 2002, 2003, 2006 David S. Miller (davem@davemloft.net)
|
2005-04-16 15:20:36 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mm.h>
|
2017-02-08 18:51:31 +01:00
|
|
|
#include <linux/sched/mm.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/hugetlb.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/sysctl.h>
|
|
|
|
|
|
|
|
#include <asm/mman.h>
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/tlb.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/mmu_context.h>
|
|
|
|
|
2006-03-20 01:17:17 -08:00
|
|
|
|
2017-02-01 16:16:36 -08: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 16:46:50 -07:00
|
|
|
case HPAGE_16GB_SHIFT:
|
|
|
|
hugepage_size = _PAGE_SZ16GB_4V;
|
|
|
|
pte_val(entry) |= _PAGE_PUD_HUGE;
|
|
|
|
break;
|
2017-03-09 14:22:23 -08:00
|
|
|
case HPAGE_2GB_SHIFT:
|
|
|
|
hugepage_size = _PAGE_SZ2GB_4V;
|
|
|
|
pte_val(entry) |= _PAGE_PMD_HUGE;
|
|
|
|
break;
|
2017-02-01 16:16:36 -08: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 12:33:26 -08:00
|
|
|
case HPAGE_64K_SHIFT:
|
|
|
|
hugepage_size = _PAGE_SZ64K_4V;
|
|
|
|
break;
|
2017-02-01 16:16:36 -08: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);
|
|
|
|
}
|
|
|
|
|
mm/hugetlb: change parameters of arch_make_huge_pte()
Patch series "Subject: [PATCH v2 0/5] Implement huge VMAP and VMALLOC on powerpc 8xx", v2.
This series implements huge VMAP and VMALLOC on powerpc 8xx.
Powerpc 8xx has 4 page sizes:
- 4k
- 16k
- 512k
- 8M
At the time being, vmalloc and vmap only support huge pages which are
leaf at PMD level.
Here the PMD level is 4M, it doesn't correspond to any supported
page size.
For now, implement use of 16k and 512k pages which is done
at PTE level.
Support of 8M pages will be implemented later, it requires use of
hugepd tables.
To allow this, the architecture provides two functions:
- arch_vmap_pte_range_map_size() which tells vmap_pte_range() what
page size to use. A stub returning PAGE_SIZE is provided when the
architecture doesn't provide this function.
- arch_vmap_pte_supported_shift() which tells __vmalloc_node_range()
what page shift to use for a given area size. A stub returning
PAGE_SHIFT is provided when the architecture doesn't provide this
function.
This patch (of 5):
At the time being, arch_make_huge_pte() has the following prototype:
pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,
struct page *page, int writable);
vma is used to get the pages shift or size.
vma is also used on Sparc to get vm_flags.
page is not used.
writable is not used.
In order to use this function without a vma, replace vma by shift and
flags. Also remove the used parameters.
Link: https://lkml.kernel.org/r/cover.1620795204.git.christophe.leroy@csgroup.eu
Link: https://lkml.kernel.org/r/f4633ac6a7da2f22f31a04a89e0a7026bb78b15b.1620795204.git.christophe.leroy@csgroup.eu
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Acked-by: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Uladzislau Rezki <uladzislau.rezki@sony.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-06-30 18:48:00 -07:00
|
|
|
pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
|
2017-02-01 16:16:36 -08:00
|
|
|
{
|
2018-02-23 15:46:41 -07:00
|
|
|
pte_t pte;
|
2017-02-01 16:16:36 -08:00
|
|
|
|
2022-03-22 14:41:47 -07:00
|
|
|
entry = pte_mkhuge(entry);
|
2018-02-23 15:46:41 -07:00
|
|
|
pte = hugepage_shift_to_tte(entry, shift);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SPARC64
|
|
|
|
/* If this vma has ADI enabled on it, turn on TTE.mcd
|
|
|
|
*/
|
mm/hugetlb: change parameters of arch_make_huge_pte()
Patch series "Subject: [PATCH v2 0/5] Implement huge VMAP and VMALLOC on powerpc 8xx", v2.
This series implements huge VMAP and VMALLOC on powerpc 8xx.
Powerpc 8xx has 4 page sizes:
- 4k
- 16k
- 512k
- 8M
At the time being, vmalloc and vmap only support huge pages which are
leaf at PMD level.
Here the PMD level is 4M, it doesn't correspond to any supported
page size.
For now, implement use of 16k and 512k pages which is done
at PTE level.
Support of 8M pages will be implemented later, it requires use of
hugepd tables.
To allow this, the architecture provides two functions:
- arch_vmap_pte_range_map_size() which tells vmap_pte_range() what
page size to use. A stub returning PAGE_SIZE is provided when the
architecture doesn't provide this function.
- arch_vmap_pte_supported_shift() which tells __vmalloc_node_range()
what page shift to use for a given area size. A stub returning
PAGE_SHIFT is provided when the architecture doesn't provide this
function.
This patch (of 5):
At the time being, arch_make_huge_pte() has the following prototype:
pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,
struct page *page, int writable);
vma is used to get the pages shift or size.
vma is also used on Sparc to get vm_flags.
page is not used.
writable is not used.
In order to use this function without a vma, replace vma by shift and
flags. Also remove the used parameters.
Link: https://lkml.kernel.org/r/cover.1620795204.git.christophe.leroy@csgroup.eu
Link: https://lkml.kernel.org/r/f4633ac6a7da2f22f31a04a89e0a7026bb78b15b.1620795204.git.christophe.leroy@csgroup.eu
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Acked-by: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Uladzislau Rezki <uladzislau.rezki@sony.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-06-30 18:48:00 -07:00
|
|
|
if (flags & VM_SPARC_ADI)
|
2018-02-23 15:46:41 -07:00
|
|
|
return pte_mkmcd(pte);
|
|
|
|
else
|
|
|
|
return pte_mknotmcd(pte);
|
|
|
|
#else
|
|
|
|
return pte;
|
|
|
|
#endif
|
2017-02-01 16:16:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 16:46:50 -07:00
|
|
|
case _PAGE_SZ16GB_4V:
|
|
|
|
shift = HPAGE_16GB_SHIFT;
|
|
|
|
break;
|
2017-03-09 14:22:23 -08:00
|
|
|
case _PAGE_SZ2GB_4V:
|
|
|
|
shift = HPAGE_2GB_SHIFT;
|
|
|
|
break;
|
2017-02-01 16:16:36 -08:00
|
|
|
case _PAGE_SZ256MB_4V:
|
|
|
|
shift = HPAGE_256MB_SHIFT;
|
|
|
|
break;
|
|
|
|
case _PAGE_SZ4MB_4V:
|
|
|
|
shift = REAL_HPAGE_SHIFT;
|
|
|
|
break;
|
2017-02-06 12:33:26 -08:00
|
|
|
case _PAGE_SZ64K_4V:
|
|
|
|
shift = HPAGE_64K_SHIFT;
|
|
|
|
break;
|
2017-02-01 16:16:36 -08: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 12:33:26 -08:00
|
|
|
case _PAGE_SZ64K_4U:
|
|
|
|
shift = HPAGE_64K_SHIFT;
|
|
|
|
break;
|
2017-02-01 16:16:36 -08:00
|
|
|
default:
|
|
|
|
shift = PAGE_SHIFT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return shift;
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:46:23 +01:00
|
|
|
static unsigned long tte_to_shift(pte_t entry)
|
2017-02-01 16:16:36 -08:00
|
|
|
{
|
|
|
|
if (tlb_type == hypervisor)
|
2020-11-13 11:46:23 +01:00
|
|
|
return sun4v_huge_tte_to_shift(entry);
|
|
|
|
|
|
|
|
return sun4u_huge_tte_to_shift(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int huge_tte_to_shift(pte_t entry)
|
|
|
|
{
|
|
|
|
unsigned long shift = tte_to_shift(entry);
|
2017-02-01 16:16:36 -08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:46:23 +01:00
|
|
|
unsigned long pud_leaf_size(pud_t pud) { return 1UL << tte_to_shift(*(pte_t *)&pud); }
|
|
|
|
unsigned long pmd_leaf_size(pmd_t pmd) { return 1UL << tte_to_shift(*(pte_t *)&pmd); }
|
|
|
|
unsigned long pte_leaf_size(pte_t pte) { return 1UL << tte_to_shift(pte); }
|
|
|
|
|
2021-05-04 18:33:00 -07:00
|
|
|
pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
|
2008-07-23 21:27:41 -07:00
|
|
|
unsigned long addr, unsigned long sz)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
pgd_t *pgd;
|
2019-11-24 10:57:20 +02:00
|
|
|
p4d_t *p4d;
|
2005-04-16 15:20:36 -07:00
|
|
|
pud_t *pud;
|
2017-02-06 12:33:26 -08:00
|
|
|
pmd_t *pmd;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
pgd = pgd_offset(mm, addr);
|
2019-11-24 10:57:20 +02:00
|
|
|
p4d = p4d_offset(pgd, addr);
|
|
|
|
pud = pud_alloc(mm, p4d, addr);
|
2017-08-11 16:46:50 -07:00
|
|
|
if (!pud)
|
|
|
|
return NULL;
|
|
|
|
if (sz >= PUD_SIZE)
|
2017-08-11 16:46:51 -07:00
|
|
|
return (pte_t *)pud;
|
|
|
|
pmd = pmd_alloc(mm, pud, addr);
|
|
|
|
if (!pmd)
|
|
|
|
return NULL;
|
|
|
|
if (sz >= PMD_SIZE)
|
|
|
|
return (pte_t *)pmd;
|
2023-06-08 12:31:10 -07:00
|
|
|
return pte_alloc_huge(mm, pmd, addr);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2017-07-06 15:39:42 -07:00
|
|
|
pte_t *huge_pte_offset(struct mm_struct *mm,
|
|
|
|
unsigned long addr, unsigned long sz)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
pgd_t *pgd;
|
2019-11-24 10:57:20 +02:00
|
|
|
p4d_t *p4d;
|
2005-04-16 15:20:36 -07:00
|
|
|
pud_t *pud;
|
2017-02-06 12:33:26 -08:00
|
|
|
pmd_t *pmd;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
pgd = pgd_offset(mm, addr);
|
2017-08-11 16:46:51 -07:00
|
|
|
if (pgd_none(*pgd))
|
|
|
|
return NULL;
|
2019-11-24 10:57:20 +02:00
|
|
|
p4d = p4d_offset(pgd, addr);
|
|
|
|
if (p4d_none(*p4d))
|
|
|
|
return NULL;
|
|
|
|
pud = pud_offset(p4d, addr);
|
2017-08-11 16:46:51 -07:00
|
|
|
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;
|
2023-06-08 12:31:10 -07:00
|
|
|
return pte_offset_huge(pmd, addr);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
mm: hugetlb: add huge page size param to set_huge_pte_at()
Patch series "Fix set_huge_pte_at() panic on arm64", v2.
This series fixes a bug in arm64's implementation of set_huge_pte_at(),
which can result in an unprivileged user causing a kernel panic. The
problem was triggered when running the new uffd poison mm selftest for
HUGETLB memory. This test (and the uffd poison feature) was merged for
v6.5-rc7.
Ideally, I'd like to get this fix in for v6.6 and I've cc'ed stable
(correctly this time) to get it backported to v6.5, where the issue first
showed up.
Description of Bug
==================
arm64's huge pte implementation supports multiple huge page sizes, some of
which are implemented in the page table with multiple contiguous entries.
So set_huge_pte_at() needs to work out how big the logical pte is, so that
it can also work out how many physical ptes (or pmds) need to be written.
It previously did this by grabbing the folio out of the pte and querying
its size.
However, there are cases when the pte being set is actually a swap entry.
But this also used to work fine, because for huge ptes, we only ever saw
migration entries and hwpoison entries. And both of these types of swap
entries have a PFN embedded, so the code would grab that and everything
still worked out.
But over time, more calls to set_huge_pte_at() have been added that set
swap entry types that do not embed a PFN. And this causes the code to go
bang. The triggering case is for the uffd poison test, commit
99aa77215ad0 ("selftests/mm: add uffd unit test for UFFDIO_POISON"), which
causes a PTE_MARKER_POISONED swap entry to be set, coutesey of commit
8a13897fb0da ("mm: userfaultfd: support UFFDIO_POISON for hugetlbfs") -
added in v6.5-rc7. Although review shows that there are other call sites
that set PTE_MARKER_UFFD_WP (which also has no PFN), these don't trigger
on arm64 because arm64 doesn't support UFFD WP.
If CONFIG_DEBUG_VM is enabled, we do at least get a BUG(), but otherwise,
it will dereference a bad pointer in page_folio():
static inline struct folio *hugetlb_swap_entry_to_folio(swp_entry_t entry)
{
VM_BUG_ON(!is_migration_entry(entry) && !is_hwpoison_entry(entry));
return page_folio(pfn_to_page(swp_offset_pfn(entry)));
}
Fix
===
The simplest fix would have been to revert the dodgy cleanup commit
18f3962953e4 ("mm: hugetlb: kill set_huge_swap_pte_at()"), but since
things have moved on, this would have required an audit of all the new
set_huge_pte_at() call sites to see if they should be converted to
set_huge_swap_pte_at(). As per the original intent of the change, it
would also leave us open to future bugs when people invariably get it
wrong and call the wrong helper.
So instead, I've added a huge page size parameter to set_huge_pte_at().
This means that the arm64 code has the size in all cases. It's a bigger
change, due to needing to touch the arches that implement the function,
but it is entirely mechanical, so in my view, low risk.
I've compile-tested all touched arches; arm64, parisc, powerpc, riscv,
s390, sparc (and additionally x86_64). I've additionally booted and run
mm selftests against arm64, where I observe the uffd poison test is fixed,
and there are no other regressions.
This patch (of 2):
In order to fix a bug, arm64 needs to be told the size of the huge page
for which the pte is being set in set_huge_pte_at(). Provide for this by
adding an `unsigned long sz` parameter to the function. This follows the
same pattern as huge_pte_clear().
This commit makes the required interface modifications to the core mm as
well as all arches that implement this function (arm64, parisc, powerpc,
riscv, s390, sparc). The actual arm64 bug will be fixed in a separate
commit.
No behavioral changes intended.
Link: https://lkml.kernel.org/r/20230922115804.2043771-1-ryan.roberts@arm.com
Link: https://lkml.kernel.org/r/20230922115804.2043771-2-ryan.roberts@arm.com
Fixes: 8a13897fb0da ("mm: userfaultfd: support UFFDIO_POISON for hugetlbfs")
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> [powerpc 8xx]
Reviewed-by: Lorenzo Stoakes <lstoakes@gmail.com> [vmalloc change]
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Helge Deller <deller@gmx.de>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: SeongJae Park <sj@kernel.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Cc: <stable@vger.kernel.org> [6.5+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-09-22 12:58:03 +01:00
|
|
|
void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
|
2005-06-21 17:14:44 -07:00
|
|
|
pte_t *ptep, pte_t entry)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2017-08-11 16:46:50 -07:00
|
|
|
unsigned int nptes, orig_shift, shift;
|
|
|
|
unsigned long i, size;
|
2016-07-29 00:54:21 -07:00
|
|
|
pte_t orig;
|
2005-06-21 17:14:44 -07:00
|
|
|
|
2017-02-01 16:16:36 -08:00
|
|
|
size = huge_tte_to_size(entry);
|
2017-08-11 16:46:50 -07: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 12:33:26 -08:00
|
|
|
nptes = size >> shift;
|
2017-02-01 16:16:36 -08:00
|
|
|
|
2006-03-22 00:49:59 -08:00
|
|
|
if (!pte_present(*ptep) && pte_present(entry))
|
2017-02-01 16:16:36 -08:00
|
|
|
mm->context.hugetlb_pte_count += nptes;
|
2006-03-22 00:49:59 -08:00
|
|
|
|
2017-02-01 16:16:36 -08:00
|
|
|
addr &= ~(size - 1);
|
2016-07-29 00:54:21 -07:00
|
|
|
orig = *ptep;
|
2017-02-24 03:03:16 -08:00
|
|
|
orig_shift = pte_none(orig) ? PAGE_SHIFT : huge_tte_to_shift(orig);
|
2016-03-30 11:17:13 -07:00
|
|
|
|
2017-02-01 16:16:36 -08:00
|
|
|
for (i = 0; i < nptes; i++)
|
2017-02-06 12:33:26 -08:00
|
|
|
ptep[i] = __pte(pte_val(entry) + (i << shift));
|
2017-02-01 16:16:36 -08:00
|
|
|
|
2017-02-06 12:33:26 -08:00
|
|
|
maybe_tlb_batch_add(mm, addr, ptep, orig, 0, orig_shift);
|
2017-02-01 16:16:36 -08: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 12:33:26 -08:00
|
|
|
orig_shift);
|
2005-06-21 17:14:44 -07:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
mm: hugetlb: add huge page size param to set_huge_pte_at()
Patch series "Fix set_huge_pte_at() panic on arm64", v2.
This series fixes a bug in arm64's implementation of set_huge_pte_at(),
which can result in an unprivileged user causing a kernel panic. The
problem was triggered when running the new uffd poison mm selftest for
HUGETLB memory. This test (and the uffd poison feature) was merged for
v6.5-rc7.
Ideally, I'd like to get this fix in for v6.6 and I've cc'ed stable
(correctly this time) to get it backported to v6.5, where the issue first
showed up.
Description of Bug
==================
arm64's huge pte implementation supports multiple huge page sizes, some of
which are implemented in the page table with multiple contiguous entries.
So set_huge_pte_at() needs to work out how big the logical pte is, so that
it can also work out how many physical ptes (or pmds) need to be written.
It previously did this by grabbing the folio out of the pte and querying
its size.
However, there are cases when the pte being set is actually a swap entry.
But this also used to work fine, because for huge ptes, we only ever saw
migration entries and hwpoison entries. And both of these types of swap
entries have a PFN embedded, so the code would grab that and everything
still worked out.
But over time, more calls to set_huge_pte_at() have been added that set
swap entry types that do not embed a PFN. And this causes the code to go
bang. The triggering case is for the uffd poison test, commit
99aa77215ad0 ("selftests/mm: add uffd unit test for UFFDIO_POISON"), which
causes a PTE_MARKER_POISONED swap entry to be set, coutesey of commit
8a13897fb0da ("mm: userfaultfd: support UFFDIO_POISON for hugetlbfs") -
added in v6.5-rc7. Although review shows that there are other call sites
that set PTE_MARKER_UFFD_WP (which also has no PFN), these don't trigger
on arm64 because arm64 doesn't support UFFD WP.
If CONFIG_DEBUG_VM is enabled, we do at least get a BUG(), but otherwise,
it will dereference a bad pointer in page_folio():
static inline struct folio *hugetlb_swap_entry_to_folio(swp_entry_t entry)
{
VM_BUG_ON(!is_migration_entry(entry) && !is_hwpoison_entry(entry));
return page_folio(pfn_to_page(swp_offset_pfn(entry)));
}
Fix
===
The simplest fix would have been to revert the dodgy cleanup commit
18f3962953e4 ("mm: hugetlb: kill set_huge_swap_pte_at()"), but since
things have moved on, this would have required an audit of all the new
set_huge_pte_at() call sites to see if they should be converted to
set_huge_swap_pte_at(). As per the original intent of the change, it
would also leave us open to future bugs when people invariably get it
wrong and call the wrong helper.
So instead, I've added a huge page size parameter to set_huge_pte_at().
This means that the arm64 code has the size in all cases. It's a bigger
change, due to needing to touch the arches that implement the function,
but it is entirely mechanical, so in my view, low risk.
I've compile-tested all touched arches; arm64, parisc, powerpc, riscv,
s390, sparc (and additionally x86_64). I've additionally booted and run
mm selftests against arm64, where I observe the uffd poison test is fixed,
and there are no other regressions.
This patch (of 2):
In order to fix a bug, arm64 needs to be told the size of the huge page
for which the pte is being set in set_huge_pte_at(). Provide for this by
adding an `unsigned long sz` parameter to the function. This follows the
same pattern as huge_pte_clear().
This commit makes the required interface modifications to the core mm as
well as all arches that implement this function (arm64, parisc, powerpc,
riscv, s390, sparc). The actual arm64 bug will be fixed in a separate
commit.
No behavioral changes intended.
Link: https://lkml.kernel.org/r/20230922115804.2043771-1-ryan.roberts@arm.com
Link: https://lkml.kernel.org/r/20230922115804.2043771-2-ryan.roberts@arm.com
Fixes: 8a13897fb0da ("mm: userfaultfd: support UFFDIO_POISON for hugetlbfs")
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> [powerpc 8xx]
Reviewed-by: Lorenzo Stoakes <lstoakes@gmail.com> [vmalloc change]
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Helge Deller <deller@gmx.de>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: SeongJae Park <sj@kernel.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Cc: <stable@vger.kernel.org> [6.5+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-09-22 12:58:03 +01:00
|
|
|
void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
|
|
|
|
pte_t *ptep, pte_t entry, unsigned long sz)
|
|
|
|
{
|
|
|
|
__set_huge_pte_at(mm, addr, ptep, entry);
|
|
|
|
}
|
|
|
|
|
2005-06-21 17:14:44 -07:00
|
|
|
pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
|
2025-02-26 12:06:51 +00:00
|
|
|
pte_t *ptep, unsigned long sz)
|
2005-06-21 17:14:44 -07:00
|
|
|
{
|
2017-08-11 16:46:50 -07:00
|
|
|
unsigned int i, nptes, orig_shift, shift;
|
2017-02-01 16:16:36 -08:00
|
|
|
unsigned long size;
|
2005-06-21 17:14:44 -07:00
|
|
|
pte_t entry;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-06-21 17:14:44 -07:00
|
|
|
entry = *ptep;
|
2017-02-01 16:16:36 -08:00
|
|
|
size = huge_tte_to_size(entry);
|
2017-08-11 16:46:50 -07:00
|
|
|
|
|
|
|
shift = PAGE_SHIFT;
|
|
|
|
if (size >= PUD_SIZE)
|
|
|
|
shift = PUD_SHIFT;
|
|
|
|
else if (size >= PMD_SIZE)
|
|
|
|
shift = PMD_SHIFT;
|
2017-02-06 12:33:26 -08:00
|
|
|
else
|
2017-08-11 16:46:50 -07:00
|
|
|
shift = PAGE_SHIFT;
|
2017-02-06 12:33:26 -08:00
|
|
|
|
2017-08-11 16:46:50 -07:00
|
|
|
nptes = size >> shift;
|
|
|
|
orig_shift = pte_none(entry) ? PAGE_SHIFT : huge_tte_to_shift(entry);
|
2017-02-01 16:16:36 -08:00
|
|
|
|
2006-03-22 00:49:59 -08:00
|
|
|
if (pte_present(entry))
|
2017-02-01 16:16:36 -08:00
|
|
|
mm->context.hugetlb_pte_count -= nptes;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2017-02-01 16:16:36 -08:00
|
|
|
addr &= ~(size - 1);
|
|
|
|
for (i = 0; i < nptes; i++)
|
|
|
|
ptep[i] = __pte(0UL);
|
2005-06-21 17:14:44 -07:00
|
|
|
|
2017-08-11 16:46:50 -07:00
|
|
|
maybe_tlb_batch_add(mm, addr, ptep, entry, 0, orig_shift);
|
2017-02-01 16:16:36 -08: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 16:46:50 -07:00
|
|
|
orig_shift);
|
2016-03-30 11:17:13 -07:00
|
|
|
|
2005-06-21 17:14:44 -07:00
|
|
|
return entry;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2016-07-29 00:54:21 -07: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);
|
2017-11-15 17:35:37 -08:00
|
|
|
mm_dec_nr_ptes(tlb->mm);
|
2016-07-29 00:54:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-11-24 10:57:20 +02:00
|
|
|
static void hugetlb_free_pud_range(struct mmu_gather *tlb, p4d_t *p4d,
|
2016-07-29 00:54:21 -07:00
|
|
|
unsigned long addr, unsigned long end,
|
|
|
|
unsigned long floor, unsigned long ceiling)
|
|
|
|
{
|
|
|
|
pud_t *pud;
|
|
|
|
unsigned long next;
|
|
|
|
unsigned long start;
|
|
|
|
|
|
|
|
start = addr;
|
2019-11-24 10:57:20 +02:00
|
|
|
pud = pud_offset(p4d, addr);
|
2016-07-29 00:54:21 -07:00
|
|
|
do {
|
|
|
|
next = pud_addr_end(addr, end);
|
|
|
|
if (pud_none_or_clear_bad(pud))
|
|
|
|
continue;
|
2017-08-11 16:46:50 -07:00
|
|
|
if (is_hugetlb_pud(*pud))
|
|
|
|
pud_clear(pud);
|
|
|
|
else
|
|
|
|
hugetlb_free_pmd_range(tlb, pud, addr, next, floor,
|
|
|
|
ceiling);
|
2016-07-29 00:54:21 -07: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;
|
|
|
|
|
2019-11-24 10:57:20 +02:00
|
|
|
pud = pud_offset(p4d, start);
|
|
|
|
p4d_clear(p4d);
|
2016-07-29 00:54:21 -07:00
|
|
|
pud_free_tlb(tlb, pud, start);
|
2017-11-15 17:35:33 -08:00
|
|
|
mm_dec_nr_puds(tlb->mm);
|
2016-07-29 00:54:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void hugetlb_free_pgd_range(struct mmu_gather *tlb,
|
|
|
|
unsigned long addr, unsigned long end,
|
|
|
|
unsigned long floor, unsigned long ceiling)
|
|
|
|
{
|
|
|
|
pgd_t *pgd;
|
2019-11-24 10:57:20 +02:00
|
|
|
p4d_t *p4d;
|
2016-07-29 00:54:21 -07:00
|
|
|
unsigned long next;
|
|
|
|
|
2017-04-17 15:46:41 -07: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 00:54:21 -07:00
|
|
|
pgd = pgd_offset(tlb->mm, addr);
|
2019-11-24 10:57:20 +02:00
|
|
|
p4d = p4d_offset(pgd, addr);
|
2016-07-29 00:54:21 -07:00
|
|
|
do {
|
2019-11-24 10:57:20 +02:00
|
|
|
next = p4d_addr_end(addr, end);
|
|
|
|
if (p4d_none_or_clear_bad(p4d))
|
2016-07-29 00:54:21 -07:00
|
|
|
continue;
|
2019-11-24 10:57:20 +02:00
|
|
|
hugetlb_free_pud_range(tlb, p4d, addr, next, floor, ceiling);
|
|
|
|
} while (p4d++, addr = next, addr != end);
|
2016-07-29 00:54:21 -07:00
|
|
|
}
|