Skip to content

Commit 42f5fe1

Browse files
q2venPaolo Abeni
authored andcommitted
phonet: Convert phonet_device_list.lock to spinlock_t.
addr_doit() calls phonet_address_add() or phonet_address_del() for RTM_NEWADDR or RTM_DELADDR, respectively. Both functions only touch phonet_device_list(dev_net(dev)), which is currently protected by RTNL and its dedicated mutex, phonet_device_list.lock. We will convert addr_doit() to RCU and cannot use mutex inside RCU. Let's convert the mutex to spinlock_t. Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 68ed5c3 commit 42f5fe1

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

include/net/phonet/pn_dev.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212

1313
#include <linux/list.h>
1414
#include <linux/mutex.h>
15+
#include <linux/spinlock.h>
1516

1617
struct net;
1718

1819
struct phonet_device_list {
1920
struct list_head list;
20-
struct mutex lock;
21+
spinlock_t lock;
2122
};
2223

2324
struct phonet_device_list *phonet_device_list(struct net *net);

net/phonet/pn_dev.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static struct phonet_device *__phonet_device_alloc(struct net_device *dev)
5454
pnd->netdev = dev;
5555
bitmap_zero(pnd->addrs, 64);
5656

57-
BUG_ON(!mutex_is_locked(&pndevs->lock));
57+
lockdep_assert_held(&pndevs->lock);
5858
list_add_rcu(&pnd->list, &pndevs->list);
5959
return pnd;
6060
}
@@ -64,7 +64,8 @@ static struct phonet_device *__phonet_get(struct net_device *dev)
6464
struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev));
6565
struct phonet_device *pnd;
6666

67-
BUG_ON(!mutex_is_locked(&pndevs->lock));
67+
lockdep_assert_held(&pndevs->lock);
68+
6869
list_for_each_entry(pnd, &pndevs->list, list) {
6970
if (pnd->netdev == dev)
7071
return pnd;
@@ -91,11 +92,13 @@ static void phonet_device_destroy(struct net_device *dev)
9192

9293
ASSERT_RTNL();
9394

94-
mutex_lock(&pndevs->lock);
95+
spin_lock(&pndevs->lock);
96+
9597
pnd = __phonet_get(dev);
9698
if (pnd)
9799
list_del_rcu(&pnd->list);
98-
mutex_unlock(&pndevs->lock);
100+
101+
spin_unlock(&pndevs->lock);
99102

100103
if (pnd) {
101104
struct net *net = dev_net(dev);
@@ -136,7 +139,8 @@ int phonet_address_add(struct net_device *dev, u8 addr)
136139
struct phonet_device *pnd;
137140
int err = 0;
138141

139-
mutex_lock(&pndevs->lock);
142+
spin_lock(&pndevs->lock);
143+
140144
/* Find or create Phonet-specific device data */
141145
pnd = __phonet_get(dev);
142146
if (pnd == NULL)
@@ -145,7 +149,9 @@ int phonet_address_add(struct net_device *dev, u8 addr)
145149
err = -ENOMEM;
146150
else if (test_and_set_bit(addr >> 2, pnd->addrs))
147151
err = -EEXIST;
148-
mutex_unlock(&pndevs->lock);
152+
153+
spin_unlock(&pndevs->lock);
154+
149155
return err;
150156
}
151157

@@ -155,7 +161,8 @@ int phonet_address_del(struct net_device *dev, u8 addr)
155161
struct phonet_device *pnd;
156162
int err = 0;
157163

158-
mutex_lock(&pndevs->lock);
164+
spin_lock(&pndevs->lock);
165+
159166
pnd = __phonet_get(dev);
160167
if (!pnd || !test_and_clear_bit(addr >> 2, pnd->addrs)) {
161168
err = -EADDRNOTAVAIL;
@@ -164,7 +171,8 @@ int phonet_address_del(struct net_device *dev, u8 addr)
164171
list_del_rcu(&pnd->list);
165172
else
166173
pnd = NULL;
167-
mutex_unlock(&pndevs->lock);
174+
175+
spin_unlock(&pndevs->lock);
168176

169177
if (pnd)
170178
kfree_rcu(pnd, rcu);
@@ -313,7 +321,7 @@ static int __net_init phonet_init_net(struct net *net)
313321
return -ENOMEM;
314322

315323
INIT_LIST_HEAD(&pnn->pndevs.list);
316-
mutex_init(&pnn->pndevs.lock);
324+
spin_lock_init(&pnn->pndevs.lock);
317325
mutex_init(&pnn->routes.lock);
318326
return 0;
319327
}

0 commit comments

Comments
 (0)