Linux Input/HID development
 help / color / mirror / Atom feed
* Re: [PATCH v3 01/11] can: Add LIN bus as CAN abstraction
From: Christoph Fritz @ 2024-05-08 18:20 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Oliver Hartkopp, Marc Kleine-Budde, Jiri Slaby, Vincent Mailhol,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jiri Kosina,
	Benjamin Tissoires, Greg Kroah-Hartman, Sebastian Reichel,
	Linus Walleij, Andreas Lauser, Jonathan Corbet, Pavel Pisa,
	linux-can, Netdev, devicetree, linux-input, linux-serial
In-Reply-To: <4e8a50a0-f938-8aaf-fe4b-d18765407d4d@linux.intel.com>

...
> ...
> > > > +static int lin_create_sysfs_id_files(struct net_device *ndev)
> > > > +{
> > > > +	struct lin_device *ldev = netdev_priv(ndev);
> > > > +	struct kobj_attribute *attr;
> > > > +	int ret;
> > > > +
> > > > +	for (int id = 0; id < LIN_NUM_IDS; id++) {
> > > > +		ldev->sysfs_entries[id].ldev = ldev;
> > > > +		attr = &ldev->sysfs_entries[id].attr;
> > > > +		attr->attr.name = kasprintf(GFP_KERNEL, "%02x", id);
> > > > +		if (!attr->attr.name)
> > > > +			return -ENOMEM;
> > > > +		attr->attr.mode = 0644;
> > > > +		attr->show = lin_identifier_show;
> > > > +		attr->store = lin_identifier_store;
> > > > +
> > > > +		sysfs_attr_init(&attr->attr);
> > > > +		ret = sysfs_create_file(ldev->lin_ids_kobj, &attr->attr);
> > > > +		if (ret) {
> > > > +			kfree(attr->attr.name);
> > > > +			return -ENOMEM;
> > > > +		}
> > > > +	}
> > > > +
> > > > +	return 0;
> > > > +}
> > > 
> > > Can you use .dev_groups instead ?
> > 
> > I'm not sure where to attach this in this glue code here. Should I do a
> > class_register() and add the .dev_groups there?
> 
> I guess struct class would be correct direction but I'm not sure if it's 
> viable in this case. It would avoid the need for custom sysfs setup code
> if it's workable.

I just tried to find a way, but these are 64 sysfs files and declaring
them all static looks a bit odd to me. I might be missing something
here.

For v4 I would stick to the dynamic setup and fix the rollback.

Any objections?


Thanks
  -- Christoph


^ permalink raw reply

* Re: [PATCH v3 01/11] can: Add LIN bus as CAN abstraction
From: Greg Kroah-Hartman @ 2024-05-08 18:48 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Ilpo Järvinen, Oliver Hartkopp, Marc Kleine-Budde,
	Jiri Slaby, Vincent Mailhol, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Jiri Kosina, Benjamin Tissoires, Sebastian Reichel,
	Linus Walleij, Andreas Lauser, Jonathan Corbet, Pavel Pisa,
	linux-can, Netdev, devicetree, linux-input, linux-serial
In-Reply-To: <215d898a0244d717467d44a8e93f186e2f282daa.camel@hexdev.de>

On Wed, May 08, 2024 at 08:20:51PM +0200, Christoph Fritz wrote:
> ...
> > ...
> > > > > +static int lin_create_sysfs_id_files(struct net_device *ndev)
> > > > > +{
> > > > > +	struct lin_device *ldev = netdev_priv(ndev);
> > > > > +	struct kobj_attribute *attr;
> > > > > +	int ret;
> > > > > +
> > > > > +	for (int id = 0; id < LIN_NUM_IDS; id++) {
> > > > > +		ldev->sysfs_entries[id].ldev = ldev;
> > > > > +		attr = &ldev->sysfs_entries[id].attr;
> > > > > +		attr->attr.name = kasprintf(GFP_KERNEL, "%02x", id);
> > > > > +		if (!attr->attr.name)
> > > > > +			return -ENOMEM;
> > > > > +		attr->attr.mode = 0644;
> > > > > +		attr->show = lin_identifier_show;
> > > > > +		attr->store = lin_identifier_store;
> > > > > +
> > > > > +		sysfs_attr_init(&attr->attr);
> > > > > +		ret = sysfs_create_file(ldev->lin_ids_kobj, &attr->attr);
> > > > > +		if (ret) {
> > > > > +			kfree(attr->attr.name);
> > > > > +			return -ENOMEM;
> > > > > +		}
> > > > > +	}
> > > > > +
> > > > > +	return 0;
> > > > > +}
> > > > 
> > > > Can you use .dev_groups instead ?
> > > 
> > > I'm not sure where to attach this in this glue code here. Should I do a
> > > class_register() and add the .dev_groups there?
> > 
> > I guess struct class would be correct direction but I'm not sure if it's 
> > viable in this case. It would avoid the need for custom sysfs setup code
> > if it's workable.
> 
> I just tried to find a way, but these are 64 sysfs files and declaring
> them all static looks a bit odd to me. I might be missing something
> here.
> 
> For v4 I would stick to the dynamic setup and fix the rollback.
> 
> Any objections?

Yes, you race with userspace and loose by trying to do this "by hand".
Make this static please.

thanks,

greg k-h

^ permalink raw reply

* Re: [PATCH] dt-bindings: Use full path to other schemas
From: Rob Herring (Arm) @ 2024-05-08 19:10 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: linux-mtd, linux-kernel, Shijie Qin, Ming Qian,
	Vignesh Raghavendra, Miquel Raynal, Zhou Peng, linux-input,
	devicetree, linux-media, Krzysztof Kozlowski,
	Mauro Carvalho Chehab, Dmitry Torokhov, Conor Dooley,
	Jeff LaBundy, Richard Weinberger
In-Reply-To: <20240505084618.135705-1-krzysztof.kozlowski@linaro.org>


On Sun, 05 May 2024 10:46:18 +0200, Krzysztof Kozlowski wrote:
> When referencing other schema, it is preferred to use an absolute path
> (/schemas/....), which allows also an seamless move of particular schema
> out of Linux kernel to dtschema.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> 
> ---
> 
> Rob, maybe you can take it directly? Should apply cleanly on your tree.
> ---
>  Documentation/devicetree/bindings/input/azoteq,iqs7222.yaml | 2 +-
>  Documentation/devicetree/bindings/media/amphion,vpu.yaml    | 2 +-
>  Documentation/devicetree/bindings/mtd/mtd.yaml              | 4 ++--
>  3 files changed, 4 insertions(+), 4 deletions(-)
> 

Applied, thanks!


^ permalink raw reply

* Re: [PATCH v2 4/5] selftests: Drop define _GNU_SOURCE
From: Edward Liaw @ 2024-05-08 20:27 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: shuah, Mark Brown, Jaroslav Kysela, Takashi Iwai, Catalin Marinas,
	Will Deacon, Nhat Pham, Johannes Weiner, Christian Brauner,
	Eric Biederman, Kees Cook, OGAWA Hirofumi, Thomas Gleixner,
	Ingo Molnar, Peter Zijlstra, Darren Hart, Davidlohr Bueso,
	André Almeida, Jiri Kosina, Benjamin Tissoires,
	Jason Gunthorpe, Kevin Tian, Andy Lutomirski, Will Drewry,
	Marc Zyngier, Oliver Upton, James Morse, Suzuki K Poulose,
	Zenghui Yu, Paolo Bonzini, Anup Patel, Atish Patra, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Christian Borntraeger, Janosch Frank,
	Claudio Imbrenda, David Hildenbrand, Mickaël Salaün,
	Paul Moore, James Morris, Serge E. Hallyn, Andrew Morton,
	Seth Forshee, Bongsu Jeon, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Steffen Klassert, Herbert Xu,
	Andreas Färber, Manivannan Sadhasivam, Matthieu Baerts,
	Mat Martineau, Geliang Tang, Willem de Bruijn, Fenghua Yu,
	Reinette Chatre, Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum, linux-kernel, linux-kselftest, kernel-team,
	linux-sound, linux-arm-kernel, linux-mm, linux-input, iommu,
	kvmarm, kvm, kvm-riscv, linux-riscv, linux-security-module,
	linux-fsdevel, netdev, linux-actions, mptcp, linux-rtc, linux-sgx,
	bpf
In-Reply-To: <ZjuEILj0SZRuTL9I@google.com>

On Wed, May 8, 2024 at 6:54 AM Sean Christopherson <seanjc@google.com> wrote:
>
> On Tue, May 07, 2024, Edward Liaw wrote:
> > _GNU_SOURCE is provided by KHDR_INCLUDES, so it should be dropped to
> > prevent _GNU_SOURCE redefined warnings.
>
> ...
>
> > diff --git a/tools/testing/selftests/x86/test_syscall_vdso.c b/tools/testing/selftests/x86/test_syscall_vdso.c
> > index 8965c311bd65..5cd13279bba5 100644
> > --- a/tools/testing/selftests/x86/test_syscall_vdso.c
> > +++ b/tools/testing/selftests/x86/test_syscall_vdso.c
> > @@ -8,10 +8,6 @@
> >   * Can be built statically:
> >   * gcc -Os -Wall -static -m32 test_syscall_vdso.c thunks_32.S
> >   */
> > -#undef _GNU_SOURCE
> > -#define _GNU_SOURCE 1
> > -#undef __USE_GNU
> > -#define __USE_GNU 1
>
> AFAICT, manually defining __USE_GNU is frowned upon, so I'm guessing the __USE_GNU
> stuff is just the result of misguided copy+paste.  But it would be nice to get
> confirmation that this test isn't doing something clever.  Or at the very least,
> explain the removal of __USE_GNU in the changelog.

It looks like test_syscall_vdso, test_FCMOV, test_FCOMI, and
test_FISTTP don't actually use any GNU extensions.  I'll add that to
the commit message.


>
> >  #include <unistd.h>
> >  #include <stdlib.h>
> >  #include <string.h>

^ permalink raw reply

* Re: [PATCH v2 1/5] selftests: Compile kselftest headers with -D_GNU_SOURCE
From: John Hubbard @ 2024-05-08 21:23 UTC (permalink / raw)
  To: Edward Liaw, shuah, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Catalin Marinas, Will Deacon, Nhat Pham, Johannes Weiner,
	Christian Brauner, Eric Biederman, Kees Cook, OGAWA Hirofumi,
	Thomas Gleixner, Ingo Molnar, Peter Zijlstra, Darren Hart,
	Davidlohr Bueso, André Almeida, Jiri Kosina,
	Benjamin Tissoires, Jason Gunthorpe, Kevin Tian, Andy Lutomirski,
	Will Drewry, Marc Zyngier, Oliver Upton, James Morse,
	Suzuki K Poulose, Zenghui Yu, Paolo Bonzini, Sean Christopherson,
	Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Mickaël Salaün, Paul Moore,
	James Morris, Serge E. Hallyn, Andrew Morton, Seth Forshee,
	Bongsu Jeon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Steffen Klassert, Herbert Xu, Andreas Färber,
	Manivannan Sadhasivam, Matthieu Baerts, Mat Martineau,
	Geliang Tang, Willem de Bruijn, Fenghua Yu, Reinette Chatre,
	Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum
  Cc: linux-kernel, linux-kselftest, kernel-team, linux-sound,
	linux-arm-kernel, linux-mm, linux-input, iommu, kvmarm, kvm,
	kvm-riscv, linux-riscv, linux-security-module, linux-fsdevel,
	netdev, linux-actions, mptcp, linux-rtc, linux-sgx, bpf,
	kernel test robot
In-Reply-To: <20240507214254.2787305-2-edliaw@google.com>

On 5/7/24 2:38 PM, Edward Liaw wrote:
> Add the -D_GNU_SOURCE flag to KHDR_INCLUDES so that it is defined in a
> central location.
> 
> 809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
> asprintf into kselftest_harness.h, which is a GNU extension and needs
> _GNU_SOURCE to either be defined prior to including headers or with the
> -D_GNU_SOURCE flag passed to the compiler.
> 
> Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202404301040.3bea5782-oliver.sang@intel.com
> Signed-off-by: Edward Liaw <edliaw@google.com>
> ---
>   tools/testing/selftests/Makefile            | 4 ++--
>   tools/testing/selftests/kselftest_harness.h | 2 +-
>   tools/testing/selftests/lib.mk              | 2 +-
>   3 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
> index e1504833654d..ed012a7f0786 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -161,11 +161,11 @@ ifneq ($(KBUILD_OUTPUT),)
>     # $(realpath ...) resolves symlinks
>     abs_objtree := $(realpath $(abs_objtree))
>     BUILD := $(abs_objtree)/kselftest
> -  KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
> +  KHDR_INCLUDES := -D_GNU_SOURCE -isystem ${abs_objtree}/usr/include
>   else
>     BUILD := $(CURDIR)
>     abs_srctree := $(shell cd $(top_srcdir) && pwd)
> -  KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
> +  KHDR_INCLUDES := -D_GNU_SOURCE -isystem ${abs_srctree}/usr/include
>     DEFAULT_INSTALL_HDR_PATH := 1
>   endif

Just a small copy-paste duplication request: can we maybe do it this
way, instead, to remove the duplication? It's small *so far*, but
still. :)

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index e1504833654d..13a5b11db59a 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -152,6 +152,8 @@ ifeq ("$(origin O)", "command line")
    KBUILD_OUTPUT := $(O)
  endif
  
+KHDR_INCLUDES := -D_GNU_SOURCE
+
  ifneq ($(KBUILD_OUTPUT),)
    # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
    # expand a shell special character '~'. We use a somewhat tedious way here.
@@ -161,11 +163,11 @@ ifneq ($(KBUILD_OUTPUT),)
    # $(realpath ...) resolves symlinks
    abs_objtree := $(realpath $(abs_objtree))
    BUILD := $(abs_objtree)/kselftest
-  KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
+  KHDR_INCLUDES += -isystem ${abs_objtree}/usr/include
  else
    BUILD := $(CURDIR)
    abs_srctree := $(shell cd $(top_srcdir) && pwd)
-  KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
+  KHDR_INCLUDES += -isystem ${abs_srctree}/usr/include
    DEFAULT_INSTALL_HDR_PATH := 1
  endif


>   
> diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
> index d98702b6955d..b2a1b6343896 100644
> --- a/tools/testing/selftests/kselftest_harness.h
> +++ b/tools/testing/selftests/kselftest_harness.h
> @@ -51,7 +51,7 @@
>   #define __KSELFTEST_HARNESS_H
>   
>   #ifndef _GNU_SOURCE
> -#define _GNU_SOURCE
> +static_assert(0, "kselftest harness requires _GNU_SOURCE to be defined");
>   #endif
>   #include <asm/types.h>
>   #include <ctype.h>
> diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
> index da2cade3bab0..2503dc732b4d 100644
> --- a/tools/testing/selftests/lib.mk
> +++ b/tools/testing/selftests/lib.mk
> @@ -45,7 +45,7 @@ selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
>   top_srcdir = $(selfdir)/../../..
>   
>   ifeq ($(KHDR_INCLUDES),)
> -KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include
> +KHDR_INCLUDES := -D_GNU_SOURCE -isystem $(top_srcdir)/usr/include
>   endif
>   
>   # The following are built by lib.mk common compile rules.

The rest looks good. And whether you accept my recommendation above,
or not, either way this patch looks good, so please feel free to add:

Reviewed-by: John Hubbard <jhubbard@nvidia.com>


thanks,
-- 
John Hubbard
NVIDIA


^ permalink raw reply related

* Re: [PATCH v2 2/5] selftests/sgx: Include KHDR_INCLUDES in Makefile
From: John Hubbard @ 2024-05-08 21:25 UTC (permalink / raw)
  To: Edward Liaw, shuah, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Catalin Marinas, Will Deacon, Nhat Pham, Johannes Weiner,
	Christian Brauner, Eric Biederman, Kees Cook, OGAWA Hirofumi,
	Thomas Gleixner, Ingo Molnar, Peter Zijlstra, Darren Hart,
	Davidlohr Bueso, André Almeida, Jiri Kosina,
	Benjamin Tissoires, Jason Gunthorpe, Kevin Tian, Andy Lutomirski,
	Will Drewry, Marc Zyngier, Oliver Upton, James Morse,
	Suzuki K Poulose, Zenghui Yu, Paolo Bonzini, Sean Christopherson,
	Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Mickaël Salaün, Paul Moore,
	James Morris, Serge E. Hallyn, Andrew Morton, Seth Forshee,
	Bongsu Jeon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Steffen Klassert, Herbert Xu, Andreas Färber,
	Manivannan Sadhasivam, Matthieu Baerts, Mat Martineau,
	Geliang Tang, Willem de Bruijn, Fenghua Yu, Reinette Chatre,
	Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum
  Cc: linux-kernel, linux-kselftest, kernel-team, linux-sound,
	linux-arm-kernel, linux-mm, linux-input, iommu, kvmarm, kvm,
	kvm-riscv, linux-riscv, linux-security-module, linux-fsdevel,
	netdev, linux-actions, mptcp, linux-rtc, linux-sgx, bpf,
	kernel test robot
In-Reply-To: <20240507214254.2787305-3-edliaw@google.com>

On 5/7/24 2:38 PM, Edward Liaw wrote:
> Add KHDR_INCLUDES to the CFLAGS to pull in the kselftest harness
> dependencies (-D_GNU_SOURCE).
> 
> Also, remove redefinitions of _GNU_SOURCE in the source code.
> 
> Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202404301040.3bea5782-oliver.sang@intel.com
> Signed-off-by: Edward Liaw <edliaw@google.com>
> ---
>   tools/testing/selftests/sgx/Makefile    | 2 +-
>   tools/testing/selftests/sgx/sigstruct.c | 1 -
>   2 files changed, 1 insertion(+), 2 deletions(-)

