qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL v2 00/13] Linux user for 4.2 patches
@ 2019-11-06 13:04 Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 01/13] linux-user: Support for NETLINK socket options Laurent Vivier
                   ` (14 more replies)
  0 siblings, 15 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mark Cave-Ayland, Riku Voipio, Alex Bennée, Laurent Vivier,
	Artyom Tarasenko

The following changes since commit 36609b4fa36f0ac934874371874416f7533a5408:

  Merge remote-tracking branch 'remotes/palmer/tags/palmer-for-master-4.2-sf1' into staging (2019-11-02 17:59:03 +0000)

are available in the Git repository at:

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

for you to fetch changes up to 5849dfe410b3fefec7d54a536cda7ccbf809ebea:

  linux-user/alpha: Set r20 secondary return value (2019-11-06 13:45:05 +0100)

----------------------------------------------------------------
sparc/sparc64 fixes: this doesn't fix debian chroot for me
but they are a step in the good direction.
Fix Netlink support.
Trivial fix for alpha

PULL v2: fix checkpatch warnings

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

Josh Kunz (1):
  linux-user: Support for NETLINK socket options

Richard Henderson (12):
  scripts/qemu-binfmt-conf: Update for sparc64
  tests/tcg/multiarch/linux-test: Fix error check for shmat
  target/sparc: Define an enumeration for accessing env->regwptr
  linux-user/sparc: Use WREG constants in sparc/target_cpu.h
  linux-user/sparc: Begin using WREG constants in sparc/signal.c
  linux-user/sparc: Use WREG_SP constant in sparc/signal.c
  linux-user/sparc: Fix WREG usage in setup_frame
  linux-user/sparc64: Fix target_signal_frame
  linux-user: Rename cpu_clone_regs to cpu_clone_regs_child
  linux-user: Introduce cpu_clone_regs_parent
  linux-user/sparc: Fix cpu_clone_regs_*
  linux-user/alpha: Set r20 secondary return value

 linux-user/aarch64/target_cpu.h    |   7 +-
 linux-user/alpha/target_cpu.h      |  16 ++++-
 linux-user/arm/target_cpu.h        |   7 +-
 linux-user/cris/target_cpu.h       |   7 +-
 linux-user/hppa/target_cpu.h       |   7 +-
 linux-user/i386/target_cpu.h       |   7 +-
 linux-user/m68k/target_cpu.h       |   7 +-
 linux-user/microblaze/target_cpu.h |   7 +-
 linux-user/mips/target_cpu.h       |   7 +-
 linux-user/nios2/target_cpu.h      |   7 +-
 linux-user/openrisc/target_cpu.h   |   8 ++-
 linux-user/ppc/target_cpu.h        |   7 +-
 linux-user/riscv/target_cpu.h      |   7 +-
 linux-user/s390x/target_cpu.h      |   7 +-
 linux-user/sh4/target_cpu.h        |   7 +-
 linux-user/sparc/signal.c          | 102 ++++++++++-----------------
 linux-user/sparc/target_cpu.h      |  60 +++++++++++-----
 linux-user/syscall.c               | 107 ++++++++++++++++++++++++++++-
 linux-user/tilegx/target_cpu.h     |   7 +-
 linux-user/xtensa/target_cpu.h     |   8 ++-
 scripts/qemu-binfmt-conf.sh        |   8 ++-
 target/sparc/cpu.h                 |  33 +++++++++
 tests/tcg/multiarch/linux-test.c   |   3 +-
 23 files changed, 338 insertions(+), 105 deletions(-)

-- 
2.21.0



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

* [PULL v2 01/13] linux-user: Support for NETLINK socket options
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-12 10:11   ` Peter Maydell
  2019-11-06 13:04 ` [PULL v2 02/13] scripts/qemu-binfmt-conf: Update for sparc64 Laurent Vivier
                   ` (13 subsequent siblings)
  14 siblings, 1 reply; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Riku Voipio, Mark Cave-Ayland, Laurent Vivier, Josh Kunz,
	Alex Bennée, Artyom Tarasenko

From: Josh Kunz <jkz@google.com>

This change includes support for all AF_NETLINK socket options up to about
kernel version 5.4 (5.4 is not formally released at the time of writing).
Socket options that were introduced in kernel versions before the oldest
currently stable kernel version are guarded by kernel version macros.

This change has been built under gcc 8.3, and clang 9.0, and it passes
`make check`. The netlink options have been tested by emulating some
non-trival software that uses NETLINK socket options, but they have
not been exaustively verified.

Signed-off-by: Josh Kunz <jkz@google.com>
Message-Id: <20191029224310.164025-1-jkz@google.com>
[lv: updated patch according to CODING_STYLE]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 101 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 101 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f6751eecb78c..247883292ce5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2248,6 +2248,39 @@ set_timeout:
             return -TARGET_EFAULT;
 	ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, sizeof(val)));
         break;
+#ifdef SOL_NETLINK
+    case SOL_NETLINK:
+        switch (optname) {
+        case NETLINK_PKTINFO:
+        case NETLINK_ADD_MEMBERSHIP:
+        case NETLINK_DROP_MEMBERSHIP:
+        case NETLINK_BROADCAST_ERROR:
+        case NETLINK_NO_ENOBUFS:
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+        case NETLINK_LISTEN_ALL_NSID:
+        case NETLINK_CAP_ACK:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+        case NETLINK_EXT_ACK:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)
+        case NETLINK_GET_STRICT_CHK:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
+            break;
+        default:
+            goto unimplemented;
+        }
+        val = 0;
+        if (optlen < sizeof(uint32_t)) {
+            return -TARGET_EINVAL;
+        }
+        if (get_user_u32(val, optval_addr)) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(setsockopt(sockfd, SOL_NETLINK, optname, &val,
+                                   sizeof(val)));
+        break;
+#endif /* SOL_NETLINK */
     default:
     unimplemented:
         gemu_log("Unsupported setsockopt level=%d optname=%d\n", level, optname);
@@ -2532,6 +2565,74 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
             break;
         }
         break;
+#ifdef SOL_NETLINK
+    case SOL_NETLINK:
+        switch (optname) {
+        case NETLINK_PKTINFO:
+        case NETLINK_BROADCAST_ERROR:
+        case NETLINK_NO_ENOBUFS:
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+        case NETLINK_LISTEN_ALL_NSID:
+        case NETLINK_CAP_ACK:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+        case NETLINK_EXT_ACK:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)
+        case NETLINK_GET_STRICT_CHK:
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
+            if (get_user_u32(len, optlen)) {
+                return -TARGET_EFAULT;
+            }
+            if (len != sizeof(val)) {
+                return -TARGET_EINVAL;
+            }
+            lv = len;
+            ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
+            if (ret < 0) {
+                return ret;
+            }
+            if (put_user_u32(lv, optlen)
+                || put_user_u32(val, optval_addr)) {
+                return -TARGET_EFAULT;
+            }
+            break;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+        case NETLINK_LIST_MEMBERSHIPS:
+        {
+            uint32_t *results;
+            int i;
+            if (get_user_u32(len, optlen)) {
+                return -TARGET_EFAULT;
+            }
+            if (len < 0) {
+                return -TARGET_EINVAL;
+            }
+            results = lock_user(VERIFY_WRITE, optval_addr, len, 1);
+            if (!results) {
+                return -TARGET_EFAULT;
+            }
+            lv = len;
+            ret = get_errno(getsockopt(sockfd, level, optname, results, &lv));
+            if (ret < 0) {
+                unlock_user(results, optval_addr, 0);
+                return ret;
+            }
+            /* swap host endianess to target endianess. */
+            for (i = 0; i < (len / sizeof(uint32_t)); i++) {
+                results[i] = tswap32(results[i]);
+            }
+            if (put_user_u32(lv, optlen)) {
+                return -TARGET_EFAULT;
+            }
+            unlock_user(results, optval_addr, 0);
+            break;
+        }
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) */
+        default:
+            goto unimplemented;
+        }
+#endif /* SOL_NETLINK */
     default:
     unimplemented:
         gemu_log("getsockopt level=%d optname=%d not yet supported\n",
-- 
2.21.0



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

* [PULL v2 02/13] scripts/qemu-binfmt-conf: Update for sparc64
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 01/13] linux-user: Support for NETLINK socket options Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 03/13] tests/tcg/multiarch/linux-test: Fix error check for shmat Laurent Vivier
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Alex Bennée, Artyom Tarasenko

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

Also note that we were missing the qemu_target_list entry
for plain sparc; fix that at the same time.

Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Tested-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20191106113318.10226-2-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 scripts/qemu-binfmt-conf.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh
index b5a16742a149..9f1580a91c7d 100755
--- a/scripts/qemu-binfmt-conf.sh
+++ b/scripts/qemu-binfmt-conf.sh
@@ -1,8 +1,8 @@
 #!/bin/sh
 # Enable automatic program execution by the kernel.
 
-qemu_target_list="i386 i486 alpha arm armeb sparc32plus ppc ppc64 ppc64le m68k \
-mips mipsel mipsn32 mipsn32el mips64 mips64el \
+qemu_target_list="i386 i486 alpha arm armeb sparc sparc32plus sparc64 \
+ppc ppc64 ppc64le m68k mips mipsel mipsn32 mipsn32el mips64 mips64el \
 sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb \
 microblaze microblazeel or1k x86_64"
 
@@ -38,6 +38,10 @@ sparc32plus_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x
 sparc32plus_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
 sparc32plus_family=sparc
 
+sparc64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2b'
+sparc64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+sparc64_family=sparc
+
 ppc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14'
 ppc_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
 ppc_family=ppc
-- 
2.21.0



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

