* [PATCH net-next] net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1)
@ 2025-10-14 14:06 Eric Dumazet
2025-10-15 2:06 ` Kuniyuki Iwashima
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Eric Dumazet @ 2025-10-14 14:06 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, netdev, eric.dumazet, Eric Dumazet, Xuanqiang Luo,
Kuniyuki Iwashima
sk->sk_refcnt has been converted to refcount_t in 2017.
__sock_put(sk) being refcount_dec(&sk->sk_refcnt), it will complain
loudly if the current refcnt is 1 (or less) in a non racy way.
We can remove four WARN_ON() in favor of the generic refcount_dec()
check.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
Cc: Kuniyuki Iwashima <kuniyu@google.com>
---
include/net/sock.h | 12 ++++--------
net/netlink/af_netlink.c | 4 +---
net/tipc/socket.c | 4 +---
3 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 60bcb13f045c..596302bffedf 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -828,11 +828,9 @@ static inline bool sk_del_node_init(struct sock *sk)
{
bool rc = __sk_del_node_init(sk);
- if (rc) {
- /* paranoid for a while -acme */
- WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
+ if (rc)
__sock_put(sk);
- }
+
return rc;
}
#define sk_del_node_init_rcu(sk) sk_del_node_init(sk)
@@ -850,11 +848,9 @@ static inline bool sk_nulls_del_node_init_rcu(struct sock *sk)
{
bool rc = __sk_nulls_del_node_init_rcu(sk);
- if (rc) {
- /* paranoid for a while -acme */
- WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
+ if (rc)
__sock_put(sk);
- }
+
return rc;
}
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 2b46c0cd752a..687a84c48882 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -596,10 +596,8 @@ static void netlink_remove(struct sock *sk)
table = &nl_table[sk->sk_protocol];
if (!rhashtable_remove_fast(&table->hash, &nlk_sk(sk)->node,
- netlink_rhashtable_params)) {
- WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
+ netlink_rhashtable_params))
__sock_put(sk);
- }
netlink_table_grab();
if (nlk_sk(sk)->subscriptions) {
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 1574a83384f8..bc614a1f019c 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -3031,10 +3031,8 @@ static void tipc_sk_remove(struct tipc_sock *tsk)
struct sock *sk = &tsk->sk;
struct tipc_net *tn = net_generic(sock_net(sk), tipc_net_id);
- if (!rhashtable_remove_fast(&tn->sk_rht, &tsk->node, tsk_rht_params)) {
- WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
+ if (!rhashtable_remove_fast(&tn->sk_rht, &tsk->node, tsk_rht_params))
__sock_put(sk);
- }
}
static const struct rhashtable_params tsk_rht_params = {
--
2.51.0.788.g6d19910ace-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1)
2025-10-14 14:06 [PATCH net-next] net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1) Eric Dumazet
@ 2025-10-15 2:06 ` Kuniyuki Iwashima
2025-10-15 6:03 ` luoxuanqiang
2025-10-16 0:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: Kuniyuki Iwashima @ 2025-10-15 2:06 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
netdev, eric.dumazet, Xuanqiang Luo
On Tue, Oct 14, 2025 at 7:06 AM Eric Dumazet <edumazet@google.com> wrote:
>
> sk->sk_refcnt has been converted to refcount_t in 2017.
>
> __sock_put(sk) being refcount_dec(&sk->sk_refcnt), it will complain
> loudly if the current refcnt is 1 (or less) in a non racy way.
>
> We can remove four WARN_ON() in favor of the generic refcount_dec()
> check.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Thanks for catching this!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1)
2025-10-14 14:06 [PATCH net-next] net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1) Eric Dumazet
2025-10-15 2:06 ` Kuniyuki Iwashima
@ 2025-10-15 6:03 ` luoxuanqiang
2025-10-15 6:44 ` Eric Dumazet
2025-10-16 0:40 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: luoxuanqiang @ 2025-10-15 6:03 UTC (permalink / raw)
To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, netdev, eric.dumazet, Kuniyuki Iwashima
在 2025/10/14 22:06, Eric Dumazet 写道:
> sk->sk_refcnt has been converted to refcount_t in 2017.
>
> __sock_put(sk) being refcount_dec(&sk->sk_refcnt), it will complain
> loudly if the current refcnt is 1 (or less) in a non racy way.
>
> We can remove four WARN_ON() in favor of the generic refcount_dec()
> check.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Xuanqiang Luo<luoxuanqiang@kylinos.cn>
Dear Eric,
Following your line of thought, I found there's also a point in btrfs that
needs modification.
Would you like to modify it together? Though it has nothing to do with
socket, or shall I modify it separately later?
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 89ae0c7a610a..485bef0ba419 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -138,7 +138,6 @@ static const unsigned int btrfs_blocked_trans_types[TRANS_STATE_MAX] = {
void btrfs_put_transaction(struct btrfs_transaction *transaction)
{
- WARN_ON(refcount_read(&transaction->use_count) == 0);
if (refcount_dec_and_test(&transaction->use_count)) {
BUG_ON(!list_empty(&transaction->list));
WARN_ON(!xa_empty(&transaction->delayed_refs.head_refs));
Thanks!
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1)
2025-10-15 6:03 ` luoxuanqiang
@ 2025-10-15 6:44 ` Eric Dumazet
0 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2025-10-15 6:44 UTC (permalink / raw)
To: luoxuanqiang
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
netdev, eric.dumazet, Kuniyuki Iwashima
On Tue, Oct 14, 2025 at 11:04 PM luoxuanqiang <xuanqiang.luo@linux.dev> wrote:
>
>
> 在 2025/10/14 22:06, Eric Dumazet 写道:
> > sk->sk_refcnt has been converted to refcount_t in 2017.
> >
> > __sock_put(sk) being refcount_dec(&sk->sk_refcnt), it will complain
> > loudly if the current refcnt is 1 (or less) in a non racy way.
> >
> > We can remove four WARN_ON() in favor of the generic refcount_dec()
> > check.
> >
> > Signed-off-by: Eric Dumazet <edumazet@google.com>
>
> Reviewed-by: Xuanqiang Luo<luoxuanqiang@kylinos.cn>
>
> Dear Eric,
>
> Following your line of thought, I found there's also a point in btrfs that
> needs modification.
>
> Would you like to modify it together? Though it has nothing to do with
> socket, or shall I modify it separately later?
I removed stuff around sk_refcnt only.
If you want, please send a patch to the appropriate lists and maintainers.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1)
2025-10-14 14:06 [PATCH net-next] net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1) Eric Dumazet
2025-10-15 2:06 ` Kuniyuki Iwashima
2025-10-15 6:03 ` luoxuanqiang
@ 2025-10-16 0:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-10-16 0:40 UTC (permalink / raw)
To: Eric Dumazet
Cc: davem, kuba, pabeni, horms, netdev, eric.dumazet, luoxuanqiang,
kuniyu
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 14 Oct 2025 14:06:05 +0000 you wrote:
> sk->sk_refcnt has been converted to refcount_t in 2017.
>
> __sock_put(sk) being refcount_dec(&sk->sk_refcnt), it will complain
> loudly if the current refcnt is 1 (or less) in a non racy way.
>
> We can remove four WARN_ON() in favor of the generic refcount_dec()
> check.
>
> [...]
Here is the summary with links:
- [net-next] net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1)
https://git.kernel.org/netdev/net-next/c/e5b670e5439b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-10-16 0:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-14 14:06 [PATCH net-next] net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1) Eric Dumazet
2025-10-15 2:06 ` Kuniyuki Iwashima
2025-10-15 6:03 ` luoxuanqiang
2025-10-15 6:44 ` Eric Dumazet
2025-10-16 0:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).