public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpumask: fix cpumask leak in partition_sched_domains
@ 2013-07-27  7:26 Xiaotian Feng
  2013-08-06  2:31 ` Xiaotian Feng
  0 siblings, 1 reply; 8+ messages in thread
From: Xiaotian Feng @ 2013-07-27  7:26 UTC (permalink / raw)
  Cc: Xiaotian Feng, Ingo Molnar, Peter Zijlstra, linux-kernel

If doms_new is NULL, partition_sched_domains() will reset ndoms_cur
to 0, and free old sched domains with free_sched_domains(doms_cur, ndoms_cur).
As ndoms_cur is 0, the cpumask will not be freed.

Signed-off-by: Xiaotian Feng <xtfeng@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org
---
 kernel/sched/core.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b7c32cb..3d6c57b 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6184,8 +6184,9 @@ match1:
 		;
 	}
 
+	n= ndoms_cur;
 	if (doms_new == NULL) {
-		ndoms_cur = 0;
+		n = 0;
 		doms_new = &fallback_doms;
 		cpumask_andnot(doms_new[0], cpu_active_mask, cpu_isolated_map);
 		WARN_ON_ONCE(dattr_new);
@@ -6193,7 +6194,7 @@ match1:
 
 	/* Build new domains */
 	for (i = 0; i < ndoms_new; i++) {
-		for (j = 0; j < ndoms_cur && !new_topology; j++) {
+		for (j = 0; j < n && !new_topology; j++) {
 			if (cpumask_equal(doms_new[i], doms_cur[j])
 			    && dattrs_equal(dattr_new, i, dattr_cur, j))
 				goto match2;
-- 
1.7.9.6 (Apple Git-31.1)


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

* Re: [PATCH] cpumask: fix cpumask leak in partition_sched_domains
  2013-07-27  7:26 [PATCH] cpumask: fix cpumask leak in partition_sched_domains Xiaotian Feng
@ 2013-08-06  2:31 ` Xiaotian Feng
  2013-08-06  4:37   ` Rusty Russell
  0 siblings, 1 reply; 8+ messages in thread
From: Xiaotian Feng @ 2013-08-06  2:31 UTC (permalink / raw)
  To: Rusty Russell, Peter Zijlstra; +Cc: Xiaotian Feng, Ingo Molnar, linux-kernel

On Sat, Jul 27, 2013 at 3:26 PM, Xiaotian Feng <xtfeng@gmail.com> wrote:
> If doms_new is NULL, partition_sched_domains() will reset ndoms_cur
> to 0, and free old sched domains with free_sched_domains(doms_cur, ndoms_cur).
> As ndoms_cur is 0, the cpumask will not be freed.
>
> Signed-off-by: Xiaotian Feng <xtfeng@gmail.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: linux-kernel@vger.kernel.org

Any comments? Cc'ed Rusty.

> ---
>  kernel/sched/core.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index b7c32cb..3d6c57b 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -6184,8 +6184,9 @@ match1:
>                 ;
>         }
>
> +       n= ndoms_cur;
>         if (doms_new == NULL) {
> -               ndoms_cur = 0;
> +               n = 0;
>                 doms_new = &fallback_doms;
>                 cpumask_andnot(doms_new[0], cpu_active_mask, cpu_isolated_map);
>                 WARN_ON_ONCE(dattr_new);
> @@ -6193,7 +6194,7 @@ match1:
>
>         /* Build new domains */
>         for (i = 0; i < ndoms_new; i++) {
> -               for (j = 0; j < ndoms_cur && !new_topology; j++) {
> +               for (j = 0; j < n && !new_topology; j++) {
>                         if (cpumask_equal(doms_new[i], doms_cur[j])
>                             && dattrs_equal(dattr_new, i, dattr_cur, j))
>                                 goto match2;
> --
> 1.7.9.6 (Apple Git-31.1)
>

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

* Re: [PATCH] cpumask: fix cpumask leak in partition_sched_domains
  2013-08-06  2:31 ` Xiaotian Feng
