Commit 33c9da5d authored by Tiwei Bie's avatar Tiwei Bie Committed by Johannes Berg
Browse files

um: Rewrite the sigio workaround based on epoll and tgkill



The existing sigio workaround implementation removes FDs from the
poll when events are triggered, requiring users to re-add them via
add_sigio_fd() after processing. This introduces a potential race
condition between FD removal in write_sigio_thread() and next_poll
update in __add_sigio_fd(), and is inefficient due to frequent FD
removal and re-addition. Rewrite the implementation based on epoll
and tgkill for improved efficiency and reliability.

Signed-off-by: default avatarTiwei Bie <tiwei.btw@antgroup.com>
Link: https://patch.msgid.link/20250315161910.4082396-2-tiwei.btw@antgroup.com


Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 69f52573
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ static int __init rng_init (void)
	if (err < 0)
		goto err_out_cleanup_hw;

	sigio_broken(random_fd);
	sigio_broken();
	hwrng.name = RNG_MODULE_NAME;
	hwrng.read = rng_dev_read;

+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ int uml_rtc_start(bool timetravel)
		}

		/* apparently timerfd won't send SIGIO, use workaround */
		sigio_broken(uml_rtc_irq_fds[0]);
		sigio_broken();
		err = add_sigio_fd(uml_rtc_irq_fds[0]);
		if (err < 0) {
			close(uml_rtc_irq_fds[0]);
+1 −1
Original line number Diff line number Diff line
@@ -314,7 +314,7 @@ extern void um_irqs_resume(void);
extern int add_sigio_fd(int fd);
extern int ignore_sigio_fd(int fd);
extern void maybe_sigio_broken(int fd);
extern void sigio_broken(int fd);
extern void sigio_broken(void);
/*
 * unlocked versions for IRQ controller code.
 *
+0 −1
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@
#ifndef __SIGIO_H__
#define __SIGIO_H__

extern int write_sigio_irq(int fd);
extern void sigio_lock(void);
extern void sigio_unlock(void);

+0 −26
Original line number Diff line number Diff line
@@ -8,32 +8,6 @@
#include <os.h>
#include <sigio.h>

/* Protected by sigio_lock() called from write_sigio_workaround */
static int sigio_irq_fd = -1;

static irqreturn_t sigio_interrupt(int irq, void *data)
{
	char c;

	os_read_file(sigio_irq_fd, &c, sizeof(c));
	return IRQ_HANDLED;
}

int write_sigio_irq(int fd)
{
	int err;

	err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt,
			     0, "write sigio", NULL);
	if (err < 0) {
		printk(KERN_ERR "write_sigio_irq : um_request_irq failed, "
		       "err = %d\n", err);
		return -1;
	}
	sigio_irq_fd = fd;
	return 0;
}

/* These are called from os-Linux/sigio.c to protect its pollfds arrays. */
static DEFINE_MUTEX(sigio_mutex);

Loading