Skip to contentSkip to conversation

linux-user: epoll_pwait2 syscall

PATCH Applied Michael Tokarev 4 participants 8 messages Jan 9 – Jan 10

lore
Share & tools
lore
#0 lore raw

v2 cover linux-user: epoll_pwait2 syscall

These two changes implements epoll_pwait2 system call. First is a clean-up so the actual implementation is simpler.

v2: add the get_errno() wrapper missing in v1. That was a brown-paper bag bug again.

I also checked the CI/build failure of the very first attempt to implement this syscall by Zixing Liu, see
https://lists.gnu.org/archive/html/qemu-trivial/2025-05/msg00054.html - the issue was due to incomplete in-qemu copy of linux-headers, which is now fixed (by dropping the old copy entirely).

Michael Tokarev (2):
linux-user: cleanup epoll_pwait ifdeff'ery
linux-user: implement epoll_pwait2 syscall

 linux-user/syscall.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH v2 1/2 linux-user: cleanup epoll_pwait ifdeff'ery

All linux targets these days have epoll_pwait system call (while some miss epoll_wait, which is less generic). And all linux targets definitely has one or another epoll_*wait* system call - so whole code block dealing with this system call should always be present.

Remove the now-unneeded ifdef'fery.

---
 linux-user/syscall.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
linux-user/syscall.c +1 -7
index 2060e561a2..d89c36382e 100644
@@ -13615,13 +13615,10 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
     }
 #endif
 
-#if defined(TARGET_NR_epoll_wait) || defined(TARGET_NR_epoll_pwait)
 #if defined(TARGET_NR_epoll_wait)
     case TARGET_NR_epoll_wait:
 #endif
-#if defined(TARGET_NR_epoll_pwait)
     case TARGET_NR_epoll_pwait:
-#endif
     {
         struct target_epoll_event *target_ep;
         struct epoll_event *ep;
@@ -13646,7 +13643,6 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         }
 
         switch (num) {
-#if defined(TARGET_NR_epoll_pwait)
         case TARGET_NR_epoll_pwait:
         {
             sigset_t *set = NULL;
@@ -13666,7 +13662,6 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
             }
             break;
         }
-#endif
 #if defined(TARGET_NR_epoll_wait)
         case TARGET_NR_epoll_wait:
             ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
@@ -13690,8 +13685,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         g_free(ep);
         return ret;
     }
-#endif
-#endif
+#endif /* CONFIG_EPOLL */
 #ifdef TARGET_NR_prlimit64
     case TARGET_NR_prlimit64:
     {
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH v2 1/2] linux-user: cleanup epoll_pwait ifdeff'ery

Quoted 3 lines · Michael Tokarev

All linux targets these days have epoll_pwait system call (while some miss epoll_wait, which is less generic). And all linux targets definitely has one or another epoll_*wait*

s/has/have/?

Quoted 10 lines

system call - so whole code block dealing with this system call should always be present.

Remove the now-unneeded ifdef'fery.

---
  linux-user/syscall.c | 8 +-------
  1 file changed, 1 insertion(+), 7 deletions(-)
#3 lore raw

PATCH v2 2/2 linux-user: implement epoll_pwait2 syscall

In reply to Michael Tokarev

epoll_pwait2 is the same as epoll_pwait but with timeout being (a pointer to) struct timespec instead of an integer.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3210

---
 linux-user/syscall.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)
linux-user/syscall.c +23 -6
index d89c36382e..8f41cdb94b 100644
@@ -708,8 +708,11 @@ safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds,
               size_t, sigsetsize)
 #endif
 safe_syscall6(int, epoll_pwait, int, epfd, struct epoll_event *, events,
-              int, maxevents, int, timeout, const sigset_t *, sigmask,
-              size_t, sigsetsize)
+              int, maxevents, int, timeout,
+              const sigset_t *, sigmask, size_t, sigsetsize)
+safe_syscall6(int, epoll_pwait2, int, epfd, struct epoll_event *, events,
+              int, maxevents, struct timespec *, timeout_ts,
+              const sigset_t *, sigmask, size_t, sigsetsize)
 #if defined(__NR_futex)
 safe_syscall6(int,futex,int *,uaddr,int,op,int,val, \
               const struct timespec *,timeout,int *,uaddr2,int,val3)
@@ -13619,12 +13622,20 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
     case TARGET_NR_epoll_wait:
 #endif
     case TARGET_NR_epoll_pwait:
+    case TARGET_NR_epoll_pwait2:
     {
         struct target_epoll_event *target_ep;
         struct epoll_event *ep;
         int epfd = arg1;
         int maxevents = arg3;
-        int timeout = arg4;
+        struct timespec ts, *timeout_ts = NULL;
+
+        if (num == TARGET_NR_epoll_pwait2 && arg4 != 0) {
+            if (target_to_host_timespec(&ts, arg4)) {
+                return -TARGET_EFAULT;
+            }
+            timeout_ts = &ts;
+        }
 
         if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) {
             return -TARGET_EINVAL;
@@ -13644,6 +13655,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
 
         switch (num) {
         case TARGET_NR_epoll_pwait:
+        case TARGET_NR_epoll_pwait2:
         {
             sigset_t *set = NULL;
 
@@ -13654,8 +13666,13 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
                 }
             }
 
-            ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
-                                             set, SIGSET_T_SIZE));
+            if (num == TARGET_NR_epoll_pwait) {
+                ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, arg4,
+                                                 set, SIGSET_T_SIZE));
+            } else {
+                ret = get_errno(safe_epoll_pwait2(epfd, ep, maxevents, timeout_ts,
+                                                  set, SIGSET_T_SIZE));
+            }
 
             if (set) {
                 finish_sigsuspend_mask(ret);
@@ -13664,7 +13681,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         }
 #if defined(TARGET_NR_epoll_wait)
         case TARGET_NR_epoll_wait:
