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  linux-cve-announce  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]
Message-ID: <ZAYUODI1yaH5PqHk@yury-laptop>
Date:   Mon, 6 Mar 2023 08:26:32 -0800
From:   Yury Norov <yury.norov@...il.com>
To:     Vernon Yang <vernon2gm@...il.com>
Cc:     torvalds@...ux-foundation.org, tytso@....edu, Jason@...c4.com,
        davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
        pabeni@...hat.com, jejb@...ux.ibm.com, martin.petersen@...cle.com,
        andriy.shevchenko@...ux.intel.com, linux@...musvillemoes.dk,
        james.smart@...adcom.com, dick.kennedy@...adcom.com,
        linux-kernel@...r.kernel.org, wireguard@...ts.zx2c4.com,
        netdev@...r.kernel.org, linux-scsi@...r.kernel.org
Subject: Re: [PATCH 1/5] random: fix try_to_generate_entropy() if no further
 cpus set

On Tue, Mar 07, 2023 at 12:06:47AM +0800, Vernon Yang wrote:
> After commit 596ff4a09b89 ("cpumask: re-introduce constant-sized cpumask
> optimizations"), when NR_CPUS <= BITS_PER_LONG, small_cpumask_bits used
> a macro instead of variable-sized for efficient.
> 
> If no further cpus set, the cpumask_next() returns small_cpumask_bits,
> it must greater than or equal to nr_cpumask_bits, so fix it to correctly.
> 
> Signed-off-by: Vernon Yang <vernon2gm@...il.com>

Hi Vernon,

In all that cases, nr_cpu_ids must be used. The difference is that
nr_cpumask_bits is an upper limit for possible CPUs, and it's derived
from compile-time NR_CPUS, unless CPUMASK_OFFSTACK is enabled.

nr_cpu_ids is an actual number of CPUS as counted on boot.

So, nr_cpu_ids is always equal or less than nr_cpumask_bits, and we'd
compare with the smaller number.

Nor sure, but maybe it's worth to introduce a macro like:
 #define valid_cpuid(cpu) (cpu) < nr_cpu_ids

Thanks,
Yury
> ---
>  drivers/char/random.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/char/random.c b/drivers/char/random.c
> index ce3ccd172cc8..d76f12a5f74f 100644
> --- a/drivers/char/random.c
> +++ b/drivers/char/random.c
> @@ -1311,7 +1311,7 @@ static void __cold try_to_generate_entropy(void)
>  			/* Basic CPU round-robin, which avoids the current CPU. */
>  			do {
>  				cpu = cpumask_next(cpu, &timer_cpus);
> -				if (cpu == nr_cpumask_bits)
> +				if (cpu >= nr_cpumask_bits)
>  					cpu = cpumask_first(&timer_cpus);
>  			} while (cpu == smp_processor_id() && num_cpus > 1);
>  
> -- 
> 2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