Skip to content

Commit 596cf45

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge updates from Andrew Morton: "Incoming: - a small number of updates to scripts/, ocfs2 and fs/buffer.c - most of MM I still have quite a lot of material (mostly not MM) staged after linux-next due to -next dependencies. I'll send those across next week as the preprequisites get merged up" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (135 commits) mm/page_io.c: annotate refault stalls from swap_readpage mm/Kconfig: fix trivial help text punctuation mm/Kconfig: fix indentation mm/memory_hotplug.c: remove __online_page_set_limits() mm: fix typos in comments when calling __SetPageUptodate() mm: fix struct member name in function comments mm/shmem.c: cast the type of unmap_start to u64 mm: shmem: use proper gfp flags for shmem_writepage() mm/shmem.c: make array 'values' static const, makes object smaller userfaultfd: require CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK fs/userfaultfd.c: wp: clear VM_UFFD_MISSING or VM_UFFD_WP during userfaultfd_register() userfaultfd: wrap the common dst_vma check into an inlined function userfaultfd: remove unnecessary WARN_ON() in __mcopy_atomic_hugetlb() userfaultfd: use vma_pagesize for all huge page size calculation mm/madvise.c: use PAGE_ALIGN[ED] for range checking mm/madvise.c: replace with page_size() in madvise_inject_error() mm/mmap.c: make vma_merge() comment more easy to understand mm/hwpoison-inject: use DEFINE_DEBUGFS_ATTRIBUTE to define debugfs fops autonuma: reduce cache footprint when scanning page tables autonuma: fix watermark checking in migrate_balanced_pgdat() ...
2 parents c3bfc5d + 9377906 commit 596cf45

95 files changed

Lines changed: 2661 additions & 1506 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/admin-guide/cgroup-v2.rst‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,12 @@ PAGE_SIZE multiple when read back.
12881288
inactive_anon, active_anon, inactive_file, active_file, unevictable
12891289
Amount of memory, swap-backed and filesystem-backed,
12901290
on the internal memory management lists used by the
1291-
page reclaim algorithm
1291+
page reclaim algorithm.
1292+
1293+
As these represent internal list state (eg. shmem pages are on anon
1294+
memory management lists), inactive_foo + active_foo may not be equal to
1295+
the value for the foo counter, since the foo counter is type-based, not
1296+
list-based.
12921297

12931298
slab_reclaimable
12941299
Part of "slab" that might be reclaimed, such as

‎Documentation/dev-tools/kasan.rst‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,66 @@ brk handler is used to print bug reports.
218218
A potential expansion of this mode is a hardware tag-based mode, which would
219219
use hardware memory tagging support instead of compiler instrumentation and
220220
manual shadow memory manipulation.
221+
222+
What memory accesses are sanitised by KASAN?
223+
--------------------------------------------
224+
225+
The kernel maps memory in a number of different parts of the address
226+
space. This poses something of a problem for KASAN, which requires
227+
that all addresses accessed by instrumented code have a valid shadow
228+
region.
229+
230+
The range of kernel virtual addresses is large: there is not enough
231+
real memory to support a real shadow region for every address that
232+
could be accessed by the kernel.
233+
234+
By default
235+
~~~~~~~~~~
236+
237+
By default, architectures only map real memory over the shadow region
238+
for the linear mapping (and potentially other small areas). For all
239+
other areas - such as vmalloc and vmemmap space - a single read-only
240+
page is mapped over the shadow area. This read-only shadow page
241+
declares all memory accesses as permitted.
242+
243+
This presents a problem for modules: they do not live in the linear
244+
mapping, but in a dedicated module space. By hooking in to the module
245+
allocator, KASAN can temporarily map real shadow memory to cover
246+
them. This allows detection of invalid accesses to module globals, for
247+
example.
248+
249+
This also creates an incompatibility with ``VMAP_STACK``: if the stack
250+
lives in vmalloc space, it will be shadowed by the read-only page, and
251+
the kernel will fault when trying to set up the shadow data for stack
252+
variables.
253+
254+
CONFIG_KASAN_VMALLOC
255+
~~~~~~~~~~~~~~~~~~~~
256+
257+
With ``CONFIG_KASAN_VMALLOC``, KASAN can cover vmalloc space at the
258+
cost of greater memory usage. Currently this is only supported on x86.
259+
260+
This works by hooking into vmalloc and vmap, and dynamically
261+
allocating real shadow memory to back the mappings.
262+
263+
Most mappings in vmalloc space are small, requiring less than a full
264+
page of shadow space. Allocating a full shadow page per mapping would
265+
therefore be wasteful. Furthermore, to ensure that different mappings
266+
use different shadow pages, mappings would have to be aligned to
267+
``KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE``.
268+
269+
Instead, we share backing space across multiple mappings. We allocate
270+
a backing page when a mapping in vmalloc space uses a particular page
271+
of the shadow region. This page can be shared by other vmalloc
272+
mappings later on.
273+
274+
We hook in to the vmap infrastructure to lazily clean up unused shadow
275+
memory.
276+
277+
To avoid the difficulties around swapping mappings around, we expect
278+
that the part of the shadow region that covers the vmalloc space will
279+
not be covered by the early shadow page, but will be left
280+
unmapped. This will require changes in arch-specific code.
281+
282+
This allows ``VMAP_STACK`` support on x86, and can simplify support of
283+
architectures that do not have a fixed module region.

