linux-um.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Tiwei Bie <tiwei.bie@linux.dev>
To: richard@nod.at, anton.ivanov@cambridgegreys.com,
	johannes@sipsolutions.net
Cc: linux-um@lists.infradead.org, tiwei.btw@antgroup.com,
	tiwei.bie@linux.dev
Subject: [PATCH 8/9] um: Support directing IO signals to calling thread
Date: Sun, 27 Jul 2025 14:29:36 +0800	[thread overview]
Message-ID: <20250727062937.1369050-9-tiwei.bie@linux.dev> (raw)
In-Reply-To: <20250727062937.1369050-1-tiwei.bie@linux.dev>

From: Tiwei Bie <tiwei.btw@antgroup.com>

Extend os_set_fd_async() to allow the calling thread to direct
I/O availability signals to itself. After this change, existing
users will explicitly direct these signals to the CPU0 thread,
which was achieved by ignoring SIGIO in helper threads. This is
a preparation for adding SMP support.

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
---
 arch/um/include/shared/os.h |  2 +-
 arch/um/kernel/irq.c        |  4 ++--
 arch/um/os-Linux/file.c     | 10 +++++++---
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
index 0ca6e4548671..ca377421181d 100644
--- a/arch/um/include/shared/os.h
+++ b/arch/um/include/shared/os.h
@@ -155,7 +155,7 @@ extern int os_pread_file(int fd, void *buf, int len, unsigned long long offset);
 extern int os_pwrite_file(int fd, const void *buf, int count, unsigned long long offset);
 extern int os_file_modtime(const char *file, long long *modtime);
 extern int os_pipe(int *fd, int stream, int close_on_exec);
-extern int os_set_fd_async(int fd);
+extern int os_set_fd_async(int fd, int self);
 extern int os_clear_fd_async(int fd);
 extern int os_set_fd_block(int fd, int blocking);
 extern int os_accept_connection(int fd);
diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c
index 5ed8014e43e4..193b6374d890 100644
--- a/arch/um/kernel/irq.c
+++ b/arch/um/kernel/irq.c
@@ -302,7 +302,7 @@ static int activate_fd(int irq, int fd, enum um_irq_type type, void *dev_id,
 	int err, events = os_event_mask(type);
 	unsigned long flags;
 
-	err = os_set_fd_async(fd);
+	err = os_set_fd_async(fd, 0);
 	if (err < 0)
 		goto out;
 
@@ -607,7 +607,7 @@ void um_irqs_resume(void)
 	raw_spin_lock_irqsave(&irq_lock, flags);
 	list_for_each_entry(entry, &active_fds, list) {
 		if (entry->suspended) {
-			int err = os_set_fd_async(entry->fd);
+			int err = os_set_fd_async(entry->fd, 0);
 
 			WARN(err < 0, "os_set_fd_async returned %d\n", err);
 			entry->suspended = false;
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
index 617886d1fb1e..2544a0fc9fbb 100644
--- a/arch/um/os-Linux/file.c
+++ b/arch/um/os-Linux/file.c
@@ -391,8 +391,12 @@ int os_pipe(int *fds, int stream, int close_on_exec)
 	return err;
 }
 
-int os_set_fd_async(int fd)
+int os_set_fd_async(int fd, int self)
 {
+	struct f_owner_ex owner = {
+		.type = F_OWNER_TID,
+		.pid = self ? gettid() : os_getpid(),
+	};
 	int err, flags;
 
 	flags = fcntl(fd, F_GETFL);
@@ -408,9 +412,9 @@ int os_set_fd_async(int fd)
 	}
 
 	if ((fcntl(fd, F_SETSIG, SIGIO) < 0) ||
-	    (fcntl(fd, F_SETOWN, os_getpid()) < 0)) {
+	    (fcntl(fd, F_SETOWN_EX, &owner) < 0)) {
 		err = -errno;
-		printk(UM_KERN_ERR "os_set_fd_async : Failed to fcntl F_SETOWN "
+		printk(UM_KERN_ERR "os_set_fd_async : Failed to fcntl F_SETOWN_EX "
 		       "(or F_SETSIG) fd %d, errno = %d\n", fd, errno);
 		return err;
 	}
-- 
2.34.1



  parent reply	other threads:[~2025-07-27  6:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-27  6:29 [PATCH 0/9] um: Add SMP support Tiwei Bie
2025-07-27  6:29 ` [PATCH 1/9] um: Stop tracking virtual CPUs via mm_cpumask() Tiwei Bie
2025-07-27  6:29 ` [PATCH 2/9] um: Remove unused cpu_data and current_cpu_data macros Tiwei Bie
2025-07-27  6:29 ` [PATCH 3/9] um: vdso: Implement __vdso_getcpu() via syscall Tiwei Bie
2025-07-27  6:29 ` [PATCH 4/9] um: Preserve errno within signal handler Tiwei Bie
2025-07-27  6:29 ` [PATCH 5/9] um: Turn signals_* into thread-local variables Tiwei Bie
2025-07-27  6:29 ` [PATCH 6/9] um: Determine sleep based on need_resched() Tiwei Bie
2025-07-27  6:29 ` [PATCH 7/9] um: Define timers on a per-CPU basis Tiwei Bie
2025-07-27  6:29 ` Tiwei Bie [this message]
2025-07-27  6:29 ` [PATCH 9/9] um: Add initial SMP support Tiwei Bie
2025-07-28 10:47   ` Johannes Berg
2025-07-28 15:28     ` Randy Dunlap
2025-07-28 16:04     ` Tiwei Bie
2025-07-28 16:27       ` Johannes Berg
2025-07-29 15:06         ` Tiwei Bie
2025-07-29 15:37           ` Johannes Berg
2025-07-30  4:18             ` Tiwei Bie
2025-08-10  4:33               ` Tiwei Bie
2025-07-28 13:55   ` Johannes Berg
2025-07-28 16:06     ` Tiwei Bie

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=20250727062937.1369050-9-tiwei.bie@linux.dev \
    --to=tiwei.bie@linux.dev \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-um@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=tiwei.btw@antgroup.com \
    /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;
as well as URLs for NNTP newsgroup(s).