Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1923855rda; Tue, 24 Oct 2023 07:23:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6q/xulCm8nxm5MVnPakpOmu6Wim1XcCnz9YLO0gCQ/Lxyq4WAMFkRfj3kq/NFxc3KSF7Z X-Received: by 2002:a17:902:ea02:b0:1c5:6f43:9502 with SMTP id s2-20020a170902ea0200b001c56f439502mr17322350plg.14.1698157389459; Tue, 24 Oct 2023 07:23:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698157389; cv=none; d=google.com; s=arc-20160816; b=yTa/rnjAb0fX0+XL4KgpAHqORk7ZiwiZGGhiNF5QJoyVD1Ude5moxl7G8lq8Oy6IBI rFwes6YZE9oDdsrNgbxJeWUbN8Pd6ue+QtbH0NggsW/hhx0HJ4h+mk9lXomC/OWzz9Rj SUaIlkYBHs4nNMJ6+4qV1cgXnzteMfmQfAgatG3ltQaWpXq2xAwZeg6NtytuXC0i1vLP 5JqSWFLo7JQDnFvilPr6MAWcGgLqCKy2r/1O3kmnkpSkDXVlJZ68B1CzQPCBLkBOuc0r a0SEofVGtOpqM99Vqf3vHjt9j/AIc/d3xRWrjJbXDiEBglcOXAV5q9Wp7E4MqlSH8VRU 9QtQ== 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=DMkKZbVayV+UHO5Qbc7nkBIjyL5B5bBnYpYu21nJFcE=; fh=34pnteApgENfeISqD9l2qIVA4N0CMyJu/Cdu2IzN7oM=; b=ril+tPea9LeJKxthT7aeZW5Fxbbl7t4PwG2BB4XQ23J3z6B6RBTq+q8bwFEJUlFy0O 30mq93BgbrW/63/ZeR2XlOjhZvWqwaVR5e8FFrlw2xTpEzw0684UVk/Oi/6odND/RRSI NilYstY0BPAUKBJxNTgEgLpnP6cBhm1EVgV+qC6UYXXLhXJRdY0RSNWiSLr+lu2H7vOW agp3He42iRNqXHjth0fybtQIDuzI1P9ZgFdkGlMdcxHcRSaqYYsRfe+uPKAgEc02e2tL grSd+YK9ltUGPy/hk3oupQA7uq5LxY38PXXx2on/FVIzv0lt8nukZdaDURxMVxNK0M1I DM8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=oh2gY6j1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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. [23.128.96.36]) by mx.google.com with ESMTPS id c1-20020a170902c1c100b001c7342b46e4si8012169plc.23.2023.10.24.07.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 07:23:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=oh2gY6j1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 6152B80401DE; Tue, 24 Oct 2023 07:23:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343532AbjJXOWw (ORCPT + 99 others); Tue, 24 Oct 2023 10:22:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234549AbjJXOWw (ORCPT ); Tue, 24 Oct 2023 10:22:52 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D71BB6 for ; Tue, 24 Oct 2023 07:22:50 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1c9bc9e6a89so33991025ad.0 for ; Tue, 24 Oct 2023 07:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698157370; x=1698762170; 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=DMkKZbVayV+UHO5Qbc7nkBIjyL5B5bBnYpYu21nJFcE=; b=oh2gY6j1bFFD9d3nucjH1TsNFe6rzGIwKhqliU59gvwaHMmVIqPTY7UxSIRv8GvXbC A7icerkObIIdcuvd/Z5uzF6y05T+tKkz4dAb6iMG0h5N2i7/h+lAdc4kKeJ5g9WNL7ZT iIT8CLZ3Y6+7GwbxS//kWfKEfUkpUHhFSv0D0I+q72y6oqR5dZsfRuFw1cVgEtV2Bqs8 NhYV4Z8sql9gQk+JGwcB9q/LF/TuFc9qXkc+54860qFRAEY+yVdIIs/H6Gxa+Rm/Ocxz gadi0wCecbRaPpFj5I4CwJC4RvemrS5xUiaQofsafFETPmdnnRTkl9LHLiqzSilua+dc 0mfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698157370; x=1698762170; 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=DMkKZbVayV+UHO5Qbc7nkBIjyL5B5bBnYpYu21nJFcE=; b=p8s0SgpZt3Unr0ZQS5X44TT2rYipR6VImkurpp0QCQA0YQsXcCi6OQdK86agM3nwcf G9m72mMZR0URYAhS6lYVV00bdL+XL52wVXzpHNERJpY95CB5BhVBVEw1MeH45NtTT/cd lm+reTEiWf1mY1WfZeoY+/+9ESeD1dCJ+mdxuEYwYrZKd2E4zCd5F0duW4Bt6xYb08av VutlJuxIS0mjNIcq+wKbGc5zX41m++gbVZ7Rv433u1RDl3RDBvzymlI5lTrcjakeMYZ7 a6ElLBskOyOAjV+iFJXS6VwZUNAOA5PDdTMn5NE2GBvMAW9kp+hjd15wu7jeswTfoW4w 7YoA== X-Gm-Message-State: AOJu0YzQX6W1Hum73twqDGX9+F7ENyoUck2IPl9zhJSYem26xWeZtQ9n oUE9pAAC/fFEiUB94seM52OhRpXBIBY= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:64c2:b0:1cb:de60:874c with SMTP id y2-20020a17090264c200b001cbde60874cmr63314pli.12.1698157369648; Tue, 24 Oct 2023 07:22:49 -0700 (PDT) Date: Tue, 24 Oct 2023 07:22:48 -0700 In-Reply-To: <957b598d-c2bc-4568-2f36-a4ae762b49a8@gmail.com> Mime-Version: 1.0 References: <20231024002633.2540714-1-seanjc@google.com> <20231024002633.2540714-12-seanjc@google.com> <957b598d-c2bc-4568-2f36-a4ae762b49a8@gmail.com> Message-ID: Subject: Re: [PATCH v5 11/13] KVM: selftests: Test consistency of CPUID with num of fixed counters From: Sean Christopherson To: JinrongLiang Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Like Xu , Jinrong Liang 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,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, 24 Oct 2023 07:23:06 -0700 (PDT) On Tue, Oct 24, 2023, JinrongLiang wrote: > =E5=9C=A8 2023/10/24 08:26, Sean Christopherson =E5=86=99=E9=81=93: > > From: Jinrong Liang > >=20 > > Extend the PMU counters test to verify KVM emulation of fixed counters = in > > addition to general purpose counters. Fixed counters add an extra wrin= kle > > in the form of an extra supported bitmask. Thus quoth the SDM: > >=20 > > fixed-function performance counter 'i' is supported if ECX[i] || (ED= X[4:0] > i) > >=20 > > Test that KVM handles a counter being available through either method. > >=20 > > Co-developed-by: Like Xu > > Signed-off-by: Like Xu > > Signed-off-by: Jinrong Liang > > Co-developed-by: Sean Christopherson > > Signed-off-by: Sean Christopherson > > --- > > .../selftests/kvm/x86_64/pmu_counters_test.c | 58 ++++++++++++++++++= - > > 1 file changed, 55 insertions(+), 3 deletions(-) > >=20 > > diff --git a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c b/t= ools/testing/selftests/kvm/x86_64/pmu_counters_test.c > > index 274b7f4d4b53..f1d9cdd69a17 100644 > > --- a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c > > +++ b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c > > @@ -227,13 +227,19 @@ __GUEST_ASSERT(expect_gp ? vector =3D=3D GP_VECTO= R : !vector, \ > > expect_gp ? "#GP" : "no fault", msr, vector) \ > > static void guest_rd_wr_counters(uint32_t base_msr, uint8_t nr_possib= le_counters, > > - uint8_t nr_counters) > > + uint8_t nr_counters, uint32_t or_mask) > > { > > uint8_t i; > > for (i =3D 0; i < nr_possible_counters; i++) { > > const uint32_t msr =3D base_msr + i; > > - const bool expect_success =3D i < nr_counters; > > + > > + /* > > + * Fixed counters are supported if the counter is less than the > > + * number of enumerated contiguous counters *or* the counter is > > + * explicitly enumerated in the supported counters mask. > > + */ > > + const bool expect_success =3D i < nr_counters || (or_mask & BIT(i)); > > /* > > * KVM drops writes to MSR_P6_PERFCTR[0|1] if the counters are > > @@ -273,7 +279,7 @@ static void guest_test_gp_counters(void) > > else > > base_msr =3D MSR_IA32_PERFCTR0; > > - guest_rd_wr_counters(base_msr, MAX_NR_GP_COUNTERS, nr_gp_counters); > > + guest_rd_wr_counters(base_msr, MAX_NR_GP_COUNTERS, nr_gp_counters, 0)= ; > > } > > static void test_gp_counters(uint8_t nr_gp_counters, uint64_t perf_ca= p) > > @@ -292,10 +298,51 @@ static void test_gp_counters(uint8_t nr_gp_counte= rs, uint64_t perf_cap) > > kvm_vm_free(vm); > > } > > +static void guest_test_fixed_counters(void) > > +{ > > + uint64_t supported_bitmask =3D 0; > > + uint8_t nr_fixed_counters =3D 0; > > + > > + /* KVM provides fixed counters iff the vPMU version is 2+. */ >=20 > s/iff/if/ The "iff" is intentional, it's shorthand for "if and only if". Ha, it even= has a Wikipedia page: https://en.wikipedia.org/wiki/If_and_only_if.