On Tue, 3 Aug 2021 at 05:18, Richard Henderson <richard.hender...@linaro.org> wrote: > > Cc: Philippe Mathieu-Daudé <f4...@amsat.org> > Signed-off-by: Richard Henderson <richard.hender...@linaro.org> > --- > linux-user/mips/cpu_loop.c | 20 ++++++++++++++++---- > target/mips/cpu.c | 2 +- > target/mips/tcg/op_helper.c | 3 +-- > target/mips/tcg/user/tlb_helper.c | 23 +++++++++++------------ > 4 files changed, 29 insertions(+), 19 deletions(-) > > diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c > index 9d813ece4e..51f4eb65a6 100644 > --- a/linux-user/mips/cpu_loop.c > +++ b/linux-user/mips/cpu_loop.c > @@ -158,12 +158,24 @@ done_syscall: > break; > case EXCP_TLBL: > case EXCP_TLBS: > - case EXCP_AdEL: > - case EXCP_AdES: > info.si_signo = TARGET_SIGSEGV; > info.si_errno = 0; > - /* XXX: check env->error_code */ > - info.si_code = TARGET_SEGV_MAPERR; > + info.si_code = (env->error_code & EXCP_TLB_NOMATCH > + ? TARGET_SEGV_MAPERR : TARGET_SEGV_ACCERR); > + info._sifields._sigfault._addr = env->CP0_BadVAddr; > + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); > + break; > + case EXCP_AdEL: > + case EXCP_AdES: > + /* > + * Note that on real hw AdE is also raised for access to a > + * kernel address from user mode instead of a TLB error. > + * For simplicity, we do not distinguish this in the user > + * version of mips_cpu_tlb_fill so only unaligned comes here. > + */ > + info.si_signo = TARGET_SIGBUS; > + info.si_errno = 0; > + info.si_code = TARGET_BUS_ADRALN;
The MIPS kernel code doesn't use si_code BUS_ADRALN for alignment errors, as far as I can see -- it just calls force_sig(SIGBUS): https://elixir.bootlin.com/linux/latest/source/arch/mips/kernel/unaligned.c#L557 which gets you the same thing our force_sig() does: a code of SI_KERNEL. So I think we should be calling force_sig(TARGET_SIGBUS); here rather than filling in a target_siginfo_t and calling queue_signal(). > info._sifields._sigfault._addr = env->CP0_BadVAddr; > queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); > break; thanks -- PMM