Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5051673rdb; Tue, 12 Dec 2023 18:26:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGa8RM4NqYNjQKDW2ZIoRLJH4KlLqj3nmdfy3mlDP1+eDuNNXOCihk+JOFpc0GUB8V1zVIz X-Received: by 2002:a05:6e02:1ca7:b0:35d:59a2:2c1 with SMTP id x7-20020a056e021ca700b0035d59a202c1mr11157860ill.97.1702434372909; Tue, 12 Dec 2023 18:26:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702434372; cv=none; d=google.com; s=arc-20160816; b=c2ecAc0HleHeba4QuciCEAeEweSdBTQxV8Rkdyew4HM40GZb2tHUOGi/eiczLkiut+ hcfeSUaiurDH+Z+CCOOcQ+sClRJN5Ri0RBsqgKuDxT5dP4nF1YSAyq0tuwEoUBav1PKb vqJ3Q91Izpn4gnBAmzLWj+I5z2a4GXzSOhQiFvhp5Xrim9RkVe2Qo/bHuq2xt/DqSXdC r8NN7KdFGio//M3xyuELo0tXFOioC0muHXkFmZBtpKmTzZ5+XWLNb6BnG5kmswH9ezaF jD7LScQJpPXRSLSCZfI0Zwf/ZAN6Q0NZQ71OpmEA1D7CG9SkhUyKImhibylt4W/RtbYR YgAA== 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=uToa4vWGRVyqvNFgMnA004x4lYo/i2CHkX+gzS+aQ5U=; fh=wUb0wISlYWrkOPdArbP9JqvhHRZe2ZwuJGVamsOJa2M=; b=PuhqJD5gp7/rgPhKL3K5iHanzWUoXAMUCWUDnw85bY+Ik6ABSQmnORf8DYweyC/sMM Xsad23tDK84CfuT2imsA9OXLYaOUZrmTH/srqEMuLQze2Ixqh24nMUhs/dEqsOPDppG0 xofs0IEYyZMW0VcMAIcAxOqWuoToJd1dNM5stbN1dZ2/xK525tnPb0AMxYTNxxZPANIV NSgF3NTEPWrwUpl2L4YgvMhbQVZz7pbOoHO1PHVmNhfr/ZaiA8rqBFJtY8EJKcDfFfar nFw3RrtyVePWB0TJXnwMVTL1xd34cM2wSTEKEHgV+r0brfgQyyNzoUEkziM8gwFBFcZA SrrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IZKJMI6X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id p13-20020a170902e74d00b001d33cc8086esi1672448plf.443.2023.12.12.18.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 18:26:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IZKJMI6X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 76E238096D9C; Tue, 12 Dec 2023 18:26:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378272AbjLMCZh (ORCPT + 99 others); Tue, 12 Dec 2023 21:25:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378352AbjLMCZf (ORCPT ); Tue, 12 Dec 2023 21:25:35 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17D0FDB for ; Tue, 12 Dec 2023 18:25:40 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-2866c800dd5so7494658a91.0 for ; Tue, 12 Dec 2023 18:25:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702434339; x=1703039139; 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=uToa4vWGRVyqvNFgMnA004x4lYo/i2CHkX+gzS+aQ5U=; b=IZKJMI6XpjJ5pzY3zpODomr7ey0c/FzlY9F0mtrBNv3aJI3CadHMYYPMn8FdcBRctm cchNyz5bEuAfAVBEyUEHqorQs3XMHu1PdHBpEGeLWPjvKsjNM6UROGaxJYVfxAavI0x9 SkXIbMmf9p/Oq0K/+UE8Pxg+SzCitEL1WYkj+/4ZUN9EcWldJgWPW5LePYc/YKhsE/Oi yD07iI9jnRREjbXG7PuyE0bQLqhHzvboB/1Jd2Iq6XeUrrWtcp91phn8hQHv3VuD3tUi axah1yp4ojXscggSrB1+QbajQbTtTwPiNkeQH6Zzj6JDDauno0cRVybhCMhKqYi25Wd+ W32w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702434339; x=1703039139; 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=uToa4vWGRVyqvNFgMnA004x4lYo/i2CHkX+gzS+aQ5U=; b=cyVL9mHmVpa6EiwDamtIeeeZZZKDx9XKybptWU0PLMwmvyFr/TCXEeZqVXz5UexXJz 4NIDD9nZASzIRLvo/SX/3barmNbpVFsAII0fGAm6NKv87K397LymlQvPGOMXGW1BgOFY dV/DXf9r0bpT1jSE5lWuhyI+rTO1uom6HhfBvTFGaJFyvdXuMIdF8D5EqZQfqxoZuCfR 9MOQTavttQraVvOGeDNnqS6vZLHPCViesC0tXVEMjsmn4O0+5yKcRR2geDppWsa3nycK 6IaUU3e/kckal0c+wG+EsHhOGT3lZDTqX7A1vb5rj14M/kbSL1rhWp8ENJvJWyED5bg1 RIkw== X-Gm-Message-State: AOJu0YxBsmlTgjePB3OFoC9WL3YAsAd6dwDYdmixZJyDThgmiqrXklFO JUqaUgmF7DKGW9mMv8nq/8ixEJdzTjU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:a504:b0:1d0:54ff:da25 with SMTP id s4-20020a170902a50400b001d054ffda25mr50045plq.0.1702434339424; Tue, 12 Dec 2023 18:25:39 -0800 (PST) Date: Tue, 12 Dec 2023 18:25:37 -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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 12 Dec 2023 18:26:09 -0800 (PST) On Mon, Dec 11, 2023, Jim Mattson wrote: > On Mon, Dec 11, 2023 at 3:43=E2=80=AFPM Sean Christopherson wrote: > > > > > @@ -82,9 +85,13 @@ static struct kvm_pmc *intel_rdpmc_ecx_to_pmc(= struct kvm_vcpu *vcpu, > > > > > /* > > > > > * Fixed PMCs are supported on all architectural PMUs. Not= e, KVM only > > > > > * emulates fixed PMCs for PMU v2+, but the flag itself is = still valid, > > > > > - * i.e. let RDPMC fail due to accessing a non-existent coun= ter. > > > > > + * i.e. let RDPMC fail due to accessing a non-existent coun= ter. Reject > > > > > + * attempts to read all other types, which are unknown/unsu= pported. > > > > > */ > > > > > - idx &=3D ~INTEL_RDPMC_FIXED; > > > > > + if (idx & INTEL_RDPMC_TYPE_MASK & ~INTEL_RDPMC_FIXED) > > > > > > You know how I hate to be pedantic (ROFL), but the SDM only says: > > > > > > If the processor does support architectural performance monitoring > > > (CPUID.0AH:EAX[7:0] =E2=89=A0 0), ECX[31:16] specifies type of PMC wh= ile > > > ECX[15:0] specifies the index of the PMC to be read within that type. > > > > > > It does not say that the types are bitwise-exclusive. > > > > > > 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= that > > 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 = FIXED and > > "none" types. Or are you objecting to the comment? >=20 > You're right. The code is fine. My brain is not. >=20 > But what's wrong with something like: >=20 > type =3D idx & INTEL_RDPMC_TYPE_MASK; > if (type !=3D INTEL_RDPMC_GP && type !=3D INTEL_RDPMC_FIXED) ... >=20 > This makes it more clear what kvm accepts and what it doesn't accept, > regardless of the actual values of the macros. Because when I read the SDM, my reading was heavily colored by KVM's existi= ng implementation. And the SDM using 4000H and 2000H for the non-zero types d= oesn't help (those scream "flags" to me). But rereading things, the SDM clearly s= tates they are explicit, distinct types. I'll massage this to have KVM treat the= m as such.