qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/6] Linux user for 5.0 patches
@ 2020-03-26  7:23 Laurent Vivier
  2020-03-26  7:23 ` [PULL 1/6] linux-user, configure: fix (again) syscall_nr.h dependencies cleanup Laurent Vivier
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Laurent Vivier @ 2020-03-26  7:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier

The following changes since commit 736cf607e40674776d752acc201f565723e86045:

  Update version for v5.0.0-rc0 release (2020-03-24 17:50:00 +0000)

are available in the Git repository at:

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

for you to fetch changes up to a52f5f87bece827a338d6eb3332e3def86fb9c33:

  linux-user: Flush out implementation of gettimeofday (2020-03-26 08:08:54 +0100)

----------------------------------------------------------------
Emulate x86_64 vsyscalls
Fix syscall_nr.h cleanup

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

Laurent Vivier (1):
  linux-user, configure: fix (again) syscall_nr.h dependencies cleanup

Richard Henderson (5):
  target/i386: Renumber EXCP_SYSCALL
  linux-user/i386: Split out gen_signal
  linux-user/i386: Emulate x86_64 vsyscalls
  linux-user: Add x86_64 vsyscall page to /proc/self/maps
  linux-user: Flush out implementation of gettimeofday

 configure                  |   8 +-
 linux-user/i386/cpu_loop.c | 201 ++++++++++++++++++++++++++-----------
 linux-user/syscall.c       |  39 ++++++-
 target/i386/cpu.h          |  12 ++-
 target/i386/translate.c    |  14 ++-
 5 files changed, 205 insertions(+), 69 deletions(-)

-- 
2.25.1



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

* [PULL 1/6] linux-user, configure: fix (again) syscall_nr.h dependencies cleanup
  2020-03-26  7:23 [PULL 0/6] Linux user for 5.0 patches Laurent Vivier
@ 2020-03-26  7:23 ` Laurent Vivier
  2020-03-26  7:23 ` [PULL 2/6] target/i386: Renumber EXCP_SYSCALL Laurent Vivier
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2020-03-26  7:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio, Richard Henderson, Laurent Vivier

This patch fixes two problems:
- it cleanups linux-user variants (for instance ppc64-linux-user
  and ppc64le-linux-user)
- it removes the .o file when it removes the .d file, otherwise the .o
  file is never updated

Fixes: 5f29856b852d ("linux-user, configure: improve syscall_nr.h dependencies checking")
Fixes: 4d6a835dea47 ("linux-user: introduce parameters to generate syscall_nr.h")
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200325075757.1959961-1-laurent@vivier.eu>
---
 configure | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index da09c3589572..89fe881dd46f 100755
--- a/configure
+++ b/configure
@@ -1910,9 +1910,11 @@ for arch in alpha hppa m68k xtensa sh4 microblaze arm ppc s390x sparc sparc64 \
     # remove the file if it has been generated in the source directory
     rm -f "${source_path}/linux-user/${arch}/syscall_nr.h"
     # remove the dependency files
-    test -d ${arch}-linux-user && find ${arch}-linux-user -type f -name "*.d" \
-         -exec grep -q "${source_path}/linux-user/${arch}/syscall_nr.h" {} \; \
-         -exec rm {} \;
+    for target in ${arch}*-linux-user ; do
+        test -d "${target}" && find "${target}" -type f -name "*.d" \
+             -exec grep -q "${source_path}/linux-user/${arch}/syscall_nr.h" {} \; \
+             -print | while read file ; do rm "${file}" "${file%.d}.o" ; done
+    done
 done
 
 if test -z "$python"
-- 
2.25.1



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

* [PULL 2/6] target/i386: Renumber EXCP_SYSCALL
  2020-03-26  7:23 [PULL 0/6] Linux user for 5.0 patches Laurent Vivier
  2020-03-26  7:23 ` [PULL 1/6] linux-user, configure: fix (again) syscall_nr.h dependencies cleanup Laurent Vivier
