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: <ZxpFQBRqWMDjhtSY@smile.fi.intel.com>
Date: Thu, 24 Oct 2024 16:01:52 +0300
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: "Huang, Ying" <ying.huang@...el.com>
Cc: Dan Williams <dan.j.williams@...el.com>,
	David Hildenbrand <david@...hat.com>,
	Andrew Morton <akpm@...ux-foundation.org>, linux-mm@...ck.org,
	linux-kernel@...r.kernel.org, linux-cxl@...r.kernel.org,
	Davidlohr Bueso <dave@...olabs.net>,
	Jonathan Cameron <jonathan.cameron@...wei.com>,
	Alistair Popple <apopple@...dia.com>,
	Bjorn Helgaas <bhelgaas@...gle.com>, Baoquan He <bhe@...hat.com>,
	Dave Jiang <dave.jiang@...el.com>,
	Alison Schofield <alison.schofield@...el.com>
Subject: Re: [RFC] resource: Avoid unnecessary resource tree walking in
 __region_intersects()

On Thu, Oct 24, 2024 at 08:30:39PM +0800, Huang, Ying wrote:
> Andy Shevchenko <andriy.shevchenko@...ux.intel.com> writes:
> > On Wed, Oct 23, 2024 at 02:07:52PM -0700, Dan Williams wrote:
> >> Andy Shevchenko wrote:
> >> > On Fri, Oct 11, 2024 at 09:06:37AM +0800, Huang, Ying wrote:
> >> > > David Hildenbrand <david@...hat.com> writes:
> >> > > > On 10.10.24 08:55, Huang Ying wrote:

...

> >> > > > 	for ((_p) = (_root)->child; (_p); (_p) = next_resource_XXX(_root, _p))
> >> > > 
> >> > > Yes.  This can improve code readability.
> >> > > 
> >> > > A possible issue is that "_root" will be evaluated twice in above macro
> >> > > definition.  IMO, this should be avoided.
> >> > 
> >> > Ideally, yes. But how many for_each type of macros you see that really try hard
> >> > to achieve that? I believe we shouldn't worry right now about this and rely on
> >> > the fact that root is the given variable. Or do you have an example of what you
> >> > suggested in the other reply, i.e. where it's an evaluation of the heavy call?
> >> > 
> >> > > Do you have some idea about
> >> > > how to do that?  Something like below?
> >> > > 
> >> > > #define for_each_resource_XXX(_root, _p)                                \
> >> > > 	for (typeof(_root) __root = (_root), __p = (_p) = (__root)->child; \
> >> > > 	     __p && (_p); (_p) = next_resource_XXX(__root, _p))
> >> > 
> >> > This is a bit ugly :-( I would avoid ugliness as long as we have no problem to
> >> > solve (see above).
> >> 
> >> Using a local defined variable to avoid double evaluation is standard
> >> practice. I do not understand "avoid ugliness as long as we have no problem to
> >> solve", the problem to solve will be if someone accidentally does
> >> something like "for_each_resource_descendant(root++, res)". *That* will
> >> be a problem when someone finally realizes that the macro is hiding a
> >> double evaluation.
> >
> > Can you explain, why do we need __p and how can we get rid of that?
> > I understand the part of the local variable for root.
> 
> If don't use '__p', the macro becomes
> 
> #define for_each_resource_XXX(_root, _p)                                \
> 	for (typeof(_root) __root = (_root), (_p) = (__root)->child; \
> 	     (_p); (_p) = next_resource_XXX(__root, _p))
> 
> Where, '_p' must be a variable name, and it will be a new variable
> inside for loop and mask the variable with same name outside of macro.
> IIUC, this breaks the macro convention in kernel and has subtle variable
> masking semantics.

Yep.

In property.h nobody cares about evaluation which makes the macro as simple as

#define for_each_resource_XXX(_root, _p)		\
	for (_p = next_resource_XXX(__root, NULL); _p;	\
	     _p = next_resource_XXX(__root, _p))

(Dan,
 that's what I called to avoid solving issues we don't have and most likely
 will never have.)

but if you want to stick with your variant some improvements can be done:

#define for_each_resource_XXX(_root, _p)				\
	for (typeof(_root) __root = (_root), __p = _p = __root->child;	\
	     __p && _p; _p = next_resource_XXX(__root, _p))


1) no need to have local variable in parentheses;
2) no need to have iterator in parentheses, otherwise it would be crazy code
that has put something really wrong there and still expect the thing to work.

> >> So no, this proposal is not "ugly", it is a best practice. See the
> >> definition of min_not_zero() for example.
> >
> > I know that there are a lot of macros that look uglier that this one.

-- 
With Best Regards,
Andy Shevchenko



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