]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
drop some test_bit patches from all queues
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 10 Oct 2022 19:09:36 +0000 (21:09 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 10 Oct 2022 19:09:36 +0000 (21:09 +0200)
Cause build breakages on some arches.

21 files changed:
queue-4.14/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch [deleted file]
queue-4.14/series
queue-4.14/wait_on_bit-add-an-acquire-memory-barrier.patch [deleted file]
queue-4.19/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch [deleted file]
queue-4.19/series
queue-4.19/wait_on_bit-add-an-acquire-memory-barrier.patch [deleted file]
queue-4.9/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch [deleted file]
queue-4.9/series
queue-4.9/wait_on_bit-add-an-acquire-memory-barrier.patch [deleted file]
queue-5.10/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch [deleted file]
queue-5.10/series
queue-5.10/wait_on_bit-add-an-acquire-memory-barrier.patch [deleted file]
queue-5.15/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch [deleted file]
queue-5.15/series
queue-5.15/wait_on_bit-add-an-acquire-memory-barrier.patch [deleted file]
queue-5.19/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch [deleted file]
queue-5.19/series
queue-5.19/wait_on_bit-add-an-acquire-memory-barrier.patch [deleted file]
queue-5.4/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch [deleted file]
queue-5.4/series
queue-5.4/wait_on_bit-add-an-acquire-memory-barrier.patch [deleted file]

diff --git a/queue-4.14/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch b/queue-4.14/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
deleted file mode 100644 (file)
index f8b514a..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-From d6ffe6067a54972564552ea45d320fb98db1ac5e Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 16:43:51 -0400
-Subject: provide arch_test_bit_acquire for architectures that define test_bit
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit d6ffe6067a54972564552ea45d320fb98db1ac5e upstream.
-
-Some architectures define their own arch_test_bit and they also need
-arch_test_bit_acquire, otherwise they won't compile.  We also clean up
-the code by using the generic test_bit if that is equivalent to the
-arch-specific version.
-
-Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
-Cc: stable@vger.kernel.org
-Fixes: 8238b4579866 ("wait_on_bit: add an acquire memory barrier")
-Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/alpha/include/asm/bitops.h   |    7 +++++++
- arch/hexagon/include/asm/bitops.h |   15 +++++++++++++++
- arch/ia64/include/asm/bitops.h    |    7 +++++++
- arch/m68k/include/asm/bitops.h    |    6 ++++++
- arch/s390/include/asm/bitops.h    |    7 +++++++
- arch/sh/include/asm/bitops-op32.h |    7 +++++++
- 6 files changed, 49 insertions(+)
-
---- a/arch/alpha/include/asm/bitops.h
-+++ b/arch/alpha/include/asm/bitops.h
-@@ -289,6 +289,13 @@ test_bit(int nr, const volatile void * a
-       return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) != 0UL;
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /*
-  * ffz = Find First Zero in word. Undefined if no zero exists,
-  * so code should check against ~0UL first..
---- a/arch/hexagon/include/asm/bitops.h
-+++ b/arch/hexagon/include/asm/bitops.h
-@@ -186,7 +186,22 @@ static inline int __test_bit(int nr, con
-       return retval;
- }
-+static inline int __test_bit_acquire(int nr, const volatile unsigned long *addr)
-+{
-+      int retval;
-+
-+      asm volatile(
-+      "{P0 = tstbit(%1,%2); if (P0.new) %0 = #1; if (!P0.new) %0 = #0;}\n"
-+      : "=&r" (retval)
-+      : "r" (addr[BIT_WORD(nr)]), "r" (nr % BITS_PER_LONG)
-+      : "p0", "memory"
-+      );
-+
-+      return retval;
-+}
-+
- #define test_bit(nr, addr) __test_bit(nr, addr)
-+#define test_bit_acquire(nr, addr) __test_bit_acquire(nr, addr)
- /*
-  * ffz - find first zero in word.
---- a/arch/ia64/include/asm/bitops.h
-+++ b/arch/ia64/include/asm/bitops.h
-@@ -337,6 +337,13 @@ test_bit (int nr, const volatile void *a
-       return 1 & (((const volatile __u32 *) addr)[nr >> 5] >> (nr & 31));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /**
-  * ffz - find the first zero bit in a long word
-  * @x: The long word to find the bit in
---- a/arch/m68k/include/asm/bitops.h
-+++ b/arch/m68k/include/asm/bitops.h
-@@ -153,6 +153,12 @@ static inline int test_bit(int nr, const
-       return (vaddr[nr >> 5] & (1UL << (nr & 31))) != 0;
- }
-+static __always_inline bool
-+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)));
-+}
- static inline int bset_reg_test_and_set_bit(int nr,
-                                           volatile unsigned long *vaddr)
---- a/arch/s390/include/asm/bitops.h
-+++ b/arch/s390/include/asm/bitops.h
-@@ -215,6 +215,13 @@ static inline int test_bit(unsigned long
-       return (*addr >> (nr & 7)) & 1;
- }
-+static __always_inline bool
-+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)));
-+}
-+
- static inline int test_and_set_bit_lock(unsigned long nr,
-                                       volatile unsigned long *ptr)
- {
---- a/arch/sh/include/asm/bitops-op32.h
-+++ b/arch/sh/include/asm/bitops-op32.h
-@@ -140,4 +140,11 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- #endif /* __ASM_SH_BITOPS_OP32_H */
index 16702bcd30c7925a6284a3cc3a0639b527a32a4b..dcaaf3e55173b47472831b452b7badf62b371a3a 100644 (file)
@@ -20,8 +20,6 @@ clk-iproc-do-not-rely-on-node-name-for-correct-pll-s.patch
 makefile.extrawarn-move-wcast-function-type-strict-to-w-1.patch
 i2c-dev-prevent-zero_size_ptr-deref-in-i2cdev_ioctl_rdwr.patch
 arm-fix-function-graph-tracer-and-unwinder-dependencies.patch
-wait_on_bit-add-an-acquire-memory-barrier.patch
-provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
 fs-fix-uaf-gpf-bug-in-nilfs_mdt_destroy.patch
 dmaengine-xilinx_dma-cleanup-for-fetching-xlnx-num-f.patch
 dmaengine-xilinx_dma-report-error-in-case-of-dma_set.patch
diff --git a/queue-4.14/wait_on_bit-add-an-acquire-memory-barrier.patch b/queue-4.14/wait_on_bit-add-an-acquire-memory-barrier.patch
deleted file mode 100644 (file)
index dc9bccd..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-From 8238b4579866b7c1bb99883cfe102a43db5506ff Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 09:17:08 -0400
-Subject: wait_on_bit: add an acquire memory barrier
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit 8238b4579866b7c1bb99883cfe102a43db5506ff upstream.
-
-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>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/x86/include/asm/bitops.h           |   21 +++++++++++++++++++++
- include/asm-generic/bitops/non-atomic.h |   14 ++++++++++++++
- include/linux/buffer_head.h             |    2 +-
- include/linux/wait_bit.h                |    8 ++++----
- kernel/sched/wait_bit.c                 |    2 +-
- 5 files changed, 41 insertions(+), 6 deletions(-)
-
---- a/arch/x86/include/asm/bitops.h
-+++ b/arch/x86/include/asm/bitops.h
-@@ -328,6 +328,20 @@ static __always_inline bool constant_tes
-               (addr[nr >> _BITOPS_LONG_SHIFT])) != 0;
- }
-+static __always_inline bool constant_test_bit_acquire(long nr, const volatile unsigned long *addr)
-+{
-+      bool oldbit;
-+
-+      asm volatile("testb %2,%1"
-+                   CC_SET(nz)
-+                   : CC_OUT(nz) (oldbit)
-+                   : "m" (((unsigned char *)addr)[nr >> 3]),
-+                     "i" (1 << (nr & 7))
-+                   :"memory");
-+
-+      return oldbit;
-+}
-+
- static __always_inline bool variable_test_bit(long nr, volatile const unsigned long *addr)
- {
-       bool oldbit;
-@@ -354,6 +368,13 @@ static bool test_bit(int nr, const volat
-        ? constant_test_bit((nr), (addr))      \
-        : variable_test_bit((nr), (addr)))
-+static __always_inline bool
-+test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
-+{
-+      return __builtin_constant_p(nr) ? constant_test_bit_acquire(nr, addr) :
-+                                        variable_test_bit(nr, addr);
-+}
-+
- /**
-  * __ffs - find first set bit in word
-  * @word: The word to search
---- a/include/asm-generic/bitops/non-atomic.h
-+++ b/include/asm-generic/bitops/non-atomic.h
-@@ -3,6 +3,7 @@
- #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
- #include <asm/types.h>
-+#include <asm/barrier.h>
- /**
-  * __set_bit - Set a bit in memory
-@@ -106,4 +107,17 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+/**
-+ * arch_test_bit_acquire - Determine, with acquire semantics, whether a bit is set
-+ * @nr: bit number to test
-+ * @addr: Address to start counting from
-+ */
-+static __always_inline bool
-+arch_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)));
-+}
-+#define test_bit_acquire arch_test_bit_acquire
-+
- #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
---- a/include/linux/buffer_head.h
-+++ b/include/linux/buffer_head.h
-@@ -163,7 +163,7 @@ static __always_inline int buffer_uptoda
-        * make it consistent with folio_test_uptodate
-        * pairs with smp_mb__before_atomic in set_buffer_uptodate
-        */
--      return (smp_load_acquire(&bh->b_state) & (1UL << BH_Uptodate)) != 0;
-+      return test_bit_acquire(BH_Uptodate, &bh->b_state);
- }
- #define bh_offset(bh)         ((unsigned long)(bh)->b_data & ~PAGE_MASK)
---- a/include/linux/wait_bit.h
-+++ b/include/linux/wait_bit.h
-@@ -76,7 +76,7 @@ static inline int
- wait_on_bit(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait,
-@@ -101,7 +101,7 @@ static inline int
- wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait_io,
-@@ -128,7 +128,7 @@ wait_on_bit_timeout(unsigned long *word,
-                   unsigned long timeout)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit_timeout(word, bit,
-                                              bit_wait_timeout,
-@@ -156,7 +156,7 @@ wait_on_bit_action(unsigned long *word,
-                  unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit, action, mode);
- }
---- a/kernel/sched/wait_bit.c
-+++ b/kernel/sched/wait_bit.c
-@@ -49,7 +49,7 @@ __wait_on_bit(struct wait_queue_head *wq
-               prepare_to_wait(wq_head, &wbq_entry->wq_entry, mode);
-               if (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags))
-                       ret = (*action)(&wbq_entry->key, mode);
--      } while (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-+      } while (test_bit_acquire(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-       finish_wait(wq_head, &wbq_entry->wq_entry);
-       return ret;
- }
diff --git a/queue-4.19/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch b/queue-4.19/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
deleted file mode 100644 (file)
index f8b514a..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-From d6ffe6067a54972564552ea45d320fb98db1ac5e Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 16:43:51 -0400
-Subject: provide arch_test_bit_acquire for architectures that define test_bit
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit d6ffe6067a54972564552ea45d320fb98db1ac5e upstream.
-
-Some architectures define their own arch_test_bit and they also need
-arch_test_bit_acquire, otherwise they won't compile.  We also clean up
-the code by using the generic test_bit if that is equivalent to the
-arch-specific version.
-
-Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
-Cc: stable@vger.kernel.org
-Fixes: 8238b4579866 ("wait_on_bit: add an acquire memory barrier")
-Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/alpha/include/asm/bitops.h   |    7 +++++++
- arch/hexagon/include/asm/bitops.h |   15 +++++++++++++++
- arch/ia64/include/asm/bitops.h    |    7 +++++++
- arch/m68k/include/asm/bitops.h    |    6 ++++++
- arch/s390/include/asm/bitops.h    |    7 +++++++
- arch/sh/include/asm/bitops-op32.h |    7 +++++++
- 6 files changed, 49 insertions(+)
-
---- a/arch/alpha/include/asm/bitops.h
-+++ b/arch/alpha/include/asm/bitops.h
-@@ -289,6 +289,13 @@ test_bit(int nr, const volatile void * a
-       return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) != 0UL;
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /*
-  * ffz = Find First Zero in word. Undefined if no zero exists,
-  * so code should check against ~0UL first..
---- a/arch/hexagon/include/asm/bitops.h
-+++ b/arch/hexagon/include/asm/bitops.h
-@@ -186,7 +186,22 @@ static inline int __test_bit(int nr, con
-       return retval;
- }
-+static inline int __test_bit_acquire(int nr, const volatile unsigned long *addr)
-+{
-+      int retval;
-+
-+      asm volatile(
-+      "{P0 = tstbit(%1,%2); if (P0.new) %0 = #1; if (!P0.new) %0 = #0;}\n"
-+      : "=&r" (retval)
-+      : "r" (addr[BIT_WORD(nr)]), "r" (nr % BITS_PER_LONG)
-+      : "p0", "memory"
-+      );
-+
-+      return retval;
-+}
-+
- #define test_bit(nr, addr) __test_bit(nr, addr)
-+#define test_bit_acquire(nr, addr) __test_bit_acquire(nr, addr)
- /*
-  * ffz - find first zero in word.
---- a/arch/ia64/include/asm/bitops.h
-+++ b/arch/ia64/include/asm/bitops.h
-@@ -337,6 +337,13 @@ test_bit (int nr, const volatile void *a
-       return 1 & (((const volatile __u32 *) addr)[nr >> 5] >> (nr & 31));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /**
-  * ffz - find the first zero bit in a long word
-  * @x: The long word to find the bit in
---- a/arch/m68k/include/asm/bitops.h
-+++ b/arch/m68k/include/asm/bitops.h
-@@ -153,6 +153,12 @@ static inline int test_bit(int nr, const
-       return (vaddr[nr >> 5] & (1UL << (nr & 31))) != 0;
- }
-+static __always_inline bool
-+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)));
-+}
- static inline int bset_reg_test_and_set_bit(int nr,
-                                           volatile unsigned long *vaddr)
---- a/arch/s390/include/asm/bitops.h
-+++ b/arch/s390/include/asm/bitops.h
-@@ -215,6 +215,13 @@ static inline int test_bit(unsigned long
-       return (*addr >> (nr & 7)) & 1;
- }
-+static __always_inline bool
-+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)));
-+}
-+
- static inline int test_and_set_bit_lock(unsigned long nr,
-                                       volatile unsigned long *ptr)
- {
---- a/arch/sh/include/asm/bitops-op32.h
-+++ b/arch/sh/include/asm/bitops-op32.h
-@@ -140,4 +140,11 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- #endif /* __ASM_SH_BITOPS_OP32_H */
index f6aff406a5f57c71def5dc5f39fb1a28089a1575..08cacd0f59ebe6eaf9733e87876630c47c2fa26d 100644 (file)
@@ -1,8 +1,6 @@
 makefile.extrawarn-move-wcast-function-type-strict-to-w-1.patch
 docs-update-mediator-information-in-coc-docs.patch
 arm-fix-function-graph-tracer-and-unwinder-dependencies.patch
-wait_on_bit-add-an-acquire-memory-barrier.patch
-provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
 fs-fix-uaf-gpf-bug-in-nilfs_mdt_destroy.patch
 firmware-arm_scmi-add-scmi-pm-driver-remove-routine.patch
 dmaengine-xilinx_dma-cleanup-for-fetching-xlnx-num-f.patch
diff --git a/queue-4.19/wait_on_bit-add-an-acquire-memory-barrier.patch b/queue-4.19/wait_on_bit-add-an-acquire-memory-barrier.patch
deleted file mode 100644 (file)
index 03aeaa9..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-From 8238b4579866b7c1bb99883cfe102a43db5506ff Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 09:17:08 -0400
-Subject: wait_on_bit: add an acquire memory barrier
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit 8238b4579866b7c1bb99883cfe102a43db5506ff upstream.
-
-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>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/x86/include/asm/bitops.h           |   21 +++++++++++++++++++++
- include/asm-generic/bitops/non-atomic.h |   14 ++++++++++++++
- include/linux/buffer_head.h             |    2 +-
- include/linux/wait_bit.h                |    8 ++++----
- kernel/sched/wait_bit.c                 |    2 +-
- 5 files changed, 41 insertions(+), 6 deletions(-)
-
---- a/arch/x86/include/asm/bitops.h
-+++ b/arch/x86/include/asm/bitops.h
-@@ -317,6 +317,20 @@ static __always_inline bool constant_tes
-               (addr[nr >> _BITOPS_LONG_SHIFT])) != 0;
- }
-+static __always_inline bool constant_test_bit_acquire(long nr, const volatile unsigned long *addr)
-+{
-+      bool oldbit;
-+
-+      asm volatile("testb %2,%1"
-+                   CC_SET(nz)
-+                   : CC_OUT(nz) (oldbit)
-+                   : "m" (((unsigned char *)addr)[nr >> 3]),
-+                     "i" (1 << (nr & 7))
-+                   :"memory");
-+
-+      return oldbit;
-+}
-+
- static __always_inline bool variable_test_bit(long nr, volatile const unsigned long *addr)
- {
-       bool oldbit;
-@@ -343,6 +357,13 @@ static bool test_bit(int nr, const volat
-        ? constant_test_bit((nr), (addr))      \
-        : variable_test_bit((nr), (addr)))
-+static __always_inline bool
-+test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
-+{
-+      return __builtin_constant_p(nr) ? constant_test_bit_acquire(nr, addr) :
-+                                        variable_test_bit(nr, addr);
-+}
-+
- /**
-  * __ffs - find first set bit in word
-  * @word: The word to search
---- a/include/asm-generic/bitops/non-atomic.h
-+++ b/include/asm-generic/bitops/non-atomic.h
-@@ -3,6 +3,7 @@
- #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
- #include <asm/types.h>
-+#include <asm/barrier.h>
- /**
-  * __set_bit - Set a bit in memory
-@@ -106,4 +107,17 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+/**
-+ * arch_test_bit_acquire - Determine, with acquire semantics, whether a bit is set
-+ * @nr: bit number to test
-+ * @addr: Address to start counting from
-+ */
-+static __always_inline bool
-+arch_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)));
-+}
-+#define test_bit_acquire arch_test_bit_acquire
-+
- #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
---- a/include/linux/buffer_head.h
-+++ b/include/linux/buffer_head.h
-@@ -166,7 +166,7 @@ static __always_inline int buffer_uptoda
-        * make it consistent with folio_test_uptodate
-        * pairs with smp_mb__before_atomic in set_buffer_uptodate
-        */
--      return (smp_load_acquire(&bh->b_state) & (1UL << BH_Uptodate)) != 0;
-+      return test_bit_acquire(BH_Uptodate, &bh->b_state);
- }
- #define bh_offset(bh)         ((unsigned long)(bh)->b_data & ~PAGE_MASK)
---- a/include/linux/wait_bit.h
-+++ b/include/linux/wait_bit.h
-@@ -71,7 +71,7 @@ static inline int
- wait_on_bit(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait,
-@@ -96,7 +96,7 @@ static inline int
- wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait_io,
-@@ -123,7 +123,7 @@ wait_on_bit_timeout(unsigned long *word,
-                   unsigned long timeout)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit_timeout(word, bit,
-                                              bit_wait_timeout,
-@@ -151,7 +151,7 @@ wait_on_bit_action(unsigned long *word,
-                  unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit, action, mode);
- }
---- a/kernel/sched/wait_bit.c
-+++ b/kernel/sched/wait_bit.c
-@@ -46,7 +46,7 @@ __wait_on_bit(struct wait_queue_head *wq
-               prepare_to_wait(wq_head, &wbq_entry->wq_entry, mode);
-               if (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags))
-                       ret = (*action)(&wbq_entry->key, mode);
--      } while (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-+      } while (test_bit_acquire(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-       finish_wait(wq_head, &wbq_entry->wq_entry);
diff --git a/queue-4.9/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch b/queue-4.9/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
deleted file mode 100644 (file)
index d91fd5a..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-From d6ffe6067a54972564552ea45d320fb98db1ac5e Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 16:43:51 -0400
-Subject: provide arch_test_bit_acquire for architectures that define test_bit
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit d6ffe6067a54972564552ea45d320fb98db1ac5e upstream.
-
-Some architectures define their own arch_test_bit and they also need
-arch_test_bit_acquire, otherwise they won't compile.  We also clean up
-the code by using the generic test_bit if that is equivalent to the
-arch-specific version.
-
-Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
-Cc: stable@vger.kernel.org
-Fixes: 8238b4579866 ("wait_on_bit: add an acquire memory barrier")
-Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/alpha/include/asm/bitops.h   |    7 +++++++
- arch/hexagon/include/asm/bitops.h |   15 +++++++++++++++
- arch/ia64/include/asm/bitops.h    |    7 +++++++
- arch/m68k/include/asm/bitops.h    |    6 ++++++
- arch/s390/include/asm/bitops.h    |    7 +++++++
- arch/sh/include/asm/bitops-op32.h |    7 +++++++
- 6 files changed, 49 insertions(+)
-
---- a/arch/alpha/include/asm/bitops.h
-+++ b/arch/alpha/include/asm/bitops.h
-@@ -288,6 +288,13 @@ test_bit(int nr, const volatile void * a
-       return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) != 0UL;
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /*
-  * ffz = Find First Zero in word. Undefined if no zero exists,
-  * so code should check against ~0UL first..
---- a/arch/hexagon/include/asm/bitops.h
-+++ b/arch/hexagon/include/asm/bitops.h
-@@ -186,7 +186,22 @@ static inline int __test_bit(int nr, con
-       return retval;
- }
-+static inline int __test_bit_acquire(int nr, const volatile unsigned long *addr)
-+{
-+      int retval;
-+
-+      asm volatile(
-+      "{P0 = tstbit(%1,%2); if (P0.new) %0 = #1; if (!P0.new) %0 = #0;}\n"
-+      : "=&r" (retval)
-+      : "r" (addr[BIT_WORD(nr)]), "r" (nr % BITS_PER_LONG)
-+      : "p0", "memory"
-+      );
-+
-+      return retval;
-+}
-+
- #define test_bit(nr, addr) __test_bit(nr, addr)
-+#define test_bit_acquire(nr, addr) __test_bit_acquire(nr, addr)
- /*
-  * ffz - find first zero in word.
---- a/arch/ia64/include/asm/bitops.h
-+++ b/arch/ia64/include/asm/bitops.h
-@@ -336,6 +336,13 @@ test_bit (int nr, const volatile void *a
-       return 1 & (((const volatile __u32 *) addr)[nr >> 5] >> (nr & 31));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /**
-  * ffz - find the first zero bit in a long word
-  * @x: The long word to find the bit in
---- a/arch/m68k/include/asm/bitops.h
-+++ b/arch/m68k/include/asm/bitops.h
-@@ -153,6 +153,12 @@ static inline int test_bit(int nr, const
-       return (vaddr[nr >> 5] & (1UL << (nr & 31))) != 0;
- }
-+static __always_inline bool
-+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)));
-+}
- static inline int bset_reg_test_and_set_bit(int nr,
-                                           volatile unsigned long *vaddr)
---- a/arch/s390/include/asm/bitops.h
-+++ b/arch/s390/include/asm/bitops.h
-@@ -270,6 +270,13 @@ static inline int test_bit(unsigned long
-       return (*addr >> (nr & 7)) & 1;
- }
-+static __always_inline bool
-+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)));
-+}
-+
- static inline int test_and_set_bit_lock(unsigned long nr,
-                                       volatile unsigned long *ptr)
- {
---- a/arch/sh/include/asm/bitops-op32.h
-+++ b/arch/sh/include/asm/bitops-op32.h
-@@ -139,4 +139,11 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- #endif /* __ASM_SH_BITOPS_OP32_H */
index 20e39b9067cd43da1b6c0c83cbd88a5c4386293a..4bc97ad7770b0b836fdc9ea492dcdb918746ee26 100644 (file)
@@ -15,8 +15,6 @@ clk-iproc-minor-tidy-up-of-iproc-pll-data-structures.patch
 clk-iproc-do-not-rely-on-node-name-for-correct-pll-s.patch
 makefile.extrawarn-move-wcast-function-type-strict-to-w-1.patch
 arm-fix-function-graph-tracer-and-unwinder-dependencies.patch
-wait_on_bit-add-an-acquire-memory-barrier.patch
-provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
 fs-fix-uaf-gpf-bug-in-nilfs_mdt_destroy.patch
 dmaengine-xilinx_dma-cleanup-for-fetching-xlnx-num-f.patch
 dmaengine-xilinx_dma-report-error-in-case-of-dma_set.patch
diff --git a/queue-4.9/wait_on_bit-add-an-acquire-memory-barrier.patch b/queue-4.9/wait_on_bit-add-an-acquire-memory-barrier.patch
deleted file mode 100644 (file)
index 9ec67d9..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-From 8238b4579866b7c1bb99883cfe102a43db5506ff Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 09:17:08 -0400
-Subject: wait_on_bit: add an acquire memory barrier
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit 8238b4579866b7c1bb99883cfe102a43db5506ff upstream.
-
-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>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/x86/include/asm/bitops.h           |   21 +++++++++++++++++++++
- include/asm-generic/bitops/non-atomic.h |   14 ++++++++++++++
- include/linux/buffer_head.h             |    2 +-
- include/linux/wait.h                    |    8 ++++----
- kernel/sched/wait.c                     |    2 +-
- 5 files changed, 41 insertions(+), 6 deletions(-)
-
---- a/arch/x86/include/asm/bitops.h
-+++ b/arch/x86/include/asm/bitops.h
-@@ -314,6 +314,20 @@ static __always_inline bool constant_tes
-               (addr[nr >> _BITOPS_LONG_SHIFT])) != 0;
- }
-+static __always_inline bool constant_test_bit_acquire(long nr, const volatile unsigned long *addr)
-+{
-+      bool oldbit;
-+
-+      asm volatile("testb %2,%1"
-+                   CC_SET(nz)
-+                   : CC_OUT(nz) (oldbit)
-+                   : "m" (((unsigned char *)addr)[nr >> 3]),
-+                     "i" (1 << (nr & 7))
-+                   :"memory");
-+
-+      return oldbit;
-+}
-+
- static __always_inline bool variable_test_bit(long nr, volatile const unsigned long *addr)
- {
-       bool oldbit;
-@@ -340,6 +354,13 @@ static bool test_bit(int nr, const volat
-        ? constant_test_bit((nr), (addr))      \
-        : variable_test_bit((nr), (addr)))
-+static __always_inline bool
-+test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
-+{
-+      return __builtin_constant_p(nr) ? constant_test_bit_acquire(nr, addr) :
-+                                        variable_test_bit(nr, addr);
-+}
-+
- /**
-  * __ffs - find first set bit in word
-  * @word: The word to search
---- a/include/asm-generic/bitops/non-atomic.h
-+++ b/include/asm-generic/bitops/non-atomic.h
-@@ -2,6 +2,7 @@
- #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
- #include <asm/types.h>
-+#include <asm/barrier.h>
- /**
-  * __set_bit - Set a bit in memory
-@@ -105,4 +106,17 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+/**
-+ * arch_test_bit_acquire - Determine, with acquire semantics, whether a bit is set
-+ * @nr: bit number to test
-+ * @addr: Address to start counting from
-+ */
-+static __always_inline bool
-+arch_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)));
-+}
-+#define test_bit_acquire arch_test_bit_acquire
-+
- #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
---- a/include/linux/buffer_head.h
-+++ b/include/linux/buffer_head.h
-@@ -162,7 +162,7 @@ static __always_inline int buffer_uptoda
-        * make it consistent with folio_test_uptodate
-        * pairs with smp_mb__before_atomic in set_buffer_uptodate
-        */
--      return (smp_load_acquire(&bh->b_state) & (1UL << BH_Uptodate)) != 0;
-+      return test_bit_acquire(BH_Uptodate, &bh->b_state);
- }
- #define bh_offset(bh)         ((unsigned long)(bh)->b_data & ~PAGE_MASK)
---- a/include/linux/wait.h
-+++ b/include/linux/wait.h
-@@ -1066,7 +1066,7 @@ static inline int
- wait_on_bit(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait,
-@@ -1091,7 +1091,7 @@ static inline int
- wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait_io,
-@@ -1118,7 +1118,7 @@ wait_on_bit_timeout(unsigned long *word,
-                   unsigned long timeout)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit_timeout(word, bit,
-                                              bit_wait_timeout,
-@@ -1146,7 +1146,7 @@ wait_on_bit_action(unsigned long *word,
-                  unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit, action, mode);
- }
---- a/kernel/sched/wait.c
-+++ b/kernel/sched/wait.c
-@@ -389,7 +389,7 @@ __wait_on_bit(wait_queue_head_t *wq, str
-               prepare_to_wait(wq, &q->wait, mode);
-               if (test_bit(q->key.bit_nr, q->key.flags))
-                       ret = (*action)(&q->key, mode);
--      } while (test_bit(q->key.bit_nr, q->key.flags) && !ret);
-+      } while (test_bit_acquire(q->key.bit_nr, q->key.flags) && !ret);
-       finish_wait(wq, &q->wait);
-       return ret;
- }
diff --git a/queue-5.10/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch b/queue-5.10/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
deleted file mode 100644 (file)
index 372c0ce..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-From d6ffe6067a54972564552ea45d320fb98db1ac5e Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 16:43:51 -0400
-Subject: provide arch_test_bit_acquire for architectures that define test_bit
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit d6ffe6067a54972564552ea45d320fb98db1ac5e upstream.
-
-Some architectures define their own arch_test_bit and they also need
-arch_test_bit_acquire, otherwise they won't compile.  We also clean up
-the code by using the generic test_bit if that is equivalent to the
-arch-specific version.
-
-Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
-Cc: stable@vger.kernel.org
-Fixes: 8238b4579866 ("wait_on_bit: add an acquire memory barrier")
-Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/alpha/include/asm/bitops.h   |    7 +++++++
- arch/hexagon/include/asm/bitops.h |   15 +++++++++++++++
- arch/ia64/include/asm/bitops.h    |    7 +++++++
- arch/m68k/include/asm/bitops.h    |    6 ++++++
- arch/s390/include/asm/bitops.h    |    7 +++++++
- arch/sh/include/asm/bitops-op32.h |    7 +++++++
- 6 files changed, 49 insertions(+)
-
---- a/arch/alpha/include/asm/bitops.h
-+++ b/arch/alpha/include/asm/bitops.h
-@@ -289,6 +289,13 @@ test_bit(int nr, const volatile void * a
-       return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) != 0UL;
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /*
-  * ffz = Find First Zero in word. Undefined if no zero exists,
-  * so code should check against ~0UL first..
---- a/arch/hexagon/include/asm/bitops.h
-+++ b/arch/hexagon/include/asm/bitops.h
-@@ -172,7 +172,22 @@ static inline int __test_bit(int nr, con
-       return retval;
- }
-+static inline int __test_bit_acquire(int nr, const volatile unsigned long *addr)
-+{
-+      int retval;
-+
-+      asm volatile(
-+      "{P0 = tstbit(%1,%2); if (P0.new) %0 = #1; if (!P0.new) %0 = #0;}\n"
-+      : "=&r" (retval)
-+      : "r" (addr[BIT_WORD(nr)]), "r" (nr % BITS_PER_LONG)
-+      : "p0", "memory"
-+      );
-+
-+      return retval;
-+}
-+
- #define test_bit(nr, addr) __test_bit(nr, addr)
-+#define test_bit_acquire(nr, addr) __test_bit_acquire(nr, addr)
- /*
-  * ffz - find first zero in word.
---- a/arch/ia64/include/asm/bitops.h
-+++ b/arch/ia64/include/asm/bitops.h
-@@ -337,6 +337,13 @@ test_bit (int nr, const volatile void *a
-       return 1 & (((const volatile __u32 *) addr)[nr >> 5] >> (nr & 31));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /**
-  * ffz - find the first zero bit in a long word
-  * @x: The long word to find the bit in
---- a/arch/m68k/include/asm/bitops.h
-+++ b/arch/m68k/include/asm/bitops.h
-@@ -153,6 +153,12 @@ static inline int test_bit(int nr, const
-       return (vaddr[nr >> 5] & (1UL << (nr & 31))) != 0;
- }
-+static __always_inline bool
-+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)));
-+}
- static inline int bset_reg_test_and_set_bit(int nr,
-                                           volatile unsigned long *vaddr)
---- a/arch/s390/include/asm/bitops.h
-+++ b/arch/s390/include/asm/bitops.h
-@@ -219,6 +219,13 @@ static inline bool arch_test_bit(unsigne
-       return (*addr >> (nr & 7)) & 1;
- }
-+static __always_inline bool
-+arch_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)));
-+}
-+
- static inline bool arch_test_and_set_bit_lock(unsigned long nr,
-                                             volatile unsigned long *ptr)
- {
---- a/arch/sh/include/asm/bitops-op32.h
-+++ b/arch/sh/include/asm/bitops-op32.h
-@@ -138,4 +138,11 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- #endif /* __ASM_SH_BITOPS_OP32_H */
index 33ab4fb89890a44f704d021280244533b45f5128..066a5be7bd698fbf07b357dd2e3cb1469060346a 100644 (file)
@@ -5,8 +5,6 @@ xsk-inherit-need_wakeup-flag-for-shared-sockets.patch
 alsa-pcm-oss-fix-race-at-sndctl_dsp_sync.patch
 mm-gup-fix-the-fast-gup-race-against-thp-collapse.patch
 powerpc-64s-radix-don-t-need-to-broadcast-ipi-for-radix-pmd-collapse-flush.patch