@ 2020-03-26  7:23 ` Laurent Vivier
  2020-03-26  7:23 ` [PULL 3/6] linux-user/i386: Split out gen_signal Laurent Vivier
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2020-03-26  7:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé,
	Riku Voipio, Richard Henderson, Laurent Vivier, Paolo Bonzini,
	Alex Bennée

From: Richard Henderson <richard.henderson@linaro.org>

We are not short of numbers for EXCP_*.  There is no need to confuse things
by having EXCP_VMEXIT and EXCP_SYSCALL overlap, even though the former is
only used for system mode and the latter is only used for user mode.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200213032223.14643-2-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 target/i386/cpu.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 60d797d5941f..49ecc23104c9 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1001,9 +1001,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];
 #define EXCP11_ALGN	17
 #define EXCP12_MCHK	18
 
-#define EXCP_SYSCALL    0x100 /* only happens in user only emulation
-                                 for syscall instruction */
-#define EXCP_VMEXIT     0x100
+#define EXCP_VMEXIT     0x100 /* only for system emulation */
+#define EXCP_SYSCALL    0x101 /* only for user emulation */
 
 /* i386-specific interrupt pending bits.  */
 #define CPU_INTERRUPT_POLL      CPU_INTERRUPT_TGT_EXT_1
-- 
2.25.1



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

* [PULL 3/6] linux-user/i386: Split out gen_signal
  2020-03-26  7:23 [PULL 0/6] Linux user for 5.0 patches Laurent Vivier
  2020-03-26  7:23 ` [PULL 1/6] linux-user, configure: fix (again) syscall_nr.h dependencies cleanup Laurent Vivier
  2020-03-26  7:23 ` [PULL 2/6] target/i386: Renumber EXCP_SYSCALL Laurent Vivier
@ 2020-03-26  7:23 ` Laurent Vivier
  2020-03-26  7:23 ` [PULL 4/6] linux-user/i386: Emulate x86_64 vsyscalls Laurent Vivier
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2020-03-26  7:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé,
	Riku Voipio, Richard Henderson, Laurent Vivier, Paolo Bonzini,
	Alex Bennée

From: Richard Henderson <richard.henderson@linaro.org>

This is a bit tidier than open-coding the 5 lines necessary
to initialize the target_siginfo_t.  In addition, this zeros
the remaining bytes of the target_siginfo_t, rather than
passing in garbage.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200213032223.14643-3-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/i386/cpu_loop.c | 93 ++++++++++++++------------------------
 1 file changed, 33 insertions(+), 60 deletions(-)

diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
index 024b6f4d588c..e217cca5ee1e 100644
--- a/linux-user/i386/cpu_loop.c
+++ b/linux-user/i386/cpu_loop.c
@@ -81,13 +81,23 @@ static void set_idt(int n, unsigned int dpl)
 }
 #endif
 
