qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/8] Linux user for 7.2 patches
@ 2022-10-25  7:35 Laurent Vivier
  2022-10-25  7:35 ` [PULL 1/8] linux-user: Fix more MIPS n32 syscall ABI issues Laurent Vivier
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Laurent Vivier @ 2022-10-25  7:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier

The following changes since commit 0529245488865038344d64fff7ee05864d3d17f6:

  Merge tag 'pull-target-arm-20221020' of https://git.linaro.org/people/pmaydell/qemu-arm into staging (2022-10-20 14:36:12 -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 bd5ccd61080abf976a6a6cc2d09d31299bea0cee:

  linux-user: Add guest memory layout to exception dump (2022-10-25 09:20:40 +0200)

----------------------------------------------------------------
linux-user pull request 20221025

Add faccess2()
Fix ioclt(), execve(), pidfd_send_signal() and MIPS n32 syscall ABI
Improve EXCP_DUMP()

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

Daniel P. Berrangé (2):
  linux-user: add more compat ioctl definitions
  linux-user: remove conditionals for many fs.h ioctls

Helge Deller (1):
  linux-user: Add guest memory layout to exception dump

Laurent Vivier (3):
  linux-user: fix pidfd_send_signal()
  linux-user: handle /proc/self/exe with execve() syscall
  linux-user: don't use AT_EXECFD in do_openat()

WANG Xuerui (2):
  linux-user: Fix more MIPS n32 syscall ABI issues
  linux-user: Implement faccessat2

 linux-user/cpu_loop-common.h |  15 ++----
 linux-user/i386/cpu_loop.c   |   6 +--
 linux-user/ioctls.h          |  24 ---------
 linux-user/strace.c          |   6 +--
 linux-user/strace.list       |   3 ++
 linux-user/syscall.c         | 100 +++++++++++++++++++++++++++++------
 6 files changed, 96 insertions(+), 58 deletions(-)

-- 
2.37.3



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

* [PULL 1/8] linux-user: Fix more MIPS n32 syscall ABI issues
  2022-10-25  7:35 [PULL 0/8] Linux user for 7.2 patches Laurent Vivier
@ 2022-10-25  7:35 ` Laurent Vivier
  2022-10-25  7:36 ` [PULL 2/8] linux-user: fix pidfd_send_signal() Laurent Vivier
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2022-10-25  7:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: WANG Xuerui, Philippe Mathieu-Daudé, Jiaxun Yang,
	Andreas K . Hüttel, Joshua Kinard, Laurent Vivier

From: WANG Xuerui <xen0n@gentoo.org>

In commit 80f0fe3a85 ("linux-user: Fix syscall parameter handling for
MIPS n32") the ABI problem regarding offset64 on MIPS n32 was fixed,
but still some cases remain where the n32 is incorrectly treated as any
other 32-bit ABI that passes 64-bit arguments in pairs of GPRs. Fix by
excluding TARGET_ABI_MIPSN32 from various TARGET_ABI_BITS == 32 checks.

Closes: https://gitlab.com/qemu-project/qemu/-/issues/1238
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Andreas K. Hüttel <dilfridge@gentoo.org>
Cc: Joshua Kinard <kumba@gentoo.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Andreas K. Huettel <dilfridge@gentoo.org>
Message-Id: <20221006085500.290341-1-xen0n@gentoo.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2e954d8dbd9e..8b2d39fe73b3 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11793,7 +11793,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         return -host_to_target_errno(ret);
 #endif
 
-#if TARGET_ABI_BITS == 32
+#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
 
 #ifdef TARGET_NR_fadvise64_64
     case TARGET_NR_fadvise64_64:
@@ -11920,7 +11920,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         return get_errno(sys_gettid());
 #ifdef TARGET_NR_readahead
     case TARGET_NR_readahead:
-#if TARGET_ABI_BITS == 32
+#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
         if (regpairs_aligned(cpu_env, num)) {
             arg2 = arg3;
             arg3 = arg4;
@@ -12612,7 +12612,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
 #endif /* CONFIG_EVENTFD  */
 #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
     case TARGET_NR_fallocate:
-#if TARGET_ABI_BITS == 32
+#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
         ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4),
                                   target_offset64(arg5, arg6)));
 #else
@@ -12623,7 +12623,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
 #if defined(CONFIG_SYNC_FILE_RANGE)
 #if defined(TARGET_NR_sync_file_range)
     case TARGET_NR_sync_file_range:
-#if TARGET_ABI_BITS == 32
+#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
 #if defined(TARGET_MIPS)
         ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
                                         target_offset64(arg5, arg6), arg7));
@@ -12645,7 +12645,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
     case TARGET_NR_arm_sync_file_range:
 #endif
         /* This is like sync_file_range but the arguments are reordered */
-#if TARGET_ABI_BITS == 32
+#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32)
         ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4),
                                         target_offset64(arg5, arg6), arg2));
 #else
-- 
2.37.3



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

* [PULL 2/8] linux-user: fix pidfd_send_signal()
  2022-10-25  7:35 [PULL 0/8] Linux user for 7.2 patches Laurent Vivier
  2022-10-25  7:35 ` [PULL 1/8] linux-user: Fix more MIPS n32 syscall ABI issues Laurent Vivier
