Miaohe Lin
2effe407f7
mm/hugetlb: fix DEBUG_LOCKS_WARN_ON(1) when dissolve_free_hugetlb_folio()
...
commit 52ccdde16b6540abe43b6f8d8e1e1ec90b0983af upstream.
When I did memory failure tests recently, below warning occurs:
DEBUG_LOCKS_WARN_ON(1)
WARNING: CPU: 8 PID: 1011 at kernel/locking/lockdep.c:232 __lock_acquire+0xccb/0x1ca0
Modules linked in: mce_inject hwpoison_inject
CPU: 8 PID: 1011 Comm: bash Kdump: loaded Not tainted 6.9.0-rc3-next-20240410-00012-gdb69f219f4be #3
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
RIP: 0010:__lock_acquire+0xccb/0x1ca0
RSP: 0018:ffffa7a1c7fe3bd0 EFLAGS: 00000082
RAX: 0000000000000000 RBX: eb851eb853975fcf RCX: ffffa1ce5fc1c9c8
RDX: 00000000ffffffd8 RSI: 0000000000000027 RDI: ffffa1ce5fc1c9c0
RBP: ffffa1c6865d3280 R08: ffffffffb0f570a8 R09: 0000000000009ffb
R10: 0000000000000286 R11: ffffffffb0f2ad50 R12: ffffa1c6865d3d10
R13: ffffa1c6865d3c70 R14: 0000000000000000 R15: 0000000000000004
FS: 00007ff9f32aa740(0000) GS:ffffa1ce5fc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007ff9f3134ba0 CR3: 00000008484e4000 CR4: 00000000000006f0
Call Trace:
<TASK>
lock_acquire+0xbe/0x2d0
_raw_spin_lock_irqsave+0x3a/0x60
hugepage_subpool_put_pages.part.0+0xe/0xc0
free_huge_folio+0x253/0x3f0
dissolve_free_huge_page+0x147/0x210
__page_handle_poison+0x9/0x70
memory_failure+0x4e6/0x8c0
hard_offline_page_store+0x55/0xa0
kernfs_fop_write_iter+0x12c/0x1d0
vfs_write+0x380/0x540
ksys_write+0x64/0xe0
do_syscall_64+0xbc/0x1d0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7ff9f3114887
RSP: 002b:00007ffecbacb458 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 000000000000000c RCX: 00007ff9f3114887
RDX: 000000000000000c RSI: 0000564494164e10 RDI: 0000000000000001
RBP: 0000564494164e10 R08: 00007ff9f31d1460 R09: 000000007fffffff
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000000000c
R13: 00007ff9f321b780 R14: 00007ff9f3217600 R15: 00007ff9f3216a00
</TASK>
Kernel panic - not syncing: kernel: panic_on_warn set ...
CPU: 8 PID: 1011 Comm: bash Kdump: loaded Not tainted 6.9.0-rc3-next-20240410-00012-gdb69f219f4be #3
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
Call Trace:
<TASK>
panic+0x326/0x350
check_panic_on_warn+0x4f/0x50
__warn+0x98/0x190
report_bug+0x18e/0x1a0
handle_bug+0x3d/0x70
exc_invalid_op+0x18/0x70
asm_exc_invalid_op+0x1a/0x20
RIP: 0010:__lock_acquire+0xccb/0x1ca0
RSP: 0018:ffffa7a1c7fe3bd0 EFLAGS: 00000082
RAX: 0000000000000000 RBX: eb851eb853975fcf RCX: ffffa1ce5fc1c9c8
RDX: 00000000ffffffd8 RSI: 0000000000000027 RDI: ffffa1ce5fc1c9c0
RBP: ffffa1c6865d3280 R08: ffffffffb0f570a8 R09: 0000000000009ffb
R10: 0000000000000286 R11: ffffffffb0f2ad50 R12: ffffa1c6865d3d10
R13: ffffa1c6865d3c70 R14: 0000000000000000 R15: 0000000000000004
lock_acquire+0xbe/0x2d0
_raw_spin_lock_irqsave+0x3a/0x60
hugepage_subpool_put_pages.part.0+0xe/0xc0
free_huge_folio+0x253/0x3f0
dissolve_free_huge_page+0x147/0x210
__page_handle_poison+0x9/0x70
memory_failure+0x4e6/0x8c0
hard_offline_page_store+0x55/0xa0
kernfs_fop_write_iter+0x12c/0x1d0
vfs_write+0x380/0x540
ksys_write+0x64/0xe0
do_syscall_64+0xbc/0x1d0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7ff9f3114887
RSP: 002b:00007ffecbacb458 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 000000000000000c RCX: 00007ff9f3114887
RDX: 000000000000000c RSI: 0000564494164e10 RDI: 0000000000000001
RBP: 0000564494164e10 R08: 00007ff9f31d1460 R09: 000000007fffffff
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000000000c
R13: 00007ff9f321b780 R14: 00007ff9f3217600 R15: 00007ff9f3216a00
</TASK>
After git bisecting and digging into the code, I believe the root cause is
that _deferred_list field of folio is unioned with _hugetlb_subpool field.
In __update_and_free_hugetlb_folio(), folio->_deferred_list is
initialized leading to corrupted folio->_hugetlb_subpool when folio is
hugetlb. Later free_huge_folio() will use _hugetlb_subpool and above
warning happens.
But it is assumed hugetlb flag must have been cleared when calling
folio_put() in update_and_free_hugetlb_folio(). This assumption is broken
due to below race:
CPU1 CPU2
dissolve_free_huge_page update_and_free_pages_bulk
update_and_free_hugetlb_folio hugetlb_vmemmap_restore_folios
folio_clear_hugetlb_vmemmap_optimized
clear_flag = folio_test_hugetlb_vmemmap_optimized
if (clear_flag) <-- False, it's already cleared.
__folio_clear_hugetlb(folio) <-- Hugetlb is not cleared.
folio_put
free_huge_folio <-- free_the_page is expected.
list_for_each_entry()
__folio_clear_hugetlb <-- Too late.
Fix this issue by checking whether folio is hugetlb directly instead of
checking clear_flag to close the race window.
Link: https://lkml.kernel.org/r/20240419085819.1901645-1-linmiaohe@huawei.com
Fixes: 32c877191e02 ("hugetlb: do not clear hugetlb dtor until allocating vmemmap")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-05-17 11:56:24 +02:00
..
2024-03-01 13:26:39 +01:00
2024-04-03 15:19:27 +02:00
2023-12-03 07:32:08 +01:00
2023-04-26 14:28:41 +02:00
2023-04-26 14:28:39 +02:00
2022-08-02 12:34:03 -04:00
2022-08-28 14:02:45 -07:00
2022-09-11 20:25:50 -07:00
2023-11-28 17:07:14 +00:00
2024-04-03 15:19:42 +02:00
2022-06-27 12:52:53 -07:00
2022-09-26 19:46:26 -07:00
2022-03-22 15:57:11 -07:00
2022-04-26 13:36:25 -07:00
2022-11-22 18:50:44 -08:00
2024-01-10 17:10:31 +01:00
2022-10-03 14:02:53 -07:00
2022-09-26 12:14:34 -07:00
2022-07-17 17:14:27 -07:00
2023-07-01 13:16:25 +02:00
2022-10-12 18:51:51 -07:00
2022-09-26 19:46:05 -07:00
2024-03-06 14:45:06 +00:00
2024-05-17 11:55:52 +02:00
2023-09-19 12:27:56 +02:00
2022-08-08 18:06:43 -07:00
2024-05-17 11:56:24 +02:00
2022-10-03 14:03:05 -07:00
2022-09-26 19:46:16 -07:00
2024-01-10 17:10:31 +01:00
2022-06-27 12:22:31 +01:00
2023-07-01 13:16:24 +02:00
2023-06-14 11:15:29 +02:00
2024-01-10 17:10:31 +01:00
2022-10-28 13:37:22 -07:00
2023-03-30 12:49:29 +02:00
2022-06-16 19:48:31 -07:00
2023-06-28 11:12:17 +02:00
2023-08-30 16:11:11 +02:00
2022-10-03 14:03:36 -07:00
2024-03-01 13:26:36 +01:00
2024-03-01 13:26:32 +01:00
2023-06-28 11:12:27 +02:00
2024-01-10 17:10:33 +01:00
2024-04-27 17:07:16 +02:00
2023-03-10 09:34:27 +01:00
2024-04-10 16:28:33 +02:00
2023-11-08 14:11:02 +01:00
2022-06-16 19:48:30 -07:00
2022-11-08 15:57:23 -08:00
2024-04-03 15:19:36 +02:00
2022-11-22 18:50:43 -08:00
2024-05-17 11:55:52 +02:00
2023-03-22 13:34:03 +01:00
2022-09-26 19:46:27 -07:00
2022-09-26 19:46:09 -07:00
2022-10-03 14:02:43 -07:00
2023-11-08 14:11:03 +01:00
2022-11-30 14:49:42 -08:00
2022-04-21 20:01:10 -07:00
2022-09-26 19:46:09 -07:00
2022-10-12 15:56:46 -07:00
2023-02-09 11:28:22 +01:00
2022-09-26 19:46:25 -07:00
2023-07-05 18:27:37 +01:00
2022-09-26 19:46:29 -07:00
2024-04-03 15:19:42 +02:00
2022-09-11 20:26:01 -07:00
2022-11-22 18:50:41 -08:00
2022-05-19 14:08:54 -07:00
2023-02-09 11:28:04 +01:00
2022-10-28 13:37:22 -07:00
2022-10-03 14:03:03 -07:00
2023-06-14 11:15:29 +02:00
2022-09-26 19:46:05 -07:00
2024-02-23 09:12:32 +01:00
2022-10-10 17:53:04 -07:00
2022-05-13 07:20:18 -07:00
2022-07-17 17:14:47 -07:00
2022-05-13 07:20:05 -07:00
2023-02-09 11:28:04 +01:00
2022-09-03 10:13:13 -07:00
2024-05-17 11:56:21 +02:00
2023-03-10 09:34:25 +01:00
2022-10-03 14:03:05 -07:00
2022-10-03 14:03:36 -07:00
2023-12-20 17:00:26 +01:00
2023-02-22 12:59:46 +01:00
2022-10-03 14:03:07 -07:00
2023-10-06 14:57:03 +02:00
2023-03-30 12:49:23 +02:00
2022-10-10 17:53:04 -07:00
2022-09-29 11:30:55 +02:00
2022-10-11 17:42:55 -06:00
2022-08-08 18:06:42 -07:00
2024-01-31 16:17:02 -08:00
2022-10-03 14:03:36 -07:00
2022-10-03 14:02:46 -07:00
2022-10-03 14:02:51 -07:00
2022-10-03 14:02:45 -07:00
2024-03-01 13:26:32 +01:00
2024-04-03 15:19:32 +02:00
2024-01-10 17:10:31 +01:00
2023-06-28 11:12:17 +02:00
2024-02-23 09:12:51 +01:00
2023-09-13 09:42:59 +02:00
2023-09-13 09:43:00 +02:00
2023-09-13 09:42:33 +02:00
2024-04-03 15:19:42 +02:00
2022-10-10 17:53:04 -07:00
2023-12-20 17:00:26 +01:00
2022-08-02 12:34:03 -04:00
2023-08-23 17:52:40 +02:00
2024-03-01 13:26:39 +01:00