]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/blob - rt-patches/0250-memcontrol-Prevent-scheduling-while-atomic-in-cgroup.patch
rt_patches: required rebase due to printk change
[hercules2020/nv-tegra/linux-4.4.git] / rt-patches / 0250-memcontrol-Prevent-scheduling-while-atomic-in-cgroup.patch
1 From 4f1f6257ddad8645baa9b2c00b7920137e4d7f6b Mon Sep 17 00:00:00 2001
2 From: Mike Galbraith <umgwanakikbuti@gmail.com>
3 Date: Sat, 21 Jun 2014 10:09:48 +0200
4 Subject: [PATCH 250/366] memcontrol: Prevent scheduling while atomic in cgroup
5  code
6
7 mm, memcg: make refill_stock() use get_cpu_light()
8
9 Nikita reported the following memcg scheduling while atomic bug:
10
11 Call Trace:
12 [e22d5a90] [c0007ea8] show_stack+0x4c/0x168 (unreliable)
13 [e22d5ad0] [c0618c04] __schedule_bug+0x94/0xb0
14 [e22d5ae0] [c060b9ec] __schedule+0x530/0x550
15 [e22d5bf0] [c060bacc] schedule+0x30/0xbc
16 [e22d5c00] [c060ca24] rt_spin_lock_slowlock+0x180/0x27c
17 [e22d5c70] [c00b39dc] res_counter_uncharge_until+0x40/0xc4
18 [e22d5ca0] [c013ca88] drain_stock.isra.20+0x54/0x98
19 [e22d5cc0] [c01402ac] __mem_cgroup_try_charge+0x2e8/0xbac
20 [e22d5d70] [c01410d4] mem_cgroup_charge_common+0x3c/0x70
21 [e22d5d90] [c0117284] __do_fault+0x38c/0x510
22 [e22d5df0] [c011a5f4] handle_pte_fault+0x98/0x858
23 [e22d5e50] [c060ed08] do_page_fault+0x42c/0x6fc
24 [e22d5f40] [c000f5b4] handle_page_fault+0xc/0x80
25
26 What happens:
27
28    refill_stock()
29       get_cpu_var()
30       drain_stock()
31          res_counter_uncharge()
32             res_counter_uncharge_until()
33                spin_lock() <== boom
34
35 Fix it by replacing get/put_cpu_var() with get/put_cpu_light().
36
37 Reported-by: Nikita Yushchenko <nyushchenko@dev.rtsoft.ru>
38 Signed-off-by: Mike Galbraith <umgwanakikbuti@gmail.com>
39 Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
40 ---
41  mm/memcontrol.c | 7 +++++--
42  1 file changed, 5 insertions(+), 2 deletions(-)
43
44 diff --git a/mm/memcontrol.c b/mm/memcontrol.c
45 index 8e5dc27..82cc68b 100644
46 --- a/mm/memcontrol.c
47 +++ b/mm/memcontrol.c
48 @@ -1925,14 +1925,17 @@ static void drain_local_stock(struct work_struct *dummy)
49   */
50  static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
51  {
52 -       struct memcg_stock_pcp *stock = &get_cpu_var(memcg_stock);
53 +       struct memcg_stock_pcp *stock;
54 +       int cpu = get_cpu_light();
55 +
56 +       stock = &per_cpu(memcg_stock, cpu);
57  
58         if (stock->cached != memcg) { /* reset if necessary */
59                 drain_stock(stock);
60                 stock->cached = memcg;
61         }
62         stock->nr_pages += nr_pages;
63 -       put_cpu_var(memcg_stock);
64 +       put_cpu_light();
65  }
66  
67  /*
68 -- 
69 1.9.1
70