@ 2022-10-25  7:36 ` Laurent Vivier
  2022-10-25  7:36 ` [PULL 3/8] linux-user: handle /proc/self/exe with execve() syscall Laurent Vivier
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2022-10-25  7:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Helge Deller

According to pidfd_send_signal(2), info argument can be a NULL pointer.
Fix strace to correctly manage ending comma in parameters.

Fixes: cc054c6f13 ("linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls")
cc: Helge Deller <deller@gmx.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Helge Deller <deller@gmx.de>
Message-Id: <20221005163826.1455313-1-laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.c  |  4 ++--
 linux-user/syscall.c | 19 ++++++++++++-------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 37bc96df9bb6..86c081c83f74 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -3383,10 +3383,10 @@ print_pidfd_send_signal(CPUArchState *cpu_env, const struct syscallname *name,
 
         unlock_user(p, arg2, 0);
     } else {
-        print_pointer(arg2, 1);
+        print_pointer(arg2, 0);
     }
 
-    print_raw_param("%u", arg3, 0);
+    print_raw_param("%u", arg3, 1);
     print_syscall_epilogue(name);
 }
 #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8b2d39fe73b3..ad06ec7bd54c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8679,16 +8679,21 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
 #if defined(__NR_pidfd_send_signal) && defined(TARGET_NR_pidfd_send_signal)
     case TARGET_NR_pidfd_send_signal:
         {
-            siginfo_t uinfo;
+            siginfo_t uinfo, *puinfo;
 
-            p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
-            if (!p) {
-                return -TARGET_EFAULT;
+            if (arg3) {
+                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);
+                 puinfo = &uinfo;
+            } else {
+                 puinfo = NULL;
             }
-            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));
+                                              puinfo, arg4));
         }
         return ret;
 #endif
-- 
2.37.3



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

* [PULL 3/8] linux-user: handle /proc/self/exe with execve() syscall
  2022-10-25  7:35 [PULL 0/8] Linux user for 7.2 patches Laurent Vivier
  2022-10-25  7:35 ` [PULL 1/8] linux-user: Fix more MIPS n32 syscall ABI issues Laurent Vivier
  2022-10-25  7:36 ` [PULL 2/8] linux-user: fix pidfd_send_signal() Laurent Vivier
@ 2022-10-25  7:36 ` Laurent Vivier
  2022-10-25  7:36 ` [PULL 4/8] linux-user: don't use AT_EXECFD in do_openat() Laurent Vivier
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2022-10-25  7:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier

If path is /proc/self/exe, use the executable path
provided by exec_path.

Don't use execfd as it is closed by loader_exec() and otherwise
will survive to the exec() syscall and be usable child process.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220927124357.688536-2-laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ad06ec7bd54c..a7a29091c91e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8860,7 +8860,11 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
              * before the execve completes and makes it the other
              * program's problem.
              */
