On Thu, Apr 18, 2024, Thomas Prescher wrote: > On Wed, 2024-04-17 at 09:28 -0700, Sean Christopherson wrote: > > On Wed, Apr 17, 2024, Sean Christopherson wrote: > > > On Wed, Apr 17, 2024, Thomas Prescher wrote: > > > > On Tue, 2024-04-16 at 11:07 -0700, Sean Christopherson wrote: > > > > > Hur dur, I forgot that KVM provides a "guest_mode" stat. > > > > > Userspace can do > > > > > KVM_GET_STATS_FD on the vCPU FD to get a file handle to the > > > > > binary stats, > > > > > and then you wouldn't need to call back into KVM just to query > > > > > guest_mode. > > > > > > > > > > Ah, and I also forgot that we have kvm_run.flags, so adding > > > > > KVM_RUN_X86_GUEST_MODE would also be trivial (I almost > > > > > suggested it > > > > > earlier, but didn't want to add a new field to kvm_run without > > > > > a very good > > > > > reason). > > > > > > > > Thanks for the pointers. This is really helpful. > > > > > > > > I tried the "guest_mode" stat as you suggested and it solves the > > > > immediate issue we have with VirtualBox/KVM. > > > > > > Note, > > > > Gah, got distracted. I was going to say that we should add > > KVM_RUN_X86_GUEST_MODE, > > because stats aren't guaranteed ABI[*], i.e. relying on guest_mode > > could prove > > problematic in the long run (though that's unlikely). > > > > [*] > > https://lore.kernel.org/all/CABgObfZ4kqaXLaOAOj4aGB5GAe9GxOmJmOP+7kdke6OqA35HzA@xxxxxxxxxxxxxx > > Allright. I will propose a patch that sets the KVM_RUN_X86_GUEST_MODE > flag in the next couple of days. Do we also need a new capability for > this flag so userland can query whether this field is actually updated > by KVM? Hmm, yeah, I don't see any way around that.