linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Shuah Khan <skhan@linuxfoundation.org>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Christian Brauner <christian@brauner.io>
Cc: Shuah Khan <shuah@kernel.org>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Suren Baghdasaryan <surenb@google.com>,
	"Vlastimil Babka" <vbabka@suse.cz>, <pedro.falcato@gmail.com>,
	<linux-kselftest@vger.kernel.org>, <linux-mm@kvack.org>,
	<linux-fsdevel@vger.kernel.org>, <linux-api@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	Oliver Sang <oliver.sang@intel.com>
Subject: Re: [PATCH v4 3/4] selftests: pidfd: add pidfd.h UAPI wrapper
Date: Thu, 17 Oct 2024 15:22:02 -0700	[thread overview]
Message-ID: <80e06cf2-fcd4-48be-86f9-a5d6acec46c4@nvidia.com> (raw)
In-Reply-To: <f24e645f-e7e6-436d-875b-7e15feeae8eb@linuxfoundation.org>

On 10/17/24 3:11 PM, Shuah Khan wrote:
> On 10/17/24 15:45, John Hubbard wrote:
>> On 10/17/24 2:05 PM, Lorenzo Stoakes wrote:
>>> Conflicts can arise between system fcntl.h and linux/fcntl.h, imported by
>>> the linux/pidfd.h UAPI header.
>>>
>>> Work around this by adding a wrapper for linux/pidfd.h to
>>> tools/include/ which sets the linux/fcntl.h header guard ahead of
>>> importing the pidfd.h header file.
>>>
>>> Adjust the pidfd selftests Makefile to reference this include directory and
>>> put it at a higher precidence than any make header installed headers to
>>> ensure the wrapper is preferred.
>>
>> ...but we are not actually using the installed headers, now. And we intend
>> to continue avoiding them. So the ordering shouldn't matter. More below:
>>
>>>
>>> This way we can directly import the UAPI header file without issue, use the
>>> latest system header file without having to duplicate anything.
>>>
>>> Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
>>> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
>>> ---
>>>   tools/include/linux/pidfd.h            | 14 ++++++++++++++
>>>   tools/testing/selftests/pidfd/Makefile |  3 +--
>>>   2 files changed, 15 insertions(+), 2 deletions(-)
>>>   create mode 100644 tools/include/linux/pidfd.h
>>>
>>> diff --git a/tools/include/linux/pidfd.h b/tools/include/linux/pidfd.h
>>> new file mode 100644
>>> index 000000000000..113c8023072d
>>> --- /dev/null
>>> +++ b/tools/include/linux/pidfd.h
>>> @@ -0,0 +1,14 @@
>>> +/* SPDX-License-Identifier: GPL-2.0-only */
>>> +
>>> +#ifndef _TOOLS_LINUX_PIDFD_H
>>> +#define _TOOLS_LINUX_PIDFD_H
>>> +
>>> +/*
>>> + * Some systems have issues with the linux/fcntl.h import in linux/pidfd.h, so
>>> + * work around this by setting the header guard.
>>> + */
>>> +#define _LINUX_FCNTL_H
>>> +#include "../../../include/uapi/linux/pidfd.h"
>>> +#undef _LINUX_FCNTL_H
>>
>> Oh shoot, I think you, Shuah and I were referring to different uapi locations,
>> the whole time. And so the basic approach is different after all.
>>
>> Your include path above actually refers to:
>>
>>      $(top_srcdir)/include/uapi/linux/fcntl.h
> 
> Correct. I am glad we are on the same page now.
> 
>>
>> ...but what I was intending was to copy a snapshot of that file (or a
>> snapshot from the one generated by "make headers"), to here:
>>
>>      $(top_srcdir)/tools/include/uapi/linux/fcntl.h
> 
> So why do the copy and snapshot. Anytime you build userspace in the
> reoo - you will need to run "make headers: whether you install
> them under tools/include or include.

No, you only do "make headers" once, and that's a temporary thing too.
After the author of the new selftest runs "make headers", the author
will typically remove those headers, in order to verify that the
selftests still build without the kernel generated header files.

That's it! No one else has to deal with it. And that's what is being
asked for here.

> 
> 
>>
>> ...and then use $(TOOLS_INCLUDES), which is already in selftests/lib.mk,
>> for that reason: to be available to all of the kselftests:
>>
>>      TOOLS_INCLUDES := -isystem $(top_srcdir)/tools/include/uapi
> 
> Yes some tests do include that.
> 
>>
>> The reasoning for this directory is further explained here:
>>
>>      tools/include/uapi/README
>>
>> (And I see that selftests/proc has started using $(TOOLS_INCLUDES), that's
>> progress.)
> 
> Yes the same problems apply here - what complicates this more is
> selftests are supposed to test kernel changes, hence the need to
> include latest kernel headers. The simple solution is adding a
> dependency so we don't have to duplicate the headers. I don't
> believe the perf solution works here. We will have to figure out
> a solution.

