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 1/2] target/riscv: Restrict mideleg/medeleg/medelegh access to S-mode harts
Date: Tue, 1 Jul 2025 11:47:49 +0800 [thread overview]
Message-ID: <fad98061-eceb-4dae-ac7c-5a95bea1d582@lanxincomputing.com> (raw)
In-Reply-To: <20250701030021.99218-2-jay.chang@sifive.com>
On 7/1/2025 11:00 AM, Jay Chang wrote:
> RISC-V Privileged Spec states:
> "In harts with S-mode, the medeleg and mideleg registers must exist, and
> setting a bit in medeleg or mideleg will delegate the corresponding trap
> , when occurring in S-mode or U-mode, to the S-mode trap handler. In
> harts without S-mode, the medeleg and mideleg registers should not
> exist."
>
> Add smode predicate to ensure these CSRs are only accessible when S-mode
> is supported.
>
> 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 | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index 6296ecd1e1..0e0ad37654 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -5862,8 +5862,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
> NULL, read_mstatus_i128 },
> [CSR_MISA] = { "misa", any, read_misa, write_misa,
> NULL, read_misa_i128 },
> - [CSR_MIDELEG] = { "mideleg", any, NULL, NULL, rmw_mideleg },
> - [CSR_MEDELEG] = { "medeleg", any, read_medeleg, write_medeleg },
> + [CSR_MIDELEG] = { "mideleg", smode, NULL, NULL, rmw_mideleg },
> + [CSR_MEDELEG] = { "medeleg", smode, read_medeleg, write_medeleg },
> [CSR_MIE] = { "mie", any, NULL, NULL, rmw_mie },
> [CSR_MTVEC] = { "mtvec", any, read_mtvec, write_mtvec },
> [CSR_MCOUNTEREN] = { "mcounteren", umode, read_mcounteren,
> @@ -5871,7 +5871,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
>
> [CSR_MSTATUSH] = { "mstatush", any32, read_mstatush,
> write_mstatush },
> - [CSR_MEDELEGH] = { "medelegh", any32, read_zero, write_ignore,
> + [CSR_MEDELEGH] = { "medelegh", smode32, read_zero, write_ignore,
> .min_priv_ver = PRIV_VERSION_1_13_0 },
> [CSR_HEDELEGH] = { "hedelegh", hmode32, read_hedelegh, write_hedelegh,
> .min_priv_ver = PRIV_VERSION_1_13_0 },
Reviewed-by: Nutty Liu<liujingqi@lanxincomputing.com>
Thanks,
Nutty
next prev parent reply other threads:[~2025-07-01 3:49 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 [this message]
2025-07-01 3:00 ` [PATCH v3 2/2] target/riscv: Restrict midelegh " Jay Chang
2025-07-01 3:45 ` Nutty Liu
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=fad98061-eceb-4dae-ac7c-5a95bea1d582@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.