linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] stop_machine: check work->done while handling enqueued works
@ 2013-02-08  3:39 Hillf Danton
  2013-02-08  8:21 ` Namhyung Kim
  2013-02-09 19:08 ` Tejun Heo
  0 siblings, 2 replies; 6+ messages in thread
From: Hillf Danton @ 2013-02-08  3:39 UTC (permalink / raw)
  To: Rusty Russell, Tejun Heo; +Cc: Andrew Morton, Ingo Molnar, Hillf Danton, LKML

The comment just above cpu_stop_signal_done() says it is uncertain that
the input @done is valid, and the works enqueued through the function
stop_one_cpu_nowait() do carry no done, thus we have to check if it is
valid when updating work result.

Signed-off-by: Hillf Danton <dhillf@gmail.com>
---

--- a/kernel/stop_machine.c	Thu Feb  7 20:03:10 2013
+++ b/kernel/stop_machine.c	Fri Feb  8 11:07:40 2013
@@ -279,7 +279,7 @@ repeat:
 		preempt_disable();

 		ret = fn(arg);
-		if (ret)
+		if (ret && done != NULL)
 			done->ret = ret;

 		/* restore preemption and check it's still balanced */
--

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] stop_machine: check work->done while handling enqueued works
  2013-02-08  3:39 [PATCH 1/2] stop_machine: check work->done while handling enqueued works Hillf Danton
@ 2013-02-08  8:21 ` Namhyung Kim
  2013-02-09 19:08 ` Tejun Heo
  1 sibling, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2013-02-08  8:21 UTC (permalink / raw)
  To: Hillf Danton; +Cc: Rusty Russell, Tejun Heo, Andrew Morton, Ingo Molnar, LKML

Hi Hillf,

On Fri, 8 Feb 2013 11:39:56 +0800, Hillf Danton wrote:
> The comment just above cpu_stop_signal_done() says it is uncertain that
> the input @done is valid, and the works enqueued through the function
> stop_one_cpu_nowait() do carry no done, thus we have to check if it is
> valid when updating work result.

The only user of stop_one_cpu_nowait() is the scheduler active balancer
and active_load_balance_cpu_stop() always returns 0.  But I think this
change makes its sense and the code evolves, so:

Reviewed-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung

>
> Signed-off-by: Hillf Danton <dhillf@gmail.com>
> ---
>
> --- a/kernel/stop_machine.c	Thu Feb  7 20:03:10 2013
> +++ b/kernel/stop_machine.c	Fri Feb  8 11:07:40 2013
> @@ -279,7 +279,7 @@ repeat:
>  		preempt_disable();
>
>  		ret = fn(arg);
> -		if (ret)
> +		if (ret && done != NULL)
>  			done->ret = ret;
>
>  		/* restore preemption and check it's still balanced */
> --

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] stop_machine: check work->done while handling enqueued works
  2013-02-08  3:39 [PATCH 1/2] stop_machine: check work->done while handling enqueued works Hillf Danton
  2013-02-08  8:21 ` Namhyung Kim
@ 2013-02-09 19:08 ` Tejun Heo
  2013-02-10  4:18   ` Hillf Danton
  1 sibling, 1 reply; 6+ messages in thread
From: Tejun Heo @ 2013-02-09 19:08 UTC (permalink / raw)
  To: Hillf Danton; +Cc: Rusty Russell, Andrew Morton, Ingo Molnar, LKML

Hello, Hillf.

On Fri, Feb 08, 2013 at 11:39:56AM +0800, Hillf Danton wrote:
> The comment just above cpu_stop_signal_done() says it is uncertain that
> the input @done is valid, and the works enqueued through the function
> stop_one_cpu_nowait() do carry no done, thus we have to check if it is
> valid when updating work result.

How about something like the following?

In cpu_stopper_thread(), @work->done may be NULL if the cpu stop work
is queued from stop_one_cpu_nowait(); however, cpu_stopper_thread()
updates @done->ret without checking whether @done exists or not when
the work function fails.

While this can lead to oops, the only current user of
stop_one_cpu_nowait() - active_load_balance_cpu_stop() - always
returns 0 and thus there's no in-kernel user which triggers this bug.

Fix it by checking whether @done exists before updating @done->ret.

> Signed-off-by: Hillf Danton <dhillf@gmail.com>
> ---
> 
> --- a/kernel/stop_machine.c	Thu Feb  7 20:03:10 2013
> +++ b/kernel/stop_machine.c	Fri Feb  8 11:07:40 2013
> @@ -279,7 +279,7 @@ repeat:
>  		preempt_disable();
> 
>  		ret = fn(arg);
> -		if (ret)
> +		if (ret && done != NULL)

It's a nitpick and probalby is just a preference but I've never liked
!= NULL or != 0.  Can we just do if (ret && done)?

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] stop_machine: check work->done while handling enqueued works
  2013-02-09 19:08 ` Tejun Heo
