Skip to content

Commit 0be4b19

Browse files
paulmckrcufbq
authored andcommitted
rcutorture: Update rcutorture_one_extend_check() for lazy preemption
The rcutorture_one_extend_check() function's last check assumes that if cur_ops->readlock_nesting() returns greater than zero, either the RCUTORTURE_RDR_RCU_1 or the RCUTORTURE_RDR_RCU_2 bit must be set, that is, there must be at least one rcu_read_lock() in effect. This works for preemptible RCU and for non-preemptible RCU running in a non-preemptible kernel. But it fails for non-preemptible RCU running in a preemptible kernel because then RCU's cur_ops->readlock_nesting() function, which is rcu_torture_readlock_nesting(), will return the PREEMPT_MASK mask bits from preempt_count(). The result will be greater than zero if preemption is disabled, including by the RCUTORTURE_RDR_PREEMPT and RCUTORTURE_RDR_SCHED bits. This commit therefore adjusts this check to take into account the case fo non-preemptible RCU running in a preemptible kernel. [boqun: Fix the if condition and add comment] Reported-by: kernel test robot <oliver.sang@intel.com> Closes: https://lore.kernel.org/oe-lkp/202502171415.8ec87c87-lkp@intel.com Co-developed-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Co-developed-by: Joel Fernandes <joelagnelf@nvidia.com> Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Tested-by: kernel test robot <oliver.sang@intel.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
1 parent 9fd858c commit 0be4b19

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

kernel/rcu/rcutorture.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,8 @@ static void rcu_torture_reader_do_mbchk(long myid, struct rcu_torture *rtp,
18731873
#define ROEC_ARGS "%s %s: Current %#x To add %#x To remove %#x preempt_count() %#x\n", __func__, s, curstate, new, old, preempt_count()
18741874
static void rcutorture_one_extend_check(char *s, int curstate, int new, int old, bool insoftirq)
18751875
{
1876+
int mask;
1877+
18761878
if (!IS_ENABLED(CONFIG_RCU_TORTURE_TEST_CHK_RDR_STATE))
18771879
return;
18781880

@@ -1902,8 +1904,16 @@ static void rcutorture_one_extend_check(char *s, int curstate, int new, int old,
19021904
WARN_ONCE(cur_ops->extendables &&
19031905
!(curstate & (RCUTORTURE_RDR_PREEMPT | RCUTORTURE_RDR_SCHED)) &&
19041906
(preempt_count() & PREEMPT_MASK), ROEC_ARGS);
1905-
WARN_ONCE(cur_ops->readlock_nesting &&
1906-
!(curstate & (RCUTORTURE_RDR_RCU_1 | RCUTORTURE_RDR_RCU_2)) &&
1907+
1908+
/*
1909+
* non-preemptible RCU in a preemptible kernel uses "preempt_count() &
1910+
* PREEMPT_MASK" as ->readlock_nesting().
1911+
*/
1912+
mask = RCUTORTURE_RDR_RCU_1 | RCUTORTURE_RDR_RCU_2;
1913+
if (!IS_ENABLED(CONFIG_PREEMPT_RCU))
1914+
mask |= RCUTORTURE_RDR_PREEMPT | RCUTORTURE_RDR_SCHED;
1915+
1916+
WARN_ONCE(cur_ops->readlock_nesting && !(curstate & mask) &&
19071917
cur_ops->readlock_nesting() > 0, ROEC_ARGS);
19081918
}
19091919

0 commit comments

Comments
 (0)