Skip to content

Commit b1042d3

Browse files
congwangdavem330
authored andcommitted
netlink: convert netlink tap spinlock to mutex
Both netlink_add_tap() and netlink_remove_tap() are called in process context, no need to bother spinlock. Note, in fact, currently we always hold RTNL when calling these two functions, so we don't need any other lock at all, but keeping this lock doesn't harm anything. Cc: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 25e3f70 commit b1042d3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

net/netlink/af_netlink.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static unsigned int netlink_tap_net_id;
176176

177177
struct netlink_tap_net {
178178
struct list_head netlink_tap_all;
179-
spinlock_t netlink_tap_lock;
179+
struct mutex netlink_tap_lock;
180180
};
181181

182182
int netlink_add_tap(struct netlink_tap *nt)
@@ -187,9 +187,9 @@ int netlink_add_tap(struct netlink_tap *nt)
187187
if (unlikely(nt->dev->type != ARPHRD_NETLINK))
188188
return -EINVAL;
189189

190-
spin_lock(&nn->netlink_tap_lock);
190+
mutex_lock(&nn->netlink_tap_lock);
191191
list_add_rcu(&nt->list, &nn->netlink_tap_all);
192-
spin_unlock(&nn->netlink_tap_lock);
192+
mutex_unlock(&nn->netlink_tap_lock);
193193

194194
__module_get(nt->module);
195195

@@ -204,7 +204,7 @@ static int __netlink_remove_tap(struct netlink_tap *nt)
204204
bool found = false;
205205
struct netlink_tap *tmp;
206206

207-
spin_lock(&nn->netlink_tap_lock);
207+
mutex_lock(&nn->netlink_tap_lock);
208208

209209
list_for_each_entry(tmp, &nn->netlink_tap_all, list) {
210210
if (nt == tmp) {
@@ -216,7 +216,7 @@ static int __netlink_remove_tap(struct netlink_tap *nt)
216216

217217
pr_warn("__netlink_remove_tap: %p not found\n", nt);
218218
out:
219-
spin_unlock(&nn->netlink_tap_lock);
219+
mutex_unlock(&nn->netlink_tap_lock);
220220

221221
if (found)
222222
module_put(nt->module);
@@ -240,7 +240,7 @@ static __net_init int netlink_tap_init_net(struct net *net)
240240
struct netlink_tap_net *nn = net_generic(net, netlink_tap_net_id);
241241

242242
INIT_LIST_HEAD(&nn->netlink_tap_all);
243-
spin_lock_init(&nn->netlink_tap_lock);
243+
mutex_init(&nn->netlink_tap_lock);
244244
return 0;
245245
}
246246

0 commit comments

Comments
 (0)