SPARC and UltraSPARC platform development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vitaly Zuevsky" <vitaly.zuevsky@gcore.com>
Cc: sparclinux@vger.kernel.org
Subject: Re: [RFC PATCH net-next v1 1/2] net: add SO_NO_RFS to exclude a socket from RFS and aRFS
Date: Sun, 01 Nov 2026 11:33:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-192381@kernel.org> (raw)
In-Reply-To: <20261031113330.45704-2-vitaly.zuevsky@gcore.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] net: stale rps_sock_flow_table entry when SO_NO_RFS set in sk_setsockopt()
--

commit f945cdda3b76cd51e3536a08a7c03f44d3ce0486
Author: Vitaly Zuevsky <vitaly.zuevsky@gcore.com>

net: add SO_NO_RFS to exclude a socket from RFS and aRFS

This commit adds the SO_NO_RFS boolean socket option and corresponding
SOCK_NO_RFS socket flag to allow excluding a socket from RFS and aRFS flow
steering. When set, _sock_rps_record_flow() and _sock_rps_delete_flow() return
early without updating net_hotdata.rps_sock_flow_table.

[ ... ]

> diff --git a/include/net/rps.h b/include/net/rps.h
> index e33c6a2fa8bbc..5afa488682360 100644
> --- a/include/net/rps.h
> +++ b/include/net/rps.h
> @@ -98,6 +98,13 @@ static inline void _sock_rps_record_flow(const struct sock *sk)
>  	 * [1] : sk_state and sk_prot are in the same cache line.
>  	 */
>  	if (sk->sk_state == TCP_ESTABLISHED) {
> +		/* SO_NO_RFS: application asked us to never steer this flow.
> +		 * Tested after sk_state so the common case stays on one
> +		 * cache line.
> +		 */
> +		if (unlikely(sock_flag(sk, SOCK_NO_RFS)))
> +			return;
> +
>  		/* This READ_ONCE() is paired with the WRITE_ONCE()
>  		 * from sock_rps_save_rxhash() and sock_rps_reset_rxhash().
>  		 */
> @@ -111,6 +118,12 @@ static inline void _sock_rps_delete_flow(const struct sock *sk)
>  	rps_tag_ptr tag_ptr;
>  	u32 hash, index;
>  
> +	/* Never recorded, so never clear a slot that may belong to
> +	 * another flow.
> +	 */
> +	if (sock_flag(sk, SOCK_NO_RFS))
> +		return;
> +
>  	hash = READ_ONCE(sk->sk_rxhash);
>  	if (!hash)
>  		return;

[ ... ]

> diff --git a/net/core/sock.c b/net/core/sock.c
> index e7405be8941f9..02b8cc4bc1c44 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1597,6 +1597,10 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
>  		reuseport_update_incoming_cpu(sk, val);
>  		break;
>  
> +	case SO_NO_RFS:
> +		sock_valbool_flag(sk, SOCK_NO_RFS, valbool);
> +		break;

[Severity: Medium]
What happens if userspace enables SO_NO_RFS on a socket after it has already
recorded an entry in net_hotdata.rps_sock_flow_table?

For example, when a listening socket does not have SO_NO_RFS set,
inet_accept() -> __inet_accept() records the newly accepted socket before
returning the file descriptor to userspace:

net/ipv4/af_inet.c:__inet_accept() {
	...
	sock_rps_record_flow(newsk);
	...
}

The same applies if setsockopt(SO_NO_RFS) is called on a connected socket
after an initial sendmsg() or recvmsg().

Because sk_setsockopt() sets SOCK_NO_RFS without calling
sock_rps_delete_flow(sk), the existing entry remains in
net_hotdata.rps_sock_flow_table, so get_rps_cpu() and set_rps_cpu() continue
steering the flow to the previously recorded CPU. When the socket is later
unhashed, _sock_rps_delete_flow() sees SOCK_NO_RFS set and returns early
without resetting table[index].ent to RPS_NO_CPU, leaving a stale entry in
rps_sock_flow_table.

Conversely, because sock_rps_save_rxhash() still populates sk->sk_rxhash when
SOCK_NO_RFS is set, if a socket receives packets while SO_NO_RFS is enabled
and later clears SO_NO_RFS before closing, wouldn't _sock_rps_delete_flow()
see a non-zero sk->sk_rxhash with SOCK_NO_RFS cleared and clear
table[index].ent even though the socket never recorded itself?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261031113330.45704-1-vitaly.zuevsky@gcore.com?part=1

  parent reply	other threads:[~2026-11-01 11:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 11:33 [RFC PATCH net-next v1 0/2] net: per-socket opt-out from RFS/aRFS Vitaly Zuevsky
2026-10-31 11:33 ` [RFC PATCH net-next v1 1/2] net: add SO_NO_RFS to exclude a socket from RFS and aRFS Vitaly Zuevsky
2026-10-31 15:15   ` Willem de Bruijn
2026-11-01 11:33   ` sashiko-bot [this message]
2026-11-03  4:49   ` Kuniyuki Iwashima
2026-10-31 11:33 ` [RFC PATCH net-next v1 2/2] Documentation: networking: document SO_NO_RFS Vitaly Zuevsky
2026-11-01 11:33   ` sashiko-bot

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=sashiko-outbox-192381@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sparclinux@vger.kernel.org \
    --cc=vitaly.zuevsky@gcore.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