‎arch/Kconfig‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,16 +836,17 @@ config HAVE_ARCH_VMAP_STACK
836836
config VMAP_STACK
837837
default y
838838
bool "Use a virtually-mapped stack"
839-
depends on HAVE_ARCH_VMAP_STACK && !KASAN
839+
depends on HAVE_ARCH_VMAP_STACK
840+
depends on !KASAN || KASAN_VMALLOC
840841
---help---
841842
Enable this if you want the use virtually-mapped kernel stacks
842843
with guard pages. This causes kernel stack overflows to be
843844
caught immediately rather than causing difficult-to-diagnose
844845
corruption.
845846

846-
This is presently incompatible with KASAN because KASAN expects
847-
the stack to map directly to the KASAN shadow map using a formula
848-
that is incorrect if the stack is in vmalloc space.
847+
To use this with KASAN, the architecture must support backing
848+
virtual mappings with real shadow memory, and KASAN_VMALLOC must
849+
be enabled.
849850

850851
config ARCH_OPTIONAL_KERNEL_RWX
851852
def_bool n

‎arch/arc/include/asm/pgtable.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#define _ASM_ARC_PGTABLE_H
3434

3535
#include <linux/bits.h>
36-
#define __ARCH_USE_5LEVEL_HACK
3736
#include <asm-generic/pgtable-nopmd.h>
3837
#include <asm/page.h>
3938
#include <asm/mmu.h> /* to propagate CONFIG_ARC_MMU_VER <n> */

‎arch/arc/mm/fault.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ noinline static int handle_kernel_vaddr_fault(unsigned long address)
3030
* with the 'reference' page table.
3131
*/
3232
pgd_t *pgd, *pgd_k;
33+
p4d_t *p4d, *p4d_k;
3334
pud_t *pud, *pud_k;
3435
pmd_t *pmd, *pmd_k;
3536

@@ -39,8 +40,13 @@ noinline static int handle_kernel_vaddr_fault(unsigned long address)
3940
if (!pgd_present(*pgd_k))
4041
goto bad_area;
4142

42-
pud = pud_offset(pgd, address);
43-
pud_k = pud_offset(pgd_k, address);
43+
p4d = p4d_offset(pgd, address);
44+
p4d_k = p4d_offset(pgd_k, address);
45+
if (!p4d_present(*p4d_k))
46+
goto bad_area;
47+
48+
pud = pud_offset(p4d, address);
49+
pud_k = pud_offset(p4d_k, address);
4450
if (!pud_present(*pud_k))
4551
goto bad_area;
4652

‎arch/arc/mm/highmem.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,14 @@ EXPORT_SYMBOL(__kunmap_atomic);
111111
static noinline pte_t * __init alloc_kmap_pgtable(unsigned long kvaddr)
112112
{
113113
pgd_t *pgd_k;
114+
p4d_t *p4d_k;
114115
pud_t *pud_k;
115116
pmd_t *pmd_k;
116117
pte_t *pte_k;
117118

118119
pgd_k = pgd_offset_k(kvaddr);
119-
pud_k = pud_offset(pgd_k, kvaddr);
120+
p4d_k = p4d_offset(pgd_k, kvaddr);
121+
pud_k = pud_offset(p4d_k, kvaddr);
120122
pmd_k = pmd_offset(pud_k, kvaddr);
121123

122124
pte_k = (pte_t *)memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);

‎arch/powerpc/include/asm/book3s/64/pgtable-4k.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ static inline int get_hugepd_cache_index(int index)
7070
/* should not reach */
7171
}
7272

73-
#else /* !CONFIG_HUGETLB_PAGE */
74-
static inline int pmd_huge(pmd_t pmd) { return 0; }
75-
static inline int pud_huge(pud_t pud) { return 0; }
7673
#endif /* CONFIG_HUGETLB_PAGE */
7774

7875
#endif /* __ASSEMBLY__ */

‎arch/powerpc/include/asm/book3s/64/pgtable-64k.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ static inline int get_hugepd_cache_index(int index)
5959
BUG();
6060
}
6161

62-
#else /* !CONFIG_HUGETLB_PAGE */
63-
static inline int pmd_huge(pmd_t pmd) { return 0; }
64-
static inline int pud_huge(pud_t pud) { return 0; }
6562
#endif /* CONFIG_HUGETLB_PAGE */
6663

6764
static inline int remap_4k_pfn(struct vm_area_struct *vma, unsigned long addr,

‎arch/powerpc/mm/book3s64/radix_pgtable.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/memblock.h>
1414
#include <linux/of_fdt.h>
1515
#include <linux/mm.h>
16+
#include <linux/hugetlb.h>
1617
#include <linux/string_helpers.h>
1718
#include <linux/stop_machine.h>
1819

‎arch/x86/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ config X86
134134
select HAVE_ARCH_JUMP_LABEL
135135
select HAVE_ARCH_JUMP_LABEL_RELATIVE
136136
select HAVE_ARCH_KASAN if X86_64
137+
select HAVE_ARCH_KASAN_VMALLOC if X86_64
137138
select HAVE_ARCH_KGDB
138139
select HAVE_ARCH_MMAP_RND_BITS if MMU
139140
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT

0 commit comments

Comments
 (0)