LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] x86/kvm/pmu: Set AMD's virt PMU version to 1
@ 2019-05-08 17:02 Borislav Petkov
  2019-05-08 17:08 ` Lendacky, Thomas
  0 siblings, 1 reply; 4+ messages in thread
From: Borislav Petkov @ 2019-05-08 17:02 UTC (permalink / raw)
  To: LKML
  Cc: H. Peter Anvin, Ingo Molnar, Janakarajan Natarajan, kvm,
	Liran Alon, Mihai Carabas, Paolo Bonzini, Peter Zijlstra,
	Radim Krčmář,
	Thomas Gleixner, Tom Lendacky, x86

From: Borislav Petkov <bp@suse.de>

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.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Janakarajan Natarajan <Janakarajan.Natarajan@amd.com>
Cc: kvm@vger.kernel.org
Cc: Liran Alon <liran.alon@oracle.com>
Cc: Mihai Carabas <mihai.carabas@oracle.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: x86@kernel.org
---
 arch/x86/kvm/pmu_amd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/pmu_amd.c b/arch/x86/kvm/pmu_amd.c
index 1495a735b38e..50fa9450fcf1 100644
--- a/arch/x86/kvm/pmu_amd.c
+++ b/arch/x86/kvm/pmu_amd.c
@@ -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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/kvm/pmu: Set AMD's virt PMU version to 1
  2019-05-08 17:02 [PATCH] x86/kvm/pmu: Set AMD's virt PMU version to 1 Borislav Petkov
@ 2019-05-08 17:08 ` Lendacky, Thomas
  2019-05-08 17:14   ` Borislav Petkov
  0 siblings, 1 reply; 4+ messages in thread
From: Lendacky, Thomas @ 2019-05-08 17:08 UTC (permalink / raw)
  To: Borislav Petkov, LKML
  Cc: H. Peter Anvin, Ingo Molnar, Natarajan, Janakarajan, kvm,
	Liran Alon, Mihai Carabas, Paolo Bonzini, Peter Zijlstra,
	Radim Krčmář,
	Thomas Gleixner, x86

On 5/8/19 12:02 PM, Borislav Petkov wrote:
> From: Borislav Petkov <bp@suse.de>
> 
> 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

> 
> 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.
> 
> Signed-off-by: Borislav Petkov <bp@suse.de>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Janakarajan Natarajan <Janakarajan.Natarajan@amd.com>
> Cc: kvm@vger.kernel.org
> Cc: Liran Alon <liran.alon@oracle.com>
> Cc: Mihai Carabas <mihai.carabas@oracle.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: "Radim Krčmář" <rkrcmar@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: x86@kernel.org
> ---
>  arch/x86/kvm/pmu_amd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/pmu_amd.c b/arch/x86/kvm/pmu_amd.c
> index 1495a735b38e..50fa9450fcf1 100644
> --- a/arch/x86/kvm/pmu_amd.c
> +++ b/arch/x86/kvm/pmu_amd.c
> @@ -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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/kvm/pmu: Set AMD's virt PMU version to 1
  2019-05-08 17:08 ` Lendacky, Thomas
@ 2019-05-08 17:14   ` Borislav Petkov
  2019-05-20 13:24     ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Borislav Petkov @ 2019-05-08 17:14 UTC (permalink / raw)
  To: Lendacky, Thomas
  Cc: LKML, H. Peter Anvin, Ingo Molnar, Natarajan, Janakarajan, kvm,
	Liran Alon, Mihai Carabas, Paolo Bonzini, Peter Zijlstra,
	Radim Krčmář,
	Thomas Gleixner, x86

On Wed, May 08, 2019 at 05:08:44PM +0000, Lendacky, Thomas wrote:
> On 5/8/19 12:02 PM, Borislav Petkov wrote:
> > From: Borislav Petkov <bp@suse.de>
> > 
> > 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.

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/kvm/pmu: Set AMD's virt PMU version to 1
  2019-05-08 17:14   ` Borislav Petkov
@ 2019-05-20 13:24     ` Paolo Bonzini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2019-05-20 13:24 UTC (permalink / raw)
  To: Borislav Petkov, Lendacky, Thomas
  Cc: LKML, H. Peter Anvin, Ingo Molnar, Natarajan, Janakarajan, kvm,
	Liran Alon, Mihai Carabas, Peter Zijlstra,
	Radim Krčmář,
	Thomas Gleixner, x86

On 08/05/19 19:14, Borislav Petkov wrote:
> On Wed, May 08, 2019 at 05:08:44PM +0000, Lendacky, Thomas wrote:
>> On 5/8/19 12:02 PM, Borislav Petkov wrote:
>>> From: Borislav Petkov <bp@suse.de>
>>>
>>> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-05-20 13:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-08 17:02 [PATCH] x86/kvm/pmu: Set AMD's virt PMU version to 1 Borislav Petkov
2019-05-08 17:08 ` Lendacky, Thomas
2019-05-08 17:14   ` Borislav Petkov
2019-05-20 13:24     ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).