diff mbox series

[2/2] docs: memory-barriers: Add note on plain-accesses to address-dependency barriers

Message ID 20230803032408.2514989-2-joel@joelfernandes.org (mailing list archive)
State New, archived
Headers show
Series [1/2] docs: rcu: Add cautionary note on plain-accesses to requirements | expand

Commit Message

Joel Fernandes Aug. 3, 2023, 3:24 a.m. UTC
The compiler has the ability to cause misordering by destroying
address-dependency barriers if comparison operations are used. Add a
note about this to memory-barriers.txt and point to rcu-dereference.rst
for more information.

Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 Documentation/memory-barriers.txt | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Paul E. McKenney Aug. 3, 2023, 6:52 p.m. UTC | #1
On Thu, Aug 03, 2023 at 03:24:07AM +0000, Joel Fernandes (Google) wrote:
> The compiler has the ability to cause misordering by destroying
> address-dependency barriers if comparison operations are used. Add a
> note about this to memory-barriers.txt and point to rcu-dereference.rst
> for more information.
> 
> Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> ---
>  Documentation/memory-barriers.txt | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
> index 06e14efd8662..acc8ec5ce563 100644
> --- a/Documentation/memory-barriers.txt
> +++ b/Documentation/memory-barriers.txt
> @@ -435,6 +435,11 @@ Memory barriers come in four basic varieties:
>       variables such as READ_ONCE() and rcu_dereference() provide implicit
>       address-dependency barriers.
>  
> +     [!] Note that address dependency barriers can be destroyed by comparison
> +     of a pointer obtained by a marked accessor such as READ_ONCE() or
> +     rcu_dereference() with some value.  For an example of this, see
> +     rcu_dereference.rst (part where the comparison of pointers is discussed).

Hmmm...

Given that this is in a section marked "historical" (for the old
smp_read_barrier_depends() API), why not instead add a pointer to
Documentation/RCU/rcu_dereference.rst to the beginning of the section,
noted as the updated material?

							Thanx, Paul

> +
>   (3) Read (or load) memory barriers.
>  
>       A read barrier is an address-dependency barrier plus a guarantee that all
> -- 
> 2.41.0.585.gd2178a4bd4-goog
>
Joel Fernandes Aug. 4, 2023, 5:11 a.m. UTC | #2
On Thu, Aug 03, 2023 at 11:52:06AM -0700, Paul E. McKenney wrote:
> On Thu, Aug 03, 2023 at 03:24:07AM +0000, Joel Fernandes (Google) wrote:
> > The compiler has the ability to cause misordering by destroying
> > address-dependency barriers if comparison operations are used. Add a
> > note about this to memory-barriers.txt and point to rcu-dereference.rst
> > for more information.
> > 
> > Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> > ---
> >  Documentation/memory-barriers.txt | 5 +++++
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
> > index 06e14efd8662..acc8ec5ce563 100644
> > --- a/Documentation/memory-barriers.txt
> > +++ b/Documentation/memory-barriers.txt
> > @@ -435,6 +435,11 @@ Memory barriers come in four basic varieties:
> >       variables such as READ_ONCE() and rcu_dereference() provide implicit
> >       address-dependency barriers.
> >  
> > +     [!] Note that address dependency barriers can be destroyed by comparison
> > +     of a pointer obtained by a marked accessor such as READ_ONCE() or
> > +     rcu_dereference() with some value.  For an example of this, see
> > +     rcu_dereference.rst (part where the comparison of pointers is discussed).
> 
> Hmmm...
> 
> Given that this is in a section marked "historical" (for the old
> smp_read_barrier_depends() API), why not instead add a pointer to
> Documentation/RCU/rcu_dereference.rst to the beginning of the section,
> noted as the updated material?

Sounds good. There's also another section in the same file on Address
dependency barriers (also marked historical). So something like the
following?

---8<-----------------------

diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
index acc8ec5ce563..ba50220716ca 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -396,6 +396,10 @@ Memory barriers come in four basic varieties:
 
 
  (2) Address-dependency barriers (historical).
+     [!] This section is marked as HISTORICAL: For more up-to-date
+     information, including how compiler transformations related to pointer
+     comparisons can sometimes cause problems, see
+     Documentation/RCU/rcu_dereference.rst.
 
      An address-dependency barrier is a weaker form of read barrier.  In the
      case where two loads are performed such that the second depends on the