@ 2013-08-06  4:37   ` Rusty Russell
  2013-08-06  5:10     ` Xiaotian Feng
  2013-08-06 12:06     ` Xiaotian Feng
  0 siblings, 2 replies; 8+ messages in thread
From: Rusty Russell @ 2013-08-06  4:37 UTC (permalink / raw)
  To: Xiaotian Feng, Peter Zijlstra; +Cc: Xiaotian Feng, Ingo Molnar, linux-kernel

Xiaotian Feng <xtfeng@gmail.com> writes:
> On Sat, Jul 27, 2013 at 3:26 PM, Xiaotian Feng <xtfeng@gmail.com> wrote:
>> If doms_new is NULL, partition_sched_domains() will reset ndoms_cur
>> to 0, and free old sched domains with free_sched_domains(doms_cur, ndoms_cur).
>> As ndoms_cur is 0, the cpumask will not be freed.
>>
>> Signed-off-by: Xiaotian Feng <xtfeng@gmail.com>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Cc: Peter Zijlstra <peterz@infradead.org>
>> Cc: linux-kernel@vger.kernel.org
>
> Any comments? Cc'ed Rusty.

The code is a little convoluted, but your fix is logical.

>> ---
>>  kernel/sched/core.c |    5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>> index b7c32cb..3d6c57b 100644
>> --- a/kernel/sched/core.c
>> +++ b/kernel/sched/core.c
>> @@ -6184,8 +6184,9 @@ match1:
>>                 ;
>>         }
>>
>> +       n= ndoms_cur;

You're missing a ' ' here:
        n = ndoms_cur;

>>         if (doms_new == NULL) {
>> -               ndoms_cur = 0;
>> +               n = 0;
>>                 doms_new = &fallback_doms;
>>                 cpumask_andnot(doms_new[0], cpu_active_mask, cpu_isolated_map);
>>                 WARN_ON_ONCE(dattr_new);
>> @@ -6193,7 +6194,7 @@ match1:
>>
>>         /* Build new domains */
>>         for (i = 0; i < ndoms_new; i++) {
>> -               for (j = 0; j < ndoms_cur && !new_topology; j++) {
>> +               for (j = 0; j < n && !new_topology; j++) {
>>                         if (cpumask_equal(doms_new[i], doms_cur[j])
>>                             && dattrs_equal(dattr_new, i, dattr_cur, j))
>>                                 goto match2;
>> --
>> 1.7.9.6 (Apple Git-31.1)
>>

Cheers,
Rusty.

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

* Re: [PATCH] cpumask: fix cpumask leak in partition_sched_domains
  2013-08-06  4:37   ` Rusty Russell
@ 2013-08-06  5:10     ` Xiaotian Feng
  2013-08-06 12:06     ` Xiaotian Feng
  1 sibling, 0 replies; 8+ messages in thread
From: Xiaotian Feng @ 2013-08-06  5:10 UTC (permalink / raw)
  To: Rusty Russell; +Cc: Peter Zijlstra, Ingo Molnar, linux-kernel

On Tue, Aug 6, 2013 at 12:37 PM, Rusty Russell <rusty@rustcorp.com.au> wrote:
> Xiaotian Feng <xtfeng@gmail.com> writes:
>> On Sat, Jul 27, 2013 at 3:26 PM, Xiaotian Feng <xtfeng@gmail.com> wrote:
>>> If doms_new is NULL, partition_sched_domains() will reset ndoms_cur
>>> to 0, and free old sched domains with free_sched_domains(doms_cur, ndoms_cur).
>>> As ndoms_cur is 0, the cpumask will not be freed.
>>>
>>> Signed-off-by: Xiaotian Feng <xtfeng@gmail.com>
>>> Cc: Ingo Molnar <mingo@redhat.com>
>>> Cc: Peter Zijlstra <peterz@infradead.org>
>>> Cc: linux-kernel@vger.kernel.org
>>
>> Any comments? Cc'ed Rusty.
>
> The code is a little convoluted, but your fix is logical.
>

Yes, it's quite convoluted :(

>>> ---
>>>  kernel/sched/core.c |    5 +++--
>>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>>> index b7c32cb..3d6c57b 100644
>>> --- a/kernel/sched/core.c
>>> +++ b/kernel/sched/core.c
>>> @@ -6184,8 +6184,9 @@ match1:
>>>                 ;
>>>         }
>>>
>>> +       n= ndoms_cur;
>
> You're missing a ' ' here:
>         n = ndoms_cur;
>

I'll update this, thanks :)

