qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Riku Voipio <riku.voipio@iki.fi>,
	Alistair Francis <alistair.francis@wdc.com>,
	Laurent Vivier <laurent@vivier.eu>
Subject: [PULL 12/38] linux-user: Support futex_time64
Date: Mon, 16 Mar 2020 17:15:24 +0100	[thread overview]
Message-ID: <20200316161550.336150-13-laurent@vivier.eu> (raw)
In-Reply-To: <20200316161550.336150-1-laurent@vivier.eu>

From: Alistair Francis <alistair.francis@wdc.com>

Add support for host and target futex_time64. If futex_time64 exists on
the host we try that first before falling back to the standard futex
syscall.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <517832730838e1d0b5eda26781b280854d792f9e.1584143748.git.alistair.francis@wdc.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 144 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 131 insertions(+), 13 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index aaf62d48992a..32d75cfe3b8a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -245,7 +245,12 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,	\
 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
 #define __NR_sys_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo
 #define __NR_sys_syslog __NR_syslog
-#define __NR_sys_futex __NR_futex
+#if defined(__NR_futex)
+# define __NR_sys_futex __NR_futex
+#endif
+#if defined(__NR_futex_time64)
+# define __NR_sys_futex_time64 __NR_futex_time64
+#endif
 #define __NR_sys_inotify_init __NR_inotify_init
 #define __NR_sys_inotify_add_watch __NR_inotify_add_watch
 #define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch
@@ -295,10 +300,16 @@ _syscall1(int,exit_group,int,error_code)
 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
 _syscall1(int,set_tid_address,int *,tidptr)
 #endif
-#if defined(TARGET_NR_futex) && defined(__NR_futex)
+#if (defined(TARGET_NR_futex) && defined(__NR_futex)) || \
+    (defined(TARGET_NR_futex_time64) && \
+        (HOST_LONG_BITS == 64 && defined(__NR_futex)))
 _syscall6(int,sys_futex,int *,uaddr,int,op,int,val,
           const struct timespec *,timeout,int *,uaddr2,int,val3)
 #endif
+#if (defined(TARGET_NR_futex_time64) && defined(__NR_futex_teim64))
+_syscall6(int,sys_futex_time64,int *,uaddr,int,op,int,val,
+          const struct timespec *,timeout,int *,uaddr2,int,val3)
+#endif
 #define __NR_sys_sched_getaffinity __NR_sched_getaffinity
 _syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len,
           unsigned long *, user_mask_ptr);
@@ -762,10 +773,14 @@ safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds,
 safe_syscall6(int, epoll_pwait, int, epfd, struct epoll_event *, events,
               int, maxevents, int, timeout, const sigset_t *, sigmask,
               size_t, sigsetsize)
-#ifdef TARGET_NR_futex
+#if defined(__NR_futex)
 safe_syscall6(int,futex,int *,uaddr,int,op,int,val, \
               const struct timespec *,timeout,int *,uaddr2,int,val3)
 #endif
+#if defined(__NR_futex_time64)
+safe_syscall6(int,futex_time64,int *,uaddr,int,op,int,val, \
+              const struct timespec *,timeout,int *,uaddr2,int,val3)
+#endif
 safe_syscall2(int, rt_sigsuspend, sigset_t *, newset, size_t, sigsetsize)
 safe_syscall2(int, kill, pid_t, pid, int, sig)
 safe_syscall2(int, tkill, int, tid, int, sig)
@@ -1229,7 +1244,7 @@ static inline abi_long target_to_host_timespec(struct timespec *host_ts,
 }
 #endif
 
