Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp322730rdb; Sat, 19 Aug 2023 03:21:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0reIx4adge+F4tk+o/svQt94A5nPiXT/Qdsliflf8S+at/bP4kq4lM72LOYW7KnbFVNci X-Received: by 2002:a05:6a21:3294:b0:137:3eba:b808 with SMTP id yt20-20020a056a21329400b001373ebab808mr2601383pzb.5.1692440469468; Sat, 19 Aug 2023 03:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692440469; cv=none; d=google.com; s=arc-20160816; b=KU+dQPykvq0lBYZ30bWetXEAc0w+KpQ+/GHPI+6VYU/9BWvdMmw7BOlN81zHSI9Q+c FnLATLBqthJglkcA54sjJTI07ZSM7qkazFUupY0txOHxMsBks0wPF3zrbeGlT/OBWQQr dKinLZqSrp1ol+fozGZifwtxMGOlHCysvap5bwBF1MnfgS4Rwyvqx7xd2zb55g8TEAmB 7k/1y76cjYjhI3KaV2UYhE+cKMXzZ8BjmJw2p76O+nrTb0IstWuTV/VbcFLW2KCdGmGm Y06RyCn7DGEvEZQkEuhfcJjWzSFZWwl8QtQAjxrVCsloVGTC/3ultjLthm/rqALGyh6J pFdQ== 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=KU+yygDiyP0ELbBFxmC0szeJUfwpE0TiBmbPQ8YXVAs=; fh=Dy/rEDhrs+E4iXecvLh474vHepjbRYA8H4nUgPl3if4=; b=v7ZLyHywbIUnGe69KBnPAeyIOwWyHTxjLbeHISfazPBlneX8RjHbVqDbJ3GZyIPVOP NqAMN1IY9ReF1RQIjTQ2Mt3rqV4rd0QC7vWPa5me80/5dkZGotLZtgnuOIIRGm1SI5DV eLufMea/MvHCTG2da1okzoaUrRCc2k4Y4lV9yas4Bty9jNa84NJbA/yUwF6L4tXkbjeX vPFuT9AWq/cqY2PMhsknRaORQIuCoAmtVSbkjTDqyoOWIlyls0n+xVKV1UICSA5+WW99 2hKJCAgTe4RA13SBp94YDglTZ3hugyH/qUqDBE8bmVOtj6Y/YVtuABWHztUImc5pmjy3 z1yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=zNA3vpDD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m9-20020a654389000000b0055bc23bdde5si3172977pgp.176.2023.08.19.03.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 03:21:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=zNA3vpDD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 29F45459FD; Sat, 19 Aug 2023 01:30:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354817AbjHQUR1 (ORCPT + 99 others); Thu, 17 Aug 2023 16:17:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354392AbjHQURS (ORCPT ); Thu, 17 Aug 2023 16:17:18 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E519359C for ; Thu, 17 Aug 2023 13:17:16 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5646868b9e7so308593a12.3 for ; Thu, 17 Aug 2023 13:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692303436; x=1692908236; 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=KU+yygDiyP0ELbBFxmC0szeJUfwpE0TiBmbPQ8YXVAs=; b=zNA3vpDDz1KyBjk9Ob5BUHexoZIGyPiAf/jYnuCLTrIqL4j8d6uRJul5dmw74Bh5Hq SeyuGFaDDWqXuIHXDZA8/MCkbxdNniW3sClCvGAJwf+6uB9P9YBYZucziWA+uHZ9V3aQ ry1zwBbNsGxEkazo8EH9jBDiVKZ6gZuLtJp6BpHlGyFW2+HSz0J3LwOKAJBm5+Sbpzzh 1dOvxxvTnzFRJ0DUIV9Np2zj6Wx5KXBVohTo0UHZTaxclJriOTeM0q8Ral8VlimAaMPU HI0tbM5WA3rH/97lmAIvs2Vj+Px3wTzwhMfDsgg9wXUriOKOFynRHp9VmuR+kHhQtls9 snsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692303436; x=1692908236; 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=KU+yygDiyP0ELbBFxmC0szeJUfwpE0TiBmbPQ8YXVAs=; b=TbFtmr34WyuzVTj8xwiTh75yQjaVPCEddDXO+giwYD9LY88OjP0KjkEWX1vy6fg3my IO0EsIsOraP7He3M9SKApmT0kDIixZBOm/7Bp8lC+wLxJVRb3XXP/jBJXKIcqINfuM5A 51CLOFYHDJf6kWLXRkgxG4hVLauZg4ea+vsazQF9WA+jJNb/wEM9Db+KcXjhnWnvQjGd hrJlbWJFpTfPN5pgRf9SW9pr6k8/8/z+AJe1rbajkzKLa4jdiGF7ElSPuBENYggQ4pwX F/ghTnkRfCXQt//t33QbtNvba1AbToOBlK8rec/IgdsditNynj9I5xjOvQj+ie58i1Ml us9w== X-Gm-Message-State: AOJu0YyqlFAdj43FKvWrDUZ+YWV9QeYCEDTQXZTbnyJTOFmCkKHe5gjt IBpg1Obwz5gAV8rkOQyFNWFujsXIywM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:b00f:0:b0:565:dddd:1f65 with SMTP id h15-20020a63b00f000000b00565dddd1f65mr61039pgf.7.1692303435763; Thu, 17 Aug 2023 13:17:15 -0700 (PDT) Date: Thu, 17 Aug 2023 13:17:14 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230810090945.16053-1-cloudliang@tencent.com> <20230810090945.16053-4-cloudliang@tencent.com> <20230814234926.GD2257301@ls.amr.corp.intel.com> Message-ID: Subject: Re: [PATCH v6 3/6] KVM: selftests: Introduce __kvm_pmu_event_filter to improved event filter settings From: Sean Christopherson To: Jinrong Liang Cc: Isaku Yamahata , Paolo Bonzini , Isaku Yamahata , 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 Tue, Aug 15, 2023, Jinrong Liang wrote: > Isaku Yamahata =E4=BA=8E2023=E5=B9=B48=E6=9C= =8815=E6=97=A5=E5=91=A8=E4=BA=8C 07:49=E5=86=99=E9=81=93=EF=BC=9A > > > > On Thu, Aug 10, 2023 at 05:09:42PM +0800, > > Jinrong Liang wrote: > > > > > From: Jinrong Liang > > > > > > Add custom "__kvm_pmu_event_filter" structure to improve pmu event > > > filter settings. Simplifies event filter setup by organizing event > > > filter parameters in a cleaner, more organized way. > > > > > > Suggested-by: Sean Christopherson > > > Signed-off-by: Jinrong Liang > > > --- > > > .../kvm/x86_64/pmu_event_filter_test.c | 182 +++++++++-------= -- > > > 1 file changed, 90 insertions(+), 92 deletions(-) > > > > > > 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 5ac05e64bec9..94f5a89aac40 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 > > > @@ -28,6 +28,10 @@ > > > > > > #define NUM_BRANCHES 42 > > > > > > +/* Matches KVM_PMU_EVENT_FILTER_MAX_EVENTS in pmu.c */ > > > +#define MAX_FILTER_EVENTS 300 > > > > Can we simply use KVM_PMU_EVENT_FILTER_MAX_EVENTS and remove MAX_FILTER= _EVENTS? >=20 > I didn't find the definition of KVM_PMU_EVENT_FILTER_MAX_EVENTS in > selftests. KVM_PMU_EVENT_FILTER_MAX_EVENTS is defined in pmu.c. To use > it, we need to define it in selftests. Huh. That seems like something that should be enumerated to userspace. > > > +#define MAX_TEST_EVENTS 10 > > > + > > > /* > > > * This is how the event selector and unit mask are stored in an AMD > > > * core performance event-select register. Intel's format is similar= , > > > @@ -69,21 +73,33 @@ > > > > > > #define INST_RETIRED EVENT(0xc0, 0) > > > > > > +struct __kvm_pmu_event_filter { > > > + __u32 action; > > > + __u32 nevents; > > > + __u32 fixed_counter_bitmap; > > > + __u32 flags; > > > + __u32 pad[4]; > > > + __u64 events[MAX_FILTER_EVENTS]; > > > +}; > > > + > > > > Is this same to struct kvm_pmu_event_filter? >=20 > In tools/arch/x86/include/uapi/asm/kvm.h >=20 > /* for KVM_CAP_PMU_EVENT_FILTER */ > struct kvm_pmu_event_filter { > __u32 action; > __u32 nevents; > __u32 fixed_counter_bitmap; > __u32 flags; > __u32 pad[4]; > __u64 events[]; > }; To more directly answer Isaku's question: They're *basically* the same, and have an identical layout, but the struct = defined by KVM uses a flexible array because the number of events comes from usersp= ace and forcing userspace to create an 1KiB+ object just to define a single eve= nt filter would be obnoxious. There are alternatives, e.g. using an struct overlay to set a single entry: struct { struct kvm_msrs header; struct kvm_msr_entry entry; } buffer =3D {}; memset(&buffer, 0, sizeof(buffer)); buffer.header.nmsrs =3D 1; buffer.entry.index =3D msr_index; buffer.entry.data =3D msr_value; but that gets annoying (and IMO confusing) because of the nested structs. I'll massage the changelog to callout the alternative, and why it's undesir= able.