Skip to content

Commit ec33b59

Browse files
committed
mm/mempool: fix poisoning order>0 pages with HIGHMEM
The kernel test has reported: BUG: unable to handle page fault for address: fffba000 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page *pde = 03171067 *pte = 00000000 Oops: Oops: 0002 [#1] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Tainted: G T 6.18.0-rc2-00031-gec7f31b2a2d3 #1 NONE a1d066dfe789f54bc7645c7989957d2bdee593ca Tainted: [T]=RANDSTRUCT Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 EIP: memset (arch/x86/include/asm/string_32.h:168 arch/x86/lib/memcpy_32.c:17) Code: a5 8b 4d f4 83 e1 03 74 02 f3 a4 83 c4 04 5e 5f 5d 2e e9 73 41 01 00 90 90 90 3e 8d 74 26 00 55 89 e5 57 56 89 c6 89 d0 89 f7 <f3> aa 89 f0 5e 5f 5d 2e e9 53 41 01 00 cc cc cc 55 89 e5 53 57 56 EAX: 0000006b EBX: 00000015 ECX: 001fefff EDX: 0000006b ESI: fffb9000 EDI: fffba000 EBP: c611fbf0 ESP: c611fbe8 DS: 007b ES: 007b FS: 0000 GS: 0000 SS: 0068 EFLAGS: 00010287 CR0: 80050033 CR2: fffba000 CR3: 0316e000 CR4: 00040690 Call Trace: poison_element (mm/mempool.c:83 mm/mempool.c:102) mempool_init_node (mm/mempool.c:142 mm/mempool.c:226) mempool_init_noprof (mm/mempool.c:250 (discriminator 1)) ? mempool_alloc_pages (mm/mempool.c:640) bio_integrity_initfn (block/bio-integrity.c:483 (discriminator 8)) ? mempool_alloc_pages (mm/mempool.c:640) do_one_initcall (init/main.c:1283) Christoph found out this is due to the poisoning code not dealing properly with CONFIG_HIGHMEM because only the first page is mapped but then the whole potentially high-order page is accessed. We could give up on HIGHMEM here, but it's straightforward to fix this with a loop that's mapping, poisoning or checking and unmapping individual pages. Reported-by: kernel test robot <oliver.sang@intel.com> Closes: https://lore.kernel.org/oe-lkp/202511111411.9ebfa1ba-lkp@intel.com Analyzed-by: Christoph Hellwig <hch@lst.de> Fixes: bdfedb7 ("mm, mempool: poison elements backed by slab allocator") Cc: stable@vger.kernel.org Tested-by: kernel test robot <oliver.sang@intel.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://patch.msgid.link/20251113-mempool-poison-v1-1-233b3ef984c3@suse.cz Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
1 parent cbcff93 commit ec33b59

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

mm/mempool.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,20 @@ static void check_element(mempool_t *pool, void *element)
6868
} else if (pool->free == mempool_free_pages) {
6969
/* Mempools backed by page allocator */
7070
int order = (int)(long)pool->pool_data;
71-
void *addr = kmap_local_page((struct page *)element);
7271

73-
__check_element(pool, addr, 1UL << (PAGE_SHIFT + order));
74-
kunmap_local(addr);
72+
#ifdef CONFIG_HIGHMEM
73+
for (int i = 0; i < (1 << order); i++) {
74+
struct page *page = (struct page *)element;
75+
void *addr = kmap_local_page(page + i);
76+
77+
__check_element(pool, addr, PAGE_SIZE);
78+
kunmap_local(addr);
79+
}
80+
#else
81+
void *addr = page_address((struct page *)element);
82+
83+
__check_element(pool, addr, PAGE_SIZE << order);
84+
#endif
7585
}
7686
}
7787

@@ -97,10 +107,20 @@ static void poison_element(mempool_t *pool, void *element)
97107
} else if (pool->alloc == mempool_alloc_pages) {
98108
/* Mempools backed by page allocator */
99109
int order = (int)(long)pool->pool_data;
100-
void *addr = kmap_local_page((struct page *)element);
101110

102-
__poison_element(addr, 1UL << (PAGE_SHIFT + order));
103-
kunmap_local(addr);
111+
#ifdef CONFIG_HIGHMEM
112+
for (int i = 0; i < (1 << order); i++) {
113+
struct page *page = (struct page *)element;
114+
void *addr = kmap_local_page(page + i);
115+
116+
__poison_element(addr, PAGE_SIZE);
117+
kunmap_local(addr);
118+
}
119+
#else
120+
void *addr = page_address((struct page *)element);
121+
122+
__poison_element(addr, PAGE_SIZE << order);
123+
#endif
104124
}
105125
}
106126
#else /* CONFIG_SLUB_DEBUG_ON */

0 commit comments

Comments
 (0)