Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1268069

Re: [PATCH] KVM: svm: add support for RDTSCP

From Paolo Bonzini <pbonzini@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH] KVM: svm: add support for RDTSCP
Date 2015-11-12 17:20 +0100
Message-ID <qu2Ln-2J4-9@gated-at.bofh.it> (permalink)
References <qu0qe-16P-7@gated-at.bofh.it> <qu1mi-1Ij-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



On 12/11/2015 15:45, Joerg Roedel wrote:
> Hi Paolo,
> 
> On Thu, Nov 12, 2015 at 02:49:16PM +0100, Paolo Bonzini wrote:
>> RDTSCP was never supported for AMD CPUs, which nobody noticed because
>> Linux does not use it.  But exactly the fact that Linux does not
>> use it makes the implementation very simple; we can freely trash
>> MSR_TSC_AUX while running the guest.
>>
>> Cc: Joerg Roedel <joro@8bytes.org>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  arch/x86/kvm/svm.c | 24 +++++++++++++++++++++++-
>>  1 file changed, 23 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
>> index 83a1c64..c302614 100644
>> --- a/arch/x86/kvm/svm.c
>> +++ b/arch/x86/kvm/svm.c
>> @@ -86,6 +86,7 @@ static const u32 host_save_user_msrs[] = {
>>  	MSR_FS_BASE,
>>  #endif
>>  	MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP,
>> +	MSR_TSC_AUX,
>>  };
>>  
>>  #define NR_HOST_SAVE_USER_MSRS ARRAY_SIZE(host_save_user_msrs)
>> @@ -135,6 +136,7 @@ struct vcpu_svm {
>>  	uint64_t asid_generation;
>>  	uint64_t sysenter_esp;
>>  	uint64_t sysenter_eip;
>> +	uint64_t tsc_aux;
>>  
>>  	u64 next_rip;
>>  
>> @@ -1238,6 +1240,9 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
>>  			wrmsrl(MSR_AMD64_TSC_RATIO, tsc_ratio);
>>  		}
>>  	}
>> +	/* This assumes that the kernel never uses MSR_TSC_AUX */
>> +	if (static_cpu_has(X86_FEATURE_RDTSCP))
>> +		wrmsrl(MSR_TSC_AUX, svm->tsc_aux);
>>  }
> 
> Hmm, you seem to still intercept MSR_TSC_AUX, is that intentional?

Yes.  If I didn't intercept MSR_TSC_AUX, I would have to read it into
svm->tsc_aux on every svm_vcpu_put.  Because writing MSR_TSC_AUX is a
rare operation, I intercept the write, and update both svm->tsc_aux and
the processor MSR_TSC_AUX in svm_set_msr.

This is different from other host_save_msrs because the processor does
not save MSR_TSC_AUX automatically in the VMCB.  As remarked above, it
only works because the kernel never uses RDTSCP.

> Loading the guests value into the real cpu msr only makes sense to me
> when the MSR is no longer intercepted.

It's necessary for the correct operation of RDTSCP.  Since we don't
intercept RDTSCP, we need to load MSR_TSC_AUX.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH] KVM: svm: add support for RDTSCP Paolo Bonzini <pbonzini@redhat.com> - 2015-11-12 14:50 +0100
  [PATCH] KVM: x86: expose MSR_TSC_AUX to userspace Paolo Bonzini <pbonzini@redhat.com> - 2015-11-12 14:50 +0100
    Re: [PATCH] KVM: x86: expose MSR_TSC_AUX to userspace Paolo Bonzini <pbonzini@redhat.com> - 2015-11-13 10:50 +0100
      Re: [PATCH] KVM: x86: expose MSR_TSC_AUX to userspace Peter Hornyack <peterhornyack@google.com> - 2015-11-13 18:50 +0100
  Re: [PATCH] KVM: svm: add support for RDTSCP Joerg Roedel <joro@8bytes.org> - 2015-11-12 15:50 +0100
    Re: [PATCH] KVM: svm: add support for RDTSCP Paolo Bonzini <pbonzini@redhat.com> - 2015-11-12 17:20 +0100

csiph-web