From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B359402457 for ; Thu, 30 Apr 2026 12:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777553617; cv=none; b=OcYgumpfWiE43Kw/kwd2X0kn/eEOFm0ePVB6R/2RJwTYwtsXbhzzqDlmEZd1mfMsZlzDuWpeZRH0JHkKj29Gb7Y6YDno7lNmB44yE4fmVjpBlglqX365LlAybhexxJfbRl4TXWK1OINuY8IpywmkH1XJxTA/rmoH/VLIU+HPD34= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777553617; c=relaxed/simple; bh=0QJYdccmCS5Xa21Yb/0zhA86xvgSH0oN6kSd6sMETRU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cAQfnhTHBNOBZZGN48kzovh3HGTK6/aAeJoZ9UAR3SREP6Qb1ktbwtWlk/ZYdXmBQafbtAcyLKwMDP/RFZcM2DlZp1TTnQh7M+5lrOFHDYkHgBXg1WIVGRHtkS0G5iDdLdAbtmhCIE2VgBCHvkdzM/x/OyCnTRXOFN3t9gj9ULo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=C8sa4buL; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="C8sa4buL" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-483487335c2so10097625e9.2 for ; Thu, 30 Apr 2026 05:53:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1777553610; x=1778158410; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Gd4Mjpp2AlESfBnJvdKqbI6D/125UdC7Iwt7tAYiysY=; b=C8sa4buLaPgC0NYHmQ3rDzpMSg09ivzcXIU5rGmue5HNJqInXvmD8cV1gXHLMaDg8O oxas9TbxuW7cRc2AZccFuoIzx9J800mrcbqoP1b5BuWTCLx17zKEnasJ8nlZ/vg0kJy2 G7cCO9b/VPE2QxbJN1SLZB8QnDaVs9Od2HNnXDU0KsmqE5RLnartK7Q0IZ2JR+GnkVu6 4K3q/vVVPXHtJbLrm5+stK6W70yBk6ui0azv/ux/RaFIEg0lBuZOkV1CoEPeZQVmA0sd UIceRZFTz7B8T86PHNVL0pk2ZaOaOSUIwKV7lJi/yPvijzuvxZn/IZDFTKpeRLJQhWO4 lqfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777553610; x=1778158410; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Gd4Mjpp2AlESfBnJvdKqbI6D/125UdC7Iwt7tAYiysY=; b=g27xE0Kl8bInvBZOUM6vN6/0/i4ku5JtpCSlyMNP+KWy9yy/Ol0i7b17kqfdFynXjw ef0sMKILaQuf9Nj7nt3hkjey9AuoDA7oBg25w7XqH0Kr31PvdDtblkvGXMX6YReT/Iw2 RlorBtwBcANpXDOEIdMRnoZ3A/aEoeNQqfMNzyh6xe6DyvjigJge9Yjpcu9ETyVhCeU9 6x2UsiWtr4A0qhMqt/N8sUGsu9W0CmBqGS5/AeofpNAm5aQJ/aUFrT/TZMEWtxickeQ/ Ff5mOCENCbLkAjIUoZCfVRWwanK1LSfp9pKAIPMFriX6FHBEZmN/s00U+Y3OD0cMUoKf nELQ== X-Forwarded-Encrypted: i=1; AFNElJ98xau0ELXCZo4IHNscPzQYOWMMIBrJhpW3VpQt2ld09ma24B8aMNpFHrNGeG9wrbIgaz61GglAuSL/haE=@vger.kernel.org X-Gm-Message-State: AOJu0YyZal5FgJCPY8bWGEvBrO9qitBjoEdu1F+AIYJu/N4g4/xMcAIK jmVfG/WorlIS+r6iA5pU4c+Nnf5/Z55t4byk5neJlUJz02mDesZavAl3KeaEeYLpMhbTd4sw+SL B3aI4Kwc= X-Gm-Gg: AeBDieuGRySX6UME7TiZC72AsQsEUYLuJAJ8dlA5JqAGpDZIqlwXcLNtr8wTLeZDvV3 I+YRKpgfrHE8WAwrPvQd/p6S0Cyx8IpuU6CDfNfkfURYClNL/nR9IZ6vjOHO+hVKlRtkUTre4LY j/eUXCy57TDWdHovJL41deZhxV1IjBq1B6TAkvE95SGOuWSxv1irNEbHTP32xmNr5WvMWzQ2GGV 0UBXtfs88cSovPEAUPf9MBhMhL5H3++RWjAO8dxR3ldbMzE41vf7uVmO7KHfK/4aJNQEkYI+WaV 4kQnfF1MRZ6SlA29ET7kTEBdhcx7hRLuuUvo2Y6bFx7ZUqNW0JNJLkx0ocw9Qn3/ezAAxhqjV7E wElIN5cQKRSMlTl9fNm/2k+AnR4goFDmNx1FdbiS7PzQHA11P6+PGzLDN3bRDVvDvqB6eSRFywl kvBT+KtnEibhs8a7smziW/B0u2Ge89ajHEyxA= X-Received: by 2002:a05:600c:4f09:b0:48a:525b:e148 with SMTP id 5b1f17b1804b1-48a844e4a91mr42949605e9.4.1777553610189; Thu, 30 Apr 2026 05:53:30 -0700 (PDT) Received: from localhost ([2804:7f0:b765:105d:ce28:aaff:fe86:149c]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12de320ecf9sm9556673c88.2.2026.04.30.05.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2026 05:53:29 -0700 (PDT) From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Date: Thu, 30 Apr 2026 09:53:14 -0300 Subject: [PATCH bpf-next v10 02/11] selftests/bpf: Fix test_kmods KDIR to honor O= and distro kernels Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20260430-selftests-bpf_misconfig-v10-2-cd302a31af16@suse.com> References: <20260430-selftests-bpf_misconfig-v10-0-cd302a31af16@suse.com> In-Reply-To: <20260430-selftests-bpf_misconfig-v10-0-cd302a31af16@suse.com> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , Shuah Khan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Alan Maguire , "Ricardo B. Marliere" X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openssh-sha256; t=1777553600; l=5932; i=rbm@suse.com; h=from:subject:message-id; bh=0QJYdccmCS5Xa21Yb/0zhA86xvgSH0oN6kSd6sMETRU=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgguRCc5X8/UX9M40lkMnr//aFGOhce x5ezt8MFNUFlqYAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QMU4QeABYcR31gwl0/12eQdG/oYP2aQIWHpQR4t6nNBPDfefkyZ6cAE/hxk4awZjAFjMiMwmX0a ojDiUjbm6ugk= X-Developer-Key: i=rbm@suse.com; a=openssh; fpr=SHA256:pzhe0fJpYLz+3cZ33FFPhIfaUElk9CXPFFXmalIH+1g test_kmods/Makefile always pointed KDIR at the kernel source tree root, ignoring O= and KBUILD_OUTPUT. On distro kernels where the source tree has not been built, the Makefile had no fallback and would fail unconditionally. When O= or KBUILD_OUTPUT is set and points at a prepared kernel build directory (one containing Module.symvers), pass it through so kbuild can locate the correct build infrastructure (scripts, Kconfig, etc.). Note that the module artifacts themselves still land in the M= directory, which is test_kmods/; O= only controls where kbuild finds its build infrastructure. Fall back to /lib/modules/$(uname -r)/build when neither an explicit valid build directory nor an in-tree Module.symvers is present. A selftests-only O= value (one that does not contain Module.symvers, e.g. a private output directory) is intentionally not treated as a kernel build directory. Without this guard, a user invoking "make -C tools/testing/selftests/bpf O=/tmp/out" would have test_kmods try to use /tmp/out as the kernel build dir and fail. The parent bpf/Makefile resolves O= and KBUILD_OUTPUT to absolute paths before invoking the test_kmods sub-make. Without this, $(abspath ...) inside test_kmods/Makefile would resolve relative paths against the sub-make's CWD (test_kmods/) rather than the user's invocation directory. When O= is passed to kbuild, also pass KBUILD_OUTPUT=$(KMOD_O_VALID) explicitly. The parent invocation lifts KBUILD_OUTPUT into MAKEFLAGS as a command-line variable, which would otherwise suppress kbuild's own "KBUILD_OUTPUT := $(O)" assignment and cause it to use the inherited KBUILD_OUTPUT instead of the validated O=. Guard both all and clean against a missing KDIR so the step is silently skipped rather than fatal. Make the parent Makefile's cp conditional so it does not abort when modules were not built. Signed-off-by: Ricardo B. Marlière --- tools/testing/selftests/bpf/Makefile | 10 +++++---- tools/testing/selftests/bpf/test_kmods/Makefile | 30 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 6094fe99b5f6..cc6ee7a2df93 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -296,13 +296,15 @@ $(OUTPUT)/sign-file: ../../../../scripts/sign-file.c # subst() turns the rule into a pattern matching rule $(addprefix test_kmods/,$(subst .ko,%ko,$(TEST_KMODS))): $(VMLINUX_BTF) $(RESOLVE_BTFIDS) $(wildcard test_kmods/Makefile test_kmods/*.[ch]) $(Q)$(RM) test_kmods/*.ko test_kmods/*.mod.o # force re-compilation - $(Q)$(MAKE) $(submake_extras) -C test_kmods \ - RESOLVE_BTFIDS=$(RESOLVE_BTFIDS) \ + $(Q)$(MAKE) $(submake_extras) -C test_kmods \ + $(if $(O),O=$(abspath $(O))) \ + $(if $(KBUILD_OUTPUT),KBUILD_OUTPUT=$(abspath $(KBUILD_OUTPUT)))\ + RESOLVE_BTFIDS=$(RESOLVE_BTFIDS) \ EXTRA_CFLAGS='' EXTRA_LDFLAGS='' $(TEST_KMOD_TARGETS): $(addprefix test_kmods/,$(TEST_KMODS)) $(call msg,MOD,,$@) - $(Q)cp test_kmods/$(@F) $@ + $(Q)$(if $(PERMISSIVE),if [ -f test_kmods/$(@F) ]; then )cp test_kmods/$(@F) $@$(if $(PERMISSIVE),; fi) DEFAULT_BPFTOOL := $(HOST_SCRATCH_DIR)/sbin/bpftool @@ -718,7 +720,7 @@ $(TRUNNER_LIB_OBJS): $(TRUNNER_OUTPUT)/%.o:$(TOOLSDIR)/lib/%.c $(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT) ifneq ($2:$(OUTPUT),:$(shell pwd)) $$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_FILES)) - $(Q)rsync -aq $$^ $(TRUNNER_OUTPUT)/ + $(Q)rsync -aq $(if $(PERMISSIVE),--ignore-missing-args) $$^ $(TRUNNER_OUTPUT)/ endif # some X.test.o files have runtime dependencies on Y.bpf.o files diff --git a/tools/testing/selftests/bpf/test_kmods/Makefile b/tools/testing/selftests/bpf/test_kmods/Makefile index 63c4d3f6a12f..031c7454ce65 100644 --- a/tools/testing/selftests/bpf/test_kmods/Makefile +++ b/tools/testing/selftests/bpf/test_kmods/Makefile @@ -1,5 +1,16 @@ TEST_KMOD_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))) -KDIR ?= $(abspath $(TEST_KMOD_DIR)/../../../../..) +SRCTREE_KDIR := $(abspath $(TEST_KMOD_DIR)/../../../../..) +# Honor O=/KBUILD_OUTPUT only if they point at a prepared kernel build +# directory (one containing Module.symvers); otherwise treat the value as a +# selftests-only output directory and fall back to in-tree or distro headers. +# The parent bpf/Makefile resolves O=/KBUILD_OUTPUT to absolute paths before +# invoking this sub-make so relative paths still anchor to the user's +# invocation directory. +KMOD_O := $(or $(O),$(KBUILD_OUTPUT)) +KMOD_O_VALID := $(if $(KMOD_O),$(if $(wildcard $(KMOD_O)/Module.symvers),$(KMOD_O))) +KDIR ?= $(if $(KMOD_O_VALID),$(SRCTREE_KDIR), \ + $(if $(wildcard $(SRCTREE_KDIR)/Module.symvers),$(SRCTREE_KDIR), \ + /lib/modules/$(shell uname -r)/build)) ifeq ($(V),1) Q = @@ -14,8 +25,21 @@ $(foreach m,$(MODULES),$(eval obj-m += $(m:.ko=.o))) CFLAGS_bpf_testmod.o = -I$(src) +# When BPF_STRICT_BUILD != 0, a missing KDIR is fatal (the default). +# When permissive, skip silently. +PERMISSIVE := $(filter 0,$(BPF_STRICT_BUILD)) + all: - $(Q)$(MAKE) -C $(KDIR) M=$(TEST_KMOD_DIR) modules +ifeq ($(PERMISSIVE),) + $(Q)$(MAKE) -C $(KDIR) $(if $(KMOD_O_VALID),O=$(KMOD_O_VALID) KBUILD_OUTPUT=$(KMOD_O_VALID),KBUILD_OUTPUT=) \ + M=$(TEST_KMOD_DIR) modules +else ifneq ("$(wildcard $(KDIR))", "") + $(Q)$(MAKE) -C $(KDIR) $(if $(KMOD_O_VALID),O=$(KMOD_O_VALID) KBUILD_OUTPUT=$(KMOD_O_VALID),KBUILD_OUTPUT=) \ + M=$(TEST_KMOD_DIR) modules +endif clean: - $(Q)$(MAKE) -C $(KDIR) M=$(TEST_KMOD_DIR) clean +ifneq ("$(wildcard $(KDIR))", "") + $(Q)$(MAKE) -C $(KDIR) $(if $(KMOD_O_VALID),O=$(KMOD_O_VALID) KBUILD_OUTPUT=$(KMOD_O_VALID),KBUILD_OUTPUT=) \ + M=$(TEST_KMOD_DIR) clean +endif -- 2.54.0