-            ret = get_errno(safe_execve(p, argp, envp));
+            if (is_proc_myself(p, "exe")) {
+                ret = get_errno(safe_execve(exec_path, argp, envp));
+            } else {
+                ret = get_errno(safe_execve(p, argp, envp));
+            }
             unlock_user(p, arg1, 0);
 
             goto execve_end;
-- 
2.37.3



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

* [PULL 4/8] linux-user: don't use AT_EXECFD in do_openat()
  2022-10-25  7:35 [PULL 0/8] Linux user for 7.2 patches Laurent Vivier
                   ` (2 preceding siblings ...)
  2022-10-25  7:36 ` [PULL 3/8] linux-user: handle /proc/self/exe with execve() syscall Laurent Vivier
@ 2022-10-25  7:36 ` Laurent Vivier
  2022-10-25  7:36 ` [PULL 5/8] linux-user: add more compat ioctl definitions Laurent Vivier
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2022-10-25  7:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier

AT_EXECFD gives access to the binary file even if
it is not readable (only executable).

Moreover it can be opened with flags and mode that are not the ones
provided by do_openat() caller.

And it is not available because loader_exec() has closed it.

To avoid that, use only safe_openat() with the exec_path.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220927124357.688536-3-laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a7a29091c91e..665db67c0598 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8251,8 +8251,7 @@ static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int
     };
 
     if (is_proc_myself(pathname, "exe")) {
-        int execfd = qemu_getauxval(AT_EXECFD);
-        return execfd ? execfd : safe_openat(dirfd, exec_path, flags, mode);
+        return safe_openat(dirfd, exec_path, flags, mode);
     }
 
     for (fake_open = fakes; fake_open->filename; fake_open++) {
-- 
2.37.3



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

* [PULL 5/8] linux-user: add more compat ioctl definitions
  2022-10-25  7:35 [PULL 0/8] Linux user for 7.2 patches Laurent Vivier
                   ` (3 preceding siblings ...)
  2022-10-25  7:36 ` [PULL 4/8] linux-user: don't use AT_EXECFD in do_openat() Laurent Vivier
@ 2022-10-25  7:36 ` Laurent Vivier
  2022-10-25  7:36 ` [PULL 6/8] linux-user: remove conditionals for many fs.h ioctls Laurent Vivier
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2022-10-25  7:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel P. Berrangé, Laurent Vivier

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

GLibc changes prevent us from including linux/fs.h anymore,
and we previously adjusted to this in

  commit 3cd3df2a9584e6f753bb62a0028bd67124ab5532
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Tue Aug 2 12:41:34 2022 -0400

    linux-user: fix compat with glibc >= 2.36 sys/mount.h

That change required adding compat ioctl definitions on the
QEMU side for any ioctls that we would otherwise obtain
from linux/fs.h.  This commit adds more that were initially
missed, due to their usage being conditionalized in QEMU.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20221004093206.652431-2-berrange@redhat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 665db67c0598..d499cac1d5d1 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -111,6 +111,31 @@
 #define FS_IOC32_SETFLAGS              _IOW('f', 2, int)
 #define FS_IOC32_GETVERSION            _IOR('v', 1, int)
 #define FS_IOC32_SETVERSION            _IOW('v', 2, int)
+
+#define BLKGETSIZE64 _IOR(0x12,114,size_t)
+#define BLKDISCARD _IO(0x12,119)
+#define BLKIOMIN _IO(0x12,120)
+#define BLKIOOPT _IO(0x12,121)
+#define BLKALIGNOFF _IO(0x12,122)
+#define BLKPBSZGET _IO(0x12,123)
+#define BLKDISCARDZEROES _IO(0x12,124)
+#define BLKSECDISCARD _IO(0x12,125)
+#define BLKROTATIONAL _IO(0x12,126)
+#define BLKZEROOUT _IO(0x12,127)
+
+#define FIBMAP     _IO(0x00,1)
+#define FIGETBSZ   _IO(0x00,2)
+
+struct file_clone_range {
+        __s64 src_fd;
+        __u64 src_offset;
+        __u64 src_length;
+        __u64 dest_offset;
+};
+
+#define FICLONE         _IOW(0x94, 9, int)
+#define FICLONERANGE    _IOW(0x94, 13, struct file_clone_range)
+
 #else
 #include <linux/fs.h>
 #endif
-- 
2.37.3



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

* [PULL 6/8] linux-user: remove conditionals for many fs.h ioctls
  2022-10-25  7:35 [PULL 0/8] Linux user for 7.2 patches Laurent Vivier
                   ` (4 preceding siblings ...)
  2022-10-25  7:36 ` [PULL 5/8] linux-user: add more compat ioctl definitions Laurent Vivier
@ 2022-10-25  7:36 ` Laurent Vivier
  2022-10-25  7:36 ` [PULL 7/8] linux-user: Implement faccessat2 Laurent Vivier
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2022-10-25  7:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel P. Berrangé, Laurent Vivier

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

These ioctls have been defined in linux/fs.h for a long time

  * BLKGETSIZE64 - <2.6.12 (linux.git epoch)
  * BLKDISCARD - 2.6.28 (d30a2605be9d5132d95944916e8f578fcfe4f976)
  * BLKIOMIN - 2.6.32 (ac481c20ef8f6c6f2be75d581863f40c43874ef7)
  * BLKIOOPT - 2.6.32 (ac481c20ef8f6c6f2be75d581863f40c43874ef7)
  * BLKALIGNOFF - 2.6.32 (ac481c20ef8f6c6f2be75d581863f40c43874ef7)
  * BLKPBSZGET - 2.6.32 (ac481c20ef8f6c6f2be75d581863f40c43874ef7)
  * BLKDISCARDZEROES - 2.6.32 (98262f2762f0067375f83824d81ea929e37e6bfe)
  * BLKSECDISCARD - 2.6.36 (8d57a98ccd0b4489003473979da8f5a1363ba7a3)
  * BLKROTATIONAL - 3.2 (ef00f59c95fe6e002e7c6e3663cdea65e253f4cc)
  * BLKZEROOUT - 3.6 (66ba32dc167202c3cf8c86806581a9393ec7f488)
  * FIBMAP - <2.6.12 (linux.git epoch)
  * FIGETBSZ - <2.6.12 (linux.git epoch)

and when building with latest glibc, we'll see compat definitions
in syscall.c anyway thanks to the previous patch. Thus we can
assume they always exist and remove the conditional checks.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20221004093206.652431-3-berrange@redhat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/ioctls.h | 24 ------------------------
 1 file changed, 24 deletions(-)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index f182d40190ed..071f7ca25375 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -96,9 +96,7 @@
      IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
      IOCTL(BLKRRPART, 0, TYPE_NULL)
      IOCTL(BLKGETSIZE, IOC_R, MK_PTR(TYPE_ULONG))
-#ifdef BLKGETSIZE64
      IOCTL(BLKGETSIZE64, IOC_R, MK_PTR(TYPE_ULONGLONG))
-#endif
      IOCTL(BLKFLSBUF, 0, TYPE_NULL)
      IOCTL(BLKRASET, 0, TYPE_INT)
      IOCTL(BLKRAGET, IOC_R, MK_PTR(TYPE_LONG))
@@ -107,33 +105,15 @@
      IOCTL_SPECIAL(BLKPG, IOC_W, do_ioctl_blkpg,
                    MK_PTR(MK_STRUCT(STRUCT_blkpg_ioctl_arg)))
 
-#ifdef BLKDISCARD
      IOCTL(BLKDISCARD, IOC_W, MK_PTR(MK_ARRAY(TYPE_ULONGLONG, 2)))
-#endif
-#ifdef BLKIOMIN
      IOCTL(BLKIOMIN, IOC_R, MK_PTR(TYPE_INT))
-#endif
-#ifdef BLKIOOPT
      IOCTL(BLKIOOPT, IOC_R, MK_PTR(TYPE_INT))
-#endif
-#ifdef BLKALIGNOFF
      IOCTL(BLKALIGNOFF, IOC_R, MK_PTR(TYPE_INT))
-#endif
-#ifdef BLKPBSZGET
      IOCTL(BLKPBSZGET, IOC_R, MK_PTR(TYPE_INT))
-#endif
-#ifdef BLKDISCARDZEROES
      IOCTL(BLKDISCARDZEROES, IOC_R, MK_PTR(TYPE_INT))
-#endif
-#ifdef BLKSECDISCARD
      IOCTL(BLKSECDISCARD, IOC_W, MK_PTR(MK_ARRAY(TYPE_ULONGLONG, 2)))
-#endif
-#ifdef BLKROTATIONAL
      IOCTL(BLKROTATIONAL, IOC_R, MK_PTR(TYPE_SHORT))
-#endif
-#ifdef BLKZEROOUT
      IOCTL(BLKZEROOUT, IOC_W, MK_PTR(MK_ARRAY(TYPE_ULONGLONG, 2)))
-#endif
 
      IOCTL(FDMSGON, 0, TYPE_NULL)
      IOCTL(FDMSGOFF, 0, TYPE_NULL)
@@ -149,17 +129,13 @@
      IOCTL(FDTWADDLE, 0, TYPE_NULL)
      IOCTL(FDEJECT, 0, TYPE_NULL)
 
-#ifdef FIBMAP
      IOCTL(FIBMAP, IOC_W | IOC_R, MK_PTR(TYPE_LONG))
-#endif
 #ifdef FICLONE
      IOCTL(FICLONE, IOC_W, TYPE_INT)
      IOCTL(FICLONERANGE, IOC_W, MK_PTR(MK_STRUCT(STRUCT_file_clone_range)))
 #endif
 
-#ifdef FIGETBSZ
      IOCTL(FIGETBSZ, IOC_R, MK_PTR(TYPE_LONG))
-#endif
 #ifdef CONFIG_FIEMAP
      IOCTL_SPECIAL(FS_IOC_FIEMAP, IOC_W | IOC_R, do_ioctl_fs_ioc_fiemap,
                    MK_PTR(MK_STRUCT(STRUCT_fiemap)))
-- 
2.37.3



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

* [PULL 7/8] linux-user: Implement faccessat2
  2022-10-25  7:35 [PULL 0/8] Linux user for 7.2 patches Laurent Vivier
                   ` (5 preceding siblings ...)
  2022-10-25  7:36 ` [PULL 6/8] linux-user: remove conditionals for many fs.h ioctls Laurent Vivier
@ 2022-10-25  7:36 ` Laurent Vivier
  2022-10-25  7:36 ` [PULL 8/8] linux-user: Add guest memory layout to exception dump Laurent Vivier
  2022-10-26 14:01 ` [PULL 0/8] Linux user for 7.2 patches Stefan Hajnoczi
  8 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2022-10-25  7:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: WANG Xuerui, Andreas K . Hüttel, Laurent Vivier

From: WANG Xuerui <xen0n@gentoo.org>

User space has been preferring this syscall for a while, due to its
closer match with C semantics, and newer platforms such as LoongArch
apparently have libc implementations that don't fallback to faccessat
so normal access checks are failing without the emulation in place.

Tested by successfully emerging several packages within a Gentoo loong
stage3 chroot, emulated on amd64 with help of static qemu-loongarch64.

Reported-by: Andreas K. Hüttel <dilfridge@gentoo.org>
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
Message-Id: <20221009060813.2289077-1-xen0n@gentoo.org>
[lv: removing defined(__NR_faccessat2) in syscall.c,
     adding defined(TARGET_NR_faccessat2) on print_faccessat()]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/strace.c    | 2 +-
 linux-user/strace.list | 3 +++
 linux-user/syscall.c   | 9 +++++++++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 86c081c83f74..9ae5a812cd71 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1969,7 +1969,7 @@ print_execv(CPUArchState *cpu_env, const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_faccessat
+#if defined(TARGET_NR_faccessat) || defined(TARGET_NR_faccessat2)
 static void
 print_faccessat(CPUArchState *cpu_env, const struct syscallname *name,
                 abi_long arg0, abi_long arg1, abi_long arg2,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index a87415bf3d50..3df2184580aa 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -178,6 +178,9 @@
 #ifdef TARGET_NR_faccessat
 { TARGET_NR_faccessat, "faccessat" , NULL, print_faccessat, NULL },
 #endif
+#ifdef TARGET_NR_faccessat2
+{ TARGET_NR_faccessat2, "faccessat2" , NULL, print_faccessat, NULL },
+#endif
 #ifdef TARGET_NR_fadvise64
 { TARGET_NR_fadvise64, "fadvise64" , NULL, NULL, NULL },
 #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index d499cac1d5d1..e985ad167f21 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9143,6 +9143,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         unlock_user(p, arg2, 0);
         return ret;
 #endif
+#if defined(TARGET_NR_faccessat2)
+    case TARGET_NR_faccessat2:
+        if (!(p = lock_user_string(arg2))) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(faccessat(arg1, p, arg3, arg4));
+        unlock_user(p, arg2, 0);
+        return ret;
+#endif
 #ifdef TARGET_NR_nice /* not on alpha */
     case TARGET_NR_nice:
         return get_errno(nice(arg1));
-- 
2.37.3



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

* [PULL 8/8] linux-user: Add guest memory layout to exception dump
  2022-10-25  7:35 [PULL 0/8] Linux user for 7.2 patches Laurent Vivier
                   ` (6 preceding siblings ...)
  2022-10-25  7:36 ` [PULL 7/8] linux-user: Implement faccessat2 Laurent Vivier
@ 2022-10-25  7:36 ` Laurent Vivier
  2022-10-26 14:01 ` [PULL 0/8] Linux user for 7.2 patches Stefan Hajnoczi
  8 siblings, 0 replies; 10+ messages in thread
From: Laurent Vivier @ 2022-10-25  7:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, Richard Henderson, Laurent Vivier

From: Helge Deller <deller@gmx.de>

When the emulation stops with a hard exception it's very useful for
debugging purposes to dump the current guest memory layout (for an
example see /proc/self/maps) beside the CPU registers.

The open_self_maps() function provides such a memory dump, but since
it's located in the syscall.c file, various changes (add #includes, make
this function externally visible, ...) are needed to be able to call it
from the existing EXCP_DUMP() macro.

This patch takes another approach by re-defining EXCP_DUMP() to call
target_exception_dump(), which is in syscall.c, consolidates the log
print functions and allows to add the call to dump the memory layout.

Beside a reduced code footprint, this approach keeps the changes across
the various callers minimal, and keeps EXCP_DUMP() highlighted as
important macro/function.

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <Y1bzAWbw07WBKPxw@p100>
[lv: remove pc declaration and setting]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/cpu_loop-common.h | 15 +++------------
 linux-user/i386/cpu_loop.c   |  6 ++----
 linux-user/syscall.c         | 28 ++++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/linux-user/cpu_loop-common.h b/linux-user/cpu_loop-common.h
index 36ff5b14f2a7..e644d2ef9096 100644
--- a/linux-user/cpu_loop-common.h
+++ b/linux-user/cpu_loop-common.h
@@ -23,18 +23,9 @@
 #include "exec/log.h"
 #include "special-errno.h"
 
-#define EXCP_DUMP(env, fmt, ...)                                        \
-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)
+void target_exception_dump(CPUArchState *env, const char *fmt, int code);
+#define EXCP_DUMP(env, fmt, code) \
+    target_exception_dump(env, fmt, code)
 
 void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs);
 #endif
diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
index 42837399bcae..865413c08f07 100644
--- a/linux-user/i386/cpu_loop.c
+++ b/linux-user/i386/cpu_loop.c
@@ -201,7 +201,6 @@ void cpu_loop(CPUX86State *env)
 {
     CPUState *cs = env_cpu(env);
     int trapnr;
-    abi_ulong pc;
     abi_ulong ret;
 
     for(;;) {
@@ -307,9 +306,8 @@ void cpu_loop(CPUX86State *env)
             cpu_exec_step_atomic(cs);
             break;
         default:
-            pc = env->segs[R_CS].base + env->eip;
-            EXCP_DUMP(env, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
-                      (long)pc, trapnr);
+            EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n",
+                      trapnr);
             abort();
         }
         process_pending_signals(env);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e985ad167f21..8402c1399d3c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -183,6 +183,7 @@ struct file_clone_range {
 #include "qapi/error.h"
 #include "fd-trans.h"
 #include "tcg/tcg.h"
+#include "cpu_loop-common.h"
 
 #ifndef CLONE_IO
 #define CLONE_IO                0x80000000      /* Clone io context */
@@ -8169,6 +8170,33 @@ static int is_proc_myself(const char *filename, const char *entry)
     return 0;
 }
 
+static void excp_dump_file(FILE *logfile, CPUArchState *env,
+                      const char *fmt, int code)
+{
+    if (logfile) {
+        CPUState *cs = env_cpu(env);
+
+        fprintf(logfile, fmt, code);
+        fprintf(logfile, "Failing executable: %s\n", exec_path);
+        cpu_dump_state(cs, logfile, 0);
+        open_self_maps(env, fileno(logfile));
+    }
+}
+
+void target_exception_dump(CPUArchState *env, const char *fmt, int code)
+{
+    /* dump to console */
+    excp_dump_file(stderr, env, fmt, code);
+
+    /* dump to log file */
+    if (qemu_log_separate()) {
+        FILE *logfile = qemu_log_trylock();
+
+        excp_dump_file(logfile, env, fmt, code);
+        qemu_log_unlock(logfile);
+    }
+}
+
 #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \
     defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA)
 static int is_proc(const char *filename, const char *entry)
-- 
2.37.3



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

* Re: [PULL 0/8] Linux user for 7.2 patches
  2022-10-25  7:35 [PULL 0/8] Linux user for 7.2 patches Laurent Vivier
                   ` (7 preceding siblings ...)
  2022-10-25  7:36 ` [PULL 8/8] linux-user: Add guest memory layout to exception dump Laurent Vivier
@ 2022-10-26 14:01 ` Stefan Hajnoczi
  8 siblings, 0 replies; 10+ messages in thread
From: Stefan Hajnoczi @ 2022-10-26 14:01 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] 10+ messages in thread

end of thread, other threads:[~2022-10-26 14:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-25  7:35 [PULL 0/8] Linux user for 7.2 patches Laurent Vivier
2022-10-25  7:35 ` [PULL 1/8] linux-user: Fix more MIPS n32 syscall ABI issues Laurent Vivier
2022-10-25  7:36 ` [PULL 2/8] linux-user: fix pidfd_send_signal() Laurent Vivier
2022-10-25  7:36 ` [PULL 3/8] linux-user: handle /proc/self/exe with execve() syscall Laurent Vivier
2022-10-25  7:36 ` [PULL 4/8] linux-user: don't use AT_EXECFD in do_openat() Laurent Vivier
2022-10-25  7:36 ` [PULL 5/8] linux-user: add more compat ioctl definitions Laurent Vivier
2022-10-25  7:36 ` [PULL 6/8] linux-user: remove conditionals for many fs.h ioctls Laurent Vivier
2022-10-25  7:36 ` [PULL 7/8] linux-user: Implement faccessat2 Laurent Vivier
2022-10-25  7:36 ` [PULL 8/8] linux-user: Add guest memory layout to exception dump Laurent Vivier
2022-10-26 14:01 ` [PULL 0/8] Linux user for 7.2 patches Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).