qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches
@ 2019-07-17 14:54 Laurent Vivier
  2019-07-17 14:54 ` [Qemu-devel] [PULL 1/3] linux-user: Fix structure target_ucontext for MIPS Laurent Vivier
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Laurent Vivier @ 2019-07-17 14:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Aleksandar Rikalo, Riku Voipio, Laurent Vivier,
	Aleksandar Markovic, Paolo Bonzini, Aurelien Jarno,
	Richard Henderson

The following changes since commit a1a4d49f60d2b899620ee2be4ebb991c4a90a026:

  Merge remote-tracking branch 'remotes/philmd-gitlab/tags/pflash-next-20190716' into staging (2019-07-16 17:02:44 +0100)

are available in the Git repository at:

  git://github.com/vivier/qemu.git tags/linux-user-for-4.1-pull-request

for you to fetch changes up to ad0bcf5d59f120d546be7a2c3590afc66eea0b01:

  linux-user: check valid address in access_ok() (2019-07-17 09:02:51 +0200)

----------------------------------------------------------------
fix access_ok() to allow to run LTP on AARCH64,
fix SIOCGSTAMP with 5.2 kernel headers,
fix structure target_ucontext for MIPS

----------------------------------------------------------------

Aleksandar Markovic (1):
  linux-user: Fix structure target_ucontext for MIPS

Daniel P. Berrangé (1):
  linux-user: fix to handle variably sized SIOCGSTAMP with new kernels

Rémi Denis-Courmont (1):
  linux-user: check valid address in access_ok()

 include/exec/cpu_ldst.h    |   4 ++
 linux-user/ioctls.h        |  11 ++-
 linux-user/mips/signal.c   |   5 +-
 linux-user/qemu.h          |   4 +-
 linux-user/syscall.c       | 140 +++++++++++++++++++++++++++++--------
 linux-user/syscall_defs.h  |  30 +++++++-
 linux-user/syscall_types.h |   6 --
 7 files changed, 158 insertions(+), 42 deletions(-)

-- 
2.21.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PULL 1/3] linux-user: Fix structure target_ucontext for MIPS
  2019-07-17 14:54 [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches Laurent Vivier
@ 2019-07-17 14:54 ` Laurent Vivier
  2019-07-17 14:54 ` [Qemu-devel] [PULL 2/3] linux-user: fix to handle variably sized SIOCGSTAMP with new kernels Laurent Vivier
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Laurent Vivier @ 2019-07-17 14:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dragan Mladjenovic, Aleksandar Rikalo, Riku Voipio,
	Laurent Vivier, Aleksandar Markovic, Paolo Bonzini,
	Aurelien Jarno, Richard Henderson

From: Aleksandar Markovic <amarkovic@wavecomp.com>

Structure ucontext for MIPS is defined in the following way in
Linux kernel:

(arch/mips/include/uapi/asm/ucontext.h, lines 54-64)

struct ucontext {
    /* Historic fields matching asm-generic */
    unsigned long       uc_flags;
    struct ucontext     *uc_link;
    stack_t             uc_stack;
    struct sigcontext   uc_mcontext;
    sigset_t            uc_sigmask;

    /* Extended context structures may follow ucontext */
    unsigned long long	uc_extcontext[0];
};

Fix the structure target_ucontext for MIPS to reflect the definition
above, except the correction for field uc_extcontext, which will
follow at some later time.

Fixes: 94c5495d

Reported-by: Dragan Mladjenovic <dmladjenovic@wavecomp.com>
Signed-off-by: Aleksandar Markovic <amarkovic@wavecomp.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <1562931470-3700-2-git-send-email-aleksandar.markovic@rt-rk.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/mips/signal.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/linux-user/mips/signal.c b/linux-user/mips/signal.c
index 6aa303ec9c16..455a8a229a83 100644
--- a/linux-user/mips/signal.c
+++ b/linux-user/mips/signal.c
@@ -71,10 +71,9 @@ struct sigframe {
 };
 
 struct target_ucontext {
-    target_ulong tuc_flags;
-    target_ulong tuc_link;
+    abi_ulong tuc_flags;
+    abi_ulong tuc_link;
     target_stack_t tuc_stack;
-    target_ulong pad0;
     struct target_sigcontext tuc_mcontext;
     target_sigset_t tuc_sigmask;
 };
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PULL 2/3] linux-user: fix to handle variably sized SIOCGSTAMP with new kernels
  2019-07-17 14:54 [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches Laurent Vivier
  2019-07-17 14:54 ` [Qemu-devel] [PULL 1/3] linux-user: Fix structure target_ucontext for MIPS Laurent Vivier
