Skip to contentSkip to conversation

rcutorture: Convert schedule_timeout_uninterruptible() to mdelay() in rcu_torture_stall()

PATCH In review Zqiang 3 participants 7 messages Mar 20, 2023 – Mar 21, 2023

Subsystems (2)
lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH v2 1/1 rcutorture: Convert schedule_timeout_uninterruptible() to mdelay() in rcu_torture_stall()

For kernels built with enable PREEMPT_NONE and CONFIG_DEBUG_ATOMIC_SLEEP, running the RCU stall tests.

runqemu kvm slirp nographic qemuparams="-m 1024 -smp 4" bootparams="nokaslr console=ttyS0 rcutorture.stall_cpu=30 rcutorture.stall_no_softlockup=1 rcutorture.stall_cpu_irqsoff=1 rcutorture.stall_cpu_block=1" -d

[   10.841071] rcu-torture: rcu_torture_stall begin CPU stall
[   10.841073] rcu_torture_stall start on CPU 3.
[   10.841077] BUG: scheduling while atomic: rcu_torture_sta/66/0x0000000
....
[   10.841108] Call Trace:
[   10.841110]  <TASK>
[   10.841112]  dump_stack_lvl+0x64/0xb0
[   10.841118]  dump_stack+0x10/0x20
[   10.841121]  __schedule_bug+0x8b/0xb0
[   10.841126]  __schedule+0x2172/0x2940
[   10.841157]  schedule+0x9b/0x150
[   10.841160]  schedule_timeout+0x2e8/0x4f0
[   10.841192]  schedule_timeout_uninterruptible+0x47/0x50
[   10.841195]  rcu_torture_stall+0x2e8/0x300
[   10.841199]  kthread+0x175/0x1a0
[   10.841206]  ret_from_fork+0x2c/0x50

The above calltrace occurs in the local_irq_disable/enable() critical section call schedule_timeout(), and invoke schedule_timeout() also implies a quiescent state, of course it also fails to trigger RCU stall, this commit therefore use mdelay() instead of schedule_timeout() to trigger RCU stall.

---
 kernel/rcu/rcutorture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcutorture.c +1 -1
index d06c2da04c34..a08a72bef5f1 100644
@@ -2472,7 +2472,7 @@ static int rcu_torture_stall(void *args)
 #ifdef CONFIG_PREEMPTION
 				preempt_schedule();
 #else
