diff mbox series

kvm: vmx: Allow guest read access to IA32_TSC

Message ID 20181109173511.178056-1-jmattson@google.com (mailing list archive)
State New, archived
Headers show
Series kvm: vmx: Allow guest read access to IA32_TSC | expand

Commit Message

Jim Mattson Nov. 9, 2018, 5:35 p.m. UTC
Let the guest read the IA32_TSC MSR with the generic RDMSR instruction
as well as the specific RDTSC(P) instructions. Note that the hardware
applies the TSC multiplier and offset (when applicable) to the result of
RDMSR(IA32_TSC), just as it does to the result of RDTSC(P).

Signed-off-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Peter Shier <pshier@google.com>
Reviewed-by: Marc Orr <marcorr@google.com>
---
 arch/x86/kvm/vmx.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Liran Alon Nov. 9, 2018, 6:24 p.m. UTC | #1
> On 9 Nov 2018, at 19:35, Jim Mattson <jmattson@google.com> wrote:
> 
> Let the guest read the IA32_TSC MSR with the generic RDMSR instruction
> as well as the specific RDTSC(P) instructions. Note that the hardware
> applies the TSC multiplier and offset (when applicable) to the result of
> RDMSR(IA32_TSC), just as it does to the result of RDTSC(P).

Yep.
This is explicitly specified in Intel SDM 25.3 CHANGES TO INSTRUCTIONS BEHAVIOR IN VMX NON-ROOT OPERATION
at the RDMSR bullet.

> 
> Signed-off-by: Jim Mattson <jmattson@google.com>
> Reviewed-by: Peter Shier <pshier@google.com>
> Reviewed-by: Marc Orr <marcorr@google.com>
> ---
> arch/x86/kvm/vmx.c | 1 +
> 1 file changed, 1 insertion(+)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index ccc6a01eb4f4..b9602d000fbf 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -11521,6 +11521,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
> 		goto free_msrs;
> 
> 	msr_bitmap = vmx->vmcs01.msr_bitmap;
> +	vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_TSC, MSR_TYPE_R);
> 	vmx_disable_intercept_for_msr(msr_bitmap, MSR_FS_BASE, MSR_TYPE_RW);
> 	vmx_disable_intercept_for_msr(msr_bitmap, MSR_GS_BASE, MSR_TYPE_RW);
> 	vmx_disable_intercept_for_msr(msr_bitmap, MSR_KERNEL_GS_BASE, MSR_TYPE_RW);
> -- 
> 2.19.1.930.g4563a0d9d0-goog
> 

Reviewed-by: Liran Alon <liran.alon@oracle.com>
Radim Krčmář Dec. 20, 2018, 8:20 p.m. UTC | #2
2018-11-09 09:35-0800, Jim Mattson:
> Let the guest read the IA32_TSC MSR with the generic RDMSR instruction
> as well as the specific RDTSC(P) instructions. Note that the hardware
> applies the TSC multiplier and offset (when applicable) to the result of
> RDMSR(IA32_TSC), just as it does to the result of RDTSC(P).
> 
> Signed-off-by: Jim Mattson <jmattson@google.com>
> Reviewed-by: Peter Shier <pshier@google.com>
> Reviewed-by: Marc Orr <marcorr@google.com>
> ---

Queued, thanks.
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index ccc6a01eb4f4..b9602d000fbf 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -11521,6 +11521,7 @@  static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
 		goto free_msrs;
 
 	msr_bitmap = vmx->vmcs01.msr_bitmap;
+	vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_TSC, MSR_TYPE_R);
 	vmx_disable_intercept_for_msr(msr_bitmap, MSR_FS_BASE, MSR_TYPE_RW);
 	vmx_disable_intercept_for_msr(msr_bitmap, MSR_GS_BASE, MSR_TYPE_RW);
 	vmx_disable_intercept_for_msr(msr_bitmap, MSR_KERNEL_GS_BASE, MSR_TYPE_RW);