hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/include/linux/srcu.h
....@@ -1,24 +1,11 @@
1
+/* SPDX-License-Identifier: GPL-2.0+ */
12 /*
23 * Sleepable Read-Copy Update mechanism for mutual exclusion
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation; either version 2 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, you can access it online at
16
- * http://www.gnu.org/licenses/gpl-2.0.html.
174 *
185 * Copyright (C) IBM Corporation, 2006
196 * Copyright (C) Fujitsu, 2012
207 *
21
- * Author: Paul McKenney <paulmck@us.ibm.com>
8
+ * Author: Paul McKenney <paulmck@linux.ibm.com>
229 * Lai Jiangshan <laijs@cn.fujitsu.com>
2310 *
2411 * For detailed explanation of Read-Copy Update mechanism see -
....@@ -38,20 +25,20 @@
3825
3926 #ifdef CONFIG_DEBUG_LOCK_ALLOC
4027
41
-int __init_srcu_struct(struct srcu_struct *sp, const char *name,
28
+int __init_srcu_struct(struct srcu_struct *ssp, const char *name,
4229 struct lock_class_key *key);
4330
44
-#define init_srcu_struct(sp) \
31
+#define init_srcu_struct(ssp) \
4532 ({ \
4633 static struct lock_class_key __srcu_key; \
4734 \
48
- __init_srcu_struct((sp), #sp, &__srcu_key); \
35
+ __init_srcu_struct((ssp), #ssp, &__srcu_key); \
4936 })
5037
5138 #define __SRCU_DEP_MAP_INIT(srcu_name) .dep_map = { .name = #srcu_name },
5239 #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
5340
54
-int init_srcu_struct(struct srcu_struct *sp);
41
+int init_srcu_struct(struct srcu_struct *ssp);
5542
5643 #define __SRCU_DEP_MAP_INIT(srcu_name)
5744 #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
....@@ -67,52 +54,21 @@
6754 struct srcu_struct { };
6855 #endif
6956
70
-void call_srcu(struct srcu_struct *sp, struct rcu_head *head,
57
+void call_srcu(struct srcu_struct *ssp, struct rcu_head *head,
7158 void (*func)(struct rcu_head *head));
72
-void _cleanup_srcu_struct(struct srcu_struct *sp, bool quiesced);
73
-int __srcu_read_lock(struct srcu_struct *sp) __acquires(sp);
74
-void __srcu_read_unlock(struct srcu_struct *sp, int idx) __releases(sp);
75
-void synchronize_srcu(struct srcu_struct *sp);
76
-
77
-/**
78
- * cleanup_srcu_struct - deconstruct a sleep-RCU structure
79
- * @sp: structure to clean up.
80
- *
81
- * Must invoke this after you are finished using a given srcu_struct that
82
- * was initialized via init_srcu_struct(), else you leak memory.
83
- */
84
-static inline void cleanup_srcu_struct(struct srcu_struct *sp)
85
-{
86
- _cleanup_srcu_struct(sp, false);
87
-}
88
-
89
-/**
90
- * cleanup_srcu_struct_quiesced - deconstruct a quiesced sleep-RCU structure
91
- * @sp: structure to clean up.
92
- *
93
- * Must invoke this after you are finished using a given srcu_struct that
94
- * was initialized via init_srcu_struct(), else you leak memory. Also,
95
- * all grace-period processing must have completed.
96
- *
97
- * "Completed" means that the last synchronize_srcu() and
98
- * synchronize_srcu_expedited() calls must have returned before the call
99
- * to cleanup_srcu_struct_quiesced(). It also means that the callback
100
- * from the last call_srcu() must have been invoked before the call to
101
- * cleanup_srcu_struct_quiesced(), but you can use srcu_barrier() to help
102
- * with this last. Violating these rules will get you a WARN_ON() splat
103
- * (with high probability, anyway), and will also cause the srcu_struct
104
- * to be leaked.
105
- */
106
-static inline void cleanup_srcu_struct_quiesced(struct srcu_struct *sp)
107
-{
108
- _cleanup_srcu_struct(sp, true);
109
-}
59
+void cleanup_srcu_struct(struct srcu_struct *ssp);
60
+int __srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp);
61
+void __srcu_read_unlock(struct srcu_struct *ssp, int idx) __releases(ssp);
62
+void synchronize_srcu(struct srcu_struct *ssp);
63
+unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp);
64
+unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp);
65
+bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie);
11066
11167 #ifdef CONFIG_DEBUG_LOCK_ALLOC
11268
11369 /**
11470 * srcu_read_lock_held - might we be in SRCU read-side critical section?
115
- * @sp: The srcu_struct structure to check
71
+ * @ssp: The srcu_struct structure to check
11672 *
11773 * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an SRCU
11874 * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC,
....@@ -126,16 +82,16 @@
12682 * relies on normal RCU, it can be called from the CPU which
12783 * is in the idle loop from an RCU point of view or offline.
12884 */
129
-static inline int srcu_read_lock_held(const struct srcu_struct *sp)
85
+static inline int srcu_read_lock_held(const struct srcu_struct *ssp)
13086 {
13187 if (!debug_lockdep_rcu_enabled())
13288 return 1;
133
- return lock_is_held(&sp->dep_map);
89
+ return lock_is_held(&ssp->dep_map);
13490 }
13591
13692 #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
13793
138
-static inline int srcu_read_lock_held(const struct srcu_struct *sp)
94
+static inline int srcu_read_lock_held(const struct srcu_struct *ssp)
13995 {
14096 return 1;
14197 }
....@@ -145,7 +101,7 @@
145101 /**
146102 * srcu_dereference_check - fetch SRCU-protected pointer for later dereferencing
147103 * @p: the pointer to fetch and protect for later dereferencing
148
- * @sp: pointer to the srcu_struct, which is used to check that we
104
+ * @ssp: pointer to the srcu_struct, which is used to check that we
149105 * really are in an SRCU read-side critical section.
150106 * @c: condition to check for update-side use
151107 *
....@@ -154,29 +110,32 @@
154110 * to 1. The @c argument will normally be a logical expression containing
155111 * lockdep_is_held() calls.
156112 */
157
-#define srcu_dereference_check(p, sp, c) \
158
- __rcu_dereference_check((p), (c) || srcu_read_lock_held(sp), __rcu)
113
+#define srcu_dereference_check(p, ssp, c) \
114
+ __rcu_dereference_check((p), (c) || srcu_read_lock_held(ssp), __rcu)
159115
160116 /**
161117 * srcu_dereference - fetch SRCU-protected pointer for later dereferencing
162118 * @p: the pointer to fetch and protect for later dereferencing
163
- * @sp: pointer to the srcu_struct, which is used to check that we
119
+ * @ssp: pointer to the srcu_struct, which is used to check that we
164120 * really are in an SRCU read-side critical section.
165121 *
166122 * Makes rcu_dereference_check() do the dirty work. If PROVE_RCU
167123 * is enabled, invoking this outside of an RCU read-side critical
168124 * section will result in an RCU-lockdep splat.
169125 */
170
-#define srcu_dereference(p, sp) srcu_dereference_check((p), (sp), 0)
126
+#define srcu_dereference(p, ssp) srcu_dereference_check((p), (ssp), 0)
171127
172128 /**
173129 * srcu_dereference_notrace - no tracing and no lockdep calls from here
130
+ * @p: the pointer to fetch and protect for later dereferencing
131
+ * @ssp: pointer to the srcu_struct, which is used to check that we
132
+ * really are in an SRCU read-side critical section.
174133 */
175
-#define srcu_dereference_notrace(p, sp) srcu_dereference_check((p), (sp), 1)
134
+#define srcu_dereference_notrace(p, ssp) srcu_dereference_check((p), (ssp), 1)
176135
177136 /**
178137 * srcu_read_lock - register a new reader for an SRCU-protected structure.
179
- * @sp: srcu_struct in which to register the new reader.
138
+ * @ssp: srcu_struct in which to register the new reader.
180139 *
181140 * Enter an SRCU read-side critical section. Note that SRCU read-side
182141 * critical sections may be nested. However, it is illegal to
....@@ -191,44 +150,45 @@
191150 * srcu_read_unlock() in an irq handler if the matching srcu_read_lock()
192151 * was invoked in process context.
193152 */
194
-static inline int srcu_read_lock(struct srcu_struct *sp) __acquires(sp)
153
+static inline int srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp)
195154 {
196155 int retval;
197156
198
- retval = __srcu_read_lock(sp);
199
- rcu_lock_acquire(&(sp)->dep_map);
157
+ retval = __srcu_read_lock(ssp);
158
+ rcu_lock_acquire(&(ssp)->dep_map);
200159 return retval;
201160 }
202161
203162 /* Used by tracing, cannot be traced and cannot invoke lockdep. */
204163 static inline notrace int
205
-srcu_read_lock_notrace(struct srcu_struct *sp) __acquires(sp)
164
+srcu_read_lock_notrace(struct srcu_struct *ssp) __acquires(ssp)
206165 {
207166 int retval;
208167
209
- retval = __srcu_read_lock(sp);
168
+ retval = __srcu_read_lock(ssp);
210169 return retval;
211170 }
212171
213172 /**
214173 * srcu_read_unlock - unregister a old reader from an SRCU-protected structure.
215
- * @sp: srcu_struct in which to unregister the old reader.
174
+ * @ssp: srcu_struct in which to unregister the old reader.
216175 * @idx: return value from corresponding srcu_read_lock().
217176 *
218177 * Exit an SRCU read-side critical section.
219178 */
220
-static inline void srcu_read_unlock(struct srcu_struct *sp, int idx)
221
- __releases(sp)
179
+static inline void srcu_read_unlock(struct srcu_struct *ssp, int idx)
180
+ __releases(ssp)
222181 {
223
- rcu_lock_release(&(sp)->dep_map);
224
- __srcu_read_unlock(sp, idx);
182
+ WARN_ON_ONCE(idx & ~0x1);
183
+ rcu_lock_release(&(ssp)->dep_map);
184
+ __srcu_read_unlock(ssp, idx);
225185 }
226186
227187 /* Used by tracing, cannot be traced and cannot call lockdep. */
228188 static inline notrace void
229
-srcu_read_unlock_notrace(struct srcu_struct *sp, int idx) __releases(sp)
189
+srcu_read_unlock_notrace(struct srcu_struct *ssp, int idx) __releases(ssp)
230190 {
231
- __srcu_read_unlock(sp, idx);
191
+ __srcu_read_unlock(ssp, idx);
232192 }
233193
234194 /**