]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.18.49/net-pktgen-remove-rcu-locking-in-pktgen_change_name.patch
Linux 4.19.45
[thirdparty/kernel/stable-queue.git] / releases / 3.18.49 / net-pktgen-remove-rcu-locking-in-pktgen_change_name.patch
1 From foo@baz Mon Feb 20 16:34:36 CET 2017
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Sat, 15 Oct 2016 17:50:49 +0200
4 Subject: [PATCH 087/760] net: pktgen: remove rcu locking in pktgen_change_name()
5
6 From: Eric Dumazet <edumazet@google.com>
7
8
9 [ Upstream commit 9a0b1e8ba4061778897b544afc898de2163382f7 ]
10
11 After Jesper commit back in linux-3.18, we trigger a lockdep
12 splat in proc_create_data() while allocating memory from
13 pktgen_change_name().
14
15 This patch converts t->if_lock to a mutex, since it is now only
16 used from control path, and adds proper locking to pktgen_change_name()
17
18 1) pktgen_thread_lock to protect the outer loop (iterating threads)
19 2) t->if_lock to protect the inner loop (iterating devices)
20
21 Note that before Jesper patch, pktgen_change_name() was lacking proper
22 protection, but lockdep was not able to detect the problem.
23
24 Fixes: 8788370a1d4b ("pktgen: RCU-ify "if_list" to remove lock in next_to_run()")
25 Reported-by: John Sperbeck <jsperbeck@google.com>
26 Signed-off-by: Eric Dumazet <edumazet@google.com>
27 Cc: Jesper Dangaard Brouer <brouer@redhat.com>
28 Signed-off-by: David S. Miller <davem@davemloft.net>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31 ---
32 net/core/pktgen.c | 17 ++++++++++-------
33 1 file changed, 10 insertions(+), 7 deletions(-)
34
35 --- a/net/core/pktgen.c
36 +++ b/net/core/pktgen.c
37 @@ -211,8 +211,8 @@
38 #define T_REMDEV (1<<3) /* Remove one dev */
39
40 /* If lock -- protects updating of if_list */
41 -#define if_lock(t) spin_lock(&(t->if_lock));
42 -#define if_unlock(t) spin_unlock(&(t->if_lock));
43 +#define if_lock(t) mutex_lock(&(t->if_lock));
44 +#define if_unlock(t) mutex_unlock(&(t->if_lock));
45
46 /* Used to help with determining the pkts on receive */
47 #define PKTGEN_MAGIC 0xbe9be955
48 @@ -418,7 +418,7 @@ struct pktgen_net {
49 };
50
51 struct pktgen_thread {
52 - spinlock_t if_lock; /* for list of devices */
53 + struct mutex if_lock; /* for list of devices */
54 struct list_head if_list; /* All device here */
55 struct list_head th_list;
56 struct task_struct *tsk;
57 @@ -1952,11 +1952,13 @@ static void pktgen_change_name(const str
58 {
59 struct pktgen_thread *t;
60
61 + mutex_lock(&pktgen_thread_lock);
62 +
63 list_for_each_entry(t, &pn->pktgen_threads, th_list) {
64 struct pktgen_dev *pkt_dev;
65
66 - rcu_read_lock();
67 - list_for_each_entry_rcu(pkt_dev, &t->if_list, list) {
68 + if_lock(t);
69 + list_for_each_entry(pkt_dev, &t->if_list, list) {
70 if (pkt_dev->odev != dev)
71 continue;
72
73 @@ -1971,8 +1973,9 @@ static void pktgen_change_name(const str
74 dev->name);
75 break;
76 }
77 - rcu_read_unlock();
78 + if_unlock(t);
79 }
80 + mutex_unlock(&pktgen_thread_lock);
81 }
82
83 static int pktgen_device_event(struct notifier_block *unused,
84 @@ -3656,7 +3659,7 @@ static int __net_init pktgen_create_thre
85 return -ENOMEM;
86 }
87
88 - spin_lock_init(&t->if_lock);
89 + mutex_init(&t->if_lock);
90 t->cpu = cpu;
91
92 INIT_LIST_HEAD(&t->if_list);