@ 2019-07-17 14:54 ` Laurent Vivier
  2019-07-17 14:54 ` [Qemu-devel] [PULL 3/3] linux-user: check valid address in access_ok() Laurent Vivier
  2019-07-18 10:20 ` [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches Peter Maydell
  3 siblings, 0 replies; 9+ messages in thread
From: Laurent Vivier @ 2019-07-17 14:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé,
	Arnd Bergmann, Aleksandar Rikalo, Riku Voipio, Laurent Vivier,
	Aleksandar Markovic, Paolo Bonzini, Aurelien Jarno,
	Richard Henderson

From: Daniel P. Berrangé <berrange@redhat.com>

The SIOCGSTAMP symbol was previously defined in the
asm-generic/sockios.h header file. QEMU sees that header
indirectly via sys/socket.h

In linux kernel commit 0768e17073dc527ccd18ed5f96ce85f9985e9115
the asm-generic/sockios.h header no longer defines SIOCGSTAMP.
Instead it provides only SIOCGSTAMP_OLD, which only uses a
32-bit time_t on 32-bit architectures.

The linux/sockios.h header then defines SIOCGSTAMP using
either SIOCGSTAMP_OLD or SIOCGSTAMP_NEW as appropriate. If
SIOCGSTAMP_NEW is used, then the tv_sec field is 64-bit even
on 32-bit architectures

To cope with this we must now convert the old and new type from
the target to the host one.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Message-Id: <20190714135423.1274-1-laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/ioctls.h        |  11 ++-
 linux-user/syscall.c       | 140 +++++++++++++++++++++++++++++--------
 linux-user/syscall_defs.h  |  30 +++++++-
 linux-user/syscall_types.h |   6 --
 4 files changed, 149 insertions(+), 38 deletions(-)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 5e84dc7c3a77..9a4957840ac4 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -222,8 +222,15 @@
   IOCTL(SIOCGIWNAME, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_char_ifreq)))
   IOCTL(SIOCSPGRP, IOC_W, MK_PTR(TYPE_INT)) /* pid_t */
   IOCTL(SIOCGPGRP, IOC_R, MK_PTR(TYPE_INT)) /* pid_t */
-  IOCTL(SIOCGSTAMP, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timeval)))
-  IOCTL(SIOCGSTAMPNS, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timespec)))
+
+  { TARGET_SIOCGSTAMP_OLD, SIOCGSTAMP, "IOCGSTAMP_OLD", IOC_R, \
+    do_ioctl_SIOCGSTAMP },
+  { TARGET_SIOCGSTAMPNS_OLD, SIOCGSTAMPNS, "IOCGSTAMPNS_OLD", IOC_R, \
+    do_ioctl_SIOCGSTAMPNS },
+  { TARGET_SIOCGSTAMP_NEW, SIOCGSTAMP, "IOCGSTAMP_NEW", IOC_R, \
+    do_ioctl_SIOCGSTAMP },
+  { TARGET_SIOCGSTAMPNS_NEW, SIOCGSTAMPNS, "IOCGSTAMPNS_NEW", IOC_R, \
+    do_ioctl_SIOCGSTAMPNS },
 
   IOCTL(RNDGETENTCNT, IOC_R, MK_PTR(TYPE_INT))
   IOCTL(RNDADDTOENTCNT, IOC_W, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 39a37496fed5..8367cb138dfe 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -37,6 +37,7 @@
 #include <sched.h>
 #include <sys/timex.h>
 #include <sys/socket.h>
+#include <linux/sockios.h>
 #include <sys/un.h>
 #include <sys/uio.h>
 #include <poll.h>
@@ -1126,8 +1127,9 @@ static inline abi_long copy_from_user_timeval(struct timeval *tv,
 {
     struct target_timeval *target_tv;
 
-    if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 1))
+    if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 1)) {
         return -TARGET_EFAULT;
+    }
 
     __get_user(tv->tv_sec, &target_tv->tv_sec);
     __get_user(tv->tv_usec, &target_tv->tv_usec);
@@ -1142,8 +1144,26 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
 {
     struct target_timeval *target_tv;
 
-    if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0))
+    if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) {
+        return -TARGET_EFAULT;
+    }
+
+    __put_user(tv->tv_sec, &target_tv->tv_sec);
+    __put_user(tv->tv_usec, &target_tv->tv_usec);
+
+    unlock_user_struct(target_tv, target_tv_addr, 1);
+
+    return 0;
+}
+
+static inline abi_long copy_to_user_timeval64(abi_ulong target_tv_addr,
+                                             const struct timeval *tv)
+{
+    struct target__kernel_sock_timeval *target_tv;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) {
         return -TARGET_EFAULT;
+    }
 
     __put_user(tv->tv_sec, &target_tv->tv_sec);
     __put_user(tv->tv_usec, &target_tv->tv_usec);
@@ -1153,6 +1173,48 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
     return 0;
 }
 
+static inline abi_long target_to_host_timespec(struct timespec *host_ts,
+                                               abi_ulong target_addr)
+{
+    struct target_timespec *target_ts;
+
+    if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1)) {
+        return -TARGET_EFAULT;
+    }
+    __get_user(host_ts->tv_sec, &target_ts->tv_sec);
+    __get_user(host_ts->tv_nsec, &target_ts->tv_nsec);
+    unlock_user_struct(target_ts, target_addr, 0);
+    return 0;
+}
+
+static inline abi_long host_to_target_timespec(abi_ulong target_addr,
+                                               struct timespec *host_ts)
+{
+    struct target_timespec *target_ts;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0)) {
+        return -TARGET_EFAULT;
+    }
+    __put_user(host_ts->tv_sec, &target_ts->tv_sec);
+    __put_user(host_ts->tv_nsec, &target_ts->tv_nsec);
+    unlock_user_struct(target_ts, target_addr, 1);
+    return 0;
+}
+
+static inline abi_long host_to_target_timespec64(abi_ulong target_addr,
+                                                 struct timespec *host_ts)
+{
+    struct target__kernel_timespec *target_ts;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0)) {
+        return -TARGET_EFAULT;
+    }
+    __put_user(host_ts->tv_sec, &target_ts->tv_sec);
+    __put_user(host_ts->tv_nsec, &target_ts->tv_nsec);
+    unlock_user_struct(target_ts, target_addr, 1);
+    return 0;
+}
+
 static inline abi_long copy_from_user_timezone(struct timezone *tz,
                                                abi_ulong target_tz_addr)
 {
@@ -4899,6 +4961,54 @@ static abi_long do_ioctl_kdsigaccept(const IOCTLEntry *ie, uint8_t *buf_temp,
     return get_errno(safe_ioctl(fd, ie->host_cmd, sig));
 }
 
+static abi_long do_ioctl_SIOCGSTAMP(const IOCTLEntry *ie, uint8_t *buf_temp,
+                                    int fd, int cmd, abi_long arg)
+{
+    struct timeval tv;
+    abi_long ret;
+
+    ret = get_errno(safe_ioctl(fd, SIOCGSTAMP, &tv));
+    if (is_error(ret)) {
+        return ret;
+    }
+
+    if (cmd == (int)TARGET_SIOCGSTAMP_OLD) {
+        if (copy_to_user_timeval(arg, &tv)) {
+            return -TARGET_EFAULT;
+        }
+    } else {
+        if (copy_to_user_timeval64(arg, &tv)) {
+            return -TARGET_EFAULT;
+        }
+    }
+
+    return ret;
+}
+
+static abi_long do_ioctl_SIOCGSTAMPNS(const IOCTLEntry *ie, uint8_t *buf_temp,
+                                      int fd, int cmd, abi_long arg)
+{
+    struct timespec ts;
+    abi_long ret;
+
+    ret = get_errno(safe_ioctl(fd, SIOCGSTAMPNS, &ts));
+    if (is_error(ret)) {
+        return ret;
+    }
+
+    if (cmd == (int)TARGET_SIOCGSTAMPNS_OLD) {
+        if (host_to_target_timespec(arg, &ts)) {
+            return -TARGET_EFAULT;
+        }
+    } else{
+        if (host_to_target_timespec64(arg, &ts)) {
+            return -TARGET_EFAULT;
+        }
+    }
+
+    return ret;
+}
+
 #ifdef TIOCGPTPEER
 static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp,
                                      int fd, int cmd, abi_long arg)
@@ -6271,32 +6381,6 @@ static inline abi_long target_ftruncate64(void *cpu_env, abi_long arg1,
 }
 #endif
 
-static inline abi_long target_to_host_timespec(struct timespec *host_ts,
-                                               abi_ulong target_addr)
-{
-    struct target_timespec *target_ts;
-
-    if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1))
-        return -TARGET_EFAULT;
-    __get_user(host_ts->tv_sec, &target_ts->tv_sec);
-    __get_user(host_ts->tv_nsec, &target_ts->tv_nsec);
-    unlock_user_struct(target_ts, target_addr, 0);
-    return 0;
-}
-
-static inline abi_long host_to_target_timespec(abi_ulong target_addr,
-                                               struct timespec *host_ts)
-{
-    struct target_timespec *target_ts;
-
-    if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0))
-        return -TARGET_EFAULT;
-    __put_user(host_ts->tv_sec, &target_ts->tv_sec);
-    __put_user(host_ts->tv_nsec, &target_ts->tv_nsec);
-    unlock_user_struct(target_ts, target_addr, 1);
-    return 0;
-}
-
 static inline abi_long target_to_host_itimerspec(struct itimerspec *host_itspec,
                                                  abi_ulong target_addr)
 {
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index fffa89f2564b..06622703008a 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -209,16 +209,34 @@ struct target_linger {
     abi_int l_linger;       /* How long to linger for       */
 };
 
+#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
+struct target_timeval {
+    abi_long tv_sec;
+    abi_int tv_usec;
+};
+#define target__kernel_sock_timeval target_timeval
+#else
 struct target_timeval {
     abi_long tv_sec;
     abi_long tv_usec;
 };
 
+struct target__kernel_sock_timeval {
+    abi_llong tv_sec;
+    abi_llong tv_usec;
+};
+#endif
+
 struct target_timespec {
     abi_long tv_sec;
     abi_long tv_nsec;
 };
 
+struct target__kernel_timespec {
+    abi_llong tv_sec;
+    abi_llong tv_nsec;
+};
+
 struct target_timezone {
     abi_int tz_minuteswest;
     abi_int tz_dsttime;
@@ -749,8 +767,16 @@ struct target_pollfd {
 #define TARGET_SIOCGPGRP       0x8904
 #endif
 
-#define TARGET_SIOCGSTAMP      0x8906          /* Get stamp (timeval) */
-#define TARGET_SIOCGSTAMPNS    0x8907          /* Get stamp (timespec) */
+#if defined(TARGET_SH4)
+#define TARGET_SIOCGSTAMP_OLD   TARGET_IOR('s', 100, struct target_timeval)
+#define TARGET_SIOCGSTAMPNS_OLD TARGET_IOR('s', 101, struct target_timespec)
+#else
+#define TARGET_SIOCGSTAMP_OLD   0x8906
+#define TARGET_SIOCGSTAMPNS_OLD 0x8907
+#endif
+
+#define TARGET_SIOCGSTAMP_NEW   TARGET_IOR(0x89, 0x06, abi_llong[2])
+#define TARGET_SIOCGSTAMPNS_NEW TARGET_IOR(0x89, 0x07, abi_llong[2])
 
 /* Networking ioctls */
 #define TARGET_SIOCADDRT       0x890B          /* add routing table entry */
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index b98a23b0f1b0..4e3698382629 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -14,12 +14,6 @@ STRUCT(serial_icounter_struct,
 STRUCT(sockaddr,
        TYPE_SHORT, MK_ARRAY(TYPE_CHAR, 14))
 
-STRUCT(timeval,
-       MK_ARRAY(TYPE_LONG, 2))
-
-STRUCT(timespec,
-       MK_ARRAY(TYPE_LONG, 2))
-
 STRUCT(rtentry,
        TYPE_ULONG, MK_STRUCT(STRUCT_sockaddr), MK_STRUCT(STRUCT_sockaddr), MK_STRUCT(STRUCT_sockaddr),
        TYPE_SHORT, TYPE_SHORT, TYPE_ULONG, TYPE_PTRVOID, TYPE_SHORT, TYPE_PTRVOID,
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PULL 3/3] linux-user: check valid address in access_ok()
  2019-07-17 14:54 [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches Laurent Vivier
  2019-07-17 14:54 ` [Qemu-devel] [PULL 1/3] linux-user: Fix structure target_ucontext for MIPS Laurent Vivier
  2019-07-17 14:54 ` [Qemu-devel] [PULL 2/3] linux-user: fix to handle variably sized SIOCGSTAMP with new kernels Laurent Vivier
@ 2019-07-17 14:54 ` Laurent Vivier
  2019-07-18 10:20 ` [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches Peter Maydell
  3 siblings, 0 replies; 9+ messages in thread
From: Laurent Vivier @ 2019-07-17 14:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Rémi Denis-Courmont, Aleksandar Rikalo,
	Riku Voipio, Laurent Vivier, Aleksandar Markovic, Paolo Bonzini,
	Aurelien Jarno, Richard Henderson

From: Rémi Denis-Courmont <remi@remlab.net>

Fix a crash with LTP testsuite and aarch64:

  tst_test.c:1015: INFO: Timeout per run is 0h 05m 00s
  qemu-aarch64: .../qemu/accel/tcg/translate-all.c:2522: page_check_range: Assertion `start < ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS)' failed.
  qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x60001554

