diff mbox series

[1/3] KVM: nVMX: Really make emulated nested preemption timer pinned

Message ID 20200508203643.85477-2-jmattson@google.com (mailing list archive)
State New, archived
Headers show
Series Pin the hrtimer used for VMX-preemption timer emulation | expand

Commit Message

Jim Mattson May 8, 2020, 8:36 p.m. UTC
The PINNED bit is ignored by hrtimer_init. It is only considered when
starting the timer.

When the hrtimer isn't pinned to the same logical processor as the
vCPU thread to be interrupted, the emulated VMX-preemption timer
often fails to adhere to the architectural specification.

Fixes: f15a75eedc18e ("KVM: nVMX: make emulated nested preemption timer pinned")
Signed-off-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Peter Shier <pshier@google.com>
Reviewed-by: Oliver Upton <oupton@google.com>
---
 arch/x86/kvm/vmx/nested.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Sean Christopherson May 8, 2020, 10:16 p.m. UTC | #1
LOL, love the shortlog :-)

On Fri, May 08, 2020 at 01:36:41PM -0700, Jim Mattson wrote:
> The PINNED bit is ignored by hrtimer_init. It is only considered when
> starting the timer.
> 
> When the hrtimer isn't pinned to the same logical processor as the
> vCPU thread to be interrupted, the emulated VMX-preemption timer
> often fails to adhere to the architectural specification.
> 
> Fixes: f15a75eedc18e ("KVM: nVMX: make emulated nested preemption timer pinned")
> Signed-off-by: Jim Mattson <jmattson@google.com>
> Reviewed-by: Peter Shier <pshier@google.com>
> Reviewed-by: Oliver Upton <oupton@google.com>
> ---
>  arch/x86/kvm/vmx/nested.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index fd78ffbde644..1f7fe6f47cbc 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -2041,7 +2041,7 @@ static void vmx_start_preemption_timer(struct kvm_vcpu *vcpu)
>  	preemption_timeout *= 1000000;
>  	do_div(preemption_timeout, vcpu->arch.virtual_tsc_khz);
>  	hrtimer_start(&vmx->nested.preemption_timer,
> -		      ns_to_ktime(preemption_timeout), HRTIMER_MODE_REL);
> +		      ns_to_ktime(preemption_timeout), HRTIMER_MODE_REL_PINNED);
>  }
>  
>  static u64 nested_vmx_calc_efer(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)
> -- 
> 2.26.2.645.ge9eca65c58-goog
>
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index fd78ffbde644..1f7fe6f47cbc 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -2041,7 +2041,7 @@  static void vmx_start_preemption_timer(struct kvm_vcpu *vcpu)
 	preemption_timeout *= 1000000;
 	do_div(preemption_timeout, vcpu->arch.virtual_tsc_khz);
 	hrtimer_start(&vmx->nested.preemption_timer,
-		      ns_to_ktime(preemption_timeout), HRTIMER_MODE_REL);
+		      ns_to_ktime(preemption_timeout), HRTIMER_MODE_REL_PINNED);
 }
 
 static u64 nested_vmx_calc_efer(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)