Re: kernel panic on null pointer on page->mem_cgroup
On Mon 21-08-17 09:02:18, Johannes Weiner wrote: > On Thu, Aug 10, 2017 at 01:56:05PM +0200, Michal Hocko wrote: > > On Wed 09-08-17 14:38:25, Johannes Weiner wrote: > > > The issue is that writeback doesn't hold a page reference and the page > > > might get freed after PG_writeback is cleared (and the mapping is > > > unlocked) in test_clear_page_writeback(). The stat functions looking > > > up the page's node or zone are safe, as those attributes are static > > > across allocation and free cycles. But page->mem_cgroup is not, and it > > > will get cleared if we race with truncation or migration. > > > > Is there anything that prevents us from holding a reference on a page > > under writeback? > > Hm, I'm hesitant to add redundant life-time management to the page > there just for memcg, which is not always configured in. > > Pinning the memcg instead is slightly more complex, but IMO has the > complexity in a preferrable place. If that is the single place that needs such a special handling and it is very likely to stay that way then the additional complexity is probably justified. I am just worried that this is really subtle and history tells us that such a code usually kicks us back later. > Would you agree? Well, I was not objecting to the patch. It seems correct I am just worried a robust fix would be preferable. And a clear object life time sounds like a more robust thing to do. -- Michal Hocko SUSE Labs
Re: kernel panic on null pointer on page->mem_cgroup
On Thu, Aug 10, 2017 at 01:56:05PM +0200, Michal Hocko wrote: > On Wed 09-08-17 14:38:25, Johannes Weiner wrote: > > The issue is that writeback doesn't hold a page reference and the page > > might get freed after PG_writeback is cleared (and the mapping is > > unlocked) in test_clear_page_writeback(). The stat functions looking > > up the page's node or zone are safe, as those attributes are static > > across allocation and free cycles. But page->mem_cgroup is not, and it > > will get cleared if we race with truncation or migration. > > Is there anything that prevents us from holding a reference on a page > under writeback? Hm, I'm hesitant to add redundant life-time management to the page there just for memcg, which is not always configured in. Pinning the memcg instead is slightly more complex, but IMO has the complexity in a preferrable place. Would you agree?
Re: kernel panic on null pointer on page->mem_cgroup
Hi Johannes, On 08/09, Johannes Weiner wrote: > On Tue, Aug 08, 2017 at 10:39:27PM -0400, Brad Bolen wrote: > > Yes, the BUG_ON(!page_count(page)) fired for me as well. > > Brad, Jaegeuk, does the following patch address this problem? I also confirmed that this patch addresses the problem. Tested-by: Jaegeuk Kim Thanks, > > --- > > >From cf0060892eb70bccbc8cedeac0a5756c8f7b975e Mon Sep 17 00:00:00 2001 > From: Johannes Weiner > Date: Wed, 9 Aug 2017 12:06:03 -0400 > Subject: [PATCH] mm: memcontrol: fix NULL pointer crash in > test_clear_page_writeback() > > Jaegeuk and Brad report a NULL pointer crash when writeback ending > tries to update the memcg stats: > > [] BUG: unable to handle kernel NULL pointer dereference at 03b0 > [] IP: test_clear_page_writeback+0x12e/0x2c0 > [...] > [] RIP: 0010:test_clear_page_writeback+0x12e/0x2c0 > [] RSP: 0018:8e3abfd03d78 EFLAGS: 00010046 > [] RAX: RBX: db59c03f8900 RCX: ffe8 > [] RDX: RSI: 0010 RDI: 8e3abffeb000 > [] RBP: 8e3abfd03da8 R08: 00020059 R09: fffc > [] R10: R11: 00020048 R12: 8e3a8c39f668 > [] R13: 0001 R14: 8e3a8c39f680 R15: > [] FS: () GS:8e3abfd0() > knlGS: > [] CS: 0010 DS: ES: CR0: 80050033 > [] CR2: 03b0 CR3: 2c5e1000 CR4: 000406e0 > [] DR0: DR1: DR2: > [] DR3: DR6: fffe0ff0 DR7: 0400 > [] Call Trace: > [] > [] end_page_writeback+0x47/0x70 > [] f2fs_write_end_io+0x76/0x180 [f2fs] > [] bio_endio+0x9f/0x120 > [] blk_update_request+0xa8/0x2f0 > [] scsi_end_request+0x39/0x1d0 > [] scsi_io_completion+0x211/0x690 > [] scsi_finish_command+0xd9/0x120 > [] scsi_softirq_done+0x127/0x150 > [] __blk_mq_complete_request_remote+0x13/0x20 > [] flush_smp_call_function_queue+0x56/0x110 > [] generic_smp_call_function_single_interrupt+0x13/0x30 > [] smp_call_function_single_interrupt+0x27/0x40 > [] call_function_single_interrupt+0x89/0x90 > [] RIP: 0010:native_safe_halt+0x6/0x10 > > (gdb) l *(test_clear_page_writeback+0x12e) > 0x811bae3e is in test_clear_page_writeback > (./include/linux/memcontrol.h:619). > 614 mod_node_page_state(page_pgdat(page), idx, val); > 615 if (mem_cgroup_disabled() || !page->mem_cgroup) > 616 return; > 617 mod_memcg_state(page->mem_cgroup, idx, val); > 618 pn = page->mem_cgroup->nodeinfo[page_to_nid(page)]; > 619 this_cpu_add(pn->lruvec_stat->count[idx], val); > 620 } > 621 > 622 unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, > 623 gfp_t gfp_mask, > > The issue is that writeback doesn't hold a page reference and the page > might get freed after PG_writeback is cleared (and the mapping is > unlocked) in test_clear_page_writeback(). The stat functions looking > up the page's node or zone are safe, as those attributes are static > across allocation and free cycles. But page->mem_cgroup is not, and it > will get cleared if we race with truncation or migration. > > It appears this race window has been around for a while, but less > likely to trigger when the memcg stats were updated first thing after > PG_writeback is cleared. Recent changes reshuffled this code to update > the global node stats before the memcg ones, though, stretching the > race window out to an extent where people can reproduce the problem. > > Update test_clear_page_writeback() to look up and pin page->mem_cgroup > before clearing PG_writeback, then not use that pointer afterward. It > is a partial revert of 62cccb8c8e7a ("mm: simplify lock_page_memcg()") > but leaves the pageref-holding callsites that aren't affected alone. > > Fixes: 62cccb8c8e7a ("mm: simplify lock_page_memcg()") > Reported-by: Jaegeuk Kim > Reported-by: Bradley Bolen > Cc: # 4.6+ > Signed-off-by: Johannes Weiner > --- > include/linux/memcontrol.h | 10 -- > mm/memcontrol.c| 43 +++ > mm/page-writeback.c| 15 --- > 3 files changed, 51 insertions(+), 17 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 3914e3dd6168..9b15a4bcfa77 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -484,7 +484,8 @@ bool mem_cgroup_oom_synchronize(bool wait); > extern int do_swap_account; > #endif > > -void lock_page_memcg(struct page *page); > +struct mem_cgroup *lock_page_memcg(struct page *page); > +void __unlock_page_memcg(struct mem_cgroup *memcg); > void unlock_page_memcg(struct page *page); > > static inline unsigned long memcg_page_state(struct mem_cgroup *memcg, > @@ -809,7 +810,12 @@ mem_cgroup_print_oom_info(struct mem_cg
Re: kernel panic on null pointer on page->mem_cgroup
Johannes, Yes, the patch (slightly modified to apply for 4.11) does make my problem go away. Thank you for driving this to a solution. Brad On Wed, Aug 9, 2017 at 2:38 PM, Johannes Weiner wrote: > On Tue, Aug 08, 2017 at 10:39:27PM -0400, Brad Bolen wrote: >> Yes, the BUG_ON(!page_count(page)) fired for me as well. > > Brad, Jaegeuk, does the following patch address this problem? > > --- > > From cf0060892eb70bccbc8cedeac0a5756c8f7b975e Mon Sep 17 00:00:00 2001 > From: Johannes Weiner > Date: Wed, 9 Aug 2017 12:06:03 -0400 > Subject: [PATCH] mm: memcontrol: fix NULL pointer crash in > test_clear_page_writeback() > > Jaegeuk and Brad report a NULL pointer crash when writeback ending > tries to update the memcg stats: > > [] BUG: unable to handle kernel NULL pointer dereference at 03b0 > [] IP: test_clear_page_writeback+0x12e/0x2c0 > [...] > [] RIP: 0010:test_clear_page_writeback+0x12e/0x2c0 > [] RSP: 0018:8e3abfd03d78 EFLAGS: 00010046 > [] RAX: RBX: db59c03f8900 RCX: ffe8 > [] RDX: RSI: 0010 RDI: 8e3abffeb000 > [] RBP: 8e3abfd03da8 R08: 00020059 R09: fffc > [] R10: R11: 00020048 R12: 8e3a8c39f668 > [] R13: 0001 R14: 8e3a8c39f680 R15: > [] FS: () GS:8e3abfd0() > knlGS: > [] CS: 0010 DS: ES: CR0: 80050033 > [] CR2: 03b0 CR3: 2c5e1000 CR4: 000406e0 > [] DR0: DR1: DR2: > [] DR3: DR6: fffe0ff0 DR7: 0400 > [] Call Trace: > [] > [] end_page_writeback+0x47/0x70 > [] f2fs_write_end_io+0x76/0x180 [f2fs] > [] bio_endio+0x9f/0x120 > [] blk_update_request+0xa8/0x2f0 > [] scsi_end_request+0x39/0x1d0 > [] scsi_io_completion+0x211/0x690 > [] scsi_finish_command+0xd9/0x120 > [] scsi_softirq_done+0x127/0x150 > [] __blk_mq_complete_request_remote+0x13/0x20 > [] flush_smp_call_function_queue+0x56/0x110 > [] generic_smp_call_function_single_interrupt+0x13/0x30 > [] smp_call_function_single_interrupt+0x27/0x40 > [] call_function_single_interrupt+0x89/0x90 > [] RIP: 0010:native_safe_halt+0x6/0x10 > > (gdb) l *(test_clear_page_writeback+0x12e) > 0x811bae3e is in test_clear_page_writeback > (./include/linux/memcontrol.h:619). > 614 mod_node_page_state(page_pgdat(page), idx, val); > 615 if (mem_cgroup_disabled() || !page->mem_cgroup) > 616 return; > 617 mod_memcg_state(page->mem_cgroup, idx, val); > 618 pn = page->mem_cgroup->nodeinfo[page_to_nid(page)]; > 619 this_cpu_add(pn->lruvec_stat->count[idx], val); > 620 } > 621 > 622 unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int > order, > 623 gfp_t gfp_mask, > > The issue is that writeback doesn't hold a page reference and the page > might get freed after PG_writeback is cleared (and the mapping is > unlocked) in test_clear_page_writeback(). The stat functions looking > up the page's node or zone are safe, as those attributes are static > across allocation and free cycles. But page->mem_cgroup is not, and it > will get cleared if we race with truncation or migration. > > It appears this race window has been around for a while, but less > likely to trigger when the memcg stats were updated first thing after > PG_writeback is cleared. Recent changes reshuffled this code to update > the global node stats before the memcg ones, though, stretching the > race window out to an extent where people can reproduce the problem. > > Update test_clear_page_writeback() to look up and pin page->mem_cgroup > before clearing PG_writeback, then not use that pointer afterward. It > is a partial revert of 62cccb8c8e7a ("mm: simplify lock_page_memcg()") > but leaves the pageref-holding callsites that aren't affected alone. > > Fixes: 62cccb8c8e7a ("mm: simplify lock_page_memcg()") > Reported-by: Jaegeuk Kim > Reported-by: Bradley Bolen > Cc: # 4.6+ > Signed-off-by: Johannes Weiner > --- > include/linux/memcontrol.h | 10 -- > mm/memcontrol.c| 43 +++ > mm/page-writeback.c| 15 --- > 3 files changed, 51 insertions(+), 17 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 3914e3dd6168..9b15a4bcfa77 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -484,7 +484,8 @@ bool mem_cgroup_oom_synchronize(bool wait); > extern int do_swap_account; > #endif > > -void lock_page_memcg(struct page *page); > +struct mem_cgroup *lock_page_memcg(struct page *page); > +void __unlock_page_memcg(struct mem_cgroup *memcg); > void unlock_page_memcg(struct page *page); > > static inline unsigned long memcg_page_state(struct mem_cgroup *memc
Re: kernel panic on null pointer on page->mem_cgroup
On Wed 09-08-17 14:38:25, Johannes Weiner wrote: > On Tue, Aug 08, 2017 at 10:39:27PM -0400, Brad Bolen wrote: > > Yes, the BUG_ON(!page_count(page)) fired for me as well. > > Brad, Jaegeuk, does the following patch address this problem? > > --- > > >From cf0060892eb70bccbc8cedeac0a5756c8f7b975e Mon Sep 17 00:00:00 2001 > From: Johannes Weiner > Date: Wed, 9 Aug 2017 12:06:03 -0400 > Subject: [PATCH] mm: memcontrol: fix NULL pointer crash in > test_clear_page_writeback() > > Jaegeuk and Brad report a NULL pointer crash when writeback ending > tries to update the memcg stats: > > [] BUG: unable to handle kernel NULL pointer dereference at 03b0 > [] IP: test_clear_page_writeback+0x12e/0x2c0 > [...] > [] RIP: 0010:test_clear_page_writeback+0x12e/0x2c0 > [] RSP: 0018:8e3abfd03d78 EFLAGS: 00010046 > [] RAX: RBX: db59c03f8900 RCX: ffe8 > [] RDX: RSI: 0010 RDI: 8e3abffeb000 > [] RBP: 8e3abfd03da8 R08: 00020059 R09: fffc > [] R10: R11: 00020048 R12: 8e3a8c39f668 > [] R13: 0001 R14: 8e3a8c39f680 R15: > [] FS: () GS:8e3abfd0() > knlGS: > [] CS: 0010 DS: ES: CR0: 80050033 > [] CR2: 03b0 CR3: 2c5e1000 CR4: 000406e0 > [] DR0: DR1: DR2: > [] DR3: DR6: fffe0ff0 DR7: 0400 > [] Call Trace: > [] > [] end_page_writeback+0x47/0x70 > [] f2fs_write_end_io+0x76/0x180 [f2fs] > [] bio_endio+0x9f/0x120 > [] blk_update_request+0xa8/0x2f0 > [] scsi_end_request+0x39/0x1d0 > [] scsi_io_completion+0x211/0x690 > [] scsi_finish_command+0xd9/0x120 > [] scsi_softirq_done+0x127/0x150 > [] __blk_mq_complete_request_remote+0x13/0x20 > [] flush_smp_call_function_queue+0x56/0x110 > [] generic_smp_call_function_single_interrupt+0x13/0x30 > [] smp_call_function_single_interrupt+0x27/0x40 > [] call_function_single_interrupt+0x89/0x90 > [] RIP: 0010:native_safe_halt+0x6/0x10 > > (gdb) l *(test_clear_page_writeback+0x12e) > 0x811bae3e is in test_clear_page_writeback > (./include/linux/memcontrol.h:619). > 614 mod_node_page_state(page_pgdat(page), idx, val); > 615 if (mem_cgroup_disabled() || !page->mem_cgroup) > 616 return; > 617 mod_memcg_state(page->mem_cgroup, idx, val); > 618 pn = page->mem_cgroup->nodeinfo[page_to_nid(page)]; > 619 this_cpu_add(pn->lruvec_stat->count[idx], val); > 620 } > 621 > 622 unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, > 623 gfp_t gfp_mask, > > The issue is that writeback doesn't hold a page reference and the page > might get freed after PG_writeback is cleared (and the mapping is > unlocked) in test_clear_page_writeback(). The stat functions looking > up the page's node or zone are safe, as those attributes are static > across allocation and free cycles. But page->mem_cgroup is not, and it > will get cleared if we race with truncation or migration. Is there anything that prevents us from holding a reference on a page under writeback? -- Michal Hocko SUSE Labs
Re: kernel panic on null pointer on page->mem_cgroup
On Tue, Aug 08, 2017 at 10:39:27PM -0400, Brad Bolen wrote: > Yes, the BUG_ON(!page_count(page)) fired for me as well. Brad, Jaegeuk, does the following patch address this problem? --- >From cf0060892eb70bccbc8cedeac0a5756c8f7b975e Mon Sep 17 00:00:00 2001 From: Johannes Weiner Date: Wed, 9 Aug 2017 12:06:03 -0400 Subject: [PATCH] mm: memcontrol: fix NULL pointer crash in test_clear_page_writeback() Jaegeuk and Brad report a NULL pointer crash when writeback ending tries to update the memcg stats: [] BUG: unable to handle kernel NULL pointer dereference at 03b0 [] IP: test_clear_page_writeback+0x12e/0x2c0 [...] [] RIP: 0010:test_clear_page_writeback+0x12e/0x2c0 [] RSP: 0018:8e3abfd03d78 EFLAGS: 00010046 [] RAX: RBX: db59c03f8900 RCX: ffe8 [] RDX: RSI: 0010 RDI: 8e3abffeb000 [] RBP: 8e3abfd03da8 R08: 00020059 R09: fffc [] R10: R11: 00020048 R12: 8e3a8c39f668 [] R13: 0001 R14: 8e3a8c39f680 R15: [] FS: () GS:8e3abfd0() knlGS: [] CS: 0010 DS: ES: CR0: 80050033 [] CR2: 03b0 CR3: 2c5e1000 CR4: 000406e0 [] DR0: DR1: DR2: [] DR3: DR6: fffe0ff0 DR7: 0400 [] Call Trace: [] [] end_page_writeback+0x47/0x70 [] f2fs_write_end_io+0x76/0x180 [f2fs] [] bio_endio+0x9f/0x120 [] blk_update_request+0xa8/0x2f0 [] scsi_end_request+0x39/0x1d0 [] scsi_io_completion+0x211/0x690 [] scsi_finish_command+0xd9/0x120 [] scsi_softirq_done+0x127/0x150 [] __blk_mq_complete_request_remote+0x13/0x20 [] flush_smp_call_function_queue+0x56/0x110 [] generic_smp_call_function_single_interrupt+0x13/0x30 [] smp_call_function_single_interrupt+0x27/0x40 [] call_function_single_interrupt+0x89/0x90 [] RIP: 0010:native_safe_halt+0x6/0x10 (gdb) l *(test_clear_page_writeback+0x12e) 0x811bae3e is in test_clear_page_writeback (./include/linux/memcontrol.h:619). 614 mod_node_page_state(page_pgdat(page), idx, val); 615 if (mem_cgroup_disabled() || !page->mem_cgroup) 616 return; 617 mod_memcg_state(page->mem_cgroup, idx, val); 618 pn = page->mem_cgroup->nodeinfo[page_to_nid(page)]; 619 this_cpu_add(pn->lruvec_stat->count[idx], val); 620 } 621 622 unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, 623 gfp_t gfp_mask, The issue is that writeback doesn't hold a page reference and the page might get freed after PG_writeback is cleared (and the mapping is unlocked) in test_clear_page_writeback(). The stat functions looking up the page's node or zone are safe, as those attributes are static across allocation and free cycles. But page->mem_cgroup is not, and it will get cleared if we race with truncation or migration. It appears this race window has been around for a while, but less likely to trigger when the memcg stats were updated first thing after PG_writeback is cleared. Recent changes reshuffled this code to update the global node stats before the memcg ones, though, stretching the race window out to an extent where people can reproduce the problem. Update test_clear_page_writeback() to look up and pin page->mem_cgroup before clearing PG_writeback, then not use that pointer afterward. It is a partial revert of 62cccb8c8e7a ("mm: simplify lock_page_memcg()") but leaves the pageref-holding callsites that aren't affected alone. Fixes: 62cccb8c8e7a ("mm: simplify lock_page_memcg()") Reported-by: Jaegeuk Kim Reported-by: Bradley Bolen Cc: # 4.6+ Signed-off-by: Johannes Weiner --- include/linux/memcontrol.h | 10 -- mm/memcontrol.c| 43 +++ mm/page-writeback.c| 15 --- 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 3914e3dd6168..9b15a4bcfa77 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -484,7 +484,8 @@ bool mem_cgroup_oom_synchronize(bool wait); extern int do_swap_account; #endif -void lock_page_memcg(struct page *page); +struct mem_cgroup *lock_page_memcg(struct page *page); +void __unlock_page_memcg(struct mem_cgroup *memcg); void unlock_page_memcg(struct page *page); static inline unsigned long memcg_page_state(struct mem_cgroup *memcg, @@ -809,7 +810,12 @@ mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p) { } -static inline void lock_page_memcg(struct page *page) +static inline struct mem_cgroup *lock_page_memcg(struct page *page) +{ + return NULL; +} + +static inline void __unlock_page_memcg(struct mem_cgroup *memcg) { } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 3df3c04d73a
Re: kernel panic on null pointer on page->mem_cgroup
Yes, the BUG_ON(!page_count(page)) fired for me as well. On Tue, Aug 8, 2017 at 9:44 PM, Jaegeuk Kim wrote: > On 08/08, Johannes Weiner wrote: >> On Tue, Aug 08, 2017 at 03:13:42PM -0400, Brad Bolen wrote: >> > On Tue, Aug 8, 2017 at 1:37 PM, Johannes Weiner wrote: >> > > On Tue, Aug 08, 2017 at 09:56:01AM -0700, Jaegeuk Kim wrote: >> > >> On 08/08, Johannes Weiner wrote: >> > >> > Hi Jaegeuk and Bradley, >> > >> > >> > >> > On Mon, Aug 07, 2017 at 09:01:50PM -0400, Bradley Bolen wrote: >> > >> > > I am getting a very similar error on v4.11 with an arm64 board. >> > >> > > >> > >> > > I, too, also see page->mem_cgroup checked to make sure that it is >> > >> > > not >> > >> > > NULL and then several instructions later it is NULL. It does appear >> > >> > > that someone is changing that member without taking the lock. In my >> > >> > > setup, I see >> > >> > > >> > >> > > crash> bt >> > >> > > PID: 72 TASK: e1f48640 CPU: 0 COMMAND: "mmcqd/1" >> > >> > > #0 [] (__crash_kexec) from [] >> > >> > > #1 [] (panic) from [] >> > >> > > #2 [] (svcerr_panic) from [] >> > >> > > #3 [] (_SvcErr_) from [] >> > >> > > #4 [] (die) from [] >> > >> > > #5 [] (__do_kernel_fault) from [] >> > >> > > #6 [] (do_page_fault) from [] >> > >> > > #7 [] (do_DataAbort) from [] >> > >> > > pc : []lr : []psr: a193 >> > >> > > sp : c1a19cc8 ip : fp : c1a19d04 >> > >> > > r10: 0006ae29 r9 : r8 : dfbf1800 >> > >> > > r7 : dfbf1800 r6 : 0001 r5 : f3c1107c r4 : e2fb6424 >> > >> > > r3 : r2 : 00040228 r1 : 221e3000 r0 : a113 >> > >> > > Flags: NzCv IRQs off FIQs on Mode SVC_32 ISA ARM >> > >> > > #8 [] (__dabt_svc) from [] >> > >> > > #9 [] (test_clear_page_writeback) from [] >> > >> > > #10 [] (end_page_writeback) from [] >> > >> > > #11 [] (end_swap_bio_write) from [] >> > >> > > #12 [] (bio_endio) from [] >> > >> > > #13 [] (dec_pending) from [] >> > >> > > #14 [] (clone_endio) from [] >> > >> > > #15 [] (bio_endio) from [] >> > >> > > #16 [] (crypt_dec_pending [dm_crypt]) from [] >> > >> > > #17 [] (crypt_endio [dm_crypt]) from [] >> > >> > > #18 [] (bio_endio) from [] >> > >> > > #19 [] (blk_update_request) from [] >> > >> > > #20 [] (blk_update_bidi_request) from [] >> > >> > > #21 [] (blk_end_bidi_request) from [] >> > >> > > #22 [] (blk_end_request) from [] >> > >> > > #23 [] (mmc_blk_issue_rw_rq) from [] >> > >> > > #24 [] (mmc_blk_issue_rq) from [] >> > >> > > #25 [] (mmc_queue_thread) from [] >> > >> > > #26 [] (kthread) from [] >> > >> > > crash> sym c0112540 >> > >> > > c0112540 (T) test_clear_page_writeback+512 >> > >> > > /kernel-source/include/linux/memcontrol.h: 518 >> > >> > > >> > >> > > crash> bt 35 >> > >> > > PID: 35 TASK: e1d45dc0 CPU: 1 COMMAND: "kswapd0" >> > >> > > #0 [] (__schedule) from [] >> > >> > > #1 [] (schedule) from [] >> > >> > > #2 [] (schedule_timeout) from [] >> > >> > > #3 [] (io_schedule_timeout) from [] >> > >> > > #4 [] (mempool_alloc) from [] >> > >> > > #5 [] (bio_alloc_bioset) from [] >> > >> > > #6 [] (get_swap_bio) from [] >> > >> > > #7 [] (__swap_writepage) from [] >> > >> > > #8 [] (swap_writepage) from [] >> > >> > > #9 [] (shmem_writepage) from [] >> > >> > > #10 [] (shrink_page_list) from [] >> > >> > > #11 [] (shrink_inactive_list) from [] >> > >> > > #12 [] (shrink_node_memcg) from [] >> > >> > > #13 [] (shrink_node) from [] >> > >> > > #14 [] (kswapd) from [] >> > >> > > #15 [] (kthread) from [] >> > >> > > >> > >> > > It appears that uncharge_list() in mm/memcontrol.c is not taking the >> > >> > > page lock when it sets mem_cgroup to NULL. I am not familiar with >> > >> > > the >> > >> > > mm code so I do not know if this is on purpose or not. There is a >> > >> > > comment in uncharge_list that makes me believe that the crashing >> > >> > > code >> > >> > > should not have been running: >> > >> > > /* >> > >> > > * Nobody should be changing or seriously looking at >> > >> > > * page->mem_cgroup at this point, we have fully >> > >> > > * exclusive access to the page. >> > >> > > */ >> > >> > > However, I am new to looking at this area of the kernel so I am not >> > >> > > sure. >> > >> > >> > >> > The lock is for pages that are actively being used, whereas the free >> > >> > path requires the page refcount to be 0; nobody else should be having >> > >> > access to the page at that time. >> > >> >> > >> Given various trials for a while, using __mod_memcg_state() instead of >> > >> mod_memcg_state() ssems somehow blowing the panic away. It might be >> > >> caused >> > >> by kernel preemption? >> > > >> > > That's puzzling. Is that reliably the case? Because on x86-64, >> > > __this_cpu_add and this_cpu_add should result in the same code: >> > > >> > > #define raw_cpu_add_8(pcp, val) percpu_add_op((pcp), val) >> > > #define this_cpu_add_8(pcp, val)percpu_add_op((pcp), val) >> > > >> > > which boils down to single instructions
Re: kernel panic on null pointer on page->mem_cgroup
On 08/08, Johannes Weiner wrote: > On Tue, Aug 08, 2017 at 03:13:42PM -0400, Brad Bolen wrote: > > On Tue, Aug 8, 2017 at 1:37 PM, Johannes Weiner wrote: > > > On Tue, Aug 08, 2017 at 09:56:01AM -0700, Jaegeuk Kim wrote: > > >> On 08/08, Johannes Weiner wrote: > > >> > Hi Jaegeuk and Bradley, > > >> > > > >> > On Mon, Aug 07, 2017 at 09:01:50PM -0400, Bradley Bolen wrote: > > >> > > I am getting a very similar error on v4.11 with an arm64 board. > > >> > > > > >> > > I, too, also see page->mem_cgroup checked to make sure that it is not > > >> > > NULL and then several instructions later it is NULL. It does appear > > >> > > that someone is changing that member without taking the lock. In my > > >> > > setup, I see > > >> > > > > >> > > crash> bt > > >> > > PID: 72 TASK: e1f48640 CPU: 0 COMMAND: "mmcqd/1" > > >> > > #0 [] (__crash_kexec) from [] > > >> > > #1 [] (panic) from [] > > >> > > #2 [] (svcerr_panic) from [] > > >> > > #3 [] (_SvcErr_) from [] > > >> > > #4 [] (die) from [] > > >> > > #5 [] (__do_kernel_fault) from [] > > >> > > #6 [] (do_page_fault) from [] > > >> > > #7 [] (do_DataAbort) from [] > > >> > > pc : []lr : []psr: a193 > > >> > > sp : c1a19cc8 ip : fp : c1a19d04 > > >> > > r10: 0006ae29 r9 : r8 : dfbf1800 > > >> > > r7 : dfbf1800 r6 : 0001 r5 : f3c1107c r4 : e2fb6424 > > >> > > r3 : r2 : 00040228 r1 : 221e3000 r0 : a113 > > >> > > Flags: NzCv IRQs off FIQs on Mode SVC_32 ISA ARM > > >> > > #8 [] (__dabt_svc) from [] > > >> > > #9 [] (test_clear_page_writeback) from [] > > >> > > #10 [] (end_page_writeback) from [] > > >> > > #11 [] (end_swap_bio_write) from [] > > >> > > #12 [] (bio_endio) from [] > > >> > > #13 [] (dec_pending) from [] > > >> > > #14 [] (clone_endio) from [] > > >> > > #15 [] (bio_endio) from [] > > >> > > #16 [] (crypt_dec_pending [dm_crypt]) from [] > > >> > > #17 [] (crypt_endio [dm_crypt]) from [] > > >> > > #18 [] (bio_endio) from [] > > >> > > #19 [] (blk_update_request) from [] > > >> > > #20 [] (blk_update_bidi_request) from [] > > >> > > #21 [] (blk_end_bidi_request) from [] > > >> > > #22 [] (blk_end_request) from [] > > >> > > #23 [] (mmc_blk_issue_rw_rq) from [] > > >> > > #24 [] (mmc_blk_issue_rq) from [] > > >> > > #25 [] (mmc_queue_thread) from [] > > >> > > #26 [] (kthread) from [] > > >> > > crash> sym c0112540 > > >> > > c0112540 (T) test_clear_page_writeback+512 > > >> > > /kernel-source/include/linux/memcontrol.h: 518 > > >> > > > > >> > > crash> bt 35 > > >> > > PID: 35 TASK: e1d45dc0 CPU: 1 COMMAND: "kswapd0" > > >> > > #0 [] (__schedule) from [] > > >> > > #1 [] (schedule) from [] > > >> > > #2 [] (schedule_timeout) from [] > > >> > > #3 [] (io_schedule_timeout) from [] > > >> > > #4 [] (mempool_alloc) from [] > > >> > > #5 [] (bio_alloc_bioset) from [] > > >> > > #6 [] (get_swap_bio) from [] > > >> > > #7 [] (__swap_writepage) from [] > > >> > > #8 [] (swap_writepage) from [] > > >> > > #9 [] (shmem_writepage) from [] > > >> > > #10 [] (shrink_page_list) from [] > > >> > > #11 [] (shrink_inactive_list) from [] > > >> > > #12 [] (shrink_node_memcg) from [] > > >> > > #13 [] (shrink_node) from [] > > >> > > #14 [] (kswapd) from [] > > >> > > #15 [] (kthread) from [] > > >> > > > > >> > > It appears that uncharge_list() in mm/memcontrol.c is not taking the > > >> > > page lock when it sets mem_cgroup to NULL. I am not familiar with > > >> > > the > > >> > > mm code so I do not know if this is on purpose or not. There is a > > >> > > comment in uncharge_list that makes me believe that the crashing code > > >> > > should not have been running: > > >> > > /* > > >> > > * Nobody should be changing or seriously looking at > > >> > > * page->mem_cgroup at this point, we have fully > > >> > > * exclusive access to the page. > > >> > > */ > > >> > > However, I am new to looking at this area of the kernel so I am not > > >> > > sure. > > >> > > > >> > The lock is for pages that are actively being used, whereas the free > > >> > path requires the page refcount to be 0; nobody else should be having > > >> > access to the page at that time. > > >> > > >> Given various trials for a while, using __mod_memcg_state() instead of > > >> mod_memcg_state() ssems somehow blowing the panic away. It might be > > >> caused > > >> by kernel preemption? > > > > > > That's puzzling. Is that reliably the case? Because on x86-64, > > > __this_cpu_add and this_cpu_add should result in the same code: > > > > > > #define raw_cpu_add_8(pcp, val) percpu_add_op((pcp), val) > > > #define this_cpu_add_8(pcp, val)percpu_add_op((pcp), val) > > > > > > which boils down to single instructions - incq, decq, addq - and so > > > never needs explicit disabling of scheduler or interrupt preemption. > > > > > >> > > I was able to create a reproducible scenario by using a udelay to > > >> > > increase the time between the if (page->me
Re: kernel panic on null pointer on page->mem_cgroup
On Tue, Aug 08, 2017 at 03:13:42PM -0400, Brad Bolen wrote: > On Tue, Aug 8, 2017 at 1:37 PM, Johannes Weiner wrote: > > On Tue, Aug 08, 2017 at 09:56:01AM -0700, Jaegeuk Kim wrote: > >> On 08/08, Johannes Weiner wrote: > >> > Hi Jaegeuk and Bradley, > >> > > >> > On Mon, Aug 07, 2017 at 09:01:50PM -0400, Bradley Bolen wrote: > >> > > I am getting a very similar error on v4.11 with an arm64 board. > >> > > > >> > > I, too, also see page->mem_cgroup checked to make sure that it is not > >> > > NULL and then several instructions later it is NULL. It does appear > >> > > that someone is changing that member without taking the lock. In my > >> > > setup, I see > >> > > > >> > > crash> bt > >> > > PID: 72 TASK: e1f48640 CPU: 0 COMMAND: "mmcqd/1" > >> > > #0 [] (__crash_kexec) from [] > >> > > #1 [] (panic) from [] > >> > > #2 [] (svcerr_panic) from [] > >> > > #3 [] (_SvcErr_) from [] > >> > > #4 [] (die) from [] > >> > > #5 [] (__do_kernel_fault) from [] > >> > > #6 [] (do_page_fault) from [] > >> > > #7 [] (do_DataAbort) from [] > >> > > pc : []lr : []psr: a193 > >> > > sp : c1a19cc8 ip : fp : c1a19d04 > >> > > r10: 0006ae29 r9 : r8 : dfbf1800 > >> > > r7 : dfbf1800 r6 : 0001 r5 : f3c1107c r4 : e2fb6424 > >> > > r3 : r2 : 00040228 r1 : 221e3000 r0 : a113 > >> > > Flags: NzCv IRQs off FIQs on Mode SVC_32 ISA ARM > >> > > #8 [] (__dabt_svc) from [] > >> > > #9 [] (test_clear_page_writeback) from [] > >> > > #10 [] (end_page_writeback) from [] > >> > > #11 [] (end_swap_bio_write) from [] > >> > > #12 [] (bio_endio) from [] > >> > > #13 [] (dec_pending) from [] > >> > > #14 [] (clone_endio) from [] > >> > > #15 [] (bio_endio) from [] > >> > > #16 [] (crypt_dec_pending [dm_crypt]) from [] > >> > > #17 [] (crypt_endio [dm_crypt]) from [] > >> > > #18 [] (bio_endio) from [] > >> > > #19 [] (blk_update_request) from [] > >> > > #20 [] (blk_update_bidi_request) from [] > >> > > #21 [] (blk_end_bidi_request) from [] > >> > > #22 [] (blk_end_request) from [] > >> > > #23 [] (mmc_blk_issue_rw_rq) from [] > >> > > #24 [] (mmc_blk_issue_rq) from [] > >> > > #25 [] (mmc_queue_thread) from [] > >> > > #26 [] (kthread) from [] > >> > > crash> sym c0112540 > >> > > c0112540 (T) test_clear_page_writeback+512 > >> > > /kernel-source/include/linux/memcontrol.h: 518 > >> > > > >> > > crash> bt 35 > >> > > PID: 35 TASK: e1d45dc0 CPU: 1 COMMAND: "kswapd0" > >> > > #0 [] (__schedule) from [] > >> > > #1 [] (schedule) from [] > >> > > #2 [] (schedule_timeout) from [] > >> > > #3 [] (io_schedule_timeout) from [] > >> > > #4 [] (mempool_alloc) from [] > >> > > #5 [] (bio_alloc_bioset) from [] > >> > > #6 [] (get_swap_bio) from [] > >> > > #7 [] (__swap_writepage) from [] > >> > > #8 [] (swap_writepage) from [] > >> > > #9 [] (shmem_writepage) from [] > >> > > #10 [] (shrink_page_list) from [] > >> > > #11 [] (shrink_inactive_list) from [] > >> > > #12 [] (shrink_node_memcg) from [] > >> > > #13 [] (shrink_node) from [] > >> > > #14 [] (kswapd) from [] > >> > > #15 [] (kthread) from [] > >> > > > >> > > It appears that uncharge_list() in mm/memcontrol.c is not taking the > >> > > page lock when it sets mem_cgroup to NULL. I am not familiar with the > >> > > mm code so I do not know if this is on purpose or not. There is a > >> > > comment in uncharge_list that makes me believe that the crashing code > >> > > should not have been running: > >> > > /* > >> > > * Nobody should be changing or seriously looking at > >> > > * page->mem_cgroup at this point, we have fully > >> > > * exclusive access to the page. > >> > > */ > >> > > However, I am new to looking at this area of the kernel so I am not > >> > > sure. > >> > > >> > The lock is for pages that are actively being used, whereas the free > >> > path requires the page refcount to be 0; nobody else should be having > >> > access to the page at that time. > >> > >> Given various trials for a while, using __mod_memcg_state() instead of > >> mod_memcg_state() ssems somehow blowing the panic away. It might be caused > >> by kernel preemption? > > > > That's puzzling. Is that reliably the case? Because on x86-64, > > __this_cpu_add and this_cpu_add should result in the same code: > > > > #define raw_cpu_add_8(pcp, val) percpu_add_op((pcp), val) > > #define this_cpu_add_8(pcp, val)percpu_add_op((pcp), val) > > > > which boils down to single instructions - incq, decq, addq - and so > > never needs explicit disabling of scheduler or interrupt preemption. > > > >> > > I was able to create a reproducible scenario by using a udelay to > >> > > increase the time between the if (page->mem_cgroup) check and the later > >> > > dereference of it to increase the race window. I then mounted an empty > >> > > ext4 partition and ran the following no more than twice before it > >> > > crashed. > >> > > dd if=/dev/zero of=/tmp/ext4disk/test bs=1M coun
Re: kernel panic on null pointer on page->mem_cgroup
On Tue, Aug 8, 2017 at 1:37 PM, Johannes Weiner wrote: > On Tue, Aug 08, 2017 at 09:56:01AM -0700, Jaegeuk Kim wrote: >> On 08/08, Johannes Weiner wrote: >> > Hi Jaegeuk and Bradley, >> > >> > On Mon, Aug 07, 2017 at 09:01:50PM -0400, Bradley Bolen wrote: >> > > I am getting a very similar error on v4.11 with an arm64 board. >> > > >> > > I, too, also see page->mem_cgroup checked to make sure that it is not >> > > NULL and then several instructions later it is NULL. It does appear >> > > that someone is changing that member without taking the lock. In my >> > > setup, I see >> > > >> > > crash> bt >> > > PID: 72 TASK: e1f48640 CPU: 0 COMMAND: "mmcqd/1" >> > > #0 [] (__crash_kexec) from [] >> > > #1 [] (panic) from [] >> > > #2 [] (svcerr_panic) from [] >> > > #3 [] (_SvcErr_) from [] >> > > #4 [] (die) from [] >> > > #5 [] (__do_kernel_fault) from [] >> > > #6 [] (do_page_fault) from [] >> > > #7 [] (do_DataAbort) from [] >> > > pc : []lr : []psr: a193 >> > > sp : c1a19cc8 ip : fp : c1a19d04 >> > > r10: 0006ae29 r9 : r8 : dfbf1800 >> > > r7 : dfbf1800 r6 : 0001 r5 : f3c1107c r4 : e2fb6424 >> > > r3 : r2 : 00040228 r1 : 221e3000 r0 : a113 >> > > Flags: NzCv IRQs off FIQs on Mode SVC_32 ISA ARM >> > > #8 [] (__dabt_svc) from [] >> > > #9 [] (test_clear_page_writeback) from [] >> > > #10 [] (end_page_writeback) from [] >> > > #11 [] (end_swap_bio_write) from [] >> > > #12 [] (bio_endio) from [] >> > > #13 [] (dec_pending) from [] >> > > #14 [] (clone_endio) from [] >> > > #15 [] (bio_endio) from [] >> > > #16 [] (crypt_dec_pending [dm_crypt]) from [] >> > > #17 [] (crypt_endio [dm_crypt]) from [] >> > > #18 [] (bio_endio) from [] >> > > #19 [] (blk_update_request) from [] >> > > #20 [] (blk_update_bidi_request) from [] >> > > #21 [] (blk_end_bidi_request) from [] >> > > #22 [] (blk_end_request) from [] >> > > #23 [] (mmc_blk_issue_rw_rq) from [] >> > > #24 [] (mmc_blk_issue_rq) from [] >> > > #25 [] (mmc_queue_thread) from [] >> > > #26 [] (kthread) from [] >> > > crash> sym c0112540 >> > > c0112540 (T) test_clear_page_writeback+512 >> > > /kernel-source/include/linux/memcontrol.h: 518 >> > > >> > > crash> bt 35 >> > > PID: 35 TASK: e1d45dc0 CPU: 1 COMMAND: "kswapd0" >> > > #0 [] (__schedule) from [] >> > > #1 [] (schedule) from [] >> > > #2 [] (schedule_timeout) from [] >> > > #3 [] (io_schedule_timeout) from [] >> > > #4 [] (mempool_alloc) from [] >> > > #5 [] (bio_alloc_bioset) from [] >> > > #6 [] (get_swap_bio) from [] >> > > #7 [] (__swap_writepage) from [] >> > > #8 [] (swap_writepage) from [] >> > > #9 [] (shmem_writepage) from [] >> > > #10 [] (shrink_page_list) from [] >> > > #11 [] (shrink_inactive_list) from [] >> > > #12 [] (shrink_node_memcg) from [] >> > > #13 [] (shrink_node) from [] >> > > #14 [] (kswapd) from [] >> > > #15 [] (kthread) from [] >> > > >> > > It appears that uncharge_list() in mm/memcontrol.c is not taking the >> > > page lock when it sets mem_cgroup to NULL. I am not familiar with the >> > > mm code so I do not know if this is on purpose or not. There is a >> > > comment in uncharge_list that makes me believe that the crashing code >> > > should not have been running: >> > > /* >> > > * Nobody should be changing or seriously looking at >> > > * page->mem_cgroup at this point, we have fully >> > > * exclusive access to the page. >> > > */ >> > > However, I am new to looking at this area of the kernel so I am not >> > > sure. >> > >> > The lock is for pages that are actively being used, whereas the free >> > path requires the page refcount to be 0; nobody else should be having >> > access to the page at that time. >> >> Given various trials for a while, using __mod_memcg_state() instead of >> mod_memcg_state() ssems somehow blowing the panic away. It might be caused >> by kernel preemption? > > That's puzzling. Is that reliably the case? Because on x86-64, > __this_cpu_add and this_cpu_add should result in the same code: > > #define raw_cpu_add_8(pcp, val) percpu_add_op((pcp), val) > #define this_cpu_add_8(pcp, val)percpu_add_op((pcp), val) > > which boils down to single instructions - incq, decq, addq - and so > never needs explicit disabling of scheduler or interrupt preemption. > >> > > I was able to create a reproducible scenario by using a udelay to >> > > increase the time between the if (page->mem_cgroup) check and the later >> > > dereference of it to increase the race window. I then mounted an empty >> > > ext4 partition and ran the following no more than twice before it >> > > crashed. >> > > dd if=/dev/zero of=/tmp/ext4disk/test bs=1M count=100 >> > >> > Thanks, that's useful. I'm going to try to reproduce this also. >> > >> > There is a >> > >> > VM_BUG_ON_PAGE(!PageHWPoison(page) && page_count(page), page); >> > >> > inside uncharge_list() that verifies that there shouldn't in fact be >> > any pages en
Re: kernel panic on null pointer on page->mem_cgroup
On Tue, Aug 08, 2017 at 09:56:01AM -0700, Jaegeuk Kim wrote: > On 08/08, Johannes Weiner wrote: > > Hi Jaegeuk and Bradley, > > > > On Mon, Aug 07, 2017 at 09:01:50PM -0400, Bradley Bolen wrote: > > > I am getting a very similar error on v4.11 with an arm64 board. > > > > > > I, too, also see page->mem_cgroup checked to make sure that it is not > > > NULL and then several instructions later it is NULL. It does appear > > > that someone is changing that member without taking the lock. In my > > > setup, I see > > > > > > crash> bt > > > PID: 72 TASK: e1f48640 CPU: 0 COMMAND: "mmcqd/1" > > > #0 [] (__crash_kexec) from [] > > > #1 [] (panic) from [] > > > #2 [] (svcerr_panic) from [] > > > #3 [] (_SvcErr_) from [] > > > #4 [] (die) from [] > > > #5 [] (__do_kernel_fault) from [] > > > #6 [] (do_page_fault) from [] > > > #7 [] (do_DataAbort) from [] > > > pc : []lr : []psr: a193 > > > sp : c1a19cc8 ip : fp : c1a19d04 > > > r10: 0006ae29 r9 : r8 : dfbf1800 > > > r7 : dfbf1800 r6 : 0001 r5 : f3c1107c r4 : e2fb6424 > > > r3 : r2 : 00040228 r1 : 221e3000 r0 : a113 > > > Flags: NzCv IRQs off FIQs on Mode SVC_32 ISA ARM > > > #8 [] (__dabt_svc) from [] > > > #9 [] (test_clear_page_writeback) from [] > > > #10 [] (end_page_writeback) from [] > > > #11 [] (end_swap_bio_write) from [] > > > #12 [] (bio_endio) from [] > > > #13 [] (dec_pending) from [] > > > #14 [] (clone_endio) from [] > > > #15 [] (bio_endio) from [] > > > #16 [] (crypt_dec_pending [dm_crypt]) from [] > > > #17 [] (crypt_endio [dm_crypt]) from [] > > > #18 [] (bio_endio) from [] > > > #19 [] (blk_update_request) from [] > > > #20 [] (blk_update_bidi_request) from [] > > > #21 [] (blk_end_bidi_request) from [] > > > #22 [] (blk_end_request) from [] > > > #23 [] (mmc_blk_issue_rw_rq) from [] > > > #24 [] (mmc_blk_issue_rq) from [] > > > #25 [] (mmc_queue_thread) from [] > > > #26 [] (kthread) from [] > > > crash> sym c0112540 > > > c0112540 (T) test_clear_page_writeback+512 > > > /kernel-source/include/linux/memcontrol.h: 518 > > > > > > crash> bt 35 > > > PID: 35 TASK: e1d45dc0 CPU: 1 COMMAND: "kswapd0" > > > #0 [] (__schedule) from [] > > > #1 [] (schedule) from [] > > > #2 [] (schedule_timeout) from [] > > > #3 [] (io_schedule_timeout) from [] > > > #4 [] (mempool_alloc) from [] > > > #5 [] (bio_alloc_bioset) from [] > > > #6 [] (get_swap_bio) from [] > > > #7 [] (__swap_writepage) from [] > > > #8 [] (swap_writepage) from [] > > > #9 [] (shmem_writepage) from [] > > > #10 [] (shrink_page_list) from [] > > > #11 [] (shrink_inactive_list) from [] > > > #12 [] (shrink_node_memcg) from [] > > > #13 [] (shrink_node) from [] > > > #14 [] (kswapd) from [] > > > #15 [] (kthread) from [] > > > > > > It appears that uncharge_list() in mm/memcontrol.c is not taking the > > > page lock when it sets mem_cgroup to NULL. I am not familiar with the > > > mm code so I do not know if this is on purpose or not. There is a > > > comment in uncharge_list that makes me believe that the crashing code > > > should not have been running: > > > /* > > > * Nobody should be changing or seriously looking at > > > * page->mem_cgroup at this point, we have fully > > > * exclusive access to the page. > > > */ > > > However, I am new to looking at this area of the kernel so I am not > > > sure. > > > > The lock is for pages that are actively being used, whereas the free > > path requires the page refcount to be 0; nobody else should be having > > access to the page at that time. > > Given various trials for a while, using __mod_memcg_state() instead of > mod_memcg_state() ssems somehow blowing the panic away. It might be caused > by kernel preemption? That's puzzling. Is that reliably the case? Because on x86-64, __this_cpu_add and this_cpu_add should result in the same code: #define raw_cpu_add_8(pcp, val) percpu_add_op((pcp), val) #define this_cpu_add_8(pcp, val)percpu_add_op((pcp), val) which boils down to single instructions - incq, decq, addq - and so never needs explicit disabling of scheduler or interrupt preemption. > > > I was able to create a reproducible scenario by using a udelay to > > > increase the time between the if (page->mem_cgroup) check and the later > > > dereference of it to increase the race window. I then mounted an empty > > > ext4 partition and ran the following no more than twice before it > > > crashed. > > > dd if=/dev/zero of=/tmp/ext4disk/test bs=1M count=100 > > > > Thanks, that's useful. I'm going to try to reproduce this also. > > > > There is a > > > > VM_BUG_ON_PAGE(!PageHWPoison(page) && page_count(page), page); > > > > inside uncharge_list() that verifies that there shouldn't in fact be > > any pages ending writeback when they get into that function. Can you > > build your kernel with CONFIG_DEBUG_VM to enable that test? > > I'll test this as well. ;) Thanks. I'm t
Re: kernel panic on null pointer on page->mem_cgroup
On 08/08, Johannes Weiner wrote: > Hi Jaegeuk and Bradley, > > On Mon, Aug 07, 2017 at 09:01:50PM -0400, Bradley Bolen wrote: > > I am getting a very similar error on v4.11 with an arm64 board. > > > > I, too, also see page->mem_cgroup checked to make sure that it is not > > NULL and then several instructions later it is NULL. It does appear > > that someone is changing that member without taking the lock. In my > > setup, I see > > > > crash> bt > > PID: 72 TASK: e1f48640 CPU: 0 COMMAND: "mmcqd/1" > > #0 [] (__crash_kexec) from [] > > #1 [] (panic) from [] > > #2 [] (svcerr_panic) from [] > > #3 [] (_SvcErr_) from [] > > #4 [] (die) from [] > > #5 [] (__do_kernel_fault) from [] > > #6 [] (do_page_fault) from [] > > #7 [] (do_DataAbort) from [] > > pc : []lr : []psr: a193 > > sp : c1a19cc8 ip : fp : c1a19d04 > > r10: 0006ae29 r9 : r8 : dfbf1800 > > r7 : dfbf1800 r6 : 0001 r5 : f3c1107c r4 : e2fb6424 > > r3 : r2 : 00040228 r1 : 221e3000 r0 : a113 > > Flags: NzCv IRQs off FIQs on Mode SVC_32 ISA ARM > > #8 [] (__dabt_svc) from [] > > #9 [] (test_clear_page_writeback) from [] > > #10 [] (end_page_writeback) from [] > > #11 [] (end_swap_bio_write) from [] > > #12 [] (bio_endio) from [] > > #13 [] (dec_pending) from [] > > #14 [] (clone_endio) from [] > > #15 [] (bio_endio) from [] > > #16 [] (crypt_dec_pending [dm_crypt]) from [] > > #17 [] (crypt_endio [dm_crypt]) from [] > > #18 [] (bio_endio) from [] > > #19 [] (blk_update_request) from [] > > #20 [] (blk_update_bidi_request) from [] > > #21 [] (blk_end_bidi_request) from [] > > #22 [] (blk_end_request) from [] > > #23 [] (mmc_blk_issue_rw_rq) from [] > > #24 [] (mmc_blk_issue_rq) from [] > > #25 [] (mmc_queue_thread) from [] > > #26 [] (kthread) from [] > > crash> sym c0112540 > > c0112540 (T) test_clear_page_writeback+512 > > /kernel-source/include/linux/memcontrol.h: 518 > > > > crash> bt 35 > > PID: 35 TASK: e1d45dc0 CPU: 1 COMMAND: "kswapd0" > > #0 [] (__schedule) from [] > > #1 [] (schedule) from [] > > #2 [] (schedule_timeout) from [] > > #3 [] (io_schedule_timeout) from [] > > #4 [] (mempool_alloc) from [] > > #5 [] (bio_alloc_bioset) from [] > > #6 [] (get_swap_bio) from [] > > #7 [] (__swap_writepage) from [] > > #8 [] (swap_writepage) from [] > > #9 [] (shmem_writepage) from [] > > #10 [] (shrink_page_list) from [] > > #11 [] (shrink_inactive_list) from [] > > #12 [] (shrink_node_memcg) from [] > > #13 [] (shrink_node) from [] > > #14 [] (kswapd) from [] > > #15 [] (kthread) from [] > > > > It appears that uncharge_list() in mm/memcontrol.c is not taking the > > page lock when it sets mem_cgroup to NULL. I am not familiar with the > > mm code so I do not know if this is on purpose or not. There is a > > comment in uncharge_list that makes me believe that the crashing code > > should not have been running: > > /* > > * Nobody should be changing or seriously looking at > > * page->mem_cgroup at this point, we have fully > > * exclusive access to the page. > > */ > > However, I am new to looking at this area of the kernel so I am not > > sure. > > The lock is for pages that are actively being used, whereas the free > path requires the page refcount to be 0; nobody else should be having > access to the page at that time. Given various trials for a while, using __mod_memcg_state() instead of mod_memcg_state() ssems somehow blowing the panic away. It might be caused by kernel preemption? > > > I was able to create a reproducible scenario by using a udelay to > > increase the time between the if (page->mem_cgroup) check and the later > > dereference of it to increase the race window. I then mounted an empty > > ext4 partition and ran the following no more than twice before it > > crashed. > > dd if=/dev/zero of=/tmp/ext4disk/test bs=1M count=100 > > Thanks, that's useful. I'm going to try to reproduce this also. > > There is a > > VM_BUG_ON_PAGE(!PageHWPoison(page) && page_count(page), page); > > inside uncharge_list() that verifies that there shouldn't in fact be > any pages ending writeback when they get into that function. Can you > build your kernel with CONFIG_DEBUG_VM to enable that test? I'll test this as well. ;) Thanks,
Re: kernel panic on null pointer on page->mem_cgroup
Hi Jaegeuk and Bradley, On Mon, Aug 07, 2017 at 09:01:50PM -0400, Bradley Bolen wrote: > I am getting a very similar error on v4.11 with an arm64 board. > > I, too, also see page->mem_cgroup checked to make sure that it is not > NULL and then several instructions later it is NULL. It does appear > that someone is changing that member without taking the lock. In my > setup, I see > > crash> bt > PID: 72 TASK: e1f48640 CPU: 0 COMMAND: "mmcqd/1" > #0 [] (__crash_kexec) from [] > #1 [] (panic) from [] > #2 [] (svcerr_panic) from [] > #3 [] (_SvcErr_) from [] > #4 [] (die) from [] > #5 [] (__do_kernel_fault) from [] > #6 [] (do_page_fault) from [] > #7 [] (do_DataAbort) from [] > pc : []lr : []psr: a193 > sp : c1a19cc8 ip : fp : c1a19d04 > r10: 0006ae29 r9 : r8 : dfbf1800 > r7 : dfbf1800 r6 : 0001 r5 : f3c1107c r4 : e2fb6424 > r3 : r2 : 00040228 r1 : 221e3000 r0 : a113 > Flags: NzCv IRQs off FIQs on Mode SVC_32 ISA ARM > #8 [] (__dabt_svc) from [] > #9 [] (test_clear_page_writeback) from [] > #10 [] (end_page_writeback) from [] > #11 [] (end_swap_bio_write) from [] > #12 [] (bio_endio) from [] > #13 [] (dec_pending) from [] > #14 [] (clone_endio) from [] > #15 [] (bio_endio) from [] > #16 [] (crypt_dec_pending [dm_crypt]) from [] > #17 [] (crypt_endio [dm_crypt]) from [] > #18 [] (bio_endio) from [] > #19 [] (blk_update_request) from [] > #20 [] (blk_update_bidi_request) from [] > #21 [] (blk_end_bidi_request) from [] > #22 [] (blk_end_request) from [] > #23 [] (mmc_blk_issue_rw_rq) from [] > #24 [] (mmc_blk_issue_rq) from [] > #25 [] (mmc_queue_thread) from [] > #26 [] (kthread) from [] > crash> sym c0112540 > c0112540 (T) test_clear_page_writeback+512 > /kernel-source/include/linux/memcontrol.h: 518 > > crash> bt 35 > PID: 35 TASK: e1d45dc0 CPU: 1 COMMAND: "kswapd0" > #0 [] (__schedule) from [] > #1 [] (schedule) from [] > #2 [] (schedule_timeout) from [] > #3 [] (io_schedule_timeout) from [] > #4 [] (mempool_alloc) from [] > #5 [] (bio_alloc_bioset) from [] > #6 [] (get_swap_bio) from [] > #7 [] (__swap_writepage) from [] > #8 [] (swap_writepage) from [] > #9 [] (shmem_writepage) from [] > #10 [] (shrink_page_list) from [] > #11 [] (shrink_inactive_list) from [] > #12 [] (shrink_node_memcg) from [] > #13 [] (shrink_node) from [] > #14 [] (kswapd) from [] > #15 [] (kthread) from [] > > It appears that uncharge_list() in mm/memcontrol.c is not taking the > page lock when it sets mem_cgroup to NULL. I am not familiar with the > mm code so I do not know if this is on purpose or not. There is a > comment in uncharge_list that makes me believe that the crashing code > should not have been running: > /* > * Nobody should be changing or seriously looking at > * page->mem_cgroup at this point, we have fully > * exclusive access to the page. > */ > However, I am new to looking at this area of the kernel so I am not > sure. The lock is for pages that are actively being used, whereas the free path requires the page refcount to be 0; nobody else should be having access to the page at that time. > I was able to create a reproducible scenario by using a udelay to > increase the time between the if (page->mem_cgroup) check and the later > dereference of it to increase the race window. I then mounted an empty > ext4 partition and ran the following no more than twice before it > crashed. > dd if=/dev/zero of=/tmp/ext4disk/test bs=1M count=100 Thanks, that's useful. I'm going to try to reproduce this also. There is a VM_BUG_ON_PAGE(!PageHWPoison(page) && page_count(page), page); inside uncharge_list() that verifies that there shouldn't in fact be any pages ending writeback when they get into that function. Can you build your kernel with CONFIG_DEBUG_VM to enable that test? Thanks
kernel panic on null pointer on page->mem_cgroup
Hi Johannes, Can I ask your help about the below panic which is annoying me recently. I'm currently testing xfstests with 4.13-rc2, and have hit the below panic very randomly. [ 3722.366490] BUG: unable to handle kernel NULL pointer dereference at 03b0 [ 3722.378815] IP: test_clear_page_writeback+0x12e/0x2c0 [ 3722.384931] PGD 3fb77067 [ 3722.384932] P4D 3fb77067 [ 3722.389222] PUD 1302f067 [ 3722.392676] PMD 0 [ 3722.407447] [ 3722.416459] Oops: [#1] SMP [ 3722.424191] Modules linked in: quota_v2 quota_tree dm_snapshot dm_bufio dm_flakey f2fs(O) ppdev joydev input_leds serio_raw snd_intel8x0 snd_ac97_codec ac97_bus snd_pcm snd_timer snd parport_pc soundcore mac_hid i2c_piix4 parport ib_iser rdma_cm iw_cm ib_cm ib_core configfs iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi autofs4 btrfs raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx xor raid6_pq libcrc32c raid1 raid0 multipath linear hid_generic usbhid hid crct10dif_pclmul crc32_pclmul ghash_clmulni_intel pcbc aesni_intel aes_x86_64 crypto_simd glue_helper cryptd ahci psmouse libahci e1000 pata_acpi video [last unloaded: scsi_debug] [ 3722.494822] CPU: 2 PID: 0 Comm: swapper/2 Tainted: G O 4.13.0-rc2+ #7 [ 3722.509659] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 3722.523018] task: 8e3abe32bc00 task.stack: ab1e801f [ 3722.534108] RIP: 0010:test_clear_page_writeback+0x12e/0x2c0 [ 3722.547281] RSP: 0018:8e3abfd03d78 EFLAGS: 00010046 [ 3722.561761] RAX: RBX: db59c03f8900 RCX: ffe8 [ 3722.595343] RDX: RSI: 0010 RDI: 8e3abffeb000 [ 3722.615108] RBP: 8e3abfd03da8 R08: 00020059 R09: fffc [ 3722.674717] R10: R11: 00020048 R12: 8e3a8c39f668 [ 3722.691916] R13: 0001 R14: 8e3a8c39f680 R15: [ 3722.736393] FS: () GS:8e3abfd0() knlGS: [ 3722.797553] CS: 0010 DS: ES: CR0: 80050033 [ 3722.852623] CR2: 03b0 CR3: 2c5e1000 CR4: 000406e0 [ 3722.896451] DR0: DR1: DR2: [ 3722.950847] DR3: DR6: fffe0ff0 DR7: 0400 [ 3722.965578] Call Trace: [ 3722.971710] [ 3722.976306] end_page_writeback+0x47/0x70 [ 3722.983252] f2fs_write_end_io+0x76/0x180 [f2fs] [ 3723.012721] bio_endio+0x9f/0x120 [ 3723.035764] blk_update_request+0xa8/0x2f0 [ 3723.064621] scsi_end_request+0x39/0x1d0 [ 3723.086994] scsi_io_completion+0x211/0x690 [ 3723.116553] scsi_finish_command+0xd9/0x120 [ 3723.143690] scsi_softirq_done+0x127/0x150 [ 3723.170070] __blk_mq_complete_request_remote+0x13/0x20 [ 3723.199780] flush_smp_call_function_queue+0x56/0x110 [ 3723.233148] generic_smp_call_function_single_interrupt+0x13/0x30 [ 3723.255267] smp_call_function_single_interrupt+0x27/0x40 [ 3723.285327] call_function_single_interrupt+0x89/0x90 [ 3723.309718] RIP: 0010:native_safe_halt+0x6/0x10 (gdb) l *(test_clear_page_writeback+0x12e) 0x811bae3e is in test_clear_page_writeback (./include/linux/memcontrol.h:619). 614 mod_node_page_state(page_pgdat(page), idx, val); 615 if (mem_cgroup_disabled() || !page->mem_cgroup) 616 return; 617 mod_memcg_state(page->mem_cgroup, idx, val); 618 pn = page->mem_cgroup->nodeinfo[page_to_nid(page)]; 619 this_cpu_add(pn->lruvec_stat->count[idx], val); 620 } 621 622 unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, 623 gfp_t gfp_mask, So first, without your below patch, I've confirmed that there is no problem. commit 00f3ca2c2d6635d ("mm: memcontrol: per-lruvec stats infrastructure") Second, what I've figured out so far is page->mem_cgroup is already checked above, but after that line, it just becomes NULL. Is it possible somebody can take it away without locking the page? Could you please shed a light on this? Or, is there a patch to fix this already? Thanks,