From patchwork Mon Oct 9 23:08:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 13414651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35107E95A8D for ; Mon, 9 Oct 2023 23:09:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=zi6DbYFIP04nr47d1v2hnVitf2c1MSLwF5MSRG4XwA4=; b=m+YNm9Jz5wCO8Vt1QO84zffQjp 990JS9lIDMBlDZCRcURfyFQa/BZqo+lC2IEY45+GOnA9xpGvtaDtl8x6YPZIXGhv2FwhtBbjo+uLy yMhYmXw/3NDZEJEap6uzfqlK3kiLbfnY4Q23HuyD1SEunEbwsXodF/HkMZ8zFEtHFF7UknFFLjsmT RbxKmZ6MXyDb33rCfAiKz1UNxwKJ0yy9Csq15ZidxNp2yiUlEf4wwx9AXpi2G0+WRGd2KvKTBgyb/ e8M4chOtEnL5/0JCrzJGuzRhm9bys9a60UgMOwWXQJLqGxS+VA9J32/yAhvpQq1fZND4NCaO9yF+S gtLgbq8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qpzNE-00Bmon-1w; Mon, 09 Oct 2023 23:09:16 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qpzN9-00Bml7-1Q for linux-arm-kernel@lists.infradead.org; Mon, 09 Oct 2023 23:09:12 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d9a3e5f1742so922898276.0 for ; Mon, 09 Oct 2023 16:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696892950; x=1697497750; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NiBpW9pAzYjkcsGf2tpIHcI9bB/NEZB+QU7M3fwotPk=; b=T8pRad2TTsU63FU4Y569j5676CLklc8hw8rjEepWWvydkyGv0XbA2twQ3lQ47TdQrK s6V2b8tNdrIyRA+sK7r0jMQb9y9hUXdQYJxbo7Ek6cYp1b0NAVK3xB36RtXw6Wpw3P/l n9SvGSDrXENCqmB+kndISqEsrQI941a2hhOhEWyoHHxMkt5DCvw0fTDR6ZidHmG659yj jjMxHh6Wv8cOzDfKztAOAcfmk04Z8x1BJg9BHAZKDWP/J9GwD5nJwvfOdMOGviy8JBBR 1uz0SGdJSeEjVTk+bQmgt5Wkshj8rCCw6n4F2AUxDp6fPgdEjdd7kOMEP7mIPKY7EbWv b0Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696892950; x=1697497750; 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=NiBpW9pAzYjkcsGf2tpIHcI9bB/NEZB+QU7M3fwotPk=; b=X3JZwy/uFpVse02DWSG6kPy1up7WAhZnMzpfQAOb4KVpSkqWcqiiaG5DMCo/wlZfhA T54ltLQ8sRjyaZS44UXbjvfxuDjQjCc0/RmlsKcOGEi0h5QMAuNeZ8BPInaCDRfLjtZk LKXs2ezAo7FxL/nuo7nDXk/IbRR7FtbDfV6tsWRww2tXAd6J1XyAmOVhl1Jr/5brR7BZ zB3OpdqNyspllaG3rTNuDIhAnOIqgPM5kPeLUYoy88HiKYl2VMgOWeDaG5mj1C5yoASr 0dt5wwFNVSA2ExP3uv9Va74vBFzUy9wd44cwk9TngrS3O2x2WkDnBmo2y+ktmRifhxUv T9EQ== X-Gm-Message-State: AOJu0YyJoYx5euTG3vyIPcEfGUE5c7z9ibs4lj/3ds/jZlpIpm29nm9X aCKUKc2B55HB7Gny34GHfTJKTGT/Oq9w X-Google-Smtp-Source: AGHT+IGhUbm0HO7NhAypaQMYBLq6ihENbJzVhn6yFKRW07/auTo8tnu6zuo6xvHt4/x6EbTnXbNJa84X0oC+ X-Received: from rananta-linux.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:20a1]) (user=rananta job=sendgmr) by 2002:a25:ce89:0:b0:d91:c4e8:bfdd with SMTP id x131-20020a25ce89000000b00d91c4e8bfddmr219902ybe.1.1696892950277; Mon, 09 Oct 2023 16:09:10 -0700 (PDT) Date: Mon, 9 Oct 2023 23:08:52 +0000 In-Reply-To: <20231009230858.3444834-1-rananta@google.com> Mime-Version: 1.0 References: <20231009230858.3444834-1-rananta@google.com> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Message-ID: <20231009230858.3444834-7-rananta@google.com> Subject: [PATCH v7 06/12] KVM: arm64: PMU: Add a helper to read the number of counters From: Raghavendra Rao Ananta To: Oliver Upton , Marc Zyngier Cc: Alexandru Elisei , James Morse , Suzuki K Poulose , Paolo Bonzini , Zenghui Yu , Shaoqin Huang , Jing Zhang , Reiji Watanabe , Colton Lewis , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231009_160911_481696_E1975962 X-CRM114-Status: GOOD ( 11.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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) +{ + 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;