* [PULL v2 03/13] tests/tcg/multiarch/linux-test: Fix error check for shmat
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 01/13] linux-user: Support for NETLINK socket options Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 02/13] scripts/qemu-binfmt-conf: Update for sparc64 Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 04/13] target/sparc: Define an enumeration for accessing env->regwptr Laurent Vivier
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Philippe Mathieu-Daudé,
	Alex Bennée, Artyom Tarasenko

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

The error indicator for this syscall is -1, not 0.

Fixes: e374bfa35bfb ("shm tests - disabled clone test")
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20191106113318.10226-3-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 tests/tcg/multiarch/linux-test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
index fa4243fc0426..673d7c8a1c25 100644
--- a/tests/tcg/multiarch/linux-test.c
+++ b/tests/tcg/multiarch/linux-test.c
@@ -503,8 +503,9 @@ static void test_shm(void)
 
     shmid = chk_error(shmget(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | 0777));
     ptr = shmat(shmid, NULL, 0);
-    if (!ptr)
+    if (ptr == (void *)-1) {
         error("shmat");
+    }
 
     memset(ptr, 0, SHM_SIZE);
 
-- 
2.21.0



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

* [PULL v2 04/13] target/sparc: Define an enumeration for accessing env->regwptr
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (2 preceding siblings ...)
  2019-11-06 13:04 ` [PULL v2 03/13] tests/tcg/multiarch/linux-test: Fix error check for shmat Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 05/13] linux-user/sparc: Use WREG constants in sparc/target_cpu.h Laurent Vivier
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Alex Bennée, Artyom Tarasenko

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

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20191106113318.10226-4-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 target/sparc/cpu.h | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
index 778aa8e073c7..ae97c7d9f799 100644
--- a/target/sparc/cpu.h
+++ b/target/sparc/cpu.h
@@ -13,6 +13,39 @@
 
 /*#define EXCP_INTERRUPT 0x100*/
 
+/* Windowed register indexes.  */
+enum {
+    WREG_O0,
+    WREG_O1,
+    WREG_O2,
+    WREG_O3,
+    WREG_O4,
+    WREG_O5,
+    WREG_O6,
+    WREG_O7,
+
+    WREG_L0,
+    WREG_L1,
+    WREG_L2,
+    WREG_L3,
+    WREG_L4,
+    WREG_L5,
+    WREG_L6,
+    WREG_L7,
+
+    WREG_I0,
+    WREG_I1,
+    WREG_I2,
+    WREG_I3,
+    WREG_I4,
+    WREG_I5,
+    WREG_I6,
+    WREG_I7,
+
+    WREG_SP = WREG_O6,
+    WREG_FP = WREG_I6,
+};
+
 /* trap definitions */
 #ifndef TARGET_SPARC64
 #define TT_TFAULT   0x01
-- 
2.21.0



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

* [PULL v2 05/13] linux-user/sparc: Use WREG constants in sparc/target_cpu.h
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (3 preceding siblings ...)
  2019-11-06 13:04 ` [PULL v2 04/13] target/sparc: Define an enumeration for accessing env->regwptr Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 06/13] linux-user/sparc: Begin using WREG constants in sparc/signal.c Laurent Vivier
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Alex Bennée, Artyom Tarasenko

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

This fixes a naming bug wherein we used "UREG_FP" to access the
stack pointer.  OTOH, the "UREG_FP" constant was also defined
incorrectly such that it *did* reference the stack pointer.

Note that the kernel legitimately uses the name "FP", because it
utilizes the rolled stack window in processing the system call.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20191106113318.10226-5-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/sparc/target_cpu.h | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/linux-user/sparc/target_cpu.h b/linux-user/sparc/target_cpu.h
index 1ffc0ae9f2ec..b30fbc72c43b 100644
--- a/linux-user/sparc/target_cpu.h
+++ b/linux-user/sparc/target_cpu.h
@@ -41,15 +41,9 @@ static inline void cpu_set_tls(CPUSPARCState *env, target_ulong newtls)
     env->gregs[7] = newtls;
 }
 
-#ifndef UREG_I6
-#define UREG_I6        6
-#endif
-#ifndef UREG_FP
-#define UREG_FP        UREG_I6
-#endif
-
 static inline abi_ulong get_sp_from_cpustate(CPUSPARCState *state)
 {
-    return state->regwptr[UREG_FP];
+    return state->regwptr[WREG_SP];
 }
+
 #endif
-- 
2.21.0



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

