x86/kvm/pmu: Set AMD's virt PMU version to 1
Borislav Petkov
maintainerPATCH 1/1 x86/kvm/pmu: Set AMD's virt PMU version to 1
From: Borislav Petkov <[email protected]>
After commit:
672ff6cff80c ("KVM: x86: Raise #GP when guest vCPU do not support PMU")
my AMD guests started #GPing like this:
general protection fault: 0000 [#1] PREEMPT SMP CPU: 1 PID: 4355 Comm: bash Not tainted 5.1.0-rc6+ #3 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014 RIP: 0010:x86_perf_event_update+0x3b/0xa0
with Code: pointing to RDPMC. It is RDPMC because the guest has the hardware watchdog CONFIG_HARDLOCKUP_DETECTOR_PERF enabled which uses perf. Instrumenting kvm_pmu_rdpmc() some, showed that it fails due to:
if (!pmu->version)
return 1;
which the above commit added. Since AMD's PMU leaves the version at 0, that causes the #GP injection into the guest.
Set pmu->version arbitrarily to 1 and move it above the non-applicable struct kvm_pmu members.
--- arch/x86/kvm/pmu_amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/pmu_amd.c +1 -1
@@ -269,10 +269,10 @@ static void amd_pmu_refresh(struct kvm_vcpu *vcpu) pmu->counter_bitmask[KVM_PMC_GP ] = ((u64 )1 <<48 ) -1 ; pmu->reserved_bits =0xffffffff00200000ull ; + pmu->version =1 ;/* not applicable to AMD; but clean them to prevent any fall out */ pmu->counter_bitmask[KVM_PMC_FIXED ] =0 ; pmu->nr_arch_fixed_counters =0 ; - pmu->version =0 ; pmu->global_status =0 ; }
Signature · 1 line
2.21.0
Quoted 5 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
After commit:
672ff6cff80c("KVM: x86: Raise #GP when guest vCPU do not support PMU")
You should add this commit as a fixes tag. Since that commit went into 5.1 it would be worth this fix going into the 5.1 stable tree.
Thanks,
Tom
Quoted 57 lines
my AMD guests started #GPing like this:
general protection fault: 0000 [#1] PREEMPT SMP CPU: 1 PID: 4355 Comm: bash Not tainted 5.1.0-rc6+ #3 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014 RIP: 0010:x86_perf_event_update+0x3b/0xa0with Code: pointing to RDPMC. It is RDPMC because the guest has the hardware watchdog
CONFIG_HARDLOCKUP_DETECTOR_PERFenabled which uses perf. Instrumentingkvm_pmu_rdpmc()some, showed that it fails due to:if (!pmu->version)
return 1;which the above commit added. Since AMD's PMU leaves the version at 0, that causes the #GP injection into the guest.
Set
pmu->versionarbitrarily to 1 and move it above the non-applicable structkvm_pmumembers.Signed-off-by Borislav Petkov <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Ingo Molnar <[email protected]>Cc Janakarajan Natarajan <[email protected]>Cc Liran Alon <[email protected]>Cc Mihai Carabas <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Zijlstra <[email protected]>Cc "Radim Krčmář" <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Tom Lendacky <[email protected]>--- arch/x86/kvm/pmu_amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/pmu_amd.c +1
-2@@ -269,10 +269,10 @@ static void amd_pmu_refresh(struct kvm_vcpu *vcpu) pmu->counter_bitmask[KVM_PMC_GP ] = ((u64 )1 <<48 ) -1 ; pmu->reserved_bits =0xffffffff00200000ull ; + pmu->version =1 ;/* not applicable to AMD; but clean them to prevent any fall out */ pmu->counter_bitmask[KVM_PMC_FIXED ] =0 ; pmu->nr_arch_fixed_counters =0 ; - pmu->version =0 ; pmu->global_status =0 ; } --2.21.0
Borislav Petkov
maintainerQuoted 9 lines · Thomas
Quoted 5 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
After commit:
672ff6cff80c("KVM: x86: Raise #GP when guest vCPU do not support PMU")You should add this commit as a fixes tag. Since that commit went into 5.1 it would be worth this fix going into the 5.1 stable tree.
Paolo, Radim, can you do that pls, when applying?
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Paolo Bonzini
maintainerQuoted 4 lines · Borislav Petkov
Quoted 3 lines · Thomas
Quoted 2 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
After commit:
672ff6cff80c("KVM: x86: Raise #GP when guest vCPU do not support PMU")You should add this commit as a fixes tag. Since that commit went into 5.1 it would be worth this fix going into the 5.1 stable tree.
Paolo, Radim, can you do that pls, when applying?
Yes, done (and queued the patch).
Paolo