@@ -561,6 +565,9 @@ There are certain things that the Linux kernel memory barriers do not guarantee:
 
 ADDRESS-DEPENDENCY BARRIERS (HISTORICAL)
 ----------------------------------------
+[!] This section is marked as HISTORICAL: For more up-to-date information,
+including how compiler transformations related to pointer comparisons can
+sometimes cause problems, see Documentation/RCU/rcu_dereference.rst.
 
 As of v4.15 of the Linux kernel, an smp_mb() was added to READ_ONCE() for
 DEC Alpha, which means that about the only people who need to pay attention
Paul E. McKenney Aug. 4, 2023, 1:52 p.m. UTC | #3
On Fri, Aug 04, 2023 at 05:11:27AM +0000, Joel Fernandes wrote:
> On Thu, Aug 03, 2023 at 11:52:06AM -0700, Paul E. McKenney wrote:
> > On Thu, Aug 03, 2023 at 03:24:07AM +0000, Joel Fernandes (Google) wrote:
> > > The compiler has the ability to cause misordering by destroying
> > > address-dependency barriers if comparison operations are used. Add a
> > > note about this to memory-barriers.txt and point to rcu-dereference.rst
> > > for more information.
> > > 
> > > Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> > > ---
> > >  Documentation/memory-barriers.txt | 5 +++++
> > >  1 file changed, 5 insertions(+)
> > > 
> > > diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
> > > index 06e14efd8662..acc8ec5ce563 100644
> > > --- a/Documentation/memory-barriers.txt
> > > +++ b/Documentation/memory-barriers.txt
> > > @@ -435,6 +435,11 @@ Memory barriers come in four basic varieties:
> > >       variables such as READ_ONCE() and rcu_dereference() provide implicit
> > >       address-dependency barriers.
> > >  
> > > +     [!] Note that address dependency barriers can be destroyed by comparison
> > > +     of a pointer obtained by a marked accessor such as READ_ONCE() or
> > > +     rcu_dereference() with some value.  For an example of this, see
> > > +     rcu_dereference.rst (part where the comparison of pointers is discussed).
> > 
> > Hmmm...
> > 
> > Given that this is in a section marked "historical" (for the old
> > smp_read_barrier_depends() API), why not instead add a pointer to
> > Documentation/RCU/rcu_dereference.rst to the beginning of the section,
> > noted as the updated material?
> 
> Sounds good. There's also another section in the same file on Address
> dependency barriers (also marked historical). So something like the
> following?

Given a Signed-off-by and so forth, I would be happy to take this one.

							Thanx, Paul

