Skip to contentSkip to conversation

My torture test related fixes for v7.5

PATCH In review Joel Fernandes 3 participants 12 messages Nov 9 – Nov 12

Subsystems (3)
lore
Share & tools
lore

Joel Fernandes

author maintainer
#0 lore raw

v2 cover My torture test related fixes for v7.5

Some test related fixes for v7.5 from me. Sending a v2 as I had to add a MAINTAINERS entry to fix git send-email.

Joel Fernandes (5):
rcu-tasks: Track barrier callbacks in debugobjects
scftorture: Reject empty workloads before starting helpers
scftorture: Protect the initial affinity check from hotplug
kasan: Avoid an unrelated RCU warning in the callback test
MAINTAINERS: Add scftorture to TORTURE-TEST MODULES

 MAINTAINERS             |  2 ++
 kernel/rcu/tasks.h      |  3 +++
 kernel/scftorture.c     | 30 +++++++++++++++++++++++-------
 mm/kasan/kasan_test_c.c |  3 ++-
 4 files changed, 30 insertions(+), 8 deletions(-)
Signature · 1 line
2.54.0
author maintainer
#1 lore raw

PATCH v2 1/5 rcu-tasks: Track barrier callbacks in debugobjects

rcu_tasks_invoke_cbs() now unqueues each callback from debugobjects. However, rcu_barrier_tasks_generic() inserts its per-CPU barrier heads directly with rcu_segcblist_entrain(), bypassing the queue hook in call_rcu_tasks_generic(). This produces active_state and deactivate warnings for untracked objects when a barrier callback runs.

Activate each barrier head before entrainment and undo that activation when there are no callbacks to entrain behind. Successful entrainment is balanced by the invocation path, as for ordinary callbacks.

The existing n_barrier_cbs=2 torture test reproduces the warnings before this change and completes without them afterwards.

This fixes patch "rcu-tasks: Detect duplicate callback enqueue".

Cc Kunwu Chan <[email protected]>
Cc Paul E. McKenney <[email protected]>
---
 kernel/rcu/tasks.h | 3 +++
 1 file changed, 3 insertions(+)
kernel/rcu/tasks.h +3 -0
index d5d060a5c4b6..a20db323612b 100644
@@ -470,9 +470,12 @@ static void __maybe_unused rcu_barrier_tasks_generic(struct rcu_tasks *rtp)
 			break;
 		rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu);
 		rtpcp->barrier_q_head.func = rcu_barrier_tasks_generic_cb;
+		debug_rcu_head_queue(&rtpcp->barrier_q_head);
 		raw_spin_lock_irqsave_rcu_node(rtpcp, flags);
 		if (rcu_segcblist_entrain(&rtpcp->cblist, &rtpcp->barrier_q_head))
 			atomic_inc(&rtp->barrier_q_count);
+		else
+			debug_rcu_head_unqueue(&rtpcp->barrier_q_head);
 		raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags);
 	}
 	if (atomic_sub_and_test(2, &rtp->barrier_q_count))
Signature · 1 line
2.54.0
maintainer
#2 lore raw

Re: [PATCH v2 1/5] rcu-tasks: Track barrier callbacks in debugobjects

Quoted 10 lines · Joel Fernandes

rcu_tasks_invoke_cbs() now unqueues each callback from debugobjects. However, rcu_barrier_tasks_generic() inserts its per-CPU barrier heads directly with rcu_segcblist_entrain(), bypassing the queue hook in call_rcu_tasks_generic(). This produces active_state and deactivate warnings for untracked objects when a barrier callback runs.

Activate each barrier head before entrainment and undo that activation when there are no callbacks to entrain behind. Successful entrainment is balanced by the invocation path, as for ordinary callbacks.

Quoted 8 lines

The existing n_barrier_cbs=2 torture test reproduces the warnings before this change and completes without them afterwards.

This fixes patch "rcu-tasks: Detect duplicate callback enqueue".

Cc Kunwu Chan <[email protected]>
Cc Paul E. McKenney <[email protected]>

This looks good to me, but I strongly suggest squashing it into the original patch for bisectability. With appropriate attribution, of course.

Thanx, Paul

Quoted 24 lines
---
 kernel/rcu/tasks.h | 3 +++
 1 file changed, 3 insertions(+)