Looks good, and also still works with a clang/LLVM build (that is,
with the whole series applied.

Reviewed-by: John Hubbard <jhubbard@nvidia.com>

thanks,
-- 
John Hubbard
NVIDIA

> 
> diff --git a/tools/testing/selftests/sgx/Makefile b/tools/testing/selftests/sgx/Makefile
> index 867f88ce2570..26ea30fae23c 100644
> --- a/tools/testing/selftests/sgx/Makefile
> +++ b/tools/testing/selftests/sgx/Makefile
> @@ -12,7 +12,7 @@ OBJCOPY := $(CROSS_COMPILE)objcopy
>   endif
>   
>   INCLUDES := -I$(top_srcdir)/tools/include
> -HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC
> +HOST_CFLAGS := -Wall -Werror $(KHDR_INCLUDES) -g $(INCLUDES) -fPIC
>   HOST_LDFLAGS := -z noexecstack -lcrypto
>   ENCL_CFLAGS += -Wall -Werror -static-pie -nostdlib -ffreestanding -fPIE \
>   	       -fno-stack-protector -mrdrnd $(INCLUDES)
> diff --git a/tools/testing/selftests/sgx/sigstruct.c b/tools/testing/selftests/sgx/sigstruct.c
> index d73b29becf5b..200034a0fee5 100644
> --- a/tools/testing/selftests/sgx/sigstruct.c
> +++ b/tools/testing/selftests/sgx/sigstruct.c
> @@ -1,7 +1,6 @@
>   // SPDX-License-Identifier: GPL-2.0
>   /*  Copyright(c) 2016-20 Intel Corporation. */
>   
> -#define _GNU_SOURCE
>   #include <assert.h>
>   #include <getopt.h>
>   #include <stdbool.h>



^ permalink raw reply

* Re: [PATCH v2 4/5] selftests: Drop define _GNU_SOURCE
From: John Hubbard @ 2024-05-08 21:39 UTC (permalink / raw)
  To: Edward Liaw, shuah, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Catalin Marinas, Will Deacon, Nhat Pham, Johannes Weiner,
	Christian Brauner, Eric Biederman, Kees Cook, OGAWA Hirofumi,
	Thomas Gleixner, Ingo Molnar, Peter Zijlstra, Darren Hart,
	Davidlohr Bueso, André Almeida, Jiri Kosina,
	Benjamin Tissoires, Jason Gunthorpe, Kevin Tian, Andy Lutomirski,
	Will Drewry, Marc Zyngier, Oliver Upton, James Morse,
	Suzuki K Poulose, Zenghui Yu, Paolo Bonzini, Sean Christopherson,
	Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Mickaël Salaün, Paul Moore,
	James Morris, Serge E. Hallyn, Andrew Morton, Seth Forshee,
	Bongsu Jeon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Steffen Klassert, Herbert Xu, Andreas Färber,
	Manivannan Sadhasivam, Matthieu Baerts, Mat Martineau,
	Geliang Tang, Willem de Bruijn, Fenghua Yu, Reinette Chatre,
	Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum
  Cc: linux-kernel, linux-kselftest, kernel-team, linux-sound,
	linux-arm-kernel, linux-mm, linux-input, iommu, kvmarm, kvm,
	kvm-riscv, linux-riscv, linux-security-module, linux-fsdevel,
	netdev, linux-actions, mptcp, linux-rtc, linux-sgx, bpf
In-Reply-To: <20240507214254.2787305-5-edliaw@google.com>

On 5/7/24 2:38 PM, Edward Liaw wrote:
> _GNU_SOURCE is provided by KHDR_INCLUDES, so it should be dropped to
> prevent _GNU_SOURCE redefined warnings.
> 
> Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
> Signed-off-by: Edward Liaw <edliaw@google.com>
> ---

Very nice.

Reviewed-by: John Hubbard <jhubbard@nvidia.com>

thanks,
-- 
John Hubbard
NVIDIA

>   tools/testing/selftests/cachestat/test_cachestat.c            | 2 --
>   tools/testing/selftests/capabilities/test_execve.c            | 2 --
>   tools/testing/selftests/clone3/clone3.c                       | 2 --
>   .../testing/selftests/clone3/clone3_cap_checkpoint_restore.c  | 2 --
>   tools/testing/selftests/clone3/clone3_clear_sighand.c         | 2 --
>   tools/testing/selftests/clone3/clone3_selftests.h             | 1 -
>   tools/testing/selftests/clone3/clone3_set_tid.c               | 2 --
>   tools/testing/selftests/core/close_range_test.c               | 2 --
>   tools/testing/selftests/drivers/dma-buf/udmabuf.c             | 1 -
>   tools/testing/selftests/fchmodat2/fchmodat2_test.c            | 2 --
>   tools/testing/selftests/filesystems/binderfs/binderfs_test.c  | 2 --
>   tools/testing/selftests/filesystems/devpts_pts.c              | 1 -
>   tools/testing/selftests/filesystems/dnotify_test.c            | 1 -
>   tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c | 2 --
>   tools/testing/selftests/filesystems/eventfd/eventfd_test.c    | 2 --
>   tools/testing/selftests/filesystems/fat/rename_exchange.c     | 2 --
>   tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c   | 2 --
>   .../testing/selftests/filesystems/statmount/statmount_test.c  | 3 ---
>   tools/testing/selftests/futex/functional/futex_requeue_pi.c   | 3 ---
>   tools/testing/selftests/ipc/msgque.c                          | 1 -
>   tools/testing/selftests/kcmp/kcmp_test.c                      | 2 --
>   tools/testing/selftests/kvm/aarch64/arch_timer.c              | 2 --
>   tools/testing/selftests/kvm/aarch64/page_fault_test.c         | 1 -
>   tools/testing/selftests/kvm/aarch64/psci_test.c               | 3 ---
>   tools/testing/selftests/kvm/aarch64/vgic_init.c               | 1 -
>   tools/testing/selftests/kvm/arch_timer.c                      | 3 ---
>   tools/testing/selftests/kvm/demand_paging_test.c              | 3 ---
>   tools/testing/selftests/kvm/dirty_log_test.c                  | 3 ---
>   tools/testing/selftests/kvm/guest_memfd_test.c                | 2 --
>   tools/testing/selftests/kvm/hardware_disable_test.c           | 3 ---
>   tools/testing/selftests/kvm/include/userfaultfd_util.h        | 3 ---
>   tools/testing/selftests/kvm/kvm_binary_stats_test.c           | 2 --
>   tools/testing/selftests/kvm/kvm_create_max_vcpus.c            | 2 --
>   tools/testing/selftests/kvm/kvm_page_table_test.c             | 3 ---
>   tools/testing/selftests/kvm/lib/assert.c                      | 3 ---
>   tools/testing/selftests/kvm/lib/kvm_util.c                    | 2 --
>   tools/testing/selftests/kvm/lib/memstress.c                   | 2 --
>   tools/testing/selftests/kvm/lib/test_util.c                   | 2 --
>   tools/testing/selftests/kvm/lib/userfaultfd_util.c            | 3 ---
>   tools/testing/selftests/kvm/lib/x86_64/sev.c                  | 1 -
>   tools/testing/selftests/kvm/max_guest_memory_test.c           | 2 --
>   .../testing/selftests/kvm/memslot_modification_stress_test.c  | 3 ---
>   tools/testing/selftests/kvm/riscv/arch_timer.c                | 3 ---
>   tools/testing/selftests/kvm/rseq_test.c                       | 1 -
>   tools/testing/selftests/kvm/s390x/cmma_test.c                 | 2 --
>   tools/testing/selftests/kvm/s390x/sync_regs_test.c            | 2 --
>   tools/testing/selftests/kvm/set_memory_region_test.c          | 1 -
>   tools/testing/selftests/kvm/steal_time.c                      | 1 -
>   tools/testing/selftests/kvm/x86_64/amx_test.c                 | 2 --
>   .../selftests/kvm/x86_64/exit_on_emulation_failure_test.c     | 3 ---
>   tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c            | 2 --
>   tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c             | 2 --
>   tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c             | 1 -
>   tools/testing/selftests/kvm/x86_64/hyperv_ipi.c               | 2 --
>   tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c          | 1 -
>   tools/testing/selftests/kvm/x86_64/hyperv_tlb_flush.c         | 2 --
>   tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c   | 2 --
>   tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c       | 3 ---
>   tools/testing/selftests/kvm/x86_64/platform_info_test.c       | 2 --
>   tools/testing/selftests/kvm/x86_64/pmu_counters_test.c        | 2 --
>   tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c    | 3 ---
>   .../selftests/kvm/x86_64/private_mem_conversions_test.c       | 1 -
>   tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c          | 1 -
>   tools/testing/selftests/kvm/x86_64/set_sregs_test.c           | 1 -
>   .../selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c  | 3 ---
>   tools/testing/selftests/kvm/x86_64/smm_test.c                 | 1 -
>   tools/testing/selftests/kvm/x86_64/state_test.c               | 1 -
>   tools/testing/selftests/kvm/x86_64/sync_regs_test.c           | 2 --
>   tools/testing/selftests/kvm/x86_64/ucna_injection_test.c      | 2 --
>   tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c  | 2 --
>   tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c       | 3 ---
>   tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c        | 1 -
>   .../testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c  | 1 -
>   tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c           | 2 --
>   tools/testing/selftests/kvm/x86_64/xapic_state_test.c         | 1 -
>   tools/testing/selftests/kvm/x86_64/xss_msr_test.c             | 2 --
>   tools/testing/selftests/landlock/base_test.c                  | 2 --
>   tools/testing/selftests/landlock/fs_test.c                    | 2 --
>   tools/testing/selftests/landlock/net_test.c                   | 2 --
>   tools/testing/selftests/landlock/ptrace_test.c                | 2 --
>   tools/testing/selftests/lsm/common.c                          | 2 --
>   tools/testing/selftests/lsm/lsm_get_self_attr_test.c          | 2 --
>   tools/testing/selftests/lsm/lsm_list_modules_test.c           | 2 --
>   tools/testing/selftests/lsm/lsm_set_self_attr_test.c          | 2 --
>   tools/testing/selftests/membarrier/membarrier_test_impl.h     | 1 -
>   .../selftests/membarrier/membarrier_test_multi_thread.c       | 1 -
>   .../selftests/membarrier/membarrier_test_single_thread.c      | 1 -
>   tools/testing/selftests/memfd/common.c                        | 1 -
>   tools/testing/selftests/memfd/fuse_test.c                     | 2 --
>   tools/testing/selftests/memfd/memfd_test.c                    | 1 -
>   tools/testing/selftests/mm/cow.c                              | 1 -
>   tools/testing/selftests/mm/gup_longterm.c                     | 1 -
>   tools/testing/selftests/mm/hugepage-mmap.c                    | 1 -
>   tools/testing/selftests/mm/hugepage-mremap.c                  | 2 --
>   tools/testing/selftests/mm/hugetlb-madvise.c                  | 2 --
>   tools/testing/selftests/mm/hugetlb-read-hwpoison.c            | 2 --
>   tools/testing/selftests/mm/khugepaged.c                       | 1 -
>   tools/testing/selftests/mm/ksm_functional_tests.c             | 1 -
>   tools/testing/selftests/mm/madv_populate.c                    | 1 -
>   tools/testing/selftests/mm/map_populate.c                     | 2 --
>   tools/testing/selftests/mm/mdwe_test.c                        | 1 -
>   tools/testing/selftests/mm/memfd_secret.c                     | 2 --
>   tools/testing/selftests/mm/mlock2-tests.c                     | 1 -
>   tools/testing/selftests/mm/mrelease_test.c                    | 1 -
>   tools/testing/selftests/mm/mremap_dontunmap.c                 | 1 -
>   tools/testing/selftests/mm/mremap_test.c                      | 2 --
>   tools/testing/selftests/mm/pagemap_ioctl.c                    | 1 -
>   tools/testing/selftests/mm/pkey-helpers.h                     | 1 -
>   tools/testing/selftests/mm/protection_keys.c                  | 1 -
>   tools/testing/selftests/mm/split_huge_page_test.c             | 2 --
>   tools/testing/selftests/mm/thuge-gen.c                        | 2 --
>   tools/testing/selftests/mm/uffd-common.h                      | 1 -
>   tools/testing/selftests/mount_setattr/mount_setattr_test.c    | 1 -
>   .../move_mount_set_group/move_mount_set_group_test.c          | 1 -
>   tools/testing/selftests/net/af_unix/diag_uid.c                | 2 --
>   tools/testing/selftests/net/af_unix/scm_pidfd.c               | 1 -
>   tools/testing/selftests/net/af_unix/unix_connect.c            | 2 --
>   tools/testing/selftests/net/csum.c                            | 3 ---
>   tools/testing/selftests/net/gro.c                             | 3 ---
>   tools/testing/selftests/net/ip_defrag.c                       | 3 ---
>   tools/testing/selftests/net/ipsec.c                           | 3 ---
>   tools/testing/selftests/net/ipv6_flowlabel.c                  | 3 ---
>   tools/testing/selftests/net/ipv6_flowlabel_mgr.c              | 3 ---
>   tools/testing/selftests/net/mptcp/mptcp_connect.c             | 3 ---
>   tools/testing/selftests/net/mptcp/mptcp_inq.c                 | 3 ---
>   tools/testing/selftests/net/mptcp/mptcp_sockopt.c             | 3 ---
>   tools/testing/selftests/net/msg_zerocopy.c                    | 3 ---
>   tools/testing/selftests/net/nettest.c                         | 2 --
>   tools/testing/selftests/net/psock_fanout.c                    | 3 ---
>   tools/testing/selftests/net/psock_snd.c                       | 3 ---
>   tools/testing/selftests/net/reuseport_addr_any.c              | 3 ---
>   tools/testing/selftests/net/reuseport_bpf_cpu.c               | 3 ---
>   tools/testing/selftests/net/reuseport_bpf_numa.c              | 3 ---
>   tools/testing/selftests/net/reuseport_dualstack.c             | 3 ---
>   tools/testing/selftests/net/so_incoming_cpu.c                 | 1 -
>   tools/testing/selftests/net/so_netns_cookie.c                 | 1 -
>   tools/testing/selftests/net/so_txtime.c                       | 3 ---
>   tools/testing/selftests/net/tap.c                             | 3 ---
>   tools/testing/selftests/net/tcp_fastopen_backup_key.c         | 1 -
>   tools/testing/selftests/net/tcp_inq.c                         | 2 --
>   tools/testing/selftests/net/tcp_mmap.c                        | 1 -
>   tools/testing/selftests/net/tls.c                             | 3 ---
>   tools/testing/selftests/net/toeplitz.c                        | 3 ---
>   tools/testing/selftests/net/tun.c                             | 3 ---
>   tools/testing/selftests/net/txring_overwrite.c                | 3 ---
>   tools/testing/selftests/net/txtimestamp.c                     | 3 ---
>   tools/testing/selftests/net/udpgso.c                          | 3 ---
>   tools/testing/selftests/net/udpgso_bench_rx.c                 | 3 ---
>   tools/testing/selftests/net/udpgso_bench_tx.c                 | 3 ---
>   tools/testing/selftests/perf_events/remove_on_exec.c          | 2 --
>   tools/testing/selftests/perf_events/sigtrap_threads.c         | 2 --
>   tools/testing/selftests/pid_namespace/regression_enomem.c     | 1 -
>   tools/testing/selftests/pidfd/pidfd.h                         | 1 -
>   tools/testing/selftests/pidfd/pidfd_fdinfo_test.c             | 2 --
>   tools/testing/selftests/pidfd/pidfd_getfd_test.c              | 2 --
>   tools/testing/selftests/pidfd/pidfd_open_test.c               | 2 --
>   tools/testing/selftests/pidfd/pidfd_poll_test.c               | 2 --
>   tools/testing/selftests/pidfd/pidfd_setns_test.c              | 2 --
>   tools/testing/selftests/pidfd/pidfd_test.c                    | 2 --
>   tools/testing/selftests/pidfd/pidfd_wait.c                    | 2 --
>   tools/testing/selftests/ptrace/get_set_sud.c                  | 1 -
>   tools/testing/selftests/ptrace/peeksiginfo.c                  | 1 -
>   tools/testing/selftests/rseq/basic_percpu_ops_test.c          | 1 -
>   tools/testing/selftests/rseq/basic_test.c                     | 2 --
>   tools/testing/selftests/rseq/param_test.c                     | 1 -
>   tools/testing/selftests/rseq/rseq.c                           | 2 --
>   tools/testing/selftests/seccomp/seccomp_benchmark.c           | 1 -
>   tools/testing/selftests/seccomp/seccomp_bpf.c                 | 2 --
>   tools/testing/selftests/user_events/abi_test.c                | 2 --
>   tools/testing/selftests/x86/amx.c                             | 2 --
>   tools/testing/selftests/x86/check_initial_reg_state.c         | 3 ---
>   tools/testing/selftests/x86/corrupt_xstate_header.c           | 3 ---
>   tools/testing/selftests/x86/entry_from_vm86.c                 | 3 ---
>   tools/testing/selftests/x86/fsgsbase.c                        | 2 --
>   tools/testing/selftests/x86/fsgsbase_restore.c                | 2 --
>   tools/testing/selftests/x86/ioperm.c                          | 2 --
>   tools/testing/selftests/x86/iopl.c                            | 2 --
>   tools/testing/selftests/x86/lam.c                             | 1 -
>   tools/testing/selftests/x86/ldt_gdt.c                         | 2 --
>   tools/testing/selftests/x86/mov_ss_trap.c                     | 2 --
>   tools/testing/selftests/x86/nx_stack.c                        | 2 --
>   tools/testing/selftests/x86/ptrace_syscall.c                  | 2 --
>   tools/testing/selftests/x86/sigaltstack.c                     | 2 --
>   tools/testing/selftests/x86/sigreturn.c                       | 3 ---
>   tools/testing/selftests/x86/single_step_syscall.c             | 3 ---
>   tools/testing/selftests/x86/syscall_arg_fault.c               | 3 ---
>   tools/testing/selftests/x86/syscall_numbering.c               | 3 ---
>   tools/testing/selftests/x86/sysret_rip.c                      | 3 ---
>   tools/testing/selftests/x86/sysret_ss_attrs.c                 | 3 ---
>   tools/testing/selftests/x86/test_FCMOV.c                      | 4 ----
>   tools/testing/selftests/x86/test_FCOMI.c                      | 4 ----
>   tools/testing/selftests/x86/test_FISTTP.c                     | 4 ----
>   tools/testing/selftests/x86/test_mremap_vdso.c                | 1 -
>   tools/testing/selftests/x86/test_shadow_stack.c               | 3 ---
>   tools/testing/selftests/x86/test_syscall_vdso.c               | 4 ----
>   tools/testing/selftests/x86/test_vsyscall.c                   | 3 ---
>   tools/testing/selftests/x86/unwind_vdso.c                     | 3 ---
>   tools/testing/selftests/x86/vdso_restorer.c                   | 3 ---
>   198 files changed, 405 deletions(-)
> 
> diff --git a/tools/testing/selftests/cachestat/test_cachestat.c b/tools/testing/selftests/cachestat/test_cachestat.c
> index b171fd53b004..c1a6ce7b0912 100644
> --- a/tools/testing/selftests/cachestat/test_cachestat.c
> +++ b/tools/testing/selftests/cachestat/test_cachestat.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
> -
>   #include <stdio.h>
>   #include <stdbool.h>
>   #include <linux/kernel.h>
> diff --git a/tools/testing/selftests/capabilities/test_execve.c b/tools/testing/selftests/capabilities/test_execve.c
> index 7cde07a5df78..e3954b88c3ee 100644
> --- a/tools/testing/selftests/capabilities/test_execve.c
> +++ b/tools/testing/selftests/capabilities/test_execve.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
> -
>   #include <cap-ng.h>
>   #include <linux/capability.h>
>   #include <stdbool.h>
> diff --git a/tools/testing/selftests/clone3/clone3.c b/tools/testing/selftests/clone3/clone3.c
> index 3c9bf0cd82a8..3c5e45dae617 100644
> --- a/tools/testing/selftests/clone3/clone3.c
> +++ b/tools/testing/selftests/clone3/clone3.c
> @@ -1,8 +1,6 @@
>   // SPDX-License-Identifier: GPL-2.0
>   
>   /* Based on Christian Brauner's clone3() example */
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <inttypes.h>
>   #include <linux/types.h>
> diff --git a/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c b/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c
> index 31b56d625655..bb99ea20f7d5 100644
> --- a/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c
> +++ b/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c
> @@ -7,8 +7,6 @@
>    */
>   
>   /* capabilities related code based on selftests/bpf/test_verifier.c */
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <linux/types.h>
>   #include <linux/sched.h>
> diff --git a/tools/testing/selftests/clone3/clone3_clear_sighand.c b/tools/testing/selftests/clone3/clone3_clear_sighand.c
> index 54a8b2445be9..50336d56db6b 100644
> --- a/tools/testing/selftests/clone3/clone3_clear_sighand.c
> +++ b/tools/testing/selftests/clone3/clone3_clear_sighand.c
> @@ -1,6 +1,4 @@
>   /* SPDX-License-Identifier: GPL-2.0 */
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <sched.h>
>   #include <signal.h>
> diff --git a/tools/testing/selftests/clone3/clone3_selftests.h b/tools/testing/selftests/clone3/clone3_selftests.h
> index 3d2663fe50ba..172e19d5515f 100644
> --- a/tools/testing/selftests/clone3/clone3_selftests.h
> +++ b/tools/testing/selftests/clone3/clone3_selftests.h
> @@ -3,7 +3,6 @@
>   #ifndef _CLONE3_SELFTESTS_H
>   #define _CLONE3_SELFTESTS_H
>   
> -#define _GNU_SOURCE
>   #include <sched.h>
>   #include <linux/sched.h>
>   #include <linux/types.h>
> diff --git a/tools/testing/selftests/clone3/clone3_set_tid.c b/tools/testing/selftests/clone3/clone3_set_tid.c
> index ed785afb6077..8b5ed4484ee6 100644
> --- a/tools/testing/selftests/clone3/clone3_set_tid.c
> +++ b/tools/testing/selftests/clone3/clone3_set_tid.c
> @@ -5,8 +5,6 @@
>    * These tests are assuming to be running in the host's
>    * PID namespace.
>    */
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <linux/types.h>
>   #include <linux/sched.h>
> diff --git a/tools/testing/selftests/core/close_range_test.c b/tools/testing/selftests/core/close_range_test.c
> index c59e4adb905d..1c2902bcc913 100644
> --- a/tools/testing/selftests/core/close_range_test.c
> +++ b/tools/testing/selftests/core/close_range_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <linux/kernel.h>
> diff --git a/tools/testing/selftests/drivers/dma-buf/udmabuf.c b/tools/testing/selftests/drivers/dma-buf/udmabuf.c
> index c812080e304e..7c8dbab8ac44 100644
> --- a/tools/testing/selftests/drivers/dma-buf/udmabuf.c
> +++ b/tools/testing/selftests/drivers/dma-buf/udmabuf.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #define __EXPORTED_HEADERS__
>   
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/fchmodat2/fchmodat2_test.c b/tools/testing/selftests/fchmodat2/fchmodat2_test.c
> index e0319417124d..6b411859c2cd 100644
> --- a/tools/testing/selftests/fchmodat2/fchmodat2_test.c
> +++ b/tools/testing/selftests/fchmodat2/fchmodat2_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0-or-later
> -
> -#define _GNU_SOURCE
>   #include <fcntl.h>
>   #include <sys/stat.h>
>   #include <sys/types.h>
> diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
> index 5f362c0fd890..fca693db1b09 100644
> --- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
> +++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <pthread.h>
> diff --git a/tools/testing/selftests/filesystems/devpts_pts.c b/tools/testing/selftests/filesystems/devpts_pts.c
> index b1fc9b916ace..73766447eeb0 100644
> --- a/tools/testing/selftests/filesystems/devpts_pts.c
> +++ b/tools/testing/selftests/filesystems/devpts_pts.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <sched.h>
> diff --git a/tools/testing/selftests/filesystems/dnotify_test.c b/tools/testing/selftests/filesystems/dnotify_test.c
> index c0a9b2d3302d..05367a70b963 100644
> --- a/tools/testing/selftests/filesystems/dnotify_test.c
> +++ b/tools/testing/selftests/filesystems/dnotify_test.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE	/* needed to get the defines */
>   #include <fcntl.h>	/* in glibc 2.2 this has the needed
>   				   values defined */
>   #include <signal.h>
> diff --git a/tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c b/tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c
> index 65ede506305c..9bc2ddad7e92 100644
> --- a/tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c
> +++ b/tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <asm/unistd.h>
>   #include <linux/time_types.h>
>   #include <poll.h>
> diff --git a/tools/testing/selftests/filesystems/eventfd/eventfd_test.c b/tools/testing/selftests/filesystems/eventfd/eventfd_test.c
> index f142a137526c..17935f42fbc9 100644
> --- a/tools/testing/selftests/filesystems/eventfd/eventfd_test.c
> +++ b/tools/testing/selftests/filesystems/eventfd/eventfd_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <asm/unistd.h>
> diff --git a/tools/testing/selftests/filesystems/fat/rename_exchange.c b/tools/testing/selftests/filesystems/fat/rename_exchange.c
> index e488ad354fce..56cf3ad8640d 100644
> --- a/tools/testing/selftests/filesystems/fat/rename_exchange.c
> +++ b/tools/testing/selftests/filesystems/fat/rename_exchange.c
> @@ -6,8 +6,6 @@
>    * Copyright 2022 Red Hat Inc.
>    * Author: Javier Martinez Canillas <javierm@redhat.com>
>    */
> -
> -#define _GNU_SOURCE
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c b/tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c
> index 759f86e7d263..b58a80bde95a 100644
> --- a/tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c
> +++ b/tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
> -
>   #include <inttypes.h>
>   #include <unistd.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test.c b/tools/testing/selftests/filesystems/statmount/statmount_test.c
> index 3eafd7da58e2..d1cefd1b7d16 100644
> --- a/tools/testing/selftests/filesystems/statmount/statmount_test.c
> +++ b/tools/testing/selftests/filesystems/statmount/statmount_test.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0-or-later
> -
> -#define _GNU_SOURCE
> -
>   #include <assert.h>
>   #include <stdint.h>
>   #include <sched.h>
> diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi.c b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
> index 7f3ca5c78df1..8e41f9fe784c 100644
> --- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c
> +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
> @@ -16,9 +16,6 @@
>    *      2009-Nov-6: futex test adaptation by Darren Hart <dvhart@linux.intel.com>
>    *
>    *****************************************************************************/
> -
> -#define _GNU_SOURCE
> -
>   #include <errno.h>
>   #include <limits.h>
>   #include <pthread.h>
> diff --git a/tools/testing/selftests/ipc/msgque.c b/tools/testing/selftests/ipc/msgque.c
> index 656c43c24044..291c81d59a9d 100644
> --- a/tools/testing/selftests/ipc/msgque.c
> +++ b/tools/testing/selftests/ipc/msgque.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include <stdlib.h>
>   #include <stdio.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/kcmp/kcmp_test.c b/tools/testing/selftests/kcmp/kcmp_test.c
> index 25110c7c0b3e..885c9e943cee 100644
> --- a/tools/testing/selftests/kcmp/kcmp_test.c
> +++ b/tools/testing/selftests/kcmp/kcmp_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
> -
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <signal.h>
> diff --git a/tools/testing/selftests/kvm/aarch64/arch_timer.c b/tools/testing/selftests/kvm/aarch64/arch_timer.c
> index 4eaba83cdcf3..5369959e9fc2 100644
> --- a/tools/testing/selftests/kvm/aarch64/arch_timer.c
> +++ b/tools/testing/selftests/kvm/aarch64/arch_timer.c
> @@ -5,8 +5,6 @@
>    *
>    * Copyright (c) 2021, Google LLC.
>    */
> -#define _GNU_SOURCE
> -
>   #include "arch_timer.h"
>   #include "delay.h"
>   #include "gic.h"
> diff --git a/tools/testing/selftests/kvm/aarch64/page_fault_test.c b/tools/testing/selftests/kvm/aarch64/page_fault_test.c
> index 5972905275cf..79e99f47a9fe 100644
> --- a/tools/testing/selftests/kvm/aarch64/page_fault_test.c
> +++ b/tools/testing/selftests/kvm/aarch64/page_fault_test.c
> @@ -7,7 +7,6 @@
>    * hugetlbfs with a hole). It checks that the expected handling method is
>    * called (e.g., uffd faults with the right address and write/read flag).
>    */
> -#define _GNU_SOURCE
>   #include <linux/bitmap.h>
>   #include <fcntl.h>
>   #include <test_util.h>
> diff --git a/tools/testing/selftests/kvm/aarch64/psci_test.c b/tools/testing/selftests/kvm/aarch64/psci_test.c
> index 9b004905d1d3..1c8c6f0c1ca3 100644
> --- a/tools/testing/selftests/kvm/aarch64/psci_test.c
> +++ b/tools/testing/selftests/kvm/aarch64/psci_test.c
> @@ -10,9 +10,6 @@
>    *  - A test for KVM's handling of PSCI SYSTEM_SUSPEND and the associated
>    *    KVM_SYSTEM_EVENT_SUSPEND UAPI.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <linux/psci.h>
>   
>   #include "kvm_util.h"
> diff --git a/tools/testing/selftests/kvm/aarch64/vgic_init.c b/tools/testing/selftests/kvm/aarch64/vgic_init.c
> index ca917c71ff60..b3b5fb0ff0a9 100644
> --- a/tools/testing/selftests/kvm/aarch64/vgic_init.c
> +++ b/tools/testing/selftests/kvm/aarch64/vgic_init.c
> @@ -4,7 +4,6 @@
>    *
>    * Copyright (C) 2020, Red Hat, Inc.
>    */
> -#define _GNU_SOURCE
>   #include <linux/kernel.h>
>   #include <sys/syscall.h>
>   #include <asm/kvm.h>
> diff --git a/tools/testing/selftests/kvm/arch_timer.c b/tools/testing/selftests/kvm/arch_timer.c
> index ae1f1a6d8312..fcebd8d81ce4 100644
> --- a/tools/testing/selftests/kvm/arch_timer.c
> +++ b/tools/testing/selftests/kvm/arch_timer.c
> @@ -19,9 +19,6 @@
>    *
>    * Copyright (c) 2021, Google LLC.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <stdlib.h>
>   #include <pthread.h>
>   #include <linux/sizes.h>
> diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
> index bf3609f71854..0c4d3b6afbf8 100644
> --- a/tools/testing/selftests/kvm/demand_paging_test.c
> +++ b/tools/testing/selftests/kvm/demand_paging_test.c
> @@ -6,9 +6,6 @@
>    * Copyright (C) 2018, Red Hat, Inc.
>    * Copyright (C) 2019, Google, Inc.
>    */
> -
> -#define _GNU_SOURCE /* for pipe2 */
> -
>   #include <inttypes.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
> index eaad5b20854c..bf1ebc29f22a 100644
> --- a/tools/testing/selftests/kvm/dirty_log_test.c
> +++ b/tools/testing/selftests/kvm/dirty_log_test.c
> @@ -4,9 +4,6 @@
>    *
>    * Copyright (C) 2018, Red Hat, Inc.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_name */
> -
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <pthread.h>
> diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c
> index 92eae206baa6..309fe84b84ad 100644
> --- a/tools/testing/selftests/kvm/guest_memfd_test.c
> +++ b/tools/testing/selftests/kvm/guest_memfd_test.c
> @@ -4,8 +4,6 @@
>    *
>    * Author: Chao Peng <chao.p.peng@linux.intel.com>
>    */
> -
> -#define _GNU_SOURCE
>   #include <stdlib.h>
>   #include <string.h>
>   #include <unistd.h>
> diff --git a/tools/testing/selftests/kvm/hardware_disable_test.c b/tools/testing/selftests/kvm/hardware_disable_test.c
> index decc521fc760..bce73bcb973c 100644
> --- a/tools/testing/selftests/kvm/hardware_disable_test.c
> +++ b/tools/testing/selftests/kvm/hardware_disable_test.c
> @@ -4,9 +4,6 @@
>    * kvm_arch_hardware_disable is called and it attempts to unregister the user
>    * return notifiers.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <fcntl.h>
>   #include <pthread.h>
>   #include <semaphore.h>
> diff --git a/tools/testing/selftests/kvm/include/userfaultfd_util.h b/tools/testing/selftests/kvm/include/userfaultfd_util.h
> index 877449c34592..a9d97c213584 100644
> --- a/tools/testing/selftests/kvm/include/userfaultfd_util.h
> +++ b/tools/testing/selftests/kvm/include/userfaultfd_util.h
> @@ -5,9 +5,6 @@
>    * Copyright (C) 2018, Red Hat, Inc.
>    * Copyright (C) 2019-2022 Google LLC
>    */
> -
> -#define _GNU_SOURCE /* for pipe2 */
> -
>   #include <inttypes.h>
>   #include <time.h>
>   #include <pthread.h>
> diff --git a/tools/testing/selftests/kvm/kvm_binary_stats_test.c b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
> index 698c1cfa3111..f02355c3c4c2 100644
> --- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c
> +++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
> @@ -6,8 +6,6 @@
>    *
>    * Test the fd-based interface for KVM statistics.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/kvm_create_max_vcpus.c b/tools/testing/selftests/kvm/kvm_create_max_vcpus.c
> index b9e23265e4b3..c78f34699f73 100644
> --- a/tools/testing/selftests/kvm/kvm_create_max_vcpus.c
> +++ b/tools/testing/selftests/kvm/kvm_create_max_vcpus.c
> @@ -6,8 +6,6 @@
>    *
>    * Test for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_VCPU_ID.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/testing/selftests/kvm/kvm_page_table_test.c
> index e0ba97ac1c56..7759c685086b 100644
> --- a/tools/testing/selftests/kvm/kvm_page_table_test.c
> +++ b/tools/testing/selftests/kvm/kvm_page_table_test.c
> @@ -8,9 +8,6 @@
>    * page size have been pre-allocated on your system, if you are planning to
>    * use hugepages to back the guest memory for testing.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_name */
> -
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <time.h>
> diff --git a/tools/testing/selftests/kvm/lib/assert.c b/tools/testing/selftests/kvm/lib/assert.c
> index 2bd25b191d15..b49690658c60 100644
> --- a/tools/testing/selftests/kvm/lib/assert.c
> +++ b/tools/testing/selftests/kvm/lib/assert.c
> @@ -4,9 +4,6 @@
>    *
>    * Copyright (C) 2018, Google LLC.
>    */
> -
> -#define _GNU_SOURCE /* for getline(3) and strchrnul(3)*/
> -
>   #include "test_util.h"
>   
>   #include <execinfo.h>
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index b2262b5fad9e..1eaf001d0ad4 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -4,8 +4,6 @@
>    *
>    * Copyright (C) 2018, Google LLC.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_name */
>   #include "test_util.h"
>   #include "kvm_util.h"
>   #include "processor.h"
> diff --git a/tools/testing/selftests/kvm/lib/memstress.c b/tools/testing/selftests/kvm/lib/memstress.c
> index cf2c73971308..555e3932e529 100644
> --- a/tools/testing/selftests/kvm/lib/memstress.c
> +++ b/tools/testing/selftests/kvm/lib/memstress.c
> @@ -2,8 +2,6 @@
>   /*
>    * Copyright (C) 2020, Google LLC.
>    */
> -#define _GNU_SOURCE
> -
>   #include <inttypes.h>
>   #include <linux/bitmap.h>
>   
> diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
> index 5a8f8becb129..8ed0b74ae837 100644
> --- a/tools/testing/selftests/kvm/lib/test_util.c
> +++ b/tools/testing/selftests/kvm/lib/test_util.c
> @@ -4,8 +4,6 @@
>    *
>    * Copyright (C) 2020, Google LLC.
>    */
> -
> -#define _GNU_SOURCE
>   #include <stdio.h>
>   #include <stdarg.h>
>   #include <assert.h>
> diff --git a/tools/testing/selftests/kvm/lib/userfaultfd_util.c b/tools/testing/selftests/kvm/lib/userfaultfd_util.c
> index f4eef6eb2dc2..bd07568a5240 100644
> --- a/tools/testing/selftests/kvm/lib/userfaultfd_util.c
> +++ b/tools/testing/selftests/kvm/lib/userfaultfd_util.c
> @@ -6,9 +6,6 @@
>    * Copyright (C) 2018, Red Hat, Inc.
>    * Copyright (C) 2019-2022 Google LLC
>    */
> -
> -#define _GNU_SOURCE /* for pipe2 */
> -
>   #include <inttypes.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/lib/x86_64/sev.c b/tools/testing/selftests/kvm/lib/x86_64/sev.c
> index e248d3364b9c..e83809febae1 100644
> --- a/tools/testing/selftests/kvm/lib/x86_64/sev.c
> +++ b/tools/testing/selftests/kvm/lib/x86_64/sev.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0-only
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <stdint.h>
>   #include <stdbool.h>
>   
> diff --git a/tools/testing/selftests/kvm/max_guest_memory_test.c b/tools/testing/selftests/kvm/max_guest_memory_test.c
> index 1a6da7389bf1..0b9678858b6d 100644
> --- a/tools/testing/selftests/kvm/max_guest_memory_test.c
> +++ b/tools/testing/selftests/kvm/max_guest_memory_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
> -
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <pthread.h>
> diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> index 156361966612..05fcf902e067 100644
> --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> @@ -6,9 +6,6 @@
>    * Copyright (C) 2018, Red Hat, Inc.
>    * Copyright (C) 2020, Google, Inc.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_name */
> -
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <sys/syscall.h>
> diff --git a/tools/testing/selftests/kvm/riscv/arch_timer.c b/tools/testing/selftests/kvm/riscv/arch_timer.c
> index 0f9cabd99fd4..4b5004ef9c6b 100644
> --- a/tools/testing/selftests/kvm/riscv/arch_timer.c
> +++ b/tools/testing/selftests/kvm/riscv/arch_timer.c
> @@ -7,9 +7,6 @@
>    *
>    * Copyright (c) 2024, Intel Corporation.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include "arch_timer.h"
>   #include "kvm_util.h"
>   #include "processor.h"
> diff --git a/tools/testing/selftests/kvm/rseq_test.c b/tools/testing/selftests/kvm/rseq_test.c
> index 28f97fb52044..b3536400f9ac 100644
> --- a/tools/testing/selftests/kvm/rseq_test.c
> +++ b/tools/testing/selftests/kvm/rseq_test.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0-only
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <pthread.h>
> diff --git a/tools/testing/selftests/kvm/s390x/cmma_test.c b/tools/testing/selftests/kvm/s390x/cmma_test.c
> index 626a2b8a2037..84ba79c42ab1 100644
> --- a/tools/testing/selftests/kvm/s390x/cmma_test.c
> +++ b/tools/testing/selftests/kvm/s390x/cmma_test.c
> @@ -7,8 +7,6 @@
>    * Authors:
>    *  Nico Boehr <nrb@linux.ibm.com>
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/s390x/sync_regs_test.c b/tools/testing/selftests/kvm/s390x/sync_regs_test.c
> index 43fb25ddc3ec..53def355ccba 100644
> --- a/tools/testing/selftests/kvm/s390x/sync_regs_test.c
> +++ b/tools/testing/selftests/kvm/s390x/sync_regs_test.c
> @@ -10,8 +10,6 @@
>    *
>    * Test expected behavior of the KVM_CAP_SYNC_REGS functionality.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c
> index bd57d991e27d..214ff84f6fdb 100644
> --- a/tools/testing/selftests/kvm/set_memory_region_test.c
> +++ b/tools/testing/selftests/kvm/set_memory_region_test.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <pthread.h>
>   #include <sched.h>
> diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
> index bae0c5026f82..e9231387c589 100644
> --- a/tools/testing/selftests/kvm/steal_time.c
> +++ b/tools/testing/selftests/kvm/steal_time.c
> @@ -4,7 +4,6 @@
>    *
>    * Copyright (C) 2020, Red Hat, Inc.
>    */
> -#define _GNU_SOURCE
>   #include <stdio.h>
>   #include <time.h>
>   #include <sched.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c
> index eae521f050e0..8e5713e36d4b 100644
> --- a/tools/testing/selftests/kvm/x86_64/amx_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c
> @@ -6,8 +6,6 @@
>    *
>    * Tests for amx #NM exception and save/restore.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/exit_on_emulation_failure_test.c b/tools/testing/selftests/kvm/x86_64/exit_on_emulation_failure_test.c
> index 6c2e5e0ceb1f..9c21b6bccc38 100644
> --- a/tools/testing/selftests/kvm/x86_64/exit_on_emulation_failure_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/exit_on_emulation_failure_test.c
> @@ -4,9 +4,6 @@
>    *
>    * Test for KVM_CAP_EXIT_ON_EMULATION_FAILURE.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
> -
>   #include "flds_emulation.h"
>   
>   #include "test_util.h"
> diff --git a/tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c b/tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c
> index df351ae17029..10b1b0ba374e 100644
> --- a/tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c
> @@ -2,8 +2,6 @@
>   /*
>    * Copyright (C) 2023, Google LLC.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <sys/ioctl.h>
>   
>   #include "test_util.h"
> diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c b/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c
> index 5c27efbf405e..4f5881d4ef66 100644
> --- a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c
> +++ b/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c
> @@ -7,8 +7,6 @@
>    * This work is licensed under the terms of the GNU GPL, version 2.
>    *
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c b/tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c
> index 4c7257ecd2a6..4f3f3a9b038b 100644
> --- a/tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c
> +++ b/tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c
> @@ -4,7 +4,6 @@
>    *
>    * Tests for Enlightened VMCS, including nested guest state.
>    */
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_ipi.c b/tools/testing/selftests/kvm/x86_64/hyperv_ipi.c
> index f1617762c22f..8206f5ef42dd 100644
> --- a/tools/testing/selftests/kvm/x86_64/hyperv_ipi.c
> +++ b/tools/testing/selftests/kvm/x86_64/hyperv_ipi.c
> @@ -5,8 +5,6 @@
>    * Copyright (C) 2022, Red Hat, Inc.
>    *
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <pthread.h>
>   #include <inttypes.h>
>   
> diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c b/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c
> index c9b18707edc0..b987a3d79715 100644
> --- a/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c
> @@ -4,7 +4,6 @@
>    *
>    * Tests for Hyper-V extensions to SVM.
>    */
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_tlb_flush.c b/tools/testing/selftests/kvm/x86_64/hyperv_tlb_flush.c
> index 05b56095cf76..077cd0ec3040 100644
> --- a/tools/testing/selftests/kvm/x86_64/hyperv_tlb_flush.c
> +++ b/tools/testing/selftests/kvm/x86_64/hyperv_tlb_flush.c
> @@ -5,8 +5,6 @@
>    * Copyright (C) 2022, Red Hat, Inc.
>    *
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <asm/barrier.h>
>   #include <pthread.h>
>   #include <inttypes.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c b/tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c
> index 3670331adf21..3eb0313ffa39 100644
> --- a/tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0-only
> -#define _GNU_SOURCE /* for program_invocation_short_name */
> -
>   #include "test_util.h"
>   #include "kvm_util.h"
>   #include "processor.h"
> diff --git a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c
> index 17bbb96fc4df..e7efb2b35f8b 100644
> --- a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c
> @@ -5,9 +5,6 @@
>    *
>    * Copyright (C) 2022, Google LLC.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <fcntl.h>
>   #include <stdint.h>
>   #include <time.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/platform_info_test.c b/tools/testing/selftests/kvm/x86_64/platform_info_test.c
> index 87011965dc41..2165b1ad8b38 100644
> --- a/tools/testing/selftests/kvm/x86_64/platform_info_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/platform_info_test.c
> @@ -9,8 +9,6 @@
>    * Verifies expected behavior of controlling guest access to
>    * MSR_PLATFORM_INFO.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c
> index 26c85815f7e9..77f14138594e 100644
> --- a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c
> @@ -2,8 +2,6 @@
>   /*
>    * Copyright (C) 2023, Tencent, Inc.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <x86intrin.h>
>   
>   #include "pmu.h"
> diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c
> index 3c85d1ae9893..5ce53b8c46e0 100644
> --- a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c
> @@ -9,9 +9,6 @@
>    * Verifies the expected behavior of allow lists and deny lists for
>    * virtual PMU events.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
> -
>   #include "kvm_util.h"
>   #include "pmu.h"
>   #include "processor.h"
> diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
> index e0f642d2a3c4..82a8d88b5338 100644
> --- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
> @@ -2,7 +2,6 @@
>   /*
>    * Copyright (C) 2022, Google LLC.
>    */
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <limits.h>
>   #include <pthread.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c b/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c
> index 366cf18600bc..d691d86e5bc3 100644
> --- a/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c
> +++ b/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c
> @@ -4,7 +4,6 @@
>    *
>    * Copyright (C) 2020, Red Hat, Inc.
>    */
> -#define _GNU_SOURCE /* for program_invocation_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/set_sregs_test.c b/tools/testing/selftests/kvm/x86_64/set_sregs_test.c
> index 3610981d9162..c021c0795a96 100644
> --- a/tools/testing/selftests/kvm/x86_64/set_sregs_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/set_sregs_test.c
> @@ -10,7 +10,6 @@
>    * That bug allowed a user-mode program that called the KVM_SET_SREGS
>    * ioctl to put a VCPU's local APIC into an invalid state.
>    */
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c b/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c
> index 416207c38a17..362be40fc00d 100644
> --- a/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c
> @@ -5,9 +5,6 @@
>    * Test that KVM emulates instructions in response to EPT violations when
>    * allow_smaller_maxphyaddr is enabled and guest.MAXPHYADDR < host.MAXPHYADDR.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
> -
>   #include "flds_emulation.h"
>   
>   #include "test_util.h"
> diff --git a/tools/testing/selftests/kvm/x86_64/smm_test.c b/tools/testing/selftests/kvm/x86_64/smm_test.c
> index e18b86666e1f..55c88d664a94 100644
> --- a/tools/testing/selftests/kvm/x86_64/smm_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/smm_test.c
> @@ -4,7 +4,6 @@
>    *
>    * Tests for SMM.
>    */
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/state_test.c b/tools/testing/selftests/kvm/x86_64/state_test.c
> index 88b58aab7207..1c756db329e5 100644
> --- a/tools/testing/selftests/kvm/x86_64/state_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/state_test.c
> @@ -6,7 +6,6 @@
>    *
>    * Tests for vCPU state save/restore, including nested guest state.
>    */
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c
> index adb5593daf48..8fa3948b0170 100644
> --- a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c
> @@ -8,8 +8,6 @@
>    * including requesting an invalid register set, updates to/from values
>    * in kvm_run.s.regs when kvm_valid_regs and kvm_dirty_regs are toggled.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/ucna_injection_test.c b/tools/testing/selftests/kvm/x86_64/ucna_injection_test.c
> index dcbb3c29fb8e..abe71946941f 100644
> --- a/tools/testing/selftests/kvm/x86_64/ucna_injection_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/ucna_injection_test.c
> @@ -17,8 +17,6 @@
>    * delivered into the guest or not.
>    *
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <pthread.h>
>   #include <inttypes.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c b/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c
> index f4f61a2d2464..53afbea4df88 100644
> --- a/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c
> @@ -4,8 +4,6 @@
>    *
>    * Tests for exiting into userspace on registered MSRs
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <sys/ioctl.h>
>   
>   #include "kvm_test_harness.h"
> diff --git a/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c b/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c
> index 977948fd52e6..fa512d033205 100644
> --- a/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c
> @@ -4,9 +4,6 @@
>    *
>    * Copyright (C) 2018, Red Hat, Inc.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_name */
> -
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <linux/bitmap.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
> index ea0cb3cae0f7..3b93f262b797 100644
> --- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
> @@ -10,7 +10,6 @@
>    * and check it can be retrieved with KVM_GET_MSR, also test
>    * the invalid LBR formats are rejected.
>    */
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <sys/ioctl.h>
>   
>   #include <linux/bitmap.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c b/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c
> index affc32800158..00dd2ac07a61 100644
> --- a/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c
> @@ -9,7 +9,6 @@
>    * value instead of partially decayed timer value
>    *
>    */
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c b/tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c
> index 725c206ba0b9..c78e5f755116 100644
> --- a/tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c
> @@ -19,8 +19,6 @@
>    * Migration is a command line option. When used on non-numa machines will
>    * exit with error. Test is still usefull on non-numa for testing IPIs.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <getopt.h>
>   #include <pthread.h>
>   #include <inttypes.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/xapic_state_test.c b/tools/testing/selftests/kvm/x86_64/xapic_state_test.c
> index ab75b873a4ad..69849acd95b0 100644
> --- a/tools/testing/selftests/kvm/x86_64/xapic_state_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/xapic_state_test.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0-only
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/kvm/x86_64/xss_msr_test.c b/tools/testing/selftests/kvm/x86_64/xss_msr_test.c
> index 167c97abff1b..f331a4e9bae3 100644
> --- a/tools/testing/selftests/kvm/x86_64/xss_msr_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/xss_msr_test.c
> @@ -4,8 +4,6 @@
>    *
>    * Tests for the IA32_XSS MSR.
>    */
> -
> -#define _GNU_SOURCE /* for program_invocation_short_name */
>   #include <sys/ioctl.h>
>   
>   #include "test_util.h"
> diff --git a/tools/testing/selftests/landlock/base_test.c b/tools/testing/selftests/landlock/base_test.c
> index a6f89aaea77d..bdb3955a9452 100644
> --- a/tools/testing/selftests/landlock/base_test.c
> +++ b/tools/testing/selftests/landlock/base_test.c
> @@ -5,8 +5,6 @@
>    * Copyright © 2017-2020 Mickaël Salaün <mic@digikod.net>
>    * Copyright © 2019-2020 ANSSI
>    */
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <linux/landlock.h>
> diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
> index 9a6036fbf289..acec1c82c8b4 100644
> --- a/tools/testing/selftests/landlock/fs_test.c
> +++ b/tools/testing/selftests/landlock/fs_test.c
> @@ -6,8 +6,6 @@
>    * Copyright © 2020 ANSSI
>    * Copyright © 2020-2022 Microsoft Corporation
>    */
> -
> -#define _GNU_SOURCE
>   #include <fcntl.h>
>   #include <linux/landlock.h>
>   #include <linux/magic.h>
> diff --git a/tools/testing/selftests/landlock/net_test.c b/tools/testing/selftests/landlock/net_test.c
> index f21cfbbc3638..eed040adcbac 100644
> --- a/tools/testing/selftests/landlock/net_test.c
> +++ b/tools/testing/selftests/landlock/net_test.c
> @@ -5,8 +5,6 @@
>    * Copyright © 2022-2023 Huawei Tech. Co., Ltd.
>    * Copyright © 2023 Microsoft Corporation
>    */
> -
> -#define _GNU_SOURCE
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <fcntl.h>
> diff --git a/tools/testing/selftests/landlock/ptrace_test.c b/tools/testing/selftests/landlock/ptrace_test.c
> index a19db4d0b3bd..c831e6d03b02 100644
> --- a/tools/testing/selftests/landlock/ptrace_test.c
> +++ b/tools/testing/selftests/landlock/ptrace_test.c
> @@ -5,8 +5,6 @@
>    * Copyright © 2017-2020 Mickaël Salaün <mic@digikod.net>
>    * Copyright © 2019-2020 ANSSI
>    */
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <linux/landlock.h>
> diff --git a/tools/testing/selftests/lsm/common.c b/tools/testing/selftests/lsm/common.c
> index 9ad258912646..1b18aac570f1 100644
> --- a/tools/testing/selftests/lsm/common.c
> +++ b/tools/testing/selftests/lsm/common.c
> @@ -4,8 +4,6 @@
>    *
>    * Copyright © 2023 Casey Schaufler <casey@schaufler-ca.com>
>    */
> -
> -#define _GNU_SOURCE
>   #include <linux/lsm.h>
>   #include <fcntl.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/lsm/lsm_get_self_attr_test.c b/tools/testing/selftests/lsm/lsm_get_self_attr_test.c
> index df215e4aa63f..7465bde3f922 100644
> --- a/tools/testing/selftests/lsm/lsm_get_self_attr_test.c
> +++ b/tools/testing/selftests/lsm/lsm_get_self_attr_test.c
> @@ -5,8 +5,6 @@
>    *
>    * Copyright © 2022 Casey Schaufler <casey@schaufler-ca.com>
>    */
> -
> -#define _GNU_SOURCE
>   #include <linux/lsm.h>
>   #include <fcntl.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/lsm/lsm_list_modules_test.c b/tools/testing/selftests/lsm/lsm_list_modules_test.c
> index 06d24d4679a6..a6b44e25c21f 100644
> --- a/tools/testing/selftests/lsm/lsm_list_modules_test.c
> +++ b/tools/testing/selftests/lsm/lsm_list_modules_test.c
> @@ -5,8 +5,6 @@
>    *
>    * Copyright © 2022 Casey Schaufler <casey@schaufler-ca.com>
>    */
> -
> -#define _GNU_SOURCE
>   #include <linux/lsm.h>
>   #include <string.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/lsm/lsm_set_self_attr_test.c b/tools/testing/selftests/lsm/lsm_set_self_attr_test.c
> index 66dec47e3ca3..110c6a07e74c 100644
> --- a/tools/testing/selftests/lsm/lsm_set_self_attr_test.c
> +++ b/tools/testing/selftests/lsm/lsm_set_self_attr_test.c
> @@ -5,8 +5,6 @@
>    *
>    * Copyright © 2022 Casey Schaufler <casey@schaufler-ca.com>
>    */
> -
> -#define _GNU_SOURCE
>   #include <linux/lsm.h>
>   #include <string.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/membarrier/membarrier_test_impl.h b/tools/testing/selftests/membarrier/membarrier_test_impl.h
> index af89855adb7b..a8a60b6271a5 100644
> --- a/tools/testing/selftests/membarrier/membarrier_test_impl.h
> +++ b/tools/testing/selftests/membarrier/membarrier_test_impl.h
> @@ -1,5 +1,4 @@
>   /* SPDX-License-Identifier: GPL-2.0 */
> -#define _GNU_SOURCE
>   #include <linux/membarrier.h>
>   #include <syscall.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/membarrier/membarrier_test_multi_thread.c b/tools/testing/selftests/membarrier/membarrier_test_multi_thread.c
> index a9cc17facfb3..b4651e2ade00 100644
> --- a/tools/testing/selftests/membarrier/membarrier_test_multi_thread.c
> +++ b/tools/testing/selftests/membarrier/membarrier_test_multi_thread.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include <linux/membarrier.h>
>   #include <syscall.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/membarrier/membarrier_test_single_thread.c b/tools/testing/selftests/membarrier/membarrier_test_single_thread.c
> index 4cdc8b1d124c..17ae5199b916 100644
> --- a/tools/testing/selftests/membarrier/membarrier_test_single_thread.c
> +++ b/tools/testing/selftests/membarrier/membarrier_test_single_thread.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include <linux/membarrier.h>
>   #include <syscall.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/memfd/common.c b/tools/testing/selftests/memfd/common.c
> index 8eb3d75f6e60..879d4f4c66fa 100644
> --- a/tools/testing/selftests/memfd/common.c
> +++ b/tools/testing/selftests/memfd/common.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #define __EXPORTED_HEADERS__
>   
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/memfd/fuse_test.c b/tools/testing/selftests/memfd/fuse_test.c
> index 93798c8c5d54..15bc189bf831 100644
> --- a/tools/testing/selftests/memfd/fuse_test.c
> +++ b/tools/testing/selftests/memfd/fuse_test.c
> @@ -12,8 +12,6 @@
>    * the read() syscall with our memory-mapped memfd object as receive buffer to
>    * force the kernel to write into our memfd object.
>    */
> -
> -#define _GNU_SOURCE
>   #define __EXPORTED_HEADERS__
>   
>   #include <errno.h>
> diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
> index 18f585684e20..5172c27a8748 100644
> --- a/tools/testing/selftests/memfd/memfd_test.c
> +++ b/tools/testing/selftests/memfd/memfd_test.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #define __EXPORTED_HEADERS__
>   
>   #include <errno.h>
> diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c
> index 363bf5f801be..6f1a36d51f19 100644
> --- a/tools/testing/selftests/mm/cow.c
> +++ b/tools/testing/selftests/mm/cow.c
> @@ -6,7 +6,6 @@
>    *
>    * Author(s): David Hildenbrand <david@redhat.com>
>    */
> -#define _GNU_SOURCE
>   #include <stdlib.h>
>   #include <string.h>
>   #include <stdbool.h>
> diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/selftests/mm/gup_longterm.c
> index ad168d35b23b..3bfd5a630081 100644
> --- a/tools/testing/selftests/mm/gup_longterm.c
> +++ b/tools/testing/selftests/mm/gup_longterm.c
> @@ -6,7 +6,6 @@
>    *
>    * Author(s): David Hildenbrand <david@redhat.com>
>    */
> -#define _GNU_SOURCE
>   #include <stdlib.h>
>   #include <string.h>
>   #include <stdbool.h>
> diff --git a/tools/testing/selftests/mm/hugepage-mmap.c b/tools/testing/selftests/mm/hugepage-mmap.c
> index 267eea2e0e0b..edb46888222f 100644
> --- a/tools/testing/selftests/mm/hugepage-mmap.c
> +++ b/tools/testing/selftests/mm/hugepage-mmap.c
> @@ -16,7 +16,6 @@
>    * range.
>    * Other architectures, such as ppc64, i386 or x86_64 are not so constrained.
>    */
> -#define _GNU_SOURCE
>   #include <stdlib.h>
>   #include <stdio.h>
>   #include <unistd.h>
> diff --git a/tools/testing/selftests/mm/hugepage-mremap.c b/tools/testing/selftests/mm/hugepage-mremap.c
> index c463d1c09c9b..8e22822bb754 100644
> --- a/tools/testing/selftests/mm/hugepage-mremap.c
> +++ b/tools/testing/selftests/mm/hugepage-mremap.c
> @@ -11,8 +11,6 @@
>    * To make sure the test triggers pmd sharing and goes through the 'unshare'
>    * path in the mremap code use 1GB (1024) or more.
>    */
> -
> -#define _GNU_SOURCE
>   #include <stdlib.h>
>   #include <stdio.h>
>   #include <unistd.h>
> diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c
> index e74107185324..70c40c67bc5d 100644
> --- a/tools/testing/selftests/mm/hugetlb-madvise.c
> +++ b/tools/testing/selftests/mm/hugetlb-madvise.c
> @@ -11,8 +11,6 @@
>    * filesystem.  Therefore, a hugetlbfs filesystem must be mounted on some
>    * directory.
>    */
> -
> -#define _GNU_SOURCE
>   #include <stdlib.h>
>   #include <stdio.h>
>   #include <unistd.h>
> diff --git a/tools/testing/selftests/mm/hugetlb-read-hwpoison.c b/tools/testing/selftests/mm/hugetlb-read-hwpoison.c
> index ba6cc6f9cabc..6b8b41b4f754 100644
> --- a/tools/testing/selftests/mm/hugetlb-read-hwpoison.c
> +++ b/tools/testing/selftests/mm/hugetlb-read-hwpoison.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <stdlib.h>
>   #include <stdio.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
> index 829320a519e7..d18bf400dae6 100644
> --- a/tools/testing/selftests/mm/khugepaged.c
> +++ b/tools/testing/selftests/mm/khugepaged.c
> @@ -1,4 +1,3 @@
> -#define _GNU_SOURCE
>   #include <ctype.h>
>   #include <errno.h>
>   #include <fcntl.h>
> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
> index d615767e396b..1deae905c42e 100644
> --- a/tools/testing/selftests/mm/ksm_functional_tests.c
> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
> @@ -6,7 +6,6 @@
>    *
>    * Author(s): David Hildenbrand <david@redhat.com>
>    */
> -#define _GNU_SOURCE
>   #include <stdlib.h>
>   #include <string.h>
>   #include <stdbool.h>
> diff --git a/tools/testing/selftests/mm/madv_populate.c b/tools/testing/selftests/mm/madv_populate.c
> index 17bcb07f19f3..d19ad13ffd7e 100644
> --- a/tools/testing/selftests/mm/madv_populate.c
> +++ b/tools/testing/selftests/mm/madv_populate.c
> @@ -6,7 +6,6 @@
>    *
>    * Author(s): David Hildenbrand <david@redhat.com>
>    */
> -#define _GNU_SOURCE
>   #include <stdlib.h>
>   #include <string.h>
>   #include <stdbool.h>
> diff --git a/tools/testing/selftests/mm/map_populate.c b/tools/testing/selftests/mm/map_populate.c
> index 5c8a53869b1b..ff4d4079bd0e 100644
> --- a/tools/testing/selftests/mm/map_populate.c
> +++ b/tools/testing/selftests/mm/map_populate.c
> @@ -4,8 +4,6 @@
>    *
>    * MAP_POPULATE | MAP_PRIVATE should COW VMA pages.
>    */
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <sys/mman.h>
> diff --git a/tools/testing/selftests/mm/mdwe_test.c b/tools/testing/selftests/mm/mdwe_test.c
> index 1e01d3ddc11c..200bedcdc32e 100644
> --- a/tools/testing/selftests/mm/mdwe_test.c
> +++ b/tools/testing/selftests/mm/mdwe_test.c
> @@ -7,7 +7,6 @@
>   #include <linux/mman.h>
>   #include <linux/prctl.h>
>   
> -#define _GNU_SOURCE
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <sys/auxv.h>
> diff --git a/tools/testing/selftests/mm/memfd_secret.c b/tools/testing/selftests/mm/memfd_secret.c
> index 9b298f6a04b3..750adede2816 100644
> --- a/tools/testing/selftests/mm/memfd_secret.c
> +++ b/tools/testing/selftests/mm/memfd_secret.c
> @@ -4,8 +4,6 @@
>    *
>    * Author: Mike Rapoport <rppt@linux.ibm.com>
>    */
> -
> -#define _GNU_SOURCE
>   #include <sys/uio.h>
>   #include <sys/mman.h>
>   #include <sys/wait.h>
> diff --git a/tools/testing/selftests/mm/mlock2-tests.c b/tools/testing/selftests/mm/mlock2-tests.c
> index 26f744188ad0..42574290d728 100644
> --- a/tools/testing/selftests/mm/mlock2-tests.c
> +++ b/tools/testing/selftests/mm/mlock2-tests.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include <sys/mman.h>
>   #include <stdint.h>
>   #include <unistd.h>
> diff --git a/tools/testing/selftests/mm/mrelease_test.c b/tools/testing/selftests/mm/mrelease_test.c
> index 100370a7111d..d78bf686e99f 100644
> --- a/tools/testing/selftests/mm/mrelease_test.c
> +++ b/tools/testing/selftests/mm/mrelease_test.c
> @@ -2,7 +2,6 @@
>   /*
>    * Copyright 2022 Google LLC
>    */
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <stdbool.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/mm/mremap_dontunmap.c b/tools/testing/selftests/mm/mremap_dontunmap.c
> index 1d75084b9ca5..934fa6b441b2 100644
> --- a/tools/testing/selftests/mm/mremap_dontunmap.c
> +++ b/tools/testing/selftests/mm/mremap_dontunmap.c
> @@ -5,7 +5,6 @@
>    *
>    * Copyright 2020, Brian Geffon <bgeffon@google.com>
>    */
> -#define _GNU_SOURCE
>   #include <sys/mman.h>
>   #include <linux/mman.h>
>   #include <errno.h>
> diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c
> index 2f8b991f78cb..e057154630e0 100644
> --- a/tools/testing/selftests/mm/mremap_test.c
> +++ b/tools/testing/selftests/mm/mremap_test.c
> @@ -2,8 +2,6 @@
>   /*
>    * Copyright 2020 Google LLC
>    */
> -#define _GNU_SOURCE
> -
>   #include <errno.h>
>   #include <stdlib.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/selftests/mm/pagemap_ioctl.c
> index d59517ed3d48..2a18b5d276f0 100644
> --- a/tools/testing/selftests/mm/pagemap_ioctl.c
> +++ b/tools/testing/selftests/mm/pagemap_ioctl.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include <stdio.h>
>   #include <fcntl.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/selftests/mm/pkey-helpers.h
> index 1af3156a9db8..37d6b01ce90a 100644
> --- a/tools/testing/selftests/mm/pkey-helpers.h
> +++ b/tools/testing/selftests/mm/pkey-helpers.h
> @@ -1,7 +1,6 @@
>   /* SPDX-License-Identifier: GPL-2.0 */
>   #ifndef _PKEYS_HELPER_H
>   #define _PKEYS_HELPER_H
> -#define _GNU_SOURCE
>   #include <string.h>
>   #include <stdarg.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c
> index 48dc151f8fca..9f7de92caeda 100644
> --- a/tools/testing/selftests/mm/protection_keys.c
> +++ b/tools/testing/selftests/mm/protection_keys.c
> @@ -21,7 +21,6 @@
>    *	gcc -mxsave      -o protection_keys    -O2 -g -std=gnu99 -pthread -Wall protection_keys.c -lrt -ldl -lm
>    *	gcc -mxsave -m32 -o protection_keys_32 -O2 -g -std=gnu99 -pthread -Wall protection_keys.c -lrt -ldl -lm
>    */
> -#define _GNU_SOURCE
>   #define __SANE_USERSPACE_TYPES__
>   #include <errno.h>
>   #include <linux/elf.h>
> diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
> index d3c7f5fb3e7b..ae6ac950d7a1 100644
> --- a/tools/testing/selftests/mm/split_huge_page_test.c
> +++ b/tools/testing/selftests/mm/split_huge_page_test.c
> @@ -3,8 +3,6 @@
>    * A test of splitting PMD THPs and PTE-mapped THPs from a specified virtual
>    * address range in a process via <debugfs>/split_huge_pages interface.
>    */
> -
> -#define _GNU_SOURCE
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <stdarg.h>
> diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftests/mm/thuge-gen.c
> index ea7fd8fe2876..28a5c31bd791 100644
> --- a/tools/testing/selftests/mm/thuge-gen.c
> +++ b/tools/testing/selftests/mm/thuge-gen.c
> @@ -12,8 +12,6 @@
>      ipcrm -m by hand, like this
>      sudo ipcs | awk '$1 == "0x00000000" {print $2}' | xargs -n1 sudo ipcrm -m
>      (warning this will remove all if someone else uses them) */
> -
> -#define _GNU_SOURCE 1
>   #include <sys/mman.h>
>   #include <stdlib.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h
> index cc5629c3d2aa..abb44319264a 100644
> --- a/tools/testing/selftests/mm/uffd-common.h
> +++ b/tools/testing/selftests/mm/uffd-common.h
> @@ -7,7 +7,6 @@
>   #ifndef __UFFD_COMMON_H__
>   #define __UFFD_COMMON_H__
>   
> -#define _GNU_SOURCE
>   #include <stdio.h>
>   #include <errno.h>
>   #include <unistd.h>
> diff --git a/tools/testing/selftests/mount_setattr/mount_setattr_test.c b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
> index c6a8c732b802..d894417134b6 100644
> --- a/tools/testing/selftests/mount_setattr/mount_setattr_test.c
> +++ b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include <sched.h>
>   #include <stdio.h>
>   #include <errno.h>
> diff --git a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
> index bcf51d785a37..bd975670f61d 100644
> --- a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
> +++ b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include <sched.h>
>   #include <stdio.h>
>   #include <errno.h>
> diff --git a/tools/testing/selftests/net/af_unix/diag_uid.c b/tools/testing/selftests/net/af_unix/diag_uid.c
> index 79a3dd75590e..279d0c5f70d3 100644
> --- a/tools/testing/selftests/net/af_unix/diag_uid.c
> +++ b/tools/testing/selftests/net/af_unix/diag_uid.c
> @@ -1,7 +1,5 @@
>   // SPDX-License-Identifier: GPL-2.0
>   /* Copyright Amazon.com Inc. or its affiliates. */
> -
> -#define _GNU_SOURCE
>   #include <sched.h>
>   
>   #include <unistd.h>
> diff --git a/tools/testing/selftests/net/af_unix/scm_pidfd.c b/tools/testing/selftests/net/af_unix/scm_pidfd.c
> index 7e534594167e..2986b8cd0418 100644
> --- a/tools/testing/selftests/net/af_unix/scm_pidfd.c
> +++ b/tools/testing/selftests/net/af_unix/scm_pidfd.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0 OR MIT
> -#define _GNU_SOURCE
>   #include <error.h>
>   #include <limits.h>
>   #include <stddef.h>
> diff --git a/tools/testing/selftests/net/af_unix/unix_connect.c b/tools/testing/selftests/net/af_unix/unix_connect.c
> index d799fd8f5c7c..34e816862cc7 100644
> --- a/tools/testing/selftests/net/af_unix/unix_connect.c
> +++ b/tools/testing/selftests/net/af_unix/unix_connect.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <sched.h>
>   
>   #include <stddef.h>
> diff --git a/tools/testing/selftests/net/csum.c b/tools/testing/selftests/net/csum.c
> index 90eb06fefa59..8262aa862331 100644
> --- a/tools/testing/selftests/net/csum.c
> +++ b/tools/testing/selftests/net/csum.c
> @@ -58,9 +58,6 @@
>    * different seed for each run (and logs this for reproducibility). It
>    * is advised to enable this for extra coverage in continuous testing.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <asm/byteorder.h>
>   #include <errno.h>
> diff --git a/tools/testing/selftests/net/gro.c b/tools/testing/selftests/net/gro.c
> index 353e1e867fbb..f5d7032e6466 100644
> --- a/tools/testing/selftests/net/gro.c
> +++ b/tools/testing/selftests/net/gro.c
> @@ -34,9 +34,6 @@
>    * flakiness is to be expected.
>    *
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/ip_defrag.c b/tools/testing/selftests/net/ip_defrag.c
> index f9ed749fd8c7..80c9e567a3d8 100644
> --- a/tools/testing/selftests/net/ip_defrag.c
> +++ b/tools/testing/selftests/net/ip_defrag.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/ipsec.c b/tools/testing/selftests/net/ipsec.c
> index be4a30a0d02a..04aa06d26b09 100644
> --- a/tools/testing/selftests/net/ipsec.c
> +++ b/tools/testing/selftests/net/ipsec.c
> @@ -3,9 +3,6 @@
>    * ipsec.c - Check xfrm on veth inside a net-ns.
>    * Copyright (c) 2018 Dmitry Safonov
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <asm/types.h>
>   #include <errno.h>
> diff --git a/tools/testing/selftests/net/ipv6_flowlabel.c b/tools/testing/selftests/net/ipv6_flowlabel.c
> index 708a9822259d..b7e0c3c02e20 100644
> --- a/tools/testing/selftests/net/ipv6_flowlabel.c
> +++ b/tools/testing/selftests/net/ipv6_flowlabel.c
> @@ -1,8 +1,5 @@
>   // SPDX-License-Identifier: GPL-2.0
>   /* Test IPV6_FLOWINFO cmsg on send and recv */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <asm/byteorder.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/ipv6_flowlabel_mgr.c b/tools/testing/selftests/net/ipv6_flowlabel_mgr.c
> index af95b48acea9..ebd219ba386e 100644
> --- a/tools/testing/selftests/net/ipv6_flowlabel_mgr.c
> +++ b/tools/testing/selftests/net/ipv6_flowlabel_mgr.c
> @@ -1,8 +1,5 @@
>   // SPDX-License-Identifier: GPL-2.0
>   /* Test IPV6_FLOWINFO_MGR */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <error.h>
>   #include <errno.h>
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> index d2043ec3bf6d..ea93030ed3ec 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
> +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
> -
>   #include <errno.h>
>   #include <limits.h>
>   #include <fcntl.h>
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_inq.c b/tools/testing/selftests/net/mptcp/mptcp_inq.c
> index 218aac467321..c5bf873d76c2 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_inq.c
> +++ b/tools/testing/selftests/net/mptcp/mptcp_inq.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
> -
>   #include <assert.h>
>   #include <errno.h>
>   #include <fcntl.h>
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
> index 926b0be87c99..7203ca9900e9 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
> +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
> -
>   #include <assert.h>
>   #include <errno.h>
>   #include <fcntl.h>
> diff --git a/tools/testing/selftests/net/msg_zerocopy.c b/tools/testing/selftests/net/msg_zerocopy.c
> index bdc03a2097e8..9278bf585c80 100644
> --- a/tools/testing/selftests/net/msg_zerocopy.c
> +++ b/tools/testing/selftests/net/msg_zerocopy.c
> @@ -24,9 +24,6 @@
>    * the kernel queues completions on the error queue for all zerocopy
>    * transfers.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <error.h>
>   #include <errno.h>
> diff --git a/tools/testing/selftests/net/nettest.c b/tools/testing/selftests/net/nettest.c
> index cd8a58097448..88e1d3b2ddf1 100644
> --- a/tools/testing/selftests/net/nettest.c
> +++ b/tools/testing/selftests/net/nettest.c
> @@ -3,8 +3,6 @@
>    *
>    * Copyright (c) 2013-2019 David Ahern <dsahern@gmail.com>. All rights reserved.
>    */
> -
> -#define _GNU_SOURCE
>   #include <features.h>
>   #include <sys/types.h>
>   #include <sys/ioctl.h>
> diff --git a/tools/testing/selftests/net/psock_fanout.c b/tools/testing/selftests/net/psock_fanout.c
> index 1a736f700be4..5b2d34440ae9 100644
> --- a/tools/testing/selftests/net/psock_fanout.c
> +++ b/tools/testing/selftests/net/psock_fanout.c
> @@ -26,9 +26,6 @@
>    * Todo:
>    * - functionality: PACKET_FANOUT_FLAG_DEFRAG
>    */
> -
> -#define _GNU_SOURCE		/* for sched_setaffinity */
> -
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <fcntl.h>
> diff --git a/tools/testing/selftests/net/psock_snd.c b/tools/testing/selftests/net/psock_snd.c
> index edf1e6f80d41..2f29b513e18f 100644
> --- a/tools/testing/selftests/net/psock_snd.c
> +++ b/tools/testing/selftests/net/psock_snd.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/reuseport_addr_any.c b/tools/testing/selftests/net/reuseport_addr_any.c
> index b8475cb29be7..9ee6ece52865 100644
> --- a/tools/testing/selftests/net/reuseport_addr_any.c
> +++ b/tools/testing/selftests/net/reuseport_addr_any.c
> @@ -3,9 +3,6 @@
>   /* Test that sockets listening on a specific address are preferred
>    * over sockets listening on addr_any.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/reuseport_bpf_cpu.c b/tools/testing/selftests/net/reuseport_bpf_cpu.c
> index 2d646174729f..e93e38cfb2a8 100644
> --- a/tools/testing/selftests/net/reuseport_bpf_cpu.c
> +++ b/tools/testing/selftests/net/reuseport_bpf_cpu.c
> @@ -11,9 +11,6 @@
>    * This entire process is done for several different core id permutations
>    * and for each IPv4/IPv6 and TCP/UDP combination.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/reuseport_bpf_numa.c b/tools/testing/selftests/net/reuseport_bpf_numa.c
> index c9ba36aa688e..502fdb9ce770 100644
> --- a/tools/testing/selftests/net/reuseport_bpf_numa.c
> +++ b/tools/testing/selftests/net/reuseport_bpf_numa.c
> @@ -3,9 +3,6 @@
>    * Test functionality of BPF filters with SO_REUSEPORT. Same test as
>    * in reuseport_bpf_cpu, only as one socket per NUMA node.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/reuseport_dualstack.c b/tools/testing/selftests/net/reuseport_dualstack.c
> index fb7a59ed759e..d3c3d3f39f8f 100644
> --- a/tools/testing/selftests/net/reuseport_dualstack.c
> +++ b/tools/testing/selftests/net/reuseport_dualstack.c
> @@ -10,9 +10,6 @@
>    * This test creates these mixed AF_INET/AF_INET6 sockets and asserts the
>    * AF_INET preference for v4 packets.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/so_incoming_cpu.c b/tools/testing/selftests/net/so_incoming_cpu.c
> index e9fa14e10732..95bd0cdc3253 100644
> --- a/tools/testing/selftests/net/so_incoming_cpu.c
> +++ b/tools/testing/selftests/net/so_incoming_cpu.c
> @@ -1,6 +1,5 @@
>   // SPDX-License-Identifier: GPL-2.0
>   /* Copyright Amazon.com Inc. or its affiliates. */
> -#define _GNU_SOURCE
>   #include <sched.h>
>   
>   #include <fcntl.h>
> diff --git a/tools/testing/selftests/net/so_netns_cookie.c b/tools/testing/selftests/net/so_netns_cookie.c
> index b39e87e967cd..18532d564f79 100644
> --- a/tools/testing/selftests/net/so_netns_cookie.c
> +++ b/tools/testing/selftests/net/so_netns_cookie.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include <sched.h>
>   #include <unistd.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/net/so_txtime.c b/tools/testing/selftests/net/so_txtime.c
> index 8457b7ccbc09..011a24af9786 100644
> --- a/tools/testing/selftests/net/so_txtime.c
> +++ b/tools/testing/selftests/net/so_txtime.c
> @@ -9,9 +9,6 @@
>    * the expected stream. Sender will read transmit timestamps from the error
>    * queue. The streams can differ due to out-of-order delivery and drops.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <error.h>
>   #include <errno.h>
> diff --git a/tools/testing/selftests/net/tap.c b/tools/testing/selftests/net/tap.c
> index 247c3b3ac1c9..fa78b92d9740 100644
> --- a/tools/testing/selftests/net/tap.c
> +++ b/tools/testing/selftests/net/tap.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
> -
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/net/tcp_fastopen_backup_key.c b/tools/testing/selftests/net/tcp_fastopen_backup_key.c
> index c1cb0c75156a..d30f89bb944c 100644
> --- a/tools/testing/selftests/net/tcp_fastopen_backup_key.c
> +++ b/tools/testing/selftests/net/tcp_fastopen_backup_key.c
> @@ -12,7 +12,6 @@
>    * there are no cases in which a cookie is not accepted by verifying
>    * that TcpExtTCPFastOpenPassiveFail remains 0.
>    */
> -#define _GNU_SOURCE
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/tcp_inq.c b/tools/testing/selftests/net/tcp_inq.c
> index bd6a9c7a3e8a..71ee145f151e 100644
> --- a/tools/testing/selftests/net/tcp_inq.c
> +++ b/tools/testing/selftests/net/tcp_inq.c
> @@ -5,8 +5,6 @@
>    *
>    * Simple example on how to use TCP_INQ and TCP_CM_INQ.
>    */
> -#define _GNU_SOURCE
> -
>   #include <error.h>
>   #include <netinet/in.h>
>   #include <netinet/tcp.h>
> diff --git a/tools/testing/selftests/net/tcp_mmap.c b/tools/testing/selftests/net/tcp_mmap.c
> index 4fcce5150850..72d5f1207ee0 100644
> --- a/tools/testing/selftests/net/tcp_mmap.c
> +++ b/tools/testing/selftests/net/tcp_mmap.c
> @@ -46,7 +46,6 @@
>    * received 32768 MB (99.9939 % mmap'ed) in 7.43764 s, 36.9577 Gbit
>    *   cpu usage user:0.035 sys:3.467, 106.873 usec per MB, 65530 c-switches
>    */
> -#define _GNU_SOURCE
>   #include <pthread.h>
>   #include <sys/types.h>
>   #include <fcntl.h>
> diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c
> index f27a12d2a2c9..6dbad97d1d0a 100644
> --- a/tools/testing/selftests/net/tls.c
> +++ b/tools/testing/selftests/net/tls.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/toeplitz.c b/tools/testing/selftests/net/toeplitz.c
> index 9ba03164d73a..e2d739892ce4 100644
> --- a/tools/testing/selftests/net/toeplitz.c
> +++ b/tools/testing/selftests/net/toeplitz.c
> @@ -20,9 +20,6 @@
>    * 5. Compute the cpu that RPS should select based on rx_hash and $rps_bitmap
>    * 6. Compare the cpus from 4 and 5
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c
> index fa83918b62d1..a64dcfb242c1 100644
> --- a/tools/testing/selftests/net/tun.c
> +++ b/tools/testing/selftests/net/tun.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
> -
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/net/txring_overwrite.c b/tools/testing/selftests/net/txring_overwrite.c
> index 7d9ea039450a..96972e0110a0 100644
> --- a/tools/testing/selftests/net/txring_overwrite.c
> +++ b/tools/testing/selftests/net/txring_overwrite.c
> @@ -4,9 +4,6 @@
>    * Verify that consecutive sends over packet tx_ring are mirrored
>    * with their original content intact.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <assert.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/txtimestamp.c b/tools/testing/selftests/net/txtimestamp.c
> index ec60a16c9307..33dba9e90dea 100644
> --- a/tools/testing/selftests/net/txtimestamp.c
> +++ b/tools/testing/selftests/net/txtimestamp.c
> @@ -16,9 +16,6 @@
>    * This test requires a dummy TCP server.
>    * A simple `nc6 [-u] -l -p $DESTPORT` will do
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <asm/types.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/udpgso.c b/tools/testing/selftests/net/udpgso.c
> index 85b3baa3f7f3..9dc1026a033a 100644
> --- a/tools/testing/selftests/net/udpgso.c
> +++ b/tools/testing/selftests/net/udpgso.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
> -
>   #include <stddef.h>
>   #include <arpa/inet.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/net/udpgso_bench_rx.c b/tools/testing/selftests/net/udpgso_bench_rx.c
> index 1cbadd267c96..999df1236320 100644
> --- a/tools/testing/selftests/net/udpgso_bench_rx.c
> +++ b/tools/testing/selftests/net/udpgso_bench_rx.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <error.h>
>   #include <errno.h>
> diff --git a/tools/testing/selftests/net/udpgso_bench_tx.c b/tools/testing/selftests/net/udpgso_bench_tx.c
> index 477392715a9a..d7632993b354 100644
> --- a/tools/testing/selftests/net/udpgso_bench_tx.c
> +++ b/tools/testing/selftests/net/udpgso_bench_tx.c
> @@ -1,7 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
> -
>   #include <arpa/inet.h>
>   #include <errno.h>
>   #include <error.h>
> diff --git a/tools/testing/selftests/perf_events/remove_on_exec.c b/tools/testing/selftests/perf_events/remove_on_exec.c
> index 5814611a1dc7..ef4d923f4759 100644
> --- a/tools/testing/selftests/perf_events/remove_on_exec.c
> +++ b/tools/testing/selftests/perf_events/remove_on_exec.c
> @@ -5,8 +5,6 @@
>    * Copyright (C) 2021, Google LLC.
>    */
>   
> -#define _GNU_SOURCE
> -
>   /* We need the latest siginfo from the kernel repo. */
>   #include <sys/types.h>
>   #include <asm/siginfo.h>
> diff --git a/tools/testing/selftests/perf_events/sigtrap_threads.c b/tools/testing/selftests/perf_events/sigtrap_threads.c
> index d1d8483ac628..14d1a3c8cb5c 100644
> --- a/tools/testing/selftests/perf_events/sigtrap_threads.c
> +++ b/tools/testing/selftests/perf_events/sigtrap_threads.c
> @@ -5,8 +5,6 @@
>    * Copyright (C) 2021, Google LLC.
>    */
>   
> -#define _GNU_SOURCE
> -
>   /* We need the latest siginfo from the kernel repo. */
>   #include <sys/types.h>
>   #include <asm/siginfo.h>
> diff --git a/tools/testing/selftests/pid_namespace/regression_enomem.c b/tools/testing/selftests/pid_namespace/regression_enomem.c
> index 7d84097ad45c..54dc8f16d92a 100644
> --- a/tools/testing/selftests/pid_namespace/regression_enomem.c
> +++ b/tools/testing/selftests/pid_namespace/regression_enomem.c
> @@ -1,4 +1,3 @@
> -#define _GNU_SOURCE
>   #include <assert.h>
>   #include <errno.h>
>   #include <fcntl.h>
> diff --git a/tools/testing/selftests/pidfd/pidfd.h b/tools/testing/selftests/pidfd/pidfd.h
> index 88d6830ee004..e33177b1aa41 100644
> --- a/tools/testing/selftests/pidfd/pidfd.h
> +++ b/tools/testing/selftests/pidfd/pidfd.h
> @@ -3,7 +3,6 @@
>   #ifndef __PIDFD_H
>   #define __PIDFD_H
>   
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <sched.h>
> diff --git a/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c b/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
> index 01cc37bf611c..67c9dc436c71 100644
> --- a/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
> +++ b/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <assert.h>
>   #include <errno.h>
>   #include <fcntl.h>
> diff --git a/tools/testing/selftests/pidfd/pidfd_getfd_test.c b/tools/testing/selftests/pidfd/pidfd_getfd_test.c
> index cd51d547b751..b6a0e9b3d2f5 100644
> --- a/tools/testing/selftests/pidfd/pidfd_getfd_test.c
> +++ b/tools/testing/selftests/pidfd/pidfd_getfd_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <limits.h>
> diff --git a/tools/testing/selftests/pidfd/pidfd_open_test.c b/tools/testing/selftests/pidfd/pidfd_open_test.c
> index 8a59438ccc78..781a3931fb5a 100644
> --- a/tools/testing/selftests/pidfd/pidfd_open_test.c
> +++ b/tools/testing/selftests/pidfd/pidfd_open_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <inttypes.h>
> diff --git a/tools/testing/selftests/pidfd/pidfd_poll_test.c b/tools/testing/selftests/pidfd/pidfd_poll_test.c
> index 610811275357..a40fb27a78bb 100644
> --- a/tools/testing/selftests/pidfd/pidfd_poll_test.c
> +++ b/tools/testing/selftests/pidfd/pidfd_poll_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <linux/types.h>
>   #include <poll.h>
> diff --git a/tools/testing/selftests/pidfd/pidfd_setns_test.c b/tools/testing/selftests/pidfd/pidfd_setns_test.c
> index 6e2f2cd400ca..49d7a78cc4fe 100644
> --- a/tools/testing/selftests/pidfd/pidfd_setns_test.c
> +++ b/tools/testing/selftests/pidfd/pidfd_setns_test.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <limits.h>
> diff --git a/tools/testing/selftests/pidfd/pidfd_test.c b/tools/testing/selftests/pidfd/pidfd_test.c
> index c081ae91313a..c3d52406b8fd 100644
> --- a/tools/testing/selftests/pidfd/pidfd_test.c
> +++ b/tools/testing/selftests/pidfd/pidfd_test.c
> @@ -1,6 +1,4 @@
>   /* SPDX-License-Identifier: GPL-2.0 */
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <linux/types.h>
> diff --git a/tools/testing/selftests/pidfd/pidfd_wait.c b/tools/testing/selftests/pidfd/pidfd_wait.c
> index 0dcb8365ddc3..54beba0983f1 100644
> --- a/tools/testing/selftests/pidfd/pidfd_wait.c
> +++ b/tools/testing/selftests/pidfd/pidfd_wait.c
> @@ -1,6 +1,4 @@
>   /* SPDX-License-Identifier: GPL-2.0 */
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <linux/sched.h>
>   #include <linux/types.h>
> diff --git a/tools/testing/selftests/ptrace/get_set_sud.c b/tools/testing/selftests/ptrace/get_set_sud.c
> index 5297b10d25c3..054a78ebe8b5 100644
> --- a/tools/testing/selftests/ptrace/get_set_sud.c
> +++ b/tools/testing/selftests/ptrace/get_set_sud.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include "../kselftest_harness.h"
>   #include <stdio.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/ptrace/peeksiginfo.c b/tools/testing/selftests/ptrace/peeksiginfo.c
> index a6884f66dc01..1b7b77190f72 100644
> --- a/tools/testing/selftests/ptrace/peeksiginfo.c
> +++ b/tools/testing/selftests/ptrace/peeksiginfo.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include <stdio.h>
>   #include <signal.h>
>   #include <unistd.h>
> diff --git a/tools/testing/selftests/rseq/basic_percpu_ops_test.c b/tools/testing/selftests/rseq/basic_percpu_ops_test.c
> index 2348d2c20d0a..5961c24ee1ae 100644
> --- a/tools/testing/selftests/rseq/basic_percpu_ops_test.c
> +++ b/tools/testing/selftests/rseq/basic_percpu_ops_test.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: LGPL-2.1
> -#define _GNU_SOURCE
>   #include <assert.h>
>   #include <pthread.h>
>   #include <sched.h>
> diff --git a/tools/testing/selftests/rseq/basic_test.c b/tools/testing/selftests/rseq/basic_test.c
> index 295eea16466f..1fed749b4bd7 100644
> --- a/tools/testing/selftests/rseq/basic_test.c
> +++ b/tools/testing/selftests/rseq/basic_test.c
> @@ -2,8 +2,6 @@
>   /*
>    * Basic test coverage for critical regions and rseq_current_cpu().
>    */
> -
> -#define _GNU_SOURCE
>   #include <assert.h>
>   #include <sched.h>
>   #include <signal.h>
> diff --git a/tools/testing/selftests/rseq/param_test.c b/tools/testing/selftests/rseq/param_test.c
> index 2f37961240ca..48a55d94eb72 100644
> --- a/tools/testing/selftests/rseq/param_test.c
> +++ b/tools/testing/selftests/rseq/param_test.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: LGPL-2.1
> -#define _GNU_SOURCE
>   #include <assert.h>
>   #include <linux/membarrier.h>
>   #include <pthread.h>
> diff --git a/tools/testing/selftests/rseq/rseq.c b/tools/testing/selftests/rseq/rseq.c
> index 96e812bdf8a4..88602889414c 100644
> --- a/tools/testing/selftests/rseq/rseq.c
> +++ b/tools/testing/selftests/rseq/rseq.c
> @@ -14,8 +14,6 @@
>    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>    * Lesser General Public License for more details.
>    */
> -
> -#define _GNU_SOURCE
>   #include <errno.h>
>   #include <sched.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/seccomp/seccomp_benchmark.c b/tools/testing/selftests/seccomp/seccomp_benchmark.c
> index b83099160fbc..3632a4890da9 100644
> --- a/tools/testing/selftests/seccomp/seccomp_benchmark.c
> +++ b/tools/testing/selftests/seccomp/seccomp_benchmark.c
> @@ -2,7 +2,6 @@
>    * Strictly speaking, this is not a test. But it can report during test
>    * runs so relative performace can be measured.
>    */
> -#define _GNU_SOURCE
>   #include <assert.h>
>   #include <err.h>
>   #include <limits.h>
> diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
> index 783ebce8c4de..972ccc12553e 100644
> --- a/tools/testing/selftests/seccomp/seccomp_bpf.c
> +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
> @@ -4,8 +4,6 @@
>    *
>    * Test code for seccomp bpf.
>    */
> -
> -#define _GNU_SOURCE
>   #include <sys/types.h>
>   
>   /*
> diff --git a/tools/testing/selftests/user_events/abi_test.c b/tools/testing/selftests/user_events/abi_test.c
> index 7288a05136ba..a1f156dbbd56 100644
> --- a/tools/testing/selftests/user_events/abi_test.c
> +++ b/tools/testing/selftests/user_events/abi_test.c
> @@ -4,8 +4,6 @@
>    *
>    * Copyright (c) 2022 Beau Belgrave <beaub@linux.microsoft.com>
>    */
> -
> -#define _GNU_SOURCE
>   #include <sched.h>
>   
>   #include <errno.h>
> diff --git a/tools/testing/selftests/x86/amx.c b/tools/testing/selftests/x86/amx.c
> index d884fd69dd51..9441635fc452 100644
> --- a/tools/testing/selftests/x86/amx.c
> +++ b/tools/testing/selftests/x86/amx.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -
> -#define _GNU_SOURCE
>   #include <err.h>
>   #include <errno.h>
>   #include <pthread.h>
> diff --git a/tools/testing/selftests/x86/check_initial_reg_state.c b/tools/testing/selftests/x86/check_initial_reg_state.c
> index 3bc95f3ed585..0129cdae8abe 100644
> --- a/tools/testing/selftests/x86/check_initial_reg_state.c
> +++ b/tools/testing/selftests/x86/check_initial_reg_state.c
> @@ -3,9 +3,6 @@
>    * check_initial_reg_state.c - check that execve sets the correct state
>    * Copyright (c) 2014-2016 Andrew Lutomirski
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <stdio.h>
>   
>   unsigned long ax, bx, cx, dx, si, di, bp, sp, flags;
> diff --git a/tools/testing/selftests/x86/corrupt_xstate_header.c b/tools/testing/selftests/x86/corrupt_xstate_header.c
> index cf9ce8fbb656..d2c746149678 100644
> --- a/tools/testing/selftests/x86/corrupt_xstate_header.c
> +++ b/tools/testing/selftests/x86/corrupt_xstate_header.c
> @@ -4,9 +4,6 @@
>    *
>    * Based on analysis and a test case from Thomas Gleixner.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <stdlib.h>
>   #include <stdio.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/x86/entry_from_vm86.c b/tools/testing/selftests/x86/entry_from_vm86.c
> index d1e919b0c1dc..9fa9d4a847ac 100644
> --- a/tools/testing/selftests/x86/entry_from_vm86.c
> +++ b/tools/testing/selftests/x86/entry_from_vm86.c
> @@ -5,9 +5,6 @@
>    *
>    * This exercises a few paths that need to special-case vm86 mode.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <assert.h>
>   #include <stdlib.h>
>   #include <sys/syscall.h>
> diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c
> index 8c780cce941d..348134d2cefc 100644
> --- a/tools/testing/selftests/x86/fsgsbase.c
> +++ b/tools/testing/selftests/x86/fsgsbase.c
> @@ -3,8 +3,6 @@
>    * fsgsbase.c, an fsgsbase test
>    * Copyright (c) 2014-2016 Andy Lutomirski
>    */
> -
> -#define _GNU_SOURCE
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <stdbool.h>
> diff --git a/tools/testing/selftests/x86/fsgsbase_restore.c b/tools/testing/selftests/x86/fsgsbase_restore.c
> index 6fffadc51579..88dce47ab8e6 100644
> --- a/tools/testing/selftests/x86/fsgsbase_restore.c
> +++ b/tools/testing/selftests/x86/fsgsbase_restore.c
> @@ -12,8 +12,6 @@
>    *
>    * This is not part of fsgsbase.c, because that test is 64-bit only.
>    */
> -
> -#define _GNU_SOURCE
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <stdbool.h>
> diff --git a/tools/testing/selftests/x86/ioperm.c b/tools/testing/selftests/x86/ioperm.c
> index 57ec5e99edb9..07b7c10f8d39 100644
> --- a/tools/testing/selftests/x86/ioperm.c
> +++ b/tools/testing/selftests/x86/ioperm.c
> @@ -3,8 +3,6 @@
>    * ioperm.c - Test case for ioperm(2)
>    * Copyright (c) 2015 Andrew Lutomirski
>    */
> -
> -#define _GNU_SOURCE
>   #include <err.h>
>   #include <stdio.h>
>   #include <stdint.h>
> diff --git a/tools/testing/selftests/x86/iopl.c b/tools/testing/selftests/x86/iopl.c
> index 7e3e09c1abac..baa691154905 100644
> --- a/tools/testing/selftests/x86/iopl.c
> +++ b/tools/testing/selftests/x86/iopl.c
> @@ -3,8 +3,6 @@
>    * iopl.c - Test case for a Linux on Xen 64-bit bug
>    * Copyright (c) 2015 Andrew Lutomirski
>    */
> -
> -#define _GNU_SOURCE
>   #include <err.h>
>   #include <stdio.h>
>   #include <stdint.h>
> diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c
> index 215b8150b7cc..39edfd7f6037 100644
> --- a/tools/testing/selftests/x86/lam.c
> +++ b/tools/testing/selftests/x86/lam.c
> @@ -1,5 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/x86/ldt_gdt.c b/tools/testing/selftests/x86/ldt_gdt.c
> index 3a29346e1452..3b4237a85a12 100644
> --- a/tools/testing/selftests/x86/ldt_gdt.c
> +++ b/tools/testing/selftests/x86/ldt_gdt.c
> @@ -3,8 +3,6 @@
>    * ldt_gdt.c - Test cases for LDT and GDT access
>    * Copyright (c) 2015 Andrew Lutomirski
>    */
> -
> -#define _GNU_SOURCE
>   #include <err.h>
>   #include <stdio.h>
>   #include <stdint.h>
> diff --git a/tools/testing/selftests/x86/mov_ss_trap.c b/tools/testing/selftests/x86/mov_ss_trap.c
> index cc3de6ff9fba..47ecc63220b7 100644
> --- a/tools/testing/selftests/x86/mov_ss_trap.c
> +++ b/tools/testing/selftests/x86/mov_ss_trap.c
> @@ -19,8 +19,6 @@
>    *
>    * This should mostly cover CVE-2018-1087 and CVE-2018-8897.
>    */
> -#define _GNU_SOURCE
> -
>   #include <stdlib.h>
>   #include <sys/ptrace.h>
>   #include <sys/types.h>
> diff --git a/tools/testing/selftests/x86/nx_stack.c b/tools/testing/selftests/x86/nx_stack.c
> index ea4a4e246879..97c5b34096cc 100644
> --- a/tools/testing/selftests/x86/nx_stack.c
> +++ b/tools/testing/selftests/x86/nx_stack.c
> @@ -23,8 +23,6 @@
>    * Regular stack is completely overwritten before testing.
>    * Test doesn't exit SIGSEGV handler after first fault at INT3.
>    */
> -#undef _GNU_SOURCE
> -#define _GNU_SOURCE
>   #undef NDEBUG
>   #include <assert.h>
>   #include <signal.h>
> diff --git a/tools/testing/selftests/x86/ptrace_syscall.c b/tools/testing/selftests/x86/ptrace_syscall.c
> index 12aaa063196e..bdc81c8bd1a7 100644
> --- a/tools/testing/selftests/x86/ptrace_syscall.c
> +++ b/tools/testing/selftests/x86/ptrace_syscall.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#define _GNU_SOURCE
> -
>   #include <sys/ptrace.h>
>   #include <sys/types.h>
>   #include <sys/wait.h>
> diff --git a/tools/testing/selftests/x86/sigaltstack.c b/tools/testing/selftests/x86/sigaltstack.c
> index f689af75e979..7f41c3a4268b 100644
> --- a/tools/testing/selftests/x86/sigaltstack.c
> +++ b/tools/testing/selftests/x86/sigaltstack.c
> @@ -1,6 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0-only
> -
> -#define _GNU_SOURCE
>   #include <signal.h>
>   #include <stdio.h>
>   #include <stdbool.h>
> diff --git a/tools/testing/selftests/x86/sigreturn.c b/tools/testing/selftests/x86/sigreturn.c
> index 5d7961a5f7f6..2054f729b2c2 100644
> --- a/tools/testing/selftests/x86/sigreturn.c
> +++ b/tools/testing/selftests/x86/sigreturn.c
> @@ -24,9 +24,6 @@
>    *
>    * Do not run on outdated, unpatched kernels at risk of nasty crashes.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <sys/time.h>
>   #include <time.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/x86/single_step_syscall.c b/tools/testing/selftests/x86/single_step_syscall.c
> index 9a30f443e928..375f3b50a0b5 100644
> --- a/tools/testing/selftests/x86/single_step_syscall.c
> +++ b/tools/testing/selftests/x86/single_step_syscall.c
> @@ -9,9 +9,6 @@
>    * immediately issues #DB from CPL 0.  This requires special handling in
>    * the kernel.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <sys/time.h>
>   #include <time.h>
>   #include <stdlib.h>
> diff --git a/tools/testing/selftests/x86/syscall_arg_fault.c b/tools/testing/selftests/x86/syscall_arg_fault.c
> index 461fa41a4d02..10eee1bcd015 100644
> --- a/tools/testing/selftests/x86/syscall_arg_fault.c
> +++ b/tools/testing/selftests/x86/syscall_arg_fault.c
> @@ -3,9 +3,6 @@
>    * syscall_arg_fault.c - tests faults 32-bit fast syscall stack args
>    * Copyright (c) 2015 Andrew Lutomirski
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <stdlib.h>
>   #include <stdio.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/x86/syscall_numbering.c b/tools/testing/selftests/x86/syscall_numbering.c
> index 991591718bb0..c72fc8aaa4d3 100644
> --- a/tools/testing/selftests/x86/syscall_numbering.c
> +++ b/tools/testing/selftests/x86/syscall_numbering.c
> @@ -5,9 +5,6 @@
>    *
>    * Copyright (c) 2018 Andrew Lutomirski
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <stdlib.h>
>   #include <stdio.h>
>   #include <stdbool.h>
> diff --git a/tools/testing/selftests/x86/sysret_rip.c b/tools/testing/selftests/x86/sysret_rip.c
> index 84d74be1d902..24bc219358a5 100644
> --- a/tools/testing/selftests/x86/sysret_rip.c
> +++ b/tools/testing/selftests/x86/sysret_rip.c
> @@ -3,9 +3,6 @@
>    * sigreturn.c - tests that x86 avoids Intel SYSRET pitfalls
>    * Copyright (c) 2014-2016 Andrew Lutomirski
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <stdlib.h>
>   #include <unistd.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/x86/sysret_ss_attrs.c b/tools/testing/selftests/x86/sysret_ss_attrs.c
> index 5f3d4fca440f..f8b9e0b2a0c5 100644
> --- a/tools/testing/selftests/x86/sysret_ss_attrs.c
> +++ b/tools/testing/selftests/x86/sysret_ss_attrs.c
> @@ -7,9 +7,6 @@
>    * the hidden attributes set to an unusable state.  Make sure the kernel
>    * doesn't let this happen.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <stdlib.h>
>   #include <unistd.h>
>   #include <stdio.h>
> diff --git a/tools/testing/selftests/x86/test_FCMOV.c b/tools/testing/selftests/x86/test_FCMOV.c
> index 6b5036fbb735..0c9431ba7d31 100644
> --- a/tools/testing/selftests/x86/test_FCMOV.c
> +++ b/tools/testing/selftests/x86/test_FCMOV.c
> @@ -1,8 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#undef _GNU_SOURCE
> -#define _GNU_SOURCE 1
> -#undef __USE_GNU
> -#define __USE_GNU 1
>   #include <unistd.h>
>   #include <stdlib.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/x86/test_FCOMI.c b/tools/testing/selftests/x86/test_FCOMI.c
> index aec6692c6dcf..ba186665918d 100644
> --- a/tools/testing/selftests/x86/test_FCOMI.c
> +++ b/tools/testing/selftests/x86/test_FCOMI.c
> @@ -1,8 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#undef _GNU_SOURCE
> -#define _GNU_SOURCE 1
> -#undef __USE_GNU
> -#define __USE_GNU 1
>   #include <unistd.h>
>   #include <stdlib.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/x86/test_FISTTP.c b/tools/testing/selftests/x86/test_FISTTP.c
> index 09789c0ce3e9..95580cdaaa32 100644
> --- a/tools/testing/selftests/x86/test_FISTTP.c
> +++ b/tools/testing/selftests/x86/test_FISTTP.c
> @@ -1,8 +1,4 @@
>   // SPDX-License-Identifier: GPL-2.0
> -#undef _GNU_SOURCE
> -#define _GNU_SOURCE 1
> -#undef __USE_GNU
> -#define __USE_GNU 1
>   #include <unistd.h>
>   #include <stdlib.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/x86/test_mremap_vdso.c b/tools/testing/selftests/x86/test_mremap_vdso.c
> index f0d876d48277..a8bdba356682 100644
> --- a/tools/testing/selftests/x86/test_mremap_vdso.c
> +++ b/tools/testing/selftests/x86/test_mremap_vdso.c
> @@ -9,7 +9,6 @@
>    * Can be built statically:
>    * gcc -Os -Wall -static -m32 test_mremap_vdso.c
>    */
> -#define _GNU_SOURCE
>   #include <stdio.h>
>   #include <errno.h>
>   #include <unistd.h>
> diff --git a/tools/testing/selftests/x86/test_shadow_stack.c b/tools/testing/selftests/x86/test_shadow_stack.c
> index 757e6527f67e..0ceca9064cec 100644
> --- a/tools/testing/selftests/x86/test_shadow_stack.c
> +++ b/tools/testing/selftests/x86/test_shadow_stack.c
> @@ -7,9 +7,6 @@
>    * special glibc shadow stack support (longjmp(), swapcontext(), etc). Just
>    * stick to the basics and hope the compiler doesn't do anything strange.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <sys/syscall.h>
>   #include <asm/mman.h>
>   #include <sys/mman.h>
> diff --git a/tools/testing/selftests/x86/test_syscall_vdso.c b/tools/testing/selftests/x86/test_syscall_vdso.c
> index 8965c311bd65..5cd13279bba5 100644
> --- a/tools/testing/selftests/x86/test_syscall_vdso.c
> +++ b/tools/testing/selftests/x86/test_syscall_vdso.c
> @@ -8,10 +8,6 @@
>    * Can be built statically:
>    * gcc -Os -Wall -static -m32 test_syscall_vdso.c thunks_32.S
>    */
> -#undef _GNU_SOURCE
> -#define _GNU_SOURCE 1
> -#undef __USE_GNU
> -#define __USE_GNU 1
>   #include <unistd.h>
>   #include <stdlib.h>
>   #include <string.h>
> diff --git a/tools/testing/selftests/x86/test_vsyscall.c b/tools/testing/selftests/x86/test_vsyscall.c
> index 47cab972807c..cbf4e5012005 100644
> --- a/tools/testing/selftests/x86/test_vsyscall.c
> +++ b/tools/testing/selftests/x86/test_vsyscall.c
> @@ -1,7 +1,4 @@
>   /* SPDX-License-Identifier: GPL-2.0 */
> -
> -#define _GNU_SOURCE
> -
>   #include <stdio.h>
>   #include <sys/time.h>
>   #include <time.h>
> diff --git a/tools/testing/selftests/x86/unwind_vdso.c b/tools/testing/selftests/x86/unwind_vdso.c
> index 4c311e1af4c7..754f5d4d425a 100644
> --- a/tools/testing/selftests/x86/unwind_vdso.c
> +++ b/tools/testing/selftests/x86/unwind_vdso.c
> @@ -5,9 +5,6 @@
>    *
>    * This tests __kernel_vsyscall's unwind info.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <features.h>
>   #include <stdio.h>
>   
> diff --git a/tools/testing/selftests/x86/vdso_restorer.c b/tools/testing/selftests/x86/vdso_restorer.c
> index fe99f2434155..8193de22a390 100644
> --- a/tools/testing/selftests/x86/vdso_restorer.c
> +++ b/tools/testing/selftests/x86/vdso_restorer.c
> @@ -10,9 +10,6 @@
>    * 64-bit userspace has never supported sa_restorer == NULL, so this is
>    * 32-bit only.
>    */
> -
> -#define _GNU_SOURCE
> -
>   #include <err.h>
>   #include <stdio.h>
>   #include <dlfcn.h>



^ permalink raw reply

* Re: [PATCH v2 3/5] selftests: Include KHDR_INCLUDES in Makefile
From: John Hubbard @ 2024-05-08 21:41 UTC (permalink / raw)
  To: Edward Liaw, shuah, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Catalin Marinas, Will Deacon, Nhat Pham, Johannes Weiner,
	Christian Brauner, Eric Biederman, Kees Cook, OGAWA Hirofumi,
	Thomas Gleixner, Ingo Molnar, Peter Zijlstra, Darren Hart,
	Davidlohr Bueso, André Almeida, Jiri Kosina,
	Benjamin Tissoires, Jason Gunthorpe, Kevin Tian, Andy Lutomirski,
	Will Drewry, Marc Zyngier, Oliver Upton, James Morse,
	Suzuki K Poulose, Zenghui Yu, Paolo Bonzini, Sean Christopherson,
	Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Mickaël Salaün, Paul Moore,
	James Morris, Serge E. Hallyn, Andrew Morton, Seth Forshee,
	Bongsu Jeon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Steffen Klassert, Herbert Xu, Andreas Färber,
	Manivannan Sadhasivam, Matthieu Baerts, Mat Martineau,
	Geliang Tang, Willem de Bruijn, Fenghua Yu, Reinette Chatre,
	Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum
  Cc: linux-kernel, linux-kselftest, kernel-team, linux-sound,
	linux-arm-kernel, linux-mm, linux-input, iommu, kvmarm, kvm,
	kvm-riscv, linux-riscv, linux-security-module, linux-fsdevel,
	netdev, linux-actions, mptcp, linux-rtc, linux-sgx, bpf
In-Reply-To: <20240507214254.2787305-4-edliaw@google.com>

On 5/7/24 2:38 PM, Edward Liaw wrote:
> Add KHDR_INCLUDES to CFLAGS to pull in the kselftest harness
> dependencies (-D_GNU_SOURCE).
> 
> Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
> Signed-off-by: Edward Liaw <edliaw@google.com>
> ---
>   tools/testing/selftests/alsa/Makefile                  | 2 +-
>   tools/testing/selftests/arm64/signal/Makefile          | 2 +-
>   tools/testing/selftests/exec/Makefile                  | 2 +-
>   tools/testing/selftests/filesystems/overlayfs/Makefile | 2 +-
>   tools/testing/selftests/hid/Makefile                   | 2 +-
>   tools/testing/selftests/nci/Makefile                   | 2 +-
>   tools/testing/selftests/prctl/Makefile                 | 2 ++
>   tools/testing/selftests/proc/Makefile                  | 2 +-
>   tools/testing/selftests/riscv/mm/Makefile              | 2 +-
>   tools/testing/selftests/rtc/Makefile                   | 2 +-
>   tools/testing/selftests/tmpfs/Makefile                 | 2 +-
>   11 files changed, 12 insertions(+), 10 deletions(-)

Hi Edward,

Seeing as how these all include lib.mk, and all use CFLAGS, is there
any reason not to simply fix this in lib.mk instead? Like this:

diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index 7fa4a96e26ed..df72610e0d2b 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -170,6 +170,8 @@ clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_dir)
  CFLAGS += $(USERCFLAGS)
  LDFLAGS += $(USERLDFLAGS)
  
