Patch "mm: fix devm_memremap_pages crash, use mem_hotplug_{begin, done}" has been added to the 4.4-stable tree
This is a note to let you know that I've just added the patch titled
mm: fix devm_memremap_pages crash, use mem_hotplug_{begin, done}to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
mm-fix-devm_memremap_pages-crash-use-mem_hotplug_-begin-done.patch
and it can be found in the queue-4.4 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
f931ab479dd24cf7a2c6e2df19778406892591fbMon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Tue, 10 Jan 2017 16:57:36 -0800
Subject: mm: fix devm_memremap_pages crash, use mem_hotplug_{begin, done}
From: Dan Williams <[email protected]>
commit f931ab479dd24cf7a2c6e2df19778406892591fb upstream.
Both arch_add_memory() and arch_remove_memory() expect a single threaded context.
For example, arch/x86/mm/init_64.c::kernel_physical_mapping_init() does not hold any locks over this check and branch:
if (pgd_val(*pgd)) {
pud = (pud_t *)pgd_page_vaddr(*pgd);
paddr_last = phys_pud_init(pud, __pa(vaddr),
__pa(vaddr_end),
page_size_mask);
continue;
}
pud = alloc_low_page();
paddr_last = phys_pud_init(pud, __pa(vaddr), __pa(vaddr_end),
page_size_mask);The result is that two threads calling devm_memremap_pages() simultaneously can end up colliding on pgd initialization. This leads to crash signatures like the following where the loser of the race initializes the wrong pgd entry:
BUG: unable to handle kernel paging request at ffff888ebfff0000
IP: memcpy_erms+0x6/0x10
PGD 2f8e8fc067 PUD 0 /* <---- Invalid PUD */
Oops: 0000 [#1] SMP DEBUG_PAGEALLOC
CPU: 54 PID: 3818 Comm: systemd-udevd Not tainted 4.6.7+ #13
task: ffff882fac290040 ti: ffff882f887a4000 task.ti: ffff882f887a4000
RIP: memcpy_erms+0x6/0x10
[..]
Call Trace:
? pmem_do_bvec+0x205/0x370 [nd_pmem]
? blk_queue_enter+0x3a/0x280
pmem_rw_page+0x38/0x80 [nd_pmem]
bdev_read_page+0x84/0xb0Hold the standard memory hotplug mutex over calls to arch_{add,remove}_memory().
--- kernel/memremap.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/memremap.c +4 -0
@@ -159,7 +159,9 @@ static void devm_memremap_pages_release(struct page_map *page_map = res;/* pages are dead and unused, undo the arch mapping */ +mem_hotplug_begin ();arch_remove_memory (page_map->res.start,resource_size (&page_map->res)); +mem_hotplug_done (); }void *devm_memremap_pages (struct device *dev,struct resource *res)
@@ -189,7 +191,9 @@ void *devm_memremap_pages(struct deviceif (nid <0 ) nid =numa_mem_id (); +mem_hotplug_begin (); error =arch_add_memory (nid, res->start,resource_size (res), true); +mem_hotplug_done ();if (error) {devres_free (page_map);return ERR_PTR (error);
Patches currently in stable-queue which might be from [email protected] are
queue-4.4/mm-fix-devm_memremap_pages-crash-use-mem_hotplug_-begin-done.patch