+static void gen_signal(CPUX86State *env, int sig, int code, abi_ptr addr)
+{
+    target_siginfo_t info = {
+        .si_signo = sig,
+        .si_code = code,
+        ._sifields._sigfault._addr = addr
+    };
+
+    queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+}
+
 void cpu_loop(CPUX86State *env)
 {
     CPUState *cs = env_cpu(env);
     int trapnr;
     abi_ulong pc;
     abi_ulong ret;
-    target_siginfo_t info;
 
     for(;;) {
         cpu_exec_start(cs);
@@ -134,70 +144,45 @@ void cpu_loop(CPUX86State *env)
 #endif
         case EXCP0B_NOSEG:
         case EXCP0C_STACK:
-            info.si_signo = TARGET_SIGBUS;
-            info.si_errno = 0;
-            info.si_code = TARGET_SI_KERNEL;
-            info._sifields._sigfault._addr = 0;
-            queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+            gen_signal(env, TARGET_SIGBUS, TARGET_SI_KERNEL, 0);
             break;
         case EXCP0D_GPF:
             /* XXX: potential problem if ABI32 */
 #ifndef TARGET_X86_64
             if (env->eflags & VM_MASK) {
                 handle_vm86_fault(env);
-            } else
-#endif
-            {
-                info.si_signo = TARGET_SIGSEGV;
-                info.si_errno = 0;
-                info.si_code = TARGET_SI_KERNEL;
-                info._sifields._sigfault._addr = 0;
-                queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+                break;
             }
+#endif
+            gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
             break;
         case EXCP0E_PAGE:
-            info.si_signo = TARGET_SIGSEGV;
-            info.si_errno = 0;
-            if (!(env->error_code & 1))
-                info.si_code = TARGET_SEGV_MAPERR;
-            else
-                info.si_code = TARGET_SEGV_ACCERR;
-            info._sifields._sigfault._addr = env->cr[2];
-            queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+            gen_signal(env, TARGET_SIGSEGV,
+                       (env->error_code & 1 ?
+                        TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR),
+                       env->cr[2]);
             break;
         case EXCP00_DIVZ:
 #ifndef TARGET_X86_64
             if (env->eflags & VM_MASK) {
                 handle_vm86_trap(env, trapnr);
-            } else
-#endif
-            {
-                /* division by zero */
-                info.si_signo = TARGET_SIGFPE;
-                info.si_errno = 0;
-                info.si_code = TARGET_FPE_INTDIV;
-                info._sifields._sigfault._addr = env->eip;
-                queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+                break;
             }
+#endif
+            gen_signal(env, TARGET_SIGFPE, TARGET_FPE_INTDIV, env->eip);
             break;
         case EXCP01_DB:
         case EXCP03_INT3:
 #ifndef TARGET_X86_64
             if (env->eflags & VM_MASK) {
                 handle_vm86_trap(env, trapnr);
-            } else
+                break;
+            }
 #endif
-            {
-                info.si_signo = TARGET_SIGTRAP;
-                info.si_errno = 0;
-                if (trapnr == EXCP01_DB) {
-                    info.si_code = TARGET_TRAP_BRKPT;
-                    info._sifields._sigfault._addr = env->eip;
-                } else {
-                    info.si_code = TARGET_SI_KERNEL;
-                    info._sifields._sigfault._addr = 0;
-                }
-                queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+            if (trapnr == EXCP01_DB) {
+                gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip);
+            } else {
+                gen_signal(env, TARGET_SIGTRAP, TARGET_SI_KERNEL, 0);
             }
             break;
         case EXCP04_INTO:
@@ -205,31 +190,19 @@ void cpu_loop(CPUX86State *env)
 #ifndef TARGET_X86_64
             if (env->eflags & VM_MASK) {
                 handle_vm86_trap(env, trapnr);
-            } else
-#endif
-            {
-                info.si_signo = TARGET_SIGSEGV;
-                info.si_errno = 0;
-                info.si_code = TARGET_SI_KERNEL;
-                info._sifields._sigfault._addr = 0;
-                queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+                break;
             }
+#endif
+            gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
             break;
         case EXCP06_ILLOP:
-            info.si_signo = TARGET_SIGILL;
-            info.si_errno = 0;
-            info.si_code = TARGET_ILL_ILLOPN;
-            info._sifields._sigfault._addr = env->eip;
-            queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+            gen_signal(env, TARGET_SIGILL, TARGET_ILL_ILLOPN, env->eip);
             break;
         case EXCP_INTERRUPT:
             /* just indicate that signals should be handled asap */
             break;
         case EXCP_DEBUG:
-            info.si_signo = TARGET_SIGTRAP;
-            info.si_errno = 0;
-            info.si_code = TARGET_TRAP_BRKPT;
-            queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+            gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, 0);
             break;
         case EXCP_ATOMIC:
             cpu_exec_step_atomic(cs);
-- 
2.25.1



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

* [PULL 4/6] linux-user/i386: Emulate x86_64 vsyscalls
  2020-03-26  7:23 [PULL 0/6] Linux user for 5.0 patches Laurent Vivier
                   ` (2 preceding siblings ...)
  2020-03-26  7:23 ` [PULL 3/6] linux-user/i386: Split out gen_signal Laurent Vivier