>>>         if (doms_new == NULL) {
>>> -               ndoms_cur = 0;
>>> +               n = 0;
>>>                 doms_new = &fallback_doms;
>>>                 cpumask_andnot(doms_new[0], cpu_active_mask, cpu_isolated_map);
>>>                 WARN_ON_ONCE(dattr_new);
>>> @@ -6193,7 +6194,7 @@ match1:
>>>
>>>         /* Build new domains */
>>>         for (i = 0; i < ndoms_new; i++) {
>>> -               for (j = 0; j < ndoms_cur && !new_topology; j++) {
>>> +               for (j = 0; j < n && !new_topology; j++) {
>>>                         if (cpumask_equal(doms_new[i], doms_cur[j])
>>>                             && dattrs_equal(dattr_new, i, dattr_cur, j))
>>>                                 goto match2;
>>> --
>>> 1.7.9.6 (Apple Git-31.1)
>>>
>
> Cheers,
> Rusty.

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

* [PATCH] cpumask: fix cpumask leak in partition_sched_domains
  2013-08-06  4:37   ` Rusty Russell
  2013-08-06  5:10     ` Xiaotian Feng
@ 2013-08-06 12:06     ` Xiaotian Feng
  2013-08-15  1:55       ` Xiaotian Feng
                         ` (2 more replies)
  1 sibling, 3 replies; 8+ messages in thread
From: Xiaotian Feng @ 2013-08-06 12:06 UTC (permalink / raw)
  Cc: Xiaotian Feng, Ingo Molnar, Peter Zijlstra, Rusty Russell,
	Thomas Gleixner, linux-kernel

If doms_new is NULL, partition_sched_domains() will reset ndoms_cur
to 0, and free old sched domains with free_sched_domains(doms_cur, ndoms_cur).
As ndoms_cur is 0, the cpumask will not be freed.

Signed-off-by: Xiaotian Feng <xtfeng@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
---
 kernel/sched/core.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b7c32cb..3d6c57b 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6184,8 +6184,9 @@ match1:
 		;
 	}
 
+	n = ndoms_cur;
 	if (doms_new == NULL) {
-		ndoms_cur = 0;
+		n = 0;
 		doms_new = &fallback_doms;
 		cpumask_andnot(doms_new[0], cpu_active_mask, cpu_isolated_map);
 		WARN_ON_ONCE(dattr_new);
@@ -6193,7 +6194,7 @@ match1:
 
 	/* Build new domains */
 	for (i = 0; i < ndoms_new; i++) {
-		for (j = 0; j < ndoms_cur && !new_topology; j++) {
+		for (j = 0; j < n && !new_topology; j++) {
 			if (cpumask_equal(doms_new[i], doms_cur[j])
 			    && dattrs_equal(dattr_new, i, dattr_cur, j))
 				goto match2;
-- 
1.7.9.6 (Apple Git-31.1)


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

* Re: [PATCH] cpumask: fix cpumask leak in partition_sched_domains
  2013-08-06 12:06     ` Xiaotian Feng
@ 2013-08-15  1:55       ` Xiaotian Feng
  2013-08-15  9:09       ` Peter Zijlstra
  2013-08-16 18:46       ` [tip:sched/core] cpumask: Fix cpumask leak in partition_sched_domains() tip-bot for Xiaotian Feng
  2 siblings, 0 replies; 8+ messages in thread
From: Xiaotian Feng @ 2013-08-15  1:55 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Rusty Russell, Thomas Gleixner
  Cc: Xiaotian Feng, linux-kernel

On Tue, Aug 6, 2013 at 8:06 PM, Xiaotian Feng <xtfeng@gmail.com> wrote:
> If doms_new is NULL, partition_sched_domains() will reset ndoms_cur
> to 0, and free old sched domains with free_sched_domains(doms_cur, ndoms_cur).
> As ndoms_cur is 0, the cpumask will not be freed.
>
> Signed-off-by: Xiaotian Feng <xtfeng@gmail.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Rusty Russell <rusty@rustcorp.com.au>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: linux-kernel@vger.kernel.org

Any comments on this patch? Without this patch, I can see following
with kmemleak.

unreferenced object 0xffff880118d26aa8 (size 512):
  comm "swapper/0", pid 1, jiffies 4294892366 (age 287.736s)
  hex dump (first 32 bytes):
    0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace:
    [<ffffffff817350e6>] kmemleak_alloc+0x26/0x50
    [<ffffffff811b92c6>] kmem_cache_alloc_node_trace+0x116/0x2d0
    [<ffffffff8139e66f>] alloc_cpumask_var_node+0x1f/0x90
    [<ffffffff8139e6ee>] alloc_cpumask_var+0xe/0x10
    [<ffffffff810a328c>] alloc_sched_domains+0x5c/0x80
    [<ffffffff81daf8c6>] sched_init_smp+0x365/0x47d
    [<ffffffff81d8f01e>] kernel_init_freeable+0xe3/0x1ef
    [<ffffffff81731b1e>] kernel_init+0xe/0xf0
    [<ffffffff817543ac>] ret_from_fork+0x7c/0xb0
    [<ffffffffffffffff>] 0xffffffffffffffff

> ---
>  kernel/sched/core.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index b7c32cb..3d6c57b 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -6184,8 +6184,9 @@ match1:
>                 ;
>         }
>
> +       n = ndoms_cur;
>         if (doms_new == NULL) {
> -               ndoms_cur = 0;
> +               n = 0;
>                 doms_new = &fallback_doms;
>                 cpumask_andnot(doms_new[0], cpu_active_mask, cpu_isolated_map);
>                 WARN_ON_ONCE(dattr_new);
> @@ -6193,7 +6194,7 @@ match1:
>
>         /* Build new domains */
>         for (i = 0; i < ndoms_new; i++) {
> -               for (j = 0; j < ndoms_cur && !new_topology; j++) {
> +               for (j = 0; j < n && !new_topology; j++) {
>                         if (cpumask_equal(doms_new[i], doms_cur[j])
>                             && dattrs_equal(dattr_new, i, dattr_cur, j))
>                                 goto match2;
> --
> 1.7.9.6 (Apple Git-31.1)
>

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

* Re: [PATCH] cpumask: fix cpumask leak in partition_sched_domains
  2013-08-06 12:06     ` Xiaotian Feng
  2013-08-15  1:55       ` Xiaotian Feng
@ 2013-08-15  9:09       ` Peter Zijlstra
  2013-08-16 18:46       ` [tip:sched/core] cpumask: Fix cpumask leak in partition_sched_domains() tip-bot for Xiaotian Feng
  2 siblings, 0 replies; 8+ messages in thread
From: Peter Zijlstra @ 2013-08-15  9:09 UTC (permalink / raw)
  To: Xiaotian Feng; +Cc: Ingo Molnar, Rusty Russell, Thomas Gleixner, linux-kernel

On Tue, Aug 06, 2013 at 08:06:42PM +0800, Xiaotian Feng wrote:
> If doms_new is NULL, partition_sched_domains() will reset ndoms_cur
> to 0, and free old sched domains with free_sched_domains(doms_cur, ndoms_cur).
> As ndoms_cur is 0, the cpumask will not be freed.
> 
> Signed-off-by: Xiaotian Feng <xtfeng@gmail.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Rusty Russell <rusty@rustcorp.com.au>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: linux-kernel@vger.kernel.org

Thanks!

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

* [tip:sched/core] cpumask: Fix cpumask leak in partition_sched_domains()
  2013-08-06 12:06     ` Xiaotian Feng
  2013-08-15  1:55       ` Xiaotian Feng
  2013-08-15  9:09       ` Peter Zijlstra
@ 2013-08-16 18:46       ` tip-bot for Xiaotian Feng
  2 siblings, 0 replies; 8+ messages in thread
From: tip-bot for Xiaotian Feng @ 2013-08-16 18:46 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, rusty, peterz, tglx, xtfeng

Commit-ID:  c8d2d47a9cbb4222ae4e993aa0e3703430c8193c
Gitweb:     http://git.kernel.org/tip/c8d2d47a9cbb4222ae4e993aa0e3703430c8193c
Author:     Xiaotian Feng <xtfeng@gmail.com>
AuthorDate: Tue, 6 Aug 2013 20:06:42 +0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 16 Aug 2013 17:44:27 +0200

cpumask: Fix cpumask leak in partition_sched_domains()

If doms_new is NULL, partition_sched_domains() will reset ndoms_cur
to 0, and free old sched domains with free_sched_domains(doms_cur, ndoms_cur).
As ndoms_cur is 0, the cpumask will not be freed.

Signed-off-by: Xiaotian Feng <xtfeng@gmail.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1375790802-11857-1-git-send-email-xtfeng@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b7415cf..cf8f100 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6184,8 +6184,9 @@ match1:
 		;
 	}
 
+	n = ndoms_cur;
 	if (doms_new == NULL) {
-		ndoms_cur = 0;
+		n = 0;
 		doms_new = &fallback_doms;
 		cpumask_andnot(doms_new[0], cpu_active_mask, cpu_isolated_map);
 		WARN_ON_ONCE(dattr_new);
@@ -6193,7 +6194,7 @@ match1:
 
 	/* Build new domains */
 	for (i = 0; i < ndoms_new; i++) {
-		for (j = 0; j < ndoms_cur && !new_topology; j++) {
+		for (j = 0; j < n && !new_topology; j++) {
 			if (cpumask_equal(doms_new[i], doms_cur[j])
 			    && dattrs_equal(dattr_new, i, dattr_cur, j))
 				goto match2;

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

end of thread, other threads:[~2013-08-16 18:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-27  7:26 [PATCH] cpumask: fix cpumask leak in partition_sched_domains Xiaotian Feng
2013-08-06  2:31 ` Xiaotian Feng
2013-08-06  4:37   ` Rusty Russell
2013-08-06  5:10     ` Xiaotian Feng
2013-08-06 12:06     ` Xiaotian Feng
2013-08-15  1:55       ` Xiaotian Feng
2013-08-15  9:09       ` Peter Zijlstra
2013-08-16 18:46       ` [tip:sched/core] cpumask: Fix cpumask leak in partition_sched_domains() tip-bot for Xiaotian Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox