public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: Use $(SRCARCH) instead of $(ARCH)
@ 2025-04-30 22:47 David Matlack
  2025-05-01  0:34 ` David Matlack
  2025-05-01 17:47 ` David Matlack
  0 siblings, 2 replies; 4+ messages in thread
From: David Matlack @ 2025-04-30 22:47 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Sean Christopherson, Muhammad Usama Anjum, kvm, linux-riscv,
	David Matlack

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>
---
 tools/testing/selftests/kvm/Makefile     | 10 +++++----
 tools/testing/selftests/kvm/Makefile.kvm | 26 ++++++++++++------------
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index 20af35a91d6f..02bf061c51f8 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -1,13 +1,15 @@
 # SPDX-License-Identifier: GPL-2.0-only
 top_srcdir = ../../../..
+
 include $(top_srcdir)/scripts/subarch.include
-ARCH            ?= $(SUBARCH)
+ARCH 	?= $(SUBARCH)
+SRCARCH := $(ARCH)
 
-ifeq ($(ARCH),$(filter $(ARCH),arm64 s390 riscv x86 x86_64))
-# Top-level selftests allows ARCH=x86_64 :-(
 ifeq ($(ARCH),x86_64)
-	ARCH := x86
+        SRCARCH := x86
 endif
+
+ifeq ($(SRCARCH),$(filter $(SRCARCH),arm64 s390 riscv x86))
 include Makefile.kvm
 else
 # Empty targets for unsupported architectures
diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
index f62b0a5aba35..065029b35355 100644
--- a/tools/testing/selftests/kvm/Makefile.kvm
+++ b/tools/testing/selftests/kvm/Makefile.kvm
@@ -193,10 +193,10 @@ TEST_GEN_PROGS_riscv += steal_time
 SPLIT_TESTS += arch_timer
 SPLIT_TESTS += get-reg-list
 
-TEST_PROGS += $(TEST_PROGS_$(ARCH))
-TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(ARCH))
-TEST_GEN_PROGS_EXTENDED += $(TEST_GEN_PROGS_EXTENDED_$(ARCH))
-LIBKVM += $(LIBKVM_$(ARCH))
+TEST_PROGS += $(TEST_PROGS_$(SRCARCH))
+TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(SRCARCH))
+TEST_GEN_PROGS_EXTENDED += $(TEST_GEN_PROGS_EXTENDED_$(SRCARCH))
+LIBKVM += $(LIBKVM_$(SRCARCH))
 
 OVERRIDE_TARGETS = 1
 
@@ -208,24 +208,24 @@ include ../lib.mk
 INSTALL_HDR_PATH = $(top_srcdir)/usr
 LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
 LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include
-LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
+LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(SRCARCH)/include
 CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
 	-Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \
 	-fno-builtin-memcmp -fno-builtin-memcpy \
 	-fno-builtin-memset -fno-builtin-strnlen \
 	-fno-stack-protector -fno-PIE -fno-strict-aliasing \
 	-I$(LINUX_TOOL_INCLUDE) -I$(LINUX_TOOL_ARCH_INCLUDE) \
-	-I$(LINUX_HDR_PATH) -Iinclude -I$(<D) -Iinclude/$(ARCH) \
+	-I$(LINUX_HDR_PATH) -Iinclude -I$(<D) -Iinclude/$(SRCARCH) \
 	-I ../rseq -I.. $(EXTRA_CFLAGS) $(KHDR_INCLUDES)
-ifeq ($(ARCH),s390)
+ifeq ($(SRCARCH),s390)
 	CFLAGS += -march=z10
 endif
-ifeq ($(ARCH),x86)
+ifeq ($(SRCARCH),x86)
 ifeq ($(shell echo "void foo(void) { }" | $(CC) -march=x86-64-v2 -x c - -c -o /dev/null 2>/dev/null; echo "$$?"),0)
 	CFLAGS += -march=x86-64-v2
 endif
 endif
-ifeq ($(ARCH),arm64)
+ifeq ($(SRCARCH),arm64)
 tools_dir := $(top_srcdir)/tools
 arm64_tools_dir := $(tools_dir)/arch/arm64/tools/
 