-#if defined(TARGET_NR_clock_settime64)
+#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64)
 static inline abi_long target_to_host_timespec64(struct timespec *host_ts,
                                                  abi_ulong target_addr)
 {
@@ -6907,6 +6922,55 @@ static inline abi_long host_to_target_statx(struct target_statx *host_stx,
 }
 #endif
 
+static int do_sys_futex(int *uaddr, int op, int val,
+                         const struct timespec *timeout, int *uaddr2,
+                         int val3)
+{
+#if HOST_LONG_BITS == 64
+#if defined(__NR_futex)
+    /* always a 64-bit time_t, it doesn't define _time64 version  */
+    return sys_futex(uaddr, op, val, timeout, uaddr2, val3);
+
+#endif
+#else /* HOST_LONG_BITS == 64 */
+#if defined(__NR_futex_time64)
+    if (sizeof(timeout->tv_sec) == 8) {
+        /* _time64 function on 32bit arch */
+        return sys_futex_time64(uaddr, op, val, timeout, uaddr2, val3);
+    }
+#endif
+#if defined(__NR_futex)
+    /* old function on 32bit arch */
+    return sys_futex(uaddr, op, val, timeout, uaddr2, val3);
+#endif
+#endif /* HOST_LONG_BITS == 64 */
+    g_assert_not_reached();
+}
+
+static int do_safe_futex(int *uaddr, int op, int val,
+                         const struct timespec *timeout, int *uaddr2,
+                         int val3)
+{
+#if HOST_LONG_BITS == 64
+#if defined(__NR_futex)
+    /* always a 64-bit time_t, it doesn't define _time64 version  */
+    return get_errno(safe_futex(uaddr, op, val, timeout, uaddr2, val3));
+#endif
+#else /* HOST_LONG_BITS == 64 */
+#if defined(__NR_futex_time64)
+    if (sizeof(timeout->tv_sec) == 8) {
+        /* _time64 function on 32bit arch */
+        return get_errno(safe_futex_time64(uaddr, op, val, timeout, uaddr2,
+                                           val3));
+    }
+#endif
+#if defined(__NR_futex)
+    /* old function on 32bit arch */
+    return get_errno(safe_futex(uaddr, op, val, timeout, uaddr2, val3));
+#endif
+#endif /* HOST_LONG_BITS == 64 */
+    return -TARGET_ENOSYS;
+}
 
 /* ??? Using host futex calls even when target atomic operations
    are not really atomic probably breaks things.  However implementing
@@ -6936,12 +7000,61 @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
         } else {
             pts = NULL;
         }
-        return get_errno(safe_futex(g2h(uaddr), op, tswap32(val),
+        return get_errno(do_safe_futex(g2h(uaddr), op, tswap32(val),
+                         pts, NULL, val3));
+    case FUTEX_WAKE:
+        return get_errno(do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0));
+    case FUTEX_FD:
+        return get_errno(do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0));
+    case FUTEX_REQUEUE:
+    case FUTEX_CMP_REQUEUE:
+    case FUTEX_WAKE_OP:
+        /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the
+           TIMEOUT parameter is interpreted as a uint32_t by the kernel.
+           But the prototype takes a `struct timespec *'; insert casts
+           to satisfy the compiler.  We do not need to tswap TIMEOUT
+           since it's not compared to guest memory.  */
+        pts = (struct timespec *)(uintptr_t) timeout;
+        return get_errno(do_safe_futex(g2h(uaddr), op, val, pts,
+                                       g2h(uaddr2),
+                                       (base_op == FUTEX_CMP_REQUEUE
+                                        ? tswap32(val3)
+                                        : val3)));
+    default:
+        return -TARGET_ENOSYS;
+    }
+}
+#endif
+
+#if defined(TARGET_NR_futex_time64)
+static int do_futex_time64(target_ulong uaddr, int op, int val, target_ulong timeout,
+                           target_ulong uaddr2, int val3)
+{
+    struct timespec ts, *pts;
+    int base_op;
+
+    /* ??? We assume FUTEX_* constants are the same on both host
+       and target.  */
+#ifdef FUTEX_CMD_MASK
+    base_op = op & FUTEX_CMD_MASK;
+#else
+    base_op = op;
+#endif
+    switch (base_op) {
+    case FUTEX_WAIT:
+    case FUTEX_WAIT_BITSET:
+        if (timeout) {
+            pts = &ts;
+            target_to_host_timespec64(pts, timeout);
+        } else {
+            pts = NULL;
+        }
+        return get_errno(do_safe_futex(g2h(uaddr), op, tswap32(val),
                          pts, NULL, val3));
     case FUTEX_WAKE:
-        return get_errno(safe_futex(g2h(uaddr), op, val, NULL, NULL, 0));
+        return get_errno(do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0));
     case FUTEX_FD:
-        return get_errno(safe_futex(g2h(uaddr), op, val, NULL, NULL, 0));
+        return get_errno(do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0));
     case FUTEX_REQUEUE:
     case FUTEX_CMP_REQUEUE:
     case FUTEX_WAKE_OP:
