From mboxrd@z Thu Jan 1 00:00:00 1970 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 48473CD342F for ; Mon, 4 May 2026 21:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mx9MuEs10AivytOpsddviHcuIhm9po4u8KpiL1CkIVk=; b=4qVGAv3DKcf4M9IKvDxL3DQiec +toMWG3MMTC4fCRSY6aUVZVfmTYfA12xURTlEigUZcbG19fVzlUBMWZdX3IbteQPpFNtIQCnwI1Lp UPcKe0j2bhwPKk0KV0rTeuVXjpU23UtHfijegQ8bD97DyCMJBrnt/iOasyH2y5Y2PqJ8GBFBe+6lW /XOhKBUy5IGH/K9cMh+xIQ3CXbnxbZ9o+cLr/V9v77m01F6Hsl4SFbAormWZokPWFBH/scJySRoJ8 kaA8OKjQgbFkLH+5B3eC+i6HmFTza6L/iLWVEVXipGMyGWrEWBfFVPZkLiKyij7lmHogCpqLoCohI mNwA2O1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wK0gV-0000000ELIR-2Y1G; Mon, 04 May 2026 21:18:35 +0000 Received: from mail-oo1-xc49.google.com ([2607:f8b0:4864:20::c49]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wK0gS-0000000ELG2-2eUG for linux-arm-kernel@lists.infradead.org; Mon, 04 May 2026 21:18:33 +0000 Received: by mail-oo1-xc49.google.com with SMTP id 006d021491bc7-6948c46e69aso5140948eaf.1 for ; Mon, 04 May 2026 14:18:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777929511; x=1778534311; 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=mx9MuEs10AivytOpsddviHcuIhm9po4u8KpiL1CkIVk=; b=XAXrSKIEjG0J8MW/qlzUG3CmN3sD/SnR0oMYfrjxBr0KUAHZsUuYnRYbYLpEOvJepC r8ExLZwHSFCgWIwzHiI3139S1uQhKqZsg6eQ+DrzRtMobN6UpayzeivPpp1AHVfsAMCK MRCDKgh56L8sBLaMe+DqenJnOxXasqqTRu1BIYsB1D8hwcsld0iVOAhsBRAXtXyeIYY3 YHiYFdAwd0oPis79KE6L/2Wj7ZXOfqKveg+c155xQAoVHAUXFux2q6Hz2taNK/yeuibM cojj+whxniGhFcTJ6WJcVlXyEwQ82vR/b/TxvcLjZOeaTzTB8RiweyY0mRKlJu3WI0YT TGow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777929511; x=1778534311; 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=mx9MuEs10AivytOpsddviHcuIhm9po4u8KpiL1CkIVk=; b=ORXSVYs79evkTNRO9jbrvCYbTLhnD/i6+GXqG3ulIsKyOYHWSGsy6eO4ooRC/pNwjq BZlI6GLxW+wztTg3OfZ4bNt0kQdwQUEqhQrXFrrtoHVzM2ptjww7Rh91JJgddtKsUGaH k/u06eqzsArRwagj8ew/L6KRlRnPxIvQbfHF5U5t6Xsv3U3nDKDHpAMVSPsgPczXybtz a67G9tZNpc9Qc7ZtPGJ56E+mr2w8dN4bWsk4toDUtlek4D4b9CHHx+A8b/hbv6OPWczT Ii5Z1Rf6DmOtTih7k01vFBABn6iiAuqYkGRbyMSKBNsenRbc6AYlfTGCbuvxOk8dhGMi rtQQ== X-Forwarded-Encrypted: i=1; AFNElJ+gp8osfz+RXTflHFviffqLaS1adwzCEX8IpZqRxVq0+RZ9smCUKx1tV57WmqqTuoalx1KzgStzqkaPX9PR0I+d@lists.infradead.org X-Gm-Message-State: AOJu0YzP8fKpAMl33n8Ql3Enj3k8qu1k0nVea5EItna3GTpx6kC17ZFw aY2SUbk/xPyw1ajA32MSheukLu6/Z8LYijeZZZanuoaMQWufQfIjRwQ6EDc1FY7k3CX+xMeO42e +bEBVuLDw/kD43daFIBxxYwOTdQ== X-Received: from jams10.prod.google.com ([2002:a02:c50a:0:b0:5d9:a04c:991d]) (user=coltonlewis job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:179b:b0:696:1814:717a with SMTP id 006d021491bc7-69697dc2ac6mr5287197eaf.47.1777929510525; Mon, 04 May 2026 14:18:30 -0700 (PDT) Date: Mon, 4 May 2026 21:17:55 +0000 In-Reply-To: <20260504211813.1804997-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20260504211813.1804997-1-coltonlewis@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504211813.1804997-3-coltonlewis@google.com> Subject: [PATCH v7 02/20] KVM: arm64: Reorganize PMU includes From: Colton Lewis To: kvm@vger.kernel.org Cc: Alexandru Elisei , Paolo Bonzini , Jonathan Corbet , Russell King , Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , Mingwei Zhang , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Mark Rutland , Shuah Khan , Ganapatrao Kulkarni , James Clark , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-perf-users@vger.kernel.org, linux-kselftest@vger.kernel.org, Colton Lewis Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260504_141832_681051_E110A91E X-CRM114-Status: GOOD ( 13.61 ) 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 From: Marc Zyngier Including *all* of asm/kvm_host.h in asm/arm_pmuv3.h is a bad idea because that is much more than arm_pmuv3.h logically needs and creates a circular dependency that makes it easy to introduce compiler errors when editing this code. asm/kvm_host.h includes kvm/arm_pmu.h includes perf/arm_pmuv3.h includes asm/arm_pmuv3.h includes asm/kvm_host.h Reorganize the PMU includes to be more sane. In particular: * Remove the circular dependency by removing the kvm_host.h include from asm/arm_pmuv3.h since 99% of it isn't needed. * Move the remaining tiny bit of KVM/PMU interface from kvm_host.h into arm_pmu.h * Conditionally on ARM64, include the more targeted arm_pmu.h directly in the arm_pmuv3.c driver. Signed-off-by: Marc Zyngier Signed-off-by: Colton Lewis --- arch/arm64/include/asm/arm_pmuv3.h | 2 -- arch/arm64/include/asm/kvm_host.h | 14 -------------- drivers/perf/arm_pmuv3.c | 5 +++++ include/kvm/arm_pmu.h | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/arch/arm64/include/asm/arm_pmuv3.h b/arch/arm64/include/asm/arm_pmuv3.h index 8a777dec8d88a..cf2b2212e00a2 100644 --- a/arch/arm64/include/asm/arm_pmuv3.h +++ b/arch/arm64/include/asm/arm_pmuv3.h @@ -6,8 +6,6 @@ #ifndef __ASM_PMUV3_H #define __ASM_PMUV3_H -#include - #include #include diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 70cb9cfd760a3..1f789ba589d56 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1441,25 +1441,11 @@ void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu); void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu); void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu); -static inline bool kvm_pmu_counter_deferred(struct perf_event_attr *attr) -{ - return (!has_vhe() && attr->exclude_host); -} - #ifdef CONFIG_KVM -void kvm_set_pmu_events(u64 set, struct perf_event_attr *attr); -void kvm_clr_pmu_events(u64 clr); -bool kvm_set_pmuserenr(u64 val); void kvm_enable_trbe(void); void kvm_disable_trbe(void); void kvm_tracing_set_el1_configuration(u64 trfcr_while_in_guest); #else -static inline void kvm_set_pmu_events(u64 set, struct perf_event_attr *attr) {} -static inline void kvm_clr_pmu_events(u64 clr) {} -static inline bool kvm_set_pmuserenr(u64 val) -{ - return false; -} static inline void kvm_enable_trbe(void) {} static inline void kvm_disable_trbe(void) {} static inline void kvm_tracing_set_el1_configuration(u64 trfcr_while_in_guest) {} diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c index 8014ff766cff5..8d3b832cd633a 100644 --- a/drivers/perf/arm_pmuv3.c +++ b/drivers/perf/arm_pmuv3.c @@ -9,6 +9,11 @@ */ #include + +#if defined(CONFIG_ARM64) +#include +#endif + #include #include diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h index 96754b51b4116..e91d15a7a564b 100644 --- a/include/kvm/arm_pmu.h +++ b/include/kvm/arm_pmu.h @@ -9,9 +9,19 @@ #include #include +#include #define KVM_ARMV8_PMU_MAX_COUNTERS 32 +#define kvm_pmu_counter_deferred(attr) \ + ({ \ + !has_vhe() && (attr)->exclude_host; \ + }) + +struct kvm; +struct kvm_device_attr; +struct kvm_vcpu; + #if IS_ENABLED(CONFIG_HW_PERF_EVENTS) && IS_ENABLED(CONFIG_KVM) struct kvm_pmc { u8 idx; /* index into the pmu->pmc array */ @@ -66,6 +76,9 @@ int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu, int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu); struct kvm_pmu_events *kvm_get_pmu_events(void); +void kvm_set_pmu_events(u64 set, struct perf_event_attr *attr); +void kvm_clr_pmu_events(u64 clr); +bool kvm_set_pmuserenr(u64 val); void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu); void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu); void kvm_vcpu_pmu_resync_el0(void); @@ -159,6 +172,12 @@ static inline u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1) #define kvm_vcpu_has_pmu(vcpu) ({ false; }) static inline void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu) {} +static inline void kvm_set_pmu_events(u64 set, struct perf_event_attr *attr) {} +static inline void kvm_clr_pmu_events(u64 clr) {} +static inline bool kvm_set_pmuserenr(u64 val) +{ + return false; +} static inline void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu) {} static inline void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu) {} static inline void kvm_vcpu_reload_pmu(struct kvm_vcpu *vcpu) {} -- 2.54.0.545.g6539524ca2-goog