linux-user: fix various SIGSEGV delivery bugs
cover linux-user: fix various SIGSEGV delivery bugs
This patchset fixes most of the problems with delivering SIGSEGV noted in https://bugs.launchpad.net/qemu/+bug/1705118:
* s390x is missing masking operations on the fault address passed to the guest in si_addr
* ppc is passing the PC of the offending insn, not the data address, into si_addr
* sparc fails to record the address of a data fault and so passes 0 into si_addr
* sparc isn't implementing rt_sigaction correctly (it has an extra 'restorer' argument, similar to alpha)
It doesn't actually get the sparc testcase from that bug working, though, because SPARC is entirely missing support for setup_rt_frame() and do_rt_sigreturn(), so it can't deliver RT signals.
Implementing RT signal delivery is too big a bugfix for an afternoon, so here are the simpler parts. I'll leave the signal delivery part to somebody who cares about SPARC guests...
thanks
-- PMM
Peter Maydell (4):
linux-user/s390x: Mask si_addr for SIGSEGV
linux-user/ppc: Report correct fault address for data faults linux-user/sparc: Put address for data faults where linux-user expects
it
linux-user: Handle rt_sigaction correctly for SPARC
linux-user/main.c | 8 ++++++-- linux-user/syscall.c | 27 +++++++++++++++++++++++---- target/sparc/mmu_helper.c | 8 ++++++++ 3 files changed, 37 insertions(+), 6 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/4 linux-user/s390x: Mask si_addr for SIGSEGV
For s390x, the address passed to a signal handler in the siginfo_t si_addr field is masked (in the kernel this is done in do_sigbus() and do_sigsegv() in arch/s390/mm/fault.c). Implement this architecture-specific oddity in linux-user.
This is one of the issues described in
https://bugs.launchpad.net/qemu/+bug/1705118
--- linux-user/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
linux-user/main.c +5 -1
@@ -3238,6 +3238,10 @@ void cpu_loop(CPUAlphaState *env)#endif /* TARGET_ALPHA */ #ifdef TARGET_S390X + +/* s390x masks the fault address it reports in si_addr for SIGSEGV and SIGBUS */ +#define S390X_FAIL_ADDR_MASK -4096LL +void cpu_loop (CPUS390XState *env) {CPUState *cs =CPU (s390_env_get_cpu (env));
@@ -3294,7 +3298,7 @@ void cpu_loop(CPUS390XState *env) sig =TARGET_SIGSEGV ;/* XXX: check env->error_code */ n =TARGET_SEGV_MAPERR ; - addr = env->__excp_addr; + addr = env->__excp_addr &S390X_FAIL_ADDR_MASK ; goto do_signal;case PGM_EXECUTE :case PGM_SPECIFICATION :
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 1/4] linux-user/s390x: Mask si_addr for SIGSEGV
Le 06/11/2017 à 19:33, Peter Maydell a écrit :
Quoted 30 lines
For s390x, the address passed to a signal handler in the
siginfo_tsi_addrfield is masked (in the kernel this is done indo_sigbus()anddo_sigsegv()inarch/s390/mm/fault.c). Implement this architecture-specific oddity in linux-user.This is one of the issues described in
https://bugs.launchpad.net/qemu/+bug/1705118Signed-off-by Peter Maydell <[email protected]>--- linux-user/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)linux-user/main.c +4
-0@@ -3238,6 +3238,10 @@ void cpu_loop(CPUAlphaState *env)#endif /* TARGET_ALPHA */ #ifdef TARGET_S390X + +/* s390x masks the fault address it reports in si_addr for SIGSEGV and SIGBUS */ +#define S390X_FAIL_ADDR_MASK -4096LL +void cpu_loop (CPUS390XState *env) {CPUState *cs =CPU (s390_env_get_cpu (env));
linux-user/main.c void cpu_loop(CPUS390XState *env) · line 3304
Quoted 8 lines
linux-user/main.c +1
-1@@ -3294,7 +3298,7 @@ void cpu_loop(CPUS390XState *env) sig =TARGET_SIGSEGV ;/* XXX: check env->error_code */ n =TARGET_SEGV_MAPERR ; - addr = env->__excp_addr; + addr = env->__excp_addr &S390X_FAIL_ADDR_MASK ; goto do_signal;case PGM_EXECUTE :case PGM_SPECIFICATION :
Re: [Qemu-devel] [PATCH 1/4] linux-user/s390x: Mask si_addr for SIGSEGV
In reply to Peter MaydellQuoted 9 lines · Peter Maydell
For s390x, the address passed to a signal handler in the
siginfo_tsi_addrfield is masked (in the kernel this is done indo_sigbus()anddo_sigsegv()inarch/s390/mm/fault.c). Implement this architecture-specific oddity in linux-user.This is one of the issues described in
https://bugs.launchpad.net/qemu/+bug/1705118Signed-off-by Peter Maydell <[email protected]>
Quoted 29 lines
--- linux-user/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)linux-user/main.c +5
-1@@ -3238,6 +3238,10 @@ void cpu_loop(CPUAlphaState *env)#endif /* TARGET_ALPHA */ #ifdef TARGET_S390X + +/* s390x masks the fault address it reports in si_addr for SIGSEGV and SIGBUS */ +#define S390X_FAIL_ADDR_MASK -4096LL +void cpu_loop (CPUS390XState *env) {CPUState *cs =CPU (s390_env_get_cpu (env));@@ -3294,7 +3298,7 @@ void cpu_loop(CPUS390XState *env) sig =TARGET_SIGSEGV ;/* XXX: check env->error_code */ n =TARGET_SEGV_MAPERR ; - addr = env->__excp_addr; + addr = env->__excp_addr &S390X_FAIL_ADDR_MASK ; goto do_signal;case PGM_EXECUTE :case PGM_SPECIFICATION :
Re: [Qemu-devel] [PATCH 1/4] linux-user/s390x: Mask si_addr for SIGSEGV
In reply to Peter MaydellQuoted 5 lines · Peter Maydell
For s390x, the address passed to a signal handler in the
siginfo_tsi_addrfield is masked (in the kernel this is done indo_sigbus()anddo_sigsegv()inarch/s390/mm/fault.c). Implement this architecture-specific oddity in linux-user.
Quoted 7 lines
This is one of the issues described in
https://bugs.launchpad.net/qemu/+bug/1705118Signed-off-by Peter Maydell <[email protected]>--- linux-user/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Accurate, but really seems like a s390x kernel bug.
r~
Re: [Qemu-devel] [PATCH 1/4] linux-user/s390x: Mask si_addr for SIGSEGV
Quoted 9 lines · Richard Henderson
Quoted 8 lines · Peter Maydell
For s390x, the address passed to a signal handler in the
siginfo_tsi_addrfield is masked (in the kernel this is done indo_sigbus()anddo_sigsegv()inarch/s390/mm/fault.c). Implement this architecture-specific oddity in linux-user.This is one of the issues described in
https://bugs.launchpad.net/qemu/+bug/1705118
Quoted 6 lines
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>--- linux-user/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)Accurate, but really seems like a s390x kernel bug.
The kernel code goes out of its way to do the masking, so if it's a bug presumably it's a "retain back compat with some older bug" thing...
thanks
-- PMM
PATCH 2/4 linux-user/ppc: Report correct fault address for data faults
In reply to Peter MaydellFor faults on loads and stores, ppc_cpu_handle_mmu_fault() in target/ppc/user_only_helper.c stores the offending address in env->spr[SPR_DAR]. Report this correctly to the guest in si_addr, rather than incorrectly using the address of the instruction that caused the fault.
This fixes the test case in
https://bugs.launchpad.net/qemu/+bug/1077116
for ppc, ppc64 and ppc64le.
--- linux-user/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/main.c +1 -1
@@ -1420,7 +1420,7 @@ void cpu_loop(CPUPPCState *env) info.si_code =TARGET_SEGV_MAPERR ;break ; } - info._sifields._sigfault._addr = env->nip; + info._sifields._sigfault._addr = env->spr[SPR_DAR ];queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info);break ;case POWERPC_EXCP_ISI :/* Instruction storage exception */
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 2/4] linux-user/ppc: Report correct fault address for data faults
Le 06/11/2017 à 19:33, Peter Maydell a écrit :
Quoted 21 lines
For faults on loads and stores,
ppc_cpu_handle_mmu_fault()intarget/ppc/user_only_helper.cstores the offending address in env->spr[SPR_DAR]. Report this correctly to the guest insi_addr, rather than incorrectly using the address of the instruction that caused the fault.This fixes the test case in
https://bugs.launchpad.net/qemu/+bug/1077116
for ppc, ppc64 and ppc64le.Signed-off-by Peter Maydell <[email protected]>--- linux-user/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/main.c +0
-0
linux-user/main.c void cpu_loop(CPUPPCState *env) · line 1426
Quoted 8 lines
linux-user/main.c +1
-1@@ -1420,7 +1420,7 @@ void cpu_loop(CPUPPCState *env) info.si_code =TARGET_SEGV_MAPERR ;break ; } - info._sifields._sigfault._addr = env->nip; + info._sifields._sigfault._addr = env->spr[SPR_DAR ];queue_signal (env, info.si_signo,QEMU_SI_FAULT , &info);break ;case POWERPC_EXCP_ISI :/* Instruction storage exception */
Re: [Qemu-devel] [PATCH 2/4] linux-user/ppc: Report correct fault address for data faults
In reply to Peter MaydellQuoted 6 lines · Peter Maydell
For faults on loads and stores,
ppc_cpu_handle_mmu_fault()intarget/ppc/user_only_helper.cstores the offending address in env->spr[SPR_DAR]. Report this correctly to the guest insi_addr, rather than incorrectly using the address of the instruction that caused the fault.
Quoted 8 lines
This fixes the test case in
https://bugs.launchpad.net/qemu/+bug/1077116
for ppc, ppc64 and ppc64le.Signed-off-by Peter Maydell <[email protected]>--- linux-user/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
PATCH 3/4 linux-user/sparc: Put address for data faults where linux-user expects it
In reply to Peter MaydellIn the user-mode-only version of sparc_cpu_handle_mmu_fault(), we must save the fault address for a data fault into the CPU state's mmu registers, because the code in linux-user/main.c expects to find it there in order to populate the si_addr field of the guest siginfo.
--- target/sparc/mmu_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+)
target/sparc/mmu_helper.c +8 -0
@@ -30,10 +30,18 @@int sparc_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int rw,int mmu_idx) { +SPARCCPU *cpu =SPARC_CPU (cs); +CPUSPARCState *env = &cpu->env; +if (rw &2 ) { cs->exception_index =TT_TFAULT ; }else { cs->exception_index =TT_DFAULT ; +#ifdef TARGET_SPARC64 + env->dmmu.mmuregs[4 ] = address; +#else + env->mmuregs[4 ] = address; +#endif }return 1 ; }
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 3/4] linux-user/sparc: Put address for data faults where linux-user expects it
Le 06/11/2017 à 19:33, Peter Maydell a écrit :
Quoted 25 lines
In the user-mode-only version of
sparc_cpu_handle_mmu_fault(), we must save the fault address for a data fault into the CPU state's mmu registers, because the code inlinux-user/main.cexpects to find it there in order to populate thesi_addrfield of the guest siginfo.Signed-off-by Peter Maydell <[email protected]>--- target/sparc/mmu_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+)target/sparc/mmu_helper.c +3
-0@@ -30,10 +30,18 @@int sparc_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int rw,int mmu_idx) { +SPARCCPU *cpu =SPARC_CPU (cs); +CPUSPARCState *env = &cpu->env; +if (rw &2 ) { cs->exception_index =TT_TFAULT ;
target/sparc/mmu_helper.c line 47
Quoted 10 lines
target/sparc/mmu_helper.c +5
-0}else { cs->exception_index =TT_DFAULT ; +#ifdef TARGET_SPARC64 + env->dmmu.mmuregs[4 ] = address; +#else + env->mmuregs[4 ] = address; +#endif }return 1 ; }
The softmmu version of sparc_cpu_handle_mmu_fault() also updates mmuregs[3]. Is it needed for this one (for ucontext)?
Thanks,
Laurent
Re: [Qemu-devel] [PATCH 3/4] linux-user/sparc: Put address for data faults where linux-user expects it
Quoted 31 lines · Laurent Vivier
Quoted 30 lines · Peter Maydell
In the user-mode-only version of
sparc_cpu_handle_mmu_fault(), we must save the fault address for a data fault into the CPU state's mmu registers, because the code inlinux-user/main.cexpects to find it there in order to populate thesi_addrfield of the guest siginfo.Signed-off-by Peter Maydell <[email protected]>--- target/sparc/mmu_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+)target/sparc/mmu_helper.c +7
-0@@ -30,10 +30,18 @@int sparc_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int rw,int mmu_idx) { +SPARCCPU *cpu =SPARC_CPU (cs); +CPUSPARCState *env = &cpu->env; +if (rw &2 ) { cs->exception_index =TT_TFAULT ; }else { cs->exception_index =TT_DFAULT ; +#ifdef TARGET_SPARC64 + env->dmmu.mmuregs[4 ] = address; +#else + env->mmuregs[4 ] = address;
Quoted 8 lines
target/sparc/mmu_helper.c line 47
Quoted 5 lines
target/sparc/mmu_helper.c +1
-0+#endif }return 1 ; }The softmmu version of
sparc_cpu_handle_mmu_fault()also updates mmuregs[3]. Is it needed for this one (for ucontext)?
Nothing in linux-user/ reads mmuregs[3], so I assume not.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 3/4] linux-user/sparc: Put address for data faults where linux-user expects it
In reply to Peter MaydellLe 06/11/2017 à 19:33, Peter Maydell a écrit :
Quoted 25 lines
In the user-mode-only version of
sparc_cpu_handle_mmu_fault(), we must save the fault address for a data fault into the CPU state's mmu registers, because the code inlinux-user/main.cexpects to find it there in order to populate thesi_addrfield of the guest siginfo.Signed-off-by Peter Maydell <[email protected]>--- target/sparc/mmu_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+)target/sparc/mmu_helper.c +3
-0@@ -30,10 +30,18 @@int sparc_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int rw,int mmu_idx) { +SPARCCPU *cpu =SPARC_CPU (cs); +CPUSPARCState *env = &cpu->env; +if (rw &2 ) { cs->exception_index =TT_TFAULT ;
target/sparc/mmu_helper.c line 47
Quoted 10 lines
target/sparc/mmu_helper.c +5
-0}else { cs->exception_index =TT_DFAULT ; +#ifdef TARGET_SPARC64 + env->dmmu.mmuregs[4 ] = address; +#else + env->mmuregs[4 ] = address; +#endif }return 1 ; }
Re: [Qemu-devel] [PATCH 3/4] linux-user/sparc: Put address for data faults where linux-user expects it
In reply to Peter MaydellQuoted 7 lines · Peter Maydell
In the user-mode-only version of
sparc_cpu_handle_mmu_fault(), we must save the fault address for a data fault into the CPU state's mmu registers, because the code inlinux-user/main.cexpects to find it there in order to populate thesi_addrfield of the guest siginfo.Signed-off-by Peter Maydell <[email protected]>
Quoted 28 lines
--- target/sparc/mmu_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+)target/sparc/mmu_helper.c +8
-0@@ -30,10 +30,18 @@int sparc_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int rw,int mmu_idx) { +SPARCCPU *cpu =SPARC_CPU (cs); +CPUSPARCState *env = &cpu->env; +if (rw &2 ) { cs->exception_index =TT_TFAULT ; }else { cs->exception_index =TT_DFAULT ; +#ifdef TARGET_SPARC64 + env->dmmu.mmuregs[4 ] = address; +#else + env->mmuregs[4 ] = address; +#endif }return 1 ; }
Re: [Qemu-devel] [PATCH 3/4] linux-user/sparc: Put address for data faults where linux-user expects it
In reply to Peter MaydellQuoted 10 lines · Peter Maydell
In the user-mode-only version of
sparc_cpu_handle_mmu_fault(), we must save the fault address for a data fault into the CPU state's mmu registers, because the code inlinux-user/main.cexpects to find it there in order to populate thesi_addrfield of the guest siginfo.Signed-off-by Peter Maydell <[email protected]>--- target/sparc/mmu_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+)
r~
PATCH 4/4 linux-user: Handle rt_sigaction correctly for SPARC
In reply to Peter MaydellSPARC is like Alpha in its handling of the rt_sigaction syscall:
it takes an extra parameter 'restorer' which needs to be copied into the sa_restorer field of the sigaction struct. The order of the arguments differs slightly between SPARC and Alpha but the implementation is otherwise the same. (Compare the rt_sigaction() functions in arch/sparc/kernel/sys_sparc_64.c and arch/alpha/kernel/signal.c.)
Note that this change is somewhat moot until SPARC acquires support for actually delivering RT signals.
--- linux-user/syscall.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
linux-user/syscall.c +23 -4
@@ -8556,8 +8556,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_NR_rt_sigaction: {#if defined(TARGET_ALPHA ) -struct target_sigaction act, oact, *pact =0 ; +/* For Alpha and SPARC this is a 5 argument syscall, with +* a 'restorer' parameter which must be copied into the +* sa_restorer field of the sigaction struct. +* For Alpha that 'restorer' is arg5; for SPARC it is arg4, +* and arg5 is the sigsetsize. +* Alpha also has a separate rt_sigaction struct that it uses +* here; SPARC uses the usual sigaction struct. +*/ struct target_rt_sigaction *rt_act; +struct target_sigaction act, oact, *pact =0 ;if (arg4 !=sizeof (target_sigset_t)) { ret = -TARGET_EINVAL ;
@@ -8583,18 +8591,29 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, unlock_user_struct(rt_act, arg3, 1); }#else +#ifdef TARGET_SPARC +target_ulong restorer = arg4; +target_ulong sigsetsize = arg5; +#else +target_ulong sigsetsize = arg4; +#endif struct target_sigaction *act;struct target_sigaction *oact; -if (arg4 !=sizeof (target_sigset_t)) { +if (sigsetsize !=sizeof (target_sigset_t)) { ret = -TARGET_EINVAL ;break ; }if (arg2) { -if (!lock_user_struct (VERIFY_READ , act, arg2,1 )) +if (!lock_user_struct (VERIFY_READ , act, arg2,1 )) { goto efault; - }else + } +#ifdef TARGET_SPARC + act->sa_restorer = restorer; +#endif + }else { act =NULL ; + }if (arg3) {if (!lock_user_struct (VERIFY_WRITE , oact, arg3,0 )) { ret = -TARGET_EFAULT ;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 4/4] linux-user: Handle rt_sigaction correctly for SPARC
Le 06/11/2017 à 19:33, Peter Maydell a écrit :
Quoted 62 lines
SPARC is like Alpha in its handling of the
rt_sigactionsyscall:
it takes an extra parameter 'restorer' which needs to be copied into thesa_restorerfield of the sigaction struct. The order of the arguments differs slightly between SPARC and Alpha but the implementation is otherwise the same. (Compare thert_sigaction()functions inarch/sparc/kernel/sys_sparc_64.candarch/alpha/kernel/signal.c.)Note that this change is somewhat moot until SPARC acquires support for actually delivering RT signals.
Signed-off-by Peter Maydell <[email protected]>--- linux-user/syscall.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)linux-user/syscall.c +17
-4@@ -8556,8 +8556,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_NR_rt_sigaction: {#if defined(TARGET_ALPHA ) -struct target_sigaction act, oact, *pact =0 ; +/* For Alpha and SPARC this is a 5 argument syscall, with +* a 'restorer' parameter which must be copied into the +* sa_restorer field of the sigaction struct. +* For Alpha that 'restorer' is arg5; for SPARC it is arg4, +* and arg5 is the sigsetsize. +* Alpha also has a separate rt_sigaction struct that it uses +* here; SPARC uses the usual sigaction struct. +*/ struct target_rt_sigaction *rt_act; +struct target_sigaction act, oact, *pact =0 ;if (arg4 !=sizeof (target_sigset_t)) { ret = -TARGET_EINVAL ;@@ -8583,18 +8591,29 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, unlock_user_struct(rt_act, arg3, 1); }#else +#ifdef TARGET_SPARC +target_ulong restorer = arg4; +target_ulong sigsetsize = arg5; +#else +target_ulong sigsetsize = arg4; +#endif struct target_sigaction *act;struct target_sigaction *oact; -if (arg4 !=sizeof (target_sigset_t)) { +if (sigsetsize !=sizeof (target_sigset_t)) { ret = -TARGET_EINVAL ;break ; }if (arg2) { -if (!lock_user_struct (VERIFY_READ , act, arg2,1 )) +if (!lock_user_struct (VERIFY_READ , act, arg2,1 )) { goto efault; - }else
linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 8619
Quoted 10 lines
linux-user/syscall.c +6
-0+ } +#ifdef TARGET_SPARC + act->sa_restorer = restorer; +#endif + }else { act =NULL ; + }if (arg3) {if (!lock_user_struct (VERIFY_WRITE , oact, arg3,0 )) { ret = -TARGET_EFAULT ;
Re: [Qemu-devel] [PATCH 4/4] linux-user: Handle rt_sigaction correctly for SPARC
In reply to Peter MaydellHi Peter,
Quoted 23 lines · Peter Maydell
SPARC is like Alpha in its handling of the
rt_sigactionsyscall:
it takes an extra parameter 'restorer' which needs to be copied into thesa_restorerfield of the sigaction struct. The order of the arguments differs slightly between SPARC and Alpha but the implementation is otherwise the same. (Compare thert_sigaction()functions inarch/sparc/kernel/sys_sparc_64.candarch/alpha/kernel/signal.c.)Note that this change is somewhat moot until SPARC acquires support for actually delivering RT signals.
Signed-off-by Peter Maydell <[email protected]>--- linux-user/syscall.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)linux-user/syscall.c +0
-0@@ -8556,8 +8556,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_NR_rt_sigaction: {
linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 8566
Quoted 10 lines
linux-user/syscall.c +8
-1-struct target_sigaction act, oact, *pact =0 ; +/* For Alpha and SPARC this is a 5 argument syscall, with +* a 'restorer' parameter which must be copied into the +* sa_restorer field of the sigaction struct. +* For Alpha that 'restorer' is arg5; for SPARC it is arg4, +* and arg5 is the sigsetsize. +* Alpha also has a separate rt_sigaction struct that it uses +* here; SPARC uses the usual sigaction struct. +*/
I find it easier to read moving the #if after the comment. Since using restorer for sparc improve readability we can use it for alpha as well (code is a bit more consistent):
#if defined(TARGET_ALPHA)
target_ulong restorer = arg5;Quoted 5 lines
linux-user/syscall.c +1
-0struct target_rt_sigaction *rt_act; +struct target_sigaction act, oact, *pact =0 ;if (arg4 !=sizeof (target_sigset_t)) { ret = -TARGET_EINVAL ;
...
act.sa_restorer = restorer;
Whichever way:
Quoted 34 lines
linux-user/syscall.c +14
-3@@ -8583,18 +8591,29 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, unlock_user_struct(rt_act, arg3, 1); }#else +#ifdef TARGET_SPARC +target_ulong restorer = arg4; +target_ulong sigsetsize = arg5; +#else +target_ulong sigsetsize = arg4; +#endif struct target_sigaction *act;struct target_sigaction *oact; -if (arg4 !=sizeof (target_sigset_t)) { +if (sigsetsize !=sizeof (target_sigset_t)) { ret = -TARGET_EINVAL ;break ; }if (arg2) { -if (!lock_user_struct (VERIFY_READ , act, arg2,1 )) +if (!lock_user_struct (VERIFY_READ , act, arg2,1 )) { goto efault; - }else + } +#ifdef TARGET_SPARC + act->sa_restorer = restorer; +#endif + }else { act =NULL ; + }if (arg3) {if (!lock_user_struct (VERIFY_WRITE , oact, arg3,0 )) { ret = -TARGET_EFAULT ;
Quoted 15 lines · Peter Maydell
This patchset fixes most of the problems with delivering SIGSEGV noted in https://bugs.launchpad.net/qemu/+bug/1705118:
* s390x is missing masking operations on the fault address passed to the guest insi_addr
* ppc is passing the PC of the offending insn, not the data address, intosi_addr
* sparc fails to record the address of a data fault and so passes 0 intosi_addr
* sparc isn't implementingrt_sigactioncorrectly (it has an extra 'restorer' argument, similar to alpha)It doesn't actually get the sparc testcase from that bug working, though, because SPARC is entirely missing support for
setup_rt_frame()anddo_rt_sigreturn(), so it can't deliver RT signals.
Quoted 6 lines
Implementing RT signal delivery is too big a bugfix for an afternoon, so here are the simpler parts. I'll leave the signal delivery part to somebody who cares about SPARC guests...
thanks
-- PMM
Thanks!
series applied to linux-user tree,
Riku
Quoted 15 lines
Peter Maydell (4):
linux-user/s390x: Masksi_addrfor SIGSEGV
linux-user/ppc: Report correct fault address for data faults linux-user/sparc: Put address for data faults where linux-user expects
it
linux-user: Handlert_sigactioncorrectly for SPARClinux-user/main.c | 8 ++++++-- linux-user/syscall.c | 27 +++++++++++++++++++++++---- target/sparc/mmu_helper.c | 8 ++++++++ 3 files changed, 37 insertions(+), 6 deletions(-)Signature · 1 line
2.7.4