diff mbox series

[net-next] raw: complete rcu conversion

Message ID 20220620100509.3493504-1-eric.dumazet@gmail.com (mailing list archive)
State Accepted
Commit af185d8c76333daa877678e0166a7b45e63bf3c4
Delegated to: Netdev Maintainers
Headers show
Series [net-next] raw: complete rcu conversion | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 15 this patch: 15
netdev/cc_maintainers warning 2 maintainers not CCed: yoshfuji@linux-ipv6.org dsahern@kernel.org
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 15 this patch: 15
netdev/checkpatch warning CHECK: spinlock_t definition without comment
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Eric Dumazet June 20, 2022, 10:05 a.m. UTC
From: Eric Dumazet <edumazet@google.com>

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 <edumazet@google.com>
---
 include/net/raw.h   | 4 ++--
 net/ipv4/raw.c      | 8 ++++----
 net/ipv4/raw_diag.c | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org June 21, 2022, 10:20 a.m. UTC | #1
Hello:

This patch was applied to netdev/net-next.git (master)
by Paolo Abeni <pabeni@redhat.com>:

On Mon, 20 Jun 2022 03:05:09 -0700 you wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> 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.
> 
> [...]

Here is the summary with links:
  - [net-next] raw: complete rcu conversion
    https://git.kernel.org/netdev/net-next/c/af185d8c7633

You are awesome, thank you!
diff mbox series

Patch

diff --git a/include/net/raw.h b/include/net/raw.h
index d81eeeb8f1e6790c398eaa7cb9921f7387b2afcf..d224376360e11c838f02a84595f7040a8a3f4bb0 100644
--- a/include/net/raw.h
+++ b/include/net/raw.h
@@ -32,7 +32,7 @@  int raw_rcv(struct sock *, struct sk_buff *);
 #define RAW_HTABLE_SIZE	MAX_INET_PROTOS
 
 struct raw_hashinfo {
-	rwlock_t lock;
+	spinlock_t lock;
 	struct hlist_nulls_head ht[RAW_HTABLE_SIZE];
 };
 
@@ -40,7 +40,7 @@  static inline void raw_hashinfo_init(struct raw_hashinfo *hashinfo)
 {
 	int i;
 
-	rwlock_init(&hashinfo->lock);
+	spin_lock_init(&hashinfo->lock);
 	for (i = 0; i < RAW_HTABLE_SIZE; i++)
 		INIT_HLIST_NULLS_HEAD(&hashinfo->ht[i], i);
 }
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 959bea12dc484258d372c039800d29e81b7ea18b..027389969915e456b0009e2a0b4ad81afb836e9d 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -95,10 +95,10 @@  int raw_hash_sk(struct sock *sk)
 
 	hlist = &h->ht[inet_sk(sk)->inet_num & (RAW_HTABLE_SIZE - 1)];
 
-	write_lock_bh(&h->lock);
+	spin_lock(&h->lock);
 	__sk_nulls_add_node_rcu(sk, hlist);
 	sock_set_flag(sk, SOCK_RCU_FREE);
-	write_unlock_bh(&h->lock);
+	spin_unlock(&h->lock);
 	sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
 
 	return 0;
@@ -109,10 +109,10 @@  void raw_unhash_sk(struct sock *sk)
 {
 	struct raw_hashinfo *h = sk->sk_prot->h.raw_hash;
 
-	write_lock_bh(&h->lock);
+	spin_lock(&h->lock);
 	if (__sk_nulls_del_node_init_rcu(sk))
 		sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
-	write_unlock_bh(&h->lock);
+	spin_unlock(&h->lock);
 }
 EXPORT_SYMBOL_GPL(raw_unhash_sk);
 
diff --git a/net/ipv4/raw_diag.c b/net/ipv4/raw_diag.c
index ac4b6525d3c67bd44fbf8f56d05279a9fa6acf16..999321834b94a8f7f2a4996575b7cfaafb6fa2b7 100644
--- a/net/ipv4/raw_diag.c
+++ b/net/ipv4/raw_diag.c
@@ -156,7 +156,7 @@  static void raw_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
 	s_slot = cb->args[0];
 	num = s_num = cb->args[1];
 
-	read_lock(&hashinfo->lock);
+	rcu_read_lock();
 	for (slot = s_slot; slot < RAW_HTABLE_SIZE; s_num = 0, slot++) {
 		num = 0;
 
@@ -184,7 +184,7 @@  static void raw_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
 	}
 
 out_unlock:
-	read_unlock(&hashinfo->lock);
+	rcu_read_unlock();
 
 	cb->args[0] = slot;
 	cb->args[1] = num;