@@ -6951,16 +7064,17 @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
            to satisfy the compiler.  We do not need to tswap TIMEOUT
            since it's not compared to guest memory.  */
         pts = (struct timespec *)(uintptr_t) timeout;
-        return get_errno(safe_futex(g2h(uaddr), op, val, pts,
-                                    g2h(uaddr2),
-                                    (base_op == FUTEX_CMP_REQUEUE
-                                     ? tswap32(val3)
-                                     : val3)));
+        return get_errno(do_safe_futex(g2h(uaddr), op, val, pts,
+                                       g2h(uaddr2),
+                                       (base_op == FUTEX_CMP_REQUEUE
+                                        ? tswap32(val3)
+                                        : val3)));
     default:
         return -TARGET_ENOSYS;
     }
 }
 #endif
+
 #if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
 static abi_long do_name_to_handle_at(abi_long dirfd, abi_long pathname,
                                      abi_long handle, abi_long mount_id,
@@ -7532,7 +7646,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
             ts = cpu->opaque;
             if (ts->child_tidptr) {
                 put_user_u32(0, ts->child_tidptr);
-                sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
+                do_sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
                           NULL, NULL, 0);
             }
             thread_cpu = NULL;
@@ -11630,6 +11744,10 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_futex:
         return do_futex(arg1, arg2, arg3, arg4, arg5, arg6);
 #endif
+#ifdef TARGET_NR_futex_time64
+    case TARGET_NR_futex_time64:
+        return do_futex_time64(arg1, arg2, arg3, arg4, arg5, arg6);
+#endif
 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
     case TARGET_NR_inotify_init:
         ret = get_errno(sys_inotify_init());
