On Fri, 2026-09-04 at 14:43 -0400, Trevor Gamblin wrote: > Create a new function to encapsulate the privilege/hypervisor checks > performed inside helper_tlb_flush(). The idea is to pass GETPC() as > an > argument directly to it inside the helper_tlb_flush() function. We'll > use this function in the following patch for helper_tlb_flush_page(). > > Signed-off-by: Trevor Gamblin <[email protected]>
Reviewed-by: Alistair Francis <[email protected]> Alistair > --- > target/riscv/tcg/op_helper.c | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > diff --git a/target/riscv/tcg/op_helper.c > b/target/riscv/tcg/op_helper.c > index 3e94005d2b..7f63f3ada5 100644 > --- a/target/riscv/tcg/op_helper.c > +++ b/target/riscv/tcg/op_helper.c > @@ -588,21 +588,25 @@ void helper_wrs_nto(CPURISCVState *env) > } > } > > -void helper_tlb_flush(CPURISCVState *env) > +static void check_sfence_vma(CPURISCVState *env, uintptr_t ra) > { > - CPUState *cs = env_cpu(env); > if (!env->virt_enabled && > (env->priv == PRV_U || > (env->priv == PRV_S && get_field(env->mstatus, > MSTATUS_TVM)))) { > - riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, > GETPC()); > + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, ra); > } else if (env->virt_enabled && > (env->priv == PRV_U || get_field(env->hstatus, > HSTATUS_VTVM))) { > - riscv_raise_exception(env, > RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC()); > - } else { > - tlb_flush(cs); > + riscv_raise_exception(env, > RISCV_EXCP_VIRT_INSTRUCTION_FAULT, ra); > } > } > > +void helper_tlb_flush(CPURISCVState *env) > +{ > + CPUState *cs = env_cpu(env); > + check_sfence_vma(env, GETPC()); > + tlb_flush(cs); > +} > + > void helper_tlb_flush_all(CPURISCVState *env) > { > CPUState *cs = env_cpu(env);
