Received: by 2002:ab2:1c04:0:b0:1f7:53ba:1ebe with SMTP id f4csp138573lqg; Fri, 26 Apr 2024 10:51:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUrJ6p/QB3avR1e1UBL6+rgPh2qzi5kHQCEUovI33hn3oJ0lbEHYMb+8EPu+NU/HgaT6hI9U7vZvzTHkthbzxR5gbpuwUcLYf5olvhzeg== X-Google-Smtp-Source: AGHT+IF8OkNUlz1/1Sz5+pWr6gjQ8mI2Qeq5GWMIZBaxdvlI4P2ahWSV1keIvyJlK3Y77BtE7BEj X-Received: by 2002:a05:6a20:9189:b0:1a7:186:f976 with SMTP id v9-20020a056a20918900b001a70186f976mr4315647pzd.40.1714153878643; Fri, 26 Apr 2024 10:51:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714153878; cv=pass; d=google.com; s=arc-20160816; b=spE7kkcH7aLyJXvsWNN+2szH0sj1XE5XulQj+7GN/5saBOmbCHyI1sCneuhBX7GvY0 HMX/z2d5yOtfU7xxUrnyn3IU/Be/cnYVVvavBHSwHvtoLjGSqxWnuIpouS0NSVHNAiIm XqDguDCQST3/TJLc46pGPIkiPU+Fa0oWlpVoxPsEVf6p+vLfmoQURRw2aPHwZNymdePW vrvvPwI9tvwBd4ouAe16YTx4975hOgkyuu6dJ7BJIBQ3OBuVz6BSTEdk37pFcSZg+Sj6 zEoXkCQ9x1tUHBeVS3DYG7e8kmaO+aTUAle4VGQIqH1JYYNPKXJRsvAAlOl5uZUkim6v VDTg== 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=w5ZDeZTXSmOaaQXGTf4DCxlMsT1Dk6mcgYrNJWWFkHU=; fh=g9UCkqlorEMA7uOOhHTqzi37EO3wzdGiXjygRVd3D9o=; b=j5ugVvTq9TKjxto8CoIso2MVoFrerVxmTESpssbPpLVA6f6ESuF4n/e26qNuqjNXDr z2jM8V5yyL730Jhp8gojqWYOmH6746EE90YTMKViSfWgMnQvinWSGw3yGtfPIPCmlevM V6mnaZpgahjjDSMOfVJqhu1attrkUK5cqcSj6r10fPczsW365L5wFlEGqjvDsYuL5ns0 9NllU7zPVQWUxJJHKPe7ipSyiVPLTalseRYMiZFN5D0xO2wdtYPnwz0+1RAEu564hY+1 k22j2xccUsR/t3N7fg1fQwmu8D9YzgS7LTfUuMYkB6210h4DdXspmNXsaH1EcKXTCSP8 JujA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b="Alc/Ff+z"; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-160510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160510-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id kp7-20020a056a00464700b006ece3da5268si15648194pfb.391.2024.04.26.10.51.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 10:51:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b="Alc/Ff+z"; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-160510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160510-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 AE834B22F54 for ; Fri, 26 Apr 2024 17:40:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3517315ECD3; Fri, 26 Apr 2024 17:40:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="Alc/Ff+z" Received: from smtp-8fa8.mail.infomaniak.ch (smtp-8fa8.mail.infomaniak.ch [83.166.143.168]) (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 F29C01DDF8 for ; Fri, 26 Apr 2024 17:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.166.143.168 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714153248; cv=none; b=uxP954Ux7PeIUmhu/695WScww4yBGIn5cP++5pNUENfv9XoYcrSRKfss1xIhCoMRuAtemK9yPSHJ92xu07OFh6NoCz7mKiY/WbwWIaihuVrWfVFJ9POFq6rtNoPQ3XfOIpRobT86uVFzgPHZL/jv3UXvxEnUI7nnZBvZuMCtOjw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714153248; c=relaxed/simple; bh=CQBiIeVTKBpDd91iYuqIIzq3XnC8Q4yWuXaprTtqOFQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IhRLQdS2beLrgx6Mw9YGAPbrRJGWORMPy1tjIi14gDp3ErwSVpr8z8bUnIP9VoN09LKrKLfLEBPFka0z1BeRZwqronJjZWm7O1qHMzJjga1CI0X2Cev8oXwdH7r4IasmFEJMk/w1pAFAoq1Q+9/+SDYz7h/u9G46I+EaXcCawTY= 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=Alc/Ff+z; arc=none smtp.client-ip=83.166.143.168 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-0000.mail.infomaniak.ch (smtp-3-0000.mail.infomaniak.ch [10.4.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4VR0184XrKzXZt; Fri, 26 Apr 2024 19:23:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1714152188; bh=CQBiIeVTKBpDd91iYuqIIzq3XnC8Q4yWuXaprTtqOFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Alc/Ff+zUYtVfEFUxhg2vFb0uqi/XpKcMtiYKj4YgB1ib4V5/Gn7UNS6e2YElnRB6 E6OHfBsMEwtyMjvV3Skj5ZboRIibBCXgaF7IAA6PRVLnnUbGANaSXTa18se2aVVlL1 r1F5gksDlqVRyUnqobnTpbMn9RPIu/B8E8B5BVRg= Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4VR0180Yq0zgR1; Fri, 26 Apr 2024 19:23:08 +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 v1 4/5] selftests/harness: Fix interleaved scheduling leading to race conditions Date: Fri, 26 Apr 2024 19:22:51 +0200 Message-ID: <20240426172252.1862930-5-mic@digikod.net> In-Reply-To: <20240426172252.1862930-1-mic@digikod.net> References: <20240426172252.1862930-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/20240426172252.1862930-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 73491efbae9e..d2dd246a3843 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -67,6 +67,8 @@ #include #include #include +#include +#include #include "kselftest.h" @@ -81,6 +83,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() * @@ -1180,7 +1193,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