]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
4a70a03eec9c7cc558210c6be323288bae611908
[thirdparty/kernel/stable-queue.git] /
1 From a264df74df38855096393447f1b8f386069a94b9 Mon Sep 17 00:00:00 2001
2 From: Roman Gushchin <guro@fb.com>
3 Date: Wed, 4 Dec 2019 16:49:46 -0800
4 Subject: mm: memcg/slab: wait for !root kmem_cache refcnt killing on root kmem_cache destruction
5
6 From: Roman Gushchin <guro@fb.com>
7
8 commit a264df74df38855096393447f1b8f386069a94b9 upstream.
9
10 Christian reported a warning like the following obtained during running
11 some KVM-related tests on s390:
12
13 WARNING: CPU: 8 PID: 208 at lib/percpu-refcount.c:108 percpu_ref_exit+0x50/0x58
14 Modules linked in: kvm(-) xt_CHECKSUM xt_MASQUERADE bonding xt_tcpudp ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 ipt_REJECT nf_reject_ipv4 xt_conntrack ip6table_na>
15 CPU: 8 PID: 208 Comm: kworker/8:1 Not tainted 5.2.0+ #66
16 Hardware name: IBM 2964 NC9 712 (LPAR)
17 Workqueue: events sysfs_slab_remove_workfn
18 Krnl PSW : 0704e00180000000 0000001529746850 (percpu_ref_exit+0x50/0x58)
19 R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 RI:0 EA:3
20 Krnl GPRS: 00000000ffff8808 0000001529746740 000003f4e30e8e18 0036008100000000
21 0000001f00000000 0035008100000000 0000001fb3573ab8 0000000000000000
22 0000001fbdb6de00 0000000000000000 0000001529f01328 0000001fb3573b00
23 0000001fbb27e000 0000001fbdb69300 000003e009263d00 000003e009263cd0
24 Krnl Code: 0000001529746842: f0a0000407fe srp 4(11,%r0),2046,0
25 0000001529746848: 47000700 bc 0,1792
26 #000000152974684c: a7f40001 brc 15,152974684e
27 >0000001529746850: a7f4fff2 brc 15,1529746834
28 0000001529746854: 0707 bcr 0,%r7
29 0000001529746856: 0707 bcr 0,%r7
30 0000001529746858: eb8ff0580024 stmg %r8,%r15,88(%r15)
31 000000152974685e: a738ffff lhi %r3,-1
32 Call Trace:
33 ([<000003e009263d00>] 0x3e009263d00)
34 [<00000015293252ea>] slab_kmem_cache_release+0x3a/0x70
35 [<0000001529b04882>] kobject_put+0xaa/0xe8
36 [<000000152918cf28>] process_one_work+0x1e8/0x428
37 [<000000152918d1b0>] worker_thread+0x48/0x460
38 [<00000015291942c6>] kthread+0x126/0x160
39 [<0000001529b22344>] ret_from_fork+0x28/0x30
40 [<0000001529b2234c>] kernel_thread_starter+0x0/0x10
41 Last Breaking-Event-Address:
42 [<000000152974684c>] percpu_ref_exit+0x4c/0x58
43 ---[ end trace b035e7da5788eb09 ]---
44
45 The problem occurs because kmem_cache_destroy() is called immediately
46 after deleting of a memcg, so it races with the memcg kmem_cache
47 deactivation.
48
49 flush_memcg_workqueue() at the beginning of kmem_cache_destroy() is
50 supposed to guarantee that all deactivation processes are finished, but
51 failed to do so. It waits for an rcu grace period, after which all
52 children kmem_caches should be deactivated. During the deactivation
53 percpu_ref_kill() is called for non root kmem_cache refcounters, but it
54 requires yet another rcu grace period to finish the transition to the
55 atomic (dead) state.
56
57 So in a rare case when not all children kmem_caches are destroyed at the
58 moment when the root kmem_cache is about to be gone, we need to wait
59 another rcu grace period before destroying the root kmem_cache.
60
61 This issue can be triggered only with dynamically created kmem_caches
62 which are used with memcg accounting. In this case per-memcg child
63 kmem_caches are created. They are deactivated from the cgroup removing
64 path. If the destruction of the root kmem_cache is racing with the
65 removal of the cgroup (both are quite complicated multi-stage
66 processes), the described issue can occur. The only known way to
67 trigger it in the real life, is to unload some kernel module which
68 creates a dedicated kmem_cache, used from different memory cgroups with
69 GFP_ACCOUNT flag. If the unloading happens immediately after calling
70 rmdir on the corresponding cgroup, there is some chance to trigger the
71 issue.
72
73 Link: http://lkml.kernel.org/r/20191129025011.3076017-1-guro@fb.com
74 Fixes: f0a3a24b532d ("mm: memcg/slab: rework non-root kmem_cache lifecycle management")
75 Signed-off-by: Roman Gushchin <guro@fb.com>
76 Reported-by: Christian Borntraeger <borntraeger@de.ibm.com>
77 Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
78 Reviewed-by: Shakeel Butt <shakeelb@google.com>
79 Acked-by: Michal Hocko <mhocko@suse.com>
80 Cc: Johannes Weiner <hannes@cmpxchg.org>
81 Cc: <stable@vger.kernel.org>
82 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
83 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
84 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
85
86 ---
87 mm/slab_common.c | 12 ++++++++++++
88 1 file changed, 12 insertions(+)
89
90 --- a/mm/slab_common.c
91 +++ b/mm/slab_common.c
92 @@ -904,6 +904,18 @@ static void flush_memcg_workqueue(struct
93 * previous workitems on workqueue are processed.
94 */
95 flush_workqueue(memcg_kmem_cache_wq);
96 +
97 + /*
98 + * If we're racing with children kmem_cache deactivation, it might
99 + * take another rcu grace period to complete their destruction.
100 + * At this moment the corresponding percpu_ref_kill() call should be
101 + * done, but it might take another rcu grace period to complete
102 + * switching to the atomic mode.
103 + * Please, note that we check without grabbing the slab_mutex. It's safe
104 + * because at this moment the children list can't grow.
105 + */
106 + if (!list_empty(&s->memcg_params.children))
107 + rcu_barrier();
108 }
109 #else
110 static inline int shutdown_memcg_caches(struct kmem_cache *s)