From nobody Sat Oct 11 08:30:50 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 878B3231821; Wed, 11 Jun 2025 07:38:33 +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=1749627515; cv=none; b=GfXCIzYcgw8/xfpuV04oWN+UY4Kd5lwD3uZPE0BqfTC93JP8UnPi03CaBVaVm8V76ugV7sb3ABsw6HjElXXZYCBaTuVopLU/pb6BgKinM4cxTjINCrULbxiMeIOOGxSLxDOxCtL1wJyVgRPxQ6v60oxY5AVi6rUjvVY+UlwXG8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627515; c=relaxed/simple; bh=XUXHouC/V1vE5vzsV6IGUS5rVrpbLkz4GlNe4NCYMuc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NrDLCuVBdC1x2VpRM3p8h+8phZVXeHtikZC7i1Xmn6ZOO0r0aVaJPCTLJFalzEJdMAEzr1GEM+WGYHUp1UP6VjPQspoG3WSlBc38xJA78W9+jhV4AwGkJdQApnT5cGPqMxYz8UUXwPJrvkgpEyeSYdFZiPVvQ++1aIl/gJcTob4= 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=JG84CNXx; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=9cqj5Qwe; 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="JG84CNXx"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="9cqj5Qwe" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627511; 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=g2u/MNcTEWtPCOXtSTAERzN55pAfd3jSntXhox37eg4=; b=JG84CNXxEHRsSVKOmQLNgCzjoI5gPN/8X4LtxSRWz3wzUwmcJLzGZJStGsPQG9JoKW0qbk Ffd+9bePN/Odd5wxn6E5vpBfyokFPXWf0Logy/p673kxTR3gDdnt1yXHazdyqR+0f+nUVf w2GZ7MFSAiOkK/uR6yArp3vkwuHfgoo1dLi88mOQg0f3bf0/1WkSUtprgMpUJbpWx5ozUo DNRUmJgKwhyPdsiGijhKdKMKTs5Lr7UAVGuFx+FzgcE5egEBNZBN6EbayqHnWIJpEOSBo3 jWBXOmQ7j2CxtNa7ETDM/Wm65yY7cQFfDTshlB2reC65a2+R/7M1kYFEb6p1QQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627511; 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=g2u/MNcTEWtPCOXtSTAERzN55pAfd3jSntXhox37eg4=; b=9cqj5QweBA3hvlLfbrd+D5Gn5vEdLhgkeGKdtunUukTdZCP9+qdhoXdKFZ2zHMMqAwopDR D0SRYDm7X0/5kcBg== Date: Wed, 11 Jun 2025 09:38:07 +0200 Subject: [PATCH v3 01/16] kbuild: userprogs: avoid duplicating 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: <20250611-kunit-kselftests-v3-1-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=1184; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=XUXHouC/V1vE5vzsV6IGUS5rVrpbLkz4GlNe4NCYMuc=; b=4WFKI9mAgKXVxy5ZlX5DrLBu5OxdhJcH3eywwL778enAQRfUaFirPc8B2cBuy7NfaZ9PJ4xRC 0N8Px9pM2xPCWzNhf0I2stFC0evHCo46puDQ1Twoqy3FkNtzwFCMXM/ 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 --- 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.49.0 From nobody Sat Oct 11 08:30:50 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 878482309B6; Wed, 11 Jun 2025 07:38:33 +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=1749627515; cv=none; b=RRQpj0m1IZCBirRs66w8+Y928mUyU1Rt8xThKU+agNqRoJdVTeL5PC7MyoqIWSSQgTImMl29k2+byotyeAfaW8M/BbsTiLlOB7xEMgih80wM3PrDi9A5p+we/kob+Tfz8J5SNqMbxuCstzngI8yNmrStoOPmfwZcRGckduckHLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627515; c=relaxed/simple; bh=VQTecfMbGmIE2mhR3lC6cykpMVHE/XGTMFcN207W2vw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qJtuYk2515JEBVQHpPYVlTNpTL1HLVXUT41FVK3Z8IZdBz6swxgdkFSIcxjDVdTqHQmWL/1B8GKhAkHnzfPoHZ88mX19g101ZEviaQmkz1HPU/zt3dereSYzN521MwBMFjGq/pk3QHXu+S2nMYuhLP8uq3POfM3N/g6C1bAAZa0= 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=iUtSnZ8S; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LNeYvbSa; 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="iUtSnZ8S"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LNeYvbSa" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627511; 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=BxrB5F7pB41w5mjMWE31LUYj7rWMdcxJbt62UaOAMsU=; b=iUtSnZ8SzUl94tBC7W3072/gLmGcrlaE2EhTrJWMC2GDLjcZPMyVl1KreixsLGR48oGRTL 41lQuTNF3Ct7gb7hOZHrd7N2WMpGx+7pl8TSdAncde6FbKe6cSM0iX7sTwTOd7GFthV/tW tmoxU40Ge1JoK1iywTSGHNQpQErtQXKaA4lz5kMjl2BeesEWIiLg2EonyazKjnPHSEgMTU MdiT10EeC1oJiNmtL6lXpU5pDgszIDjUqnLdUZw+21K3BMQIQcCEKb0gOd6PSqNBMA0Min oKu17jdxQD9/jsQfSL4JuvvCb0kI/rSJHcNAaTQ6K3iB9xnSXwUURDJ47hPaSg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627511; 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=BxrB5F7pB41w5mjMWE31LUYj7rWMdcxJbt62UaOAMsU=; b=LNeYvbSa+LpU/7ZesflVIAWrD2JkrhkWvf19GMqBrxd23szxDDLnHqcSuz7EczU1H0oDlT 7YPp73cJcxAEYsDw== Date: Wed, 11 Jun 2025 09:38:08 +0200 Subject: [PATCH v3 02/16] 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: <20250611-kunit-kselftests-v3-2-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=1177; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=VQTecfMbGmIE2mhR3lC6cykpMVHE/XGTMFcN207W2vw=; b=IFuBTpGS+0Ubi/+ZN/eyZa5QO9sDBYBdL8p0IZCQJ6pqJ48E7Q50nmm8O7fsEW2cmBChEcD0m YbGBwFi3zgxB/ciDPbleIFJK+oMk2BGULFU+OAUKTBj9jX8WJTM3PrO 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. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Nicolas Schier --- 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.49.0 From nobody Sat Oct 11 08:30:50 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 1B221231839; Wed, 11 Jun 2025 07:38:33 +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=1749627515; cv=none; b=OuFx3kjNG3EI/VnJU8x1e565AXGdRJ/9bEGhAGEKpOizhNggJtx+YqRYRW0xm7NHZq7Z+nT2rCQknrmuReH1uA0cEXYXmCDP7kw4B8bzT9ebDW+0QCpoI3UwCircY2nSwv/V7Ow7hfIEkHRefeqqyZFsuJ1e1dIVAgsZ87X4MR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627515; c=relaxed/simple; bh=Ig7VKamiq+jWT99/vdaegByHHqWOv/1lyFWjxVw9lxo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HbZfax0mjZMki3AF1GFyfZO7mN5/uSzptGTyqxESa9HFCik56Fudt0QIbAfMKJw6tYgwEj7fDTKQ4VAyitC8Id8hHhcCHhoBqUuH6a1rnzIr6sGt4pKJibV0S1jS7O3BXLPjf7xl3/4ML0R8DBZCNTw/MWJs0sN0o/fRFrL5aPM= 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=UR9NDson; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=lPpp0yDP; 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="UR9NDson"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="lPpp0yDP" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627512; 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=hcFlZXIPovISI3A0GF02Ptjj0W/JPNuTnnrkTLv4Ues=; b=UR9NDson0GcUp9w/XqKsBHuKAcL28/I2N/FmV0wSvcAQlfgDX0kAP5e2Y8bXDsSJBCOX3/ hAdR9Bp1v+B6HqdzL5DFGwtBV5Fkj9sDGCauNoFzr6CRO4Lr7xUYqsFsqVpZReu6wHiMd0 T+9FXetbBwxakxr1W3bGJ3lTRW1Zpg2moNCF3zkKgHvmhR4V5c6e041ERx3EWjqXY88cG8 XIKOwDtiGz0v9BxDWIdQL4O/pSqDk+smRuEqwqU6zl+b1yQFUM3m+AHdFX4Q5uiVN+hZC+ YpjtOOkqJpX0kUFylEla+mygxgQs+6MWmUjpb2PNUxxFJLRu0jsVwT5QigyhIg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627512; 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=hcFlZXIPovISI3A0GF02Ptjj0W/JPNuTnnrkTLv4Ues=; b=lPpp0yDPR/ocLggWrZd9PXrFmK0KcWsQfHggDzf1NnD9xoU+99dENQNApPI5E6ZJqyrmVM AAxin48bL8+sv/Cg== Date: Wed, 11 Jun 2025 09:38:09 +0200 Subject: [PATCH v3 03/16] 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: <20250611-kunit-kselftests-v3-3-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=1194; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=Ig7VKamiq+jWT99/vdaegByHHqWOv/1lyFWjxVw9lxo=; b=AYcuC+jTyGyu/gvw30+W29owm0QbmOqI2QX2qDN5aSROokvjbuctKzldX5zq8F8/qfXOSlkAB uvYR7vYCLITCZZ/j7GNVi1mHnUKBop13J7YE/s9VxXI2p5wq0UHRRFn X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= For the kunit UAPI functionality this feature is needed. This reverts commit d1b99cdf22e0 ("init: remove unused CONFIG_CC_CAN_LINK_S= TATIC") Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Nicolas Schier --- 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.49.0 From nobody Sat Oct 11 08:30:50 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 72DF223183C; Wed, 11 Jun 2025 07:38:34 +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=1749627516; cv=none; b=c3Zb8VhYWwf9d+Tkq08jGu4aU0yAa6kTuPZ6v5wNlmH1sN4RcKoBKnMtPWcIjo7AwkL5cKCt/JjOjD2IQNwWle41qOQvr1VoBPpB0LPDqhNHRNegWmXiFG/wH3eNguYmjb3CM8z1uY4TQpN572XKWOTakAMvbkvAtB2Xywrpef4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627516; c=relaxed/simple; bh=JA+lgR6jDYP95l8ivl1hKVe2RNOg9XU9LTMBTUtdWi0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=utVfPCwIoMxsPt66AUBFGpYZQC1CXxEwHjsWt9njX/GE/dupm6c4fqzSazDi36230bO6XIcTy6Tv3yQzMvKsaAVO5/qDsS8oeuRE633E/WL+hJZNakrMkql8JITvSPPfBWWwXknqjfoU025yhHGHxHKs/Ux/D00Hvm1ZMrd+4L8= 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=TOtBh2KU; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dcdGNp35; 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="TOtBh2KU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dcdGNp35" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627512; 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=1E+pxdC7XCvBOJZ8pPzaFk5ypsAf/K5wNQ3KeFLn+F8=; b=TOtBh2KUnuVUS85lSgOHCG1Fg+t5UqkQ41US1tcjvzvyS8oPdeMPXvCrknrP7INKLsI28G 6SFNHskWUP+eJ0riYZXKK1OoxxOpdvghQ6uyWNteogP/1acmivFX6mmYejNvlr3ZFwahxp EeZMlXXc6pJ/HY1ypPO/UAWII9PEoz1ULxHccGKw4W6CVAoObU6vDDLvvxLwThuc2pQpjs /JJ5pmAPBMrA/5E+F2gZtsDaosx4JfSPa63nd9W/VpPluNsAqRAO63m26iaZ+wC2dC7kJ1 iFlAf+LkhTcbxMa2M2gPR+7kewxvUUF081sAB0Dd+hrJbUDoB0TLsl7Oa3KAFA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627512; 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=1E+pxdC7XCvBOJZ8pPzaFk5ypsAf/K5wNQ3KeFLn+F8=; b=dcdGNp35cwbN5l5enyvrw6QqtNl8z0RMXdG6AeX+mek+y58WZuuaxlr1/igfQ65QB18v2D fiADWYTRb3Csz1BQ== Date: Wed, 11 Jun 2025 09:38:10 +0200 Subject: [PATCH v3 04/16] kbuild: userprogs: add nolibc 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: <20250611-kunit-kselftests-v3-4-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=3395; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=JA+lgR6jDYP95l8ivl1hKVe2RNOg9XU9LTMBTUtdWi0=; b=sshp51ZicOppr5xNE4J5XSfIA6Ho2MK+qJPaO4m7xgV0guqxem23z+NRO9Fn1L/NBaCPXM/F4 irTj9CDLvh+AcNB81yPzcohfGaEWOImNfEmzL/uyKt+d0bHjfhF15sx X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Userprogs are built with the regular kernel compiler $CC. A kernel compiler does not necessarily contain a libc which is required for a normal userspace application. However the kernel tree does contain a minimal libc implementation "nolibc" which can be used to build userspace applications. Introduce support to build userprogs against nolibc instead of the default libc of the compiler, which may not exist. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Nicolas Schier --- This could probably be moved out of the generic kbuild makefiles. I think the ergonimics would suffer and this functionality could be used by other users of userprogs. Also this does currently not support out-of-tree builds. For that tools/include/nolibc/*.h and usr/include/*.h would need to be installed into the build directory. --- Documentation/kbuild/makefiles.rst | 13 +++++++++++++ scripts/Makefile.userprogs | 13 ++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/make= files.rst index 8aef3650c1f32b6b197e0dc777e26775d371a081..4cc7a1b89f1803857a472328461= 3111e9ad71d92 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -974,6 +974,19 @@ When linking bpfilter_umh, it will be passed the extra= option -static. =20 From command line, :ref:`USERCFLAGS and USERLDFLAGS ` wil= l also be used. =20 +Building userprogs against nolibc +--------------------------------- + +Not all kernel toolchains provide a libc. +Simple userprogs can be built against a very simple libc call "nolibc" pro= vided +by the kernel source tree. +This requires ``CONFIG_HEADERS_INSTALL=3Dy``. + +Example:: + + # lib/kunit/Makefile + uapi-preinit-nolibc :=3D $(CONFIG_ARCH_HAS_NOLIBC) + When userspace programs are actually built ------------------------------------------ =20 diff --git a/scripts/Makefile.userprogs b/scripts/Makefile.userprogs index f3a7e1ef3753b54303718fae97f4b3c9d4eac07c..b1633a9de6c86a023c70a717bac= 0b80b89d01431 100644 --- a/scripts/Makefile.userprogs +++ b/scripts/Makefile.userprogs @@ -16,10 +16,17 @@ user-csingle :=3D $(addprefix $(obj)/, $(user-csingle)) user-cmulti :=3D $(addprefix $(obj)/, $(user-cmulti)) user-cobjs :=3D $(addprefix $(obj)/, $(user-cobjs)) =20 +user_nolibc_ccflags :=3D -nostdlib -nostdinc -static -fno-ident -fno-async= hronous-unwind-tables \ + -ffreestanding -fno-stack-protector \ + -isystem $(objtree)/usr/include -include $(srctree)/tools/include/= nolibc/nolibc.h -isystem $(srctree)/tools/include/nolibc/ +user_nolibc_ldflags :=3D -nostdlib -nostdinc -static + user_ccflags =3D -Wp,-MMD,$(depfile) $(KBUILD_USERCFLAGS) $(userccflags) \ - $($(target-stem)-userccflags) -user_ldflags =3D $(KBUILD_USERLDFLAGS) $(userldflags) $($(target-stem)-use= rldflags) -user_ldlibs =3D $(userldlibs) $($(target-stem)-userldlibs) + $($(target-stem)-userccflags) $(if $($(target-stem)-nolibc),$(user_noli= bc_ccflags)) +user_ldflags =3D $(KBUILD_USERLDFLAGS) $(userldflags) $($(target-stem)-use= rldflags) \ + $(if $($(target-stem)-nolibc),$(user_nolibc_ldflags)) +user_ldlibs =3D $(userldlibs) $($(target-stem)-userldlibs) \ + $(if $($(target-stem)-nolibc),$(user_nolibc_ldlibs)) =20 # Create an executable from a single .c file quiet_cmd_user_cc_c =3D CC [U] $@ --=20 2.49.0 From nobody Sat Oct 11 08:30:50 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 346DE2356DD; Wed, 11 Jun 2025 07:38:35 +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=1749627517; cv=none; b=LteLd1mBY0eg130WnPsaKvAbNgnr50Q2L6OaAyNy+Rz1xPWaMyKDrnzlE0u/xa1k6r3MTCpTjs/DI5x/o58J9MMnhP5wKQuLHrLCkdsQvPBSnN8BGii7Fet3IfLYEBaAFWiA1RseAYFw/V3snLDyDkUvqrr9mM69OPKIizrwKn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627517; c=relaxed/simple; bh=NCYTY30jFMB+Vxbmu6gr5/Uxw4+rY0ZcejjmNfEv86U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JRWebZMiyPPd/c/Osurtj5NS63OMKfVBmvTwxW4RH8hrbJEduqchPxGiB2OZ+eCIIH/kEHZVyogBCLcXwcf1mwt+7nXNBdUAmUoze2FK0rSjykqJkKeChSva5f2aiuNwIieBXWJFfhaRxDBWkX6s6b9zK7xhXarW9hYmwB6Nisk= 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=FtjiXTJr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xIy08ukS; 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="FtjiXTJr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xIy08ukS" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627513; 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=6bG4aMoRqijm3QsbYqiZsQD0WSL7HKO6ZuqtzLxBHQU=; b=FtjiXTJrFGffV5jhH+yFjWxWUATl/QvykL8dX798Lj6XiLu2SWe948QyGqN8DeDVUm7NJe dhdNr6M2sBpSA47K4GzSqLsJlNUbnU6zny6ovmVNbFQ13U2Ifzf1stY9pypJqyK0g/Iezg SoRbmwjZZXoqjQXtBT1Qr/aZ0LsflD+5fbAWggU+H01hue47gmAnkAiQc9iuwJWOLWPqIX tHsHRPysx/z8vRn5m5csfz5bpMtFsVVQk48C7mcAqG5peJkRJgeBGRQNPHRXimQtohD3iB 8/g9ve1Sjo8I7G2ufDq7VWot6Q9s7tcKRLX6JMZqXUdsuMJKzVfly2225Azt6A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627513; 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=6bG4aMoRqijm3QsbYqiZsQD0WSL7HKO6ZuqtzLxBHQU=; b=xIy08ukSjsvelw4n9iDAl/SKLtOjP40mLJaUSwtRzttZ9Kue2Xd0byi/dKPInKbVlzMLz8 T4CKfurqQSuSpUBA== Date: Wed, 11 Jun 2025 09:38:11 +0200 Subject: [PATCH v3 05/16] kbuild: introduce CONFIG_ARCH_HAS_NOLIBC 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: <20250611-kunit-kselftests-v3-5-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=1774; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=NCYTY30jFMB+Vxbmu6gr5/Uxw4+rY0ZcejjmNfEv86U=; b=C+X62q9na/SevRhmECzkRpWWu/ZtskbFub2LDFhmDIb1LkmC0kEXosS7Qp5TK+9oIMXwYXsvZ 3j4MvU6yBZDDlcPlW+u3ECJRTUjkZY+yQ2ESvNuM/Pcq9271nNEmAQi X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Nolibc does not support all architectures. Add a kconfig option, so users can know where it is available. The new option is maintained inside tools/include/nolibc/ as only that directory is responsible for nolibc's availability. Reviewed-by: Nicolas Schier Signed-off-by: Thomas Wei=C3=9Fschuh --- init/Kconfig | 2 ++ tools/include/nolibc/Kconfig.nolibc | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index 26cafbad4f1560fb56b4bef31ae29baf54175661..6d10f2816e453d1d28e4b8249cb= bd95c28baa0f1 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 "tools/include/nolibc/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/tools/include/nolibc/Kconfig.nolibc b/tools/include/nolibc/Kco= nfig.nolibc new file mode 100644 index 0000000000000000000000000000000000000000..29cbc5437e70cbc5e256f00b74d= 0ab4801b40de7 --- /dev/null +++ b/tools/include/nolibc/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 --=20 2.49.0 From nobody Sat Oct 11 08:30:50 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 DB6492356B3; Wed, 11 Jun 2025 07:38:35 +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=1749627517; cv=none; b=Pvedm6FniaJqNs2UN4/mF0AOmI3iSdsE/8hKYr1mbHjLVgXJoPlbr0kFKt4FhpNMsrstr8rMHD2X1HHfGj87h7tXU9V5vIEtzcbo0PH2AyK/RTdyS1CY6GjFw8wvdzTRNUddSJYvFL6E8TNVbFeuI7C47fgjEnEJlaQTlGOnq7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627517; c=relaxed/simple; bh=oUkJFiHVSNpRRfiuTGCTp6nUhDJGSME1Xr0CfXdtdoU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VFcIr4dsumeL+Nb49HuaeXMw/65onRomIz0ehv4I2FjDAozctLR3VkV0OPbNSMwwZI8BcorzWa+91d3maVEB/ZmHFFPRs2CYjyEV03pO3Wf0jq9UTFzTqfy5N7n38018ytesiOj0q17GB56AndgC6xMuTIN7QcAlsYimQf6XQGs= 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=e7Z91fB1; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XrPFzeWW; 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="e7Z91fB1"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XrPFzeWW" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627513; 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=Jdu/Go4SV5qRaqiaKhllMqx5OXzM41p0GtpXKOIUrDI=; b=e7Z91fB1vallOUjZUNrsO4Z55jFsqYvlY4HHephEEeYBuSk+tmsXoK3j7YhaVypVI8cBtu Jjd9sEdlu6b412OKur4cdbuC6ecfGS6VDqVdOYsOcTdI+rZzvssuQHyvtRhW27dLsXmaEa mdu+lkVWnBf93I3y4wE0WzHt+T8zZJULXhV1v3o5eE+C+YA8n1zxnrClVYg6vh7skymoSh 3HYf2sySkwaey4jcShNeu2SgvTfTmO3iv2Pki/zEqmgK750Bcwf96xcFmKsCO7Or1+09Me XcGrxLUDnV6uODvgo0MqiaLjbdKDNxKGJDaoZAtbMSnSGiIxMGaHuxRCeSLxhQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627513; 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=Jdu/Go4SV5qRaqiaKhllMqx5OXzM41p0GtpXKOIUrDI=; b=XrPFzeWW/HV/DxmvdsF0KCXIjFmh/fnW2o2Ta8YdF+9ZUSr0durYeotrh2kXgb+WfGbKN8 0Sii8rbXP2S3KdAw== Date: Wed, 11 Jun 2025 09:38:12 +0200 Subject: [PATCH v3 06/16] 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: <20250611-kunit-kselftests-v3-6-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=800; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=oUkJFiHVSNpRRfiuTGCTp6nUhDJGSME1Xr0CfXdtdoU=; b=fW2l6DvURy9crOmbdwFZlP/AeJHt4Y3p5726+DixNW0iHRf41O72qIyfYfkfxhgae2OL/CTBt UuY8ic+qIqWDEzSQz2o+92JxyDiEnRCX5fGe5AyWfmQeFArjYnkii1k X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Some upcoming new documentation should link directly to the userprogs secti= on. Add a label to the section so it can be referenced. Signed-off-by: Thomas Wei=C3=9Fschuh --- Documentation/kbuild/makefiles.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/make= files.rst index 4cc7a1b89f1803857a4723284613111e9ad71d92..2adea36ac6ebf6c292e01a3e04c= 0b633e3c1b8ad 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.49.0 From nobody Sat Oct 11 08:30:50 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 86DEF23645F; Wed, 11 Jun 2025 07:38:36 +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=1749627518; cv=none; b=ZGckYIdoITOTe5GXpoIhyRf0lcGf4cZo2/Chgm4PGCBeikhOa/5Vsl2q8TITPxOXFs0G9Wc3o8tC4bQQSzJMvCpAnnkwulCBog99k8DJ9bJON/CxOxbJWGy2hmu3tXQJt4HHLwqnt8S4X5EBCqPhwEgaZbVGGxoWPwAwofUDSUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627518; c=relaxed/simple; bh=pD/oIF6vl9bmzEkj5ZAggKlVnatrMGsxFjGxCBob1vE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pYEcaYdUNTPZ3UnC9Tmsn6NPW4NS3cnRl7DfhWuNlCCVW157C2xSOkCnC+rOGuAVjUhGaXlu0unXRe7cWrsu6oruACyShqixeFIkJxupEOP3Y2OCPuVr8y9HzWC/645dipeEIa55qneGxe6vHvQnYhha2uzVpP9MuYR0Epr6BiY= 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=oTMf50hh; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Eyt1KjCL; 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="oTMf50hh"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Eyt1KjCL" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627514; 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=hLESzJCjyRk9NgOKWsvqneN/Z/AUG3s6f3HWO22jmYQ=; b=oTMf50hhVcZvAq7cTFl2mfQ/H4rC+iKT77rmSwh9XM4lzT+iEYd+Iwslf1uxQ+S0+g8xW2 2iweO6okLzO+oGrR8jwnfbkW3N5rEOKiuC4IWVtJEZL34pfSOTmfQNSBZ3sRxium/aN6ky G2W0oigiG4c2afXkqglMZ09onZcvyDT6vqUsAubrdys8DNRFbZ1GL4NOXg5Aed6hff/6+5 pBcWCVqCsS9vd9n6SGQtlCseLG95HY/CegtQ6Em5vLCjEaElicn2rPAWqMYyS/iVbq5W6Z Iic/sKQWofH6ropkyg3u56CVQXVGdqonVn0u932jzrUwLdAAoarX9tMPjux4dQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627514; 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=hLESzJCjyRk9NgOKWsvqneN/Z/AUG3s6f3HWO22jmYQ=; b=Eyt1KjCLG4nBEZrCwUCujpVH1Np3Ey9ikW6SJ/XQstAYueHJ9vwJj8AF04q6pcLn6gsdkE a/wdLSa1qB7TwWBg== Date: Wed, 11 Jun 2025 09:38:13 +0200 Subject: [PATCH v3 07/16] kbuild: introduce blob 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: <20250611-kunit-kselftests-v3-7-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=7359; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=pD/oIF6vl9bmzEkj5ZAggKlVnatrMGsxFjGxCBob1vE=; b=okb47YtxatsIw23cWcUwSqe3GEUIdBFjMySlBe+F8PzQLJv/i65uwNeakG3GPik12BxsbwBTY l0bAQhPUq7yAGA3PuaiJ5HPWP9bGdsm/3aHZ0V6wue2TOqRI4F79SWJ X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Various subsystems embed non-code build artifacts into the kernel, for example the initramfs, /proc/config.gz, vDSO image, etc. Currently each user has their own implementation for that. Add a common "blob" framework to provide this functionality. It provides standard kbuild and C APIs to embed and later access non-code build artifacts into the kernel image or modules. Reviewed-by: Nicolas Schier Signed-off-by: Thomas Wei=C3=9Fschuh --- Due to its closeness to kbuild this is currently added to its MAINTAINER en= try. But I can also maintain it on its own. --- Documentation/kbuild/makefiles.rst | 23 +++++++++++++++++++++-- MAINTAINERS | 2 ++ include/linux/blob.h | 31 +++++++++++++++++++++++++++++++ scripts/Makefile.blobs | 19 +++++++++++++++++++ scripts/Makefile.build | 6 ++++++ scripts/Makefile.clean | 2 +- scripts/blob-wrap.c | 27 +++++++++++++++++++++++++++ 7 files changed, 107 insertions(+), 3 deletions(-) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/make= files.rst index 2adea36ac6ebf6c292e01a3e04c0b633e3c1b8ad..5d158780948ab6d7d21287231e3= 10dc87d5e1dc7 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -525,8 +525,8 @@ otherwise the command line check will fail, and the tar= get will always be built. =20 If the target is already listed in the recognized syntax such as -obj-y/m, lib-y/m, extra-y/m, always-y/m, hostprogs, userprogs, Kbuild -automatically adds it to $(targets). Otherwise, the target must be +obj-y/m, lib-y/m, extra-y/m, always-y/m, hostprogs, userprogs, blobs, +Kbuild automatically adds it to $(targets). Otherwise, the target must be explicitly added to $(targets). =20 Assignments to $(targets) are without $(obj)/ prefix. if_changed may be @@ -1019,6 +1019,25 @@ There are two ways to do this. This will tell Kbuild to build binderfs_example when it visits this Makefile. =20 +.. _kbuild_blobs: + +Blob framework +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Kbuild supports wrapping source or generated files into object files which= are linked +into the kernel and then accessed at runtime through ``include/linux/blob.= h``. + +Example:: + + obj-m :=3D some-module.o + userprogs :=3D some-userprog + blobs :=3D some-userprog.blob.o + some-userprog.blob-symbol :=3D some_userprog + some-module-y +=3D some-userprog.blob.o + +Kbuild will build the :ref:`userprog ` ``some-userprog``= and +link it into ``some-module`` from where it can be accessed as ``BLOB(some_= userprog)``. + Kbuild clean infrastructure =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=3D=3D =20 diff --git a/MAINTAINERS b/MAINTAINERS index a92290fffa163f9fe8fe3f04bf66426f9a894409..435f8af750d40d859b48dd4f93f= 7991768f218e1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13063,11 +13063,13 @@ Q: https://patchwork.kernel.org/project/linux-kbu= ild/list/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuil= d.git F: Documentation/kbuild/ F: Makefile +F: include/linux/blob.h F: scripts/*vmlinux* F: scripts/Kbuild* F: scripts/Makefile* F: scripts/bash-completion/ F: scripts/basic/ +F: scripts/blob-wrap.c F: scripts/clang-tools/ F: scripts/dummy-tools/ F: scripts/include/ diff --git a/include/linux/blob.h b/include/linux/blob.h new file mode 100644 index 0000000000000000000000000000000000000000..4104d04e036fadce220e05fd2d9= b996323dd06e8 --- /dev/null +++ b/include/linux/blob.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Linkable blob API. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + */ + +#ifndef _LINUX_BLOB_H +#define _LINUX_BLOB_H + +#include +#include + +struct blob { + const char *const path; + const u8 *data; + const u8 *end; +}; + +#define BLOB(_symbol) ({ \ + extern const struct blob CONCATENATE(__blob_, _symbol); \ + &CONCATENATE(__blob_, _symbol); \ +}) + +static inline size_t blob_size(const struct blob *blob) +{ + return blob->end - blob->data; +} + +#endif /* _LINUX_BLOB_H */ diff --git a/scripts/Makefile.blobs b/scripts/Makefile.blobs new file mode 100644 index 0000000000000000000000000000000000000000..fd20ebb41c1d6509750debf7896= a08a143d28759 --- /dev/null +++ b/scripts/Makefile.blobs @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Build linkable blobs +# + +blobs :=3D $(addprefix $(obj)/, $(blobs)) + +blob-stem =3D $(subst -,_,$(subst .blob,,$(basename $(patsubst $(obj)/%,%,= $@)))) +blob-symbol =3D $(or $($(target-stem)-symbol),$(blob-stem)) + +blob-flags =3D -DBLOB_SYMBOL=3D"$(blob-symbol)" -DBLOB_INPUT=3D$< + +quiet_cmd_blob =3D BLOB $@ + cmd_blob =3D $(CC) $(c_flags) $(blob-flags) -c -o $@ $(srctree)/scri= pts/blob-wrap.c + +$(blobs): $(obj)/%.blob.o: $(obj)/% $(srctree)/scripts/blob-wrap.c FORCE + $(call if_changed_dep,blob) + +targets +=3D $(blobs) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index a6461ea411f7a95a9dd156897bec43cb22ef1092..de000268a538875596aae597efa= f06058474b17d 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -529,6 +529,12 @@ ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %= .dtb.o %.dtbo.o,$(targets) include $(srctree)/scripts/Makefile.dtbs endif =20 +# $(sort ...) is used here to remove duplicated words and excessive spaces. +blobs :=3D $(sort $(blobs)) +ifneq ($(blobs),) +include $(srctree)/scripts/Makefile.blobs +endif + # Build # ------------------------------------------------------------------------= --- =20 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean index 6ead00ec7313b3e4330a8de5f1342f2da1d6eb84..536972b0a528d117e17296da993= 6825c3903af6e 100644 --- a/scripts/Makefile.clean +++ b/scripts/Makefile.clean @@ -25,7 +25,7 @@ subdir-ymn :=3D $(addprefix $(obj)/,$(subdir-ymn)) # directory =20 __clean-files :=3D \ - $(clean-files) $(targets) $(hostprogs) $(userprogs) \ + $(clean-files) $(targets) $(hostprogs) $(userprogs) $(blobs) \ $(extra-y) $(extra-m) $(extra-) \ $(always-y) $(always-m) $(always-) \ $(hostprogs-always-y) $(hostprogs-always-m) $(hostprogs-always-) \ diff --git a/scripts/blob-wrap.c b/scripts/blob-wrap.c new file mode 100644 index 0000000000000000000000000000000000000000..82ab3bc641bd69ec35029c2f4a9= dd6d6c6720a02 --- /dev/null +++ b/scripts/blob-wrap.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include + +#define BLOB_SYMBOL_DATA CONCATENATE(__blob_data_, BLOB_SYMBOL) +#define BLOB_SYMBOL_END CONCATENATE(__blob_end_, BLOB_SYMBOL) + +asm ( +" .pushsection .rodata, \"a\"\n" +" .global " __stringify(BLOB_SYMBOL_DATA) "\n" +__stringify(BLOB_SYMBOL_DATA) ":\n" +" .incbin \"" __stringify(BLOB_INPUT) "\"\n" +" .global " __stringify(BLOB_SYMBOL_END) "\n" +__stringify(BLOB_SYMBOL_END) ":\n" +" .popsection\n" +); + +extern const u8 BLOB_SYMBOL_DATA; +extern const u8 BLOB_SYMBOL_END; + +const struct blob CONCATENATE(__blob_, BLOB_SYMBOL) =3D { + .path =3D __stringify(BLOB_INPUT), + .data =3D &BLOB_SYMBOL_DATA, + .end =3D &BLOB_SYMBOL_END, +}; --=20 2.49.0 From nobody Sat Oct 11 08:30:50 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 899642367A1; Wed, 11 Jun 2025 07:38:36 +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=1749627518; cv=none; b=egLPCmfev76YtHWXVymkaLDN33kE1wDlaawmJdFL49BLO3oSY0MfnO8G4vbCO/LYYx1WIJo3L/lpSRJcTxscPpnBwr+s93Kkfoesyt+Nf+pdJ+F+h+z4tM18I5XSg57yfCytrGd8iWvp3COrEYWbCL3pcMdFPWMLWQptfEEXf5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627518; c=relaxed/simple; bh=lI/60pEr6pY3/pLg+6Hxz2diPV2LL+wQWsSjlOiVzgY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CJeVSPUZ8vbeQ/yJTv3rhXLkVOgxpgO4DCEFbMr0kqKmxA0v1/ccUrRyjarVIg14X3xM0jiZRd/XmIZMzWOrpLmPmD0POx0aXROH6iLhaUH3OODgIQwfVdpdaTurabz25TQdi92wEimg9eRxQEsEV/tPGvy/bT50HA8UsiRKsuA= 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=DvYyg6Qv; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iNdYa4BG; 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="DvYyg6Qv"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iNdYa4BG" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627514; 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=VYgtidffxNZR2vi7Ilvk4ikd2wExNwWXZn779oXpOZw=; b=DvYyg6QvrAo5e+rlyt/4KLUOfbkR1iPns2d35AFrnM0IieJ3DplwfsMtI6Xne+BZslL3BN /Gb1bwfvg97Vn1v3WOxkwnSmldUde2QM5k6twv3hg6l4GwndFFSuA29I+Sj+fXHkT5vI3z VzYXudrr3iM+krKkavjQ/2clQ9ddURFv9+xNs9U76m0bQuURPESAqroseTaKg3XPvkpMn3 9dy0zuRxUGOEHsU/RcQBCZzrXpPqBGl/lYVdhCtKnqMHnYfkODKzMcNaH00B+rKmFL6di8 ae47FP0aw0RuczB1ZAMsOg1w0gcRTNqUmPeEAbpZabS7nRy+LZWAizlM8+LiGQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627514; 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=VYgtidffxNZR2vi7Ilvk4ikd2wExNwWXZn779oXpOZw=; b=iNdYa4BGqT8T0LBKV8V4HUwFq81N8ZO5b2HUwUfdOfNoS62BHJdUQRxRci9ajmsS4kAcHd 9Mwt3V27vHBKwCBQ== Date: Wed, 11 Jun 2025 09:38:14 +0200 Subject: [PATCH v3 08/16] 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: <20250611-kunit-kselftests-v3-8-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=2070; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=lI/60pEr6pY3/pLg+6Hxz2diPV2LL+wQWsSjlOiVzgY=; b=sHO8F73U/BrcQR+S5CdVr2kAfBk6sOvpmwGLe0GkHA6MtLjeLt3qQ2pEdENOYL4cGlV2NaBsp I53K+L8LC7pDqkqfZsB1bte48hcxCzXlCnvHHw8owd8DlTq+B8X/8Wx X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Currently there is no test 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 --- tools/testing/kunit/kunit_tool_test.py | 9 +++++= ++++ .../kunit/test_data/test_is_test_passed-failure-nested.log | 7 +++++= ++ 2 files changed, 16 insertions(+) diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/k= unit_tool_test.py index bbba921e0eacb18663abfcabb2bccf330d8666f5..691cde9b030f7729128490c1bdb= 42ccee1967ad6 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -165,6 +165,15 @@ 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) + 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..835816e0a07715a514f5f5afab1= b6250037feaf4 --- /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 test 1 +not ok 2 subtest 2 --=20 2.49.0 From nobody Sat Oct 11 08:30:50 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 D1ADE2367B3; Wed, 11 Jun 2025 07:38:36 +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=1749627519; cv=none; b=FV1NJo4MGkN6OGgGm0PAjqggERYvO/R/K58Tdn3erd2BKE06pikDIwKQNKTmR3Sz06Ldf8pgQe9BwSdXezx8coqOZqAvgm5ReNkhC03aA33p7hPwZQdEKIN9wa8nQNTEgRQLSgbCkHuRxATBvCtGHS+RZfmLEtt9AB9f4227fNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627519; c=relaxed/simple; bh=FZfj35XystYEPz6f/lxQAJk1DAHaROG5oImBgsaZQ2g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=P6KYxVmw1718KxEvfbT8yEnBVhVuIx4zwted49s1QD0VxTN6hVJkZBVvti6nUCNwjBy8HHWJ4h7wtKyz1BjnAjF42M1V0+q97eSIq7iTISJyA8zir7w0wd14wcZPeXTSfXfSKP8zZMQh/90qe5m2ylT/5rGYagrHt4n+bt6XJCY= 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=zzlZDAnd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6LiWGfLR; 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="zzlZDAnd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6LiWGfLR" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627515; 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=ASaFKtTomPi+O0p6+4d6hkjh0TrYrUSZldDYJPbgnvI=; b=zzlZDAndtBm8zhTNt7cGQbdwfhW2KoUwXGuCO25lMgB7zxRoPlqMT3C58WvTfEfHi3XUbS NU8I44a7cs7ct83ZIFE7zhJktuDhOYINj8ov5WSstoE5U5GGFMfece2QpMclyrNiP3L199 IHMNMlhHgsM2CLVM0VxEhNpv77cEjdSD02v9maMhoz+bdlI/nBI6Fe9HRbW/UpKOi2uYol kJRAagAGZ5Tt6HS/t79ozirsRUavM36M41gInToTvMn6ihHdlelnI7Roiv+lo3AeJrxuC9 ymdaKxzbHcbBGFgY/X0WZZXNAbaKLWLLYSbF8l8+gLjPnVHeyOfpQBUIMN0iog== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627515; 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=ASaFKtTomPi+O0p6+4d6hkjh0TrYrUSZldDYJPbgnvI=; b=6LiWGfLR9zUtuqZZovALvZ0fcMP/X0JLFGGbVyv3HogGVzipEIDnXMws5pw8BBpDzWZSXs MDzbTF4lNHPTaxDg== Date: Wed, 11 Jun 2025 09:38:15 +0200 Subject: [PATCH v3 09/16] 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: <20250611-kunit-kselftests-v3-9-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=2733; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=FZfj35XystYEPz6f/lxQAJk1DAHaROG5oImBgsaZQ2g=; b=rbSRPrWrHfCqEogOmtiX3FUvOIW2ud6MKv1OAWG0SHmG4ZYHwNjEZpRqQ1xF+wwZ8wCGy8L14 pq+FrfzahUXAvlcC1y0/RcdSnpkkxKb23cZS8Ody+e6CmwWvGO+K4ld 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 | 5 += ++++ tools/testing/kunit/kunit_tool_test.py | 2 +- tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log | 3 += ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kuni= t_parser.py index c176487356e6c94882046b19ea696d750905b8d5..2478beb28fc3db825855ad46200= 340e884da7df1 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -686,6 +686,11 @@ def bubble_up_test_results(test: Test) -> None: counts.add_status(status) elif test.counts.get_status() =3D=3D TestStatus.TEST_CRASHED: test.status =3D TestStatus.TEST_CRASHED + if not test.ok_status(): + for t in subtests: + if not t.ok_status(): + counts.add_status(t.status) + break =20 def parse_test(lines: LineStream, expected_num: int, log: List[str], is_su= btest: bool, printer: Printer) -> Test: """ diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/k= unit_tool_test.py index 691cde9b030f7729128490c1bdb42ccee1967ad6..c25f52650837e83325b06bddd2a= a665fd29f91d9 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -170,7 +170,7 @@ class KUnitParserTest(unittest.TestCase): 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(result.counts.failed, 3) self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[0].sta= tus) self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].sta= tus) =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 835816e0a07715a514f5f5afab1b6250037feaf4..cd9033c464792e6294905a56763= 46684182874ad 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.49.0 From nobody Sat Oct 11 08:30:50 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 4F64F2376EF; Wed, 11 Jun 2025 07:38:37 +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=1749627519; cv=none; b=QdJwkuP4TItMVRwe2xG4J3uaGiRTH9Ywx3aX4Az8rD9+URMTZL+7joKYoPrH4NTr4d3d6FHQ0/+t+6ROcOFLcbB+smX5PlLqmUaqqFW4jqWZvkgbeTgk10WExxSxOPjnb0jRcJQAgQDlJ9AgVy3nfK+494IBsWa0NV/3ODuUkLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627519; c=relaxed/simple; bh=jBKSdQACvBBwcM6WzYQQQ4hGpXONRfQDjnNvXZvxW6A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Vpk0xl7c6fYYAUHe0M5FRbxBzuCjcuIqSixb4xJPjT8V6ZmCLfMIQi0ebhcAo91bsWZFQaJiOtuSdoWhosxzod42yk9RgOC5HEFUKJ1auy83Gg0QjlxLFGph9QufrBfmiNHgMSj/mZKQIrA2qti31iqu6N5ZPUIjGAY887vsPrM= 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=geerNP5r; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qtPNzx5N; 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="geerNP5r"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qtPNzx5N" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627515; 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=vdek1izyzsKO1yVmEA7bKNhgQcuaR13nn+u8f6WyIHk=; b=geerNP5rxOPVeqffu3dQrtqo4+vGzQHyBJQQ2gTbXnsNbGfcYqeRI3eH+7kl6d6Q8ZOWM8 cZSaPjHv0bETgi/Bu0OA082S6U3pF8SYOBGgIoUdEfQogLVPazY5apgW8s9qmYKVeeLzdw OCwgF8qiNtMuxHTMARdglws33NZPZq4vzZ+xqwydlaF501Hh73VXlsVXlkf/eqVBCew8ok 3Osi+tEr7cfaW6b6Nv/gXUhZzz2/ny4Je2CcdrJo3ntBV0XT5e8wKWgU6vgAjHAKy1C6lq KGZndSVn2ldurZLYZmIK/8Q1/P4AN0fVimsOA3H6tux+iV7E5yDn5vV1QjiydQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627515; 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=vdek1izyzsKO1yVmEA7bKNhgQcuaR13nn+u8f6WyIHk=; b=qtPNzx5NePI7G6dwBvU7pzFKpSbdK0NPlWYBDIrCPoSjEKR4g6RLBmdNNUOn4hLiKepuEb bo6Y19/By7QYsoAw== Date: Wed, 11 Jun 2025 09:38:16 +0200 Subject: [PATCH v3 10/16] 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: <20250611-kunit-kselftests-v3-10-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=2785; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=jBKSdQACvBBwcM6WzYQQQ4hGpXONRfQDjnNvXZvxW6A=; b=bjaPIZjodgAcgTvHsoZuoYuCJ+8/113ovz1oTBu/1LlrHK/MHWKqy2KqNxuYAG05G3hLbAykW UvyjivABt0VD8uvoFsDEry57lSwU0Hn9WKM/N0eHfz2aN/PQpcmR7uG 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 2478beb28fc3db825855ad46200340e884da7df1..4599d23c79b79f0e219d655c705= 3c8c3b34f8152 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]+)? ?(- )?(.*) # S= KIP ?(.*)$') =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.49.0 From nobody Sat Oct 11 08:30:50 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 0317D239E60; Wed, 11 Jun 2025 07:38:37 +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=1749627519; cv=none; b=fi110kfmMuU4U1c84p++Vtc69HPaOsUwFiud3bnI9MVHrt3E+WUGpgTDktd0kwCFz+aPpkVDvGkdlsDgqsjHQ4/OJ8z3zhuN1tSNBDrTLevmLPHdhizwCzT+e7zlzoZ+R3NbEpL5zhRDuAHMzKC6EkzzvmNmn5ToNV91GAbEUMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627519; c=relaxed/simple; bh=hoA7a97F0nHmzoK4uqkonciDyfelXXtJw3EAVaFoPK4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CUcjrNlSbxDxYHk6P7T7ZrFpYh2BGtMxeawMc+R3Yg+PBe0quoGqEWcPoeSTRNXcqTk4BvA4GDKj+QhYeULJ9LJSUX8MK7Pn9rQSlsvQdjGyYR68SbpKC4sL0jYDkWcqQ84EJiQtWmucg2++pNvnw+rCV9162Q9LHzSNCDfPZAI= 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=rtyzkTdI; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=oZ2SorEm; 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="rtyzkTdI"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oZ2SorEm" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627516; 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=Jf+qTdJjsAtA+bB5leI4PJTuwlXOlpIX5ZJo2P0ZrRA=; b=rtyzkTdI4GnKlQy8FN0jWBCti8GM9cjAY4EaL0AVuEJ93q4rewugfqVCWCxMA13xPwVpnb Jv7Uas8YsyShnN6b1dugWzdwFWu6vjUMehLDoNRgBz9/vI+JyHvfNuI0gjLWO6OFxGmbBw /H4zgXqAgVwwHbpJWgCgWiQcgOw+KJUeIWr5+2lpjvW6SU2NEZek3Eno1Ww6oOdAE0toGO COQb7uoVM5cnifhwLsEnl9P/Ymkv7HkV4C6te8Nblte9PyD4NZNpIUzoBB4Ht55oZGezeE zo4QMc4P24bWpBZ0/9r1T3Xtelh+N1WUwvIOxBea0YW1CQdPbyUwflgN7DIXGw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627516; 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=Jf+qTdJjsAtA+bB5leI4PJTuwlXOlpIX5ZJo2P0ZrRA=; b=oZ2SorEmLMjdu7q+yki1JdD+B3tmZrXFV36vdUQFb7NaR26cMuYlhNKzBL3fO+wGYmAdnP bBc4CPNEeC8dBtBg== Date: Wed, 11 Jun 2025 09:38:17 +0200 Subject: [PATCH v3 11/16] 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: <20250611-kunit-kselftests-v3-11-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=1555; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=hoA7a97F0nHmzoK4uqkonciDyfelXXtJw3EAVaFoPK4=; b=7XCG/h4e3mcUAjfa8Aj+npyCUw3MngEOW9PZ10TGYegk+rYvn7jRHXImmwGjIDh8ysh0FSRVG BGs07a1PUmiDcgBOvjkKKcDKLVtVaI6WGVnyGxP8YNWPsVPqhYjU4ID 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.49.0 From nobody Sat Oct 11 08:30:50 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 925F023ABB3; Wed, 11 Jun 2025 07:38:38 +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=1749627520; cv=none; b=XiLsl2SsQc/OYOs+bqWMJYoLiIQo2oCa0jFD/d7NPfebVSIdhrGdgVGW0vsQ7H/T2FaucBUWf7rcrJJUohv5yFp30qLNmJxk4xJmKm1DSBt4ZkYGQDKDzahjjjFrBZlQtYw57S8yltsZEp30WI3b7nk/lir2ksYrYOpKax0Pfdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627520; c=relaxed/simple; bh=GN2rs7xDDVc7vTzexjV169ensgRHmJNe+Aa1g92I+yw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j5OhpbQQSuGe+sXNdGhLT05HMaUsc2U7NQwiNeensqqheWli4nKRQDyG06dTBhZ233yjJnAIDsXgUEnsxpuOMjKagD7IbJgluGxPq5H8TERIxEeElTEQjYj8lfcMv5THciECOdkD108iUrjsI5TVDsD2pWhlz4ejvqQXxqFnyHc= 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=sqfWria4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=RwA/RNJj; 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="sqfWria4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="RwA/RNJj" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627516; 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=Aw4RctE+kQHvgi29VkPu93qy1QWd5JKnsQyp7snGObQ=; b=sqfWria4kP4SOQlx1s0jeMGRs860S4UMdUyhSuujik88VHEcuMnxIlIzeiMySEFDo8/epW zWE7I4w886hrw9IKV74YQICqYDtk4ZljmNT/3k3hZX5EHJRW8x/MRK8b6Pv0D6yqkk0Lnk RzZVc0SuQnyBP0O82sAcl7gImdhtMDf9QmBbtoVcBuZqSZwaoyDWICKSBvAnRfC+gKvslq j00F6hpjjcCYg79YCcUhI6i+BB3qjnt4I+HLuAdIi6WWKTuO3bE0Mt5yYRoCIk5bulU5LR MNIlWDJP2qjZUMBYnLlWfU8KC31qUcY2jDWuclMq3kFmGC4lsYRMJp64jpu1DA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627516; 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=Aw4RctE+kQHvgi29VkPu93qy1QWd5JKnsQyp7snGObQ=; b=RwA/RNJjm6lnqAE+lJMU9c2ShEsZEVzHJ/yZEjQdiKvsS/DNrm2odS9qKdRlhkpVMy7ERE MzGpaaEV28jg1FAg== Date: Wed, 11 Jun 2025 09:38:18 +0200 Subject: [PATCH v3 12/16] 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: <20250611-kunit-kselftests-v3-12-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=948; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=GN2rs7xDDVc7vTzexjV169ensgRHmJNe+Aa1g92I+yw=; b=ng06gPoY8CuYRAkcYG8/q+yKDYB+VZpGZMcx5yDl1uLNf1fCDkWV7YBZf521G7jCF0zPnjHlX 9OeH5xEqNjZBWFVvYKUb/B7Ra3JxbP98FF2DZVmzfzvgdNwwTVDCIF0 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.49.0 From nobody Sat Oct 11 08:30:50 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 EEDB323C51B; Wed, 11 Jun 2025 07:38:38 +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=1749627521; cv=none; b=MW72ySTpNlVtmQXj5WIVI9c1p4SUmp6f4rq1OOjMQenMJOyUTPswaIK2yUtti71DB4oZKMkPBJhVXsjeQkzj69DPPW4yxd496TvBAk2V4brfmN41IjYtPbfRKzdrJj9qCpd2nXqA1q/6O2xAmeGkHODqKHjK1EK6R+Lq3psf3EM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627521; c=relaxed/simple; bh=evEGEaBGQMG0aitCkvMZt05/zY4lUxUR/hnJjYKn4fo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eU6THLD4KGenecFq7ZjCsPTAz9iBbarue21vZy9TNve9HPqAMamkhhghcCKIS1sjX8d78NB2gk76mwVk+dzAv+vLkw9BscKymlWsKBfUsHyH8cpTAq+TjraacGRx/rVQ2pVhqDxMK6S/kO4svq7TJOcQ5qnrVgZsIFpO2KWb1oI= 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=vvKCN8Tq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LMZ0eyYZ; 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="vvKCN8Tq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LMZ0eyYZ" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627517; 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=qeegnuKXd7oGvHQeYd1FFdhElwCqs7fHSjqNXBdE5Lw=; b=vvKCN8Tq4s4gEA2s0fDnxXXUEWuavHqxbTdh4kq+eWnK68mThoL4vhXX+qykTTrkuoa7b8 JsBgN7lqHEWSBcnhp726AjAc26oaDtiN5FnkYl1hF6XskmYM/dVIR5nUGKJMJqzfdeqsdo 20u8g/BiO0VMkW2Vr1d+BnrbiDkJq35p4UgKxPrrakt/2CYEsOjmK93Ju7+RrvL9fznxon zEQ3XWbbYWZ754DEMW3FTE0NSi+vC0RYJbH7Vi1bUfcyo0yAYIbjUbOhwR9gkaHac+klay I8XI+TBQcq3L+tgd8eZrTIx83mixH8g0VEuXbs1Q+DKywtSVUWPItC8eg0x/AA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627517; 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=qeegnuKXd7oGvHQeYd1FFdhElwCqs7fHSjqNXBdE5Lw=; b=LMZ0eyYZFca1AKrT3UF6v82JYggq0IQgFXwnlR0oe6Ej/5eQoU6SD3Mrot/uxa7VmoOAs5 j/g50bBqH4GXjBAg== Date: Wed, 11 Jun 2025 09:38:19 +0200 Subject: [PATCH v3 13/16] 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: <20250611-kunit-kselftests-v3-13-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=11591; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=evEGEaBGQMG0aitCkvMZt05/zY4lUxUR/hnJjYKn4fo=; b=G1B8m25juVZheEKsACqcej0oKhcJmWhf2GqXj6NSs6+lHU67Dg1v+/dwg30pFLbFI1MmLgKWH Q5bgeQao7bsAp2if/NQ74k5Ox7BGDDLG7qhA1fb+01Jxtx+om04sG1p 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 Reviewed-by: David Gow --- Currently this depends on CONFIG_KUNIT=3Dy as it uses some non-exported symbols around process management. --- Documentation/dev-tools/kunit/api/index.rst | 5 + Documentation/dev-tools/kunit/api/uapi.rst | 12 ++ include/kunit/uapi.h | 24 +++ lib/kunit/Kconfig | 10 + lib/kunit/Makefile | 2 + lib/kunit/uapi.c | 287 ++++++++++++++++++++++++= ++++ 6 files changed, 340 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..b4764424c629bf69194cf2786f5= 2aef154b02bf8 --- /dev/null +++ b/Documentation/dev-tools/kunit/api/uapi.rst @@ -0,0 +1,12 @@ +.. 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 should be built as :ref:`userprogs ` and= included into the test +module or kernel as :ref:`blobs `. + +.. kernel-doc:: include/kunit/uapi.h + :internal: diff --git a/include/kunit/uapi.h b/include/kunit/uapi.h new file mode 100644 index 0000000000000000000000000000000000000000..a6181790c96a42df05839097991= c1fbfd889cdbe --- /dev/null +++ b/include/kunit/uapi.h @@ -0,0 +1,24 @@ +/* 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 + +struct blob; +struct kunit; + +/** + * 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 blob *execu= table); + +#endif /* _KUNIT_UAPI_H */ diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index a97897edd9642f3e5df7fdd9dee26ee5cf00d6a4..1f2f5f2213a7d8438cd2683955f= 22e34f3a036dd 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -93,4 +93,14 @@ 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 + def_bool y + depends on KUNIT=3Dy + depends on CC_CAN_LINK_STATIC || ARCH_HAS_NOLIBC + select HEADERS_INSTALL + 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. + endif # KUNIT diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 656f1fa35abcc635e67d5b4cb1bc586b48415ac5..dafa09bd4241c24d31c4c19edec= b67bf724127d7 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -12,6 +12,8 @@ kunit-objs +=3D test.o \ device.o \ platform.o =20 +kunit-$(CONFIG_KUNIT_UAPI) +=3D uapi.o + ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs +=3D debugfs.o endif diff --git a/lib/kunit/uapi.c b/lib/kunit/uapi.c new file mode 100644 index 0000000000000000000000000000000000000000..121146dda533b3f90aca37c20bd= 0e7a1d20cb3b5 --- /dev/null +++ b/lib/kunit/uapi.c @@ -0,0 +1,287 @@ +// 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; +} + +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; + 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 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_file(mnt, exe_name, 0755, executable->data, blob= _size(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 blob *execu= table) +{ + u8 exit_code, exit_signal; + int err; + + err =3D kunit_uapi_run_executable(test, executable); + if (err < 0) + KUNIT_FAIL(test, "Could not run test executable: %pe\n", ERR_PTR(err)); + + exit_code =3D err >> 8; + exit_signal =3D err & 0xff; + + if (exit_signal) + KUNIT_FAIL(test, "kselftest exited with signal: %d\n", exit_signal); + else if (exit_code =3D=3D KSFT_PASS) + ; /* Noop */ + else if (exit_code =3D=3D KSFT_FAIL) + KUNIT_FAIL(test, "kselftest exited with code KSFT_FAIL\n"); + else if (exit_code =3D=3D KSFT_XPASS) + KUNIT_FAIL(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(test, "kselftest exited with unknown exit code: %d\n", exit_c= ode); +} +EXPORT_SYMBOL_GPL(kunit_uapi_run_kselftest); --=20 2.49.0 From nobody Sat Oct 11 08:30:50 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 CA64623F42A; Wed, 11 Jun 2025 07:38:39 +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=1749627522; cv=none; b=dYG5/ZSxOCgtsbVdeyhLGE1/D8Bg5+eogArcYNxP++Co0pbN/sYdhKcYrwK9lrEir/QIG+VdNqbUqLEAc27t+Nf2Ecf43JscwYoJ7gY1arlJI60dY4RU7RIFbNLCQpQ+8GRHAxMmzLFjfssq6Fl9+xP63Gw4ZB4RlBqURW7Xdv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627522; c=relaxed/simple; bh=NFNt7Qlaqk+bPAFRhwXBhyWH+aNFky6f4VGa4UdOsxk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DsPoyCzu7pYOfLwzu2tNGFYB3IZuLgpC07HVkuh5i+JOI0RXUZzlw/h5QxuDsfuFaOQsDMGCWyz3tThG9+T5alVkR4Qart9TjZ5TOxZYMObLGKqsOX403qW3yZVIaCPM/+e5gqpVWNFuFYU+FH7jXtrx2uskv1++IZm8xZYVfXQ= 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=T5bmVhlo; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=PT0tliqc; 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="T5bmVhlo"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="PT0tliqc" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627517; 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=O1R7jll6gJht8nkDymGrhmtxvxJqq0Loxw0lV05Szcc=; b=T5bmVhlomsZwAcdU/X7j6dy3T7WarXxEZYR1CXiMRKk+CU796SQVVyAHTS6PQFRQ5gVs5x Wese/kbbKWAUJ1dxki/bt88X7jLaSJNauxKYq9ibR2X0O0SIlouvxE03fugjgFxMW2e1re QHPyTRCoWkZ5HbuNoM3tqPsMrOlHN1YiO3AwWSkjH70wa17Syf4SzgzL81mR0zZExQC4sf w+aeOdFDtewCxLPJgslSZwt3j3EA8BzAcHyUjLdVADvKEOgBa3JwbMtP/GC3IuOppVUyvw cuYoHpm/eWKm4gc5hcOp2gQqZi9yH7UsfeAbkenAK3IxK5oIj1aMmQ+lOU1JzA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627517; 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=O1R7jll6gJht8nkDymGrhmtxvxJqq0Loxw0lV05Szcc=; b=PT0tliqc5evsvvZ4i67OWnTDNH/6Ac0eDMwC7CU/FIay95ZcIy8xl/gMJFV+k2UBU07+Dd bDgtv0inwB1/MGAA== Date: Wed, 11 Jun 2025 09:38:20 +0200 Subject: [PATCH v3 14/16] 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: <20250611-kunit-kselftests-v3-14-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=3252; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=NFNt7Qlaqk+bPAFRhwXBhyWH+aNFky6f4VGa4UdOsxk=; b=spGlc8yDjyRQUfz/VdgRBAAb7qkA9L7+W1fZOkmv4Jim/pNIBkdQvlRNJtXN+DGP8/r7zzMFs TCgUpuwUjiSALsSPVj1aILfRC0X4jvrUyT19wM8nT+07D/0Yz3jB93d 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 --- lib/kunit/Makefile | 9 ++++++++- lib/kunit/kunit-example-test.c | 15 +++++++++++++++ lib/kunit/kunit-example-uapi.c | 22 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index dafa09bd4241c24d31c4c19edecb67bf724127d7..e406a31df1df834a87961663de0= b7921b59481c2 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -30,4 +30,11 @@ obj-$(CONFIG_KUNIT_TEST) +=3D string-stream-test.o 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 +kunit-example-uapi-nolibc :=3D $(CONFIG_ARCH_HAS_NOLIBC) +blobs +=3D kunit-example-uapi.blob.o + +obj-$(CONFIG_KUNIT_EXAMPLE_TEST) +=3D kunit-example-mod.o +kunit-example-mod-y +=3D kunit-example-test.o +kunit-example-mod-$(CONFIG_KUNIT_UAPI) +=3D kunit-example-uapi.blob.o diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c index 3056d6bc705d0a8f196f0f4412e679dbb0e03114..b2681a6e047dfd6fea4a7cca60e= 81651d09c2eae 100644 --- a/lib/kunit/kunit-example-test.c +++ b/lib/kunit/kunit-example-test.c @@ -6,8 +6,11 @@ * Author: Brendan Higgins */ =20 +#include + #include #include +#include =20 /* * This is the most fundamental element of KUnit, the test case. A test ca= se @@ -277,6 +280,17 @@ 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) +{ + if (IS_ENABLED(CONFIG_KUNIT_UAPI)) + kunit_uapi_run_kselftest(test, BLOB(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.49.0 From nobody Sat Oct 11 08:30:50 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 AA73523F412; Wed, 11 Jun 2025 07:38:39 +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=1749627522; cv=none; b=JpMwxMYTNL3/xvDqdhWxnvVfi4qi5inp3IXR8+KyRyA0BSx6cl/pqev8LPUmE1hjSMapNAuME7k+k+m23lXMx00BbUV07Neo5HuGOXS0U9X4sqYLmYL6AoRQ4Jgij/r7/ePloQpRONwTangMxj9q1Odq4T+G3gRrX2auY+eHr6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627522; c=relaxed/simple; bh=LrqS14BgBBh1vJManAT++TMRX3/0WwlTJmmoCOXwvPw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iKuky/3BfQP3BJoUgTG6CeVYtDplXqZGkPIMeGlwcHNswuSSODWsbQ+K99db7kkAA+w0TnmdJTlkphlXd68elpYccmrciH3igHvyjc9hpj45JJZcJ+FSW3j1TxaNcv3ujZRdFusz5fE7Q3b3SiZhrRr0ArtBcLMDch3r/fMHuGc= 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=eLrUCPsY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Wj2au+nK; 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="eLrUCPsY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Wj2au+nK" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627518; 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=gsOOrGBakifNVCfKsVVVvhphUazsao0TPGogrQbBl2g=; b=eLrUCPsYv5gADn8+3sK2GRnIrrpbSOpLe4GNHneQO4DeP8C62gwifn+84R6qE6uQ0loLKO J7tRzhsIW2w2ZxBLzEHNzLzDaAbJC8DiyQ5usTIoZN4Hrq+IM7BX35S7uPcWDNw2XOzygz GWeqUYv9000ZCnvIPizgUcCqARevMeSEVp2tCo2A6k6J4XGzUewxv/OckUyMAXcIPDttmW pYaom6imO2ePjMaZsA1D81UhfrmRDzZGejo5Mvhm4ovSknOtoAa4elJNmvb8upHsvRGR7T W0vYFIrkNqYZBxRrjF0NcfqJDzlDsRZw3eqI+Sx5RTXPZIK0c4Pu446HOCkazg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627518; 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=gsOOrGBakifNVCfKsVVVvhphUazsao0TPGogrQbBl2g=; b=Wj2au+nKYQgPGmH1T5ci+Jv8EalPVdjiAV4Ttu2hoAj7phxQJbDRiWJOHEwtpSMw30xZ0X S6KPIrFpsnG0gKBA== Date: Wed, 11 Jun 2025 09:38:21 +0200 Subject: [PATCH v3 15/16] 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: <20250611-kunit-kselftests-v3-15-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=4665; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=LrqS14BgBBh1vJManAT++TMRX3/0WwlTJmmoCOXwvPw=; b=QOBN8OgiUAjyXsyLfqrFeeDagneiyz16sdrt6s8Kt0CsPoZwX20L0gJ0EWVEx35SoA0gC5np6 aKnUPlAdBi/Bn5I+vXXqYQUmndHsyI4s3CWGST2VM+c22P+zHSAbrle 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 --- lib/kunit/Makefile | 9 ++++++- lib/kunit/uapi-preinit.c | 63 ++++++++++++++++++++++++++++++++++++++++++++= ++++ lib/kunit/uapi.c | 11 +++++++-- 3 files changed, 80 insertions(+), 3 deletions(-) diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index e406a31df1df834a87961663de0b7921b59481c2..19493ec320c61e2ccbb58e8b2e9= 43e9a4ec447e2 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -12,7 +12,14 @@ kunit-objs +=3D test.o \ device.o \ platform.o =20 -kunit-$(CONFIG_KUNIT_UAPI) +=3D uapi.o +userprogs +=3D uapi-preinit +uapi-preinit-nolibc :=3D $(CONFIG_ARCH_HAS_NOLIBC) +uapi-preinit-userccflags +=3D -static \ + -include include/generated/autoconf.h \ + -include $(srctree)/tools/include/linux/kconfig.h +blobs +=3D uapi-preinit.blob.o +uapi-preinit.blob-symbol :=3D kunit_uapi_preinit +kunit-$(CONFIG_KUNIT_UAPI) +=3D uapi.o uapi-preinit.blob.o =20 ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs +=3D debugfs.o 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; +} diff --git a/lib/kunit/uapi.c b/lib/kunit/uapi.c index 121146dda533b3f90aca37c20bd0e7a1d20cb3b5..bccc081a6538507724c1ef34020= 3cfd147170dc4 100644 --- a/lib/kunit/uapi.c +++ b/lib/kunit/uapi.c @@ -139,7 +139,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(BLOB(kunit_uapi_preinit)->path)= , argv, NULL); if (!ctx->exec_err) return 0; do_exit(0); @@ -239,6 +239,7 @@ static int kunit_uapi_run_executable_in_mount(struct ku= nit *test, const char *ex =20 static int kunit_uapi_run_executable(struct kunit *test, const struct blob= *executable) { + const struct blob *preinit =3D BLOB(kunit_uapi_preinit); const char *exe_name =3D kbasename(executable->path); struct vfsmount *mnt; int err; @@ -247,7 +248,13 @@ static int kunit_uapi_run_executable(struct kunit *tes= t, const struct blob *exec if (IS_ERR(mnt)) return PTR_ERR(mnt); =20 - err =3D kunit_uapi_write_file(mnt, exe_name, 0755, executable->data, blob= _size(executable)); + err =3D kunit_uapi_write_file(mnt, kbasename(preinit->path), 0755, + preinit->data, + blob_size(preinit)); + + if (!err) + err =3D kunit_uapi_write_file(mnt, exe_name, 0755, + executable->data, blob_size(executable)); =20 if (!err) err =3D kunit_uapi_run_executable_in_mount(test, exe_name, mnt); --=20 2.49.0 From nobody Sat Oct 11 08:30:50 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 4DF92242D9D; Wed, 11 Jun 2025 07:38:40 +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=1749627522; cv=none; b=od3NPQ1Gj9rNuXPqRdKtMN88LUJGR/E6MuqFc6NDt1QIWjl6UuQgeh7oIh8ngyWkujnBE5EdbZc10qGTAUk3fxuvKycKo+DpL4WjkCbIDxnTSP3Wniki8UP9bufNU+d9cpZtv45UP1qHFc91clgd6IgYISkvXyLTSbAI96j3RB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749627522; c=relaxed/simple; bh=bI9Z3Z4OikY2vHRcbYfX3N2odvEeMwzFe2AM1aXY+bg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Aw7K3iCfDIucYGuoieIGqkNGvY1NgfSBTLjJyqsyvbNStJWUhpXdomV76KJ/UdW5kM2wymU1vLLoNAIzF2F/+dvy452vo+ui5ResupgypezRDkiKdQ35cqP/kO39IyfZvw+tJlZR96Zt63wzLlTF6WhMuxs+oIeL6Dme7fvEc8Y= 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=oZwKLG8I; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Wu9FsCQI; 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="oZwKLG8I"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Wu9FsCQI" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1749627518; 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=dTxmS6W6qZRqdjglNd/91xq5t0Sf7lvKNn22lds3tBg=; b=oZwKLG8IUYTuUtRD28FKxeMMdCaTX/U77iFBOswUdySXxbVT0aDEE12rgFAxHJCdJ7Tm2U j6NkHDdUdtsgxon12m0mDq8uGHOm6NbZH9Wbi8QU0k7qSuW6trogSG6s6qz86EhOh1od19 EGXzQh4JsW4Y2bflXKGr3DuGTzNmqMU8nmrZQ4ve6JTaAL5koDWhDLxSwQPz3bSPy63zFR MTqLMd0CNemfTcflrIwpcgZj/z0ITqLcGZ4FSTgUhKXBbpB4/m9EQJ+v34ck3A4Bg9hqbq x0QK8ENEZh104a9oRpzVdBpWgJKwvbgWBntL+tJDDmxIYSks5Dw6ZfZ9TtiB9Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1749627518; 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=dTxmS6W6qZRqdjglNd/91xq5t0Sf7lvKNn22lds3tBg=; b=Wu9FsCQIrzyRPV9W4FVqoM9fMCPZfkB3SrqeMepwTJ5K0yPoPDHGsRbu3xfz8QlRFhndmH eC2CiW8jpb6AobAw== Date: Wed, 11 Jun 2025 09:38:22 +0200 Subject: [PATCH v3 16/16] 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: <20250611-kunit-kselftests-v3-16-55e3d148cbc6@linutronix.de> References: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de> In-Reply-To: <20250611-kunit-kselftests-v3-0-55e3d148cbc6@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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nicolas Schier 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, linux-riscv@lists.infradead.org, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1749627510; l=1609; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=bI9Z3Z4OikY2vHRcbYfX3N2odvEeMwzFe2AM1aXY+bg=; b=BvsjK8jQfTlN3RKliodcN6Wpr2QQ8UHWYzK87A9Ed7LZXQp5P1ASKEUXcxymrizK7ceed/oo0 tW6g6ftHi92ABxOyphlY05wObpqRI2GKkfZjkxgZImTBYuS2FOV2ylS 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 Reviewed-by: David Gow --- lib/kunit/kunit-example-uapi.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/kunit/kunit-example-uapi.c b/lib/kunit/kunit-example-uapi.c index 4ce657050dd4a576632a41ca0309c4cb5134ce14..5e7a0f3b68f182c42b03e667567= e66f02d8c2b86 100644 --- a/lib/kunit/kunit-example-uapi.c +++ b/lib/kunit/kunit-example-uapi.c @@ -8,13 +8,45 @@ * This is *userspace* code. */ =20 +#include +#include +#include + #include "../../tools/testing/selftests/kselftest.h" =20 +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-example-u\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(4); - ksft_test_result_pass("userspace test 1\n"); + test_procfs(); 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"); --=20 2.49.0