[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 21/27] target/riscv: prioritize pmp errors in raise_mmu_excepti
From: |
Alistair Francis |
Subject: |
[PULL v2 21/27] target/riscv: prioritize pmp errors in raise_mmu_exception() |
Date: |
Mon, 3 Jun 2024 21:16:37 +1000 |
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
raise_mmu_exception(), as is today, is prioritizing guest page faults by
checking first if virt_enabled && !first_stage, and then considering the
regular inst/load/store faults.
There's no mention in the spec about guest page fault being a higher
priority that PMP faults. In fact, privileged spec section 3.7.1 says:
"Attempting to fetch an instruction from a PMP region that does not have
execute permissions raises an instruction access-fault exception.
Attempting to execute a load or load-reserved instruction which accesses
a physical address within a PMP region without read permissions raises a
load access-fault exception. Attempting to execute a store,
store-conditional, or AMO instruction which accesses a physical address
within a PMP region without write permissions raises a store
access-fault exception."
So, in fact, we're doing it wrong - PMP faults should always be thrown,
regardless of also being a first or second stage fault.
The way riscv_cpu_tlb_fill() and get_physical_address() work is
adequate: a TRANSLATE_PMP_FAIL error is immediately reported and
reflected in the 'pmp_violation' flag. What we need is to change
raise_mmu_exception() to prioritize it.
Reported-by: Joseph Chan <jchan@ventanamicro.com>
Fixes: 82d53adfbb ("target/riscv/cpu_helper.c: Invalid exception on MMU
translation stage")
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20240413105929.7030-1-alexei.filippov@syntacore.com>
Cc: qemu-stable <qemu-stable@nongnu.org>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu_helper.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index d71245a8cb..574886a694 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -1177,28 +1177,30 @@ static void raise_mmu_exception(CPURISCVState *env,
target_ulong address,
switch (access_type) {
case MMU_INST_FETCH:
- if (env->virt_enabled && !first_stage) {
+ if (pmp_violation) {
+ cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT;
+ } else if (env->virt_enabled && !first_stage) {
cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT;
} else {
- cs->exception_index = pmp_violation ?
- RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT;
+ cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT;
}
break;
case MMU_DATA_LOAD:
- if (two_stage && !first_stage) {
+ if (pmp_violation) {
+ cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT;
+ } else if (two_stage && !first_stage) {
cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT;
} else {
- cs->exception_index = pmp_violation ?
- RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT;
+ cs->exception_index = RISCV_EXCP_LOAD_PAGE_FAULT;
}
break;
case MMU_DATA_STORE:
- if (two_stage && !first_stage) {
+ if (pmp_violation) {
+ cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT;
+ } else if (two_stage && !first_stage) {
cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT;
} else {
- cs->exception_index = pmp_violation ?
- RISCV_EXCP_STORE_AMO_ACCESS_FAULT :
- RISCV_EXCP_STORE_PAGE_FAULT;
+ cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT;
}
break;
default:
--
2.45.1
- [PULL v2 15/27] target/riscv: Implement dynamic establishment of custom decoder, (continued)
- [PULL v2 15/27] target/riscv: Implement dynamic establishment of custom decoder, Alistair Francis, 2024/06/03
- [PULL v2 13/27] target/riscv: Fix the element agnostic function problem, Alistair Francis, 2024/06/03
- [PULL v2 17/27] target/riscv: rvv: Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions, Alistair Francis, 2024/06/03
- [PULL v2 09/27] trans_privileged.c.inc: set (m|s)tval on ebreak breakpoint, Alistair Francis, 2024/06/03
- [PULL v2 18/27] target/riscv: rvv: Check single width operator for vector fp widen instructions, Alistair Francis, 2024/06/03
- [PULL v2 16/27] riscv: thead: Add th.sxstatus CSR emulation, Alistair Francis, 2024/06/03
- [PULL v2 19/27] target/riscv: rvv: Check single width operator for vfncvt.rod.f.f.w, Alistair Francis, 2024/06/03
- [PULL v2 20/27] target/riscv: rvv: Remove redudant SEW checking for vector fp narrow/widen instructions, Alistair Francis, 2024/06/03
- [PULL v2 22/27] target/riscv: do not set mtval2 for non guest-page faults, Alistair Francis, 2024/06/03
- [PULL v2 23/27] target/riscv: Remove experimental prefix from "B" extension, Alistair Francis, 2024/06/03
- [PULL v2 21/27] target/riscv: prioritize pmp errors in raise_mmu_exception(),
Alistair Francis <=
- [PULL v2 24/27] target/riscv: rvzicbo: Fixup CBO extension register calculation, Alistair Francis, 2024/06/03
- [PULL v2 26/27] riscv, gdbstub.c: fix reg_width in ricsv_gen_dynamic_vector_feature(), Alistair Francis, 2024/06/03
- [PULL v2 27/27] disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs, Alistair Francis, 2024/06/03
- [PULL v2 25/27] target/riscv/kvm.c: Fix the hart bit setting of AIA, Alistair Francis, 2024/06/03
- Re: [PULL v2 00/27] riscv-to-apply queue, Philippe Mathieu-Daudé, 2024/06/03
- Re: [PULL v2 00/27] riscv-to-apply queue, Richard Henderson, 2024/06/04