Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp302512pxb; Wed, 20 Apr 2022 23:19:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXKNMOInm6gX0NzAwJZXWTEyK/Vl4tp881IZHAnZpqIyGSJy0042QtA4aM4BeiULJLeSRt X-Received: by 2002:a17:907:628e:b0:6d9:c6fa:6168 with SMTP id nd14-20020a170907628e00b006d9c6fa6168mr21289144ejc.132.1650521972643; Wed, 20 Apr 2022 23:19:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650521972; cv=none; d=google.com; s=arc-20160816; b=CHXBcWCZZTgG6NRnbPtax+CeXGSHmYMtDsdyaDu22W3EdElrI2jSiBdy9C/o7IJkk8 4Ern+ybz0VfRfSt3rw/kHtF2kaVXE0tfxnx4f3gecGwbxk/eIZARv8C5bcZo2QFzEty7 rihMz21rvYcwLnnkVxHKHA9OwZ+cHlTua+GoX4xtMPMePFzNc3t00PLuDQhv6NbpI++6 p3YGU5Y6A5VCJRPrdODQuvazJFj+KGSieZcjynu9BGIh8Ht6I+WbaE8VJd51pvvznDaE DUzESTdKwYOEIpRlrPIDh+g2Kp7TTbz5cXcGwalyM+tGp+PzlVI+vc+BOn/kvvD2Mviy gE4g== 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=kc4sdiTQf1GhNFD7aRwJn8s5rW8A8DQ2fbx5M6iTXf8=; b=q3SuUw2iLhD5JflMqWMOqPdyw8pGMzDCSRpvR7Hjt1d9BXeezHk32Cv1ry8IXs/09C FdRdkGmeUSANZPs2ECeCO5GDRfeMOnpYQMglFvKEhRiDRIwHeGFbKtfmjGzsu9PfAPi6 GlXDk6WnXi/j9tTKwlGZuXeYwXdkysTkL57OF7XsdtVhCvw48WRv5toHlEIA2wNWYmnX ehA8ByFvp1sPKIU6pJl0NtAlNZ/O7FMEI2A16569A1+pkk8s0Y0g7kAo3AL/XjAh/1Lg 4ZI2nDXd/U7nlLJO0TYyXvXCl/heet012NOmVplAYHEQy9wKPsLsHwvXJuZPLvXnARtU 5qDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CoSOLRpC; 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 f14-20020a056402194e00b00425a5abc1dcsi198479edz.305.2022.04.20.23.19.09; Wed, 20 Apr 2022 23:19:32 -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=CoSOLRpC; 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 S245163AbiDRN6h (ORCPT + 99 others); Mon, 18 Apr 2022 09:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242681AbiDRNdC (ORCPT ); Mon, 18 Apr 2022 09:33:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B1EB201B7; Mon, 18 Apr 2022 05:57:49 -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 dfw.source.kernel.org (Postfix) with ESMTPS id EAF9661259; Mon, 18 Apr 2022 12:57:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0491EC385A1; Mon, 18 Apr 2022 12:57:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286668; bh=lo7FtlyJVfJXLnY912gcwlLUcCiexeAFG/oWgZWvNmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CoSOLRpCs8zvLJJ2I8VOuwl3x6f62oFzcNvWthJ38owO6YW8EeNVc3GYnssLhKfri huA7q1OhhIPpzLuj12hVx06sqlpL+4xfipBh074GmVoCMe8L7UxEg46e6SEUlVFJX7 Ee4YcU4A1N0ONsVldNpQ2iwfEf+kGVUksfvJCEcY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lotus Fenn , Jim Mattson , Like Xu , David Dunn , Paolo Bonzini , Sasha Levin Subject: [PATCH 4.14 206/284] KVM: x86/svm: Clear reserved bits written to PerfEvtSeln MSRs Date: Mon, 18 Apr 2022 14:13:07 +0200 Message-Id: <20220418121217.579718160@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@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 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: Jim Mattson [ Upstream commit 9b026073db2f1ad0e4d8b61c83316c8497981037 ] AMD EPYC CPUs never raise a #GP for a WRMSR to a PerfEvtSeln MSR. Some reserved bits are cleared, and some are not. Specifically, on Zen3/Milan, bits 19 and 42 are not cleared. When emulating such a WRMSR, KVM should not synthesize a #GP, regardless of which bits are set. However, undocumented bits should not be passed through to the hardware MSR. So, rather than checking for reserved bits and synthesizing a #GP, just clear the reserved bits. This may seem pedantic, but since KVM currently does not support the "Host/Guest Only" bits (41:40), it is necessary to clear these bits rather than synthesizing #GP, because some popular guests (e.g Linux) will set the "Host Only" bit even on CPUs that don't support EFER.SVME, and they don't expect a #GP. For example, root@Ubuntu1804:~# perf stat -e r26 -a sleep 1 Performance counter stats for 'system wide': 0 r26 1.001070977 seconds time elapsed Feb 23 03:59:58 Ubuntu1804 kernel: [ 405.379957] unchecked MSR access error: WRMSR to 0xc0010200 (tried to write 0x0000020000130026) at rIP: 0xffffffff9b276a28 (native_write_msr+0x8/0x30) Feb 23 03:59:58 Ubuntu1804 kernel: [ 405.379958] Call Trace: Feb 23 03:59:58 Ubuntu1804 kernel: [ 405.379963] amd_pmu_disable_event+0x27/0x90 Fixes: ca724305a2b0 ("KVM: x86/vPMU: Implement AMD vPMU code for KVM") Reported-by: Lotus Fenn Signed-off-by: Jim Mattson Reviewed-by: Like Xu Reviewed-by: David Dunn Message-Id: <20220226234131.2167175-1-jmattson@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/pmu_amd.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/pmu_amd.c b/arch/x86/kvm/pmu_amd.c index cd944435dfbd..e0473c72062e 100644 --- a/arch/x86/kvm/pmu_amd.c +++ b/arch/x86/kvm/pmu_amd.c @@ -139,12 +139,10 @@ static int amd_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) /* MSR_K7_EVNTSELn */ pmc = get_gp_pmc(pmu, msr, MSR_K7_EVNTSEL0); if (pmc) { - if (data == pmc->eventsel) - return 0; - if (!(data & pmu->reserved_bits)) { + data &= ~pmu->reserved_bits; + if (data != pmc->eventsel) reprogram_gp_counter(pmc, data); - return 0; - } + return 0; } return 1; -- 2.35.1