Skip to contentSkip to conversation

linux-user fixes & improvements

PATCH Superseded Paul Burton 3 participants 24 messages Jun 21, 2014 – Aug 5, 2014

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover linux-user fixes & improvements

From: Paul Burton <[email protected]>

This series fixes a number of bugs in QEMUs linux-user support, some specific to targetting the MIPS architecture but mostly generic. It also adds support for some previously unsupported syscalls & {g,s}etsockopt options.

Paul Burton (16):
linux-user: translate the result of getsockopt SO_TYPE
linux-user: support SO_ACCEPTCONN getsockopt option
linux-user: support SO_{SND,RCV}BUFFORCE setsockopt options
linux-user: support SO_PASSSEC setsockopt option
linux-user: allow NULL arguments to mount
linux-user: support strace of epoll_create1
linux-user: fix struct target_epoll_event layout for MIPS
linux-user: respect timezone for settimeofday
linux-user: allow NULL tv argument for settimeofday
linux-user: support timerfd_{create,gettime,settime} syscalls
linux-user: support ioprio_{get,set} syscalls
linux-user: support {name_to,open_by}_handle_at syscalls
linux-user: support the setns syscall
linux-user: support the unshare syscall
linux-user: support the KDSIGACCEPT ioctl
linux-user: support the SIOCGIFINDEX ioctl

 linux-user/ioctls.h       |   2 +
 linux-user/socket.h       |   5 +
 linux-user/strace.c       |  30 +++++
 linux-user/strace.list    |  21 ++++
 linux-user/syscall.c      | 271 +++++++++++++++++++++++++++++++++++++++++-----
 linux-user/syscall_defs.h |   9 +-
 6 files changed, 311 insertions(+), 27 deletions(-)
Signature · 1 line
2.0.0
#1 lore raw

PATCH v2 1/16 linux-user: translate the result of getsockopt SO_TYPE

QEMU previously passed the result of the host syscall directly to the target program. This is a problem if the host & target have different representations of socket types, as is the case when running a MIPS target program on an x86 host. Introduce a host_to_target_sock_type helper function mirroring the existing target_to_host_sock_type, and call it to translate the value provided by getsockopt when called for the SO_TYPE option.

---
Changes in v2:
- Remove indirection via a function pointer, and just call host_to_target_sock_type directly.

---
 linux-user/syscall.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
linux-user/syscall.c +31 -0
index 7d74079..30610e7 100644
@@ -592,6 +592,35 @@ char *target_strerror(int err)
     return strerror(target_to_host_errno(err));
 }
 
+static inline int host_to_target_sock_type(int host_type)
+{
+    int target_type;
+
+    switch (host_type & 0xf /* SOCK_TYPE_MASK */) {
+    case SOCK_DGRAM:
+        target_type = TARGET_SOCK_DGRAM;
+        break;
+    case SOCK_STREAM:
+        target_type = TARGET_SOCK_STREAM;
+        break;
+    default:
+        target_type = host_type & 0xf /* SOCK_TYPE_MASK */;
+        break;
+    }
+
+#if defined(SOCK_CLOEXEC)
+    if (host_type & SOCK_CLOEXEC)
+        target_type |= TARGET_SOCK_CLOEXEC;
+#endif
+
+#if defined(SOCK_NONBLOCK)
+    if (host_type & SOCK_NONBLOCK)
+        target_type |= TARGET_SOCK_NONBLOCK;
+#endif
+
+    return target_type;
+}
+
 static abi_ulong target_brk;
 static abi_ulong target_original_brk;
 static abi_ulong brk_page;
@@ -1636,6 +1665,8 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
         ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
         if (ret < 0)
             return ret;
+        if (optname == SO_TYPE)
+            val = host_to_target_sock_type(val);
         if (len > lv)
             len = lv;
         if (len == 4) {
Signature · 1 line
2.0.0
#2 lore raw

PATCH v2 2/16 linux-user: support SO_ACCEPTCONN getsockopt option

In reply to Paul Burton

Translate the SO_ACCEPTCONN option to the host value & execute the syscall as expected.

---
Changes in v2:
- None.

---
 linux-user/syscall.c | 3 +++
 1 file changed, 3 insertions(+)
linux-user/syscall.c +3 -0
index 30610e7..dba5b4d 100644
@@ -1650,6 +1650,9 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
         case TARGET_SO_RCVLOWAT:
             optname = SO_RCVLOWAT;
             goto int_case;
+        case TARGET_SO_ACCEPTCONN:
+            optname = SO_ACCEPTCONN;
+            goto int_case;
         default:
             goto int_case;
         }
Signature · 1 line
2.0.0
#3 lore raw

PATCH v2 3/16 linux-user: support SO_{SND, RCV}BUFFORCE setsockopt options

In reply to Paul Burton

Translate the SO_SNDBUFFORCE & SO_RCVBUFFORCE options to setsockopt to the host values & perform the syscall as expected, allowing use of those options by target programs.

---
Changes in v2:
- None.

---
 linux-user/syscall.c | 6 ++++++
 1 file changed, 6 insertions(+)
