Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5247359yba; Wed, 8 May 2019 10:04:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxN1IhrOu9OfNrNDUzJdB4MQNC+QKd8tDc1p4OFjkmZEny6K+VC6mY9d0m7WBPNMlVPNos X-Received: by 2002:a17:902:6bc2:: with SMTP id m2mr1529641plt.24.1557335065575; Wed, 08 May 2019 10:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557335065; cv=none; d=google.com; s=arc-20160816; b=nUMcx5N2HmGqbasPZNc84iCPWEaD1eCdrQPr1crecmaUH25qFMDvlEoyS61z2hxEDR /WLZjcLpXb0YghstsdKDEkzmZH1q1EbbB6wj51OF1DGS0T913wo+KVG1rWzUQdSrgB+v EZEyA/efbfrOSAzCJykecLQoOW/FjAQv+FDuV/1yhRDlzKWWNDHRcn5v97do42BytJ6S 2e5FC9aP0snyOJAjNaJybabIdREJ6PaGHHrItqo1ol8WkXGLS0UNEIRPnncPelPA0Jld XhBT52o8jSMGylZYg2aVjyZjpG1eo0PHhbX+CTWcSad/0+7e1myT0e2cWZfxuffWojuS IXrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QsH1WRMJgZkl2tX1i0OToAGG8BFivK5Xbifm/yUt7oA=; b=kz8NeCHGeo17KrpFGhdkPe3tOeKa2wWyzdnXkj0+KIoRtNTHjkwtMNuve8P7uC9vKq y+Hnfk/CfZDB5kHsNrEKB2ntEaN+da8FV+ZgxKOLBzjYQ00yElInA1rGV6s5YLElWAOc 4zl4WxfiUj8w18p7vSSfPJ68NzfcQ91fQL6pZmgPm+9duXLNruBdt5dkobWSiFQ7tEob rCAC2s+zTxTlWCTWj6jlE9mEXY0SQI6yswL/iWALK2DmctAk2Bo2LIjwv4n0e5xKyXKo B5pdCV0gshesI4iHNdoUg4ykX11f1SBYIELBSqTTQAgT/C0X0KZWj4jRorFMaWtNmlK0 Su0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=REDLYE51; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l11si24430578plb.370.2019.05.08.10.04.01; Wed, 08 May 2019 10:04:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=REDLYE51; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728886AbfEHRC7 (ORCPT + 99 others); Wed, 8 May 2019 13:02:59 -0400 Received: from mail.skyhub.de ([5.9.137.197]:53066 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728351AbfEHRC6 (ORCPT ); Wed, 8 May 2019 13:02:58 -0400 Received: from zn.tnic (p200300EC2F0F5800A4469260603C8E24.dip0.t-ipconnect.de [IPv6:2003:ec:2f0f:5800:a446:9260:603c:8e24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 6C4361EC05E1; Wed, 8 May 2019 19:02:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1557334976; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=QsH1WRMJgZkl2tX1i0OToAGG8BFivK5Xbifm/yUt7oA=; b=REDLYE51XtLVWUDWWulI3/3wY8CRHmaZfrJAI0z2dO8K9UeEGfN8pKnrY6LPE4lC6AvZvS wJkPbBz3kfHRDhLZXOqNC3b9YFq7k4UsitR5cnZ7DNvd49/lS+tLLJDvjj6a8TMr/Y1DN+ gcX9bYoyvndsu8ooPpOH2WDIiXfISuk= From: Borislav Petkov To: LKML Cc: "H. Peter Anvin" , Ingo Molnar , Janakarajan Natarajan , kvm@vger.kernel.org, Liran Alon , Mihai Carabas , Paolo Bonzini , Peter Zijlstra , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Gleixner , Tom Lendacky , x86@kernel.org Subject: [PATCH] x86/kvm/pmu: Set AMD's virt PMU version to 1 Date: Wed, 8 May 2019 19:02:48 +0200 Message-Id: <20190508170248.15271-1-bp@alien8.de> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov 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 Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Janakarajan Natarajan Cc: kvm@vger.kernel.org Cc: Liran Alon Cc: Mihai Carabas Cc: Paolo Bonzini Cc: Peter Zijlstra Cc: "Radim Krčmář" Cc: Thomas Gleixner Cc: Tom Lendacky 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