-wait_on_bit-add-an-acquire-memory-barrier.patch
-provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
 fs-fix-uaf-gpf-bug-in-nilfs_mdt_destroy.patch
 compiler_attributes.h-move-__compiletime_-error-warning.patch
 firmware-arm_scmi-add-scmi-pm-driver-remove-routine.patch
diff --git a/queue-5.10/wait_on_bit-add-an-acquire-memory-barrier.patch b/queue-5.10/wait_on_bit-add-an-acquire-memory-barrier.patch
deleted file mode 100644 (file)
index 93bceab..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-From 8238b4579866b7c1bb99883cfe102a43db5506ff Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 09:17:08 -0400
-Subject: wait_on_bit: add an acquire memory barrier
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit 8238b4579866b7c1bb99883cfe102a43db5506ff upstream.
-
-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>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/x86/include/asm/bitops.h                        |   21 +++++++++++++++++++
- include/asm-generic/bitops/instrumented-non-atomic.h |   12 ++++++++++
- include/asm-generic/bitops/non-atomic.h              |   14 ++++++++++++
- include/linux/buffer_head.h                          |    2 -
- include/linux/wait_bit.h                             |    8 +++----
- kernel/sched/wait_bit.c                              |    2 -
- 6 files changed, 53 insertions(+), 6 deletions(-)
-
---- a/arch/x86/include/asm/bitops.h
-+++ b/arch/x86/include/asm/bitops.h
-@@ -207,6 +207,20 @@ static __always_inline bool constant_tes
-               (addr[nr >> _BITOPS_LONG_SHIFT])) != 0;
- }
-+static __always_inline bool constant_test_bit_acquire(long nr, const volatile unsigned long *addr)
-+{
-+      bool oldbit;
-+
-+      asm volatile("testb %2,%1"
-+                   CC_SET(nz)
-+                   : CC_OUT(nz) (oldbit)
-+                   : "m" (((unsigned char *)addr)[nr >> 3]),
-+                     "i" (1 << (nr & 7))
-+                   :"memory");
-+
-+      return oldbit;
-+}
-+
- static __always_inline bool variable_test_bit(long nr, volatile const unsigned long *addr)
- {
-       bool oldbit;
-@@ -224,6 +238,13 @@ static __always_inline bool variable_tes
-        ? constant_test_bit((nr), (addr))      \
-        : variable_test_bit((nr), (addr)))
-+static __always_inline bool
-+arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
-+{
-+      return __builtin_constant_p(nr) ? constant_test_bit_acquire(nr, addr) :
-+                                        variable_test_bit(nr, addr);
-+}
-+
- /**
-  * __ffs - find first set bit in word
-  * @word: The word to search
---- a/include/asm-generic/bitops/instrumented-non-atomic.h
-+++ b/include/asm-generic/bitops/instrumented-non-atomic.h
-@@ -135,4 +135,16 @@ static inline bool test_bit(long nr, con
-       return arch_test_bit(nr, addr);
- }
-+/**
-+ * _test_bit_acquire - Determine, with acquire semantics, whether a bit is set
-+ * @nr: bit number to test
-+ * @addr: Address to start counting from
-+ */
-+static __always_inline bool
-+test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
-+{
-+      instrument_atomic_read(addr + BIT_WORD(nr), sizeof(long));
-+      return arch_test_bit_acquire(nr, addr);
-+}
-+
- #endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */
---- a/include/asm-generic/bitops/non-atomic.h
-+++ b/include/asm-generic/bitops/non-atomic.h
-@@ -3,6 +3,7 @@
- #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
- #include <asm/types.h>
-+#include <asm/barrier.h>
- /**
-  * __set_bit - Set a bit in memory
-@@ -106,4 +107,17 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+/**
-+ * arch_test_bit_acquire - Determine, with acquire semantics, whether a bit is set
-+ * @nr: bit number to test
-+ * @addr: Address to start counting from
-+ */
-+static __always_inline bool
-+arch_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)));
-+}
-+#define test_bit_acquire arch_test_bit_acquire
-+
- #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
---- a/include/linux/buffer_head.h
-+++ b/include/linux/buffer_head.h
-@@ -166,7 +166,7 @@ static __always_inline int buffer_uptoda
-        * make it consistent with folio_test_uptodate
-        * pairs with smp_mb__before_atomic in set_buffer_uptodate
-        */
--      return (smp_load_acquire(&bh->b_state) & (1UL << BH_Uptodate)) != 0;
-+      return test_bit_acquire(BH_Uptodate, &bh->b_state);
- }
- #define bh_offset(bh)         ((unsigned long)(bh)->b_data & ~PAGE_MASK)
---- a/include/linux/wait_bit.h
-+++ b/include/linux/wait_bit.h
-@@ -71,7 +71,7 @@ static inline int
- wait_on_bit(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait,
-@@ -96,7 +96,7 @@ static inline int
- wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait_io,
-@@ -123,7 +123,7 @@ wait_on_bit_timeout(unsigned long *word,
-                   unsigned long timeout)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit_timeout(word, bit,
-                                              bit_wait_timeout,
-@@ -151,7 +151,7 @@ wait_on_bit_action(unsigned long *word,
-                  unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit, action, mode);
- }
---- a/kernel/sched/wait_bit.c
-+++ b/kernel/sched/wait_bit.c
-@@ -47,7 +47,7 @@ __wait_on_bit(struct wait_queue_head *wq
-               prepare_to_wait(wq_head, &wbq_entry->wq_entry, mode);
-               if (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags))
-                       ret = (*action)(&wbq_entry->key, mode);
--      } while (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-+      } while (test_bit_acquire(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-       finish_wait(wq_head, &wbq_entry->wq_entry);
diff --git a/queue-5.15/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch b/queue-5.15/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
deleted file mode 100644 (file)
index 9255480..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-From d6ffe6067a54972564552ea45d320fb98db1ac5e Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 16:43:51 -0400
-Subject: provide arch_test_bit_acquire for architectures that define test_bit
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit d6ffe6067a54972564552ea45d320fb98db1ac5e upstream.
-
-Some architectures define their own arch_test_bit and they also need
-arch_test_bit_acquire, otherwise they won't compile.  We also clean up
-the code by using the generic test_bit if that is equivalent to the
-arch-specific version.
-
-Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
-Cc: stable@vger.kernel.org
-Fixes: 8238b4579866 ("wait_on_bit: add an acquire memory barrier")
-Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/alpha/include/asm/bitops.h   |    7 +++++++
- arch/hexagon/include/asm/bitops.h |   15 +++++++++++++++
- arch/ia64/include/asm/bitops.h    |    7 +++++++
- arch/m68k/include/asm/bitops.h    |    6 ++++++
- arch/s390/include/asm/bitops.h    |    7 +++++++
- arch/sh/include/asm/bitops-op32.h |    7 +++++++
- 6 files changed, 49 insertions(+)
-
---- a/arch/alpha/include/asm/bitops.h
-+++ b/arch/alpha/include/asm/bitops.h
-@@ -289,6 +289,13 @@ test_bit(int nr, const volatile void * a
-       return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) != 0UL;
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /*
-  * ffz = Find First Zero in word. Undefined if no zero exists,
-  * so code should check against ~0UL first..
---- a/arch/hexagon/include/asm/bitops.h
-+++ b/arch/hexagon/include/asm/bitops.h
-@@ -172,7 +172,22 @@ static inline int __test_bit(int nr, con
-       return retval;
- }
-+static inline int __test_bit_acquire(int nr, const volatile unsigned long *addr)
-+{
-+      int retval;
-+
-+      asm volatile(
-+      "{P0 = tstbit(%1,%2); if (P0.new) %0 = #1; if (!P0.new) %0 = #0;}\n"
-+      : "=&r" (retval)
-+      : "r" (addr[BIT_WORD(nr)]), "r" (nr % BITS_PER_LONG)
-+      : "p0", "memory"
-+      );
-+
-+      return retval;
-+}
-+
- #define test_bit(nr, addr) __test_bit(nr, addr)
-+#define test_bit_acquire(nr, addr) __test_bit_acquire(nr, addr)
- /*
-  * ffz - find first zero in word.
---- a/arch/ia64/include/asm/bitops.h
-+++ b/arch/ia64/include/asm/bitops.h
-@@ -337,6 +337,13 @@ test_bit (int nr, const volatile void *a
-       return 1 & (((const volatile __u32 *) addr)[nr >> 5] >> (nr & 31));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /**
-  * ffz - find the first zero bit in a long word
-  * @x: The long word to find the bit in
---- a/arch/m68k/include/asm/bitops.h
-+++ b/arch/m68k/include/asm/bitops.h
-@@ -153,6 +153,12 @@ static inline int test_bit(int nr, const
-       return (vaddr[nr >> 5] & (1UL << (nr & 31))) != 0;
- }
-+static __always_inline bool
-+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)));
-+}
- static inline int bset_reg_test_and_set_bit(int nr,
-                                           volatile unsigned long *vaddr)
---- a/arch/s390/include/asm/bitops.h
-+++ b/arch/s390/include/asm/bitops.h
-@@ -184,6 +184,13 @@ static inline bool arch_test_bit(unsigne
-       return *addr & mask;
- }
-+static __always_inline bool
-+arch_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)));
-+}
-+
- static inline bool arch_test_and_set_bit_lock(unsigned long nr,
-                                             volatile unsigned long *ptr)
- {
---- a/arch/sh/include/asm/bitops-op32.h
-+++ b/arch/sh/include/asm/bitops-op32.h
-@@ -138,4 +138,11 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- #endif /* __ASM_SH_BITOPS_OP32_H */
index af518eac89fdc0c398a937b63dbf36bcea1b457c..679f3913c987e3a98e50a6d0ba93042c652bcc55 100644 (file)
@@ -3,8 +3,6 @@ docs-update-mediator-information-in-coc-docs.patch
 xsk-inherit-need_wakeup-flag-for-shared-sockets.patch
 mm-gup-fix-the-fast-gup-race-against-thp-collapse.patch
 powerpc-64s-radix-don-t-need-to-broadcast-ipi-for-radix-pmd-collapse-flush.patch
-wait_on_bit-add-an-acquire-memory-barrier.patch
-provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
 fs-fix-uaf-gpf-bug-in-nilfs_mdt_destroy.patch
 firmware-arm_scmi-improve-checks-in-the-info_get-ope.patch
 firmware-arm_scmi-harden-accesses-to-the-sensor-doma.patch
diff --git a/queue-5.15/wait_on_bit-add-an-acquire-memory-barrier.patch b/queue-5.15/wait_on_bit-add-an-acquire-memory-barrier.patch
deleted file mode 100644 (file)
index 825c6bf..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-From 8238b4579866b7c1bb99883cfe102a43db5506ff Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 09:17:08 -0400
-Subject: wait_on_bit: add an acquire memory barrier
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit 8238b4579866b7c1bb99883cfe102a43db5506ff upstream.
-
-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>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/x86/include/asm/bitops.h                        |   21 +++++++++++++++++++
- include/asm-generic/bitops/instrumented-non-atomic.h |   12 ++++++++++
- include/asm-generic/bitops/non-atomic.h              |   14 ++++++++++++
- include/linux/buffer_head.h                          |    2 -
- include/linux/wait_bit.h                             |    8 +++----
- kernel/sched/wait_bit.c                              |    2 -
- 6 files changed, 53 insertions(+), 6 deletions(-)
-
---- a/arch/x86/include/asm/bitops.h
-+++ b/arch/x86/include/asm/bitops.h
-@@ -207,6 +207,20 @@ static __always_inline bool constant_tes
-               (addr[nr >> _BITOPS_LONG_SHIFT])) != 0;
- }
-+static __always_inline bool constant_test_bit_acquire(long nr, const volatile unsigned long *addr)
-+{
-+      bool oldbit;
-+
-+      asm volatile("testb %2,%1"
-+                   CC_SET(nz)
-+                   : CC_OUT(nz) (oldbit)
-+                   : "m" (((unsigned char *)addr)[nr >> 3]),
-+                     "i" (1 << (nr & 7))
-+                   :"memory");
-+
-+      return oldbit;
-+}
-+
- static __always_inline bool variable_test_bit(long nr, volatile const unsigned long *addr)
- {
-       bool oldbit;
-@@ -224,6 +238,13 @@ static __always_inline bool variable_tes
-        ? constant_test_bit((nr), (addr))      \
-        : variable_test_bit((nr), (addr)))
-+static __always_inline bool
-+arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
-+{
-+      return __builtin_constant_p(nr) ? constant_test_bit_acquire(nr, addr) :
-+                                        variable_test_bit(nr, addr);
-+}
-+
- /**
-  * __ffs - find first set bit in word
-  * @word: The word to search
---- a/include/asm-generic/bitops/instrumented-non-atomic.h
-+++ b/include/asm-generic/bitops/instrumented-non-atomic.h
-@@ -135,4 +135,16 @@ static inline bool test_bit(long nr, con
-       return arch_test_bit(nr, addr);
- }
-+/**
-+ * _test_bit_acquire - Determine, with acquire semantics, whether a bit is set
-+ * @nr: bit number to test
-+ * @addr: Address to start counting from
-+ */
-+static __always_inline bool
-+test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
-+{
-+      instrument_atomic_read(addr + BIT_WORD(nr), sizeof(long));
-+      return arch_test_bit_acquire(nr, addr);
-+}
-+
- #endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */
---- a/include/asm-generic/bitops/non-atomic.h
-+++ b/include/asm-generic/bitops/non-atomic.h
-@@ -3,6 +3,7 @@
- #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
- #include <asm/types.h>
-+#include <asm/barrier.h>
- /**
-  * arch___set_bit - Set a bit in memory
-@@ -119,4 +120,17 @@ arch_test_bit(unsigned int nr, const vol
- }
- #define test_bit arch_test_bit
-+/**
-+ * arch_test_bit_acquire - Determine, with acquire semantics, whether a bit is set
-+ * @nr: bit number to test
-+ * @addr: Address to start counting from
-+ */
-+static __always_inline bool
-+arch_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)));
-+}
-+#define test_bit_acquire arch_test_bit_acquire
-+
- #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
---- a/include/linux/buffer_head.h
-+++ b/include/linux/buffer_head.h
-@@ -166,7 +166,7 @@ static __always_inline int buffer_uptoda
-        * make it consistent with folio_test_uptodate
-        * pairs with smp_mb__before_atomic in set_buffer_uptodate
-        */
--      return (smp_load_acquire(&bh->b_state) & (1UL << BH_Uptodate)) != 0;
-+      return test_bit_acquire(BH_Uptodate, &bh->b_state);
- }
- #define bh_offset(bh)         ((unsigned long)(bh)->b_data & ~PAGE_MASK)
---- a/include/linux/wait_bit.h
-+++ b/include/linux/wait_bit.h
-@@ -71,7 +71,7 @@ static inline int
- wait_on_bit(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait,
-@@ -96,7 +96,7 @@ static inline int
- wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait_io,
-@@ -123,7 +123,7 @@ wait_on_bit_timeout(unsigned long *word,
-                   unsigned long timeout)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit_timeout(word, bit,
-                                              bit_wait_timeout,
-@@ -151,7 +151,7 @@ wait_on_bit_action(unsigned long *word,
-                  unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit, action, mode);
- }
---- a/kernel/sched/wait_bit.c
-+++ b/kernel/sched/wait_bit.c
-@@ -47,7 +47,7 @@ __wait_on_bit(struct wait_queue_head *wq
-               prepare_to_wait(wq_head, &wbq_entry->wq_entry, mode);
-               if (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags))
-                       ret = (*action)(&wbq_entry->key, mode);
--      } while (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-+      } while (test_bit_acquire(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-       finish_wait(wq_head, &wbq_entry->wq_entry);
diff --git a/queue-5.19/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch b/queue-5.19/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
deleted file mode 100644 (file)
index 9255480..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-From d6ffe6067a54972564552ea45d320fb98db1ac5e Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 16:43:51 -0400
-Subject: provide arch_test_bit_acquire for architectures that define test_bit
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit d6ffe6067a54972564552ea45d320fb98db1ac5e upstream.
-
-Some architectures define their own arch_test_bit and they also need
-arch_test_bit_acquire, otherwise they won't compile.  We also clean up
-the code by using the generic test_bit if that is equivalent to the
-arch-specific version.
-
-Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
-Cc: stable@vger.kernel.org
-Fixes: 8238b4579866 ("wait_on_bit: add an acquire memory barrier")
-Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/alpha/include/asm/bitops.h   |    7 +++++++
- arch/hexagon/include/asm/bitops.h |   15 +++++++++++++++
- arch/ia64/include/asm/bitops.h    |    7 +++++++
- arch/m68k/include/asm/bitops.h    |    6 ++++++
- arch/s390/include/asm/bitops.h    |    7 +++++++
- arch/sh/include/asm/bitops-op32.h |    7 +++++++
- 6 files changed, 49 insertions(+)
-
---- a/arch/alpha/include/asm/bitops.h
-+++ b/arch/alpha/include/asm/bitops.h
-@@ -289,6 +289,13 @@ test_bit(int nr, const volatile void * a
-       return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) != 0UL;
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /*
-  * ffz = Find First Zero in word. Undefined if no zero exists,
-  * so code should check against ~0UL first..
---- a/arch/hexagon/include/asm/bitops.h
-+++ b/arch/hexagon/include/asm/bitops.h
-@@ -172,7 +172,22 @@ static inline int __test_bit(int nr, con
-       return retval;
- }
-+static inline int __test_bit_acquire(int nr, const volatile unsigned long *addr)
-+{
-+      int retval;
-+
-+      asm volatile(
-+      "{P0 = tstbit(%1,%2); if (P0.new) %0 = #1; if (!P0.new) %0 = #0;}\n"
-+      : "=&r" (retval)
-+      : "r" (addr[BIT_WORD(nr)]), "r" (nr % BITS_PER_LONG)
-+      : "p0", "memory"
-+      );
-+
-+      return retval;
-+}
-+
- #define test_bit(nr, addr) __test_bit(nr, addr)
-+#define test_bit_acquire(nr, addr) __test_bit_acquire(nr, addr)
- /*
-  * ffz - find first zero in word.
---- a/arch/ia64/include/asm/bitops.h
-+++ b/arch/ia64/include/asm/bitops.h
-@@ -337,6 +337,13 @@ test_bit (int nr, const volatile void *a
-       return 1 & (((const volatile __u32 *) addr)[nr >> 5] >> (nr & 31));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /**
-  * ffz - find the first zero bit in a long word
-  * @x: The long word to find the bit in
---- a/arch/m68k/include/asm/bitops.h
-+++ b/arch/m68k/include/asm/bitops.h
-@@ -153,6 +153,12 @@ static inline int test_bit(int nr, const
-       return (vaddr[nr >> 5] & (1UL << (nr & 31))) != 0;
- }
-+static __always_inline bool
-+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)));
-+}
- static inline int bset_reg_test_and_set_bit(int nr,
-                                           volatile unsigned long *vaddr)
---- a/arch/s390/include/asm/bitops.h
-+++ b/arch/s390/include/asm/bitops.h
-@@ -184,6 +184,13 @@ static inline bool arch_test_bit(unsigne
-       return *addr & mask;
- }
-+static __always_inline bool
-+arch_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)));
-+}
-+
- static inline bool arch_test_and_set_bit_lock(unsigned long nr,
-                                             volatile unsigned long *ptr)
- {
---- a/arch/sh/include/asm/bitops-op32.h
-+++ b/arch/sh/include/asm/bitops-op32.h
-@@ -138,4 +138,11 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- #endif /* __ASM_SH_BITOPS_OP32_H */
index 820030ad493ed59d52f9511eb650120b8ef50192..124fd4d31f70b8fbda5ff5e5196f64073a39070f 100644 (file)
@@ -3,8 +3,6 @@ makefile.extrawarn-move-wcast-function-type-strict-to-w-1.patch
 hardening-remove-clang-s-enable-flag-for-ftrivial-auto-var-init-zero.patch
 docs-update-mediator-information-in-coc-docs.patch
 xsk-inherit-need_wakeup-flag-for-shared-sockets.patch
-wait_on_bit-add-an-acquire-memory-barrier.patch
-provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
 fs-fix-uaf-gpf-bug-in-nilfs_mdt_destroy.patch
 firmware-arm_scmi-improve-checks-in-the-info_get-ope.patch
 firmware-arm_scmi-harden-accesses-to-the-sensor-doma.patch
diff --git a/queue-5.19/wait_on_bit-add-an-acquire-memory-barrier.patch b/queue-5.19/wait_on_bit-add-an-acquire-memory-barrier.patch
deleted file mode 100644 (file)
index 85fd791..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-From 8238b4579866b7c1bb99883cfe102a43db5506ff Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 09:17:08 -0400
-Subject: wait_on_bit: add an acquire memory barrier
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit 8238b4579866b7c1bb99883cfe102a43db5506ff upstream.
-
-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>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/x86/include/asm/bitops.h                        |   21 +++++++++++++++++++
- include/asm-generic/bitops/instrumented-non-atomic.h |   12 ++++++++++
- include/asm-generic/bitops/non-atomic.h              |   14 ++++++++++++
- include/linux/buffer_head.h                          |    2 -
- include/linux/wait_bit.h                             |    8 +++----
- kernel/sched/wait_bit.c                              |    2 -
- 6 files changed, 53 insertions(+), 6 deletions(-)
-
---- a/arch/x86/include/asm/bitops.h
-+++ b/arch/x86/include/asm/bitops.h
-@@ -207,6 +207,20 @@ static __always_inline bool constant_tes
-               (addr[nr >> _BITOPS_LONG_SHIFT])) != 0;
- }
-+static __always_inline bool constant_test_bit_acquire(long nr, const volatile unsigned long *addr)
-+{
-+      bool oldbit;
-+
-+      asm volatile("testb %2,%1"
-+                   CC_SET(nz)
-+                   : CC_OUT(nz) (oldbit)
-+                   : "m" (((unsigned char *)addr)[nr >> 3]),
-+                     "i" (1 << (nr & 7))
-+                   :"memory");
-+
-+      return oldbit;
-+}
-+
- static __always_inline bool variable_test_bit(long nr, volatile const unsigned long *addr)
- {
-       bool oldbit;
-@@ -224,6 +238,13 @@ static __always_inline bool variable_tes
-        ? constant_test_bit((nr), (addr))      \
-        : variable_test_bit((nr), (addr)))
-+static __always_inline bool
-+arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
-+{
-+      return __builtin_constant_p(nr) ? constant_test_bit_acquire(nr, addr) :
-+                                        variable_test_bit(nr, addr);
-+}
-+
- /**
-  * __ffs - find first set bit in word
-  * @word: The word to search
---- a/include/asm-generic/bitops/instrumented-non-atomic.h
-+++ b/include/asm-generic/bitops/instrumented-non-atomic.h
-@@ -135,4 +135,16 @@ static __always_inline bool test_bit(lon
-       return arch_test_bit(nr, addr);
- }
-+/**
-+ * _test_bit_acquire - Determine, with acquire semantics, whether a bit is set
-+ * @nr: bit number to test
-+ * @addr: Address to start counting from
-+ */
-+static __always_inline bool
-+test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
-+{
-+      instrument_atomic_read(addr + BIT_WORD(nr), sizeof(long));
-+      return arch_test_bit_acquire(nr, addr);
-+}
-+
- #endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */
---- a/include/asm-generic/bitops/non-atomic.h
-+++ b/include/asm-generic/bitops/non-atomic.h
-@@ -3,6 +3,7 @@
- #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
- #include <asm/types.h>
-+#include <asm/barrier.h>
- /**
-  * arch___set_bit - Set a bit in memory
-@@ -119,4 +120,17 @@ arch_test_bit(unsigned int nr, const vol
- }
- #define test_bit arch_test_bit
-+/**
-+ * arch_test_bit_acquire - Determine, with acquire semantics, whether a bit is set
-+ * @nr: bit number to test
-+ * @addr: Address to start counting from
-+ */
-+static __always_inline bool
-+arch_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)));
-+}
-+#define test_bit_acquire arch_test_bit_acquire
-+
- #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
---- a/include/linux/buffer_head.h
-+++ b/include/linux/buffer_head.h
-@@ -166,7 +166,7 @@ static __always_inline int buffer_uptoda
-        * make it consistent with folio_test_uptodate
-        * pairs with smp_mb__before_atomic in set_buffer_uptodate
-        */
--      return (smp_load_acquire(&bh->b_state) & (1UL << BH_Uptodate)) != 0;
-+      return test_bit_acquire(BH_Uptodate, &bh->b_state);
- }
- #define bh_offset(bh)         ((unsigned long)(bh)->b_data & ~PAGE_MASK)
---- a/include/linux/wait_bit.h
-+++ b/include/linux/wait_bit.h
-@@ -71,7 +71,7 @@ static inline int
- wait_on_bit(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait,
-@@ -96,7 +96,7 @@ static inline int
- wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait_io,
-@@ -123,7 +123,7 @@ wait_on_bit_timeout(unsigned long *word,
-                   unsigned long timeout)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit_timeout(word, bit,
-                                              bit_wait_timeout,
-@@ -151,7 +151,7 @@ wait_on_bit_action(unsigned long *word,
-                  unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit, action, mode);
- }
---- a/kernel/sched/wait_bit.c
-+++ b/kernel/sched/wait_bit.c
-@@ -47,7 +47,7 @@ __wait_on_bit(struct wait_queue_head *wq
-               prepare_to_wait(wq_head, &wbq_entry->wq_entry, mode);
-               if (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags))
-                       ret = (*action)(&wbq_entry->key, mode);
--      } while (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-+      } while (test_bit_acquire(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-       finish_wait(wq_head, &wbq_entry->wq_entry);
diff --git a/queue-5.4/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch b/queue-5.4/provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
deleted file mode 100644 (file)
index e3dcb93..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-From d6ffe6067a54972564552ea45d320fb98db1ac5e Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 16:43:51 -0400
-Subject: provide arch_test_bit_acquire for architectures that define test_bit
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit d6ffe6067a54972564552ea45d320fb98db1ac5e upstream.
-
-Some architectures define their own arch_test_bit and they also need
-arch_test_bit_acquire, otherwise they won't compile.  We also clean up
-the code by using the generic test_bit if that is equivalent to the
-arch-specific version.
-
-Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
-Cc: stable@vger.kernel.org
-Fixes: 8238b4579866 ("wait_on_bit: add an acquire memory barrier")
-Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/alpha/include/asm/bitops.h   |    7 +++++++
- arch/hexagon/include/asm/bitops.h |   15 +++++++++++++++
- arch/ia64/include/asm/bitops.h    |    7 +++++++
- arch/m68k/include/asm/bitops.h    |    6 ++++++
- arch/s390/include/asm/bitops.h    |    7 +++++++
- arch/sh/include/asm/bitops-op32.h |    7 +++++++
- 6 files changed, 49 insertions(+)
-
---- a/arch/alpha/include/asm/bitops.h
-+++ b/arch/alpha/include/asm/bitops.h
-@@ -289,6 +289,13 @@ test_bit(int nr, const volatile void * a
-       return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) != 0UL;
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /*
-  * ffz = Find First Zero in word. Undefined if no zero exists,
-  * so code should check against ~0UL first..
---- a/arch/hexagon/include/asm/bitops.h
-+++ b/arch/hexagon/include/asm/bitops.h
-@@ -172,7 +172,22 @@ static inline int __test_bit(int nr, con
-       return retval;
- }
-+static inline int __test_bit_acquire(int nr, const volatile unsigned long *addr)
-+{
-+      int retval;
-+
-+      asm volatile(
-+      "{P0 = tstbit(%1,%2); if (P0.new) %0 = #1; if (!P0.new) %0 = #0;}\n"
-+      : "=&r" (retval)
-+      : "r" (addr[BIT_WORD(nr)]), "r" (nr % BITS_PER_LONG)
-+      : "p0", "memory"
-+      );
-+
-+      return retval;
-+}
-+
- #define test_bit(nr, addr) __test_bit(nr, addr)
-+#define test_bit_acquire(nr, addr) __test_bit_acquire(nr, addr)
- /*
-  * ffz - find first zero in word.
---- a/arch/ia64/include/asm/bitops.h
-+++ b/arch/ia64/include/asm/bitops.h
-@@ -337,6 +337,13 @@ test_bit (int nr, const volatile void *a
-       return 1 & (((const volatile __u32 *) addr)[nr >> 5] >> (nr & 31));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- /**
-  * ffz - find the first zero bit in a long word
-  * @x: The long word to find the bit in
---- a/arch/m68k/include/asm/bitops.h
-+++ b/arch/m68k/include/asm/bitops.h
-@@ -153,6 +153,12 @@ static inline int test_bit(int nr, const
-       return (vaddr[nr >> 5] & (1UL << (nr & 31))) != 0;
- }
-+static __always_inline bool
-+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)));
-+}
- static inline int bset_reg_test_and_set_bit(int nr,
-                                           volatile unsigned long *vaddr)
---- a/arch/s390/include/asm/bitops.h
-+++ b/arch/s390/include/asm/bitops.h
-@@ -219,6 +219,13 @@ static inline bool arch_test_bit(unsigne
-       return (*addr >> (nr & 7)) & 1;
- }
-+static __always_inline bool
-+arch_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)));
-+}
-+
- static inline bool arch_test_and_set_bit_lock(unsigned long nr,
-                                             volatile unsigned long *ptr)
- {
---- a/arch/sh/include/asm/bitops-op32.h
-+++ b/arch/sh/include/asm/bitops-op32.h
-@@ -140,4 +140,11 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+static __always_inline bool
-+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)));
-+}
-+
- #endif /* __ASM_SH_BITOPS_OP32_H */
index acdad2bf09550ec3c3b0fa546b8383777bd7ffdd..5724aae87e590ba900113c8a7e812152ae63d069 100644 (file)
@@ -1,6 +1,4 @@
 mm-pagewalk-fix-race-between-unmap-and-page-walker.patch
-wait_on_bit-add-an-acquire-memory-barrier.patch
-provide-arch_test_bit_acquire-for-architectures-that-define-test_bit.patch
 perf-tools-fixup-get_current_dir_name-compilation.patch
 fs-fix-uaf-gpf-bug-in-nilfs_mdt_destroy.patch
 firmware-arm_scmi-add-scmi-pm-driver-remove-routine.patch
diff --git a/queue-5.4/wait_on_bit-add-an-acquire-memory-barrier.patch b/queue-5.4/wait_on_bit-add-an-acquire-memory-barrier.patch
deleted file mode 100644 (file)
index 1aebd3a..0000000
+++ /dev/null
@@ -1,173 +0,0 @@
-From 8238b4579866b7c1bb99883cfe102a43db5506ff Mon Sep 17 00:00:00 2001
-From: Mikulas Patocka <mpatocka@redhat.com>
-Date: Fri, 26 Aug 2022 09:17:08 -0400
-Subject: wait_on_bit: add an acquire memory barrier
-
-From: Mikulas Patocka <mpatocka@redhat.com>
-
-commit 8238b4579866b7c1bb99883cfe102a43db5506ff upstream.
-
-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>
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- arch/x86/include/asm/bitops.h             |   21 +++++++++++++++++++++
- include/asm-generic/bitops-instrumented.h |    6 ++++++
- include/asm-generic/bitops/non-atomic.h   |   14 ++++++++++++++
- include/linux/buffer_head.h               |    2 +-
- include/linux/wait_bit.h                  |    8 ++++----
- kernel/sched/wait_bit.c                   |    2 +-
- 6 files changed, 47 insertions(+), 6 deletions(-)
-
---- a/arch/x86/include/asm/bitops.h
-+++ b/arch/x86/include/asm/bitops.h
-@@ -207,6 +207,20 @@ static __always_inline bool constant_tes
-               (addr[nr >> _BITOPS_LONG_SHIFT])) != 0;
- }
-+static __always_inline bool constant_test_bit_acquire(long nr, const volatile unsigned long *addr)
-+{
-+      bool oldbit;
-+
-+      asm volatile("testb %2,%1"
-+                   CC_SET(nz)
-+                   : CC_OUT(nz) (oldbit)
-+                   : "m" (((unsigned char *)addr)[nr >> 3]),
-+                     "i" (1 << (nr & 7))
-+                   :"memory");
-+
-+      return oldbit;
-+}
-+
- static __always_inline bool variable_test_bit(long nr, volatile const unsigned long *addr)
- {
-       bool oldbit;
-@@ -224,6 +238,13 @@ static __always_inline bool variable_tes
-        ? constant_test_bit((nr), (addr))      \
-        : variable_test_bit((nr), (addr)))
-+static __always_inline bool
-+arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
-+{
-+      return __builtin_constant_p(nr) ? constant_test_bit_acquire(nr, addr) :
-+                                        variable_test_bit(nr, addr);
-+}
-+
- /**
-  * __ffs - find first set bit in word
-  * @word: The word to search
---- a/include/asm-generic/bitops-instrumented.h
-+++ b/include/asm-generic/bitops-instrumented.h
-@@ -238,6 +238,12 @@ static inline bool test_bit(long nr, con
-       return arch_test_bit(nr, addr);
- }
-+static inline bool test_bit_acquire(long nr, const volatile unsigned long *addr)
-+{
-+      kasan_check_read(addr + BIT_WORD(nr), sizeof(long));
-+      return arch_test_bit_acquire(nr, addr);
-+}
-+
- #if defined(arch_clear_bit_unlock_is_negative_byte)
- /**
-  * clear_bit_unlock_is_negative_byte - Clear a bit in memory and test if bottom
---- a/include/asm-generic/bitops/non-atomic.h
-+++ b/include/asm-generic/bitops/non-atomic.h
-@@ -3,6 +3,7 @@
- #define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
- #include <asm/types.h>
-+#include <asm/barrier.h>
- /**
-  * __set_bit - Set a bit in memory
-@@ -106,4 +107,17 @@ static inline int test_bit(int nr, const
-       return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
- }
-+/**
-+ * arch_test_bit_acquire - Determine, with acquire semantics, whether a bit is set
-+ * @nr: bit number to test
-+ * @addr: Address to start counting from
-+ */
-+static __always_inline bool
-+arch_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)));
-+}
-+#define test_bit_acquire arch_test_bit_acquire
-+
- #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
---- a/include/linux/buffer_head.h
-+++ b/include/linux/buffer_head.h
-@@ -166,7 +166,7 @@ static __always_inline int buffer_uptoda
-        * make it consistent with folio_test_uptodate
-        * pairs with smp_mb__before_atomic in set_buffer_uptodate
-        */
--      return (smp_load_acquire(&bh->b_state) & (1UL << BH_Uptodate)) != 0;
-+      return test_bit_acquire(BH_Uptodate, &bh->b_state);
- }
- #define bh_offset(bh)         ((unsigned long)(bh)->b_data & ~PAGE_MASK)
---- a/include/linux/wait_bit.h
-+++ b/include/linux/wait_bit.h
-@@ -71,7 +71,7 @@ static inline int
- wait_on_bit(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait,
-@@ -96,7 +96,7 @@ static inline int
- wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit,
-                                      bit_wait_io,
-@@ -123,7 +123,7 @@ wait_on_bit_timeout(unsigned long *word,
-                   unsigned long timeout)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit_timeout(word, bit,
-                                              bit_wait_timeout,
-@@ -151,7 +151,7 @@ wait_on_bit_action(unsigned long *word,
-                  unsigned mode)
- {
-       might_sleep();
--      if (!test_bit(bit, word))
-+      if (!test_bit_acquire(bit, word))
-               return 0;
-       return out_of_line_wait_on_bit(word, bit, action, mode);
- }
---- a/kernel/sched/wait_bit.c
-+++ b/kernel/sched/wait_bit.c
-@@ -47,7 +47,7 @@ __wait_on_bit(struct wait_queue_head *wq
-               prepare_to_wait(wq_head, &wbq_entry->wq_entry, mode);
-               if (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags))
-                       ret = (*action)(&wbq_entry->key, mode);
--      } while (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-+      } while (test_bit_acquire(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
-       finish_wait(wq_head, &wbq_entry->wq_entry);