Skip to content

Commit 33c9da5

Browse files
btw616jmberg-intel
authored andcommitted
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: Tiwei Bie <tiwei.btw@antgroup.com> Link: https://patch.msgid.link/20250315161910.4082396-2-tiwei.btw@antgroup.com Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 69f5257 commit 33c9da5

File tree

6 files changed

+47
-316
lines changed

6 files changed

+47
-316
lines changed

arch/um/drivers/random.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static int __init rng_init (void)
7979
if (err < 0)
8080
goto err_out_cleanup_hw;
8181

82-
sigio_broken(random_fd);
82+
sigio_broken();
8383
hwrng.name = RNG_MODULE_NAME;
8484
hwrng.read = rng_dev_read;
8585

arch/um/drivers/rtc_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int uml_rtc_start(bool timetravel)
3939
}
4040

4141
/* apparently timerfd won't send SIGIO, use workaround */
42-
sigio_broken(uml_rtc_irq_fds[0]);
42+
sigio_broken();
4343
err = add_sigio_fd(uml_rtc_irq_fds[0]);
4444
if (err < 0) {
4545
close(uml_rtc_irq_fds[0]);

arch/um/include/shared/os.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ extern void um_irqs_resume(void);
314314
extern int add_sigio_fd(int fd);
315315
extern int ignore_sigio_fd(int fd);
316316
extern void maybe_sigio_broken(int fd);
317-
extern void sigio_broken(int fd);
317+
extern void sigio_broken(void);
318318
/*
319319
* unlocked versions for IRQ controller code.
320320
*

arch/um/include/shared/sigio.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#ifndef __SIGIO_H__
77
#define __SIGIO_H__
88

9-
extern int write_sigio_irq(int fd);
109
extern void sigio_lock(void);
1110
extern void sigio_unlock(void);
1211

arch/um/kernel/sigio.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,6 @@
88
#include <os.h>
99
#include <sigio.h>
1010

11-
/* Protected by sigio_lock() called from write_sigio_workaround */
12-
static int sigio_irq_fd = -1;
13-
14-
static irqreturn_t sigio_interrupt(int irq, void *data)
15-
{
16-
char c;
17-
18-
os_read_file(sigio_irq_fd, &c, sizeof(c));
19-
return IRQ_HANDLED;
20-
}
21-
22-
int write_sigio_irq(int fd)
23-
{
24-
int err;
25-
26-
err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt,
27-
0, "write sigio", NULL);
28-
if (err < 0) {
29-
printk(KERN_ERR "write_sigio_irq : um_request_irq failed, "
30-
"err = %d\n", err);
31-
return -1;
32-
}
33-
sigio_irq_fd = fd;
34-
return 0;
35-
}
36-
3711
/* These are called from os-Linux/sigio.c to protect its pollfds arrays. */
3812
static DEFINE_MUTEX(sigio_mutex);
3913

0 commit comments

Comments
 (0)