* [PATCH 1/2] KVM: lapic: fix preemption timer backward when TSC backward
@ 2016-08-30 8:14 Wanpeng Li
2016-08-30 8:14 ` [PATCH 2/2] KVM: nVMX: make emulated nested preemption timer pinned Wanpeng Li
2016-09-02 10:48 ` [PATCH 1/2] KVM: lapic: fix preemption timer backward when TSC backward Paolo Bonzini
0 siblings, 2 replies; 4+ messages in thread
From: Wanpeng Li @ 2016-08-30 8:14 UTC (permalink / raw)
To: linux-kernel, kvm
Cc: Wanpeng Li, Paolo Bonzini, Radim Krčmář, Yunhong Jiang
From: Wanpeng Li <wanpeng.li@hotmail.com>
TSC_OFFSET will be adjusted if discovers TSC backward during vCPU load.
The preemption timer which will leverage guest tsc to reprogram its
preemption timer value is also reprogrammed if vCPU is scheded in to
a different pCPU. However, current implementation reprogram preemption
timer before TSC_OFFSET is adjusted to the right value, this will result
in preemption timer also backward and fire prematurity.
This patch fix it by adjusting TSC_OFFSET before reprogramming preemption
timer if TSC backward.
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Yunhong Jiang <yunhong.jiang@intel.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
arch/x86/kvm/x86.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 19f9f9e..699f872 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2743,16 +2743,16 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
if (tsc_delta < 0)
mark_tsc_unstable("KVM discovered backwards TSC");
- if (kvm_lapic_hv_timer_in_use(vcpu) &&
- kvm_x86_ops->set_hv_timer(vcpu,
- kvm_get_lapic_tscdeadline_msr(vcpu)))
- kvm_lapic_switch_to_sw_timer(vcpu);
if (check_tsc_unstable()) {
u64 offset = kvm_compute_tsc_offset(vcpu,
vcpu->arch.last_guest_tsc);
kvm_x86_ops->write_tsc_offset(vcpu, offset);
vcpu->arch.tsc_catchup = 1;
}
+ if (kvm_lapic_hv_timer_in_use(vcpu) &&
+ kvm_x86_ops->set_hv_timer(vcpu,
+ kvm_get_lapic_tscdeadline_msr(vcpu)))
+ kvm_lapic_switch_to_sw_timer(vcpu);
/*
* On a host with synchronized TSC, there is no need to update
* kvmclock on vcpu->cpu migration
--
1.9.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] KVM: nVMX: make emulated nested preemption timer pinned
2016-08-30 8:14 [PATCH 1/2] KVM: lapic: fix preemption timer backward when TSC backward Wanpeng Li
@ 2016-08-30 8:14 ` Wanpeng Li
2016-09-02 10:48 ` Paolo Bonzini
2016-09-02 10:48 ` [PATCH 1/2] KVM: lapic: fix preemption timer backward when TSC backward Paolo Bonzini
1 sibling, 1 reply; 4+ messages in thread
From: Wanpeng Li @ 2016-08-30 8:14 UTC (permalink / raw)
To: linux-kernel, kvm
Cc: Wanpeng Li, Paolo Bonzini, Radim Krčmář, Yunhong Jiang
From: Wanpeng Li <wanpeng.li@hotmail.com>
Commit 61abdbe0bc ("kvm: x86: make lapic hrtimer pinned") pins the emulated
lapic timer. This patch does the same for the emulated nested preemption
timer to avoid vmexit an unrelated vCPU and the latency of kicking IPI to
another vCPU.
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Yunhong Jiang <yunhong.jiang@intel.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
arch/x86/kvm/vmx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 5cede40..090a3f8 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -7013,7 +7013,7 @@ static int handle_vmon(struct kvm_vcpu *vcpu)
vmx->nested.vmcs02_num = 0;
hrtimer_init(&vmx->nested.preemption_timer, CLOCK_MONOTONIC,
- HRTIMER_MODE_REL);
+ HRTIMER_MODE_REL_PINNED);
vmx->nested.preemption_timer.function = vmx_preemption_timer_fn;
vmx->nested.vmxon = true;
--
1.9.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] KVM: nVMX: make emulated nested preemption timer pinned
2016-08-30 8:14 ` [PATCH 2/2] KVM: nVMX: make emulated nested preemption timer pinned Wanpeng Li
@ 2016-09-02 10:48 ` Paolo Bonzini
0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2016-09-02 10:48 UTC (permalink / raw)
To: Wanpeng Li, linux-kernel, kvm
Cc: Wanpeng Li, Radim Krčmář, Yunhong Jiang
On 30/08/2016 10:14, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
>
> Commit 61abdbe0bc ("kvm: x86: make lapic hrtimer pinned") pins the emulated
> lapic timer. This patch does the same for the emulated nested preemption
> timer to avoid vmexit an unrelated vCPU and the latency of kicking IPI to
> another vCPU.
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: Yunhong Jiang <yunhong.jiang@intel.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
> arch/x86/kvm/vmx.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 5cede40..090a3f8 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -7013,7 +7013,7 @@ static int handle_vmon(struct kvm_vcpu *vcpu)
> vmx->nested.vmcs02_num = 0;
>
> hrtimer_init(&vmx->nested.preemption_timer, CLOCK_MONOTONIC,
> - HRTIMER_MODE_REL);
> + HRTIMER_MODE_REL_PINNED);
> vmx->nested.preemption_timer.function = vmx_preemption_timer_fn;
>
> vmx->nested.vmxon = true;
>
Queued for 4.9, thanks.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] KVM: lapic: fix preemption timer backward when TSC backward
2016-08-30 8:14 [PATCH 1/2] KVM: lapic: fix preemption timer backward when TSC backward Wanpeng Li
2016-08-30 8:14 ` [PATCH 2/2] KVM: nVMX: make emulated nested preemption timer pinned Wanpeng Li
@ 2016-09-02 10:48 ` Paolo Bonzini
1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2016-09-02 10:48 UTC (permalink / raw)
To: Wanpeng Li, linux-kernel, kvm
Cc: Wanpeng Li, Radim Krčmář, Yunhong Jiang
On 30/08/2016 10:14, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
>
> TSC_OFFSET will be adjusted if discovers TSC backward during vCPU load.
> The preemption timer which will leverage guest tsc to reprogram its
> preemption timer value is also reprogrammed if vCPU is scheded in to
> a different pCPU. However, current implementation reprogram preemption
> timer before TSC_OFFSET is adjusted to the right value, this will result
> in preemption timer also backward and fire prematurity.
>
> This patch fix it by adjusting TSC_OFFSET before reprogramming preemption
> timer if TSC backward.
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: Yunhong Jiang <yunhong.jiang@intel.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
> arch/x86/kvm/x86.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 19f9f9e..699f872 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2743,16 +2743,16 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
> if (tsc_delta < 0)
> mark_tsc_unstable("KVM discovered backwards TSC");
>
> - if (kvm_lapic_hv_timer_in_use(vcpu) &&
> - kvm_x86_ops->set_hv_timer(vcpu,
> - kvm_get_lapic_tscdeadline_msr(vcpu)))
> - kvm_lapic_switch_to_sw_timer(vcpu);
> if (check_tsc_unstable()) {
> u64 offset = kvm_compute_tsc_offset(vcpu,
> vcpu->arch.last_guest_tsc);
> kvm_x86_ops->write_tsc_offset(vcpu, offset);
> vcpu->arch.tsc_catchup = 1;
> }
> + if (kvm_lapic_hv_timer_in_use(vcpu) &&
> + kvm_x86_ops->set_hv_timer(vcpu,
> + kvm_get_lapic_tscdeadline_msr(vcpu)))
> + kvm_lapic_switch_to_sw_timer(vcpu);
> /*
> * On a host with synchronized TSC, there is no need to update
> * kvmclock on vcpu->cpu migration
>
Queued for 4.8, thanks.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-09-02 10:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-30 8:14 [PATCH 1/2] KVM: lapic: fix preemption timer backward when TSC backward Wanpeng Li
2016-08-30 8:14 ` [PATCH 2/2] KVM: nVMX: make emulated nested preemption timer pinned Wanpeng Li
2016-09-02 10:48 ` Paolo Bonzini
2016-09-02 10:48 ` [PATCH 1/2] KVM: lapic: fix preemption timer backward when TSC backward Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®