Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6272173iob; Tue, 10 May 2022 14:33:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7u09jIUX8XCYtUvOwx+mGmxt/TPz6EiPoKfb/JbPBTXAZ00D4GMDRqUjnBt2Ib1k7DYxy X-Received: by 2002:a05:6402:27cc:b0:427:b562:935a with SMTP id c12-20020a05640227cc00b00427b562935amr25989468ede.216.1652218404831; Tue, 10 May 2022 14:33:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652218404; cv=none; d=google.com; s=arc-20160816; b=ks9dnkiJqqDOhZKLMES7b4FyOevm5O6A7/2t3SYip5zBc1yHOPzv/Wo3eUFU5FVQPq soGyXm7rr8beva5jxAoBmtncnvcA7W+5q5Q5Egi97Yc2qZ0HqJwUJXbpCFycsjge6zTT H1lXuHFvLX86jKx9UUa3gwhRPILBrO8B6ak7Wr28IBNvmi7W+1+dhfEq2+/QEEipNPLn LAkMHMEAE3q3v0L430bgkby0RARmt9bwIEQ8dDNTVQW8AwlGKrpPkMhaUT08Mv194Y++ eWQM9ztAG7rYYKkzntOj7HjEM4tVVeDNZKMHS6OIiqcqRN1GdXW/OQoyuSnsoaSJw+sN iAug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OG6VNMbmNkoW0oiMpzdvJFSjf+lWpAs48bn+sF2lvxY=; b=F0zp/TIQHfFYlJhsbsLUKq9o59jbdEQ2UxhE/LAXUazClXJyKhr1pxexYuxJdp324x V2Q9qAE46Dxl3lDSxn+VdPFjs7B7obfxan4kWVG0wlfARW8MjAAYC/rofbXigNWe288s qpU4f7wFwzgcV4MeKs2dxsLC2cehidtR7TkSO4APqAqC8kGN+L/+lKxLcFALdSDAIjMB u9382MEtIy419hhnkvFSZiuN5quhJZMJTSRM0uRl8LTb3LRVebdfv+ubVSzN8v/2PNMI z4bkUEYKSWeZcL9xfrc3JJQ8/n7oYO5D3WEZy8JMGr6Z1PpYz6f8hoN0quX0ciakJR8+ EKMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B0dmhTea; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp16-20020a170906c15000b006f37a0e4737si351110ejc.381.2022.05.10.14.33.00; Tue, 10 May 2022 14:33:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B0dmhTea; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245373AbiEJOBr (ORCPT + 99 others); Tue, 10 May 2022 10:01:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245149AbiEJNie (ORCPT ); Tue, 10 May 2022 09:38:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6590D24A391; Tue, 10 May 2022 06:27:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2A56BB81DA9; Tue, 10 May 2022 13:27:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F72AC385C2; Tue, 10 May 2022 13:27:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652189246; bh=3he/NOd7/Fye5vlSVdhEBApvn0usOiCMnXHsL7S2vCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B0dmhTeaynu9FstNiwcL1T9fwE2FVNv0a2hJT/Oj89LmlDEndlCMxEIAk13VJojCc xqftR9lWP+wcaySg/5T7P5h3meidYXFtenDWQD3WgEQ/nYV1fqF0aYSi8g7FpCqi/V 2XI8Nx1zvkfRaiN8861BtA060FUAbBPiAu2P+qFI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vasant Hegde , Sandipan Das , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.10 58/70] kvm: x86/cpuid: Only provide CPUID leaf 0xA if host has architectural PMU Date: Tue, 10 May 2022 15:08:17 +0200 Message-Id: <20220510130734.565809400@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130732.861729621@linuxfoundation.org> References: <20220510130732.861729621@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sandipan Das [ Upstream commit 5a1bde46f98b893cda6122b00e94c0c40a6ead3c ] On some x86 processors, CPUID leaf 0xA provides information on Architectural Performance Monitoring features. It advertises a PMU version which Qemu uses to determine the availability of additional MSRs to manage the PMCs. Upon receiving a KVM_GET_SUPPORTED_CPUID ioctl request for the same, the kernel constructs return values based on the x86_pmu_capability irrespective of the vendor. This leaf and the additional MSRs are not supported on AMD and Hygon processors. If AMD PerfMonV2 is detected, the PMU version is set to 2 and guest startup breaks because of an attempt to access a non-existent MSR. Return zeros to avoid this. Fixes: a6c06ed1a60a ("KVM: Expose the architectural performance monitoring CPUID leaf") Reported-by: Vasant Hegde Signed-off-by: Sandipan Das Message-Id: <3fef83d9c2b2f7516e8ff50d60851f29a4bcb716.1651058600.git.sandipan.das@amd.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/cpuid.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 41b0dc37720e..6e1ea5e85e59 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -668,6 +668,11 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) union cpuid10_eax eax; union cpuid10_edx edx; + if (!static_cpu_has(X86_FEATURE_ARCH_PERFMON)) { + entry->eax = entry->ebx = entry->ecx = entry->edx = 0; + break; + } + perf_get_x86_pmu_capability(&cap); /* -- 2.35.1