Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60f53782 authored by Paul E. McKenney's avatar Paul E. McKenney
Browse files

rcu: Prevent initialization race in rcutorture kthreads



When you do something like "t = kthread_run(...)", it is possible that
the kthread will start running before the assignment to "t" happens.
If the child kthread expects to find a pointer to its task_struct in "t",
it will then be fatally disappointed.  This commit therefore switches
such cases to kthread_create() followed by wake_up_process(), guaranteeing
that the assignment happens before the child kthread starts running.

Reported-by: default avatarFengguang Wu <fengguang.wu@intel.com>
Signed-off-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
parent 2caa1e44
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -2029,7 +2029,7 @@ rcu_torture_init(void)
	/* Start up the kthreads. */
	/* Start up the kthreads. */


	VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
	VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
	writer_task = kthread_run(rcu_torture_writer, NULL,
	writer_task = kthread_create(rcu_torture_writer, NULL,
				     "rcu_torture_writer");
				     "rcu_torture_writer");
	if (IS_ERR(writer_task)) {
	if (IS_ERR(writer_task)) {
		firsterr = PTR_ERR(writer_task);
		firsterr = PTR_ERR(writer_task);
@@ -2037,6 +2037,7 @@ rcu_torture_init(void)
		writer_task = NULL;
		writer_task = NULL;
		goto unwind;
		goto unwind;
	}
	}
	wake_up_process(writer_task);
	fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
	fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
				   GFP_KERNEL);
				   GFP_KERNEL);
	if (fakewriter_tasks == NULL) {
	if (fakewriter_tasks == NULL) {
@@ -2151,7 +2152,7 @@ rcu_torture_init(void)
	}
	}
	if (shutdown_secs > 0) {
	if (shutdown_secs > 0) {
		shutdown_time = jiffies + shutdown_secs * HZ;
		shutdown_time = jiffies + shutdown_secs * HZ;
		shutdown_task = kthread_run(rcu_torture_shutdown, NULL,
		shutdown_task = kthread_create(rcu_torture_shutdown, NULL,
					       "rcu_torture_shutdown");
					       "rcu_torture_shutdown");
		if (IS_ERR(shutdown_task)) {
		if (IS_ERR(shutdown_task)) {
			firsterr = PTR_ERR(shutdown_task);
			firsterr = PTR_ERR(shutdown_task);
@@ -2159,6 +2160,7 @@ rcu_torture_init(void)
			shutdown_task = NULL;
			shutdown_task = NULL;
			goto unwind;
			goto unwind;
		}
		}
		wake_up_process(shutdown_task);
	}
	}
	i = rcu_torture_onoff_init();
	i = rcu_torture_onoff_init();
	if (i != 0) {
	if (i != 0) {