-            ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
+            ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, arg4,
                                              NULL, 0));
             break;
 #endif
Signature · 1 line
2.47.3
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] linux-user: implement epoll_pwait2 syscall

Quoted 9 lines · Michael Tokarev

epoll_pwait2 is the same as epoll_pwait but with timeout being (a pointer to) struct timespec instead of an integer.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3210

---
  linux-user/syscall.c | 29 +++++++++++++++++++++++------
  1 file changed, 23 insertions(+), 6 deletions(-)
#5 lore raw

Re: [PATCH v2 2/2] linux-user: implement epoll_pwait2 syscall

In reply to Michael Tokarev
Quoted 60 lines · Michael Tokarev

epoll_pwait2 is the same as epoll_pwait but with timeout being (a pointer to) struct timespec instead of an integer.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3210

---
  linux-user/syscall.c | 29 +++++++++++++++++++++++------
  1 file changed, 23 insertions(+), 6 deletions(-)
linux-user/syscall.c +15 -3
index d89c36382e..8f41cdb94b 100644
@@ -708,8 +708,11 @@ safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds,
                size_t, sigsetsize)
  #endif
  safe_syscall6(int, epoll_pwait, int, epfd, struct epoll_event *, events,
-              int, maxevents, int, timeout, const sigset_t *, sigmask,
-              size_t, sigsetsize)
+              int, maxevents, int, timeout,
+              const sigset_t *, sigmask, size_t, sigsetsize)
+safe_syscall6(int, epoll_pwait2, int, epfd, struct epoll_event *, events,
+              int, maxevents, struct timespec *, timeout_ts,
+              const sigset_t *, sigmask, size_t, sigsetsize)
  #if defined(__NR_futex)
  safe_syscall6(int,futex,int *,uaddr,int,op,int,val, \
                const struct timespec *,timeout,int *,uaddr2,int,val3)
@@ -13619,12 +13622,20 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
      case TARGET_NR_epoll_wait:
  #endif
      case TARGET_NR_epoll_pwait:
+    case TARGET_NR_epoll_pwait2:
      {
          struct target_epoll_event *target_ep;
          struct epoll_event *ep;
          int epfd = arg1;
          int maxevents = arg3;
-        int timeout = arg4;
+        struct timespec ts, *timeout_ts = NULL;
+
+        if (num == TARGET_NR_epoll_pwait2 && arg4 != 0) {
+            if (target_to_host_timespec(&ts, arg4)) {
+                return -TARGET_EFAULT;
+            }
+            timeout_ts = &ts;
+        }
 
          if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) {
              return -TARGET_EINVAL;
@@ -13644,6 +13655,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
 
          switch (num) {
          case TARGET_NR_epoll_pwait:
+        case TARGET_NR_epoll_pwait2:
          {
              sigset_t *set = NULL;
 
@@ -13654,8 +13666,13 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
                  }
              }

linux-user/syscall.c static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, · line 13675

Quoted 10 lines
linux-user/syscall.c +7 -2
 
-            ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
-                                             set, SIGSET_T_SIZE));
+            if (num == TARGET_NR_epoll_pwait) {
+                ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, arg4,
+                                                 set, SIGSET_T_SIZE));
+            } else {
+                ret = get_errno(safe_epoll_pwait2(epfd, ep, maxevents, timeout_ts,
+                                                  set, SIGSET_T_SIZE));
+            }

This second test needs to be vs pwait2, lest you break epoll_wait.

r~

#6 lore raw

Re: [PATCH v2 2/2] linux-user: implement epoll_pwait2 syscall

Quoted 14 lines · Richard Henderson
Quoted 14 lines
(quoted diff) +0 -0
@@ -13644,6 +13655,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, 
 abi_long arg1,
           switch (num) {

          case TARGET_NR_epoll_pwait:
+        case TARGET_NR_epoll_pwait2:
          {
              sigset_t *set = NULL;

linux-user/syscall.c +1 -2
@@ -13654,8 +13666,13 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, 
 abi_long arg1,
                   }
               }
-            ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout,
-                                             set, SIGSET_T_SIZE));
+            if (num == TARGET_NR_epoll_pwait) {
Quoted 8 lines

linux-user/syscall.c static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, · line 13675

Quoted 6 lines
linux-user/syscall.c +6 -0
+                ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, arg4,
+                                                 set, SIGSET_T_SIZE));
+            } else {
+                ret = get_errno(safe_epoll_pwait2(epfd, ep, maxevents, timeout_ts,
+                                                  set, SIGSET_T_SIZE));
+            }

This second test needs to be vs pwait2, lest you break epoll_wait.

Bah, seconds later I noticed the switch in the context.

r~

#7 lore raw
In reply to Michael Tokarev
Quoted 12 lines · Michael Tokarev

These two changes implements epoll_pwait2 system call. First is a clean-up so the actual implementation is simpler.

v2: add the get_errno() wrapper missing in v1. That was a brown-paper bag bug again.

I also checked the CI/build failure of the very first attempt to implement this syscall by Zixing Liu, see
https://lists.gnu.org/archive/html/qemu-trivial/2025-05/msg00054.html - the issue was due to incomplete in-qemu copy of linux-headers, which is now fixed (by dropping the old copy entirely).

Quoted 3 lines

Michael Tokarev (2):
linux-user: cleanup epoll_pwait ifdeff'ery
linux-user: implement epoll_pwait2 syscall

Queued, thanks.

r~