aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2016-10-15 11:50:49 -0400
committerDavid S. Miller <davem@davemloft.net>2016-10-17 10:52:59 -0400
commit9a0b1e8ba4061778897b544afc898de2163382f7 (patch)
tree910a94c53d211ba3a5a17f6dc39fad9649becd65 /net/core
parenta04a480d4392ea6efd117be2de564117b2a009c0 (diff)
net: pktgen: remove rcu locking in pktgen_change_name()
After Jesper commit back in linux-3.18, we trigger a lockdep splat in proc_create_data() while allocating memory from pktgen_change_name(). This patch converts t->if_lock to a mutex, since it is now only used from control path, and adds proper locking to pktgen_change_name() 1) pktgen_thread_lock to protect the outer loop (iterating threads) 2) t->if_lock to protect the inner loop (iterating devices) Note that before Jesper patch, pktgen_change_name() was lacking proper protection, but lockdep was not able to detect the problem. Fixes: 8788370a1d4b ("pktgen: RCU-ify "if_list" to remove lock in next_to_run()") Reported-by: John Sperbeck <jsperbeck@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/pktgen.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 5219a9e2127a..306b8f0e03c1 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -216,8 +216,8 @@
216#define M_QUEUE_XMIT 2 /* Inject packet into qdisc */ 216#define M_QUEUE_XMIT 2 /* Inject packet into qdisc */
217 217
218/* If lock -- protects updating of if_list */ 218/* If lock -- protects updating of if_list */
219#define if_lock(t) spin_lock(&(t->if_lock)); 219#define if_lock(t) mutex_lock(&(t->if_lock));
220#define if_unlock(t) spin_unlock(&(t->if_lock)); 220#define if_unlock(t) mutex_unlock(&(t->if_lock));
221 221
222/* Used to help with determining the pkts on receive */ 222/* Used to help with determining the pkts on receive */
223#define PKTGEN_MAGIC 0xbe9be955 223#define PKTGEN_MAGIC 0xbe9be955
@@ -423,7 +423,7 @@ struct pktgen_net {
423}; 423};
424 424
425struct pktgen_thread { 425struct pktgen_thread {
426 spinlock_t if_lock; /* for list of devices */ 426 struct mutex if_lock; /* for list of devices */
427 struct list_head if_list; /* All device here */ 427 struct list_head if_list; /* All device here */
428 struct list_head th_list; 428 struct list_head th_list;
429 struct task_struct *tsk; 429 struct task_struct *tsk;
@@ -2010,11 +2010,13 @@ static void pktgen_change_name(const struct pktgen_net *pn, struct net_device *d
2010{ 2010{
2011 struct pktgen_thread *t; 2011 struct pktgen_thread *t;
2012 2012
2013 mutex_lock(&pktgen_thread_lock);
2014
2013 list_for_each_entry(t, &pn->pktgen_threads, th_list) { 2015 list_for_each_entry(t, &pn->pktgen_threads, th_list) {
2014 struct pktgen_dev *pkt_dev; 2016 struct pktgen_dev *pkt_dev;
2015 2017
2016 rcu_read_lock(); 2018 if_lock(t);
2017 list_for_each_entry_rcu(pkt_dev, &t->if_list, list) { 2019 list_for_each_entry(pkt_dev, &t->if_list, list) {
2018 if (pkt_dev->odev != dev) 2020 if (pkt_dev->odev != dev)
2019 continue; 2021 continue;
2020 2022
@@ -2029,8 +2031,9 @@ static void pktgen_change_name(const struct pktgen_net *pn, struct net_device *d
2029 dev->name); 2031 dev->name);
2030 break; 2032 break;
2031 } 2033 }
2032 rcu_read_unlock(); 2034 if_unlock(t);
2033 } 2035 }
2036 mutex_unlock(&pktgen_thread_lock);
2034} 2037}
2035 2038
2036static int pktgen_device_event(struct notifier_block *unused, 2039static int pktgen_device_event(struct notifier_block *unused,
@@ -3762,7 +3765,7 @@ static int __net_init pktgen_create_thread(int cpu, struct pktgen_net *pn)
3762 return -ENOMEM; 3765 return -ENOMEM;
3763 } 3766 }
3764 3767
3765 spin_lock_init(&t->if_lock); 3768 mutex_init(&t->if_lock);
3766 t->cpu = cpu; 3769 t->cpu = cpu;
3767 3770
3768 INIT_LIST_HEAD(&t->if_list); 3771 INIT_LIST_HEAD(&t->if_list);