linux-user/syscall.c +6 -0
index dba5b4d..ce1ea1f 100644
@@ -1500,9 +1500,15 @@ set_timeout:
         case TARGET_SO_SNDBUF:
 		optname = SO_SNDBUF;
 		break;
+        case TARGET_SO_SNDBUFFORCE:
+		optname = SO_SNDBUFFORCE;
+		break;
         case TARGET_SO_RCVBUF:
 		optname = SO_RCVBUF;
 		break;
+        case TARGET_SO_RCVBUFFORCE:
+		optname = SO_RCVBUFFORCE;
+		break;
         case TARGET_SO_KEEPALIVE:
 		optname = SO_KEEPALIVE;
 		break;
Signature · 1 line
2.0.0
#4 lore raw

PATCH v2 4/16 linux-user: support SO_PASSSEC setsockopt option

In reply to Paul Burton

Translate the SO_PASSSEC option to setsockopt to the host value & perform the syscall as expected, allowing use of the option by target programs.

---
Changes in v2:
- Fix the value of TARGET_SO_PASSSEC for the sparc target.

---
 linux-user/socket.h  | 5 +++++
 linux-user/syscall.c | 3 +++
 2 files changed, 8 insertions(+)
linux-user/socket.h +5 -0
index ae17959..4dacae6 100644
@@ -63,6 +63,7 @@
     #define TARGET_SO_PEERSEC              30
     #define TARGET_SO_SNDBUFFORCE          31
     #define TARGET_SO_RCVBUFFORCE          33
+    #define TARGET_SO_PASSSEC              34
 
     /** sock_type - Socket types
      *
@@ -242,6 +243,10 @@
 
     #define TARGET_SOCK_MAX (TARGET_SOCK_PACKET + 1)
     #define TARGET_SOCK_TYPE_MASK    0xf  /* Covers up to TARGET_SOCK_MAX-1. */
+
+    #define TARGET_SO_PASSSEC        31
+#else
+    #define TARGET_SO_PASSSEC        34
 #endif
 
     /* For setsockopt(2) */
linux-user/syscall.c +3 -0
index ce1ea1f..7da21c7 100644
@@ -1529,6 +1529,9 @@ set_timeout:
         case TARGET_SO_PASSCRED:
 		optname = SO_PASSCRED;
 		break;
+        case TARGET_SO_PASSSEC:
+		optname = SO_PASSSEC;
+		break;
         case TARGET_SO_TIMESTAMP:
 		optname = SO_TIMESTAMP;
 		break;
Signature · 1 line
2.0.0
#5 lore raw

PATCH v2 5/16 linux-user: allow NULL arguments to mount

In reply to Paul Burton

Calls to the mount syscall can legitimately provide NULL as the value for the source of filesystemtype arguments, which QEMU would previously reject & return -EFAULT to the target program. An example of this is remounting an already mounted filesystem with different properties.

Instead of rejecting such syscalls with -EFAULT, pass NULL along to the kernel as the target program expects.

Additionally this patch fixes a potential memory leak when DEBUG_REMAP is enabled and lock_user_string fails on the target or filesystemtype arguments but a prior argument was non-NULL and already locked.

Since the patch already touched most lines of the TARGET_NR_mount case, it fixes the indentation for good measure.

---
Changes in v2:
- None.

---
 linux-user/syscall.c | 68 +++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 46 insertions(+), 22 deletions(-)
linux-user/syscall.c +46 -22
index 7da21c7..3861f0f 100644
@@ -5563,29 +5563,53 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
     case TARGET_NR_mount:
-		{
-			/* need to look at the data field */
-			void *p2, *p3;
-			p = lock_user_string(arg1);
-			p2 = lock_user_string(arg2);
-			p3 = lock_user_string(arg3);
-                        if (!p || !p2 || !p3)
-                            ret = -TARGET_EFAULT;
-                        else {
-                            /* FIXME - arg5 should be locked, but it isn't clear how to
-                             * do that since it's not guaranteed to be a NULL-terminated
-                             * string.
-                             */
-                            if ( ! arg5 )
-                                ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, NULL));
-                            else
-                                ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, g2h(arg5)));
-                        }
+        {
+            /* need to look at the data field */
+            void *p2, *p3;
+
+            if (arg1) {
+                p = lock_user_string(arg1);
+                if (!p)
+                    goto efault;
+            } else {
+                p = NULL;
+            }
+
+            p2 = lock_user_string(arg2);
+            if (!p2) {
+                if (arg1)
+                    unlock_user(p, arg1, 0);
+                    goto efault;
+            }
+
+            if (arg3) {
+                p3 = lock_user_string(arg3);
+                if (!p3) {
+                    if (arg1)
                         unlock_user(p, arg1, 0);
-                        unlock_user(p2, arg2, 0);
-                        unlock_user(p3, arg3, 0);
-			break;
-		}
+                    unlock_user(p2, arg2, 0);
+                    goto efault;
+                }
+            } else {
+                p3 = NULL;
+            }
+
+            /* FIXME - arg5 should be locked, but it isn't clear how to
+             * do that since it's not guaranteed to be a NULL-terminated
+             * string.
+             */
+             if (!arg5)
+                 ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, NULL));
+             else
+                 ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, g2h(arg5)));
+
+             if (arg1)
+                 unlock_user(p, arg1, 0);
+             unlock_user(p2, arg2, 0);
+             if (arg3)
+                 unlock_user(p3, arg3, 0);
+        }
+        break;
 #ifdef TARGET_NR_umount
     case TARGET_NR_umount:
         if (!(p = lock_user_string(arg1)))
