Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp445609rdg; Tue, 10 Oct 2023 15:31:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEuUg+Mfdq8HvLN+/CpckXVP21p5WpQ8v7skTUowzh5jdSRzAMl+BWF6FbX3T3lnh7qwimS X-Received: by 2002:a05:6a00:13a3:b0:693:4552:cd6a with SMTP id t35-20020a056a0013a300b006934552cd6amr20077310pfg.16.1696977069401; Tue, 10 Oct 2023 15:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977069; cv=none; d=google.com; s=arc-20160816; b=r4XvNtaea6WCrAWrVB7/5mRu2nmYyRxFUEPUH6bF1xb7cIIyCgHEFkp73svnVxGzo6 4YVkVq6yZk32x99efTJpfjWqmYXPCNjEX0kV+lRbrQgeAPcl+tbdqeIS2e6U1INwQX05 9x8n9ixcueO1Y72ljo19/zYo10S9XfesBpXlfs7Z9qUtA1t7UVQEnn6rpA2BmQ/I+Ip/ LG1Uud9S165JS7piPdptLo2SfhIXCq2lLAEg6sIOKq/3zUK+IxAvJmIcIz8mZvp/7vzv UNmXmqOqXmGJIUCryIiGjulPVgmzfZqqPqOjNY+kQvUh+U8JORM+/LwQagsrRDTzOyYD 72Yg== 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:dkim-signature:date; bh=/lM90Up6SI7d/uT4OcCpfnqLaN2bM1VE++77i6UZHLg=; fh=4I6BNv7iobpZrRcbueKA7r9RD02xPQmynyU/PeDFguM=; b=KhqaSehHAt4j1ODtmAWqvWIlvD5N53PCwI4oE/lll72amvXSg+yc9a1diW4WWSUS5X 4YxbmpLNkFBsO5K2BTIrhfaxkaRtTgZOx5ay+ZcY6ao6g6T1bRODxUYRq8LvF5syFnog M/laV1jnzZoyX1+nXvKyuoWi9zM0RMwlw/6TDzMOG5vx5PqsEhpE36SVRUkojePSxze7 lUjmq5GhjCRhnn54m5DLsZbmizR7aA0K7wevmzoLbXVQ0NIAhGosHGv0JhgPlUDZ2oZ4 CwYa16KjZezcbapRXwnadDx08G8zdaSRNc5Blo7FXe/C3j3x8mLpNDWJs/s2Vny6G95e vJBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=oaZYsJNm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id bw11-20020a056a00408b00b006a68a46431bsi3997506pfb.50.2023.10.10.15.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:31:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=oaZYsJNm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 991FF801D5B7; Tue, 10 Oct 2023 15:31:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234402AbjJJWax (ORCPT + 99 others); Tue, 10 Oct 2023 18:30:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233121AbjJJWav (ORCPT ); Tue, 10 Oct 2023 18:30:51 -0400 Received: from out-205.mta1.migadu.com (out-205.mta1.migadu.com [95.215.58.205]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52203E3 for ; Tue, 10 Oct 2023 15:30:39 -0700 (PDT) Date: Tue, 10 Oct 2023 22:30:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1696977037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/lM90Up6SI7d/uT4OcCpfnqLaN2bM1VE++77i6UZHLg=; b=oaZYsJNm62P+DG0gECk9TGwg1Rvb25tEqRmt+8I4Vt24ltE+ubl4Ksj2iTkpsKf0Lz9SAc GDjT4LfvV3vkJtIiVgkNYEBt9JlLmDEyPy8AlD4DelofZNOVn6GW9JSW1Vo7qSjP23anU4 Q6vUTqEojDviyiXttF+ECliCoHG4gJo= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Raghavendra Rao Ananta Cc: Marc Zyngier , Alexandru Elisei , James Morse , Suzuki K Poulose , Paolo Bonzini , Zenghui Yu , Shaoqin Huang , Jing Zhang , Reiji Watanabe , Colton Lewis , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v7 06/12] KVM: arm64: PMU: Add a helper to read the number of counters Message-ID: References: <20231009230858.3444834-1-rananta@google.com> <20231009230858.3444834-7-rananta@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231009230858.3444834-7-rananta@google.com> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 10 Oct 2023 15:31:07 -0700 (PDT) X-Spam-Level: ** On Mon, Oct 09, 2023 at 11:08:52PM +0000, Raghavendra Rao Ananta wrote: > Add a helper, kvm_arm_get_num_counters(), to read the number > of counters from the arm_pmu associated to the VM. Make the > function global as upcoming patches will be interested to > know the value while setting the PMCR.N of the guest from > userspace. > > Signed-off-by: Raghavendra Rao Ananta > --- > arch/arm64/kvm/pmu-emul.c | 17 +++++++++++++++++ > include/kvm/arm_pmu.h | 6 ++++++ > 2 files changed, 23 insertions(+) > > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > index a161d6266a5c..84aa8efd9163 100644 > --- a/arch/arm64/kvm/pmu-emul.c > +++ b/arch/arm64/kvm/pmu-emul.c > @@ -873,6 +873,23 @@ static bool pmu_irq_is_valid(struct kvm *kvm, int irq) > return true; > } > > +/** > + * kvm_arm_get_num_counters - Get the number of general-purpose PMU counters. > + * @kvm: The kvm pointer > + */ > +int kvm_arm_get_num_counters(struct kvm *kvm) nit: the naming suggests this returns the configured number of PMCs, not the limit. Maybe kvm_arm_pmu_get_max_counters()? > +{ > + struct arm_pmu *arm_pmu = kvm->arch.arm_pmu; > + > + lockdep_assert_held(&kvm->arch.config_lock); > + > + /* > + * The arm_pmu->num_events considers the cycle counter as well. > + * Ignore that and return only the general-purpose counters. > + */ > + return arm_pmu->num_events - 1; > +} > + > static void kvm_arm_set_pmu(struct kvm *kvm, struct arm_pmu *arm_pmu) > { > lockdep_assert_held(&kvm->arch.config_lock); > diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h > index cd980d78b86b..672f3e9d7eea 100644 > --- a/include/kvm/arm_pmu.h > +++ b/include/kvm/arm_pmu.h > @@ -102,6 +102,7 @@ void kvm_vcpu_pmu_resync_el0(void); > > u8 kvm_arm_pmu_get_pmuver_limit(void); > int kvm_arm_set_default_pmu(struct kvm *kvm); > +int kvm_arm_get_num_counters(struct kvm *kvm); > > u64 kvm_vcpu_read_pmcr(struct kvm_vcpu *vcpu); > #else > @@ -181,6 +182,11 @@ static inline int kvm_arm_set_default_pmu(struct kvm *kvm) > return -ENODEV; > } > > +static inline int kvm_arm_get_num_counters(struct kvm *kvm) > +{ > + return -ENODEV; > +} > + > static inline u64 kvm_vcpu_read_pmcr(struct kvm_vcpu *vcpu) > { > return 0; > -- > 2.42.0.609.gbb76f46606-goog > -- Thanks, Oliver