Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7687628rwp; Tue, 18 Jul 2023 21:18:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlHNqEbfZR6vbCfvvA71nc9UcSOgwnkmYM1ZsZ1xgFMTG5rxpM/8oU61kHTn0o9oyE3Jm7Fo X-Received: by 2002:a17:907:2da7:b0:993:eef2:5d5d with SMTP id gt39-20020a1709072da700b00993eef25d5dmr1715389ejc.27.1689740308337; Tue, 18 Jul 2023 21:18:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689740308; cv=none; d=google.com; s=arc-20160816; b=OdPTH8H7qMoan5nPb4wy+E/mgZVts8HVnCX45Uv1i0fbJHJ6ydSw7oOdo1ykY7dzz2 mNA+RPi+zVAvIr45SIPWAzUW3OFM9zB8tcEz63A1KMSUTiyUA6l2o3219UCIuBMO+ybL 6Uv4M7qgchYjKx97AYbSRpgJ0fuNe/EHb3wuecMcDoGWysbamhwkd9oIKeCuTqf73ctg q8N1SzP1fyB26qpbQm858UrrV1EXmXKdfuCi4I7OCBrtr0NnX2LNE2ndsoIfAT3pzo1f Rp1De7uzhnqjOjNZ/7App6YZHje3uvIfRVQW6lav2T+tSsebJm+llxjq7U4PKiGirC9I WfDA== 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:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=qio6pzOCmaXDOiQChQf7WzygxDgvq1z60uM5r+IDyqY=; fh=vYjSwXbp++Zaad0V0kAh+M8H8OQ3IG8kWHXLFZ6BGtM=; b=Lzsz3gdH+KySC7Dkw7jb3xun7QVImPm8fT3n9eB/ZWVKC2+ag3S98kxYb7pTDJPzAZ zrrqAzvWMr2v21CAi948ni2VESAFfM9ic3d/4p+yxnt5J2AZV3Ld7Tcuxc/H5TY0j9p6 a3IdeQ5CCo+KbUKFnQpOgiettfD5IRFUPY+4sJ5nOkETbgoz/ekepPOR+FpyokVxRDVK LHxHmdOeGt7rsFNr+TJWzOH92UL/wqp/8zLDzE89UhbxkGWGyQuOjW/NYywvvnXCZQN6 dbyezD3xoVoYZArNOTY/PURJXQXRGdG1TAInLGXCY/ueZZxze6giZMxp1b+Eqv5LSDMa d+Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Y2aUVkMB; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j21-20020a170906279500b00992be03096dsi1981033ejc.846.2023.07.18.21.18.03; Tue, 18 Jul 2023 21:18:28 -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=@gmail.com header.s=20221208 header.b=Y2aUVkMB; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230390AbjGSDVK (ORCPT + 99 others); Tue, 18 Jul 2023 23:21:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjGSDVI (ORCPT ); Tue, 18 Jul 2023 23:21:08 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F2D31BDD; Tue, 18 Jul 2023 20:21:07 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id 4fb4d7f45d1cf-51e99584a82so8725061a12.1; Tue, 18 Jul 2023 20:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689736865; x=1692328865; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qio6pzOCmaXDOiQChQf7WzygxDgvq1z60uM5r+IDyqY=; b=Y2aUVkMBihFO9W2ebrAbF83gFoTV8pv2h0CasKOz7w2rnrjkU3q4qLMH1WffzyCDvQ TpW9L/jmf9/4ZK8IFVPCCZnwRVemTS1YS9+cLDpx+d3JZDYFOQvxn/QKETpqLfjAQ86X KvPCA9NwvoViVru65MbhLgqzE4TRz18Bd1M3dnpBvZAypWPAZdaZn0SMDBopziEFMkRo tGkRXXtw5KepS72fszxopa4FrxSftLvUF6spR0iTDGJp62Wb731J+4lsQJlY+H5D3J1C U6TOepFXm8jC0sjXeuBmyipIpXKcTMQ4Ngg3+nBeZ69usw6/lIypnvZ0qVQI08jsJWSm 75NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689736865; x=1692328865; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qio6pzOCmaXDOiQChQf7WzygxDgvq1z60uM5r+IDyqY=; b=R5HnbtppeGoKbQXFTl4nMX/o/kido3mVdmDm1OlZpQt5X7o/+PyBQwxp6igOFnZ91R eeHjBdukm/AgcmAqxCc31+CcUZMAciJfFEb1NxNusi12pmWgc/R0ENaIJDLJIlKbIVnF BB/OGNVZCkmx3kpcq+Pw0211KLtPdgBtH73IZtNihYMTM9KchtfW1yBzNzclWU4N5KHF BUbD9Dss0zPIXIUnxw5bqH4Al1Hqnd6Hucbe5oM8/7D8h7oPW4pWN17dqjkCn03MGFD+ c30XLKih8vqi/x3L0uqdOXI37qaRcEi/+S4yp4AEdrVJMPVESmNgEj+AJXlYsk98i0/6 sWEg== X-Gm-Message-State: ABy/qLbpV2MS/LaqR3pUB6Gaiume1ELpe21P2lwaBlckV2F8w77xNDEL 0TnNSYf0dZf6yzxgHaY+8w9Hvy1bGP4iHxySL5HS6wMGjdezDlBj2j0= X-Received: by 2002:aa7:d418:0:b0:51e:2282:e1fc with SMTP id z24-20020aa7d418000000b0051e2282e1fcmr1518758edq.6.1689736865579; Tue, 18 Jul 2023 20:21:05 -0700 (PDT) MIME-Version: 1.0 References: <20230717062343.3743-1-cloudliang@tencent.com> <20230717062343.3743-5-cloudliang@tencent.com> <20230719011752.GD25699@ls.amr.corp.intel.com> In-Reply-To: <20230719011752.GD25699@ls.amr.corp.intel.com> From: Jinrong Liang Date: Wed, 19 Jul 2023 11:20:54 +0800 Message-ID: Subject: Re: [PATCH v4 4/6] KVM: selftests: Add test cases for unsupported PMU event filter input values To: Isaku Yamahata Cc: Sean Christopherson , Paolo Bonzini , Jim Mattson , Shuah Khan , Aaron Lewis , David Matlack , Vishal Annapurve , Wanpeng Li , Like Xu , Jinrong Liang , linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 Isaku Yamahata =E4=BA=8E2023=E5=B9=B47=E6=9C=881= 9=E6=97=A5=E5=91=A8=E4=B8=89 09:17=E5=86=99=E9=81=93=EF=BC=9A > > On Mon, Jul 17, 2023 at 02:23:41PM +0800, > Jinrong Liang wrote: > > > From: Jinrong Liang > > > > Add test cases to verify the handling of unsupported input values for t= he > > PMU event filter. The tests cover unsupported "action" values, unsuppor= ted > > "flags" values, and unsupported "nevents" values. All these cases shoul= d > > return an error, as they are currently not supported by the filter. > > Furthermore, the tests also cover the scenario where setting non-existe= nt > > fixed counters in the fixed bitmap does not fail. > > > > Signed-off-by: Jinrong Liang > > --- > > .../kvm/x86_64/pmu_event_filter_test.c | 26 +++++++++++++++++++ > > 1 file changed, 26 insertions(+) > > > > diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c= b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c > > index ffcbbf25b29b..63f85f583ef8 100644 > > --- a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c > > +++ b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c > > @@ -32,6 +32,10 @@ > > #define MAX_FILTER_EVENTS 300 > > #define MAX_TEST_EVENTS 10 > > > > +#define PMU_EVENT_FILTER_INVALID_ACTION (KVM_PMU_EVENT_DE= NY + 1) > > +#define PMU_EVENT_FILTER_INVALID_FLAGS (KVM_PMU_= EVENT_FLAG_MASKED_EVENTS + 1) > > flag is a bit mask. Not number. So +1 sounds weird. > As KVM_PMU_EVENT_FLAGS_VALID_MASK =3D 1, this happens to get wanted resu= lt, though. We need an invalid flags, KVM_PMU_EVENT_FLAGS_VALID_MASK is actually equal to KVM_PMU_EVENT_FLAG_MASKED_EVENTS. In kvm.h: #define KVM_PMU_EVENT_FLAG_MASKED_EVENTS BIT(0) #define KVM_PMU_EVENT_FLAGS_VALID_MASK (KVM_PMU_EVENT_FLAG_MASKED_EVENTS) How about this modification: #define PMU_EVENT_FILTER_INVALID_FLAGS (KVM_PMU_EVENT_FLAGS_VALID_MASK << 1) > > > > +#define PMU_EVENT_FILTER_INVALID_NEVENTS (MAX_FILTER_EVENT= S + 1) > > + > > /* > > * This is how the event selector and unit mask are stored in an AMD > > * core performance event-select register. Intel's format is similar, > > @@ -757,6 +761,8 @@ static int set_pmu_single_event_filter(struct kvm_v= cpu *vcpu, uint64_t event, > > > > static void test_filter_ioctl(struct kvm_vcpu *vcpu) > > { > > + uint8_t nr_fixed_counters =3D kvm_cpu_property(X86_PROPERTY_PMU_N= R_FIXED_COUNTERS); > > + struct __kvm_pmu_event_filter f; > > uint64_t e =3D ~0ul; > > int r; > > > > @@ -777,6 +783,26 @@ static void test_filter_ioctl(struct kvm_vcpu *vcp= u) > > KVM_PMU_EVENT_FLAG_MASKED_EVENTS, > > KVM_PMU_EVENT_ALLOW); > > TEST_ASSERT(r =3D=3D 0, "Valid PMU Event Filter is failing"); > > + > > + f =3D base_event_filter; > > + f.action =3D PMU_EVENT_FILTER_INVALID_ACTION; > > + r =3D do_vcpu_set_pmu_event_filter(vcpu, &f); > > + TEST_ASSERT(r, "Set invalid action is expected to fail"); > > + > > + f =3D base_event_filter; > > + f.flags =3D PMU_EVENT_FILTER_INVALID_FLAGS; > > + r =3D do_vcpu_set_pmu_event_filter(vcpu, &f); > > + TEST_ASSERT(r, "Set invalid flags is expected to fail"); > > + > > + f =3D base_event_filter; > > + f.nevents =3D PMU_EVENT_FILTER_INVALID_NEVENTS; > > + r =3D do_vcpu_set_pmu_event_filter(vcpu, &f); > > + TEST_ASSERT(r, "Exceeding the max number of filter events should = fail"); > > + > > + f =3D base_event_filter; > > + f.fixed_counter_bitmap =3D ~GENMASK_ULL(nr_fixed_counters, 0); > > + r =3D do_vcpu_set_pmu_event_filter(vcpu, &f); > > + TEST_ASSERT(!r, "Masking non-existent fixed counters should be al= lowed"); > > } > > > > int main(int argc, char *argv[]) > > -- > > 2.39.3 > > > > -- > Isaku Yamahata