Skip to content

Commit 29c8c18

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge yet more updates from Andrew Morton: "This is the material which was staged after willystuff in linux-next. Subsystems affected by this patch series: mm (debug, selftests, pagecache, thp, rmap, migration, kasan, hugetlb, pagemap, madvise), and selftests" * emailed patches from Andrew Morton <[email protected]>: (113 commits) selftests: kselftest framework: provide "finished" helper mm: madvise: MADV_DONTNEED_LOCKED mm: fix race between MADV_FREE reclaim and blkdev direct IO read mm: generalize ARCH_HAS_FILTER_PGPROT mm: unmap_mapping_range_tree() with i_mmap_rwsem shared mm: warn on deleting redirtied only if accounted mm/huge_memory: remove stale locking logic from __split_huge_pmd() mm/huge_memory: remove stale page_trans_huge_mapcount() mm/swapfile: remove stale reuse_swap_page() mm/khugepaged: remove reuse_swap_page() usage mm/huge_memory: streamline COW logic in do_huge_pmd_wp_page() mm: streamline COW logic in do_swap_page() mm: slightly clarify KSM logic in do_swap_page() mm: optimize do_wp_page() for fresh pages in local LRU pagevecs mm: optimize do_wp_page() for exclusive pages in the swapcache mm/huge_memory: make is_transparent_hugepage() static userfaultfd/selftests: enable hugetlb remap and remove event testing selftests/vm: add hugetlb madvise MADV_DONTNEED MADV_REMOVE test mm: enable MADV_DONTNEED for hugetlb mappings kasan: disable LOCKDEP when printing reports ...
2 parents aa5b537 + 25fd2d4 commit 29c8c18

Some content is hidden

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

73 files changed

+2458
-956
lines changed

Documentation/dev-tools/kasan.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Software tag-based KASAN mode is only supported in Clang.
3030

3131
The hardware KASAN mode (#3) relies on hardware to perform the checks but
3232
still requires a compiler version that supports memory tagging instructions.
33-
This mode is supported in GCC 10+ and Clang 11+.
33+
This mode is supported in GCC 10+ and Clang 12+.
3434

3535
Both software KASAN modes work with SLUB and SLAB memory allocators,
3636
while the hardware tag-based KASAN currently only supports SLUB.
@@ -206,6 +206,9 @@ additional boot parameters that allow disabling KASAN or controlling features:
206206
Asymmetric mode: a bad access is detected synchronously on reads and
207207
asynchronously on writes.
208208

209+
- ``kasan.vmalloc=off`` or ``=on`` disables or enables tagging of vmalloc
210+
allocations (default: ``on``).
211+
209212
- ``kasan.stacktrace=off`` or ``=on`` disables or enables alloc and free stack
210213
traces collection (default: ``on``).
211214

@@ -279,8 +282,8 @@ Software tag-based KASAN uses 0xFF as a match-all pointer tag (accesses through
279282
pointers with the 0xFF pointer tag are not checked). The value 0xFE is currently
280283
reserved to tag freed memory regions.
281284

282-
Software tag-based KASAN currently only supports tagging of slab and page_alloc
283-
memory.
285+
Software tag-based KASAN currently only supports tagging of slab, page_alloc,
286+
and vmalloc memory.
284287

285288
Hardware tag-based KASAN
286289
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -303,8 +306,8 @@ Hardware tag-based KASAN uses 0xFF as a match-all pointer tag (accesses through
303306
pointers with the 0xFF pointer tag are not checked). The value 0xFE is currently
304307
reserved to tag freed memory regions.
305308

306-
Hardware tag-based KASAN currently only supports tagging of slab and page_alloc
307-
memory.
309+
Hardware tag-based KASAN currently only supports tagging of slab, page_alloc,
310+
and VM_ALLOC-based vmalloc memory.
308311

309312
If the hardware does not support MTE (pre ARMv8.5), hardware tag-based KASAN
310313
will not be enabled. In this case, all KASAN boot parameters are ignored.
@@ -319,6 +322,8 @@ checking gets disabled.
319322
Shadow memory
320323
-------------
321324

325+
The contents of this section are only applicable to software KASAN modes.
326+
322327
The kernel maps memory in several different parts of the address space.
323328
The range of kernel virtual addresses is large: there is not enough real
324329
memory to support a real shadow region for every address that could be
@@ -349,7 +354,7 @@ CONFIG_KASAN_VMALLOC
349354

350355
With ``CONFIG_KASAN_VMALLOC``, KASAN can cover vmalloc space at the
351356
cost of greater memory usage. Currently, this is supported on x86,
352-
riscv, s390, and powerpc.
357+
arm64, riscv, s390, and powerpc.
353358

354359
This works by hooking into vmalloc and vmap and dynamically
355360
allocating real shadow memory to back the mappings.

Documentation/vm/page_owner.rst

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Usage
7878

7979
2) Enable page owner: add "page_owner=on" to boot cmdline.
8080