kernel/rcu/tasks.h +3 -0
index d5d060a5c4b6..a20db323612b 100644
@@ -470,9 +470,12 @@ static void __maybe_unused rcu_barrier_tasks_generic(struct rcu_tasks *rtp)
 			break;
 		rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu);
 		rtpcp->barrier_q_head.func = rcu_barrier_tasks_generic_cb;
+		debug_rcu_head_queue(&rtpcp->barrier_q_head);
 		raw_spin_lock_irqsave_rcu_node(rtpcp, flags);
 		if (rcu_segcblist_entrain(&rtpcp->cblist, &rtpcp->barrier_q_head))
 			atomic_inc(&rtp->barrier_q_count);
+		else
+			debug_rcu_head_unqueue(&rtpcp->barrier_q_head);
 		raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags);
 	}
 	if (atomic_sub_and_test(2, &rtp->barrier_q_count))
Signature · 1 line
2.54.0
author maintainer
#3 lore raw

PATCH v2 2/5 scftorture: Reject empty workloads before starting helpers

In reply to Joel Fernandes

A module loaded with nthreads=0 starts its statistics task, but cleanup skips stopping that task. Unloading the module then leaves it executing freed module text. Reject a zero thread count before starting helpers; negative counts still select the online CPU count.

Also, when built as a module with reschedule-only, this leaves the selector empty because resched_cpu() is unavailable to modules. It warns while selecting an operation, invokes no callbacks, and can nevertheless report SUCCESS. Reject an empty effective selector after filtering unsupported operations.

Both failures were reproduced in a guest without the patches.

---
 kernel/scftorture.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
kernel/scftorture.c +11 -0
index 603b2dba1536..ff9a8271a464 100644
@@ -588,6 +588,12 @@ static int __init scf_torture_init(void)
 
 	scftorture_print_module_parms("Start of test");
 
