qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v15 8/9] target/loongarch: Adjust functions and structure to


From: Richard Henderson
Subject: Re: [PATCH v15 8/9] target/loongarch: Adjust functions and structure to support user-mode
Date: Fri, 10 Jun 2022 15:45:18 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1

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.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]