81-
3) Do the job what you want to debug
81+
3) Do the job that you want to debug.
8282

8383
4) Analyze information from page owner::
8484

@@ -89,22 +89,75 @@ Usage
8989

9090
Page allocated via order XXX, ...
9191
PFN XXX ...
92-
// Detailed stack
92+
// Detailed stack
9393

9494
Page allocated via order XXX, ...
9595
PFN XXX ...
96-
// Detailed stack
96+
// Detailed stack
9797

9898
The ``page_owner_sort`` tool ignores ``PFN`` rows, puts the remaining rows
9999
in buf, uses regexp to extract the page order value, counts the times
100-
and pages of buf, and finally sorts them according to the times.
100+
and pages of buf, and finally sorts them according to the parameter(s).
101101

102102
See the result about who allocated each page
103103
in the ``sorted_page_owner.txt``. General output::
104104

105105
XXX times, XXX pages:
106106
Page allocated via order XXX, ...
107-
// Detailed stack
107+
// Detailed stack
108108

109109
By default, ``page_owner_sort`` is sorted according to the times of buf.
110-
If you want to sort by the pages nums of buf, use the ``-m`` parameter.
110+
If you want to sort by the page nums of buf, use the ``-m`` parameter.
111+
The detailed parameters are:
112+
113+
fundamental function:
114+
115+
Sort:
116+
-a Sort by memory allocation time.
117+
-m Sort by total memory.
118+
-p Sort by pid.
119+
-P Sort by tgid.
120+
-n Sort by task command name.
121+
-r Sort by memory release time.
122+
-s Sort by stack trace.
123+
-t Sort by times (default).
124+
125+
additional function:
126+
127+
Cull:
128+
-c Cull by comparing stacktrace instead of total block.
129+
--cull <rules>
130+
Specify culling rules.Culling syntax is key[,key[,...]].Choose a
131+
multi-letter key from the **STANDARD FORMAT SPECIFIERS** section.
132+
133+
134+
<rules> is a single argument in the form of a comma-separated list,
135+
which offers a way to specify individual culling rules. The recognized
136+
keywords are described in the **STANDARD FORMAT SPECIFIERS** section below.
137+
<rules> can be specified by the sequence of keys k1,k2, ..., as described in
138+
the STANDARD SORT KEYS section below. Mixed use of abbreviated and
139+
complete-form of keys is allowed.
140+
141+
142+
Examples:
143+
./page_owner_sort <input> <output> --cull=stacktrace
144+
./page_owner_sort <input> <output> --cull=st,pid,name
145+
./page_owner_sort <input> <output> --cull=n,f
146+
147+
Filter:
148+
-f Filter out the information of blocks whose memory has been released.
149+
150+
Select:
151+
--pid <PID> Select by pid.
152+
--tgid <TGID> Select by tgid.
153+
--name <command> Select by task command name.
154+
155+
STANDARD FORMAT SPECIFIERS
156+
==========================
157+
158+
KEY LONG DESCRIPTION
159+
p pid process ID
160+
tg tgid thread group ID
161+
n name task command name
162+
f free whether the page has been released or not
163+
st stacktrace stace trace of the page allocation

