1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
From 166485c3d38dd51a1a9a35edb7b2d3c1054a2418 Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Tue, 19 Nov 2019 09:25:04 +0100
Subject: [PATCH 228/323] locking: Make spinlock_t and rwlock_t a RCU section
on RT
Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/5.10/older/patches-5.10.204-rt100.tar.xz
On !RT a locked spinlock_t and rwlock_t disables preemption which
implies a RCU read section. There is code that relies on that behaviour.
Add an explicit RCU read section on RT while a sleeping lock (a lock
which would disables preemption on !RT) acquired.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
kernel/locking/rtmutex.c | 6 ++++++
kernel/locking/rwlock-rt.c | 6 ++++++
2 files changed, 12 insertions(+)
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 2fe178651254..31b374d36d04 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1136,6 +1136,7 @@ void __lockfunc rt_spin_lock(spinlock_t *lock)
{
spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock);
+ rcu_read_lock();
migrate_disable();
}
EXPORT_SYMBOL(rt_spin_lock);
@@ -1150,6 +1151,7 @@ void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass)
{
spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock);
+ rcu_read_lock();
migrate_disable();
}
EXPORT_SYMBOL(rt_spin_lock_nested);
@@ -1159,6 +1161,7 @@ void __lockfunc rt_spin_lock_nest_lock(spinlock_t *lock,
{
spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_);
rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock);
+ rcu_read_lock();
migrate_disable();
}
EXPORT_SYMBOL(rt_spin_lock_nest_lock);
@@ -1169,6 +1172,7 @@ void __lockfunc rt_spin_unlock(spinlock_t *lock)
/* NOTE: we always pass in '1' for nested, for simplicity */
spin_release(&lock->dep_map, _RET_IP_);
migrate_enable();
+ rcu_read_unlock();
rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock);
}
EXPORT_SYMBOL(rt_spin_unlock);
@@ -1198,6 +1202,7 @@ int __lockfunc rt_spin_trylock(spinlock_t *lock)
ret = __rt_mutex_trylock(&lock->lock);
if (ret) {
spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
+ rcu_read_lock();
migrate_disable();
}
return ret;
@@ -1212,6 +1217,7 @@ int __lockfunc rt_spin_trylock_bh(spinlock_t *lock)
ret = __rt_mutex_trylock(&lock->lock);
if (ret) {
spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
+ rcu_read_lock();
migrate_disable();
} else {
local_bh_enable();
diff --git a/kernel/locking/rwlock-rt.c b/kernel/locking/rwlock-rt.c
index 16be7111aae7..3d2d1f14b513 100644
--- a/kernel/locking/rwlock-rt.c
+++ b/kernel/locking/rwlock-rt.c
@@ -270,6 +270,7 @@ int __lockfunc rt_read_trylock(rwlock_t *rwlock)
ret = __read_rt_trylock(rwlock);
if (ret) {
rwlock_acquire_read(&rwlock->dep_map, 0, 1, _RET_IP_);
+ rcu_read_lock();
migrate_disable();
}
return ret;
@@ -283,6 +284,7 @@ int __lockfunc rt_write_trylock(rwlock_t *rwlock)
ret = __write_rt_trylock(rwlock);
if (ret) {
rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
+ rcu_read_lock();
migrate_disable();
}
return ret;
@@ -293,6 +295,7 @@ void __lockfunc rt_read_lock(rwlock_t *rwlock)
{
rwlock_acquire_read(&rwlock->dep_map, 0, 0, _RET_IP_);
__read_rt_lock(rwlock);
+ rcu_read_lock();
migrate_disable();
}
EXPORT_SYMBOL(rt_read_lock);
@@ -301,6 +304,7 @@ void __lockfunc rt_write_lock(rwlock_t *rwlock)
{
rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
__write_rt_lock(rwlock);
+ rcu_read_lock();
migrate_disable();
}
EXPORT_SYMBOL(rt_write_lock);
@@ -309,6 +313,7 @@ void __lockfunc rt_read_unlock(rwlock_t *rwlock)
{
rwlock_release(&rwlock->dep_map, _RET_IP_);
migrate_enable();
+ rcu_read_unlock();
__read_rt_unlock(rwlock);
}
EXPORT_SYMBOL(rt_read_unlock);
@@ -317,6 +322,7 @@ void __lockfunc rt_write_unlock(rwlock_t *rwlock)
{
rwlock_release(&rwlock->dep_map, _RET_IP_);
migrate_enable();
+ rcu_read_unlock();
__write_rt_unlock(rwlock);
}
EXPORT_SYMBOL(rt_write_unlock);
--
2.43.0
|