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:   Thu, 27 Jan 2022 15:02:05 +0000
From:   "Michael Kelley (LINUX)" <mikelley@...rosoft.com>
To:     vkuznets <vkuznets@...hat.com>, Yury Norov <yury.norov@...il.com>
CC:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Michał Mirosław <mirq-linux@...e.qmqm.pl>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Peter Zijlstra <peterz@...radead.org>,
        David Laight <David.Laight@...lab.com>,
        Joe Perches <joe@...ches.com>, Dennis Zhou <dennis@...nel.org>,
        Emil Renner Berthing <kernel@...il.dk>,
        Nicholas Piggin <npiggin@...il.com>,
        Matti Vaittinen <matti.vaittinen@...rohmeurope.com>,
        Alexey Klimov <aklimov@...hat.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        KY Srinivasan <kys@...rosoft.com>,
        Haiyang Zhang <haiyangz@...rosoft.com>,
        Stephen Hemminger <sthemmin@...rosoft.com>,
        Wei Liu <wei.liu@...nel.org>, Dexuan Cui <decui@...rosoft.com>,
        "linux-hyperv@...r.kernel.org" <linux-hyperv@...r.kernel.org>
Subject: RE: [PATCH 43/54] drivers/hv: replace cpumask_weight with
 cpumask_weight_eq

From: Vitaly Kuznetsov <vkuznets@...hat.com> Sent: Monday, January 24, 2022 1:20 AM
> 
> Yury Norov <yury.norov@...il.com> writes:
> 
> > init_vp_index() calls cpumask_weight() to compare the weights of cpumasks
> > We can do it more efficiently with cpumask_weight_eq because conditional
> > cpumask_weight may stop traversing the cpumask earlier (at least one), as
> > soon as condition is met.
> 
> Same comment as for "PATCH 41/54": cpumask_weight_eq() can only stop
> earlier if the condition is not met, to prove the equality all bits need
> always have to be examined.
> 
> >
> > Signed-off-by: Yury Norov <yury.norov@...il.com>
> > ---
> >  drivers/hv/channel_mgmt.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
> > index 60375879612f..7420a5fd47b5 100644
> > --- a/drivers/hv/channel_mgmt.c
> > +++ b/drivers/hv/channel_mgmt.c
> > @@ -762,8 +762,8 @@ static void init_vp_index(struct vmbus_channel *channel)
> >  		}
> >  		alloced_mask = &hv_context.hv_numa_map[numa_node];
> >
> > -		if (cpumask_weight(alloced_mask) ==
> > -		    cpumask_weight(cpumask_of_node(numa_node))) {
> > +		if (cpumask_weight_eq(alloced_mask,
> > +			    cpumask_weight(cpumask_of_node(numa_node)))) {
> 
> This code is not performace critical and I prefer the old version:
> 
>  	cpumask_weight() == cpumask_weight()
> 
>  looks better than
> 
> 	cpumask_weight_eq(..., cpumask_weight())
> 
> (let alone the inner cpumask_of_node()) to me.
> 
> >  			/*
> >  			 * We have cycled through all the CPUs in the node;
> >  			 * reset the alloced map.
> 
> --
> Vitaly

I agree with Vitaly in preferring the old version, and indeed performance
here is a shrug.  But actually, I think the old version is a poorly coded way
to determine if the two cpumasks are equal. The following would correctly
capture the intent:

	if (cpumask_equal(alloced_mask, cpumask_of_node(numa_node))

Michael



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