KVM: selftests: Fix incremental build dependencies
Fuad Tabba
reviewerv2 cover KVM: selftests: Fix incremental build dependencies
Hi folks,
Changes since v1 [1]:
- Use FORCE for the sysreg header rule instead of duplicating the generator's inputs. (Oliver)
- Added patch 2, the same class of bug in libcgroup.mk, found while testing patch 1.
Two fixes for Makefile rules that name a directory where a file's mtime is what matters. The first is arm64-only: the sysreg header isn't regenerated on an incremental build when the sysreg table changes. The second is arch-independent: cgroup_util.o recompiles, and every test relinks, on the run after any rebuild in lib/. The two patches are independent.
I'd suggested v1 go through kvmarm as it was arm64-only. With patch 2 being generic, this one is addressed to kvm with kvmarm on Cc. Since the patches are independent, they can also go through separate trees if that's easier.
Based on Linux 7.3-rc1 (cee9395acd804).
Cheers,
/fuad
[1] https://lore.kernel.org/all/[email protected]/
Fuad Tabba (2):
KVM: selftests: Fix arm64 sysreg header dependencies selftests/cgroup: Make the object directory an order-only prerequisite
tools/testing/selftests/cgroup/lib/libcgroup.mk | 2 +- tools/testing/selftests/kvm/Makefile.kvm | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-)
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
Signature · 1 line
2.39.5
Fuad Tabba
reviewerPATCH v2 1/2 KVM: selftests: Fix arm64 sysreg header dependencies
The rule generating the arm64 sysreg header targets the generated directory, and its only prerequisite is tools/arch/arm64/tools/*, which expands to the inner Makefile. An existing directory looks up to date, so an incremental build never regenerates sysreg-defs.h for a change to the sysreg table. A selftest referencing a register added to the table since then fails with undeclared SYS_* identifiers. Clean builds are unaffected.
Always recurse into tools/arch/arm64/tools, whose Makefile already tracks the generator's inputs, and target the header rather than its directory. The recursion leaves the header untouched when nothing changed, so the dependents rebuild only when the header does.
--- tools/testing/selftests/kvm/Makefile.kvm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
tools/testing/selftests/kvm/Makefile.kvm +11 -5
@@ -303,10 +303,16 @@ arm64_hdr_outdir := $(tools_dir)/ endif GEN_HDRS := $(arm64_hdr_outdir)arch/arm64/include/generated/ +GEN_SYSREG_DEFS := $(GEN_HDRS)asm/sysreg-defs.h CFLAGS += -I$(GEN_HDRS) -$(GEN_HDRS): $(wildcard $(arm64_tools_dir)/*) +# The inner Makefile tracks the generator's inputs and leaves the header +# untouched when nothing changed, so dependents rebuild only when it does. +$(GEN_SYSREG_DEFS): FORCE $(MAKE) -C $(arm64_tools_dir) OUTPUT=$(arm64_hdr_outdir) + +FORCE: +.PHONY: FORCE endif no-pie-option := $(call try-run, echo 'int main(void) { return 0; }' | \
@@ -359,10 +365,10 @@ EXTRA_CLEAN += $(GEN_HDRS) \ $(TEST_GEN_OBJ) \ cscope.* -$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c $(GEN_HDRS) +$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c $(GEN_SYSREG_DEFS) $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ -$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S $(GEN_HDRS) +$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S $(GEN_SYSREG_DEFS) $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ # Compile the string overrides as freestanding to prevent the compiler from
@@ -372,10 +378,10 @@ $(LIBKVM_STRING_OBJ): $(OUTPUT)/%.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -ffreestanding $< -o $@ $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS)))) -$(SPLIT_TEST_GEN_OBJ): $(GEN_HDRS) +$(SPLIT_TEST_GEN_OBJ): $(GEN_SYSREG_DEFS) $(TEST_GEN_PROGS): $(LIBKVM_OBJS) $(TEST_GEN_PROGS_EXTENDED): $(LIBKVM_OBJS) -$(TEST_GEN_OBJ): $(GEN_HDRS) +$(TEST_GEN_OBJ): $(GEN_SYSREG_DEFS) cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib .. cscope:
Signature · 1 line
2.39.5
Sean Christopherson
reviewerRe: [PATCH v2 1/2] KVM: selftests: Fix arm64 sysreg header dependencies
Quoted 31 lines · Fuad Tabba
The rule generating the arm64 sysreg header targets the generated directory, and its only prerequisite is
tools/arch/arm64/tools/*, which expands to the innerMakefile. An existing directory looks up to date, so an incremental build never regeneratessysreg-defs.hfor a change to the sysreg table. A selftest referencing a register added to the table since then fails with undeclared SYS_* identifiers. Clean builds are unaffected.Always recurse into
tools/arch/arm64/tools, whoseMakefilealready tracks the generator's inputs, and target the header rather than its directory. The recursion leaves the header untouched when nothing changed, so the dependents rebuild only when the header does.Fixes 70c7b704ca725 ("KVM: selftests: Avoid using forced target for generating arm64 headers")Assisted-by LLMSigned-off-by Fuad Tabba <[email protected]>--- tools/testing/selftests/kvm/Makefile.kvm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)tools/testing/selftests/kvm/Makefile.kvm +1
-0@@ -303,10 +303,16 @@ arm64_hdr_outdir := $(tools_dir)/ endif GEN_HDRS := $(arm64_hdr_outdir)arch/arm64/include/generated/ +GEN_SYSREG_DEFS := $(GEN_HDRS)asm/sysreg-defs.h CFLAGS += -I$(GEN_HDRS)
tools/testing/selftests/kvm/Makefile.kvm arm64_hdr_outdir := $(tools_dir)/ · line 316
Quoted 10 lines
tools/testing/selftests/kvm/Makefile.kvm +6
-1-$(GEN_HDRS): $(wildcard $(arm64_tools_dir)/*) +# The inner Makefile tracks the generator's inputs and leaves the header +# untouched when nothing changed, so dependents rebuild only when it does. +$(GEN_SYSREG_DEFS): FORCE $(MAKE) -C $(arm64_tools_dir) OUTPUT=$(arm64_hdr_outdir) + +FORCE: +.PHONY: FORCE endif
Definitely doesn't have to be now, but at some point should we split out some of this arch-specific sub-Makefiles? It's nice not having to hunt around to figure out which tests are supported by which arch, but the amount of arch specific goo we're accruing is getting unwieldy.
Quoted 30 lines
tools/testing/selftests/kvm/Makefile.kvm +4
-4no-pie-option := $(call try-run, echo 'int main(void) { return 0; }' | \@@ -359,10 +365,10 @@ EXTRA_CLEAN += $(GEN_HDRS) \ $(TEST_GEN_OBJ) \ cscope.* -$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c $(GEN_HDRS) +$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c $(GEN_SYSREG_DEFS) $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ -$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S $(GEN_HDRS) +$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S $(GEN_SYSREG_DEFS) $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ # Compile the string overrides as freestanding to prevent the compiler from@@ -372,10 +378,10 @@ $(LIBKVM_STRING_OBJ): $(OUTPUT)/%.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -ffreestanding $< -o $@ $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS)))) -$(SPLIT_TEST_GEN_OBJ): $(GEN_HDRS) +$(SPLIT_TEST_GEN_OBJ): $(GEN_SYSREG_DEFS) $(TEST_GEN_PROGS): $(LIBKVM_OBJS) $(TEST_GEN_PROGS_EXTENDED): $(LIBKVM_OBJS) -$(TEST_GEN_OBJ): $(GEN_HDRS) +$(TEST_GEN_OBJ): $(GEN_SYSREG_DEFS) cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib .. cscope:Signature · 1 line
2.39.5
Fuad Tabba
reviewerRe: [PATCH v2 1/2] KVM: selftests: Fix arm64 sysreg header dependencies
Hi Sean,
On Thu, 24 Sep 2026 17:32:58 +0100, Sean Christopherson <[email protected]> wrote:
[...]
Quoted 4 lines
Definitely doesn't have to be now, but at some point should we split out some of this arch-specific sub-Makefiles? It's nice not having to hunt around to figure out which tests are supported by which arch, but the amount of arch specific goo we're accruing is getting unwieldy.
I think so. I'd keep the test lists where they are and move the per-arch build logic (the ifeq ($(ARCH),...) blocks) into arch-specific sub-Makefiles. I could send that as a follow-up once this patch lands.
Cheers,
/fuad
Fuad Tabba
reviewerPATCH v2 2/2 selftests/cgroup: Make the object directory an order-only prerequisite
In reply to Fuad Tabbalibcgroup.mk names $(LIBCGROUP_O_DIRS) as a regular prerequisite of cgroup_util.o. The directory's mtime moves whenever an object is created or replaced in it, so an incremental KVM selftests build that rebuilt anything in lib/ recompiles cgroup_util.o and relinks every test on the following run. Make the directory order-only, as libvfio.mk does.
--- tools/testing/selftests/cgroup/lib/libcgroup.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/cgroup/lib/libcgroup.mk +1 -1
@@ -13,7 +13,7 @@ EXTRA_HDRS := $(selfdir)/clone3/clone3_selftests.h $(LIBCGROUP_O_DIRS): mkdir -p $@ -$(LIBCGROUP_O): $(OUTPUT)/%.o : $(CGROUP_DIR)/%.c $(EXTRA_HDRS) $(LIBCGROUP_O_DIRS) +$(LIBCGROUP_O): $(OUTPUT)/%.o : $(CGROUP_DIR)/%.c $(EXTRA_HDRS) | $(LIBCGROUP_O_DIRS) $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ EXTRA_CLEAN += $(LIBCGROUP_O)
Signature · 1 line
2.39.5
Re: [PATCH v2 2/2] selftests/cgroup: Make the object directory an order-only prerequisite
Quoted 5 lines · Fuad Tabba
libcgroup.mk names $(LIBCGROUP_O_DIRS) as a regular prerequisite of cgroup_util.o. The directory's mtime moves whenever an object is created or replaced in it, so an incremental KVM selftests build that rebuilt anything in
lib/recompiles cgroup_util.o and relinks every test on the following run.
I'd expect the other test would recompile stuff in lib/ but not in cgroup/lib/, however that distinction is likely lost when $(OUTPUT) is expanded from the included *.mk file.
Quoted 1 line
Make the directory order-only, as libvfio.mk does.
Sensible approach given that vfio.
Quoted 7 lines
Fixes 2c754a84ff16a ("cgroup: selftests: Move cgroup_util into its own library")Assisted-by LLMSigned-off-by Fuad Tabba <[email protected]>--- tools/testing/selftests/cgroup/lib/libcgroup.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Fuad Tabba
reviewerHi Sean, Paolo,
Gentle ping on this series.
Cheers,
/fuad
Hi Sean, Paolo,
Another gentle ping on this series. Is there anything else you'd like to see before it goes in?
Cheers,
/fuad
Sean Christopherson
reviewerQuoted 4 lines · Fuad Tabba
Hi Sean, Paolo,
Another gentle ping on this series. Is there anything else you'd like to see before it goes in?
I'll grab the KVM change, but I would prefer the cgroup change go through the cgroup tree, even though Michal already acked it. AFAICT there are no dependencies, and it really has nothing to do with KVM.
Quoted 6 lines · Fuad Tabba
Changes since v1 [1]:
- Use FORCE for the sysreg header rule instead of duplicating the generator's inputs. (Oliver)
- Added patch 2, the same class of bug in libcgroup.mk, found while testing patch 1.
Quoted 8 lines
Two fixes for
Makefilerules that name a directory where a file's mtime is what matters. The first is arm64-only: the sysreg header isn't regenerated on an incremental build when the sysreg table changes. The second is arch-independent: cgroup_util.o recompiles, and every test relinks, on the run after any rebuild inlib/. The two patches are independent.[...]
Applied patch 1 to kvm-x86 fixes, thanks!
[1/2] KVM: selftests: Fix arm64 sysreg header dependencies
https://github.com/kvm-x86/linux/commit/b2ddd6af0646