+CFLAGS += $(KHDR_INCLUDES)
+
  # When make O= with kselftest target from main level
  # the following aren't defined.
  #


thanks,
-- 
John Hubbard
NVIDIA

> 
> diff --git a/tools/testing/selftests/alsa/Makefile b/tools/testing/selftests/alsa/Makefile
> index 5af9ba8a4645..9a0ef194522c 100644
> --- a/tools/testing/selftests/alsa/Makefile
> +++ b/tools/testing/selftests/alsa/Makefile
> @@ -6,7 +6,7 @@ LDLIBS += $(shell pkg-config --libs alsa)
>   ifeq ($(LDLIBS),)
>   LDLIBS += -lasound
>   endif
> -CFLAGS += -L$(OUTPUT) -Wl,-rpath=./
> +CFLAGS += $(KHDR_INCLUDES) -L$(OUTPUT) -Wl,-rpath=./
>   
>   LDLIBS+=-lpthread
>   
> diff --git a/tools/testing/selftests/arm64/signal/Makefile b/tools/testing/selftests/arm64/signal/Makefile
> index 8f5febaf1a9a..ae682ade615d 100644
> --- a/tools/testing/selftests/arm64/signal/Makefile
> +++ b/tools/testing/selftests/arm64/signal/Makefile
> @@ -2,7 +2,7 @@
>   # Copyright (C) 2019 ARM Limited
>   
>   # Additional include paths needed by kselftest.h and local headers
> -CFLAGS += -D_GNU_SOURCE -std=gnu99 -I.
> +CFLAGS += $(KHDR_INCLUDES) -std=gnu99 -I.
>   
>   SRCS := $(filter-out testcases/testcases.c,$(wildcard testcases/*.c))
>   PROGS := $(patsubst %.c,%,$(SRCS))
> diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftests/exec/Makefile
> index fb4472ddffd8..15e78ec7c55e 100644
> --- a/tools/testing/selftests/exec/Makefile
> +++ b/tools/testing/selftests/exec/Makefile
> @@ -1,7 +1,7 @@
>   # SPDX-License-Identifier: GPL-2.0
>   CFLAGS = -Wall
>   CFLAGS += -Wno-nonnull
> -CFLAGS += -D_GNU_SOURCE
> +CFLAGS += $(KHDR_INCLUDES)
>   
>   TEST_PROGS := binfmt_script.py
>   TEST_GEN_PROGS := execveat load_address_4096 load_address_2097152 load_address_16777216 non-regular
> diff --git a/tools/testing/selftests/filesystems/overlayfs/Makefile b/tools/testing/selftests/filesystems/overlayfs/Makefile
> index 56b2b48a765b..6c29c963c7a8 100644
> --- a/tools/testing/selftests/filesystems/overlayfs/Makefile
> +++ b/tools/testing/selftests/filesystems/overlayfs/Makefile
> @@ -2,6 +2,6 @@
>   
>   TEST_GEN_PROGS := dev_in_maps
>   
> -CFLAGS := -Wall -Werror
> +CFLAGS := -Wall -Werror $(KHDR_INCLUDES)
>   
>   include ../../lib.mk
> diff --git a/tools/testing/selftests/hid/Makefile b/tools/testing/selftests/hid/Makefile
> index 2b5ea18bde38..0661b34488ef 100644
> --- a/tools/testing/selftests/hid/Makefile
> +++ b/tools/testing/selftests/hid/Makefile
> @@ -21,7 +21,7 @@ CXX ?= $(CROSS_COMPILE)g++
>   
>   HOSTPKG_CONFIG := pkg-config
>   
> -CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(OUTPUT)
> +CFLAGS += -g -O0 -rdynamic -Wall -Werror $(KHDR_INCLUDES) -I$(OUTPUT)
>   CFLAGS += -I$(OUTPUT)/tools/include
>   
>   LDLIBS += -lelf -lz -lrt -lpthread
> diff --git a/tools/testing/selftests/nci/Makefile b/tools/testing/selftests/nci/Makefile
> index 47669a1d6a59..bbc5b8ec3b17 100644
> --- a/tools/testing/selftests/nci/Makefile
> +++ b/tools/testing/selftests/nci/Makefile
> @@ -1,5 +1,5 @@
>   # SPDX-License-Identifier: GPL-2.0
> -CFLAGS += -Wl,-no-as-needed -Wall
> +CFLAGS += -Wl,-no-as-needed -Wall $(KHDR_INCLUDES)
>   LDFLAGS += -lpthread
>   
>   TEST_GEN_PROGS := nci_dev
> diff --git a/tools/testing/selftests/prctl/Makefile b/tools/testing/selftests/prctl/Makefile
> index 01dc90fbb509..1a0aefec9d6f 100644
> --- a/tools/testing/selftests/prctl/Makefile
> +++ b/tools/testing/selftests/prctl/Makefile
> @@ -6,6 +6,8 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
>   ifeq ($(ARCH),x86)
>   TEST_PROGS := disable-tsc-ctxt-sw-stress-test disable-tsc-on-off-stress-test \
>   		disable-tsc-test set-anon-vma-name-test set-process-name
> +
> +CFLAGS += $(KHDR_INCLUDES)
>   all: $(TEST_PROGS)
>   
>   include ../lib.mk
> diff --git a/tools/testing/selftests/proc/Makefile b/tools/testing/selftests/proc/Makefile
> index cd95369254c0..9596014c10a0 100644
> --- a/tools/testing/selftests/proc/Makefile
> +++ b/tools/testing/selftests/proc/Makefile
> @@ -1,6 +1,6 @@
>   # SPDX-License-Identifier: GPL-2.0-only
>   CFLAGS += -Wall -O2 -Wno-unused-function
> -CFLAGS += -D_GNU_SOURCE
> +CFLAGS += $(KHDR_INCLUDES)
>   LDFLAGS += -pthread
>   
>   TEST_GEN_PROGS :=
> diff --git a/tools/testing/selftests/riscv/mm/Makefile b/tools/testing/selftests/riscv/mm/Makefile
> index c333263f2b27..715a21241113 100644
> --- a/tools/testing/selftests/riscv/mm/Makefile
> +++ b/tools/testing/selftests/riscv/mm/Makefile
> @@ -3,7 +3,7 @@
>   # Originally tools/testing/arm64/abi/Makefile
>   
>   # Additional include paths needed by kselftest.h and local headers
> -CFLAGS += -D_GNU_SOURCE -std=gnu99 -I.
> +CFLAGS += $(KHDR_INCLUDES) -std=gnu99 -I.
>   
>   TEST_GEN_FILES := mmap_default mmap_bottomup
>   
> diff --git a/tools/testing/selftests/rtc/Makefile b/tools/testing/selftests/rtc/Makefile
> index 55198ecc04db..654f9d58da3c 100644
> --- a/tools/testing/selftests/rtc/Makefile
> +++ b/tools/testing/selftests/rtc/Makefile
> @@ -1,5 +1,5 @@
>   # SPDX-License-Identifier: GPL-2.0
> -CFLAGS += -O3 -Wl,-no-as-needed -Wall
> +CFLAGS += -O3 -Wl,-no-as-needed -Wall $(KHDR_INCLUDES)
>   LDLIBS += -lrt -lpthread -lm
>   
>   TEST_GEN_PROGS = rtctest
> diff --git a/tools/testing/selftests/tmpfs/Makefile b/tools/testing/selftests/tmpfs/Makefile
> index aa11ccc92e5b..bcdc1bb6d2e6 100644
> --- a/tools/testing/selftests/tmpfs/Makefile
> +++ b/tools/testing/selftests/tmpfs/Makefile
> @@ -1,6 +1,6 @@
>   # SPDX-License-Identifier: GPL-2.0-only
>   CFLAGS += -Wall -O2
> -CFLAGS += -D_GNU_SOURCE
> +CFLAGS += $(KHDR_INCLUDES)
>   
>   TEST_GEN_PROGS :=
>   TEST_GEN_PROGS += bug-link-o-tmpfile



^ permalink raw reply related

* Re: [PATCH v2 5/5] selftests: Drop duplicate -D_GNU_SOURCE
From: John Hubbard @ 2024-05-08 21:49 UTC (permalink / raw)
  To: Edward Liaw, shuah, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Catalin Marinas, Will Deacon, Nhat Pham, Johannes Weiner,
	Christian Brauner, Eric Biederman, Kees Cook, OGAWA Hirofumi,
	Thomas Gleixner, Ingo Molnar, Peter Zijlstra, Darren Hart,
	Davidlohr Bueso, André Almeida, Jiri Kosina,
	Benjamin Tissoires, Jason Gunthorpe, Kevin Tian, Andy Lutomirski,
	Will Drewry, Marc Zyngier, Oliver Upton, James Morse,
	Suzuki K Poulose, Zenghui Yu, Paolo Bonzini, Sean Christopherson,
	Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Mickaël Salaün, Paul Moore,
	James Morris, Serge E. Hallyn, Andrew Morton, Seth Forshee,
	Bongsu Jeon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Steffen Klassert, Herbert Xu, Andreas Färber,
	Manivannan Sadhasivam, Matthieu Baerts, Mat Martineau,
	Geliang Tang, Willem de Bruijn, Fenghua Yu, Reinette Chatre,
	Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum
  Cc: linux-kernel, linux-kselftest, kernel-team, linux-sound,
	linux-arm-kernel, linux-mm, linux-input, iommu, kvmarm, kvm,
	kvm-riscv, linux-riscv, linux-security-module, linux-fsdevel,
	netdev, linux-actions, mptcp, linux-rtc, linux-sgx, bpf
In-Reply-To: <20240507214254.2787305-6-edliaw@google.com>

On 5/7/24 2:38 PM, Edward Liaw wrote:
> -D_GNU_SOURCE can be de-duplicated here, as it is added by
> KHDR_INCLUDES.
> 
> Signed-off-by: Edward Liaw <edliaw@google.com>
> ---

Most of the churn in these Makefiles can be avoided if it is possible to
take my recommendation on patch 3/5 [1].

However, as it is, it is correct, so if the above does not happen,
please feel free to add:

Reviewed-by: John Hubbard <jhubbard@nvidia.com>


[1] https://lore.kernel.org/all/ec8ab737-a841-4cd5-8ec1-e0a777744262@nvidia.com/

thanks,
-- 
John Hubbard
NVIDIA

>   tools/testing/selftests/futex/functional/Makefile | 2 +-
>   tools/testing/selftests/iommu/Makefile            | 2 --
>   tools/testing/selftests/net/tcp_ao/Makefile       | 2 +-
>   tools/testing/selftests/resctrl/Makefile          | 2 +-
>   4 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/futex/functional/Makefile b/tools/testing/selftests/futex/functional/Makefile
> index a392d0917b4e..f79f9bac7918 100644
> --- a/tools/testing/selftests/futex/functional/Makefile
> +++ b/tools/testing/selftests/futex/functional/Makefile
> @@ -1,6 +1,6 @@
>   # SPDX-License-Identifier: GPL-2.0
>   INCLUDES := -I../include -I../../ $(KHDR_INCLUDES)
> -CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES) $(KHDR_INCLUDES)
> +CFLAGS := $(CFLAGS) -g -O2 -Wall -pthread $(INCLUDES) $(KHDR_INCLUDES)
>   LDLIBS := -lpthread -lrt
>   
>   LOCAL_HDRS := \
> diff --git a/tools/testing/selftests/iommu/Makefile b/tools/testing/selftests/iommu/Makefile
> index 32c5fdfd0eef..fd6477911f24 100644
> --- a/tools/testing/selftests/iommu/Makefile
> +++ b/tools/testing/selftests/iommu/Makefile
> @@ -2,8 +2,6 @@
>   CFLAGS += -Wall -O2 -Wno-unused-function
>   CFLAGS += $(KHDR_INCLUDES)
>   
> -CFLAGS += -D_GNU_SOURCE
> -
>   TEST_GEN_PROGS :=
>   TEST_GEN_PROGS += iommufd
>   TEST_GEN_PROGS += iommufd_fail_nth
> diff --git a/tools/testing/selftests/net/tcp_ao/Makefile b/tools/testing/selftests/net/tcp_ao/Makefile
> index 522d991e310e..c608b1ec02e6 100644
> --- a/tools/testing/selftests/net/tcp_ao/Makefile
> +++ b/tools/testing/selftests/net/tcp_ao/Makefile
> @@ -26,7 +26,7 @@ LIB	:= $(LIBDIR)/libaotst.a
>   LDLIBS	+= $(LIB) -pthread
>   LIBDEPS	:= lib/aolib.h Makefile
>   
> -CFLAGS	:= -Wall -O2 -g -D_GNU_SOURCE -fno-strict-aliasing
> +CFLAGS	:= -Wall -O2 -g -fno-strict-aliasing
>   CFLAGS	+= $(KHDR_INCLUDES)
>   CFLAGS	+= -iquote ./lib/ -I ../../../../include/
>   
> diff --git a/tools/testing/selftests/resctrl/Makefile b/tools/testing/selftests/resctrl/Makefile
> index 2deac2031de9..5073dbc96125 100644
> --- a/tools/testing/selftests/resctrl/Makefile
> +++ b/tools/testing/selftests/resctrl/Makefile
> @@ -1,6 +1,6 @@
>   # SPDX-License-Identifier: GPL-2.0
>   
> -CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE
> +CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2
>   CFLAGS += $(KHDR_INCLUDES)
>   
>   TEST_GEN_PROGS := resctrl_tests



^ permalink raw reply

* Re: [PATCH v2 0/5] Define _GNU_SOURCE for sources using
From: Shuah Khan @ 2024-05-08 23:10 UTC (permalink / raw)
  To: Edward Liaw, shuah, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Catalin Marinas, Will Deacon, Nhat Pham, Johannes Weiner,
	Christian Brauner, Eric Biederman, Kees Cook, OGAWA Hirofumi,
	Thomas Gleixner, Ingo Molnar, Peter Zijlstra, Darren Hart,
	Davidlohr Bueso, André Almeida, Jiri Kosina,
	Benjamin Tissoires, Jason Gunthorpe, Kevin Tian, Andy Lutomirski,
	Will Drewry, Marc Zyngier, Oliver Upton, James Morse,
	Suzuki K Poulose, Zenghui Yu, Paolo Bonzini, Sean Christopherson,
	Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Mickaël Salaün, Paul Moore,
	James Morris, Serge E. Hallyn, Andrew Morton, Seth Forshee,
	Bongsu Jeon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Steffen Klassert, Herbert Xu, Andreas Färber,
	Manivannan Sadhasivam, Matthieu Baerts, Mat Martineau,
	Geliang Tang, Willem de Bruijn, Fenghua Yu, Reinette Chatre,
	Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum
  Cc: linux-kernel, linux-kselftest, kernel-team, linux-sound,
	linux-arm-kernel, linux-mm, linux-input, iommu, kvmarm, kvm,
	kvm-riscv, linux-riscv, linux-security-module, linux-fsdevel,
	netdev, linux-actions, mptcp, linux-rtc, linux-sgx, bpf,
	Shuah Khan
In-Reply-To: <20240507214254.2787305-1-edliaw@google.com>

On 5/7/24 15:38, Edward Liaw wrote:
> 809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
> asprintf into kselftest_harness.h, which is a GNU extension and needs
> _GNU_SOURCE to either be defined prior to including headers or with the
> -D_GNU_SOURCE flag passed to the compiler.
> 
> v1: https://lore.kernel.org/linux-kselftest/20240430235057.1351993-1-edliaw@google.com/
> v2: add -D_GNU_SOURCE to KHDR_INCLUDES so that it is in a single
> location.  Remove #define _GNU_SOURCE from source code to resolve
> redefinition warnings.
> 
> Edward Liaw (5):
>    selftests: Compile kselftest headers with -D_GNU_SOURCE
>    selftests/sgx: Include KHDR_INCLUDES in Makefile

I appled patches 1/5 and 2.5 - The rest need to be split up.

>    selftests: Include KHDR_INCLUDES in Makefile
>    selftests: Drop define _GNU_SOURCE
>    selftests: Drop duplicate -D_GNU_SOURCE
> 

Please split these patches pwe test directory. Otherwise it will
cause merge conflicts which can be hard to resolve.

>   tools/testing/selftests/Makefile                              | 4 ++--
>   tools/testing/selftests/alsa/Makefile                         | 2 +-
>   tools/testing/selftests/arm64/signal/Makefile                 | 2 +-
>   tools/testing/selftests/cachestat/test_cachestat.c            | 2 --
>   tools/testing/selftests/capabilities/test_execve.c            | 2 --
>   tools/testing/selftests/clone3/clone3.c                       | 2 --
>   .../testing/selftests/clone3/clone3_cap_checkpoint_restore.c  | 2 --
>   tools/testing/selftests/clone3/clone3_clear_sighand.c         | 2 --
>   tools/testing/selftests/clone3/clone3_selftests.h             | 1 -
>   tools/testing/selftests/clone3/clone3_set_tid.c               | 2 --
>   tools/testing/selftests/core/close_range_test.c               | 2 --
>   tools/testing/selftests/drivers/dma-buf/udmabuf.c             | 1 -
>   tools/testing/selftests/exec/Makefile                         | 2 +-
>   tools/testing/selftests/fchmodat2/fchmodat2_test.c            | 2 --
>   tools/testing/selftests/filesystems/binderfs/binderfs_test.c  | 2 --
>   tools/testing/selftests/filesystems/devpts_pts.c              | 1 -
>   tools/testing/selftests/filesystems/dnotify_test.c            | 1 -
>   tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c | 2 --
>   tools/testing/selftests/filesystems/eventfd/eventfd_test.c    | 2 --
>   tools/testing/selftests/filesystems/fat/rename_exchange.c     | 2 --
>   tools/testing/selftests/filesystems/overlayfs/Makefile        | 2 +-
>   tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c   | 2 --
>   .../testing/selftests/filesystems/statmount/statmount_test.c  | 3 ---
>   tools/testing/selftests/futex/functional/Makefile             | 2 +-
>   tools/testing/selftests/futex/functional/futex_requeue_pi.c   | 3 ---
>   tools/testing/selftests/hid/Makefile                          | 2 +-
>   tools/testing/selftests/iommu/Makefile                        | 2 --
>   tools/testing/selftests/ipc/msgque.c                          | 1 -
>   tools/testing/selftests/kcmp/kcmp_test.c                      | 2 --
>   tools/testing/selftests/kselftest_harness.h                   | 2 +-
>   tools/testing/selftests/kvm/aarch64/arch_timer.c              | 2 --
>   tools/testing/selftests/kvm/aarch64/page_fault_test.c         | 1 -
>   tools/testing/selftests/kvm/aarch64/psci_test.c               | 3 ---
>   tools/testing/selftests/kvm/aarch64/vgic_init.c               | 1 -
>   tools/testing/selftests/kvm/arch_timer.c                      | 3 ---
>   tools/testing/selftests/kvm/demand_paging_test.c              | 3 ---
>   tools/testing/selftests/kvm/dirty_log_test.c                  | 3 ---
>   tools/testing/selftests/kvm/guest_memfd_test.c                | 2 --
>   tools/testing/selftests/kvm/hardware_disable_test.c           | 3 ---
>   tools/testing/selftests/kvm/include/userfaultfd_util.h        | 3 ---
>   tools/testing/selftests/kvm/kvm_binary_stats_test.c           | 2 --
>   tools/testing/selftests/kvm/kvm_create_max_vcpus.c            | 2 --
>   tools/testing/selftests/kvm/kvm_page_table_test.c             | 3 ---
>   tools/testing/selftests/kvm/lib/assert.c                      | 3 ---
>   tools/testing/selftests/kvm/lib/kvm_util.c                    | 2 --
>   tools/testing/selftests/kvm/lib/memstress.c                   | 2 --
>   tools/testing/selftests/kvm/lib/test_util.c                   | 2 --
>   tools/testing/selftests/kvm/lib/userfaultfd_util.c            | 3 ---
>   tools/testing/selftests/kvm/lib/x86_64/sev.c                  | 1 -
>   tools/testing/selftests/kvm/max_guest_memory_test.c           | 2 --
>   .../testing/selftests/kvm/memslot_modification_stress_test.c  | 3 ---
>   tools/testing/selftests/kvm/riscv/arch_timer.c                | 3 ---
>   tools/testing/selftests/kvm/rseq_test.c                       | 1 -
>   tools/testing/selftests/kvm/s390x/cmma_test.c                 | 2 --
>   tools/testing/selftests/kvm/s390x/sync_regs_test.c            | 2 --
>   tools/testing/selftests/kvm/set_memory_region_test.c          | 1 -
>   tools/testing/selftests/kvm/steal_time.c                      | 1 -
>   tools/testing/selftests/kvm/x86_64/amx_test.c                 | 2 --
>   .../selftests/kvm/x86_64/exit_on_emulation_failure_test.c     | 3 ---
>   tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c            | 2 --
>   tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c             | 2 --
>   tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c             | 1 -
>   tools/testing/selftests/kvm/x86_64/hyperv_ipi.c               | 2 --
>   tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c          | 1 -
>   tools/testing/selftests/kvm/x86_64/hyperv_tlb_flush.c         | 2 --
>   tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c   | 2 --
>   tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c       | 3 ---
>   tools/testing/selftests/kvm/x86_64/platform_info_test.c       | 2 --
>   tools/testing/selftests/kvm/x86_64/pmu_counters_test.c        | 2 --
>   tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c    | 3 ---
>   .../selftests/kvm/x86_64/private_mem_conversions_test.c       | 1 -
>   tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c          | 1 -
>   tools/testing/selftests/kvm/x86_64/set_sregs_test.c           | 1 -
>   .../selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c  | 3 ---
>   tools/testing/selftests/kvm/x86_64/smm_test.c                 | 1 -
>   tools/testing/selftests/kvm/x86_64/state_test.c               | 1 -
>   tools/testing/selftests/kvm/x86_64/sync_regs_test.c           | 2 --
>   tools/testing/selftests/kvm/x86_64/ucna_injection_test.c      | 2 --
>   tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c  | 2 --
>   tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c       | 3 ---
>   tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c        | 1 -
>   .../testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c  | 1 -
>   tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c           | 2 --
>   tools/testing/selftests/kvm/x86_64/xapic_state_test.c         | 1 -
>   tools/testing/selftests/kvm/x86_64/xss_msr_test.c             | 2 --
>   tools/testing/selftests/landlock/base_test.c                  | 2 --
>   tools/testing/selftests/landlock/fs_test.c                    | 2 --
>   tools/testing/selftests/landlock/net_test.c                   | 2 --
>   tools/testing/selftests/landlock/ptrace_test.c                | 2 --
>   tools/testing/selftests/lib.mk                                | 2 +-
>   tools/testing/selftests/lsm/common.c                          | 2 --
>   tools/testing/selftests/lsm/lsm_get_self_attr_test.c          | 2 --
>   tools/testing/selftests/lsm/lsm_list_modules_test.c           | 2 --
>   tools/testing/selftests/lsm/lsm_set_self_attr_test.c          | 2 --
>   tools/testing/selftests/membarrier/membarrier_test_impl.h     | 1 -
>   .../selftests/membarrier/membarrier_test_multi_thread.c       | 1 -
>   .../selftests/membarrier/membarrier_test_single_thread.c      | 1 -
>   tools/testing/selftests/memfd/common.c                        | 1 -
>   tools/testing/selftests/memfd/fuse_test.c                     | 2 --
>   tools/testing/selftests/memfd/memfd_test.c                    | 1 -
>   tools/testing/selftests/mm/cow.c                              | 1 -
>   tools/testing/selftests/mm/gup_longterm.c                     | 1 -
>   tools/testing/selftests/mm/hugepage-mmap.c                    | 1 -
>   tools/testing/selftests/mm/hugepage-mremap.c                  | 2 --
>   tools/testing/selftests/mm/hugetlb-madvise.c                  | 2 --
>   tools/testing/selftests/mm/hugetlb-read-hwpoison.c            | 2 --
>   tools/testing/selftests/mm/khugepaged.c                       | 1 -
>   tools/testing/selftests/mm/ksm_functional_tests.c             | 1 -
>   tools/testing/selftests/mm/madv_populate.c                    | 1 -
>   tools/testing/selftests/mm/map_populate.c                     | 2 --
>   tools/testing/selftests/mm/mdwe_test.c                        | 1 -
>   tools/testing/selftests/mm/memfd_secret.c                     | 2 --
>   tools/testing/selftests/mm/mlock2-tests.c                     | 1 -
>   tools/testing/selftests/mm/mrelease_test.c                    | 1 -
>   tools/testing/selftests/mm/mremap_dontunmap.c                 | 1 -
>   tools/testing/selftests/mm/mremap_test.c                      | 2 --
>   tools/testing/selftests/mm/pagemap_ioctl.c                    | 1 -
>   tools/testing/selftests/mm/pkey-helpers.h                     | 1 -
>   tools/testing/selftests/mm/protection_keys.c                  | 1 -
>   tools/testing/selftests/mm/split_huge_page_test.c             | 2 --
>   tools/testing/selftests/mm/thuge-gen.c                        | 2 --
>   tools/testing/selftests/mm/uffd-common.h                      | 1 -
>   tools/testing/selftests/mount_setattr/mount_setattr_test.c    | 1 -
>   .../move_mount_set_group/move_mount_set_group_test.c          | 1 -
>   tools/testing/selftests/nci/Makefile                          | 2 +-
>   tools/testing/selftests/net/af_unix/diag_uid.c                | 2 --
>   tools/testing/selftests/net/af_unix/scm_pidfd.c               | 1 -
>   tools/testing/selftests/net/af_unix/unix_connect.c            | 2 --
>   tools/testing/selftests/net/csum.c                            | 3 ---
>   tools/testing/selftests/net/gro.c                             | 3 ---
>   tools/testing/selftests/net/ip_defrag.c                       | 3 ---
>   tools/testing/selftests/net/ipsec.c                           | 3 ---
>   tools/testing/selftests/net/ipv6_flowlabel.c                  | 3 ---
>   tools/testing/selftests/net/ipv6_flowlabel_mgr.c              | 3 ---
>   tools/testing/selftests/net/mptcp/mptcp_connect.c             | 3 ---
>   tools/testing/selftests/net/mptcp/mptcp_inq.c                 | 3 ---
>   tools/testing/selftests/net/mptcp/mptcp_sockopt.c             | 3 ---
>   tools/testing/selftests/net/msg_zerocopy.c                    | 3 ---
>   tools/testing/selftests/net/nettest.c                         | 2 --
>   tools/testing/selftests/net/psock_fanout.c                    | 3 ---
>   tools/testing/selftests/net/psock_snd.c                       | 3 ---
>   tools/testing/selftests/net/reuseport_addr_any.c              | 3 ---
>   tools/testing/selftests/net/reuseport_bpf_cpu.c               | 3 ---
>   tools/testing/selftests/net/reuseport_bpf_numa.c              | 3 ---
>   tools/testing/selftests/net/reuseport_dualstack.c             | 3 ---
>   tools/testing/selftests/net/so_incoming_cpu.c                 | 1 -
>   tools/testing/selftests/net/so_netns_cookie.c                 | 1 -
>   tools/testing/selftests/net/so_txtime.c                       | 3 ---
>   tools/testing/selftests/net/tap.c                             | 3 ---
>   tools/testing/selftests/net/tcp_ao/Makefile                   | 2 +-
>   tools/testing/selftests/net/tcp_fastopen_backup_key.c         | 1 -
>   tools/testing/selftests/net/tcp_inq.c                         | 2 --
>   tools/testing/selftests/net/tcp_mmap.c                        | 1 -
>   tools/testing/selftests/net/tls.c                             | 3 ---
>   tools/testing/selftests/net/toeplitz.c                        | 3 ---
>   tools/testing/selftests/net/tun.c                             | 3 ---
>   tools/testing/selftests/net/txring_overwrite.c                | 3 ---
>   tools/testing/selftests/net/txtimestamp.c                     | 3 ---
>   tools/testing/selftests/net/udpgso.c                          | 3 ---
>   tools/testing/selftests/net/udpgso_bench_rx.c                 | 3 ---
>   tools/testing/selftests/net/udpgso_bench_tx.c                 | 3 ---
>   tools/testing/selftests/perf_events/remove_on_exec.c          | 2 --
>   tools/testing/selftests/perf_events/sigtrap_threads.c         | 2 --
>   tools/testing/selftests/pid_namespace/regression_enomem.c     | 1 -
>   tools/testing/selftests/pidfd/pidfd.h                         | 1 -
>   tools/testing/selftests/pidfd/pidfd_fdinfo_test.c             | 2 --
>   tools/testing/selftests/pidfd/pidfd_getfd_test.c              | 2 --
>   tools/testing/selftests/pidfd/pidfd_open_test.c               | 2 --
>   tools/testing/selftests/pidfd/pidfd_poll_test.c               | 2 --
>   tools/testing/selftests/pidfd/pidfd_setns_test.c              | 2 --
>   tools/testing/selftests/pidfd/pidfd_test.c                    | 2 --
>   tools/testing/selftests/pidfd/pidfd_wait.c                    | 2 --
>   tools/testing/selftests/prctl/Makefile                        | 2 ++
>   tools/testing/selftests/proc/Makefile                         | 2 +-
>   tools/testing/selftests/ptrace/get_set_sud.c                  | 1 -
>   tools/testing/selftests/ptrace/peeksiginfo.c                  | 1 -
>   tools/testing/selftests/resctrl/Makefile                      | 2 +-
>   tools/testing/selftests/riscv/mm/Makefile                     | 2 +-
>   tools/testing/selftests/rseq/basic_percpu_ops_test.c          | 1 -
>   tools/testing/selftests/rseq/basic_test.c                     | 2 --
>   tools/testing/selftests/rseq/param_test.c                     | 1 -
>   tools/testing/selftests/rseq/rseq.c                           | 2 --
>   tools/testing/selftests/rtc/Makefile                          | 2 +-
>   tools/testing/selftests/seccomp/seccomp_benchmark.c           | 1 -
>   tools/testing/selftests/seccomp/seccomp_bpf.c                 | 2 --
>   tools/testing/selftests/sgx/Makefile                          | 2 +-
>   tools/testing/selftests/sgx/sigstruct.c                       | 1 -
>   tools/testing/selftests/tmpfs/Makefile                        | 2 +-
>   tools/testing/selftests/user_events/abi_test.c                | 2 --
>   tools/testing/selftests/x86/amx.c                             | 2 --
>   tools/testing/selftests/x86/check_initial_reg_state.c         | 3 ---
>   tools/testing/selftests/x86/corrupt_xstate_header.c           | 3 ---
>   tools/testing/selftests/x86/entry_from_vm86.c                 | 3 ---
>   tools/testing/selftests/x86/fsgsbase.c                        | 2 --
>   tools/testing/selftests/x86/fsgsbase_restore.c                | 2 --
>   tools/testing/selftests/x86/ioperm.c                          | 2 --
>   tools/testing/selftests/x86/iopl.c                            | 2 --
>   tools/testing/selftests/x86/lam.c                             | 1 -
>   tools/testing/selftests/x86/ldt_gdt.c                         | 2 --
>   tools/testing/selftests/x86/mov_ss_trap.c                     | 2 --
>   tools/testing/selftests/x86/nx_stack.c                        | 2 --
>   tools/testing/selftests/x86/ptrace_syscall.c                  | 2 --
>   tools/testing/selftests/x86/sigaltstack.c                     | 2 --
>   tools/testing/selftests/x86/sigreturn.c                       | 3 ---
>   tools/testing/selftests/x86/single_step_syscall.c             | 3 ---
>   tools/testing/selftests/x86/syscall_arg_fault.c               | 3 ---
>   tools/testing/selftests/x86/syscall_numbering.c               | 3 ---
>   tools/testing/selftests/x86/sysret_rip.c                      | 3 ---
>   tools/testing/selftests/x86/sysret_ss_attrs.c                 | 3 ---
>   tools/testing/selftests/x86/test_FCMOV.c                      | 4 ----
>   tools/testing/selftests/x86/test_FCOMI.c                      | 4 ----
>   tools/testing/selftests/x86/test_FISTTP.c                     | 4 ----
>   tools/testing/selftests/x86/test_mremap_vdso.c                | 1 -
>   tools/testing/selftests/x86/test_shadow_stack.c               | 3 ---
>   tools/testing/selftests/x86/test_syscall_vdso.c               | 4 ----
>   tools/testing/selftests/x86/test_vsyscall.c                   | 3 ---
>   tools/testing/selftests/x86/unwind_vdso.c                     | 3 ---
>   tools/testing/selftests/x86/vdso_restorer.c                   | 3 ---
>   218 files changed, 20 insertions(+), 426 deletions(-)
> 
> --
> 2.45.0.rc1.225.g2a3ae87e7f-goog
> 
> 

thanks,
-- Shuah

^ permalink raw reply

* Re: [PATCH v2 3/5] selftests: Include KHDR_INCLUDES in Makefile
From: Edward Liaw @ 2024-05-09  0:29 UTC (permalink / raw)
  To: John Hubbard
  Cc: shuah, Mark Brown, Jaroslav Kysela, Takashi Iwai, Catalin Marinas,
	Will Deacon, Nhat Pham, Johannes Weiner, Christian Brauner,
	Eric Biederman, Kees Cook, OGAWA Hirofumi, Thomas Gleixner,
	Ingo Molnar, Peter Zijlstra, Darren Hart, Davidlohr Bueso,
	André Almeida, Jiri Kosina, Benjamin Tissoires,
	Jason Gunthorpe, Kevin Tian, Andy Lutomirski, Will Drewry,
	Marc Zyngier, Oliver Upton, James Morse, Suzuki K Poulose,
	Zenghui Yu, Paolo Bonzini, Sean Christopherson, Anup Patel,
	Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Mickaël Salaün, Paul Moore,
	James Morris, Serge E. Hallyn, Andrew Morton, Seth Forshee,
	Bongsu Jeon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Steffen Klassert, Herbert Xu, Andreas Färber,
	Manivannan Sadhasivam, Matthieu Baerts, Mat Martineau,
	Geliang Tang, Willem de Bruijn, Fenghua Yu, Reinette Chatre,
	Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum, linux-kernel, linux-kselftest, kernel-team,
	linux-sound, linux-arm-kernel, linux-mm, linux-input, iommu,
	kvmarm, kvm, kvm-riscv, linux-riscv, linux-security-module,
	linux-fsdevel, netdev, linux-actions, mptcp, linux-rtc, linux-sgx,
	bpf
In-Reply-To: <ec8ab737-a841-4cd5-8ec1-e0a777744262@nvidia.com>

On Wed, May 8, 2024 at 2:41 PM John Hubbard <jhubbard@nvidia.com> wrote:
>
> On 5/7/24 2:38 PM, Edward Liaw wrote:
> > Add KHDR_INCLUDES to CFLAGS to pull in the kselftest harness
> > dependencies (-D_GNU_SOURCE).
> >
> > Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
> > Signed-off-by: Edward Liaw <edliaw@google.com>
> > ---
> >   tools/testing/selftests/alsa/Makefile                  | 2 +-
> >   tools/testing/selftests/arm64/signal/Makefile          | 2 +-
> >   tools/testing/selftests/exec/Makefile                  | 2 +-
> >   tools/testing/selftests/filesystems/overlayfs/Makefile | 2 +-
> >   tools/testing/selftests/hid/Makefile                   | 2 +-
> >   tools/testing/selftests/nci/Makefile                   | 2 +-
> >   tools/testing/selftests/prctl/Makefile                 | 2 ++
> >   tools/testing/selftests/proc/Makefile                  | 2 +-
> >   tools/testing/selftests/riscv/mm/Makefile              | 2 +-
> >   tools/testing/selftests/rtc/Makefile                   | 2 +-
> >   tools/testing/selftests/tmpfs/Makefile                 | 2 +-
> >   11 files changed, 12 insertions(+), 10 deletions(-)
>
> Hi Edward,
>
> Seeing as how these all include lib.mk, and all use CFLAGS, is there
> any reason not to simply fix this in lib.mk instead? Like this:
>
> diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
> index 7fa4a96e26ed..df72610e0d2b 100644
> --- a/tools/testing/selftests/lib.mk
> +++ b/tools/testing/selftests/lib.mk
> @@ -170,6 +170,8 @@ clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_dir)
>   CFLAGS += $(USERCFLAGS)
>   LDFLAGS += $(USERLDFLAGS)
>
> +CFLAGS += $(KHDR_INCLUDES)
> +
>   # When make O= with kselftest target from main level
>   # the following aren't defined.
>   #
>

Or how about just adding -D_GNU_SOURCE to CFLAGS then?



>
> thanks,
> --
> John Hubbard
> NVIDIA
>
> >
> > diff --git a/tools/testing/selftests/alsa/Makefile b/tools/testing/selftests/alsa/Makefile
> > index 5af9ba8a4645..9a0ef194522c 100644
> > --- a/tools/testing/selftests/alsa/Makefile
> > +++ b/tools/testing/selftests/alsa/Makefile
> > @@ -6,7 +6,7 @@ LDLIBS += $(shell pkg-config --libs alsa)
> >   ifeq ($(LDLIBS),)
> >   LDLIBS += -lasound
> >   endif
> > -CFLAGS += -L$(OUTPUT) -Wl,-rpath=./
> > +CFLAGS += $(KHDR_INCLUDES) -L$(OUTPUT) -Wl,-rpath=./
> >
> >   LDLIBS+=-lpthread
> >
> > diff --git a/tools/testing/selftests/arm64/signal/Makefile b/tools/testing/selftests/arm64/signal/Makefile
> > index 8f5febaf1a9a..ae682ade615d 100644
> > --- a/tools/testing/selftests/arm64/signal/Makefile
> > +++ b/tools/testing/selftests/arm64/signal/Makefile
> > @@ -2,7 +2,7 @@
> >   # Copyright (C) 2019 ARM Limited
> >
> >   # Additional include paths needed by kselftest.h and local headers
> > -CFLAGS += -D_GNU_SOURCE -std=gnu99 -I.
> > +CFLAGS += $(KHDR_INCLUDES) -std=gnu99 -I.
> >
> >   SRCS := $(filter-out testcases/testcases.c,$(wildcard testcases/*.c))
> >   PROGS := $(patsubst %.c,%,$(SRCS))
> > diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftests/exec/Makefile
> > index fb4472ddffd8..15e78ec7c55e 100644
> > --- a/tools/testing/selftests/exec/Makefile
> > +++ b/tools/testing/selftests/exec/Makefile
> > @@ -1,7 +1,7 @@
> >   # SPDX-License-Identifier: GPL-2.0
> >   CFLAGS = -Wall
> >   CFLAGS += -Wno-nonnull
> > -CFLAGS += -D_GNU_SOURCE
> > +CFLAGS += $(KHDR_INCLUDES)
> >
> >   TEST_PROGS := binfmt_script.py
> >   TEST_GEN_PROGS := execveat load_address_4096 load_address_2097152 load_address_16777216 non-regular
> > diff --git a/tools/testing/selftests/filesystems/overlayfs/Makefile b/tools/testing/selftests/filesystems/overlayfs/Makefile
> > index 56b2b48a765b..6c29c963c7a8 100644
> > --- a/tools/testing/selftests/filesystems/overlayfs/Makefile
> > +++ b/tools/testing/selftests/filesystems/overlayfs/Makefile
> > @@ -2,6 +2,6 @@
> >
> >   TEST_GEN_PROGS := dev_in_maps
> >
> > -CFLAGS := -Wall -Werror
> > +CFLAGS := -Wall -Werror $(KHDR_INCLUDES)
> >
> >   include ../../lib.mk
> > diff --git a/tools/testing/selftests/hid/Makefile b/tools/testing/selftests/hid/Makefile
> > index 2b5ea18bde38..0661b34488ef 100644
> > --- a/tools/testing/selftests/hid/Makefile
> > +++ b/tools/testing/selftests/hid/Makefile
> > @@ -21,7 +21,7 @@ CXX ?= $(CROSS_COMPILE)g++
> >
> >   HOSTPKG_CONFIG := pkg-config
> >
> > -CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(OUTPUT)
> > +CFLAGS += -g -O0 -rdynamic -Wall -Werror $(KHDR_INCLUDES) -I$(OUTPUT)
> >   CFLAGS += -I$(OUTPUT)/tools/include
> >
> >   LDLIBS += -lelf -lz -lrt -lpthread
> > diff --git a/tools/testing/selftests/nci/Makefile b/tools/testing/selftests/nci/Makefile
> > index 47669a1d6a59..bbc5b8ec3b17 100644
> > --- a/tools/testing/selftests/nci/Makefile
> > +++ b/tools/testing/selftests/nci/Makefile
> > @@ -1,5 +1,5 @@
> >   # SPDX-License-Identifier: GPL-2.0
> > -CFLAGS += -Wl,-no-as-needed -Wall
> > +CFLAGS += -Wl,-no-as-needed -Wall $(KHDR_INCLUDES)
> >   LDFLAGS += -lpthread
> >
> >   TEST_GEN_PROGS := nci_dev
> > diff --git a/tools/testing/selftests/prctl/Makefile b/tools/testing/selftests/prctl/Makefile
> > index 01dc90fbb509..1a0aefec9d6f 100644
> > --- a/tools/testing/selftests/prctl/Makefile
> > +++ b/tools/testing/selftests/prctl/Makefile
> > @@ -6,6 +6,8 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
> >   ifeq ($(ARCH),x86)
> >   TEST_PROGS := disable-tsc-ctxt-sw-stress-test disable-tsc-on-off-stress-test \
> >               disable-tsc-test set-anon-vma-name-test set-process-name
> > +
> > +CFLAGS += $(KHDR_INCLUDES)
> >   all: $(TEST_PROGS)
> >
> >   include ../lib.mk
> > diff --git a/tools/testing/selftests/proc/Makefile b/tools/testing/selftests/proc/Makefile
> > index cd95369254c0..9596014c10a0 100644
> > --- a/tools/testing/selftests/proc/Makefile
> > +++ b/tools/testing/selftests/proc/Makefile
> > @@ -1,6 +1,6 @@
> >   # SPDX-License-Identifier: GPL-2.0-only
> >   CFLAGS += -Wall -O2 -Wno-unused-function
> > -CFLAGS += -D_GNU_SOURCE
> > +CFLAGS += $(KHDR_INCLUDES)
> >   LDFLAGS += -pthread
> >
> >   TEST_GEN_PROGS :=
> > diff --git a/tools/testing/selftests/riscv/mm/Makefile b/tools/testing/selftests/riscv/mm/Makefile
> > index c333263f2b27..715a21241113 100644
> > --- a/tools/testing/selftests/riscv/mm/Makefile
> > +++ b/tools/testing/selftests/riscv/mm/Makefile
> > @@ -3,7 +3,7 @@
> >   # Originally tools/testing/arm64/abi/Makefile
> >
> >   # Additional include paths needed by kselftest.h and local headers
> > -CFLAGS += -D_GNU_SOURCE -std=gnu99 -I.
> > +CFLAGS += $(KHDR_INCLUDES) -std=gnu99 -I.
> >
> >   TEST_GEN_FILES := mmap_default mmap_bottomup
> >
> > diff --git a/tools/testing/selftests/rtc/Makefile b/tools/testing/selftests/rtc/Makefile
> > index 55198ecc04db..654f9d58da3c 100644
> > --- a/tools/testing/selftests/rtc/Makefile
> > +++ b/tools/testing/selftests/rtc/Makefile
> > @@ -1,5 +1,5 @@
> >   # SPDX-License-Identifier: GPL-2.0
> > -CFLAGS += -O3 -Wl,-no-as-needed -Wall
> > +CFLAGS += -O3 -Wl,-no-as-needed -Wall $(KHDR_INCLUDES)
> >   LDLIBS += -lrt -lpthread -lm
> >
> >   TEST_GEN_PROGS = rtctest
> > diff --git a/tools/testing/selftests/tmpfs/Makefile b/tools/testing/selftests/tmpfs/Makefile
> > index aa11ccc92e5b..bcdc1bb6d2e6 100644
> > --- a/tools/testing/selftests/tmpfs/Makefile
> > +++ b/tools/testing/selftests/tmpfs/Makefile
> > @@ -1,6 +1,6 @@
> >   # SPDX-License-Identifier: GPL-2.0-only
> >   CFLAGS += -Wall -O2
> > -CFLAGS += -D_GNU_SOURCE
> > +CFLAGS += $(KHDR_INCLUDES)
> >
> >   TEST_GEN_PROGS :=
> >   TEST_GEN_PROGS += bug-link-o-tmpfile
>
>

^ permalink raw reply

* Re: [PATCH v2 3/5] selftests: Include KHDR_INCLUDES in Makefile
From: John Hubbard @ 2024-05-09  1:03 UTC (permalink / raw)
  To: Edward Liaw
  Cc: shuah, Mark Brown, Jaroslav Kysela, Takashi Iwai, Catalin Marinas,
	Will Deacon, Nhat Pham, Johannes Weiner, Christian Brauner,
	Eric Biederman, Kees Cook, OGAWA Hirofumi, Thomas Gleixner,
	Ingo Molnar, Peter Zijlstra, Darren Hart, Davidlohr Bueso,
	André Almeida, Jiri Kosina, Benjamin Tissoires,
	Jason Gunthorpe, Kevin Tian, Andy Lutomirski, Will Drewry,
	Marc Zyngier, Oliver Upton, James Morse, Suzuki K Poulose,
	Zenghui Yu, Paolo Bonzini, Sean Christopherson, Anup Patel,
	Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Mickaël Salaün, Paul Moore,
	James Morris, Serge E. Hallyn, Andrew Morton, Seth Forshee,
	Bongsu Jeon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Steffen Klassert, Herbert Xu, Andreas Färber,
	Manivannan Sadhasivam, Matthieu Baerts, Mat Martineau,
	Geliang Tang, Willem de Bruijn, Fenghua Yu, Reinette Chatre,
	Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum, linux-kernel, linux-kselftest, kernel-team,
	linux-sound, linux-arm-kernel, linux-mm, linux-input, iommu,
	kvmarm, kvm, kvm-riscv, linux-riscv, linux-security-module,
	linux-fsdevel, netdev, linux-actions, mptcp, linux-rtc, linux-sgx,
	bpf
In-Reply-To: <CAG4es9XPLhHhH-Hfm3_m5zLLtiB1zme8pAazMhErMpHqJcAMmw@mail.gmail.com>

On 5/8/24 5:29 PM, Edward Liaw wrote:
> On Wed, May 8, 2024 at 2:41 PM John Hubbard <jhubbard@nvidia.com> wrote:
>> On 5/7/24 2:38 PM, Edward Liaw wrote:
...
>> Seeing as how these all include lib.mk, and all use CFLAGS, is there
>> any reason not to simply fix this in lib.mk instead? Like this:
>>
>> diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
>> index 7fa4a96e26ed..df72610e0d2b 100644
>> --- a/tools/testing/selftests/lib.mk
>> +++ b/tools/testing/selftests/lib.mk
>> @@ -170,6 +170,8 @@ clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_dir)
>>    CFLAGS += $(USERCFLAGS)
>>    LDFLAGS += $(USERLDFLAGS)
>>
>> +CFLAGS += $(KHDR_INCLUDES)
>> +
>>    # When make O= with kselftest target from main level
>>    # the following aren't defined.
>>    #
>>
> 
> Or how about just adding -D_GNU_SOURCE to CFLAGS then?

Yes, that would also work. I think either one would be good.


thanks,
-- 
John Hubbard
NVIDIA


^ permalink raw reply

* [PATCH v2 0/1] Input: add gamecube adapter support
From: Milas Robin @ 2024-05-09  1:12 UTC (permalink / raw)
  To: dmitry.torokhov; +Cc: linux-input, milas.robin
In-Reply-To: <ZjqV_uMHj8Q6VG96@google.com>

> > +struct ngc_data {
> > +	char phys[64];
> > +
> > +	struct usb_device *udev;
> > +	struct usb_interface *intf;
> > +
> > +	struct urb *irq_in;
> > +	u8 *idata;
> > +	dma_addr_t idata_dma;
> > +	spinlock_t idata_lock;
> > +
> > +	struct urb *irq_out;
> > +	struct usb_anchor irq_out_anchor;
> > +	u8 *odata;
> > +	dma_addr_t odata_dma;
> > +	spinlock_t odata_lock;		/* output data */
> > +	bool irq_out_active;		/* we must not use an active URB */
> 
> I think all of this starting with irq_out should be under #ifdef
> CONFIG_JOYSTICK_NGC_FF.

Unfortunately, a first packet must be sent to the adapter before it start
sending controllers values.

I was able to remove the irq_out_active field with some rewrite.
Technically it would be possible to remove the odata_lock field too but with
the current code I have it would mean putting a lockdep_assert_held into
an ifndef which feels weird to me.

> > +static int ngc_queue_rumble(struct ngc_data *gdata)
> > +{
> > +	int error;
> > +
> 
> Please check irq_out_active flag here and also provide a stub for
> !CONFIG_JOYSTICK_NGC_FF so you do not need to sprinkle #ifdef checks..

I changed the way my code is cut to reduce the number of #ifdef as best as I can

I incorporated every changes on this new version

Thank you for your review

Robin

^ permalink raw reply

* [PATCH v2 1/1] Input: add gamecube adapter support
From: Milas Robin @ 2024-05-09  1:14 UTC (permalink / raw)
  To: milas.robin; +Cc: dmitry.torokhov, linux-input
In-Reply-To: <PA4P189MB146928AA17984371B61EB909FAE62@PA4P189MB1469.EURP189.PROD.OUTLOOK.COM>

Add support for the Wii U / Nintendo Switch gamecube controller adapter

Signed-off-by: Milas Robin <milas.robin@live.fr>
---
 drivers/input/joystick/Kconfig            |  20 +
 drivers/input/joystick/Makefile           |   1 +
 drivers/input/joystick/gamecube-adapter.c | 564 ++++++++++++++++++++++
 3 files changed, 585 insertions(+)
 create mode 100644 drivers/input/joystick/gamecube-adapter.c

diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
index 7755e5b454d2..18ab1f893ed0 100644
--- a/drivers/input/joystick/Kconfig
+++ b/drivers/input/joystick/Kconfig
@@ -422,4 +422,24 @@ config JOYSTICK_SEESAW
 	  To compile this driver as a module, choose M here: the module will be
 	  called adafruit-seesaw.
 
+config JOYSTICK_NGC
+	tristate "Nintendo GameCube adapter support"
+	depends on USB_ARCH_HAS_HCD
+	select USB
+	help
+	  Say Y here if you want to use Nintendo GameCube adapter with
+	  your computer.
+	  Make sure to say Y to "Joystick support" (CONFIG_INPUT_JOYDEV)
+	  and/or "Event interface support" (CONFIG_INPUT_EVDEV) as well.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called gamecube_adapter.
+
+config JOYSTICK_NGC_FF
+	bool "Nintendo GameCube adapter rumble support"
+	depends on JOYSTICK_NGC && INPUT
+	select INPUT_FF_MEMLESS
+	help
+	  Say Y here if you want to take advantage of GameCube controller rumble features.
+
 endif
diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile
index 9976f596a920..db0f137ba57f 100644
--- a/drivers/input/joystick/Makefile
+++ b/drivers/input/joystick/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_JOYSTICK_JOYDUMP)		+= joydump.o
 obj-$(CONFIG_JOYSTICK_MAGELLAN)		+= magellan.o
 obj-$(CONFIG_JOYSTICK_MAPLE)		+= maplecontrol.o
 obj-$(CONFIG_JOYSTICK_N64)		+= n64joy.o
+obj-$(CONFIG_JOYSTICK_NGC)		+= gamecube-adapter.o
 obj-$(CONFIG_JOYSTICK_PSXPAD_SPI)	+= psxpad-spi.o
 obj-$(CONFIG_JOYSTICK_PXRC)		+= pxrc.o
 obj-$(CONFIG_JOYSTICK_QWIIC)		+= qwiic-joystick.o
diff --git a/drivers/input/joystick/gamecube-adapter.c b/drivers/input/joystick/gamecube-adapter.c
new file mode 100644
index 000000000000..abc0da9ab8d2
--- /dev/null
+++ b/drivers/input/joystick/gamecube-adapter.c
@@ -0,0 +1,564 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *  Copyright (c) 2024 Milas Robin
+ *
+ *  Based on the work of:
+ *	Michael Lelli
+ *	Dolphin Emulator project
+ */
+
+#include <linux/usb.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/input.h>
+#include <linux/usb/input.h>
+
+/* Did not use usb-hid as it is not an hid driver */
+#define USB_VENDOR_ID_NINTENDO		0x057e
+#define USB_DEVICE_ID_NINTENDO_GCADAPTER 0x0337
+
+#define EP_IN  0x81
+#define EP_OUT 0x02
+
+#define GCC_OUT_PKT_LEN 5
+#define GCC_IN_PKT_LEN 37
+
+#define CONTROLLER_COUNT 4
+
+enum gamecube_status {
+	GAMECUBE_NONE,
+	GAMECUBE_WIRED = 0x10,
+	GAMECUBE_WIRELESS = 0x20,
+};
+
+struct gcc_data {
+	struct ngc_data *adapter;
+	struct input_dev *input;
+	u8 no;
+	u8 status;
+	bool enable;
+};
+
+struct ngc_data {
+	char phys[64];
+
+	struct usb_device *udev;
+	struct usb_interface *intf;
+
+	struct urb *irq_in;
+	u8 *idata;
+	dma_addr_t idata_dma;
+	spinlock_t idata_lock;
+
+	struct urb *irq_out;
+	u8 *odata;
+	dma_addr_t odata_dma;
+	spinlock_t odata_lock;		/* output data */
+#ifdef CONFIG_JOYSTICK_NGC_FF
+	bool irq_out_active;		/* we must not use an active URB */
+	u8 odata_rumbles[CONTROLLER_COUNT];
+	bool rumble_changed;		/* if rumble need update*/
+#endif
+
+	struct gcc_data controllers[CONTROLLER_COUNT];
+	struct work_struct work;	/* create/delete controller input files */
+};
+
+struct ngc_key {
+	u8		byte;
+	u8		bit;
+	unsigned int	keycode;
+};
+
+static const struct ngc_key ngc_keys[] = {
+	{ 1, 0, BTN_A },
+	{ 1, 1, BTN_B },
+	{ 1, 2, BTN_X },
+	{ 1, 3, BTN_Y },
+	{ 1, 4, BTN_DPAD_LEFT },
+	{ 1, 5, BTN_DPAD_RIGHT },
+	{ 1, 6, BTN_DPAD_DOWN },
+	{ 1, 7, BTN_DPAD_UP },
+	{ 2, 0, BTN_START },
+	{ 2, 1, BTN_TR2 },
+	{ 2, 2, BTN_TR },
+	{ 2, 3, BTN_TL },
+};
+
+static int ngc_send_urb(struct ngc_data *gdata)
+{
+	int error;
+
+	lockdep_assert_held(&gdata->odata_lock);
+
+	error = usb_submit_urb(gdata->irq_out, GFP_ATOMIC);
+	if (error) {
+		dev_err(&gdata->intf->dev,
+			"%s - usb_submit_urb failed with result %d\n",
+			__func__, error);
+		error = -EIO;
+
+	}
+#ifdef CONFIG_JOYSTICK_NGC_FF
+	gdata->irq_out_active = error == 0;
+#endif
+	return error;
+}
+
+#ifdef CONFIG_JOYSTICK_NGC_FF
+
+static bool ngc_prepare_next_packet(struct ngc_data *gdata)
+{
+	lockdep_assert_held(&gdata->odata_lock);
+
+	if (!gdata->rumble_changed)
+		return false;
+	gdata->rumble_changed = false;
+	memcpy(gdata->odata + 1, gdata->odata_rumbles,
+			 sizeof(gdata->odata_rumbles));
+	gdata->odata[0] = 0x11;
+	gdata->irq_out->transfer_buffer_length = 5;
+	return true;
+}
+
+static int ngc_set_rumble_value(struct ngc_data *gdata, u8 controller, bool value)
+{
+	if (controller > CONTROLLER_COUNT)
+		return -EINVAL;
+	guard(spinlock_irqsave)(&gdata->odata_lock);
+	if (gdata->odata_rumbles[controller] == value)
+		return 0;
+	gdata->odata_rumbles[controller] = value;
+	gdata->rumble_changed = true;
+	if (gdata->irq_out_active)
+		return 0;
+	ngc_prepare_next_packet(gdata);
+	return ngc_send_urb(gdata);
+}
+
+static int ngc_rumble_play(struct input_dev *dev, void *data,
+			      struct ff_effect *eff)
+{
+	struct gcc_data *gccdata = input_get_drvdata(dev);
+
+	/*
+	 * The gamecube controller  supports only a single rumble motor so if any
+	 * magnitude is set to non-zero then we start the rumble motor. If both are
+	 * set to zero, we stop the rumble motor.
+	 */
+
+	return ngc_set_rumble_value(gccdata->adapter, gccdata->no,
+				    eff->u.rumble.strong_magnitude ||
+					eff->u.rumble.weak_magnitude);
+}
+static int ngc_init_ff(struct gcc_data *gccdev)
+{
+	input_set_capability(gccdev->input, EV_FF, FF_RUMBLE);
+
+	return input_ff_create_memless(gccdev->input, NULL, ngc_rumble_play);
+}
+#else
+static int ngc_init_ff(struct gcc_data *gccdev) { return 0; }
+static bool ngc_prepare_next_packet(struct ngc_data *gdata) { return false; }
+#endif
+
+static void ngc_irq_out(struct urb *urb)
+{
+	struct ngc_data *gdata = urb->context;
+	struct device *dev = &gdata->intf->dev;
+
+	guard(spinlock_irqsave)(&gdata->odata_lock);
+
+	switch (urb->status) {
+	case 0:
+		/* success */
+		break;
+	case -ECONNRESET:
+	case -ENOENT:
+	case -ESHUTDOWN:
+		/* this urb is terminated, clean up */
+		dev_dbg(dev, "%s - urb shutting down with status: %d\n",
+			__func__, urb->status);
+		goto shutdown;
+
+	default:
+		dev_dbg(dev, "%s - nonzero urb status received: %d\n",
+			__func__, urb->status);
+		goto resubmit;
+	}
+	if (!ngc_prepare_next_packet(gdata))
+		goto shutdown;
+resubmit:
+	ngc_send_urb(gdata);
+	return;
+shutdown:
+#ifdef CONFIG_JOYSTICK_NGC_FF
+	gdata->irq_out_active = false;
+#endif
+}
+
+static int ngc_init_output(struct ngc_data *gdata,
+			 struct usb_endpoint_descriptor *irq)
+{
+	int error = -ENOMEM;
+
+	gdata->odata = usb_alloc_coherent(gdata->udev, GCC_OUT_PKT_LEN, GFP_KERNEL,
+			 &gdata->odata_dma);
+	if (!gdata->odata)
+		return error;
+
+	spin_lock_init(&gdata->odata_lock);
+
+	gdata->irq_out = usb_alloc_urb(0, GFP_KERNEL);
+
+	if (!gdata->irq_out)
+		goto err_free_coherent;
+
+	usb_fill_int_urb(gdata->irq_out, gdata->udev,
+			 usb_sndintpipe(gdata->udev, irq->bEndpointAddress),
+			 gdata->odata, GCC_OUT_PKT_LEN, ngc_irq_out, gdata,
+			 irq->bInterval);
+	gdata->irq_out->transfer_dma = gdata->odata_dma;
+	gdata->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+	return 0;
+
+err_free_coherent:
+	usb_free_coherent(gdata->udev, GCC_OUT_PKT_LEN, gdata->odata,
+			 gdata->odata_dma);
+	return error;
+}
+
+static void ngc_deinit_output(struct ngc_data *gdata)
+{
+	usb_free_urb(gdata->irq_out);
+	usb_free_coherent(gdata->udev, GCC_OUT_PKT_LEN, gdata->odata,
+			 gdata->odata_dma);
+}
+
+static void gcc_input(struct gcc_data *gccdata, const u8 *keys)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(ngc_keys); i++) {
+		input_report_key(gccdata->input, ngc_keys[i].keycode,
+			!!(keys[ngc_keys[i].byte] & BIT(ngc_keys[i].bit)));
+	}
+	input_report_abs(gccdata->input, ABS_X, keys[3]);
+	input_report_abs(gccdata->input, ABS_Y, keys[4] ^ 0xFF);
+	input_report_abs(gccdata->input, ABS_RX, keys[5]);
+	input_report_abs(gccdata->input, ABS_RY, keys[6] ^ 0xFF);
+	input_report_abs(gccdata->input, ABS_Z, keys[7]);
+	input_report_abs(gccdata->input, ABS_RZ, keys[8]);
+
+	input_sync(gccdata->input);
+}
+
+
+static u8 ngc_connected_type(u8 status)
+{
+	u8 type = status & (GAMECUBE_WIRED | GAMECUBE_WIRELESS);
+
+	switch (type) {
+	case GAMECUBE_WIRED:
+	case GAMECUBE_WIRELESS:
+		return type;
+	default:
+		return 0;
+	}
+}
+
+static int ngc_controller_init(struct gcc_data *gccdev, u8 status)
+{
+	int i;
+	int error;
+
+	gccdev->input = input_allocate_device();
+	if (!gccdev->input)
+		return -ENOMEM;
+
+	input_set_drvdata(gccdev->input, gccdev);
+	usb_to_input_id(gccdev->adapter->udev, &gccdev->input->id);
+	gccdev->input->name = "Nintendo GameCube Controller";
+	gccdev->input->phys = gccdev->adapter->phys;
+
+	set_bit(EV_KEY, gccdev->input->evbit);
+	for (i = 0; i < ARRAY_SIZE(ngc_keys); i++)
+		set_bit(ngc_keys[i].keycode, gccdev->input->keybit);
+	input_set_abs_params(gccdev->input, ABS_X, 0, 255, 16, 16);
+	input_set_abs_params(gccdev->input, ABS_Y, 0, 255, 16, 16);
+	input_set_abs_params(gccdev->input, ABS_RX, 0, 255, 16, 16);
+	input_set_abs_params(gccdev->input, ABS_RY, 0, 255, 16, 16);
+	input_set_abs_params(gccdev->input, ABS_Z, 0, 255, 16, 0);
+	input_set_abs_params(gccdev->input, ABS_RZ, 0, 255, 16, 0);
+	error = ngc_init_ff(gccdev);
+	if (error) {
+		dev_warn(&gccdev->input->dev, "Could not create ff (skipped)");
+		goto ngc_deinit_controller;
+	}
+	error = input_register_device(gccdev->input);
+	if (error)
+		goto ngc_deinit_controller_ff;
+	gccdev->enable = true;
+	return 0;
+ngc_deinit_controller_ff:
+	input_ff_destroy(gccdev->input);
+ngc_deinit_controller:
+	input_free_device(gccdev->input);
+	return error;
+}
+
+static void ngc_controller_update_work(struct work_struct *work)
+{
+	int i;
+	u8 status[CONTROLLER_COUNT];
+	bool enable[CONTROLLER_COUNT];
+	unsigned long flags;
+	struct ngc_data *gdata = container_of(work, struct ngc_data, work);
+
+	for (i = 0; i < CONTROLLER_COUNT; i++) {
+		status[i] = gdata->controllers[i].status;
+		enable[i] = ngc_connected_type(status[i]) != 0;
+	}
+
+	for (i = 0; i < CONTROLLER_COUNT; i++) {
+		if (enable[i] && !gdata->controllers[i].enable) {
+			if (ngc_controller_init(&gdata->controllers[i], status[i]) != 0)
+				enable[i] = false;
+		}
+	}
+
+	spin_lock_irqsave(&gdata->idata_lock, flags);
+	for (i = 0; i < CONTROLLER_COUNT; i++)
+		swap(gdata->controllers[i].enable, enable[i]);
+	spin_unlock_irqrestore(&gdata->idata_lock, flags);
+
+	for (i = 0; i < CONTROLLER_COUNT; i++) {
+		if (enable[i] && !gdata->controllers[i].enable)
+			input_unregister_device(gdata->controllers[i].input);
+	}
+}
+
+static void ngc_input(struct ngc_data *gdata)
+{
+	int i;
+	unsigned long flags;
+	bool updated = false;
+
+	for (i = 0; i < CONTROLLER_COUNT; i++) {
+		updated = updated ||
+			 gdata->idata[1 + 9 * i] != gdata->controllers[i].status;
+		gdata->controllers[i].status = gdata->idata[1 + 9 * i];
+	}
+	if (updated)
+		schedule_work(&gdata->work);
+	spin_lock_irqsave(&gdata->idata_lock, flags);
+	for (i = 0; i < CONTROLLER_COUNT; i++) {
+		if (gdata->controllers[i].enable)
+			gcc_input(&gdata->controllers[i], &gdata->idata[1 + 9 * i]);
+	}
+	spin_unlock_irqrestore(&gdata->idata_lock, flags);
+}
+
+static void ngc_irq_in(struct urb *urb)
+{
+	struct ngc_data *gdata = urb->context;
+	struct usb_interface *intf = gdata->intf;
+	int error;
+
+	switch (urb->status) {
+	case 0:
+		break;
+	case -EOVERFLOW:
+	case -ECONNRESET:
+	case -ENOENT:
+	case -ESHUTDOWN:
+		dev_dbg(&intf->dev, "controller urb shutting down: %d\n",
+			urb->status);
+		return;
+	default:
+		dev_dbg(&intf->dev, "controller urb status: %d\n", urb->status);
+		goto exit;
+	}
+	if (gdata->irq_in->actual_length != GCC_IN_PKT_LEN)
+		dev_warn(&intf->dev, "Bad sized packet\n");
+	else if (gdata->idata[0] != 0x21)
+		dev_warn(&intf->dev, "Unknown opcode %d\n", gdata->idata[0]);
+	else
+		ngc_input(gdata);
+exit:
+	error = usb_submit_urb(gdata->irq_in, GFP_ATOMIC);
+	if (error)
+		dev_err(&intf->dev, "controller urb failed: %d\n", error);
+}
+
+static int ngc_init_input(struct ngc_data *gdata,
+			 struct usb_endpoint_descriptor *irq)
+{
+	int error = -ENOMEM;
+
+	gdata->idata = usb_alloc_coherent(gdata->udev, GCC_IN_PKT_LEN, GFP_KERNEL,
+			 &gdata->idata_dma);
+	if (!gdata->idata)
+		return error;
+
+	gdata->irq_in = usb_alloc_urb(0, GFP_KERNEL);
+	if (!gdata->irq_in)
+		goto err_free_coherent;
+
+	usb_fill_int_urb(gdata->irq_in, gdata->udev,
+			 usb_rcvintpipe(gdata->udev, irq->bEndpointAddress),
+			 gdata->idata, GCC_IN_PKT_LEN, ngc_irq_in, gdata,
+			 irq->bInterval);
+	gdata->irq_in->transfer_dma = gdata->idata_dma;
+	gdata->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+	spin_lock_init(&gdata->idata_lock);
+	INIT_WORK(&gdata->work, ngc_controller_update_work);
+
+	return 0;
+
+err_free_coherent:
+	usb_free_coherent(gdata->udev, GCC_IN_PKT_LEN, gdata->idata,
+			 gdata->idata_dma);
+	return error;
+
+}
+
+
+static void ngc_deinit_input(struct ngc_data *gdata)
+{
+	usb_free_urb(gdata->irq_in);
+	usb_free_coherent(gdata->udev, GCC_IN_PKT_LEN, gdata->idata,
+			 gdata->idata_dma);
+}
+
+
+static int ngc_init_irq(struct ngc_data *gdata)
+{
+	struct usb_endpoint_descriptor *eps[] = { NULL, NULL };
+	int error;
+
+	error = usb_find_common_endpoints(gdata->intf->cur_altsetting, NULL, NULL,
+					  &eps[0], &eps[1]);
+	if (error)
+		return -ENODEV;
+	error = ngc_init_output(gdata, eps[1]);
+	if (error)
+		return error;
+	error = ngc_init_input(gdata, eps[0]);
+	if (error)
+		goto err_deinit_out;
+#ifdef CONFIG_JOYSTICK_NGC_FF
+	gdata->rumble_changed = false;
+	gdata->irq_out_active = true;
+#endif
+	gdata->odata[0] = 0x13;
+	gdata->irq_out->transfer_buffer_length = 1;
+
+	error = usb_submit_urb(gdata->irq_in, GFP_KERNEL);
+	if (error)
+		goto err_deinit_in;
+
+	error = usb_submit_urb(gdata->irq_out, GFP_KERNEL);
+	if (error) {
+		dev_err(&gdata->intf->dev,
+			"%s - usb_submit_urb failed with result %d\n",
+			__func__, error);
+		error = -EIO;
+		goto err_kill_in_urb;
+	}
+
+	return 0;
+err_kill_in_urb:
+	usb_kill_urb(gdata->irq_in);
+err_deinit_in:
+	ngc_deinit_input(gdata);
+err_deinit_out:
+	ngc_deinit_output(gdata);
+	return error;
+}
+
+static void ngc_deinit_irq(struct ngc_data *gdata)
+{
+	usb_kill_urb(gdata->irq_out);
+	usb_kill_urb(gdata->irq_in);
+	/* Make sure we are done with presence work if it was scheduled */
+	flush_work(&gdata->work);
+
+	ngc_deinit_input(gdata);
+	ngc_deinit_output(gdata);
+}
+
+static void ngc_init_controllers(struct ngc_data *gdata)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(gdata->controllers); i++) {
+		gdata->controllers[i].adapter = gdata;
+		gdata->controllers[i].no = i;
+		gdata->controllers[i].status = GAMECUBE_NONE;
+		gdata->controllers[i].enable = false;
+	}
+}
+
+static int ngc_usb_probe(struct usb_interface *iface, const struct usb_device_id *id)
+{
+	struct usb_device *udev = interface_to_usbdev(iface);
+	struct ngc_data *gdata;
+	int error;
+
+	gdata = kzalloc(sizeof(struct ngc_data), GFP_KERNEL);
+	if (!gdata)
+		return -ENOMEM;
+	usb_set_intfdata(iface, gdata);
+	gdata->udev = udev;
+	gdata->intf = iface;
+
+	usb_make_path(udev, gdata->phys, sizeof(gdata->phys));
+	strlcat(gdata->phys, "/input0", sizeof(gdata->phys));
+
+	ngc_init_controllers(gdata);
+	error = ngc_init_irq(gdata);
+	if (error)
+		goto err_free_devs;
+	dev_info(&iface->dev, "New device registered\n");
+	return 0;
+err_free_devs:
+	usb_set_intfdata(iface, NULL);
+	kfree(gdata);
+	return error;
+}
+
+static void ngc_usb_disconnect(struct usb_interface *iface)
+{
+	struct ngc_data *gdata = usb_get_intfdata(iface);
+	int i;
+
+	for (i = 0; i < CONTROLLER_COUNT; i++) {
+		if (gdata->controllers[i].enable)
+			input_unregister_device(gdata->controllers[i].input);
+	}
+	ngc_deinit_irq(gdata);
+	usb_set_intfdata(iface, NULL);
+	kfree(gdata);
+}
+
+static const struct usb_device_id ngc_usb_devices[] = {
+	{ USB_DEVICE(USB_VENDOR_ID_NINTENDO,
+		     USB_DEVICE_ID_NINTENDO_GCADAPTER) },
+	{}
+};
+MODULE_DEVICE_TABLE(usb, ngc_usb_devices);
+
+static struct usb_driver ngc_usb_driver = {
+	.name		= "gamecube_adapter",
+	.id_table	= ngc_usb_devices,
+	.probe		= ngc_usb_probe,
+	.disconnect	= ngc_usb_disconnect,
+};
+
+module_usb_driver(ngc_usb_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Robin Milas <milas.robin@live.fr>");
+MODULE_DESCRIPTION("Driver for GameCube adapter");
-- 
2.45.0


^ permalink raw reply related

* Re: [PATCH v2 3/5] selftests: Include KHDR_INCLUDES in Makefile
From: Mark Brown @ 2024-05-09  5:14 UTC (permalink / raw)
  To: Edward Liaw
  Cc: shuah, Jaroslav Kysela, Takashi Iwai, Catalin Marinas,
	Will Deacon, Nhat Pham, Johannes Weiner, Christian Brauner,
	Eric Biederman, Kees Cook, OGAWA Hirofumi, Thomas Gleixner,
	Ingo Molnar, Peter Zijlstra, Darren Hart, Davidlohr Bueso,
	André Almeida, Jiri Kosina, Benjamin Tissoires,
	Jason Gunthorpe, Kevin Tian, Andy Lutomirski, Will Drewry,
	Marc Zyngier, Oliver Upton, James Morse, Suzuki K Poulose,
	Zenghui Yu, Paolo Bonzini, Sean Christopherson, Anup Patel,
	Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Mickaël Salaün, Paul Moore,
	James Morris, Serge E. Hallyn, Andrew Morton, Seth Forshee,
	Bongsu Jeon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Steffen Klassert, Herbert Xu, Andreas Färber,
	Manivannan Sadhasivam, Matthieu Baerts, Mat Martineau,
	Geliang Tang, Willem de Bruijn, Fenghua Yu, Reinette Chatre,
	Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum, linux-kernel, linux-kselftest, kernel-team,
	linux-sound, linux-arm-kernel, linux-mm, linux-input, iommu,
	kvmarm, kvm, kvm-riscv, linux-riscv, linux-security-module,
	linux-fsdevel, netdev, linux-actions, mptcp, linux-rtc, linux-sgx,
	bpf
In-Reply-To: <20240507214254.2787305-4-edliaw@google.com>

[-- Attachment #1: Type: text/plain, Size: 272 bytes --]

On Tue, May 07, 2024 at 09:38:28PM +0000, Edward Liaw wrote:

>  tools/testing/selftests/arm64/signal/Makefile          | 2 +-

This is not really using any of the kselftest framework at all to build
so I'm not sure the change makes sense for it.  OTOH it does no harm...

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply

* Re: [PATCH v2 0/5] Define _GNU_SOURCE for sources using
From: Edward Liaw @ 2024-05-09  6:13 UTC (permalink / raw)
  To: Shuah Khan
  Cc: shuah, Mark Brown, Jaroslav Kysela, Takashi Iwai, Catalin Marinas,
	Will Deacon, Nhat Pham, Johannes Weiner, Christian Brauner,
	Eric Biederman, Kees Cook, OGAWA Hirofumi, Thomas Gleixner,
	Ingo Molnar, Peter Zijlstra, Darren Hart, Davidlohr Bueso,
	André Almeida, Jiri Kosina, Benjamin Tissoires,
	Jason Gunthorpe, Kevin Tian, Andy Lutomirski, Will Drewry,
	Marc Zyngier, Oliver Upton, James Morse, Suzuki K Poulose,
	Zenghui Yu, Paolo Bonzini, Sean Christopherson, Anup Patel,
	Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Mickaël Salaün, Paul Moore,
	James Morris, Serge E. Hallyn, Andrew Morton, Seth Forshee,
	Bongsu Jeon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Steffen Klassert, Herbert Xu, Andreas Färber,
	Manivannan Sadhasivam, Matthieu Baerts, Mat Martineau,
	Geliang Tang, Willem de Bruijn, Fenghua Yu, Reinette Chatre,
	Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum, linux-kernel, linux-kselftest, kernel-team,
	linux-sound, linux-arm-kernel, linux-mm, linux-input, iommu,
	kvmarm, kvm, kvm-riscv, linux-riscv, linux-security-module,
	linux-fsdevel, netdev, linux-actions, mptcp, linux-rtc, linux-sgx,
	bpf
In-Reply-To: <f4e45604-86b0-4be6-9bea-36edf301df33@linuxfoundation.org>

On Wed, May 8, 2024 at 4:10 PM Shuah Khan <skhan@linuxfoundation.org> wrote:
>
> On 5/7/24 15:38, Edward Liaw wrote:
> > 809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
> > asprintf into kselftest_harness.h, which is a GNU extension and needs
> > _GNU_SOURCE to either be defined prior to including headers or with the
> > -D_GNU_SOURCE flag passed to the compiler.
> >
> > v1: https://lore.kernel.org/linux-kselftest/20240430235057.1351993-1-edliaw@google.com/
> > v2: add -D_GNU_SOURCE to KHDR_INCLUDES so that it is in a single
> > location.  Remove #define _GNU_SOURCE from source code to resolve
> > redefinition warnings.
> >
> > Edward Liaw (5):
> >    selftests: Compile kselftest headers with -D_GNU_SOURCE
> >    selftests/sgx: Include KHDR_INCLUDES in Makefile
>
> I appled patches 1/5 and 2.5 - The rest need to be split up.
>
> >    selftests: Include KHDR_INCLUDES in Makefile
> >    selftests: Drop define _GNU_SOURCE
> >    selftests: Drop duplicate -D_GNU_SOURCE
> >
>
> Please split these patches pwe test directory. Otherwise it will
> cause merge conflicts which can be hard to resolve.

Hi Shuah,
Sean asked that I rebase the patches on linux-next, and I will need to
remove additional _GNU_SOURCE defines.  Should I send an unsplit v3 to
be reviewed, then split it afterwards?  I'm concerned that it will be
difficult to review with ~70 patches once split.

^ permalink raw reply

* [PATCH v1 1/1] Input: gpio-keys - expose wakeup keys in sysfs
From: Guido Günther @ 2024-05-09 12:00 UTC (permalink / raw)
  To: Dmitry Torokhov, Geert Uytterhoeven, Hermes Zhang, Tony Lindgren,
	linux-input, linux-kernel, phone-devel
In-Reply-To: <cover.1715255980.git.agx@sigxcpu.org>

This helps user space to figure out which keys should be used to unidle a
device. E.g on phones the volume rocker should usually not unblank the
screen.

Signed-off-by: Guido Günther <agx@sigxcpu.org>
---
 drivers/input/keyboard/gpio_keys.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 9f3bcd41cf67..84f43d1d4375 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -198,7 +198,8 @@ static void gpio_keys_enable_button(struct gpio_button_data *bdata)
  */
 static ssize_t gpio_keys_attr_show_helper(struct gpio_keys_drvdata *ddata,
 					  char *buf, unsigned int type,
-					  bool only_disabled)
+					  bool only_disabled,
+					  bool only_wakeup)
 {
 	int n_events = get_n_events_by_type(type);
 	unsigned long *bits;
@@ -218,6 +219,9 @@ static ssize_t gpio_keys_attr_show_helper(struct gpio_keys_drvdata *ddata,
 		if (only_disabled && !bdata->disabled)
 			continue;
 
+		if (only_wakeup && !bdata->button->wakeup)
+			continue;
+
 		__set_bit(*bdata->code, bits);
 	}
 
@@ -297,7 +301,7 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata,
 	return error;
 }
 
-#define ATTR_SHOW_FN(name, type, only_disabled)				\
+#define ATTR_SHOW_FN(name, type, only_disabled, only_wakeup)		\
 static ssize_t gpio_keys_show_##name(struct device *dev,		\
 				     struct device_attribute *attr,	\
 				     char *buf)				\
