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);