Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1343688rwd; Thu, 25 May 2023 11:09:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ79i38fOoZ+rDYufCwActRfw/HMD72dZh3RwwnAox1VcOkhGI0lkveChC3tIushCwKG8R86 X-Received: by 2002:a17:903:1c7:b0:1ad:bccc:af77 with SMTP id e7-20020a17090301c700b001adbcccaf77mr3153753plh.18.1685038196207; Thu, 25 May 2023 11:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685038196; cv=none; d=google.com; s=arc-20160816; b=Zuv2HYFRXhBVfzn4wn+dMWxll44hBHaUInLJTZB099KZx2fd+wlBoAvfSQ3ZrcRIlo EHd2o6LhGjREx34LALL+7NbV6tZQDzG2s2KnDJjN8lE+vdyWlmavoQDBlAGLHKQm89J/ NHf2O/As6Surdk1FIpamLVl3sc9npiQ0rONd/btKQFs8wNtqPdMDBBY3HLaiam7wGakk LFKUGyV004EHsBTpqtirbB7iEdKm7Q5Wy66o1QNbYWEjSx8DgVRZ+B+P6Or3h4lE29L6 qLOvzUG7kUruLYtC3hFIEay0fRF4AKNE1F5SHr+ynXGt14+R/2Xg4+/T9XHr+CIqSF4E vIUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=XbZfqBItcXzKLk1nfsDlp5Oogh2CcWLWMFdBRAuDk8A=; b=TY3KeCCo3dlgJ0oL2Xg3ZThviUuVnSpTaVNQpaJ9nNTOGIy8GiIlS2OEuNZwBpb3E3 F2JE2dEuTvg67AbDr7SJwFGuKg1WHoZzAnjfEQNLFV4f2OctzJCdfGB5ttmtWScUDjX/ S4lcbGpCV89MyQaLICS16c3mAm4fibktuZ28Lywju4RvGHBi2SqY2UOEZJ8ZxfUgbBpI ocQEDED7wZ+/XL6Mq6o8Z3k+7Mk/v5oJr5tYQSlAOKaJ84WJ5RUoZSi4xSAH1sf6SUKF zUn3Ewuc06WaW847xN5NLfzxc8mBEE2vnlYdnk6grOyPFEy5kJJl1bSOgUrau5hvYuKj MlHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=1Fu2PdpC; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i186-20020a6387c3000000b0053415b1caa8si1652788pge.157.2023.05.25.11.09.40; Thu, 25 May 2023 11:09:56 -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=@google.com header.s=20221208 header.b=1Fu2PdpC; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239168AbjEYR4S (ORCPT + 99 others); Thu, 25 May 2023 13:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233274AbjEYR4R (ORCPT ); Thu, 25 May 2023 13:56:17 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E40BB6 for ; Thu, 25 May 2023 10:56:15 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-2536e522b5cso8086a91.3 for ; Thu, 25 May 2023 10:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685037375; x=1687629375; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XbZfqBItcXzKLk1nfsDlp5Oogh2CcWLWMFdBRAuDk8A=; b=1Fu2PdpCfqH0lSpeQe9fNQSos+bXML3EY2SUDzAa3hOINxqpZBiwx+MKgAXVqSW3Mf MW7fpm4nqWSK2vXx3qvWinUTBWg7a9vccLx5zjdoUU4QTqUpXQq0Cx8SEyyWG85HYd/y 5kl7Y7yefIzp6JZhL1XHcqCn/84W0wDSnSG7xOdPYS6bKI1jZQBfUCkWFKeCtb5Kmdr4 8HY43RvH5ZpeqfR3AFXcThEpJ516hVdsT60gZ/C+0wXpjuO0XBywIqv8zs6gikrGO+VE VATFnSylOGmFtIWVBMuC8HB7mydZsgzQ0yFx5WAscXShL+wBFMj8nK1l28M7hlQG4HXl e99w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685037375; x=1687629375; h=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=XbZfqBItcXzKLk1nfsDlp5Oogh2CcWLWMFdBRAuDk8A=; b=b4eQ/Y7oqg+hFySi20lCfsBl5fCO8tM9qCQClOaNEdU1XZS3hEJTHKjzwIn9vvl/ye G0KoiTr4POR8u5Wd3MMg5X+AAxWTSRg/UD6CaeruTlX2JTlL2+48Ba6HmfWHP6ocxLGM Pudg5w5uyTzusyTJmjOcStVWLf7FHIxZkXWodhswdS9eSSQn06eMAphF972EKTxequv3 NhZ8OpzkVfcVCgplIN2dVqddGnDszUB9SArtrzprTRlShTWzDyx3ceFx8rdFni754bi3 BXL6kW2FhXR8xDnsZOcoJq7sxt2cdM+6kMlbLCgxry4QrktDW28p7zLICf01z7Opb3Gm uaQg== X-Gm-Message-State: AC+VfDzFFMEBznH21QqVbdi1x1ZVeNmhlpaIJfvhsCH0VyBZZHOFxWtd sbWJNWTA2uvRw3lreMXD8o9vBJEWrgg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:fc4:b0:24d:fb1d:106d with SMTP id gd4-20020a17090b0fc400b0024dfb1d106dmr537997pjb.2.1685037374878; Thu, 25 May 2023 10:56:14 -0700 (PDT) Date: Thu, 25 May 2023 10:56:13 -0700 In-Reply-To: <20230420104622.12504-5-ljrcore@126.com> Mime-Version: 1.0 References: <20230420104622.12504-1-ljrcore@126.com> <20230420104622.12504-5-ljrcore@126.com> Message-ID: Subject: Re: [PATCH v2 4/7] KVM: x86/pmu: Add documentation for fixed ctr on PMU filter From: Sean Christopherson To: Jinrong Liang Cc: Like Xu , Paolo Bonzini , Jonathan Corbet , Shuah Khan , Aaron Lewis , David Matlack , Vishal Annapurve , Wanpeng Li , Bagas Sanjaya , Jinrong Liang , linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" 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,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 20, 2023, Jinrong Liang wrote: > From: Jinrong Liang > > From: Jinrong Liang > > Update the documentation for the KVM_SET_PMU_EVENT_FILTER ioctl > to include a detailed description of how fixed performance events > are handled in the pmu filter. The action and fixed_counter_bitmap > members of the pmu filter to determine whether fixed performance > events can be programmed by the guest. This information is helpful > for correctly configuring the fixed_counter_bitmap and action fields > to filter fixed performance events. > > Suggested-by: Like Xu > Reported-by: kernel test robot > Link: https://lore.kernel.org/oe-kbuild-all/202304150850.rx4UDDsB-lkp@intel.com > Signed-off-by: Jinrong Liang > --- Please post this separately from the selftests changes. > 1 file changed, 21 insertions(+) > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > index a69e91088d76..b5836767e0e7 100644 > --- a/Documentation/virt/kvm/api.rst > +++ b/Documentation/virt/kvm/api.rst > @@ -5122,6 +5122,27 @@ Valid values for 'action':: > #define KVM_PMU_EVENT_ALLOW 0 > #define KVM_PMU_EVENT_DENY 1 > > +Via this API, KVM userspace can also control the behavior of the VM's fixed > +counters (if any) by configuring the "action" and "fixed_counter_bitmap" fields. > + > +Specifically, KVM follows the following pseudo-code when determining whether to > +allow the guest FixCtr[i] to count its pre-defined fixed event:: > + > + FixCtr[i]_is_allowed = (action == ALLOW) && (bitmap & BIT(i)) || > + (action == DENY) && !(bitmap & BIT(i)); > + FixCtr[i]_is_denied = !FixCtr[i]_is_allowed; > + > +Note once this API interface is called, the default zero value of the field No, there is no "default" value. Userspace provides the exact value. The KVM *selftest* clears fixed_counter_bitmap in all cases, but there is no default anywhere. > +"fixed_counter_bitmap" will implicitly affect all fixed counters, even if it's There is no implicit behavior, userspace very explicitly provides fixed_counter_bitmap. > +expected to be used only to control the events on generic counters. I would rather phrase this as: --- KVM always consumes fixed_counter_bitmap, it's userspace's responsibility to ensure fixed_counter_bitmap is set correctly, e.g. if userspace wants to define a filter that only affects general purpose counters. --- > +In addition, pre-defined performance events on the fixed counters already have > +event_select and unit_mask values defined, which means userspace can also > +control fixed counters by configuring "action"+ "events" fields. > > +When there is a contradiction between these two polices, the fixed performance > +counter will only follow the rule of the pseudo-code above. This is unnecessary vague. I think what you're saying is, with a slight reword of the first paragraph too: --- Note, the "events" field also applies to fixed counters' hardcoded event_select and unit_mask values. "fixed_counter_bitmap" has higher priority than "events" if there is a contradiction between the two. ---