Signature · 1 line
2.0.0
#6 lore raw

PATCH v2 6/16 linux-user: support strace of epoll_create1

In reply to Paul Burton

Add the epoll_create1 syscall to strace.list in order to display that syscall when it occurs, rather than a message about the syscall being unknown despite QEMU already implementing support for it.

---
Changes in v2:
- None.

---
 linux-user/strace.list | 3 +++
 1 file changed, 3 insertions(+)
linux-user/strace.list +3 -0
index cf5841a..fcb258d 100644
@@ -114,6 +114,9 @@
 #ifdef TARGET_NR_epoll_create
 { TARGET_NR_epoll_create, "epoll_create" , NULL, NULL, NULL },
 #endif
+#ifdef TARGET_NR_epoll_create1
+{ TARGET_NR_epoll_create1, "epoll_create1" , NULL, NULL, NULL },
+#endif
 #ifdef TARGET_NR_epoll_ctl
 { TARGET_NR_epoll_ctl, "epoll_ctl" , NULL, NULL, NULL },
 #endif
Signature · 1 line
2.0.0
#7 lore raw

PATCH v2 7/16 linux-user: fix struct target_epoll_event layout for MIPS

In reply to Paul Burton

MIPS requires the pad field to 64b-align the data field just as ARM does.

---
Changes in v2:
- Apply the same padding for the mips64 target.

---
 linux-user/syscall_defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall_defs.h +1 -1
