Skip to content

Commit af185d8

Browse files
edumazetPaolo Abeni
authored andcommitted
raw: complete rcu conversion
raw_diag_dump() can use rcu_read_lock() instead of read_lock() Now the hashinfo lock is only used from process context, in write mode only, we can convert it to a spinlock, and we do not need to block BH anymore. Signed-off-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent f9aefd6 commit af185d8

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

include/net/raw.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ int raw_rcv(struct sock *, struct sk_buff *);
3232
#define RAW_HTABLE_SIZE MAX_INET_PROTOS
3333

3434
struct raw_hashinfo {
35-
rwlock_t lock;
35+
spinlock_t lock;
3636
struct hlist_nulls_head ht[RAW_HTABLE_SIZE];
3737
};
3838

3939
static inline void raw_hashinfo_init(struct raw_hashinfo *hashinfo)
4040
{
4141
int i;
4242

43-
rwlock_init(&hashinfo->lock);
43+
spin_lock_init(&hashinfo->lock);
4444
for (i = 0; i < RAW_HTABLE_SIZE; i++)
4545
INIT_HLIST_NULLS_HEAD(&hashinfo->ht[i], i);
4646
}

net/ipv4/raw.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ int raw_hash_sk(struct sock *sk)
9595

9696
hlist = &h->ht[inet_sk(sk)->inet_num & (RAW_HTABLE_SIZE - 1)];
9797

98-
write_lock_bh(&h->lock);
98+
spin_lock(&h->lock);
9999
__sk_nulls_add_node_rcu(sk, hlist);
100100
sock_set_flag(sk, SOCK_RCU_FREE);
101-
write_unlock_bh(&h->lock);
101+
spin_unlock(&h->lock);
102102
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
103103

104104
return 0;
@@ -109,10 +109,10 @@ void raw_unhash_sk(struct sock *sk)
109109
{
110110
struct raw_hashinfo *h = sk->sk_prot->h.raw_hash;
111111

112-
write_lock_bh(&h->lock);
112+
spin_lock(&h->lock);
113113
if (__sk_nulls_del_node_init_rcu(sk))
114114
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
115-
write_unlock_bh(&h->lock);
115+
spin_unlock(&h->lock);
116116
}
117117
EXPORT_SYMBOL_GPL(raw_unhash_sk);
118118

net/ipv4/raw_diag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static void raw_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
156156
s_slot = cb->args[0];
157157
num = s_num = cb->args[1];
158158

159-
read_lock(&hashinfo->lock);
159+
rcu_read_lock();
160160
for (slot = s_slot; slot < RAW_HTABLE_SIZE; s_num = 0, slot++) {
161161
num = 0;
162162

@@ -184,7 +184,7 @@ static void raw_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
184184
}
185185

186186
out_unlock:
187-
read_unlock(&hashinfo->lock);
187+
rcu_read_unlock();
188188

189189
cb->args[0] = slot;
190190
cb->args[1] = num;

0 commit comments

Comments
 (0)