* [PATCH] kvm: clear kvmclock MSR on reset
@ 2019-10-10 10:50 Paolo Bonzini
2019-10-16 17:06 ` Vitaly Kuznetsov
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2019-10-10 10:50 UTC (permalink / raw)
To: linux-kernel, kvm; +Cc: vkuznets, suleiman
After resetting the vCPU, the kvmclock MSR keeps the previous value but it is
not enabled. This can be confusing, so fix it.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/x86.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index f26f8be4e621..a55252c69118 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2533,6 +2533,7 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
static void kvmclock_reset(struct kvm_vcpu *vcpu)
{
vcpu->arch.pv_time_enabled = false;
+ vcpu->arch.time = 0;
}
static void kvm_vcpu_flush_tlb(struct kvm_vcpu *vcpu, bool invalidate_gpa)
@@ -2698,8 +2699,6 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
case MSR_KVM_SYSTEM_TIME: {
struct kvm_arch *ka = &vcpu->kvm->arch;
- kvmclock_reset(vcpu);
-
if (vcpu->vcpu_id == 0 && !msr_info->host_initiated) {
bool tmp = (msr == MSR_KVM_SYSTEM_TIME);
@@ -2713,14 +2712,13 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
kvm_make_request(KVM_REQ_GLOBAL_CLOCK_UPDATE, vcpu);
/* we verify if the enable bit is set... */
+ vcpu->arch.pv_time_enabled = false;
if (!(data & 1))
break;
if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
&vcpu->arch.pv_time, data & ~1ULL,
sizeof(struct pvclock_vcpu_time_info)))
- vcpu->arch.pv_time_enabled = false;
- else
vcpu->arch.pv_time_enabled = true;
break;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kvm: clear kvmclock MSR on reset
2019-10-10 10:50 [PATCH] kvm: clear kvmclock MSR on reset Paolo Bonzini
@ 2019-10-16 17:06 ` Vitaly Kuznetsov
2019-10-21 17:19 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Vitaly Kuznetsov @ 2019-10-16 17:06 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: suleiman, linux-kernel, kvm
Paolo Bonzini <pbonzini@redhat.com> writes:
> After resetting the vCPU, the kvmclock MSR keeps the previous value but it is
> not enabled. This can be confusing, so fix it.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> arch/x86/kvm/x86.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index f26f8be4e621..a55252c69118 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2533,6 +2533,7 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
> static void kvmclock_reset(struct kvm_vcpu *vcpu)
> {
> vcpu->arch.pv_time_enabled = false;
> + vcpu->arch.time = 0;
> }
>
> static void kvm_vcpu_flush_tlb(struct kvm_vcpu *vcpu, bool invalidate_gpa)
> @@ -2698,8 +2699,6 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
> case MSR_KVM_SYSTEM_TIME: {
> struct kvm_arch *ka = &vcpu->kvm->arch;
>
> - kvmclock_reset(vcpu);
> -
> if (vcpu->vcpu_id == 0 && !msr_info->host_initiated) {
> bool tmp = (msr == MSR_KVM_SYSTEM_TIME);
>
> @@ -2713,14 +2712,13 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
> kvm_make_request(KVM_REQ_GLOBAL_CLOCK_UPDATE, vcpu);
>
> /* we verify if the enable bit is set... */
> + vcpu->arch.pv_time_enabled = false;
> if (!(data & 1))
> break;
>
> if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
> &vcpu->arch.pv_time, data & ~1ULL,
> sizeof(struct pvclock_vcpu_time_info)))
> - vcpu->arch.pv_time_enabled = false;
> - else
> vcpu->arch.pv_time_enabled = true;
Hm, are you sure you didn't want to write !kvm_gfn_to_hva_cache_init()?
>
> break;
--
Vitaly
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kvm: clear kvmclock MSR on reset
2019-10-16 17:06 ` Vitaly Kuznetsov
@ 2019-10-21 17:19 ` Paolo Bonzini
0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2019-10-21 17:19 UTC (permalink / raw)
To: Vitaly Kuznetsov; +Cc: suleiman, linux-kernel, kvm
On 16/10/19 19:06, Vitaly Kuznetsov wrote:
>> /* we verify if the enable bit is set... */
>> + vcpu->arch.pv_time_enabled = false;
>> if (!(data & 1))
>> break;
>>
>> if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
>> &vcpu->arch.pv_time, data & ~1ULL,
>> sizeof(struct pvclock_vcpu_time_info)))
>> - vcpu->arch.pv_time_enabled = false;
>> - else
>> vcpu->arch.pv_time_enabled = true;
Yes...
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-21 17:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-10 10:50 [PATCH] kvm: clear kvmclock MSR on reset Paolo Bonzini
2019-10-16 17:06 ` Vitaly Kuznetsov
2019-10-21 17:19 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).