From: Alistair Francis <alistair23@gmail.com>
To: Ivan Klokov <ivan.klokov@syntacore.com>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, palmer@dabbelt.com,
alistair.francis@wdc.com, bin.meng@windriver.com,
liwei1518@gmail.com, dbarboza@ventanamicro.com,
zhiwei_liu@linux.alibaba.com
Subject: Re: [PATCH v2 1/2] target/riscv/cpu_helper.c: Invalid exception on MMU translation stage
Date: Wed, 22 Nov 2023 12:04:17 +1000 [thread overview]
Message-ID: <CAKmqyKOn3J7HqUcS2RLxE9dUJkUkKvmTySuA3EUDffPy__A6pA@mail.gmail.com> (raw)
In-Reply-To: <20231121071757.7178-2-ivan.klokov@syntacore.com>
On Tue, Nov 21, 2023 at 6:51 PM Ivan Klokov <ivan.klokov@syntacore.com> wrote:
>
> According to RISCV privileged spec sect. 5.3.2 Virtual Address Translation Process
> access-fault exceptions may raise only after PMA/PMP check. Current implementation
> generates an access-fault for mbare mode even if there were no PMA/PMP errors.
> This patch removes the erroneous MMU mode check and generates an access-fault
> exception based on the pmp_violation flag only.
>
> Fixes: 1448689c7b ("target/riscv: Allow specifying MMU stage")
>
> Signed-off-by: Ivan Klokov <ivan.klokov@syntacore.com>
Please keep existing tags when sending a new version if there aren't any changes
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/cpu_helper.c | 30 +++++++-----------------------
> 1 file changed, 7 insertions(+), 23 deletions(-)
>
> diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
> index b7af69de53..9ff0952e46 100644
> --- a/target/riscv/cpu_helper.c
> +++ b/target/riscv/cpu_helper.c
> @@ -1143,47 +1143,31 @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
> bool two_stage_indirect)
> {
> CPUState *cs = env_cpu(env);
> - int page_fault_exceptions, vm;
> - uint64_t stap_mode;
> -
> - if (riscv_cpu_mxl(env) == MXL_RV32) {
> - stap_mode = SATP32_MODE;
> - } else {
> - stap_mode = SATP64_MODE;
> - }
> -
> - if (first_stage) {
> - vm = get_field(env->satp, stap_mode);
> - } else {
> - vm = get_field(env->hgatp, stap_mode);
> - }
> -
> - page_fault_exceptions = vm != VM_1_10_MBARE && !pmp_violation;
>
> switch (access_type) {
> case MMU_INST_FETCH:
> if (env->virt_enabled && !first_stage) {
> cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT;
> } else {
> - cs->exception_index = page_fault_exceptions ?
> - RISCV_EXCP_INST_PAGE_FAULT : RISCV_EXCP_INST_ACCESS_FAULT;
> + cs->exception_index = pmp_violation ?
> + RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT;
> }
> break;
> case MMU_DATA_LOAD:
> if (two_stage && !first_stage) {
> cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT;
> } else {
> - cs->exception_index = page_fault_exceptions ?
> - RISCV_EXCP_LOAD_PAGE_FAULT : RISCV_EXCP_LOAD_ACCESS_FAULT;
> + cs->exception_index = pmp_violation ?
> + RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT;
> }
> break;
> case MMU_DATA_STORE:
> if (two_stage && !first_stage) {
> cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT;
> } else {
> - cs->exception_index = page_fault_exceptions ?
> - RISCV_EXCP_STORE_PAGE_FAULT :
> - RISCV_EXCP_STORE_AMO_ACCESS_FAULT;
> + cs->exception_index = pmp_violation ?
> + RISCV_EXCP_STORE_AMO_ACCESS_FAULT :
> + RISCV_EXCP_STORE_PAGE_FAULT;
> }
> break;
> default:
> --
> 2.34.1
>
>
next prev parent reply other threads:[~2023-11-22 2:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-21 7:17 [PATCH v2 0/2] Fix mmu translation with H extension Ivan Klokov
2023-11-21 7:17 ` [PATCH v2 1/2] target/riscv/cpu_helper.c: Invalid exception on MMU translation stage Ivan Klokov
2023-11-21 12:54 ` Daniel Henrique Barboza
2023-11-22 2:04 ` Alistair Francis [this message]
2023-11-21 7:17 ` [PATCH v2 2/2] target/riscv/cpu_helper.c: Fix mxr bit behavior Ivan Klokov
2023-11-21 12:55 ` Daniel Henrique Barboza
2023-11-22 2:10 ` Alistair Francis
2023-11-22 2:30 ` [PATCH v2 0/2] Fix mmu translation with H extension 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=CAKmqyKOn3J7HqUcS2RLxE9dUJkUkKvmTySuA3EUDffPy__A6pA@mail.gmail.com \
--to=alistair23@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=bin.meng@windriver.com \
--cc=dbarboza@ventanamicro.com \
--cc=ivan.klokov@syntacore.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 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).