index 69c3982..e379b45 100644
@@ -2528,7 +2528,7 @@ typedef union target_epoll_data {
 
 struct target_epoll_event {
     uint32_t events;
-#ifdef TARGET_ARM
+#if defined(TARGET_ARM) || defined(TARGET_MIPS) || defined(TARGET_MIPS64)
     uint32_t __pad;
 #endif
     target_epoll_data_t data;
Signature · 1 line
2.0.0
#8 lore raw

PATCH v2 8/16 linux-user: respect timezone for settimeofday

In reply to Paul Burton

The settimeofday syscall accepts a tz argument indicating the desired timezone to the kernel. QEMU previously ignored any argument provided by the target program & always passed NULL to the kernel. Instead, translate the argument & pass along the data userland provided.

Although this argument is described by the settimeofday man page as obsolete, it is used by systemd as of version 213.

---
Changes in v2:
- None.

---
 linux-user/syscall.c      | 27 ++++++++++++++++++++++++++-
 linux-user/syscall_defs.h |  5 +++++
 2 files changed, 31 insertions(+), 1 deletion(-)
linux-user/syscall.c +26 -1
index 3861f0f..ef04dc6 100644
@@ -933,6 +933,22 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
     return 0;
 }
 
+static inline abi_long copy_from_user_timezone(struct timezone *tz,
+                                               abi_ulong target_tz_addr)
+{
+    struct target_timezone *target_tz;
+
+    if (!lock_user_struct(VERIFY_READ, target_tz, target_tz_addr, 1))
+        return -TARGET_EFAULT;
+
+    __get_user(tz->tz_minuteswest, &target_tz->tz_minuteswest);
+    __get_user(tz->tz_dsttime, &target_tz->tz_dsttime);
+
+    unlock_user_struct(target_tz, target_tz_addr, 0);
+
+    return 0;
+}
+
 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
 #include <mqueue.h>
 
@@ -6327,9 +6343,18 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_settimeofday:
         {
             struct timeval tv;
+            struct timezone tz, *ptz = NULL;
+
             if (copy_from_user_timeval(&tv, arg1))
                 goto efault;
-            ret = get_errno(settimeofday(&tv, NULL));
+
+            if (arg2) {
+                if (copy_from_user_timezone(&tz, arg2))
+                    goto efault;
+                ptz = &tz;
+            }
+
+            ret = get_errno(settimeofday(&tv, ptz));
         }
         break;
 #if defined(TARGET_NR_select)
linux-user/syscall_defs.h +5 -0
index e379b45..a1f1fce 100644
@@ -165,6 +165,11 @@ struct target_timespec {
     abi_long tv_nsec;
 };
 
+struct target_timezone {
+    abi_int tz_minuteswest;
+    abi_int tz_dsttime;
+};
+
 struct target_itimerval {
     struct target_timeval it_interval;
     struct target_timeval it_value;
Signature · 1 line
2.0.0
#9 lore raw

Re: [Qemu-devel] [PATCH v2 08/16] linux-user: respect timezone for settimeofday

Quoted 22 lines · Paul Burton

The settimeofday syscall accepts a tz argument indicating the desired timezone to the kernel. QEMU previously ignored any argument provided by the target program & always passed NULL to the kernel. Instead, translate the argument & pass along the data userland provided.

Although this argument is described by the settimeofday man page as obsolete, it is used by systemd as of version 213.

---
Changes in v2:
- None.

---
 linux-user/syscall.c      | 27 ++++++++++++++++++++++++++-
 linux-user/syscall_defs.h |  5 +++++
 2 files changed, 31 insertions(+), 1 deletion(-)
linux-user/syscall.c +0 -0
index 3861f0f..ef04dc6 100644

linux-user/syscall.c static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr, · line 942

Quoted 10 lines
linux-user/syscall.c +7 -0
@@ -933,6 +933,22 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
     return 0;
 }
 
+static inline abi_long copy_from_user_timezone(struct timezone *tz,
+                                               abi_ulong target_tz_addr)
+{
+    struct target_timezone *target_tz;
+
+    if (!lock_user_struct(VERIFY_READ, target_tz, target_tz_addr, 1))
+        return -TARGET_EFAULT;

Coding style mandates braces even on single-line if()s; checkpatch.pl will catch this usually.

Code looks OK otherwise.

thanks
-- PMM

#10 lore raw

Re: [Qemu-devel] [PATCH v2 08/16] linux-user: respect timezone for settimeofday

Quoted 5 lines · Peter Maydell

linux-user/syscall.c static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr, · line 942

Quoted 2 lines
linux-user/syscall.c +2 -0
+    if (!lock_user_struct(VERIFY_READ, target_tz, target_tz_addr, 1))
+        return -TARGET_EFAULT;

Coding style mandates braces even on single-line if()s; checkpatch.pl will catch this usually.

I copied that style from the equivalent timeval functions, but yeah I'll make sure to get into the habit of running checkpatch for QEMU patches.

Quoted 1 line

Code looks OK otherwise.

Thanks for looking,
Paul

#11 lore raw

PATCH v2 9/16 linux-user: allow NULL tv argument for settimeofday

In reply to Paul Burton

The tv argument to the settimeofday syscall is allowed to be NULL, if the program only wishes to provide the timezone. QEMU previously returned -EFAULT when tv was NULL. Instead, execute the syscall & provide NULL to the kernel as the target program expected.

---
Changes in v2:
- None.

---
 linux-user/syscall.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
linux-user/syscall.c +7 -4
index ef04dc6..cd0221b 100644
@@ -6342,11 +6342,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_NR_settimeofday:
         {
-            struct timeval tv;
+            struct timeval tv, *ptv = NULL;
             struct timezone tz, *ptz = NULL;
 
-            if (copy_from_user_timeval(&tv, arg1))
-                goto efault;
+            if (arg1) {
+                if (copy_from_user_timeval(&tv, arg1))
+                    goto efault;
+                ptv = &tv;
+            }
 
             if (arg2) {
                 if (copy_from_user_timezone(&tz, arg2))
@@ -6354,7 +6357,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
                 ptz = &tz;
             }
 
-            ret = get_errno(settimeofday(&tv, ptz));
+            ret = get_errno(settimeofday(ptv, ptz));
         }
         break;
 #if defined(TARGET_NR_select)
Signature · 1 line
2.0.0
#12 lore raw

PATCH v2 10/16 linux-user: support timerfd_{create, gettime, settime} syscalls

In reply to Paul Burton

Adds support for the timerfd_create, timerfd_gettime & timerfd_settime syscalls, allowing use of timerfds by target programs.

---
Changes in v2:
- None.

---
 linux-user/strace.list |  9 +++++++++
 linux-user/syscall.c   | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
linux-user/strace.list +9 -0
index fcb258d..8de972a 100644
@@ -1404,6 +1404,15 @@
 #ifdef TARGET_NR_timer_settime
 { TARGET_NR_timer_settime, "timer_settime" , NULL, NULL, NULL },
 #endif
+#ifdef TARGET_NR_timerfd_create
+{ TARGET_NR_timerfd_create, "timerfd_create" , NULL, NULL, NULL },
+#endif
+#ifdef TARGET_NR_timerfd_gettime
+{ TARGET_NR_timerfd_gettime, "timerfd_gettime" , NULL, NULL, NULL },
+#endif
+#ifdef TARGET_NR_timerfd_settime
+{ TARGET_NR_timerfd_settime, "timerfd_settime" , NULL, NULL, NULL },
+#endif
 #ifdef TARGET_NR_times
 { TARGET_NR_times, "times" , NULL, NULL, NULL },
 #endif
linux-user/syscall.c +44 -0

56 lines not on this page · raw message

Signature · 1 line
2.0.0
#13 lore raw

PATCH v2 11/16 linux-user: support ioprio_{get, set} syscalls

In reply to Paul Burton

Add support for the ioprio_get & ioprio_set syscalls, allowing their use by target programs.

---
Changes in v2:
- Declare the host syscalls conditionally upon whether both host & target define their numbers, to avoid compile time warnings/errors about the host syscall functions being unused when built for targets which don't support them.

---
 linux-user/syscall.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
linux-user/syscall.c +18 -0
index 1c300be..fb36f46 100644
@@ -252,6 +252,12 @@ _syscall2(int, capget, struct __user_cap_header_struct *, header,
           struct __user_cap_data_struct *, data);
 _syscall2(int, capset, struct __user_cap_header_struct *, header,
           struct __user_cap_data_struct *, data);
+#if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get)
+_syscall2(int, ioprio_get, int, which, int, who)
+#endif
+#if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set)
+_syscall3(int, ioprio_set, int, which, int, who, int, ioprio)
+#endif
 
 static bitmask_transtbl fcntl_flags_tbl[] = {
   { TARGET_O_ACCMODE,   TARGET_O_WRONLY,    O_ACCMODE,   O_WRONLY,    },
@@ -9474,6 +9480,18 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
+#if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get)
+    case TARGET_NR_ioprio_get:
+        ret = get_errno(ioprio_get(arg1, arg2));
+        break;
+#endif
+
+#if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set)
+    case TARGET_NR_ioprio_set:
+        ret = get_errno(ioprio_set(arg1, arg2, arg3));
+        break;
+#endif
+
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
Signature · 1 line
2.0.0
#14 lore raw

PATCH v2 12/16 linux-user: support {name_to, open_by}_handle_at syscalls

In reply to Paul Burton

Implement support for the name_to_handle_at and open_by_handle_at syscalls, allowing their use by the target program.

---
Changes in v2:
- None.

---
 linux-user/strace.c    | 30 ++++++++++++++++++++++++++++++
 linux-user/strace.list |  6 ++++++
 linux-user/syscall.c   | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+)
linux-user/strace.c +30 -0
index ea6c1d2..c20ddf1 100644
@@ -1552,6 +1552,36 @@ print_kill(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_name_to_handle_at
+static void
+print_name_to_handle_at(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_pointer(arg2, 0);
+    print_pointer(arg3, 0);
+    print_raw_param("0x%x", arg4, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_open_by_handle_at
+static void
+print_open_by_handle_at(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_raw_param("%d", arg0, 0);
+    print_pointer(arg2, 0);
+    print_open_flags(arg3, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 /*
  * An array of all of the syscalls we know about
  */
linux-user/strace.list +6 -0
index 8de972a..147f579 100644
@@ -582,6 +582,9 @@
 #ifdef TARGET_NR_munmap
 { TARGET_NR_munmap, "munmap" , NULL, print_munmap, NULL },
 #endif
+#ifdef TARGET_NR_name_to_handle_at
+{ TARGET_NR_name_to_handle_at, "name_to_handle_at" , NULL, print_name_to_handle_at, NULL },
+#endif
 #ifdef TARGET_NR_nanosleep
 { TARGET_NR_nanosleep, "nanosleep" , NULL, NULL, NULL },
 #endif
@@ -624,6 +627,9 @@
 #ifdef TARGET_NR_openat
 { TARGET_NR_openat, "openat" , NULL, print_openat, NULL },
 #endif
+#ifdef TARGET_NR_open_by_handle_at
+{ TARGET_NR_open_by_handle_at, "open_by_handle_at" , NULL, print_open_by_handle_at, NULL },
+#endif
 #ifdef TARGET_NR_osf_adjtime
 { TARGET_NR_osf_adjtime, "osf_adjtime" , NULL, NULL, NULL },
 #endif
linux-user/syscall.c +50 -0

56 lines not on this page · raw message

Signature · 1 line
2.0.0
#15 lore raw

Re: [Qemu-devel] [PATCH v2 12/16] linux-user: support {name_to, open_by}_handle_at syscalls

Hi,

Comments inline:

Quoted 83 lines · Paul Burton

Implement support for the name_to_handle_at and open_by_handle_at syscalls, allowing their use by the target program.

---
Changes in v2:
- None.

---
 linux-user/strace.c    | 30 ++++++++++++++++++++++++++++++
 linux-user/strace.list |  6 ++++++
 linux-user/syscall.c   | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+)
linux-user/strace.c +30 -0
index ea6c1d2..c20ddf1 100644
@@ -1552,6 +1552,36 @@ print_kill(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_name_to_handle_at
+static void
+print_name_to_handle_at(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_pointer(arg2, 0);
+    print_pointer(arg3, 0);
+    print_raw_param("0x%x", arg4, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_open_by_handle_at
+static void
+print_open_by_handle_at(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_raw_param("%d", arg0, 0);
+    print_pointer(arg2, 0);
+    print_open_flags(arg3, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 /*
  * An array of all of the syscalls we know about
  */
linux-user/strace.list +6 -0
index 8de972a..147f579 100644
@@ -582,6 +582,9 @@
 #ifdef TARGET_NR_munmap
 { TARGET_NR_munmap, "munmap" , NULL, print_munmap, NULL },
 #endif
+#ifdef TARGET_NR_name_to_handle_at
+{ TARGET_NR_name_to_handle_at, "name_to_handle_at" , NULL, print_name_to_handle_at, NULL },
+#endif
 #ifdef TARGET_NR_nanosleep
 { TARGET_NR_nanosleep, "nanosleep" , NULL, NULL, NULL },
 #endif
@@ -624,6 +627,9 @@
 #ifdef TARGET_NR_openat
 { TARGET_NR_openat, "openat" , NULL, print_openat, NULL },
 #endif
+#ifdef TARGET_NR_open_by_handle_at
+{ TARGET_NR_open_by_handle_at, "open_by_handle_at" , NULL, print_open_by_handle_at, NULL },
+#endif
 #ifdef TARGET_NR_osf_adjtime
 { TARGET_NR_osf_adjtime, "osf_adjtime" , NULL, NULL, NULL },
 #endif
linux-user/syscall.c +0 -0
index fb36f46..0495781 100644

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 5350

Quoted 4 lines
linux-user/syscall.c +1 -0
@@ -5347,6 +5347,56 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         unlock_user(p, arg2, 0);
         break;
 #endif
+#ifdef TARGET_NR_name_to_handle_at

+#if defined(TARGET_NR_name_to_handle_at) && defined(__NR_name_to_handle_at)

This is something that all other syscall definitions need - else qemu won't compile on old distributions anymore.

Quoted 14 lines
linux-user/syscall.c +14 -0
+    case TARGET_NR_name_to_handle_at:
+        {
+            struct file_handle *fh;
+            uint32_t sz;
+            int mount_id;
+
+            if (!(p = lock_user_string(arg2)))
+                goto efault;
+
+            if (get_user_u32(sz, arg3)) {
+                unlock_user(p, arg2, 0);
+                goto efault;
+            }
+

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 5374

Quoted 10 lines
linux-user/syscall.c +10 -0
+            if (!(fh = lock_user(VERIFY_WRITE, arg3, sizeof(*fh) + sz, 1))) {
+                unlock_user(p, arg2, 0);
+                goto efault;
+            }
+
+            ret = get_errno(name_to_handle_at(arg1, path(p), fh,
+                                              &mount_id, arg5));
+
+            unlock_user(p, arg2, 0);
+            unlock_user(p, arg3, sizeof(*fh) + sz);

I think:
+ unlock_user(fh, arg3, sizeof(*fh) + sz);

Quoted 12 lines
linux-user/syscall.c +12 -0
+
+            if (put_user_s32(mount_id, arg4))
+                goto efault;
+        }
+        break;
+#endif
+#ifdef TARGET_NR_open_by_handle_at
+    case TARGET_NR_open_by_handle_at:
+        {
+            struct file_handle *fh;
+            uint32_t sz;
+

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 5396

Quoted 10 lines
linux-user/syscall.c +10 -0
+            if (get_user_u32(sz, arg2))
+                goto efault;
+
+            if (!(fh = lock_user(VERIFY_WRITE, arg2, sizeof(*fh) + sz, 1)))
+                goto efault;
+
+            ret = get_errno(open_by_handle_at(arg1, fh,
+                    target_to_host_bitmask(arg3, fcntl_flags_tbl)));
+
+            unlock_user(p, arg2, sizeof(*fh) + sz);

And here too:

+ unlock_user(fh, arg2, sizeof(*fh) + sz);

Quoted 8 lines
linux-user/syscall.c +3 -0
+        }
+        break;
+#endif
     case TARGET_NR_close:
         ret = get_errno(close(arg1));
         break;
Signature · 1 line
2.0.0
#16 lore raw

PATCH v2 13/16 linux-user: support the setns syscall

In reply to Paul Burton

Add support for the setns syscall, trivially passed through to the host.

---
Changes in v2:
- None.

---
 linux-user/strace.list | 3 +++
 linux-user/syscall.c   | 6 ++++++
 2 files changed, 9 insertions(+)
linux-user/strace.list +3 -0
index 147f579..d5b8033 100644
@@ -1191,6 +1191,9 @@
 #ifdef TARGET_NR_set_mempolicy
 { TARGET_NR_set_mempolicy, "set_mempolicy" , NULL, NULL, NULL },
 #endif
+#ifdef TARGET_NR_setns
+{ TARGET_NR_setns, "setns" , NULL, NULL, NULL },
+#endif
 #ifdef TARGET_NR_setpgid
 { TARGET_NR_setpgid, "setpgid" , NULL, NULL, NULL },
 #endif
linux-user/syscall.c +6 -0
index 0495781..0bbdf61 100644
@@ -9542,6 +9542,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
+#ifdef TARGET_NR_setns
+    case TARGET_NR_setns:
+        ret = get_errno(setns(arg1, arg2));
+        break;
+#endif
+
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
Signature · 1 line
2.0.0
#17 lore raw

PATCH v2 14/16 linux-user: support the unshare syscall

In reply to Paul Burton

Add support for the unshare syscall, trivially passed through to the host.

---
Changes in v2:
- None.

---
 linux-user/syscall.c | 6 ++++++
 1 file changed, 6 insertions(+)
linux-user/syscall.c +6 -0
index 0bbdf61..936064c 100644
@@ -9548,6 +9548,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
+#ifdef TARGET_NR_unshare
+    case TARGET_NR_unshare:
+        ret = get_errno(unshare(arg1));
+        break;
+#endif
+
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
Signature · 1 line
2.0.0
#18 lore raw

PATCH v2 15/16 linux-user: support the KDSIGACCEPT ioctl

In reply to Paul Burton

Add a definition of the KDSIGACCEPT ioctl & allow its use by target programs.

---
Changes in v2:
- None.

---
 linux-user/ioctls.h       | 1 +
 linux-user/syscall_defs.h | 1 +
 2 files changed, 2 insertions(+)
linux-user/ioctls.h +1 -0
index 309fb21..cd21e64 100644
@@ -64,6 +64,7 @@
      IOCTL(KDSKBLED, 0, TYPE_INT)
      IOCTL(KDGETLED, 0, TYPE_INT)
      IOCTL(KDSETLED, 0, TYPE_INT)
+     IOCTL(KDSIGACCEPT, 0, TYPE_INT)
 
      IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
      IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
linux-user/syscall_defs.h +1 -0
index a1f1fce..4adfd3a 100644
@@ -831,6 +831,7 @@ struct target_pollfd {
 #define TARGET_KDSKBLED        0x4B65	/* set led flags (not lights) */
 #define TARGET_KDGETLED        0x4B31	/* return current led state */
 #define TARGET_KDSETLED        0x4B32	/* set led state [lights, not flags] */
+#define TARGET_KDSIGACCEPT     0x4B4E
 
 #define TARGET_SIOCATMARK      0x8905
 
Signature · 1 line
2.0.0
#19 lore raw

Re: [Qemu-devel] [PATCH v2 15/16] linux-user: support the KDSIGACCEPT ioctl

Quoted 29 lines · Paul Burton

Add a definition of the KDSIGACCEPT ioctl & allow its use by target programs.

---
Changes in v2:
- None.

---
 linux-user/ioctls.h       | 1 +
 linux-user/syscall_defs.h | 1 +
 2 files changed, 2 insertions(+)
linux-user/ioctls.h +1 -0
index 309fb21..cd21e64 100644
@@ -64,6 +64,7 @@
      IOCTL(KDSKBLED, 0, TYPE_INT)
      IOCTL(KDGETLED, 0, TYPE_INT)
      IOCTL(KDSETLED, 0, TYPE_INT)
+     IOCTL(KDSIGACCEPT, 0, TYPE_INT)
 
      IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
      IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
linux-user/syscall_defs.h +0 -0
index a1f1fce..4adfd3a 100644

linux-user/syscall_defs.h struct target_pollfd { · line 836

Quoted 6 lines
linux-user/syscall_defs.h +1 -0
@@ -831,6 +831,7 @@ struct target_pollfd {
 #define TARGET_KDSKBLED        0x4B65  /* set led flags (not lights) */
 #define TARGET_KDGETLED        0x4B31  /* return current led state */
 #define TARGET_KDSETLED        0x4B32  /* set led state [lights, not flags] */
+#define TARGET_KDSIGACCEPT     0x4B4E
 
 #define TARGET_SIOCATMARK      0x8905

The argument to this ioctl is a signal number, right? Surely we need to translate it to a host signal number, not just pass it through as TYPE_INT...

thanks
-- PMM

#20 lore raw

Re: [Qemu-devel] [PATCH v2 15/16] linux-user: support the KDSIGACCEPT ioctl

Quoted 9 lines · Peter Maydell
Quoted 9 lines
linux-user/ioctls.h +1 -0
index 309fb21..cd21e64 100644
@@ -64,6 +64,7 @@
      IOCTL(KDSKBLED, 0, TYPE_INT)
      IOCTL(KDGETLED, 0, TYPE_INT)
      IOCTL(KDSETLED, 0, TYPE_INT)
+     IOCTL(KDSIGACCEPT, 0, TYPE_INT)

...snip...

Quoted 4 lines

The argument to this ioctl is a signal number, right? Surely we need to translate it to a host signal number, not just pass it through as TYPE_INT...

True, not sure how I missed that - the clue is in the name!

Thanks,
Paul

#21 lore raw

PATCH v2 16/16 linux-user: support the SIOCGIFINDEX ioctl

In reply to Paul Burton

Add a definition of the SIOCGIFINDEX ioctl, allowing its use by target programs.

---
Changes in v2:
- None.

---
 linux-user/ioctls.h       | 1 +
 linux-user/syscall_defs.h | 1 +
 2 files changed, 2 insertions(+)
linux-user/ioctls.h +1 -0
index cd21e64..20551a8 100644
@@ -118,6 +118,7 @@
   IOCTL(SIOCSIFMEM, IOC_W, MK_PTR(MK_STRUCT(STRUCT_ptr_ifreq)))
   IOCTL(SIOCADDMULTI, IOC_W, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq)))
   IOCTL(SIOCDELMULTI, IOC_W, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq)))
+  IOCTL(SIOCGIFINDEX, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq)))
   IOCTL(SIOCSIFLINK, 0, TYPE_NULL)
   IOCTL_SPECIAL(SIOCGIFCONF, IOC_W | IOC_R, do_ioctl_ifconf,
                 MK_PTR(MK_STRUCT(STRUCT_ifconf)))
linux-user/syscall_defs.h +1 -0
index 4adfd3a..8563027 100644
@@ -865,6 +865,7 @@ struct target_pollfd {
 #define TARGET_SIOCSIFSLAVE    0x8930
 #define TARGET_SIOCADDMULTI    0x8931          /* Multicast address lists      */
 #define TARGET_SIOCDELMULTI    0x8932
+#define TARGET_SIOCGIFINDEX    0x8933
 
 /* Bridging control calls */
 #define TARGET_SIOCGIFBR       0x8940          /* Bridging support             */
Signature · 1 line
2.0.0
#22 lore raw
In reply to Paul Burton
Quoted 6 lines · Paul Burton

From: Paul Burton <[email protected]>

This series fixes a number of bugs in QEMUs linux-user support, some specific to targetting the MIPS architecture but mostly generic. It also adds support for some previously unsupported syscalls & {g,s}etsockopt options.

Looks mostly good - unfortunately I missed some issues last round. iI gave comments to the {name_to,open_by}_handle_at patch - which also caused the build error for Peter.

Also, compile test on older distro showed that new syscalls need both target and host test:

#ifdef TARGET_NR_setns

needs to be replaced with

#if defined(TARGET_NR_setns) && defined(__NR_setns)

Riku

Quoted 28 lines

Paul Burton (16):
linux-user: translate the result of getsockopt SO_TYPE
linux-user: support SO_ACCEPTCONN getsockopt option
linux-user: support SO_{SND,RCV}BUFFORCE setsockopt options
linux-user: support SO_PASSSEC setsockopt option
linux-user: allow NULL arguments to mount
linux-user: support strace of epoll_create1
linux-user: fix struct target_epoll_event layout for MIPS
linux-user: respect timezone for settimeofday
linux-user: allow NULL tv argument for settimeofday
linux-user: support timerfd_{create,gettime,settime} syscalls
linux-user: support ioprio_{get,set} syscalls
linux-user: support {name_to,open_by}_handle_at syscalls
linux-user: support the setns syscall
linux-user: support the unshare syscall
linux-user: support the KDSIGACCEPT ioctl
linux-user: support the SIOCGIFINDEX ioctl

 linux-user/ioctls.h       |   2 +
 linux-user/socket.h       |   5 +
 linux-user/strace.c       |  30 +++++
 linux-user/strace.list    |  21 ++++
 linux-user/syscall.c      | 271 +++++++++++++++++++++++++++++++++++++++++-----
 linux-user/syscall_defs.h |   9 +-
 6 files changed, 311 insertions(+), 27 deletions(-)
Signature · 1 line
2.0.0
#23 lore raw

Hi Paul,

Quoted 12 lines · Riku Voipio
Quoted 6 lines · Paul Burton

From: Paul Burton <[email protected]>

This series fixes a number of bugs in QEMUs linux-user support, some specific to targetting the MIPS architecture but mostly generic. It also adds support for some previously unsupported syscalls & {g,s}etsockopt options.

Looks mostly good - unfortunately I missed some issues last round. iI gave comments to the {name_to,open_by}_handle_at patch - which also caused the build error for Peter.

Quoted 8 lines

Also, compile test on older distro showed that new syscalls need both target and host test:

#ifdef TARGET_NR_setns

needs to be replaced with

#if defined(TARGET_NR_setns) && defined(__NR_setns)

Do you have time to to make the needed ifdef changes and send the remaining patches again? I can also make the changes myself, if you prefer.

Riku

Quoted 30 lines

Riku

Quoted 28 lines

Paul Burton (16):
linux-user: translate the result of getsockopt SO_TYPE
linux-user: support SO_ACCEPTCONN getsockopt option
linux-user: support SO_{SND,RCV}BUFFORCE setsockopt options
linux-user: support SO_PASSSEC setsockopt option
linux-user: allow NULL arguments to mount
linux-user: support strace of epoll_create1
linux-user: fix struct target_epoll_event layout for MIPS
linux-user: respect timezone for settimeofday
linux-user: allow NULL tv argument for settimeofday
linux-user: support timerfd_{create,gettime,settime} syscalls
linux-user: support ioprio_{get,set} syscalls
linux-user: support {name_to,open_by}_handle_at syscalls
linux-user: support the setns syscall
linux-user: support the unshare syscall
linux-user: support the KDSIGACCEPT ioctl
linux-user: support the SIOCGIFINDEX ioctl

 linux-user/ioctls.h       |   2 +
 linux-user/socket.h       |   5 +
 linux-user/strace.c       |  30 +++++
 linux-user/strace.list    |  21 ++++
 linux-user/syscall.c      | 271 +++++++++++++++++++++++++++++++++++++++++-----
 linux-user/syscall_defs.h |   9 +-
 6 files changed, 311 insertions(+), 27 deletions(-)
Signature · 1 line
2.0.0