On Wed, Apr 27, 2022, Paolo Bonzini wrote:
Right now, the VMX preemption timer is special cased via the hv_timer_pending, but the purpose of the callback can be easily extended to observing any event that can occur only in non-root mode. Interrupts, NMIs etc. are already handled properly by the *_interrupt_allowed callbacks, so what is missing is only MTF. Check it in the newly-renamed callback, so that kvm_vcpu_running's call to kvm_check_nested_events becomes redundant.
Cc: stable@vger.kernel.org Reported-by: Maxim Levitsky mlevitsk@redhat.com Signed-off-by: Paolo Bonzini pbonzini@redhat.com
arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/vmx/nested.c | 7 ++++++- arch/x86/kvm/x86.c | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 4ff36610af6a..e2e4f60159e9 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1504,7 +1504,7 @@ struct kvm_x86_ops { struct kvm_x86_nested_ops { void (*leave_nested)(struct kvm_vcpu *vcpu); int (*check_events)(struct kvm_vcpu *vcpu);
- bool (*hv_timer_pending)(struct kvm_vcpu *vcpu);
- bool (*has_events)(struct kvm_vcpu *vcpu); void (*triple_fault)(struct kvm_vcpu *vcpu); int (*get_state)(struct kvm_vcpu *vcpu, struct kvm_nested_state __user *user_kvm_nested_state,
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 856c87563883..54672025c3a1 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3857,6 +3857,11 @@ static bool nested_vmx_preemption_timer_pending(struct kvm_vcpu *vcpu) to_vmx(vcpu)->nested.preemption_timer_expired; } +static bool vmx_has_nested_events(struct kvm_vcpu *vcpu) +{
- return nested_vmx_preemption_timer_pending(vcpu) || vmx->nested.mtf_pending;
This doesn't even compile...
arch/x86/kvm/vmx/nested.c: In function ‘vmx_has_nested_events’: arch/x86/kvm/vmx/nested.c:3862:61: error: ‘vmx’ undeclared (first use in this function) 3862 | return nested_vmx_preemption_timer_pending(vcpu) || vmx->nested.mtf_pending; | ^~~ arch/x86/kvm/vmx/nested.c:3862:61: note: each undeclared identifier is reported only once for each function it appears in CC [M] arch/x86/kvm/svm/svm_onhyperv.o arch/x86/kvm/vmx/nested.c:3863:1: error: control reaches end of non-void function [-Werror=return-type] 3863 | } | ^ cc1: all warnings being treated as errors LD [M] arch/x86/kvm/kvm.o