@@ -56,6 +56,13 @@ void call_srcu(struct srcu_struct *ssp, struct rcu_head *head,
56
56
void cleanup_srcu_struct (struct srcu_struct * ssp );
57
57
int __srcu_read_lock (struct srcu_struct * ssp ) __acquires (ssp );
58
58
void __srcu_read_unlock (struct srcu_struct * ssp , int idx ) __releases (ssp );
59
+ #ifdef CONFIG_TINY_SRCU
60
+ #define __srcu_read_lock_lite __srcu_read_lock
61
+ #define __srcu_read_unlock_lite __srcu_read_unlock
62
+ #else // #ifdef CONFIG_TINY_SRCU
63
+ int __srcu_read_lock_lite (struct srcu_struct * ssp ) __acquires (ssp );
64
+ void __srcu_read_unlock_lite (struct srcu_struct * ssp , int idx ) __releases (ssp );
65
+ #endif // #else // #ifdef CONFIG_TINY_SRCU
59
66
void synchronize_srcu (struct srcu_struct * ssp );
60
67
61
68
#define SRCU_GET_STATE_COMPLETED 0x1
@@ -176,17 +183,6 @@ static inline int srcu_read_lock_held(const struct srcu_struct *ssp)
176
183
177
184
#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
178
185
179
- #define SRCU_NMI_UNKNOWN 0x0
180
- #define SRCU_NMI_UNSAFE 0x1
181
- #define SRCU_NMI_SAFE 0x2
182
-
183
- #if defined(CONFIG_PROVE_RCU ) && defined(CONFIG_TREE_SRCU )
184
- void srcu_check_nmi_safety (struct srcu_struct * ssp , bool nmi_safe );
185
- #else
186
- static inline void srcu_check_nmi_safety (struct srcu_struct * ssp ,
187
- bool nmi_safe ) { }
188
- #endif
189
-
190
186
191
187
/**
192
188
* srcu_dereference_check - fetch SRCU-protected pointer for later dereferencing
@@ -236,33 +232,67 @@ static inline void srcu_check_nmi_safety(struct srcu_struct *ssp,
236
232
* a mutex that is held elsewhere while calling synchronize_srcu() or
237
233
* synchronize_srcu_expedited().
238
234
*
239
- * Note that srcu_read_lock() and the matching srcu_read_unlock() must
240
- * occur in the same context, for example, it is illegal to invoke
241
- * srcu_read_unlock() in an irq handler if the matching srcu_read_lock()
242
- * was invoked in process context.
235
+ * The return value from srcu_read_lock() must be passed unaltered
236
+ * to the matching srcu_read_unlock(). Note that srcu_read_lock() and
237
+ * the matching srcu_read_unlock() must occur in the same context, for
238
+ * example, it is illegal to invoke srcu_read_unlock() in an irq handler
239
+ * if the matching srcu_read_lock() was invoked in process context. Or,
240
+ * for that matter to invoke srcu_read_unlock() from one task and the
241
+ * matching srcu_read_lock() from another.
243
242
*/
244
243
static inline int srcu_read_lock (struct srcu_struct * ssp ) __acquires (ssp )
245
244
{
246
245
int retval ;
247
246
248
- srcu_check_nmi_safety (ssp , false );
247
+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
249
248
retval = __srcu_read_lock (ssp );
250
249
srcu_lock_acquire (& ssp -> dep_map );
251
250
return retval ;
252
251
}
253
252
253
+ /**
254
+ * srcu_read_lock_lite - register a new reader for an SRCU-protected structure.
255
+ * @ssp: srcu_struct in which to register the new reader.
256
+ *
257
+ * Enter an SRCU read-side critical section, but for a light-weight
258
+ * smp_mb()-free reader. See srcu_read_lock() for more information.
259
+ *
260
+ * If srcu_read_lock_lite() is ever used on an srcu_struct structure,
261
+ * then none of the other flavors may be used, whether before, during,
262
+ * or after. Note that grace-period auto-expediting is disabled for _lite
263
+ * srcu_struct structures because auto-expedited grace periods invoke
264
+ * synchronize_rcu_expedited(), IPIs and all.
265
+ *
266
+ * Note that srcu_read_lock_lite() can be invoked only from those contexts
267
+ * where RCU is watching, that is, from contexts where it would be legal
268
+ * to invoke rcu_read_lock(). Otherwise, lockdep will complain.
269
+ */
270
+ static inline int srcu_read_lock_lite (struct srcu_struct * ssp ) __acquires (ssp )
271
+ {
272
+ int retval ;
273
+
274
+ srcu_check_read_flavor_lite (ssp );
275
+ retval = __srcu_read_lock_lite (ssp );
276
+ rcu_try_lock_acquire (& ssp -> dep_map );
277
+ return retval ;
278
+ }
279
+
254
280
/**
255
281
* srcu_read_lock_nmisafe - register a new reader for an SRCU-protected structure.
256
282
* @ssp: srcu_struct in which to register the new reader.
257
283
*
258
284
* Enter an SRCU read-side critical section, but in an NMI-safe manner.
259
285
* See srcu_read_lock() for more information.
286
+ *
287
+ * If srcu_read_lock_nmisafe() is ever used on an srcu_struct structure,
288
+ * then none of the other flavors may be used, whether before, during,
289
+ * or after.
260
290
*/
261
291
static inline int srcu_read_lock_nmisafe (struct srcu_struct * ssp ) __acquires (ssp )
262
292
{
263
293
int retval ;
264
294
265
- srcu_check_nmi_safety (ssp , true );
295
+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NMI );
266
296
retval = __srcu_read_lock_nmisafe (ssp );
267
297
rcu_try_lock_acquire (& ssp -> dep_map );
268
298
return retval ;
@@ -274,7 +304,7 @@ srcu_read_lock_notrace(struct srcu_struct *ssp) __acquires(ssp)
274
304
{
275
305
int retval ;
276
306
277
- srcu_check_nmi_safety (ssp , false );
307
+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
278
308
retval = __srcu_read_lock (ssp );
279
309
return retval ;
280
310
}
@@ -303,7 +333,7 @@ srcu_read_lock_notrace(struct srcu_struct *ssp) __acquires(ssp)
303
333
static inline int srcu_down_read (struct srcu_struct * ssp ) __acquires (ssp )
304
334
{
305
335
WARN_ON_ONCE (in_nmi ());
306
- srcu_check_nmi_safety (ssp , false );
336
+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
307
337
return __srcu_read_lock (ssp );
308
338
}
309
339
@@ -318,11 +348,27 @@ static inline void srcu_read_unlock(struct srcu_struct *ssp, int idx)
318
348
__releases (ssp )
319
349
{
320
350
WARN_ON_ONCE (idx & ~0x1 );
321
- srcu_check_nmi_safety (ssp , false );
351
+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
322
352
srcu_lock_release (& ssp -> dep_map );
323
353
__srcu_read_unlock (ssp , idx );
324
354
}
325
355
356
+ /**
357
+ * srcu_read_unlock_lite - unregister a old reader from an SRCU-protected structure.
358
+ * @ssp: srcu_struct in which to unregister the old reader.
359
+ * @idx: return value from corresponding srcu_read_lock().
360
+ *
361
+ * Exit a light-weight SRCU read-side critical section.
362
+ */
363
+ static inline void srcu_read_unlock_lite (struct srcu_struct * ssp , int idx )
364
+ __releases (ssp )
365
+ {
366
+ WARN_ON_ONCE (idx & ~0x1 );
367
+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_LITE );
368
+ srcu_lock_release (& ssp -> dep_map );
369
+ __srcu_read_unlock_lite (ssp , idx );
370
+ }
371
+
326
372
/**
327
373
* srcu_read_unlock_nmisafe - unregister a old reader from an SRCU-protected structure.
328
374
* @ssp: srcu_struct in which to unregister the old reader.
@@ -334,7 +380,7 @@ static inline void srcu_read_unlock_nmisafe(struct srcu_struct *ssp, int idx)
334
380
__releases (ssp )
335
381
{
336
382
WARN_ON_ONCE (idx & ~0x1 );
337
- srcu_check_nmi_safety (ssp , true );
383
+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NMI );
338
384
rcu_lock_release (& ssp -> dep_map );
339
385
__srcu_read_unlock_nmisafe (ssp , idx );
340
386
}
@@ -343,7 +389,7 @@ static inline void srcu_read_unlock_nmisafe(struct srcu_struct *ssp, int idx)
343
389
static inline notrace void
344
390
srcu_read_unlock_notrace (struct srcu_struct * ssp , int idx ) __releases (ssp )
345
391
{
346
- srcu_check_nmi_safety (ssp , false );
392
+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
347
393
__srcu_read_unlock (ssp , idx );
348
394
}
349
395
@@ -360,7 +406,7 @@ static inline void srcu_up_read(struct srcu_struct *ssp, int idx)
360
406
{
361
407
WARN_ON_ONCE (idx & ~0x1 );
362
408
WARN_ON_ONCE (in_nmi ());
363
- srcu_check_nmi_safety (ssp , false );
409
+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
364
410
__srcu_read_unlock (ssp , idx );
365
411
}
366
412
0 commit comments