From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B61BF2877CC; Thu, 17 Jul 2025 08:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742689; cv=none; b=R+UPNO17grw+Qb4slryYN/4njDg96q37HWp8v+rj2Zm/3cXEa6vBq1y9m85QIs/eiOhG0s2vcoeCQyEyqeDDCd0GSF05r1ppqOHLPtGJSfh7qDwvK7nkK39arg/V+Y8xAP653iRVDjO9TOQnoPQvsrOnVlIW4P/pLUqVJguL0dA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742689; c=relaxed/simple; bh=cfu3lghX/dVKMnf+oTJvUQeZzazAXiEvWWJO6QHDXlY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L3j/NaXiajBt/VFrgDD+K09vS5Md++fplREqPaabQJtluReYOxyxpsY30yFNlPCxAfP8RDK+7sTUG7pm5u9hblqYpcb/TvqqZEZ5AhuZP/q15dSwlJV0S61yPZexBGkGbweguDZ0wiA8CE0kdWczuYRn12Dxgfvv6zsdVlX6svM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OPzjx07J; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xAUGO+Gy; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OPzjx07J"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xAUGO+Gy" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xN4BVFhjUpkxABwqqODMy02TSfofXF5j7xQt53A5sBo=; b=OPzjx07J6hoGGcvsU2fCdpXuPeKld8KiH2ZENQmPI2YiE2BGny6t4r799olu5TWHi1Krks vf1RzZf/cyyF2+lHBNrPIGfMPZlqgG3992ql0ioDlMNb5hqwrf0D998VMLPbkGdIZucc2H D7K1KWy1RGa3sKnuTWGj1yoGcBih2IGdvL0VFpMH2ugPNfrVvvJyOhn6es5nWGFSPteRpG G1rPVzCXrSfufAe3G6rO/8uSbIqcFLLvQ5XV7aVUBi0qnXVdO74jKzFursgCQ+t4KdtD4i ckaB+oil+xGeV78osbYLSa74xduTwIGoFeBXzhkUiMzM6LiAk3EjzdSoMdz6aQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xN4BVFhjUpkxABwqqODMy02TSfofXF5j7xQt53A5sBo=; b=xAUGO+Gyfr4tVFpKJ1JIrlbkIcDic4DfuPY2wBG5AwxYAafFn8F5+So7p+Jgk5vnTH6f4D m+iIN58gwWCUwIDw== Date: Thu, 17 Jul 2025 10:48:03 +0200 Subject: [PATCH v5 01/15] kbuild: userprogs: avoid duplication of flags inherited from kernel 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-1-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=1281; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=cfu3lghX/dVKMnf+oTJvUQeZzazAXiEvWWJO6QHDXlY=; b=Vd8KNi0o39hC712kNsh4HqtZ1iWGgJyUvVmox4SD4cDv9sM2uVDnNecFKnQbmIaGuUnS+Xgw7 H4Ox/ALXHZXCJGKfU1HzaPiVb+/itP7PQ4yTl34pPGNDMfWvjc4EzyJ X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The duplication makes maintenance harder. Changes need to be done in two places and the lines will grow overly long. Use an intermediary variable instead. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Nicolas Schier Acked-by: Masahiro Yamada --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 35e6e5240c61a8a329011929fcd0352b881dccdc..c4293cf91e968ca8ee64452841f= b266e24df63f6 100644 --- a/Makefile +++ b/Makefile @@ -1130,8 +1130,9 @@ LDFLAGS_vmlinux +=3D --emit-relocs --discard-none endif =20 # Align the bit size of userspace programs with the kernel -KBUILD_USERCFLAGS +=3D $(filter -m32 -m64 --target=3D%, $(KBUILD_CPPFLAGS= ) $(KBUILD_CFLAGS)) -KBUILD_USERLDFLAGS +=3D $(filter -m32 -m64 --target=3D%, $(KBUILD_CPPFLAGS= ) $(KBUILD_CFLAGS)) +USERFLAGS_FROM_KERNEL :=3D -m32 -m64 --target=3D% +KBUILD_USERCFLAGS +=3D $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLA= GS) $(KBUILD_CFLAGS)) +KBUILD_USERLDFLAGS +=3D $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLA= GS) $(KBUILD_CFLAGS)) =20 # userspace programs are linked via the compiler, use the correct linker ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_LD_IS_LLD),yy) --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFB562877D0; Thu, 17 Jul 2025 08:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742690; cv=none; b=ZOeTQpaWsMrfgStWQGunUkkXBVqz2+K2jEj8RY/kXUJ+9P1bn0c8kBGga71W/8ypSMvRby1uBXyfmBGgmkSJtKHAiTSqEilz7hc4VgN7OORVw5+HpK9/IFEbfd7azy9FTY65BxDF9APFacDrHa4/qp4dxFa8uL9e048Dug/vMvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742690; c=relaxed/simple; bh=dIUE6tZrTNTxC3+u6IFHyxs2sPvw2ecmLqykRiDqz8A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mfWggGH303kZhqVaxhwOK579FgEJPyWiDp4b26NROOQc+Te5jMEWL094YkmzgezV41TDnPR+t/pChGk2AT8S/7HgRRv/UlMC1X8X8U6FyZqiQwowDekYGkHwGvpdpfjXyUXpijWI9hjZAUF9fLRcVvcYQxUyZyMyCWLc4IiagsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=NFYBhHDj; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3F05fl5d; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NFYBhHDj"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3F05fl5d" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8fvHbbWayxoLaIlEeiWIWwoowc66jl/1QEnNwzRl72c=; b=NFYBhHDj+5vC0apu+11p3HC6Bj2Z33ovApsNFofSqJawsmrakJ29w+3HzANzC8APMKdwvY xmAjwmkV8sIolJMM2iqqA5VTWGhoaV7ZfU0vkEQOZ7l5pzNxDqaT/dL2aCM3kale/TgBpz G/RggqZJez5aazdgwzoctP5hPKB+j4Em85X8p2HvHgxCTHVv8YdFAsIwLPOqogIyevD9zg YEPRCeg4yVy7N1fHeBpoNoqn2YQyefZH6hifjHPa5T4/nFe3ZSVZnwO3FkQ0MAR1bbisuf A6bhdbX5VKywI9cFEycZlNU8KqNT+UwpgPiX/Hr3lME9AR6gO5mUqHNhmuVMAg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8fvHbbWayxoLaIlEeiWIWwoowc66jl/1QEnNwzRl72c=; b=3F05fl5dvW/9fmYbgnK9lprIg2y3za18t+pFe4KZuCBQQu616nRklOcBwiew7Yg4cI52cm oNNwA0o9pQd1e5DQ== Date: Thu, 17 Jul 2025 10:48:04 +0200 Subject: [PATCH v5 02/15] kbuild: userprogs: also inherit byte order and ABI from kernel 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-2-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=1274; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=dIUE6tZrTNTxC3+u6IFHyxs2sPvw2ecmLqykRiDqz8A=; b=8LQUp/nSE/ybRwiXPcHvCz5equrF34qvOUZqTx+PG8THmHxyI9O6UNJ0QjzRMHBKGbO1phZ1Z Bzr8vyvrh+mDJVCJ37DsumVYtf2Y9/PwTESa44N85y9P6gO04dAxeRA X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Make sure the byte order and ABI of the userprogs matches the one of the kernel, similar to how the bit size is handled. Otherwise the userprogs may not be executable. This happens for example on powerpc little endian, or riscv32. Reviewed-by: Nicolas Schier Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Masahiro Yamada --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c4293cf91e968ca8ee64452841fb266e24df63f6..b9aa1058321dabd3b3dd5610e45= a2807dfa257f4 100644 --- a/Makefile +++ b/Makefile @@ -1129,8 +1129,8 @@ ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),) LDFLAGS_vmlinux +=3D --emit-relocs --discard-none endif =20 -# Align the bit size of userspace programs with the kernel -USERFLAGS_FROM_KERNEL :=3D -m32 -m64 --target=3D% +# Align the bit size, byte order and architecture of userspace programs wi= th the kernel +USERFLAGS_FROM_KERNEL :=3D -m32 -m64 -mlittle-endian -mbig-endian --target= =3D% -march=3D% -mabi=3D% KBUILD_USERCFLAGS +=3D $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLA= GS) $(KBUILD_CFLAGS)) KBUILD_USERLDFLAGS +=3D $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLA= GS) $(KBUILD_CFLAGS)) =20 --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B615D2877C6; Thu, 17 Jul 2025 08:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742689; cv=none; b=Y5vKRpx0QI7Jb0VWaPx3BSqjuNoI2u60YmrkUXGoppVeel45IrPRd+UMParL+5zzJDq+egoyjx7K/xF1/wSHA41tmBGMUWwZt8CiwvQS4mUyeLfc1wQUsv4+J1W0wLxRNbMniwiUdwCgPuZbWoqlxshiOjJazDHdKjInGpHtTbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742689; c=relaxed/simple; bh=2jMdX6j55NT9eihyocsisG6oF4T76N5o4zc+QU5NAAM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BgqOT6G9u57H2VT1fG0h+UlKNicstwaxjCoEarVglKtZD6SBTMaEv3nzh3bv++cV9IZvsUuccTTFCqRJcW/2SP6YbVKlPIWN++EthOXH9psDQD9rlbC2EOdCxbaaSxfsPOTQCqfw+gnrhRiUgkhch2fRPwIhGgB/5J8Hg+6fh64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iyM1zKKI; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7NzxRth6; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iyM1zKKI"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7NzxRth6" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pWbDBIIXVL3ZWM9iRY5xS/P3YT+spaFoacgu8gc6A0w=; b=iyM1zKKIkm8FsKvW1XpLqiIs0+6vNqb26PlBs1dckBn+rPECfpE7rV50zGolGtlNG84k7M 8tW6dRW9xYhUr7ePkQm6zX94jVSXFqfBVGWwRgmy0oF6weXs1+CmEYwmiOLupy31QbJ40/ qEc9VcHdz86LQOAwhBfxODdlV+aLtbWMqTnGR3jnLNaQUMKQ6zrQYNCkeMqS5C1TU8tYVY 9URM33pKqrZv9XNAI/XhyBLeC65HoEXgXm368eN3kc3b02OwQK3jHxK9I8B/YJXc80lyA4 QTK60AC68VZsJ4vXCh6ZnTu5C5uRZQbbamhi2CjIJ/ANMwQypeC7nLpGfzJFrw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pWbDBIIXVL3ZWM9iRY5xS/P3YT+spaFoacgu8gc6A0w=; b=7NzxRth6zWVV/6I4Dq1iHBWA9/fd5z/WOJ49OSIcjU2VB/cZiJ3oAh1IqTKWw4HSAjRS11 vimlphpNeiIQ6+Cg== Date: Thu, 17 Jul 2025 10:48:05 +0200 Subject: [PATCH v5 03/15] kbuild: doc: add label for userprogs section 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-3-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=891; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=2jMdX6j55NT9eihyocsisG6oF4T76N5o4zc+QU5NAAM=; b=+3aySTgi6hWn9mZEvgNetw07NXKrm6NyhIOGMeEqfgPL0d3Qqs8y7i99gbydKBvBgqLxdXGEo Le7o3xihKh1DCfAS37Y50FC2L5PE8tOSeM12h0u6XixSPfJUZrXhOYI X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Some upcoming documentation will link directly to the userprogs section. Add a label to the section so it can be referenced. Reviewed-by: Nicolas Schier Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Masahiro Yamada --- Documentation/kbuild/makefiles.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/make= files.rst index 8aef3650c1f32b6b197e0dc777e26775d371a081..c14c1f632f6069c8751c8388a35= bef539e19f9e8 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -891,6 +891,8 @@ This is possible in two ways: This will tell kbuild to build lxdialog even if not referenced in any rule. =20 +.. _kbuild_userprogs: + Userspace Program support =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D =20 --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B60F528750E; Thu, 17 Jul 2025 08:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742690; cv=none; b=cLzqICV2UPc7KwaIav/anIqZfHDgdC6x/4R9uhjFxf4JHYFZ/9ukfB1k+FycgQvXLQ2RcjKBfaxgYNo1UG+Y6ahY8yXpKvdMLJlP5Ws5WAhvcJkFO6rRTMapSKD0vR/nc+KRFn+dGop4kcn4Mp3CWk4+bgrukFOzrVqL6Kw/xxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742690; c=relaxed/simple; bh=3M4JPjvhl+Rjt+50SdyWcI3mzzor/iTnWrktBIXqayw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O4l3XGwfK5/AMwXxz9642e0LtXnccTRut4lCyrvIK0DAodjJEVAmVTlS2jZw9pUfVCJCXt/mwRBaOPm2qMqqzxScFVtfj696yrPqm32rof/x+rH0/qdL7czl9QA+BnqWNW+nvUgsDPrT0llppaYfbgaQYnIt9nffQyJtJBdnhsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=SAAP1r/j; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=B7LBOg/O; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="SAAP1r/j"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="B7LBOg/O" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fk5e8oxV0FhssnGzrs35dTGs3v+t08Hny2Sdw8z3PgQ=; b=SAAP1r/jfB77yPtJufaakQ8N3HsC1SzMt/gtlfCduPj60AzpnI1NyNZf58iZ0CLn++BAcD hvIAI4d9vjVxxGHdeCBC6arLXLcG23xb4sk8zn2T6/CGsNuk/ruCs+5R+5/ZoxmHwVlCz8 YmZyMzYpMJfZoR9/p0ShO2QnGgs1RfTEmaMzGLmyIRbxpERvdZB82kUc7YTzmbFCgRmv0i yd8RuB/EiMMS1vTBVkH3kY79R6DWwFyLmc2kyuUExYojt/C0Km/fKBNQ44tcFKSHbEOEmc 5bSjtZokMKQTAHxlEFp4YO2YyWz3TgvjZpHkEGc5Ji3Fi83lljQTZJpQH5/7xA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fk5e8oxV0FhssnGzrs35dTGs3v+t08Hny2Sdw8z3PgQ=; b=B7LBOg/OtrXQjQSO/Saxz8j/GtU+uYxmTZBl7MgF93PyTUTfUjXD8s1yaeNGMV5tkt9vKJ 4XfjJw+WKhNvYLAQ== Date: Thu, 17 Jul 2025 10:48:06 +0200 Subject: [PATCH v5 04/15] init: re-add CONFIG_CC_CAN_LINK_STATIC 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-4-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=1334; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=3M4JPjvhl+Rjt+50SdyWcI3mzzor/iTnWrktBIXqayw=; b=tXd+Mus/T9aD1SZ7NorbGjFvZ/DpE4NQwE3cajqT3dbbAz89RCSe1qE/DfmnGqgFt23NmD3cG aTsszNf+FGRCBQxKIygzvKSyOYKjLQUao1kFTFtrXexVkhIGdfJSKlU X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= For the kunit UAPI functionality this feature is needed again. Effectively revert commit d1b99cdf22e0 ("init: remove unused CONFIG_CC_CAN_LINK_STATIC"), which removed the option. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Nicolas Schier Reviewed-by: Masahiro Yamada --- init/Kconfig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index af4c2f0854554bbcdf193852cf5c1d2c2accc64f..26cafbad4f1560fb56b4bef31ae= 29baf54175661 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -87,6 +87,11 @@ config CC_CAN_LINK default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) = $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag)) if 64BIT default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) = $(USERCFLAGS) $(USERLDFLAGS) $(m32-flag)) =20 +config CC_CAN_LINK_STATIC + bool + default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) = $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag) -static) if 64BIT + default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) = $(USERCFLAGS) $(USERLDFLAGS) $(m32-flag) -static) + # Fixed in GCC 14, 13.3, 12.4 and 11.5 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113921 config GCC_ASM_GOTO_OUTPUT_BROKEN --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA9AE285418; Thu, 17 Jul 2025 08:49:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742146; cv=none; b=D0WPskpitWv85rUzCkxT0Tw8vNcwrZbrQP1AJEVSur+qPdiX95LO1UBesMLgklEpd7/2fEa5KHZXtxwq/1i2S3ftYUmFqNRfqcAiYihBA1Lyd7XUaXxTlkmr9U1SlcCPp1ryPTlOxnSCjbWoMyBy5tsWGHLAeXM3iwL++17Sfnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742146; c=relaxed/simple; bh=jzd2GUyiQxguW35ue6s9/EhpHIGuMVbD761YRMKAxLU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FJt0iAdx0xO7TRBTz+GO5ZsN6+wJXEvbjk3P/zn1ieGiiREIK1WSiVAHYXzP11+ajNGwNUUHqcEs3Seu4wIQAYTWqR3sI3+AXBz8jLvVsAaiS9M6SZkmFBeP5335iB/taKijHpnFjrT1mf9pVkCaFu/k8jG+bs6gx8NbhagTvOA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0r1anL2X; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BY10f4Cv; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0r1anL2X"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BY10f4Cv" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZBDQvUHybVGdnxlnUf0GHbOvIvdhQLf7DfYi3dD2ndo=; b=0r1anL2XdznoHnt0YQNzoHoVPgouB7uPz0KjE2zGIk0E/YL1f49fBnD8gB/zF7on6U2IFc I7f7ZzsaeLfPBHbQgnvz5qw/FvYYnv+YsTLzm64rR2mzWZxbJQdHm+sg4ivTr3Efyl8jIu UyLHVFLT/RAXXhxsRI5LHn7Cye5b+h05WJY6UpnZ4XahvvJo0ADVob9j3D+81Z9QxvLVYM Lveq1/WEZMSxEqvMvxfaeJ35+eo5rUfzA0rSopge68bAjTIBAsqPwROKlTbsijE1PBb5h2 3mRt3my3r+LdEY9DtR8DE3ThSjB1bqyxOLZHGDUM0cz4z/laJ2WcvRO61wgPzw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZBDQvUHybVGdnxlnUf0GHbOvIvdhQLf7DfYi3dD2ndo=; b=BY10f4Cvo0dik2q5QxTr5XWE8yAT2Bjh0+VuB/YSdoYqzwursG5yWt8pBlvUwfel/bM2PB Olx3ZbtWGa2Ge7Ag== Date: Thu, 17 Jul 2025 10:48:07 +0200 Subject: [PATCH v5 05/15] init: add nolibc build support 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-5-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=3172; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=jzd2GUyiQxguW35ue6s9/EhpHIGuMVbD761YRMKAxLU=; b=dmf4tJQr/51uuhkxdme9I0cExjnXB3IbgezIgvUWGaA7uD3N5c2wOPXgZ2+kxEhd8DOop2TGb 1ZHq7+H/KUDDVgv3r0H8ACgHCzcWbBg4ShFzTvi32/oMIT08FYCpnTG X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Building userspace applications through the kbuild "userprogs" framework requires a libc. Kernel toolchains often do not contain a libc. In this case it is useful to use the nolibc library from the kernel tree. Nolibc does not support all architectures and requires compiler flags. Add a kconfig option, so users can know where it is available and provide a variable for common options. Reviewed-by: Nicolas Schier Signed-off-by: Thomas Wei=C3=9Fschuh --- MAINTAINERS | 2 ++ init/Kconfig | 2 ++ init/Kconfig.nolibc | 15 +++++++++++++++ init/Makefile.nolibc | 13 +++++++++++++ 4 files changed, 32 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index a92290fffa163f9fe8fe3f04bf66426f9a894409..e806158cc6798cf97a4aab58c03= 8fb5351d469aa 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17702,6 +17702,8 @@ M: Willy Tarreau M: Thomas Wei=C3=9Fschuh S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc.g= it +F: init/Kconfig.nolibc +F: init/Makefile.nolibc F: tools/include/nolibc/ F: tools/testing/selftests/nolibc/ =20 diff --git a/init/Kconfig b/init/Kconfig index 26cafbad4f1560fb56b4bef31ae29baf54175661..0af62f135192e0470e16eb6bb2f= bb45ac38f4b81 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -92,6 +92,8 @@ config CC_CAN_LINK_STATIC default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) = $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag) -static) if 64BIT default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) = $(USERCFLAGS) $(USERLDFLAGS) $(m32-flag) -static) =20 +source "init/Kconfig.nolibc" + # Fixed in GCC 14, 13.3, 12.4 and 11.5 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113921 config GCC_ASM_GOTO_OUTPUT_BROKEN diff --git a/init/Kconfig.nolibc b/init/Kconfig.nolibc new file mode 100644 index 0000000000000000000000000000000000000000..29cbc5437e70cbc5e256f00b74d= 0ab4801b40de7 --- /dev/null +++ b/init/Kconfig.nolibc @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 + +config ARCH_HAS_NOLIBC + bool + default y if ARM + default y if ARM64 + default y if LOONGARCH + default y if M68K + default y if MIPS + default y if PPC + default y if RISCV + default y if S390 + default y if SPARC + default y if UML_X86 + default y if X86 diff --git a/init/Makefile.nolibc b/init/Makefile.nolibc new file mode 100644 index 0000000000000000000000000000000000000000..dacc78ab4c81c93f3a24ebeb70e= 34253842f9a53 --- /dev/null +++ b/init/Makefile.nolibc @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0 +# Compiler flags, which are necessary to build userspace applications with= the +# in-kernel libc "nolibc". + +ifeq ($(and $(CONFIG_ARCH_HAS_NOLIBC),$(CONFIG_HEADERS_INSTALL)),y) + +NOLIBC_USERCFLAGS :=3D -nostdlib -nostdinc -static -ffreestanding \ + -fno-asynchronous-unwind-tables -fno-stack-protector \ + -I$(objtree)/usr/include -I$(srctree)/tools/include/nolibc/ + +NOLIBC_USERLDFLAGS :=3D -nostdlib -nostdinc -static + +endif # CONFIG_ARCH_HAS_NOLIBC && CONFIG_HEADERS_INSTALL --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BED728030E; Thu, 17 Jul 2025 08:49:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742146; cv=none; b=XldYuDdIfmzKhS4iP+PpYI6+EyZ4mJy+uW9sMJJdeTM4L8LQUMkATAbZVWEt54AAE7U1ulZT/6VCzlxabeGLl79/I8lkLjRP7fWvlot0Dzzv+pH674bprUQeh49mWt3i2Qgqps6breg46vIBl4iFcUgmAIP/Rzr5zYgOtl+7E+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742146; c=relaxed/simple; bh=e5INoDiN3Ni8QRATpOXYa4LnNZtNpkknNpkiBqwwmSY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DQ+aCHwa+tvrmvQgYd1DlktDFa//5/MLH46/klwjhgl6l9Z64wb6WsFV5ZhxSe89hBNUOs5FV4/I7XqlPlkPSFr1/e/Ps/80ihva5eJpgOw6yg78sxCnFl0ZPf+V9C/d9PjoS7dP89vNBaflvIBwp+b4nGrhrfo+mxY9T8GwloI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=d8oTzFqJ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HZ6uFZe1; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="d8oTzFqJ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HZ6uFZe1" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7MpYHuvMjFWWKu6Z/zYB3Mv8gm+e0pCu+LkUQrZSY3U=; b=d8oTzFqJXGnBOvO4zb6cDa5rul2gJUTTSkcahTe/BRpx/iywuRWwT4xroLXY6VNdnh3QZO RHV/IsU6AgdRkJxSFPZ7vIZP6F6jO33pX5kuHPHJGKUTJZYBPdGiDBtIJ/XHMAGEm/x4s2 ywLUAaHuzknRTE+wI83TTNrERZ7Rl1Ved/qv0OIMfaJd8jW9PdCqSZ9lR5xkQZZzGwVy2y n1fL3jCk/xaG/3+VrkeFrvHhEMimW3KwNzytnF1TI0iPHaKMHAL5z7oBRJSv9QM/cxO9q8 MPecXmf0A+I+NgNkN0GmLg8gxNIvH46QRwHVzubjmX+YMeVg9WnQ/9nUqa0oxA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7MpYHuvMjFWWKu6Z/zYB3Mv8gm+e0pCu+LkUQrZSY3U=; b=HZ6uFZe1pV6FRTSkcaX2SUoimPLdA9eDlpPYStwgYkLBSXHxZvPT4cQryUWLjvl4xnegwW BtIPfJ3KSAFlMtAg== Date: Thu, 17 Jul 2025 10:48:08 +0200 Subject: [PATCH v5 06/15] fs,fork,exit: export symbols necessary for KUnit UAPI support 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-6-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=4941; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=e5INoDiN3Ni8QRATpOXYa4LnNZtNpkknNpkiBqwwmSY=; b=wfPAfz0Y4PnhHoB3TtD/RceiqTS+353VN2/ItMuXvqsLsEeUYNcSU3SR921UGRtIT0MxXYMPk 5poxQGlxv/wBEgVJPydBHOSY4lgE3Iw4v8Bg9/g2pPQIzqWk9ZPNFN8 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The KUnit UAPI infrastructure starts userspace processes. As it should be able to be built as a module, export the necessary symbols. Signed-off-by: Thomas Wei=C3=9Fschuh --- For details on how these are used, see patch 12: "kunit: Introduce UAPI testing framework". Any ideas on how to make this work without new exports are very welcome. --- fs/exec.c | 2 ++ fs/file.c | 1 + fs/filesystems.c | 2 ++ fs/fs_struct.c | 1 + fs/pipe.c | 2 ++ kernel/exit.c | 3 +++ kernel/fork.c | 2 ++ 7 files changed, 13 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index 1f5fdd2e096e392b342f122d35aba4cf035441c7..13f7f27641942eddcb179bdd93d= 99b799d155813 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -68,6 +68,7 @@ #include #include #include +#include =20 #include #include @@ -1919,6 +1920,7 @@ int kernel_execve(const char *kernel_filename, putname(filename); return retval; } +EXPORT_SYMBOL_GPL_FOR_MODULES(kernel_execve, "kunit-uapi"); =20 static int do_execve(struct filename *filename, const char __user *const __user *__argv, diff --git a/fs/file.c b/fs/file.c index 3a3146664cf37115624e12f7f06826d48827e9d7..89d07feb9c328337451ce40cb0f= 368b6cb986c2c 100644 --- a/fs/file.c +++ b/fs/file.c @@ -1317,6 +1317,7 @@ int replace_fd(unsigned fd, struct file *file, unsign= ed flags) spin_unlock(&files->file_lock); return err; } +EXPORT_SYMBOL_GPL_FOR_MODULES(replace_fd, "kunit-uapi"); =20 /** * receive_fd() - Install received file into file descriptor table diff --git a/fs/filesystems.c b/fs/filesystems.c index 95e5256821a53494d88f496193305a2e50e04444..a3a588f387bbd8268246d102638= 9deaadf265d0b 100644 --- a/fs/filesystems.c +++ b/fs/filesystems.c @@ -17,6 +17,7 @@ #include #include #include +#include =20 /* * Handling of filesystem drivers list. @@ -45,6 +46,7 @@ void put_filesystem(struct file_system_type *fs) { module_put(fs->owner); } +EXPORT_SYMBOL_GPL_FOR_MODULES(put_filesystem, "kunit-uapi"); =20 static struct file_system_type **find_filesystem(const char *name, unsigne= d len) { diff --git a/fs/fs_struct.c b/fs/fs_struct.c index 64c2d0814ed6889cc12603410e6e9dc44089586f..26340d225deba3f2ec30252293f= df417235a6a4a 100644 --- a/fs/fs_struct.c +++ b/fs/fs_struct.c @@ -46,6 +46,7 @@ void set_fs_pwd(struct fs_struct *fs, const struct path *= path) if (old_pwd.dentry) path_put(&old_pwd); } +EXPORT_SYMBOL_GPL_FOR_MODULES(set_fs_pwd, "kunit-uapi"); =20 static inline int replace_path(struct path *p, const struct path *old, con= st struct path *new) { diff --git a/fs/pipe.c b/fs/pipe.c index 45077c37bad154ef146b047834d35d489fcc4d8d..d6cb743d2cfc041f08b498a5a76= 4e9a96dc34069 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -27,6 +27,7 @@ #include #include #include +#include =20 #include #include @@ -971,6 +972,7 @@ int create_pipe_files(struct file **res, int flags) file_set_fsnotify_mode(res[1], FMODE_NONOTIFY_PERM); return 0; } +EXPORT_SYMBOL_GPL_FOR_MODULES(create_pipe_files, "kunit-uapi"); =20 static int __do_pipe_flags(int *fd, struct file **files, int flags) { diff --git a/kernel/exit.c b/kernel/exit.c index bd743900354ca5fc6c550f80e30393a632eb9a4e..610dffb1276ac60b475708587ca= 053f315fea9c3 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -70,6 +70,7 @@ #include #include #include +#include =20 #include =20 @@ -1005,6 +1006,7 @@ void __noreturn do_exit(long code) lockdep_free_task(tsk); do_task_dead(); } +EXPORT_SYMBOL_GPL_FOR_MODULES(do_exit, "kunit-uapi"); =20 void __noreturn make_task_dead(int signr) { @@ -1887,6 +1889,7 @@ int kernel_wait(pid_t pid, int *stat) put_pid(wo.wo_pid); return ret; } +EXPORT_SYMBOL_GPL_FOR_MODULES(kernel_wait, "kunit-uapi"); =20 SYSCALL_DEFINE4(wait4, pid_t, upid, int __user *, stat_addr, int, options, struct rusage __user *, ru) diff --git a/kernel/fork.c b/kernel/fork.c index 1ee8eb11f38bae1d2eb6de9494aea94b7a19e6c3..5de7a9bc005ade6dcfbdfe1a63c= adbef8782658c 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -105,6 +105,7 @@ #include #include #include +#include =20 #include #include @@ -2676,6 +2677,7 @@ pid_t user_mode_thread(int (*fn)(void *), void *arg, = unsigned long flags) =20 return kernel_clone(&args); } +EXPORT_SYMBOL_GPL_FOR_MODULES(user_mode_thread, "kunit-uapi"); =20 #ifdef __ARCH_WANT_SYS_FORK SYSCALL_DEFINE0(fork) --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BDFF1D7984; Thu, 17 Jul 2025 08:49:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742145; cv=none; b=n6GYna89k3t9YzElwNva/No5YgrR1ytr4FwwY70DNPfzgDaO5/5/JR1WdbuyEW10GBTpVtlFZb80JiLduKNkp3b3qRpfF/uDwmK1iT+zo1hYONBAi2EI6bSNyWtprYQv90FogZ9YU1aQKLuzAlkYDH7qbHTDplgYa5M+82JWls8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742145; c=relaxed/simple; bh=yVjZBovVFYRelPKtg1fQMKDDpGxbxaYJbTiXbrwq7Ao=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iFyZCUnASBft5A/EY8p8FBn+qVik9Fi/NIdg5D4nFXoywC63IEZjY9XIG5YkGJ0cDB8V/TtsZD5Lfla8IAnyZbVQhaXgucUxlK2apAUxS5A8JiPWfXQaAQVCST39TCLT7YgK9Pyfz5KsCYS+sp06+49Q4PM5vHf4CkJ4++d5L6Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=c4InLabs; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ddBrI2MT; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="c4InLabs"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ddBrI2MT" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=28EngJ2RMDboH1kPF4R/YHxhFvguWtCe6+9usWrMNYU=; b=c4InLabsGxInUfJEVc4VHN+M7m9gY7FaVq4Fh87mEtQeVsGS7aGcVw2ftFFcKW7J26QtV5 hDXIK95Ot9w5B2rQxkIOiYwLuMgRNlFbB4EmiB+LBeU4Px9dNLsNmXXxEKsYkn3Ny/7g/7 Dq5fIk6EIxiHUkTcWTN7al+Dd7zZeNkqSxAFFXXrtwPCwbH6DoqGphJebGJXOcsqo2a2Ze K7EYYttIQnUMPv2q6CVmYxbYS/96TPEHXbBY9p03Ngq2W/06oIlYrRD3dq6/twUF99qo3v 2c0ZTBOYO1th581QFz2mXoHZ55KTwlqTb7n/W+/uCSk/rNH4rkWr2ldCz3zJnw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=28EngJ2RMDboH1kPF4R/YHxhFvguWtCe6+9usWrMNYU=; b=ddBrI2MT61kbAKq9OFyxCJ9PR3IsugoRkN2Y0EuYU4DRHe3S4fOgCdN+H2GdaeBRbmaACo onKl+M/WN/9jDmAg== Date: Thu, 17 Jul 2025 10:48:09 +0200 Subject: [PATCH v5 07/15] kunit: tool: Add test for nested test result reporting 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-7-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=2264; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=yVjZBovVFYRelPKtg1fQMKDDpGxbxaYJbTiXbrwq7Ao=; b=4Rrhad+4zQdJ2WFKLGxo3krskqwms12O3XlbFK00zw7rCvDGjBSyqv5SNZW3aB1Xu4ynOqiRl xpmXlFDkWVhAaEiQgCJwSMO3zlaMRuGoxR6q/z+TdQfJMmqfa8aXr4J X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Currently there is a lack of tests validating the result reporting from nested tests. Add one, it will also be used to validate upcoming changes to the nested test parsing. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow Reviewed-by: Rae Moar --- tools/testing/kunit/kunit_tool_test.py | 10 ++++++= ++++ .../kunit/test_data/test_is_test_passed-failure-nested.log | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/k= unit_tool_test.py index bbba921e0eacb18663abfcabb2bccf330d8666f5..b74dc05fc2fe5b3ff629172fc7a= afeb5c3d29fb3 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -165,6 +165,16 @@ class KUnitParserTest(unittest.TestCase): self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status) self.assertEqual(result.counts.errors, 0) =20 + def test_parse_failed_nested_tests_log(self): + nested_log =3D test_data_path('test_is_test_passed-failure-nested.log') + with open(nested_log) as file: + result =3D kunit_parser.parse_run_tests(file.readlines(), stdout) + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status) + self.assertEqual(result.counts.failed, 2) + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[0].sta= tus) + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].sta= tus) + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].sub= tests[0].status) + def test_no_header(self): empty_log =3D test_data_path('test_is_test_passed-no_tests_run_no_header= .log') with open(empty_log) as file: diff --git a/tools/testing/kunit/test_data/test_is_test_passed-failure-nest= ed.log b/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.l= og new file mode 100644 index 0000000000000000000000000000000000000000..2e528da39ab5b2be0fca6cf9160= c10929fba3c9e --- /dev/null +++ b/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log @@ -0,0 +1,7 @@ +KTAP version 1 +1..2 +not ok 1 subtest 1 + KTAP version 1 + 1..1 + not ok 1 subsubtest 1 +not ok 2 subtest 2 --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BE68266B67; Thu, 17 Jul 2025 08:49:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742145; cv=none; b=iBEty/9duyxef75jP0FO2UVVjW9BRMAvMumA/g/Mh2hqIQWe2ZIYNP2IkO9wBHqV2a8oDQ2nlSwUYwygbXqVTuBEOVFWZ8zj+cyFFtk1Fs373OyN64IcGChGXUQCYuUAOZFQYGFudo2a0QKVkc1jDNIiwSVg4yPo/CUo+Vd2kPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742145; c=relaxed/simple; bh=a/wJSYwyt34G89SNmJ3zmx0DFBABaWN8wJwhGB4qj6M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YoCMwv5amPD/xHn0/fgcfRw1mz0g5pwlLvtnmR6E7ifFbWw51zQg2O+ye3KFdshR4yJ7G7gqHbfCs24NHHzaJ5KqW9Qz6X+vrc5jQYczStDEZB63h5xB/JjO48jsw3FCrNTcqgsEuraZ9yMjcBZRWcp5upz0QiwfOEUnZB+DKvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=z/e5YP3n; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=4K1YHeej; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="z/e5YP3n"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4K1YHeej" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HTyGoXC0dVBZ4irV+U60qFcUCjn8ZNx4ePIDmwa7kkM=; b=z/e5YP3n8sdJJ7RJkZzDUhlccH//pj4MtKZGk+xANNmnjfs+vd/s+FBnJXI98BTfum4KCe a2SORUf6JbPx6NKcw6ZOfVBpq0w0plfEe++rRrGTh12A6IoNhiitvmk154l70KvBjg9b1u 1u29HqekVdpVglHpzSO+PfNf+S33kqBPk87IEJ8svBMSll9tnis614+Y5XXu+qMet6V8H+ M9ryrxknJeK56Ag2ltYAgGyVREw4/b2++GEIWLGeUvQGzjsWwlgnKKYEHku+YKxocP3PeV xRKdcYAWVOZl/iGctW1PmDEL+gKBFDI2EXJhDkmx5PUqmUEU0lMla1on5krVJA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HTyGoXC0dVBZ4irV+U60qFcUCjn8ZNx4ePIDmwa7kkM=; b=4K1YHeej61l1AWM6ROFp0S48a+vTZ12cgz/A6VIEwjhsX+AXWqQSFG4Tbnmz7Dx8om7DOk 49kXanApK5HN15DQ== Date: Thu, 17 Jul 2025 10:48:10 +0200 Subject: [PATCH v5 08/15] kunit: tool: Don't overwrite test status based on subtest counts 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-8-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=2830; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=a/wJSYwyt34G89SNmJ3zmx0DFBABaWN8wJwhGB4qj6M=; b=tXs02f7ND1lQX/On+HUIDoFSH9res3NJSpIasrWk/3xCX1p1/YCA88ILiipewxL8ogZjRAXqs GyK9GF5hcoxA0mNtn0zx+aEe753J9xMt29ch1IS66MaLxZyLP3bUVp6 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= If a subtest itself reports success, but the outer testcase fails, the whole testcase should be reported as a failure. However the status is recalculated based on the test counts, overwriting the outer test result. Synthesize a failed test in this case to make sure the failure is not swallowed. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow --- tools/testing/kunit/kunit_parser.py | 3 += ++ tools/testing/kunit/kunit_tool_test.py | 1 + tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log | 3 += ++ 3 files changed, 7 insertions(+) diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kuni= t_parser.py index c176487356e6c94882046b19ea696d750905b8d5..a7a61e627e348db14b953080ec8= 789994fba955a 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -687,6 +687,9 @@ def bubble_up_test_results(test: Test) -> None: elif test.counts.get_status() =3D=3D TestStatus.TEST_CRASHED: test.status =3D TestStatus.TEST_CRASHED =20 + if status =3D=3D TestStatus.FAILURE and test.counts.get_status() =3D=3D T= estStatus.SUCCESS: + counts.add_status(status) + def parse_test(lines: LineStream, expected_num: int, log: List[str], is_su= btest: bool, printer: Printer) -> Test: """ Finds next test to parse in LineStream, creates new Test object, diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/k= unit_tool_test.py index b74dc05fc2fe5b3ff629172fc7aafeb5c3d29fb3..d5bbcb95ab6abb1a8ee91439d87= daaf29d159294 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -172,6 +172,7 @@ class KUnitParserTest(unittest.TestCase): self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status) self.assertEqual(result.counts.failed, 2) self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[0].sta= tus) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.subtests[0].sub= tests[0].status) self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].sta= tus) self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].sub= tests[0].status) =20 diff --git a/tools/testing/kunit/test_data/test_is_test_passed-failure-nest= ed.log b/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.l= og index 2e528da39ab5b2be0fca6cf9160c10929fba3c9e..5498dfd0b0db24663e1a1e9bf78= c587de6746522 100644 --- a/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log +++ b/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log @@ -1,5 +1,8 @@ KTAP version 1 1..2 + KTAP version 1 + 1..1 + ok 1 test 1 not ok 1 subtest 1 KTAP version 1 1..1 --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B80FA283144; Thu, 17 Jul 2025 08:49:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742145; cv=none; b=NaJx16AASByx/NkgzD+Vb++g7R8na7ESDRLfrVm1EHrEfWrvfhtuTQiZjBwvzXHUNz73313Prs3g9VdDVvZANXPXmrC6lsFOvOEnOPI7ahBxnMx/AhrU2dpgO7hLu87EtMB4PAy1s7TlvnowQBR8FxPZtjjvCTyNyH8BvZqe29o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742145; c=relaxed/simple; bh=nqksscqfXqyzTU4syNyfSYS0rZFgGTiiZdVYjcMKiOU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tOcKDTtN5j8PV9eHzJ7uWf7aDZ4YLfwpLYfxmwqZY1hBTagHHLmorFSHtJ5FFfxuyndUexWFnEMQhJ+TwJFM502DDE7EVTfmjQpglspfVmYinccIfCDKzzXu/KPGRCpjXCimW9icbSRwXt5Vj/piJ4cN6yOcESMs0vl2VxyN5EM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Og6qufiN; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YeWwTP1h; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Og6qufiN"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YeWwTP1h" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HGd8ubbWunkfJYLzTiQIqN4TppaArb7LyPstVl7gkvQ=; b=Og6qufiNQGQTQ57NkCHKoAAm7powCJgw7/RWO2qGF/jlRkLSrtw6iDwzo1vFuCIIijprke q0p5sJrXCLfKMmRDpYJDkQe/vCAAvfE/2Jiw/pf2g5NComZY0tnnhoXAJruDo246m0vcje XYQrXubbI9mIqvGpNrqCEENSMoAfFuO1iZ24o9GRVesA75TnCHM7J8r8bBazzX3G92ApYy bYrT1owphkLuKVLDI0OMlkrhXyTpNjPBieMANT95fRTsEI+k5e1lL/V1WSWgkg43WLlWDX M5OeZGEcM++g/Q+/F7AJ2/ZjtBejS5aSB0jLRDENJKPkOWiyonO3OsYeD1lOHQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HGd8ubbWunkfJYLzTiQIqN4TppaArb7LyPstVl7gkvQ=; b=YeWwTP1h32iVhGidFWcm+PUWWjNidVPw2Cr1BbPavgIbdVuqStheDJKKB3UdfkblaqVOh8 v9i3kGjHnBZUNHCw== Date: Thu, 17 Jul 2025 10:48:11 +0200 Subject: [PATCH v5 09/15] kunit: tool: Parse skipped tests from kselftest.h 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-9-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=2829; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=nqksscqfXqyzTU4syNyfSYS0rZFgGTiiZdVYjcMKiOU=; b=Zq1mrbjSt+Zlq8ZjnVSL9Jo84/acvktNqayzm+LN1XPYXkxZ3xwwYilhJUXi7lj0rBygEeyvS W75qBTLoW7+CefyuYY2haaSY20fRRc00PlYkDHUKhWcMuAA+xgTM75/ X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Skipped tests reported by kselftest.h use a different format than KTAP, there is no explicit test name. Normally the test name is part of the free-form string after the SKIP keyword: ok 3 # SKIP test: some reason Extend the parser to handle those correctly. Use the free-form string as test name instead. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow --- tools/testing/kunit/kunit_parser.py | 8 +++++-= -- tools/testing/kunit/test_data/test_is_test_passed-kselftest.log | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kuni= t_parser.py index a7a61e627e348db14b953080ec8789994fba955a..5338489dcbe48c01912c5e8f02a= 481d6860a5d15 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -352,9 +352,9 @@ def parse_test_plan(lines: LineStream, test: Test) -> b= ool: lines.pop() return True =20 -TEST_RESULT =3D re.compile(r'^\s*(ok|not ok) ([0-9]+) (- )?([^#]*)( # .*)?= $') +TEST_RESULT =3D re.compile(r'^\s*(ok|not ok) ([0-9]+) ?(- )?([^#]*)( # .*)= ?$') =20 -TEST_RESULT_SKIP =3D re.compile(r'^\s*(ok|not ok) ([0-9]+) (- )?(.*) # SKI= P(.*)$') +TEST_RESULT_SKIP =3D re.compile(r'^\s*(ok|not ok) ([0-9]+) ?(- )?(.*) # SK= IP ?(.*)$') =20 def peek_test_name_match(lines: LineStream, test: Test) -> bool: """ @@ -379,6 +379,8 @@ def peek_test_name_match(lines: LineStream, test: Test)= -> bool: if not match: return False name =3D match.group(4) + if not name: + return False return name =3D=3D test.name =20 def parse_test_result(lines: LineStream, test: Test, @@ -416,7 +418,7 @@ def parse_test_result(lines: LineStream, test: Test, =20 # Set name of test object if skip_match: - test.name =3D skip_match.group(4) + test.name =3D skip_match.group(4) or skip_match.group(5) else: test.name =3D match.group(4) =20 diff --git a/tools/testing/kunit/test_data/test_is_test_passed-kselftest.lo= g b/tools/testing/kunit/test_data/test_is_test_passed-kselftest.log index 65d3f27feaf22a3f47ed831c4c24f6f11c625a92..30d9ef18bcec177067288d52427= 71236f29b7d56 100644 --- a/tools/testing/kunit/test_data/test_is_test_passed-kselftest.log +++ b/tools/testing/kunit/test_data/test_is_test_passed-kselftest.log @@ -1,5 +1,5 @@ TAP version 13 -1..2 +1..3 # selftests: membarrier: membarrier_test_single_thread # TAP version 13 # 1..2 @@ -12,3 +12,4 @@ ok 1 selftests: membarrier: membarrier_test_single_thread # ok 1 sys_membarrier available # ok 2 sys membarrier invalid command test: command =3D -1, flags =3D 0, e= rrno =3D 22. Failed as expected ok 2 selftests: membarrier: membarrier_test_multi_thread +ok 3 # SKIP selftests: membarrier: membarrier_test_multi_thread --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B81C7283C82; Thu, 17 Jul 2025 08:49:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742145; cv=none; b=J8XDNtCjP/a4TljMxI8lhXKn4fD5VHn2lhEoSfrWKKVFHTUWJFgkqd0/18Kw0UBzLHlcTRGL+QVT7pRIi5qw0Ra5QEBDPVl12v7JDIb2LQ32jOjThknvyQbJaCCz4v9LNhy2hkpHLojJwuPJ5Kd9psrs+dn/uv0WSxFU14vmfRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742145; c=relaxed/simple; bh=uYbDX0tuhfBybp4zBtjmC97SEQNiCLwjFQ5JZf0se98=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lI1fUbitiSxgFwxubeaY3GFVtZxLA2cLLUkxpBb1Jdy2HakwnkRLqxKeFOa2yGcB7aWwQvi54Cx3lR6QWI05e0D+uI9QJUH9T12/jD+0ZJT9ZAgP9UWW/TrsxERzmA9gHWqLSfRmVJOpYsEFJC18Qr09YdlPJ4iJ3UiAEEv0rcQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=F1UQYxFL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ejZx2Edt; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="F1UQYxFL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ejZx2Edt" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3coL6itBSAQiKwOZXEjAxfGw4ky2lWtS9inL/ixAlLY=; b=F1UQYxFLM4xqtBPz2jcxDiS0tjJxXXbaK5ry92KcFGkZrYMhcDwnMzbLGiSaKQJlc0JVR5 WOtGizERh75cEMjXTSZxju/Jh397Fejsgz28E9X+P1OAajMabZF5vh+yvxQmB0OhPgMkzt dlpvHkd06JjvU/Bt3KZOjTW6zYVdoQYmbuhV7gKp/8a+iE7RIyHJap/BHDJnw7fcJ1qgGk OtCE9nXGlyzXLTL72A/zd0t9hEJCrKqLODy7otvj09z66zgEjotryz35Y1SfE+niQ04ndO pYBGtAYHUtRBfLyDPnmo209OnCoJG1GFA4jLmkfl4O7+yxbrQENHqDMu1g3FZg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3coL6itBSAQiKwOZXEjAxfGw4ky2lWtS9inL/ixAlLY=; b=ejZx2EdtueEVmba6KbH+m9aPZYYWPrL0kWz1728k/DLtzcvoMwUSPs/Xo9GRvHhVkXg2ar kRhnIJhFdtOqRJAA== Date: Thu, 17 Jul 2025 10:48:12 +0200 Subject: [PATCH v5 10/15] kunit: Always descend into kunit directory during build 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-10-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=1601; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=uYbDX0tuhfBybp4zBtjmC97SEQNiCLwjFQ5JZf0se98=; b=bHyewFwHKAKDKekhXmQwKbW62825yb2xHBgjfNAFCj4wxJ+UUeg7RzKadxfAdhpJsrB5VH68V 5z5qvKPS2cFCc3k0zres0QX9nsS4ZPOjCOOrfIvUwLl+EKtCklHOsQh X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= An upcoming change will add 'userprogs' to the kunit subdirectory. For kbuild to properly clean up these build artifacts the subdirectory needs to be always processed. Pushing the special logic for hook.o into the kunit Makefile also makes the logic easier to understand. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow --- lib/Makefile | 4 ---- lib/kunit/Makefile | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index c38582f187dd81916113319072e5cfef26f26c84..698566135091cc3bf0054f1954b= 434dc3325364a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -108,11 +108,7 @@ test_fpu-y :=3D test_fpu_glue.o test_fpu_impl.o CFLAGS_test_fpu_impl.o +=3D $(CC_FLAGS_FPU) CFLAGS_REMOVE_test_fpu_impl.o +=3D $(CC_FLAGS_NO_FPU) =20 -# Some KUnit files (hooks.o) need to be built-in even when KUnit is a modu= le, -# so we can't just use obj-$(CONFIG_KUNIT). -ifdef CONFIG_KUNIT obj-y +=3D kunit/ -endif =20 ifeq ($(CONFIG_DEBUG_KOBJECT),y) CFLAGS_kobject.o +=3D -DDEBUG diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 5aa51978e456ab3bb60c12071a26cf2bdcb1b508..656f1fa35abcc635e67d5b4cb1b= c586b48415ac5 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -17,7 +17,7 @@ kunit-objs +=3D debugfs.o endif =20 # KUnit 'hooks' are built-in even when KUnit is built as a module. -obj-y +=3D hooks.o +obj-$(if $(CONFIG_KUNIT),y) +=3D hooks.o =20 obj-$(CONFIG_KUNIT_TEST) +=3D kunit-test.o obj-$(CONFIG_KUNIT_TEST) +=3D platform-test.o --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C81CA283FD0; Thu, 17 Jul 2025 08:49:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742145; cv=none; b=uooOyKIjhyCz3GaYOhzs1iXAk3nO7O4niAKBYZ7Hy5kc2CPcgcNFfgOCfPcwFGlVzM++ExQFI0L+RPnsObvh0yjmxvQHZuG+4yyOtapnpkMKC4ek9V5keLLKl39VsCx3T8SRXGz3eKqezU5RT3e1HXNNB7/HhMgNlaTRjfW8oGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742145; c=relaxed/simple; bh=zShZPUvddV04nP7ePLLt+JfO552xNTacDebxpq2ayPk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HVSpdVaHGHEFudiUoTxE/uAQVuS3zVldAVp0RN73xuvRCEnNviVVuLKyVoF6sp09/A+8WIttb7es1qDLemWkTZtKljkZrSqwznm7+mVVOPmE+brlH5TQRiaRt9Xb/Zp/cwAoqx7BrqSD2nCiFzFZIQHJsYhCi7lA/dMMPyF1FiQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ruIWxhz6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7GCbJK+O; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ruIWxhz6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7GCbJK+O" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nqEciMN5D1yrpF8pzbxqPFErBTdvvekVDOGyFqtNWdk=; b=ruIWxhz6iZzxbtyuGwYjw2YjWsp/jjOtyAwuJaUqFagDnhAdlZS6CdE+g2YknzQQo8hCl0 b9wOSDMj48Zjll7gWT+t/eSN4SV6IK36UuKUZQn1JLVsLYstcPKu+CLbajBy1WcWzhS1HH 6tkderBga6hzSP5+5Xzx44dcKVhgGtMspuM6kU2vo0o7GUxVY9uwdEabZbWpwDnPbI0PVh AQo7yNnm63df29vP0FgZ1lN4uf1hgXPrWXAqMmkZFEnH8G6DSgbP9dn4T3CMTDK8AEzswz h+8MZnduC21SggyRdrf7cpC/efwp338sXUk3urkMmKjmbHNP2nMHuj5eoKt+6A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nqEciMN5D1yrpF8pzbxqPFErBTdvvekVDOGyFqtNWdk=; b=7GCbJK+OmrqaSlNwI2OZDb6lxp0TKS8gqKA3TtlHY+5zhm3XvXAip6DqFgHag8Dx5LJc7F YIkVFa9A7k5lJ1Cg== Date: Thu, 17 Jul 2025 10:48:13 +0200 Subject: [PATCH v5 11/15] kunit: qemu_configs: loongarch: Enable LSX/LSAX 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-11-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=994; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=zShZPUvddV04nP7ePLLt+JfO552xNTacDebxpq2ayPk=; b=UBKD/xPL6CqWivmgfWaIC2N85F6b3+iQ2bezBOMjDmOU2pdgyLsDWs2kiw3Y6B0ovxsU/v0Jg R+DzM5jfM6eDsVf4lNMbsl53KkMhoZMmBITvOBBmyXhdinavxasECx+ X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The upcoming kunit UAPI framework will run userspace executables as part of kunit. These may use the LSX or LASX instructions. Make sure the kunit kernel can handle these instructions. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow --- tools/testing/kunit/qemu_configs/loongarch.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/kunit/qemu_configs/loongarch.py b/tools/testing/= kunit/qemu_configs/loongarch.py index a92422967d1da9f1658ef1e80d0d7365ddbae307..1dba755284f11ffc94d8946105b= 0cfa49cb6f604 100644 --- a/tools/testing/kunit/qemu_configs/loongarch.py +++ b/tools/testing/kunit/qemu_configs/loongarch.py @@ -11,6 +11,8 @@ CONFIG_PVPANIC_PCI=3Dy CONFIG_SERIAL_8250=3Dy CONFIG_SERIAL_8250_CONSOLE=3Dy CONFIG_SERIAL_OF_PLATFORM=3Dy +CONFIG_CPU_HAS_LSX=3Dy +CONFIG_CPU_HAS_LASX=3Dy ''', qemu_arch=3D'loongarch64', kernel_path=3D'arch/loongarch/boot/vmlinux.elf', --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C82372853E3; Thu, 17 Jul 2025 08:49:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742146; cv=none; b=E763O5iiBEzm1qSKLRuMKP2viyrc4SuhPcstw4Q5IyzsqNOKgGXceUANws1focvc/C0Ft6MjJGGhmWgllTQDaWqRYoZo6yUGcZtaVH5HXlZ6xSASm+yDH3xnVbVDV1vUr9LWjzQX+9kYr93X//CmZZxxC4BieKbScWaIYAGEfUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742146; c=relaxed/simple; bh=mfcMki5KK+/KbDcTTF5OezeLcLaBGy0wsbG8/bHYp2s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WZj0AhB6zcUeFHm5kfE8Ttbp9m9krdMdEsJjTFIr/H5jGQS5wCIHZsHqXBaT6hqcY9cI01CwfXk+g+s0KOt1av6/3ez5IBiA7avRbj+StgHNtEcHrM8UQsk1wq9bdpbfwfu2TZUeNHGguUpp1u4MYV2soJHYVrZUIXo8bJSg2l8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=NlJfuOlG; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5uETJ4zu; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NlJfuOlG"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5uETJ4zu" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zvpYRSX3dCwhUhvnrqY8NQ1OPJxhTxnlr/LMQMVtoGk=; b=NlJfuOlGyvpOX+uY59qogeQjZ5JZIr6s45pQmp9dssp90ybECDX/ymZqwSjXWGNskcWc96 ApmHWeDqQH4igV/1Umt8nedPYaWl0LPURAwSWumvVQe0KLuz7JOxBl2jxsXnRxDojdsmA0 JoS5bVvg6YpnvXmR3rLImYsLcxMr/mm/7+r6AJ1iJiaTsh73lRRj/gIZmv5ZAuWkmpZntj DwH0KNoKeIKudb/PjfVH+45TL3W1I7mM9vfdiIz4APa06efxWHNmuAyuh4AuEWRmzSA/B0 dbHYQpFAa303fpMS/ry1bISsbJNjwdz0UbtsM4AnF1OTMkrmycoWx+UYxMQeJw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zvpYRSX3dCwhUhvnrqY8NQ1OPJxhTxnlr/LMQMVtoGk=; b=5uETJ4zunMuS1z9E16n+UvoVN1oiJ2/KmCEtX/uLDlM34CKgGm/9JB2VwCSayLf1f8fui3 u3DTNNXNLSmveQDA== Date: Thu, 17 Jul 2025 10:48:14 +0200 Subject: [PATCH v5 12/15] kunit: Introduce UAPI testing framework 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-12-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=15330; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=mfcMki5KK+/KbDcTTF5OezeLcLaBGy0wsbG8/bHYp2s=; b=wkAZdQaF4McTlvHuxjRhA0rJC3+eKdW1Kv61tyxRkPqXnQK3RQkv/lleZsFursfLcmudRq5jA HyeES8+gvW5BOK8kQjl/oF0v18DEayeCBlkD5QCxdP7Szui40Nx6GZ6 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Enable running UAPI tests as part of kunit. The selftests are embedded into the kernel image and their output is forwarded to kunit for unified reporting. The implementation reuses parts of usermode drivers and usermode helpers. However these frameworks are not used directly as they make it impossible to retrieve a thread's exit code. Signed-off-by: Thomas Wei=C3=9Fschuh --- This is similar to the usermode helper framework, but not using it as there would be some issues. It gets neutered by CONFIG_STATIC_USERMODEHELPER_PATH. That could be worked around by overriding sub_info->path, but that would be a hack. Also it does not allow the implementation of a custom wait routine to forward the process output to KUnit as implemented in kunit_uapi_forward_to_printk(). That may be solved by adding another thread, or messing with the internals of the framework, but that would also be ugly. --- Documentation/dev-tools/kunit/api/index.rst | 5 + Documentation/dev-tools/kunit/api/uapi.rst | 14 ++ MAINTAINERS | 6 + include/kunit/uapi.h | 77 +++++++ lib/kunit/Kconfig | 14 ++ lib/kunit/Makefile | 2 + lib/kunit/kunit-uapi.c | 300 ++++++++++++++++++++++++= ++++ 7 files changed, 418 insertions(+) diff --git a/Documentation/dev-tools/kunit/api/index.rst b/Documentation/de= v-tools/kunit/api/index.rst index 5cdb552a0808f25baeff5e47a9227b7b62c69e40..34d8fee9a97059d6da919a6fb1a= 7e359b5e0beef 100644 --- a/Documentation/dev-tools/kunit/api/index.rst +++ b/Documentation/dev-tools/kunit/api/index.rst @@ -9,6 +9,7 @@ API Reference test resource functionredirection + uapi clk of platformdevice @@ -32,6 +33,10 @@ Documentation/dev-tools/kunit/api/functionredirection.rst =20 - Documents the KUnit Function Redirection API =20 +Documentation/dev-tools/kunit/api/uapi.rst + + - Documents the KUnit Userspace testing API + Driver KUnit API =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/Documentation/dev-tools/kunit/api/uapi.rst b/Documentation/dev= -tools/kunit/api/uapi.rst new file mode 100644 index 0000000000000000000000000000000000000000..1f01b5c6c9db42f603f6507f2f3= 3ef388f5b91d7 --- /dev/null +++ b/Documentation/dev-tools/kunit/api/uapi.rst @@ -0,0 +1,14 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Userspace Test API +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This file documents all of the userspace testing API. +Userspace tests are built as :ref:`kbuild userprogs `, +linked statically and without any external dependencies. + +For the widest platform compatibility they should use nolibc, as provided = by `init/Makefile.nolibc`. + +.. kernel-doc:: include/kunit/uapi.h + :internal: diff --git a/MAINTAINERS b/MAINTAINERS index e806158cc6798cf97a4aab58c038fb5351d469aa..0f60501c6de570723123b24eb93= 0d15f1bd956eb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13540,6 +13540,12 @@ S: Maintained F: Documentation/devicetree/bindings/leds/backlight/kinetic,ktz8866.yaml F: drivers/video/backlight/ktz8866.c =20 +KUNIT UAPI TESTING FRAMEWORK (in addition to KERNEL UNIT TESTING FRAMEWORK) +M: Thomas Wei=C3=9Fschuh +S: Maintained +F: include/kunit/uapi.h +F: lib/kunit/kunit-uapi.c + KVM PARAVIRT (KVM/paravirt) M: Paolo Bonzini R: Vitaly Kuznetsov diff --git a/include/kunit/uapi.h b/include/kunit/uapi.h new file mode 100644 index 0000000000000000000000000000000000000000..a5c923f5d82a91e0acd9dc17369= f84f00b7d342f --- /dev/null +++ b/include/kunit/uapi.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * KUnit Userspace testing API. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + */ + +#ifndef _KUNIT_UAPI_H +#define _KUNIT_UAPI_H + +#include + +struct kunit; + +/** + * struct kunit_uapi_blob - Blob embedded build artifact + * @path: Path of the embedded artifact. + * @data: Start of the embedded data in memory. + * @end: End of the embedded data in memory. + */ +struct kunit_uapi_blob { + const char *const path; + const u8 *data; + const u8 *end; +}; + +#if IS_ENABLED(CONFIG_KUNIT_UAPI) + +/** + * KUNIT_UAPI_EMBED_BLOB() - Embed another build artifact into the kernel + * @_name: The name of symbol under which the artifact is embedded. + * @_path: Path to the artifact on disk. + * + * Embeds a build artifact like a userspace executable into the kernel or = current module. + * The build artifact is read from disk and needs to be already built. + */ +#define KUNIT_UAPI_EMBED_BLOB(_name, _path) \ + asm ( \ + " .pushsection .rodata, \"a\" \n" \ + " .global " __stringify(CONCATENATE(_name, _data)) " \n" \ + __stringify(CONCATENATE(_name, _data)) ": \n" \ + " .incbin " __stringify(_path) " \n" \ + " .size " __stringify(CONCATENATE(_name, _data)) ", " \ + ". - " __stringify(CONCATENATE(_name, _data)) " \n" \ + " .global " __stringify(CONCATENATE(_name, _end)) " \n" \ + __stringify(CONCATENATE(_name, _end)) ": \n" \ + " .popsection \n" \ + ); \ + \ + extern const char CONCATENATE(_name, _data)[]; \ + extern const char CONCATENATE(_name, _end)[]; \ + \ + static const struct kunit_uapi_blob _name =3D { \ + .path =3D _path, \ + .data =3D CONCATENATE(_name, _data), \ + .end =3D CONCATENATE(_name, _end), \ + } \ + +#else /* !CONFIG_KUNIT_UAPI */ + +/* Unresolved external reference, to be optimized away */ +#define KUNIT_UAPI_EMBED_BLOB(_name, _path) \ + extern const struct kunit_uapi_blob _name + +#endif /* CONFIG_KUNIT_UAPI */ + +/** + * kunit_uapi_run_kselftest() - Run a userspace kselftest as part of kunit + * @test: The test context object. + * @executable: kselftest executable to run + * + * Runs the kselftest and forwards its TAP output and exit status to kunit. + */ +void kunit_uapi_run_kselftest(struct kunit *test, const struct kunit_uapi_= blob *executable); + +#endif /* _KUNIT_UAPI_H */ diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index a97897edd9642f3e5df7fdd9dee26ee5cf00d6a4..c88e6cf5610bc8246c94d16b902= 5461f0cd3b2d2 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -93,4 +93,18 @@ config KUNIT_AUTORUN_ENABLED In most cases this should be left as Y. Only if additional opt-in behavior is needed should this be set to N. =20 +config KUNIT_UAPI + tristate "KUnit UAPI testing framework" + depends on KUNIT + depends on CC_CAN_LINK_STATIC || ARCH_HAS_NOLIBC + depends on !LTO_CLANG # https://github.com/llvm/llvm-project/issues/112920 + select HEADERS_INSTALL + default KUNIT + help + Enables support for building and running userspace selftests as part of= kunit. + These tests should be statically linked and use kselftest.h or kselftes= t_harness.h + for status reporting. + + In most cases this should be left as Y. + endif # KUNIT diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 656f1fa35abcc635e67d5b4cb1bc586b48415ac5..6059621a2d32c8e7384acda5979= 3f05826af8c81 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -12,6 +12,8 @@ kunit-objs +=3D test.o \ device.o \ platform.o =20 +obj-$(CONFIG_KUNIT_UAPI) +=3D kunit-uapi.o + ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs +=3D debugfs.o endif diff --git a/lib/kunit/kunit-uapi.c b/lib/kunit/kunit-uapi.c new file mode 100644 index 0000000000000000000000000000000000000000..24356f68eca0df07032fb8a9e92= daffde01b21d3 --- /dev/null +++ b/lib/kunit/kunit-uapi.c @@ -0,0 +1,300 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace testing API. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define KSFT_PASS 0 +#define KSFT_FAIL 1 +#define KSFT_XFAIL 2 +#define KSFT_XPASS 3 +#define KSFT_SKIP 4 + +static struct vfsmount *kunit_uapi_mount_ramfs(void) +{ + struct file_system_type *type; + struct vfsmount *mnt; + + type =3D get_fs_type("ramfs"); + if (!type) + return ERR_PTR(-ENODEV); + + /* FIXME + * The mount setup is supposed to look like this: + * kunit_uapi_mount_ramfs() sets up a private mount, + * with nothing visible except the new tmpfs. + * Then each executable execution gets a new namespace on top of that + * on which it can mount whatever it needs. + * However I didn't manage to set this up, so keep everything simple + * for now and let somebody familiar with the VFS figure this out. + */ + + mnt =3D kern_mount(type); + put_filesystem(type); + + return mnt; +} + +static int kunit_uapi_write_file(struct vfsmount *mnt, const char *name, m= ode_t mode, + const u8 *data, size_t size) +{ + struct file *file; + ssize_t written; + + file =3D file_open_root_mnt(mnt, name, O_CREAT | O_WRONLY, mode); + if (IS_ERR(file)) + return PTR_ERR(file); + + written =3D kernel_write(file, data, size, NULL); + filp_close(file, NULL); + if (written !=3D size) { + if (written >=3D 0) + return -ENOMEM; + return written; + } + + /* Flush delayed fput so exec can open the file read-only */ + flush_delayed_fput(); + + return 0; +} + +static int kunit_uapi_write_executable(struct vfsmount *mnt, + const struct kunit_uapi_blob *executable) +{ + return kunit_uapi_write_file(mnt, kbasename(executable->path), 0755, + executable->data, executable->end - executable->data); +} + +struct kunit_uapi_user_mode_thread_ctx { + const char *executable; + + /* Signals mnt, out, pwd and tgid */ + struct completion setup_done; + struct vfsmount *mnt; + struct file *out; + struct path pwd; + pid_t tgid; + + /* Valid after wait(tgid) */ + int exec_err; +}; + +static int kunit_uapi_user_mode_thread_init(void *data) +{ + struct kunit_uapi_user_mode_thread_ctx *ctx =3D data; + const char *const argv[] =3D { + ctx->executable, + NULL + }; + struct file *out[2]; + int err; + + err =3D create_pipe_files(out, 0); + if (err) + return err; + + /* stdin, use the *write* end to the pipe to have an unreadable input */ + err =3D replace_fd(0, out[1], 0); + if (err < 0) { + fput(out[0]); + fput(out[1]); + return err; + } + + /* stdout */ + err =3D replace_fd(1, out[1], 0); + if (err < 0) { + replace_fd(0, NULL, 0); + fput(out[0]); + fput(out[1]); + return err; + } + + /* stderr */ + err =3D replace_fd(2, out[1], 0); + if (err < 0) { + replace_fd(0, NULL, 0); + replace_fd(1, NULL, 0); + fput(out[0]); + fput(out[1]); + return err; + } + + fput(out[1]); + + ctx->out =3D out[0]; + ctx->tgid =3D current->tgid; + + set_fs_pwd(current->fs, &ctx->pwd); + kernel_sigaction(SIGKILL, SIG_DFL); + kernel_sigaction(SIGABRT, SIG_DFL); + + complete(&ctx->setup_done); + ctx->exec_err =3D kernel_execve(ctx->executable, argv, NULL); + if (!ctx->exec_err) + return 0; + do_exit(0); +} + +static size_t kunit_uapi_printk_subtest_lines(struct kunit *test, char *bu= f, size_t s) +{ + const char *ptr =3D buf, *newline; + size_t n; + + while (s) { + newline =3D strnchr(ptr, s, '\n'); + if (!newline) + break; + + n =3D newline - ptr + 1; + + kunit_log(KERN_INFO, test, KUNIT_SUBSUBTEST_INDENT "%.*s", (int)n, ptr); + ptr +=3D n; + s -=3D n; + } + + memmove(buf, ptr, s); + + return s; +} + +static int kunit_uapi_forward_to_printk(struct kunit *test, struct file *o= utput) +{ + /* + * printk() automatically adds a newline after each message. + * Therefore only fully accumulated lines can be forwarded. + * Each line needs to fit into the buffer below. + */ + char buf[512]; + size_t s =3D 0; + ssize_t n; + + while (1) { + n =3D kernel_read(output, buf + s, sizeof(buf) - s, NULL); + if (n <=3D 0) + return n; + s =3D kunit_uapi_printk_subtest_lines(test, buf, s + n); + } +} + +static void kunit_uapi_kill_pid(pid_t pid) +{ + struct pid *p; + + p =3D find_get_pid(pid); + kill_pid(p, SIGKILL, 1); + put_pid(p); +} + +static int kunit_uapi_run_executable_in_mount(struct kunit *test, const ch= ar *executable, + struct vfsmount *mnt) +{ + struct kunit_uapi_user_mode_thread_ctx ctx =3D { + .setup_done =3D COMPLETION_INITIALIZER_ONSTACK(ctx.setup_done), + .executable =3D executable, + .pwd =3D { + .mnt =3D mnt, + .dentry =3D mnt->mnt_root, + }, + }; + int forward_err, wait_err, ret =3D 0; + pid_t pid; + + /* If SIGCHLD is ignored do_wait won't populate the status. */ + kernel_sigaction(SIGCHLD, SIG_DFL); + pid =3D user_mode_thread(kunit_uapi_user_mode_thread_init, &ctx, SIGCHLD); + if (pid < 0) { + kernel_sigaction(SIGCHLD, SIG_IGN); + return pid; + } + + wait_for_completion(&ctx.setup_done); + + forward_err =3D kunit_uapi_forward_to_printk(test, ctx.out); + if (forward_err) + kunit_uapi_kill_pid(ctx.tgid); + + wait_err =3D kernel_wait(ctx.tgid, &ret); + + /* Restore default kernel sig handler */ + kernel_sigaction(SIGCHLD, SIG_IGN); + + if (ctx.exec_err) + return ctx.exec_err; + if (forward_err) + return forward_err; + if (wait_err < 0) + return wait_err; + return ret; +} + +static int kunit_uapi_run_executable(struct kunit *test, + const struct kunit_uapi_blob *executable) +{ + const char *exe_name =3D kbasename(executable->path); + struct vfsmount *mnt; + int err; + + mnt =3D kunit_uapi_mount_ramfs(); + if (IS_ERR(mnt)) + return PTR_ERR(mnt); + + err =3D kunit_uapi_write_executable(mnt, executable); + + if (!err) + err =3D kunit_uapi_run_executable_in_mount(test, exe_name, mnt); + + kern_unmount(mnt); + + return err; +} + +void kunit_uapi_run_kselftest(struct kunit *test, const struct kunit_uapi_= blob *executable) +{ + u8 exit_code, exit_signal; + int err; + + err =3D kunit_uapi_run_executable(test, executable); + if (err < 0) + KUNIT_FAIL_AND_ABORT(test, "Could not run test executable: %pe\n", ERR_P= TR(err)); + + exit_code =3D err >> 8; + exit_signal =3D err & 0xff; + + if (exit_signal) + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with signal: %d\n", exit_si= gnal); + else if (exit_code =3D=3D KSFT_PASS) + ; /* Noop */ + else if (exit_code =3D=3D KSFT_FAIL) + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with code KSFT_FAIL\n"); + else if (exit_code =3D=3D KSFT_XPASS) + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with code KSFT_XPASS\n"); + else if (exit_code =3D=3D KSFT_XFAIL) + ; /* Noop */ + else if (exit_code =3D=3D KSFT_SKIP) + kunit_mark_skipped(test, "kselftest exited with code KSFT_SKIP\n"); + else + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with unknown exit code: %d\= n", + exit_code); +} +EXPORT_SYMBOL_GPL(kunit_uapi_run_kselftest); + +MODULE_DESCRIPTION("KUnit UAPI testing framework"); +MODULE_AUTHOR("Thomas Wei=C3=9Fschuh DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0tpX44ktUDNib4EBN7BoleLiitPrc6dl49XI3WpfGX0=; b=IWAVZI3Xxz1Rnpl9GzBO81p3Fzo7WG9Em3b2e0p/LszawIPQsKlE8iw8CH23Qv5/Or9r2t x4ayNwNt0d9y23ElwAEJ1kHJWftAyGrmC5PDMf2GI68asxzqN7McRYUXxLHUrREQuXmwyr SQEU0HdNp6r/Qy+utQg6Yg7BPcC3g9lGBDbBnokLsGau1jWqW8Neqfppc9uYv9uQtGQNAb +m+Vbq4JdKiDtTISuxGX7A7Y6r8yN0G44B82xntanqRn+PKgf6wlrIXYMPi6zpLFckLwBl bcI0NMHbXAS3a5XK2Su7gFU0/5u5inhQg4maWBI1xbb3xeiHGQqwiZIZdUk6VA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0tpX44ktUDNib4EBN7BoleLiitPrc6dl49XI3WpfGX0=; b=pfSFKZ6eEi4f/R3r7nCDsIXukWedCrntCSrLuL278pXA0wmS6fBCiMT64swXhviqdbLBg8 X2Aoi0TtV6YcrZAA== Date: Thu, 17 Jul 2025 10:48:15 +0200 Subject: [PATCH v5 13/15] kunit: uapi: Add example for UAPI tests 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-13-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=3733; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=K5hk0UAv11oD+jmCKZ8Qnmjw66cnIqh2YtZbJ/VkqiI=; b=r33QPStj/S9FFCRRI4esHKaPvv9Ls3MIK2qM/BTS+qoy1hp+sNE4jOra21z/8FITA3X5AXxOV L3xMf4fthUXDEB59JRa73Cinj2Z7n08NU/cijLnmJ3I7XsjCxPUQGXP X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Extend the example to show how to run a userspace executable. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow --- MAINTAINERS | 1 + lib/kunit/Makefile | 10 ++++++++++ lib/kunit/kunit-example-test.c | 15 +++++++++++++++ lib/kunit/kunit-example-uapi.c | 22 ++++++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 0f60501c6de570723123b24eb930d15f1bd956eb..b1405f0a0e638d1654d9dc9e51d= 784ddc838cf5b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13544,6 +13544,7 @@ KUNIT UAPI TESTING FRAMEWORK (in addition to KERNEL= UNIT TESTING FRAMEWORK) M: Thomas Wei=C3=9Fschuh S: Maintained F: include/kunit/uapi.h +F: lib/kunit/kunit-example-uapi.c F: lib/kunit/kunit-uapi.c =20 KVM PARAVIRT (KVM/paravirt) diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 6059621a2d32c8e7384acda59793f05826af8c81..2434470e998525e5667ebc207d1= 1659835b5e888 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -1,3 +1,5 @@ +include $(srctree)/init/Makefile.nolibc + obj-$(CONFIG_KUNIT) +=3D kunit.o =20 kunit-objs +=3D test.o \ @@ -31,3 +33,11 @@ obj-$(CONFIG_KUNIT_TEST) +=3D assert_test.o endif =20 obj-$(CONFIG_KUNIT_EXAMPLE_TEST) +=3D kunit-example-test.o + +userprogs +=3D kunit-example-uapi +kunit-example-uapi-userccflags :=3D -static $(NOLIBC_USERCFLAGS) + +ifdef CONFIG_KUNIT_UAPI +CFLAGS_kunit-example-test.o :=3D -Wa,-I$(obj) +$(obj)/kunit-example-test.o: $(obj)/kunit-example-uapi +endif diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c index 3056d6bc705d0a8f196f0f4412e679dbb0e03114..0c5e1e59f9358b84aee2621e342= d824a2f99f9aa 100644 --- a/lib/kunit/kunit-example-test.c +++ b/lib/kunit/kunit-example-test.c @@ -8,6 +8,7 @@ =20 #include #include +#include =20 /* * This is the most fundamental element of KUnit, the test case. A test ca= se @@ -277,6 +278,19 @@ static void example_slow_test(struct kunit *test) KUNIT_EXPECT_EQ(test, 1 + 1, 2); } =20 +/* + * This test shows the usage of UAPI tests. + */ +static void example_uapi_test(struct kunit *test) +{ + KUNIT_UAPI_EMBED_BLOB(kunit_example_uapi, "kunit-example-uapi"); + + if (IS_ENABLED(CONFIG_KUNIT_UAPI)) + kunit_uapi_run_kselftest(test, &kunit_example_uapi); + else + kunit_skip(test, "CONFIG_KUNIT_UAPI is not enabled"); +} + /* * Here we make a list of all the test cases we want to add to the test su= ite * below. @@ -297,6 +311,7 @@ static struct kunit_case example_test_cases[] =3D { KUNIT_CASE(example_priv_test), KUNIT_CASE_PARAM(example_params_test, example_gen_params), KUNIT_CASE_SLOW(example_slow_test), + KUNIT_CASE(example_uapi_test), {} }; =20 diff --git a/lib/kunit/kunit-example-uapi.c b/lib/kunit/kunit-example-uapi.c new file mode 100644 index 0000000000000000000000000000000000000000..4ce657050dd4a576632a41ca030= 9c4cb5134ce14 --- /dev/null +++ b/lib/kunit/kunit-example-uapi.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace example test. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + * + * This is *userspace* code. + */ + +#include "../../tools/testing/selftests/kselftest.h" + +int main(void) +{ + ksft_print_header(); + ksft_set_plan(4); + ksft_test_result_pass("userspace test 1\n"); + ksft_test_result_pass("userspace test 2\n"); + ksft_test_result_skip("userspace test 3: some reason\n"); + ksft_test_result_pass("userspace test 4\n"); + ksft_finished(); +} --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7984285CAC; Thu, 17 Jul 2025 08:49:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742147; cv=none; b=H65o4JRWMizrOywURfpcQIhWvPLsOha0/zqnqCyXlIVIzvWWg0nBuKsjHKBEqgEcTr661GhsKDi68m90t5TLpwpKxJF+RxeZofe1Jgoi86P98+rnx8ufO11/yr6JCzcfn5PfYdCEcVBh74rVlE99+rHCyhF1Rnv4Gt0+B7diKgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742147; c=relaxed/simple; bh=rsRst4GAUSvhO7BiyO660CynxR9JGWccwNT8lkt95Wk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Dr5IVH8gVmdXDQDpUX7nnzgwACTPLOT/lYWwOKMyxFSTWVD60Fq+uXLbjSni5vH2FS+H3G7kWYFCJ2vwCiuqUXnHF9aFGZoc596srIIk0aNpsrkkyU8XBLctqGgwepcB8RsN0/+zdCeaWNq59qa8IJud8uVWZoayMSdZ3DKyo60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dWFD09ri; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iYbpEPZM; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dWFD09ri"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iYbpEPZM" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QRrnBoH8IFFRjQzyw//nS3EiPMvLn5TdGq4dYEYIlJg=; b=dWFD09riE4O4+tZjIAy3cTk4M3sVWb5h8/ILsyaeqeEdqCqkgho5ZFfoKgaxrWjZ+asFn+ ByYwC5aZ9i5Q/ZhdRB9tKzakPfrtG6P9wjdX3b9kLtZRPN1sBvmqeSSSoo4kBYqi+ek43s TIBuzJAR0k6euvl3OQVP4TFknbVpXjXiRCSX+uxATx7CQNAThIPaHO0V+Qht46YUdybipO /v4Fjb4Vpe2PambZaOYX/jIWSfdUP4x+5HjzEONzlfJTw16k7yRm4WkXYDaYCbNeScHpKL lJCW3gOQEgjFFRWsf3Ffu7gVojL1IqRL8YC3RbASjBfB70Tc46TnYCaJAC27vQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QRrnBoH8IFFRjQzyw//nS3EiPMvLn5TdGq4dYEYIlJg=; b=iYbpEPZMe/vqrYdB5bRCpT8IjAvhzc4BJ9D9ik//CupsJl2UzOYHlpo8v+/8U00zmS8llO sYN2CUYEXI+HBtBw== Date: Thu, 17 Jul 2025 10:48:16 +0200 Subject: [PATCH v5 14/15] kunit: uapi: Introduce preinit executable 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-14-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=4791; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=rsRst4GAUSvhO7BiyO660CynxR9JGWccwNT8lkt95Wk=; b=7dAV+lyPvW4Xt9wGzS6ae0Dt5BYPoxtZ/NSDbgwLz5AEC5rxIHcjV1gwBzTHFSJP+u1XG6RWh DRZ0Mhl86nyDlbvkt2qSCmxOUhu50WR2b7u/wwforIfclfyjskegjFf X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= UAPI selftests may expect a "normal" userspace environment. For example the normal kernel API pseudo-filesystems should be mounted. This could be done from kernel code but it is non-idiomatic. Add a preinit userspace executable which performs these setup steps before running the final test executable. This preinit executable is only ever run from the kernel. Give it access to autoconf.h and kconfig.h to adapt itself to the tested kernel. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow --- MAINTAINERS | 1 + lib/kunit/Makefile | 7 ++++++ lib/kunit/kunit-uapi.c | 9 +++++-- lib/kunit/uapi-preinit.c | 63 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index b1405f0a0e638d1654d9dc9e51d784ddc838cf5b..e81dfa180ab374ef91c7a45e546= e6e9a8f454fa7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13546,6 +13546,7 @@ S: Maintained F: include/kunit/uapi.h F: lib/kunit/kunit-example-uapi.c F: lib/kunit/kunit-uapi.c +F: lib/kunit/uapi-preinit.c =20 KVM PARAVIRT (KVM/paravirt) M: Paolo Bonzini diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 2434470e998525e5667ebc207d11659835b5e888..e52a31b0852caef5669f11f6059= c29ce5911aa43 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -14,8 +14,15 @@ kunit-objs +=3D test.o \ device.o \ platform.o =20 +userprogs +=3D uapi-preinit +uapi-preinit-userccflags +=3D -static $(NOLIBC_USERCFLAGS) \ + -include include/generated/autoconf.h \ + -include $(srctree)/tools/include/linux/kconfig.h obj-$(CONFIG_KUNIT_UAPI) +=3D kunit-uapi.o =20 +CFLAGS_kunit-uapi.o :=3D -Wa,-I$(obj) +$(obj)/kunit-uapi.o: $(obj)/uapi-preinit + ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs +=3D debugfs.o endif diff --git a/lib/kunit/kunit-uapi.c b/lib/kunit/kunit-uapi.c index 24356f68eca0df07032fb8a9e92daffde01b21d3..382a2bfee3c78a6e042a56a9ccd= efcd55b5265a1 100644 --- a/lib/kunit/kunit-uapi.c +++ b/lib/kunit/kunit-uapi.c @@ -25,6 +25,8 @@ #define KSFT_XPASS 3 #define KSFT_SKIP 4 =20 +KUNIT_UAPI_EMBED_BLOB(kunit_uapi_preinit, "uapi-preinit"); + static struct vfsmount *kunit_uapi_mount_ramfs(void) { struct file_system_type *type; @@ -146,7 +148,7 @@ static int kunit_uapi_user_mode_thread_init(void *data) kernel_sigaction(SIGABRT, SIG_DFL); =20 complete(&ctx->setup_done); - ctx->exec_err =3D kernel_execve(ctx->executable, argv, NULL); + ctx->exec_err =3D kernel_execve(kbasename(kunit_uapi_preinit.path), argv,= NULL); if (!ctx->exec_err) return 0; do_exit(0); @@ -255,7 +257,10 @@ static int kunit_uapi_run_executable(struct kunit *tes= t, if (IS_ERR(mnt)) return PTR_ERR(mnt); =20 - err =3D kunit_uapi_write_executable(mnt, executable); + err =3D kunit_uapi_write_executable(mnt, &kunit_uapi_preinit); + + if (!err) + err =3D kunit_uapi_write_executable(mnt, executable); =20 if (!err) err =3D kunit_uapi_run_executable_in_mount(test, exe_name, mnt); diff --git a/lib/kunit/uapi-preinit.c b/lib/kunit/uapi-preinit.c new file mode 100644 index 0000000000000000000000000000000000000000..81182039965a8c93aebb2d5d76f= 4113bfef277a6 --- /dev/null +++ b/lib/kunit/uapi-preinit.c @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace environment setup. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + * + * This is *userspace* code. + */ + +#include +#include + +#include "../../tools/testing/selftests/kselftest.h" + +static int setup_api_mount(const char *target, const char *fstype) +{ + int ret; + + ret =3D mkdir(target, 0755); + if (ret && errno !=3D EEXIST) + return -errno; + + ret =3D mount("none", target, fstype, 0, NULL); + if (ret && errno !=3D EBUSY) + return -errno; + + return 0; +} + +static void exit_failure(const char *stage, int err) +{ + /* If preinit fails synthesize a failed test report. */ + ksft_print_header(); + ksft_set_plan(1); + ksft_test_result_fail("Failed during test setup: %s: %s\n", stage, strerr= or(-err)); + ksft_finished(); +} + +int main(int argc, char **argv, char **envp) +{ + int ret; + + ret =3D setup_api_mount("/proc", "proc"); + if (ret) + exit_failure("mount /proc", ret); + + ret =3D setup_api_mount("/sys", "sysfs"); + if (ret) + exit_failure("mount /sys", ret); + + if (IS_ENABLED(CONFIG_DEVTMPFS)) { + ret =3D setup_api_mount("/dev", "devtmpfs"); + if (ret) + exit_failure("mount /dev", ret); + } + + ret =3D execve(argv[0], argv, envp); + if (ret) + exit_failure("execve", ret); + + return 0; +} --=20 2.50.0 From nobody Sun Dec 14 20:16:28 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D080428A40C; Thu, 17 Jul 2025 08:49:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742148; cv=none; b=QIDx3Lc8UOnBuk1AbqacHkCCDWy9HnoIaSPduMVFb9xAdz0TrmOcQqj5LAK5mgbFGToEIDZjNX29rdcJHF8nzfXzNkTodaX1CMjR4bdkvuqGUu4dhaOXoJV2VhfwW/B8FG/HfQaavDeG9jnu/p0FcXHiXJYrEesxtZV2jcUwxs4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752742148; c=relaxed/simple; bh=3PSdVbXQmTSX+u1cNcSDBelpx2lCw5SctfoPsq3CtY0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VyyZJuWoQjEtoukcBwR3e8Ng22i5XiURX8vmUSt0PCbJHLBRKepecPiiLiyexylHzgcKp+8tqFPdFx7Qf8izMZevo6x6gkupBoZzIYpazXk/HvUdyBvSjIOXu1uMT8X4IASiK4aDyT2TGEjg1cz+O5gwsN4Qw5DsPTK9DUzndMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=C3U2SXGe; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ccz5GVRT; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="C3U2SXGe"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ccz5GVRT" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752742141; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lZPBaW6nQswmP9PfbPdPy5OGhGGfbO57Bjqn0Zo8Qlw=; b=C3U2SXGevfZa+II9ALnvwkUprEcBe7yrVzAVlvh3p+ggZxzsBVPq1UuJbRsUBkdBH6xoJu 2ugNpZAPjUpBpNNEOBqdCUvJq75Yx3s7KcF3y9UFzJhNFHdlSh3OewXw729T+RHxw9TJPN oo03NrRBwLIRkljCm/AhHFOngqZ2DHloY3up6jiGenkOlue8M/w1Sij3oDmZJBs/WsFXxy PuWMhbdrSvB0x3PMGkT3hdA/TyNYs3FuKcNZM15UN7VrrO8vvqdOl9GxIghRsf30+rvtNZ E4J2NWNp3sNKTg2bi9luEeHcJofJeb9LwxydRyLSzmkhqTJ4UYqVAP0OY0Aq7g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752742141; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lZPBaW6nQswmP9PfbPdPy5OGhGGfbO57Bjqn0Zo8Qlw=; b=Ccz5GVRTXNI9oDwdE3iTvJuEF6/RmFK/XHjj+nMPj/RXg6+5ymIRXmJFluoSaFFTLxfN2S KSNzJs7cHATQ0DAQ== Date: Thu, 17 Jul 2025 10:48:17 +0200 Subject: [PATCH v5 15/15] kunit: uapi: Validate usability of /proc 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: quoted-printable Message-Id: <20250717-kunit-kselftests-v5-15-442b711cde2e@linutronix.de> References: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> In-Reply-To: <20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain Cc: Christophe Leroy , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1752742130; l=4239; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=3PSdVbXQmTSX+u1cNcSDBelpx2lCw5SctfoPsq3CtY0=; b=dpqH8WrkFORXjxNS3hXpsNTuZ4sRMk81sUAzgVPKF74b5qC+n+XMeOFQB6CbApPBGO49JjXr6 +CvsEb9GeXxADUWi8+WpQ2B2edvpGQowOi4XSfJ39LlpIO+6oeZLQKx X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Show that the selftests are executed from a fairly "normal" userspace context. Signed-off-by: Thomas Wei=C3=9Fschuh --- MAINTAINERS | 1 + lib/kunit/Makefile | 9 ++++++++ lib/kunit/kunit-test-uapi.c | 51 +++++++++++++++++++++++++++++++++++++++++= ++++ lib/kunit/kunit-test.c | 23 +++++++++++++++++++- 4 files changed, 83 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index e81dfa180ab374ef91c7a45e546e6e9a8f454fa7..d86e8e0bfee75acecfeb9569d53= ea8ea99727985 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13545,6 +13545,7 @@ M: Thomas Wei=C3=9Fschuh S: Maintained F: include/kunit/uapi.h F: lib/kunit/kunit-example-uapi.c +F: lib/kunit/kunit-test-uapi.c F: lib/kunit/kunit-uapi.c F: lib/kunit/uapi-preinit.c =20 diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index e52a31b0852caef5669f11f6059c29ce5911aa43..44a93c59a48fb7b4bb34b26333a= 28283c704cdef 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -31,6 +31,15 @@ endif obj-$(if $(CONFIG_KUNIT),y) +=3D hooks.o =20 obj-$(CONFIG_KUNIT_TEST) +=3D kunit-test.o + +userprogs +=3D kunit-test-uapi +kunit-test-uapi-userccflags :=3D -static $(NOLIBC_USERCFLAGS) + +ifdef CONFIG_KUNIT_UAPI +CFLAGS_kunit-test.o :=3D -Wa,-I$(obj) +$(obj)/kunit-test.o: $(obj)/kunit-test-uapi +endif + obj-$(CONFIG_KUNIT_TEST) +=3D platform-test.o =20 # string-stream-test compiles built-in only. diff --git a/lib/kunit/kunit-test-uapi.c b/lib/kunit/kunit-test-uapi.c new file mode 100644 index 0000000000000000000000000000000000000000..ec5395d809ee2a4bd3c47a573a5= 76e2f98ef5c1b --- /dev/null +++ b/lib/kunit/kunit-test-uapi.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace selftest. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + * + * This is *userspace* code. + */ + +#include +#include +#include + +#include "../../tools/testing/selftests/kselftest.h" + +static void test_procfs(void) +{ + char buf[256]; + ssize_t r; + int fd; + + fd =3D open("/proc/self/comm", O_RDONLY); + if (fd =3D=3D -1) { + ksft_test_result_fail("procfs: open() failed: %s\n", strerror(errno)); + return; + } + + r =3D read(fd, buf, sizeof(buf)); + close(fd); + + if (r =3D=3D -1) { + ksft_test_result_fail("procfs: read() failed: %s\n", strerror(errno)); + return; + } + + if (r !=3D 16 || strncmp("kunit-test-uapi\n", buf, 16) !=3D 0) { + ksft_test_result_fail("procfs: incorrect comm\n"); + return; + } + + ksft_test_result_pass("procfs\n"); +} + +int main(void) +{ + ksft_print_header(); + ksft_set_plan(1); + test_procfs(); + ksft_finished(); +} diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c index d9c781c859fde1f3623eb71b6829e82aa4803762..03972a3cb172d4af61bec17be80= 0ddfb4bbd7268 100644 --- a/lib/kunit/kunit-test.c +++ b/lib/kunit/kunit-test.c @@ -8,6 +8,7 @@ #include "linux/gfp_types.h" #include #include +#include =20 #include #include @@ -868,10 +869,30 @@ static struct kunit_suite kunit_current_test_suite = =3D { .test_cases =3D kunit_current_test_cases, }; =20 +static void kunit_uapi_test(struct kunit *test) +{ + KUNIT_UAPI_EMBED_BLOB(kunit_test_uapi, "kunit-test-uapi"); + + if (IS_ENABLED(CONFIG_KUNIT_UAPI)) + kunit_uapi_run_kselftest(test, &kunit_test_uapi); + else + kunit_skip(test, "CONFIG_KUNIT_UAPI is not enabled"); +} + +static struct kunit_case kunit_uapi_test_cases[] =3D { + KUNIT_CASE(kunit_uapi_test), + {} +}; + +static struct kunit_suite kunit_uapi_test_suite =3D { + .name =3D "kunit_uapi", + .test_cases =3D kunit_uapi_test_cases, +}; + kunit_test_suites(&kunit_try_catch_test_suite, &kunit_resource_test_suite, &kunit_log_test_suite, &kunit_status_test_suite, &kunit_current_test_suite, &kunit_device_test_suite, - &kunit_fault_test_suite); + &kunit_fault_test_suite, &kunit_uapi_test_suite); =20 MODULE_DESCRIPTION("KUnit test for core test infrastructure"); MODULE_LICENSE("GPL v2"); --=20 2.50.0