From nobody Mon May 4 13:06:51 2026 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 F042737CD49; Mon, 4 May 2026 09:33: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=1777887217; cv=none; b=W4bMQOdKH818VGSICIh1eNX/7GxbuJr4hx+4ljB1wrNo/mIPblQXuy+Ew+7etR+hHHf8haqb/Hpsi9L4NiQ3K55XZx33JD2ulM3htnvH3nazEl6x52+wMoyW69wlY5TQch/5hoAmsEGqLV6guoPNXRlek8F2D6qXSMtAtmSj/74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777887217; c=relaxed/simple; bh=f2sOt9t/Nc7lPFpTZEDpIpO59t74OzxRJgeKcPUSTUw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q400UuuKc5PMH5zYmmeQvtTV+amjbVjyj3sX/Dyo4WTI6m29WS1FnZBSIxmKV7uqv4/3J+3ACzCeryWADzzmBn5oQ9cXaPkPXVaUdoAsPYS5fTO9eZxL+7hdtvquD9ns6p2uycviyIGTJeOcrBHYRLZBbCSRtCoUl738tzQrYi4= 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=ZfEnFY9m; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=desvd651; 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="ZfEnFY9m"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="desvd651" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777887213; 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=AX3UrfvA1Ikfg089WZjhUzDCbqXp2g4JW2YQG6OsmjU=; b=ZfEnFY9mf0iJZB1ywy4UBaWbZrc8H/EtXlIfbBtfonmSQSi2Am5KYfHBpV464WS0iKBQVk 6v5ZWvddDmCBlBV6ifCojrzz5ZmWlZymKx08Vhmsx3PaIqzeiLQKLjSS4nCV8fDXzlgvvJ rbnYq640vbPkkr3ZwcpdcGcj7PDaQIWiEj0Re5BcyHA+dlbBYcDZyGYiqqPjjlfWwt8fI1 BtY+bvEi3g54Wp66xeAsMpAMmpmQ3qGGHfUgPPQ2oLjfTo9P7/E4P8xN3U4sw7yeQOsSj9 fLIiA/IC7ghbqQx5j9hCDkBnKUz1LzCG0YrIyP2UNZpTkGo9hUrHXB19fEqR7A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777887213; 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=AX3UrfvA1Ikfg089WZjhUzDCbqXp2g4JW2YQG6OsmjU=; b=desvd651teQu4s3xchQ3J/eCMojhKG1JMLBIUG7dUu/RPjOGwGT2ntEK8YhMREvL4L9KFL c1ifPU38TgG8EEDw== Date: Mon, 04 May 2026 11:33:17 +0200 Subject: [PATCH v6 01/11] 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: <20260504-kunit-kselftests-v6-1-712d3d526d97@linutronix.de> References: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> To: Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain , David Gow , Rae Moar Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christophe Leroy , Nicolas Schier , Masahiro Yamada X-Developer-Signature: v=1; a=ed25519-sha256; t=1777887211; l=835; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=f2sOt9t/Nc7lPFpTZEDpIpO59t74OzxRJgeKcPUSTUw=; b=DyzVL+xRfpFMe5PKS783jTTg3qoqmzhHUZ/6MOAtZDAx+lIJdXP5aUWBZRLCxDwqpa+DBjMr0 OzcGhakd3wbBfx39rgZhAF4A3/a69mMob7GDZWZXTJML3mGcL0DyBTH X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Some upcoming documentation will link directly to the userprogs section. Add a label to the section so it can be referenced. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Nicolas Schier Acked-by: Masahiro Yamada --- Documentation/kbuild/makefiles.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/make= files.rst index 24a4708d26e8..6e54ad4cfecb 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.53.0 From nobody Mon May 4 13:06:51 2026 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 86ED937CD54; Mon, 4 May 2026 09:33: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=1777887216; cv=none; b=bvPoPf5UEyByGrJOq5X0HVgEqR6M4c+EciamYNoBPvD7TUo2D6G8QCcMWBjQgPcMAJKrOFzqrM6gtBwwpMSvT1bkuPDXN6R4qzdXwvanoF8CNxY31z+CpeP+QLV/4KCIzdzkB8rEUZaLejeLi47mZ2yEmM5k8Paq7O/fiIbJY7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777887216; c=relaxed/simple; bh=n0bgWJFcNKpR7u48Mrp0bvJ0+QUs8bWyY+A+fgnbBQA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aq3NMTG4Vm6I7hXxaSKzZoRApxAPWRlvQX9In6AGSPklgPlbSOhhe+TxoYtrsGs38UuFYFFaPyWUHqVHghDVOkagqY57Gpqo7siNK6Nmdu7mj7l9Nc8YslGu/NA+ko+mKGk1vzKFc7dU3QqaHO3+8MbmtA2pWdyhNH5N1NEWmA8= 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=31e3QaS3; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7w72VJSi; 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="31e3QaS3"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7w72VJSi" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777887214; 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=zQAG7CVmsWKVP7u5YLgZP2CRjHSITjRICazIKHci/JM=; b=31e3QaS305TiIXvNkEsYdXEq2eU+zYNch+6P5rkxUluCBQJPcV7hVEaDkKYyYeIL3C+Yt1 osYMcLwRsWWX+q5WCdjKSOqe7XfwCjUVKwqAop/pWZXx9VHZ3a2YSmNKcwkmv4A3qaF4+/ 7O3UurhRVwY0qOVaPlAyIZsaSqS4yED8MO8Q8tEVXoGLRIceH7ByYMrruwARg4v6VVJBw4 W2ZmJGNVh5qODK2gltQSGap0jHN72aMhS002NHIfI+W/tsnHmguGPJ5iqtsHXLHO2ew2o9 MBkh6IVMUZEn1UkxqgRMfrqaKKbIfEA9NB5Op7hEiNr+wVNevfQuw7cUaWdEmQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777887214; 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=zQAG7CVmsWKVP7u5YLgZP2CRjHSITjRICazIKHci/JM=; b=7w72VJSiZ5PXzKa8n3vn+sDeCdYJDKrqfyShNuVyd9tO+RxOtuTTMMTgwPN8tdVccUOYJm CDuB+hzrPiZiI8Cw== Date: Mon, 04 May 2026 11:33:18 +0200 Subject: [PATCH v6 02/11] exec: add dirfd parameter to kernel_execve() 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: <20260504-kunit-kselftests-v6-2-712d3d526d97@linutronix.de> References: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> To: Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain , David Gow , Rae Moar Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christophe Leroy , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1777887211; l=2639; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=n0bgWJFcNKpR7u48Mrp0bvJ0+QUs8bWyY+A+fgnbBQA=; b=Iv+b/AJAUhxlOTF9z5Z/INA2wyJRCzy+sdAo250bsF4VV1rrH0mVXbVA7E8pS7XEdlsgRzsjV Y0RMQJeyPDnA1ttbX0DCypA1WPwqFMqXkH/2F3PqTAa3sXcWYb8gpni X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Allow callers to specify the directory against which to resolve the program filename. Enables running executables from private mounts. Signed-off-by: Thomas Wei=C3=9Fschuh --- fs/exec.c | 4 ++-- include/linux/binfmts.h | 2 +- init/main.c | 2 +- kernel/umh.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index ba12b4c466f6..affae4b4f6f6 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1846,7 +1846,7 @@ static int do_execveat_common(int fd, struct filename= *filename, return bprm_execve(bprm); } =20 -int kernel_execve(const char *kernel_filename, +int kernel_execve(int dirfd, const char *kernel_filename, const char *const *argv, const char *const *envp) { int retval; @@ -1856,7 +1856,7 @@ int kernel_execve(const char *kernel_filename, return -EINVAL; =20 CLASS(filename_kernel, filename)(kernel_filename); - CLASS(bprm, bprm)(AT_FDCWD, filename, 0); + CLASS(bprm, bprm)(dirfd, filename, 0); if (IS_ERR(bprm)) return PTR_ERR(bprm); =20 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h index 65abd5ab8836..04e2b7a85b2b 100644 --- a/include/linux/binfmts.h +++ b/include/linux/binfmts.h @@ -144,7 +144,7 @@ int copy_string_kernel(const char *arg, struct linux_bi= nprm *bprm); extern void set_binfmt(struct linux_binfmt *new); extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t); =20 -int kernel_execve(const char *filename, +int kernel_execve(int dirfd, const char *filename, const char *const *argv, const char *const *envp); =20 #endif /* _LINUX_BINFMTS_H */ diff --git a/init/main.c b/init/main.c index 96f93bb06c49..551d03681234 100644 --- a/init/main.c +++ b/init/main.c @@ -1511,7 +1511,7 @@ static int run_init_process(const char *init_filename) pr_debug(" with environment:\n"); for (p =3D envp_init; *p; p++) pr_debug(" %s\n", *p); - return kernel_execve(init_filename, argv_init, envp_init); + return kernel_execve(AT_FDCWD, init_filename, argv_init, envp_init); } =20 static int try_to_run_init_process(const char *init_filename) diff --git a/kernel/umh.c b/kernel/umh.c index cffda97d961c..bab134fa8c36 100644 --- a/kernel/umh.c +++ b/kernel/umh.c @@ -106,7 +106,7 @@ static int call_usermodehelper_exec_async(void *data) commit_creds(new); =20 wait_for_initramfs(); - retval =3D kernel_execve(sub_info->path, + retval =3D kernel_execve(AT_FDCWD, sub_info->path, (const char *const *)sub_info->argv, (const char *const *)sub_info->envp); out: --=20 2.53.0 From nobody Mon May 4 13:06:51 2026 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 DB03B37D13B; Mon, 4 May 2026 09:33: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=1777887218; cv=none; b=Q7Wl648nOJXZWgy8094soLdrgo2hq5S2FComcD0duKj5fhwWVICVHJnMdnE3LAxhRX2EvU8++BLdywjrEAwl20gsVgxIZsS1PNPbpQ+n4j1voYj0PwnXfF9gowAVAL0+kCPH9izvt6fYyXfC+v7xtWH3lYDGExs8lIuceCbeNBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777887218; c=relaxed/simple; bh=6IQeujXtDmMJBXxwWbg/iZaGW/kWT5oGF6ONKpLUivo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HU0XI3Dno9JB4y9kun+5AB9Pq2Ehr0xMiZu7WLLRCmA/m55wauNq3w53KlseEOTB+0Wxzvz7dmE+KUImrBGLiaABI5iwHcz1DQvtCj08PEnr4OEI2bcmQDzS0qYaR4Oo01vtyyoIWu/4v/Tduei+v2MDFarze55qsAut6wEKMK8= 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=KHJzFSXo; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3JNrBWg4; 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="KHJzFSXo"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3JNrBWg4" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777887214; 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=jHToxwgv5knqBTlwVbm55Ico/NITwpixj9Vnj9WYkao=; b=KHJzFSXo8K9RwrWApixGzV0XEkity1pGDhE2I04yIGVqYXik2ObZ5MVMp5vEU/RgvdhH+n xnwkV3vZj/pBvofthYGrE+S/gesdCJAoSnOsnFd5Be69xApwwwbuAsCf6uLq/Wk273egAz HlWmUpAi6yYmXoHA34SwlvBhaEcBIuXpb2uXhkXSQZ6gWKRIkO3/yV0S27IJtm7/UXBd0f 0a3QyTtfLtwjqgNEUTWQiZ87vfoScZ4EjfqqwLBpiyMdigOEuYw0Hi7MV6Rf+aPdkjjBvf 56XrwPG6d9L4TFxe11mMQfvIqz3qMGp0Xpl/BFqWrExswaWyex/9esdzbWpOxg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777887214; 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=jHToxwgv5knqBTlwVbm55Ico/NITwpixj9Vnj9WYkao=; b=3JNrBWg4lE1cji7KDMZA96EMu1CCZeW+mQtJ3mU3dPORXJm9+LwS+RJJ6PD3Dbi4pvCKRp iMHUlYSzYh1t/oBg== Date: Mon, 04 May 2026 11:33:19 +0200 Subject: [PATCH v6 03/11] umh: add dirfd parameter 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: <20260504-kunit-kselftests-v6-3-712d3d526d97@linutronix.de> References: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> To: Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain , David Gow , Rae Moar Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christophe Leroy , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1777887211; l=5541; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=6IQeujXtDmMJBXxwWbg/iZaGW/kWT5oGF6ONKpLUivo=; b=Bk32p7HowhqNBjsR8fXr53puXfLwSLesnkOi5si5O6aApY04poo5Gma1mEo9waYkeDsu9TM1O LsjNchuYUR8Ax8X2kZKRTRsO6Lg34ZsS7JyN6TSyV/RhqESvpp0PeIw X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Allow callers to specify the directory against which to resolve the helper's filename. Enables the running of helpers from private mounts. Signed-off-by: Thomas Wei=C3=9Fschuh --- fs/coredump.c | 2 +- include/linux/umh.h | 3 ++- kernel/module/kmod.c | 2 +- kernel/umh.c | 9 ++++++--- lib/kobject_uevent.c | 2 +- security/keys/request_key.c | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index bb6fdb1f458e..45df2387be3d 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -1015,7 +1015,7 @@ static bool coredump_pipe(struct core_name *cn, struc= t coredump_params *cprm, helper_argv[argi] =3D cn->corename + argv[argi]; helper_argv[argi] =3D NULL; =20 - sub_info =3D call_usermodehelper_setup(helper_argv[0], helper_argv, NULL, + sub_info =3D call_usermodehelper_setup(AT_FDCWD, helper_argv[0], helper_a= rgv, NULL, GFP_KERNEL, umh_coredump_setup, NULL, cprm); if (!sub_info) diff --git a/include/linux/umh.h b/include/linux/umh.h index daa6a7048c11..6670b9ff85d4 100644 --- a/include/linux/umh.h +++ b/include/linux/umh.h @@ -20,6 +20,7 @@ struct file; struct subprocess_info { struct work_struct work; struct completion *complete; + int dirfd; const char *path; char **argv; char **envp; @@ -34,7 +35,7 @@ extern int call_usermodehelper(const char *path, char **argv, char **envp, int wait); =20 extern struct subprocess_info * -call_usermodehelper_setup(const char *path, char **argv, char **envp, +call_usermodehelper_setup(int dirfd, const char *path, char **argv, char *= *envp, gfp_t gfp_mask, int (*init)(struct subprocess_info *info, struct cred *new), void (*cleanup)(struct subprocess_info *), void *data); diff --git a/kernel/module/kmod.c b/kernel/module/kmod.c index a25dccdf7aa7..a85c57a707af 100644 --- a/kernel/module/kmod.c +++ b/kernel/module/kmod.c @@ -95,7 +95,7 @@ static int call_modprobe(char *orig_module_name, int wait) argv[3] =3D module_name; /* check free_modprobe_argv() */ argv[4] =3D NULL; =20 - info =3D call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL, + info =3D call_usermodehelper_setup(AT_FDCWD, modprobe_path, argv, envp, G= FP_KERNEL, NULL, free_modprobe_argv, NULL); if (!info) goto free_module_name; diff --git a/kernel/umh.c b/kernel/umh.c index bab134fa8c36..5cdcba6005d9 100644 --- a/kernel/umh.c +++ b/kernel/umh.c @@ -106,7 +106,7 @@ static int call_usermodehelper_exec_async(void *data) commit_creds(new); =20 wait_for_initramfs(); - retval =3D kernel_execve(AT_FDCWD, sub_info->path, + retval =3D kernel_execve(sub_info->dirfd, sub_info->path, (const char *const *)sub_info->argv, (const char *const *)sub_info->envp); out: @@ -331,6 +331,7 @@ static void helper_unlock(void) =20 /** * call_usermodehelper_setup - prepare to call a usermode helper + * @dirfd: directory to resolve path against * @path: path to usermode executable * @argv: arg vector for process * @envp: environment for process @@ -352,7 +353,7 @@ static void helper_unlock(void) * Function must be runnable in either a process context or the * context in which call_usermodehelper_exec is called. */ -struct subprocess_info *call_usermodehelper_setup(const char *path, char *= *argv, +struct subprocess_info *call_usermodehelper_setup(int dirfd, const char *p= ath, char **argv, char **envp, gfp_t gfp_mask, int (*init)(struct subprocess_info *info, struct cred *new), void (*cleanup)(struct subprocess_info *info), @@ -366,8 +367,10 @@ struct subprocess_info *call_usermodehelper_setup(cons= t char *path, char **argv, INIT_WORK(&sub_info->work, call_usermodehelper_exec_work); =20 #ifdef CONFIG_STATIC_USERMODEHELPER + sub_info->dirfd =3D AT_FDCWD; sub_info->path =3D CONFIG_STATIC_USERMODEHELPER_PATH; #else + sub_info->dirfd =3D dirfd; sub_info->path =3D path; #endif sub_info->argv =3D argv; @@ -484,7 +487,7 @@ int call_usermodehelper(const char *path, char **argv, = char **envp, int wait) struct subprocess_info *info; gfp_t gfp_mask =3D (wait =3D=3D UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL; =20 - info =3D call_usermodehelper_setup(path, argv, envp, gfp_mask, + info =3D call_usermodehelper_setup(AT_FDCWD, path, argv, envp, gfp_mask, NULL, NULL, NULL); if (info =3D=3D NULL) return -ENOMEM; diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index ddbc4d7482d2..426ac83f1d2a 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c @@ -628,7 +628,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobje= ct_action action, goto exit; =20 retval =3D -ENOMEM; - info =3D call_usermodehelper_setup(env->argv[0], env->argv, + info =3D call_usermodehelper_setup(AT_FDCWD, env->argv[0], env->argv, env->envp, GFP_KERNEL, NULL, cleanup_uevent_env, env); if (info) { diff --git a/security/keys/request_key.c b/security/keys/request_key.c index a7673ad86d18..f6f3d4bc0bda 100644 --- a/security/keys/request_key.c +++ b/security/keys/request_key.c @@ -101,7 +101,7 @@ static int call_usermodehelper_keys(const char *path, c= har **argv, char **envp, { struct subprocess_info *info; =20 - info =3D call_usermodehelper_setup(path, argv, envp, GFP_KERNEL, + info =3D call_usermodehelper_setup(AT_FDCWD, path, argv, envp, GFP_KERNEL, umh_keys_init, umh_keys_cleanup, session_keyring); if (!info) --=20 2.53.0 From nobody Mon May 4 13:06:51 2026 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 9752137D11C; Mon, 4 May 2026 09:33: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=1777887219; cv=none; b=gyjqv9mo/Pw64DkmjIVkL5BXlrTh5LsKDsuiB+Xe2YymdOEfnMFocfh2HnXX6lDCEg2AjMi5+TL4gA9qwnQhaqEJG320fa8i7R4B09rvK6eIzcEe3fLT7T99JyQpJX7gERSIRL4yIMawgsxxUQA9xt88mI+kCW9lKw+kPvUkPUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777887219; c=relaxed/simple; bh=C3+WFuqmWwAWuvuhG3a2V6T0cnnllWx1wESAQzOgWr8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fkc8apZXbGaLzS4s5O+JA64OQRLhEdz0tLpNdXlXNz5FUshPwvucZwHTeIejUfu+gZLuV06JXWRbAysQdU8eSs23x8CZ3/+d1Yye8imtC1pM6JanJ2qyZq1okPlC/bblF9HRo/fF2ZEQOS6WJB/0oxbe//vhDvZa1Hp9W1pNB9M= 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=3gmgsHw5; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=9lPszCZn; 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="3gmgsHw5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="9lPszCZn" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777887216; 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=phMjACbbvuhJ46Y+Cb858pBZjegCvm4hvrrYxP3IpmE=; b=3gmgsHw5te80Dz/TZDbLGM3dFTERMqapPBJi/OXq2MSNASi9YNll/M+B5OTWWK62YV0UEu Eeaogq+Rxbz/jGTEZsfFPD3NIglGsy2FrE1flRqFlxTxaJgXCNKedyI0aegneiUvs+DURI o4gv590DTa2TNYCMso6RVAdXPCxhqKpPrJiTBEG/RpFF4sJAfTlHhEQNZDEWYZDW2/UG6i RRp+aey7vW1keVEQinPXv412qNAkCWtjC2mIn2P+7rOcV0Ho8shLQW1MqaDHjZPz9axJUu 6q3wvVB8KW+sk5bnp0zn355b7G1Kxb9Oi0lP/A6ZjlXM4y1F4k3t9q0i2FWRQw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777887216; 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=phMjACbbvuhJ46Y+Cb858pBZjegCvm4hvrrYxP3IpmE=; b=9lPszCZn2QHEJUrwgxhj/VQdGyetnCTvE5dKW+y5m4uWQ9xMZJKk3F7DwsT388WsCS9kXv qKzeAJvoL9CdX+BQ== Date: Mon, 04 May 2026 11:33:20 +0200 Subject: [PATCH v6 04/11] mount: add support for __free(kern_unmount) 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: <20260504-kunit-kselftests-v6-4-712d3d526d97@linutronix.de> References: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> To: Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain , David Gow , Rae Moar Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christophe Leroy , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1777887211; l=942; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=C3+WFuqmWwAWuvuhG3a2V6T0cnnllWx1wESAQzOgWr8=; b=v8qWN3CNL84w0W8dTXihmLZsAsWIE+x2wKIstna01FUjr0T/jkeNaar/aA60a1U9P56ywJEI4 K6s10u66qsVD63S4sOtrFF++I7GIlzk8hZpWpMo88J4Is5p59tKF6VI X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Allow usage of kern_unmount from the automatic __free cleanup logic. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/linux/mount.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/mount.h b/include/linux/mount.h index acfe7ef86a1b..d8689ce61a42 100644 --- a/include/linux/mount.h +++ b/include/linux/mount.h @@ -10,6 +10,7 @@ #ifndef _LINUX_MOUNT_H #define _LINUX_MOUNT_H =20 +#include #include #include =20 @@ -99,6 +100,7 @@ extern bool our_mnt(struct vfsmount *mnt); =20 extern struct vfsmount *kern_mount(struct file_system_type *); extern void kern_unmount(struct vfsmount *mnt); +DEFINE_FREE(kern_unmount, struct vfsmount *, if (_T) kern_unmount(_T)); extern int may_umount_tree(struct vfsmount *); extern int may_umount(struct vfsmount *); int do_mount(const char *, const char __user *, --=20 2.53.0 From nobody Mon May 4 13:06:51 2026 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 2B01737EFE4; Mon, 4 May 2026 09:33: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=1777887220; cv=none; b=X3uE2Nv51w4ZDx0ZgoCY2bvEnHgFKHIahOH1zEZm3S2QDMs/3QsstPgherV+Gx3WoUjZ/qHPh4jQVCypQ7C9r/+SXZpGOCFs+UHBHEPcKETIO91jjDdEVJph2nSYAsjol+PM4elduO13FVUNLk6NKX+RxOntgkltlLA2ubkfMhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777887220; c=relaxed/simple; bh=6rrqaxgFiPHF8GVMd6WSz8gimcEUJCAQ0WbyR1cySwc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X82y4SjsMTrNPZKqSyud4wGuCw6b7CgfGm3UZKgiPPL/q3KZNWLWZsxIFd4WjA/N4ZRVIPwkwqetvfGTZlE0W9lx3q0l9tINsdKfhhcL1eqzqz/poEEUFkPTCVQ0+kco3dg0QOWxxxCHMY1C0gWzr0FTAA8L3pvUCn8o9qhms74= 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=o1NfSlad; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3iMHR0tj; 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="o1NfSlad"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3iMHR0tj" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777887216; 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=ugVOeRWOWBTtOIYgmoFYz2LhMt6W4Dhjf2Ekki4Yvyw=; b=o1NfSladl93mM06aJdoptf/eSurx6nQPJXgm2QcRqoU9KrrsZnqml9Mw8ZAP59TqxL8PlW x4Za1b4elqPJ1HgTgVq7J4aBQNwu7rfUAYy15OK1W0zgPPdXpNeprVRTXHpiKe9aA9+rWe QRDNCxHGuPy+9zraizvL+c5W4ACpPpTOCqb4EX4xOHyPRFnqzjowy2eQmPCwVJ+un+7GrH T7NVljFiawhvvp8LXv19e82B/FJuRiTHA+yV8FGLYieRtA1JIsoh2ph5qaKW/j+6qW40tc Nk2EQ3vT0YRchsXI2UWCVAGkeFSDKiGhwKkGp0Vov3V5vE6ir3q5rF9ppb7zCA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777887216; 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=ugVOeRWOWBTtOIYgmoFYz2LhMt6W4Dhjf2Ekki4Yvyw=; b=3iMHR0tjbnL8tPWjVIBtZgGPFqGE0Ei/V/A1ZWtgai9bVFgsjYH0+VP0OJAFVPacr6mFK3 QXOXum6eDsu39fBA== Date: Mon, 04 May 2026 11:33:21 +0200 Subject: [PATCH v6 05/11] init: add nolibc build support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260504-kunit-kselftests-v6-5-712d3d526d97@linutronix.de> References: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> To: Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain , David Gow , Rae Moar Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christophe Leroy , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1777887211; l=2801; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=6rrqaxgFiPHF8GVMd6WSz8gimcEUJCAQ0WbyR1cySwc=; b=lLv26QbCnoFu+xwMv5Zb421C/VYsqHUM8BHxOQNWqkF7mZy+TSz+5G6TsseajtATALbOf1Rbj X8kKFb3ozuSCcD605KF4XXKed6PUuWZkfSuZHLuIibd1Cu9USBgBroO X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Building userspace applications through the kbuild "userprogs" framework requires a libc. Kernel toolchains often do not contain a libc. In this case it is useful to use the nolibc library from the kernel tree. Nolibc does not support all architectures and requires compiler flags. Add a kconfig option, so users can know where it is available and provide a variable for common options. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Nicolas Schier --- MAINTAINERS | 2 ++ init/Kconfig | 2 ++ init/Kconfig.nolibc | 16 ++++++++++++++++ init/Makefile.nolibc | 13 +++++++++++++ 4 files changed, 33 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 2fb1c75afd16..be4f6242b3fc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18960,6 +18960,8 @@ M: Willy Tarreau M: Thomas Wei=C3=9Fschuh S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc.g= it +F: init/Kconfig.nolibc +F: init/Makefile.nolibc F: tools/include/nolibc/ F: tools/testing/selftests/nolibc/ =20 diff --git a/init/Kconfig b/init/Kconfig index 3bb92a3f6cc1..c37d9227ba72 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -106,6 +106,8 @@ config CC_CAN_LINK default $(cc_can_link_user,$(m64-flag)) if 64BIT default $(cc_can_link_user,$(m32-flag)) =20 +source "init/Kconfig.nolibc" + # Fixed in GCC 14, 13.3, 12.4 and 11.5 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113921 config GCC_ASM_GOTO_OUTPUT_BROKEN diff --git a/init/Kconfig.nolibc b/init/Kconfig.nolibc new file mode 100644 index 000000000000..07488ef18f4f --- /dev/null +++ b/init/Kconfig.nolibc @@ -0,0 +1,16 @@ +# 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 SUPERH + default y if UML_X86 + default y if X86 diff --git a/init/Makefile.nolibc b/init/Makefile.nolibc new file mode 100644 index 000000000000..dacc78ab4c81 --- /dev/null +++ b/init/Makefile.nolibc @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0 +# Compiler flags, which are necessary to build userspace applications with= the +# in-kernel libc "nolibc". + +ifeq ($(and $(CONFIG_ARCH_HAS_NOLIBC),$(CONFIG_HEADERS_INSTALL)),y) + +NOLIBC_USERCFLAGS :=3D -nostdlib -nostdinc -static -ffreestanding \ + -fno-asynchronous-unwind-tables -fno-stack-protector \ + -I$(objtree)/usr/include -I$(srctree)/tools/include/nolibc/ + +NOLIBC_USERLDFLAGS :=3D -nostdlib -nostdinc -static + +endif # CONFIG_ARCH_HAS_NOLIBC && CONFIG_HEADERS_INSTALL --=20 2.53.0 From nobody Mon May 4 13:06:51 2026 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 1B00037F000; Mon, 4 May 2026 09:33: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=1777887221; cv=none; b=QWtWtcWq7+LM2fExO22BE0x7MR+qEQBp74iewphn8OSGmU5LeR44DlYoTPwZo4JrAr/DyKfIkMUM7lT4lgRLXTdbSsKKk5UM7XR5K5H5QJXAvx9zZIbVuqcCauUK18yXB8MHkMzn+Dd5UN7pf8FwQW1Sx2lnJeyJr9TVQTdqJzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777887221; c=relaxed/simple; bh=/OTOG/yua90Lm6N+XVb5eKq3ag+BtIQRvIkh/Uh7nqY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C5U3wd6ZPCQbv60BNH4sDG8EgkmkqC1ZoSh2+ybzGBaxqGdtGzNxhOxzDNB17Be5MTva5AYaE1GWDtss8Jf6edG1caz4uiLMY9CfGETMcC9nUi4YfW3BqUYRLWygi4I/cAoySfoyzRiVTJAa0e/B7Y3C20GRGctAWRQkszQttrY= 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=19x/oCdJ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=M/Uov3tW; 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="19x/oCdJ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="M/Uov3tW" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777887217; 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=dRvGlWmW/ojdtGAUMoSosFz7deYXy8s7phdrC4jCvnM=; b=19x/oCdJuCt3sTu3vTApdQLhjebe/Ydk01U5DhSb0hNZkgEx21FnNsIhZxOGJVCESPAVsl LzmeqpUq0Jonmcm2OK6bLFurYJcZRvp2Zb3fWKq/tQ7MSfWRIa9LD+nzJsmxGiqUfVc7T7 hWa6B/d+4MdRYx7xvQQ1gJpCmIZegN7WvktTAaNeJJWzg1vwJYyEWaBoM3QCehJvhrcG5O XquE6x/y7PPljUh1TVkHsvCuFRLtoXCA/mzNbJUkJs8YoVWAFs17BuyGjNxgL3z160gyxq K8xpIPXKEWoaxzoPb4lJOfD0jpiS3f5PLcBLsf2V89LmCRScbpjbYMAkD96Qfg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777887217; 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=dRvGlWmW/ojdtGAUMoSosFz7deYXy8s7phdrC4jCvnM=; b=M/Uov3tWwMt7wja+O9d7V2NBb3AAHuPbGWW1qRdr/I9g5F06chKUTbdH2eVZUEigPOs/sW 5rX+5REI0NZEUOAw== Date: Mon, 04 May 2026 11:33:22 +0200 Subject: [PATCH v6 06/11] 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: <20260504-kunit-kselftests-v6-6-712d3d526d97@linutronix.de> References: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> To: Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain , David Gow , Rae Moar Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christophe Leroy , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1777887211; l=938; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=/OTOG/yua90Lm6N+XVb5eKq3ag+BtIQRvIkh/Uh7nqY=; b=BSBfbeny5Sp+nXeipSJPWFZtzmTsbG6naZ2YXu+Z/Sz6yPYCeqEBDHlnUD9xlFYWGXf+e9G0y 2o11zIf8DsGDWXZYcZrsJ54Mn+Gvgit5Ozs+EfUJF5lomDn2OlZ/af8 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 a92422967d1d..1dba755284f1 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.53.0 From nobody Mon May 4 13:06:51 2026 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 AE51137F01B; Mon, 4 May 2026 09:33: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=1777887222; cv=none; b=qAH3AO1zzbaDNeaAwdSIb4r2k3ff1/orMhjnVH1pvvZt3BhbdZgRILbzBADgScgzdxNT0rrPocmyS0cBbLV/jPXj6UqOs699eeul43dRfeLTwZnqU1GDIt8f7d++ZXIILo7u2BodngDk9VMVXNLoLvkPhdzVwxppfNdSPkdsLgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777887222; c=relaxed/simple; bh=2L6gp2L3ByeOjEJ+yHu5JnKMwKtbkdQ9OZqBxRAn/MM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VSXa1y9jyqjgh2FOioUIy5dg+tS8SvG1j6xUrfEVW9VT5seTSi1Dvb9GkLznxZ2V2YK3Z3krtr+YviYjCjO1Uoa7bgASBmddehFILpReLB6yhczs2m4nB+kGP9WydkrIdYzGlcfskEuehFg0f31sqF4AuxHZPAXmRONxfpCLR8M= 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=G+MH4msg; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VqwfyAtN; 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="G+MH4msg"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VqwfyAtN" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777887218; 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=bNhDee3n5mRVMX7s7eQ6SV9IedetRRfoH0zE/EbioIA=; b=G+MH4msgy+08eWsp0mIp0jz9U2a8SGS5ZabdReFhyoMSh2OTk0NZZT8FuFvV2Cfz63TX36 7aUo0mK13JPjgXJR6JH/IMF3W7Y4k+yiswVrCBcnHqXaSzxs3VjtlJgRIG2DLAjB8QvQGi JKC6FVhEbQ3VgXdbFqViS2BvQqVlR1qrzSoWml9yLL2Gp6H5Wjbc16U+ob934DRKQEoLLo C05U4338TYhox5/b71uhe/8IIdtoxjzzgw6DfloLKLbcsUhN5oI4Mbd6GHndExHuso7sl0 Sw1U/MDxu7Gad2TyQZO6elBZ0ystnuiYLh2H+WxnJqkij+aMf4gCZDFLlTMb5g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777887218; 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=bNhDee3n5mRVMX7s7eQ6SV9IedetRRfoH0zE/EbioIA=; b=VqwfyAtNQyPVNa/aneoLCY41scKAuq7mHqjFHQVQ+ccw5AujEywsQPLI4igVSi9F7FlntE VNENreqabY06ASDQ== Date: Mon, 04 May 2026 11:33:23 +0200 Subject: [PATCH v6 07/11] 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: <20260504-kunit-kselftests-v6-7-712d3d526d97@linutronix.de> References: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> To: Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain , David Gow , Rae Moar Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christophe Leroy , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1777887211; l=11941; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=2L6gp2L3ByeOjEJ+yHu5JnKMwKtbkdQ9OZqBxRAn/MM=; b=lPC4ggh6t2uwyK3HlqIKDCKnOmbbPHJlJAHhU1cet6DJ0ZYSTqc7/Ws+N6m7ycxFH4zP0+Aa+ u5t1Zt6AO+eD3mwnKlw1onf50J1UQqUmOsglyEo9Ipd6JdSyWi3HuYy 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 --- Documentation/dev-tools/kunit/api/index.rst | 5 + Documentation/dev-tools/kunit/api/uapi.rst | 14 ++ MAINTAINERS | 6 + include/kunit/uapi.h | 77 +++++++++++ lib/kunit/Kconfig | 16 +++ lib/kunit/Makefile | 2 + lib/kunit/kunit-uapi.c | 193 ++++++++++++++++++++++++= ++++ 7 files changed, 313 insertions(+) diff --git a/Documentation/dev-tools/kunit/api/index.rst b/Documentation/de= v-tools/kunit/api/index.rst index 5cdb552a0808..34d8fee9a970 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 000000000000..1f01b5c6c9db --- /dev/null +++ b/Documentation/dev-tools/kunit/api/uapi.rst @@ -0,0 +1,14 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Userspace Test API +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This file documents all of the userspace testing API. +Userspace tests are built as :ref:`kbuild userprogs `, +linked statically and without any external dependencies. + +For the widest platform compatibility they should use nolibc, as provided = by `init/Makefile.nolibc`. + +.. kernel-doc:: include/kunit/uapi.h + :internal: diff --git a/MAINTAINERS b/MAINTAINERS index be4f6242b3fc..e29ca56f7334 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14395,6 +14395,12 @@ S: Maintained F: Documentation/devicetree/bindings/leds/backlight/kinetic,ktz8866.yaml F: drivers/video/backlight/ktz8866.c =20 +KUNIT UAPI TESTING FRAMEWORK (in addition to KERNEL UNIT TESTING FRAMEWORK) +M: Thomas Wei=C3=9Fschuh +S: Maintained +F: include/kunit/uapi.h +F: lib/kunit/kunit-uapi.c + KVM PARAVIRT (KVM/paravirt) M: Paolo Bonzini R: Vitaly Kuznetsov diff --git a/include/kunit/uapi.h b/include/kunit/uapi.h new file mode 100644 index 000000000000..1e0585355124 --- /dev/null +++ b/include/kunit/uapi.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * KUnit Userspace testing API. + * + * Copyright (C) 2026, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + */ + +#ifndef _KUNIT_UAPI_H +#define _KUNIT_UAPI_H + +#include + +struct kunit; + +/** + * struct kunit_uapi_blob - Blob embedded build artifact + * @path: Path of the embedded artifact. + * @data: Start of the embedded data in memory. + * @end: End of the embedded data in memory. + */ +struct kunit_uapi_blob { + const char *const path; + const u8 *data; + const u8 *end; +}; + +#if IS_ENABLED(CONFIG_KUNIT_UAPI) + +/** + * KUNIT_UAPI_EMBED_BLOB() - Embed another build artifact into the kernel + * @_name: The name of symbol under which the artifact is embedded. + * @_path: Path to the artifact on disk. + * + * Embeds a build artifact like a userspace executable into the kernel or = current module. + * The build artifact is read from disk and needs to be already built. + */ +#define KUNIT_UAPI_EMBED_BLOB(_name, _path) \ + asm ( \ + " .pushsection .rodata, \"a\" \n" \ + " .global " __stringify(CONCATENATE(_name, _data)) " \n" \ + __stringify(CONCATENATE(_name, _data)) ": \n" \ + " .incbin " __stringify(_path) " \n" \ + " .size " __stringify(CONCATENATE(_name, _data)) ", " \ + ". - " __stringify(CONCATENATE(_name, _data)) " \n" \ + " .global " __stringify(CONCATENATE(_name, _end)) " \n" \ + __stringify(CONCATENATE(_name, _end)) ": \n" \ + " .popsection \n" \ + ); \ + \ + extern const char CONCATENATE(_name, _data)[]; \ + extern const char CONCATENATE(_name, _end)[]; \ + \ + static const struct kunit_uapi_blob _name =3D { \ + .path =3D _path, \ + .data =3D CONCATENATE(_name, _data), \ + .end =3D CONCATENATE(_name, _end), \ + } \ + +#else /* !CONFIG_KUNIT_UAPI */ + +/* Unresolved external reference, to be optimized away */ +#define KUNIT_UAPI_EMBED_BLOB(_name, _path) \ + extern const struct kunit_uapi_blob _name + +#endif /* CONFIG_KUNIT_UAPI */ + +/** + * kunit_uapi_run_kselftest() - Run a userspace kselftest as part of kunit + * @test: The test context object. + * @executable: kselftest executable to run + * + * Runs the kselftest and forwards its TAP output and exit status to kunit. + */ +void kunit_uapi_run_kselftest(struct kunit *test, const struct kunit_uapi_= blob *executable); + +#endif /* _KUNIT_UAPI_H */ diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index 498cc51e493d..f3dc9fac811a 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -141,4 +141,20 @@ config KUNIT_UML_PCI =20 If unsure, say N. =20 +config KUNIT_UAPI + tristate "KUnit UAPI testing framework" + depends on KUNIT + depends on ARCH_HAS_NOLIBC + depends on !STATIC_USERMODEHELPER + depends on !LTO_CLANG # https://github.com/llvm/llvm-project/issues/112920 + select HEADERS_INSTALL + select DEVTMPFS + default KUNIT + help + Enables support for building and running userspace selftests as part of= kunit. + These tests should be statically linked and use kselftest.h or kselftes= t_harness.h + for status reporting. + + In most cases this should be left as its default. + endif # KUNIT diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 656f1fa35abc..6059621a2d32 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -12,6 +12,8 @@ kunit-objs +=3D test.o \ device.o \ platform.o =20 +obj-$(CONFIG_KUNIT_UAPI) +=3D kunit-uapi.o + ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs +=3D debugfs.o endif diff --git a/lib/kunit/kunit-uapi.c b/lib/kunit/kunit-uapi.c new file mode 100644 index 000000000000..485b79fd193d --- /dev/null +++ b/lib/kunit/kunit-uapi.c @@ -0,0 +1,193 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace testing API. + * + * Copyright (C) 2026, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +enum { + KSFT_PASS =3D 0, + KSFT_FAIL =3D 1, + KSFT_XFAIL =3D 2, + KSFT_XPASS =3D 3, + KSFT_SKIP =3D 4, +}; + +static struct vfsmount *kunit_uapi_mount_fs(const char *name) +{ + struct file_system_type *type; + + type =3D get_fs_type(name); + if (!type) + return ERR_PTR(-ENODEV); + + return kern_mount(type); +} + +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; + } + + return 0; +} + +static const char *kunit_uapi_executable_target(const struct kunit_uapi_bl= ob *executable) +{ + return kbasename(executable->path); +} + +static int kunit_uapi_write_executable(struct vfsmount *mnt, + const struct kunit_uapi_blob *executable) +{ + return kunit_uapi_write_file(mnt, kunit_uapi_executable_target(executable= ), 0755, + executable->data, executable->end - executable->data); +} + +struct kunit_uapi_usermodehelper_ctx { + struct vfsmount *mnt; + struct kunit *test; +}; + +static int kunit_uapi_get_cwd(struct vfsmount *mnt) +{ + CLASS(get_unused_fd, fd)(O_RDONLY); + if (fd < 0) + return fd; + + struct file *file __free(fput) =3D file_open_root_mnt(mnt, "/", O_DIRECTO= RY, 0); + if (IS_ERR(file)) + return PTR_ERR(file); + + fd_install(fd, no_free_ptr(file)); + + return take_fd(fd); +} + +static int kunit_uapi_usermodehelper_init(struct subprocess_info *info, st= ruct cred *new) +{ + struct kunit_uapi_usermodehelper_ctx *ctx =3D info->data; + int dirfd; + + dirfd =3D kunit_uapi_get_cwd(ctx->mnt); + if (dirfd < 0) + return dirfd; + + kernel_sigaction(SIGKILL, SIG_DFL); + kernel_sigaction(SIGABRT, SIG_DFL); + + current->kunit_test =3D ctx->test; + + info->dirfd =3D dirfd; + + return 0; +} + +static int kunit_uapi_run_executable_in_mount(struct kunit *test, + const struct kunit_uapi_blob *executable, + struct vfsmount *mnt) +{ + const char *executable_target =3D kunit_uapi_executable_target(executable= ); + struct kunit_uapi_usermodehelper_ctx ctx =3D { + .test =3D test, + .mnt =3D mnt, + }; + struct subprocess_info *info; + const char *const argv[] =3D { + executable_target, + NULL + }; + + info =3D call_usermodehelper_setup(AT_FDCWD, executable_target, (char **)= argv, NULL, + GFP_KERNEL, kunit_uapi_usermodehelper_init, NULL, &ctx); + if (!info) + return -ENOMEM; + + /* Flush delayed fput so exec can open the file read-only */ + flush_delayed_fput(); + + return call_usermodehelper_exec(info, UMH_WAIT_PROC); +} + +static int kunit_uapi_run_executable(struct kunit *test, const struct kuni= t_uapi_blob *executable) +{ + int err; + + struct vfsmount *mnt __free(kern_unmount) =3D kunit_uapi_mount_fs("ramfs"= ); + if (IS_ERR(mnt)) + return PTR_ERR(mnt); + + err =3D kunit_uapi_write_executable(mnt, executable); + if (err) + return err; + + err =3D kunit_uapi_run_executable_in_mount(test, executable, mnt); + if (err) + return err; + + return 0; +} + +void kunit_uapi_run_kselftest(struct kunit *test, const struct kunit_uapi_= blob *executable) +{ + u8 exit_code, exit_signal; + int err; + + err =3D kunit_uapi_run_executable(test, executable); + if (err < 0) + KUNIT_FAIL_AND_ABORT(test, "Could not run test executable: %pe\n", ERR_P= TR(err)); + + exit_code =3D err >> 8; + exit_signal =3D err & 0xff; + + if (exit_signal) + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with signal: %d\n", exit_si= gnal); + else if (exit_code =3D=3D KSFT_PASS) + ; /* Noop */ + else if (exit_code =3D=3D KSFT_FAIL) + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with code KSFT_FAIL\n"); + else if (exit_code =3D=3D KSFT_XPASS) + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with code KSFT_XPASS\n"); + else if (exit_code =3D=3D KSFT_XFAIL) + ; /* Noop */ + else if (exit_code =3D=3D KSFT_SKIP) + kunit_mark_skipped(test, "kselftest exited with code KSFT_SKIP\n"); + else + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with unknown exit code: %d\= n", + exit_code); +} +EXPORT_SYMBOL_GPL(kunit_uapi_run_kselftest); + +MODULE_DESCRIPTION("KUnit UAPI testing framework"); +MODULE_AUTHOR("Thomas Wei=C3=9Fschuh DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777887218; 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=txu04uvacD5BOS6pZdks2wuxHk5ixo4TfuHlWKL2s0s=; b=mytd3Boyf69X4DDkWYFsi3ghOpooOmkdsKjdjdOBxbNWBWvOZP9MPNV43Sc79YmSQtHmRE eva8BnHmWcioprtk8fVgJd3wokb8PwA5ABxUvu9bO1BJGh8iRtLshnMDDIEgMkfXXnupq6 AQTA2l9yxbUhGe8cvG/rq3Vr1TSuiIKGR4sVCZ73LzT9lnfbc7F7j0TpunBJsfo7kSSbIs 2vFXEW3QMA90ILnGysdIhsPPNdRC2eOl+RUj9baIAALDNFxvdQJQ/x2rYgWy5kJwV8r2BI h8rZyhDn0/kpWS1B1xoj96n2d+IvapYP4hB7J3MPtfAajl0Mrbwo86x78k6WgQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777887218; 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=txu04uvacD5BOS6pZdks2wuxHk5ixo4TfuHlWKL2s0s=; b=SmVfsSu9Ki8BtDRjyzCt/w/mgkUvSIl+eZyl+8rVP3O0aXLRqNJ5Md6wQqTc+aIj6Ss/iO OGjOTGd18wjqzsAQ== Date: Mon, 04 May 2026 11:33:24 +0200 Subject: [PATCH v6 08/11] kunit: uapi: Forward test executable output to KUnit log 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: <20260504-kunit-kselftests-v6-8-712d3d526d97@linutronix.de> References: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> To: Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain , David Gow , Rae Moar Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christophe Leroy , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1777887211; l=5270; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=2eKO4vMe4Rs11ZE058NHDusLM5GzLyo6TWJUCIU1st4=; b=eAyXR25yto2GniYCRLnQQbR726ZuqwLNF+cJwkhT563vUaH60/3lrMUsQgD6kXStTvdCBgEwI vf+45teK5TZC+XQ54PNDtmEuDO+/q/Y8/AerLsK3YVRVM8UiBjRLNwu X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The output of the test executable should be grouped together with the regular KUnit output and also be available in debugfs. Install a custom miscdevice as stdout and stderr which forwards the written data to the KUnit log. Signed-off-by: Thomas Wei=C3=9Fschuh --- lib/kunit/kunit-uapi.c | 155 +++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 154 insertions(+), 1 deletion(-) diff --git a/lib/kunit/kunit-uapi.c b/lib/kunit/kunit-uapi.c index 485b79fd193d..7f0309a827a5 100644 --- a/lib/kunit/kunit-uapi.c +++ b/lib/kunit/kunit-uapi.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,8 @@ #include #include =20 +#define KUNIT_LOG_DEVICE "kunit-log" + enum { KSFT_PASS =3D 0, KSFT_FAIL =3D 1, @@ -94,10 +97,48 @@ static int kunit_uapi_get_cwd(struct vfsmount *mnt) return take_fd(fd); } =20 +static int kunit_uapi_open_standard_streams(void) +{ + struct vfsmount *devtmpfs __free(kern_unmount) =3D kunit_uapi_mount_fs("d= evtmpfs"); + if (IS_ERR(devtmpfs)) + return PTR_ERR(devtmpfs); + + CLASS(get_unused_fd, stdin_fd)(O_RDONLY); + if (stdin_fd < 0) + return stdin_fd; + + CLASS(get_unused_fd, stdout_fd)(O_WRONLY); + if (stdout_fd < 0) + return stdout_fd; + + CLASS(get_unused_fd, stderr_fd)(O_WRONLY); + if (stderr_fd < 0) + return stderr_fd; + + struct file *logfile __free(fput) =3D file_open_root_mnt(devtmpfs, KUNIT_= LOG_DEVICE, + O_RDWR, 0); + if (IS_ERR(logfile)) + return PTR_ERR(logfile); + + fd_install(stdin_fd, no_free_ptr(logfile)); + fd_install(stdout_fd, fget(stdin_fd)); + fd_install(stderr_fd, fget(stdin_fd)); + + take_fd(stdin_fd); + take_fd(stdout_fd); + take_fd(stderr_fd); + + return 0; +} + static int kunit_uapi_usermodehelper_init(struct subprocess_info *info, st= ruct cred *new) { struct kunit_uapi_usermodehelper_ctx *ctx =3D info->data; - int dirfd; + int ret, dirfd; + + ret =3D kunit_uapi_open_standard_streams(); + if (ret) + return ret; =20 dirfd =3D kunit_uapi_get_cwd(ctx->mnt); if (dirfd < 0) @@ -188,6 +229,118 @@ void kunit_uapi_run_kselftest(struct kunit *test, con= st struct kunit_uapi_blob * } EXPORT_SYMBOL_GPL(kunit_uapi_run_kselftest); =20 +struct kunit_uapi_log_private { + struct mutex mutex; + struct seq_buf buf; + char data[4096]; +}; + +static int kunit_uapi_log_open(struct inode *ino, struct file *file) +{ + struct kunit_uapi_log_private *priv; + + priv =3D kmalloc_obj(*priv); + if (!priv) + return -ENOMEM; + + mutex_init(&priv->mutex); + seq_buf_init(&priv->buf, priv->data, sizeof(priv->data)); + + file->private_data =3D priv; + + return 0; +} + +static void kunit_uapi_log_str(struct kunit *test, const char *str, size_t= len) +{ + kunit_log(KERN_INFO, test, KUNIT_SUBSUBTEST_INDENT "%.*s", (int)len, str); +} + +static void kunit_uapi_print_buf_to_log(struct kunit *test, struct seq_buf= *s) +{ + const char *start, *lf; + + if (s->size =3D=3D 0 || s->len =3D=3D 0) + return; + + start =3D seq_buf_str(s); + while ((lf =3D strchr(start, '\n'))) { + kunit_uapi_log_str(test, start, lf - start + 1); + start =3D ++lf; + } + + /* Remove printed data from buffer */ + memmove(s->buffer, start, start - s->buffer); + s->len -=3D start - s->buffer; +} + +static ssize_t kunit_uapi_log_write(struct file *file, const char __user *= ubuf, size_t count, + loff_t *off) +{ + struct kunit_uapi_log_private *priv =3D file->private_data; + struct seq_buf *buf =3D &priv->buf; + struct kunit *test; + + test =3D kunit_get_current_test(); + if (!test) + return -ENODEV; + + guard(mutex)(&priv->mutex); + + if (seq_buf_has_overflowed(buf)) + return -E2BIG; + + if (buf->size < buf->len + count) { + seq_buf_set_overflow(buf); + kunit_warn(test, "KUnit UAPI line buffer has overflowed\n"); + return -E2BIG; + } + + if (copy_from_user(buf->buffer + buf->len, ubuf, count)) + return -EFAULT; + + buf->len +=3D count; + + kunit_uapi_print_buf_to_log(test, &priv->buf); + + return count; +} + +static int kunit_uapi_log_release(struct inode *ino, struct file *file) +{ + struct kunit_uapi_log_private *priv =3D file->private_data; + struct kunit *test; + + mutex_destroy(&priv->mutex); + + test =3D kunit_get_current_test(); + if (!test) { + kfree(priv); + return -ENODEV; + } + + /* Flush last partial line */ + kunit_uapi_log_str(test, priv->buf.buffer, priv->buf.len); + kunit_uapi_log_str(test, "\n", 1); + + kfree(priv); + return 0; +} + +static const struct file_operations kunit_uapi_log_fops =3D { + .owner =3D THIS_MODULE, + .open =3D kunit_uapi_log_open, + .release =3D kunit_uapi_log_release, + .write =3D kunit_uapi_log_write, +}; + +static struct miscdevice kunit_uapi_log =3D { + .minor =3D MISC_DYNAMIC_MINOR, + .name =3D KUNIT_LOG_DEVICE, + .fops =3D &kunit_uapi_log_fops, +}; +module_misc_device(kunit_uapi_log); + MODULE_DESCRIPTION("KUnit UAPI testing framework"); MODULE_AUTHOR("Thomas Wei=C3=9Fschuh DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777887219; 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=ft5tjVlJemnVxdKrQOWR07GWUrenfDbo6YKiLlRQjYg=; b=NC+00YvnEebssrgHehzlz8bX7d+X1xp33wCP3F4/hOYN8p9eHYVnXdW9p4aP28p0zVsJt9 KeKHZP/hTwB7uHL5RRZhma/aQBpVrdIOJh1JTyz/NAxYkUX/wdjJdZYhI8xbOZJHmUdQa6 NOimy2qPsefv3aMws9u7uUwsUXTWN0MagCH2NggrHygMmRa+2AdYfvPKVvUA88IDNb1aQy Z4UF9aa9F9JaaLJtPRjudkod2k2pqxoZu9KITzPUWycNwzWDJTGBV70ah0fZbcD1owZru8 jzHvynCd/7HagURExUsddqcXdodk2pS0roZJu0rMOXpXX/Qce4KiKQ4KwZvlQA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777887219; 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=ft5tjVlJemnVxdKrQOWR07GWUrenfDbo6YKiLlRQjYg=; b=YjAiuNtuewrsNsYXNQ5rzmlr51bXN+FcRHyyKsBkqi8MmLFxxEc/o7iKpcKU16CH1ILplT wmFhEZ+1YxCEjKCA== Date: Mon, 04 May 2026 11:33:25 +0200 Subject: [PATCH v6 09/11] 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: <20260504-kunit-kselftests-v6-9-712d3d526d97@linutronix.de> References: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> To: Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain , David Gow , Rae Moar Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christophe Leroy , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1777887211; l=3560; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=X2NN2sojneity7IMySlccOZ5k53NgDydZFJmaouxqdA=; b=d+F6BfdlzPGVKpRtvndevjxQUwuA2kdiKjOKE+xclSjrFppN4PZlwNeh8L5VMEutjdqDzgLmY LaFBlIeV+GPAc2hVsx4yFUiV9oZx8OMoKI//hL7q4tmqR6l1KjH9PQg X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Extend the example to show how to run a userspace executable. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow --- MAINTAINERS | 1 + lib/kunit/Makefile | 10 ++++++++++ lib/kunit/kunit-example-test.c | 15 +++++++++++++++ lib/kunit/kunit-example-uapi.c | 22 ++++++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index e29ca56f7334..b7358d89df70 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14399,6 +14399,7 @@ KUNIT UAPI TESTING FRAMEWORK (in addition to KERNEL= UNIT TESTING FRAMEWORK) M: Thomas Wei=C3=9Fschuh S: Maintained F: include/kunit/uapi.h +F: lib/kunit/kunit-example-uapi.c F: lib/kunit/kunit-uapi.c =20 KVM PARAVIRT (KVM/paravirt) diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 6059621a2d32..2434470e9985 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -1,3 +1,5 @@ +include $(srctree)/init/Makefile.nolibc + obj-$(CONFIG_KUNIT) +=3D kunit.o =20 kunit-objs +=3D test.o \ @@ -31,3 +33,11 @@ obj-$(CONFIG_KUNIT_TEST) +=3D assert_test.o endif =20 obj-$(CONFIG_KUNIT_EXAMPLE_TEST) +=3D kunit-example-test.o + +userprogs +=3D kunit-example-uapi +kunit-example-uapi-userccflags :=3D -static $(NOLIBC_USERCFLAGS) + +ifdef CONFIG_KUNIT_UAPI +CFLAGS_kunit-example-test.o :=3D -Wa,-I$(obj) +$(obj)/kunit-example-test.o: $(obj)/kunit-example-uapi +endif diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c index 0bae7b7ca0b0..febabc995405 100644 --- a/lib/kunit/kunit-example-test.c +++ b/lib/kunit/kunit-example-test.c @@ -8,6 +8,7 @@ =20 #include #include +#include =20 /* * This is the most fundamental element of KUnit, the test case. A test ca= se @@ -489,6 +490,19 @@ static void example_params_test_with_init_dynamic_arr(= struct kunit *test) KUNIT_EXPECT_EQ(test, param_val - param_val, 0); } =20 +/* + * This test shows the usage of UAPI tests. + */ +static void example_uapi_test(struct kunit *test) +{ + KUNIT_UAPI_EMBED_BLOB(kunit_example_uapi, "kunit-example-uapi"); + + if (IS_ENABLED(CONFIG_KUNIT_UAPI)) + kunit_uapi_run_kselftest(test, &kunit_example_uapi); + else + kunit_skip(test, "CONFIG_KUNIT_UAPI is not enabled"); +} + /* * Here we make a list of all the test cases we want to add to the test su= ite * below. @@ -514,6 +528,7 @@ static struct kunit_case example_test_cases[] =3D { kunit_array_gen_params, example_param_init_dynamic_arr, example_param_exit_dynamic_arr), 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 000000000000..5875b0d680d4 --- /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) 2026, 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.53.0 From nobody Mon May 4 13:06:51 2026 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 2489537FF40; Mon, 4 May 2026 09:33: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=1777887223; cv=none; b=G/JFglTKkb/K0bwLtp7mNNMj2AsLEYBltZaJ52khX/Vy5SHdUeP6bQXrNXG+7D+qXP857Ci3a+V47/We1b6NrnZwT5M1oH6Q7H3Gi8NbEamnPeR9AyNuCxgCN/WSk/b6kOVcBTedZ+/xTrgxiTkXkXMP89FnhJ1m3RX3dJZ0Z5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777887223; c=relaxed/simple; bh=CX9mDSQHReDHwq7Y7h5slKzIlaWwgoLVwu8rW9SRZP4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B4CaXKA67oYjZdbhebWbM5EYXHkBxwspG0tyeWqq9bpcyrSQzVCHf4Rrk12wfbHbTLZl+IUj8Ptb/MT2KoRhs+g9WB7s4YdrFQoBGTn5rjqnoMkrxwgklJOVZY2SAXSjbzbaKw+hPbyWIGngQpEzHPhLHtbjsG6CiWKsqCcvES4= 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=4fiTe258; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ya8hyzbQ; 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="4fiTe258"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ya8hyzbQ" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777887219; 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=54QuLJcpe0mdHxqir8B4oCgM7uiPnZyrpfVJkv2VNTQ=; b=4fiTe258PXM0AU2nF7sr5EciL3AdNsNqw81aKrsuxiSBuO4QWf6cAgiMuXLDkBqdvK/XKu Ijh3JsX+2dnvAA7LEJpd3cMm46MSUJw5WXC1RTCOLsH2Yswj6DGbHBNmSLGncTETXbrxTG B7uwGflbsgYNglEpYOTQ+8l/Dv67mXhK16xU+rzb0T0b4WpETfUPPNPuKNBvOeR/Suw2UY 96NZZQKjHOOj8/2Fm3c8UNkb70iz1uCEWY6vurHFQLmvXaQucDFopVFYbyPCYPlhA9Tfnj +3g8IyKdCIKcMtfF5sd7lSHjIHCKrH0vup+LBZ6I9zlA1WLT5dKKLzAm0dINiw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777887219; 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=54QuLJcpe0mdHxqir8B4oCgM7uiPnZyrpfVJkv2VNTQ=; b=Ya8hyzbQcKEwRoNDtlD4uUE03ky+hH7RSJQxS5sQvYcq4X0VjPDSsiV9I/5Dbl6forYmpQ LVR3IRbfPh4yaiBg== Date: Mon, 04 May 2026 11:33:26 +0200 Subject: [PATCH v6 10/11] 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: <20260504-kunit-kselftests-v6-10-712d3d526d97@linutronix.de> References: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> To: Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain , David Gow , Rae Moar Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christophe Leroy , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1777887211; l=4914; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=CX9mDSQHReDHwq7Y7h5slKzIlaWwgoLVwu8rW9SRZP4=; b=rOUneMbzF1f113+9Wt2C9L8BsiwD6Dzs1kpZ+t+eIdHAn5qh6FHYThaZdNzBgRt7wbUS+4RoP isGDCOYJAILCmFNroiCghjSkp5vq1Kt9kPuoxp+L8KlkpBK1EnCvsKx X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= UAPI selftests may expect a "normal" userspace environment. For example the normal kernel API pseudo-filesystems should be mounted. This could be done from kernel code but it is non-idiomatic. Add a preinit userspace executable which performs these setup steps before running the final test executable. This preinit executable is only ever run from the kernel. Give it access to autoconf.h and kconfig.h to adapt itself to the tested kernel. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow --- MAINTAINERS | 1 + lib/kunit/Makefile | 5 ++++ lib/kunit/kunit-uapi.c | 11 +++++--- lib/kunit/uapi-preinit.c | 68 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 82 insertions(+), 3 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index b7358d89df70..4e8cf9fa7aa9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14401,6 +14401,7 @@ S: Maintained F: include/kunit/uapi.h F: lib/kunit/kunit-example-uapi.c F: lib/kunit/kunit-uapi.c +F: lib/kunit/uapi-preinit.c =20 KVM PARAVIRT (KVM/paravirt) M: Paolo Bonzini diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 2434470e9985..05991d69aa70 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -14,8 +14,13 @@ kunit-objs +=3D test.o \ device.o \ platform.o =20 +userprogs +=3D uapi-preinit +uapi-preinit-userccflags +=3D -static $(NOLIBC_USERCFLAGS) obj-$(CONFIG_KUNIT_UAPI) +=3D kunit-uapi.o =20 +CFLAGS_kunit-uapi.o :=3D -Wa,-I$(obj) +$(obj)/kunit-uapi.o: $(obj)/uapi-preinit + ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs +=3D debugfs.o endif diff --git a/lib/kunit/kunit-uapi.c b/lib/kunit/kunit-uapi.c index 7f0309a827a5..702d26878ccd 100644 --- a/lib/kunit/kunit-uapi.c +++ b/lib/kunit/kunit-uapi.c @@ -33,6 +33,8 @@ enum { KSFT_SKIP =3D 4, }; =20 +KUNIT_UAPI_EMBED_BLOB(kunit_uapi_preinit, "uapi-preinit"); + static struct vfsmount *kunit_uapi_mount_fs(const char *name) { struct file_system_type *type; @@ -158,18 +160,17 @@ static int kunit_uapi_run_executable_in_mount(struct = kunit *test, const struct kunit_uapi_blob *executable, struct vfsmount *mnt) { - const char *executable_target =3D kunit_uapi_executable_target(executable= ); struct kunit_uapi_usermodehelper_ctx ctx =3D { .test =3D test, .mnt =3D mnt, }; struct subprocess_info *info; const char *const argv[] =3D { - executable_target, + kunit_uapi_executable_target(executable), NULL }; =20 - info =3D call_usermodehelper_setup(AT_FDCWD, executable_target, (char **)= argv, NULL, + info =3D call_usermodehelper_setup(AT_FDCWD, kunit_uapi_preinit.path, (ch= ar **)argv, NULL, GFP_KERNEL, kunit_uapi_usermodehelper_init, NULL, &ctx); if (!info) return -ENOMEM; @@ -192,6 +193,10 @@ static int kunit_uapi_run_executable(struct kunit *tes= t, const struct kunit_uapi if (err) return err; =20 + err =3D kunit_uapi_write_executable(mnt, &kunit_uapi_preinit); + if (err) + return err; + err =3D kunit_uapi_run_executable_in_mount(test, executable, mnt); if (err) return err; diff --git a/lib/kunit/uapi-preinit.c b/lib/kunit/uapi-preinit.c new file mode 100644 index 000000000000..686737ea3c76 --- /dev/null +++ b/lib/kunit/uapi-preinit.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace environment setup. + * + * Copyright (C) 2026, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + * + * This is *userspace* code. + */ + +#include +#include + +#include "../../tools/testing/selftests/kselftest.h" + +#define KUNIT_UAPI_CHDIR_FD 3 + +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 fchdir(KUNIT_UAPI_CHDIR_FD); + close(KUNIT_UAPI_CHDIR_FD); + if (ret) + exit_failure("fchdir", 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); + + ret =3D setup_api_mount("/dev", "devtmpfs"); + if (ret) + exit_failure("mount /dev", ret); + + ret =3D execve(argv[0], argv, envp); + if (ret) + exit_failure("execve", ret); + + return 0; +} --=20 2.53.0 From nobody Mon May 4 13:06:51 2026 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 6228037D135; Mon, 4 May 2026 09:33:41 +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=1777887223; cv=none; b=tb+d3bLBjF2jVzNJOkQPjV1X8Wfs8Kcw0djL7cpJ2IeeQt+JnQ8NGBMfzzuLFBdlCodh7stDe51eLd+oIZkCzvNNwc+k1Mdhcr8Tg5N34/XPsLaZJsLflBOiYzpFCmM4JwFsbgy3bXyhN64Po8dbx8xEzk/uAsDi4JwJZ7jUuls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777887223; c=relaxed/simple; bh=TauxOYpi03qFPcnNm3AqoC889sKpf9SoQTyDHbRy9hg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VTBduZgBvyQPeQEKPVLv/odn6e1LPk5SLHgem3w+hguTnflS3SNEQaSAgfZUh7QK5AqIQ7Tvjk8BKERPP/Rt6erJWpiyS/MRCBrawhHEiVdOsRLCGb2XXXymXbEQ+VuzsRbgv0C5GYo69+WSJAZl/GzaQtF0wr2wafzcsfnWYfo= 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=BqTtpk+C; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZanvYVfs; 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="BqTtpk+C"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZanvYVfs" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777887220; 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=PrS0k2Drv80OdaJ1YmUo8BOgCdISFvzkHUaFnv4iGkM=; b=BqTtpk+CXBSv6WfgRGnKdP1smf/6qR/nWC5fL4wYSSvJxXy7s4NFkunXA3qfZLfKUsavGv +wWq9EV1hah3Ei3nPcAx79AIcSZ3TyR/mBlC1+p00FxtQ5KObA4ZCuFlDx85ejGxU7UuiJ hdLrvogkSvos2xghKe2i5Zg0/+3dTwMhgb/xDUIQfGz/hiBploTjsyScRo9K3Lp063ksFZ KzgVsVr3Wz1txl6BZ4AYTQWPMD8nC9S9mrHhWkoN7NIsQukE0LAQCDjOiPaHKUWEQNa4HQ +4ImbazmNQDpitSLHA2xSNSI6H6qGMn2BzEBX84vIbkUnsWP6iIGtvp6ILTFkw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777887220; 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=PrS0k2Drv80OdaJ1YmUo8BOgCdISFvzkHUaFnv4iGkM=; b=ZanvYVfsjTNqFNMSVnatHHJiQ1Hha7pnJ5tAY/2b8uIVYGIg3BEt/sK+UwR+ADsManbVrj jvpfybI/ZMvglgCw== Date: Mon, 04 May 2026 11:33:27 +0200 Subject: [PATCH v6 11/11] 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: <20260504-kunit-kselftests-v6-11-712d3d526d97@linutronix.de> References: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de> To: Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , Shuah Khan , Jonathan Corbet , Nicolas Schier , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Christoph Hellwig , Luis Chamberlain , David Gow , Rae Moar Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, workflows@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christophe Leroy , Nicolas Schier X-Developer-Signature: v=1; a=ed25519-sha256; t=1777887211; l=4066; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=TauxOYpi03qFPcnNm3AqoC889sKpf9SoQTyDHbRy9hg=; b=1hWzT6507OnOzELkr3kP6C8GS+SfvKLQdLpAiBvyOpYn0JryvJmarJBk+xXRskvu55bxKdheG G3cv2zqewfuCaw+z7LMh9TYx3Tv2oeaAUW9Qr91SEgKS00S4V/4Fr0G X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Show that the selftests are executed from a fairly "normal" userspace context. Signed-off-by: Thomas Wei=C3=9Fschuh --- MAINTAINERS | 1 + lib/kunit/Makefile | 9 ++++++++ lib/kunit/kunit-test-uapi.c | 51 +++++++++++++++++++++++++++++++++++++++++= ++++ lib/kunit/kunit-test.c | 24 ++++++++++++++++++++- 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 4e8cf9fa7aa9..693aafe4d3f9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14400,6 +14400,7 @@ M: Thomas Wei=C3=9Fschuh S: Maintained F: include/kunit/uapi.h F: lib/kunit/kunit-example-uapi.c +F: lib/kunit/kunit-test-uapi.c F: lib/kunit/kunit-uapi.c F: lib/kunit/uapi-preinit.c =20 diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 05991d69aa70..1a4af6b66524 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -29,6 +29,15 @@ endif obj-$(if $(CONFIG_KUNIT),y) +=3D hooks.o =20 obj-$(CONFIG_KUNIT_TEST) +=3D kunit-test.o + +userprogs +=3D kunit-test-uapi +kunit-test-uapi-userccflags :=3D -static $(NOLIBC_USERCFLAGS) + +ifdef CONFIG_KUNIT_UAPI +CFLAGS_kunit-test.o :=3D -Wa,-I$(obj) +$(obj)/kunit-test.o: $(obj)/kunit-test-uapi +endif + obj-$(CONFIG_KUNIT_TEST) +=3D platform-test.o =20 # string-stream-test compiles built-in only. diff --git a/lib/kunit/kunit-test-uapi.c b/lib/kunit/kunit-test-uapi.c new file mode 100644 index 000000000000..2e75e57865e3 --- /dev/null +++ b/lib/kunit/kunit-test-uapi.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace selftest. + * + * Copyright (C) 2026, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + * + * This is *userspace* code. + */ + +#include +#include +#include + +#include "../../tools/testing/selftests/kselftest.h" + +static void test_procfs(void) +{ + char buf[256]; + ssize_t r; + int fd; + + fd =3D open("/proc/self/comm", O_RDONLY); + if (fd =3D=3D -1) { + ksft_test_result_fail("procfs: open() failed: %s\n", strerror(errno)); + return; + } + + r =3D read(fd, buf, sizeof(buf)); + close(fd); + + if (r =3D=3D -1) { + ksft_test_result_fail("procfs: read() failed: %s\n", strerror(errno)); + return; + } + + if (r !=3D 16 || strncmp("kunit-test-uapi\n", buf, 16) !=3D 0) { + ksft_test_result_fail("procfs: incorrect comm\n"); + return; + } + + ksft_test_result_pass("procfs\n"); +} + +int main(void) +{ + ksft_print_header(); + ksft_set_plan(1); + test_procfs(); + ksft_finished(); +} diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c index 126e30879dad..b62e24fb9c55 100644 --- a/lib/kunit/kunit-test.c +++ b/lib/kunit/kunit-test.c @@ -9,6 +9,7 @@ #include #include #include +#include =20 #include #include @@ -914,10 +915,31 @@ static struct kunit_suite kunit_stub_test_suite =3D { .test_cases =3D kunit_stub_test_cases, }; =20 +static void kunit_uapi_test(struct kunit *test) +{ + KUNIT_UAPI_EMBED_BLOB(kunit_test_uapi, "kunit-test-uapi"); + + if (IS_ENABLED(CONFIG_KUNIT_UAPI)) + kunit_uapi_run_kselftest(test, &kunit_test_uapi); + else + kunit_skip(test, "CONFIG_KUNIT_UAPI is not enabled"); +} + +static struct kunit_case kunit_uapi_test_cases[] =3D { + KUNIT_CASE(kunit_uapi_test), + {} +}; + +static struct kunit_suite kunit_uapi_test_suite =3D { + .name =3D "kunit_uapi", + .test_cases =3D kunit_uapi_test_cases, +}; + kunit_test_suites(&kunit_try_catch_test_suite, &kunit_resource_test_suite, &kunit_log_test_suite, &kunit_status_test_suite, &kunit_current_test_suite, &kunit_device_test_suite, - &kunit_fault_test_suite, &kunit_stub_test_suite); + &kunit_fault_test_suite, &kunit_stub_test_suite, + &kunit_uapi_test_suite); =20 MODULE_DESCRIPTION("KUnit test for core test infrastructure"); MODULE_LICENSE("GPL v2"); --=20 2.53.0