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]
Date: Mon, 22 Apr 2024 14:15:50 +0800
From: Dawei Li <dawei.li@...ngroup.cn>
To: Sam Ravnborg <sam@...nborg.org>
Cc: davem@...emloft.net, andreas@...sler.com, sparclinux@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 6/7] sparc/leon: Remove on-stack cpumask var

Hi Sam,

Thanks for review.

On Sat, Apr 20, 2024 at 10:32:02AM +0200, Sam Ravnborg wrote:
> On Sat, Apr 20, 2024 at 01:15:46PM +0800, Dawei Li wrote:
> > In general it's preferable to avoid placing cpumasks on the stack, as
> > for large values of NR_CPUS these can consume significant amounts of
> > stack space and make stack overflows more likely.
> > 
> > Use cpumask_subset() and cpumask_first_and() to avoid the need for a
> > temporary cpumask on the stack.
> > 
> > Signed-off-by: Dawei Li <dawei.li@...ngroup.cn>
> > ---
> >  arch/sparc/kernel/leon_kernel.c | 9 +++------
> >  1 file changed, 3 insertions(+), 6 deletions(-)
> > 
> > diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
> > index 4c61da491fee..0070655041bb 100644
> > --- a/arch/sparc/kernel/leon_kernel.c
> > +++ b/arch/sparc/kernel/leon_kernel.c
> > @@ -106,13 +106,10 @@ unsigned long leon_get_irqmask(unsigned int irq)
> >  #ifdef CONFIG_SMP
> >  static int irq_choose_cpu(const struct cpumask *affinity)
> >  {
> > -	cpumask_t mask;
> > +	unsigned int cpu = cpumask_first_and(affinity, cpu_online_mask);
> >  
> > -	cpumask_and(&mask, cpu_online_mask, affinity);
> > -	if (cpumask_equal(&mask, cpu_online_mask) || cpumask_empty(&mask))
> > -		return boot_cpu_id;
> > -	else
> > -		return cpumask_first(&mask);
> > +	return cpumask_subset(cpu_online_mask, affinity) || cpu >= nr_cpu_ids ?
> > +	       boot_cpu_id : cpu;
> 
> This looks wrong - or if it is correct is is hard to parse.
> Drop ?: and use an if so the code is more readable.

I am confused a bit here, about its correctness(not coding style).

Per my understanding:

A & B = A <-> For every set bit in A, it's set for B; <-> B is superset
of A. <-> A is subset of B.

-	cpumask_and(&mask, cpu_online_mask, affinity);
-	if (cpumask_equal(&mask, cpu_online_mask))

So, codes above is equivalent to:
	if (cpumask_subset(cpu_online_mask, affinity))

Am I missing something?

About the ?:, I will restore original "if else" style. 

> 
> 	Sam
> 

Thanks,

    Dawei

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