* [PATCH] mm: memcontrol: handle div0 crash race condition in memory.low
@ 2020-06-15 14:06 Johannes Weiner
[not found] ` <20200615140658.601684-1-hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Johannes Weiner @ 2020-06-15 14:06 UTC (permalink / raw)
To: Andrew Morton
Cc: Tejun Heo, Michal Hocko, Roman Gushchin, Chris Down,
linux-mm-Bw31MaZKKs3YtjvyW6yDsg, cgroups-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, kernel-team-b10kYP2dOMg
Tejun reports seeing rare div0 crashes in memory.low stress testing:
[37228.504582] RIP: 0010:mem_cgroup_calculate_protection+0xed/0x150
[37228.505059] Code: 0f 46 d1 4c 39 d8 72 57 f6 05 16 d6 42 01 40 74 1f 4c 39 d8 76 1a 4c 39 d1 76 15 4c 29 d1 4c 29 d8 4d 29 d9 31 d2 48 0f af c1 <49> f7 f1 49 01 c2 4c 89 96 38 01 00 00 5d c3 48 0f af c7 31 d2 49
[37228.506254] RSP: 0018:ffffa14e01d6fcd0 EFLAGS: 00010246
[37228.506769] RAX: 000000000243e384 RBX: 0000000000000000 RCX: 0000000000008f4b
[37228.507319] RDX: 0000000000000000 RSI: ffff8b89bee84000 RDI: 0000000000000000
[37228.507869] RBP: ffffa14e01d6fcd0 R08: ffff8b89ca7d40f8 R09: 0000000000000000
[37228.508376] R10: 0000000000000000 R11: 00000000006422f7 R12: 0000000000000000
[37228.508881] R13: ffff8b89d9617000 R14: ffff8b89bee84000 R15: ffffa14e01d6fdb8
[37228.509397] FS: 0000000000000000(0000) GS:ffff8b8a1f1c0000(0000) knlGS:0000000000000000
[37228.509917] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[37228.510442] CR2: 00007f93b1fc175b CR3: 000000016100a000 CR4: 0000000000340ea0
[37228.511076] Call Trace:
[37228.511561] shrink_node+0x1e5/0x6c0
[37228.512044] balance_pgdat+0x32d/0x5f0
[37228.512521] kswapd+0x1d7/0x3d0
[37228.513346] ? wait_woken+0x80/0x80
[37228.514170] kthread+0x11c/0x160
[37228.514983] ? balance_pgdat+0x5f0/0x5f0
[37228.515797] ? kthread_park+0x90/0x90
[37228.516593] ret_from_fork+0x1f/0x30
This happens when parent_usage == siblings_protected. We check that
usage is bigger than protected, which should imply parent_usage being
bigger than siblings_protected. However, we don't read (or even
update) these values atomically, and they can be out of sync as the
memory state changes under us. A bit of fluctuation around the target
protection isn't a big deal, but we need to handle the div0 case.
Check the parent state explicitly to make sure we have a reasonable
positive value for the divisor.
Fixes: 8a931f801340 ("mm: memcontrol: recursive memory.low protection")
Reported-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Signed-off-by: Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
---
mm/memcontrol.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 0b38b6ad547d..5de0a9035b5f 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6360,11 +6360,16 @@ static unsigned long effective_protection(unsigned long usage,
* We're using unprotected memory for the weight so that if
* some cgroups DO claim explicit protection, we don't protect
* the same bytes twice.
+ *
+ * Check both usage and parent_usage against the respective
+ * protected values. One should imply the other, but they
+ * aren't read atomically - make sure the division is sane.
*/
if (!(cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_RECURSIVE_PROT))
return ep;
-
- if (parent_effective > siblings_protected && usage > protected) {
+ if (parent_effective > siblings_protected &&
+ parent_usage > siblings_protected &&
+ usage > protected) {
unsigned long unclaimed;
unclaimed = parent_effective - siblings_protected;
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread[parent not found: <20200615140658.601684-1-hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>]
* Re: [PATCH] mm: memcontrol: handle div0 crash race condition in memory.low [not found] ` <20200615140658.601684-1-hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org> @ 2020-06-15 15:01 ` Michal Hocko 2020-06-15 15:09 ` Chris Down 1 sibling, 0 replies; 3+ messages in thread From: Michal Hocko @ 2020-06-15 15:01 UTC (permalink / raw) To: Johannes Weiner Cc: Andrew Morton, Tejun Heo, Roman Gushchin, Chris Down, linux-mm-Bw31MaZKKs3YtjvyW6yDsg, cgroups-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, kernel-team-b10kYP2dOMg On Mon 15-06-20 10:06:58, Johannes Weiner wrote: > Tejun reports seeing rare div0 crashes in memory.low stress testing: > > [37228.504582] RIP: 0010:mem_cgroup_calculate_protection+0xed/0x150 > [37228.505059] Code: 0f 46 d1 4c 39 d8 72 57 f6 05 16 d6 42 01 40 74 1f 4c 39 d8 76 1a 4c 39 d1 76 15 4c 29 d1 4c 29 d8 4d 29 d9 31 d2 48 0f af c1 <49> f7 f1 49 01 c2 4c 89 96 38 01 00 00 5d c3 48 0f af c7 31 d2 49 > [37228.506254] RSP: 0018:ffffa14e01d6fcd0 EFLAGS: 00010246 > [37228.506769] RAX: 000000000243e384 RBX: 0000000000000000 RCX: 0000000000008f4b > [37228.507319] RDX: 0000000000000000 RSI: ffff8b89bee84000 RDI: 0000000000000000 > [37228.507869] RBP: ffffa14e01d6fcd0 R08: ffff8b89ca7d40f8 R09: 0000000000000000 > [37228.508376] R10: 0000000000000000 R11: 00000000006422f7 R12: 0000000000000000 > [37228.508881] R13: ffff8b89d9617000 R14: ffff8b89bee84000 R15: ffffa14e01d6fdb8 > [37228.509397] FS: 0000000000000000(0000) GS:ffff8b8a1f1c0000(0000) knlGS:0000000000000000 > [37228.509917] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > [37228.510442] CR2: 00007f93b1fc175b CR3: 000000016100a000 CR4: 0000000000340ea0 > [37228.511076] Call Trace: > [37228.511561] shrink_node+0x1e5/0x6c0 > [37228.512044] balance_pgdat+0x32d/0x5f0 > [37228.512521] kswapd+0x1d7/0x3d0 > [37228.513346] ? wait_woken+0x80/0x80 > [37228.514170] kthread+0x11c/0x160 > [37228.514983] ? balance_pgdat+0x5f0/0x5f0 > [37228.515797] ? kthread_park+0x90/0x90 > [37228.516593] ret_from_fork+0x1f/0x30 > > This happens when parent_usage == siblings_protected. We check that > usage is bigger than protected, which should imply parent_usage being > bigger than siblings_protected. However, we don't read (or even > update) these values atomically, and they can be out of sync as the > memory state changes under us. A bit of fluctuation around the target > protection isn't a big deal, but we need to handle the div0 case. > > Check the parent state explicitly to make sure we have a reasonable > positive value for the divisor. > > Fixes: 8a931f801340 ("mm: memcontrol: recursive memory.low protection") > Reported-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org> > Signed-off-by: Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org> Acked-by: Michal Hocko <mhocko-IBi9RG/b67k@public.gmane.org> > --- > mm/memcontrol.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 0b38b6ad547d..5de0a9035b5f 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -6360,11 +6360,16 @@ static unsigned long effective_protection(unsigned long usage, > * We're using unprotected memory for the weight so that if > * some cgroups DO claim explicit protection, we don't protect > * the same bytes twice. > + * > + * Check both usage and parent_usage against the respective > + * protected values. One should imply the other, but they > + * aren't read atomically - make sure the division is sane. > */ > if (!(cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_RECURSIVE_PROT)) > return ep; > - > - if (parent_effective > siblings_protected && usage > protected) { > + if (parent_effective > siblings_protected && > + parent_usage > siblings_protected && > + usage > protected) { > unsigned long unclaimed; > > unclaimed = parent_effective - siblings_protected; > -- > 2.26.2 -- Michal Hocko SUSE Labs ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: memcontrol: handle div0 crash race condition in memory.low [not found] ` <20200615140658.601684-1-hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org> 2020-06-15 15:01 ` Michal Hocko @ 2020-06-15 15:09 ` Chris Down 1 sibling, 0 replies; 3+ messages in thread From: Chris Down @ 2020-06-15 15:09 UTC (permalink / raw) To: Johannes Weiner Cc: Andrew Morton, Tejun Heo, Michal Hocko, Roman Gushchin, linux-mm-Bw31MaZKKs3YtjvyW6yDsg, cgroups-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, kernel-team-b10kYP2dOMg Johannes Weiner writes: >Tejun reports seeing rare div0 crashes in memory.low stress testing: > >[37228.504582] RIP: 0010:mem_cgroup_calculate_protection+0xed/0x150 >[37228.505059] Code: 0f 46 d1 4c 39 d8 72 57 f6 05 16 d6 42 01 40 74 1f 4c 39 d8 76 1a 4c 39 d1 76 15 4c 29 d1 4c 29 d8 4d 29 d9 31 d2 48 0f af c1 <49> f7 f1 49 01 c2 4c 89 96 38 01 00 00 5d c3 48 0f af c7 31 d2 49 >[37228.506254] RSP: 0018:ffffa14e01d6fcd0 EFLAGS: 00010246 >[37228.506769] RAX: 000000000243e384 RBX: 0000000000000000 RCX: 0000000000008f4b >[37228.507319] RDX: 0000000000000000 RSI: ffff8b89bee84000 RDI: 0000000000000000 >[37228.507869] RBP: ffffa14e01d6fcd0 R08: ffff8b89ca7d40f8 R09: 0000000000000000 >[37228.508376] R10: 0000000000000000 R11: 00000000006422f7 R12: 0000000000000000 >[37228.508881] R13: ffff8b89d9617000 R14: ffff8b89bee84000 R15: ffffa14e01d6fdb8 >[37228.509397] FS: 0000000000000000(0000) GS:ffff8b8a1f1c0000(0000) knlGS:0000000000000000 >[37228.509917] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 >[37228.510442] CR2: 00007f93b1fc175b CR3: 000000016100a000 CR4: 0000000000340ea0 >[37228.511076] Call Trace: >[37228.511561] shrink_node+0x1e5/0x6c0 >[37228.512044] balance_pgdat+0x32d/0x5f0 >[37228.512521] kswapd+0x1d7/0x3d0 >[37228.513346] ? wait_woken+0x80/0x80 >[37228.514170] kthread+0x11c/0x160 >[37228.514983] ? balance_pgdat+0x5f0/0x5f0 >[37228.515797] ? kthread_park+0x90/0x90 >[37228.516593] ret_from_fork+0x1f/0x30 > >This happens when parent_usage == siblings_protected. We check that >usage is bigger than protected, which should imply parent_usage being >bigger than siblings_protected. However, we don't read (or even >update) these values atomically, and they can be out of sync as the >memory state changes under us. A bit of fluctuation around the target >protection isn't a big deal, but we need to handle the div0 case. > >Check the parent state explicitly to make sure we have a reasonable >positive value for the divisor. > >Fixes: 8a931f801340 ("mm: memcontrol: recursive memory.low protection") >Reported-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Acked-by: Chris Down <chris-6Bi1550iOqEnzZ6mRAm98g@public.gmane.org> ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-15 15:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-15 14:06 [PATCH] mm: memcontrol: handle div0 crash race condition in memory.low Johannes Weiner
[not found] ` <20200615140658.601684-1-hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
2020-06-15 15:01 ` Michal Hocko
2020-06-15 15:09 ` Chris Down
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox