Re: [PATCH 1/2] X86/KVM: Properly update 'tsc_offset' to represent the running guest

From: Paolo Bonzini
Date: Fri Apr 13 2018 - 11:35:22 EST


On 13/04/2018 14:40, Raslan, KarimAllah wrote:
>>
>> static void update_ia32_tsc_adjust_msr(struct kvm_vcpu *vcpu, s64 offset)
>> {
>> - u64 curr_offset = vcpu->arch.tsc_offset;
>> + u64 curr_offset = kvm_x86_ops->read_l1_tsc_offset(vcpu);
> I might be missing something but is this really strictly needed or is
> it really a bug?
>
> I can seeÂupdate_ia32_tsc_adjust_msrÂcalled fromÂkvm_write_tsc onlyÂ
> which is called from a)Âvmx_set_msr or b)Âkvm_arch_vcpu_postcreate.
> The adjust_msr would only be called if !host_initiated. So onlyÂ
> vmx_set_msr which is coming from an L1 write (or a restore but that
> would not be !host_initiated). So the only that tsc_adjust is called is
> !is_guest_mode.

It can also be called from guest mode if the MSR bitmap says there's no
L1 vmexit for that MSR; that's what the testcases do.

Paolo

>> vcpu->arch.ia32_tsc_adjust_msr += offset - curr_offset;