qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alistair Francis <alistair23@gmail.com>
To: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, palmer@dabbelt.com,
	 alistair.francis@wdc.com, dbarboza@ventanamicro.com,
	liwei1518@gmail.com,  bmeng.cn@gmail.com,
	TANG Tiancheng <tangtiancheng.ttc@alibaba-inc.com>
Subject: Re: [PATCH v1 2/7] target/riscv: Fix satp read and write implicitly or explicitly.
Date: Fri, 11 Oct 2024 13:58:07 +1000	[thread overview]
Message-ID: <CAKmqyKOtnBzNgeAWL6m0-oRRMgHXXKpv3n2WbtV4Z6bmL6MLVw@mail.gmail.com> (raw)
In-Reply-To: <20241007033400.50163-3-zhiwei_liu@linux.alibaba.com>

On Mon, Oct 7, 2024 at 1:35 PM LIU Zhiwei <zhiwei_liu@linux.alibaba.com> wrote:
>
> From: TANG Tiancheng <tangtiancheng.ttc@alibaba-inc.com>
>
> CSR satp is SXLEN bits in length and always has the $layout determined by
> the SXL configuration, regardless of the current XLEN.
>
> Only process CSR satp, as we still don't have a riscv_cpu_vsxl API
> currently.
>
> Added sxl32 property to control sxlen as 32 in s-mode for QEMU RV64.
>
> Signed-off-by: TANG Tiancheng <tangtiancheng.ttc@alibaba-inc.com>
> Fixes: c7b9517188 (RISC-V: Implement modular CSR helper interface)
> Reviewed-by: Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
> ---
>  target/riscv/cpu_cfg.h |  4 ++++
>  target/riscv/csr.c     | 25 +++++++++++++++++++------
>  2 files changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
> index 8b272fb826..cdbd2afe29 100644
> --- a/target/riscv/cpu_cfg.h
> +++ b/target/riscv/cpu_cfg.h
> @@ -173,6 +173,10 @@ struct RISCVCPUConfig {
>      bool short_isa_string;
>
>  #ifndef CONFIG_USER_ONLY
> +    /*
> +     * true when RV64 QEMU running with mxlen==64 but sxlen==32.
> +     */
> +    bool sxl32;
>      RISCVSATPMap satp_mode;
>  #endif
>  };
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index b33cc1ec23..93a5cf87ed 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -1504,16 +1504,29 @@ static RISCVException read_mstatus(CPURISCVState *env, int csrno,
>
>  static bool validate_vm(CPURISCVState *env, target_ulong vm)
>  {
> -    uint64_t mode_supported = riscv_cpu_cfg(env)->satp_mode.map;
> +    uint64_t mode_supported = 0;
> +    if (riscv_cpu_cfg(env)->sxl32 && (riscv_cpu_mxl(env) != MXL_RV32)) {

This should be using the actual SXLEN values, not this special
property. What happens if the property is set to false but the guest
software sets SXLEN to 32-bits? This will break

Alistair

> +        mode_supported = (1 << VM_1_10_MBARE) | (1 << VM_1_10_SV32);
> +    } else {
> +        mode_supported = riscv_cpu_cfg(env)->satp_mode.map;
> +    }
>      return get_field(mode_supported, (1 << vm));
>  }
>
>  static target_ulong legalize_xatp(CPURISCVState *env, target_ulong old_xatp,
> -                                  target_ulong val)
> +                                  target_ulong val, int csrno)
>  {
>      target_ulong mask;
>      bool vm;
> -    if (riscv_cpu_mxl(env) == MXL_RV32) {
> +    RISCVMXL xl;
> +
> +    if (csrno == CSR_SATP) {
> +        xl = riscv_cpu_sxl(env);
> +    } else {
> +        xl = riscv_cpu_mxl(env);
> +    }
> +
> +    if (xl == MXL_RV32) {
>          vm = validate_vm(env, get_field(val, SATP32_MODE));
>          mask = (val ^ old_xatp) & (SATP32_MODE | SATP32_ASID | SATP32_PPN);
>      } else {
> @@ -3316,7 +3329,7 @@ static RISCVException write_satp(CPURISCVState *env, int csrno,
>          return RISCV_EXCP_NONE;
>      }
>
> -    env->satp = legalize_xatp(env, env->satp, val);
> +    env->satp = legalize_xatp(env, env->satp, val, csrno);
>      return RISCV_EXCP_NONE;
>  }
>
> @@ -3834,7 +3847,7 @@ static RISCVException read_hgatp(CPURISCVState *env, int csrno,
>  static RISCVException write_hgatp(CPURISCVState *env, int csrno,
>                                    target_ulong val)
>  {
> -    env->hgatp = legalize_xatp(env, env->hgatp, val);
> +    env->hgatp = legalize_xatp(env, env->hgatp, val, csrno);
>      return RISCV_EXCP_NONE;
>  }
>
> @@ -4116,7 +4129,7 @@ static RISCVException read_vsatp(CPURISCVState *env, int csrno,
>  static RISCVException write_vsatp(CPURISCVState *env, int csrno,
>                                    target_ulong val)
>  {
> -    env->vsatp = legalize_xatp(env, env->vsatp, val);
> +    env->vsatp = legalize_xatp(env, env->vsatp, val, csrno);
>      return RISCV_EXCP_NONE;
>  }
>
> --
> 2.43.0
>
>


  reply	other threads:[~2024-10-11  3:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-07  3:33 [PATCH v1 0/7] target/riscv: Support SXL32 on RV64 CPU LIU Zhiwei
2024-10-07  3:33 ` [PATCH v1 1/7] target/riscv: Fix sstatus read and write LIU Zhiwei
2024-10-11  3:44   ` Alistair Francis
2024-10-07  3:33 ` [PATCH v1 2/7] target/riscv: Fix satp read and write implicitly or explicitly LIU Zhiwei
2024-10-11  3:58   ` Alistair Francis [this message]
2024-10-07  3:33 ` [PATCH v1 3/7] target/riscv: Read pte and satp based on SXL in PTW LIU Zhiwei
2024-10-11  3:59   ` Alistair Francis
2024-10-07  3:33 ` [PATCH v1 4/7] hw/riscv: Align kernel to 4MB when sxl32 is on LIU Zhiwei
2024-10-07  3:33 ` [PATCH v1 5/7] target/riscv: Enable 32-bit only registers for RV64 with sxl32 LIU Zhiwei
2024-10-11  4:00   ` Alistair Francis
2024-10-07  3:33 ` [PATCH v1 6/7] target/riscv: Reset SXL and UXL according to sxl32 LIU Zhiwei
2024-10-07  3:34 ` [PATCH v1 7/7] target/riscv: Expose sxl32 configuration in RISC-V CPU LIU Zhiwei
2024-10-11  3:56   ` Alistair Francis
2024-10-11  3:55 ` [PATCH v1 0/7] target/riscv: Support SXL32 on RV64 CPU Alistair Francis
2024-10-22  6:41   ` LIU Zhiwei

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=CAKmqyKOtnBzNgeAWL6m0-oRRMgHXXKpv3n2WbtV4Z6bmL6MLVw@mail.gmail.com \
    --to=alistair23@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=bmeng.cn@gmail.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=liwei1518@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=tangtiancheng.ttc@alibaba-inc.com \
    --cc=zhiwei_liu@linux.alibaba.com \
    /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).