@@ -306,22 +310,26 @@ static ssize_t gpio_keys_show_##name(struct device *dev,		\
 	struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);	\
 									\
 	return gpio_keys_attr_show_helper(ddata, buf,			\
-					  type, only_disabled);		\
+					  type, only_disabled,		\
+					  only_wakeup);			\
 }
 
-ATTR_SHOW_FN(keys, EV_KEY, false);
-ATTR_SHOW_FN(switches, EV_SW, false);
-ATTR_SHOW_FN(disabled_keys, EV_KEY, true);
-ATTR_SHOW_FN(disabled_switches, EV_SW, true);
+ATTR_SHOW_FN(keys, EV_KEY, false, false);
+ATTR_SHOW_FN(switches, EV_SW, false, false);
+ATTR_SHOW_FN(disabled_keys, EV_KEY, true, false);
+ATTR_SHOW_FN(disabled_switches, EV_SW, true, false);
+ATTR_SHOW_FN(wakeup_keys, EV_KEY, false, true);
 
 /*
  * ATTRIBUTES:
  *
  * /sys/devices/platform/gpio-keys/keys [ro]
  * /sys/devices/platform/gpio-keys/switches [ro]
+ * /sys/devices/platform/gpio-keys/wakeup_keys [ro]
  */
 static DEVICE_ATTR(keys, S_IRUGO, gpio_keys_show_keys, NULL);
 static DEVICE_ATTR(switches, S_IRUGO, gpio_keys_show_switches, NULL);