@ 2020-03-26  7:23 ` Laurent Vivier
  2020-03-26  7:23 ` [PULL 5/6] linux-user: Add x86_64 vsyscall page to /proc/self/maps Laurent Vivier
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2020-03-26  7:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Riku Voipio, Richard Henderson, Laurent Vivier

From: Richard Henderson <richard.henderson@linaro.org>

Notice the magic page during translate, much like we already
do for the arm32 commpage.  At runtime, raise an exception to
return cpu_loop for emulation.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200213032223.14643-4-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/i386/cpu_loop.c | 108 +++++++++++++++++++++++++++++++++++++
 target/i386/cpu.h          |   7 +++
 target/i386/translate.c    |  14 ++++-
 3 files changed, 128 insertions(+), 1 deletion(-)

diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
index e217cca5ee1e..70cde417e605 100644
--- a/linux-user/i386/cpu_loop.c
+++ b/linux-user/i386/cpu_loop.c
@@ -92,6 +92,109 @@ static void gen_signal(CPUX86State *env, int sig, int code, abi_ptr addr)
     queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
 }
 
+#ifdef TARGET_X86_64
+static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, size_t len)
+{
+    /*
+     * For all the vsyscalls, NULL means "don't write anything" not
+     * "write it at address 0".
+     */
+    if (addr == 0 || access_ok(VERIFY_WRITE, addr, len)) {
+        return true;
+    }
+
+    env->error_code = PG_ERROR_W_MASK | PG_ERROR_U_MASK;
+    gen_signal(env, TARGET_SIGSEGV, TARGET_SEGV_MAPERR, addr);
+    return false;
+}
+
+/*
+ * Since v3.1, the kernel traps and emulates the vsyscall page.
+ * Entry points other than the official generate SIGSEGV.
+ */
+static void emulate_vsyscall(CPUX86State *env)
+{
+    int syscall;
+    abi_ulong ret;
+    uint64_t caller;
+
+    /*
+     * Validate the entry point.  We have already validated the page
+     * during translation to get here; now verify the offset.
+     */
+    switch (env->eip & ~TARGET_PAGE_MASK) {
+    case 0x000:
+        syscall = TARGET_NR_gettimeofday;
+        break;
+    case 0x400:
+        syscall = TARGET_NR_time;
+        break;
+    case 0x800:
+        syscall = TARGET_NR_getcpu;
+        break;
+    default:
+        goto sigsegv;
+    }
+
+    /*
+     * Validate the return address.
+     * Note that the kernel treats this the same as an invalid entry point.
+     */
+    if (get_user_u64(caller, env->regs[R_ESP])) {
+        goto sigsegv;
+    }
+
+    /*
+     * Validate the the pointer arguments.
+     */
+    switch (syscall) {
+    case TARGET_NR_gettimeofday:
+        if (!write_ok_or_segv(env, env->regs[R_EDI],
+                              sizeof(struct target_timeval)) ||
+            !write_ok_or_segv(env, env->regs[R_ESI],
+                              sizeof(struct target_timezone))) {
+            return;
+        }
+        break;
+    case TARGET_NR_time:
+        if (!write_ok_or_segv(env, env->regs[R_EDI], sizeof(abi_long))) {
+            return;
+        }
+        break;
+    case TARGET_NR_getcpu:
+        if (!write_ok_or_segv(env, env->regs[R_EDI], sizeof(uint32_t)) ||
+            !write_ok_or_segv(env, env->regs[R_ESI], sizeof(uint32_t))) {
+            return;
+        }
+        break;
+    default:
+        g_assert_not_reached();
+    }
+
+    /*
+     * Perform the syscall.  None of the vsyscalls should need restarting.
+     */
+    ret = do_syscall(env, syscall, env->regs[R_EDI], env->regs[R_ESI],
+                     env->regs[R_EDX], env->regs[10], env->regs[8],
+                     env->regs[9], 0, 0);
+    g_assert(ret != -TARGET_ERESTARTSYS);
+    g_assert(ret != -TARGET_QEMU_ESIGRETURN);
+    if (ret == -TARGET_EFAULT) {
+        goto sigsegv;
+    }
+    env->regs[R_EAX] = ret;
+
+    /* Emulate a ret instruction to leave the vsyscall page.  */
+    env->eip = caller;
+    env->regs[R_ESP] += 8;
+    return;
+
+ sigsegv:
+    /* Like force_sig(SIGSEGV).  */
+    gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
+}
+#endif
+
 void cpu_loop(CPUX86State *env)
 {
     CPUState *cs = env_cpu(env);
@@ -141,6 +244,11 @@ void cpu_loop(CPUX86State *env)
                 env->regs[R_EAX] = ret;
             }
             break;
+#endif
+#ifdef TARGET_X86_64
+        case EXCP_VSYSCALL:
+            emulate_vsyscall(env);
+            break;
 #endif
         case EXCP0B_NOSEG:
         case EXCP0C_STACK:
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 49ecc23104c9..9af1b0c12e8e 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1003,6 +1003,7 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];
 
 #define EXCP_VMEXIT     0x100 /* only for system emulation */
 #define EXCP_SYSCALL    0x101 /* only for user emulation */
+#define EXCP_VSYSCALL   0x102 /* only for user emulation */
 
 /* i386-specific interrupt pending bits.  */
 #define CPU_INTERRUPT_POLL      CPU_INTERRUPT_TGT_EXT_1
@@ -2218,4 +2219,10 @@ static inline bool hyperv_feat_enabled(X86CPU *cpu, int feat)
     return !!(cpu->hyperv_features & BIT(feat));
 }
 
+#if defined(TARGET_X86_64) && \
+    defined(CONFIG_USER_ONLY) && \
+    defined(CONFIG_LINUX)
+# define TARGET_VSYSCALL_PAGE  (UINT64_C(-10) << 20)
+#endif
+
 #endif /* I386_CPU_H */
diff --git a/target/i386/translate.c b/target/i386/translate.c
index d9af8f4078b3..5e5dbb41b0ce 100644
--- a/target/i386/translate.c
+++ b/target/i386/translate.c
@@ -8555,7 +8555,19 @@ static bool i386_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu,
 static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
 {
     DisasContext *dc = container_of(dcbase, DisasContext, base);
-    target_ulong pc_next = disas_insn(dc, cpu);
+    target_ulong pc_next;
+
+#ifdef TARGET_VSYSCALL_PAGE
+    /*
+     * Detect entry into the vsyscall page and invoke the syscall.
+     */
+    if ((dc->base.pc_next & TARGET_PAGE_MASK) == TARGET_VSYSCALL_PAGE) {
+        gen_exception(dc, EXCP_VSYSCALL, dc->base.pc_next);
+        return;
+    }
+#endif
+
+    pc_next = disas_insn(dc, cpu);
 
     if (dc->tf || (dc->base.tb->flags & HF_INHIBIT_IRQ_MASK)) {
         /* if single step mode, we generate only one instruction and
-- 
2.25.1



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

* [PULL 5/6] linux-user: Add x86_64 vsyscall page to /proc/self/maps
  2020-03-26  7:23 [PULL 0/6] Linux user for 5.0 patches Laurent Vivier
                   ` (3 preceding siblings ...)
  2020-03-26  7:23 ` [PULL 4/6] linux-user/i386: Emulate x86_64 vsyscalls Laurent Vivier
@ 2020-03-26  7:23 ` Laurent Vivier
  2020-03-26  7:23 ` [PULL 6/6] linux-user: Flush out implementation of gettimeofday Laurent Vivier
  2020-03-26 15:42 ` [PULL 0/6] Linux user for 5.0 patches Peter Maydell
  6 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2020-03-26  7:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio, Richard Henderson, Laurent Vivier

From: Richard Henderson <richard.henderson@linaro.org>

The page isn't (necessarily) present in the host /proc/self/maps,
and even if it might be it isn't present in page_flags, and even
if it was it might not have the same set of page permissions.

The easiest thing to do, particularly when it comes to the
"[vsyscall]" note at the end of line, is to special case it.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200213032223.14643-5-richard.henderson@linaro.org>
[lv: remove trailing space]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 35f414666243..dbdd56e42077 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7144,6 +7144,16 @@ static int open_self_maps(void *cpu_env, int fd)
         }
     }
 
+#ifdef TARGET_VSYSCALL_PAGE
+    /*
+     * We only support execution from the vsyscall page.
+     * This is as if CONFIG_LEGACY_VSYSCALL_XONLY=y from v5.3.
+     */
+    dprintf(fd, TARGET_FMT_lx "-" TARGET_FMT_lx
+            " --xp 00000000 00:00 0 [vsyscall]\n",
+            TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE);
+#endif
+
     free(line);
     fclose(fp);
 
-- 
2.25.1



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

* [PULL 6/6] linux-user: Flush out implementation of gettimeofday
  2020-03-26  7:23 [PULL 0/6] Linux user for 5.0 patches Laurent Vivier
                   ` (4 preceding siblings ...)
  2020-03-26  7:23 ` [PULL 5/6] linux-user: Add x86_64 vsyscall page to /proc/self/maps Laurent Vivier
@ 2020-03-26  7:23 ` Laurent Vivier
  2020-03-26 15:42 ` [PULL 0/6] Linux user for 5.0 patches Peter Maydell
  6 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2020-03-26  7:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alex Bennée, Riku Voipio, Richard Henderson, Laurent Vivier,
	Philippe Mathieu-Daudé

From: Richard Henderson <richard.henderson@linaro.org>

The first argument, timeval, is allowed to be NULL.

The second argument, timezone, was missing.  While its use is
deprecated, it is still present in the syscall.

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200213032223.14643-6-richard.henderson@linaro.org>
[lv: add "#if defined(TARGET_NR_gettimeofday)"]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index dbdd56e42077..49395dcea978 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1273,6 +1273,25 @@ static inline abi_long host_to_target_timespec64(abi_ulong target_addr,
     return 0;
 }
 
+#if defined(TARGET_NR_gettimeofday)
+static inline abi_long copy_to_user_timezone(abi_ulong target_tz_addr,
+                                             struct timezone *tz)
+{
+    struct target_timezone *target_tz;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_tz, target_tz_addr, 1)) {
+        return -TARGET_EFAULT;
+    }
+
+    __put_user(tz->tz_minuteswest, &target_tz->tz_minuteswest);
+    __put_user(tz->tz_dsttime, &target_tz->tz_dsttime);
+
+    unlock_user_struct(target_tz, target_tz_addr, 1);
+
+    return 0;
+}
+#endif
+
 #if defined(TARGET_NR_settimeofday)
 static inline abi_long copy_from_user_timezone(struct timezone *tz,
                                                abi_ulong target_tz_addr)
@@ -8710,10 +8729,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_gettimeofday:
         {
             struct timeval tv;
-            ret = get_errno(gettimeofday(&tv, NULL));
+            struct timezone tz;
+
+            ret = get_errno(gettimeofday(&tv, &tz));
             if (!is_error(ret)) {
-                if (copy_to_user_timeval(arg1, &tv))
+                if (arg1 && copy_to_user_timeval(arg1, &tv)) {
+                    return -TARGET_EFAULT;
+                }
+                if (arg2 && copy_to_user_timezone(arg2, &tz)) {
                     return -TARGET_EFAULT;
+                }
             }
         }
         return ret;
-- 
2.25.1



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

* Re: [PULL 0/6] Linux user for 5.0 patches
  2020-03-26  7:23 [PULL 0/6] Linux user for 5.0 patches Laurent Vivier
                   ` (5 preceding siblings ...)
  2020-03-26  7:23 ` [PULL 6/6] linux-user: Flush out implementation of gettimeofday Laurent Vivier
@ 2020-03-26 15:42 ` Peter Maydell
  2020-03-26 16:43   ` Laurent Vivier
  6 siblings, 1 reply; 10+ messages in thread
From: Peter Maydell @ 2020-03-26 15:42 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Riku Voipio, QEMU Developers

