qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Song Gao <gaosong@loongson.cn>, qemu-devel@nongnu.org
Cc: laurent@vivier.eu, Xiaojuan Yang <yangxiaojuan@loongson.cn>
Subject: Re: [PATCH v15 8/9] target/loongarch: Adjust functions and structure to support user-mode
Date: Thu, 9 Jun 2022 11:42:00 -0700	[thread overview]
Message-ID: <4c0fd198-922e-d94f-fec4-05c53c5d6858@linaro.org> (raw)
In-Reply-To: <20220609024209.2406188-9-gaosong@loongson.cn>

On 6/8/22 19:42, Song Gao wrote:
> diff --git a/target/loongarch/helper.h b/target/loongarch/helper.h
> index 85c11a60d4..ee42707868 100644
> --- a/target/loongarch/helper.h
> +++ b/target/loongarch/helper.h
> @@ -93,8 +93,7 @@ DEF_HELPER_2(frint_d, i64, env, i64)
>   
>   DEF_HELPER_FLAGS_2(set_rounding_mode, TCG_CALL_NO_RWG, void, env, i32)
>   
> -DEF_HELPER_1(rdtime_d, i64, env)
> -
> +#ifndef CONFIG_USER_ONLY
>   /* CSRs helper */
>   DEF_HELPER_1(csrrd_pgd, i64, env)
>   DEF_HELPER_1(csrrd_tval, i64, env)
> @@ -128,3 +127,5 @@ DEF_HELPER_4(lddir, tl, env, tl, tl, i32)
>   DEF_HELPER_4(ldpte, void, env, tl, tl, i32)
>   DEF_HELPER_1(ertn, void, env)
>   DEF_HELPER_1(idle, void, env)
> +DEF_HELPER_1(rdtime_d, i64, env)
> +#endif

This is wrong.

>   static bool trans_rdtimel_w(DisasContext *ctx, arg_rdtimel_w *a)
>   {
> +#ifdef CONFIG_USER_ONLY
> +    return cpu_get_host_ticks();

This is very wrong.  You're calling cpu_get_host_ticks at translation time.
There are no changes required during translation.

You should in fact be calling cpu_get_host_ticks in helper_rdtime_d.

>   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).

>   void helper_asrtgt_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
>       }
>   }

Likewise.


r~


  parent reply	other threads:[~2022-06-09 20:15 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-09  2:42 [PATCH v15 0/9] Add LoongArch linux-user emulation support Song Gao
2022-06-09  2:42 ` [PATCH v15 1/9] linux-user: Add LoongArch generic header files Song Gao
2022-06-09  9:54   ` WANG Xuerui
2022-06-09  2:42 ` [PATCH v15 2/9] linux-user: Add LoongArch signal support Song Gao
2022-06-09 18:00   ` Richard Henderson
2022-06-09  2:42 ` [PATCH v15 3/9] linux-user: Add LoongArch elf support Song Gao
2022-06-09  2:42 ` [PATCH v15 4/9] linux-user: Add LoongArch syscall support Song Gao
2022-06-09 10:04   ` WANG Xuerui
2022-06-10  1:15     ` gaosong
2022-06-09  2:42 ` [PATCH v15 5/9] linux-user: Add LoongArch cpu_loop support Song Gao
2022-06-09  2:42 ` [PATCH v15 6/9] default-configs: Add loongarch linux-user support Song Gao
2022-06-09 10:11   ` WANG Xuerui
2022-06-09 18:14   ` Richard Henderson
2022-06-09  2:42 ` [PATCH v15 7/9] scripts: add loongarch64 binfmt config Song Gao
2022-06-09  2:42 ` [PATCH v15 8/9] target/loongarch: Adjust functions and structure to support user-mode Song Gao
2022-06-09 10:18   ` WANG Xuerui
2022-06-09 18:42   ` Richard Henderson [this message]
2022-06-10  6:53     ` gaosong
2022-06-10 22:45       ` Richard Henderson
2022-06-11  3:10         ` gaosong
2022-06-11 16:06           ` Richard Henderson
2022-06-13  3:50             ` gaosong
2022-06-13 16:05               ` Richard Henderson
2022-06-09  2:42 ` [PATCH v15 9/9] target/loongarch: Update README Song Gao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4c0fd198-922e-d94f-fec4-05c53c5d6858@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=gaosong@loongson.cn \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=yangxiaojuan@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).