Netdev List
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <razor@blackwall.org>
To: Eric Dumazet <edumazet@google.com>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	netdev@vger.kernel.org, eric.dumazet@gmail.com,
	Daniel Borkmann <daniel@iogearbox.net>
Subject: Re: [PATCH net-next] netkit: no longer rely on RTNL in netkit_fill_info()
Date: Wed, 16 Sep 2026 16:33:00 +0300	[thread overview]
Message-ID: <5a8fdfa2-2ecb-453b-9df7-e52e4c381892@blackwall.org> (raw)
In-Reply-To: <20260916111953.1611574-1-edumazet@google.com>

On 16/09/2026 14:19, Eric Dumazet wrote:
> netkit_fill_info() used rtnl_dereference() to fetch nk->peer,
> and thus required RTNL.
> 
> nk->peer is already an RCU protected pointer, updated with
> rcu_assign_pointer() and read from the fast path with
> rcu_dereference(). Simply use rcu_dereference() under
> rcu_read_lock() instead.
> 
> While at it, use READ_ONCE() when reading nk->policy, because
> netkit_change_link() can change it at any time (it already uses
> WRITE_ONCE()).
> 
> Other fields (primary, mode, pair, scrub) are only set from
> netkit_new_link(), before the device is visible to dumps.
> 
> Also add missing const qualifiers.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Nikolay Aleksandrov <razor@blackwall.org>
> ---
>   drivers/net/netkit.c | 17 +++++++++++------
>   1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/netkit.c b/drivers/net/netkit.c
> index a3931cd821321c3e4888edf86efc414199127bcf..82e608e733d9ee70f71c374570211c73da76ae2c 100644
> --- a/drivers/net/netkit.c
> +++ b/drivers/net/netkit.c
> @@ -1209,12 +1209,12 @@ static size_t netkit_get_size(const struct net_device *dev)
>   
>   static int netkit_fill_info(struct sk_buff *skb, const struct net_device *dev)
>   {
> -	struct netkit *nk = netkit_priv(dev);
> -	struct net_device *peer = rtnl_dereference(nk->peer);
> +	const struct netkit *nk = netkit_priv(dev);
> +	const struct net_device *peer;
>   
>   	if (nla_put_u8(skb, IFLA_NETKIT_PRIMARY, nk->primary))
>   		return -EMSGSIZE;
> -	if (nla_put_u32(skb, IFLA_NETKIT_POLICY, nk->policy))
> +	if (nla_put_u32(skb, IFLA_NETKIT_POLICY, READ_ONCE(nk->policy)))
>   		return -EMSGSIZE;
>   	if (nla_put_u32(skb, IFLA_NETKIT_MODE, nk->mode))
>   		return -EMSGSIZE;
> @@ -1228,13 +1228,18 @@ static int netkit_fill_info(struct sk_buff *skb, const struct net_device *dev)
>   	if (nla_put_u32(skb, IFLA_NETKIT_PAIRING, nk->pair))
>   		return -EMSGSIZE;
>   
> +	rcu_read_lock();
> +	peer = rcu_dereference(nk->peer);
>   	if (peer) {
>   		nk = netkit_priv(peer);
> -		if (nla_put_u32(skb, IFLA_NETKIT_PEER_POLICY, nk->policy))
> -			return -EMSGSIZE;
> -		if (nla_put_u32(skb, IFLA_NETKIT_PEER_SCRUB, nk->scrub))
> +		if (nla_put_u32(skb, IFLA_NETKIT_PEER_POLICY,
> +				READ_ONCE(nk->policy)) ||
> +		    nla_put_u32(skb, IFLA_NETKIT_PEER_SCRUB, nk->scrub)) {
> +			rcu_read_unlock();
>   			return -EMSGSIZE;
> +		}
>   	}
> +	rcu_read_unlock();
>   
>   	return 0;
>   }

Thanks!
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>


  parent reply	other threads:[~2026-09-16 13:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 11:19 [PATCH net-next] netkit: no longer rely on RTNL in netkit_fill_info() Eric Dumazet
2026-09-16 12:54 ` Daniel Borkmann
2026-09-16 13:33 ` Nikolay Aleksandrov [this message]
2026-09-18  0:00 ` patchwork-bot+netdevbpf

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=5a8fdfa2-2ecb-453b-9df7-e52e4c381892@blackwall.org \
    --to=razor@blackwall.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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