+static DEVICE_ATTR(wakeup_keys, S_IRUGO, gpio_keys_show_wakeup_keys, NULL);
 
 #define ATTR_STORE_FN(name, type)					\
 static ssize_t gpio_keys_store_##name(struct device *dev,		\
@@ -361,6 +369,7 @@ static struct attribute *gpio_keys_attrs[] = {
 	&dev_attr_switches.attr,
 	&dev_attr_disabled_keys.attr,
 	&dev_attr_disabled_switches.attr,
+	&dev_attr_wakeup_keys.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(gpio_keys);
-- 
2.43.0


^ permalink raw reply related

* Re: [PATCH v2 0/5] Define _GNU_SOURCE for sources using
From: Shuah Khan @ 2024-05-09 14:37 UTC (permalink / raw)
  To: Edward Liaw
  Cc: shuah, Mark Brown, Jaroslav Kysela, Takashi Iwai, Catalin Marinas,
	Will Deacon, Nhat Pham, Johannes Weiner, Christian Brauner,
	Eric Biederman, Kees Cook, OGAWA Hirofumi, Thomas Gleixner,
	Ingo Molnar, Peter Zijlstra, Darren Hart, Davidlohr Bueso,
	André Almeida, Jiri Kosina, Benjamin Tissoires,
	Jason Gunthorpe, Kevin Tian, Andy Lutomirski, Will Drewry,
	Marc Zyngier, Oliver Upton, James Morse, Suzuki K Poulose,
	Zenghui Yu, Paolo Bonzini, Sean Christopherson, Anup Patel,
	Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Mickaël Salaün, Paul Moore,
	James Morris, Serge E. Hallyn, Andrew Morton, Seth Forshee,
	Bongsu Jeon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Steffen Klassert, Herbert Xu, Andreas Färber,
	Manivannan Sadhasivam, Matthieu Baerts, Mat Martineau,
	Geliang Tang, Willem de Bruijn, Fenghua Yu, Reinette Chatre,
	Mathieu Desnoyers, Paul E. McKenney, Boqun Feng,
	Alexandre Belloni, Jarkko Sakkinen, Dave Hansen,
	Muhammad Usama Anjum, linux-kernel, linux-kselftest, kernel-team,
	linux-sound, linux-arm-kernel, linux-mm, linux-input, iommu,
	kvmarm, kvm, kvm-riscv, linux-riscv, linux-security-module,
	linux-fsdevel, netdev, linux-actions, mptcp, linux-rtc, linux-sgx,
	bpf, Shuah Khan
In-Reply-To: <CAG4es9XE2D94BNboRSf607NbJVW7OW4xkVq4jZ8pDZ_AZsb3nQ@mail.gmail.com>

On 5/9/24 00:13, Edward Liaw wrote:
> On Wed, May 8, 2024 at 4:10 PM Shuah Khan <skhan@linuxfoundation.org> wrote:
>>
>> On 5/7/24 15:38, Edward Liaw wrote:
>>> 809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
>>> asprintf into kselftest_harness.h, which is a GNU extension and needs
>>> _GNU_SOURCE to either be defined prior to including headers or with the
>>> -D_GNU_SOURCE flag passed to the compiler.
>>>
>>> v1: https://lore.kernel.org/linux-kselftest/20240430235057.1351993-1-edliaw@google.com/
>>> v2: add -D_GNU_SOURCE to KHDR_INCLUDES so that it is in a single
>>> location.  Remove #define _GNU_SOURCE from source code to resolve
>>> redefinition warnings.
>>>
>>> Edward Liaw (5):
>>>     selftests: Compile kselftest headers with -D_GNU_SOURCE
>>>     selftests/sgx: Include KHDR_INCLUDES in Makefile
>>
>> I appled patches 1/5 and 2.5 - The rest need to be split up.
>>
>>>     selftests: Include KHDR_INCLUDES in Makefile
>>>     selftests: Drop define _GNU_SOURCE
>>>     selftests: Drop duplicate -D_GNU_SOURCE
>>>
>>
>> Please split these patches pwe test directory. Otherwise it will
>> cause merge conflicts which can be hard to resolve.
> 
> Hi Shuah,
> Sean asked that I rebase the patches on linux-next, and I will need to
> remove additional _GNU_SOURCE defines.  Should I send an unsplit v3 to
> be reviewed, then split it afterwards?  I'm concerned that it will be
> difficult to review with ~70 patches once split.

Please send them split - it will be easier to review and apply. You
might as well wait until the merge window is done. I don't think
anybody would have time to review now since merge window starts
next week.


thanks,
-- Shuah

^ permalink raw reply

* Re: [PATCH v3 01/11] can: Add LIN bus as CAN abstraction
From: Christoph Fritz @ 2024-05-09 17:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Ilpo Järvinen, Oliver Hartkopp, Marc Kleine-Budde,
	Jiri Slaby, Vincent Mailhol, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Jiri Kosina, Benjamin Tissoires, Sebastian Reichel,
	Linus Walleij, Andreas Lauser, Jonathan Corbet, Pavel Pisa,
	linux-can, Netdev, devicetree, linux-input, linux-serial
In-Reply-To: <2024050852-vixen-arson-cb42@gregkh>

On Wed, 2024-05-08 at 19:48 +0100, Greg Kroah-Hartman wrote:
> On Wed, May 08, 2024 at 08:20:51PM +0200, Christoph Fritz wrote:
> > ...
> > > ...
> > > > > > +static int lin_create_sysfs_id_files(struct net_device *ndev)
> > > > > > +{
> > > > > > +	struct lin_device *ldev = netdev_priv(ndev);
> > > > > > +	struct kobj_attribute *attr;
> > > > > > +	int ret;
> > > > > > +
> > > > > > +	for (int id = 0; id < LIN_NUM_IDS; id++) {
> > > > > > +		ldev->sysfs_entries[id].ldev = ldev;
> > > > > > +		attr = &ldev->sysfs_entries[id].attr;
> > > > > > +		attr->attr.name = kasprintf(GFP_KERNEL, "%02x", id);
> > > > > > +		if (!attr->attr.name)
> > > > > > +			return -ENOMEM;
> > > > > > +		attr->attr.mode = 0644;
> > > > > > +		attr->show = lin_identifier_show;
> > > > > > +		attr->store = lin_identifier_store;
> > > > > > +
> > > > > > +		sysfs_attr_init(&attr->attr);
> > > > > > +		ret = sysfs_create_file(ldev->lin_ids_kobj, &attr->attr);
> > > > > > +		if (ret) {
> > > > > > +			kfree(attr->attr.name);
> > > > > > +			return -ENOMEM;
> > > > > > +		}
> > > > > > +	}
> > > > > > +
> > > > > > +	return 0;
> > > > > > +}
> > > > > 
> > > > > Can you use .dev_groups instead ?
> > > > 
> > > > I'm not sure where to attach this in this glue code here. Should I do a
> > > > class_register() and add the .dev_groups there?
> > > 
> > > I guess struct class would be correct direction but I'm not sure if it's 
> > > viable in this case. It would avoid the need for custom sysfs setup code
> > > if it's workable.
> > 
> > I just tried to find a way, but these are 64 sysfs files and declaring
> > them all static looks a bit odd to me. I might be missing something
> > here.
> > 
> > For v4 I would stick to the dynamic setup and fix the rollback.
> > 
> > Any objections?
> 
> Yes, you race with userspace and loose by trying to do this "by hand".
> Make this static please.

OK, static init coming up in v4

thanks
  -- Christoph

^ permalink raw reply

* Re: [PATCH v3 02/11] HID: hexLIN: Add support for USB LIN bus adapter
From: Christoph Fritz @ 2024-05-09 17:06 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Jiri Slaby, Oliver Hartkopp, Marc Kleine-Budde, Vincent Mailhol,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jiri Kosina,
	Benjamin Tissoires, Greg Kroah-Hartman, Sebastian Reichel,
	Linus Walleij, Andreas Lauser, Jonathan Corbet, Pavel Pisa,
	linux-can, Netdev, devicetree, linux-input, linux-serial
In-Reply-To: <422e0d3a-3eb9-ff78-8419-56e894e04137@linux.intel.com>

On Mon, 2024-05-06 at 19:53 +0300, Ilpo Järvinen wrote:
> On Thu, 2 May 2024, Christoph Fritz wrote:
> 
> > This patch introduces driver support for the hexLIN USB LIN bus adapter,
> > enabling LIN communication over USB for both controller and responder
> > modes. The driver interfaces with the CAN_LIN framework for userland
> > connectivity.
> > 
> > For more details on the adapter, visit: https://hexdev.de/hexlin/
> > 
> > Tested-by: Andreas Lauser <andreas.lauser@mercedes-benz.com>
> > Signed-off-by: Christoph Fritz <christoph.fritz@hexdev.de>
> > ---
> >  drivers/hid/Kconfig             |  19 +
> >  drivers/hid/Makefile            |   1 +
> >  drivers/hid/hid-hexdev-hexlin.c | 611 ++++++++++++++++++++++++++++++++
> >  drivers/hid/hid-ids.h           |   1 +
> >  drivers/hid/hid-quirks.c        |   3 +
> >  5 files changed, 635 insertions(+)
> >  create mode 100644 drivers/hid/hid-hexdev-hexlin.c
> > 
> > diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
> > index 4c682c6507040..d2fb35d83c640 100644
> > --- a/drivers/hid/Kconfig
> > +++ b/drivers/hid/Kconfig
> > @@ -496,6 +496,25 @@ config HID_GYRATION
> >  	help
> >  	Support for Gyration remote control.
> >  
> > +config HID_MCS_HEXDEV
> > +	tristate "hexDEV LIN-BUS adapter support"
> > +	depends on HID && CAN_NETLINK && CAN_DEV
> > +	select CAN_LIN
> > +	help
> > +	  Support for hexDEV its hexLIN USB LIN bus adapter.
> > +
> > +	  Local Interconnect Network (LIN) to USB adapter for controller and
> > +	  responder usage.
> > +	  This device driver is using CAN_LIN for a userland connection on
> > +	  one side and USB HID for the actual hardware adapter on the other
> > +	  side.
> > +
> > +	  If you have such an adapter, say Y here and see
> > +	  <https://hexdev.de/hexlin>.
> > +
> > +	  To compile this driver as a module, choose M here: the
> > +	  module will be called hid-hexlin.
> > +
> >  config HID_ICADE
> >  	tristate "ION iCade arcade controller"
> >  	help
> > diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
> > index 082a728eac600..f9b13e6117e60 100644
> > --- a/drivers/hid/Makefile
> > +++ b/drivers/hid/Makefile
> > @@ -59,6 +59,7 @@ obj-$(CONFIG_HID_GOOGLE_STADIA_FF)	+= hid-google-stadiaff.o
> >  obj-$(CONFIG_HID_VIVALDI)	+= hid-vivaldi.o
> >  obj-$(CONFIG_HID_GT683R)	+= hid-gt683r.o
> >  obj-$(CONFIG_HID_GYRATION)	+= hid-gyration.o
> > +obj-$(CONFIG_HID_MCS_HEXDEV)	+= hid-hexdev-hexlin.o
> >  obj-$(CONFIG_HID_HOLTEK)	+= hid-holtek-kbd.o
> >  obj-$(CONFIG_HID_HOLTEK)	+= hid-holtek-mouse.o
> >  obj-$(CONFIG_HID_HOLTEK)	+= hid-holtekff.o
> > diff --git a/drivers/hid/hid-hexdev-hexlin.c b/drivers/hid/hid-hexdev-hexlin.c
> > new file mode 100644
> > index 0000000000000..1ddc1e00ab2da
> > --- /dev/null
> > +++ b/drivers/hid/hid-hexdev-hexlin.c
> > @@ -0,0 +1,611 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * LIN bus USB adapter driver https://hexdev.de/hexlin
> > + *
> > + * Copyright (C) 2024 hexDEV GmbH
> > + */
> > +
> > +#include <linux/completion.h>
> > +#include <linux/hid.h>
> > +#include <linux/module.h>
> > +#include <linux/wait.h>
> > +#include <net/lin.h>
> > +#include "hid-ids.h"
> > +
> > +enum {
> > +	/* answers */
> > +	HEXLIN_SUCCESS = 0x01,
> > +	HEXLIN_FRAME = 0x02,
> > +	HEXLIN_ERROR = 0x03,
> > +	HEXLIN_FAIL = 0x0F,
> > +
> > +	/* lin-responder */
> > +	HEXLIN_SET_MODE_RESPONDER = 0x10,
> > +	HEXLIN_SET_RESPONDER_ANSWER_ID = 0x11,
> > +	HEXLIN_GET_RESPONDER_ANSWER_ID = 0x12,
> > +
> > +	/* lin-controller */
> > +	HEXLIN_SET_MODE_CONTROLLER = 0x20,
> > +	HEXLIN_SEND_BREAK = 0x21,
> > +	HEXLIN_SEND_UNCONDITIONAL_FRAME = 0x22,
> > +
> > +	/* lin-div */
> > +	HEXLIN_SET_BAUDRATE = 0x34,
> > +	HEXLIN_GET_BAUDRATE = 0x35,
> > +
> > +	/* div */
> > +	HEXLIN_RESET = 0xF0,
> > +	HEXLIN_GET_VERSION = 0xF1,
> 
> Could you align the values?

OK

> 
> > +};
> > +
> > +#define HEXLIN_SUCCESS_SZ			1
> > +#define HEXLIN_FRAME_SZ				17
> > +#define HEXLIN_FAIL_SZ				1
> > +#define HEXLIN_GET_RESPONDER_ANSWER_ID_SZ	20
> > +#define HEXLIN_GET_BAUDRATE_SZ			3
> 
> Is this sizeof(hexlin_baudrate_req)?

No

> If so, don't add define for it.
> This probably applies to other defines here too.

I'll refactor these defines in upcoming v4 to a minimum.

> 
> > +#define HEXLIN_BAUDRATE_SZ			2
> > +#define HEXLIN_GET_VERSION_SZ			2
> > +#define HEXLIN_PKGLEN_MAX_SZ			64
> > +
> > +struct hexlin_val8_req {
> > +	u8 cmd;
> > +	u8 v;
> > +} __packed;
> > +
> > +struct hexlin_baudrate_req {
> > +	u8 cmd;
> > +	u16 baudrate;
> > +} __packed;
> > +
> > +struct hexlin_frame {
> > +	u32 flags;
> > +	u8 len;
> > +	u8 lin_id;
> > +	u8 data[LIN_MAX_DLEN];
> > +	u8 checksum;
> > +	u8 checksum_mode;
> > +} __packed;
> > +
> > +struct hexlin_unconditional_req {
> > +	u8 cmd;
> > +	struct hexlin_frame frm;
> > +} __packed;
> > +
> > +struct hexlin_responder_answer {
> > +	u8 is_active;
> > +	u8 is_event_frame;
> > +	u8 event_associated_id;
> > +	struct hexlin_frame frm;
> > +} __packed;
> > +
> > +struct hexlin_responder_answer_req {
> > +	u8 cmd;
> > +	struct hexlin_responder_answer answ;
> > +} __packed;
> > +
> > +struct hexlin_priv_data {
> > +	struct hid_device *hid_dev;
> > +	struct lin_device *ldev;
> > +	u16 baudrate;
> > +	struct completion wait_in_report;
> > +	bool is_error;
> > +	struct mutex tx_lock;  /* protects hexlin_tx_report() */
> > +	struct hexlin_responder_answer_req rar;
> > +	u8 fw_version;
> > +};
> > +
> > +static int hexlin_tx_report(struct hexlin_priv_data *priv,
> > +			    const void *out_report, size_t len)
> > +{
> > +	u8 *buf;
> > +	int ret;
> > +
> > +	buf = kmemdup(out_report, len, GFP_KERNEL);
> > +	if (!buf)
> > +		return -ENOMEM;
> > +
> > +	ret = hid_hw_output_report(priv->hid_dev, buf, len);
> > +	kfree(buf);
> 
> Is duplicatign the buffer necessary?

No, my intention was to keep the functions calling hexlin_tx_report()
simpler and let the compiler optimize this.

In the upcoming v4, I merged this into hexlin_tx_req_status() and
dropped the kmemdup().

> 
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret != len)
> > +		return -EIO;
> > +
> > +	return 0;
> > +}
> > +
> > +static int hexlin_tx_req_status(struct hexlin_priv_data *priv,
> > +				const void *out_report, int len)
> > +{
> > +	int ret;
> > +	unsigned long t;
> > +
> > +	mutex_lock(&priv->tx_lock);
> > +
> > +	reinit_completion(&priv->wait_in_report);
> > +
> > +	ret = hexlin_tx_report(priv, out_report, len);
> > +	if (ret)
> > +		goto tx_exit;
> > +
> > +	t = wait_for_completion_killable_timeout(&priv->wait_in_report,
> > +						 msecs_to_jiffies(1000));
> 
> HZ?

OK

> 
> > +	if (!t)
> > +		ret = -ETIMEDOUT;
> > +
> > +	if (priv->is_error)
> > +		ret = -EINVAL;
> > +
> > +tx_exit:
> > +	mutex_unlock(&priv->tx_lock);
> > +
> > +	return ret;
> > +}
> > +
> > +#define HEXLIN_GET_CMD(name, enum_cmd)					\
> > +	static int hexlin_##name(struct hexlin_priv_data *priv)		\
> > +	{								\
> > +		u8 cmd = enum_cmd;					\
> > +		int ret;						\
> > +									\
> > +		ret = hexlin_tx_req_status(priv, &cmd, sizeof(u8));	\
> 
> Take sizeof() of the relevant variable instead, so:
> 
> sizeof(cmd)

OK

> 
> > +		if (ret)						\
> > +			hid_err(priv->hid_dev, "%s failed with %d\n",	\
> > +				__func__, ret);				\
> > +									\
> > +		return ret;						\
> > +	}
> > +
> > +HEXLIN_GET_CMD(get_version, HEXLIN_GET_VERSION)
> > +HEXLIN_GET_CMD(reset_dev, HEXLIN_RESET)
> > +HEXLIN_GET_CMD(get_baudrate, HEXLIN_GET_BAUDRATE)
> > +
> > +#define HEXLIN_VAL_CMD(name, enum_cmd, struct_type, vtype)		\
> > +	static int hexlin_##name(struct hexlin_priv_data *p, vtype val)	\
> > +	{								\
> > +		struct struct_type req;					\
> > +		int ret;						\
> > +									\
> > +		req.cmd = enum_cmd;					\
> > +		req.v = val;						\
> > +									\
> > +		ret = hexlin_tx_req_status(p, &req,			\
> > +					   sizeof(struct struct_type));	\
> 
> sizeof(req)

OK

> 
> > +		if (ret)						\
> > +			hid_err(p->hid_dev, "%s failed with %d\n",	\
> > +				__func__, ret);				\
> > +									\
> > +		return ret;						\
> > +	}
> > +
> > +HEXLIN_VAL_CMD(send_break, HEXLIN_SEND_BREAK, hexlin_val8_req, u8)
> > +
> > +static int hexlin_queue_frames_insert(struct hexlin_priv_data *priv,
> > +				      const u8 *raw_data, int sz)
> > +{
> > +	struct hid_device *hdev = priv->hid_dev;
> > +	struct hexlin_frame hxf;
> > +	struct lin_frame lf;
> > +
> > +	if (sz != sizeof(struct hexlin_frame))
> > +		return -EREMOTEIO;
> > +
> > +	memcpy(&hxf, raw_data, sz);
> 
> Why you cannot just cast the pointer to correct type?

I can, will be refactored in v4.

> 
> > +	le32_to_cpus(hxf.flags);
> 
> You must use correct endianess typing. The struct hexlin_frame should have 
> __le32 flags so sparse's endianness check is happy.

OK

> 
> But .flags are not used at all so why is this required in the first place?

Was necessary in the development process and will be used in hid_dbg()
below in v4.

> 
> > +	lf.len = hxf.len;
> > +	lf.lin_id = hxf.lin_id;
> > +	memcpy(lf.data, hxf.data, LIN_MAX_DLEN);
> > +	lf.checksum = hxf.checksum;
> > +	lf.checksum_mode = hxf.checksum_mode;
> > +
> > +	hid_dbg(hdev, "id:%02x, len:%u, data:%*ph, checksum:%02x (%s)\n",
> > +		   lf.lin_id, lf.len, lf.len, lf.data, lf.checksum,
> > +		   lf.checksum_mode ? "enhanced" : "classic");
> > +
> > +	lin_rx(priv->ldev, &lf);
> > +
> > +	return 0;
> > +}
> > +
> > +static int hexlin_send_unconditional(struct hexlin_priv_data *priv,
> > +			      const struct hexlin_frame *hxf)
> > +{
> > +	struct hexlin_unconditional_req req;
> > +	int ret;
> > +
> > +	if (hxf->lin_id > LIN_ID_MASK)
> > +		return -EINVAL;
> > +
> > +	req.cmd = HEXLIN_SEND_UNCONDITIONAL_FRAME;
> > +	memcpy(&req.frm, hxf, sizeof(struct hexlin_frame));
> > +
> > +	ret = hexlin_tx_req_status(priv, &req,
> > +				   sizeof(struct hexlin_unconditional_req));
> 
> sizeof(req)

OK

> 
> > +
> > +	if (ret)
> > +		hid_err(priv->hid_dev, "%s failed with %d\n", __func__, ret);
> > +
> > +	return ret;
> > +}
> > +
> > +static int hexlin_set_baudrate(struct hexlin_priv_data *priv, u16 baudrate)
> > +{
> > +	struct hexlin_baudrate_req req;
> > +	int ret;
> > +
> > +	if (baudrate < LIN_MIN_BAUDRATE || baudrate > LIN_MAX_BAUDRATE)
> > +		return -EINVAL;
> > +
> > +	req.cmd = HEXLIN_SET_BAUDRATE;
> > +	req.baudrate = cpu_to_le16(baudrate);
> 
> The struct should have __le16 baudrate.

OK

> 
> > +
> > +	ret = hexlin_tx_req_status(priv, &req,
> > +				   sizeof(struct hexlin_baudrate_req));
> > +	if (ret)
> > +		hid_err(priv->hid_dev, "%s failed with %d\n", __func__, ret);
> > +
> > +	return ret;
> > +}
> > +
> > +static int hexlin_get_responder_answer_id(struct hexlin_priv_data *priv, u8 id,
> > +					  struct hexlin_responder_answer_req *rar)
> > +{
> > +	u8 req[2] = { HEXLIN_GET_RESPONDER_ANSWER_ID, id };
> > +	int ret;
> > +
> > +	if (id > LIN_ID_MASK)
> > +		return -EINVAL;
> > +
> > +	ret = hexlin_tx_req_status(priv, &req, sizeof(req));
> > +	if (ret) {
> > +		hid_err(priv->hid_dev, "%s failed with %d\n", __func__, ret);
> 
> Try to write error message that is meaningful to user, printing __func__ 
> is not very helpful for user.

OK, will be refactored in v4.

> 
> > +		return ret;
> > +	}
> > +
> > +	memcpy(rar, &priv->rar, sizeof(struct hexlin_responder_answer_req));
> 
> sizeof(*rar)

OK

> 
> > +	return 0;
> > +}
> > +
> > +static int hexlin_set_responder_answer_id(struct hexlin_priv_data *priv,
> > +					  const struct lin_responder_answer *answ)
> > +{
> > +	struct hexlin_responder_answer_req rar;
> > +	int ret;
> > +
> > +	if (answ->lf.lin_id > LIN_ID_MASK ||
> > +	    answ->event_associated_id > LIN_ID_MASK)
> > +		return -EINVAL;
> > +
> > +	rar.cmd = HEXLIN_SET_RESPONDER_ANSWER_ID;
> > +	rar.answ.is_active = answ->is_active;
> > +	rar.answ.is_event_frame = answ->is_event_frame;
> > +	rar.answ.event_associated_id = answ->event_associated_id;
> > +	rar.answ.frm.len = answ->lf.len;
> > +	rar.answ.frm.lin_id = answ->lf.lin_id;
> > +	memcpy(rar.answ.frm.data, answ->lf.data, LIN_MAX_DLEN);
> > +	rar.answ.frm.checksum = answ->lf.checksum;
> > +	rar.answ.frm.checksum_mode = answ->lf.checksum_mode;
> > +
> > +	ret = hexlin_tx_req_status(priv, &rar,
> > +				   sizeof(struct hexlin_responder_answer_req));
> 
> Ditto.

OK

thanks
  -- Christoph



^ permalink raw reply

* Re: [PATCH v3 07/11] can: Add support for serdev LIN adapters
From: Christoph Fritz @ 2024-05-09 17:06 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Jiri Slaby, Oliver Hartkopp, Marc Kleine-Budde, Vincent Mailhol,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jiri Kosina,
	Benjamin Tissoires, Greg Kroah-Hartman, Sebastian Reichel,
	Linus Walleij, Andreas Lauser, Jonathan Corbet, Pavel Pisa,
	linux-can, netdev, devicetree, linux-input, linux-serial
In-Reply-To: <71837e7a-b0cf-a8ff-788f-50ba68313621@linux.intel.com>

On Mon, 2024-05-06 at 20:03 +0300, Ilpo Järvinen wrote:
> On Thu, 2 May 2024, Christoph Fritz wrote:
> 
> > This commit introduces LIN-Bus support for UART devices equipped with
> > LIN transceivers, utilizing the Serial Device Bus (serdev) interface.
> > 
> > For more details on an adapter, visit: https://hexdev.de/hexlin#tty
> > 
> > Signed-off-by: Christoph Fritz <christoph.fritz@hexdev.de>
> > ---
> >  drivers/net/can/Kconfig      |  16 ++
> >  drivers/net/can/Makefile     |   1 +
> >  drivers/net/can/lin-serdev.c | 500 +++++++++++++++++++++++++++++++++++
> >  3 files changed, 517 insertions(+)
> >  create mode 100644 drivers/net/can/lin-serdev.c
> > 
> > diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
> > index 0934bbf8d03b2..91c6cdeefe440 100644
> > --- a/drivers/net/can/Kconfig
> > +++ b/drivers/net/can/Kconfig
> > @@ -181,6 +181,22 @@ config CAN_LIN
> >  
> >  	  Actual device drivers need to be enabled too.
> >  
> > +config CAN_LIN_SERDEV
> > +	tristate "Serial LIN Adaptors"
> > +	depends on CAN_LIN && SERIAL_DEV_BUS && OF
> > +	help
> > +	  LIN-Bus support for serial devices equipped with LIN transceievers.
> > +	  This device driver is using CAN_LIN for a userland connection on
> > +	  one side and the kernel its serial device bus (serdev) interface
> > +	  on the other side.
> > +
> > +	  If you have a hexlin tty adapter, say Y here and see
> > +	  <https://hexdev.de/hexlin#tty>.
> > +
> > +	  This driver can also be built as a module. If so, the module will be
> > +	  called lin-serdev.ko.
> > +
> > +
> >  config CAN_SLCAN
> >  	tristate "Serial / USB serial CAN Adaptors (slcan)"
> >  	depends on TTY
> > diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
> > index 0093ee9219ca8..21ca514a42439 100644
> > --- a/drivers/net/can/Makefile
> > +++ b/drivers/net/can/Makefile
> > @@ -26,6 +26,7 @@ obj-$(CONFIG_CAN_IFI_CANFD)	+= ifi_canfd/
> >  obj-$(CONFIG_CAN_JANZ_ICAN3)	+= janz-ican3.o
> >  obj-$(CONFIG_CAN_KVASER_PCIEFD)	+= kvaser_pciefd.o
> >  obj-$(CONFIG_CAN_LIN)		+= lin.o
> > +obj-$(CONFIG_CAN_LIN_SERDEV)	+= lin-serdev.o
> >  obj-$(CONFIG_CAN_MSCAN)		+= mscan/
> >  obj-$(CONFIG_CAN_M_CAN)		+= m_can/
> >  obj-$(CONFIG_CAN_PEAK_PCIEFD)	+= peak_canfd/
> > diff --git a/drivers/net/can/lin-serdev.c b/drivers/net/can/lin-serdev.c
> > new file mode 100644
> > index 0000000000000..13fd9a54c6c93
> > --- /dev/null
> > +++ b/drivers/net/can/lin-serdev.c
> > @@ -0,0 +1,500 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/* Copyright (C) 2024 hexDEV GmbH - https://hexdev.de */
> > +
> > +#include <linux/delay.h>
> > +#include <linux/init.h>
> > +#include <linux/kfifo.h>
> > +#include <linux/module.h>
> > +#include <linux/of.h>
> > +#include <linux/serdev.h>
> > +#include <linux/slab.h>
> > +#include <linux/tty.h>
> > +#include <net/lin.h>
> > +
> > +#define LINSER_SAMPLES_PER_CHAR		10
> > +#define LINSER_TX_BUFFER_SIZE		11
> > +#define LINSER_RX_FIFO_SIZE		256
> > +#define LINSER_PARSE_BUFFER		24
> > +
> > +struct linser_rx {
> > +	u8 data;
> > +	u8 flag;
> > +};
> > +
> > +enum linser_rx_status {
> > +	NEED_MORE = -1,
> > +	MODE_OK = 0,
> > +	NEED_FORCE,
> > +};
> > +
> > +struct linser_priv {
> > +	struct lin_device *lin_dev;
> > +	struct serdev_device *serdev;
> > +	DECLARE_KFIFO_PTR(rx_fifo, struct linser_rx);
> > +	struct delayed_work rx_work;
> > +	unsigned long break_usleep_min;
> > +	unsigned long break_usleep_max;
> > +	unsigned long post_break_usleep_min;
> > +	unsigned long post_break_usleep_max;
> > +	unsigned long force_timeout_jfs;
> > +	struct lin_responder_answer respond_answ[LIN_NUM_IDS];
> > +	struct mutex resp_lock; /* protects respond_answ */
> > +	bool is_stopped;
> > +};
> > +
> > +static int linser_open(struct lin_device *ldev)
> > +{
> > +	struct serdev_device *serdev = to_serdev_device(ldev->dev);
> > +	struct linser_priv *priv = serdev_device_get_drvdata(serdev);
> > +	int ret;
> > +
> > +	if (priv->is_stopped) {
> > +		ret = serdev_device_open(serdev);
> > +		if (ret) {
> > +			dev_err(&serdev->dev, "Unable to open device\n");
> > +			return ret;
> > +		}
> > +
> > +		serdev_device_set_flow_control(serdev, false);
> > +		serdev_device_set_break_detection(serdev, true);
> > +
> > +		priv->is_stopped = false;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static int linser_stop(struct lin_device *ldev)
> > +{
> > +	struct serdev_device *serdev = to_serdev_device(ldev->dev);
> > +	struct linser_priv *priv = serdev_device_get_drvdata(serdev);
> > +
> > +	if (priv->is_stopped)
> > +		return 0;
> > +
> > +	serdev_device_close(serdev);
> > +	priv->is_stopped = true;
> > +
> > +	return 0;
> > +}
> > +
> > +static int linser_send_break(struct linser_priv *priv)
> > +{
> > +	struct serdev_device *serdev = priv->serdev;
> > +	int ret;
> > +
> > +	ret = serdev_device_break_ctl(serdev, -1);
> > +	if (ret)
> > +		return ret;
> > +
> > +	usleep_range(priv->break_usleep_min, priv->break_usleep_max);
> > +
> > +	ret = serdev_device_break_ctl(serdev, 0);
> > +	if (ret)
> > +		return ret;
> > +
> > +	usleep_range(priv->post_break_usleep_min, priv->post_break_usleep_max);
> > +
> > +	return 0;
> > +}
> > +
> > +static int linser_ldo_tx(struct lin_device *ldev, const struct lin_frame *lf)
> > +{
> > +	struct serdev_device *serdev = to_serdev_device(ldev->dev);
> > +	struct linser_priv *priv = serdev_device_get_drvdata(serdev);
> > +	u8 pid = LIN_FORM_PID(lf->lin_id);
> > +	u8 buf[LINSER_TX_BUFFER_SIZE];
> > +	ssize_t written_len, total_len;
> > +	u8 checksum;
> > +	int ret;
> > +
> > +	if (lf->len + 3 > LINSER_TX_BUFFER_SIZE) {
> > +		dev_err(&serdev->dev, "Frame length %u exceeds buffer size\n", lf->len);
> > +		return -EINVAL;
> > +	}
> > +
> > +	buf[0] = LIN_SYNC_BYTE;
> > +	buf[1] = pid;
> > +	total_len = 2;
> > +
> > +	if (lf->len) {
> > +		memcpy(&buf[2], lf->data, lf->len);
> > +		checksum = lin_get_checksum(pid, lf->len, lf->data,
> > +					    lf->checksum_mode);
> > +		buf[lf->len + 2] = checksum;
> > +		total_len += lf->len + 1;
> > +	}
> > +
> > +	ret = linser_send_break(priv);
> > +	if (ret)
> > +		return ret;
> > +
> > +	written_len = serdev_device_write(serdev, buf, total_len, 0);
> > +	if (written_len < total_len)
> > +		return written_len < 0 ? (int)written_len : -EIO;
> > +
> > +	dev_dbg(&serdev->dev, "sent out: %*ph\n", (int)total_len, buf);
> > +
> > +	serdev_device_wait_until_sent(serdev, 0);
> > +
> > +	return 0;
> > +}
> > +
> > +static void linser_derive_timings(struct linser_priv *priv, u16 bitrate)
> > +{
> > +	unsigned long break_baud = (bitrate * 2) / 3;
> > +	unsigned long timeout_us;
> > +
> > +	priv->break_usleep_min = (USEC_PER_SEC * LINSER_SAMPLES_PER_CHAR) /
> > +				 break_baud;
> > +	priv->break_usleep_max = priv->break_usleep_min + 50;
> > +	priv->post_break_usleep_min = (USEC_PER_SEC * 1 /* 1 bit */) / break_baud;
> 
> Don't mix comments and code like this.

OK

> 
> > +	priv->post_break_usleep_max = priv->post_break_usleep_min + 30;
> > +
> > +	timeout_us = DIV_ROUND_CLOSEST(USEC_PER_SEC * 256 /* bit */, bitrate);
> 
> Ditto.

OK

> 
> > +	priv->force_timeout_jfs = usecs_to_jiffies(timeout_us);
> > +}
> > +
> > +static int linser_update_bitrate(struct lin_device *ldev, u16 bitrate)
> > +{
> > +	struct serdev_device *serdev = to_serdev_device(ldev->dev);
> > +	struct linser_priv *priv = serdev_device_get_drvdata(serdev);
> > +	unsigned int speed;
> > +	int ret;
> > +
> > +	ret = linser_open(ldev);
> > +	if (ret)
> > +		return ret;
> > +
> > +	speed = serdev_device_set_baudrate(serdev, bitrate);
> > +	if (!bitrate || speed != bitrate)
> > +		return -EINVAL;
> > +
> > +	linser_derive_timings(priv, bitrate);
> > +
> > +	return 0;
> > +}
> > +
> > +static int linser_get_responder_answer(struct lin_device *ldev, u8 id,
> > +				       struct lin_responder_answer *answ)
> > +{
> > +	struct serdev_device *serdev = to_serdev_device(ldev->dev);
> > +	struct linser_priv *priv = serdev_device_get_drvdata(serdev);
> > +	struct lin_responder_answer *r = &priv->respond_answ[id];
> > +
> > +	if (!answ)
> > +		return -EINVAL;
> > +
> > +	mutex_lock(&priv->resp_lock);
> 
> guard(mutex)(&priv->resp_lock);

OK

> 
> > +	memcpy(answ, r, sizeof(struct lin_responder_answer));
> 
> sizeof(*answ);

OK

> 
> > +	mutex_unlock(&priv->resp_lock);
> > +
> > +	return 0;
> > +}
> > +
> > +static int linser_update_resp_answer(struct lin_device *ldev,
> > +				     const struct lin_responder_answer *answ)
> > +{
> > +	struct serdev_device *serdev = to_serdev_device(ldev->dev);
> > +	struct linser_priv *priv = serdev_device_get_drvdata(serdev);
> > +	struct lin_responder_answer *r = &priv->respond_answ[answ->lf.lin_id];
> > +
> > +	if (!answ)
> > +		return -EINVAL;
> > +
> > +	mutex_lock(&priv->resp_lock);
> > +	memcpy(r, answ, sizeof(struct lin_responder_answer));
> 
> Ditto.

OK

> 
> > +	r->lf.checksum = lin_get_checksum(LIN_FORM_PID(answ->lf.lin_id),
> > +					  answ->lf.len,
> > +					  answ->lf.data,
> > +					  answ->lf.checksum_mode);
> > +	mutex_unlock(&priv->resp_lock);
> > +
> > +	return 0;
> > +}
> > +
> > +static struct lin_device_ops linser_lindev_ops = {
> > +	.ldo_open = linser_open,
> > +	.ldo_stop = linser_stop,
> > +	.ldo_tx = linser_ldo_tx,
> > +	.update_bitrate = linser_update_bitrate,
> > +	.get_responder_answer = linser_get_responder_answer,
> > +	.update_responder_answer = linser_update_resp_answer,
> > +};
> > +
> > +static bool linser_tx_frame_as_responder(struct linser_priv *priv, u8 id)
> > +{
> > +	struct lin_responder_answer *answ = &priv->respond_answ[id];
> > +	struct serdev_device *serdev = priv->serdev;
> > +	u8 buf[LINSER_TX_BUFFER_SIZE];
> > +	u8 checksum, count, n;
> > +	ssize_t write_len;
> > +
> > +	mutex_lock(&priv->resp_lock);
> 
> scoped_guard() can be used here.

OK

> 
> > +
> > +	if (!answ->is_active) {
> > +		mutex_unlock(&priv->resp_lock);
> > +		return false;
> > +	}
> > +
> > +	if (answ->is_event_frame) {
> > +		struct lin_responder_answer *e_answ;
> > +
> > +		e_answ = &priv->respond_answ[answ->event_associated_id];
> > +		n = min(e_answ->lf.len, LIN_MAX_DLEN);
> > +		if (memcmp(answ->lf.data, e_answ->lf.data, n) != 0) {
> > +			memcpy(answ->lf.data, e_answ->lf.data, n);
> > +			checksum = lin_get_checksum(LIN_FORM_PID(answ->lf.lin_id),
> > +						    n, e_answ->lf.data,
> > +						    answ->lf.checksum_mode);
> > +			answ = e_answ;
> > +		} else {
> > +			mutex_unlock(&priv->resp_lock);
> > +			return false;
> 
> Use reverse logic so you can reduce indent.

OK

> 
> > +		}
> > +	} else {
> > +		checksum = answ->lf.checksum;
> > +	}
> > +
> > +	count = min(answ->lf.len, LIN_MAX_DLEN);
> > +	memcpy(&buf[0], answ->lf.data, count);
> > +	buf[count] = checksum;
> > +
> > +	mutex_unlock(&priv->resp_lock);
> > +
> > +	write_len = serdev_device_write(serdev, buf, count + 1, 0);
> > +	if (write_len < count + 1)
> > +		return false;
> > +
> > +	serdev_device_wait_until_sent(serdev, 0);
> > +
> > +	return true;
> > +}
> > +
> > +static void linser_pop_fifo(struct linser_priv *priv, size_t n)
> > +{
> > +	for (size_t i = 0; i < n; i++)
> > +		kfifo_skip(&priv->rx_fifo);
> > +}
> > +
> > +static int linser_fill_frame(struct linser_priv *priv, struct lin_frame *lf)
> > +{
> > +	struct serdev_device *serdev = priv->serdev;
> > +	struct linser_rx buf[LINSER_PARSE_BUFFER];
> > +	unsigned int count, i, brk = 0;
> > +
> > +	count = kfifo_out_peek(&priv->rx_fifo, buf, LINSER_PARSE_BUFFER);
> > +
> > +	memset(lf, 0, sizeof(struct lin_frame));
> > +
> > +	for (i = 0; i < count; i++) {
> > +		dev_dbg(&serdev->dev, "buf[%d]: data=%02x, flag=%02x\n",
> > +			i, buf[i].data, buf[i].flag);
> > +	}
> > +
> > +	if (count < 3)
> > +		return NEED_MORE;
> > +
> > +	if (buf[0].flag != TTY_BREAK || buf[1].data != LIN_SYNC_BYTE) {
> > +		linser_pop_fifo(priv, 1); /* pop incorrect start */
> > +		return NEED_MORE;
> > +	} else if (!LIN_CHECK_PID(buf[2].data)) {
> > +		linser_pop_fifo(priv, 3); /* pop incorrect header */
> > +		return NEED_MORE;
> > +	}
> > +
> > +	lf->lin_id = LIN_GET_ID(buf[2].data);
> > +
> > +	/* from here on we do have a correct LIN header */
> > +
> > +	if (count == 3)
> > +		return linser_tx_frame_as_responder(priv, lf->lin_id) ?
> > +		       NEED_MORE : NEED_FORCE;
> > +
> > +	for (i = 3; i < count && i < LINSER_PARSE_BUFFER && i < 12; i++) {
> > +		if (buf[i].flag == TTY_BREAK) {
> > +			brk = i;
> > +			break;
> > +		}
> > +		lf->len++;
> > +	}
> > +	if (lf->len)
> > +		lf->len -= 1; /* account for checksum */
> > +
> > +	if (brk == 3)
> > +		return MODE_OK;
> > +
> > +	if (brk == 4) {
> > +		/* suppress wrong answer data-byte in between PID and break
> > +		 * because checksum is missing
> > +		 */
> > +		return MODE_OK;
> > +	}
> > +
> > +	for (i = 0; i < lf->len; i++)
> > +		lf->data[i] = buf[3 + i].data;
> > +	lf->checksum = buf[2 + lf->len + 1].data;
> > +	mutex_lock(&priv->resp_lock);
> > +	lf->checksum_mode = priv->respond_answ[lf->lin_id].lf.checksum_mode;
> > +	mutex_unlock(&priv->resp_lock);
> > +
> > +	dev_dbg(&serdev->dev, "brk:%i, len:%u, data:%*ph, checksum:%x (%s)\n",
> > +		brk, lf->len, lf->len, lf->data, lf->checksum,
> > +		lf->checksum_mode ? "enhanced" : "classic");
> > +
> > +	if (brk > 4)
> > +		return MODE_OK;	/* frame in between two breaks: so complete */
> > +
> > +	if (lf->len == 8)
> > +		return MODE_OK;
> > +
> > +	return NEED_FORCE;
> > +}
> > +
> > +static int linser_process_frame(struct linser_priv *priv, bool force)
> > +{
> > +	struct serdev_device *serdev = priv->serdev;
> > +	struct lin_frame lf;
> > +	size_t bytes_to_pop;
> > +	int ret = NEED_MORE;
> > +
> > +	while (kfifo_len(&priv->rx_fifo) >= LIN_HEADER_SIZE) {
> > +		ret = linser_fill_frame(priv, &lf);
> > +
> > +		if (ret == MODE_OK || (ret == NEED_FORCE && force)) {
> > +			dev_dbg(&serdev->dev, "lin_rx: %s\n",
> > +				force ? "force" : "normal");
> > +			lin_rx(priv->lin_dev, &lf);
> > +			bytes_to_pop = LIN_HEADER_SIZE + lf.len +
> > +				       (lf.len ? 1 : 0);
> > +			linser_pop_fifo(priv, bytes_to_pop);
> > +			force = false;
> > +			ret = MODE_OK;
> > +		} else {
> > +			return ret;
> 
> Reverse logic & deindent the main block.

OK

...

thanks
  -- Christoph


^ permalink raw reply

* Re: [PATCH v3 08/11] can: bcm: Add LIN answer offloading for responder mode
From: Christoph Fritz @ 2024-05-09 17:06 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Jiri Slaby, Oliver Hartkopp, Marc Kleine-Budde, Vincent Mailhol,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jiri Kosina,
	Benjamin Tissoires, Greg Kroah-Hartman, Sebastian Reichel,
	Linus Walleij, Andreas Lauser, Jonathan Corbet, Pavel Pisa,
	linux-can, Netdev, devicetree, linux-input, linux-serial
In-Reply-To: <48a79803-0fc9-3931-08f1-4b26b4a9ae93@linux.intel.com>

On Mon, 2024-05-06 at 20:08 +0300, Ilpo Järvinen wrote:
> On Thu, 2 May 2024, Christoph Fritz wrote:
> 
> > Enhance CAN broadcast manager with RX_LIN_SETUP and RX_LIN_DELETE
> > operations to setup automatic LIN frame responses in responder mode.
> > 
> > Additionally, the patch introduces the LIN_EVENT_FRAME flag to
> > setup event-triggered LIN frames.
> > 
> > Signed-off-by: Christoph Fritz <christoph.fritz@hexdev.de>
> > ---
> >  include/uapi/linux/can/bcm.h |  5 ++-
> >  net/can/bcm.c                | 74 +++++++++++++++++++++++++++++++++++-
> >  2 files changed, 77 insertions(+), 2 deletions(-)
> > 
> > diff --git a/include/uapi/linux/can/bcm.h b/include/uapi/linux/can/bcm.h
> > index f1e45f533a72c..c46268a114078 100644
> > --- a/include/uapi/linux/can/bcm.h
> > +++ b/include/uapi/linux/can/bcm.h
> > @@ -86,7 +86,9 @@ enum {
> >  	TX_EXPIRED,	/* notification on performed transmissions (count=0) */
> >  	RX_STATUS,	/* reply to RX_READ request */
> >  	RX_TIMEOUT,	/* cyclic message is absent */
> > -	RX_CHANGED	/* updated CAN frame (detected content change) */
> > +	RX_CHANGED,	/* updated CAN frame (detected content change) */
> > +	RX_LIN_SETUP,	/* create auto-response for LIN frame */
> > +	RX_LIN_DELETE,  /* remove auto-response for LIN frame */
> >  };
> >  
> >  #define SETTIMER            0x0001
> > @@ -101,5 +103,6 @@ enum {
> >  #define TX_RESET_MULTI_IDX  0x0200
> >  #define RX_RTR_FRAME        0x0400
> >  #define CAN_FD_FRAME        0x0800
> > +#define LIN_EVENT_FRAME     0x1000
> >  
> >  #endif /* !_UAPI_CAN_BCM_H */
> > diff --git a/net/can/bcm.c b/net/can/bcm.c
> > index 27d5fcf0eac9d..a717e594234d1 100644
> > --- a/net/can/bcm.c
> > +++ b/net/can/bcm.c
> > @@ -59,6 +59,7 @@
> >  #include <linux/can/bcm.h>
> >  #include <linux/slab.h>
> >  #include <net/sock.h>
> > +#include <net/lin.h>
> >  #include <net/net_namespace.h>
> >  
> >  /*
> > @@ -1330,6 +1331,59 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk,
> >  	return cfsiz + MHSIZ;
> >  }
> >  
> > +static int bcm_lin_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
> > +			 int ifindex, struct sock *sk, int cfsiz, int is_active)
> > +{
> > +	struct lin_responder_answer answ;
> > +	struct net_device *dev;
> > +	struct sk_buff *skb;
> > +	struct canfd_frame cf;
> > +	netdevice_tracker tracker;
> > +	size_t sz;
> > +	int ret;
> > +
> > +	if (msg_head->nframes > 1)
> > +		return -EINVAL;
> > +
> > +	if (!(msg_head->flags & CAN_FD_FRAME))
> > +		return -EINVAL;
> > +
> > +	ret = memcpy_from_msg(&cf, msg, cfsiz);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	answ.lf.lin_id = cf.can_id & LIN_ID_MASK;
> > +	answ.is_active = is_active;
> > +	answ.is_event_frame = !!(msg_head->flags & LIN_EVENT_FRAME);
> > +	answ.event_associated_id = msg_head->can_id;
> > +	answ.lf.len = min(cf.len, LIN_MAX_DLEN);
> > +	memcpy(answ.lf.data, cf.data, answ.lf.len);
> > +	sz = min(sizeof(struct lin_responder_answer), sizeof(cf.data));
> > +	cf.can_id |= LIN_RXOFFLOAD_DATA_FLAG;
> > +	memcpy(cf.data, &answ, sz);
> > +
> > +	dev = netdev_get_by_index(sock_net(sk), ifindex, &tracker, GFP_KERNEL);
> > +	if (!dev)
> > +		return -ENODEV;
> > +
> > +	skb = alloc_skb(cfsiz + sizeof(struct can_skb_priv), gfp_any());
> 
> You just called the other function with GFP_KERNEL and you now need 
> gfp_any(). Which is correct??

I guess GFP_KERNEL but I'm not sure so I'll let gfp_any() decide for
netdev_get_by_index() too.

> 
> > +	if (!skb)
> > +		goto lin_out;
> > +
> > +	can_skb_reserve(skb);
> > +	can_skb_prv(skb)->ifindex = dev->ifindex;
> > +	can_skb_prv(skb)->skbcnt = 0;
> > +	skb_put_data(skb, &cf, cfsiz);
> > +
> > +	skb->dev = dev;
> > +	can_skb_set_owner(skb, sk);
> > +	ret = can_send(skb, 1); /* send with loopback */
> > +
> > +lin_out:
> > +	netdev_put(dev, &tracker);
> > +	return ret;
> > +}
> > +
> >  /*
> >   * bcm_sendmsg - process BCM commands (opcodes) from the userspace
> >   */
> > @@ -1429,12 +1483,30 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
> >  
> >  	case TX_SEND:
> >  		/* we need exactly one CAN frame behind the msg head */
> > -		if ((msg_head.nframes != 1) || (size != cfsiz + MHSIZ))
> > +		if (msg_head.nframes != 1 || size != cfsiz + MHSIZ)
> 
> Unrelated style fix, doesn't belong to this patch.

OK

...

thanks
  -- Christoph


^ permalink raw reply

* Re: [PATCH v3 09/11] can: lin: Handle rx offload config frames
From: Christoph Fritz @ 2024-05-09 17:07 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Jiri Slaby, Oliver Hartkopp, Marc Kleine-Budde, Vincent Mailhol,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jiri Kosina,
	Benjamin Tissoires, Greg Kroah-Hartman, Sebastian Reichel,
	Linus Walleij, Andreas Lauser, Jonathan Corbet, Pavel Pisa,
	linux-can, Netdev, devicetree, linux-input, linux-serial
In-Reply-To: <9cf35451-9d03-e487-c06b-580208ac3a3d@linux.intel.com>

On Mon, 2024-05-06 at 20:11 +0300, Ilpo Järvinen wrote:
> On Thu, 2 May 2024, Christoph Fritz wrote:
> 
> > The CAN Broadcast Manager now has the capability to dispatch CANFD
> > frames marked with the id LINBUS_RXOFFLOAD_ID. This patch introduces
> > functionality to interpret these specific frames, enabling the
> > configuration of RX offloading within the LIN driver.
> > 
> > Signed-off-by: Christoph Fritz <christoph.fritz@hexdev.de>
> > ---
> >  drivers/net/can/lin.c | 29 +++++++++++++++++++++++++++++
> >  1 file changed, 29 insertions(+)
> > 
> > diff --git a/drivers/net/can/lin.c b/drivers/net/can/lin.c
> > index 95906003666fb..ee2ebea2c865f 100644
> > --- a/drivers/net/can/lin.c
> > +++ b/drivers/net/can/lin.c
> > @@ -194,6 +194,27 @@ static void lin_remove_sysfs_id_files(struct net_device *ndev)
> >  	}
> >  }
> >  
> > +static int lin_setup_rxoffload(struct lin_device *ldev,
> > +			       struct canfd_frame *cfd)
> > +{
> > +	struct lin_responder_answer answ;
> > +
> > +	if (!(cfd->flags & CANFD_FDF))
> > +		return -EMSGSIZE;
> 
> This seems a bit odd error code.

OK, will be changed in v4 to more common -EINVAL.

> 
> > +	BUILD_BUG_ON(sizeof(struct lin_responder_answer) > sizeof(cfd->data));
> > +	memcpy(&answ, cfd->data, sizeof(struct lin_responder_answer));
> 
> 2x sizeof(answ)

OK

...

thanks
  -- Christoph


^ permalink raw reply

* [PATCH v4 00/11] LIN Bus support for Linux
From: Christoph Fritz @ 2024-05-09 17:17 UTC (permalink / raw)
  To: Ilpo Järvinen, Jiri Slaby, Simon Horman, Greg Kroah-Hartman,
	Marc Kleine-Budde, Oliver Hartkopp, Vincent Mailhol,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jiri Kosina,
	Benjamin Tissoires, Sebastian Reichel, Linus Walleij
  Cc: Andreas Lauser, Jonathan Corbet, Pavel Pisa, linux-can, netdev,
	devicetree, linux-input, linux-serial

This series is introducing basic Local Interconnect Network (LIN) (ISO
17987) [0] support to the Linux kernel, along with two drivers that make
use of it: An advanced USB adapter and a lightweight serdev driver (for
UARTs equipped with a LIN transceiver).

The LIN bus is common in the automotive industry for connecting
low-level devices like side mirrors, seats, ambient lights, etc.

The LIN bus is a lower-cost bus system with a subset of features of CAN.
Its earlier specification (before ISO) is publicly accessible [1].

This series of patches follows up on a discussion initiated by an RFC
patch series [2].

The core of this series is the first patch, which implements the CAN_LIN
glue driver. It basically utilizes the CAN interface on one side and
for device drivers on the other side it creates a rx() function and
several callbacks.

This approach is non-invasive, as LIN frames (nearly identical to CAN
frames) are just treated as a special case of CAN frames. This approach
eliminates the need for a separate API for LIN, allowing the use of
existing CAN tools, including the CAN broadcast manager.

For the responder part of LIN, when a device responds to a controller
request, it can reply on up to LIN its 64 possible IDs (0...63) with a
maximum of 8 bytes payload.  The response must be sent relatively
quickly, so offloading is used (which is used by most devices anyway).
Devices that do not support offloading (like the lightweight serdev)
handle the list of responses in the driver on a best-effort basis.

The CAN broadcast manager (bcm) makes a good interface for the LIN
userland interface, bcm is therefore enhanced to handle the
configuration of these offload RX frames, so that the device can handle
the response on its own.  As a basic alternative, a sysfs file per LIN
identifier gets also introduced.

The USB device driver for the hexLIN [3] adapter uses the HID protocol
and is located in the drivers/hid directory. Which is a bit uncommon for
a CAN device, but this is a LIN device and mainly a hid driver.

The other driver, the UART lin-serdev driver requires support for break
detection, this is addressed by two serdev patches.

The lin-serdev driver has been tested on an ARM SoC, on its uart
(uart-pl011) an adapter board (hexLIN-tty [4]) has been used.  As a
sidenote, in that tty serial driver (amba-pl011.c) it was necessary to
disable DMA_ENGINE to accurately detect breaks [5].

The functions for generating LIN-Breaks and checksums, originally from
a line discipline driver named sllin [6], have been adopted into the
lin-serdev driver.

To make use of the LIN mode configuration (commander or responder)
option, a patch for iproute2 [7] has been made.

The lin-utils [8] provide userland tools for reference, testing, and
evaluation. These utilities are currently separate but may potentially
be integrated into can-utils in the future.

[0]: https://en.wikipedia.org/wiki/Local_Interconnect_Network
[1]: https://www.lin-cia.org/fileadmin/microsites/lin-cia.org/resources/documents/LIN_2.2A.pdf
[2]: https://lwn.net/Articles/916049/
[3]: https://hexdev.de/hexlin
[4]: https://hexdev.de/hexlin#hexLINSER
[5]: https://github.com/raspberrypi/linux/issues/5985
[6]: https://github.com/lin-bus/linux-lin/blob/master/sllin/sllin.c
[7]: https://github.com/ch-f/iproute2/tree/lin-feature
[8]: https://github.com/ch-f/lin-utils

Changes in v4:
 - rebase to next-20240509
 - dt-bindings: rename lin-serdev to hexlinser
 - lin: don't use ndev uninitialized, use dev_err() instead
 - lin: fix missing failure return value
 - lin: use sysfs_emit() instead of scnprintf()
 - lin: use static init of sysfs files
 - hexlin: fix hid_dbg indent
 - hexlin: use __le16 for req.baudrate
 - hexlin: refactor to be able to drop kmemdup()
 - linser and hexlin: s/IS_ERR_OR_NULL()/IS_ERR()/
 - serdev treewide: refactor receive_buf() by adding argument flags
 - address minor changes from review

Changes in v3:
 - drop unneccessary mutex_lock/unlock and _destroy() in hexlin
 - add Kconfig depends for HID_MCS_HEXDEV
 - simplify reset retry in hexlin
 - simplify hid driver init
 - fix dt-bindings and its commit message
 - adapt and reorder includes
 - use unsigned long instead of ulong
 - use macro USEC_PER_SEC in linser_derive_timings()
 - drop goto in linser_tx_frame_as_responder() and use unlock+return
 - simplify linser_pop_fifo() by using kfifo_skip()
 - squash [PATCH v2 08/12] can: lin: Add special frame id for rx...

Changes in v2:
 - add open/stop functions to also address teardown issues
 - adapt dt-bindings description and add hexdev
 - use 'unsigned int' instead of 'uint'
 - add and adapt macros
 - address review comments

Christoph Fritz (11):
  can: Add LIN bus as CAN abstraction
  HID: hexLIN: Add support for USB LIN adapter
  treewide, serdev: add flags argument to receive_buf()
  tty: serdev: Add method to enable break flags
  dt-bindings: vendor-prefixes: Add hexDEV
  dt-bindings: net/can: Add serial LIN adapter hexLINSER
  can: Add support for hexDEV serial LIN adapter hexLINSER
  can: bcm: Add LIN answer offloading for responder mode
  can: lin: Handle rx offload config frames
  can: lin: Support setting LIN mode
  HID: hexLIN: Implement ability to update lin mode

 .../bindings/net/can/hexdev,hex-linser.yaml   |  32 +
 .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
 drivers/bluetooth/btmtkuart.c                 |   3 +-
 drivers/bluetooth/btnxpuart.c                 |   3 +-
 drivers/bluetooth/hci_serdev.c                |   3 +-
 drivers/gnss/serial.c                         |   2 +-
 drivers/gnss/sirf.c                           |   2 +-
 drivers/greybus/gb-beagleplay.c               |   2 +-
 drivers/hid/Kconfig                           |  19 +
 drivers/hid/Makefile                          |   1 +
 drivers/hid/hid-hexdev-hexlin.c               | 620 ++++++++++++++++++
 drivers/hid/hid-ids.h                         |   1 +
 drivers/hid/hid-quirks.c                      |   3 +
 drivers/iio/chemical/pms7003.c                |   2 +-
 drivers/iio/chemical/scd30_serial.c           |   3 +-
 drivers/iio/chemical/sps30_serial.c           |   3 +-
 drivers/iio/imu/bno055/bno055_ser_core.c      |   3 +-
 drivers/mfd/rave-sp.c                         |   2 +-
 drivers/net/can/Kconfig                       |  25 +
 drivers/net/can/Makefile                      |   2 +
 drivers/net/can/hex-linser.c                  | 505 ++++++++++++++
 drivers/net/can/lin.c                         | 537 +++++++++++++++
 drivers/net/ethernet/qualcomm/qca_uart.c      |   3 +-
 drivers/nfc/pn533/uart.c                      |   2 +-
 drivers/nfc/s3fwrn5/uart.c                    |   3 +-
 drivers/platform/chrome/cros_ec_uart.c        |   3 +-
 drivers/platform/surface/aggregator/core.c    |   2 +-
 .../lenovo-yoga-tab2-pro-1380-fastcharger.c   |   3 +-
 drivers/tty/serdev/core.c                     |  11 +
 drivers/tty/serdev/serdev-ttyport.c           |  19 +-
 drivers/w1/masters/w1-uart.c                  |   3 +-
 include/linux/serdev.h                        |  12 +-
 include/net/lin.h                             |  97 +++
 include/uapi/linux/can/bcm.h                  |   5 +-
 include/uapi/linux/can/netlink.h              |   2 +
 net/can/bcm.c                                 |  72 ++
 sound/drivers/serial-generic.c                |   3 +-
 37 files changed, 1991 insertions(+), 24 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/can/hexdev,hex-linser.yaml
 create mode 100644 drivers/hid/hid-hexdev-hexlin.c
 create mode 100644 drivers/net/can/hex-linser.c
 create mode 100644 drivers/net/can/lin.c
 create mode 100644 include/net/lin.h

-- 
2.39.2


^ permalink raw reply

* [PATCH v4 01/11] can: Add LIN bus as CAN abstraction
From: Christoph Fritz @ 2024-05-09 17:17 UTC (permalink / raw)
  To: Ilpo Järvinen, Jiri Slaby, Simon Horman, Greg Kroah-Hartman,
	Marc Kleine-Budde, Oliver Hartkopp, Vincent Mailhol,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jiri Kosina,
	Benjamin Tissoires, Sebastian Reichel, Linus Walleij
  Cc: Andreas Lauser, Jonathan Corbet, Pavel Pisa, linux-can, netdev,
	devicetree, linux-input, linux-serial
In-Reply-To: <20240509171736.2048414-1-christoph.fritz@hexdev.de>

Introduce a LIN (local interconnect network) abstraction on top of CAN.
This is a glue driver adapting CAN on one side while offering LIN
abstraction on the other side. So that upcoming LIN device drivers can
make use of it.

Tested-by: Andreas Lauser <andreas.lauser@mercedes-benz.com>
Signed-off-by: Christoph Fritz <christoph.fritz@hexdev.de>
---
 drivers/net/can/Kconfig          |  10 +
 drivers/net/can/Makefile         |   1 +
 drivers/net/can/lin.c            | 470 +++++++++++++++++++++++++++++++
 include/net/lin.h                |  90 ++++++
 include/uapi/linux/can/netlink.h |   1 +
 5 files changed, 572 insertions(+)
 create mode 100644 drivers/net/can/lin.c
 create mode 100644 include/net/lin.h

diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index 2e31db55d9278..0934bbf8d03b2 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -171,6 +171,16 @@ config CAN_KVASER_PCIEFD
 	    Kvaser M.2 PCIe 4xCAN
 	    Kvaser PCIe 8xCAN
 
+config CAN_LIN
+	tristate "LIN mode support"
+	help
+	  This is a glue driver for LIN-BUS support.
+
+	  The local interconnect (LIN) bus is a simple bus with a feature
+	  subset of CAN. It is often combined with CAN for simple controls.
+
+	  Actual device drivers need to be enabled too.
+
 config CAN_SLCAN
 	tristate "Serial / USB serial CAN Adaptors (slcan)"
 	depends on TTY
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
index 4669cd51e7bf5..0093ee9219ca8 100644
--- a/drivers/net/can/Makefile
+++ b/drivers/net/can/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_CAN_GRCAN)		+= grcan.o
 obj-$(CONFIG_CAN_IFI_CANFD)	+= ifi_canfd/
 obj-$(CONFIG_CAN_JANZ_ICAN3)	+= janz-ican3.o
 obj-$(CONFIG_CAN_KVASER_PCIEFD)	+= kvaser_pciefd.o
+obj-$(CONFIG_CAN_LIN)		+= lin.o
 obj-$(CONFIG_CAN_MSCAN)		+= mscan/
 obj-$(CONFIG_CAN_M_CAN)		+= m_can/
 obj-$(CONFIG_CAN_PEAK_PCIEFD)	+= peak_canfd/
diff --git a/drivers/net/can/lin.c b/drivers/net/can/lin.c
new file mode 100644
index 0000000000000..a22768c17e3f8
--- /dev/null
+++ b/drivers/net/can/lin.c
@@ -0,0 +1,470 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (C) 2024 hexDEV GmbH - https://hexdev.de */
+
+#include <linux/can/core.h>
+#include <linux/can/dev.h>
+#include <linux/can/error.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/netdevice.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <net/lin.h>
+
+static const u8 lin_id_parity_tbl[] = {
+	0x80, 0xC0, 0x40, 0x00, 0xC0, 0x80, 0x00, 0x40,
+	0x00, 0x40, 0xC0, 0x80, 0x40, 0x00, 0x80, 0xC0,
+	0x40, 0x00, 0x80, 0xC0, 0x00, 0x40, 0xC0, 0x80,
+	0xC0, 0x80, 0x00, 0x40, 0x80, 0xC0, 0x40, 0x00,
+	0x00, 0x40, 0xC0, 0x80, 0x40, 0x00, 0x80, 0xC0,
+	0x80, 0xC0, 0x40, 0x00, 0xC0, 0x80, 0x00, 0x40,
+	0xC0, 0x80, 0x00, 0x40, 0x80, 0xC0, 0x40, 0x00,
+	0x40, 0x00, 0x80, 0xC0, 0x00, 0x40, 0xC0, 0x80,
+};
+
+u8 lin_get_id_parity(u8 id)
+{
+	return lin_id_parity_tbl[id];
+}
+EXPORT_SYMBOL(lin_get_id_parity);
+
+static ssize_t lin_identifier_show(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct lin_device *ldev = netdev_priv(to_net_dev(dev));
+	struct lin_responder_answer answ;
+	int k, count, ret;
+	long id;
+
+	if (!ldev->ldev_ops->get_responder_answer)
+		return -EOPNOTSUPP;
+
+	ret = kstrtol(attr->attr.name, 16, &id);
+	if (ret)
+		return ret;
+	if (id < 0 || id >= LIN_NUM_IDS)
+		return -EINVAL;
+
+	count = sysfs_emit(buf, "%-6s %-11s %-9s %-9s %-2s %-24s %-6s\n",
+			   "state", "cksum-mode", "is_event", "event_id",
+			   "n", "data", "cksum");
+
+	ret = ldev->ldev_ops->get_responder_answer(ldev, id, &answ);
+	if (ret)
+		return ret;
+
+	count += sysfs_emit_at(buf, count, "%-6s %-11s %-9s %-9u %-2u ",
+			       answ.is_active ? "active" : "off",
+			       answ.lf.checksum_mode ? "enhanced" : "classic",
+			       answ.is_event_frame ? "yes" : "no",
+			       answ.event_associated_id,
+			       answ.lf.len);
+
+	for (k = 0; k < answ.lf.len; k++)
+		count += sysfs_emit_at(buf, count, "%02x ", answ.lf.data[k]);
+	for (; k < 8; k++)
+		count += sysfs_emit_at(buf, count, "   ");
+	if (answ.lf.len)
+		count += sysfs_emit_at(buf, count, " %02x", answ.lf.checksum);
+
+	count += sysfs_emit_at(buf, count, "\n");
+
+	return count;
+}
+
+static const char *parse_and_advance(const char *buf, long *result,
+				     unsigned int base)
+{
+	char num_str[5] = {0};
+	int num_len = 0;
+
+	while (*buf && isspace(*buf))
+		buf++;
+	while (*buf && isalnum(*buf) && num_len < sizeof(num_str) - 1)
+		num_str[num_len++] = *buf++;
+	if (kstrtol(num_str, base, result))
+		return NULL;
+
+	return buf;
+}
+
+static ssize_t lin_identifier_store(struct device *dev,
+				    struct device_attribute *attr,
+				    const char *buf, size_t count)
+{
+	struct lin_device *ldev = netdev_priv(to_net_dev(dev));
+	struct lin_responder_answer answ = { 0 };
+	const char *ptr = buf;
+	int ret;
+	long v;
+
+	if (!ldev->ldev_ops->update_responder_answer)
+		return -EOPNOTSUPP;
+
+	ret = kstrtol(attr->attr.name, 16, &v);
+	if (ret)
+		return ret;
+	if (v < 0 || v >= LIN_NUM_IDS)
+		return -EINVAL;
+	answ.lf.lin_id = v;
+
+	ptr = parse_and_advance(ptr, &v, 2);
+	if (!ptr)
+		return -EINVAL;
+	answ.is_active = v != 0;
+
+	ptr = parse_and_advance(ptr, &v, 2);
+	if (!ptr)
+		return -EINVAL;
+	answ.lf.checksum_mode = v != 0;
+
+	ptr = parse_and_advance(ptr, &v, 2);
+	if (!ptr)
+		return -EINVAL;
+	answ.is_event_frame = v != 0;
+
+	ptr = parse_and_advance(ptr, &v, 16);
+	if (!ptr || v > LIN_ID_MASK)
+		return -EINVAL;
+	answ.event_associated_id = v;
+
+	ptr = parse_and_advance(ptr, &v, 16);
+	if (!ptr || v > LIN_MAX_DLEN)
+		return -EINVAL;
+	answ.lf.len = v;
+
+	for (int i = 0; i < answ.lf.len; i++) {
+		ptr = parse_and_advance(ptr, &v, 16);
+		if (!ptr)
+			return -EINVAL;
+		answ.lf.data[i] = v;
+	}
+
+	ret = ldev->ldev_ops->update_responder_answer(ldev, &answ);
+	if (ret)
+		return ret;
+
+	return count;
+}
+
+#define LID(_name) \
+	struct device_attribute linid_##_name = __ATTR(_name, 0644, \
+	lin_identifier_show, lin_identifier_store)
+
+LID(00); LID(01); LID(02); LID(03); LID(04); LID(05); LID(06); LID(07);
+LID(08); LID(09); LID(0a); LID(0b); LID(0c); LID(0d); LID(0e); LID(0f);
+LID(10); LID(11); LID(12); LID(13); LID(14); LID(15); LID(16); LID(17);
+LID(18); LID(19); LID(1a); LID(1b); LID(1c); LID(1d); LID(1e); LID(1f);
+LID(20); LID(21); LID(22); LID(23); LID(24); LID(25); LID(26); LID(27);
+LID(28); LID(29); LID(2a); LID(2b); LID(2c); LID(2d); LID(2e); LID(2f);
+LID(30); LID(31); LID(32); LID(33); LID(34); LID(35); LID(36); LID(37);
+LID(38); LID(39); LID(3a); LID(3b); LID(3c); LID(3d); LID(3e); LID(3f);
+
+static struct attribute *lin_sysfs_attrs[] = {
+	&linid_00.attr, &linid_01.attr, &linid_02.attr, &linid_03.attr,
+	&linid_04.attr, &linid_05.attr, &linid_06.attr, &linid_07.attr,
+	&linid_08.attr, &linid_09.attr, &linid_0a.attr, &linid_0b.attr,
+	&linid_0c.attr, &linid_0d.attr, &linid_0e.attr, &linid_0f.attr,
+	&linid_10.attr, &linid_11.attr, &linid_12.attr, &linid_13.attr,
+	&linid_14.attr, &linid_15.attr, &linid_16.attr, &linid_17.attr,
+	&linid_18.attr, &linid_19.attr, &linid_1a.attr, &linid_1b.attr,
+	&linid_1c.attr, &linid_1d.attr, &linid_1e.attr, &linid_1f.attr,
+	&linid_20.attr, &linid_21.attr, &linid_22.attr, &linid_23.attr,
+	&linid_24.attr, &linid_25.attr, &linid_26.attr, &linid_27.attr,
+	&linid_28.attr, &linid_29.attr, &linid_2a.attr, &linid_2b.attr,
+	&linid_2c.attr, &linid_2d.attr, &linid_2e.attr, &linid_2f.attr,
+	&linid_30.attr, &linid_31.attr, &linid_32.attr, &linid_33.attr,
+	&linid_34.attr, &linid_35.attr, &linid_36.attr, &linid_37.attr,
+	&linid_38.attr, &linid_39.attr, &linid_3a.attr, &linid_3b.attr,
+	&linid_3c.attr, &linid_3d.attr, &linid_3e.attr, &linid_3f.attr,
+	NULL
+};
+
+static const struct attribute_group lin_sysfs_group = {
+	.name = "lin_ids",
+	.attrs = lin_sysfs_attrs,
+};
+
+static void lin_tx_work_handler(struct work_struct *ws)
+{
+	struct lin_device *ldev = container_of(ws, struct lin_device,
+					       tx_work);
+	struct net_device *ndev = ldev->ndev;
+	struct canfd_frame *cfd;
+	struct lin_frame lf;
+	int ret;
+
+	ldev->tx_busy = true;
+
+	cfd = (struct canfd_frame *)ldev->tx_skb->data;
+	lf.checksum_mode = (cfd->can_id & LIN_ENHANCED_CKSUM_FLAG) ?
+			   LINBUS_ENHANCED : LINBUS_CLASSIC;
+	lf.lin_id = cfd->can_id & LIN_ID_MASK;
+	lf.len = min(cfd->len, LIN_MAX_DLEN);
+	memcpy(lf.data, cfd->data, lf.len);
+
+	ret = ldev->ldev_ops->ldo_tx(ldev, &lf);
+	if (ret) {
+		DEV_STATS_INC(ndev, tx_dropped);
+		netdev_err_once(ndev, "transmission failure %d\n", ret);
+		goto lin_tx_out;
+	}
+
+	DEV_STATS_INC(ndev, tx_packets);
+	DEV_STATS_ADD(ndev, tx_bytes, lf.len);
+
+lin_tx_out:
+	ldev->tx_busy = false;
+	netif_wake_queue(ndev);
+}
+
+static netdev_tx_t lin_start_xmit(struct sk_buff *skb,
+				  struct net_device *ndev)
+{
+	struct lin_device *ldev = netdev_priv(ndev);
+
+	if (ldev->tx_busy)
+		return NETDEV_TX_BUSY;
+
+	netif_stop_queue(ndev);
+	ldev->tx_skb = skb;
+	queue_work(ldev->wq, &ldev->tx_work);
+
+	return NETDEV_TX_OK;
+}
+
+static int lin_open(struct net_device *ndev)
+{
+	struct lin_device *ldev = netdev_priv(ndev);
+	int ret;
+
+	ldev->tx_busy = false;
+
+	ret = open_candev(ndev);
+	if (ret)
+		return ret;
+
+	netif_wake_queue(ndev);
+
+	ldev->can.state = CAN_STATE_ERROR_ACTIVE;
+	ndev->mtu = CANFD_MTU;
+
+	return ldev->ldev_ops->ldo_open(ldev);
+}
+
+static int lin_stop(struct net_device *ndev)
+{
+	struct lin_device *ldev = netdev_priv(ndev);
+
+	close_candev(ndev);
+
+	flush_work(&ldev->tx_work);
+
+	ldev->can.state = CAN_STATE_STOPPED;
+
+	return ldev->ldev_ops->ldo_stop(ldev);
+}
+
+static const struct net_device_ops lin_netdev_ops = {
+	.ndo_open = lin_open,
+	.ndo_stop = lin_stop,
+	.ndo_start_xmit = lin_start_xmit,
+	.ndo_change_mtu = can_change_mtu,
+};
+
+u8 lin_get_checksum(u8 pid, u8 n_of_bytes, const u8 *bytes,
+		    enum lin_checksum_mode cm)
+{
+	unsigned int csum = 0;
+	int i;
+
+	if (cm == LINBUS_ENHANCED)
+		csum += pid;
+
+	for (i = 0; i < n_of_bytes; i++) {
+		csum += bytes[i];
+		if (csum > 255)
+			csum -= 255;
+	}
+
+	return (~csum & 0xff);
+}
+EXPORT_SYMBOL_GPL(lin_get_checksum);
+
+static int lin_bump_rx_err(struct lin_device *ldev, const struct lin_frame *lf)
+{
+	struct net_device *ndev = ldev->ndev;
+	struct can_frame cf = {0 };
+
+	if (lf->lin_id > LIN_ID_MASK) {
+		netdev_dbg(ndev, "id exceeds LIN max id\n");
+		cf.can_id = CAN_ERR_FLAG | CAN_ERR_PROT;
+		cf.data[3] = CAN_ERR_PROT_LOC_ID12_05;
+	}
+
+	if (lf->len > LIN_MAX_DLEN) {
+		netdev_dbg(ndev, "frame exceeds number of bytes\n");
+		cf.can_id = CAN_ERR_FLAG | CAN_ERR_PROT;
+		cf.data[3] = CAN_ERR_PROT_LOC_DLC;
+	}
+
+	if (lf->len) {
+		u8 checksum = lin_get_checksum(LIN_FORM_PID(lf->lin_id),
+					       lf->len, lf->data,
+					       lf->checksum_mode);
+
+		if (checksum != lf->checksum) {
+			netdev_dbg(ndev, "expected cksm: 0x%02x got: 0x%02x\n",
+				   checksum, lf->checksum);
+			cf.can_id = CAN_ERR_FLAG | CAN_ERR_PROT;
+			cf.data[2] = CAN_ERR_PROT_FORM;
+		}
+	}
+
+	if (cf.can_id & CAN_ERR_FLAG) {
+		struct can_frame *err_cf;
+		struct sk_buff *skb = alloc_can_err_skb(ndev, &err_cf);
+
+		if (unlikely(!skb))
+			return -ENOMEM;
+
+		err_cf->can_id |= cf.can_id;
+		memcpy(err_cf->data, cf.data, CAN_MAX_DLEN);
+
+		netif_rx(skb);
+
+		return -EREMOTEIO;
+	}
+
+	return 0;
+}
+
+int lin_rx(struct lin_device *ldev, const struct lin_frame *lf)
+{
+	struct net_device *ndev = ldev->ndev;
+	struct can_frame *cf;
+	struct sk_buff *skb;
+	int ret;
+
+	if (ldev->can.state == CAN_STATE_STOPPED)
+		return 0;
+
+	netdev_dbg(ndev, "id:%02x, len:%u, data:%*ph, checksum:%02x (%s)\n",
+		   lf->lin_id, lf->len, lf->len, lf->data, lf->checksum,
+		   lf->checksum_mode ? "enhanced" : "classic");
+
+	ret = lin_bump_rx_err(ldev, lf);
+	if (ret) {
+		DEV_STATS_INC(ndev, rx_dropped);
+		return ret;
+	}
+
+	skb = alloc_can_skb(ndev, &cf);
+	if (unlikely(!skb)) {
+		DEV_STATS_INC(ndev, rx_dropped);
+		return -ENOMEM;
+	}
+
+	cf->can_id = lf->lin_id;
+	cf->len = min(lf->len, LIN_MAX_DLEN);
+	memcpy(cf->data, lf->data, cf->len);
+
+	DEV_STATS_INC(ndev, rx_packets);
+	DEV_STATS_ADD(ndev, rx_bytes, cf->len);
+
+	netif_receive_skb(skb);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lin_rx);
+
+static int lin_set_bittiming(struct net_device *ndev)
+{
+	struct lin_device *ldev = netdev_priv(ndev);
+	unsigned int bitrate = ldev->can.bittiming.bitrate;
+
+	return ldev->ldev_ops->update_bitrate(ldev, bitrate);
+}
+
+static const u32 lin_bitrate[] = { 1200, 2400, 4800, 9600, 19200 };
+
+struct lin_device *register_lin(struct device *dev,
+				const struct lin_device_ops *ldops)
+{
+	struct net_device *ndev;
+	struct lin_device *ldev;
+	int ret;
+
+	if (!ldops || !ldops->ldo_tx || !ldops->update_bitrate  ||
+	    !ldops->ldo_open || !ldops->ldo_stop) {
+		dev_err(dev, "missing mandatory lin_device_ops\n");
+		return ERR_PTR(-EINVAL);
+	}
+
+	ndev = alloc_candev(sizeof(struct lin_device), 1);
+	if (!ndev)
+		return ERR_PTR(-ENOMEM);
+
+	ldev = netdev_priv(ndev);
+
+	ldev->ldev_ops = ldops;
+	ndev->netdev_ops = &lin_netdev_ops;
+	ndev->flags |= IFF_ECHO;
+	ndev->mtu = CANFD_MTU;
+	ndev->sysfs_groups[0] = &lin_sysfs_group;
+	ldev->can.bittiming.bitrate = LIN_DEFAULT_BAUDRATE;
+	ldev->can.ctrlmode = CAN_CTRLMODE_LIN;
+	ldev->can.ctrlmode_supported = 0;
+	ldev->can.bitrate_const = lin_bitrate;
+	ldev->can.bitrate_const_cnt = ARRAY_SIZE(lin_bitrate);
+	ldev->can.do_set_bittiming = lin_set_bittiming;
+	ldev->ndev = ndev;
+	ldev->dev = dev;
+
+	SET_NETDEV_DEV(ndev, dev);
+
+	ret = lin_set_bittiming(ndev);
+	if (ret) {
+		netdev_err(ndev, "set bittiming failed\n");
+		goto exit_candev;
+	}
+
+	ret = register_candev(ndev);
+	if (ret)
+		goto exit_candev;
+
+	/* Using workqueue as tx over USB/SPI/... may sleep */
+	ldev->wq = alloc_workqueue(dev_name(dev), WQ_FREEZABLE | WQ_MEM_RECLAIM,
+				   0);
+	if (!ldev->wq) {
+		ret = -ENOMEM;
+		goto exit_unreg;
+	}
+
+	INIT_WORK(&ldev->tx_work, lin_tx_work_handler);
+
+	netdev_info(ndev, "LIN initialized\n");
+
+	return ldev;
+
+exit_unreg:
+	unregister_candev(ndev);
+exit_candev:
+	free_candev(ndev);
+	return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(register_lin);
+
+void unregister_lin(struct lin_device *ldev)
+{
+	struct net_device *ndev = ldev->ndev;
+
+	unregister_candev(ndev);
+	destroy_workqueue(ldev->wq);
+	free_candev(ndev);
+}
+EXPORT_SYMBOL_GPL(unregister_lin);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Christoph Fritz <christoph.fritz@hexdev.de>");
+MODULE_DESCRIPTION("LIN bus to CAN glue driver");
diff --git a/include/net/lin.h b/include/net/lin.h
new file mode 100644
index 0000000000000..31bb0feefd188
--- /dev/null
+++ b/include/net/lin.h
@@ -0,0 +1,90 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/* Copyright (C) 2024 hexDEV GmbH - https://hexdev.de */
+
+#ifndef _NET_LIN_H_
+#define _NET_LIN_H_
+
+#include <linux/bitfield.h>
+#include <linux/can/dev.h>
+#include <linux/device.h>
+
+#define LIN_NUM_IDS		64
+#define LIN_HEADER_SIZE		3
+#define LIN_MAX_DLEN		8
+
+#define LIN_MAX_BAUDRATE	20000
+#define LIN_MIN_BAUDRATE	1000
+#define LIN_DEFAULT_BAUDRATE	9600
+#define LIN_SYNC_BYTE		0x55
+
+#define LIN_ID_MASK		GENMASK(5, 0)
+/* special ID descriptions for LIN */
+#define LIN_RXOFFLOAD_DATA_FLAG	BIT(9)
+#define LIN_ENHANCED_CKSUM_FLAG	BIT(8)
+
+extern u8 lin_get_id_parity(u8 id);
+
+#define LIN_GET_ID(PID)		FIELD_GET(LIN_ID_MASK, PID)
+#define LIN_FORM_PID(ID)	(LIN_GET_ID(ID) | \
+					lin_get_id_parity(LIN_GET_ID(ID)))
+#define LIN_GET_PARITY(PID)	((PID) & ~LIN_ID_MASK)
+#define LIN_CHECK_PID(PID)	(LIN_GET_PARITY(PID) == \
+					LIN_GET_PARITY(LIN_FORM_PID(PID)))
+
+struct lin_attr {
+	struct kobj_attribute attr;
+	struct lin_device *ldev;
+};
+
+struct lin_device {
+	struct can_priv can;  /* must be the first member */
+	struct net_device *ndev;
+	struct device *dev;
+	const struct lin_device_ops *ldev_ops;
+	struct workqueue_struct *wq;
+	struct work_struct tx_work;
+	bool tx_busy;
+	struct sk_buff *tx_skb;
+};
+
+enum lin_checksum_mode {
+	LINBUS_CLASSIC = 0,
+	LINBUS_ENHANCED,
+};
+
+struct lin_frame {
+	u8 lin_id;
+	u8 len;
+	u8 data[LIN_MAX_DLEN];
+	u8 checksum;
+	enum lin_checksum_mode checksum_mode;
+};
+
+struct lin_responder_answer {
+	bool is_active;
+	bool is_event_frame;
+	u8 event_associated_id;
+	struct lin_frame lf;
+};
+
+struct lin_device_ops {
+	int (*ldo_open)(struct lin_device *ldev);
+	int (*ldo_stop)(struct lin_device *ldev);
+	int (*ldo_tx)(struct lin_device *ldev, const struct lin_frame *frame);
+	int (*update_bitrate)(struct lin_device *ldev, u16 bitrate);
+	int (*update_responder_answer)(struct lin_device *ldev,
+				       const struct lin_responder_answer *answ);
+	int (*get_responder_answer)(struct lin_device *ldev, u8 id,
+				    struct lin_responder_answer *answ);
+};
+
+int lin_rx(struct lin_device *ldev, const struct lin_frame *lf);
+
+u8 lin_get_checksum(u8 pid, u8 n_of_bytes, const u8 *bytes,
+		    enum lin_checksum_mode cm);
+
+struct lin_device *register_lin(struct device *dev,
+				const struct lin_device_ops *ldops);
+void unregister_lin(struct lin_device *ldev);
+
+#endif /* _NET_LIN_H_ */
diff --git a/include/uapi/linux/can/netlink.h b/include/uapi/linux/can/netlink.h
index 02ec32d694742..a37f56d86c5f2 100644
--- a/include/uapi/linux/can/netlink.h
+++ b/include/uapi/linux/can/netlink.h
@@ -103,6 +103,7 @@ struct can_ctrlmode {
 #define CAN_CTRLMODE_CC_LEN8_DLC	0x100	/* Classic CAN DLC option */
 #define CAN_CTRLMODE_TDC_AUTO		0x200	/* CAN transiver automatically calculates TDCV */
 #define CAN_CTRLMODE_TDC_MANUAL		0x400	/* TDCV is manually set up by user */
+#define CAN_CTRLMODE_LIN		BIT(11)	/* LIN bus mode */
 
 /*
  * CAN device statistics
-- 
2.39.2


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox