Netdev List
 help / color / mirror / Atom feed
From: Vitaly Zuevsky <vitaly.zuevsky@gcore.com>
To: netdev@vger.kernel.org
Cc: sashiko-reviews@lists.linux.dev, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	horms@kernel.org, willemb@google.com,
	Kuniyuki Iwashima <kuniyu@google.com>
Subject: Re: [PATCH net-next v2] net: add SO_BYPASS_RFS to exclude a socket from RFS and aRFS
Date: Wed, 11 Nov 2026 11:47:26 -0500	[thread overview]
Message-ID: <1ef4ead0-998b-498d-b581-353519be1e9b@gcore.com> (raw)
In-Reply-To: <sashiko-outbox-205984@kernel.org>

On 09/11/2026 20:45, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] net: race in sk_setsockopt() deleting RFS flow before setting
>    sk_bypass_rfs
> It also noticed 1 related pre-existing issue this patch does not
> introduce:
> - [Medium] net: file descriptor leak in sk_getsockopt() [1]
> --
> 
> commit 0bb55ec9420355430d450dec603d8adf895ff281
> Author: Vitaly Zuevsky <vitaly.zuevsky@gcore.com>
> 
> net: add SO_BYPASS_RFS to exclude a socket from RFS and aRFS
> 
> This commit adds the SO_BYPASS_RFS boolean socket option and a skc_bypass_rfs
> bit in struct sock_common to exclude a socket from RFS and aRFS flow recording
> and deletion.
> 
>> diff --git a/net/core/sock.c b/net/core/sock.c
>> index e2401d735c5a7..00808217aebf1 100644
>> --- a/net/core/sock.c
>> +++ b/net/core/sock.c
> [ ... ]
>> @@ -1597,6 +1598,14 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
>>   		reuseport_update_incoming_cpu(sk, val);
>>   		break;
>>   
>> +#ifdef CONFIG_RPS
>> +	case SO_BYPASS_RFS:
>> +		if (valbool)
>> +			sock_rps_delete_flow(sk);
>> +		sk->sk_bypass_rfs = valbool;
>> +		break;
>> +#endif
>> +
>>   	case SO_CNX_ADVICE:
>>   		if (val == 1)
>>   			dst_negative_advice(sk);
> 
> [Severity: Medium]
> Can a concurrent receive or send re-record the flow between
> sock_rps_delete_flow() and setting sk->sk_bypass_rfs?
> 
> Callers such as inet_recvmsg() invoke sock_rps_record_flow() without
> holding the socket lock:
> 
> CPU0                              CPU1
> sk_setsockopt(SO_BYPASS_RFS, 1)
>    sock_rps_delete_flow(sk)
>      _sock_rps_delete_flow(sk)
>                                    inet_recvmsg()
>                                      sock_rps_record_flow(sk)
>                                        /* sk->sk_bypass_rfs is still 0 */
>                                        _sock_rps_record_flow(sk)  <-- re-records flow
>    sk->sk_bypass_rfs = 1;
> 
> Once sk->sk_bypass_rfs is set, sock_rps_delete_flow() returns early, so
> the re-recorded entry stays in rps_sock_flow_table while SO_BYPASS_RFS is
> enabled and is not cleared when the socket closes.  Setting
> sk->sk_bypass_rfs before calling _sock_rps_delete_flow() would avoid
> leaving a stale entry if a concurrent reader races with setsockopt().

The record path is lockless by design and the table holds hints; a 
recvmsg() racing with the setsockopt() can leave one, which is tolerated 
like any other stale entry. Reordering narrows race-window at a cost of 
dropping the wrapper, consider:

sk->sk_bypass_rfs = valbool;
if (valbool) _sock_rps_delete_flow(sk);

|CPU0: setsockopt       |CPU1: recvmsg
                         |CPU1: test bit -> 0
|CPU0: bit = 1          |CPU1: preemted
|CPU0: delete slot      |CPU1: preemted
                         |CPU1: record   -> hint written


  parent reply	other threads:[~2026-11-11 16:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09  1:45 [PATCH net-next v2] net: add SO_BYPASS_RFS to exclude a socket from RFS and aRFS Vitaly Zuevsky
     [not found] ` <sashiko-outbox-205984@kernel.org>
2026-11-11 16:47   ` Vitaly Zuevsky [this message]
2026-11-12  1:46 ` netdev-bot+sashiko
2026-11-12  1:57 ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1ef4ead0-998b-498d-b581-353519be1e9b@gcore.com \
    --to=vitaly.zuevsky@gcore.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox