All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 00/37] Linux user for 7.2 patches
@ 2022-09-28 20:27 Laurent Vivier
  2022-09-28 20:27 ` [PULL 01/37] linux-user: use 'max' instead of 'qemu32' / 'qemu64' by default Laurent Vivier
                   ` (37 more replies)
  0 siblings, 38 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier

The following changes since commit 6160d8ff81fb9fba70f5dad88d43ffd0fa44984c:

  Merge tag 'edgar/xilinx-next-2022-09-21.for-upstream' of https://github.com/edgarigl/qemu into staging (2022-09-22 13:24:28 -0400)

are available in the Git repository at:

  https://gitlab.com/laurent_vivier/qemu.git tags/linux-user-for-7.2-pull-request

for you to fetch changes up to 4a877b82f7f99f7366fbb4820687d88dcf97478f:

  linux-user: Add parameters of getrandom() syscall for strace (2022-09-28 22:24:42 +0200)

----------------------------------------------------------------
linux-user pull request 20220928-v2

use 'max' instead of 'qemu32' / 'qemu64'
add  pidfd_open(), pidfd_send_signal() and pidfd_getfd()
Improve madvise(MADV_DONTNEED)
futex syscal rework
strace improvement
HP/PA fixes and improvement
Misc fixes

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

Daniel P. Berrangé (1):
  linux-user: use 'max' instead of 'qemu32' / 'qemu64' by default

Helge Deller (18):
  linux-user: Add missing signals in strace output
  linux-user: Add missing clock_gettime64() syscall strace
  linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd()
    syscalls
  linux-user: Log failing executable in EXCP_DUMP()
  linux-user/hppa: Use EXCP_DUMP() to show enhanced debug info
  linux-user/hppa: Dump IIR on register dump
  linux-user: Fix strace of chmod() if mode == 0
  linux-user/hppa: Set TASK_UNMAPPED_BASE to 0xfa000000 for hppa arch
  linux-user: Add strace for clock_nanosleep()
  linux-user: Show timespec on strace for futex()
  linux-user: Fix TARGET_PROT_SEM for XTENSA
  linux-user: Add proper strace format strings for
    getdents()/getdents64()
  linux-user/hppa: Add signal trampoline for hppa target
  linux-user/hppa: Drop stack guard page on hppa target
  linux-user/hppa: Increase guest stack size to 80MB for hppa target
  linux-user/hppa: Allow PROT_GROWSUP and PROT_GROWSDOWN in mprotect()
  linux-user/hppa: Fix setup_sigcontext()
  linux-user: Add parameters of getrandom() syscall for strace

Ilya Leoshkevich (6):
  linux-user: Provide MADV_* definitions
  linux-user: Fix madvise(MADV_DONTNEED) on alpha
  linux-user: Implement stracing madvise()
  linux-user: Passthrough MADV_DONTNEED for certain file mappings
  tests/tcg/linux-test: Add linux-madvise test
  linux-user/s390x: Save/restore fpc when handling a signal

Jameson Nash (1):
  linux-user: fix readlinkat handling with magic exe symlink

Jiaxun Yang (2):
  linux-user: Introduce stubs for ELF AT_BASE_PLATFORM
  linux-user: Set ELF_BASE_PLATFORM for MIPS

Peter Maydell (1):
  linux-user: Don't assume 0 is not a valid host timer_t value

Richard Henderson (7):
  linux-user: Combine do_futex and do_futex_time64
  linux-user: Sink call to do_safe_futex
  linux-user: Implement FUTEX_WAKE_BITSET
  linux-user: Convert signal number for FUTEX_FD
  linux-user: Implement PI futexes
  linux-user: Update print_futex_op
  linux-user: Lock log around strace

fanwenjie (1):
  linux-user: fix bug about missing signum convert of sigqueue

 accel/tcg/translate-all.c                 |   2 +-
 include/exec/cpu-all.h                    |   6 +
 linux-user/aarch64/target_mman.h          |   1 +
 linux-user/alpha/target_mman.h            |   8 +
 linux-user/arm/target_mman.h              |   1 +
 linux-user/cpu_loop-common.h              |   2 +
 linux-user/cris/target_mman.h             |   1 +
 linux-user/elfload.c                      |  73 ++++-
 linux-user/generic/target_mman.h          |  92 +++++++
 linux-user/hexagon/target_mman.h          |   1 +
 linux-user/hppa/cpu_loop.c                |   6 +-
 linux-user/hppa/signal.c                  |  57 ++--
 linux-user/hppa/target_mman.h             |  15 +
 linux-user/hppa/target_signal.h           |  14 +-
 linux-user/hppa/target_syscall.h          |   2 +
 linux-user/i386/target_elf.h              |   2 +-
 linux-user/i386/target_mman.h             |   1 +
 linux-user/loongarch64/target_mman.h      |   1 +
 linux-user/m68k/target_mman.h             |   1 +
 linux-user/main.c                         |   9 +-
 linux-user/microblaze/target_mman.h       |   1 +
 linux-user/mips/target_mman.h             |   1 +
 linux-user/mips64/target_mman.h           |   1 +
 linux-user/mmap.c                         |  36 ++-
 linux-user/nios2/target_mman.h            |   1 +
 linux-user/openrisc/target_mman.h         |   1 +
 linux-user/ppc/target_mman.h              |   1 +
 linux-user/riscv/target_mman.h            |   1 +
 linux-user/s390x/signal.c                 |   2 +
 linux-user/s390x/target_mman.h            |   1 +
 linux-user/sh4/target_mman.h              |   1 +
 linux-user/signal-common.h                |  46 ++++
 linux-user/signal.c                       |  37 +--
 linux-user/sparc/target_mman.h            |   1 +
 linux-user/strace.c                       | 318 ++++++++++++++++------
 linux-user/strace.list                    |  24 +-
 linux-user/syscall.c                      | 206 ++++++++------
 linux-user/syscall_defs.h                 |   5 +-
 linux-user/x86_64/target_elf.h            |   2 +-
 linux-user/x86_64/target_mman.h           |   1 +
 linux-user/xtensa/target_mman.h           |   1 +
 target/hppa/helper.c                      |   6 +-
 tests/tcg/multiarch/linux/linux-madvise.c |  70 +++++
 43 files changed, 797 insertions(+), 262 deletions(-)
 create mode 100644 linux-user/aarch64/target_mman.h
 create mode 100644 linux-user/alpha/target_mman.h
 create mode 100644 linux-user/arm/target_mman.h
 create mode 100644 linux-user/cris/target_mman.h
 create mode 100644 linux-user/generic/target_mman.h
 create mode 100644 linux-user/hexagon/target_mman.h
 create mode 100644 linux-user/hppa/target_mman.h
 create mode 100644 linux-user/i386/target_mman.h
 create mode 100644 linux-user/loongarch64/target_mman.h
 create mode 100644 linux-user/m68k/target_mman.h
 create mode 100644 linux-user/microblaze/target_mman.h
 create mode 100644 linux-user/mips/target_mman.h
 create mode 100644 linux-user/mips64/target_mman.h
 create mode 100644 linux-user/nios2/target_mman.h
 create mode 100644 linux-user/openrisc/target_mman.h
 create mode 100644 linux-user/ppc/target_mman.h
 create mode 100644 linux-user/riscv/target_mman.h
 create mode 100644 linux-user/s390x/target_mman.h
 create mode 100644 linux-user/sh4/target_mman.h
 create mode 100644 linux-user/sparc/target_mman.h
 create mode 100644 linux-user/x86_64/target_mman.h
 create mode 100644 linux-user/xtensa/target_mman.h
 create mode 100644 tests/tcg/multiarch/linux/linux-madvise.c

-- 
2.37.3



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

* [PULL 01/37] linux-user: use 'max' instead of 'qemu32' / 'qemu64' by default
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 02/37] linux-user: fix readlinkat handling with magic exe symlink Laurent Vivier
                   ` (36 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé,
	Richard Henderson, Philippe Mathieu-Daudé,
	Laurent Vivier

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

The 'qemu64' CPU model implements the least featureful x86_64 CPU that's
possible. Historically this hasn't been an issue since it was rare for
OS distros to build with a higher mandatory CPU baseline.

With RHEL-9, however, the entire distro is built for the x86_64-v2 ABI
baseline:

  https://developers.redhat.com/blog/2021/01/05/building-red-hat-enterprise-linux-9-for-the-x86-64-v2-microarchitecture-level

It is likely that other distros may take similar steps in the not too
distant future. For example, it has been suggested for Fedora on a
number of occasions.

This new baseline is not compatible with the qemu64 CPU model though.
While it is possible to pass a '-cpu xxx' flag to qemu-x86_64, the
usage of QEMU doesn't always allow for this. For example, the args
are typically controlled via binfmt rules that the user has no ability
to change. This impacts users who are trying to use podman on aarch64
platforms, to run containers with x86_64 content. There's no arg to
podman that can be used to change the qemu-x86_64 args, and a non-root
user of podman can not change binfmt rules without elevating privileges:

  https://github.com/containers/podman/issues/15456#issuecomment-1228210973

Changing to the 'max' CPU model gives 'qemu-x86_64' maximum
compatibility with binaries it is likely to encounter in the wild,
and not likely to have a significant downside for existing usage.

Most other architectures already use an 'any' CPU model, which is
often mapped to 'max' (or similar) already, rather than the oldest
possible CPU model.

For the sake of consistency the 'i386' architecture is also changed
from using 'qemu32' to 'max'.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20220923110413.70593-1-berrange@redhat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/i386/target_elf.h   | 2 +-
 linux-user/x86_64/target_elf.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/i386/target_elf.h b/linux-user/i386/target_elf.h
index 1c6142e7da0d..238a9aba738a 100644
--- a/linux-user/i386/target_elf.h
+++ b/linux-user/i386/target_elf.h
@@ -9,6 +9,6 @@
 #define I386_TARGET_ELF_H
 static inline const char *cpu_get_model(uint32_t eflags)
 {
-    return "qemu32";
+    return "max";
 }
 #endif
diff --git a/linux-user/x86_64/target_elf.h b/linux-user/x86_64/target_elf.h
index 7b76a90de880..3f628f8d6619 100644
--- a/linux-user/x86_64/target_elf.h
+++ b/linux-user/x86_64/target_elf.h
@@ -9,6 +9,6 @@
 #define X86_64_TARGET_ELF_H
 static inline const char *cpu_get_model(uint32_t eflags)
 {
-    return "qemu64";
+    return "max";
 }
 #endif
-- 
2.37.3



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

* [PULL 02/37] linux-user: fix readlinkat handling with magic exe symlink
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
  2022-09-28 20:27 ` [PULL 01/37] linux-user: use 'max' instead of 'qemu32' / 'qemu64' by default Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 03/37] linux-user: Add missing signals in strace output Laurent Vivier
                   ` (35 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jameson Nash, Laurent Vivier

From: Jameson Nash <vtjnash@gmail.com>

Exactly the same as f17f4989fa193fa8279474c5462289a3cfe69aea before was
for readlink. I suppose this was simply missed at the time.

Signed-off-by: Jameson Nash <vtjnash@gmail.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220808190727.875155-1-vtjnash@gmail.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f4091212027c..abf82bab2a18 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9912,11 +9912,22 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
             p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0);
             if (!p || !p2) {
                 ret = -TARGET_EFAULT;
+            } else if (!arg4) {
+                /* Short circuit this for the magic exe check. */
+                ret = -TARGET_EINVAL;
             } else if (is_proc_myself((const char *)p, "exe")) {
                 char real[PATH_MAX], *temp;
                 temp = realpath(exec_path, real);
-                ret = temp == NULL ? get_errno(-1) : strlen(real) ;
-                snprintf((char *)p2, arg4, "%s", real);
+                /* Return value is # of bytes that we wrote to the buffer. */
+                if (temp == NULL) {
+                    ret = get_errno(-1);
+                } else {
+                    /* Don't worry about sign mismatch as earlier mapping
+                     * logic would have thrown a bad address error. */
+                    ret = MIN(strlen(real), arg4);
+                    /* We cannot NUL terminate the string. */
+                    memcpy(p2, real, ret);
+                }
             } else {
                 ret = get_errno(readlinkat(arg1, path(p), p2, arg4));
             }
-- 
2.37.3



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

* [PULL 03/37] linux-user: Add missing signals in strace output
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
  2022-09-28 20:27 ` [PULL 01/37] linux-user: use 'max' instead of 'qemu32' / 'qemu64' by default Laurent Vivier
  2022-09-28 20:27 ` [PULL 02/37] linux-user: fix readlinkat handling with magic exe symlink Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 04/37] linux-user: Add missing clock_gettime64() syscall strace Laurent Vivier
                   ` (34 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

Some of the guest signal numbers are currently not converted to
their representative names in the strace output, e.g. SIGVTALRM.

This patch introduces a smart way to generate and keep in sync the
host-to-guest and guest-to-host signal conversion tables for usage in
the qemu signal and strace code. This ensures that any signals
will now show up in both tables.

There is no functional change in this patch - with the exception that yet
missing signal names now show up in the strace code too.

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220918194555.83535-2-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/signal-common.h | 46 ++++++++++++++++++++++++++++++++++++++
 linux-user/signal.c        | 37 +++---------------------------
 linux-user/strace.c        | 30 +++++++++----------------
 3 files changed, 60 insertions(+), 53 deletions(-)

diff --git a/linux-user/signal-common.h b/linux-user/signal-common.h
index 6a7e4a93fc13..3e2dc604c2fb 100644
--- a/linux-user/signal-common.h
+++ b/linux-user/signal-common.h
@@ -118,4 +118,50 @@ static inline void finish_sigsuspend_mask(int ret)
     }
 }
 
+#if defined(SIGSTKFLT) && defined(TARGET_SIGSTKFLT)
+#define MAKE_SIG_ENTRY_SIGSTKFLT        MAKE_SIG_ENTRY(SIGSTKFLT)
+#else
+#define MAKE_SIG_ENTRY_SIGSTKFLT
+#endif
+
+#if defined(SIGIOT) && defined(TARGET_SIGIOT)
+#define MAKE_SIG_ENTRY_SIGIOT           MAKE_SIG_ENTRY(SIGIOT)
+#else
+#define MAKE_SIG_ENTRY_SIGIOT
+#endif
+
+#define MAKE_SIGNAL_LIST \
+        MAKE_SIG_ENTRY(SIGHUP) \
+        MAKE_SIG_ENTRY(SIGINT) \
+        MAKE_SIG_ENTRY(SIGQUIT) \
+        MAKE_SIG_ENTRY(SIGILL) \
+        MAKE_SIG_ENTRY(SIGTRAP) \
+        MAKE_SIG_ENTRY(SIGABRT) \
+        MAKE_SIG_ENTRY(SIGBUS) \
+        MAKE_SIG_ENTRY(SIGFPE) \
+        MAKE_SIG_ENTRY(SIGKILL) \
+        MAKE_SIG_ENTRY(SIGUSR1) \
+        MAKE_SIG_ENTRY(SIGSEGV) \
+        MAKE_SIG_ENTRY(SIGUSR2) \
+        MAKE_SIG_ENTRY(SIGPIPE) \
+        MAKE_SIG_ENTRY(SIGALRM) \
+        MAKE_SIG_ENTRY(SIGTERM) \
+        MAKE_SIG_ENTRY(SIGCHLD) \
+        MAKE_SIG_ENTRY(SIGCONT) \
+        MAKE_SIG_ENTRY(SIGSTOP) \
+        MAKE_SIG_ENTRY(SIGTSTP) \
+        MAKE_SIG_ENTRY(SIGTTIN) \
+        MAKE_SIG_ENTRY(SIGTTOU) \
+        MAKE_SIG_ENTRY(SIGURG) \
+        MAKE_SIG_ENTRY(SIGXCPU) \
+        MAKE_SIG_ENTRY(SIGXFSZ) \
+        MAKE_SIG_ENTRY(SIGVTALRM) \
+        MAKE_SIG_ENTRY(SIGPROF) \
+        MAKE_SIG_ENTRY(SIGWINCH) \
+        MAKE_SIG_ENTRY(SIGIO) \
+        MAKE_SIG_ENTRY(SIGPWR) \
+        MAKE_SIG_ENTRY(SIGSYS) \
+        MAKE_SIG_ENTRY_SIGSTKFLT \
+        MAKE_SIG_ENTRY_SIGIOT
+
 #endif
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 8d29bfaa6b5c..61c6fa3fcf12 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -53,40 +53,9 @@ abi_ulong default_rt_sigreturn;
 QEMU_BUILD_BUG_ON(__SIGRTMAX + 1 != _NSIG);
 #endif
 static uint8_t host_to_target_signal_table[_NSIG] = {
-    [SIGHUP] = TARGET_SIGHUP,
-    [SIGINT] = TARGET_SIGINT,
-    [SIGQUIT] = TARGET_SIGQUIT,
-    [SIGILL] = TARGET_SIGILL,
-    [SIGTRAP] = TARGET_SIGTRAP,
-    [SIGABRT] = TARGET_SIGABRT,
-/*    [SIGIOT] = TARGET_SIGIOT,*/
-    [SIGBUS] = TARGET_SIGBUS,
-    [SIGFPE] = TARGET_SIGFPE,
-    [SIGKILL] = TARGET_SIGKILL,
-    [SIGUSR1] = TARGET_SIGUSR1,
-    [SIGSEGV] = TARGET_SIGSEGV,
-    [SIGUSR2] = TARGET_SIGUSR2,
-    [SIGPIPE] = TARGET_SIGPIPE,
-    [SIGALRM] = TARGET_SIGALRM,
-    [SIGTERM] = TARGET_SIGTERM,
-#ifdef SIGSTKFLT
-    [SIGSTKFLT] = TARGET_SIGSTKFLT,
-#endif
-    [SIGCHLD] = TARGET_SIGCHLD,
-    [SIGCONT] = TARGET_SIGCONT,
-    [SIGSTOP] = TARGET_SIGSTOP,
-    [SIGTSTP] = TARGET_SIGTSTP,
-    [SIGTTIN] = TARGET_SIGTTIN,
-    [SIGTTOU] = TARGET_SIGTTOU,
-    [SIGURG] = TARGET_SIGURG,
-    [SIGXCPU] = TARGET_SIGXCPU,
-    [SIGXFSZ] = TARGET_SIGXFSZ,
-    [SIGVTALRM] = TARGET_SIGVTALRM,
-    [SIGPROF] = TARGET_SIGPROF,
-    [SIGWINCH] = TARGET_SIGWINCH,
-    [SIGIO] = TARGET_SIGIO,
-    [SIGPWR] = TARGET_SIGPWR,
-    [SIGSYS] = TARGET_SIGSYS,
+#define MAKE_SIG_ENTRY(sig)     [sig] = TARGET_##sig,
+        MAKE_SIGNAL_LIST
+#undef MAKE_SIG_ENTRY
     /* next signals stay the same */
 };
 
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 7d882526da03..a4eeef7ae1ca 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -17,6 +17,7 @@
 #include "qemu.h"
 #include "user-internals.h"
 #include "strace.h"
+#include "signal-common.h"
 
 struct syscallname {
     int nr;
@@ -141,30 +142,21 @@ if( cmd == val ) { \
     qemu_log("%d", cmd);
 }
 
+static const char * const target_signal_name[] = {
+#define MAKE_SIG_ENTRY(sig)     [TARGET_##sig] = #sig,
+        MAKE_SIGNAL_LIST
+#undef MAKE_SIG_ENTRY
+};
+
 static void
 print_signal(abi_ulong arg, int last)
 {
     const char *signal_name = NULL;
-    switch(arg) {
-    case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
-    case TARGET_SIGINT: signal_name = "SIGINT"; break;
-    case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
-    case TARGET_SIGILL: signal_name = "SIGILL"; break;
-    case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
-    case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
-    case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
-    case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
-    case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
-    case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
-    case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
-    case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
-    case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
-    case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
-    case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
-    case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
-    case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
-    case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
+
+    if (arg < ARRAY_SIZE(target_signal_name)) {
+        signal_name = target_signal_name[arg];
     }
+
     if (signal_name == NULL) {
         print_raw_param("%ld", arg, last);
         return;
-- 
2.37.3



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

* [PULL 04/37] linux-user: Add missing clock_gettime64() syscall strace
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (2 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 03/37] linux-user: Add missing signals in strace output Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 05/37] linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls Laurent Vivier
                   ` (33 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

Allow linux-user to strace the clock_gettime64() syscall.
This syscall is used a lot on 32-bit guest architectures which use newer
glibc versions.

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220918194555.83535-3-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.c    | 53 ++++++++++++++++++++++++++++++++++++++++++
 linux-user/strace.list |  4 ++++
 2 files changed, 57 insertions(+)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index a4eeef7ae1ca..816e67999539 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -82,6 +82,7 @@ UNUSED static void print_buf(abi_long addr, abi_long len, int last);
 UNUSED static void print_raw_param(const char *, abi_long, int);
 UNUSED static void print_timeval(abi_ulong, int);
 UNUSED static void print_timespec(abi_ulong, int);
+UNUSED static void print_timespec64(abi_ulong, int);
 UNUSED static void print_timezone(abi_ulong, int);
 UNUSED static void print_itimerval(abi_ulong, int);
 UNUSED static void print_number(abi_long, int);
@@ -795,6 +796,24 @@ print_syscall_ret_clock_gettime(CPUArchState *cpu_env, const struct syscallname
 #define print_syscall_ret_clock_getres     print_syscall_ret_clock_gettime
 #endif
 
+#if defined(TARGET_NR_clock_gettime64)
+static void
+print_syscall_ret_clock_gettime64(CPUArchState *cpu_env, const struct syscallname *name,
+                                abi_long ret, abi_long arg0, abi_long arg1,
+                                abi_long arg2, abi_long arg3, abi_long arg4,
+                                abi_long arg5)
+{
+    if (!print_syscall_err(ret)) {
+        qemu_log(TARGET_ABI_FMT_ld, ret);
+        qemu_log(" (");
+        print_timespec64(arg1, 1);
+        qemu_log(")");
+    }
+
+    qemu_log("\n");
+}
+#endif
+
 #ifdef TARGET_NR_gettimeofday
 static void
 print_syscall_ret_gettimeofday(CPUArchState *cpu_env, const struct syscallname *name,
@@ -1652,6 +1671,27 @@ print_timespec(abi_ulong ts_addr, int last)
     }
 }
 
+static void
+print_timespec64(abi_ulong ts_addr, int last)
+{
+    if (ts_addr) {
+        struct target__kernel_timespec *ts;
+
+        ts = lock_user(VERIFY_READ, ts_addr, sizeof(*ts), 1);
+        if (!ts) {
+            print_pointer(ts_addr, last);
+            return;
+        }
+        qemu_log("{tv_sec = %lld"
+                 ",tv_nsec = %lld}%s",
+                 (long long)tswap64(ts->tv_sec), (long long)tswap64(ts->tv_nsec),
+                 get_comma(last));
+        unlock_user(ts, ts_addr, 0);
+    } else {
+        qemu_log("NULL%s", get_comma(last));
+    }
+}
+
 static void
 print_timezone(abi_ulong tz_addr, int last)
 {
@@ -2267,6 +2307,19 @@ print_clock_gettime(CPUArchState *cpu_env, const struct syscallname *name,
 #define print_clock_getres     print_clock_gettime
 #endif
 
+#if defined(TARGET_NR_clock_gettime64)
+static void
+print_clock_gettime64(CPUArchState *cpu_env, 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_enums(clockids, arg0, 0);
+    print_pointer(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_clock_settime
 static void
 print_clock_settime(CPUArchState *cpu_env, const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 72e17b1acf00..a78cdf3cdfef 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1676,3 +1676,7 @@
 #ifdef TARGET_NR_copy_file_range
 { TARGET_NR_copy_file_range, "copy_file_range", "%s(%d,%p,%d,%p,"TARGET_ABI_FMT_lu",%u)", NULL, NULL },
 #endif
+#ifdef TARGET_NR_clock_gettime64
+{ TARGET_NR_clock_gettime64, "clock_gettime64" , NULL, print_clock_gettime64,
+                           print_syscall_ret_clock_gettime64 },
+#endif
-- 
2.37.3



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

* [PULL 05/37] linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (3 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 04/37] linux-user: Add missing clock_gettime64() syscall strace Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 06/37] linux-user: Log failing executable in EXCP_DUMP() Laurent Vivier
                   ` (32 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

I noticed those were missing when running the glib2.0 testsuite.
Add the syscalls including the strace output.

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220918194555.83535-4-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.c    | 28 ++++++++++++++++++++++++++++
 linux-user/strace.list |  9 +++++++++
 linux-user/syscall.c   | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 816e67999539..5ac64df02b85 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -3317,6 +3317,34 @@ print_openat(CPUArchState *cpu_env, const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_pidfd_send_signal
+static void
+print_pidfd_send_signal(CPUArchState *cpu_env, const struct syscallname *name,
+                abi_long arg0, abi_long arg1, abi_long arg2,
+                abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    void *p;
+    target_siginfo_t uinfo;
+
+    print_syscall_prologue(name);
+    print_raw_param("%d", arg0, 0);
+    print_signal(arg1, 0);
+
+    p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
+    if (p) {
+        get_target_siginfo(&uinfo, p);
+        print_siginfo(&uinfo);
+
+        unlock_user(p, arg2, 0);
+    } else {
+        print_pointer(arg2, 1);
+    }
+
+    print_raw_param("%u", arg3, 0);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_mq_unlink
 static void
 print_mq_unlink(CPUArchState *cpu_env, const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index a78cdf3cdfef..4d8b7f6a5e0c 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1664,6 +1664,15 @@
 #ifdef TARGET_NR_pipe2
 { TARGET_NR_pipe2, "pipe2", NULL, NULL, NULL },
 #endif
+#ifdef TARGET_NR_pidfd_open
+{ TARGET_NR_pidfd_open, "pidfd_open", "%s(%d,%u)", NULL, NULL },
+#endif
+#ifdef TARGET_NR_pidfd_send_signal
+{ TARGET_NR_pidfd_send_signal, "pidfd_send_signal", NULL, print_pidfd_send_signal, NULL },
+#endif
+#ifdef TARGET_NR_pidfd_getfd
+{ TARGET_NR_pidfd_getfd, "pidfd_getfd", "%s(%d,%d,%u)", NULL, NULL },
+#endif
 #ifdef TARGET_NR_atomic_cmpxchg_32
 { TARGET_NR_atomic_cmpxchg_32, "atomic_cmpxchg_32", NULL, NULL, NULL },
 #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index abf82bab2a18..850410c9b553 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -346,6 +346,16 @@ _syscall6(int,sys_futex,int *,uaddr,int,op,int,val,
 _syscall6(int,sys_futex_time64,int *,uaddr,int,op,int,val,
           const struct timespec *,timeout,int *,uaddr2,int,val3)
 #endif
+#if defined(__NR_pidfd_open) && defined(TARGET_NR_pidfd_open)
+_syscall2(int, pidfd_open, pid_t, pid, unsigned int, flags);
+#endif
+#if defined(__NR_pidfd_send_signal) && defined(TARGET_NR_pidfd_send_signal)
+_syscall4(int, pidfd_send_signal, int, pidfd, int, sig, siginfo_t *, info,
+                             unsigned int, flags);
+#endif
+#if defined(__NR_pidfd_getfd) && defined(TARGET_NR_pidfd_getfd)
+_syscall3(int, pidfd_getfd, int, pidfd, int, targetfd, unsigned int, flags);
+#endif
 #define __NR_sys_sched_getaffinity __NR_sched_getaffinity
 _syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len,
           unsigned long *, user_mask_ptr);
@@ -8683,6 +8693,30 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         ret = do_open_by_handle_at(arg1, arg2, arg3);
         fd_trans_unregister(ret);
         return ret;
+#endif
+#if defined(__NR_pidfd_open) && defined(TARGET_NR_pidfd_open)
+    case TARGET_NR_pidfd_open:
+        return get_errno(pidfd_open(arg1, arg2));
+#endif
+#if defined(__NR_pidfd_send_signal) && defined(TARGET_NR_pidfd_send_signal)
+    case TARGET_NR_pidfd_send_signal:
+        {
+            siginfo_t uinfo;
+
+            p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
+            if (!p) {
+                return -TARGET_EFAULT;
+            }
+            target_to_host_siginfo(&uinfo, p);
+            unlock_user(p, arg3, 0);
+            ret = get_errno(pidfd_send_signal(arg1, target_to_host_signal(arg2),
+                &uinfo, arg4));
+        }
+        return ret;
+#endif
+#if defined(__NR_pidfd_getfd) && defined(TARGET_NR_pidfd_getfd)
+    case TARGET_NR_pidfd_getfd:
+        return get_errno(pidfd_getfd(arg1, arg2, arg3));
 #endif
     case TARGET_NR_close:
         fd_trans_unregister(arg1);
-- 
2.37.3



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

* [PULL 06/37] linux-user: Log failing executable in EXCP_DUMP()
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (4 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 05/37] linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 07/37] linux-user/hppa: Use EXCP_DUMP() to show enhanced debug info Laurent Vivier
                   ` (31 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier, Philippe Mathieu-Daudé

From: Helge Deller <deller@gmx.de>

Enhance the EXCP_DUMP() macro to print out the failing program too.
During debugging it's sometimes hard to track down the actual failing
program if you are e.g. building a whole debian package.

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20220918194555.83535-5-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/cpu_loop-common.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/linux-user/cpu_loop-common.h b/linux-user/cpu_loop-common.h
index dc0042e4de35..36ff5b14f2a7 100644
--- a/linux-user/cpu_loop-common.h
+++ b/linux-user/cpu_loop-common.h
@@ -27,9 +27,11 @@
 do {                                                                    \
     CPUState *cs = env_cpu(env);                                        \
     fprintf(stderr, fmt , ## __VA_ARGS__);                              \
+    fprintf(stderr, "Failing executable: %s\n", exec_path);             \
     cpu_dump_state(cs, stderr, 0);                                      \
     if (qemu_log_separate()) {                                          \
         qemu_log(fmt, ## __VA_ARGS__);                                  \
+        qemu_log("Failing executable: %s\n", exec_path);                \
         log_cpu_state(cs, 0);                                           \
     }                                                                   \
 } while (0)
-- 
2.37.3



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

* [PULL 07/37] linux-user/hppa: Use EXCP_DUMP() to show enhanced debug info
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (5 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 06/37] linux-user: Log failing executable in EXCP_DUMP() Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 08/37] linux-user/hppa: Dump IIR on register dump Laurent Vivier
                   ` (30 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

Enhance the hppa linux-user cpu_loop() to show more debugging info
on hard errors.

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220918194555.83535-6-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/hppa/cpu_loop.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c
index 64263c3dc406..1ef3b461911c 100644
--- a/linux-user/hppa/cpu_loop.c
+++ b/linux-user/hppa/cpu_loop.c
@@ -147,12 +147,15 @@ void cpu_loop(CPUHPPAState *env)
             force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, env->iaoq_f);
             break;
         case EXCP_ILL:
+            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
             force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->iaoq_f);
             break;
         case EXCP_PRIV_OPR:
+            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
             force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->iaoq_f);
             break;
         case EXCP_PRIV_REG:
+            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
             force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVREG, env->iaoq_f);
             break;
         case EXCP_OVERFLOW:
@@ -171,7 +174,8 @@ void cpu_loop(CPUHPPAState *env)
             /* just indicate that signals should be handled asap */
             break;
         default:
-            g_assert_not_reached();
+            EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr);
+            abort();
         }
         process_pending_signals(env);
     }
-- 
2.37.3



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

* [PULL 08/37] linux-user/hppa: Dump IIR on register dump
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (6 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 07/37] linux-user/hppa: Use EXCP_DUMP() to show enhanced debug info Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 09/37] linux-user: Fix strace of chmod() if mode == 0 Laurent Vivier
                   ` (29 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier, Philippe Mathieu-Daudé

From: Helge Deller <deller@gmx.de>

Include the IIR register (which holds the opcode of the failing
instruction) when dumping the hppa registers.

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20220918194555.83535-7-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 target/hppa/helper.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/target/hppa/helper.c b/target/hppa/helper.c
index e2758d8df380..74b8747083f9 100644
--- a/target/hppa/helper.c
+++ b/target/hppa/helper.c
@@ -85,9 +85,11 @@ void hppa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     char psw_c[20];
     int i;
 
-    qemu_fprintf(f, "IA_F " TARGET_FMT_lx " IA_B " TARGET_FMT_lx "\n",
+    qemu_fprintf(f, "IA_F " TARGET_FMT_lx " IA_B " TARGET_FMT_lx
+                 " IIR " TREG_FMT_lx  "\n",
                  hppa_form_gva_psw(psw, env->iasq_f, env->iaoq_f),
-                 hppa_form_gva_psw(psw, env->iasq_b, env->iaoq_b));
+                 hppa_form_gva_psw(psw, env->iasq_b, env->iaoq_b),
+                 env->cr[CR_IIR]);
 
     psw_c[0]  = (psw & PSW_W ? 'W' : '-');
     psw_c[1]  = (psw & PSW_E ? 'E' : '-');
-- 
2.37.3



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

* [PULL 09/37] linux-user: Fix strace of chmod() if mode == 0
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (7 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 08/37] linux-user/hppa: Dump IIR on register dump Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 10/37] linux-user/hppa: Set TASK_UNMAPPED_BASE to 0xfa000000 for hppa arch Laurent Vivier
                   ` (28 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier, Philippe Mathieu-Daudé

From: Helge Deller <deller@gmx.de>

If the mode parameter of chmod() is zero, this value isn't shown
when stracing a program:
    chmod("filename",)
This patch fixes it up to show the zero-value as well:
    chmod("filename",000)

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20220918194555.83535-8-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 5ac64df02b85..2f539845bb90 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1505,6 +1505,11 @@ print_file_mode(abi_long mode, int last)
     const char *sep = "";
     const struct flags *m;
 
+    if (mode == 0) {
+        qemu_log("000%s", get_comma(last));
+        return;
+    }
+
     for (m = &mode_flags[0]; m->f_string != NULL; m++) {
         if ((m->f_value & mode) == m->f_value) {
             qemu_log("%s%s", m->f_string, sep);
-- 
2.37.3



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

* [PULL 10/37] linux-user/hppa: Set TASK_UNMAPPED_BASE to 0xfa000000 for hppa arch
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (8 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 09/37] linux-user: Fix strace of chmod() if mode == 0 Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 11/37] linux-user: Add strace for clock_nanosleep() Laurent Vivier
                   ` (27 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

On the parisc architecture the stack grows upwards.
Move the TASK_UNMAPPED_BASE to high memory area as it's done by the
kernel on physical machines.

Signed-off-by: Helge Deller <deller@gmx.de>
Message-Id: <20220918194555.83535-9-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/mmap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 6a828e8418a7..83fdae7034ea 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -253,8 +253,12 @@ static int mmap_frag(abi_ulong real_start,
 # define TASK_UNMAPPED_BASE  (1ul << 38)
 #endif
 #else
+#ifdef TARGET_HPPA
+# define TASK_UNMAPPED_BASE  0xfa000000
+#else
 # define TASK_UNMAPPED_BASE  0x40000000
 #endif
+#endif
 abi_ulong mmap_next_start = TASK_UNMAPPED_BASE;
 
 unsigned long last_brk;
-- 
2.37.3



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

* [PULL 11/37] linux-user: Add strace for clock_nanosleep()
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (9 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 10/37] linux-user/hppa: Set TASK_UNMAPPED_BASE to 0xfa000000 for hppa arch Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 12/37] linux-user: Show timespec on strace for futex() Laurent Vivier
                   ` (26 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220918194555.83535-10-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.c    | 15 +++++++++++++++
 linux-user/strace.list |  3 ++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 2f539845bb90..6f818212d529 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -3567,6 +3567,21 @@ print_unshare(CPUArchState *cpu_env, const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_clock_nanosleep
+static void
+print_clock_nanosleep(CPUArchState *cpu_env, 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_enums(clockids, arg0, 0);
+    print_raw_param("%d", arg1, 0);
+    print_timespec(arg2, 0);
+    print_timespec(arg3, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_utime
 static void
 print_utime(CPUArchState *cpu_env, const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 4d8b7f6a5e0c..215d971b2aea 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -91,7 +91,8 @@
                            print_syscall_ret_clock_gettime },
 #endif
 #ifdef TARGET_NR_clock_nanosleep
-{ TARGET_NR_clock_nanosleep, "clock_nanosleep" , NULL, NULL, NULL },
+{ TARGET_NR_clock_nanosleep, "clock_nanosleep" , NULL, print_clock_nanosleep,
+                            NULL },
 #endif
 #ifdef TARGET_NR_clock_settime
 { TARGET_NR_clock_settime, "clock_settime" , NULL, print_clock_settime, NULL },
-- 
2.37.3



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

* [PULL 12/37] linux-user: Show timespec on strace for futex()
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (10 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 11/37] linux-user: Add strace for clock_nanosleep() Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 13/37] linux-user: Provide MADV_* definitions Laurent Vivier
                   ` (25 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220918194555.83535-11-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 6f818212d529..b6b9abaea466 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -3714,11 +3714,20 @@ print_futex(CPUArchState *cpu_env, const struct syscallname *name,
             abi_long arg0, abi_long arg1, abi_long arg2,
             abi_long arg3, abi_long arg4, abi_long arg5)
 {
+    abi_long op = arg1 & FUTEX_CMD_MASK;
     print_syscall_prologue(name);
     print_pointer(arg0, 0);
     print_futex_op(arg1, 0);
     print_raw_param(",%d", arg2, 0);
-    print_pointer(arg3, 0); /* struct timespec */
+    switch (op) {
+        case FUTEX_WAIT:
+        case FUTEX_WAIT_BITSET:
+            print_timespec(arg3, 0);
+            break;
+        default:
+            print_pointer(arg3, 0);
+            break;
+    }
     print_pointer(arg4, 0);
     print_raw_param("%d", arg4, 1);
     print_syscall_epilogue(name);
-- 
2.37.3



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

* [PULL 13/37] linux-user: Provide MADV_* definitions
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (11 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 12/37] linux-user: Show timespec on strace for futex() Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 14/37] linux-user: Fix madvise(MADV_DONTNEED) on alpha Laurent Vivier
                   ` (24 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ilya Leoshkevich, Richard Henderson, Laurent Vivier

From: Ilya Leoshkevich <iii@linux.ibm.com>

Provide MADV_* definitions using target_mman.h header, similar to what
kernel does. Most architectures use the same values, with the exception
of alpha and hppa.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220906000839.1672934-2-iii@linux.ibm.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/aarch64/target_mman.h     |  1 +
 linux-user/alpha/target_mman.h       |  8 +++
 linux-user/arm/target_mman.h         |  1 +
 linux-user/cris/target_mman.h        |  1 +
 linux-user/generic/target_mman.h     | 92 ++++++++++++++++++++++++++++
 linux-user/hexagon/target_mman.h     |  1 +
 linux-user/hppa/target_mman.h        | 15 +++++
 linux-user/i386/target_mman.h        |  1 +
 linux-user/loongarch64/target_mman.h |  1 +
 linux-user/m68k/target_mman.h        |  1 +
 linux-user/microblaze/target_mman.h  |  1 +
 linux-user/mips/target_mman.h        |  1 +
 linux-user/mips64/target_mman.h      |  1 +
 linux-user/nios2/target_mman.h       |  1 +
 linux-user/openrisc/target_mman.h    |  1 +
 linux-user/ppc/target_mman.h         |  1 +
 linux-user/riscv/target_mman.h       |  1 +
 linux-user/s390x/target_mman.h       |  1 +
 linux-user/sh4/target_mman.h         |  1 +
 linux-user/sparc/target_mman.h       |  1 +
 linux-user/x86_64/target_mman.h      |  1 +
 linux-user/xtensa/target_mman.h      |  1 +
 22 files changed, 134 insertions(+)
 create mode 100644 linux-user/aarch64/target_mman.h
 create mode 100644 linux-user/alpha/target_mman.h
 create mode 100644 linux-user/arm/target_mman.h
 create mode 100644 linux-user/cris/target_mman.h
 create mode 100644 linux-user/generic/target_mman.h
 create mode 100644 linux-user/hexagon/target_mman.h
 create mode 100644 linux-user/hppa/target_mman.h
 create mode 100644 linux-user/i386/target_mman.h
 create mode 100644 linux-user/loongarch64/target_mman.h
 create mode 100644 linux-user/m68k/target_mman.h
 create mode 100644 linux-user/microblaze/target_mman.h
 create mode 100644 linux-user/mips/target_mman.h
 create mode 100644 linux-user/mips64/target_mman.h
 create mode 100644 linux-user/nios2/target_mman.h
 create mode 100644 linux-user/openrisc/target_mman.h
 create mode 100644 linux-user/ppc/target_mman.h
 create mode 100644 linux-user/riscv/target_mman.h
 create mode 100644 linux-user/s390x/target_mman.h
 create mode 100644 linux-user/sh4/target_mman.h
 create mode 100644 linux-user/sparc/target_mman.h
 create mode 100644 linux-user/x86_64/target_mman.h
 create mode 100644 linux-user/xtensa/target_mman.h

diff --git a/linux-user/aarch64/target_mman.h b/linux-user/aarch64/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/aarch64/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/alpha/target_mman.h b/linux-user/alpha/target_mman.h
new file mode 100644
index 000000000000..cd6e3d70a604
--- /dev/null
+++ b/linux-user/alpha/target_mman.h
@@ -0,0 +1,8 @@
+#ifndef ALPHA_TARGET_MMAN_H
+#define ALPHA_TARGET_MMAN_H
+
+#define TARGET_MADV_DONTNEED 6
+
+#include "../generic/target_mman.h"
+
+#endif
diff --git a/linux-user/arm/target_mman.h b/linux-user/arm/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/arm/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/cris/target_mman.h b/linux-user/cris/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/cris/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/generic/target_mman.h b/linux-user/generic/target_mman.h
new file mode 100644
index 000000000000..1436a3c54308
--- /dev/null
+++ b/linux-user/generic/target_mman.h
@@ -0,0 +1,92 @@
+#ifndef LINUX_USER_TARGET_MMAN_H
+#define LINUX_USER_TARGET_MMAN_H
+
+#ifndef TARGET_MADV_NORMAL
+#define TARGET_MADV_NORMAL 0
+#endif
+
+#ifndef TARGET_MADV_RANDOM
+#define TARGET_MADV_RANDOM 1
+#endif
+
+#ifndef TARGET_MADV_SEQUENTIAL
+#define TARGET_MADV_SEQUENTIAL 2
+#endif
+
+#ifndef TARGET_MADV_WILLNEED
+#define TARGET_MADV_WILLNEED 3
+#endif
+
+#ifndef TARGET_MADV_DONTNEED
+#define TARGET_MADV_DONTNEED 4
+#endif
+
+#ifndef TARGET_MADV_FREE
+#define TARGET_MADV_FREE 8
+#endif
+
+#ifndef TARGET_MADV_REMOVE
+#define TARGET_MADV_REMOVE 9
+#endif
+
+#ifndef TARGET_MADV_DONTFORK
+#define TARGET_MADV_DONTFORK 10
+#endif
+
+#ifndef TARGET_MADV_DOFORK
+#define TARGET_MADV_DOFORK 11
+#endif
+
+#ifndef TARGET_MADV_MERGEABLE
+#define TARGET_MADV_MERGEABLE 12
+#endif
+
+#ifndef TARGET_MADV_UNMERGEABLE
+#define TARGET_MADV_UNMERGEABLE 13
+#endif
+
+#ifndef TARGET_MADV_HUGEPAGE
+#define TARGET_MADV_HUGEPAGE 14
+#endif
+
+#ifndef TARGET_MADV_NOHUGEPAGE
+#define TARGET_MADV_NOHUGEPAGE 15
+#endif
+
+#ifndef TARGET_MADV_DONTDUMP
+#define TARGET_MADV_DONTDUMP 16
+#endif
+
+#ifndef TARGET_MADV_DODUMP
+#define TARGET_MADV_DODUMP 17
+#endif
+
+#ifndef TARGET_MADV_WIPEONFORK
+#define TARGET_MADV_WIPEONFORK 18
+#endif
+
+#ifndef TARGET_MADV_KEEPONFORK
+#define TARGET_MADV_KEEPONFORK 19
+#endif
+
+#ifndef TARGET_MADV_COLD
+#define TARGET_MADV_COLD 20
+#endif
+
+#ifndef TARGET_MADV_PAGEOUT
+#define TARGET_MADV_PAGEOUT 21
+#endif
+
+#ifndef TARGET_MADV_POPULATE_READ
+#define TARGET_MADV_POPULATE_READ 22
+#endif
+
+#ifndef TARGET_MADV_POPULATE_WRITE
+#define TARGET_MADV_POPULATE_WRITE 23
+#endif
+
+#ifndef TARGET_MADV_DONTNEED_LOCKED
+#define TARGET_MADV_DONTNEED_LOCKED 24
+#endif
+
+#endif
diff --git a/linux-user/hexagon/target_mman.h b/linux-user/hexagon/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/hexagon/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/hppa/target_mman.h b/linux-user/hppa/target_mman.h
new file mode 100644
index 000000000000..66dd9f79414e
--- /dev/null
+++ b/linux-user/hppa/target_mman.h
@@ -0,0 +1,15 @@
+#ifndef HPPA_TARGET_MMAN_H
+#define HPPA_TARGET_MMAN_H
+
+#define TARGET_MADV_MERGEABLE 65
+#define TARGET_MADV_UNMERGEABLE 66
+#define TARGET_MADV_HUGEPAGE 67
+#define TARGET_MADV_NOHUGEPAGE 68
+#define TARGET_MADV_DONTDUMP 69
+#define TARGET_MADV_DODUMP 70
+#define TARGET_MADV_WIPEONFORK 71
+#define TARGET_MADV_KEEPONFORK 72
+
+#include "../generic/target_mman.h"
+
+#endif
diff --git a/linux-user/i386/target_mman.h b/linux-user/i386/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/i386/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/loongarch64/target_mman.h b/linux-user/loongarch64/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/loongarch64/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/m68k/target_mman.h b/linux-user/m68k/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/m68k/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/microblaze/target_mman.h b/linux-user/microblaze/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/microblaze/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/mips/target_mman.h b/linux-user/mips/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/mips/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/mips64/target_mman.h b/linux-user/mips64/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/mips64/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/nios2/target_mman.h b/linux-user/nios2/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/nios2/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/openrisc/target_mman.h b/linux-user/openrisc/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/openrisc/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/ppc/target_mman.h b/linux-user/ppc/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/ppc/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/riscv/target_mman.h b/linux-user/riscv/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/riscv/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/s390x/target_mman.h b/linux-user/s390x/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/s390x/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/sh4/target_mman.h b/linux-user/sh4/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/sh4/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/sparc/target_mman.h b/linux-user/sparc/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/sparc/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/x86_64/target_mman.h b/linux-user/x86_64/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/x86_64/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
diff --git a/linux-user/xtensa/target_mman.h b/linux-user/xtensa/target_mman.h
new file mode 100644
index 000000000000..e7ba6070fe7c
--- /dev/null
+++ b/linux-user/xtensa/target_mman.h
@@ -0,0 +1 @@
+#include "../generic/target_mman.h"
-- 
2.37.3



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

* [PULL 14/37] linux-user: Fix madvise(MADV_DONTNEED) on alpha
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (12 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 13/37] linux-user: Provide MADV_* definitions Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 15/37] linux-user: Implement stracing madvise() Laurent Vivier
                   ` (23 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ilya Leoshkevich, Richard Henderson, Laurent Vivier

From: Ilya Leoshkevich <iii@linux.ibm.com>

MADV_DONTNEED has a different value on alpha, compared to all the other
architectures. Fix by using TARGET_MADV_DONTNEED instead of
MADV_DONTNEED.

Fixes: 892a4f6a750a ("linux-user: Add partial support for MADV_DONTNEED")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220906000839.1672934-3-iii@linux.ibm.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/mmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 83fdae7034ea..942bec7e8528 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -22,6 +22,7 @@
 #include "qemu.h"
 #include "user-internals.h"
 #include "user-mmap.h"
+#include "target_mman.h"
 
 static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
 static __thread int mmap_lock_count;
@@ -897,7 +898,7 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)
      * anonymous mappings. In this case passthrough is safe, so do it.
      */
     mmap_lock();
-    if (advice == MADV_DONTNEED &&
+    if (advice == TARGET_MADV_DONTNEED &&
         can_passthrough_madv_dontneed(start, end)) {
         ret = get_errno(madvise(g2h_untagged(start), len, MADV_DONTNEED));
         if (ret == 0) {
-- 
2.37.3



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

* [PULL 15/37] linux-user: Implement stracing madvise()
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (13 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 14/37] linux-user: Fix madvise(MADV_DONTNEED) on alpha Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 16/37] linux-user: Passthrough MADV_DONTNEED for certain file mappings Laurent Vivier
                   ` (22 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ilya Leoshkevich, Richard Henderson, Laurent Vivier

From: Ilya Leoshkevich <iii@linux.ibm.com>

The default implementation has several problems: the first argument is
not displayed as a pointer, making it harder to grep; the third
argument is not symbolized; and there are several extra unused
arguments.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220906000839.1672934-4-iii@linux.ibm.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.c    | 41 +++++++++++++++++++++++++++++++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index b6b9abaea466..2deb84a2c106 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -18,6 +18,7 @@
 #include "user-internals.h"
 #include "strace.h"
 #include "signal-common.h"
+#include "target_mman.h"
 
 struct syscallname {
     int nr;
@@ -3019,6 +3020,46 @@ print_stat(CPUArchState *cpu_env, const struct syscallname *name,
 #define print_lstat64   print_stat
 #endif
 
+#if defined(TARGET_NR_madvise)
+static struct enums madvise_advice[] = {
+    ENUM_TARGET(MADV_NORMAL),
+    ENUM_TARGET(MADV_RANDOM),
+    ENUM_TARGET(MADV_SEQUENTIAL),
+    ENUM_TARGET(MADV_WILLNEED),
+    ENUM_TARGET(MADV_DONTNEED),
+    ENUM_TARGET(MADV_FREE),
+    ENUM_TARGET(MADV_REMOVE),
+    ENUM_TARGET(MADV_DONTFORK),
+    ENUM_TARGET(MADV_DOFORK),
+    ENUM_TARGET(MADV_MERGEABLE),
+    ENUM_TARGET(MADV_UNMERGEABLE),
+    ENUM_TARGET(MADV_HUGEPAGE),
+    ENUM_TARGET(MADV_NOHUGEPAGE),
+    ENUM_TARGET(MADV_DONTDUMP),
+    ENUM_TARGET(MADV_DODUMP),
+    ENUM_TARGET(MADV_WIPEONFORK),
+    ENUM_TARGET(MADV_KEEPONFORK),
+    ENUM_TARGET(MADV_COLD),
+    ENUM_TARGET(MADV_PAGEOUT),
+    ENUM_TARGET(MADV_POPULATE_READ),
+    ENUM_TARGET(MADV_POPULATE_WRITE),
+    ENUM_TARGET(MADV_DONTNEED_LOCKED),
+    ENUM_END,
+};
+
+static void
+print_madvise(CPUArchState *cpu_env, 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_pointer(arg0, 0);
+    print_raw_param("%d", arg1, 0);
+    print_enums(madvise_advice, arg2, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
 static void
 print_fstat(CPUArchState *cpu_env, const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 215d971b2aea..c6f748505a9e 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -542,7 +542,7 @@
 { TARGET_NR_lstat64, "lstat64" , NULL, print_lstat64, NULL },
 #endif
 #ifdef TARGET_NR_madvise
-{ TARGET_NR_madvise, "madvise" , NULL, NULL, NULL },
+{ TARGET_NR_madvise, "madvise" , NULL, print_madvise, NULL },
 #endif
 #ifdef TARGET_NR_madvise1
 { TARGET_NR_madvise1, "madvise1" , NULL, NULL, NULL },
-- 
2.37.3



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

* [PULL 16/37] linux-user: Passthrough MADV_DONTNEED for certain file mappings
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (14 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 15/37] linux-user: Implement stracing madvise() Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 17/37] tests/tcg/linux-test: Add linux-madvise test Laurent Vivier
                   ` (21 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ilya Leoshkevich, Richard Henderson, Laurent Vivier

From: Ilya Leoshkevich <iii@linux.ibm.com>

This is a follow-up for commit 892a4f6a750a ("linux-user: Add partial
support for MADV_DONTNEED"), which added passthrough for anonymous
mappings. File mappings can be handled in a similar manner.

In order to do that, mark pages, for which mmap() was passed through,
with PAGE_PASSTHROUGH, and then allow madvise() passthrough for these
pages. Drop the explicit PAGE_ANON check, since anonymous mappings are
expected to have PAGE_PASSTHROUGH anyway.

Add PAGE_PASSTHROUGH to PAGE_STICKY in order to keep it on mprotect().

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220725125043.43048-1-iii@linux.ibm.com>
Message-Id: <20220906000839.1672934-5-iii@linux.ibm.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 accel/tcg/translate-all.c |  2 +-
 include/exec/cpu-all.h    |  6 ++++++
 linux-user/mmap.c         | 27 ++++++++++++++++++++++-----
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index f5e8592d4a47..d71d04d338db 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -2258,7 +2258,7 @@ int page_get_flags(target_ulong address)
 #ifndef PAGE_TARGET_STICKY
 #define PAGE_TARGET_STICKY  0
 #endif
-#define PAGE_STICKY  (PAGE_ANON | PAGE_TARGET_STICKY)
+#define PAGE_STICKY  (PAGE_ANON | PAGE_PASSTHROUGH | PAGE_TARGET_STICKY)
 
 /* Modify the flags of a page and invalidate the code if necessary.
    The flag PAGE_WRITE_ORG is positioned automatically depending
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 491629b9ba7a..16b7df41bf5e 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -262,6 +262,12 @@ extern const TargetPageBits target_page;
 #define PAGE_TARGET_1  0x0200
 #define PAGE_TARGET_2  0x0400
 
+/*
+ * For linux-user, indicates that the page is mapped with the same semantics
+ * in both guest and host.
+ */
+#define PAGE_PASSTHROUGH 0x0800
+
 #if defined(CONFIG_USER_ONLY)
 void page_dump(FILE *f);
 
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 942bec7e8528..e557f3626e5d 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -431,7 +431,8 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align)
 abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
                      int flags, int fd, abi_ulong offset)
 {
-    abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len;
+    abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len,
+              passthrough_start = -1, passthrough_end = -1;
     int page_flags, host_prot;
 
     mmap_lock();
@@ -544,6 +545,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
             host_start += offset - host_offset;
         }
         start = h2g(host_start);
+        passthrough_start = start;
+        passthrough_end = start + len;
     } else {
         if (start & ~TARGET_PAGE_MASK) {
             errno = EINVAL;
@@ -626,6 +629,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
                      host_prot, flags, fd, offset1);
             if (p == MAP_FAILED)
                 goto fail;
+            passthrough_start = real_start;
+            passthrough_end = real_end;
         }
     }
  the_end1:
@@ -633,7 +638,18 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
         page_flags |= PAGE_ANON;
     }
     page_flags |= PAGE_RESET;
-    page_set_flags(start, start + len, page_flags);
+    if (passthrough_start == passthrough_end) {
+        page_set_flags(start, start + len, page_flags);
+    } else {
+        if (start < passthrough_start) {
+            page_set_flags(start, passthrough_start, page_flags);
+        }
+        page_set_flags(passthrough_start, passthrough_end,
+                       page_flags | PAGE_PASSTHROUGH);
+        if (passthrough_end < start + len) {
+            page_set_flags(passthrough_end, start + len, page_flags);
+        }
+    }
  the_end:
     trace_target_mmap_complete(start);
     if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
@@ -852,7 +868,7 @@ static bool can_passthrough_madv_dontneed(abi_ulong start, abi_ulong end)
     }
 
     for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
-        if (!(page_get_flags(addr) & PAGE_ANON)) {
+        if (!(page_get_flags(addr) & PAGE_PASSTHROUGH)) {
             return false;
         }
     }
@@ -894,8 +910,9 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)
      * This is a hint, so ignoring and returning success is ok.
      *
      * This breaks MADV_DONTNEED, completely implementing which is quite
-     * complicated. However, there is one low-hanging fruit: host-page-aligned
-     * anonymous mappings. In this case passthrough is safe, so do it.
+     * complicated. However, there is one low-hanging fruit: mappings that are
+     * known to have the same semantics in the host and the guest. In this case
+     * passthrough is safe, so do it.
      */
     mmap_lock();
     if (advice == TARGET_MADV_DONTNEED &&
-- 
2.37.3



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

* [PULL 17/37] tests/tcg/linux-test: Add linux-madvise test
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (15 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 16/37] linux-user: Passthrough MADV_DONTNEED for certain file mappings Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 18/37] linux-user: Fix TARGET_PROT_SEM for XTENSA Laurent Vivier
                   ` (20 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ilya Leoshkevich, Richard Henderson, Laurent Vivier

From: Ilya Leoshkevich <iii@linux.ibm.com>

Add a test that checks madvise(MADV_DONTNEED) behavior with anonymous
and file mappings in order to prevent regressions.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220906000839.1672934-6-iii@linux.ibm.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 tests/tcg/multiarch/linux/linux-madvise.c | 70 +++++++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100644 tests/tcg/multiarch/linux/linux-madvise.c

diff --git a/tests/tcg/multiarch/linux/linux-madvise.c b/tests/tcg/multiarch/linux/linux-madvise.c
new file mode 100644
index 000000000000..29d0997e687c
--- /dev/null
+++ b/tests/tcg/multiarch/linux/linux-madvise.c
@@ -0,0 +1,70 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+static void test_anonymous(void)
+{
+    int pagesize = getpagesize();
+    char *page;
+    int ret;
+
+    page = mmap(NULL, pagesize, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+    assert(page != MAP_FAILED);
+
+    /* Check that mprotect() does not interfere with MADV_DONTNEED. */
+    ret = mprotect(page, pagesize, PROT_READ | PROT_WRITE);
+    assert(ret == 0);
+
+    /* Check that MADV_DONTNEED clears the page. */
+    *page = 42;
+    ret = madvise(page, pagesize, MADV_DONTNEED);
+    assert(ret == 0);
+    assert(*page == 0);
+
+    ret = munmap(page, pagesize);
+    assert(ret == 0);
+}
+
+static void test_file(void)
+{
+    char tempname[] = "/tmp/.cmadviseXXXXXX";
+    int pagesize = getpagesize();
+    ssize_t written;
+    char c = 42;
+    char *page;
+    int ret;
+    int fd;
+
+    fd = mkstemp(tempname);
+    assert(fd != -1);
+    ret = unlink(tempname);
+    assert(ret == 0);
+    written = write(fd, &c, sizeof(c));
+    assert(written == sizeof(c));
+    page = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE, fd, 0);
+    assert(page != MAP_FAILED);
+
+    /* Check that mprotect() does not interfere with MADV_DONTNEED. */
+    ret = mprotect(page, pagesize, PROT_READ | PROT_WRITE);
+    assert(ret == 0);
+
+    /* Check that MADV_DONTNEED resets the page. */
+    *page = 0;
+    ret = madvise(page, pagesize, MADV_DONTNEED);
+    assert(ret == 0);
+    assert(*page == c);
+
+    ret = munmap(page, pagesize);
+    assert(ret == 0);
+    ret = close(fd);
+    assert(ret == 0);
+}
+
+int main(void)
+{
+    test_anonymous();
+    test_file();
+
+    return EXIT_SUCCESS;
+}
-- 
2.37.3



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

* [PULL 18/37] linux-user: Fix TARGET_PROT_SEM for XTENSA
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (16 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 17/37] tests/tcg/linux-test: Add linux-madvise test Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 19/37] linux-user: Add proper strace format strings for getdents()/getdents64() Laurent Vivier
                   ` (19 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

The xtensa platform has a value of 0x10 for PROT_SEM.

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220924114501.21767-2-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall_defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 85b0f33e91d7..1e3577bfa56f 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -1246,7 +1246,7 @@ struct target_winsize {
 
 #include "termbits.h"
 
-#if defined(TARGET_MIPS)
+#if defined(TARGET_MIPS) || defined(TARGET_XTENSA)
 #define TARGET_PROT_SEM         0x10
 #else
 #define TARGET_PROT_SEM         0x08
-- 
2.37.3



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

* [PULL 19/37] linux-user: Add proper strace format strings for getdents()/getdents64()
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (17 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 18/37] linux-user: Fix TARGET_PROT_SEM for XTENSA Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 20/37] linux-user/hppa: Add signal trampoline for hppa target Laurent Vivier
                   ` (18 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

Signed-off-by: Helge Deller <deller@gmx.de>
Message-Id: <20220924114501.21767-3-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.list | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/strace.list b/linux-user/strace.list
index c6f748505a9e..f8a771b4f256 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -279,10 +279,10 @@
 { TARGET_NR_getcwd, "getcwd" , "%s(%p,%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getdents
-{ TARGET_NR_getdents, "getdents" , NULL, NULL, NULL },
+{ TARGET_NR_getdents, "getdents" , "%s(%d,%p,%u)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getdents64
-{ TARGET_NR_getdents64, "getdents64" , NULL, NULL, NULL },
+{ TARGET_NR_getdents64, "getdents64" , "%s(%d,%p,%u)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getdomainname
 { TARGET_NR_getdomainname, "getdomainname" , NULL, NULL, NULL },
-- 
2.37.3



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

* [PULL 20/37] linux-user/hppa: Add signal trampoline for hppa target
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (18 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 19/37] linux-user: Add proper strace format strings for getdents()/getdents64() Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 21/37] linux-user/hppa: Drop stack guard page on " Laurent Vivier
                   ` (17 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

In Linux kernel v5.18 the vDSO for signal trampoline was added.
This code mimiks the bare minimum of this vDSO and thus avoids that the
parisc emulation needs executable stacks.

Signed-off-by: Helge Deller <deller@gmx.de>
Message-Id: <20220924114501.21767-4-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/hppa/signal.c        | 41 +++++++++++++++++++++++++--------
 linux-user/hppa/target_signal.h | 14 +----------
 2 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/linux-user/hppa/signal.c b/linux-user/hppa/signal.c
index 962f551c0429..396e310dc92d 100644
--- a/linux-user/hppa/signal.c
+++ b/linux-user/hppa/signal.c
@@ -41,7 +41,7 @@ struct target_ucontext {
 };
 
 struct target_rt_sigframe {
-    abi_uint tramp[9];
+    abi_uint tramp[2];  /* syscall restart return address */
     target_siginfo_t info;
     struct target_ucontext uc;
     /* hidden location of upper halves of pa2.0 64-bit gregs */
@@ -101,9 +101,15 @@ static void restore_sigcontext(CPUArchState *env, struct target_sigcontext *sc)
     __get_user(env->cr[CR_SAR], &sc->sc_sar);
 }
 
-/* No, this doesn't look right, but it's copied straight from the kernel.  */
+#if TARGET_ABI_BITS == 32
+#define SIGFRAME                64
+#define FUNCTIONCALLFRAME       48
+#else
+#define SIGFRAME                128
+#define FUNCTIONCALLFRAME       96
+#endif
 #define PARISC_RT_SIGFRAME_SIZE32 \
-    ((sizeof(struct target_rt_sigframe) + 48 + 64) & -64)
+    ((sizeof(struct target_rt_sigframe) + FUNCTIONCALLFRAME + SIGFRAME) & -SIGFRAME)
 
 void setup_rt_frame(int sig, struct target_sigaction *ka,
                     target_siginfo_t *info,
@@ -118,7 +124,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     if ((ka->sa_flags & TARGET_SA_ONSTACK) && !sas_ss_flags(sp)) {
         sp = (ts->sigaltstack_used.ss_sp + 0x7f) & ~0x3f;
     }
-    frame_addr = QEMU_ALIGN_UP(sp, 64);
+    frame_addr = QEMU_ALIGN_UP(sp, SIGFRAME);
     sp = frame_addr + PARISC_RT_SIGFRAME_SIZE32;
 
     trace_user_setup_rt_frame(env, frame_addr);
@@ -139,14 +145,9 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
 
     setup_sigcontext(&frame->uc.tuc_mcontext, env);
 
-    __put_user(0x34190000, frame->tramp + 0); /* ldi 0,%r25 */
-    __put_user(0x3414015a, frame->tramp + 1); /* ldi __NR_rt_sigreturn,%r20 */
-    __put_user(0xe4008200, frame->tramp + 2); /* be,l 0x100(%sr2,%r0) */
-    __put_user(0x08000240, frame->tramp + 3); /* nop */
-
     unlock_user_struct(frame, frame_addr, 1);
 
-    env->gr[2] = h2g(frame->tramp);
+    env->gr[2] = default_rt_sigreturn;
     env->gr[30] = sp;
     env->gr[26] = sig;
     env->gr[25] = h2g(&frame->info);
@@ -197,3 +198,23 @@ long do_rt_sigreturn(CPUArchState *env)
     force_sig(TARGET_SIGSEGV);
     return -QEMU_ESIGRETURN;
 }
+
+void setup_sigtramp(abi_ulong sigtramp_page)
+{
+    uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 6*4, 0);
+    abi_ulong SIGFRAME_CONTEXT_REGS32;
+    assert(tramp != NULL);
+
+    SIGFRAME_CONTEXT_REGS32 = offsetof(struct target_rt_sigframe, uc.tuc_mcontext);
+    SIGFRAME_CONTEXT_REGS32 -= PARISC_RT_SIGFRAME_SIZE32;
+
+    __put_user(SIGFRAME_CONTEXT_REGS32, tramp + 0);
+    __put_user(0x08000240, tramp + 1);  /* nop - b/c dwarf2 unwind routines */
+    __put_user(0x34190000, tramp + 2);  /* ldi 0, %r25 (in_syscall=0) */
+    __put_user(0x3414015a, tramp + 3);  /* ldi __NR_rt_sigreturn, %r20 */
+    __put_user(0xe4008200, tramp + 4);  /* ble 0x100(%sr2, %r0) */
+    __put_user(0x08000240, tramp + 5);  /* nop */
+
+    default_rt_sigreturn = (sigtramp_page + 8) | 3;
+    unlock_user(tramp, sigtramp_page, 6*4);
+}
diff --git a/linux-user/hppa/target_signal.h b/linux-user/hppa/target_signal.h
index af6c2fce589d..190bb3d653b6 100644
--- a/linux-user/hppa/target_signal.h
+++ b/linux-user/hppa/target_signal.h
@@ -70,18 +70,6 @@ typedef struct target_sigaltstack {
 /* mask for all SS_xxx flags */
 #define TARGET_SS_FLAG_BITS  TARGET_SS_AUTODISARM
 
-/*
- * We cannot use a bare sigtramp page for hppa-linux.
- *
- * Unlike other guests where we use the instructions at PC to validate
- * an offset from SP, the hppa libgcc signal frame fallback unwinding uses
- * the PC address itself to find the frame.  This is due to the fact that
- * the hppa grows the stack upward, and the frame is of unknown size.
- *
- * TODO: We should be able to use a VDSO to address this, by providing
- * proper unwind info for the sigtramp code, at which point the fallback
- * unwinder will not be used.
- */
-#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0
+#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
 
 #endif /* HPPA_TARGET_SIGNAL_H */
-- 
2.37.3



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

* [PULL 21/37] linux-user/hppa: Drop stack guard page on hppa target
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (19 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 20/37] linux-user/hppa: Add signal trampoline for hppa target Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 22/37] linux-user/hppa: Increase guest stack size to 80MB for " Laurent Vivier
                   ` (16 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

The stack-overflow check when building the "grep" debian package fails
on the debian hppa target. Reason is, that the guard page at the top
of the stack (which is added by qemu) prevents the fault handler in the
grep program to properly detect the stack overflow.

The Linux kernel on a physical machine doesn't install a guard page
either, so drop it and as such fix the build of "grep".

Signed-off-by: Helge Deller <deller@gmx.de>
Message-Id: <20220924114501.21767-5-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/elfload.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index ba5c4c02e591..c7e3f1d47c16 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2096,9 +2096,15 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm,
     if (size < STACK_LOWER_LIMIT) {
         size = STACK_LOWER_LIMIT;
     }
-    guard = TARGET_PAGE_SIZE;
-    if (guard < qemu_real_host_page_size()) {
-        guard = qemu_real_host_page_size();
+
+    if (STACK_GROWS_DOWN) {
+        guard = TARGET_PAGE_SIZE;
+        if (guard < qemu_real_host_page_size()) {
+            guard = qemu_real_host_page_size();
+        }
+    } else {
+        /* no guard page for hppa target where stack grows upwards. */
+        guard = 0;
     }
 
     prot = PROT_READ | PROT_WRITE;
@@ -2118,7 +2124,6 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm,
         info->stack_limit = error + guard;
         return info->stack_limit + size - sizeof(void *);
     } else {
-        target_mprotect(error + size, guard, PROT_NONE);
         info->stack_limit = error + size;
         return error;
     }
-- 
2.37.3



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

* [PULL 22/37] linux-user/hppa: Increase guest stack size to 80MB for hppa target
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (20 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 21/37] linux-user/hppa: Drop stack guard page on " Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 23/37] linux-user/hppa: Allow PROT_GROWSUP and PROT_GROWSDOWN in mprotect() Laurent Vivier
                   ` (15 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

The hppa target requires a much bigger stack than many other targets,
and the Linux kernel allocates 80 MB by default for it.

This patch increases the guest stack for hppa to 80MB, and prevents
that this default stack size gets reduced by a lower stack limit on the
host.

Since the stack grows upwards on hppa, the stack_limit value marks the
upper boundary of the stack. Fix the output of /proc/self/maps (in the
guest) to show the [stack] marker on the correct memory area.

Signed-off-by: Helge Deller <deller@gmx.de>
Message-Id: <20220924114501.21767-6-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/hppa/target_syscall.h | 2 ++
 linux-user/main.c                | 9 +++++++--
 linux-user/syscall.c             | 4 ++++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/linux-user/hppa/target_syscall.h b/linux-user/hppa/target_syscall.h
index 4b382c1fcf4a..9a8f8ca62817 100644
--- a/linux-user/hppa/target_syscall.h
+++ b/linux-user/hppa/target_syscall.h
@@ -26,4 +26,6 @@ struct target_pt_regs {
 #define TARGET_MCL_FUTURE  2
 #define TARGET_MCL_ONFAULT 4
 
+#define TARGET_DEFAULT_STACK_SIZE	80 * 1024 * 1024UL
+
 #endif /* HPPA_TARGET_SYSCALL_H */
diff --git a/linux-user/main.c b/linux-user/main.c
index e44bdb17b853..88fccfe26149 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -124,10 +124,14 @@ static void usage(int exitcode);
 static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX;
 const char *qemu_uname_release;
 
+#if !defined(TARGET_DEFAULT_STACK_SIZE)
 /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
    we allocate a bigger stack. Need a better solution, for example
    by remapping the process stack directly at the right place */
-unsigned long guest_stack_size = 8 * 1024 * 1024UL;
+#define TARGET_DEFAULT_STACK_SIZE	8 * 1024 * 1024UL
+#endif
+
+unsigned long guest_stack_size = TARGET_DEFAULT_STACK_SIZE;
 
 /***********************************************************/
 /* Helper routines for implementing atomic operations.  */
@@ -668,7 +672,8 @@ int main(int argc, char **argv, char **envp)
         struct rlimit lim;
         if (getrlimit(RLIMIT_STACK, &lim) == 0
             && lim.rlim_cur != RLIM_INFINITY
-            && lim.rlim_cur == (target_long)lim.rlim_cur) {
+            && lim.rlim_cur == (target_long)lim.rlim_cur
+            && lim.rlim_cur > guest_stack_size) {
             guest_stack_size = lim.rlim_cur;
         }
     }
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 850410c9b553..f87b36b2491f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8036,7 +8036,11 @@ static int open_self_maps(CPUArchState *cpu_env, int fd)
                 continue;
             }
 
+#ifdef TARGET_HPPA
+            if (h2g(max) == ts->info->stack_limit) {
+#else
             if (h2g(min) == ts->info->stack_limit) {
+#endif
                 path = "[stack]";
             } else {
                 path = e->path;
-- 
2.37.3



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

* [PULL 23/37] linux-user/hppa: Allow PROT_GROWSUP and PROT_GROWSDOWN in mprotect()
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (21 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 22/37] linux-user/hppa: Increase guest stack size to 80MB for " Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 24/37] linux-user/hppa: Fix setup_sigcontext() Laurent Vivier
                   ` (14 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

The hppa platform uses an upwards-growing stack and required in Linux
kernels < 5.18 an executable stack for signal processing.  For that some
executables and libraries are marked to have an executable stack, for
which glibc uses the mprotect() syscall to mark the stack like this:
 mprotect(xfa000000,4096,PROT_EXEC|PROT_READ|PROT_WRITE|PROT_GROWSUP).

Currently qemu will return -TARGET_EINVAL for this syscall because of the
checks in validate_prot_to_pageflags(), which doesn't allow the
PROT_GROWSUP or PROT_GROWSDOWN flags and thus triggers this error in the
guest:
 error while loading shared libraries: libc.so.6: cannot enable executable stack as shared object requires: Invalid argument

Allow mprotect() to handle both flags and thus fix the guest.
The glibc tst-execstack testcase can be used to reproduce the issue.

Signed-off-by: Helge Deller <deller@gmx.de>
Message-Id: <20220924114501.21767-7-deller@gmx.de>
[lvivier: s/elif TARGET_HPPA/elif defined(TARGET_HPPA)/]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/mmap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index e557f3626e5d..28f3bc85ed45 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -106,6 +106,8 @@ static int validate_prot_to_pageflags(int *host_prot, int prot)
             page_flags |= PAGE_MTE;
         }
     }
+#elif defined(TARGET_HPPA)
+    valid |= PROT_GROWSDOWN | PROT_GROWSUP;
 #endif
 
     return prot & ~valid ? 0 : page_flags;
-- 
2.37.3



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

* [PULL 24/37] linux-user/hppa: Fix setup_sigcontext()
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (22 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 23/37] linux-user/hppa: Allow PROT_GROWSUP and PROT_GROWSDOWN in mprotect() Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 25/37] linux-user: fix bug about missing signum convert of sigqueue Laurent Vivier
                   ` (13 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

We don't emulate a preemptive kernel on this level, and the hppa architecture
doesn't allow context switches on the gateway page. So we always have to return
to sc_iaoq[] and not to gr[31].
This fixes the remaining random segfaults which still occured.

Signed-off-by: Helge Deller <deller@gmx.de>
Message-Id: <20220924114501.21767-8-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/hppa/signal.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/linux-user/hppa/signal.c b/linux-user/hppa/signal.c
index 396e310dc92d..f253a1586461 100644
--- a/linux-user/hppa/signal.c
+++ b/linux-user/hppa/signal.c
@@ -49,23 +49,13 @@ struct target_rt_sigframe {
 
 static void setup_sigcontext(struct target_sigcontext *sc, CPUArchState *env)
 {
-    int flags = 0;
     int i;
 
-    /* ??? if on_sig_stack, flags |= 1 (PARISC_SC_FLAG_ONSTACK).  */
-
-    if (env->iaoq_f < TARGET_PAGE_SIZE) {
-        /* In the gateway page, executing a syscall.  */
-        flags |= 2; /* PARISC_SC_FLAG_IN_SYSCALL */
-        __put_user(env->gr[31], &sc->sc_iaoq[0]);
-        __put_user(env->gr[31] + 4, &sc->sc_iaoq[1]);
-    } else {
-        __put_user(env->iaoq_f, &sc->sc_iaoq[0]);
-        __put_user(env->iaoq_b, &sc->sc_iaoq[1]);
-    }
+    __put_user(env->iaoq_f, &sc->sc_iaoq[0]);
+    __put_user(env->iaoq_b, &sc->sc_iaoq[1]);
     __put_user(0, &sc->sc_iasq[0]);
     __put_user(0, &sc->sc_iasq[1]);
-    __put_user(flags, &sc->sc_flags);
+    __put_user(0, &sc->sc_flags);
 
     __put_user(cpu_hppa_get_psw(env), &sc->sc_gr[0]);
     for (i = 1; i < 32; ++i) {
-- 
2.37.3



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

* [PULL 25/37] linux-user: fix bug about missing signum convert of sigqueue
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (23 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 24/37] linux-user/hppa: Fix setup_sigcontext() Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 26/37] linux-user: Don't assume 0 is not a valid host timer_t value Laurent Vivier
                   ` (12 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: fanwenjie, Philippe Mathieu-Daudé, Laurent Vivier

From: fanwenjie <fanwj@mail.ustc.edu.cn>

Fixes: 66fb9763af ("basic signal handling")
Fixes: cf8b8bfc50 ("linux-user: add support for rt_tgsigqueueinfo() system call")
Signed-off-by: fanwenjie <fanwj@mail.ustc.edu.cn>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f87b36b2491f..54b29f3b406a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9728,7 +9728,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
             }
             target_to_host_siginfo(&uinfo, p);
             unlock_user(p, arg3, 0);
-            ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo));
+            ret = get_errno(sys_rt_sigqueueinfo(arg1, target_to_host_signal(arg2), &uinfo));
         }
         return ret;
     case TARGET_NR_rt_tgsigqueueinfo:
@@ -9741,7 +9741,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
             }
             target_to_host_siginfo(&uinfo, p);
             unlock_user(p, arg4, 0);
-            ret = get_errno(sys_rt_tgsigqueueinfo(arg1, arg2, arg3, &uinfo));
+            ret = get_errno(sys_rt_tgsigqueueinfo(arg1, arg2, target_to_host_signal(arg3), &uinfo));
         }
         return ret;
 #ifdef TARGET_NR_sigreturn
-- 
2.37.3



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

* [PULL 26/37] linux-user: Don't assume 0 is not a valid host timer_t value
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (24 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 25/37] linux-user: fix bug about missing signum convert of sigqueue Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 27/37] linux-user/s390x: Save/restore fpc when handling a signal Laurent Vivier
                   ` (11 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Jon Alduan, Laurent Vivier

From: Peter Maydell <peter.maydell@linaro.org>

For handling guest POSIX timers, we currently use an array
g_posix_timers[], whose entries are a host timer_t value, or 0 for
"this slot is unused".  When the guest calls the timer_create syscall
we look through the array for a slot containing 0, and use that for
the new timer.

This scheme assumes that host timer_t values can never be zero.  This
is unfortunately not a valid assumption -- for some host libc
versions, timer_t values are simply indexes starting at 0.  When
using this kind of host libc, the effect is that the first and second
timers end up sharing a slot, and so when the guest tries to operate
on the first timer it changes the second timer instead.

Rework the timer allocation code, so that:
 * the 'slot in use' indication uses a separate array from the
   host timer_t array
 * we grab the free slot atomically, to avoid races when multiple
   threads call timer_create simultaneously
 * releasing an allocated slot is abstracted out into a new
   free_host_timer_slot() function called in the correct places

This fixes:
 * problems on hosts where timer_t 0 is valid
 * the FIXME in next_free_host_timer() about locking
 * bugs in the error paths in timer_create where we forgot to release
   the slot we grabbed, or forgot to free the host timer

Reported-by: Jon Alduan <jon.alduan@gmail.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220725110035.1273441-1-peter.maydell@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 54b29f3b406a..e0e0f058121f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -525,20 +525,25 @@ _syscall4(int, sys_prlimit64, pid_t, pid, int, resource,
 
 #if defined(TARGET_NR_timer_create)
 /* Maximum of 32 active POSIX timers allowed at any one time. */
-static timer_t g_posix_timers[32] = { 0, } ;
+#define GUEST_TIMER_MAX 32
+static timer_t g_posix_timers[GUEST_TIMER_MAX];
+static int g_posix_timer_allocated[GUEST_TIMER_MAX];
 
 static inline int next_free_host_timer(void)
 {
-    int k ;
-    /* FIXME: Does finding the next free slot require a lock? */
-    for (k = 0; k < ARRAY_SIZE(g_posix_timers); k++) {
-        if (g_posix_timers[k] == 0) {
-            g_posix_timers[k] = (timer_t) 1;
+    int k;
+    for (k = 0; k < ARRAY_SIZE(g_posix_timer_allocated); k++) {
+        if (qatomic_xchg(g_posix_timer_allocated + k, 1) == 0) {
             return k;
         }
     }
     return -1;
 }
+
+static inline void free_host_timer_slot(int id)
+{
+    qatomic_store_release(g_posix_timer_allocated + id, 0);
+}
 #endif
 
 static inline int host_to_target_errno(int host_errno)
@@ -12896,15 +12901,18 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
                 phost_sevp = &host_sevp;
                 ret = target_to_host_sigevent(phost_sevp, arg2);
                 if (ret != 0) {
+                    free_host_timer_slot(timer_index);
                     return ret;
                 }
             }
 
             ret = get_errno(timer_create(clkid, phost_sevp, phtimer));
             if (ret) {
-                phtimer = NULL;
+                free_host_timer_slot(timer_index);
             } else {
                 if (put_user(TIMER_MAGIC | timer_index, arg3, target_timer_t)) {
+                    timer_delete(*phtimer);
+                    free_host_timer_slot(timer_index);
                     return -TARGET_EFAULT;
                 }
             }
@@ -13040,7 +13048,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         } else {
             timer_t htimer = g_posix_timers[timerid];
             ret = get_errno(timer_delete(htimer));
-            g_posix_timers[timerid] = 0;
+            free_host_timer_slot(timerid);
         }
         return ret;
     }
-- 
2.37.3



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

* [PULL 27/37] linux-user/s390x: Save/restore fpc when handling a signal
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (25 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 26/37] linux-user: Don't assume 0 is not a valid host timer_t value Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 28/37] linux-user: Introduce stubs for ELF AT_BASE_PLATFORM Laurent Vivier
                   ` (10 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ilya Leoshkevich, Richard Henderson, Laurent Vivier

From: Ilya Leoshkevich <iii@linux.ibm.com>

Linux kernel does this in fpregs_store() and fpregs_load(), so
qemu-user should do this as well.

Found by running valgrind's none/tests/s390x/test_sig.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220817123902.585623-1-iii@linux.ibm.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/s390x/signal.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c
index 4979c4b01791..f72165576f3b 100644
--- a/linux-user/s390x/signal.c
+++ b/linux-user/s390x/signal.c
@@ -146,6 +146,7 @@ static void save_sigregs(CPUS390XState *env, target_sigregs *sregs)
      * We have to store the fp registers to current->thread.fp_regs
      * to merge them with the emulated registers.
      */
+    __put_user(env->fpc, &sregs->fpregs.fpc);
     for (i = 0; i < 16; i++) {
         __put_user(*get_freg(env, i), &sregs->fpregs.fprs[i]);
     }
@@ -331,6 +332,7 @@ static void restore_sigregs(CPUS390XState *env, target_sigregs *sc)
     for (i = 0; i < 16; i++) {
         __get_user(env->aregs[i], &sc->regs.acrs[i]);
     }
+    __get_user(env->fpc, &sc->fpregs.fpc);
     for (i = 0; i < 16; i++) {
         __get_user(*get_freg(env, i), &sc->fpregs.fprs[i]);
     }
-- 
2.37.3



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

* [PULL 28/37] linux-user: Introduce stubs for ELF AT_BASE_PLATFORM
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (26 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 27/37] linux-user/s390x: Save/restore fpc when handling a signal Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 29/37] linux-user: Set ELF_BASE_PLATFORM for MIPS Laurent Vivier
                   ` (9 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jiaxun Yang, Philippe Mathieu-Daudé, Laurent Vivier

From: Jiaxun Yang <jiaxun.yang@flygoat.com>

AT_BASE_PLATFORM is a elf auxiliary vector pointing to a string
to pass some architecture information.
See getauxval(3) man-page.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20220803103009.95972-2-jiaxun.yang@flygoat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/elfload.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index c7e3f1d47c16..581fbc858b48 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1776,6 +1776,10 @@ static inline void init_thread(struct target_pt_regs *regs,
 
 #endif /* TARGET_HEXAGON */
 
+#ifndef ELF_BASE_PLATFORM
+#define ELF_BASE_PLATFORM (NULL)
+#endif
+
 #ifndef ELF_PLATFORM
 #define ELF_PLATFORM (NULL)
 #endif
@@ -2220,8 +2224,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     int i;
     abi_ulong u_rand_bytes;
     uint8_t k_rand_bytes[16];
-    abi_ulong u_platform;
-    const char *k_platform;
+    abi_ulong u_platform, u_base_platform;
+    const char *k_platform, *k_base_platform;
     const int n = sizeof(elf_addr_t);
 
     sp = p;
@@ -2243,6 +2247,22 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
         }
     }
 
+    u_base_platform = 0;
+    k_base_platform = ELF_BASE_PLATFORM;
+    if (k_base_platform) {
+        size_t len = strlen(k_base_platform) + 1;
+        if (STACK_GROWS_DOWN) {
+            sp -= (len + n - 1) & ~(n - 1);
+            u_base_platform = sp;
+            /* FIXME - check return value of memcpy_to_target() for failure */
+            memcpy_to_target(sp, k_base_platform, len);
+        } else {
+            memcpy_to_target(sp, k_base_platform, len);
+            u_base_platform = sp;
+            sp += len + 1;
+        }
+    }
+
     u_platform = 0;
     k_platform = ELF_PLATFORM;
     if (k_platform) {
@@ -2284,6 +2304,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     }
 
     size = (DLINFO_ITEMS + 1) * 2;
+    if (k_base_platform)
+        size += 2;
     if (k_platform)
         size += 2;
 #ifdef DLINFO_ARCH_ITEMS
@@ -2361,6 +2383,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     NEW_AUX_ENT(AT_HWCAP2, (abi_ulong) ELF_HWCAP2);
 #endif
 
+    if (u_base_platform) {
+        NEW_AUX_ENT(AT_BASE_PLATFORM, u_base_platform);
+    }
     if (u_platform) {
         NEW_AUX_ENT(AT_PLATFORM, u_platform);
     }
-- 
2.37.3



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

* [PULL 29/37] linux-user: Set ELF_BASE_PLATFORM for MIPS
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (27 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 28/37] linux-user: Introduce stubs for ELF AT_BASE_PLATFORM Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 30/37] linux-user: Combine do_futex and do_futex_time64 Laurent Vivier
                   ` (8 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jiaxun Yang, Philippe Mathieu-Daudé, Laurent Vivier

From: Jiaxun Yang <jiaxun.yang@flygoat.com>

Match most appropriate base platform string based on insn_flags.
Logic is aligned with aligned with set_isa() from
arch/mips/kernel/cpu-probe.c in Linux kernel.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20220803103009.95972-3-jiaxun.yang@flygoat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/elfload.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 581fbc858b48..20894b633f58 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1080,6 +1080,37 @@ static uint32_t get_elf_hwcap(void)
 #define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
 #endif
 
+#define ELF_BASE_PLATFORM get_elf_base_platform()
+
+#define MATCH_PLATFORM_INSN(_flags, _base_platform)      \
+    do { if ((cpu->env.insn_flags & (_flags)) == _flags) \
+    { return _base_platform; } } while (0)
+
+static const char *get_elf_base_platform(void)
+{
+    MIPSCPU *cpu = MIPS_CPU(thread_cpu);
+
+    /* 64 bit ISAs goes first */
+    MATCH_PLATFORM_INSN(CPU_MIPS64R6, "mips64r6");
+    MATCH_PLATFORM_INSN(CPU_MIPS64R5, "mips64r5");
+    MATCH_PLATFORM_INSN(CPU_MIPS64R2, "mips64r2");
+    MATCH_PLATFORM_INSN(CPU_MIPS64R1, "mips64");
+    MATCH_PLATFORM_INSN(CPU_MIPS5, "mips5");
+    MATCH_PLATFORM_INSN(CPU_MIPS4, "mips4");
+    MATCH_PLATFORM_INSN(CPU_MIPS3, "mips3");
+
+    /* 32 bit ISAs */
+    MATCH_PLATFORM_INSN(CPU_MIPS32R6, "mips32r6");
+    MATCH_PLATFORM_INSN(CPU_MIPS32R5, "mips32r5");
+    MATCH_PLATFORM_INSN(CPU_MIPS32R2, "mips32r2");
+    MATCH_PLATFORM_INSN(CPU_MIPS32R1, "mips32");
+    MATCH_PLATFORM_INSN(CPU_MIPS2, "mips2");
+
+    /* Fallback */
+    return "mips";
+}
+#undef MATCH_PLATFORM_INSN
+
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
 {
-- 
2.37.3



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

* [PULL 30/37] linux-user: Combine do_futex and do_futex_time64
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (28 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 29/37] linux-user: Set ELF_BASE_PLATFORM for MIPS Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 31/37] linux-user: Sink call to do_safe_futex Laurent Vivier
                   ` (7 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, Laurent Vivier

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

Pass a boolean to select between time32 and time64.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220829021006.67305-2-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 67 ++++++++------------------------------------
 1 file changed, 11 insertions(+), 56 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e0e0f058121f..af3a605fc458 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7768,9 +7768,10 @@ static int do_safe_futex(int *uaddr, int op, int val,
    futexes locally would make futexes shared between multiple processes
    tricky.  However they're probably useless because guest atomic
    operations won't work either.  */
-#if defined(TARGET_NR_futex)
-static int do_futex(CPUState *cpu, target_ulong uaddr, int op, int val,
-                    target_ulong timeout, target_ulong uaddr2, int val3)
+#if defined(TARGET_NR_futex) || defined(TARGET_NR_futex_time64)
+static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
+                    int op, int val, target_ulong timeout,
+                    target_ulong uaddr2, int val3)
 {
     struct timespec ts, *pts;
     int base_op;
@@ -7787,7 +7788,11 @@ static int do_futex(CPUState *cpu, target_ulong uaddr, int op, int val,
     case FUTEX_WAIT_BITSET:
         if (timeout) {
             pts = &ts;
-            target_to_host_timespec(pts, timeout);
+            if (time64
+                ? target_to_host_timespec64(pts, timeout)
+                : target_to_host_timespec(pts, timeout)) {
+                return -TARGET_EFAULT;
+            }
         } else {
             pts = NULL;
         }
@@ -7817,56 +7822,6 @@ static int do_futex(CPUState *cpu, target_ulong uaddr, int op, int val,
 }
 #endif
 
-#if defined(TARGET_NR_futex_time64)
-static int do_futex_time64(CPUState *cpu, target_ulong uaddr, int op,
-                           int val, target_ulong timeout,
-                           target_ulong uaddr2, int val3)
-{
-    struct timespec ts, *pts;
-    int base_op;
-
-    /* ??? We assume FUTEX_* constants are the same on both host
-       and target.  */
-#ifdef FUTEX_CMD_MASK
-    base_op = op & FUTEX_CMD_MASK;
-#else
-    base_op = op;
-#endif
-    switch (base_op) {
-    case FUTEX_WAIT:
-    case FUTEX_WAIT_BITSET:
-        if (timeout) {
-            pts = &ts;
-            if (target_to_host_timespec64(pts, timeout)) {
-                return -TARGET_EFAULT;
-            }
-        } else {
-            pts = NULL;
-        }
-        return do_safe_futex(g2h(cpu, uaddr), op,
-                             tswap32(val), pts, NULL, val3);
-    case FUTEX_WAKE:
-        return do_safe_futex(g2h(cpu, uaddr), op, val, NULL, NULL, 0);
-    case FUTEX_FD:
-        return do_safe_futex(g2h(cpu, uaddr), op, val, NULL, NULL, 0);
-    case FUTEX_REQUEUE:
-    case FUTEX_CMP_REQUEUE:
-    case FUTEX_WAKE_OP:
-        /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the
-           TIMEOUT parameter is interpreted as a uint32_t by the kernel.
-           But the prototype takes a `struct timespec *'; insert casts
-           to satisfy the compiler.  We do not need to tswap TIMEOUT
-           since it's not compared to guest memory.  */
-        pts = (struct timespec *)(uintptr_t) timeout;
-        return do_safe_futex(g2h(cpu, uaddr), op, val, pts, g2h(cpu, uaddr2),
-                             (base_op == FUTEX_CMP_REQUEUE
-                              ? tswap32(val3) : val3));
-    default:
-        return -TARGET_ENOSYS;
-    }
-}
-#endif
-
 #if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
 static abi_long do_name_to_handle_at(abi_long dirfd, abi_long pathname,
                                      abi_long handle, abi_long mount_id,
@@ -12372,11 +12327,11 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
 #endif
 #ifdef TARGET_NR_futex
     case TARGET_NR_futex:
-        return do_futex(cpu, arg1, arg2, arg3, arg4, arg5, arg6);
+        return do_futex(cpu, false, arg1, arg2, arg3, arg4, arg5, arg6);
 #endif
 #ifdef TARGET_NR_futex_time64
     case TARGET_NR_futex_time64:
-        return do_futex_time64(cpu, arg1, arg2, arg3, arg4, arg5, arg6);
+        return do_futex(cpu, true, arg1, arg2, arg3, arg4, arg5, arg6);
 #endif
 #ifdef CONFIG_INOTIFY
 #if defined(TARGET_NR_inotify_init)
-- 
2.37.3



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

* [PULL 31/37] linux-user: Sink call to do_safe_futex
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (29 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 30/37] linux-user: Combine do_futex and do_futex_time64 Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 32/37] linux-user: Implement FUTEX_WAKE_BITSET Laurent Vivier
                   ` (6 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, Laurent Vivier

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

Leave only the argument adjustments within the shift,
and sink the actual syscall to the end.  Sink the
timespec conversion as well, as there will be more users.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220829021006.67305-3-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 60 +++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index af3a605fc458..17e17f480456 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7773,11 +7773,11 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
                     int op, int val, target_ulong timeout,
                     target_ulong uaddr2, int val3)
 {
-    struct timespec ts, *pts;
+    struct timespec ts, *pts = NULL;
+    void *haddr2 = NULL;
     int base_op;
 
-    /* ??? We assume FUTEX_* constants are the same on both host
-       and target.  */
+    /* We assume FUTEX_* constants are the same on both host and target. */
 #ifdef FUTEX_CMD_MASK
     base_op = op & FUTEX_CMD_MASK;
 #else
@@ -7786,39 +7786,41 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
     switch (base_op) {
     case FUTEX_WAIT:
     case FUTEX_WAIT_BITSET:
-        if (timeout) {
-            pts = &ts;
-            if (time64
-                ? target_to_host_timespec64(pts, timeout)
-                : target_to_host_timespec(pts, timeout)) {
-                return -TARGET_EFAULT;
-            }
-        } else {
-            pts = NULL;
-        }
-        return do_safe_futex(g2h(cpu, uaddr),
-                             op, tswap32(val), pts, NULL, val3);
+        val = tswap32(val);
+        break;
     case FUTEX_WAKE:
-        return do_safe_futex(g2h(cpu, uaddr),
-                             op, val, NULL, NULL, 0);
+        timeout = 0;
+        break;
     case FUTEX_FD:
-        return do_safe_futex(g2h(cpu, uaddr),
-                             op, val, NULL, NULL, 0);
-    case FUTEX_REQUEUE:
+        timeout = 0;
+        break;
     case FUTEX_CMP_REQUEUE:
+        val3 = tswap32(val3);
+        /* fall through */
+    case FUTEX_REQUEUE:
     case FUTEX_WAKE_OP:
-        /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the
-           TIMEOUT parameter is interpreted as a uint32_t by the kernel.
-           But the prototype takes a `struct timespec *'; insert casts
-           to satisfy the compiler.  We do not need to tswap TIMEOUT
-           since it's not compared to guest memory.  */
-        pts = (struct timespec *)(uintptr_t) timeout;
-        return do_safe_futex(g2h(cpu, uaddr), op, val, pts, g2h(cpu, uaddr2),
-                             (base_op == FUTEX_CMP_REQUEUE
-                              ? tswap32(val3) : val3));
+        /*
+         * For these, the 4th argument is not TIMEOUT, but VAL2.
+         * But the prototype of do_safe_futex takes a pointer, so
+         * insert casts to satisfy the compiler.  We do not need
+         * to tswap VAL2 since it's not compared to guest memory.
+          */
+        pts = (struct timespec *)(uintptr_t)timeout;
+        timeout = 0;
+        haddr2 = g2h(cpu, uaddr2);
+        break;
     default:
         return -TARGET_ENOSYS;
     }
+    if (timeout) {
+        pts = &ts;
+        if (time64
+            ? target_to_host_timespec64(pts, timeout)
+            : target_to_host_timespec(pts, timeout)) {
+            return -TARGET_EFAULT;
+        }
+    }
+    return do_safe_futex(g2h(cpu, uaddr), op, val, pts, haddr2, val3);
 }
 #endif
 
-- 
2.37.3



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

* [PULL 32/37] linux-user: Implement FUTEX_WAKE_BITSET
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (30 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 31/37] linux-user: Sink call to do_safe_futex Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 33/37] linux-user: Convert signal number for FUTEX_FD Laurent Vivier
                   ` (5 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, Laurent Vivier

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

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220829021006.67305-4-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 17e17f480456..e2b6b564e6cb 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7789,6 +7789,7 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
         val = tswap32(val);
         break;
     case FUTEX_WAKE:
+    case FUTEX_WAKE_BITSET:
         timeout = 0;
         break;
     case FUTEX_FD:
-- 
2.37.3



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

* [PULL 33/37] linux-user: Convert signal number for FUTEX_FD
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (31 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 32/37] linux-user: Implement FUTEX_WAKE_BITSET Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 34/37] linux-user: Implement PI futexes Laurent Vivier
                   ` (4 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, Laurent Vivier

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

The val argument to FUTEX_FD is a signal number.  Convert to match
the host, as it will be converted back when the signal is delivered.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220829021006.67305-5-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e2b6b564e6cb..3f144e3c1f5d 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7793,6 +7793,7 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
         timeout = 0;
         break;
     case FUTEX_FD:
+        val = target_to_host_signal(val);
         timeout = 0;
         break;
     case FUTEX_CMP_REQUEUE:
-- 
2.37.3



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

* [PULL 34/37] linux-user: Implement PI futexes
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (32 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 33/37] linux-user: Convert signal number for FUTEX_FD Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 35/37] linux-user: Update print_futex_op Laurent Vivier
                   ` (3 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, Laurent Vivier

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

Define the missing FUTEX_* constants in syscall_defs.h

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220829021006.67305-6-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c      | 10 ++++++++++
 linux-user/syscall_defs.h |  3 +++
 2 files changed, 13 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3f144e3c1f5d..2e954d8dbd9e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7788,8 +7788,17 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
     case FUTEX_WAIT_BITSET:
         val = tswap32(val);
         break;
+    case FUTEX_WAIT_REQUEUE_PI:
+        val = tswap32(val);
+        haddr2 = g2h(cpu, uaddr2);
+        break;
+    case FUTEX_LOCK_PI:
+    case FUTEX_LOCK_PI2:
+        break;
     case FUTEX_WAKE:
     case FUTEX_WAKE_BITSET:
+    case FUTEX_TRYLOCK_PI:
+    case FUTEX_UNLOCK_PI:
         timeout = 0;
         break;
     case FUTEX_FD:
@@ -7797,6 +7806,7 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
         timeout = 0;
         break;
     case FUTEX_CMP_REQUEUE:
+    case FUTEX_CMP_REQUEUE_PI:
         val3 = tswap32(val3);
         /* fall through */
     case FUTEX_REQUEUE:
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 1e3577bfa56f..01ee10a88fe0 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2699,6 +2699,9 @@ struct target_drm_i915_getparam {
 #define FUTEX_TRYLOCK_PI        8
 #define FUTEX_WAIT_BITSET       9
 #define FUTEX_WAKE_BITSET       10
+#define FUTEX_WAIT_REQUEUE_PI   11
+#define FUTEX_CMP_REQUEUE_PI    12
+#define FUTEX_LOCK_PI2          13
 
 #define FUTEX_PRIVATE_FLAG      128
 #define FUTEX_CLOCK_REALTIME    256
-- 
2.37.3



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

* [PULL 35/37] linux-user: Update print_futex_op
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (33 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 34/37] linux-user: Implement PI futexes Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 36/37] linux-user: Lock log around strace Laurent Vivier
                   ` (2 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, Laurent Vivier

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

Use a table for the names; print unknown values in hex,
since the value contains flags.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220829021006.67305-7-richard.henderson@linaro.org>
[lv: update print_futex() according to
"linux-user: Show timespec on strace for futex()"]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.c | 70 +++++++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 37 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 2deb84a2c106..faa733125624 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -3710,44 +3710,37 @@ print_munmap(CPUArchState *cpu_env, const struct syscallname *name,
 #endif
 
 #ifdef TARGET_NR_futex
-static void print_futex_op(abi_long tflag, int last)
-{
-#define print_op(val) \
-if( cmd == val ) { \
-    qemu_log(#val); \
-    return; \
-}
-
-    int cmd = (int)tflag;
-#ifdef FUTEX_PRIVATE_FLAG
-    if (cmd & FUTEX_PRIVATE_FLAG) {
-        qemu_log("FUTEX_PRIVATE_FLAG|");
-        cmd &= ~FUTEX_PRIVATE_FLAG;
-    }
-#endif
-#ifdef FUTEX_CLOCK_REALTIME
-    if (cmd & FUTEX_CLOCK_REALTIME) {
-        qemu_log("FUTEX_CLOCK_REALTIME|");
-        cmd &= ~FUTEX_CLOCK_REALTIME;
+static void print_futex_op(int cmd, int last)
+{
+    static const char * const futex_names[] = {
+#define NAME(X)  [X] = #X
+        NAME(FUTEX_WAIT),
+        NAME(FUTEX_WAKE),
+        NAME(FUTEX_FD),
+        NAME(FUTEX_REQUEUE),
+        NAME(FUTEX_CMP_REQUEUE),
+        NAME(FUTEX_WAKE_OP),
+        NAME(FUTEX_LOCK_PI),
+        NAME(FUTEX_UNLOCK_PI),
+        NAME(FUTEX_TRYLOCK_PI),
+        NAME(FUTEX_WAIT_BITSET),
+        NAME(FUTEX_WAKE_BITSET),
+        NAME(FUTEX_WAIT_REQUEUE_PI),
+        NAME(FUTEX_CMP_REQUEUE_PI),
+        NAME(FUTEX_LOCK_PI2),
+#undef NAME
+    };
+
+    unsigned base_cmd = cmd & FUTEX_CMD_MASK;
+
+    if (base_cmd < ARRAY_SIZE(futex_names)) {
+        qemu_log("%s%s%s",
+                 (cmd & FUTEX_PRIVATE_FLAG ? "FUTEX_PRIVATE_FLAG|" : ""),
+                 (cmd & FUTEX_CLOCK_REALTIME ? "FUTEX_CLOCK_REALTIME|" : ""),
+                 futex_names[base_cmd]);
+    } else {
+        qemu_log("0x%x", cmd);
     }
-#endif
-    print_op(FUTEX_WAIT)
-    print_op(FUTEX_WAKE)
-    print_op(FUTEX_FD)
-    print_op(FUTEX_REQUEUE)
-    print_op(FUTEX_CMP_REQUEUE)
-    print_op(FUTEX_WAKE_OP)
-    print_op(FUTEX_LOCK_PI)
-    print_op(FUTEX_UNLOCK_PI)
-    print_op(FUTEX_TRYLOCK_PI)
-#ifdef FUTEX_WAIT_BITSET
-    print_op(FUTEX_WAIT_BITSET)
-#endif
-#ifdef FUTEX_WAKE_BITSET
-    print_op(FUTEX_WAKE_BITSET)
-#endif
-    /* unknown values */
-    qemu_log("%d", cmd);
 }
 
 static void
@@ -3763,6 +3756,9 @@ print_futex(CPUArchState *cpu_env, const struct syscallname *name,
     switch (op) {
         case FUTEX_WAIT:
         case FUTEX_WAIT_BITSET:
+        case FUTEX_LOCK_PI:
+        case FUTEX_LOCK_PI2:
+        case FUTEX_WAIT_REQUEUE_PI:
             print_timespec(arg3, 0);
             break;
         default:
-- 
2.37.3



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

* [PULL 36/37] linux-user: Lock log around strace
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (34 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 35/37] linux-user: Update print_futex_op Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-28 20:27 ` [PULL 37/37] linux-user: Add parameters of getrandom() syscall for strace Laurent Vivier
  2022-09-29 14:48 ` [PULL 00/37] Linux user for 7.2 patches Stefan Hajnoczi
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, Laurent Vivier

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

Do not allow syscall arguments to be interleaved between threads.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220829021006.67305-8-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.c | 65 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 46 insertions(+), 19 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index faa733125624..37bc96df9bb6 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -3919,26 +3919,37 @@ print_syscall(CPUArchState *cpu_env, int num,
               abi_long arg4, abi_long arg5, abi_long arg6)
 {
     int i;
-    const char *format="%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")";
+    FILE *f;
+    const char *format = "%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
+                               TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
+                               TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")";
 
-    qemu_log("%d ", getpid());
+    f = qemu_log_trylock();
+    if (!f) {
+        return;
+    }
+    fprintf(f, "%d ", getpid());
 
-    for(i=0;i<nsyscalls;i++)
-        if( scnames[i].nr == num ) {
-            if( scnames[i].call != NULL ) {
-                scnames[i].call(
-                    cpu_env, &scnames[i], arg1, arg2, arg3, arg4, arg5, arg6);
+    for (i = 0; i < nsyscalls; i++) {
+        if (scnames[i].nr == num) {
+            if (scnames[i].call != NULL) {
+                scnames[i].call(cpu_env, &scnames[i], arg1, arg2, arg3,
+                                arg4, arg5, arg6);
             } else {
                 /* XXX: this format system is broken because it uses
                    host types and host pointers for strings */
-                if( scnames[i].format != NULL )
+                if (scnames[i].format != NULL) {
                     format = scnames[i].format;
-                qemu_log(format,
-                         scnames[i].name, arg1, arg2, arg3, arg4, arg5, arg6);
+                }
+                fprintf(f, format, scnames[i].name, arg1, arg2,
+                        arg3, arg4, arg5, arg6);
             }
+            qemu_log_unlock(f);
             return;
         }
-    qemu_log("Unknown syscall %d\n", num);
+    }
+    fprintf(f, "Unknown syscall %d\n", num);
+    qemu_log_unlock(f);
 }
 
 
@@ -3948,21 +3959,29 @@ print_syscall_ret(CPUArchState *cpu_env, int num, abi_long ret,
                   abi_long arg4, abi_long arg5, abi_long arg6)
 {
     int i;
+    FILE *f;
+
+    f = qemu_log_trylock();
+    if (!f) {
+        return;
+    }
 
-    for(i=0;i<nsyscalls;i++)
-        if( scnames[i].nr == num ) {
-            if( scnames[i].result != NULL ) {
+    for (i = 0; i < nsyscalls; i++) {
+        if (scnames[i].nr == num) {
+            if (scnames[i].result != NULL) {
                 scnames[i].result(cpu_env, &scnames[i], ret,
                                   arg1, arg2, arg3,
                                   arg4, arg5, arg6);
             } else {
                 if (!print_syscall_err(ret)) {
-                    qemu_log(TARGET_ABI_FMT_ld, ret);
+                    fprintf(f, TARGET_ABI_FMT_ld, ret);
                 }
-                qemu_log("\n");
+                fprintf(f, "\n");
             }
             break;
         }
+    }
+    qemu_log_unlock(f);
 }
 
 void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
@@ -3970,9 +3989,17 @@ void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
     /* Print the strace output for a signal being taken:
      * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
      */
-    qemu_log("--- ");
+    FILE *f;
+
+    f = qemu_log_trylock();
+    if (!f) {
+        return;
+    }
+
+    fprintf(f, "--- ");
     print_signal(target_signum, 1);
-    qemu_log(" ");
+    fprintf(f, " ");
     print_siginfo(tinfo);
-    qemu_log(" ---\n");
+    fprintf(f, " ---\n");
+    qemu_log_unlock(f);
 }
-- 
2.37.3



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

* [PULL 37/37] linux-user: Add parameters of getrandom() syscall for strace
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (35 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 36/37] linux-user: Lock log around strace Laurent Vivier
@ 2022-09-28 20:27 ` Laurent Vivier
  2022-09-29 14:48 ` [PULL 00/37] Linux user for 7.2 patches Stefan Hajnoczi
  37 siblings, 0 replies; 39+ messages in thread
From: Laurent Vivier @ 2022-09-28 20:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Laurent Vivier

From: Helge Deller <deller@gmx.de>

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220927093538.8954-2-deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.list | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/strace.list b/linux-user/strace.list
index f8a771b4f256..a87415bf3d50 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -352,7 +352,7 @@
 { TARGET_NR_getpriority, "getpriority", "%s(%#x,%#x)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getrandom
-{ TARGET_NR_getrandom, "getrandom", NULL, NULL, NULL },
+{ TARGET_NR_getrandom, "getrandom", "%s(%p,%u,%u)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getresgid
 { TARGET_NR_getresgid, "getresgid" , NULL, NULL, NULL },
-- 
2.37.3



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

* Re: [PULL 00/37] Linux user for 7.2 patches
  2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
                   ` (36 preceding siblings ...)
  2022-09-28 20:27 ` [PULL 37/37] linux-user: Add parameters of getrandom() syscall for strace Laurent Vivier
@ 2022-09-29 14:48 ` Stefan Hajnoczi
  37 siblings, 0 replies; 39+ messages in thread
From: Stefan Hajnoczi @ 2022-09-29 14:48 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: qemu-devel, Laurent Vivier

[-- Attachment #1: Type: text/plain, Size: 115 bytes --]

Applied, thanks.

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2022-09-29 16:37 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28 20:27 [PULL 00/37] Linux user for 7.2 patches Laurent Vivier
2022-09-28 20:27 ` [PULL 01/37] linux-user: use 'max' instead of 'qemu32' / 'qemu64' by default Laurent Vivier
2022-09-28 20:27 ` [PULL 02/37] linux-user: fix readlinkat handling with magic exe symlink Laurent Vivier
2022-09-28 20:27 ` [PULL 03/37] linux-user: Add missing signals in strace output Laurent Vivier
2022-09-28 20:27 ` [PULL 04/37] linux-user: Add missing clock_gettime64() syscall strace Laurent Vivier
2022-09-28 20:27 ` [PULL 05/37] linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls Laurent Vivier
2022-09-28 20:27 ` [PULL 06/37] linux-user: Log failing executable in EXCP_DUMP() Laurent Vivier
2022-09-28 20:27 ` [PULL 07/37] linux-user/hppa: Use EXCP_DUMP() to show enhanced debug info Laurent Vivier
2022-09-28 20:27 ` [PULL 08/37] linux-user/hppa: Dump IIR on register dump Laurent Vivier
2022-09-28 20:27 ` [PULL 09/37] linux-user: Fix strace of chmod() if mode == 0 Laurent Vivier
2022-09-28 20:27 ` [PULL 10/37] linux-user/hppa: Set TASK_UNMAPPED_BASE to 0xfa000000 for hppa arch Laurent Vivier
2022-09-28 20:27 ` [PULL 11/37] linux-user: Add strace for clock_nanosleep() Laurent Vivier
2022-09-28 20:27 ` [PULL 12/37] linux-user: Show timespec on strace for futex() Laurent Vivier
2022-09-28 20:27 ` [PULL 13/37] linux-user: Provide MADV_* definitions Laurent Vivier
2022-09-28 20:27 ` [PULL 14/37] linux-user: Fix madvise(MADV_DONTNEED) on alpha Laurent Vivier
2022-09-28 20:27 ` [PULL 15/37] linux-user: Implement stracing madvise() Laurent Vivier
2022-09-28 20:27 ` [PULL 16/37] linux-user: Passthrough MADV_DONTNEED for certain file mappings Laurent Vivier
2022-09-28 20:27 ` [PULL 17/37] tests/tcg/linux-test: Add linux-madvise test Laurent Vivier
2022-09-28 20:27 ` [PULL 18/37] linux-user: Fix TARGET_PROT_SEM for XTENSA Laurent Vivier
2022-09-28 20:27 ` [PULL 19/37] linux-user: Add proper strace format strings for getdents()/getdents64() Laurent Vivier
2022-09-28 20:27 ` [PULL 20/37] linux-user/hppa: Add signal trampoline for hppa target Laurent Vivier
2022-09-28 20:27 ` [PULL 21/37] linux-user/hppa: Drop stack guard page on " Laurent Vivier
2022-09-28 20:27 ` [PULL 22/37] linux-user/hppa: Increase guest stack size to 80MB for " Laurent Vivier
2022-09-28 20:27 ` [PULL 23/37] linux-user/hppa: Allow PROT_GROWSUP and PROT_GROWSDOWN in mprotect() Laurent Vivier
2022-09-28 20:27 ` [PULL 24/37] linux-user/hppa: Fix setup_sigcontext() Laurent Vivier
2022-09-28 20:27 ` [PULL 25/37] linux-user: fix bug about missing signum convert of sigqueue Laurent Vivier
2022-09-28 20:27 ` [PULL 26/37] linux-user: Don't assume 0 is not a valid host timer_t value Laurent Vivier
2022-09-28 20:27 ` [PULL 27/37] linux-user/s390x: Save/restore fpc when handling a signal Laurent Vivier
2022-09-28 20:27 ` [PULL 28/37] linux-user: Introduce stubs for ELF AT_BASE_PLATFORM Laurent Vivier
2022-09-28 20:27 ` [PULL 29/37] linux-user: Set ELF_BASE_PLATFORM for MIPS Laurent Vivier
2022-09-28 20:27 ` [PULL 30/37] linux-user: Combine do_futex and do_futex_time64 Laurent Vivier
2022-09-28 20:27 ` [PULL 31/37] linux-user: Sink call to do_safe_futex Laurent Vivier
2022-09-28 20:27 ` [PULL 32/37] linux-user: Implement FUTEX_WAKE_BITSET Laurent Vivier
2022-09-28 20:27 ` [PULL 33/37] linux-user: Convert signal number for FUTEX_FD Laurent Vivier
2022-09-28 20:27 ` [PULL 34/37] linux-user: Implement PI futexes Laurent Vivier
2022-09-28 20:27 ` [PULL 35/37] linux-user: Update print_futex_op Laurent Vivier
2022-09-28 20:27 ` [PULL 36/37] linux-user: Lock log around strace Laurent Vivier
2022-09-28 20:27 ` [PULL 37/37] linux-user: Add parameters of getrandom() syscall for strace Laurent Vivier
2022-09-29 14:48 ` [PULL 00/37] Linux user for 7.2 patches Stefan Hajnoczi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.