Skip to content

Commit 3deec3b

Browse files
q2venPaolo Abeni
authored andcommitted
phonet: Convert phonet_routes.lock to spinlock_t.
route_doit() calls phonet_route_add() or phonet_route_del() for RTM_NEWROUTE or RTM_DELROUTE, respectively. Both functions only touch phonet_pernet(dev_net(dev))->routes, which is currently protected by RTNL and its dedicated mutex, phonet_routes.lock. We will convert route_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 de51ad0 commit 3deec3b

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

include/net/phonet/pn_dev.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#define PN_DEV_H
1212

1313
#include <linux/list.h>
14-
#include <linux/mutex.h>
1514
#include <linux/spinlock.h>
1615

1716
struct net;

net/phonet/pn_dev.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <net/phonet/pn_dev.h>
2323

2424
struct phonet_routes {
25-
struct mutex lock;
25+
spinlock_t lock;
2626
struct net_device __rcu *table[64];
2727
};
2828

@@ -273,13 +273,15 @@ static void phonet_route_autodel(struct net_device *dev)
273273

274274
/* Remove left-over Phonet routes */
275275
bitmap_zero(deleted, 64);
276-
mutex_lock(&pnn->routes.lock);
277-
for (i = 0; i < 64; i++)
276+
277+
spin_lock(&pnn->routes.lock);
278+
for (i = 0; i < 64; i++) {
278279
if (rcu_access_pointer(pnn->routes.table[i]) == dev) {
279280
RCU_INIT_POINTER(pnn->routes.table[i], NULL);
280281
set_bit(i, deleted);
281282
}
282-
mutex_unlock(&pnn->routes.lock);
283+
}
284+
spin_unlock(&pnn->routes.lock);
283285

284286
if (bitmap_empty(deleted, 64))
285287
return; /* short-circuit RCU */
@@ -326,7 +328,7 @@ static int __net_init phonet_init_net(struct net *net)
326328

327329
INIT_LIST_HEAD(&pnn->pndevs.list);
328330
spin_lock_init(&pnn->pndevs.lock);
329-
mutex_init(&pnn->routes.lock);
331+
spin_lock_init(&pnn->routes.lock);
330332
return 0;
331333
}
332334

@@ -376,13 +378,15 @@ int phonet_route_add(struct net_device *dev, u8 daddr)
376378
int err = -EEXIST;
377379

378380
daddr = daddr >> 2;
379-
mutex_lock(&routes->lock);
381+
382+
spin_lock(&routes->lock);
380383
if (routes->table[daddr] == NULL) {
381384
rcu_assign_pointer(routes->table[daddr], dev);
382385
dev_hold(dev);
383386
err = 0;
384387
}
385-
mutex_unlock(&routes->lock);
388+
spin_unlock(&routes->lock);
389+
386390
return err;
387391
}
388392

@@ -392,12 +396,13 @@ int phonet_route_del(struct net_device *dev, u8 daddr)
392396
struct phonet_routes *routes = &pnn->routes;
393397

394398
daddr = daddr >> 2;
395-
mutex_lock(&routes->lock);
399+
400+
spin_lock(&routes->lock);
396401
if (rcu_access_pointer(routes->table[daddr]) == dev)
397402
RCU_INIT_POINTER(routes->table[daddr], NULL);
398403
else
399404
dev = NULL;
400-
mutex_unlock(&routes->lock);
405+
spin_unlock(&routes->lock);
401406

402407
if (!dev)
403408
return -ENOENT;

0 commit comments

Comments
 (0)