lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 21 Jan 2021 16:29:13 -0800
From:   Yury Norov <yury.norov@...il.com>
To:     Paul Gortmaker <paul.gortmaker@...driver.com>
Cc:     Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        "Paul E. McKenney" <paulmck@...nel.org>
Subject: Re: [PATCH 3/3] lib: support N as end of range in bitmap_parselist()

On Thu, Jan 21, 2021 at 2:34 PM Paul Gortmaker
<paul.gortmaker@...driver.com> wrote:
>
> While this is done for all bitmaps, the original use case in mind was
> for CPU masks and cpulist_parse().  Credit to Yury who suggested to
> push it down from CPU subsys to bitmap - it simplified things a lot.

Can you convert your credit to Suggested-by or Reviewed-by? :)

> It seems that a common configuration is to use the 1st couple cores
> for housekeeping tasks, and or driving a busy peripheral that generates
> a lot of interrupts, or something similar.
>
> This tends to leave the remaining ones to form a pool of similarly
> configured cores to take on the real workload of interest to the user.
>
> So on machine A - with 32 cores, it could be 0-3 for "system" and then
> 4-31 being used in boot args like nohz_full=, or rcu_nocbs= as part of
> setting up the worker pool of CPUs.
>
> But then newer machine B is added, and it has 48 cores, and so while
> the 0-3 part remains unchanged, the pool setup cpu list becomes 4-47.
>
> Deployment would be easier if we could just simply replace 31 and 47
> with "N" and let the system substitute in the actual number at boot;
> a number that it knows better than we do.
>
> No need to have custom boot args per node, no need to do a trial boot
> in order to snoop /proc/cpuinfo and/or /sys/devices/system/cpu - no
> more fencepost errors of using 32 and 48 instead of 31 and 47.
>
> Cc: Yury Norov <yury.norov@...il.com>
> Cc: Peter Zijlstra <peterz@...radead.org>
> Cc: "Paul E. McKenney" <paulmck@...nel.org>
> Signed-off-by: Paul Gortmaker <paul.gortmaker@...driver.com>
> ---
>  .../admin-guide/kernel-parameters.rst          |  4 ++++
>  lib/bitmap.c                                   | 18 +++++++++++++-----
>  2 files changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.rst b/Documentation/admin-guide/kernel-parameters.rst
> index 5e080080b058..668f0b69fb4f 100644
> --- a/Documentation/admin-guide/kernel-parameters.rst
> +++ b/Documentation/admin-guide/kernel-parameters.rst
> @@ -68,6 +68,10 @@ For example one can add to the command line following parameter:
>
>  where the final item represents CPUs 100,101,125,126,150,151,...
>
> +The value "N" can be used as the end of a range, to represent the numerically
> +last CPU on the system, i.e "foo_cpus=16-N" would be equivalent to "16-31" on
> +a 32 core system.
> +
>  The following convenience aliases are also accepted and used:
>
>          foo_cpus=all
> diff --git a/lib/bitmap.c b/lib/bitmap.c
> index a1010646fbe5..d498ea9d526b 100644
> --- a/lib/bitmap.c
> +++ b/lib/bitmap.c
> @@ -571,7 +571,7 @@ static const char *bitmap_find_region_reverse(const char *start, const char *end
>         return end;
>  }
>
> -static const char *bitmap_parse_region(const char *str, struct region *r)
> +static const char *bitmap_parse_region(const char *str, struct region *r, int nmaskbits)
>  {

in bitmap_parselist() you can store nmaskbits in the struct region, and avoid
passing nmaskbits as a parameter.

>         str = bitmap_getnum(str, &r->start);
>         if (IS_ERR(str))
> @@ -583,9 +583,15 @@ static const char *bitmap_parse_region(const char *str, struct region *r)
>         if (*str != '-')
>                 return ERR_PTR(-EINVAL);
>
> -       str = bitmap_getnum(str + 1, &r->end);
> -       if (IS_ERR(str))
> -               return str;
> +       str++;
> +       if (*str == 'N') {
> +               r->end = nmaskbits - 1;
> +               str++;
> +       } else {
> +               str = bitmap_getnum(str, &r->end);
> +               if (IS_ERR(str))
> +                       return str;
> +       }

Indeed it's much simpler. But I don't like that you increase the nesting level.
Can you keep bitmap_parse_region() a single-tab style function?

What about group size? Are you going to support N there, like "0-N:5/N"?
What about "N-N"? Is it legal? Maybe hide new logic in bitmap_getnum()?

I would also like to see tests covering new functionality. As a user of "N",
I want to be 100% sure that this "N" is a full equivalent of NR_CPUS, including
error codes that the parser returns. Otherwise it will be hard to maintain the
transition.

>         if (end_of_region(*str))
>                 goto no_pattern;
> @@ -628,6 +634,8 @@ static const char *bitmap_parse_region(const char *str, struct region *r)
>   * Syntax: range:used_size/group_size
>   * Example: 0-1023:2/256 ==> 0,1,256,257,512,513,768,769
>   * Optionally the self-descriptive "all" or "none" can be used.
> + * The value 'N' can be used as the end of a range to indicate the maximum
> + * allowed value; i.e (nmaskbits - 1).
>   *
>   * Returns: 0 on success, -errno on invalid input strings. Error values:
>   *
> @@ -656,7 +664,7 @@ int bitmap_parselist(const char *buf, unsigned long *maskp, int nmaskbits)
>                 if (buf == NULL)
>                         return 0;
>
> -               buf = bitmap_parse_region(buf, &r);
> +               buf = bitmap_parse_region(buf, &r, nmaskbits);
>                 if (IS_ERR(buf))
>                         return PTR_ERR(buf);
>
> --
> 2.17.1
>

Powered by blists - more mailing lists