From: Herbert Xu <herbert@gondor.apana.org.au>
To: Breno Leitao <leitao@debian.org>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Stephen Hemminger <stephen@networkplumber.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
paulmck@kernel.org, Cong Wang <cong.wang@bytedance.com>
Subject: Re: [PATCH net 1/2] netpoll: Use rcu_access_pointer() in __netpoll_setup
Date: Wed, 20 Nov 2024 11:01:28 +0800 [thread overview]
Message-ID: <Zz1RCAT9Ao5PsAAK@gondor.apana.org.au> (raw)
In-Reply-To: <20241119-magnetic-striped-pig-bcffa9@leitao>
On Tue, Nov 19, 2024 at 02:22:06AM -0800, Breno Leitao wrote:
>
> I looked about rcu_dereference_protected() as well, and I though it is
> used when you are de-referencing the pointer, which is a more expensive
> approach. In the code above, the code basically need to check if the
> pointer is assigned or not. Looking at the code, it seems that having
> rcu_access_pointer() inside the update lock seems a common pattern, than
> that is what I chose.
No, rcu_dereference_protected is actually cheaper than rcu_access_pointer:
#define __rcu_access_pointer(p, local, space) \
({ \
typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \
rcu_check_sparse(p, space); \
((typeof(*p) __force __kernel *)(local)); \
})
#define __rcu_dereference_protected(p, local, c, space) \
({ \
RCU_LOCKDEP_WARN(!(c), "suspicious rcu_dereference_protected() usage"); \
rcu_check_sparse(p, space); \
((typeof(*p) __force __kernel *)(p)); \
})
> On the other side, I understand we want to call an RCU primitive with
> the _protected() context, so, I looked for a possible
> `rcu_access_pointer_protected()`, but this best does not exist. Anyway,
> I am happy to change it, if it is the correct API.
There is no need for rcu_access_pointer_protected because the
rcu_dereference_protected helper is already the cheapest.
> When 8fdd95ec162a was created, npinfo was an RCU pointer, although
> without the RCU annotation that came later (5fbee843c). That is
> reason I chose to fix 8fdd95ec162a.
The code was correct as is without RCU markings. The only reason
we need the RCU markings is because an __rcu tag was added to the
variable later, without also making the necessary changes in the
existing code using that variable.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
next prev parent reply other threads:[~2024-11-20 3:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 11:15 [PATCH net 0/2] netpoll: Use RCU primitives for npinfo pointer access Breno Leitao
2024-11-18 11:15 ` [PATCH net 1/2] netpoll: Use rcu_access_pointer() in __netpoll_setup Breno Leitao
2024-11-18 12:18 ` Michal Kubiak
2024-11-19 3:28 ` Herbert Xu
2024-11-19 10:22 ` Breno Leitao
2024-11-20 3:01 ` Herbert Xu [this message]
2024-11-20 3:48 ` Herbert Xu
2024-11-20 17:58 ` Breno Leitao
2024-11-18 11:15 ` [PATCH net 2/2] netpoll: Use rcu_access_pointer() in netpoll_poll_lock Breno Leitao
2024-11-18 12:20 ` Michal Kubiak
2024-11-18 15:37 ` Breno Leitao
2024-11-19 3:02 ` Jakub Kicinski
2024-11-19 3:48 ` Herbert Xu
2024-11-19 3:40 ` [PATCH net 0/2] netpoll: Use RCU primitives for npinfo pointer access patchwork-bot+netdevbpf
2024-11-19 3:53 ` Herbert Xu
2024-11-19 14:34 ` 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=Zz1RCAT9Ao5PsAAK@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=cong.wang@bytedance.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=paulmck@kernel.org \
--cc=stephen@networkplumber.org \
/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