public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Andrea Parri <parri.andrea@gmail.com>,
	Will Deacon <will@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	Nicholas Piggin <npiggin@gmail.com>,
	David Howells <dhowells@redhat.com>,
	Jade Alglave <j.alglave@ucl.ac.uk>,
	Luc Maranget <luc.maranget@inria.fr>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Akira Yokosawa <akiyks@gmail.com>,
	Daniel Lustig <dlustig@nvidia.com>,
	Joel Fernandes <joel@joelfernandes.org>,
	linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org
Subject: Re: [PATCH] wait_on_bit: add an acquire memory barrier
Date: Thu, 25 Aug 2022 20:57:43 -0400	[thread overview]
Message-ID: <YwgahzfAlk9Jwaws@rowland.harvard.edu> (raw)
In-Reply-To: <alpine.LRH.2.02.2208251501200.31977@file01.intranet.prod.int.rdu2.redhat.com>

On Thu, Aug 25, 2022 at 05:03:40PM -0400, Mikulas Patocka wrote:
> From: Mikulas Patocka <mpatocka@redhat.com>
> 
> There are several places in the kernel where wait_on_bit is not followed
> by a memory barrier (for example, in drivers/md/dm-bufio.c:new_read). On
> architectures with weak memory ordering, it may happen that memory
> accesses that follow wait_on_bit are reordered before wait_on_bit and they
> may return invalid data.
> 
> Fix this class of bugs by introducing a new function "test_bit_acquire"
> that works like test_bit, but has acquire memory ordering semantics.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

...

> --- linux-2.6.orig/include/asm-generic/bitops/generic-non-atomic.h
> +++ linux-2.6/include/asm-generic/bitops/generic-non-atomic.h
> @@ -4,6 +4,7 @@
>  #define __ASM_GENERIC_BITOPS_GENERIC_NON_ATOMIC_H
>  
>  #include <linux/bits.h>
> +#include <asm/barrier.h>
>  
>  #ifndef _LINUX_BITOPS_H
>  #error only <linux/bitops.h> can be included directly
> @@ -127,6 +128,18 @@ generic_test_bit(unsigned long nr, const
>  	return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
>  }
>  
> +/**
> + * generic_test_bit - Determine whether a bit is set with acquire semantics

Trivial: Name in the kerneldoc isn't the same as the actual function name.

(Also, "with acquire semantics" is supposed to modify "Determine", not 
"is set" -- we don't set bits using acquire semantics.  You could change 
this to "Determine, with acquire semantics, whether a bit is set".)

Alan Stern

> + * @nr: bit number to test
> + * @addr: Address to start counting from
> + */
> +static __always_inline bool
> +generic_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
> +{
> +	unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
> +	return 1UL & (smp_load_acquire(p) >> (nr & (BITS_PER_LONG-1)));
> +}

  parent reply	other threads:[~2022-08-26  0:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-22  9:38 [PATCH] wait_on_bit: add an acquire memory barrier Mikulas Patocka
2022-08-22 17:08 ` Linus Torvalds
2022-08-22 17:39   ` Linus Torvalds
2022-08-22 18:00     ` Joel Fernandes
2022-08-25 21:03     ` Mikulas Patocka
2022-08-25 21:54       ` Linus Torvalds
2022-08-26 13:17         ` [PATCH v3] " Mikulas Patocka
2022-08-26 16:45           ` Linus Torvalds
2022-08-26 17:19             ` Linus Torvalds
2022-08-26 17:50               ` Mikulas Patocka
2022-08-26 19:23           ` Geert Uytterhoeven
2022-08-26 20:03             ` [PATCH] provide arch_test_bit_acquire for architectures that define test_bit Mikulas Patocka
2022-08-26 20:07               ` Linus Torvalds
2022-08-26 20:03             ` [PATCH v3] wait_on_bit: add an acquire memory barrier Linus Torvalds
2022-08-26 20:43               ` [PATCH] provide arch_test_bit_acquire for architectures that define test_bit Mikulas Patocka
2022-08-26 23:10                 ` Linus Torvalds
2022-08-26 23:18                   ` Linus Torvalds
2022-08-27 11:38                   ` Mikulas Patocka
2022-08-27 16:50                     ` Linus Torvalds
2022-08-26  0:57       ` Alan Stern [this message]
2022-08-26 11:23       ` [PATCH] wait_on_bit: add an acquire memory barrier Will Deacon
2022-08-26 11:46         ` Mikulas Patocka
2022-08-26 14:08           ` Mikulas Patocka
2022-08-26 17:43             ` Will Deacon
2022-08-26 18:25               ` Mikulas Patocka
2022-08-26 18:31                 ` Ard Biesheuvel
2022-08-26 19:10                   ` Mikulas Patocka
2022-08-27  6:32                     ` Ard Biesheuvel
2022-08-27  6:56                       ` Ard Biesheuvel
2022-08-27  8:42                         ` Mikulas Patocka

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=YwgahzfAlk9Jwaws@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=akiyks@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=dlustig@nvidia.com \
    --cc=j.alglave@ucl.ac.uk \
    --cc=joel@joelfernandes.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luc.maranget@inria.fr \
    --cc=mpatocka@redhat.com \
    --cc=npiggin@gmail.com \
    --cc=parri.andrea@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    --cc=will@kernel.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