@@ -259,7 +259,7 @@ LIBKVM_S_OBJ := $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S))
 LIBKVM_STRING_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_STRING))
 LIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(LIBKVM_STRING_OBJ)
 SPLIT_TEST_GEN_PROGS := $(patsubst %, $(OUTPUT)/%, $(SPLIT_TESTS))
-SPLIT_TEST_GEN_OBJ := $(patsubst %, $(OUTPUT)/$(ARCH)/%.o, $(SPLIT_TESTS))
+SPLIT_TEST_GEN_OBJ := $(patsubst %, $(OUTPUT)/$(SRCARCH)/%.o, $(SPLIT_TESTS))
 
 TEST_GEN_OBJ = $(patsubst %, %.o, $(TEST_GEN_PROGS))
 TEST_GEN_OBJ += $(patsubst %, %.o, $(TEST_GEN_PROGS_EXTENDED))
@@ -268,7 +268,7 @@ TEST_DEP_FILES += $(patsubst %.o, %.d, $(LIBKVM_OBJS))
 TEST_DEP_FILES += $(patsubst %.o, %.d, $(SPLIT_TEST_GEN_OBJ))
 -include $(TEST_DEP_FILES)
 
-$(shell mkdir -p $(sort $(OUTPUT)/$(ARCH) $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ))))
+$(shell mkdir -p $(sort $(OUTPUT)/$(SRCARCH) $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ))))
 
 $(filter-out $(SPLIT_TEST_GEN_PROGS), $(TEST_GEN_PROGS)) \
 $(TEST_GEN_PROGS_EXTENDED): %: %.o
@@ -276,9 +276,9 @@ $(TEST_GEN_PROGS_EXTENDED): %: %.o
 $(TEST_GEN_OBJ): $(OUTPUT)/%.o: %.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
 
-$(SPLIT_TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(OUTPUT)/$(ARCH)/%.o
+$(SPLIT_TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(OUTPUT)/$(SRCARCH)/%.o
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
-$(SPLIT_TEST_GEN_OBJ): $(OUTPUT)/$(ARCH)/%.o: $(ARCH)/%.c
+$(SPLIT_TEST_GEN_OBJ): $(OUTPUT)/$(SRCARCH)/%.o: $(SRCARCH)/%.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
 
 EXTRA_CLEAN += $(GEN_HDRS) \

base-commit: 45eb29140e68ffe8e93a5471006858a018480a45
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: selftests: Use $(SRCARCH) instead of $(ARCH)
  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
  1 sibling, 0 replies; 4+ messages in thread
From: David Matlack @ 2025-05-01  0:34 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Sean Christopherson, Muhammad Usama Anjum, kvm, linux-riscv

On Wed, Apr 30, 2025 at 3:47 PM David Matlack <dmatlack@google.com> 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.

Blegh I meant to say "The latter ...".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: selftests: Use $(SRCARCH) instead of $(ARCH)
  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
  2025-05-07 13:27   ` Sean Christopherson
  1 sibling, 1 reply; 4+ messages in thread
From: David Matlack @ 2025-05-01 17:47 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Sean Christopherson, Muhammad Usama Anjum, kvm, linux-riscv

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: selftests: Use $(SRCARCH) instead of $(ARCH)
  2025-05-01 17:47 ` David Matlack
@ 2025-05-07 13:27   ` Sean Christopherson
  0 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2025-05-07 13:27 UTC (permalink / raw)
  To: David Matlack
  Cc: Paolo Bonzini, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Muhammad Usama Anjum, kvm, linux-riscv

On Thu, May 01, 2025, David Matlack wrote:
> 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/.

Yes, please.  However, SRCARCH might be going away in the kernel's Makefile[*].
I recommend holding off on anything until that discussion is fully resolved.

[*] https://lore.kernel.org/all/cd541739-4ec5-4772-9cef-e3527fc69e26@app.fastmail.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-07 13:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2025-05-07 13:27   ` Sean Christopherson

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