-- 
2.24.1



  parent reply	other threads:[~2020-03-16 18:07 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-16 16:15 [PULL 00/38] Linux user for 5.0 patches Laurent Vivier
2020-03-16 16:15 ` [PULL 01/38] target/i386: Renumber EXCP_SYSCALL Laurent Vivier
2020-03-16 16:15 ` [PULL 02/38] linux-user/i386: Split out gen_signal Laurent Vivier
2020-03-16 16:15 ` [PULL 03/38] linux-user/i386: Emulate x86_64 vsyscalls Laurent Vivier
2020-03-16 16:15 ` [PULL 04/38] linux-user: Add x86_64 vsyscall page to /proc/self/maps Laurent Vivier
2020-03-16 16:15 ` [PULL 05/38] linux-user: Flush out implementation of gettimeofday Laurent Vivier
2020-03-16 16:15 ` [PULL 06/38] linux-user: Add AT_EXECFN auxval Laurent Vivier
2020-03-16 16:15 ` [PULL 07/38] linux-user: do prlimit selectively Laurent Vivier
2020-03-16 16:15 ` [PULL 08/38] linux-user: fix socket() strace Laurent Vivier
2020-03-16 16:15 ` [PULL 09/38] linux-user: Update TASK_UNMAPPED_BASE for aarch64 Laurent Vivier
2020-03-16 16:15 ` [PULL 10/38] linux-user: Protect more syscalls Laurent Vivier
2020-03-16 16:15 ` [PULL 11/38] linux-user/syscall: Add support for clock_gettime64/clock_settime64 Laurent Vivier
2020-03-16 16:15 ` Laurent Vivier [this message]
2020-03-17 16:09   ` [PULL 12/38] linux-user: Support futex_time64 Laurent Vivier
2020-03-16 16:15 ` [PULL 13/38] linux-user/riscv: Update the syscall_nr's to the 5.5 kernel Laurent Vivier
2020-03-16 16:15 ` [PULL 14/38] linux-user: introduce parameters to generate syscall_nr.h Laurent Vivier
2020-03-16 16:15 ` [PULL 15/38] linux-user, alpha: add syscall table generation support Laurent Vivier
2020-03-16 16:15 ` [PULL 16/38] linux-user, hppa: " Laurent Vivier
2020-03-16 16:15 ` [PULL 17/38] linux-user, m68k: " Laurent Vivier
2020-03-16 16:15 ` [PULL 18/38] linux-user, xtensa: " Laurent Vivier
2020-03-16 16:15 ` [PULL 19/38] linux-user, sh4: " Laurent Vivier
2020-03-16 16:15 ` [PULL 20/38] linux-user, microblaze: " Laurent Vivier
2020-03-16 16:15 ` [PULL 21/38] linux-user, arm: " Laurent Vivier
2020-03-16 16:15 ` [PULL 22/38] linux-user, ppc: " Laurent Vivier
2020-03-16 16:15 ` [PULL 23/38] linux-user, s390x: remove syscall definitions for !TARGET_S390X Laurent Vivier
2020-03-16 16:15 ` [PULL 24/38] linux-user, s390x: add syscall table generation support Laurent Vivier
2020-03-16 16:15 ` [PULL 25/38] linux-user, sparc, sparc64: " Laurent Vivier
2020-03-16 16:15 ` [PULL 26/38] linux-user, x86_64, i386: cleanup TARGET_NR_arch_prctl Laurent Vivier
2020-03-16 16:15 ` [PULL 27/38] linux-user, i386: add syscall table generation support Laurent Vivier
2020-03-16 16:15 ` [PULL 28/38] linux-user, x86_64: " Laurent Vivier
2020-03-16 16:15 ` [PULL 29/38] linux-user, mips: " Laurent Vivier
2020-03-16 16:15 ` [PULL 30/38] linux-user, mips64: " Laurent Vivier
2020-03-16 16:15 ` [PULL 31/38] linux-user, scripts: add a script to update syscall.tbl Laurent Vivier
2020-03-16 16:15 ` [PULL 32/38] linux-user: update syscall.tbl from linux 0bf999f9c5e7 Laurent Vivier
2020-03-16 16:15 ` [PULL 33/38] linux-user,mips: move content of mips_syscall_args Laurent Vivier
2020-03-16 16:15 ` [PULL 34/38] linux-user,mips: update syscall-args-o32.c.inc Laurent Vivier
2020-03-16 16:15 ` [PULL 35/38] scripts: add a script to generate syscall_nr.h Laurent Vivier
2020-03-16 16:15 ` [PULL 36/38] linux-user, aarch64: sync syscall numbers with kernel v5.5 Laurent Vivier
2020-03-16 16:15 ` [PULL 37/38] linux-user, nios2: " Laurent Vivier
2020-03-16 16:15 ` [PULL 38/38] linux-user, openrisc: " Laurent Vivier
2020-03-16 19:17 ` [PULL 00/38] Linux user for 5.0 patches Peter Maydell
2020-03-17  7:49   ` Laurent Vivier
2020-03-16 21:59 ` no-reply
2020-03-16 23:43 ` no-reply
2020-03-17  1:09 ` no-reply
2020-03-17  2:01 ` no-reply
2020-03-17  2:13 ` no-reply

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=20200316161550.336150-13-laurent@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=alistair.francis@wdc.com \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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).