* [PULL v2 06/13] linux-user/sparc: Begin using WREG constants in sparc/signal.c
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (4 preceding siblings ...)
  2019-11-06 13:04 ` [PULL v2 05/13] linux-user/sparc: Use WREG constants in sparc/target_cpu.h Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 07/13] linux-user/sparc: Use WREG_SP constant " Laurent Vivier
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Alex Bennée, Artyom Tarasenko

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

This is non-obvious because the UREG constants are in fact wrong.

s/UREG_I/WREG_O/g
s/UREG_O/WREG_I/g
s/UREG_L/WREG_L/g

These substitutions have identical integer values.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20191106113318.10226-6-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/sparc/signal.c | 95 ++++++++++++++-------------------------
 1 file changed, 33 insertions(+), 62 deletions(-)

diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c
index ead169fbaa26..aac37da239c1 100644
--- a/linux-user/sparc/signal.c
+++ b/linux-user/sparc/signal.c
@@ -104,19 +104,8 @@ struct target_rt_signal_frame {
     qemu_siginfo_fpu_t  fpu_state;
 };
 
-#define UREG_O0        16
-#define UREG_O6        22
-#define UREG_I0        0
-#define UREG_I1        1
-#define UREG_I2        2
-#define UREG_I3        3
-#define UREG_I4        4
-#define UREG_I5        5
-#define UREG_I6        6
-#define UREG_I7        7
-#define UREG_L0        8
-#define UREG_FP        UREG_I6
-#define UREG_SP        UREG_O6
+#define UREG_FP        WREG_O6
+#define UREG_SP        WREG_I6
 
 static inline abi_ulong get_sigframe(struct target_sigaction *sa, 
                                      CPUSPARCState *env,
@@ -159,30 +148,12 @@ setup___siginfo(__siginfo_t *si, CPUSPARCState *env, abi_ulong mask)
         __put_user(env->gregs[i], &si->si_regs.u_regs[i]);
     }
     for (i=0; i < 8; i++) {
-        __put_user(env->regwptr[UREG_I0 + i], &si->si_regs.u_regs[i+8]);
+        __put_user(env->regwptr[WREG_O0 + i], &si->si_regs.u_regs[i + 8]);
     }
     __put_user(mask, &si->si_mask);
     return err;
 }
 
-#if 0
-static int
-setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/
-                 CPUSPARCState *env, unsigned long mask)
-{
-    int err = 0;
-
-    __put_user(mask, &sc->sigc_mask);
-    __put_user(env->regwptr[UREG_SP], &sc->sigc_sp);
-    __put_user(env->pc, &sc->sigc_pc);
-    __put_user(env->npc, &sc->sigc_npc);
-    __put_user(env->psr, &sc->sigc_psr);
-    __put_user(env->gregs[1], &sc->sigc_g1);
-    __put_user(env->regwptr[UREG_O0], &sc->sigc_o0);
-
-    return err;
-}
-#endif
 #define NF_ALIGNEDSZ  (((sizeof(struct target_signal_frame) + 7) & (~7)))
 
 void setup_frame(int sig, struct target_sigaction *ka,
@@ -221,20 +192,20 @@ void setup_frame(int sig, struct target_sigaction *ka,
     }
 
     for (i = 0; i < 8; i++) {
-        __put_user(env->regwptr[i + UREG_L0], &sf->ss.locals[i]);
+        __put_user(env->regwptr[i + WREG_L0], &sf->ss.locals[i]);
     }
     for (i = 0; i < 8; i++) {
-        __put_user(env->regwptr[i + UREG_I0], &sf->ss.ins[i]);
+        __put_user(env->regwptr[i + WREG_O0], &sf->ss.ins[i]);
     }
     if (err)
         goto sigsegv;
 
     /* 3. signal handler back-trampoline and parameters */
     env->regwptr[UREG_FP] = sf_addr;
-    env->regwptr[UREG_I0] = sig;
-    env->regwptr[UREG_I1] = sf_addr +
+    env->regwptr[WREG_O0] = sig;
+    env->regwptr[WREG_O1] = sf_addr +
             offsetof(struct target_signal_frame, info);
-    env->regwptr[UREG_I2] = sf_addr +
+    env->regwptr[WREG_O2] = sf_addr +
             offsetof(struct target_signal_frame, info);
 
     /* 4. signal handler */
@@ -242,11 +213,11 @@ void setup_frame(int sig, struct target_sigaction *ka,
     env->npc = (env->pc + 4);
     /* 5. return to kernel instructions */
     if (ka->ka_restorer) {
-        env->regwptr[UREG_I7] = ka->ka_restorer;
+        env->regwptr[WREG_O7] = ka->ka_restorer;
     } else {
         uint32_t val32;
 
-        env->regwptr[UREG_I7] = sf_addr +
+        env->regwptr[WREG_O7] = sf_addr +
                 offsetof(struct target_signal_frame, insns) - 2 * 4;
 
         /* mov __NR_sigreturn, %g1 */
@@ -316,7 +287,7 @@ long do_sigreturn(CPUSPARCState *env)
         __get_user(env->gregs[i], &sf->info.si_regs.u_regs[i]);
     }
     for (i=0; i < 8; i++) {
-        __get_user(env->regwptr[i + UREG_I0], &sf->info.si_regs.u_regs[i+8]);
+        __get_user(env->regwptr[i + WREG_O0], &sf->info.si_regs.u_regs[i + 8]);
     }
 
     /* FIXME: implement FPU save/restore:
@@ -433,7 +404,7 @@ void sparc64_set_context(CPUSPARCState *env)
     abi_ulong fp, i7, w_addr;
     unsigned int i;
 
-    ucp_addr = env->regwptr[UREG_I0];
+    ucp_addr = env->regwptr[WREG_O0];
     if (!lock_user_struct(VERIFY_READ, ucp, ucp_addr, 1)) {
         goto do_sigsegv;
     }
@@ -443,7 +414,7 @@ void sparc64_set_context(CPUSPARCState *env)
     if ((pc | npc) & 3) {
         goto do_sigsegv;
     }
-    if (env->regwptr[UREG_I1]) {
+    if (env->regwptr[WREG_O1]) {
         target_sigset_t target_set;
         sigset_t set;
 
@@ -474,19 +445,19 @@ void sparc64_set_context(CPUSPARCState *env)
     __get_user(env->gregs[5], (&(*grp)[SPARC_MC_G5]));
     __get_user(env->gregs[6], (&(*grp)[SPARC_MC_G6]));
     __get_user(env->gregs[7], (&(*grp)[SPARC_MC_G7]));
-    __get_user(env->regwptr[UREG_I0], (&(*grp)[SPARC_MC_O0]));
-    __get_user(env->regwptr[UREG_I1], (&(*grp)[SPARC_MC_O1]));
-    __get_user(env->regwptr[UREG_I2], (&(*grp)[SPARC_MC_O2]));
-    __get_user(env->regwptr[UREG_I3], (&(*grp)[SPARC_MC_O3]));
-    __get_user(env->regwptr[UREG_I4], (&(*grp)[SPARC_MC_O4]));
-    __get_user(env->regwptr[UREG_I5], (&(*grp)[SPARC_MC_O5]));
-    __get_user(env->regwptr[UREG_I6], (&(*grp)[SPARC_MC_O6]));
-    __get_user(env->regwptr[UREG_I7], (&(*grp)[SPARC_MC_O7]));
+    __get_user(env->regwptr[WREG_O0], (&(*grp)[SPARC_MC_O0]));
+    __get_user(env->regwptr[WREG_O1], (&(*grp)[SPARC_MC_O1]));
+    __get_user(env->regwptr[WREG_O2], (&(*grp)[SPARC_MC_O2]));
+    __get_user(env->regwptr[WREG_O3], (&(*grp)[SPARC_MC_O3]));
+    __get_user(env->regwptr[WREG_O4], (&(*grp)[SPARC_MC_O4]));
+    __get_user(env->regwptr[WREG_O5], (&(*grp)[SPARC_MC_O5]));
+    __get_user(env->regwptr[WREG_O6], (&(*grp)[SPARC_MC_O6]));
+    __get_user(env->regwptr[WREG_O7], (&(*grp)[SPARC_MC_O7]));
 
     __get_user(fp, &(ucp->tuc_mcontext.mc_fp));
     __get_user(i7, &(ucp->tuc_mcontext.mc_i7));
 
-    w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6];
+    w_addr = TARGET_STACK_BIAS + env->regwptr[WREG_O6];
     if (put_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]),
                  abi_ulong) != 0) {
         goto do_sigsegv;
@@ -534,7 +505,7 @@ void sparc64_get_context(CPUSPARCState *env)
     target_sigset_t target_set;
     sigset_t set;
 
-    ucp_addr = env->regwptr[UREG_I0];
+    ucp_addr = env->regwptr[WREG_O0];
     if (!lock_user_struct(VERIFY_WRITE, ucp, ucp_addr, 0)) {
         goto do_sigsegv;
     }
@@ -580,16 +551,16 @@ void sparc64_get_context(CPUSPARCState *env)
     __put_user(env->gregs[5], &((*grp)[SPARC_MC_G5]));
     __put_user(env->gregs[6], &((*grp)[SPARC_MC_G6]));
     __put_user(env->gregs[7], &((*grp)[SPARC_MC_G7]));
-    __put_user(env->regwptr[UREG_I0], &((*grp)[SPARC_MC_O0]));
-    __put_user(env->regwptr[UREG_I1], &((*grp)[SPARC_MC_O1]));
-    __put_user(env->regwptr[UREG_I2], &((*grp)[SPARC_MC_O2]));
-    __put_user(env->regwptr[UREG_I3], &((*grp)[SPARC_MC_O3]));
-    __put_user(env->regwptr[UREG_I4], &((*grp)[SPARC_MC_O4]));
-    __put_user(env->regwptr[UREG_I5], &((*grp)[SPARC_MC_O5]));
-    __put_user(env->regwptr[UREG_I6], &((*grp)[SPARC_MC_O6]));
-    __put_user(env->regwptr[UREG_I7], &((*grp)[SPARC_MC_O7]));
-
-    w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6];
+    __put_user(env->regwptr[WREG_O0], &((*grp)[SPARC_MC_O0]));
+    __put_user(env->regwptr[WREG_O1], &((*grp)[SPARC_MC_O1]));
+    __put_user(env->regwptr[WREG_O2], &((*grp)[SPARC_MC_O2]));
+    __put_user(env->regwptr[WREG_O3], &((*grp)[SPARC_MC_O3]));
+    __put_user(env->regwptr[WREG_O4], &((*grp)[SPARC_MC_O4]));
+    __put_user(env->regwptr[WREG_O5], &((*grp)[SPARC_MC_O5]));
+    __put_user(env->regwptr[WREG_O6], &((*grp)[SPARC_MC_O6]));
+    __put_user(env->regwptr[WREG_O7], &((*grp)[SPARC_MC_O7]));
+
+    w_addr = TARGET_STACK_BIAS + env->regwptr[WREG_O6];
     fp = i7 = 0;
     if (get_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]),
                  abi_ulong) != 0) {
-- 
2.21.0



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

* [PULL v2 07/13] linux-user/sparc: Use WREG_SP constant in sparc/signal.c
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (5 preceding siblings ...)
  2019-11-06 13:04 ` [PULL v2 06/13] linux-user/sparc: Begin using WREG constants in sparc/signal.c Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 08/13] linux-user/sparc: Fix WREG usage in setup_frame Laurent Vivier
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Alex Bennée, Artyom Tarasenko

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

s/UREG_FP/WREG_SP/g

This is non-obvious because the UREG_FP constant is fact wrong.
However, the previous search-and-replace patch made it clear that
UREG_FP expands to WREG_O6, and we can see from the enumeration in
target/sparc/cpu.h that WREG_O6 is in fact WREG_SP, the stack pointer.

The UREG_SP define is unused; remove it.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20191106113318.10226-7-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/sparc/signal.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c
index aac37da239c1..e05693f20432 100644
--- a/linux-user/sparc/signal.c
+++ b/linux-user/sparc/signal.c
@@ -104,9 +104,6 @@ struct target_rt_signal_frame {
     qemu_siginfo_fpu_t  fpu_state;
 };
 
-#define UREG_FP        WREG_O6
-#define UREG_SP        WREG_I6
-
 static inline abi_ulong get_sigframe(struct target_sigaction *sa, 
                                      CPUSPARCState *env,
                                      unsigned long framesize)
@@ -201,7 +198,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
         goto sigsegv;
 
     /* 3. signal handler back-trampoline and parameters */
-    env->regwptr[UREG_FP] = sf_addr;
+    env->regwptr[WREG_SP] = sf_addr;
     env->regwptr[WREG_O0] = sig;
     env->regwptr[WREG_O1] = sf_addr +
             offsetof(struct target_signal_frame, info);
@@ -255,7 +252,7 @@ long do_sigreturn(CPUSPARCState *env)
     sigset_t host_set;
     int i;
 
-    sf_addr = env->regwptr[UREG_FP];
+    sf_addr = env->regwptr[WREG_SP];
     trace_user_do_sigreturn(env, sf_addr);
     if (!lock_user_struct(VERIFY_READ, sf, sf_addr, 1)) {
         goto segv_and_exit;
-- 
2.21.0



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

* [PULL v2 08/13] linux-user/sparc: Fix WREG usage in setup_frame
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (6 preceding siblings ...)
  2019-11-06 13:04 ` [PULL v2 07/13] linux-user/sparc: Use WREG_SP constant " Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 09/13] linux-user/sparc64: Fix target_signal_frame Laurent Vivier
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Alex Bennée, Artyom Tarasenko

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

Use WREG_I0 not WREG_O0 in order to properly save the "ins".
The "outs" were saved separately in setup___siginfo.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20191106113318.10226-8-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/sparc/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c
index e05693f20432..238d0ba00c89 100644
--- a/linux-user/sparc/signal.c
+++ b/linux-user/sparc/signal.c
@@ -192,7 +192,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
         __put_user(env->regwptr[i + WREG_L0], &sf->ss.locals[i]);
     }
     for (i = 0; i < 8; i++) {
-        __put_user(env->regwptr[i + WREG_O0], &sf->ss.ins[i]);
+        __put_user(env->regwptr[i + WREG_I0], &sf->ss.ins[i]);
     }
     if (err)
         goto sigsegv;
-- 
2.21.0



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

* [PULL v2 09/13] linux-user/sparc64: Fix target_signal_frame
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (7 preceding siblings ...)
  2019-11-06 13:04 ` [PULL v2 08/13] linux-user/sparc: Fix WREG usage in setup_frame Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 10/13] linux-user: Rename cpu_clone_regs to cpu_clone_regs_child Laurent Vivier
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Alex Bennée, Artyom Tarasenko

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

Instructions are always 4 bytes; use uint32_t not abi_ulong.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20191106113318.10226-9-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/sparc/signal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c
index 238d0ba00c89..d796f50f665b 100644
--- a/linux-user/sparc/signal.c
+++ b/linux-user/sparc/signal.c
@@ -87,7 +87,7 @@ struct target_signal_frame {
     struct sparc_stackf ss;
     __siginfo_t         info;
     abi_ulong           fpu_save;
-    abi_ulong           insns[2] __attribute__ ((aligned (8)));
+    uint32_t            insns[2] QEMU_ALIGNED(8);
     abi_ulong           extramask[TARGET_NSIG_WORDS - 1];
     abi_ulong           extra_size; /* Should be 0 */
     qemu_siginfo_fpu_t fpu_state;
@@ -98,7 +98,7 @@ struct target_rt_signal_frame {
     abi_ulong           regs[20];
     sigset_t            mask;
     abi_ulong           fpu_save;
-    unsigned int        insns[2];
+    uint32_t            insns[2];
     stack_t             stack;
     unsigned int        extra_size; /* Should be 0 */
     qemu_siginfo_fpu_t  fpu_state;
-- 
2.21.0



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

* [PULL v2 10/13] linux-user: Rename cpu_clone_regs to cpu_clone_regs_child
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (8 preceding siblings ...)
  2019-11-06 13:04 ` [PULL v2 09/13] linux-user/sparc64: Fix target_signal_frame Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 11/13] linux-user: Introduce cpu_clone_regs_parent Laurent Vivier
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Philippe Mathieu-Daudé,
	Alex Bennée, Artyom Tarasenko

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

We will need a target-specific hook for adjusting registers
in the parent during clone.  To avoid confusion, rename the
one we have to make it clear it affects the child.

At the same time, pass in the flags from the clone syscall.
We will need them for correct behaviour for Sparc.

Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20191106113318.10226-10-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/aarch64/target_cpu.h    | 3 ++-
 linux-user/alpha/target_cpu.h      | 3 ++-
 linux-user/arm/target_cpu.h        | 3 ++-
 linux-user/cris/target_cpu.h       | 3 ++-
 linux-user/hppa/target_cpu.h       | 3 ++-
 linux-user/i386/target_cpu.h       | 3 ++-
 linux-user/m68k/target_cpu.h       | 3 ++-
 linux-user/microblaze/target_cpu.h | 3 ++-
 linux-user/mips/target_cpu.h       | 3 ++-
 linux-user/nios2/target_cpu.h      | 3 ++-
 linux-user/openrisc/target_cpu.h   | 4 +++-
 linux-user/ppc/target_cpu.h        | 3 ++-
 linux-user/riscv/target_cpu.h      | 3 ++-
 linux-user/s390x/target_cpu.h      | 3 ++-
 linux-user/sh4/target_cpu.h        | 3 ++-
 linux-user/sparc/target_cpu.h      | 3 ++-
 linux-user/syscall.c               | 4 ++--
 linux-user/tilegx/target_cpu.h     | 3 ++-
 linux-user/xtensa/target_cpu.h     | 4 +++-
 19 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/linux-user/aarch64/target_cpu.h b/linux-user/aarch64/target_cpu.h
index a021c95fa418..cd012e0dc1c8 100644
--- a/linux-user/aarch64/target_cpu.h
+++ b/linux-user/aarch64/target_cpu.h
@@ -19,7 +19,8 @@
 #ifndef AARCH64_TARGET_CPU_H
 #define AARCH64_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUARMState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->xregs[31] = newsp;
diff --git a/linux-user/alpha/target_cpu.h b/linux-user/alpha/target_cpu.h
index ac4d255ae752..37ba00cf41d1 100644
--- a/linux-user/alpha/target_cpu.h
+++ b/linux-user/alpha/target_cpu.h
@@ -19,7 +19,8 @@
 #ifndef ALPHA_TARGET_CPU_H
 #define ALPHA_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUAlphaState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUAlphaState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->ir[IR_SP] = newsp;
diff --git a/linux-user/arm/target_cpu.h b/linux-user/arm/target_cpu.h
index 3f79356a07fc..6e2ba8ad4b8e 100644
--- a/linux-user/arm/target_cpu.h
+++ b/linux-user/arm/target_cpu.h
@@ -41,7 +41,8 @@ static inline unsigned long arm_max_reserved_va(CPUState *cs)
 }
 #define MAX_RESERVED_VA  arm_max_reserved_va
 
-static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUARMState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->regs[13] = newsp;
diff --git a/linux-user/cris/target_cpu.h b/linux-user/cris/target_cpu.h
index 23093439790c..eacc4d8d13e9 100644
--- a/linux-user/cris/target_cpu.h
+++ b/linux-user/cris/target_cpu.h
@@ -20,7 +20,8 @@
 #ifndef CRIS_TARGET_CPU_H
 #define CRIS_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUCRISState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUCRISState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->regs[14] = newsp;
diff --git a/linux-user/hppa/target_cpu.h b/linux-user/hppa/target_cpu.h
index 1c539bdbd6e9..f25077079088 100644
--- a/linux-user/hppa/target_cpu.h
+++ b/linux-user/hppa/target_cpu.h
@@ -19,7 +19,8 @@
 #ifndef HPPA_TARGET_CPU_H
 #define HPPA_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUHPPAState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUHPPAState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->gr[30] = newsp;
diff --git a/linux-user/i386/target_cpu.h b/linux-user/i386/target_cpu.h
index ece04d096675..1fadbf57c367 100644
--- a/linux-user/i386/target_cpu.h
+++ b/linux-user/i386/target_cpu.h
@@ -20,7 +20,8 @@
 #ifndef I386_TARGET_CPU_H
 #define I386_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUX86State *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUX86State *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->regs[R_ESP] = newsp;
diff --git a/linux-user/m68k/target_cpu.h b/linux-user/m68k/target_cpu.h
index bc7446fbafdd..57b647bc0753 100644
--- a/linux-user/m68k/target_cpu.h
+++ b/linux-user/m68k/target_cpu.h
@@ -21,7 +21,8 @@
 #ifndef M68K_TARGET_CPU_H
 #define M68K_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUM68KState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUM68KState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->aregs[7] = newsp;
diff --git a/linux-user/microblaze/target_cpu.h b/linux-user/microblaze/target_cpu.h
index 73e139938cc6..e9bc0fce6547 100644
--- a/linux-user/microblaze/target_cpu.h
+++ b/linux-user/microblaze/target_cpu.h
@@ -19,7 +19,8 @@
 #ifndef MICROBLAZE_TARGET_CPU_H
 #define MICROBLAZE_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUMBState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUMBState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->regs[R_SP] = newsp;
diff --git a/linux-user/mips/target_cpu.h b/linux-user/mips/target_cpu.h
index 02cf5eeff7c2..8601f712e086 100644
--- a/linux-user/mips/target_cpu.h
+++ b/linux-user/mips/target_cpu.h
@@ -19,7 +19,8 @@
 #ifndef MIPS_TARGET_CPU_H
 #define MIPS_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUMIPSState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUMIPSState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->active_tc.gpr[29] = newsp;
diff --git a/linux-user/nios2/target_cpu.h b/linux-user/nios2/target_cpu.h
index 5596c05c9c0f..fe5de7a9e3c7 100644
--- a/linux-user/nios2/target_cpu.h
+++ b/linux-user/nios2/target_cpu.h
@@ -20,7 +20,8 @@
 #ifndef NIOS2_TARGET_CPU_H
 #define NIOS2_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUNios2State *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUNios2State *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->regs[R_SP] = newsp;
diff --git a/linux-user/openrisc/target_cpu.h b/linux-user/openrisc/target_cpu.h
index 32ff135089e0..309cf3eeb73e 100644
--- a/linux-user/openrisc/target_cpu.h
+++ b/linux-user/openrisc/target_cpu.h
@@ -20,7 +20,9 @@
 #ifndef OPENRISC_TARGET_CPU_H
 #define OPENRISC_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUOpenRISCState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUOpenRISCState *env,
+                                        target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         cpu_set_gpr(env, 1, newsp);
diff --git a/linux-user/ppc/target_cpu.h b/linux-user/ppc/target_cpu.h
index c4641834e794..028b28312c51 100644
--- a/linux-user/ppc/target_cpu.h
+++ b/linux-user/ppc/target_cpu.h
@@ -19,7 +19,8 @@
 #ifndef PPC_TARGET_CPU_H
 #define PPC_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUPPCState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUPPCState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->gpr[1] = newsp;
diff --git a/linux-user/riscv/target_cpu.h b/linux-user/riscv/target_cpu.h
index 90f9a4171ee7..26dcafab1c77 100644
--- a/linux-user/riscv/target_cpu.h
+++ b/linux-user/riscv/target_cpu.h
@@ -1,7 +1,8 @@
 #ifndef RISCV_TARGET_CPU_H
 #define RISCV_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPURISCVState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPURISCVState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->gpr[xSP] = newsp;
diff --git a/linux-user/s390x/target_cpu.h b/linux-user/s390x/target_cpu.h
index aa181ceaee83..0b19e42f758b 100644
--- a/linux-user/s390x/target_cpu.h
+++ b/linux-user/s390x/target_cpu.h
@@ -19,7 +19,8 @@
 #ifndef S390X_TARGET_CPU_H
 #define S390X_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUS390XState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUS390XState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->regs[15] = newsp;
diff --git a/linux-user/sh4/target_cpu.h b/linux-user/sh4/target_cpu.h
index b0be9a2c1bb0..857af43ee3aa 100644
--- a/linux-user/sh4/target_cpu.h
+++ b/linux-user/sh4/target_cpu.h
@@ -19,7 +19,8 @@
 #ifndef SH4_TARGET_CPU_H
 #define SH4_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUSH4State *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUSH4State *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->gregs[15] = newsp;
diff --git a/linux-user/sparc/target_cpu.h b/linux-user/sparc/target_cpu.h
index b30fbc72c43b..029b0fc5475a 100644
--- a/linux-user/sparc/target_cpu.h
+++ b/linux-user/sparc/target_cpu.h
@@ -20,7 +20,8 @@
 #ifndef SPARC_TARGET_CPU_H
 #define SPARC_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUSPARCState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUSPARCState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->regwptr[22] = newsp;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 247883292ce5..245ed315c834 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5820,7 +5820,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
         /* we create a new CPU instance. */
         new_env = cpu_copy(env);
         /* Init regs that differ from the parent.  */
-        cpu_clone_regs(new_env, newsp);
+        cpu_clone_regs_child(new_env, newsp, flags);
         new_cpu = env_cpu(new_env);
         new_cpu->opaque = ts;
         ts->bprm = parent_ts->bprm;
@@ -5899,7 +5899,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
         ret = fork();
         if (ret == 0) {
             /* Child Process.  */
-            cpu_clone_regs(env, newsp);
+            cpu_clone_regs_child(env, newsp, flags);
             fork_end(1);
             /* There is a race condition here.  The parent process could
                theoretically read the TID in the child process before the child
diff --git a/linux-user/tilegx/target_cpu.h b/linux-user/tilegx/target_cpu.h
index d1aa5824f292..0523dc414cc5 100644
--- a/linux-user/tilegx/target_cpu.h
+++ b/linux-user/tilegx/target_cpu.h
@@ -19,7 +19,8 @@
 #ifndef TILEGX_TARGET_CPU_H
 #define TILEGX_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUTLGState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUTLGState *env, target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->regs[TILEGX_R_SP] = newsp;
diff --git a/linux-user/xtensa/target_cpu.h b/linux-user/xtensa/target_cpu.h
index e31efe3ea090..84f67d469ec0 100644
--- a/linux-user/xtensa/target_cpu.h
+++ b/linux-user/xtensa/target_cpu.h
@@ -4,7 +4,9 @@
 #ifndef XTENSA_TARGET_CPU_H
 #define XTENSA_TARGET_CPU_H
 
-static inline void cpu_clone_regs(CPUXtensaState *env, target_ulong newsp)
+static inline void cpu_clone_regs_child(CPUXtensaState *env,
+                                        target_ulong newsp,
+                                        unsigned flags)
 {
     if (newsp) {
         env->regs[1] = newsp;
-- 
2.21.0



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

* [PULL v2 11/13] linux-user: Introduce cpu_clone_regs_parent
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (9 preceding siblings ...)
  2019-11-06 13:04 ` [PULL v2 10/13] linux-user: Rename cpu_clone_regs to cpu_clone_regs_child Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 12/13] linux-user/sparc: Fix cpu_clone_regs_* Laurent Vivier
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Philippe Mathieu-Daudé,
	Alex Bennée, Artyom Tarasenko

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

We will need a target-specific hook for adjusting registers
in the parent during clone.  Add an empty inline function for
each target, and invoke it from the proper places.

Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20191106113318.10226-11-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/aarch64/target_cpu.h    | 4 ++++
 linux-user/alpha/target_cpu.h      | 4 ++++
 linux-user/arm/target_cpu.h        | 4 ++++
 linux-user/cris/target_cpu.h       | 4 ++++
 linux-user/hppa/target_cpu.h       | 4 ++++
 linux-user/i386/target_cpu.h       | 4 ++++
 linux-user/m68k/target_cpu.h       | 4 ++++
 linux-user/microblaze/target_cpu.h | 4 ++++
 linux-user/mips/target_cpu.h       | 4 ++++
 linux-user/nios2/target_cpu.h      | 4 ++++
 linux-user/openrisc/target_cpu.h   | 4 ++++
 linux-user/ppc/target_cpu.h        | 4 ++++
 linux-user/riscv/target_cpu.h      | 4 ++++
 linux-user/s390x/target_cpu.h      | 4 ++++
 linux-user/sh4/target_cpu.h        | 4 ++++
 linux-user/sparc/target_cpu.h      | 4 ++++
 linux-user/syscall.c               | 2 ++
 linux-user/tilegx/target_cpu.h     | 4 ++++
 linux-user/xtensa/target_cpu.h     | 4 ++++
 19 files changed, 74 insertions(+)

diff --git a/linux-user/aarch64/target_cpu.h b/linux-user/aarch64/target_cpu.h
index cd012e0dc1c8..6cc02e7dcdfb 100644
--- a/linux-user/aarch64/target_cpu.h
+++ b/linux-user/aarch64/target_cpu.h
@@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUARMState *env, target_ulong newsp,
     env->xregs[0] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUARMState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUARMState *env, target_ulong newtls)
 {
     /* Note that AArch64 Linux keeps the TLS pointer in TPIDR; this is
diff --git a/linux-user/alpha/target_cpu.h b/linux-user/alpha/target_cpu.h
index 37ba00cf41d1..dd25e18f47fb 100644
--- a/linux-user/alpha/target_cpu.h
+++ b/linux-user/alpha/target_cpu.h
@@ -29,6 +29,10 @@ static inline void cpu_clone_regs_child(CPUAlphaState *env, target_ulong newsp,
     env->ir[IR_A3] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUAlphaState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUAlphaState *env, target_ulong newtls)
 {
     env->unique = newtls;
diff --git a/linux-user/arm/target_cpu.h b/linux-user/arm/target_cpu.h
index 6e2ba8ad4b8e..2747211b24ab 100644
--- a/linux-user/arm/target_cpu.h
+++ b/linux-user/arm/target_cpu.h
@@ -50,6 +50,10 @@ static inline void cpu_clone_regs_child(CPUARMState *env, target_ulong newsp,
     env->regs[0] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUARMState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUARMState *env, target_ulong newtls)
 {
     if (access_secure_reg(env)) {
diff --git a/linux-user/cris/target_cpu.h b/linux-user/cris/target_cpu.h
index eacc4d8d13e9..74ead55c8114 100644
--- a/linux-user/cris/target_cpu.h
+++ b/linux-user/cris/target_cpu.h
@@ -29,6 +29,10 @@ static inline void cpu_clone_regs_child(CPUCRISState *env, target_ulong newsp,
     env->regs[10] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUCRISState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUCRISState *env, target_ulong newtls)
 {
     env->pregs[PR_PID] = (env->pregs[PR_PID] & 0xff) | newtls;
diff --git a/linux-user/hppa/target_cpu.h b/linux-user/hppa/target_cpu.h
index f25077079088..71654b3cd4c0 100644
--- a/linux-user/hppa/target_cpu.h
+++ b/linux-user/hppa/target_cpu.h
@@ -32,6 +32,10 @@ static inline void cpu_clone_regs_child(CPUHPPAState *env, target_ulong newsp,
     env->iaoq_b = env->gr[31] + 4;
 }
 
+static inline void cpu_clone_regs_parent(CPUHPPAState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUHPPAState *env, target_ulong newtls)
 {
     env->cr[27] = newtls;
diff --git a/linux-user/i386/target_cpu.h b/linux-user/i386/target_cpu.h
index 1fadbf57c367..0b44530854c8 100644
--- a/linux-user/i386/target_cpu.h
+++ b/linux-user/i386/target_cpu.h
@@ -29,6 +29,10 @@ static inline void cpu_clone_regs_child(CPUX86State *env, target_ulong newsp,
     env->regs[R_EAX] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUX86State *env, unsigned flags)
+{
+}
+
 #if defined(TARGET_ABI32)
 abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr);
 
diff --git a/linux-user/m68k/target_cpu.h b/linux-user/m68k/target_cpu.h
index 57b647bc0753..c3f288dfe83e 100644
--- a/linux-user/m68k/target_cpu.h
+++ b/linux-user/m68k/target_cpu.h
@@ -30,6 +30,10 @@ static inline void cpu_clone_regs_child(CPUM68KState *env, target_ulong newsp,
     env->dregs[0] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUM68KState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUM68KState *env, target_ulong newtls)
 {
     CPUState *cs = env_cpu(env);
diff --git a/linux-user/microblaze/target_cpu.h b/linux-user/microblaze/target_cpu.h
index e9bc0fce6547..ce7b22ece7c4 100644
--- a/linux-user/microblaze/target_cpu.h
+++ b/linux-user/microblaze/target_cpu.h
@@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUMBState *env, target_ulong newsp,
     env->regs[3] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUMBState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUMBState *env, target_ulong newtls)
 {
     env->regs[21] = newtls;
diff --git a/linux-user/mips/target_cpu.h b/linux-user/mips/target_cpu.h
index 8601f712e086..758ae4d933fe 100644
--- a/linux-user/mips/target_cpu.h
+++ b/linux-user/mips/target_cpu.h
@@ -29,6 +29,10 @@ static inline void cpu_clone_regs_child(CPUMIPSState *env, target_ulong newsp,
     env->active_tc.gpr[2] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUMIPSState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUMIPSState *env, target_ulong newtls)
 {
     env->active_tc.CP0_UserLocal = newtls;
diff --git a/linux-user/nios2/target_cpu.h b/linux-user/nios2/target_cpu.h
index fe5de7a9e3c7..50f03810675a 100644
--- a/linux-user/nios2/target_cpu.h
+++ b/linux-user/nios2/target_cpu.h
@@ -29,6 +29,10 @@ static inline void cpu_clone_regs_child(CPUNios2State *env, target_ulong newsp,
     env->regs[R_RET0] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUNios2State *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUNios2State *env, target_ulong newtls)
 {
     /*
diff --git a/linux-user/openrisc/target_cpu.h b/linux-user/openrisc/target_cpu.h
index 309cf3eeb73e..74370d67c45d 100644
--- a/linux-user/openrisc/target_cpu.h
+++ b/linux-user/openrisc/target_cpu.h
@@ -30,6 +30,10 @@ static inline void cpu_clone_regs_child(CPUOpenRISCState *env,
     cpu_set_gpr(env, 11, 0);
 }
 
+static inline void cpu_clone_regs_parent(CPUOpenRISCState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUOpenRISCState *env, target_ulong newtls)
 {
     cpu_set_gpr(env, 10, newtls);
diff --git a/linux-user/ppc/target_cpu.h b/linux-user/ppc/target_cpu.h
index 028b28312c51..76b67d2882bf 100644
--- a/linux-user/ppc/target_cpu.h
+++ b/linux-user/ppc/target_cpu.h
@@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUPPCState *env, target_ulong newsp,
     env->gpr[3] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUPPCState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUPPCState *env, target_ulong newtls)
 {
 #if defined(TARGET_PPC64)
diff --git a/linux-user/riscv/target_cpu.h b/linux-user/riscv/target_cpu.h
index 26dcafab1c77..9c642367a362 100644
--- a/linux-user/riscv/target_cpu.h
+++ b/linux-user/riscv/target_cpu.h
@@ -11,6 +11,10 @@ static inline void cpu_clone_regs_child(CPURISCVState *env, target_ulong newsp,
     env->gpr[xA0] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPURISCVState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPURISCVState *env, target_ulong newtls)
 {
     env->gpr[xTP] = newtls;
diff --git a/linux-user/s390x/target_cpu.h b/linux-user/s390x/target_cpu.h
index 0b19e42f758b..7cd71e2dbab3 100644
--- a/linux-user/s390x/target_cpu.h
+++ b/linux-user/s390x/target_cpu.h
@@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUS390XState *env, target_ulong newsp,
     env->regs[2] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUS390XState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUS390XState *env, target_ulong newtls)
 {
     env->aregs[0] = newtls >> 32;
diff --git a/linux-user/sh4/target_cpu.h b/linux-user/sh4/target_cpu.h
index 857af43ee3aa..5114f1942482 100644
--- a/linux-user/sh4/target_cpu.h
+++ b/linux-user/sh4/target_cpu.h
@@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUSH4State *env, target_ulong newsp,
     env->gregs[0] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUSH4State *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUSH4State *env, target_ulong newtls)
 {
   env->gbr = newtls;
diff --git a/linux-user/sparc/target_cpu.h b/linux-user/sparc/target_cpu.h
index 029b0fc5475a..8ff706adcef7 100644
--- a/linux-user/sparc/target_cpu.h
+++ b/linux-user/sparc/target_cpu.h
@@ -37,6 +37,10 @@ static inline void cpu_clone_regs_child(CPUSPARCState *env, target_ulong newsp,
 #endif
 }
 
+static inline void cpu_clone_regs_parent(CPUSPARCState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUSPARCState *env, target_ulong newtls)
 {
     env->gregs[7] = newtls;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 245ed315c834..ab9d933e53af 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5821,6 +5821,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
         new_env = cpu_copy(env);
         /* Init regs that differ from the parent.  */
         cpu_clone_regs_child(new_env, newsp, flags);
+        cpu_clone_regs_parent(env, flags);
         new_cpu = env_cpu(new_env);
         new_cpu->opaque = ts;
         ts->bprm = parent_ts->bprm;
@@ -5917,6 +5918,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
             if (flags & CLONE_CHILD_CLEARTID)
                 ts->child_tidptr = child_tidptr;
         } else {
+            cpu_clone_regs_parent(env, flags);
             fork_end(0);
         }
     }
