Skip to content

Commit f8b8df1

Browse files
paulmckrcufbq
authored andcommitted
srcu: Add srcu_down_read_fast() and srcu_up_read_fast()
A pair of matching srcu_read_lock_fast() and srcu_read_unlock_fast() invocations must take place within the same context, for example, within the same task. Otherwise, lockdep complains, as is the right thing to do for most use cases. However, there are use cases involving tracing (for example, uretprobes) in which an SRCU reader needs to begin in one task and end in a timer handler, which might interrupt some other task. This commit therefore supplies the semaphore-like srcu_down_read_fast() and srcu_up_read_fast() functions, which act like srcu_read_lock_fast() and srcu_read_unlock_fast(), but permitting srcu_up_read_fast() to be invoked in a different context than was the matching srcu_down_read_fast(). Neither srcu_down_read_fast() nor srcu_up_read_fast() may be invoked from an NMI handler. Reported-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: <bpf@vger.kernel.org> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
1 parent 729fb74 commit f8b8df1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

include/linux/srcu.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,24 @@ static inline struct srcu_ctr __percpu *srcu_read_lock_fast(struct srcu_struct *
281281
return retval;
282282
}
283283

284+
/**
285+
* srcu_down_read_fast - register a new reader for an SRCU-protected structure.
286+
* @ssp: srcu_struct in which to register the new reader.
287+
*
288+
* Enter a semaphore-like SRCU read-side critical section, but for
289+
* a light-weight smp_mb()-free reader. See srcu_read_lock_fast() and
290+
* srcu_down_read() for more information.
291+
*
292+
* The same srcu_struct may be used concurrently by srcu_down_read_fast()
293+
* and srcu_read_lock_fast().
294+
*/
295+
static inline struct srcu_ctr __percpu *srcu_down_read_fast(struct srcu_struct *ssp) __acquires(ssp)
296+
{
297+
WARN_ON_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && in_nmi());
298+
srcu_check_read_flavor_force(ssp, SRCU_READ_FLAVOR_FAST);
299+
return __srcu_read_lock_fast(ssp);
300+
}
301+
284302
/**
285303
* srcu_read_lock_lite - register a new reader for an SRCU-protected structure.
286304
* @ssp: srcu_struct in which to register the new reader.
@@ -400,6 +418,22 @@ static inline void srcu_read_unlock_fast(struct srcu_struct *ssp, struct srcu_ct
400418
__srcu_read_unlock_fast(ssp, scp);
401419
}
402420

421+
/**
422+
* srcu_up_read_fast - unregister a old reader from an SRCU-protected structure.
423+
* @ssp: srcu_struct in which to unregister the old reader.
424+
* @scp: return value from corresponding srcu_read_lock_fast().
425+
*
426+
* Exit an SRCU read-side critical section, but not necessarily from
427+
* the same context as the maching srcu_down_read_fast().
428+
*/
429+
static inline void srcu_up_read_fast(struct srcu_struct *ssp, struct srcu_ctr __percpu *scp)
430+
__releases(ssp)
431+
{
432+
WARN_ON_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && in_nmi());
433+
srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_FAST);
434+
__srcu_read_unlock_fast(ssp, scp);
435+
}
436+
403437
/**
404438
* srcu_read_unlock_lite - unregister a old reader from an SRCU-protected structure.
405439
* @ssp: srcu_struct in which to unregister the old reader.

0 commit comments

Comments
 (0)