From: Sabrina Dubroca <sd@queasysnail.net>
To: Jakub Kicinski <kuba@kernel.org>
Cc: "Dae R. Jeong" <threeearcat@gmail.com>,
borisp@nvidia.com, john.fastabend@gmail.com, davem@davemloft.net,
edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, ywchoi@casys.kaist.ac.kr
Subject: Re: Missing a write memory barrier in tls_init()
Date: Wed, 8 Nov 2023 10:07:58 +0100 [thread overview]
Message-ID: <ZUtP7lMqFnNK8lw_@hog> (raw)
In-Reply-To: <20231107185324.22eecf10@kernel.org>
2023-11-07, 18:53:24 -0800, Jakub Kicinski wrote:
> On Tue, 7 Nov 2023 23:45:46 +0100 Sabrina Dubroca wrote:
> > Wouldn't it be enough to just move the rcu_assign_pointer after ctx is
> > fully initialized, ie just before update_sk_prot? also clearer wrt
> > RCU.
>
> I'm not sure, IIUC rcu_assign_pointer() is equivalent to
> WRITE_ONCE() on any sane architecture, it depends on address
> dependencies to provide ordering.
Not what the doc says:
/**
* rcu_assign_pointer() - assign to RCU-protected pointer
[...]
* Inserts memory barriers on architectures that require them
* (which is most of them), and also prevents the compiler from
* reordering the code that initializes the structure after the pointer
* assignment.
[...]
*/
And it uses smp_store_release (unless writing NULL).
rcu_dereference is the one that usually doesn't contain a barrier:
/**
* rcu_dereference_check() - rcu_dereference with debug checking
[...]
* Inserts memory barriers on architectures that require them
* (currently only the Alpha), prevents the compiler from refetching
* (and from merging fetches), and, more importantly, documents exactly
* which pointers are protected by RCU and checks that the pointer is
* annotated as __rcu.
*/
> Since here we care about
> ctx->sk_prot being updated, when changes to sk->sk_prot
> are visible there is no super-obvious address dependency.
>
> There may be one. But to me at least it isn't an obvious
> "RCU used right will handle this" case.
Ok, I think you're right. Looking at smp_store_release used by rcu_assign_pointer:
#define __smp_store_release(p, v) \
do { \
compiletime_assert_atomic_type(*p); \
barrier(); \
WRITE_ONCE(*p, v); \
} while (0)
it's only going to make sure ctx->sk_proto is set when ctx is visible,
and not guarantee that ctx is visible whenever sk->sk_prot has been
switched over.
--
Sabrina
next prev parent reply other threads:[~2023-11-08 9:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-02 7:11 Missing a write memory barrier in tls_init() Dae R. Jeong
2023-11-06 22:36 ` Jakub Kicinski
2023-11-07 8:07 ` Dae R. Jeong
2023-11-07 22:45 ` Sabrina Dubroca
2023-11-08 2:53 ` Jakub Kicinski
2023-11-08 9:07 ` Sabrina Dubroca [this message]
2023-11-10 10:22 ` Dae R. Jeong
2023-11-10 11:04 ` Dae R. Jeong
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=ZUtP7lMqFnNK8lw_@hog \
--to=sd@queasysnail.net \
--cc=borisp@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=threeearcat@gmail.com \
--cc=ywchoi@casys.kaist.ac.kr \
/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;
as well as URLs for NNTP newsgroup(s).