All of lore.kernel.org
 help / color / mirror / Atom feed
* backport of patches 8238b4579866b7c1bb99883cfe102a43db5506ff and d6ffe6067a54972564552ea45d320fb98db1ac5e
@ 2022-09-30 15:32 Mikulas Patocka
  2022-09-30 15:33 ` [PATCH] wait_on_bit: add an acquire memory barrier Mikulas Patocka
                   ` (10 more replies)
  0 siblings, 11 replies; 48+ messages in thread
From: Mikulas Patocka @ 2022-09-30 15:32 UTC (permalink / raw)
  To: gregkh; +Cc: stable

Hi

Here I'm submitting backport of patches 
8238b4579866b7c1bb99883cfe102a43db5506ff and 
d6ffe6067a54972564552ea45d320fb98db1ac5e to the stable branches.

Mikulas


^ permalink raw reply	[flat|nested] 48+ messages in thread
* [PATCH] wait_on_bit: add an acquire memory barrier
@ 2022-08-22  9:38 Mikulas Patocka
  2022-08-22 17:08 ` Linus Torvalds
  0 siblings, 1 reply; 48+ messages in thread
From: Mikulas Patocka @ 2022-08-22  9:38 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Alan Stern, Andrea Parri, Will Deacon, Peter Zijlstra,
	Boqun Feng, Nicholas Piggin, David Howells, Jade Alglave,
	Luc Maranget, Paul E. McKenney, Akira Yokosawa, Daniel Lustig,
	Joel Fernandes, linux-kernel, linux-arch

Hi

I'd like to ask what do you think about this patch? Do you want to commit 
it - or do you think that the barrier should be added to the callers of 
wait_on_bit?

Mikulas



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 adding an acquire memory barrier to wait_on_bit,
wait_on_bit_io, wait_on_bit_timeout and wait_on_bit_action. The code that
uses these functions should clear the bit using the function
clear_bit_unlock.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org

---
 include/linux/wait_bit.h |   16 ++++++++++++----
 kernel/sched/wait_bit.c  |    2 ++
 2 files changed, 14 insertions(+), 4 deletions(-)

Index: linux-2.6/include/linux/wait_bit.h
===================================================================
--- linux-2.6.orig/include/linux/wait_bit.h	2022-08-20 14:33:44.000000000 +0200
+++ linux-2.6/include/linux/wait_bit.h	2022-08-20 15:41:43.000000000 +0200
@@ -71,8 +71,10 @@ static inline int
 wait_on_bit(unsigned long *word, int bit, unsigned mode)
 {
 	might_sleep();
-	if (!test_bit(bit, word))
+	if (!test_bit(bit, word)) {
+		smp_acquire__after_ctrl_dep();	/* should pair with clear_bit_unlock */
 		return 0;
+	}
 	return out_of_line_wait_on_bit(word, bit,
 				       bit_wait,
 				       mode);
@@ -96,8 +98,10 @@ static inline int
 wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
 {
 	might_sleep();
-	if (!test_bit(bit, word))
+	if (!test_bit(bit, word)) {
+		smp_acquire__after_ctrl_dep();	/* should pair with clear_bit_unlock */
 		return 0;
+	}
 	return out_of_line_wait_on_bit(word, bit,
 				       bit_wait_io,
 				       mode);
@@ -123,8 +127,10 @@ wait_on_bit_timeout(unsigned long *word,
 		    unsigned long timeout)
 {
 	might_sleep();
-	if (!test_bit(bit, word))
+	if (!test_bit(bit, word)) {
+		smp_acquire__after_ctrl_dep();	/* should pair with clear_bit_unlock */
 		return 0;
+	}
 	return out_of_line_wait_on_bit_timeout(word, bit,
 					       bit_wait_timeout,
 					       mode, timeout);
@@ -151,8 +157,10 @@ wait_on_bit_action(unsigned long *word,
 		   unsigned mode)
 {
 	might_sleep();
-	if (!test_bit(bit, word))
+	if (!test_bit(bit, word)) {
+		smp_acquire__after_ctrl_dep();	/* should pair with clear_bit_unlock */
 		return 0;
+	}
 	return out_of_line_wait_on_bit(word, bit, action, mode);
 }
 
Index: linux-2.6/kernel/sched/wait_bit.c
===================================================================
--- linux-2.6.orig/kernel/sched/wait_bit.c	2022-08-20 14:33:44.000000000 +0200
+++ linux-2.6/kernel/sched/wait_bit.c	2022-08-20 15:41:39.000000000 +0200
@@ -49,6 +49,8 @@ __wait_on_bit(struct wait_queue_head *wq
 			ret = (*action)(&wbq_entry->key, mode);
 	} while (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
 
+	smp_acquire__after_ctrl_dep();	/* should pair with clear_bit_unlock */
+
 	finish_wait(wq_head, &wbq_entry->wq_entry);
 
 	return ret;


^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2022-10-27 12:48 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-30 15:32 backport of patches 8238b4579866b7c1bb99883cfe102a43db5506ff and d6ffe6067a54972564552ea45d320fb98db1ac5e Mikulas Patocka
2022-09-30 15:33 ` [PATCH] wait_on_bit: add an acquire memory barrier Mikulas Patocka
2022-09-30 15:33 ` Mikulas Patocka
2022-09-30 15:34 ` Mikulas Patocka
2022-09-30 15:34 ` Mikulas Patocka
2022-09-30 15:34 ` Mikulas Patocka
2022-10-01  7:01   ` Greg KH
2022-09-30 15:35 ` [PATCH] provide arch_test_bit_acquire for architectures that define test_bit Mikulas Patocka
2022-09-30 15:35 ` Mikulas Patocka
2022-09-30 15:36 ` Mikulas Patocka
2022-09-30 15:36 ` Mikulas Patocka
2022-09-30 15:36 ` Mikulas Patocka
2022-10-01  7:00   ` Greg KH
2022-10-01  6:59 ` backport of patches 8238b4579866b7c1bb99883cfe102a43db5506ff and d6ffe6067a54972564552ea45d320fb98db1ac5e Greg KH
2022-10-03 12:28   ` Mikulas Patocka
2022-10-03 12:28     ` [PATCH] wait_on_bit: add an acquire memory barrier Mikulas Patocka
2022-10-03 12:29     ` Mikulas Patocka
2022-10-03 12:29     ` Mikulas Patocka
2022-10-03 12:29     ` Mikulas Patocka
2022-10-03 12:30     ` Mikulas Patocka
2022-10-03 12:30     ` [PATCH] provide arch_test_bit_acquire for architectures that define test_bit Mikulas Patocka
2022-10-03 12:31     ` Mikulas Patocka
2022-10-03 12:31     ` Mikulas Patocka
2022-10-03 12:31     ` Mikulas Patocka
2022-10-03 12:32     ` Mikulas Patocka
2022-10-05 16:48     ` backport of patches 8238b4579866b7c1bb99883cfe102a43db5506ff and d6ffe6067a54972564552ea45d320fb98db1ac5e Greg KH
2022-10-10 19:08       ` Greg KH
2022-10-11  9:48         ` Mikulas Patocka
2022-10-11  9:58           ` Greg KH
2022-10-18 11:36             ` Mikulas Patocka
2022-10-18 11:37               ` [PATCH] wait_on_bit: add an acquire memory barrier Mikulas Patocka
2022-10-18 11:37               ` Mikulas Patocka
2022-10-18 11:38               ` Mikulas Patocka
2022-10-18 11:38               ` Mikulas Patocka
2022-10-18 11:39               ` Mikulas Patocka
2022-10-18 11:39               ` Mikulas Patocka
2022-10-18 11:39               ` Mikulas Patocka
2022-10-26 17:01               ` backport of patches 8238b4579866b7c1bb99883cfe102a43db5506ff and d6ffe6067a54972564552ea45d320fb98db1ac5e Greg KH
2022-10-27 11:45                 ` Mikulas Patocka
2022-10-27 11:53                   ` Greg KH
2022-10-27 12:48                     ` Mikulas Patocka
  -- strict thread matches above, loose matches on Subject: below --
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-25 21:03     ` Mikulas Patocka
2022-08-25 21:54       ` Linus Torvalds
2022-08-26 13:17         ` [PATCH v3] " 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.