public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: David Matlack <dmatlack@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>,
	Sean Christopherson <seanjc@google.com>,
	Muhammad Usama Anjum <usama.anjum@collabora.com>,
	kvm@vger.kernel.org, linux-riscv@lists.infradead.org
Subject: Re: [PATCH] KVM: selftests: Use $(SRCARCH) instead of $(ARCH)
Date: Thu, 1 May 2025 10:47:10 -0700	[thread overview]
Message-ID: <aBOznhkrLZ0Z_3Xw@google.com> (raw)
In-Reply-To: <20250430224720.1882145-1-dmatlack@google.com>

On 2025-04-30 03:47 PM, David Matlack wrote:
> Use $(SRCARCH) in Makefile.kvm instead of $(ARCH). The former may have
> been set on the command line and thus make will ignore the variable
> assignment to convert x86_64 to x86.
> 
> Introduce $(SRCARCH) rather than just reverting commit 9af04539d474
> ("KVM: selftests: Override ARCH for x86_64 instead of using ARCH_DIR")
> to keep KVM selftests consistent with the top-level kernel Makefile,
> which uses $(SRCARCH) for the exact same purpose.
> 
> While here, drop the comment about the top-level selftests allowing
> ARCH=x86_64. The kernel itself allows/expects ARCH=x86_64 so it's
> reasonable to expect the KVM selftests to handle it as well.
> 
> Fixes: 9af04539d474 ("KVM: selftests: Override ARCH for x86_64 instead of using ARCH_DIR")
> Signed-off-by: David Matlack <dmatlack@google.com>

If this approach seems reasonable I can also send another patch to share
the definitions of $(ARCH) and $(SRCARCH) with the top-level Makefile so
that we don't need any custom Makefile code in KVM selftests for this.

e.g.

From: David Matlack <dmatlack@google.com>
Date: Thu, 1 May 2025 10:30:26 -0700
Subject: [PATCH v2] kbuild: Share $(ARCH) and $(SRCARCH) with tools/

Pull out the definitions for $(ARCH), $(SRCARCH), and $(SUBARCH) into a
scripts/arch.include and use it to reduce duplication in Makefiles under
tools/.

Signed-off-by: David Matlack <dmatlack@google.com>
---
 Makefile                                  | 28 +++--------------------
 scripts/{subarch.include => arch.include} | 24 +++++++++++++++++++
 tools/include/nolibc/Makefile             |  5 +---
 tools/testing/selftests/Makefile          |  3 +--
 tools/testing/selftests/kvm/Makefile      |  8 +------
 tools/testing/selftests/nolibc/Makefile   |  5 +---
 6 files changed, 31 insertions(+), 42 deletions(-)
 rename scripts/{subarch.include => arch.include} (61%)

diff --git a/Makefile b/Makefile
index c91afd55099e..7a10252ddbe1 100644
--- a/Makefile
+++ b/Makefile
@@ -380,8 +380,6 @@ KERNELRELEASE = $(call read-file, $(objtree)/include/config/kernel.release)
 KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
 export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
 
-include $(srctree)/scripts/subarch.include
-
 # Cross compiling and selecting different set of gcc/bin-utils
 # ---------------------------------------------------------------------------
 #
@@ -400,32 +398,12 @@ include $(srctree)/scripts/subarch.include
 # Alternatively CROSS_COMPILE can be set in the environment.
 # Default value for CROSS_COMPILE is not to prefix executables
 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
-ARCH		?= $(SUBARCH)
+
+# Import definitions for SUBARCH, ARCH, and SRCARCH.
+include $(srctree)/scripts/arch.include
 
 # Architecture as present in compile.h
 UTS_MACHINE 	:= $(ARCH)
-SRCARCH 	:= $(ARCH)
-
-# Additional ARCH settings for x86
-ifeq ($(ARCH),i386)
-        SRCARCH := x86
-endif
-ifeq ($(ARCH),x86_64)
-        SRCARCH := x86
-endif
-
-# Additional ARCH settings for sparc
-ifeq ($(ARCH),sparc32)
-       SRCARCH := sparc
-endif
-ifeq ($(ARCH),sparc64)
-       SRCARCH := sparc
-endif
-
-# Additional ARCH settings for parisc
-ifeq ($(ARCH),parisc64)
-       SRCARCH := parisc
-endif
 
 export cross_compiling :=
 ifneq ($(SRCARCH),$(SUBARCH))
