All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/3] microblaze patch queue
@ 2020-10-15  4:52 Richard Henderson
  2020-10-15  4:52 ` [PULL 1/3] tests/tcg/linux-test: Adjust getsockname for musl Richard Henderson
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Richard Henderson @ 2020-10-15  4:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell

The following changes since commit 57c98ea9acdcef5021f5671efa6475a5794a51c4:

  Merge remote-tracking branch 'remotes/kraxel/tags/ui-20201014-pull-request' into staging (2020-10-14 13:56:06 +0100)

are available in the Git repository at:

  https://github.com/rth7680/qemu.git tags/pull-mb-20201014

for you to fetch changes up to 49e258df83e2200847cd4b331f48d8d872fba51c:

  linux-user/microblaze: Remove non-rt signal frames (2020-10-14 21:19:56 -0700)

----------------------------------------------------------------
Implement rt signal frames for microblaze-linux-user
Adjust linux-user test for musl

----------------------------------------------------------------
Richard Henderson (3):
      tests/tcg/linux-test: Adjust getsockname for musl
      linux-user/microblaze: Implement rt signal frames
      linux-user/microblaze: Remove non-rt signal frames

 linux-user/microblaze/target_signal.h |   1 -
 linux-user/microblaze/signal.c        | 186 +++++++++++++++-------------------
 tests/tcg/multiarch/linux-test.c      |   2 +-
 3 files changed, 84 insertions(+), 105 deletions(-)


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

* [PULL 1/3] tests/tcg/linux-test: Adjust getsockname for musl
  2020-10-15  4:52 [PULL 0/3] microblaze patch queue Richard Henderson
@ 2020-10-15  4:52 ` Richard Henderson
  2020-10-15  4:52 ` [PULL 2/3] linux-user/microblaze: Implement rt signal frames Richard Henderson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2020-10-15  4:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Philippe Mathieu-Daudé

Unlike glibc, musl does not use transparent unions to hide
the different structures that overlap struct sockaddr.

Add an explicit cast to work around this.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tests/tcg/multiarch/linux-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
index 8a7c15cd31..96bbad5823 100644
--- a/tests/tcg/multiarch/linux-test.c
+++ b/tests/tcg/multiarch/linux-test.c
@@ -296,7 +296,7 @@ static void test_socket(void)
     server_fd = server_socket();
     /* find out what port we got */
     socklen = sizeof(server_addr);
-    ret = getsockname(server_fd, &server_addr, &socklen);
+    ret = getsockname(server_fd, (struct sockaddr *)&server_addr, &socklen);
     chk_error(ret);
     server_port = ntohs(server_addr.sin_port);
 
-- 
2.25.1



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

* [PULL 2/3] linux-user/microblaze: Implement rt signal frames
  2020-10-15  4:52 [PULL 0/3] microblaze patch queue Richard Henderson
  2020-10-15  4:52 ` [PULL 1/3] tests/tcg/linux-test: Adjust getsockname for musl Richard Henderson
@ 2020-10-15  4:52 ` Richard Henderson
  2020-10-15  4:52 ` [PULL 3/3] linux-user/microblaze: Remove non-rt " Richard Henderson
  2020-10-15 21:20 ` [PULL 0/3] microblaze patch queue Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2020-10-15  4:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Edgar E . Iglesias, peter.maydell

Allows microblaze to pass tests/tcg/multiarch/linux-test.c.

Tested-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/microblaze/signal.c | 91 ++++++++++++++++++++++++++++++----
 1 file changed, 82 insertions(+), 9 deletions(-)

diff --git a/linux-user/microblaze/signal.c b/linux-user/microblaze/signal.c
index b4eeef4673..3d316a22f1 100644
--- a/linux-user/microblaze/signal.c
+++ b/linux-user/microblaze/signal.c
@@ -35,9 +35,9 @@ struct target_stack_t {
 struct target_ucontext {
     abi_ulong tuc_flags;
     abi_ulong tuc_link;
-    struct target_stack_t tuc_stack;
+    target_stack_t tuc_stack;
     struct target_sigcontext tuc_mcontext;
-    uint32_t tuc_extramask[TARGET_NSIG_WORDS - 1];
+    target_sigset_t tuc_sigmask;
 };
 
 /* Signal frames. */
@@ -47,9 +47,9 @@ struct target_signal_frame {
     uint32_t tramp[2];
 };
 
-struct rt_signal_frame {
-    siginfo_t info;
-    ucontext_t uc;
+struct target_rt_sigframe {
+    target_siginfo_t info;
+    struct target_ucontext uc;
     uint32_t tramp[2];
 };
 
@@ -200,7 +200,55 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
                     target_siginfo_t *info,
                     target_sigset_t *set, CPUMBState *env)
 {
-    qemu_log_mask(LOG_UNIMP, "setup_rt_frame: not implemented\n");
+    struct target_rt_sigframe *frame;
+    abi_ulong frame_addr;
+
+    frame_addr = get_sigframe(ka, env, sizeof *frame);
+    trace_user_setup_rt_frame(env, frame_addr);
+
+    if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {
+        force_sigsegv(sig);
+        return;
+    }
+
+    tswap_siginfo(&frame->info, info);
+
+    __put_user(0, &frame->uc.tuc_flags);
+    __put_user(0, &frame->uc.tuc_link);
+
+    target_save_altstack(&frame->uc.tuc_stack, env);
+    setup_sigcontext(&frame->uc.tuc_mcontext, env);
+
+    for (int i = 0; i < TARGET_NSIG_WORDS; i++) {
+        __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
+    }
+
+    /* Kernel does not use SA_RESTORER. */
+
+    /* addi r12, r0, __NR_sigreturn */
+    __put_user(0x31800000U | TARGET_NR_rt_sigreturn, frame->tramp + 0);
+    /* brki r14, 0x8 */
+    __put_user(0xb9cc0008U, frame->tramp + 1);
+
+    /*
+     * Return from sighandler will jump to the tramp.
+     * Negative 8 offset because return is rtsd r15, 8
+     */
+    env->regs[15] =
+        frame_addr + offsetof(struct target_rt_sigframe, tramp) - 8;
+
+    /* Set up registers for signal handler */
+    env->regs[1] = frame_addr;
+
+    /* Signal handler args: */
+    env->regs[5] = sig;
+    env->regs[6] = frame_addr + offsetof(struct target_rt_sigframe, info);
+    env->regs[7] = frame_addr + offsetof(struct target_rt_sigframe, uc);
+
+    /* Offset to handle microblaze rtid r14, 0 */
+    env->pc = (unsigned long)ka->_sa_handler;
+
+    unlock_user_struct(frame, frame_addr, 1);
 }
 
 long do_sigreturn(CPUMBState *env)
@@ -239,7 +287,32 @@ badframe:
 
 long do_rt_sigreturn(CPUMBState *env)
 {
-    trace_user_do_rt_sigreturn(env, 0);
-    qemu_log_mask(LOG_UNIMP, "do_rt_sigreturn: not implemented\n");
-    return -TARGET_ENOSYS;
+    struct target_rt_sigframe *frame = NULL;
+    abi_ulong frame_addr = env->regs[1];
+    sigset_t set;
+
+    trace_user_do_rt_sigreturn(env, frame_addr);
+
+    if  (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) {
+        goto badframe;
+    }
+
+    target_to_host_sigset(&set, &frame->uc.tuc_sigmask);
+    set_sigmask(&set);
+
+    restore_sigcontext(&frame->uc.tuc_mcontext, env);
+
+    if (do_sigaltstack(frame_addr +
+                       offsetof(struct target_rt_sigframe, uc.tuc_stack),
+                       0, get_sp_from_cpustate(env)) == -EFAULT) {
+        goto badframe;
+    }
+
+    unlock_user_struct(frame, frame_addr, 0);
+    return -TARGET_QEMU_ESIGRETURN;
+
+ badframe:
+    unlock_user_struct(frame, frame_addr, 0);
+    force_sig(TARGET_SIGSEGV);
+    return -TARGET_QEMU_ESIGRETURN;
 }
-- 
2.25.1



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

* [PULL 3/3] linux-user/microblaze: Remove non-rt signal frames
  2020-10-15  4:52 [PULL 0/3] microblaze patch queue Richard Henderson
  2020-10-15  4:52 ` [PULL 1/3] tests/tcg/linux-test: Adjust getsockname for musl Richard Henderson
  2020-10-15  4:52 ` [PULL 2/3] linux-user/microblaze: Implement rt signal frames Richard Henderson
@ 2020-10-15  4:52 ` Richard Henderson
  2020-10-15 21:20 ` [PULL 0/3] microblaze patch queue Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2020-10-15  4:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Edgar E . Iglesias, peter.maydell

The microblaze kernel does not support these, and uses
only rt style signal frames.

Tested-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/microblaze/target_signal.h |  1 -
 linux-user/microblaze/signal.c        | 97 +--------------------------
 2 files changed, 2 insertions(+), 96 deletions(-)

diff --git a/linux-user/microblaze/target_signal.h b/linux-user/microblaze/target_signal.h
index 35efd5e928..08bcf24b9d 100644
--- a/linux-user/microblaze/target_signal.h
+++ b/linux-user/microblaze/target_signal.h
@@ -21,5 +21,4 @@ typedef struct target_sigaltstack {
 
 #include "../generic/signal.h"
 
-#define TARGET_ARCH_HAS_SETUP_FRAME
 #endif /* MICROBLAZE_TARGET_SIGNAL_H */
diff --git a/linux-user/microblaze/signal.c b/linux-user/microblaze/signal.c
index 3d316a22f1..cf0707b556 100644
--- a/linux-user/microblaze/signal.c
+++ b/linux-user/microblaze/signal.c
@@ -41,12 +41,6 @@ struct target_ucontext {
 };
 
 /* Signal frames. */
-struct target_signal_frame {
-    struct target_ucontext uc;
-    uint32_t extramask[TARGET_NSIG_WORDS - 1];
-    uint32_t tramp[2];
-};
-
 struct target_rt_sigframe {
     target_siginfo_t info;
     struct target_ucontext uc;
@@ -137,65 +131,6 @@ static abi_ulong get_sigframe(struct target_sigaction *ka,
     return ((sp - frame_size) & -8UL);
 }
 
-void setup_frame(int sig, struct target_sigaction *ka,
-                 target_sigset_t *set, CPUMBState *env)
-{
-    struct target_signal_frame *frame;
-    abi_ulong frame_addr;
-    int i;
-
-    frame_addr = get_sigframe(ka, env, sizeof *frame);
-    trace_user_setup_frame(env, frame_addr);
-    if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0))
-        goto badframe;
-
-    /* Save the mask.  */
-    __put_user(set->sig[0], &frame->uc.tuc_mcontext.oldmask);
-
-    for(i = 1; i < TARGET_NSIG_WORDS; i++) {
-        __put_user(set->sig[i], &frame->extramask[i - 1]);
-    }
-
-    setup_sigcontext(&frame->uc.tuc_mcontext, env);
-
-    /* Set up to return from userspace. If provided, use a stub
-       already in userspace. */
-    /* minus 8 is offset to cater for "rtsd r15,8" offset */
-    if (ka->sa_flags & TARGET_SA_RESTORER) {
-        env->regs[15] = ((unsigned long)ka->sa_restorer)-8;
-    } else {
-        uint32_t t;
-        /* Note, these encodings are _big endian_! */
-        /* addi r12, r0, __NR_sigreturn */
-        t = 0x31800000UL | TARGET_NR_sigreturn;
-        __put_user(t, frame->tramp + 0);
-        /* brki r14, 0x8 */
-        t = 0xb9cc0008UL;
-        __put_user(t, frame->tramp + 1);
-
-        /* Return from sighandler will jump to the tramp.
-           Negative 8 offset because return is rtsd r15, 8 */
-        env->regs[15] = frame_addr + offsetof(struct target_signal_frame, tramp)
-                                   - 8;
-    }
-
-    /* Set up registers for signal handler */
-    env->regs[1] = frame_addr;
-    /* Signal handler args: */
-    env->regs[5] = sig; /* Arg 0: signum */
-    env->regs[6] = 0;
-    /* arg 1: sigcontext */
-    env->regs[7] = frame_addr += offsetof(typeof(*frame), uc);
-
-    /* Offset of 4 to handle microblaze rtid r14, 0 */
-    env->pc = (unsigned long)ka->_sa_handler;
-
-    unlock_user_struct(frame, frame_addr, 1);
-    return;
-badframe:
-    force_sigsegv(sig);
-}
-
 void setup_rt_frame(int sig, struct target_sigaction *ka,
                     target_siginfo_t *info,
                     target_sigset_t *set, CPUMBState *env)
@@ -251,38 +186,10 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     unlock_user_struct(frame, frame_addr, 1);
 }
 
+
 long do_sigreturn(CPUMBState *env)
 {
-    struct target_signal_frame *frame;
-    abi_ulong frame_addr;
-    target_sigset_t target_set;
-    sigset_t set;
-    int i;
-
-    frame_addr = env->regs[R_SP];
-    trace_user_do_sigreturn(env, frame_addr);
-    /* Make sure the guest isn't playing games.  */
-    if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 1))
-        goto badframe;
-
-    /* Restore blocked signals */
-    __get_user(target_set.sig[0], &frame->uc.tuc_mcontext.oldmask);
-    for(i = 1; i < TARGET_NSIG_WORDS; i++) {
-        __get_user(target_set.sig[i], &frame->extramask[i - 1]);
-    }
-    target_to_host_sigset_internal(&set, &target_set);
-    set_sigmask(&set);
-
-    restore_sigcontext(&frame->uc.tuc_mcontext, env);
-    /* We got here through a sigreturn syscall, our path back is via an
-       rtb insn so setup r14 for that.  */
-    env->regs[14] = env->pc;
-
-    unlock_user_struct(frame, frame_addr, 0);
-    return -TARGET_QEMU_ESIGRETURN;
-badframe:
-    force_sig(TARGET_SIGSEGV);
-    return -TARGET_QEMU_ESIGRETURN;
+    return -TARGET_ENOSYS;
 }
 
 long do_rt_sigreturn(CPUMBState *env)
-- 
2.25.1



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

* Re: [PULL 0/3] microblaze patch queue
  2020-10-15  4:52 [PULL 0/3] microblaze patch queue Richard Henderson
                   ` (2 preceding siblings ...)
  2020-10-15  4:52 ` [PULL 3/3] linux-user/microblaze: Remove non-rt " Richard Henderson
@ 2020-10-15 21:20 ` Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2020-10-15 21:20 UTC (permalink / raw)
  To: Richard Henderson; +Cc: QEMU Developers

On Thu, 15 Oct 2020 at 05:52, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> The following changes since commit 57c98ea9acdcef5021f5671efa6475a5794a51c4:
>
>   Merge remote-tracking branch 'remotes/kraxel/tags/ui-20201014-pull-request' into staging (2020-10-14 13:56:06 +0100)
>
> are available in the Git repository at:
>
>   https://github.com/rth7680/qemu.git tags/pull-mb-20201014
>
> for you to fetch changes up to 49e258df83e2200847cd4b331f48d8d872fba51c:
>
>   linux-user/microblaze: Remove non-rt signal frames (2020-10-14 21:19:56 -0700)
>
> ----------------------------------------------------------------
> Implement rt signal frames for microblaze-linux-user
> Adjust linux-user test for musl
>
> ----------------------------------------------------------------


Applied, thanks.

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

-- PMM


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

end of thread, other threads:[~2020-10-15 21:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15  4:52 [PULL 0/3] microblaze patch queue Richard Henderson
2020-10-15  4:52 ` [PULL 1/3] tests/tcg/linux-test: Adjust getsockname for musl Richard Henderson
2020-10-15  4:52 ` [PULL 2/3] linux-user/microblaze: Implement rt signal frames Richard Henderson
2020-10-15  4:52 ` [PULL 3/3] linux-user/microblaze: Remove non-rt " Richard Henderson
2020-10-15 21:20 ` [PULL 0/3] microblaze patch queue Peter Maydell

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