That's the key point: the fact that the selftests are intended to
test kernel changes does *not* mean that we have to include the
dynamically generated header files. That's going further than
necessary. And it leads to problems and complaints for kernel
developers, who are really one of the main user groups here.

> 
>>
>> And now, it's possible to change fcntl.h in place, instead of using a wrapper.
>> Although either way seems OK to me. (I'm sort of ignoring the details of
>> the actual header file conflict itself, for now.)
>>
>>
>>> +
>>> +#endif /* _TOOLS_LINUX_PIDFD_H */
>>> diff --git a/tools/testing/selftests/pidfd/Makefile b/tools/testing/selftests/pidfd/Makefile
>>> index d731e3e76d5b..f5038c9dae14 100644
>>> --- a/tools/testing/selftests/pidfd/Makefile
>>> +++ b/tools/testing/selftests/pidfd/Makefile
>>> @@ -1,8 +1,7 @@
>>>   # SPDX-License-Identifier: GPL-2.0-only
>>> -CFLAGS += -g $(KHDR_INCLUDES) -pthread -Wall
>>> +CFLAGS += -g -isystem $(top_srcdir)/tools/include $(KHDR_INCLUDES) -pthread -Wall
>>
>> Instead, it would look like this, which now mostly matches selftests/mm/Makefile,
>> which is also helpful, because eventually this can be factored into a common
>> piece for all selftests:
>>
>>      CFLAGS += -g -isystem $(KHDR_INCLUDES) $(TOOLS_INCLUDES) -pthread -Wall
> 
> KHDR_INCLUDES is "make headers" location under the root directory. So what
> happens when you add TOOLS_INCLUDES to it.
> 
> Does "make kselftest-all" work as it is supposed to? If it and all tests
> can build then I am all for it.
> 
>>
>> I apologize for just now noticing this! And these kselftests shouldn't require
>> so much fussing around, I know. But once we get this just right, it will work
>> well and last a long time. :)
>>
> 
> 
> On the contrary if we don't discuss/fuss and get this right, we have to
> deal with changes like adding local defines and adhoc approaches in
> individual tests - that is one reason we made the "make headers"
> as a dependency. I would like to solve the problem of proliferation
> of local defines and even system calls in some cases.

Yes, let's work through this.

> 
> For now I am going let this patch go through as it is important to
> add tests.

Sure, we can iterate on it as necessary.

> 
> My goals are simple:
> 
> - no local defines unless it is abslulutely necessary

Agreed.

> - be able to build tests that add coverage for new kernel
>    api and features before we release the kernel.
> - make it easier for CIs to build and run tests

Up to a point! And that point should be somewhere *before*
it inflicts extra pain and annoyance on the kernel developers.

Let's not let CI drive this all by itself. CI is not writing
these tests, and furthermore it can adapt a little bit if necessary.

But even more to the point, avoiding "make headers" simplifies
CI, rather than complicating it.

> - continue to have tests works for kernel developres
>    e.g: mm developers build tests in mm directory. They
>    don't see the issues that crop up in CIs or running
>    the entire kselftest default run like CIs do.
> 
> Adhoc changes break some use-cases.
> 
> thanks,
> -- Shuah
> 
> 

thanks,
-- 
John Hubbard



  reply	other threads:[~2024-10-17 22:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17 21:05 [PATCH v4 0/4] introduce PIDFD_SELF* sentinels Lorenzo Stoakes
2024-10-17 21:05 ` [PATCH v4 1/4] pidfd: extend pidfd_get_pid() and de-duplicate pid lookup Lorenzo Stoakes
2024-10-23  0:20   ` Shakeel Butt
2024-10-17 21:05 ` [PATCH v4 2/4] pidfd: add PIDFD_SELF_* sentinels to refer to own thread/process Lorenzo Stoakes
2024-10-21  8:11   ` Lorenzo Stoakes
2024-10-23  0:53   ` Shakeel Butt
2024-10-23  7:18     ` Lorenzo Stoakes
2024-10-23 17:18       ` Shakeel Butt
2024-10-23 17:24         ` Lorenzo Stoakes
2024-10-17 21:05 ` [PATCH v4 3/4] selftests: pidfd: add pidfd.h UAPI wrapper Lorenzo Stoakes
2024-10-17 21:45   ` John Hubbard
2024-10-17 22:11     ` Shuah Khan
2024-10-17 22:22       ` John Hubbard [this message]
2024-10-18  6:49     ` Lorenzo Stoakes
2024-10-18 23:55       ` John Hubbard
2024-10-17 21:05 ` [PATCH v4 4/4] selftests: pidfd: add tests for PIDFD_SELF_* Lorenzo Stoakes
2024-10-25  8:10   ` kernel test robot
2024-10-25  8:48     ` Lorenzo Stoakes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=80e06cf2-fcd4-48be-86f9-a5d6acec46c4@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=christian@brauner.io \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=oliver.sang@intel.com \
    --cc=pedro.falcato@gmail.com \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox