From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD54EC36010 for ; Mon, 7 Apr 2025 19:02:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iI4bH/HSRPcYTotIIE5PQ35iIB8Ii1vOuyCkkepPDvU=; b=X1m0OpeIEijY4XKDDDO2F+ZdB8 qNMQPuUoyIiQ+eN5vVGXzR4zx+Hc+1FywMYsPBQXEdlivGdOfDk9eP9LcjOzPR6XKMKHuK6PuxgWW NESbS08+oz9m43tO6WE/oDb+sjBdyQdtdtIsAy/UEg5uE/nLme4ne+lJBT+qiH4M2DXdJ+9OwYI1u LtXXISerG8YBebSqchbowIjru8hQbp9ktlTng8xVQQ85BaDfEy4fqZpa+++n42yn1vjh3Y7z+snAq pGhNg0oFZK0L6swynLSbIbRZANXEEsWDix7uirx4ox7VrBzv6TT+4BBc8q18l0pOso3h51oOKAgzA wd0hyW7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1rjp-00000001jol-1sfp; Mon, 07 Apr 2025 19:02:29 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1qy1-00000001ULu-1A21 for linux-um@lists.infradead.org; Mon, 07 Apr 2025 18:13:05 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 1713E6116D; Mon, 7 Apr 2025 18:12:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48086C4CEE7; Mon, 7 Apr 2025 18:13:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744049584; bh=uQ9BX1Anrr185nCbF9o0UfRIAVFd3yOMLRqLKUlV05E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T1sX4potPTI7HZrXPCd5Ui4xcRonUZeG51HprKyemTHXeQKIEFEhsX9IBg2/YP7FO umkphAMRY6sULYiHwKx5HvUVi3Fy0nOYLRjIBv8hihdR72RZzhn92HHHlweYtxiB20 BP6+TjaqxOQPhi880gk+2tRpAjYWjY/cC7ALk1DnBspJTuvDHc8xqnde0kgVSBfF6m fUg/Tf1w41nt3el+0mOiCnJJas1zNNb9pwcam19rhlXiywNDp5YHCvStYfCBFQnhcP G9uNLvk0SoN/FqcSXWPVB7cwd/3a/tMQTg3JUQs4zoV41NQf1ZceLscqY9rePZ83BP 7wp/piX6aFgeA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Benjamin Berg , Johannes Berg , Sasha Levin , richard@nod.at, anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net, linux-um@lists.infradead.org Subject: [PATCH AUTOSEL 6.13 20/28] um: work around sched_yield not yielding in time-travel mode Date: Mon, 7 Apr 2025 14:12:10 -0400 Message-Id: <20250407181224.3180941-20-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250407181224.3180941-1-sashal@kernel.org> References: <20250407181224.3180941-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.13.10 Content-Transfer-Encoding: 8bit X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+linux-um=archiver.kernel.org@lists.infradead.org From: Benjamin Berg [ Upstream commit 887c5c12e80c8424bd471122d2e8b6b462e12874 ] sched_yield by a userspace may not actually cause scheduling in time-travel mode as no time has passed. In the case seen it appears to be a badly implemented userspace spinlock in ASAN. Unfortunately, with time-travel it causes an extreme slowdown or even deadlock depending on the kernel configuration (CONFIG_UML_MAX_USERSPACE_ITERATIONS). Work around it by accounting time to the process whenever it executes a sched_yield syscall. Signed-off-by: Benjamin Berg Link: https://patch.msgid.link/20250314130815.226872-1-benjamin@sipsolutions.net Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- arch/um/include/linux/time-internal.h | 2 ++ arch/um/kernel/skas/syscall.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/arch/um/include/linux/time-internal.h b/arch/um/include/linux/time-internal.h index b22226634ff60..138908b999d76 100644 --- a/arch/um/include/linux/time-internal.h +++ b/arch/um/include/linux/time-internal.h @@ -83,6 +83,8 @@ extern void time_travel_not_configured(void); #define time_travel_del_event(...) time_travel_not_configured() #endif /* CONFIG_UML_TIME_TRAVEL_SUPPORT */ +extern unsigned long tt_extra_sched_jiffies; + /* * Without CONFIG_UML_TIME_TRAVEL_SUPPORT this is a linker error if used, * which is intentional since we really shouldn't link it in that case. diff --git a/arch/um/kernel/skas/syscall.c b/arch/um/kernel/skas/syscall.c index b09e85279d2b8..a5beaea2967ec 100644 --- a/arch/um/kernel/skas/syscall.c +++ b/arch/um/kernel/skas/syscall.c @@ -31,6 +31,17 @@ void handle_syscall(struct uml_pt_regs *r) goto out; syscall = UPT_SYSCALL_NR(r); + + /* + * If no time passes, then sched_yield may not actually yield, causing + * broken spinlock implementations in userspace (ASAN) to hang for long + * periods of time. + */ + if ((time_travel_mode == TT_MODE_INFCPU || + time_travel_mode == TT_MODE_EXTERNAL) && + syscall == __NR_sched_yield) + tt_extra_sched_jiffies += 1; + if (syscall >= 0 && syscall < __NR_syscalls) { unsigned long ret = EXECUTE_SYSCALL(syscall, regs); -- 2.39.5