@@ -56,6 +56,13 @@ void call_srcu(struct srcu_struct *ssp, struct rcu_head *head,
5656void cleanup_srcu_struct (struct srcu_struct * ssp );
5757int __srcu_read_lock (struct srcu_struct * ssp ) __acquires (ssp );
5858void __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
5966void synchronize_srcu (struct srcu_struct * ssp );
6067
6168#define SRCU_GET_STATE_COMPLETED 0x1
@@ -176,17 +183,6 @@ static inline int srcu_read_lock_held(const struct srcu_struct *ssp)
176183
177184#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
178185
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-
190186
191187/**
192188 * 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,
236232 * a mutex that is held elsewhere while calling synchronize_srcu() or
237233 * synchronize_srcu_expedited().
238234 *
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.
243242 */
244243static inline int srcu_read_lock (struct srcu_struct * ssp ) __acquires (ssp )
245244{
246245 int retval ;
247246
248- srcu_check_nmi_safety (ssp , false );
247+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
249248 retval = __srcu_read_lock (ssp );
250249 srcu_lock_acquire (& ssp -> dep_map );
251250 return retval ;
252251}
253252
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+
254280/**
255281 * srcu_read_lock_nmisafe - register a new reader for an SRCU-protected structure.
256282 * @ssp: srcu_struct in which to register the new reader.
257283 *
258284 * Enter an SRCU read-side critical section, but in an NMI-safe manner.
259285 * 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.
260290 */
261291static inline int srcu_read_lock_nmisafe (struct srcu_struct * ssp ) __acquires (ssp )
262292{
263293 int retval ;
264294
265- srcu_check_nmi_safety (ssp , true );
295+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NMI );
266296 retval = __srcu_read_lock_nmisafe (ssp );
267297 rcu_try_lock_acquire (& ssp -> dep_map );
268298 return retval ;
@@ -274,7 +304,7 @@ srcu_read_lock_notrace(struct srcu_struct *ssp) __acquires(ssp)
274304{
275305 int retval ;
276306
277- srcu_check_nmi_safety (ssp , false );
307+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
278308 retval = __srcu_read_lock (ssp );
279309 return retval ;
280310}
@@ -303,7 +333,7 @@ srcu_read_lock_notrace(struct srcu_struct *ssp) __acquires(ssp)
303333static inline int srcu_down_read (struct srcu_struct * ssp ) __acquires (ssp )
304334{
305335 WARN_ON_ONCE (in_nmi ());
306- srcu_check_nmi_safety (ssp , false );
336+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
307337 return __srcu_read_lock (ssp );
308338}
309339
@@ -318,11 +348,27 @@ static inline void srcu_read_unlock(struct srcu_struct *ssp, int idx)
318348 __releases (ssp )
319349{
320350 WARN_ON_ONCE (idx & ~0x1 );
321- srcu_check_nmi_safety (ssp , false );
351+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
322352 srcu_lock_release (& ssp -> dep_map );
323353 __srcu_read_unlock (ssp , idx );
324354}
325355
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+
326372/**
327373 * srcu_read_unlock_nmisafe - unregister a old reader from an SRCU-protected structure.
328374 * @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)
334380 __releases (ssp )
335381{
336382 WARN_ON_ONCE (idx & ~0x1 );
337- srcu_check_nmi_safety (ssp , true );
383+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NMI );
338384 rcu_lock_release (& ssp -> dep_map );
339385 __srcu_read_unlock_nmisafe (ssp , idx );
340386}
@@ -343,7 +389,7 @@ static inline void srcu_read_unlock_nmisafe(struct srcu_struct *ssp, int idx)
343389static inline notrace void
344390srcu_read_unlock_notrace (struct srcu_struct * ssp , int idx ) __releases (ssp )
345391{
346- srcu_check_nmi_safety (ssp , false );
392+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
347393 __srcu_read_unlock (ssp , idx );
348394}
349395
@@ -360,7 +406,7 @@ static inline void srcu_up_read(struct srcu_struct *ssp, int idx)
360406{
361407 WARN_ON_ONCE (idx & ~0x1 );
362408 WARN_ON_ONCE (in_nmi ());
363- srcu_check_nmi_safety (ssp , false );
409+ srcu_check_read_flavor (ssp , SRCU_READ_FLAVOR_NORMAL );
364410 __srcu_read_unlock (ssp , idx );
365411}
366412
0 commit comments