mbox series

[v2,0/2] Cleanup VMFUNC handling in KVM.

Message ID 20221109075413.1405803-1-yu.c.zhang@linux.intel.com (mailing list archive)
Headers show
Series Cleanup VMFUNC handling in KVM. | expand

Message

Yu Zhang Nov. 9, 2022, 7:54 a.m. UTC
Since VMFUNC is not supported for non-nested guests, and executing VMFUNC
can cause a #UD directly, if the “enable VM functions” VM-execution control
is 0, KVM can just disable it in VM-exectution control, instead of taking
pains to trap it and emulate the #UD for L1 guests.

Also, simplified the process of setting SECONDARY_EXEC_ENABLE_VMFUNC for
nested VMX MSR configurations.

Change log:
==========
v1->v2
- Split the patch into two pieces.
- Use KVM_BUG_ON() for unexpected VM Exits.
- Comments changes.
- Commit message changes, trying to better illustrate the reason.

Yu Zhang (2):
  KVM: VMX: Do not trap VMFUNC instructions for L1 guests.
  KVM: nVMX: Simplify the setting of SECONDARY_EXEC_ENABLE_VMFUNC for
    nested.

 arch/x86/kvm/vmx/nested.c | 26 ++++++++++----------------
 arch/x86/kvm/vmx/vmx.c    |  7 ++++++-
 2 files changed, 16 insertions(+), 17 deletions(-)

Comments

Yu Zhang Nov. 17, 2022, 9:55 a.m. UTC | #1
On Wed, Nov 09, 2022 at 03:54:11PM +0800, Yu Zhang wrote:

Ping... Thanks!

B.R.
Yu
Sean Christopherson Feb. 8, 2023, 2:02 a.m. UTC | #2
On Wed, 09 Nov 2022 15:54:11 +0800, Yu Zhang wrote:
> Since VMFUNC is not supported for non-nested guests, and executing VMFUNC
> can cause a #UD directly, if the “enable VM functions” VM-execution control
> is 0, KVM can just disable it in VM-exectution control, instead of taking
> pains to trap it and emulate the #UD for L1 guests.
> 
> Also, simplified the process of setting SECONDARY_EXEC_ENABLE_VMFUNC for
> nested VMX MSR configurations.
> 
> [...]

After much waffling, applied to kvm-x86 vmx.  I ended up keeping the logic to
inject #UD on now-unexpected VMFUNC exits from L1, i.e. patch one does nothing
more than clear the control bit.  I like the idea of clearing the control bit as
it more explicitly documents what's going on, but killing the VM on an unexpected
exit that KVM can gracefully handle seemed unnecessary.

Thanks!

[1/2] KVM: VMX: Do not trap VMFUNC instructions for L1 guests.
      https://github.com/kvm-x86/linux/commit/41acdd419735
[2/2] KVM: nVMX: Simplify the setting of SECONDARY_EXEC_ENABLE_VMFUNC for nested.
      https://github.com/kvm-x86/linux/commit/496c917b0989

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes
Yu Zhang Feb. 8, 2023, 6:28 a.m. UTC | #3
> 
> After much waffling, applied to kvm-x86 vmx.  I ended up keeping the logic to
> inject #UD on now-unexpected VMFUNC exits from L1, i.e. patch one does nothing
> more than clear the control bit.  I like the idea of clearing the control bit as
> it more explicitly documents what's going on, but killing the VM on an unexpected
> exit that KVM can gracefully handle seemed unnecessary.

Glad to know that. Thanks!

B.R.
Yu