arch/alpha/include/uapi/asm/mman.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
#define MADV_POPULATE_READ 22 /* populate (prefault) page tables readable */
7575
#define MADV_POPULATE_WRITE 23 /* populate (prefault) page tables writable */
7676

77+
#define MADV_DONTNEED_LOCKED 24 /* like DONTNEED, but drop locked pages too */
78+
7779
/* compatibility flags */
7880
#define MAP_FILE 0
7981

arch/arm64/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ config ARM64
208208
select IOMMU_DMA if IOMMU_SUPPORT
209209
select IRQ_DOMAIN
210210
select IRQ_FORCED_THREADING
211-
select KASAN_VMALLOC if KASAN_GENERIC
211+
select KASAN_VMALLOC if KASAN
212212
select MODULES_USE_ELF_RELA
213213
select NEED_DMA_MAP_STATE
214214
select NEED_SG_DMA_LENGTH

arch/arm64/include/asm/vmalloc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ static inline bool arch_vmap_pmd_supported(pgprot_t prot)
2525

2626
#endif
2727

28+
#define arch_vmap_pgprot_tagged arch_vmap_pgprot_tagged
29+
static inline pgprot_t arch_vmap_pgprot_tagged(pgprot_t prot)
30+
{
31+
return pgprot_tagged(prot);
32+
}
33+
2834
#endif /* _ASM_ARM64_VMALLOC_H */

arch/arm64/include/asm/vmap_stack.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
*/
1818
static inline unsigned long *arch_alloc_vmap_stack(size_t stack_size, int node)
1919
{
20+
void *p;
21+
2022
BUILD_BUG_ON(!IS_ENABLED(CONFIG_VMAP_STACK));
2123

22-
return __vmalloc_node(stack_size, THREAD_ALIGN, THREADINFO_GFP, node,
24+
p = __vmalloc_node(stack_size, THREAD_ALIGN, THREADINFO_GFP, node,
2325
__builtin_return_address(0));
26+
return kasan_reset_tag(p);
2427
}
2528

2629
#endif /* __ASM_VMAP_STACK_H */

arch/arm64/kernel/module.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ void *module_alloc(unsigned long size)
5858
PAGE_KERNEL, 0, NUMA_NO_NODE,
5959
__builtin_return_address(0));
6060

61-
if (p && (kasan_module_alloc(p, size, gfp_mask) < 0)) {
61+
if (p && (kasan_alloc_module_shadow(p, size, gfp_mask) < 0)) {
6262
vfree(p);
6363
return NULL;
6464
}
6565

66-
return p;
66+
/* Memory is intended to be executable, reset the pointer tag. */
67+
return kasan_reset_tag(p);
6768
}
6869

6970
enum aarch64_reloc_op {

arch/arm64/mm/pageattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static int change_memory_common(unsigned long addr, int numpages,
8585
*/
8686
area = find_vm_area((void *)addr);
8787
if (!area ||
88-
end > (unsigned long)area->addr + area->size ||
88+
end > (unsigned long)kasan_reset_tag(area->addr) + area->size ||
8989
!(area->flags & VM_ALLOC))
9090
return -EINVAL;
9191

arch/arm64/net/bpf_jit_comp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,8 @@ u64 bpf_jit_alloc_exec_limit(void)
13041304

13051305
void *bpf_jit_alloc_exec(unsigned long size)
13061306
{
1307-
return vmalloc(size);
1307+
/* Memory is intended to be executable, reset the pointer tag. */
1308+
return kasan_reset_tag(vmalloc(size));
13081309
}
13091310

13101311
void bpf_jit_free_exec(void *addr)

arch/mips/include/uapi/asm/mman.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
#define MADV_POPULATE_READ 22 /* populate (prefault) page tables readable */
102102
#define MADV_POPULATE_WRITE 23 /* populate (prefault) page tables writable */
103103

104+
#define MADV_DONTNEED_LOCKED 24 /* like DONTNEED, but drop locked pages too */
105+
104106
/* compatibility flags */
105107
#define MAP_FILE 0
106108

0 commit comments

Comments
 (0)