Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4309624rdb; Mon, 11 Dec 2023 15:43:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEq2G9tLgjzq2h1IihdtEc7UaXnwjxg43SlDJO0eZncF+jVd1SuO44g5bD+SJbzanXk1p8V X-Received: by 2002:a05:6a21:328b:b0:184:da23:76b2 with SMTP id yt11-20020a056a21328b00b00184da2376b2mr7017579pzb.28.1702338219067; Mon, 11 Dec 2023 15:43:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702338219; cv=none; d=google.com; s=arc-20160816; b=W6NW8rtJ+NV8YgJnup60KyF0ulOfwCCkVBEYeImBjo1CkQQ959qroKuyGH8EboXgxO U7RDfHpslCDA6O5+P2SWfUPZnRth487mHdHXsPmCj4a6+/EG0+UfrVpxinB0adwAfMjS yZSDX9LiqXn6tazwxVhgoYj46IUKJemdqLjLt2nSnwvrPNTSYY9jDTqjinMiINERaFNW 963228uc4/+YSkKQkxQAifJ75fSyCrR7+QaCaGlN8WIsQ3NbBTO3DFrevjcmv4ouBtDU okZxWwayusE1WNTItstyX7ojI9g5EYESP6o8XxY+fEvbHtSz2I4JdlixunSC8yowWHiP 7jGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:dkim-signature; bh=L2CNIwBgf8qqJqiKqxAd6p8N8y1poBppmKnfZ/wvtKY=; fh=wUb0wISlYWrkOPdArbP9JqvhHRZe2ZwuJGVamsOJa2M=; b=r8UkOARZV8w15fy5r1CkQjeEa/VvOkYDm5lF43MmNoxF6zqAQ16VO2tRyW+ysfILFT ifFWydtTl1rmtSMZwlWLMJezRaWsrSNTYjrW1eKBwRof46v5OBcIJquX0Bcr58nRr0Ez Vch7JTSgZ83+Sr5gErwQC/U/lMYQisQCHmqy9F2heb7MrNM92TdxpbOtKa9eiesWsYku b+zAXGmEU02hQd61khkgpSHzfk54w5BNHt85fcp+wmvtl9jcIgBHtYxQFvNNzZpsFmH4 aB2jghH+uOAzPHkV44k8BQGu7syLYZAIdQrDZzyj6ry9gimxwYMW8/t0l0iG9gr7DugL ZJZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="LO/NJwRl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id c6-20020a631c46000000b005b99ea783aasi6647183pgm.755.2023.12.11.15.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 15:43:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="LO/NJwRl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 528AD809A7BB; Mon, 11 Dec 2023 15:43:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345289AbjLKXnU (ORCPT + 99 others); Mon, 11 Dec 2023 18:43:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345163AbjLKXnU (ORCPT ); Mon, 11 Dec 2023 18:43:20 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86687CD for ; Mon, 11 Dec 2023 15:43:26 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1d3376c1c83so123465ad.0 for ; Mon, 11 Dec 2023 15:43:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702338206; x=1702943006; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=L2CNIwBgf8qqJqiKqxAd6p8N8y1poBppmKnfZ/wvtKY=; b=LO/NJwRlwFspsaH6vN1v0xWssvr66YFxOJzgoYEKhMHcEnvKaB3FDLpIKr2xHgEiKc VGGh9WcYkfs6y5Fzbl6xty8kf5QIlsmzgP6g79A/4od176GTdXDSZX3woUHwSbfAAFks RtPgvdCY0Gh47kjNvRoPON5k+PKJv+baMk7+kskQS1qRO4uy0WkQnrbkkI8v6oGh6sUw kcMLrlB8UCPYtA02y3p+6DVXN7KsBBhChU4VyxkCRnebMOa9YP06PGbdt4PzCd50WD6C Dl383ilKUaAoh+gQJ8og0OaqZIA0Oup7ddo6SjwXt3OZzny8dd3QNJGCs4jzcP4AIXyd cKqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702338206; x=1702943006; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=L2CNIwBgf8qqJqiKqxAd6p8N8y1poBppmKnfZ/wvtKY=; b=FVd21GW7BUc53jKZ2KpljFvxaY0kXxJRSY48msiz9L4vDrKefU9GUM4hCjfxXSoZ4G JcHv5Q6tW3+B7BvoSSnIxHR5b9kCM1JQ8Goj1PxmzwQZApcd0BKvb7s0BSlgLZ4DJ6W5 bdzy7BNmdO54XQD8jog6UyZS3MA0DLKVX0cX5MW1DQTDTb3VE1VCN2030L3BvAV8Ilqg EzO6QE/2gSpUrTHNR6N9MljJYZSDpXKnso3qBsGTgUjLD+cKmScVm6M8JZM6oQY9TwZe UL7wo69Y19BJauGAkniJZhjF5IoEqOs6RD1eLwuzHHf8c6xzuTinUgST0nlxkKb1pCjQ ODYw== X-Gm-Message-State: AOJu0YzPUWx0kHkpNgLAB/ojyU3ZZ+tikqyCKhvj2xHU+/wwqeo4Loio s8eyWeCSZDYTu/QMEcEuPzifSiyTX0M= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:dacb:b0:1d0:9fdb:a958 with SMTP id q11-20020a170902dacb00b001d09fdba958mr42128plx.13.1702338205748; Mon, 11 Dec 2023 15:43:25 -0800 (PST) Date: Mon, 11 Dec 2023 15:43:24 -0800 In-Reply-To: Mime-Version: 1.0 References: <20231202000417.922113-1-seanjc@google.com> <20231202000417.922113-11-seanjc@google.com> Message-ID: Subject: Re: [PATCH v9 10/28] KVM: x86/pmu: Explicitly check for RDPMC of unsupported Intel PMC types From: Sean Christopherson To: Jim Mattson Cc: Dapeng Mi , Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kan Liang , Jinrong Liang , Aaron Lewis , Like Xu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 11 Dec 2023 15:43:36 -0800 (PST) On Mon, Dec 11, 2023, Jim Mattson wrote: > On Sun, Dec 10, 2023 at 10:26=E2=80=AFPM Mi, Dapeng wrote: > > > > > > On 12/2/2023 8:03 AM, Sean Christopherson wrote: > > > Explicitly check for attempts to read unsupported PMC types instead o= f > > > letting the bounds check fail. Functionally, letting the check fail = is > > > ok, but it's unnecessarily subtle and does a poor job of documenting = the > > > architectural behavior that KVM is emulating. > > > > > > Opportunistically add macros for the type vs. index to further docume= nt > > > what is going on. > > > > > > Signed-off-by: Sean Christopherson > > > --- > > > arch/x86/kvm/vmx/pmu_intel.c | 11 +++++++++-- > > > 1 file changed, 9 insertions(+), 2 deletions(-) > > > > > > diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_inte= l.c > > > index 644de27bd48a..bd4f4bdf5419 100644 > > > --- a/arch/x86/kvm/vmx/pmu_intel.c > > > +++ b/arch/x86/kvm/vmx/pmu_intel.c > > > @@ -23,6 +23,9 @@ > > > /* Perf's "BASE" is wildly misleading, this is a single-bit flag, n= ot a base. */ > > > #define INTEL_RDPMC_FIXED INTEL_PMC_FIXED_RDPMC_BASE > > > > > > +#define INTEL_RDPMC_TYPE_MASK GENMASK(31, 16) > > > +#define INTEL_RDPMC_INDEX_MASK GENMASK(15, 0) > > > + > > > #define MSR_PMC_FULL_WIDTH_BIT (MSR_IA32_PMC0 - MSR_IA32_PERFC= TR0) > > > > > > static void reprogram_fixed_counters(struct kvm_pmu *pmu, u64 data) > > > @@ -82,9 +85,13 @@ static struct kvm_pmc *intel_rdpmc_ecx_to_pmc(stru= ct kvm_vcpu *vcpu, > > > /* > > > * Fixed PMCs are supported on all architectural PMUs. Note, K= VM only > > > * emulates fixed PMCs for PMU v2+, but the flag itself is stil= l valid, > > > - * i.e. let RDPMC fail due to accessing a non-existent counter. > > > + * i.e. let RDPMC fail due to accessing a non-existent counter.= Reject > > > + * attempts to read all other types, which are unknown/unsuppor= ted. > > > */ > > > - idx &=3D ~INTEL_RDPMC_FIXED; > > > + if (idx & INTEL_RDPMC_TYPE_MASK & ~INTEL_RDPMC_FIXED) >=20 > You know how I hate to be pedantic (ROFL), but the SDM only says: >=20 > If the processor does support architectural performance monitoring > (CPUID.0AH:EAX[7:0] =E2=89=A0 0), ECX[31:16] specifies type of PMC while > ECX[15:0] specifies the index of the PMC to be read within that type. >=20 > It does not say that the types are bitwise-exclusive. >=20 > Yes, the types defined thus far are bitwise-exclusive, but who knows > what tomorrow may bring? The goal isn't to make the types exclusive, the goal is to reject types tha= t aren't supported by KVM. The above accomplishes that, no? I don't see how= KVM could get a false negative or false positive, the above allows exactly FIXE= D and "none" types. Or are you objecting to the comment?