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 91537C36018 for ; Mon, 7 Apr 2025 19:02:06 +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=Odf4Ddk1ak3Z8BBw/cVBJ2e/0hHw2GU4Sp3rBfDN88A=; b=BVBEsmEivY1xanbYNLwgzUayVa Hyra0D8tCg8HALYWuS/yWk4zxOKtYWS0/PwYNuQzgF2Z3tU4zbW87Rgwsk2QXa8venDuryOsHM1uL q2rStjFePVJSlCaXzf5jJ6nPBlBF5IUb+Sm2Zs5tGWV/HMyOwXSfVJE+8lWxOq/2PzD/Tgr/9/XDg HbvPJbxmFKufRFPjDFzDKBde14muhShn9GGO2dLzrNjsTqsQaZIG4QOPThigRdK0w+R9i4ggz+7ko Qo5S3kI8PwpSYJsP6n7LoKPb2+5QsgsO6NqV29BPFhpAWWkkVchhYQsDU7kM+FtOrWextSNF4j6XU FdihgAkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1rjS-00000001jhH-0900; Mon, 07 Apr 2025 19:02:06 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1qwy-00000001U6O-3GM0 for linux-um@lists.infradead.org; Mon, 07 Apr 2025 18:12:02 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1486B5C561A; Mon, 7 Apr 2025 18:09:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC00FC4CEDD; Mon, 7 Apr 2025 18:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744049519; bh=gU6hkKGDdvk7K7dSuye72CQjJX8W0AKAn4D7NbahrSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XH5rZBW6srTSd+yJvhIe3cLRB8CQS9m9lhRenOm0atgLI2MKNEKO4g9bQOGgtLZON mRhj3du3m+Py3okBA+cmDBMxt9lOOKEvZUdtagsUPROZie3Lu9P0srNFiuQm3N2/PR CYiSUMkcO8koB6yUNejYRIt0qFNWwqseeR8BtTDR7ChBz/k+UO68CrK/+KRO2c8Xnu Fl7WEApgITIvR8kZD+T4YLSAU3qUAjVDfdwOyUEGiju855+xlfN/OlrER75QUUQDVc fJxNicHVn2hwdqO8lNb3koRredYgpBLZAUSzkZtqPz0ptqeEEcYT+PoJb9wE7XfE3A Q1A8dTqE29D5Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tiwei Bie , Johannes Berg , Sasha Levin , richard@nod.at, anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net, linux-um@lists.infradead.org Subject: [PATCH AUTOSEL 6.14 25/31] um: Switch to the pthread-based helper in sigio workaround Date: Mon, 7 Apr 2025 14:10:41 -0400 Message-Id: <20250407181054.3177479-25-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250407181054.3177479-1-sashal@kernel.org> References: <20250407181054.3177479-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.14.1 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250407_111200_930952_99077E5B X-CRM114-Status: GOOD ( 18.34 ) 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: Tiwei Bie [ Upstream commit d295beeed2552a987796d627ba7d0985b1e2d72f ] The write_sigio thread and UML kernel thread share the same errno, which can lead to conflicts when both call syscalls concurrently. Switch to the pthread-based helper to address this issue. Signed-off-by: Tiwei Bie Link: https://patch.msgid.link/20250319135523.97050-4-tiwei.btw@antgroup.com Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- arch/um/os-Linux/sigio.c | 44 +++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/arch/um/os-Linux/sigio.c b/arch/um/os-Linux/sigio.c index 9aac8def4d635..61b348a2ea974 100644 --- a/arch/um/os-Linux/sigio.c +++ b/arch/um/os-Linux/sigio.c @@ -21,8 +21,7 @@ * Protected by sigio_lock(), also used by sigio_cleanup, which is an * exitcall. */ -static int write_sigio_pid = -1; -static unsigned long write_sigio_stack; +static struct os_helper_thread *write_sigio_td; /* * These arrays are initialized before the sigio thread is started, and @@ -48,15 +47,15 @@ static struct pollfds current_poll; static struct pollfds next_poll; static struct pollfds all_sigio_fds; -static int write_sigio_thread(void *unused) +static void *write_sigio_thread(void *unused) { struct pollfds *fds, tmp; struct pollfd *p; int i, n, respond_fd; char c; - os_set_pdeathsig(); - os_fix_helper_signals(); + os_fix_helper_thread_signals(); + fds = ¤t_poll; while (1) { n = poll(fds->poll, fds->used, -1); @@ -98,7 +97,7 @@ static int write_sigio_thread(void *unused) } } - return 0; + return NULL; } static int need_poll(struct pollfds *polls, int n) @@ -152,11 +151,10 @@ static void update_thread(void) return; fail: /* Critical section start */ - if (write_sigio_pid != -1) { - os_kill_process(write_sigio_pid, 1); - free_stack(write_sigio_stack, 0); + if (write_sigio_td) { + os_kill_helper_thread(write_sigio_td); + write_sigio_td = NULL; } - write_sigio_pid = -1; close(sigio_private[0]); close(sigio_private[1]); close(write_sigio_fds[0]); @@ -220,7 +218,7 @@ int __ignore_sigio_fd(int fd) * sigio_cleanup has already run, then update_thread will hang * or fail because the thread is no longer running. */ - if (write_sigio_pid == -1) + if (!write_sigio_td) return -EIO; for (i = 0; i < current_poll.used; i++) { @@ -279,14 +277,14 @@ static void write_sigio_workaround(void) int err; int l_write_sigio_fds[2]; int l_sigio_private[2]; - int l_write_sigio_pid; + struct os_helper_thread *l_write_sigio_td; /* We call this *tons* of times - and most ones we must just fail. */ sigio_lock(); - l_write_sigio_pid = write_sigio_pid; + l_write_sigio_td = write_sigio_td; sigio_unlock(); - if (l_write_sigio_pid != -1) + if (l_write_sigio_td) return; err = os_pipe(l_write_sigio_fds, 1, 1); @@ -312,7 +310,7 @@ static void write_sigio_workaround(void) * Did we race? Don't try to optimize this, please, it's not so likely * to happen, and no more than once at the boot. */ - if (write_sigio_pid != -1) + if (write_sigio_td) goto out_free; current_poll = ((struct pollfds) { .poll = p, @@ -325,18 +323,15 @@ static void write_sigio_workaround(void) memcpy(write_sigio_fds, l_write_sigio_fds, sizeof(l_write_sigio_fds)); memcpy(sigio_private, l_sigio_private, sizeof(l_sigio_private)); - write_sigio_pid = run_helper_thread(write_sigio_thread, NULL, - CLONE_FILES | CLONE_VM, - &write_sigio_stack); - - if (write_sigio_pid < 0) + err = os_run_helper_thread(&write_sigio_td, write_sigio_thread, NULL); + if (err < 0) goto out_clear; sigio_unlock(); return; out_clear: - write_sigio_pid = -1; + write_sigio_td = NULL; write_sigio_fds[0] = -1; write_sigio_fds[1] = -1; sigio_private[0] = -1; @@ -394,12 +389,11 @@ void maybe_sigio_broken(int fd) static void sigio_cleanup(void) { - if (write_sigio_pid == -1) + if (!write_sigio_td) return; - os_kill_process(write_sigio_pid, 1); - free_stack(write_sigio_stack, 0); - write_sigio_pid = -1; + os_kill_helper_thread(write_sigio_td); + write_sigio_td = NULL; } __uml_exitcall(sigio_cleanup); -- 2.39.5