Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1373839lqa; Mon, 29 Apr 2024 06:58:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVpLJ+jFV76s9C4bug6yqtmHrYye1VhV8nKYzkFVyJwR4mKG4tSoqpHhmRhy9ICjV9mq8SR+9yde0Fo7iqSyvxhQCQwOatEEn1sMcgTHQ== X-Google-Smtp-Source: AGHT+IE/2qPp8BiVftHatlUanwLaHYHtUkxJv0PZphz5dqSM8n6p1hLs/JdachUVlgv/0EUwWjLr X-Received: by 2002:a17:902:680e:b0:1e2:7734:63dd with SMTP id h14-20020a170902680e00b001e2773463ddmr8746324plk.30.1714399137607; Mon, 29 Apr 2024 06:58:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714399137; cv=pass; d=google.com; s=arc-20160816; b=biFopHsjy+J5LITSJHQgBLzRgrbt54A4REBDjob8DOU+VWqIBkhrCOLBnjVBlMADRC qLx3vurxPBeuaNaX6+NaJjsdrnJ3fgy4+DYi1uQKMohVXrKMXW7m9+9lh0rxey6OKhRV GeOc5TkeiyLa6PJojOEWJ//Mj41e1jMCREdSIamx0fKLVbsO3/vAutqcUhfjygYiAGN+ R1m5BpKeIsfp68EyANLB+cwC6p7LtBg73gVpHoI5gxcdqwSBb9hy+c7P288BxAPfTHAq EvVx5FpB5tnTrwUywWSOG0+uNK85udwNZNn0JbZyQkhBl0RMwy6bycuKRHl+UVBnmUf3 Rung== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DqLMuuRQ0WCzmVx2TfcAuOmXJzofGIraBFsxcXJU4w8=; fh=g9UCkqlorEMA7uOOhHTqzi37EO3wzdGiXjygRVd3D9o=; b=LJyKClH2AY85e8DMezJcc9ncgWGqyEhwjeKyp57/pOAJaY3pbIfi14S8V249JQVaqX vIq4d1FaEbG5WE2vZ0UFDhc2QZl9ZYcnO8bRPIJZofaJvi+JV4IOAOah7zjbN8cx8X95 +N4YUNjr5HnhgHg9y0YKfjO7XqAVlvXgbLI02xkV+JIB0wqrJYXJ5OX60A88MMuzHHIN e0Uu2GfNT5n2NuuMi2k9xq57r1AhYHeUhsrN2HxtNrc+D9mj44sZEGAzaewejiO03Bfc 61G/xJuHxeExAtde5IyKrC+n07lPJtek6gNHeTLwoW1xAZTGi28YS/V8RV0LEtLZElRO BhWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=Ri+4v2kP; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-162335-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162335-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id k3-20020a170902d58300b001eb5179b2c0si4325895plh.236.2024.04.29.06.58.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 06:58:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162335-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=Ri+4v2kP; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-162335-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162335-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 40584B24B4B for ; Mon, 29 Apr 2024 13:11:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83FC07BB11; Mon, 29 Apr 2024 13:09:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="Ri+4v2kP" Received: from smtp-bc0c.mail.infomaniak.ch (smtp-bc0c.mail.infomaniak.ch [45.157.188.12]) (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 6E57256B86 for ; Mon, 29 Apr 2024 13:09:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.157.188.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714396192; cv=none; b=TnCCsxKo/gc9OgMXzN1ZQpGCMX0g7IhtIOOW2T2FOscVejxW3/9OlSJrM6cOkKPyScJM1sSAtLhmvf+HztvOJbSAuQTIdHGv/jTyTB1k4BgrVTTxfxV7QwFkcIgdK1huywsMi9Lcy4hxCkJmDxPeQLXSjfEb0bIeiK1rQl0GwXo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714396192; c=relaxed/simple; bh=5ijisjBDjCgm+yNyZSUs5CJ6Yk0uBfxDT6TyioOcnpc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N7cDFYsg4sH8dtgsA054Xv14BVnKshk8dja9gOTjHVTz8jBCL0dsFpMcE3GTITLL7chpY/GRgr5+brTDXy0N9tb/bv6wvkxBH+nZ9c17zN2O2IB/6H1ZYXZgogJaQETHduhU7IlwhPCo+h67f75wdTKb4KNkZSK39sLocXaUMYg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b=Ri+4v2kP; arc=none smtp.client-ip=45.157.188.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Received: from smtp-3-0001.mail.infomaniak.ch (smtp-3-0001.mail.infomaniak.ch [10.4.36.108]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4VSkFL2r7kzQNK; Mon, 29 Apr 2024 15:09:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1714396182; bh=5ijisjBDjCgm+yNyZSUs5CJ6Yk0uBfxDT6TyioOcnpc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ri+4v2kPb8gskcXREStZJudgEjfjgC/yTNzCP8xeqCpJjvmseWbxrwCoiQ08i65Br YgYL4PijZ36BBK7x8O6go4eOKd7o5goKRfWTFQGK8f4FCUU09tDoh1y4uv0t5pix0R d7I4L7KvipDtLb97YxUHSAeNjDhK/kCgenvcvejQ= Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4VSkFK6Xc1zhld; Mon, 29 Apr 2024 15:09:41 +0200 (CEST) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: Christian Brauner , Jakub Kicinski , Kees Cook , Mark Brown , Shengyu Li , Shuah Khan Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , "David S . Miller" , =?UTF-8?q?G=C3=BCnther=20Noack?= , Will Drewry , kernel test robot , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 4/9] selftests/harness: Fix interleaved scheduling leading to race conditions Date: Mon, 29 Apr 2024 15:09:26 +0200 Message-ID: <20240429130931.2394118-5-mic@digikod.net> In-Reply-To: <20240429130931.2394118-1-mic@digikod.net> References: <20240429130931.2394118-1-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Infomaniak-Routing: alpha Fix a race condition when running several FIXTURE_TEARDOWN() managing the same resource. This fixes a race condition in the Landlock file system tests when creating or unmounting the same directory. Using clone3() with CLONE_VFORK guarantees that the child and grandchild test processes are sequentially scheduled. This is implemented with a new clone3_vfork() helper replacing the fork() call. This avoids triggering this error in __wait_for_test(): Test ended in some other way [127] Cc: Christian Brauner Cc: David S. Miller Cc: Günther Noack Cc: Jakub Kicinski Cc: Kees Cook Cc: Mark Brown Cc: Shuah Khan Cc: Will Drewry Fixes: 41cca0542d7c ("selftests/harness: Fix TEST_F()'s vfork handling") Signed-off-by: Mickaël Salaün Link: https://lore.kernel.org/r/20240429130931.2394118-5-mic@digikod.net --- tools/testing/selftests/kselftest_harness.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 55699a762c45..9f04638707ae 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -66,6 +66,8 @@ #include #include #include +#include +#include #include "kselftest.h" @@ -80,6 +82,17 @@ # define TH_LOG_ENABLED 1 #endif +/* Wait for the child process to end but without sharing memory mapping. */ +static pid_t __attribute__((__unused__)) clone3_vfork(void) +{ + struct clone_args args = { + .flags = CLONE_VFORK, + .exit_signal = SIGCHLD, + }; + + return syscall(__NR_clone3, &args, sizeof(args)); +} + /** * TH_LOG() * @@ -1183,7 +1196,7 @@ void __run_test(struct __fixture_metadata *f, fflush(stdout); fflush(stderr); - t->pid = fork(); + t->pid = clone3_vfork(); if (t->pid < 0) { ksft_print_msg("ERROR SPAWNING TEST CHILD\n"); t->exit_code = KSFT_FAIL; -- 2.44.0