From: ZhengXiang Qin <[email protected]> check_zicbom_access() currently treats any probe_access_flags() result other than TLB_INVALID_MASK as a successful access. However, a result with TLB_MMIO means that the target is MMIO-like and should not be treated as a normal cache block management target.
Raise a store/AMO access fault for Zicbom accesses to MMIO-like regions so that cbo.clean, cbo.flush and cbo.inval do not silently succeed on non-cacheable/MMIO-like memory. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3501 Fixes: e05da09b7cfd ("target/riscv: implement Zicbom extension") Reviewed-by: Daniel Henrique Barboza <[email protected]> Reviewed-by: Chao Liu <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: ZhengXiang Qin <[email protected]> Signed-off-by: Daniel Henrique Barboza <[email protected]> --- target/riscv/tcg/op_helper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/target/riscv/tcg/op_helper.c b/target/riscv/tcg/op_helper.c index d7af56ef61..52aa545eec 100644 --- a/target/riscv/tcg/op_helper.c +++ b/target/riscv/tcg/op_helper.c @@ -231,6 +231,7 @@ static void check_zicbom_access(CPURISCVState *env, { uint16_t cbomlen = riscv_cpu_cfg(env)->cbom_blocksize; int mmu_idx = riscv_env_mmu_index(env, false); + uint64_t fault_addr = address; void *phost; int ret; @@ -251,7 +252,10 @@ static void check_zicbom_access(CPURISCVState *env, */ ret = probe_access_flags(env, address, cbomlen, MMU_DATA_LOAD, mmu_idx, true, &phost, ra); - if (ret != TLB_INVALID_MASK) { + if (ret & TLB_MMIO) { + env->badaddr = fault_addr; + riscv_raise_exception(env, RISCV_EXCP_STORE_AMO_ACCESS_FAULT, ra); + } else if (ret != TLB_INVALID_MASK) { /* Success: readable */ return; } -- 2.43.0
