]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.181/rcu-locking-and-unlocking-need-to-always-be-at-least-barriers.patch
Linux 4.4.181
[thirdparty/kernel/stable-queue.git] / releases / 4.4.181 / rcu-locking-and-unlocking-need-to-always-be-at-least-barriers.patch
1 From 66be4e66a7f422128748e3c3ef6ee72b20a6197b Mon Sep 17 00:00:00 2001
2 From: Linus Torvalds <torvalds@linux-foundation.org>
3 Date: Mon, 3 Jun 2019 13:26:20 -0700
4 Subject: rcu: locking and unlocking need to always be at least barriers
5
6 From: Linus Torvalds <torvalds@linux-foundation.org>
7
8 commit 66be4e66a7f422128748e3c3ef6ee72b20a6197b upstream.
9
10 Herbert Xu pointed out that commit bb73c52bad36 ("rcu: Don't disable
11 preemption for Tiny and Tree RCU readers") was incorrect in making the
12 preempt_disable/enable() be conditional on CONFIG_PREEMPT_COUNT.
13
14 If CONFIG_PREEMPT_COUNT isn't enabled, the preemption enable/disable is
15 a no-op, but still is a compiler barrier.
16
17 And RCU locking still _needs_ that compiler barrier.
18
19 It is simply fundamentally not true that RCU locking would be a complete
20 no-op: we still need to guarantee (for example) that things that can
21 trap and cause preemption cannot migrate into the RCU locked region.
22
23 The way we do that is by making it a barrier.
24
25 See for example commit 386afc91144b ("spinlocks and preemption points
26 need to be at least compiler barriers") from back in 2013 that had
27 similar issues with spinlocks that become no-ops on UP: they must still
28 constrain the compiler from moving other operations into the critical
29 region.
30
31 Now, it is true that a lot of RCU operations already use READ_ONCE() and
32 WRITE_ONCE() (which in practice likely would never be re-ordered wrt
33 anything remotely interesting), but it is also true that that is not
34 globally the case, and that it's not even necessarily always possible
35 (ie bitfields etc).
36
37 Reported-by: Herbert Xu <herbert@gondor.apana.org.au>
38 Fixes: bb73c52bad36 ("rcu: Don't disable preemption for Tiny and Tree RCU readers")
39 Cc: stable@kernel.org
40 Cc: Boqun Feng <boqun.feng@gmail.com>
41 Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
42 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
43 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
44
45 ---
46 include/linux/rcupdate.h | 6 ++----
47 1 file changed, 2 insertions(+), 4 deletions(-)
48
49 --- a/include/linux/rcupdate.h
50 +++ b/include/linux/rcupdate.h
51 @@ -297,14 +297,12 @@ void synchronize_rcu(void);
52
53 static inline void __rcu_read_lock(void)
54 {
55 - if (IS_ENABLED(CONFIG_PREEMPT_COUNT))
56 - preempt_disable();
57 + preempt_disable();
58 }
59
60 static inline void __rcu_read_unlock(void)
61 {
62 - if (IS_ENABLED(CONFIG_PREEMPT_COUNT))
63 - preempt_enable();
64 + preempt_enable();
65 }
66
67 static inline void synchronize_rcu(void)