page_check_range() should never be called with address outside the guest
address space. This patch adds a guest_addr_valid() check in access_ok()
to only call page_check_range() with a valid address.

Fixes: f6768aa1b4c6 ("target/arm: fix AArch64 virtual address space size")
Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Message-Id: <20190704084115.24713-1-lvivier@redhat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 include/exec/cpu_ldst.h | 4 ++++
 linux-user/qemu.h       | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
index 9de8c933031b..9151fdb042c4 100644
--- a/include/exec/cpu_ldst.h
+++ b/include/exec/cpu_ldst.h
@@ -62,7 +62,11 @@ typedef uint64_t abi_ptr;
 /* All direct uses of g2h and h2g need to go away for usermode softmmu.  */
 #define g2h(x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base))
 
+#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
+#define guest_addr_valid(x) (1)
+#else
 #define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX)
+#endif
 #define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base)
 
 static inline int guest_range_valid(unsigned long start, unsigned long len)
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index fab287b7ec50..4258e4162d26 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -456,7 +456,9 @@ extern unsigned long guest_stack_size;
 
 static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
 {
-    return page_check_range((target_ulong)addr, size,
+    return guest_addr_valid(addr) &&
+           (size == 0 || guest_addr_valid(addr + size - 1)) &&
+           page_check_range((target_ulong)addr, size,
                             (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0;
 }
 
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches
  2019-07-17 14:54 [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches Laurent Vivier
                   ` (2 preceding siblings ...)
  2019-07-17 14:54 ` [Qemu-devel] [PULL 3/3] linux-user: check valid address in access_ok() Laurent Vivier
@ 2019-07-18 10:20 ` Peter Maydell
  2019-07-18 10:40   ` Laurent Vivier
  3 siblings, 1 reply; 9+ messages in thread
From: Peter Maydell @ 2019-07-18 10:20 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: Aleksandar Rikalo, Riku Voipio, QEMU Developers,
	Aleksandar Markovic, Paolo Bonzini, Aurelien Jarno,
	Richard Henderson

On Wed, 17 Jul 2019 at 15:55, Laurent Vivier <laurent@vivier.eu> wrote:
>
> The following changes since commit a1a4d49f60d2b899620ee2be4ebb991c4a90a026:
>
>   Merge remote-tracking branch 'remotes/philmd-gitlab/tags/pflash-next-20190716' into staging (2019-07-16 17:02:44 +0100)
>
> are available in the Git repository at:
>
>   git://github.com/vivier/qemu.git tags/linux-user-for-4.1-pull-request
>
> for you to fetch changes up to ad0bcf5d59f120d546be7a2c3590afc66eea0b01:
>
>   linux-user: check valid address in access_ok() (2019-07-17 09:02:51 +0200)
>
> ----------------------------------------------------------------
> fix access_ok() to allow to run LTP on AARCH64,
> fix SIOCGSTAMP with 5.2 kernel headers,
> fix structure target_ucontext for MIPS
>
> ---------------------------------------------------------------

This causes 'make check-tcg' to produce new warnings from
running the tests (x86-64 host):

  RUN     tests for x86_64
  TEST    test-mmap (default) on x86_64
ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907
  TEST    sha1 on x86_64
ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907
  TEST    linux-test on x86_64
ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907
  TEST    testthread on x86_64
ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907
  TEST    test-x86_64 on x86_64
ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907
  TEST    test-mmap (4096 byte pages) on x86_64
ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907

thanks
-- PMM


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches
  2019-07-18 10:20 ` [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches Peter Maydell
@ 2019-07-18 10:40   ` Laurent Vivier
  2019-07-18 11:00     ` Peter Maydell
  0 siblings, 1 reply; 9+ messages in thread
From: Laurent Vivier @ 2019-07-18 10:40 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Aleksandar Rikalo, Riku Voipio, QEMU Developers,
	Aleksandar Markovic, Paolo Bonzini, Aurelien Jarno,
	Richard Henderson

Le 18/07/2019 à 12:20, Peter Maydell a écrit :
> On Wed, 17 Jul 2019 at 15:55, Laurent Vivier <laurent@vivier.eu> wrote:
>>
>> The following changes since commit a1a4d49f60d2b899620ee2be4ebb991c4a90a026:
>>
>>   Merge remote-tracking branch 'remotes/philmd-gitlab/tags/pflash-next-20190716' into staging (2019-07-16 17:02:44 +0100)
>>
>> are available in the Git repository at:
>>
>>   git://github.com/vivier/qemu.git tags/linux-user-for-4.1-pull-request
>>
>> for you to fetch changes up to ad0bcf5d59f120d546be7a2c3590afc66eea0b01:
>>
>>   linux-user: check valid address in access_ok() (2019-07-17 09:02:51 +0200)
>>
>> ----------------------------------------------------------------
>> fix access_ok() to allow to run LTP on AARCH64,
>> fix SIOCGSTAMP with 5.2 kernel headers,
>> fix structure target_ucontext for MIPS
>>
>> ---------------------------------------------------------------
> 
> This causes 'make check-tcg' to produce new warnings from
> running the tests (x86-64 host):
> 
>   RUN     tests for x86_64
>   TEST    test-mmap (default) on x86_64
> ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
> ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907
>   TEST    sha1 on x86_64
> ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
> ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907
>   TEST    linux-test on x86_64
> ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
> ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907
>   TEST    testthread on x86_64
> ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
> ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907
>   TEST    test-x86_64 on x86_64
> ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
> ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907
>   TEST    test-mmap (4096 byte pages) on x86_64
> ERROR: ioctl(IOCGSTAMP_NEW): target=0x80108906 host=0x8906
> ERROR: ioctl(IOCGSTAMPNS_NEW): target=0x80108907 host=0x8907

It comes from linux-user/syscall.c:

 6328         /* automatic consistency check if same arch */
 6329 #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
 6330     (defined(__x86_64__) && defined(TARGET_X86_64))
 6331         if (unlikely(ie->target_cmd != ie->host_cmd)) {
 6332             fprintf(stderr, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
 6333                     ie->name, ie->target_cmd, ie->host_cmd);
 6334         }
 6335 #endif

because of:

+  { TARGET_SIOCGSTAMP_OLD, SIOCGSTAMP, "IOCGSTAMP_OLD", IOC_R, \
+    do_ioctl_SIOCGSTAMP },
+  { TARGET_SIOCGSTAMPNS_OLD, SIOCGSTAMPNS, "IOCGSTAMPNS_OLD", IOC_R, \
+    do_ioctl_SIOCGSTAMPNS },
+  { TARGET_SIOCGSTAMP_NEW, SIOCGSTAMP, "IOCGSTAMP_NEW", IOC_R, \
+    do_ioctl_SIOCGSTAMP },
+  { TARGET_SIOCGSTAMPNS_NEW, SIOCGSTAMPNS, "IOCGSTAMPNS_NEW", IOC_R, \
+    do_ioctl_SIOCGSTAMPNS },

As the host_cmd is not used, the simplest way to fix that is

+  { TARGET_SIOCGSTAMP_OLD, TARGET_SIOCGSTAMP_OLD, "IOCGSTAMP_OLD", IOC_R, \
+    do_ioctl_SIOCGSTAMP },
+  { TARGET_SIOCGSTAMPNS_OLD, TARGET_SIOCGSTAMPNS_OLD, "IOCGSTAMPNS_OLD", IOC_R, \
+    do_ioctl_SIOCGSTAMPNS },
+  { TARGET_SIOCGSTAMP_NEW, TARGET_SIOCGSTAMP_NEW, "IOCGSTAMP_NEW", IOC_R, \
+    do_ioctl_SIOCGSTAMP },
+  { TARGET_SIOCGSTAMPNS_NEW, TARGET_SIOCGSTAMPNS_NEW, "IOCGSTAMPNS_NEW", IOC_R, \
+    do_ioctl_SIOCGSTAMPNS },

As SIOCGSTAMP_OLD and SIOCGSTAMP_NEW can be undefined on the host (and not needed 
because we always use SIOCGSTAMP and SIOCGSTAMPNS)

Thanks,
Laurent


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches
  2019-07-18 10:40   ` Laurent Vivier
@ 2019-07-18 11:00     ` Peter Maydell
  2019-07-18 11:10       ` Laurent Vivier
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Maydell @ 2019-07-18 11:00 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: Aleksandar Rikalo, Riku Voipio, QEMU Developers,
	Aleksandar Markovic, Paolo Bonzini, Aurelien Jarno,
	Richard Henderson

On Thu, 18 Jul 2019 at 11:40, Laurent Vivier <laurent@vivier.eu> wrote:
> It comes from linux-user/syscall.c:
>
>  6328         /* automatic consistency check if same arch */
>  6329 #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
>  6330     (defined(__x86_64__) && defined(TARGET_X86_64))
>  6331         if (unlikely(ie->target_cmd != ie->host_cmd)) {
>  6332             fprintf(stderr, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
>  6333                     ie->name, ie->target_cmd, ie->host_cmd);
>  6334         }
>  6335 #endif
>
> because of:
>
> +  { TARGET_SIOCGSTAMP_OLD, SIOCGSTAMP, "IOCGSTAMP_OLD", IOC_R, \
> +    do_ioctl_SIOCGSTAMP },
> +  { TARGET_SIOCGSTAMPNS_OLD, SIOCGSTAMPNS, "IOCGSTAMPNS_OLD", IOC_R, \
> +    do_ioctl_SIOCGSTAMPNS },
> +  { TARGET_SIOCGSTAMP_NEW, SIOCGSTAMP, "IOCGSTAMP_NEW", IOC_R, \
> +    do_ioctl_SIOCGSTAMP },
> +  { TARGET_SIOCGSTAMPNS_NEW, SIOCGSTAMPNS, "IOCGSTAMPNS_NEW", IOC_R, \
> +    do_ioctl_SIOCGSTAMPNS },
>
> As the host_cmd is not used, the simplest way to fix that is
>
> +  { TARGET_SIOCGSTAMP_OLD, TARGET_SIOCGSTAMP_OLD, "IOCGSTAMP_OLD", IOC_R, \
> +    do_ioctl_SIOCGSTAMP },
> +  { TARGET_SIOCGSTAMPNS_OLD, TARGET_SIOCGSTAMPNS_OLD, "IOCGSTAMPNS_OLD", IOC_R, \
> +    do_ioctl_SIOCGSTAMPNS },
> +  { TARGET_SIOCGSTAMP_NEW, TARGET_SIOCGSTAMP_NEW, "IOCGSTAMP_NEW", IOC_R, \
> +    do_ioctl_SIOCGSTAMP },
> +  { TARGET_SIOCGSTAMPNS_NEW, TARGET_SIOCGSTAMPNS_NEW, "IOCGSTAMPNS_NEW", IOC_R, \
> +    do_ioctl_SIOCGSTAMPNS },
>
> As SIOCGSTAMP_OLD and SIOCGSTAMP_NEW can be undefined on the host (and not needed
> because we always use SIOCGSTAMP and SIOCGSTAMPNS)

So we don't use the host_cmd because we have a custom do_ioctl_foo
function which doesn't look at that field?

Sounds OK, but please include a comment explaining why.

PS: why didn't you use IOCTL_SPECIAL() rather than hand-written
array entries? None of the other ioctls.h entries do that.
Of course now we're trying to sidestep the consistency check
we can't use the macro, but it wolud have been fine otherwise.
It also would get the names of the ioctls in the string form
right -- they are all missing the initial "S" here.

Perhaps for 4.2 it might be worth considering having a
macro for "IOCTL_SPECIAL but skip the consistency check"
to be a bit less hacky here.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches
  2019-07-18 11:00     ` Peter Maydell
@ 2019-07-18 11:10       ` Laurent Vivier
  2019-07-18 11:26         ` Peter Maydell
  0 siblings, 1 reply; 9+ messages in thread
From: Laurent Vivier @ 2019-07-18 11:10 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Aleksandar Rikalo, Riku Voipio, QEMU Developers,
	Aleksandar Markovic, Paolo Bonzini, Aurelien Jarno,
	Richard Henderson

Le 18/07/2019 à 13:00, Peter Maydell a écrit :
> On Thu, 18 Jul 2019 at 11:40, Laurent Vivier <laurent@vivier.eu> wrote:
>> It comes from linux-user/syscall.c:
>>
>>  6328         /* automatic consistency check if same arch */
>>  6329 #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
>>  6330     (defined(__x86_64__) && defined(TARGET_X86_64))
>>  6331         if (unlikely(ie->target_cmd != ie->host_cmd)) {
>>  6332             fprintf(stderr, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
>>  6333                     ie->name, ie->target_cmd, ie->host_cmd);
>>  6334         }
>>  6335 #endif
>>
>> because of:
>>
>> +  { TARGET_SIOCGSTAMP_OLD, SIOCGSTAMP, "IOCGSTAMP_OLD", IOC_R, \
>> +    do_ioctl_SIOCGSTAMP },
>> +  { TARGET_SIOCGSTAMPNS_OLD, SIOCGSTAMPNS, "IOCGSTAMPNS_OLD", IOC_R, \
>> +    do_ioctl_SIOCGSTAMPNS },
>> +  { TARGET_SIOCGSTAMP_NEW, SIOCGSTAMP, "IOCGSTAMP_NEW", IOC_R, \
>> +    do_ioctl_SIOCGSTAMP },
>> +  { TARGET_SIOCGSTAMPNS_NEW, SIOCGSTAMPNS, "IOCGSTAMPNS_NEW", IOC_R, \
>> +    do_ioctl_SIOCGSTAMPNS },
>>
>> As the host_cmd is not used, the simplest way to fix that is
>>
>> +  { TARGET_SIOCGSTAMP_OLD, TARGET_SIOCGSTAMP_OLD, "IOCGSTAMP_OLD", IOC_R, \
>> +    do_ioctl_SIOCGSTAMP },
>> +  { TARGET_SIOCGSTAMPNS_OLD, TARGET_SIOCGSTAMPNS_OLD, "IOCGSTAMPNS_OLD", IOC_R, \
>> +    do_ioctl_SIOCGSTAMPNS },
>> +  { TARGET_SIOCGSTAMP_NEW, TARGET_SIOCGSTAMP_NEW, "IOCGSTAMP_NEW", IOC_R, \
>> +    do_ioctl_SIOCGSTAMP },
>> +  { TARGET_SIOCGSTAMPNS_NEW, TARGET_SIOCGSTAMPNS_NEW, "IOCGSTAMPNS_NEW", IOC_R, \
>> +    do_ioctl_SIOCGSTAMPNS },
>>
>> As SIOCGSTAMP_OLD and SIOCGSTAMP_NEW can be undefined on the host (and not needed
>> because we always use SIOCGSTAMP and SIOCGSTAMPNS)
> 
> So we don't use the host_cmd because we have a custom do_ioctl_foo
> function which doesn't look at that field?

Yes

> Sounds OK, but please include a comment explaining why.

OK

> PS: why didn't you use IOCTL_SPECIAL() rather than hand-written
> array entries? None of the other ioctls.h entries do that.

because IOCTL_SPECIAL() extracts the host command from the parameter and
so we would need the _NEW and _OLD definitions on the host, and they are
not available with kernel before 5.2

> Of course now we're trying to sidestep the consistency check
> we can't use the macro, but it wolud have been fine otherwise.
> It also would get the names of the ioctls in the string form
> right -- they are all missing the initial "S" here.

oh, yes. I fix that too.

> Perhaps for 4.2 it might be worth considering having a
> macro for "IOCTL_SPECIAL but skip the consistency check"
> to be a bit less hacky here.

Perhaps, rather than using TARGET_XXX in host_cmd I can use NULL and
check for NULL in consistency check?

Do you think we should defer the whole patch after 4.1 release?
But then the build of 4.1 will be broken with 5.2+ kernel

Thanks,
Laurent



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches
  2019-07-18 11:10       ` Laurent Vivier
@ 2019-07-18 11:26         ` Peter Maydell
  0 siblings, 0 replies; 9+ messages in thread
From: Peter Maydell @ 2019-07-18 11:26 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: Aleksandar Rikalo, Riku Voipio, QEMU Developers,
	Aleksandar Markovic, Paolo Bonzini, Aurelien Jarno,
	Richard Henderson

On Thu, 18 Jul 2019 at 12:10, Laurent Vivier <laurent@vivier.eu> wrote:
> Do you think we should defer the whole patch after 4.1 release?
> But then the build of 4.1 will be broken with 5.2+ kernel

I think this is worth putting into 4.1; but we should
look at maybe tidying up the loose ends for 4.2.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-07-18 11:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17 14:54 [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches Laurent Vivier
2019-07-17 14:54 ` [Qemu-devel] [PULL 1/3] linux-user: Fix structure target_ucontext for MIPS Laurent Vivier
2019-07-17 14:54 ` [Qemu-devel] [PULL 2/3] linux-user: fix to handle variably sized SIOCGSTAMP with new kernels Laurent Vivier
2019-07-17 14:54 ` [Qemu-devel] [PULL 3/3] linux-user: check valid address in access_ok() Laurent Vivier
2019-07-18 10:20 ` [Qemu-devel] [PULL 0/3] Linux user for 4.1 patches Peter Maydell
2019-07-18 10:40   ` Laurent Vivier
2019-07-18 11:00     ` Peter Maydell
2019-07-18 11:10       ` Laurent Vivier
2019-07-18 11:26         ` Peter Maydell

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).