diff --git a/linux-user/tilegx/target_cpu.h b/linux-user/tilegx/target_cpu.h
index 0523dc414cc5..316b7a639c3d 100644
--- a/linux-user/tilegx/target_cpu.h
+++ b/linux-user/tilegx/target_cpu.h
@@ -28,6 +28,10 @@ static inline void cpu_clone_regs_child(CPUTLGState *env, target_ulong newsp,
     env->regs[TILEGX_R_RE] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUTLGState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUTLGState *env, target_ulong newtls)
 {
     env->regs[TILEGX_R_TP] = newtls;
diff --git a/linux-user/xtensa/target_cpu.h b/linux-user/xtensa/target_cpu.h
index 84f67d469ec0..0c77bafd66f7 100644
--- a/linux-user/xtensa/target_cpu.h
+++ b/linux-user/xtensa/target_cpu.h
@@ -16,6 +16,10 @@ static inline void cpu_clone_regs_child(CPUXtensaState *env,
     env->regs[2] = 0;
 }
 
+static inline void cpu_clone_regs_parent(CPUXtensaState *env, unsigned flags)
+{
+}
+
 static inline void cpu_set_tls(CPUXtensaState *env, target_ulong newtls)
 {
     env->uregs[THREADPTR] = newtls;
-- 
2.21.0



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

* [PULL v2 12/13] linux-user/sparc: Fix cpu_clone_regs_*
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (10 preceding siblings ...)
  2019-11-06 13:04 ` [PULL v2 11/13] linux-user: Introduce cpu_clone_regs_parent Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 13:04 ` [PULL v2 13/13] linux-user/alpha: Set r20 secondary return value Laurent Vivier
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Alex Bennée, Artyom Tarasenko

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

We failed to set the secondary return value in %o1
we failed to advance the PC past the syscall,
we failed to adjust regwptr into the new structure,
we stored the stack pointer into the wrong register.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20191106113318.10226-12-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/sparc/target_cpu.h | 43 +++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/linux-user/sparc/target_cpu.h b/linux-user/sparc/target_cpu.h
index 8ff706adcef7..14b21589699b 100644
--- a/linux-user/sparc/target_cpu.h
+++ b/linux-user/sparc/target_cpu.h
@@ -23,22 +23,51 @@
 static inline void cpu_clone_regs_child(CPUSPARCState *env, target_ulong newsp,
                                         unsigned flags)
 {
+    /*
+     * After cpu_copy, env->regwptr is pointing into the old env.
+     * Update the new cpu to use its own register window.
+     */
+    env->regwptr = env->regbase + (env->cwp * 16);
+
     if (newsp) {
-        env->regwptr[22] = newsp;
+        /* When changing stacks, do it with clean register windows.  */
+#ifdef TARGET_SPARC64
+        env->cansave = env->nwindows - 2;
+        env->cleanwin = env->nwindows - 2;
+        env->canrestore = 0;
+#else
+        env->wim = 1 << env->cwp;
+#endif
+        /* ??? The kernel appears to copy one stack frame to the new stack. */
+        /* ??? The kernel force aligns the new stack. */
+        env->regwptr[WREG_SP] = newsp;
     }
-    /* syscall return for clone child: 0, and clear CF since
-     * this counts as a success return value.
-     */
-    env->regwptr[0] = 0;
+
+    if (flags & CLONE_VM) {
+        /*
+         * Syscall return for clone child: %o0 = 0 and clear CF since this
+         * counts as a success return value.  Advance the PC past the syscall.
+         * For fork child, all of this happens in cpu_loop, and we must not
+         * do the pc advance twice.
+         */
+        env->regwptr[WREG_O0] = 0;
 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
-    env->xcc &= ~PSR_CARRY;
+        env->xcc &= ~PSR_CARRY;
 #else
-    env->psr &= ~PSR_CARRY;
+        env->psr &= ~PSR_CARRY;
 #endif
+        env->pc = env->npc;
+        env->npc = env->npc + 4;
+    }
+
+    /* Set the second return value for the child: %o1 = 1.  */
+    env->regwptr[WREG_O1] = 1;
 }
 
 static inline void cpu_clone_regs_parent(CPUSPARCState *env, unsigned flags)
 {
+    /* Set the second return value for the parent: %o1 = 0.  */
+    env->regwptr[WREG_O1] = 0;
 }
 
 static inline void cpu_set_tls(CPUSPARCState *env, target_ulong newtls)
-- 
2.21.0



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

* [PULL v2 13/13] linux-user/alpha: Set r20 secondary return value
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (11 preceding siblings ...)
  2019-11-06 13:04 ` [PULL v2 12/13] linux-user/sparc: Fix cpu_clone_regs_* Laurent Vivier
@ 2019-11-06 13:04 ` Laurent Vivier
  2019-11-06 19:10 ` [PULL v2 00/13] Linux user for 4.2 patches no-reply
  2019-11-06 22:04 ` Peter Maydell
  14 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-06 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Riku Voipio, Mark Cave-Ayland, Laurent Vivier,
	Alex Bennée, Artyom Tarasenko

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

This value is not, as far as I know, used by any linux software,
but it is set by the kernel and is part of the ABI.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20191106113318.10226-13-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/alpha/target_cpu.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/linux-user/alpha/target_cpu.h b/linux-user/alpha/target_cpu.h
index dd25e18f47fb..ad408ab5cc8e 100644
--- a/linux-user/alpha/target_cpu.h
+++ b/linux-user/alpha/target_cpu.h
@@ -27,10 +27,19 @@ static inline void cpu_clone_regs_child(CPUAlphaState *env, target_ulong newsp,
     }
     env->ir[IR_V0] = 0;
     env->ir[IR_A3] = 0;
+    env->ir[IR_A4] = 1;  /* OSF/1 secondary return: child */
 }
 
 static inline void cpu_clone_regs_parent(CPUAlphaState *env, unsigned flags)
 {
+    /*
+     * OSF/1 secondary return: parent
+     * Note that the kernel does not do this if SETTLS, because the
+     * settls argument register is still live after copy_thread.
+     */
+    if (!(flags & CLONE_SETTLS)) {
+        env->ir[IR_A4] = 0;
+    }
 }
 
 static inline void cpu_set_tls(CPUAlphaState *env, target_ulong newtls)
-- 
2.21.0



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

* Re: [PULL v2 00/13] Linux user for 4.2 patches
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (12 preceding siblings ...)
  2019-11-06 13:04 ` [PULL v2 13/13] linux-user/alpha: Set r20 secondary return value Laurent Vivier
@ 2019-11-06 19:10 ` no-reply
  2019-11-06 22:04 ` Peter Maydell
  14 siblings, 0 replies; 18+ messages in thread
From: no-reply @ 2019-11-06 19:10 UTC (permalink / raw)
  To: laurent
  Cc: riku.voipio, mark.cave-ayland, qemu-devel, laurent, alex.bennee,
	atar4qemu

Patchew URL: https://patchew.org/QEMU/20191106130456.6176-1-laurent@vivier.eu/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Subject: [PULL v2 00/13] Linux user for 4.2 patches
Type: series
Message-id: 20191106130456.6176-1-laurent@vivier.eu

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
   2dd8fd6..4570c2e  master     -> master
 - [tag update]      patchew/20191018004850.9888-1-richardw.yang@linux.intel.com -> patchew/20191018004850.9888-1-richardw.yang@linux.intel.com
Switched to a new branch 'test'
66eeef8 linux-user/alpha: Set r20 secondary return value
752ee6e linux-user/sparc: Fix cpu_clone_regs_*
205ab4e linux-user: Introduce cpu_clone_regs_parent
e116815 linux-user: Rename cpu_clone_regs to cpu_clone_regs_child
e331e5c linux-user/sparc64: Fix target_signal_frame
0a9f44c linux-user/sparc: Fix WREG usage in setup_frame
39220db linux-user/sparc: Use WREG_SP constant in sparc/signal.c
54f43cd linux-user/sparc: Begin using WREG constants in sparc/signal.c
41f1345 linux-user/sparc: Use WREG constants in sparc/target_cpu.h
084e4ce target/sparc: Define an enumeration for accessing env->regwptr
8da1545 tests/tcg/multiarch/linux-test: Fix error check for shmat
29f529a scripts/qemu-binfmt-conf: Update for sparc64
ccdaa08 linux-user: Support for NETLINK socket options

=== OUTPUT BEGIN ===
1/13 Checking commit ccdaa088dec3 (linux-user: Support for NETLINK socket options)
2/13 Checking commit 29f529a599f1 (scripts/qemu-binfmt-conf: Update for sparc64)
WARNING: line over 80 characters
#36: FILE: scripts/qemu-binfmt-conf.sh:41:
+sparc64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2b'

ERROR: line over 90 characters
#37: FILE: scripts/qemu-binfmt-conf.sh:42:
+sparc64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'

total: 1 errors, 1 warnings, 20 lines checked

Patch 2/13 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

3/13 Checking commit 8da15455f6f6 (tests/tcg/multiarch/linux-test: Fix error check for shmat)
4/13 Checking commit 084e4ce785d7 (target/sparc: Define an enumeration for accessing env->regwptr)
5/13 Checking commit 41f1345f4116 (linux-user/sparc: Use WREG constants in sparc/target_cpu.h)
6/13 Checking commit 54f43cd1635a (linux-user/sparc: Begin using WREG constants in sparc/signal.c)
7/13 Checking commit 39220db616ca (linux-user/sparc: Use WREG_SP constant in sparc/signal.c)
8/13 Checking commit 0a9f44c7244a (linux-user/sparc: Fix WREG usage in setup_frame)
9/13 Checking commit e331e5c5689d (linux-user/sparc64: Fix target_signal_frame)
10/13 Checking commit e1168157fac4 (linux-user: Rename cpu_clone_regs to cpu_clone_regs_child)
11/13 Checking commit 205ab4e6001d (linux-user: Introduce cpu_clone_regs_parent)
12/13 Checking commit 752ee6ec2302 (linux-user/sparc: Fix cpu_clone_regs_*)
13/13 Checking commit 66eeef8f89f7 (linux-user/alpha: Set r20 secondary return value)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20191106130456.6176-1-laurent@vivier.eu/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

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

* Re: [PULL v2 00/13] Linux user for 4.2 patches
  2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
                   ` (13 preceding siblings ...)
  2019-11-06 19:10 ` [PULL v2 00/13] Linux user for 4.2 patches no-reply
@ 2019-11-06 22:04 ` Peter Maydell
  14 siblings, 0 replies; 18+ messages in thread
From: Peter Maydell @ 2019-11-06 22:04 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: Alex Bennée, Riku Voipio, Mark Cave-Ayland, QEMU Developers,
	Artyom Tarasenko

On Wed, 6 Nov 2019 at 13:09, Laurent Vivier <laurent@vivier.eu> wrote:
>
> The following changes since commit 36609b4fa36f0ac934874371874416f7533a5408:
>
>   Merge remote-tracking branch 'remotes/palmer/tags/palmer-for-master-4.2-sf1' into staging (2019-11-02 17:59:03 +0000)
>
> are available in the Git repository at:
>
>   git://github.com/vivier/qemu.git tags/linux-user-for-4.2-pull-request
>
> for you to fetch changes up to 5849dfe410b3fefec7d54a536cda7ccbf809ebea:
>
>   linux-user/alpha: Set r20 secondary return value (2019-11-06 13:45:05 +0100)
>
> ----------------------------------------------------------------
> sparc/sparc64 fixes: this doesn't fix debian chroot for me
> but they are a step in the good direction.
> Fix Netlink support.
> Trivial fix for alpha
>
> PULL v2: fix checkpatch warnings
>
> ----------------------------------------------------------------
>


Applied, thanks.

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

-- PMM


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

* Re: [PULL v2 01/13] linux-user: Support for NETLINK socket options
  2019-11-06 13:04 ` [PULL v2 01/13] linux-user: Support for NETLINK socket options Laurent Vivier
@ 2019-11-12 10:11   ` Peter Maydell
  2019-11-12 10:30     ` Laurent Vivier
  0 siblings, 1 reply; 18+ messages in thread
From: Peter Maydell @ 2019-11-12 10:11 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: Riku Voipio, Mark Cave-Ayland, QEMU Developers, Josh Kunz,
	Alex Bennée, Artyom Tarasenko

On Wed, 6 Nov 2019 at 13:07, Laurent Vivier <laurent@vivier.eu> wrote:
>
> From: Josh Kunz <jkz@google.com>
>
> This change includes support for all AF_NETLINK socket options up to about
> kernel version 5.4 (5.4 is not formally released at the time of writing).
> Socket options that were introduced in kernel versions before the oldest
> currently stable kernel version are guarded by kernel version macros.
>
> This change has been built under gcc 8.3, and clang 9.0, and it passes
> `make check`. The netlink options have been tested by emulating some
> non-trival software that uses NETLINK socket options, but they have
> not been exaustively verified.

Hi; Coverity reports a missing-break-in-switch error for
this commit (CID 1407221):

> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index f6751eecb78c..247883292ce5 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -2248,6 +2248,39 @@ set_timeout:
>              return -TARGET_EFAULT;
>         ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, sizeof(val)));
>          break;
> +#ifdef SOL_NETLINK
> +    case SOL_NETLINK:
> +        switch (optname) {
> +        case NETLINK_PKTINFO:
> +        case NETLINK_ADD_MEMBERSHIP:
> +        case NETLINK_DROP_MEMBERSHIP:
> +        case NETLINK_BROADCAST_ERROR:
> +        case NETLINK_NO_ENOBUFS:
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
> +        case NETLINK_LISTEN_ALL_NSID:
> +        case NETLINK_CAP_ACK:
> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) */
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
> +        case NETLINK_EXT_ACK:
> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)
> +        case NETLINK_GET_STRICT_CHK:
> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
> +            break;
> +        default:
> +            goto unimplemented;
> +        }
> +        val = 0;
> +        if (optlen < sizeof(uint32_t)) {
> +            return -TARGET_EINVAL;
> +        }
> +        if (get_user_u32(val, optval_addr)) {
> +            return -TARGET_EFAULT;
> +        }
> +        ret = get_errno(setsockopt(sockfd, SOL_NETLINK, optname, &val,
> +                                   sizeof(val)));
> +        break;
> +#endif /* SOL_NETLINK */
>      default:
>      unimplemented:
>          gemu_log("Unsupported setsockopt level=%d optname=%d\n", level, optname);
> @@ -2532,6 +2565,74 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
>              break;
>          }
>          break;
> +#ifdef SOL_NETLINK
> +    case SOL_NETLINK:
> +        switch (optname) {
> +        case NETLINK_PKTINFO:
> +        case NETLINK_BROADCAST_ERROR:
> +        case NETLINK_NO_ENOBUFS:
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
> +        case NETLINK_LISTEN_ALL_NSID:
> +        case NETLINK_CAP_ACK:
> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) */
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
> +        case NETLINK_EXT_ACK:
> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)
> +        case NETLINK_GET_STRICT_CHK:
> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
> +            if (get_user_u32(len, optlen)) {
> +                return -TARGET_EFAULT;
> +            }
> +            if (len != sizeof(val)) {
> +                return -TARGET_EINVAL;
> +            }
> +            lv = len;
> +            ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
> +            if (ret < 0) {
> +                return ret;
> +            }
> +            if (put_user_u32(lv, optlen)
> +                || put_user_u32(val, optval_addr)) {
> +                return -TARGET_EFAULT;
> +            }
> +            break;
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
> +        case NETLINK_LIST_MEMBERSHIPS:
> +        {
> +            uint32_t *results;
> +            int i;
> +            if (get_user_u32(len, optlen)) {
> +                return -TARGET_EFAULT;
> +            }
> +            if (len < 0) {
> +                return -TARGET_EINVAL;
> +            }
> +            results = lock_user(VERIFY_WRITE, optval_addr, len, 1);
> +            if (!results) {
> +                return -TARGET_EFAULT;
> +            }
> +            lv = len;
> +            ret = get_errno(getsockopt(sockfd, level, optname, results, &lv));
> +            if (ret < 0) {
> +                unlock_user(results, optval_addr, 0);
> +                return ret;
> +            }
> +            /* swap host endianess to target endianess. */
> +            for (i = 0; i < (len / sizeof(uint32_t)); i++) {
> +                results[i] = tswap32(results[i]);
> +            }
> +            if (put_user_u32(lv, optlen)) {
> +                return -TARGET_EFAULT;
> +            }
> +            unlock_user(results, optval_addr, 0);
> +            break;
> +        }
> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) */
> +        default:
> +            goto unimplemented;
> +        }
> +#endif /* SOL_NETLINK */

Here at the end of the 'case SOL_NETLINK' we will just
fall straight through into 'default:'. Missing 'break' ?

>      default:
>      unimplemented:
>          gemu_log("getsockopt level=%d optname=%d not yet supported\n",
> --
> 2.21.0

thanks
-- PMM


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

* Re: [PULL v2 01/13] linux-user: Support for NETLINK socket options
  2019-11-12 10:11   ` Peter Maydell
@ 2019-11-12 10:30     ` Laurent Vivier
  0 siblings, 0 replies; 18+ messages in thread
From: Laurent Vivier @ 2019-11-12 10:30 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Riku Voipio, Mark Cave-Ayland, QEMU Developers, Josh Kunz,
	Alex Bennée, Artyom Tarasenko

Le 12/11/2019 à 11:11, Peter Maydell a écrit :
> On Wed, 6 Nov 2019 at 13:07, Laurent Vivier <laurent@vivier.eu> wrote:
>>
>> From: Josh Kunz <jkz@google.com>
>>
>> This change includes support for all AF_NETLINK socket options up to about
>> kernel version 5.4 (5.4 is not formally released at the time of writing).
>> Socket options that were introduced in kernel versions before the oldest
>> currently stable kernel version are guarded by kernel version macros.
>>
>> This change has been built under gcc 8.3, and clang 9.0, and it passes
>> `make check`. The netlink options have been tested by emulating some
>> non-trival software that uses NETLINK socket options, but they have
>> not been exaustively verified.
> 
> Hi; Coverity reports a missing-break-in-switch error for
> this commit (CID 1407221):
> 
>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>> index f6751eecb78c..247883292ce5 100644
>> --- a/linux-user/syscall.c
>> +++ b/linux-user/syscall.c
>> @@ -2248,6 +2248,39 @@ set_timeout:
>>              return -TARGET_EFAULT;
>>         ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, sizeof(val)));
>>          break;
>> +#ifdef SOL_NETLINK
>> +    case SOL_NETLINK:
>> +        switch (optname) {
>> +        case NETLINK_PKTINFO:
>> +        case NETLINK_ADD_MEMBERSHIP:
>> +        case NETLINK_DROP_MEMBERSHIP:
>> +        case NETLINK_BROADCAST_ERROR:
>> +        case NETLINK_NO_ENOBUFS:
>> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
>> +        case NETLINK_LISTEN_ALL_NSID:
>> +        case NETLINK_CAP_ACK:
>> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) */
>> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
>> +        case NETLINK_EXT_ACK:
>> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
>> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)
>> +        case NETLINK_GET_STRICT_CHK:
>> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
>> +            break;
>> +        default:
>> +            goto unimplemented;
>> +        }
>> +        val = 0;
>> +        if (optlen < sizeof(uint32_t)) {
>> +            return -TARGET_EINVAL;
>> +        }
>> +        if (get_user_u32(val, optval_addr)) {
>> +            return -TARGET_EFAULT;
>> +        }
>> +        ret = get_errno(setsockopt(sockfd, SOL_NETLINK, optname, &val,
>> +                                   sizeof(val)));
>> +        break;
>> +#endif /* SOL_NETLINK */
>>      default:
>>      unimplemented:
>>          gemu_log("Unsupported setsockopt level=%d optname=%d\n", level, optname);
>> @@ -2532,6 +2565,74 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
>>              break;
>>          }
>>          break;
>> +#ifdef SOL_NETLINK
>> +    case SOL_NETLINK:
>> +        switch (optname) {
>> +        case NETLINK_PKTINFO:
>> +        case NETLINK_BROADCAST_ERROR:
>> +        case NETLINK_NO_ENOBUFS:
>> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
>> +        case NETLINK_LISTEN_ALL_NSID:
>> +        case NETLINK_CAP_ACK:
>> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) */
>> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
>> +        case NETLINK_EXT_ACK:
>> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
>> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)
>> +        case NETLINK_GET_STRICT_CHK:
>> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) */
>> +            if (get_user_u32(len, optlen)) {
>> +                return -TARGET_EFAULT;
>> +            }
>> +            if (len != sizeof(val)) {
>> +                return -TARGET_EINVAL;
>> +            }
>> +            lv = len;
>> +            ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
>> +            if (ret < 0) {
>> +                return ret;
>> +            }
>> +            if (put_user_u32(lv, optlen)
>> +                || put_user_u32(val, optval_addr)) {
>> +                return -TARGET_EFAULT;
>> +            }
>> +            break;
>> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
>> +        case NETLINK_LIST_MEMBERSHIPS:
>> +        {
>> +            uint32_t *results;
>> +            int i;
>> +            if (get_user_u32(len, optlen)) {
>> +                return -TARGET_EFAULT;
>> +            }
>> +            if (len < 0) {
>> +                return -TARGET_EINVAL;
>> +            }
>> +            results = lock_user(VERIFY_WRITE, optval_addr, len, 1);
>> +            if (!results) {
>> +                return -TARGET_EFAULT;
>> +            }
>> +            lv = len;
>> +            ret = get_errno(getsockopt(sockfd, level, optname, results, &lv));
>> +            if (ret < 0) {
>> +                unlock_user(results, optval_addr, 0);
>> +                return ret;
>> +            }
>> +            /* swap host endianess to target endianess. */
>> +            for (i = 0; i < (len / sizeof(uint32_t)); i++) {
>> +                results[i] = tswap32(results[i]);
>> +            }
>> +            if (put_user_u32(lv, optlen)) {
>> +                return -TARGET_EFAULT;
>> +            }
>> +            unlock_user(results, optval_addr, 0);
>> +            break;
>> +        }
>> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) */
>> +        default:
>> +            goto unimplemented;
>> +        }
>> +#endif /* SOL_NETLINK */
> 
> Here at the end of the 'case SOL_NETLINK' we will just
> fall straight through into 'default:'. Missing 'break' ?

Yes, missing 'break'.

I'm going to send a patch to fix that.

Thanks,
Laurent


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

end of thread, other threads:[~2019-11-12 10:31 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-06 13:04 [PULL v2 00/13] Linux user for 4.2 patches Laurent Vivier
2019-11-06 13:04 ` [PULL v2 01/13] linux-user: Support for NETLINK socket options Laurent Vivier
2019-11-12 10:11   ` Peter Maydell
2019-11-12 10:30     ` Laurent Vivier
2019-11-06 13:04 ` [PULL v2 02/13] scripts/qemu-binfmt-conf: Update for sparc64 Laurent Vivier
2019-11-06 13:04 ` [PULL v2 03/13] tests/tcg/multiarch/linux-test: Fix error check for shmat Laurent Vivier
2019-11-06 13:04 ` [PULL v2 04/13] target/sparc: Define an enumeration for accessing env->regwptr Laurent Vivier
2019-11-06 13:04 ` [PULL v2 05/13] linux-user/sparc: Use WREG constants in sparc/target_cpu.h Laurent Vivier
2019-11-06 13:04 ` [PULL v2 06/13] linux-user/sparc: Begin using WREG constants in sparc/signal.c Laurent Vivier
2019-11-06 13:04 ` [PULL v2 07/13] linux-user/sparc: Use WREG_SP constant " Laurent Vivier
2019-11-06 13:04 ` [PULL v2 08/13] linux-user/sparc: Fix WREG usage in setup_frame Laurent Vivier
2019-11-06 13:04 ` [PULL v2 09/13] linux-user/sparc64: Fix target_signal_frame Laurent Vivier
2019-11-06 13:04 ` [PULL v2 10/13] linux-user: Rename cpu_clone_regs to cpu_clone_regs_child Laurent Vivier
2019-11-06 13:04 ` [PULL v2 11/13] linux-user: Introduce cpu_clone_regs_parent Laurent Vivier
2019-11-06 13:04 ` [PULL v2 12/13] linux-user/sparc: Fix cpu_clone_regs_* Laurent Vivier
2019-11-06 13:04 ` [PULL v2 13/13] linux-user/alpha: Set r20 secondary return value Laurent Vivier
2019-11-06 19:10 ` [PULL v2 00/13] Linux user for 4.2 patches no-reply
2019-11-06 22:04 ` Peter Maydell

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