mm-kmsan-maintain-kmsan-metadata-for-page-operations.patch removed from -mm tree
The quilt patch titled
Subject: mm: kmsan: maintain KMSAN metadata for page operations
has been removed from the -mm tree. Its filename was
mm-kmsan-maintain-kmsan-metadata-for-page-operations.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Alexander Potapenko <[email protected]>
Subject: mm: kmsan: maintain KMSAN metadata for page operations
Date: Thu, 15 Sep 2022 17:03:48 +0200
Insert KMSAN hooks that make the necessary bookkeeping changes:
- poison page shadow and origins in alloc_pages()/free_page();
- clear page shadow and origins in clear_page(), copy_user_highpage();
- copy page metadata in copy_highpage(), wp_page_copy();
- handle vmap()/vunmap()/iounmap();
---
arch/x86/include/asm/page_64.h | 7 + arch/x86/mm/ioremap.c | 3 include/linux/highmem.h | 3 include/linux/kmsan.h | 145 +++++++++++++++++++++++++++++++ mm/internal.h | 6 + mm/kmsan/hooks.c | 86 ++++++++++++++++++ mm/kmsan/shadow.c | 113 ++++++++++++++++++++++++ mm/memory.c | 2 mm/page_alloc.c | 11 ++ mm/vmalloc.c | 20 +++- 10 files changed, 394 insertions(+), 2 deletions(-)
arch/x86/include/asm/page_64.h renamed from arch/x86/include/asm/page_64.h~mm-kmsan-maintain-kmsan-metadata-for-page-operations +7 -0
@@ -8,6 +8,8 @@#include <asm/cpufeatures.h> #include <asm/alternative.h> +#include <linux/kmsan-checks.h> +/* duplicated to the one in bootmem.h */ extern unsigned long max_pfn;extern unsigned long phys_base;
@@ -47,6 +49,11 @@ void clear_page_erms(void *page);static inline void clear_page (void *page) { +/* +* Clean up KMSAN metadata for the page being cleared. The assembly call +* below clobbers @page, so we perform unpoisoning before it. +*/ +kmsan_unpoison_memory (page,PAGE_SIZE ); alternative_call_2(clear_page_orig, clear_page_rep, X86_FEATURE_REP_GOOD, clear_page_erms, X86_FEATURE_ERMS,
arch/x86/mm/ioremap.c renamed from arch/x86/mm/ioremap.c~mm-kmsan-maintain-kmsan-metadata-for-page-operations +3 -0
@@ -17,6 +17,7 @@#include <linux/cc_platform.h> #include <linux/efi.h> #include <linux/pgtable.h> +#include <linux/kmsan.h> #include <asm/set_memory.h> #include <asm/e820/api.h>
@@ -479,6 +480,8 @@ void iounmap(volatile void __iomem *addrreturn ; } +kmsan_iounmap_page_range ((unsigned long )addr, + (unsigned long )addr +get_vm_area_size (p));memtype_free (p->phys_addr, p->phys_addr +get_vm_area_size (p));/* Finally remove it */
include/linux/highmem.h renamed from include/linux/highmem.h~mm-kmsan-maintain-kmsan-metadata-for-page-operations +3 -0
@@ -6,6 +6,7 @@#include <linux/kernel.h> #include <linux/bug.h> #include <linux/cacheflush.h> +#include <linux/kmsan.h> #include <linux/mm.h> #include <linux/uaccess.h> #include <linux/hardirq.h>
@@ -311,6 +312,7 @@ static inline void copy_user_highpage(st vfrom =kmap_local_page (from); vto =kmap_local_page (to);copy_user_page (vto, vfrom, vaddr, to); +kmsan_unpoison_memory (page_address (to),PAGE_SIZE );kunmap_local (vto);kunmap_local (vfrom); }
@@ -326,6 +328,7 @@ static inline void copy_highpage(struct vfrom =kmap_local_page (from); vto =kmap_local_page (to);copy_page (vto, vfrom); +kmsan_copy_page_meta (to, from);kunmap_local (vto);kunmap_local (vfrom); }
include/linux/kmsan.h new file +145 -0
145 lines not on this page · raw message
mm/internal.h renamed from mm/internal.h~mm-kmsan-maintain-kmsan-metadata-for-page-operations +6 -0
@@ -818,8 +818,14 @@ int vmap_pages_range_noflush(unsigned lo }#endif +int __vmap_pages_range_noflush (unsigned long addr,unsigned long end, +pgprot_t prot,struct page **pages, +unsigned int page_shift); +void vunmap_range_noflush (unsigned long start,unsigned long end); +void __vunmap_range_noflush (unsigned long start,unsigned long end); +int numa_migrate_prep (struct page *page,struct vm_area_struct *vma,unsigned long addr,int page_nid,int *flags);
mm/kmsan/hooks.c renamed from mm/kmsan/hooks.c~mm-kmsan-maintain-kmsan-metadata-for-page-operations +86 -0
98 lines not on this page · raw message
mm/kmsan/shadow.c renamed from mm/kmsan/shadow.c~mm-kmsan-maintain-kmsan-metadata-for-page-operations +113 -0
116 lines not on this page · raw message
mm/memory.c renamed from mm/memory.c~mm-kmsan-maintain-kmsan-metadata-for-page-operations +2 -0
@@ -52,6 +52,7 @@#include <linux/highmem.h> #include <linux/pagemap.h> #include <linux/memremap.h> +#include <linux/kmsan.h> #include <linux/ksm.h> #include <linux/rmap.h> #include <linux/export.h>
@@ -3136,6 +3137,7 @@ static vm_fault_t wp_page_copy(struct vmdelayacct_wpcopy_end ();return 0 ; } +kmsan_copy_page_meta (new_page, old_page); }if (mem_cgroup_charge (page_folio (new_page), mm,GFP_KERNEL ))
mm/page_alloc.c renamed from mm/page_alloc.c~mm-kmsan-maintain-kmsan-metadata-for-page-operations +11 -0
@@ -27,6 +27,7 @@#include <linux/compiler.h> #include <linux/kernel.h> #include <linux/kasan.h> +#include <linux/kmsan.h> #include <linux/module.h> #include <linux/suspend.h> #include <linux/pagevec.h>
@@ -1400,6 +1401,7 @@ static __always_inline bool free_pages_pVM_BUG_ON_PAGE (PageTail (page), page);trace_mm_page_free (page, order); +kmsan_free_page (page, order);if (unlikely (PageHWPoison (page)) && !order) {/*
@@ -3808,6 +3810,14 @@ static struct page *rmqueue_pcplist(stru/* * Allocate a page from the given zone. Use pcplists for order-0 allocations. */ + +/* +* Do not instrument rmqueue() with KMSAN. This function may call +* __msan_poison_alloca() through a call to set_pfnblock_flags_mask(). +* If __msan_poison_alloca() attempts to allocate pages for the stack depot, it +* may call rmqueue() again, which will result in a deadlock. +*/ +__no_sanitize_memory static inline struct page *rmqueue(struct zone *preferred_zone, struct zone *zone, unsigned int order,
@@ -5560,6 +5570,7 @@ out: }trace_mm_page_alloc (page, order, alloc_gfp, ac.migratetype); +kmsan_alloc_page (page, order, alloc_gfp);return page; }
mm/vmalloc.c renamed from mm/vmalloc.c~mm-kmsan-maintain-kmsan-metadata-for-page-operations +18 -2
@@ -320,6 +320,9 @@ int ioremap_page_range(unsigned long add err =vmap_range_noflush (addr, end, phys_addr,pgprot_nx (prot), ioremap_max_page_shift);flush_cache_vmap (addr, end); +if (!err) +kmsan_ioremap_page_range (addr, end, phys_addr, prot, + ioremap_max_page_shift);return err; }
@@ -416,7 +419,7 @@ static void vunmap_p4d_range(pgd_t *pgd,* * This is an internal function only. Do not use outside mm/. */ -void vunmap_range_noflush (unsigned long start,unsigned long end) +void __vunmap_range_noflush (unsigned long start,unsigned long end) {unsigned long next;pgd_t *pgd;
@@ -438,6 +441,12 @@ void vunmap_range_noflush(unsigned longarch_sync_kernel_mappings (start, end); } +void vunmap_range_noflush (unsigned long start,unsigned long end) +{ +kmsan_vunmap_range_noflush (start, end); +__vunmap_range_noflush (start, end); +} +/** * vunmap_range - unmap kernel virtual addresses * @addr: start of the VM area to unmap
@@ -575,7 +584,7 @@ static int vmap_small_pages_range_noflus* * This is an internal function only. Do not use outside mm/. */ -int vmap_pages_range_noflush (unsigned long addr,unsigned long end, +int __vmap_pages_range_noflush (unsigned long addr,unsigned long end,pgprot_t prot,struct page **pages,unsigned int page_shift) {unsigned int i, nr = (end - addr) >>PAGE_SHIFT ;
@@ -601,6 +610,13 @@ int vmap_pages_range_noflush(unsigned loreturn 0 ; } +int vmap_pages_range_noflush (unsigned long addr,unsigned long end, +pgprot_t prot,struct page **pages,unsigned int page_shift) +{ +kmsan_vmap_pages_range_noflush (addr, end, prot, pages, page_shift); +return __vmap_pages_range_noflush (addr, end, prot, pages, page_shift); +} +/** * vmap_pages_range - map pages to a kernel virtual address * @addr: start of the VM area to map
_
Patches currently in -mm which might be from [email protected] are