Fix MSR_IA32_PERF_STATUS
cover Fix MSR_IA32_PERF_STATUS
MSR_IA32_PERF_STATUS is read-only, yet exposed for save/restore. This generates annoying printk()s when userspace attempts to initialize it.
The value returned is also bogus, the comments appear to refer to another msr.
Fix both issues. Alex, please test with a guest Mac.
Avi Kivity (2):
KVM: Don't save/restore MSR_IA32_PERF_STATUS
KVM: Fix bogus value returned for MSR_IA32_PERF_STATUS
arch/x86/kvm/x86.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
PATCH 1/2 KVM: Don't save/restore MSR_IA32_PERF_STATUS
It is read/only; restoring it only results in annoying messages.
--- arch/x86/kvm/x86.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +1 -1
@@ -739,7 +739,7 @@ static u32 msrs_to_save[] = {#ifdef CONFIG_X86_64 MSR_CSTAR ,MSR_KERNEL_GS_BASE ,MSR_SYSCALL_MASK ,MSR_LSTAR , #endif -MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA +MSR_IA32_TSC ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA };static unsigned num_msrs_to_save;
Signature · 1 line
1.7.1
PATCH 2/2 KVM: Fix bogus value returned for MSR_IA32_PERF_STATUS
In reply to Avi KivityThe returned value is completely bogus, and sets reserved bits. Return zero instead.
--- arch/x86/kvm/x86.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)
arch/x86/kvm/x86.c +1 -4
@@ -1641,10 +1641,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) data = vcpu->arch.ia32_misc_enable_msr;break ;case MSR_IA32_PERF_STATUS : -/* TSC increment by tick */ - data =1000ULL ; -/* CPU multiplier */ - data |= (((uint64_t )4ULL ) <<40 ); + data =0 ;break ;case MSR_EFER : data = vcpu->arch.efer;
Signature · 1 line
1.7.1
Re: [PATCH 2/2] KVM: Fix bogus value returned for MSR_IA32_PERF_STATUS
Quoted 14 lines · Avi Kivity
The returned value is completely bogus, and sets reserved bits. Return zero instead.
Signed-off-by Avi Kivity <[email protected]>---
arch/x86/kvm/x86.c| 5 +----1 files changed, 1 insertions(+), 4 deletions(-)arch/x86/kvm/x86.c +0
-0@@ -1641,10 +1641,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) data = vcpu->arch.ia32_misc_enable_msr;
arch/x86/kvm/x86.c int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) · line 1647
Quoted 10 lines
arch/x86/kvm/x86.c +1
-4break ;case MSR_IA32_PERF_STATUS : -/* TSC increment by tick */ - data =1000ULL ; -/* CPU multiplier */ - data |= (((uint64_t )4ULL ) <<40 ); + data =0 ;break ;case MSR_EFER : data = vcpu->arch.efer;
This is the respective code snippet from xnu:
/*
* Get the TSC increment. The TSC is incremented by this
* on every bus tick. Calculate the TSC conversion factors
* to and from nano-seconds.
*/
if (cpuid_info()->cpuid_family == CPU_FAMILY_PENTIUM_M) {
uint64_t prfsts;
prfsts = rdmsr64(IA32_PERF_STS);
tscGranularity = (uint32_t)bitfield(prfsts, 44, 40);
N_by_2_bus_ratio = prfsts & bit(46);
} else {
panic("rtclock_init: unknown CPU family: 0x%X\n",
cpuid_info()->cpuid_family);
}
if (N_by_2_bus_ratio)
tscFCvtt2n = busFCvtt2n * 2 / (uint64_t)tscGranularity;
else
tscFCvtt2n = busFCvtt2n / (uint64_t)tscGranularity;
tscFreq = ((1 * Giga) << 32) / tscFCvtt2n;
tscFCvtn2t = 0xFFFFFFFFFFFFFFFFULL / tscFCvtt2n;So by passing in 0 here, you effectively make that code divide something by 0 which results in a panic.
Alex
Re: [PATCH 2/2] KVM: Fix bogus value returned for MSR_IA32_PERF_STATUS
Quoted 55 lines · Alexander Graf
Quoted 14 lines · Avi Kivity
The returned value is completely bogus, and sets reserved bits. Return zero instead.
Signed-off-by Avi Kivity<[email protected]>---
arch/x86/kvm/x86.c| 5 +----1 files changed, 1 insertions(+), 4 deletions(-)arch/x86/kvm/x86.c +0
-0@@ -1641,10 +1641,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) data = vcpu->arch.ia32_misc_enable_msr;arch/x86/kvm/x86.c int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) · line 1647
Quoted 10 lines
arch/x86/kvm/x86.c +1
-4break ;case MSR_IA32_PERF_STATUS : -/* TSC increment by tick */ - data =1000ULL ; -/* CPU multiplier */ - data |= (((uint64_t )4ULL )<<40 ); + data =0 ;break ;case MSR_EFER : data = vcpu->arch.efer;This is the respective code snippet from xnu:
/* * Get the TSC increment. The TSC is incremented by this * on every bus tick. Calculate the TSC conversion factors * to and from nano-seconds. */ if (cpuid_info()->cpuid_family == CPU_FAMILY_PENTIUM_M) { uint64_t prfsts; prfsts = rdmsr64(IA32_PERF_STS); tscGranularity = (uint32_t)bitfield(prfsts, 44, 40); N_by_2_bus_ratio = prfsts& bit(46); } else { panic("rtclock_init: unknown CPU family: 0x%X\n", cpuid_info()->cpuid_family); } if (N_by_2_bus_ratio) tscFCvtt2n = busFCvtt2n * 2 / (uint64_t)tscGranularity; else tscFCvtt2n = busFCvtt2n / (uint64_t)tscGranularity; tscFreq = ((1 * Giga)<< 32) / tscFCvtt2n; tscFCvtn2t = 0xFFFFFFFFFFFFFFFFULL / tscFCvtt2n;
Quoted 3 lines
So by passing in 0 here, you effectively make that code divide something by 0 which results in a panic.
Right. Searching again I find that this is actually documented, (under MSR_PERF_STATU s instead of IA32_PERF_STATUS). I'll just drop this patch.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Re: [PATCH 2/2] KVM: Fix bogus value returned for MSR_IA32_PERF_STATUS
Quoted 56 lines · Avi Kivity
Quoted 55 lines · Alexander Graf
Quoted 14 lines · Avi Kivity
The returned value is completely bogus, and sets reserved bits. Return zero instead.
Signed-off-by Avi Kivity<[email protected]>---
arch/x86/kvm/x86.c| 5 +----1 files changed, 1 insertions(+), 4 deletions(-)arch/x86/kvm/x86.c +0
-0@@ -1641,10 +1641,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) data = vcpu->arch.ia32_misc_enable_msr;arch/x86/kvm/x86.c int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) · line 1647
Quoted 10 lines
arch/x86/kvm/x86.c +1
-4break ;case MSR_IA32_PERF_STATUS : -/* TSC increment by tick */ - data =1000ULL ; -/* CPU multiplier */ - data |= (((uint64_t )4ULL )<<40 ); + data =0 ;break ;case MSR_EFER : data = vcpu->arch.efer;This is the respective code snippet from xnu:
/* * Get the TSC increment. The TSC is incremented by this * on every bus tick. Calculate the TSC conversion factors * to and from nano-seconds. */ if (cpuid_info()->cpuid_family == CPU_FAMILY_PENTIUM_M) { uint64_t prfsts; prfsts = rdmsr64(IA32_PERF_STS); tscGranularity = (uint32_t)bitfield(prfsts, 44, 40); N_by_2_bus_ratio = prfsts& bit(46); } else { panic("rtclock_init: unknown CPU family: 0x%X\n", cpuid_info()->cpuid_family); } if (N_by_2_bus_ratio) tscFCvtt2n = busFCvtt2n * 2 / (uint64_t)tscGranularity; else tscFCvtt2n = busFCvtt2n / (uint64_t)tscGranularity; tscFreq = ((1 * Giga)<< 32) / tscFCvtt2n; tscFCvtn2t = 0xFFFFFFFFFFFFFFFFULL / tscFCvtt2n;
Quoted 6 lines
Quoted 3 lines
So by passing in 0 here, you effectively make that code divide something by 0 which results in a panic.
Right. Searching again I find that this is actually documented, (under
MSR_PERF_STATUs instead ofIA32_PERF_STATUS). I'll just drop this patch.
Sounds good. The other one seems sane to me. I don't have a working setup for Mac guests atm. That was on the TODO list once the AHCI stuff gets upstream :).
Alex