From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932206AbdJWLvC (ORCPT ); Mon, 23 Oct 2017 07:51:02 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:56350 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932088AbdJWLvB (ORCPT ); Mon, 23 Oct 2017 07:51:01 -0400 X-Google-Smtp-Source: ABhQp+SVYQpzD1hwidmyTZLcQUPmjZCA06lJimqgNmpWo6SlkQEO5e6KktThlLtLILFScAii2VDpbQ== Date: Mon, 23 Oct 2017 13:50:50 +0200 From: Ingo Molnar To: Rakib Mullick Cc: peterz@infradead.org, mka@chromium.org, longman@redhat.com, adobriyan@gmail.com, tglx@linutronix.de, akpm@linux-foundation.org, tj@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Fix isocpus's param handling when CPUMASK_OFFSTACK=n. Message-ID: <20171023115050.twyx4kn7ttvon2ch@gmail.com> References: <20171020084939.r6ox4o7k2kgezzbk@gmail.com> <20171021071017.10554-1-rakib.mullick@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171021071017.10554-1-rakib.mullick@gmail.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Rakib Mullick wrote: > > *On Fri, Oct 20, 2017 at 2:49 PM, Ingo Molnar wrote: > > > >> Rakib Mullick wrote: > >> include/linux/cpumask.h | 16 ++++++++++++++++ > >> kernel/sched/topology.c | 8 +++++--- > >> 2 files changed, 21 insertions(+), 3 deletions(-) > > > > What kernel is this against? It does not apply to the latest kernels. > > It was against 4.14-rc4, prepared before -rc5 release. Please, consider > the below one, against -rc5. > > cpulist_parse() uses nr_cpumask_bits as limit to parse the > passed buffer from kernel commandline. What nr_cpumask_bits > represents varies depends upon CONFIG_CPUMASK_OFFSTACK option. > If CONFIG_CPUMASK_OFFSTACK=n, then nr_cpumask_bits is same as > NR_CPUS, which might not represent the # of cpus really exist > (default 64). So, there's a chance of gap between nr_cpu_ids > and NR_CPUS, which ultimately lead towards invalid cpulist_parse() > operation. For example, if isolcpus=9 is passed on a 8 cpu > system (CONFIG_CPUMASK_OFFSTACK=n) it doesn't show the error > that it suppose to. > > This patch fixes this issue by effectively find out the last > cpu of the passed isolcpus list and checking it with nr_cpu_ids. > Also, fixes the error message where the nr_cpu_ids should be > nr_cpu_ids-1, since the cpu numbering starts from 0. > > Signed-off-by: Rakib Mullick > --- > include/linux/cpumask.h | 16 ++++++++++++++++ > kernel/sched/topology.c | 8 +++++--- > 2 files changed, 21 insertions(+), 3 deletions(-) > > diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h > index cd415b7..5631725 100644 > --- a/include/linux/cpumask.h > +++ b/include/linux/cpumask.h > @@ -130,6 +130,11 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp) > return 0; > } > > +static inline unsigned int cpumask_last(const struct cpumask *srcp) > +{ > + return 0; > +} > + > /* Valid inputs for n are -1 and 0. */ > static inline unsigned int cpumask_next(int n, const struct cpumask *srcp) > { > @@ -178,6 +183,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp) > return find_first_bit(cpumask_bits(srcp), nr_cpumask_bits); > } > > +/** > + * cpumask_last - get the last cpu in a cpumask Please capitalize 'CPU' properly in documentation. > + * @srcp: - the cpumask pointer > + * > + * Returns >= nr_cpumask_bits if no cpus set. > + */ > +static inline unsigned int cpumask_last(const struct cpumask *srcp) > +{ > + return find_last_bit(cpumask_bits(srcp), nr_cpumask_bits); > +} > + > unsigned int cpumask_next(int n, const struct cpumask *srcp); > > /** > diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c > index f1cf4f3..b9265c8 100644 > --- a/kernel/sched/topology.c > +++ b/kernel/sched/topology.c > @@ -466,12 +466,14 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu) > /* Setup the mask of CPUs configured for isolated domains */ > static int __init isolated_cpu_setup(char *str) > { > - int ret; > + int ret, lastcpu; > > alloc_bootmem_cpumask_var(&cpu_isolated_map); > ret = cpulist_parse(str, cpu_isolated_map); > - if (ret) { > - pr_err("sched: Error, all isolcpus= values must be between 0 and %u\n", nr_cpu_ids); > + lastcpu = cpumask_last(cpu_isolated_map); > + if (ret || lastcpu >= nr_cpu_ids) { Any reason why 'lastcpu' has to be introduced - why not just use cpumask_last() directly in the condition? It looks obvious enough of a pattern. > + pr_err("sched: Error, all isolcpus= values must be between 0 and %u\n", > + nr_cpu_ids-1); Please don't break the line mindlessly just due to checkpatch complaining - it makes the code less readable. Thanks, Ingo