Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3191862lqp; Tue, 26 Mar 2024 02:10:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX8mL1w9uyX9oeMJG8TW+8QaKnLJkWIoEwOp5NIxPQAwcskwODu4MbT9K0S5XL7a0BV14wKByz4+wxjJPxI5+ypeKFHvMFRXE6+d3Aubw== X-Google-Smtp-Source: AGHT+IFBWSCDFPJyf3BEYK97f58RYTz5P6xQCN6mLaxqcnq14VtrtheMoxB2wHMwVwzY14OYpJoT X-Received: by 2002:ad4:5ce8:0:b0:696:8234:3ab with SMTP id iv8-20020ad45ce8000000b00696823403abmr8503479qvb.49.1711444251514; Tue, 26 Mar 2024 02:10:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711444251; cv=pass; d=google.com; s=arc-20160816; b=UPUeXwwNQGaHm8PLfpfQI30BJszncgaV/YZuzuHjKMxH+TxfafVK5s1kxu1H83fpxy 9j3ebUD1cGhsZNS7+R3GTHDjtvLJAZZ4UBBmF+5tFvsXCsePLV0y6WrQU1JzL0s+Vhlv xEtRhXx4imFP26q7t0kJIkeysh4UKCh3YQc3t2VUrCFq+mAWaiqAzcNLt/Dt4XE4jDVf CLggJBCkAsWMKfbq48vZvmp2DQnnSotv+E6xHU0wHiOg9mg7r6MYGegF2pJI7W4gd1s+ QRwqH1MgY0XqbIHYZpyUNEWHkV/kLC1mdCVuUo99gKXdCJz8np16XbWLpwHeJCDWGvDz MTjA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=tNTqP3K72+F1EfoVulbDP4WkzmaEQwdJwakQorN2vx0=; fh=rEsItEcbaioYphRG1xf00v1zvarJyV1L+67R9XfXZao=; b=VK1S4yQEQy/p7XDKHqGm+n7vwyVR6tt6TYyG/AiPNYv3io1rlIJ3ZtAsbKT2hF75di XkUsVnLzQiw7BBOztKRA6G+2OKlJpjAnUQuBl3Jy3DVEg78ZUg0N8UjnmB5ojn61Jhk9 Lf+wz448Uv9rVY07yMDaMSAGF6VS3pVm7ViOkp1bAP4aRGheKusiuhvk2wCx/bgZ3N75 ia975L2maYbfPOrZGhj/EyjURKFsFqKA/U5NWFIHWbH++F/LenfokRoCCTGKAy29ox/d /QkVcX27C2gZZUwZoOqyy2i+JWalIrHpVe5hDFK7cR0lNmOV4Pir2e8dUrpU2akb2jXz PZrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=IZBmrADh; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-118618-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118618-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c28-20020a05620a269c00b0078a581453c0si3949507qkp.410.2024.03.26.02.10.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 02:10:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118618-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=IZBmrADh; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-118618-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118618-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 16E471C2E615 for ; Tue, 26 Mar 2024 09:10:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F2564597A; Tue, 26 Mar 2024 09:10:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="IZBmrADh" Received: from smtp-42af.mail.infomaniak.ch (smtp-42af.mail.infomaniak.ch [84.16.66.175]) (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 A44A345978 for ; Tue, 26 Mar 2024 09:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=84.16.66.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711444245; cv=none; b=O9BxYZBPaF1HWdRA5npGzvP6JD2yFui67bY/hvj6PR+F4lv7CxlG4qFbw/VClEJ2K9BBJVgDM7aBnv+0RIITu66s9CT7Jq18h7pruBMVsGXfM0V/cLX214VutlhdZ1ziu6yoLBhkFR4M3C6ZftHxcIF2R7A3irnuNqh/oiCNwIo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711444245; c=relaxed/simple; bh=aG1FdaTbcKd3XGgGWnmx/xvaQsHHK4Rz/c5f2D3Q9m0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fDhYFROVJpA6jWVcPBwTkWj3CFpLq7hkvAL3toFqLDsyBLbivHKj5B++O2VT/1G5/lVu8R+CtLl8TFvXVRqQS3yhVe5KKGa3gRIfYIEex/7SYei8c/OdQEZ8Dg4K4mi/MOOIJdkVNGzsGOyxFHjYkEWmcTz6PmhkZUuGgUCzG1U= 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=IZBmrADh; arc=none smtp.client-ip=84.16.66.175 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-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4V3kNF53NkzZBV; Tue, 26 Mar 2024 10:02:53 +0100 (CET) Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4V3kND05yKzMppKc; Tue, 26 Mar 2024 10:02:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1711443773; bh=aG1FdaTbcKd3XGgGWnmx/xvaQsHHK4Rz/c5f2D3Q9m0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IZBmrADhOaPt+S5+Ai5jbfmQE6NDEfhlQ7oPI5KvdxY6OFxpZqdyc/bT9FtkXBfR6 aF4p1CvP1HyDpI7noNPncdLGg4YV1hCzZZ9kkE16vyFVLnQKlUCxqBlsP+0Vj3fgyL h1vzPtWDDxEvqYWWo+GxoH+jFFPSjPNKofKIbZeA= Date: Tue, 26 Mar 2024 10:02:51 +0100 From: =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= To: David Gow Cc: Brendan Higgins , Rae Moar , Shuah Khan , Alan Maguire , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Ingo Molnar , James Morris , Kees Cook , Luis Chamberlain , "Madhavan T . Venkataraman" , Marco Pagani , Paolo Bonzini , Sean Christopherson , Stephen Boyd , Thara Gopinath , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Zahra Tarkhani , kvm@vger.kernel.org, linux-hardening@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org Subject: Re: [PATCH v3 4/7] kunit: Handle test faults Message-ID: <20240326.ieB8Phit1Ob8@digikod.net> References: <20240319104857.70783-1-mic@digikod.net> <20240319104857.70783-5-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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Infomaniak-Routing: alpha On Sat, Mar 23, 2024 at 03:37:21PM +0800, David Gow wrote: > On Tue, 19 Mar 2024 at 18:49, Mickaël Salaün wrote: > > > > Previously, when a kernel test thread crashed (e.g. NULL pointer > > dereference, general protection fault), the KUnit test hanged for 30 > > seconds and exited with a timeout error. > > > > Fix this issue by waiting on task_struct->vfork_done instead of the > > custom kunit_try_catch.try_completion, and track the execution state by > > initially setting try_result with -EINTR and only setting it to 0 if > > the test passed. > > > > Fix kunit_generic_run_threadfn_adapter() signature by returning 0 > > instead of calling kthread_complete_and_exit(). Because thread's exit > > code is never checked, always set it to 0 to make it clear. > > > > Fix the -EINTR error message, which couldn't be reached until now. > > > > This is tested with a following patch. > > > > Cc: Brendan Higgins > > Cc: Shuah Khan > > Reviewed-by: Kees Cook > > Reviewed-by: David Gow > > Tested-by: Rae Moar > > Signed-off-by: Mickaël Salaün > > Link: https://lore.kernel.org/r/20240319104857.70783-5-mic@digikod.net > > --- > > > > Changes since v2: > > * s/-EFAULT/-EINTR/ in commit message as spotted by Rae. > > * Add a comment explaining vfork_done as suggested by David. > > * Add David's Reviewed-by. > > * Add Rae's Tested-by. > > > > Changes since v1: > > * Add Kees's Reviewed-by. > > --- > > include/kunit/try-catch.h | 3 --- > > lib/kunit/try-catch.c | 19 ++++++++++++------- > > 2 files changed, 12 insertions(+), 10 deletions(-) > > > > diff --git a/include/kunit/try-catch.h b/include/kunit/try-catch.h > > index c507dd43119d..7c966a1adbd3 100644 > > --- a/include/kunit/try-catch.h > > +++ b/include/kunit/try-catch.h > > @@ -14,13 +14,11 @@ > > > > typedef void (*kunit_try_catch_func_t)(void *); > > > > -struct completion; > > struct kunit; > > > > /** > > * struct kunit_try_catch - provides a generic way to run code which might fail. > > * @test: The test case that is currently being executed. > > - * @try_completion: Completion that the control thread waits on while test runs. > > * @try_result: Contains any errno obtained while running test case. > > * @try: The function, the test case, to attempt to run. > > * @catch: The function called if @try bails out. > > @@ -46,7 +44,6 @@ struct kunit; > > struct kunit_try_catch { > > /* private: internal use only. */ > > struct kunit *test; > > - struct completion *try_completion; > > int try_result; > > kunit_try_catch_func_t try; > > kunit_try_catch_func_t catch; > > diff --git a/lib/kunit/try-catch.c b/lib/kunit/try-catch.c > > index cab8b24b5d5a..7a3910dd78a6 100644 > > --- a/lib/kunit/try-catch.c > > +++ b/lib/kunit/try-catch.c > > @@ -18,7 +18,7 @@ > > void __noreturn kunit_try_catch_throw(struct kunit_try_catch *try_catch) > > { > > try_catch->try_result = -EFAULT; > > - kthread_complete_and_exit(try_catch->try_completion, -EFAULT); > > + kthread_exit(0); > > It turns out kthread_exit() is not exported, so this doesn't work if > KUnit is built as a module. > > I think the options we have are: > - Add EXPORT_SYMBOL(kthread_exit). I'll go this way. This should not be an issue because kthread_complete_and_exit() can already (only) call kthread_exit() if the completion is NULL, but directly calling kthread_exit() is cleaner. > - Keep using out own completion, and kthread_complete_and_exit() > - try_get_module() before spawning the thread, and use > module_put_and_kthread_exit(). > > I think all of these would be okay, but I could've missed something. > > -- David