From 8410f99b089b749f19ba229ad4dd19239fea08a4 Mon Sep 17 00:00:00 2001 From: Ning Zhang Date: Thu, 10 Jun 2021 20:02:10 +0800 Subject: [PATCH 2923/2944] mm, thp: remap the page when unmap failed for thp reclaim fix #34670772 If we don't remap the page when unmap failed, the page may not clean the migration entry, which may lead to kernel panic. Calltrace: [ 181.302423] ------------[ cut here ]------------ [ 181.307078] kernel BUG at ./include/linux/swapops.h:217! [ 181.312463] invalid opcode: 0000 [#1] SMP PTI [ 181.316842] CPU: 6 PID: 10040 Comm: access Kdump: loaded Not tainted 4.19.91-ck+ #33[ 181.324612] Hardware name: Inspur SA5212H2/YZMB-00101-108, BIOS 2.0.3 03/26/2014 [ 181.332047] RIP: 0010:migration_entry_to_page.part.89+0x0/0xe [ 181.337822] Code: 16 00 00 48 01 df 48 c1 ff 06 48 01 fd 48 89 ef e8 9e ff ff ff 85 c0 74 0c 48 89 e8 48 c1 e0 06 48 29 d8 eb 02 31 c0 5b 5d c3 <0f> 0b 90 90 90 90 90 90 90 90 90 90 90 90 e8 bb bf e3 1e 48 85 ff [ 181.356648] RSP: 0018:ffffc9000184fcb0 EFLAGS: 00010246 [ 181.361894] RAX: 400000000008001c RBX: ffff8897ac5d8040 RCX: 0000000000000000 [ 181.369051] RDX: 3c0000000179c008 RSI: ffffea005e700008 RDI: ffff88981f796588 [ 181.376210] RBP: 0000400000808000 R08: ffffea005e700200 R09: 000000000002df34 [ 181.383371] R10: ffffffff828a37c4 R11: 0000000000000a58 R12: f7fffffd0c7fee00 [ 181.390538] R13: 0000400000a00000 R14: ffffc9000184fde8 R15: 0000400000809000 [ 181.397698] FS: 0000000000000000(0000) GS:ffff88981f780000(0000) knlGS:0000000000000000 [ 181.405822] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 181.411591] CR2: 00007f2f9480ad28 CR3: 000000000220a001 CR4: 00000000000606e0 [ 181.418757] Call Trace: [ 181.421221] unmap_page_range+0xb45/0xbb0 [ 181.425267] unmap_vmas+0x42/0x90 [ 181.428606] exit_mmap+0xb5/0x1a0 [ 181.431950] mmput+0x5b/0x120 [ 181.434940] do_exit+0x281/0xc90 [ 181.438195] do_group_exit+0x39/0xa0 [ 181.441788] __x64_sys_exit_group+0x14/0x20 [ 181.445997] do_syscall_64+0x5b/0x1b0 [ 181.449679] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 181.454754] RIP: 0033:0x7f2f948d7c58 [ 181.458354] Code: Bad RIP value. In this patch, we remap the page to clean the migration entry. Signed-off-by: Ning Zhang Reviewed-by: Gang Deng --- mm/huge_memory.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 933c9ee..a6f36bb 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3293,10 +3293,8 @@ static bool replace_zero_page(struct page *page) anon_vma_lock_write(anon_vma); unmap_success = try_to_unmap(page, ttu_flags); - if (!unmap_success) - ret = false; - else if (!is_zero_page(page)) { - /* remap the non-zero page */ + if (!unmap_success || !is_zero_page(page)) { + /* remap the page */ remove_migration_ptes(page, page, true); ret = false; } else -- 1.8.3.1