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()
6 From: Eric Dumazet <edumazet@google.com>
9 [ Upstream commit 9a0b1e8ba4061778897b544afc898de2163382f7 ]
11 After Jesper commit back in linux-3.18, we trigger a lockdep
12 splat in proc_create_data() while allocating memory from
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()
18 1) pktgen_thread_lock to protect the outer loop (iterating threads)
19 2) t->if_lock to protect the inner loop (iterating devices)
21 Note that before Jesper patch, pktgen_change_name() was lacking proper
22 protection, but lockdep was not able to detect the problem.
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>
32 net/core/pktgen.c | 17 ++++++++++-------
33 1 file changed, 10 insertions(+), 7 deletions(-)
35 --- a/net/core/pktgen.c
36 +++ b/net/core/pktgen.c
38 #define T_REMDEV (1<<3) /* Remove one dev */
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));
46 /* Used to help with determining the pkts on receive */
47 #define PKTGEN_MAGIC 0xbe9be955
48 @@ -418,7 +418,7 @@ struct pktgen_net {
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
59 struct pktgen_thread *t;
61 + mutex_lock(&pktgen_thread_lock);
63 list_for_each_entry(t, &pn->pktgen_threads, th_list) {
64 struct pktgen_dev *pkt_dev;
67 - list_for_each_entry_rcu(pkt_dev, &t->if_list, list) {
69 + list_for_each_entry(pkt_dev, &t->if_list, list) {
70 if (pkt_dev->odev != dev)
73 @@ -1971,8 +1973,9 @@ static void pktgen_change_name(const str
80 + mutex_unlock(&pktgen_thread_lock);
83 static int pktgen_device_event(struct notifier_block *unused,
84 @@ -3656,7 +3659,7 @@ static int __net_init pktgen_create_thre
88 - spin_lock_init(&t->if_lock);
89 + mutex_init(&t->if_lock);
92 INIT_LIST_HEAD(&t->if_list);