> ---8<-----------------------
> 
> diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
> index acc8ec5ce563..ba50220716ca 100644
> --- a/Documentation/memory-barriers.txt
> +++ b/Documentation/memory-barriers.txt
> @@ -396,6 +396,10 @@ Memory barriers come in four basic varieties:
>  
>  
>   (2) Address-dependency barriers (historical).
> +     [!] This section is marked as HISTORICAL: For more up-to-date
> +     information, including how compiler transformations related to pointer
> +     comparisons can sometimes cause problems, see
> +     Documentation/RCU/rcu_dereference.rst.
>  
>       An address-dependency barrier is a weaker form of read barrier.  In the
>       case where two loads are performed such that the second depends on the
> @@ -561,6 +565,9 @@ There are certain things that the Linux kernel memory barriers do not guarantee:
>  
>  ADDRESS-DEPENDENCY BARRIERS (HISTORICAL)
>  ----------------------------------------
> +[!] This section is marked as HISTORICAL: For more up-to-date information,
> +including how compiler transformations related to pointer comparisons can
> +sometimes cause problems, see Documentation/RCU/rcu_dereference.rst.
>  
>  As of v4.15 of the Linux kernel, an smp_mb() was added to READ_ONCE() for
>  DEC Alpha, which means that about the only people who need to pay attention
Joel Fernandes Aug. 4, 2023, 4:27 p.m. UTC | #4
On Fri, Aug 04, 2023 at 06:52:32AM -0700, Paul E. McKenney wrote:
> On Fri, Aug 04, 2023 at 05:11:27AM +0000, Joel Fernandes wrote:
> > On Thu, Aug 03, 2023 at 11:52:06AM -0700, Paul E. McKenney wrote:
> > > On Thu, Aug 03, 2023 at 03:24:07AM +0000, Joel Fernandes (Google) wrote:
> > > > The compiler has the ability to cause misordering by destroying
> > > > address-dependency barriers if comparison operations are used. Add a
> > > > note about this to memory-barriers.txt and point to rcu-dereference.rst
> > > > for more information.
> > > > 
> > > > Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> > > > ---
> > > >  Documentation/memory-barriers.txt | 5 +++++
> > > >  1 file changed, 5 insertions(+)
> > > > 
> > > > diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
> > > > index 06e14efd8662..acc8ec5ce563 100644
> > > > --- a/Documentation/memory-barriers.txt
> > > > +++ b/Documentation/memory-barriers.txt
> > > > @@ -435,6 +435,11 @@ Memory barriers come in four basic varieties:
> > > >       variables such as READ_ONCE() and rcu_dereference() provide implicit
> > > >       address-dependency barriers.
> > > >  
> > > > +     [!] Note that address dependency barriers can be destroyed by comparison
> > > > +     of a pointer obtained by a marked accessor such as READ_ONCE() or
> > > > +     rcu_dereference() with some value.  For an example of this, see
> > > > +     rcu_dereference.rst (part where the comparison of pointers is discussed).
> > > 
> > > Hmmm...
> > > 
> > > Given that this is in a section marked "historical" (for the old
> > > smp_read_barrier_depends() API), why not instead add a pointer to
> > > Documentation/RCU/rcu_dereference.rst to the beginning of the section,
> > > noted as the updated material?
> > 
> > Sounds good. There's also another section in the same file on Address
> > dependency barriers (also marked historical). So something like the
> > following?
> 
> Given a Signed-off-by and so forth, I would be happy to take this one.

Thank you for helping me improve the docs, here it goes:

---8<-----------------------

From: "Joel Fernandes (Google)" <joel@joelfernandes.org>
Subject: [PATCH] docs: memory-barriers: Add note on compiler transformation
 and address deps

The compiler has the ability to cause misordering by destroying
address-dependency barriers if comparison operations are used. Add a
note about this to memory-barriers.txt in the beginning of both the
historical address-dependency sections and point to rcu-dereference.rst
for more information.

Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 Documentation/memory-barriers.txt | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
index acc8ec5ce563..ba50220716ca 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -396,6 +396,10 @@ Memory barriers come in four basic varieties:
 
 
  (2) Address-dependency barriers (historical).
+     [!] This section is marked as HISTORICAL: For more up-to-date
+     information, including how compiler transformations related to pointer
+     comparisons can sometimes cause problems, see
+     Documentation/RCU/rcu_dereference.rst.
 
      An address-dependency barrier is a weaker form of read barrier.  In the
      case where two loads are performed such that the second depends on the
@@ -561,6 +565,9 @@ There are certain things that the Linux kernel memory barriers do not guarantee:
 
 ADDRESS-DEPENDENCY BARRIERS (HISTORICAL)
 ----------------------------------------
+[!] This section is marked as HISTORICAL: For more up-to-date information,
+including how compiler transformations related to pointer comparisons can
+sometimes cause problems, see Documentation/RCU/rcu_dereference.rst.
 
 As of v4.15 of the Linux kernel, an smp_mb() was added to READ_ONCE() for
 DEC Alpha, which means that about the only people who need to pay attention