@ 2013-02-10  4:18   ` Hillf Danton
  0 siblings, 0 replies; 6+ messages in thread
From: Hillf Danton @ 2013-02-10  4:18 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Rusty Russell, Andrew Morton, Ingo Molnar, LKML

On Sun, Feb 10, 2013 at 3:08 AM, Tejun Heo <tj@kernel.org> wrote:
> Hello, Hillf.
>
> On Fri, Feb 08, 2013 at 11:39:56AM +0800, Hillf Danton wrote:
>> The comment just above cpu_stop_signal_done() says it is uncertain that
>> the input @done is valid, and the works enqueued through the function
>> stop_one_cpu_nowait() do carry no done, thus we have to check if it is
>> valid when updating work result.
>
> How about something like the following?

Cool, I like it, thanks.

Hillf
>
> In cpu_stopper_thread(), @work->done may be NULL if the cpu stop work
> is queued from stop_one_cpu_nowait(); however, cpu_stopper_thread()
> updates @done->ret without checking whether @done exists or not when
> the work function fails.
>
> While this can lead to oops, the only current user of
> stop_one_cpu_nowait() - active_load_balance_cpu_stop() - always
> returns 0 and thus there's no in-kernel user which triggers this bug.
>
> Fix it by checking whether @done exists before updating @done->ret.
>
>> Signed-off-by: Hillf Danton <dhillf@gmail.com>
>> ---
>>
>> --- a/kernel/stop_machine.c   Thu Feb  7 20:03:10 2013
>> +++ b/kernel/stop_machine.c   Fri Feb  8 11:07:40 2013
>> @@ -279,7 +279,7 @@ repeat:
>>               preempt_disable();
>>
>>               ret = fn(arg);
>> -             if (ret)
>> +             if (ret && done != NULL)
>
> It's a nitpick and probalby is just a preference but I've never liked
> != NULL or != 0.  Can we just do if (ret && done)?
>
> Thanks.
>
> --
> tejun

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] stop_machine: check work->done while handling enqueued works
  2013-02-10  5:22 Hillf Danton
@ 2013-02-12 17:37 ` Tejun Heo
  0 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2013-02-12 17:37 UTC (permalink / raw)
  To: Hillf Danton
  Cc: Namhyung Kim, Rusty Russell, Andrew Morton, Ingo Molnar, LKML

On Sun, Feb 10, 2013 at 01:22:43PM +0800, Hillf Danton wrote:
> In cpu_stopper_thread(), @work->done may be NULL if the cpu stop work
> is queued from stop_one_cpu_nowait(); however, cpu_stopper_thread()
> updates @done->ret without checking whether @done exists or not when
> the work function fails.
> 
> While this can lead to oops, the only current user of
> stop_one_cpu_nowait() - active_load_balance_cpu_stop() - always
> returns 0 and thus there's no in-kernel user which triggers this bug.
> 
> Fix it by checking whether @done exists before updating @done->ret.
> 
> Thanks Tejun for sharing commit message.
> 
> Signed-off-by: Hillf Danton <dhillf@gmail.com>
> Reviewed-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Tejun Heo <tj@kernel.org>

Andrew, can you please take this?

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] stop_machine: check work->done while handling enqueued works
@ 2013-02-10  5:22 Hillf Danton
  2013-02-12 17:37 ` Tejun Heo
  0 siblings, 1 reply; 6+ messages in thread
From: Hillf Danton @ 2013-02-10  5:22 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Namhyung Kim, Rusty Russell, Andrew Morton, Ingo Molnar, LKML,
	Hillf Danton

In cpu_stopper_thread(), @work->done may be NULL if the cpu stop work
is queued from stop_one_cpu_nowait(); however, cpu_stopper_thread()
updates @done->ret without checking whether @done exists or not when
the work function fails.

While this can lead to oops, the only current user of
stop_one_cpu_nowait() - active_load_balance_cpu_stop() - always
returns 0 and thus there's no in-kernel user which triggers this bug.

Fix it by checking whether @done exists before updating @done->ret.

Thanks Tejun for sharing commit message.

Signed-off-by: Hillf Danton <dhillf@gmail.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
---

--- a/kernel/stop_machine.c	Sun Feb 10 12:51:46 2013
+++ b/kernel/stop_machine.c	Sun Feb 10 12:58:58 2013
@@ -279,7 +279,7 @@ repeat:
 		preempt_disable();

 		ret = fn(arg);
-		if (ret)
+		if (ret && done)
 			done->ret = ret;

 		/* restore preemption and check it's still balanced */
--

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-02-12 17:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-08  3:39 [PATCH 1/2] stop_machine: check work->done while handling enqueued works Hillf Danton
2013-02-08  8:21 ` Namhyung Kim
2013-02-09 19:08 ` Tejun Heo
2013-02-10  4:18   ` Hillf Danton
2013-02-10  5:22 Hillf Danton
2013-02-12 17:37 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).