Skip to content

Commit 49f5903

Browse files
committed
rcu: Move preemption disabling out of __srcu_read_lock()
Currently, __srcu_read_lock() cannot be invoked from restricted environments because it contains calls to preempt_disable() and preempt_enable(), both of which can invoke lockdep, which is a bad idea in some restricted execution modes. This commit therefore moves the preempt_disable() and preempt_enable() from __srcu_read_lock() to srcu_read_lock(). It also inserts the preempt_disable() and preempt_enable() around the call to __srcu_read_lock() in do_exit(). Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org>
1 parent 7f21aee commit 49f5903

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

include/linux/srcu.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,11 @@ static inline int srcu_read_lock_held(struct srcu_struct *sp)
215215
*/
216216
static inline int srcu_read_lock(struct srcu_struct *sp) __acquires(sp)
217217
{
218-
int retval = __srcu_read_lock(sp);
218+
int retval;
219219

220+
preempt_disable();
221+
retval = __srcu_read_lock(sp);
222+
preempt_enable();
220223
rcu_lock_acquire(&(sp)->dep_map);
221224
return retval;
222225
}

kernel/exit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,9 @@ void do_exit(long code)
761761
*/
762762
flush_ptrace_hw_breakpoint(tsk);
763763

764+
TASKS_RCU(preempt_disable());
764765
TASKS_RCU(tasks_rcu_i = __srcu_read_lock(&tasks_rcu_exit_srcu));
766+
TASKS_RCU(preempt_enable());
765767
exit_notify(tsk, group_dead);
766768
proc_exit_connector(tsk);
767769
#ifdef CONFIG_NUMA

kernel/rcu/srcu.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
298298
int idx;
299299

300300
idx = READ_ONCE(sp->completed) & 0x1;
301-
preempt_disable();
302301
__this_cpu_inc(sp->per_cpu_ref->c[idx]);
303302
smp_mb(); /* B */ /* Avoid leaking the critical section. */
304303
__this_cpu_inc(sp->per_cpu_ref->seq[idx]);
305-
preempt_enable();
306304
return idx;
307305
}
308306
EXPORT_SYMBOL_GPL(__srcu_read_lock);

0 commit comments

Comments
 (0)