Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7575831rwp; Tue, 18 Jul 2023 18:27:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlGifr3bz8BUaWGUKa0uGWXPvXoNnMMRTehTz7NHAUWlJPC+J+6D07CYpobDkG4aIf4E6opn X-Received: by 2002:a05:6358:27a3:b0:135:b4c:a4b4 with SMTP id l35-20020a05635827a300b001350b4ca4b4mr1352232rwb.14.1689730060816; Tue, 18 Jul 2023 18:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689730060; cv=none; d=google.com; s=arc-20160816; b=J7FE3xAqjhmnVReSDe9jBzu/unu4M6uSDiSQjhlS+GGOFu0n9AHphv2u2rv4+CvevM SkiK4JBx4eznytmt2tf3e0Vh+iiY8f0xP+0mU6Uq5f5tu/IZizKwb+eMVKgBm/vu8LUu K6LBB0wt31YWgmr8xt1FvlNofIuPPlSOuVjL/Aae2x3GC5TiSBBABwrRo1o8V+Gp6zRk QvUryVnfh7fc+W5T5chR6YgQ4Rzb47h7pP+HNeaemXFDNlbz3/P9XWYwGKV1vh0Mjrx5 /HAaYHx43MYUFXEokE2VGggzTCA7aBbQEDWZSgL7dIKsGz7aPy5BLfC7UyU+bAEJ//34 lvpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=dFOCio/Zfe9p1GfONJpPjKEYD+NkX9/ELuqh7E52mvg=; fh=UqO/PQpNCau320ueX0+iYlM7UKorOr3THVbNOLSoXhE=; b=Pnlb8Huh7dJ25vIcS/JhydgwQncmw9PxBh+nrcmP0HzBqaIbiA8KDcT0/kUBCTE4bN h7jsRiojw+RRWrjBXVEAvhOdGyx/MUOFvUrtYJ6qLVFGbo8dJEFfe92GfGggKGwK3dLB KVz006pto3ttIr8oZCrJ5r2YQj+Rs1w2yFWQBUnfGquVlyzghvMwbPCEltIgayL/W7F+ t1X+NQb17w3YLSHtmhNEpSMK1Swe+lBl2eJEDl8vyOP9dRN5gOoOynDenbGlmPyF+GXH gIlSdpiEOHu6cn65IkJUnXspe7ZjaYVoxg2zrV8tt4Xi8Z6Ce9e32iyrLV/SQ188V+P0 kMKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=HAtDb+vL; 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 h69-20020a638348000000b0055c13ae86b1si2375919pge.597.2023.07.18.18.27.27; Tue, 18 Jul 2023 18:27:40 -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=HAtDb+vL; 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 S229797AbjGSBSE (ORCPT + 99 others); Tue, 18 Jul 2023 21:18:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjGSBR4 (ORCPT ); Tue, 18 Jul 2023 21:17:56 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70B341BC9; Tue, 18 Jul 2023 18:17:55 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1b8a462e0b0so39364735ad.3; Tue, 18 Jul 2023 18:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689729475; x=1690334275; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=dFOCio/Zfe9p1GfONJpPjKEYD+NkX9/ELuqh7E52mvg=; b=HAtDb+vL7iVnVrTmPPHFbJrX424J4PzNY0HmDcoxOr5X0XtC5WME1g9PEQImowgBmE eArhOXtvvHYX38Ih+X6X9k7+qy/ug6fbuFxrDKMFBxulS+O+svM3ye9Q4QBahMbTIKmv GBCegjLMpcsMGfL9ZD0RBd6ta34Hf7eklbyd9iVnNgKARKCRo6PMQUQfBxmZHFbF1UrX Y2WLdjIJms66+qioMRWZTOmpDmqx/HAMlRqtr8mi28q3cav6iig2X4EnV+bw0Qk9/2y9 i5Treeohd0D7I2noquW4xogtn6ShsOrhg1jnEXTc0IbXZ+BoswU3msMYwHbSppRl5Dgd Xmqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689729475; x=1690334275; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=dFOCio/Zfe9p1GfONJpPjKEYD+NkX9/ELuqh7E52mvg=; b=W2bE6IBSsIQDZhWBMjOVFmC2ninuomSp1BQLowreiRPrS8EaJ0NUx87F/45kfo/iNd kUecibCjnDFvcJVFrPihPgwhzkKhXx9IDJx4rgfwE1t2Feheq0lPsXqwd6XlyXNGVqf+ FYcKauJHEf/NjeQ+7f2/N8ilCgGGMLYzn7+qt0DSJsu05r95QJw03LHPspb00l2csODz 5lz9YmzxSLLAD+PZyZdq5xu2llfSOg0cujBu6kAvD7WW3UM8irs8qoDP7hQmQPQMHSKQ HkO0EtK/xRwygkhyG2s7G0wo5bUHjy3VwCacA0/Q0mQ8be+YxMGojMC1TS/E7tAo1tLe hZkQ== X-Gm-Message-State: ABy/qLbOM5X5kLo/d4n5xD4ZkM2fQTIntApsHVd87ljLC7LIeazAH/R/ tRE5NpHZanzCYBUp1pjuOhc= X-Received: by 2002:a17:902:f54d:b0:1b9:f1bd:b18b with SMTP id h13-20020a170902f54d00b001b9f1bdb18bmr1315043plf.6.1689729474705; Tue, 18 Jul 2023 18:17:54 -0700 (PDT) Received: from localhost ([192.55.54.50]) by smtp.gmail.com with ESMTPSA id 4-20020a170902c14400b001b9bebb7a9dsm2500203plj.90.2023.07.18.18.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 18:17:54 -0700 (PDT) Date: Tue, 18 Jul 2023 18:17:52 -0700 From: Isaku Yamahata To: Jinrong Liang 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, isaku.yamahata@gmail.com Subject: Re: [PATCH v4 4/6] KVM: selftests: Add test cases for unsupported PMU event filter input values Message-ID: <20230719011752.GD25699@ls.amr.corp.intel.com> References: <20230717062343.3743-1-cloudliang@tencent.com> <20230717062343.3743-5-cloudliang@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230717062343.3743-5-cloudliang@tencent.com> 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_BLOCKED,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 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 the > PMU event filter. The tests cover unsupported "action" values, unsupported > "flags" values, and unsupported "nevents" values. All these cases should > return an error, as they are currently not supported by the filter. > Furthermore, the tests also cover the scenario where setting non-existent > 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_DENY + 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 = 1, this happens to get wanted result, though. > +#define PMU_EVENT_FILTER_INVALID_NEVENTS (MAX_FILTER_EVENTS + 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_vcpu *vcpu, uint64_t event, > > static void test_filter_ioctl(struct kvm_vcpu *vcpu) > { > + uint8_t nr_fixed_counters = kvm_cpu_property(X86_PROPERTY_PMU_NR_FIXED_COUNTERS); > + struct __kvm_pmu_event_filter f; > uint64_t e = ~0ul; > int r; > > @@ -777,6 +783,26 @@ static void test_filter_ioctl(struct kvm_vcpu *vcpu) > KVM_PMU_EVENT_FLAG_MASKED_EVENTS, > KVM_PMU_EVENT_ALLOW); > TEST_ASSERT(r == 0, "Valid PMU Event Filter is failing"); > + > + f = base_event_filter; > + f.action = PMU_EVENT_FILTER_INVALID_ACTION; > + r = do_vcpu_set_pmu_event_filter(vcpu, &f); > + TEST_ASSERT(r, "Set invalid action is expected to fail"); > + > + f = base_event_filter; > + f.flags = PMU_EVENT_FILTER_INVALID_FLAGS; > + r = do_vcpu_set_pmu_event_filter(vcpu, &f); > + TEST_ASSERT(r, "Set invalid flags is expected to fail"); > + > + f = base_event_filter; > + f.nevents = PMU_EVENT_FILTER_INVALID_NEVENTS; > + r = do_vcpu_set_pmu_event_filter(vcpu, &f); > + TEST_ASSERT(r, "Exceeding the max number of filter events should fail"); > + > + f = base_event_filter; > + f.fixed_counter_bitmap = ~GENMASK_ULL(nr_fixed_counters, 0); > + r = do_vcpu_set_pmu_event_filter(vcpu, &f); > + TEST_ASSERT(!r, "Masking non-existent fixed counters should be allowed"); > } > > int main(int argc, char *argv[]) > -- > 2.39.3 > -- Isaku Yamahata