On Thu, 26 Mar 2020 at 07:24, Laurent Vivier <laurent@vivier.eu> wrote:
>
> The following changes since commit 736cf607e40674776d752acc201f565723e86045:
>
>   Update version for v5.0.0-rc0 release (2020-03-24 17:50:00 +0000)
>
> are available in the Git repository at:
>
>   git://github.com/vivier/qemu.git tags/linux-user-for-5.0-pull-request
>
> for you to fetch changes up to a52f5f87bece827a338d6eb3332e3def86fb9c33:
>
>   linux-user: Flush out implementation of gettimeofday (2020-03-26 08:08:54 +0100)
>
> ----------------------------------------------------------------
> Emulate x86_64 vsyscalls
> Fix syscall_nr.h cleanup
>
> ----------------------------------------------------------------

Still fails :-(

/home/petmay01/linaro/qemu-for-merges/build/all-linux-static/x86_64-linux-user/qemu-x86_64
-L ./gnemul/qemu-x86_64 x86_64/ls -l dummyfile
qemu: 0x40008117e9: unhandled CPU exception 0x101 - aborting
RAX=000000000000003f RBX=000000006ffffe34 RCX=0000004000800b18
RDX=0000004000813180
RSI=0000000000000064 RDI=0000004000800670 RBP=000000006fffff40
RSP=0000004000800668
R8 =0000000000000000 R9 =0000004000800b44 R10=0000004000801a18
R11=0000004000801260
R12=00000040008008c0 R13=0000000000000008 R14=0000000000400040
R15=00000040008032d0
RIP=00000040008117e9 RFL=00000246 [---Z-P-] CPL=3 II=0 A20=1 SMM=0 HLT=0
ES =0000 0000000000000000 00000000 00000000
CS =0033 0000000000000000 ffffffff 00effb00 DPL=3 CS64 [-RA]
SS =002b 0000000000000000 ffffffff 00cff300 DPL=3 DS   [-WA]
DS =0000 0000000000000000 00000000 00000000
FS =0000 0000000000000000 00000000 00000000
GS =0000 0000000000000000 00000000 00000000
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT=     000000400091a000 0000007f
IDT=     0000004000919000 000001ff
CR0=80010001 CR2=0000000000000000 CR3=0000000000000000 CR4=00000220
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000
DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000000500
Makefile:6: recipe for target 'test' failed

thanks
-- PMM


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

* Re: [PULL 0/6] Linux user for 5.0 patches
  2020-03-26 15:42 ` [PULL 0/6] Linux user for 5.0 patches Peter Maydell
@ 2020-03-26 16:43   ` Laurent Vivier
  2020-03-26 21:58     ` Peter Maydell
  0 siblings, 1 reply; 10+ messages in thread
From: Laurent Vivier @ 2020-03-26 16:43 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Riku Voipio, QEMU Developers

Le 26/03/2020 à 16:42, Peter Maydell a écrit :
> On Thu, 26 Mar 2020 at 07:24, Laurent Vivier <laurent@vivier.eu> wrote:
>>
>> The following changes since commit 736cf607e40674776d752acc201f565723e86045:
>>
>>   Update version for v5.0.0-rc0 release (2020-03-24 17:50:00 +0000)
>>
>> are available in the Git repository at:
>>
>>   git://github.com/vivier/qemu.git tags/linux-user-for-5.0-pull-request
>>
>> for you to fetch changes up to a52f5f87bece827a338d6eb3332e3def86fb9c33:
>>
>>   linux-user: Flush out implementation of gettimeofday (2020-03-26 08:08:54 +0100)
>>
>> ----------------------------------------------------------------
>> Emulate x86_64 vsyscalls
>> Fix syscall_nr.h cleanup
>>
>> ----------------------------------------------------------------
> 
> Still fails :-(

I would say it was expected...

I think your build dir is corrupted by a previous build.

You should have old .o file without .d file, and thus the .o file is not
refreshed (check the date of cpu_loop.o). We cannot cleanup that before
starting the build. The purpose of the cleanup in configure was to avoid
this kind of problem but I did it badly.

If you want to check incremental build, cleanup your build dir, checkout
v4.20 or master, build it, and then build the PR branch. it will work:
it's tested.

If you build 4.2.0, then master and then PR, the build dir will be
corrupted by the build of master that removes the .d files without
removing the .o files. So when you build the PR, cpu_loop.o  file
remains and is not rebuild with the new values in cpu.h.

We can't do anything to avoid that now, except removing all .o files
under *-linux-user...

Sorry for the mess...

Thanks,
Laurent




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

* Re: [PULL 0/6] Linux user for 5.0 patches
  2020-03-26 16:43   ` Laurent Vivier
@ 2020-03-26 21:58     ` Peter Maydell
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Maydell @ 2020-03-26 21:58 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Riku Voipio, QEMU Developers

On Thu, 26 Mar 2020 at 16:43, Laurent Vivier <laurent@vivier.eu> wrote:
>
> Le 26/03/2020 à 16:42, Peter Maydell a écrit :
> > On Thu, 26 Mar 2020 at 07:24, Laurent Vivier <laurent@vivier.eu> wrote:
> >>
> >> The following changes since commit 736cf607e40674776d752acc201f565723e86045:
> >>
> >>   Update version for v5.0.0-rc0 release (2020-03-24 17:50:00 +0000)
> >>
> >> are available in the Git repository at:
> >>
> >>   git://github.com/vivier/qemu.git tags/linux-user-for-5.0-pull-request
> >>
> >> for you to fetch changes up to a52f5f87bece827a338d6eb3332e3def86fb9c33:
> >>
> >>   linux-user: Flush out implementation of gettimeofday (2020-03-26 08:08:54 +0100)
> >>
> >> ----------------------------------------------------------------
> >> Emulate x86_64 vsyscalls
> >> Fix syscall_nr.h cleanup
> >>
> >> ----------------------------------------------------------------
> >
> > Still fails :-(
>
> I would say it was expected...
>
> I think your build dir is corrupted by a previous build.
>
> You should have old .o file without .d file, and thus the .o file is not
> refreshed (check the date of cpu_loop.o). We cannot cleanup that before
> starting the build. The purpose of the cleanup in configure was to avoid
> this kind of problem but I did it badly.
>
> If you want to check incremental build, cleanup your build dir, checkout
> v4.20 or master, build it, and then build the PR branch. it will work:
> it's tested.

Seems like it. I blew away and recreated the build tree, did a build
with master, and then applied this pullreq with my usual process
(so incremental build from there), and it was fine.

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.0
for any user-visible changes.

-- PMM


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

end of thread, other threads:[~2020-03-26 21:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-26  7:23 [PULL 0/6] Linux user for 5.0 patches Laurent Vivier
2020-03-26  7:23 ` [PULL 1/6] linux-user, configure: fix (again) syscall_nr.h dependencies cleanup Laurent Vivier
2020-03-26  7:23 ` [PULL 2/6] target/i386: Renumber EXCP_SYSCALL Laurent Vivier
2020-03-26  7:23 ` [PULL 3/6] linux-user/i386: Split out gen_signal Laurent Vivier
2020-03-26  7:23 ` [PULL 4/6] linux-user/i386: Emulate x86_64 vsyscalls Laurent Vivier
2020-03-26  7:23 ` [PULL 5/6] linux-user: Add x86_64 vsyscall page to /proc/self/maps Laurent Vivier
2020-03-26  7:23 ` [PULL 6/6] linux-user: Flush out implementation of gettimeofday Laurent Vivier
2020-03-26 15:42 ` [PULL 0/6] Linux user for 5.0 patches Peter Maydell
2020-03-26 16:43   ` Laurent Vivier
2020-03-26 21:58     ` 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).