mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Tiwei Bie" <tiwei.btw@antgroup.com>
To: Sasha Levin <sashal@kernel.org>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Johannes Berg <johannes.berg@intel.com>,
	richard@nod.at, anton.ivanov@cambridgegreys.com,
	johannes@sipsolutions.net, linux-um@lists.infradead.org
Subject: Re: [PATCH AUTOSEL 6.14 25/31] um: Switch to the pthread-based helper in sigio workaround
Date: Tue, 08 Apr 2025 12:29:53 +0800	[thread overview]
Message-ID: <ffa0b6af-523d-4e3e-9952-92f5b04b82b3@antgroup.com> (raw)
In-Reply-To: <20250407181054.3177479-25-sashal@kernel.org>

On 2025/4/8 02:10, Sasha Levin wrote:
> From: Tiwei Bie <tiwei.btw@antgroup.com>
> 
> [ 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 <tiwei.btw@antgroup.com>
> Link: https://patch.msgid.link/20250319135523.97050-4-tiwei.btw@antgroup.com
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
>  arch/um/os-Linux/sigio.c | 44 +++++++++++++++++-----------------------
>  1 file changed, 19 insertions(+), 25 deletions(-)

This patch depends on the helpers introduced by the below patch:

https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4f087eafdcef24b7160b097ddb9704084767b77a

So it can't be backported to the stable branch alone. Please drop
it. It is more of a preparation for the new features to be added
in the future. If it turns out later that it is also necessary for
the stable branch, I will submit a separate patchset specifically
targeting it.

Regards,
Tiwei

> 
> 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 = &current_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);


  reply	other threads:[~2025-04-08  5:00 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-07 18:10 [PATCH AUTOSEL 6.14 01/31] staging: gpib: Use min for calculating transfer length Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 02/31] usb: host: max3421-hcd: Add missing spi_device_id table Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 03/31] usb: typec: ucsi: return CCI and message from sync_control callback Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 04/31] usb: typec: ucsi: ccg: move command quirks to ucsi_ccg_sync_control() Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 05/31] iio: adc: ad4695: make ad4695_exit_conversion_mode() more robust Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 06/31] fs/ntfs3: Keep write operations atomic Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 07/31] fs/ntfs3: Fix WARNING in ntfs_extend_initialized_size Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 08/31] phy: qcom: qmp-pcie: Add X1P42100 Gen4x4 PHY Sasha Levin
2025-04-10  7:05   ` Johan Hovold
2025-04-28  0:00     ` Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 09/31] usb: dwc3: gadget: Refactor loop to avoid NULL endpoints Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 10/31] usb: dwc3: gadget: Avoid using reserved endpoints on Intel Merrifield Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 11/31] sound/virtio: Fix cancel_sync warnings on uninitialized work_structs Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 12/31] dmaengine: bcm2835-dma: fix warning when CONFIG_PM=n Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 13/31] usb: xhci: Complete 'error mid TD' transfers when handling Missed Service Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 14/31] usb: xhci: Fix isochronous Ring Underrun/Overrun event handling Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 15/31] xhci: Handle spurious events on Etron host isoc enpoints Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 16/31] i3c: master: svc: Add support for Nuvoton npcm845 i3c Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 17/31] dmaengine: dmatest: Fix dmatest waiting less when interrupted Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 18/31] usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems Running Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 19/31] phy: rockchip: usbdp: Avoid call hpd_event_trigger in dp_phy_init Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 20/31] usb: gadget: aspeed: Add NULL pointer check in ast_vhub_init_dev() Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 21/31] usb: host: xhci-plat: mvebu: use ->quirks instead of ->init_quirk() func Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 22/31] thunderbolt: Scan retimers after device router has been enumerated Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 23/31] um: work around sched_yield not yielding in time-travel mode Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 24/31] iommu/arm-smmu-v3: Set MEV bit in nested STE for DoS mitigations Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 25/31] um: Switch to the pthread-based helper in sigio workaround Sasha Levin
2025-04-08  4:29   ` Tiwei Bie [this message]
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 26/31] um: Rewrite the sigio workaround based on epoll and tgkill Sasha Levin
2025-04-08  4:36   ` Tiwei Bie
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 27/31] objtool: Silence more KCOV warnings Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 28/31] objtool, panic: Disable SMAP in __stack_chk_fail() Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 29/31] objtool, ASoC: codecs: wcd934x: Remove potential undefined behavior in wcd934x_slim_irq_handler() Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 30/31] objtool, regulator: rk808: Remove potential undefined behavior in rk806_set_mode_dcdc() Sasha Levin
2025-04-07 18:10 ` [PATCH AUTOSEL 6.14 31/31] objtool, lkdtm: Obfuscate the do_nothing() pointer Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ffa0b6af-523d-4e3e-9952-92f5b04b82b3@antgroup.com \
    --to=tiwei.btw@antgroup.com \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=johannes.berg@intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®