diff --git a/scripts/subarch.include b/scripts/arch.include
similarity index 61%
rename from scripts/subarch.include
rename to scripts/arch.include
index c4592d59d69b..545f731140df 100644
--- a/scripts/subarch.include
+++ b/scripts/arch.include
@@ -11,3 +11,27 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
 				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
 				  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
 				  -e s/riscv.*/riscv/ -e s/loongarch.*/loongarch/)
+
+ARCH		?= $(SUBARCH)
+SRCARCH 	:= $(ARCH)
+
+# Additional ARCH settings for x86
+ifeq ($(ARCH),i386)
+        SRCARCH := x86
+endif
+ifeq ($(ARCH),x86_64)
+        SRCARCH := x86
+endif
+
+# Additional ARCH settings for sparc
+ifeq ($(ARCH),sparc32)
+       SRCARCH := sparc
+endif
+ifeq ($(ARCH),sparc64)
+       SRCARCH := sparc
+endif
+
+# Additional ARCH settings for parisc
+ifeq ($(ARCH),parisc64)
+       SRCARCH := parisc
+endif
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index f9702877ac21..9a78fe77205f 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -8,10 +8,7 @@ srctree := $(patsubst %/tools/include/,%,$(dir $(CURDIR)))
 endif
 
 # when run as make -C tools/ nolibc_<foo> the arch is not set
-ifeq ($(ARCH),)
-include $(srctree)/scripts/subarch.include
-ARCH = $(SUBARCH)
-endif
+include $(srctree)/scripts/arch.include
 
 # OUTPUT is only set when run from the main makefile, otherwise
 # it defaults to this nolibc directory.
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index c77c8c8e3d9b..827ce9bf3e50 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -190,8 +190,7 @@ else
 endif
 
 # Prepare for headers install
-include $(top_srcdir)/scripts/subarch.include
-ARCH           ?= $(SUBARCH)
+include $(top_srcdir)/scripts/arch.include
 export BUILD
 export KHDR_INCLUDES
 
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index 02bf061c51f8..503530d671e9 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -1,13 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 top_srcdir = ../../../..
 
-include $(top_srcdir)/scripts/subarch.include
-ARCH 	?= $(SUBARCH)
-SRCARCH := $(ARCH)
-
-ifeq ($(ARCH),x86_64)
-        SRCARCH := x86
-endif
+include $(top_srcdir)/scripts/arch.include
 
 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm64 s390 riscv x86))
 include Makefile.kvm
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
index 58bcbbd029bc..13555d418c78 100644
--- a/tools/testing/selftests/nolibc/Makefile
+++ b/tools/testing/selftests/nolibc/Makefile
@@ -18,10 +18,7 @@ else
 objtree ?= $(srctree)
 endif
 
-ifeq ($(ARCH),)
-include $(srctree)/scripts/subarch.include
-ARCH = $(SUBARCH)
-endif
+include $(srctree)/scripts/arch.include
 
 cc-option = $(call __cc-option, $(CC),$(CLANG_CROSS_FLAGS),$(1),$(2))
 

base-commit: 45eb29140e68ffe8e93a5471006858a018480a45
prerequisite-patch-id: 3bae97c9e1093148763235f47a84fa040b512d04
-- 
2.49.0.906.g1f30a19c02-goog


  parent reply	other threads:[~2025-05-01 17:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-30 22:47 [PATCH] KVM: selftests: Use $(SRCARCH) instead of $(ARCH) David Matlack
2025-05-01  0:34 ` David Matlack
2025-05-01 17:47 ` David Matlack [this message]
2025-05-07 13:27   ` Sean Christopherson

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=aBOznhkrLZ0Z_3Xw@google.com \
    --to=dmatlack@google.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=kvm@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=usama.anjum@collabora.com \
    /path/to/YOUR_REPLY

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

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