-				schedule_timeout_uninterruptible(HZ);
+				mdelay(jiffies_to_msecs(HZ));
 #endif
 			} else if (stall_no_softlockup) {
 				touch_softlockup_watchdog();
Signature · 1 line
2.25.1
Tested-by on v2 1/1
#1 lore raw

Hi Qiang,

Quoted 8 lines

From: Zqiang <[email protected]>
Sent: Monday, March 20, 2023 11:24 AM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: [PATCH v2] rcutorture: Convert schedule_timeout_uninterruptible() to mdelay() in rcu_torture_stall()

For kernels built with enable PREEMPT_NONE and

s/enable/enabling/

Quoted 1 line

CONFIG_DEBUG_ATOMIC_SLEEP, running the RCU stall tests.

s/running/run

Quoted 23 lines

runqemu kvm slirp nographic qemuparams="-m 1024 -smp 4" bootparams="nokaslr console=ttyS0 rcutorture.stall_cpu=30 rcutorture.stall_no_softlockup=1 rcutorture.stall_cpu_irqsoff=1 rcutorture.stall_cpu_block=1" -d

[   10.841071] rcu-torture: rcu_torture_stall begin CPU stall
[   10.841073] rcu_torture_stall start on CPU 3.
[   10.841077] BUG: scheduling while atomic: rcu_torture_sta/66/0x0000000
....
[   10.841108] Call Trace:
[   10.841110]  <TASK>
[   10.841112]  dump_stack_lvl+0x64/0xb0
[   10.841118]  dump_stack+0x10/0x20
[   10.841121]  __schedule_bug+0x8b/0xb0
[   10.841126]  __schedule+0x2172/0x2940
[   10.841157]  schedule+0x9b/0x150
[   10.841160]  schedule_timeout+0x2e8/0x4f0
[   10.841192]  schedule_timeout_uninterruptible+0x47/0x50
[   10.841195]  rcu_torture_stall+0x2e8/0x300
[   10.841199]  kthread+0x175/0x1a0
[   10.841206]  ret_from_fork+0x2c/0x50
Quoted 4 lines

The above calltrace occurs in the local_irq_disable/enable() critical section call schedule_timeout(), and invoke schedule_timeout() also implies a quiescent state, of course it also fails to trigger RCU stall, this commit therefore use mdelay() instead of schedule_timeout() to trigger RCU stall.

Tweak the commit description above to fix some grammar errors:

The above call trace occurred in the local_irq_disable/enable() critical section when calling schedule_timeout() from rcu_torture_stall(). Invoking schedule_timeout() also implies a quiescent state, of course, it also fails to trigger RCU stall. This commit, therefore, uses mdelay() instead of schedule_timeout() to trigger the RCU stall.

Quoted 2 lines

I didn't reproduce the call trace after applying your patch. So, with the above minor fixes, then

Thanks
-Qiuxu

Quoted 19 lines
---
 kernel/rcu/rcutorture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcutorture.c index renamed from kernel/rcu/rcutorture.c +0 -0

d06c2da04c34..a08a72bef5f1 100644

kernel/rcu/rcutorture.c +0 -0
@@ -2472,7 +2472,7 @@ static int rcu_torture_stall(void *args)  #ifdef

CONFIG_PREEMPTION

kernel/rcu/rcutorture.c +1 -2
 				preempt_schedule();
 #else
-				schedule_timeout_uninterruptible(HZ);
+				mdelay(jiffies_to_msecs(HZ));
 #endif
 			} else if (stall_no_softlockup) {
 				touch_softlockup_watchdog();
--

2.25.1

maintainer
#2 lore raw
In reply to Zqiang

kernel/rcu/rcutorture.c static int rcu_torture_stall(void *args)

Quoted 42 lines · Zqiang

For kernels built with enable PREEMPT_NONE and CONFIG_DEBUG_ATOMIC_SLEEP, running the RCU stall tests.

runqemu kvm slirp nographic qemuparams="-m 1024 -smp 4" bootparams="nokaslr console=ttyS0 rcutorture.stall_cpu=30 rcutorture.stall_no_softlockup=1 rcutorture.stall_cpu_irqsoff=1 rcutorture.stall_cpu_block=1" -d

[   10.841071] rcu-torture: rcu_torture_stall begin CPU stall
[   10.841073] rcu_torture_stall start on CPU 3.
[   10.841077] BUG: scheduling while atomic: rcu_torture_sta/66/0x0000000
....
[   10.841108] Call Trace:
[   10.841110]  <TASK>
[   10.841112]  dump_stack_lvl+0x64/0xb0
[   10.841118]  dump_stack+0x10/0x20
[   10.841121]  __schedule_bug+0x8b/0xb0
[   10.841126]  __schedule+0x2172/0x2940
[   10.841157]  schedule+0x9b/0x150
[   10.841160]  schedule_timeout+0x2e8/0x4f0
[   10.841192]  schedule_timeout_uninterruptible+0x47/0x50
[   10.841195]  rcu_torture_stall+0x2e8/0x300
[   10.841199]  kthread+0x175/0x1a0
[   10.841206]  ret_from_fork+0x2c/0x50

The above calltrace occurs in the local_irq_disable/enable() critical section call schedule_timeout(), and invoke schedule_timeout() also implies a quiescent state, of course it also fails to trigger RCU stall, this commit therefore use mdelay() instead of schedule_timeout() to trigger RCU stall.

---
 kernel/rcu/rcutorture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcutorture.c +0 -0
index d06c2da04c34..a08a72bef5f1 100644
@@ -2472,7 +2472,7 @@ static int rcu_torture_stall(void *args)

Right here there is:

			if (stall_cpu_block) {

In other words, the rcutorture.stall_cpu_block module parameter says to block, even if it is a bad thing to do. The point of this is to verify the error messages that are supposed to be printed on the console when this happens.

kernel/rcu/rcutorture.c static int rcu_torture_stall(void *args) · line 2475

Quoted 5 lines
kernel/rcu/rcutorture.c +1 -1
 #ifdef CONFIG_PREEMPTION
 				preempt_schedule();
 #else
-				schedule_timeout_uninterruptible(HZ);
+				mdelay(jiffies_to_msecs(HZ));

So this really needs to stay schedule_timeout_uninterruptible(HZ).

So should there be a change to kernel-parameters.txt to make it more clear that this is intended behavior?

Thanx, Paul

Quoted 6 lines
kernel/rcu/rcutorture.c +0 -0
 #endif
 			} else if (stall_no_softlockup) {
 				touch_softlockup_watchdog();
Signature · 1 line
2.25.1
#3 lore raw
Quoted 58 lines

For kernels built with enable PREEMPT_NONE and CONFIG_DEBUG_ATOMIC_SLEEP, running the RCU stall tests.

runqemu kvm slirp nographic qemuparams="-m 1024 -smp 4" bootparams="nokaslr console=ttyS0 rcutorture.stall_cpu=30 rcutorture.stall_no_softlockup=1 rcutorture.stall_cpu_irqsoff=1 rcutorture.stall_cpu_block=1" -d

[   10.841071] rcu-torture: rcu_torture_stall begin CPU stall
[   10.841073] rcu_torture_stall start on CPU 3.
[   10.841077] BUG: scheduling while atomic: rcu_torture_sta/66/0x0000000
....
[   10.841108] Call Trace:
[   10.841110]  <TASK>
[   10.841112]  dump_stack_lvl+0x64/0xb0
[   10.841118]  dump_stack+0x10/0x20
[   10.841121]  __schedule_bug+0x8b/0xb0
[   10.841126]  __schedule+0x2172/0x2940
[   10.841157]  schedule+0x9b/0x150
[   10.841160]  schedule_timeout+0x2e8/0x4f0
[   10.841192]  schedule_timeout_uninterruptible+0x47/0x50
[   10.841195]  rcu_torture_stall+0x2e8/0x300
[   10.841199]  kthread+0x175/0x1a0
[   10.841206]  ret_from_fork+0x2c/0x50

The above calltrace occurs in the local_irq_disable/enable() critical section call schedule_timeout(), and invoke schedule_timeout() also implies a quiescent state, of course it also fails to trigger RCU stall, this commit therefore use mdelay() instead of schedule_timeout() to trigger RCU stall.

---
 kernel/rcu/rcutorture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcutorture.c +0 -0
index d06c2da04c34..a08a72bef5f1 100644
@@ -2472,7 +2472,7 @@ static int rcu_torture_stall(void *args)
 

Right here there is:

			if (stall_cpu_block) {

In other words, the rcutorture.stall_cpu_block module parameter says to block, even if it is a bad thing to do. The point of this is to verify the error messages that are supposed to be printed on the console when this happens.

#ifdef CONFIG_PREEMPTION

kernel/rcu/rcutorture.c +1 -1
 				preempt_schedule();
 #else
-				schedule_timeout_uninterruptible(HZ);
+				mdelay(jiffies_to_msecs(HZ));
Quoted 1 line

So this really needs to stay schedule_timeout_uninterruptible(HZ).

But invoke schedule_timeout_uninterruptible(HZ) implies a quiescent state,
this will not cause an RCU stall to occur, and still in the RCU read critical section(PREEMPT_COUNT=y).

It didn't happen RCU stall when I tested with the following parameters for rcutorture.stall_cpu=30
rcutorture.stall_no_softlockup=1 rcutorture.stall_cpu_irqsoff=1
rcutorture.stall_cpu_block=1

Thanks
Zqiang

Quoted 12 lines

So should there be a change to kernel-parameters.txt to make it more clear that this is intended behavior?

Thanx, Paul

#endif

kernel/rcu/rcutorture.c +0 -0
 			} else if (stall_no_softlockup) {
 				touch_softlockup_watchdog();
Signature · 1 line
2.25.1
maintainer
#4 lore raw
Quoted 63 lines · On Mon, Mar 20, 2023 at 11:05:17PM +0000, Zhang, Qiang1 wrote:
Quoted 58 lines

For kernels built with enable PREEMPT_NONE and CONFIG_DEBUG_ATOMIC_SLEEP, running the RCU stall tests.

runqemu kvm slirp nographic qemuparams="-m 1024 -smp 4" bootparams="nokaslr console=ttyS0 rcutorture.stall_cpu=30 rcutorture.stall_no_softlockup=1 rcutorture.stall_cpu_irqsoff=1 rcutorture.stall_cpu_block=1" -d

[   10.841071] rcu-torture: rcu_torture_stall begin CPU stall
[   10.841073] rcu_torture_stall start on CPU 3.
[   10.841077] BUG: scheduling while atomic: rcu_torture_sta/66/0x0000000
....
[   10.841108] Call Trace:
[   10.841110]  <TASK>
[   10.841112]  dump_stack_lvl+0x64/0xb0
[   10.841118]  dump_stack+0x10/0x20
[   10.841121]  __schedule_bug+0x8b/0xb0
[   10.841126]  __schedule+0x2172/0x2940
[   10.841157]  schedule+0x9b/0x150
[   10.841160]  schedule_timeout+0x2e8/0x4f0
[   10.841192]  schedule_timeout_uninterruptible+0x47/0x50
[   10.841195]  rcu_torture_stall+0x2e8/0x300
[   10.841199]  kthread+0x175/0x1a0
[   10.841206]  ret_from_fork+0x2c/0x50

The above calltrace occurs in the local_irq_disable/enable() critical section call schedule_timeout(), and invoke schedule_timeout() also implies a quiescent state, of course it also fails to trigger RCU stall, this commit therefore use mdelay() instead of schedule_timeout() to trigger RCU stall.

---
 kernel/rcu/rcutorture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcutorture.c +0 -0
index d06c2da04c34..a08a72bef5f1 100644
@@ -2472,7 +2472,7 @@ static int rcu_torture_stall(void *args)
 

Right here there is:

			if (stall_cpu_block) {

In other words, the rcutorture.stall_cpu_block module parameter says to block, even if it is a bad thing to do. The point of this is to verify the error messages that are supposed to be printed on the console when this happens.

#ifdef CONFIG_PREEMPTION

kernel/rcu/rcutorture.c +1 -1
 				preempt_schedule();
 #else
-				schedule_timeout_uninterruptible(HZ);
+				mdelay(jiffies_to_msecs(HZ));
Quoted 1 line

So this really needs to stay schedule_timeout_uninterruptible(HZ).

But invoke schedule_timeout_uninterruptible(HZ) implies a quiescent state,
this will not cause an RCU stall to occur, and still in the RCU read critical section(PREEMPT_COUNT=y).

Quoted 5 lines

It didn't happen RCU stall when I tested with the following parameters for rcutorture.stall_cpu=30
rcutorture.stall_no_softlockup=1 rcutorture.stall_cpu_irqsoff=1
rcutorture.stall_cpu_block=1

Understood. If you want that RCU CPU stall in a CONFIG_PREEMPTION=n kernel, you should not use rcutorture.stall_cpu_block=1.

In a CONFIG_PREEMPTION=y kernel, rcutorture.stall_cpu_block=1 forces the grace period to be stalled on a task rather than a CPU, exercising a different part of the RCU CPU stall warning code.

In a CONFIG_PREEMPTION=n kernel, using rcutorture.stall_cpu_block=1 forces the CPU to go through a quiescent state, as you say. It can also cause lockdep and scheduling-while-atomic complaints, depending on exactly what type of RCU reader is in effect.

So these are test-the-diagnostics parameters. The mdelay() instead makes rcutorture.stall_cpu_block=1 do the same thing as does rcutorture.stall_cpu_block=0 for CONFIG_PREEMPTION=n kernels, right?

Thanx, Paul

Quoted 15 lines

Thanks
Zqiang

Quoted 12 lines

So should there be a change to kernel-parameters.txt to make it more clear that this is intended behavior?

Thanx, Paul

#endif

kernel/rcu/rcutorture.c +0 -0
 			} else if (stall_no_softlockup) {
 				touch_softlockup_watchdog();
Signature · 1 line
2.25.1
#5 lore raw
Quoted 76 lines
Quoted 58 lines

For kernels built with enable PREEMPT_NONE and CONFIG_DEBUG_ATOMIC_SLEEP, running the RCU stall tests.

runqemu kvm slirp nographic qemuparams="-m 1024 -smp 4" bootparams="nokaslr console=ttyS0 rcutorture.stall_cpu=30 rcutorture.stall_no_softlockup=1 rcutorture.stall_cpu_irqsoff=1 rcutorture.stall_cpu_block=1" -d

[   10.841071] rcu-torture: rcu_torture_stall begin CPU stall
[   10.841073] rcu_torture_stall start on CPU 3.
[   10.841077] BUG: scheduling while atomic: rcu_torture_sta/66/0x0000000
....
[   10.841108] Call Trace:
[   10.841110]  <TASK>
[   10.841112]  dump_stack_lvl+0x64/0xb0
[   10.841118]  dump_stack+0x10/0x20
[   10.841121]  __schedule_bug+0x8b/0xb0
[   10.841126]  __schedule+0x2172/0x2940
[   10.841157]  schedule+0x9b/0x150
[   10.841160]  schedule_timeout+0x2e8/0x4f0
[   10.841192]  schedule_timeout_uninterruptible+0x47/0x50
[   10.841195]  rcu_torture_stall+0x2e8/0x300
[   10.841199]  kthread+0x175/0x1a0
[   10.841206]  ret_from_fork+0x2c/0x50

The above calltrace occurs in the local_irq_disable/enable() critical section call schedule_timeout(), and invoke schedule_timeout() also implies a quiescent state, of course it also fails to trigger RCU stall, this commit therefore use mdelay() instead of schedule_timeout() to trigger RCU stall.

---
 kernel/rcu/rcutorture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcutorture.c +0 -0
index d06c2da04c34..a08a72bef5f1 100644
@@ -2472,7 +2472,7 @@ static int rcu_torture_stall(void *args)
 

Right here there is:

			if (stall_cpu_block) {

In other words, the rcutorture.stall_cpu_block module parameter says to block, even if it is a bad thing to do. The point of this is to verify the error messages that are supposed to be printed on the console when this happens.

#ifdef CONFIG_PREEMPTION

kernel/rcu/rcutorture.c +1 -1
 				preempt_schedule();
 #else
-				schedule_timeout_uninterruptible(HZ);
+				mdelay(jiffies_to_msecs(HZ));
Quoted 1 line

So this really needs to stay schedule_timeout_uninterruptible(HZ).

But invoke schedule_timeout_uninterruptible(HZ) implies a quiescent state,
this will not cause an RCU stall to occur, and still in the RCU read critical section(PREEMPT_COUNT=y).

It didn't happen RCU stall when I tested with the following parameters for rcutorture.stall_cpu=30
rcutorture.stall_no_softlockup=1 rcutorture.stall_cpu_irqsoff=1
rcutorture.stall_cpu_block=1

Understood. If you want that RCU CPU stall in a CONFIG_PREEMPTION=n kernel, you should not use rcutorture.stall_cpu_block=1.

In a CONFIG_PREEMPTION=y kernel, rcutorture.stall_cpu_block=1 forces the grace period to be stalled on a task rather than a CPU, exercising a different part of the RCU CPU stall warning code.

Quoted 8 lines

In a CONFIG_PREEMPTION=n kernel, using rcutorture.stall_cpu_block=1 forces the CPU to go through a quiescent state, as you say. It can also cause lockdep and scheduling-while-atomic complaints, depending on exactly what type of RCU reader is in effect.

So these are test-the-diagnostics parameters. The mdelay() instead makes rcutorture.stall_cpu_block=1 do the same thing as does rcutorture.stall_cpu_block=0 for CONFIG_PREEMPTION=n kernels, right?

Yes, maybe we can increase the description of the stall_cpu_block in kernel-parameters.txt.

Quoted 9 lines

Thanx, Paul

Thanks
Zqiang

Quoted 3 lines

So should there be a change to kernel-parameters.txt to make it more clear that this is intended behavior?

Agree

Thanks
Zqiang

Quoted 9 lines
Quoted 9 lines

Thanx, Paul

#endif

kernel/rcu/rcutorture.c +0 -0
 			} else if (stall_no_softlockup) {
 				touch_softlockup_watchdog();
Signature · 1 line
2.25.1
#6 lore raw
In reply to Paul E. McKenney
Quoted 13 lines

From: Paul E. McKenney <[email protected]>
[...]

Quoted 2 lines

But invoke schedule_timeout_uninterruptible(HZ) implies a quiescent state, this will not cause an RCU stall to occur, and still in the RCU read

critical section(PREEMPT_COUNT=y).

Quoted 7 lines

It didn't happen RCU stall when I tested with the following parameters for
rcutorture.stall_cpu=30
rcutorture.stall_no_softlockup=1 rcutorture.stall_cpu_irqsoff=1
rcutorture.stall_cpu_block=1

Quoted 3 lines

Understood. If you want that RCU CPU stall in a CONFIG_PREEMPTION=n kernel, you should not use rcutorture.stall_cpu_block=1.

Verified.

if rcutorture.stall_cpu_block=0, it can trigger the expected RCU CPU stall for either torture_type=srcu or torture_type=rcu.

Quoted 9 lines

In a CONFIG_PREEMPTION=y kernel, rcutorture.stall_cpu_block=1 forces the grace period to be stalled on a task rather than a CPU, exercising a different part of the RCU CPU stall warning code.

In a CONFIG_PREEMPTION=n kernel, using rcutorture.stall_cpu_block=1 forces the CPU to go through a quiescent state, as you say. It can also cause lockdep and scheduling-while-atomic complaints, depending on exactly what type of RCU reader is in effect.

Verified.

If rcutorture.stall_cpu_block=1:
There were lockdep and scheduling-while-atomic complaints for torture_type=rcu. No lockdep and scheduling-while-atomic complaints for torture_type=srcu.

Quoted 3 lines

So these are test-the-diagnostics parameters. The mdelay() instead makes rcutorture.stall_cpu_block=1 do the same thing as does rcutorture.stall_cpu_block=0 for CONFIG_PREEMPTION=n kernels, right?

Good to know that these are test-the-diagnostics parameters and their expected behaviors. ;-) Thanks!

-Qiuxu

Quoted 1 line

Thanx, Paul