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: <87msja93ni.fsf@yhuang6-desk2.ccr.corp.intel.com>
Date: Fri, 11 Oct 2024 21:21:05 +0800
From: "Huang, Ying" <ying.huang@...el.com>
To: David Hildenbrand <david@...hat.com>
Cc: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,  Andrew Morton
 <akpm@...ux-foundation.org>,  linux-mm@...ck.org,
  linux-kernel@...r.kernel.org,  linux-cxl@...r.kernel.org,  Dan Williams
 <dan.j.williams@...el.com>,  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()

David Hildenbrand <david@...hat.com> writes:

> On 11.10.24 13:19, Andy Shevchenko wrote:
>> On Fri, Oct 11, 2024 at 02:15:55PM +0300, Andy Shevchenko wrote:
>>> On Fri, Oct 11, 2024 at 12:51:09PM +0200, David Hildenbrand wrote:
>>>> On 11.10.24 12:49, 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).
>>>>
>>>> Fully agreed, I didn't quite understand the concern about "evaluation" at
>>>> first.
>>>
>>> It's a basic concept for macros and a good mine field even for the simple
>>> cases.
>>>
>>>> If it's just reading a variable twice, it doesn't matter at all right
>>>> now.
>>>
>>> The problem (even if it's a variable) is that the content of variable can be
>>> changed when run in non-atomic context, i.e. two evaluations will give two
>>> different results. Most "simple" for_each macros leave this exercise to the
>>> caller. That's what I also suggest for now.
>> For any context as Ying provided an example with calls, they have to
>> be
>> idempotent, or you definitely get two different pointers for these, which is
>> bigger issue that what I described above.
>
> Ah, now I understood what Ying meant: if the root pointer is modified
> within the loop body we'd be in trouble.

Given we cannot provide a good macro implementation to traverse only the
descendant tree of _root, I suggest to just keep current
for_each_resource() implementation.  There is only one user of the
proposed new macro to traverse the descendant tree.  So, I suggest to
open coded the for loop instead.  More comments can be added to make it
clear.

--
Best Regards,
Huang, Ying

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