public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Xunlei Pang <xlpang@redhat.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Rusty Russell <rusty@rustcorp.com.au>
Subject: Re: [PATCH] sched/core: Clear the root_domain cpumasks in init_rootdomain()
Date: Fri, 4 Dec 2015 16:28:28 +0800	[thread overview]
Message-ID: <56614EAC.1010804@redhat.com> (raw)
In-Reply-To: <20151204080901.GA26934@gmail.com>

Hi Ingo,

On 12/04/2015 at 04:09 PM, Ingo Molnar wrote:
> * Xunlei Pang <xlpang@redhat.com> wrote:
>
>>> Hm, is the alloc_cpumask_var() done in alloc_sched_domains() safe?
>> Until now, I haven't found any other similar issues, but I will check further.
>>
>>> At least the usage pattern in init_sched_domains() looks unsafe:
>>>
>>>         doms_cur = alloc_sched_domains(ndoms_cur);
>>>         if (!doms_cur)
>>>                 doms_cur = &fallback_doms;
>>>         cpumask_andnot(doms_cur[0], cpu_map, cpu_isolated_map);
> So is this pattern in init_sched_domains() correct, for OFFSTACK=y?
>
> It looks wrong to me, as alloc_sched_domains() allocates an uninitialized cpumask 
> via alloc_cpumask_var() and returns it:
>
> cpumask_var_t *alloc_sched_domains(unsigned int ndoms)
> {
>         int i;
>         cpumask_var_t *doms;
>
>         doms = kmalloc(sizeof(*doms) * ndoms, GFP_KERNEL);
>         if (!doms)
>                 return NULL;
>         for (i = 0; i < ndoms; i++) {
>                 if (!alloc_cpumask_var(&doms[i], GFP_KERNEL)) {
>                         free_sched_domains(doms, i);
>                         return NULL;
>                 }
>         }
>         return doms;
> }
>
> and then this code:
>
>>>         cpumask_andnot(doms_cur[0], cpu_map, cpu_isolated_map);
> uses it without first clearing it.
>
> So is this another such bug, or am I missing something?

Yeah, I noticed that as well. But fortunately cpumask_andnot(), 
cpumask_and() and the like will clear doms_cur[] indirectly, also
cpu_isolated_map, cpu_active_mask, etc doesn't contain any
garbage bits. I also checked the use of it by cpuset, no extra such
bug found by me so far.

Regards,
Xunlei

>
> Thanks,
>
> 	Ingo
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/


  parent reply	other threads:[~2015-12-04  8:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-02 11:52 [PATCH] sched/core: Clear the root_domain cpumasks in init_rootdomain() Xunlei Pang
2015-12-02 12:34 ` Peter Zijlstra
2015-12-02 13:12   ` Xunlei Pang
2015-12-02 16:25     ` Peter Zijlstra
2015-12-03  2:44       ` Xunlei Pang
2015-12-03  8:28         ` Ingo Molnar
2015-12-03 11:52           ` Xunlei Pang
2015-12-04  8:09             ` Ingo Molnar
2015-12-04  8:27               ` Peter Zijlstra
2015-12-04  8:30                 ` Ingo Molnar
2015-12-04  8:28               ` Xunlei Pang [this message]
2015-12-04  8:30                 ` Ingo Molnar
2015-12-03  9:35         ` Peter Zijlstra
2015-12-04 11:52 ` [tip:locking/core] " tip-bot for Xunlei Pang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56614EAC.1010804@redhat.com \
    --to=xlpang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox