|
From: | gaosong |
Subject: | Re: [PATCH v15 8/9] target/loongarch: Adjust functions and structure to support user-mode |
Date: | Sat, 11 Jun 2022 11:10:40 +0800 |
User-agent: | Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 |
On 6/9/22 23:53, gaosong wrote:
Hi Richard,
On 2022/6/10 上午2:42, Richard Henderson wrote:
void helper_asrtle_d(CPULoongArchState *env, target_ulong rj, target_ulong rk)
{
if (rj > rk) {
+#ifdef CONFIG_USER_ONLY
+ cpu_loop_exit_sigsegv(env_cpu(env), GETPC(),
+ MMU_DATA_LOAD, true, GETPC());
+#else
do_raise_exception(env, EXCCODE_ADEM, GETPC());
+#endif
This change is wrong. First, the kernel's do_ade raises SIGBUS. Second, GETPC() is a host address, not a guest address. Third, this highlights the fact that the existing system code is wrong, and should be setting badvaddr.
You need to
(1) set badvaddr here, and then
(2) handle EXCCODE_ADEM in linux-user/loongarch/cpu_loop.c to force_fix_fault(TARGET_SIGBUS, TARGET_BUS_ADRERR, env->badvaddr).
badvaddr is env->pc or base->pc_next?
I don't know. The documentation for the ASRT{LE,GD}.D instructions is incomplete.
However, from the kernel code,
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/loongarch/kernel/traps.c#n360
I can see that the kernel expects *some* value to be set there. Given that this is the same trap used by the bound check memory accesses, I presume that badvaddr is related to the memory access not the PC. So I would expect badvaddr to be RJ.
But that is a guess. Please check with your hardware engineers.
Thanks you,
I had tested asrtgt.d on hardware. the log is :
the gdb log
(gdb) info registers
zero ra
tp sp
R0 0000000000000000 000000fff7e7c774 000000fff7ffef20
000000ffffff6940
a0 a1
a2 a3
R4 0000000000000001 000000ffffff6a88 000000ffffff6a98
000000fff7fbc4b0
a4 a5
a6 a7
R8 0000000000000000 000000fff7fe6f70 000000ffffff6a80
0000000000000080
t0 t1
t2 t3
R12 0000000000000000 0000000000000000 0000000000000000
000000fff7fbeeb8
t4 t5
t6 t7
R16 000000fff7fbdd40 000000fff7fbdd40 7f7f7f7f7f7f7f7f
0000000000000000
t8 x
fp s0
R20 ffffff0000000000 0000000000000000 000000ffffff6960
0000000000000000
s1 s2
s3 s4
R24 0000000120000658 000000aaaabd9c60 0000000000000000
000000aaaabe9b50
s5 s6
s7 s8
R28 000000aaaabd9c60 0000000000000000 0000000000000000
000000aaaabcfa08
pc 0x120000638 0x120000638 <main+32>
badvaddr 0xfff7e935c8 0xfff7e935c8
<__cxa_atexit>
(gdb) stepi
Program received signal SIGSYS, Bad system call.
0x0000000120000638 in main () at asrtle.c:8
8 asm volatile("asrtgt.d %0,%1\n\t"
(gdb) info registers
zero ra
tp sp
R0 0000000000000000 000000fff7e7c774 000000fff7ffef20
000000ffffff6940
a0 a1
a2 a3
R4 0000000000000001 000000ffffff6a88 000000ffffff6a98
000000fff7fbc4b0
a4 a5
a6 a7
R8 0000000000000000 000000fff7fe6f70 000000ffffff6a80
0000000000000080
t0 t1
t2 t3
R12 0000000000000000 0000000000000000 0000000000000000
000000fff7fbeeb8
t4 t5
t6 t7
R16 000000fff7fbdd40 000000fff7fbdd40 7f7f7f7f7f7f7f7f
0000000000000000
t8 x
fp s0
R20 ffffff0000000000 0000000000000000 000000ffffff6960
0000000000000000
s1 s2
s3 s4
R24 0000000120000658 000000aaaabd9c60 0000000000000000
000000aaaabe9b50
s5 s6
s7 s8
R28 000000aaaabd9c60 0000000000000000 0000000000000000
000000aaaabcfa08
pc 0x120000638 0x120000638 <main+32>
badvaddr 0x120000638 0x120000638 <main+32>
(gdb) disas
Dump of assembler code for function main:
0x0000000120000618 <+0>: addi.d $r3,$r3,-32(0xfe0)
0x000000012000061c <+4>: st.d $r22,$r3,24(0x18)
0x0000000120000620 <+8>: addi.d $r22,$r3,32(0x20)
0x0000000120000624 <+12>: addi.w $r12,$r0,23(0x17)
0x0000000120000628 <+16>: st.d $r12,$r22,-24(0xfe8)
0x000000012000062c <+20>: st.d $r0,$r22,-32(0xfe0)
0x0000000120000630 <+24>: ld.d $r12,$r22,-32(0xfe0)
0x0000000120000634 <+28>: ld.d $r13,$r22,-32(0xfe0)
=> 0x0000000120000638 <+32>: asrtgt.d $r12,$r12
0x000000012000063c <+36>: st.d $r12,$r22,-24(0xfe8)
0x0000000120000640 <+40>: move $r12,$r0
0x0000000120000644 <+44>: move $r4,$r12
0x0000000120000648 <+48>: ld.d $r22,$r3,24(0x18)
0x000000012000064c <+52>: addi.d $r3,$r3,32(0x20)
0x0000000120000650 <+56>: jirl $r0,$r1,0
End of assembler dump.
dmesg :
[151125.931122] pid:32782 [a.out] Caught reserved exception 10 - should not happen
So
badvaddr is the PC,
exitsting system code is BCE, (10)
And I think the change like this:
void helper_asrtle_d(CPULoongArchState *env, target_ulong rj, target_ulong rk)
{
if (rj > rk) {
env->badvaddr = env->pc;
do_raise_exception(env, EXCCODE_BCE, env->badvaddr);
}
}
cpu_loop.c
case EXCCODE_BCE:
force_sig_fault(TARGET_SIGSYS, TARGET_SI_KERNEL,
env->badvaddr)
[Prev in Thread] | Current Thread | [Next in Thread] |