From: "Nutty Liu" <liujingqi@lanxincomputing.com>
To: "Jay Chang" <jay.chang@sifive.com>, <qemu-devel@nongnu.org>,
<qemu-riscv@nongnu.org>
Cc: "Palmer Dabbelt" <palmer@dabbelt.com>,
"Alistair Francis" <alistair.francis@wdc.com>,
"Weiwei Li" <liwei1518@gmail.com>,
"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
"Frank Chang" <frank.chang@sifive.com>
Subject: Re: [PATCH v3 2/2] target/riscv: Restrict midelegh access to S-mode harts
Date: Tue, 1 Jul 2025 11:45:57 +0800 [thread overview]
Message-ID: <c8a2beb3-6a66-4d63-ac0b-e88c4dc53d64@lanxincomputing.com> (raw)
In-Reply-To: <20250701030021.99218-3-jay.chang@sifive.com>
On 7/1/2025 11:00 AM, Jay Chang wrote:
> RISC-V AIA Spec states:
> "For a machine-level environment, extension Smaia encompasses all added
> CSRs and all modifications to interrupt response behavior that the AIA
> specifies for a hart, over all privilege levels. For a supervisor-level
> environment, extension Ssaia is essentially the same as Smaia except
> excluding the machine-level CSRs and behavior not directly visible to
> supervisor level."
>
> Since midelegh is an AIA machine-mode CSR, add Smaia extension check in
> aia_smode32 predicate.
>
> Reviewed-by: Frank Chang <frank.chang@sifive.com>
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
> Signed-off-by: Jay Chang <jay.chang@sifive.com>
> ---
> target/riscv/csr.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index 0e0ad37654..74ec0e1c60 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -374,8 +374,11 @@ static RISCVException aia_smode(CPURISCVState *env, int csrno)
> static RISCVException aia_smode32(CPURISCVState *env, int csrno)
> {
> int ret;
> + int csr_priv = get_field(csrno, 0x300);
>
> - if (!riscv_cpu_cfg(env)->ext_ssaia) {
> + if (csr_priv == PRV_M && !riscv_cpu_cfg(env)->ext_smaia) {
> + return RISCV_EXCP_ILLEGAL_INST;
> + } else if (!riscv_cpu_cfg(env)->ext_ssaia) {
+ if ((csr_priv == PRV_M && !riscv_cpu_cfg(env)->ext_smaia) ||
+ (!riscv_cpu_cfg(env)->ext_ssaia)) {
Would the above code be better ?
Otherwise,
Reviewed-by: Nutty Liu<liujingqi@lanxincomputing.com>
Thanks,
Nutty
> return RISCV_EXCP_ILLEGAL_INST;
> }
>
> @@ -5911,7 +5914,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
> [CSR_MVIP] = { "mvip", aia_any, NULL, NULL, rmw_mvip },
>
> /* Machine-Level High-Half CSRs (AIA) */
> - [CSR_MIDELEGH] = { "midelegh", aia_any32, NULL, NULL, rmw_midelegh },
> + [CSR_MIDELEGH] = { "midelegh", aia_smode32, NULL, NULL, rmw_midelegh },
> [CSR_MIEH] = { "mieh", aia_any32, NULL, NULL, rmw_mieh },
> [CSR_MVIENH] = { "mvienh", aia_any32, NULL, NULL, rmw_mvienh },
> [CSR_MVIPH] = { "mviph", aia_any32, NULL, NULL, rmw_mviph },
next prev parent reply other threads:[~2025-07-01 3:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 3:00 [PATCH v3 0/2] Add S-mode checks for delegation-related CSRs Jay Chang
2025-07-01 3:00 ` [PATCH v3 1/2] target/riscv: Restrict mideleg/medeleg/medelegh access to S-mode harts Jay Chang
2025-07-01 3:47 ` Nutty Liu
2025-07-01 3:00 ` [PATCH v3 2/2] target/riscv: Restrict midelegh " Jay Chang
2025-07-01 3:45 ` Nutty Liu [this message]
2025-07-07 9:55 ` Jay Chang
2025-07-29 3:28 ` [PATCH v3 0/2] Add S-mode checks for delegation-related CSRs Alistair Francis
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=c8a2beb3-6a66-4d63-ac0b-e88c4dc53d64@lanxincomputing.com \
--to=liujingqi@lanxincomputing.com \
--cc=alistair.francis@wdc.com \
--cc=dbarboza@ventanamicro.com \
--cc=frank.chang@sifive.com \
--cc=jay.chang@sifive.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.