On Thu, Mar 20, 2025, Atish Kumar Patra wrote: > On Mon, Mar 17, 2025 at 9:08 AM Sean Christopherson <seanjc@xxxxxxxxxx> wrote: > > On Mon, Mar 17, 2025, Atish Patra wrote: > > > arch/riscv/kvm/main.c | 4 ++-- > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c > > > index 1fa8be5ee509..4b24705dc63a 100644 > > > --- a/arch/riscv/kvm/main.c > > > +++ b/arch/riscv/kvm/main.c > > > @@ -172,8 +172,8 @@ module_init(riscv_kvm_init); > > > > > > static void __exit riscv_kvm_exit(void) > > > { > > > - kvm_riscv_teardown(); > > > - > > > kvm_exit(); > > > + > > > + kvm_riscv_teardown(); > > > > I wonder if there's a way we can guard against kvm_init()/kvm_exit() being called > > too early/late. x86 had similar bugs for a very long time, e.g. see commit > > e32b120071ea ("KVM: VMX: Do _all_ initialization before exposing /dev/kvm to userspace"). > > > > E.g. maybe we do something like create+destroy a VM at the end of kvm_init() and > > the beginning of kvm_exit()? Not sure if that would work for kvm_exit(), but it > > should definitely be fine for kvm_init(). > > > Yes. That would be super useful. I am not sure about the exact > mechanism to achieve that though. Me either :-) > Do you just test code guarded within a new config that just > creates/destroys a dummy VM ? That's only idea I could come up with too, but I don't particulary like it. > May be kunit test for KVM fits here in some way ? I don't think a kunit test would be a good fit, there are likely too many dependencies, and I'm pretty sure we'd still need to hack KVM.