Paul E. McKenney Aug. 4, 2023, 6:02 p.m. UTC | #5
On Fri, Aug 04, 2023 at 04:27:45PM +0000, Joel Fernandes wrote:
> On Fri, Aug 04, 2023 at 06:52:32AM -0700, Paul E. McKenney wrote:
> > On Fri, Aug 04, 2023 at 05:11:27AM +0000, Joel Fernandes wrote:
> > > On Thu, Aug 03, 2023 at 11:52:06AM -0700, Paul E. McKenney wrote:
> > > > On Thu, Aug 03, 2023 at 03:24:07AM +0000, Joel Fernandes (Google) wrote:
> > > > > The compiler has the ability to cause misordering by destroying
> > > > > address-dependency barriers if comparison operations are used. Add a
> > > > > note about this to memory-barriers.txt and point to rcu-dereference.rst
> > > > > for more information.
> > > > > 
> > > > > Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> > > > > ---
> > > > >  Documentation/memory-barriers.txt | 5 +++++
> > > > >  1 file changed, 5 insertions(+)
> > > > > 
> > > > > diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
> > > > > index 06e14efd8662..acc8ec5ce563 100644
> > > > > --- a/Documentation/memory-barriers.txt
> > > > > +++ b/Documentation/memory-barriers.txt
> > > > > @@ -435,6 +435,11 @@ Memory barriers come in four basic varieties:
> > > > >       variables such as READ_ONCE() and rcu_dereference() provide implicit
> > > > >       address-dependency barriers.
> > > > >  
> > > > > +     [!] Note that address dependency barriers can be destroyed by comparison
> > > > > +     of a pointer obtained by a marked accessor such as READ_ONCE() or
> > > > > +     rcu_dereference() with some value.  For an example of this, see
> > > > > +     rcu_dereference.rst (part where the comparison of pointers is discussed).
> > > > 
> > > > Hmmm...
> > > > 
> > > > Given that this is in a section marked "historical" (for the old
> > > > smp_read_barrier_depends() API), why not instead add a pointer to
> > > > Documentation/RCU/rcu_dereference.rst to the beginning of the section,
> > > > noted as the updated material?
> > > 
> > > Sounds good. There's also another section in the same file on Address
> > > dependency barriers (also marked historical). So something like the
> > > following?
> > 
> > Given a Signed-off-by and so forth, I would be happy to take this one.
> 
> Thank you for helping me improve the docs, here it goes:
> 
> ---8<-----------------------
> 
> From: "Joel Fernandes (Google)" <joel@joelfernandes.org>
> Subject: [PATCH] docs: memory-barriers: Add note on compiler transformation
>  and address deps
> 
> The compiler has the ability to cause misordering by destroying
> address-dependency barriers if comparison operations are used. Add a
> note about this to memory-barriers.txt in the beginning of both the
> historical address-dependency sections and point to rcu-dereference.rst
> for more information.
> 
> Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>

Queued and pushed, thank you!

							Thanx, Paul

> ---
>  Documentation/memory-barriers.txt | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
> index acc8ec5ce563..ba50220716ca 100644
> --- a/Documentation/memory-barriers.txt
> +++ b/Documentation/memory-barriers.txt
> @@ -396,6 +396,10 @@ Memory barriers come in four basic varieties:
>  
>  
>   (2) Address-dependency barriers (historical).
> +     [!] This section is marked as HISTORICAL: For more up-to-date
> +     information, including how compiler transformations related to pointer
> +     comparisons can sometimes cause problems, see
> +     Documentation/RCU/rcu_dereference.rst.
>  
>       An address-dependency barrier is a weaker form of read barrier.  In the
>       case where two loads are performed such that the second depends on the
> @@ -561,6 +565,9 @@ There are certain things that the Linux kernel memory barriers do not guarantee:
>  
>  ADDRESS-DEPENDENCY BARRIERS (HISTORICAL)
>  ----------------------------------------
> +[!] This section is marked as HISTORICAL: For more up-to-date information,
> +including how compiler transformations related to pointer comparisons can
> +sometimes cause problems, see Documentation/RCU/rcu_dereference.rst.
>  
>  As of v4.15 of the Linux kernel, an smp_mb() was added to READ_ONCE() for
>  DEC Alpha, which means that about the only people who need to pay attention
> -- 
> 2.41.0.585.gd2178a4bd4-goog
>
diff mbox series

Patch

diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
index 06e14efd8662..acc8ec5ce563 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -435,6 +435,11 @@  Memory barriers come in four basic varieties:
      variables such as READ_ONCE() and rcu_dereference() provide implicit
      address-dependency barriers.
 
+     [!] Note that address dependency barriers can be destroyed by comparison
+     of a pointer obtained by a marked accessor such as READ_ONCE() or
+     rcu_dereference() with some value.  For an example of this, see
+     rcu_dereference.rst (part where the comparison of pointers is discussed).
+
  (3) Read (or load) memory barriers.
 
      A read barrier is an address-dependency barrier plus a guarantee that all