All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org
Subject: Re: backport of patches 8238b4579866b7c1bb99883cfe102a43db5506ff and d6ffe6067a54972564552ea45d320fb98db1ac5e
Date: Tue, 11 Oct 2022 05:48:26 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LRH.2.02.2210110531260.30193@file01.intranet.prod.int.rdu2.redhat.com> (raw)
In-Reply-To: <Y0Rtkk7hA4CBwp16@kroah.com>



On Mon, 10 Oct 2022, Greg KH wrote:

> Nope, these cause loads of breakages.  See
> https://lore.kernel.org/r/09eca44e-4d91-a060-d48c-d0aa41ac5045@roeck-us.net
> for one such example, and I know kbuild sent you other build problems.
> I'll drop all of these from the stable trees now.  Please feel free to
> resend them when you have the build issues worked out.
> 
> thanks,
> 
> greg k-h

I don't have cross compilers for all the architectures that Linux 
supports. Is there some way how to have the patch compile-tested before I 
send it to you?

Or - would you accept this patch instead of the upstream patch? It fixes 
the same bug as the upstream patch, but it's noticeably smaller and it 
could be applied to the stable kernels 4.19 to 5.19.

Mikulas



From: Mikulas Patocka <mpatocka@redhat.com>

This fixes a bug that is fixed by the upstream patch 
8238b4579866b7c1bb99883cfe102a43db5506ff.

This patch differs from the upstream patch because backporting the 
upstream patch causes many build failures on various architectures.


Original commit message:

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>
Acked-by: Will Deacon <will@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>


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

Index: linux-stable/include/linux/wait_bit.h
===================================================================
--- linux-stable.orig/include/linux/wait_bit.h	2022-10-11 11:23:12.000000000 +0200
+++ linux-stable/include/linux/wait_bit.h	2022-10-11 11:24:33.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_rmb();
 		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_rmb();
 		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_rmb();
 		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_rmb();
 		return 0;
+	}
 	return out_of_line_wait_on_bit(word, bit, action, mode);
 }
 
Index: linux-stable/kernel/sched/wait_bit.c
===================================================================
--- linux-stable.orig/kernel/sched/wait_bit.c	2022-10-11 11:23:12.000000000 +0200
+++ linux-stable/kernel/sched/wait_bit.c	2022-10-11 11:25:22.000000000 +0200
@@ -51,6 +51,8 @@ __wait_on_bit(struct wait_queue_head *wq
 
 	finish_wait(wq_head, &wbq_entry->wq_entry);
 
+	smp_rmb();
+
 	return ret;
 }
 EXPORT_SYMBOL(__wait_on_bit);


  reply	other threads:[~2022-10-11  9:48 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=alpine.LRH.2.02.2210110531260.30193@file01.intranet.prod.int.rdu2.redhat.com \
    --to=mpatocka@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=stable@vger.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 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.