Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1286071lqt; Fri, 7 Jun 2024 13:34:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZG5SxzNzdeUCdhRyrmbYKjno8TFJfbMWJ8N/UBi16HQxAKeJbRkZusuOvDS2Aoj+860Xs7Go1hobsSOwOzKWtOficHhOT5Eaz9JPTfQ== X-Google-Smtp-Source: AGHT+IHFdysFz30lY/3HHM/r/jYjvWO6H8V/2Md9+Z3vO/bJ+clwc+y9K9YoEJb6E7O0dP9M2Gvl X-Received: by 2002:a17:90a:cb90:b0:2bd:fa57:b35c with SMTP id 98e67ed59e1d1-2c2bcc0793cmr3367181a91.28.1717792493582; Fri, 07 Jun 2024 13:34:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717792493; cv=pass; d=google.com; s=arc-20160816; b=vi12NhmoQQmajZDYgvG6Dyfi5NY6/hdfJg/soXJgiZLMj1W0msLddUrM+/O8PQI+tR UvkCHjKlIyBYZ78A2cQV3Ff+nTU9Pt8NcBlDvcg3sNH4ufOrJlFd7A/oOs+oVhlZOvpf 5E6An9BXU6MDUkD8GRLeyDDqlwAdS6Qn4cL60bp/N46oNcjpDy3j92+ICs4EkLmZfjXT eqymewVSKxvlT1M9ZFuAWYfc66Rf0+pQt0q7H280bm328Id+t3t9tJ/DpW0QfWEP+OTT RHsbVZzbq/txZ8D7KMo/61PxMQc6j9itZ2E2LY4B9hP8ezsTLAD9gb0rYaEpLM+Fqpft e2LA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=AA7z1r1am+LGKmo0cHHa6ZGISbgH7OVYJZBO3z2o6ac=; fh=7MWtQIrhu8/8z5W30BSUbJmbB5Xoil/A+Q0kLnK8lig=; b=QjdEx0niDC/x5HyKJ5u1uSIJq4JD3ELGVCnt/omEIayGlS6Y6PVV3VdD3CqIxUdWoQ 9V8jXMbtK64TdiozJI8usuLac6YwplKMRj4jj81KVh1sEwsFPPFZSiacgICVa+qS7CmD y6JkLkUwz4ECfbVCn1iXlVD3b5uMf2KFQ2vYC9e9q3XUWxpOAeed2HlzIyIarge9GcvR ShsUqbW7l7lM9z1CmkNzPphev5kFbUbWKbLz3Jv8KB+N+/l4a2e/hgHFcYEGp/KpXhYi 8T4NKdbBzF11mjl1feppOWKMNfpaZ+RRK3OzItUI8PyKJWSFLckoWWTBIoB6SoKx0PDe ChGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VZkQ9mCP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-206721-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206721-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c280631cc3si5501340a91.34.2024.06.07.13.34.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 13:34:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206721-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VZkQ9mCP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-206721-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206721-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1ECFC288548 for ; Fri, 7 Jun 2024 20:34:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DAD7E156676; Fri, 7 Jun 2024 20:32:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VZkQ9mCP" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EADAB15622F; Fri, 7 Jun 2024 20:32:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717792335; cv=none; b=IEdWtp5QoDQAR6jcPor0mthbxMip7t3WF4KI2snUALfUGHlqYvWCOEoruL8Mh/r6Lnay0xFIWs9miIO+7icGRBImrSNgeKKIbsYwpWNV3WAoUZUb8y7z7UaMMOMmmZTETy3GsM5gkXrUyJd+3FMZcvTnMmTD/eSUNcxe8eOfJf8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717792335; c=relaxed/simple; bh=J5oFR+H4wsl5jwtJxa1F6XIK60SO7/dL0k4zTxfNnJU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ltnKHjhldY6/Qh2gfMTSxYelB7wE7JV740dxpWgsBZAnodwV67UeGa6HuyaztLsTEhdj5Q79n+w1aY3RG98wETHWIZhDElRy9eq7MARvLBWPkJe2ItJeXgaJu0YlWAhLoT9Bj8U0LZvZVFbr5tV4+jACplSPbrjpGG70XPDwcEg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VZkQ9mCP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 068B7C4AF19; Fri, 7 Jun 2024 20:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717792334; bh=J5oFR+H4wsl5jwtJxa1F6XIK60SO7/dL0k4zTxfNnJU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VZkQ9mCPELqch99bhj9fGm3AHA9lhMvD5G2GMqborXIHRQOSnKOohBKeQe3nnNCGk hbBgxpgW1YZD/vPsJsYzRf3acBai3oJXjp/EXzlK+0jMyjKw8wxRjI4QisbCMgGACr v63rYBo1pUbiWQkoUVGbc+mCKn6MzOiAJXNTv6W/Aywq4tvbzzyxKxnBqdNL/xr1zi GT3Pk0cv7fGrbbL1Zm126O3YiwEqNWcX9WQk8vEqZ5KAZvOvRlg/fdlRrbJBA4wY6p V7HZ0ysUBp53srbB+TDLHX40mNjcwnVwCQpRJKEpUvKoNXdRFhKDBYTYDeE5c6HX52 pRGOYADtk7f4A== From: "Rob Herring (Arm)" Date: Fri, 07 Jun 2024 14:31:33 -0600 Subject: [PATCH 8/9] KVM: arm64: Refine PMU defines for number of counters Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240607-arm-pmu-3-9-icntr-v1-8-c7bd2dceff3b@kernel.org> References: <20240607-arm-pmu-3-9-icntr-v1-0-c7bd2dceff3b@kernel.org> In-Reply-To: <20240607-arm-pmu-3-9-icntr-v1-0-c7bd2dceff3b@kernel.org> To: Russell King , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Will Deacon , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvmarm@lists.linux.dev X-Mailer: b4 0.14-dev There are 2 defines for the number of PMU counters: ARMV8_PMU_MAX_COUNTERS and ARMPMU_MAX_HWEVENTS. Both are the same currently, but Armv9.4/8.9 increases the number of possible counters from 32 to 33. With this change, the maximum number of counters will differ for KVM's PMU emulation which is PMUv3.4. Give KVM PMU emulation its own define to decouple it from the rest of the kernel's number PMU counters. The VHE PMU code needs to match the PMU driver, so switch it to use ARMPMU_MAX_HWEVENTS instead. Signed-off-by: Rob Herring (Arm) --- arch/arm64/kvm/pmu-emul.c | 8 ++++---- arch/arm64/kvm/pmu.c | 5 +++-- include/kvm/arm_pmu.h | 3 ++- include/linux/perf/arm_pmuv3.h | 2 -- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index da5ba9d061e8..77fe79b2ba04 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -234,7 +234,7 @@ void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu) int i; struct kvm_pmu *pmu = &vcpu->arch.pmu; - for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) + for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++) pmu->pmc[i].idx = i; } @@ -261,7 +261,7 @@ void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu) { int i; - for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) + for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++) kvm_pmu_release_perf_event(kvm_vcpu_idx_to_pmc(vcpu, i)); irq_work_sync(&vcpu->arch.pmu.overflow_work); } @@ -292,7 +292,7 @@ void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val) if (!(kvm_vcpu_read_pmcr(vcpu) & ARMV8_PMU_PMCR_E) || !val) return; - for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) { + for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++) { struct kvm_pmc *pmc; if (!(val & BIT(i))) @@ -324,7 +324,7 @@ void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val) if (!kvm_vcpu_has_pmu(vcpu) || !val) return; - for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) { + for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++) { struct kvm_pmc *pmc; if (!(val & BIT(i))) diff --git a/arch/arm64/kvm/pmu.c b/arch/arm64/kvm/pmu.c index 01c9a9efdd1c..7eaf5f7aeae9 100644 --- a/arch/arm64/kvm/pmu.c +++ b/arch/arm64/kvm/pmu.c @@ -5,6 +5,7 @@ */ #include #include +#include #include @@ -96,7 +97,7 @@ static void kvm_vcpu_pmu_enable_el0(unsigned long events) u64 typer; u32 counter; - for_each_set_bit(counter, &events, 32) { + for_each_set_bit(counter, &events, ARMPMU_MAX_HWEVENTS) { typer = kvm_vcpu_pmu_read_evtype_direct(counter); typer &= ~ARMV8_PMU_EXCLUDE_EL0; kvm_vcpu_pmu_write_evtype_direct(counter, typer); @@ -111,7 +112,7 @@ static void kvm_vcpu_pmu_disable_el0(unsigned long events) u64 typer; u32 counter; - for_each_set_bit(counter, &events, 32) { + for_each_set_bit(counter, &events, ARMPMU_MAX_HWEVENTS) { typer = kvm_vcpu_pmu_read_evtype_direct(counter); typer |= ARMV8_PMU_EXCLUDE_EL0; kvm_vcpu_pmu_write_evtype_direct(counter, typer); diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h index 871067fb2616..e08aeec5d936 100644 --- a/include/kvm/arm_pmu.h +++ b/include/kvm/arm_pmu.h @@ -10,6 +10,7 @@ #include #include +#define KVM_ARMV8_PMU_MAX_COUNTERS 32 #if IS_ENABLED(CONFIG_HW_PERF_EVENTS) && IS_ENABLED(CONFIG_KVM) struct kvm_pmc { @@ -25,7 +26,7 @@ struct kvm_pmu_events { struct kvm_pmu { struct irq_work overflow_work; struct kvm_pmu_events events; - struct kvm_pmc pmc[ARMV8_PMU_MAX_COUNTERS]; + struct kvm_pmc pmc[KVM_ARMV8_PMU_MAX_COUNTERS]; int irq_num; bool created; bool irq_level; diff --git a/include/linux/perf/arm_pmuv3.h b/include/linux/perf/arm_pmuv3.h index caa09241ad4f..c902fe64f070 100644 --- a/include/linux/perf/arm_pmuv3.h +++ b/include/linux/perf/arm_pmuv3.h @@ -6,8 +6,6 @@ #ifndef __PERF_ARM_PMUV3_H #define __PERF_ARM_PMUV3_H -#define ARMV8_PMU_MAX_COUNTERS 32 - /* * Common architectural and microarchitectural event numbers. */ -- 2.43.0