+	if (!nthreads) {
+		SCFTORTOUT_ERRSTRING("nthreads must be nonzero");
+		firsterr = -EINVAL;
+		goto unwind;
+	}
+
 	if (weight_resched <= 0 &&
 	    weight_single <= 0 && weight_single_rpc <= 0 && weight_single_wait <= 0 &&
 	    weight_many <= 0 && weight_many_wait <= 0 &&
@@ -636,6 +642,11 @@ static int __init scf_torture_init(void)
 	scf_sel_add(weight_many_wait1, SCF_PRIM_MANY, true);
 	scf_sel_add(weight_all1, SCF_PRIM_ALL, false);
 	scf_sel_add(weight_all_wait1, SCF_PRIM_ALL, true);
+	if (!scf_sel_array_len) {
+		SCFTORTOUT_ERRSTRING("no supported operations selected");
+		firsterr = -EINVAL;
+		goto unwind;
+	}
 	scf_sel_dump();
 
 	if (onoff_interval > 0) {
Signature · 1 line
2.54.0
maintainer Reviewed-by on v2 2/5
#4 lore raw

Re: [PATCH v2 2/5] scftorture: Reject empty workloads before starting helpers

Quoted 11 lines · Joel Fernandes

A module loaded with nthreads=0 starts its statistics task, but cleanup skips stopping that task. Unloading the module then leaves it executing freed module text. Reject a zero thread count before starting helpers; negative counts still select the online CPU count.

Also, when built as a module with reschedule-only, this leaves the selector empty because resched_cpu() is unavailable to modules. It warns while selecting an operation, invokes no callbacks, and can nevertheless report SUCCESS. Reject an empty effective selector after filtering unsupported operations.

Quoted 3 lines

Both failures were reproduced in a guest without the patches.

If you wish, you could split this into two commits, but your call.

Thanx, Paul

Quoted 36 lines
---
 kernel/scftorture.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
kernel/scftorture.c +11 -0
index 603b2dba1536..ff9a8271a464 100644
@@ -588,6 +588,12 @@ static int __init scf_torture_init(void)
 
 	scftorture_print_module_parms("Start of test");
 
+	if (!nthreads) {
+		SCFTORTOUT_ERRSTRING("nthreads must be nonzero");
+		firsterr = -EINVAL;
+		goto unwind;
+	}
+
 	if (weight_resched <= 0 &&
 	    weight_single <= 0 && weight_single_rpc <= 0 && weight_single_wait <= 0 &&
 	    weight_many <= 0 && weight_many_wait <= 0 &&
@@ -636,6 +642,11 @@ static int __init scf_torture_init(void)
 	scf_sel_add(weight_many_wait1, SCF_PRIM_MANY, true);
 	scf_sel_add(weight_all1, SCF_PRIM_ALL, false);
 	scf_sel_add(weight_all_wait1, SCF_PRIM_ALL, true);
+	if (!scf_sel_array_len) {
+		SCFTORTOUT_ERRSTRING("no supported operations selected");
+		firsterr = -EINVAL;
+		goto unwind;
+	}
 	scf_sel_dump();
 
 	if (onoff_interval > 0) {
Signature · 1 line
2.54.0
author maintainer
#5 lore raw

PATCH v2 3/5 scftorture: Protect the initial affinity check from hotplug

In reply to Joel Fernandes

An invoker binds to its target CPU, sleeps for the holdoff interval, and then warns if it is running elsewhere. CPU hotplug can offline the target during that sleep and legitimately move the invoker. A built-in test with matching worker and hotplug holdoffs reproduces this warning.

Check the initial binding while holding cpus_read_lock(), before sleeping. If the target is already offline, let the existing offline/rebind path handle it instead of warning about an impossible initial binding. Release the read lock before the holdoff and test loop so hotplug remains tested.

---
 kernel/scftorture.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
kernel/scftorture.c +12 -7
index ff9a8271a464..64ee2c5cf51c 100644
@@ -479,19 +479,24 @@ static int scftorture_invoker(void *arg)
 
 	VERBOSE_SCFTORTOUT("scftorture_invoker %d: task started", scfp->cpu);
 	cpu = scfp->cpu % nr_cpu_ids;
-	WARN_ON_ONCE(set_cpus_allowed_ptr(current, cpumask_of(cpu)));
+	cpus_read_lock();
+	if (cpu_online(cpu)) {
+		WARN_ON_ONCE(set_cpus_allowed_ptr(current, cpumask_of(cpu)));
+		/* Check affinity before hotplug can move this task away. */
+		curcpu = raw_smp_processor_id();
+		WARN_ONCE(curcpu != cpu,
+			  "%s: Wanted CPU %d, running on %d, nr_cpu_ids = %d\n",
+			  __func__, scfp->cpu, curcpu, nr_cpu_ids);
+	} else {
+		was_offline = true;
+	}
+	cpus_read_unlock();
 	set_user_nice(current, MAX_NICE);
 	if (holdoff)
 		schedule_timeout_interruptible(holdoff * HZ);
 
 	VERBOSE_SCFTORTOUT("scftorture_invoker %d: Waiting for all SCF torturers from cpu %d", scfp->cpu, raw_smp_processor_id());
 
-	// Make sure that the CPU is affinitized appropriately during testing.
-	curcpu = raw_smp_processor_id();
-	WARN_ONCE(curcpu != cpu,
-		  "%s: Wanted CPU %d, running on %d, nr_cpu_ids = %d\n",
-		  __func__, scfp->cpu, curcpu, nr_cpu_ids);
-
 	if (atomic_dec_return(&n_started))
 		while (atomic_read_acquire(&n_started)) {
 			if (torture_must_stop()) {
Signature · 1 line
2.54.0
maintainer Reviewed-by on v2 3/5
#6 lore raw

Re: [PATCH v2 3/5] scftorture: Protect the initial affinity check from hotplug

Quoted 11 lines · Joel Fernandes

An invoker binds to its target CPU, sleeps for the holdoff interval, and then warns if it is running elsewhere. CPU hotplug can offline the target during that sleep and legitimately move the invoker. A built-in test with matching worker and hotplug holdoffs reproduces this warning.

Check the initial binding while holding cpus_read_lock(), before sleeping. If the target is already offline, let the existing offline/rebind path handle it instead of warning about an impossible initial binding. Release the read lock before the holdoff and test loop so hotplug remains tested.

Good catch!

Quoted 43 lines
---
 kernel/scftorture.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
kernel/scftorture.c +12 -7
index ff9a8271a464..64ee2c5cf51c 100644
@@ -479,19 +479,24 @@ static int scftorture_invoker(void *arg)
 
 	VERBOSE_SCFTORTOUT("scftorture_invoker %d: task started", scfp->cpu);
 	cpu = scfp->cpu % nr_cpu_ids;
-	WARN_ON_ONCE(set_cpus_allowed_ptr(current, cpumask_of(cpu)));
+	cpus_read_lock();
+	if (cpu_online(cpu)) {
+		WARN_ON_ONCE(set_cpus_allowed_ptr(current, cpumask_of(cpu)));
+		/* Check affinity before hotplug can move this task away. */
+		curcpu = raw_smp_processor_id();
+		WARN_ONCE(curcpu != cpu,
+			  "%s: Wanted CPU %d, running on %d, nr_cpu_ids = %d\n",
+			  __func__, scfp->cpu, curcpu, nr_cpu_ids);
+	} else {
+		was_offline = true;
+	}
+	cpus_read_unlock();
 	set_user_nice(current, MAX_NICE);
 	if (holdoff)
 		schedule_timeout_interruptible(holdoff * HZ);
 
 	VERBOSE_SCFTORTOUT("scftorture_invoker %d: Waiting for all SCF torturers from cpu %d", scfp->cpu, raw_smp_processor_id());
 
-	// Make sure that the CPU is affinitized appropriately during testing.
-	curcpu = raw_smp_processor_id();
-	WARN_ONCE(curcpu != cpu,
-		  "%s: Wanted CPU %d, running on %d, nr_cpu_ids = %d\n",
-		  __func__, scfp->cpu, curcpu, nr_cpu_ids);
-
 	if (atomic_dec_return(&n_started))
 		while (atomic_read_acquire(&n_started)) {
 			if (torture_must_stop()) {
Signature · 1 line
2.54.0
author maintainer
#7 lore raw

PATCH v2 4/5 kasan: Avoid an unrelated RCU warning in the callback test

In reply to Joel Fernandes

rcu_uaf() passes a false protection condition to rcu_dereference_protected(), which produces a suspicious-RCU-usage warning before the intended KASAN failure occurs.

The pointer refers to a fresh allocation that has not been published to readers. State that protection condition explicitly, leaving the intended tests intact.

Test:
Built with CONFIG_KASAN_KUNIT_TEST=m
Booted Qemu guest (8 CPUs), ran modprobe kasan_test filtered to kasan.*rcu_uaf*

---
 mm/kasan/kasan_test_c.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/kasan/kasan_test_c.c +2 -1
index b9e167ed5be3..4e23765d722c 100644
@@ -967,8 +967,9 @@ static void rcu_uaf(struct kunit *test)
 	ptr = kmalloc_obj(struct kasan_rcu_info);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
 
+	/* The freshly allocated object has not been published to readers. */
 	global_rcu_ptr = rcu_dereference_protected(
-				(struct kasan_rcu_info __rcu *)ptr, NULL);
+				(struct kasan_rcu_info __rcu *)ptr, true);
 
 	KUNIT_EXPECT_KASAN_FAIL_READ(test,
 			call_rcu(&global_rcu_ptr->rcu, rcu_uaf_reclaim);
Signature · 1 line
2.54.0
maintainer Reviewed-by on v2 4/5
#8 lore raw

Re: [PATCH v2 4/5] kasan: Avoid an unrelated RCU warning in the callback test

Quoted 8 lines · Joel Fernandes

rcu_uaf() passes a false protection condition to rcu_dereference_protected(), which produces a suspicious-RCU-usage warning before the intended KASAN failure occurs.

The pointer refers to a fresh allocation that has not been published to readers. State that protection condition explicitly, leaving the intended tests intact.

Quoted 5 lines

Test:
Built with CONFIG_KASAN_KUNIT_TEST=m
Booted Qemu guest (8 CPUs), ran modprobe kasan_test filtered to kasan.*rcu_uaf*

And yes, the second argument to rcu_dereference_protected() is a boolean, not a pointer. Good catch!

Quoted 23 lines
---
 mm/kasan/kasan_test_c.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/kasan/kasan_test_c.c +2 -1
index b9e167ed5be3..4e23765d722c 100644
@@ -967,8 +967,9 @@ static void rcu_uaf(struct kunit *test)
 	ptr = kmalloc_obj(struct kasan_rcu_info);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
 
+	/* The freshly allocated object has not been published to readers. */
 	global_rcu_ptr = rcu_dereference_protected(
-				(struct kasan_rcu_info __rcu *)ptr, NULL);
+				(struct kasan_rcu_info __rcu *)ptr, true);
 
 	KUNIT_EXPECT_KASAN_FAIL_READ(test,
 			call_rcu(&global_rcu_ptr->rcu, rcu_uaf_reclaim);
Signature · 1 line
2.54.0
maintainer Reviewed-by on v2 4/5
#9 lore raw

Re: [PATCH v2 4/5] kasan: Avoid an unrelated RCU warning in the callback test

In reply to Joel Fernandes
Quoted 8 lines · Joel Fernandes

rcu_uaf() passes a false protection condition to rcu_dereference_protected(), which produces a suspicious-RCU-usage warning before the intended KASAN failure occurs.

The pointer refers to a fresh allocation that has not been published to readers. State that protection condition explicitly, leaving the intended tests intact.

Quoted 5 lines

Test:
Built with CONFIG_KASAN_KUNIT_TEST=m
Booted Qemu guest (8 CPUs), ran modprobe kasan_test filtered to kasan.*rcu_uaf*

author maintainer
#10 lore raw

PATCH v2 5/5 MAINTAINERS: Add scftorture to TORTURE-TEST MODULES

In reply to Joel Fernandes

kernel/scftorture.c has no MAINTAINERS entry, so get_maintainer.pl reports only the linux-kernel list for it. It is one of the torture-test modules alongside rcutorture, locktorture and refscale, so list it in the TORTURE-TEST MODULES entry.

While add it, add me as M: to torture modules as well as I have contributed patches/fixes to it over the years and use it for RCU.

---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index 93abbb315065..5c068224048a 100644
@@ -28282,6 +28282,7 @@ TORTURE-TEST MODULES
 M:	Davidlohr Bueso <[email protected]>
 M:	"Paul E. McKenney" <[email protected]>
 M:	Josh Triplett <[email protected]>
+M:	Joel Fernandes <[email protected]>
 L:	[email protected]
 S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/rcu/linux.git rcu/dev
@@ -28290,6 +28291,7 @@ F:	kernel/locking/locktorture.c
 F:	kernel/rcu/rcuscale.c
 F:	kernel/rcu/rcutorture.c
 F:	kernel/rcu/refscale.c
+F:	kernel/scftorture.c
 F:	kernel/torture.c
 
 TOSHIBA ACPI EXTRAS DRIVER
Signature · 1 line
2.54.0
maintainer Reviewed-by on v2 5/5
#11 lore raw

Re: [PATCH v2 5/5] MAINTAINERS: Add scftorture to TORTURE-TEST MODULES

Quoted 9 lines · Joel Fernandes

kernel/scftorture.c has no MAINTAINERS entry, so get_maintainer.pl reports only the linux-kernel list for it. It is one of the torture-test modules alongside rcutorture, locktorture and refscale, so list it in the TORTURE-TEST MODULES entry.

While add it, add me as M: to torture modules as well as I have contributed patches/fixes to it over the years and use it for RCU.

Welcome aboard! As usual, congratulations and condolences! ;-)

Quoted 27 lines
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index 93abbb315065..5c068224048a 100644
@@ -28282,6 +28282,7 @@ TORTURE-TEST MODULES
 M:	Davidlohr Bueso <[email protected]>
 M:	"Paul E. McKenney" <[email protected]>
 M:	Josh Triplett <[email protected]>
+M:	Joel Fernandes <[email protected]>
 L:	[email protected]
 S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/rcu/linux.git rcu/dev
@@ -28290,6 +28291,7 @@ F:	kernel/locking/locktorture.c
 F:	kernel/rcu/rcuscale.c
 F:	kernel/rcu/rcutorture.c
 F:	kernel/rcu/refscale.c
+F:	kernel/scftorture.c
 F:	kernel/torture.c
 
 TOSHIBA ACPI EXTRAS DRIVER
Signature · 1 line
2.54.0