diff mbox series

[v2] firmware/psci: psci_checker: Park kthreads before stopping them

Message ID 20190610173829.4741-1-jean-philippe.brucker@arm.com (mailing list archive)
State New, archived
Headers show
Series [v2] firmware/psci: psci_checker: Park kthreads before stopping them | expand

Commit Message

Jean-Philippe Brucker June 10, 2019, 5:38 p.m. UTC
Since commit 85f1abe0019f ("kthread, sched/wait: Fix kthread_parkme()
completion issue"), kthreads that are bound to a CPU must be parked
before being stopped. At the moment the PSCI checker calls
kthread_stop() directly on the suspend kthread, which triggers the
following warning:

[    6.068288] WARNING: CPU: 1 PID: 1 at kernel/kthread.c:398 __kthread_bind_mask+0x20/0x78
               ...
[    6.190151] Call trace:
[    6.192566]  __kthread_bind_mask+0x20/0x78
[    6.196615]  kthread_unpark+0x74/0x80
[    6.200235]  kthread_stop+0x44/0x1d8
[    6.203769]  psci_checker+0x3bc/0x484
[    6.207389]  do_one_initcall+0x48/0x260
[    6.211180]  kernel_init_freeable+0x2c8/0x368
[    6.215488]  kernel_init+0x10/0x100
[    6.218935]  ret_from_fork+0x10/0x1c
[    6.222467] ---[ end trace e05e22863d043cd3 ]---

kthread_unpark() tries to bind the thread to its CPU and aborts with a
WARN() if the thread wasn't in TASK_PARKED state. Park the kthreads
before stopping them.

Fixes: 85f1abe0019f ("kthread, sched/wait: Fix kthread_parkme() completion issue")
Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
---
Since v1: rebased onto v5.2-rc4
---
 drivers/firmware/psci/psci_checker.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Sudeep Holla June 11, 2019, 9:42 a.m. UTC | #1
On Mon, Jun 10, 2019 at 06:38:29PM +0100, Jean-Philippe Brucker wrote:
> Since commit 85f1abe0019f ("kthread, sched/wait: Fix kthread_parkme()
> completion issue"), kthreads that are bound to a CPU must be parked
> before being stopped. At the moment the PSCI checker calls
> kthread_stop() directly on the suspend kthread, which triggers the
> following warning:
> 
> [    6.068288] WARNING: CPU: 1 PID: 1 at kernel/kthread.c:398 __kthread_bind_mask+0x20/0x78
>                ...
> [    6.190151] Call trace:
> [    6.192566]  __kthread_bind_mask+0x20/0x78
> [    6.196615]  kthread_unpark+0x74/0x80
> [    6.200235]  kthread_stop+0x44/0x1d8
> [    6.203769]  psci_checker+0x3bc/0x484
> [    6.207389]  do_one_initcall+0x48/0x260
> [    6.211180]  kernel_init_freeable+0x2c8/0x368
> [    6.215488]  kernel_init+0x10/0x100
> [    6.218935]  ret_from_fork+0x10/0x1c
> [    6.222467] ---[ end trace e05e22863d043cd3 ]---
> 
> kthread_unpark() tries to bind the thread to its CPU and aborts with a
> WARN() if the thread wasn't in TASK_PARKED state. Park the kthreads
> before stopping them.
> 

Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>

--
Regards,
Sudeep
Lorenzo Pieralisi June 11, 2019, 10:48 a.m. UTC | #2
Hi Arnd, Olof,

Can you pick this up please (with my ACK below) or you prefer me
resending it ?

On Mon, Jun 10, 2019 at 06:38:29PM +0100, Jean-Philippe Brucker wrote:
> Since commit 85f1abe0019f ("kthread, sched/wait: Fix kthread_parkme()
> completion issue"), kthreads that are bound to a CPU must be parked
> before being stopped. At the moment the PSCI checker calls
> kthread_stop() directly on the suspend kthread, which triggers the
> following warning:
> 
> [    6.068288] WARNING: CPU: 1 PID: 1 at kernel/kthread.c:398 __kthread_bind_mask+0x20/0x78
>                ...
> [    6.190151] Call trace:
> [    6.192566]  __kthread_bind_mask+0x20/0x78
> [    6.196615]  kthread_unpark+0x74/0x80
> [    6.200235]  kthread_stop+0x44/0x1d8
> [    6.203769]  psci_checker+0x3bc/0x484
> [    6.207389]  do_one_initcall+0x48/0x260
> [    6.211180]  kernel_init_freeable+0x2c8/0x368
> [    6.215488]  kernel_init+0x10/0x100
> [    6.218935]  ret_from_fork+0x10/0x1c
> [    6.222467] ---[ end trace e05e22863d043cd3 ]---
> 
> kthread_unpark() tries to bind the thread to its CPU and aborts with a
> WARN() if the thread wasn't in TASK_PARKED state. Park the kthreads
> before stopping them.
> 
> Fixes: 85f1abe0019f ("kthread, sched/wait: Fix kthread_parkme() completion issue")
> Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
> ---
> Since v1: rebased onto v5.2-rc4
> ---
>  drivers/firmware/psci/psci_checker.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)

Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>

> diff --git a/drivers/firmware/psci/psci_checker.c b/drivers/firmware/psci/psci_checker.c
> index 08c85099d4d0..f3659443f8c2 100644
> --- a/drivers/firmware/psci/psci_checker.c
> +++ b/drivers/firmware/psci/psci_checker.c
> @@ -359,16 +359,16 @@ static int suspend_test_thread(void *arg)
>  	for (;;) {
>  		/* Needs to be set first to avoid missing a wakeup. */
>  		set_current_state(TASK_INTERRUPTIBLE);
> -		if (kthread_should_stop()) {
> -			__set_current_state(TASK_RUNNING);
> +		if (kthread_should_park())
>  			break;
> -		}
>  		schedule();
>  	}
>  
>  	pr_info("CPU %d suspend test results: success %d, shallow states %d, errors %d\n",
>  		cpu, nb_suspend, nb_shallow_sleep, nb_err);
>  
> +	kthread_parkme();
> +
>  	return nb_err;
>  }
>  
> @@ -433,8 +433,10 @@ static int suspend_tests(void)
>  
>  
>  	/* Stop and destroy all threads, get return status. */
> -	for (i = 0; i < nb_threads; ++i)
> +	for (i = 0; i < nb_threads; ++i) {
> +		err += kthread_park(threads[i]);
>  		err += kthread_stop(threads[i]);
> +	}
>   out:
>  	cpuidle_resume_and_unlock();
>  	kfree(threads);
> -- 
> 2.21.0
>
Olof Johansson June 17, 2019, 11:51 a.m. UTC | #3
On Tue, Jun 11, 2019 at 11:48:23AM +0100, Lorenzo Pieralisi wrote:
> Hi Arnd, Olof,
> 
> Can you pick this up please (with my ACK below) or you prefer me
> resending it ?

Resending is always slightly less work for us to collect acks, but I've applied
it at our end now.


Thanks!


-Olof
diff mbox series

Patch

diff --git a/drivers/firmware/psci/psci_checker.c b/drivers/firmware/psci/psci_checker.c
index 08c85099d4d0..f3659443f8c2 100644
--- a/drivers/firmware/psci/psci_checker.c
+++ b/drivers/firmware/psci/psci_checker.c
@@ -359,16 +359,16 @@  static int suspend_test_thread(void *arg)
 	for (;;) {
 		/* Needs to be set first to avoid missing a wakeup. */
 		set_current_state(TASK_INTERRUPTIBLE);
-		if (kthread_should_stop()) {
-			__set_current_state(TASK_RUNNING);
+		if (kthread_should_park())
 			break;
-		}
 		schedule();
 	}
 
 	pr_info("CPU %d suspend test results: success %d, shallow states %d, errors %d\n",
 		cpu, nb_suspend, nb_shallow_sleep, nb_err);
 
+	kthread_parkme();
+
 	return nb_err;
 }
 
@@ -433,8 +433,10 @@  static int suspend_tests(void)
 
 
 	/* Stop and destroy all threads, get return status. */
-	for (i = 0; i < nb_threads; ++i)
+	for (i = 0; i < nb_threads; ++i) {
+		err += kthread_park(threads[i]);
 		err += kthread_stop(threads[i]);
+	}
  out:
 	cpuidle_resume_and_unlock();
 	kfree(threads);