[PATCH v2 3/3] RISC-V: KVM: Reset the SBI extension when disable it

Inochi Amaoto inochiama at gmail.com
Wed Jul 29 15:33:45 PDT 2026


On Wed, Jul 29, 2026 at 01:32:40PM +0530, Anup Patel wrote:
> On Mon, Jul 6, 2026 at 7:42 AM Inochi Amaoto <inochiama at gmail.com> wrote:
> >
> > The SBI extension validation callback can only fix the parameter if
> > the extension is enabled. However, if the extension is disabled after
> > modifty some parameters, the state of the extension is still broken.
> >
> > Reset the extension when the extenion is disabled so it can have
> 
> s/extenion/extension/
> 
> > a clear context.
> >
> > Signed-off-by: Inochi Amaoto <inochiama at gmail.com>
> > ---
> >  arch/riscv/kvm/vcpu_sbi.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c
> > index b737e9a7a12a..3eb7b7c57059 100644
> > --- a/arch/riscv/kvm/vcpu_sbi.c
> > +++ b/arch/riscv/kvm/vcpu_sbi.c
> > @@ -221,6 +221,7 @@ static int riscv_vcpu_set_sbi_ext_single(struct kvm_vcpu *vcpu,
> >  {
> >         struct kvm_vcpu_sbi_context *scontext = &vcpu->arch.sbi_context;
> >         const struct kvm_riscv_sbi_extension_entry *sext;
> > +       const struct kvm_vcpu_sbi_extension *ext;
> >
> >         if (reg_val != 1 && reg_val != 0)
> >                 return -EINVAL;
> > @@ -229,6 +230,15 @@ static int riscv_vcpu_set_sbi_ext_single(struct kvm_vcpu *vcpu,
> >         if (!sext || scontext->ext_status[sext->ext_idx] == KVM_RISCV_SBI_EXT_STATUS_UNAVAILABLE)
> >                 return -ENOENT;
> >
> > +       ext = sext->ext_ptr;
> > +
> > +       if (!reg_val && scontext->ext_status[sext->ext_idx] == KVM_RISCV_SBI_EXT_STATUS_ENABLED) {
> > +               if (ext->reset) {
> > +                       ext->reset(vcpu);
> > +                       vcpu->arch.csr_dirty = true;
> 
> Let's not blindly set "csr_dirty" when any SBI extension is disabled,
> instead we should set "csr_dirtry" in kvm_sbi_ext_fwft_reset() (just
> like we do in kvm_sbi_ext_fwft_set_reg()).
> 

Good, I will move this line to the kvm_sbi_ext_fwft_reset() in the new version.

> > +               }
> > +       }
> > +
> >         scontext->ext_status[sext->ext_idx] = (reg_val) ?
> >                         KVM_RISCV_SBI_EXT_STATUS_ENABLED :
> >                         KVM_RISCV_SBI_EXT_STATUS_DISABLED;
> > --
> > 2.55.0
> >
> 
> Regards,
> Anup
> 

Regards,
Inochi



More information about the linux-riscv mailing list