Skip to contentSkip to conversation

linux-user openrisc fixes

PATCH In review Richard Henderson 2 participants 8 messages May 31, 2018 – Jun 1, 2018

lore
Share & tools
lore
#0 lore raw

cover linux-user openrisc fixes

Both of these fixes are required to fix g++ unwinding tests.

r~

Richard Henderson (2):
linux-user: Implement signals for openrisc
linux-user: Fix struct sigaltstack for openrisc

 linux-user/openrisc/target_signal.h  |   2 +-
 linux-user/openrisc/target_syscall.h |  23 +--
 linux-user/openrisc/signal.c         | 210 +++++++++++----------------
 linux-user/signal.c                  |   2 +-
 target/openrisc/cpu.c                |   1 +
 5 files changed, 88 insertions(+), 150 deletions(-)
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/2 linux-user: Implement signals for openrisc

All of the existing code was boilerplate from elsewhere, and would crash the guest upon the first signal.

---
 linux-user/openrisc/target_syscall.h |  23 +--
 linux-user/openrisc/signal.c         | 210 +++++++++++----------------
 linux-user/signal.c                  |   2 +-
 target/openrisc/cpu.c                |   1 +
 4 files changed, 87 insertions(+), 149 deletions(-)
linux-user/openrisc/target_syscall.h +3 -20
index 03104f80af..f21fab3192 100644
@@ -2,26 +2,9 @@
 #define OPENRISC_TARGET_SYSCALL_H
 
 struct target_pt_regs {
-    union {
-        struct {
-            /* Named registers */
-            uint32_t sr;       /* Stored in place of r0 */
-            target_ulong sp;   /* r1 */
-        };
-        struct {
-            /* Old style */
-            target_ulong offset[2];
-            target_ulong gprs[30];
-        };
-        struct {
-            /* New style */
-            target_ulong gpr[32];
-        };
-    };
-    target_ulong pc;
-    target_ulong orig_gpr11;   /* For restarting system calls */
-    uint32_t syscallno;        /* Syscall number (used by strace) */
-    target_ulong dummy;     /* Cheap alignment fix */
+    abi_ulong gpr[32];
+    abi_ulong pc;
+    abi_ulong sr;
 };
 
 #define UNAME_MACHINE "openrisc"
linux-user/openrisc/signal.c +82 -128

281 lines not on this page · raw message

linux-user/signal.c +1 -1
index 01de433e3a..a8d1f7a284 100644
@@ -237,7 +237,7 @@ int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
     return 0;
 }
 
-#if !defined(TARGET_OPENRISC) && !defined(TARGET_NIOS2)
+#if !defined(TARGET_NIOS2)
 /* Just set the guest's signal mask to the specified value; the
  * caller is assumed to have called block_signals() already.
  */
target/openrisc/cpu.c +1 -0
index d1ef4c737c..7648a74636 100644
@@ -28,6 +28,7 @@ static void openrisc_cpu_set_pc(CPUState *cs, vaddr value)
     OpenRISCCPU *cpu = OPENRISC_CPU(cs);
 
     cpu->env.pc = value;
+    cpu->env.dflag = 0;
 }
 
 static bool openrisc_cpu_has_work(CPUState *cs)
Signature · 1 line
2.17.0
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] linux-user: Implement signals for openrisc

Le 31/05/2018 à 06:18, Richard Henderson a écrit :

Quoted 44 lines

All of the existing code was boilerplate from elsewhere, and would crash the guest upon the first signal.

---
 linux-user/openrisc/target_syscall.h |  23 +--
 linux-user/openrisc/signal.c         | 210 +++++++++++----------------
 linux-user/signal.c                  |   2 +-
 target/openrisc/cpu.c                |   1 +
 4 files changed, 87 insertions(+), 149 deletions(-)
linux-user/openrisc/target_syscall.h +3 -20
index 03104f80af..f21fab3192 100644
@@ -2,26 +2,9 @@
 #define OPENRISC_TARGET_SYSCALL_H
 
 struct target_pt_regs {
-    union {
-        struct {
-            /* Named registers */
-            uint32_t sr;       /* Stored in place of r0 */
-            target_ulong sp;   /* r1 */
-        };
-        struct {
-            /* Old style */
-            target_ulong offset[2];
-            target_ulong gprs[30];
-        };
-        struct {
-            /* New style */
-            target_ulong gpr[32];
-        };
-    };
-    target_ulong pc;
-    target_ulong orig_gpr11;   /* For restarting system calls */
-    uint32_t syscallno;        /* Syscall number (used by strace) */
-    target_ulong dummy;     /* Cheap alignment fix */
+    abi_ulong gpr[32];
+    abi_ulong pc;
+    abi_ulong sr;
 };
 
Quoted 1 line

From where is this coming from?

In linux/arch/openrisc/include/asm/ptrace.h, we have the definition you remove.

Thanks,
Laurent

#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] linux-user: Implement signals for openrisc

Quoted 47 lines · Laurent Vivier

Le 31/05/2018 à 06:18, Richard Henderson a écrit :

Quoted 33 lines

All of the existing code was boilerplate from elsewhere, and would crash the guest upon the first signal.

---
 linux-user/openrisc/target_syscall.h |  23 +--
 linux-user/openrisc/signal.c         | 210 +++++++++++----------------
 linux-user/signal.c                  |   2 +-
 target/openrisc/cpu.c                |   1 +
 4 files changed, 87 insertions(+), 149 deletions(-)
linux-user/openrisc/target_syscall.h +0 -14
index 03104f80af..f21fab3192 100644
@@ -2,26 +2,9 @@
 #define OPENRISC_TARGET_SYSCALL_H
 
 struct target_pt_regs {
-    union {
-        struct {
-            /* Named registers */
-            uint32_t sr;       /* Stored in place of r0 */
-            target_ulong sp;   /* r1 */
-        };
-        struct {
-            /* Old style */
-            target_ulong offset[2];
-            target_ulong gprs[30];
-        };
-        struct {
-            /* New style */
-            target_ulong gpr[32];

linux-user/openrisc/target_syscall.h line 8

Quoted 10 lines
linux-user/openrisc/target_syscall.h +3 -6
-        };
-    };
-    target_ulong pc;
-    target_ulong orig_gpr11;   /* For restarting system calls */
-    uint32_t syscallno;        /* Syscall number (used by strace) */
-    target_ulong dummy;     /* Cheap alignment fix */
+    abi_ulong gpr[32];
+    abi_ulong pc;
+    abi_ulong sr;
 };

From where is this coming from?

Quoted 2 lines

In linux/arch/openrisc/include/asm/ptrace.h, we have the definition you remove.

I'm using the one from .../include/uapi/asm/ptrace.h.
I now see that they have two different names -- this one is struct user_regs_struct -- but this is also what is used by sigcontext.

I should fix the names too to avoid confusion.

r~

#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] linux-user: Implement signals for openrisc

In reply to Richard Henderson

Le 31/05/2018 à 06:18, Richard Henderson a écrit :

Quoted 11 lines

All of the existing code was boilerplate from elsewhere, and would crash the guest upon the first signal.

---
 linux-user/openrisc/target_syscall.h |  23 +--
 linux-user/openrisc/signal.c         | 210 +++++++++++----------------
 linux-user/signal.c                  |   2 +-
 target/openrisc/cpu.c                |   1 +
 4 files changed, 87 insertions(+), 149 deletions(-)

...

Quoted 4 lines
linux-user/openrisc/signal.c +0 -0
@@ -148,11 +102,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
                     target_siginfo_t *info,
                     target_sigset_t *set, CPUOpenRISCState *env)
 {

...

linux-user/openrisc/signal.c void setup_rt_frame(int sig, struct target_sigaction *ka, · line 170

Quoted 13 lines
linux-user/openrisc/signal.c +1 -7
@@ -160,47 +111,32 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
         goto give_sigsegv;
     }
 
-    info_addr = frame_addr + offsetof(struct target_rt_sigframe, info);
-    __put_user(info_addr, &frame->pinfo);
-    uc_addr = frame_addr + offsetof(struct target_rt_sigframe, uc);
-    __put_user(uc_addr, &frame->puc);
+    tswap_siginfo(&frame->info, info);
 
-    if (ka->sa_flags & SA_SIGINFO) {
-        tswap_siginfo(&frame->info, info);
-    }

Why do you remove the "ka->sa_flags & SA_SIGINFO"?

linux-user/openrisc/signal.c void setup_rt_frame(int sig, struct target_sigaction *ka, · line 178

Quoted 9 lines
linux-user/openrisc/signal.c +2 -3
-    /*err |= __clear_user(&frame->uc, offsetof(ucontext_t, uc_mcontext));*/
     __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->sc, env, set->sig[0]);
+    setup_sigcontext(&frame->uc.tuc_mcontext, env);
 
-    /*err |= copy_to_user(frame->uc.tuc_sigmask, set, sizeof(*set));*/

other targets have something like:

    for (i = 0; i < TARGET_NSIG_WORDS; i++) {
        __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
    }

to match kernel

        err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));

Do we need it?

Thanks,
Laurent

#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] linux-user: Implement signals for openrisc

Quoted 28 lines · Laurent Vivier

Le 31/05/2018 à 06:18, Richard Henderson a écrit :

Quoted 11 lines

All of the existing code was boilerplate from elsewhere, and would crash the guest upon the first signal.

---
 linux-user/openrisc/target_syscall.h |  23 +--
 linux-user/openrisc/signal.c         | 210 +++++++++++----------------
 linux-user/signal.c                  |   2 +-
 target/openrisc/cpu.c                |   1 +
 4 files changed, 87 insertions(+), 149 deletions(-)

...

Quoted 4 lines
linux-user/openrisc/signal.c +0 -0
@@ -148,11 +102,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
                     target_siginfo_t *info,
                     target_sigset_t *set, CPUOpenRISCState *env)
 {

...

Quoted 10 lines
linux-user/openrisc/signal.c +1 -4
@@ -160,47 +111,32 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
         goto give_sigsegv;
     }
 
-    info_addr = frame_addr + offsetof(struct target_rt_sigframe, info);
-    __put_user(info_addr, &frame->pinfo);
-    uc_addr = frame_addr + offsetof(struct target_rt_sigframe, uc);
-    __put_user(uc_addr, &frame->puc);
+    tswap_siginfo(&frame->info, info);
 
Quoted 5 lines

linux-user/openrisc/signal.c void setup_rt_frame(int sig, struct target_sigaction *ka, · line 170

Quoted 3 lines
linux-user/openrisc/signal.c +0 -3
-    if (ka->sa_flags & SA_SIGINFO) {
-        tswap_siginfo(&frame->info, info);
-    }

Why do you remove the "ka->sa_flags & SA_SIGINFO"?

I thought it was unconditional for rt signals, which are the only ones that openrisc has. It's definitely odd, since the kernel also checks that flag, but unconditionally points r4 to the (possibly uninitialized) siginfo_t.

Quoted 8 lines

linux-user/openrisc/signal.c void setup_rt_frame(int sig, struct target_sigaction *ka, · line 178

Quoted 1 line
linux-user/openrisc/signal.c +0 -1
-    /*err |= copy_to_user(frame->uc.tuc_sigmask, set, sizeof(*set));*/

other targets have something like:

    for (i = 0; i < TARGET_NSIG_WORDS; i++) {
        __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
    }
Quoted 5 lines

to match kernel

        err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));

Do we need it?

Yes, this is my mistake.

r~

#6 lore raw

PATCH 2/2 linux-user: Fix struct sigaltstack for openrisc

In reply to Richard Henderson
---
 linux-user/openrisc/target_signal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/openrisc/target_signal.h +1 -1
index 2a4e00b035..901097972a 100644
@@ -7,8 +7,8 @@
 
 typedef struct target_sigaltstack {
     abi_long ss_sp;
+    abi_int ss_flags;
     abi_ulong ss_size;
-    abi_long ss_flags;
 } target_stack_t;
 
 /* sigaltstack controls  */
Signature · 1 line
2.17.0
Reviewed-by on v1 2/2
#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] linux-user: Fix struct sigaltstack for openrisc

Le 31/05/2018 à 06:18, Richard Henderson a écrit :

Quoted 11 lines
---
 linux-user/openrisc/target_signal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/openrisc/target_signal.h +0 -0
index 2a4e00b035..901097972a 100644

linux-user/openrisc/target_signal.h line 14

Quoted 9 lines
linux-user/openrisc/target_signal.h +1 -1
@@ -7,8 +7,8 @@
 
 typedef struct target_sigaltstack {
     abi_long ss_sp;
+    abi_int ss_flags;
     abi_ulong ss_size;
-    abi_long ss_flags;
 } target_stack_t;
 
 /* sigaltstack controls  */