From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f74.google.com (mail-oo1-f74.google.com [209.85.161.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCC9D314A94 for ; Mon, 9 Feb 2026 22:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770676846; cv=none; b=PlsFOEmdCKaTd3kDGNvMIX9qyOIxdL0F95BL11ZypS4EVp0zcovN4vqcfoznSkx6T+dg15f75DMNU25esBQ7wHE3HFHnbPsDk0zEqiG+PgRYZNR48dv/1tJnVInRAL8lJlIfkOV1DyrEZEHMwuQ3SGHuj6fmEy6aSg1gbivKxZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770676846; c=relaxed/simple; bh=2w2NkSfnUYCtKCT1TvD2j7eUbaB9dlOlqow5wyJZoKY=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=JfgVgwxTgsAIQQuhMvjds+N9FDvxcqt9ZBkYld7w1e4noGLiGThxVK1An+l/W31+QJARkA7UvmORZ88ZxHx50grffOK1gkAGhHWR/exsrrJcHloqcEGMq+YyPsQ5HW2h5krNC1uTSzLrdbMdNOwYHJICuu1cVMl3pDO5YY9NlLk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HhXL+lHX; arc=none smtp.client-ip=209.85.161.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HhXL+lHX" Received: by mail-oo1-f74.google.com with SMTP id 006d021491bc7-663006e4c3cso1123171eaf.2 for ; Mon, 09 Feb 2026 14:40:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770676844; x=1771281644; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=30Nas80AMvo6RyW+BR+2WwHJbWJfG1zda4JX9g84//U=; b=HhXL+lHXdq2/jXdePqpenUlxL1QhrhU2eUgJlgQ2aztzvzgtrzsF+snXRALa4WyjCs Jfy175SB0ER6ISIkj+UJh4Jsn2qk578bJphXpHTEanqTwfx3xZx8kaCkZGX7OCWSpc55 IAxUvrn3sOiiH33g4L1rLvoVfGKPYeaf45TRrAihX3HPIH4UwpifJQ05kROyFEXLmMN4 nBCIPnm7DWSoJ3kX1v0u03wO5VwM5Rwgp9m7OZqcXWR50n42iRCtdXLWig17PgkjoHTf qJ+AA2Ezb6tzVTMCriGAdffxGVFgodmCAkup/s/+qESwB5LIiDt0DHIyYZcSdUP+oKca INFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770676844; x=1771281644; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=30Nas80AMvo6RyW+BR+2WwHJbWJfG1zda4JX9g84//U=; b=LXppqBbO2o+2xezP08+eOJjWFoHOjilHxYqngDC5Qfx6UtbxpFgHIyGiwCbcw5Ngrk 61+I6JLh8u1gWSBS5Ner0hm2xn7WoZT7MxLVkDKoTkkDfuG2Deh7JsU1LJbGf6UACJKo eY253Ywb46Fj7iEdPLrNSTnG/oXNjDSsWel0XKufOVkv1fr6xv57lCnRX9NA7fR8xD4i vddNs1NtchNlZF7a8YUu5YkaG9wYCWD3+uslqPXCwgsNU6+d46juh8eFcWgcgQOgkDSf +nh3hknVw3dQJyCniq7TaCQkrYIDLPKw6XcAWL1WoFxaxQ+3b5lq3odL2M7yXbtgNSGd /iVA== X-Forwarded-Encrypted: i=1; AJvYcCVOk0ev9l9PRaoWoz70Qqexz3yb6YnkMHITXRp2/3N/eM6oQjNch2wRFg57C+0ZS38NFz1dDmea/MSq2Iy+pHM=@vger.kernel.org X-Gm-Message-State: AOJu0YyyUmF+UYrCkEaqUVX47w7x6ES/UaKrEdhj1Y+rLio+ydqFOLTe ulUUjm4jJSqX1QBWL2Pk1zZIxGR47Q5Jx9AuuoXRsl7gDK1SH/o1VSBngLLpznQFCpzG1Gd1K6X i0N3XFEl6kgJZ+GLesste1YlvbA== X-Received: from ileg3.prod.google.com ([2002:a05:6e02:1a23:b0:467:9e40:e391]) (user=coltonlewis job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:220b:b0:664:86ce:df46 with SMTP id 006d021491bc7-66d0c472fd0mr6437177eaf.57.1770676843797; Mon, 09 Feb 2026 14:40:43 -0800 (PST) Date: Mon, 9 Feb 2026 22:13:55 +0000 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260209221414.2169465-1-coltonlewis@google.com> Subject: [PATCH v6 00/19] ARM64 PMU Partitioning 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 , 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" This series creates a new PMU scheme on ARM, a partitioned PMU that allows reserving a subset of counters for more direct guest access, significantly reducing overhead. More details, including performance benchmarks, can be read in the v1 cover letter linked below. An overview of what this series accomplishes was presented at KVM Forum 2025. Slides [1] and video [2] are linked below. IMPORTANT: This iteration does not yet implement the dynamic counter reservation approach suggested by Will Deacon in January [3]. I am working on it, but wanted to send this version first to keep momentum going and ensure I've addressed all issues besides that. v6: * Rebase onto v6.19-rc7 * Drop the reorganization patches I had previously included from Sean and Anish and rework without them. * Inline FGT programming for easier readability * Change register access path to drop simultaneous writing of the virtual and physical registers and write only where the canonical state should reside. The PMU register fast path behaves like a simple accessor now, relying on generic helpers when needed. * Related to the previous, drop several patches modifying sys_regs.c and incorporate PMOVS and PMEVTYPER into the fast path instead. * Move the register fast path call to kvm_hyp_handle_sysreg_vhe since this feature depends on VHE mode * Remove the heavyweight access checks from the fast path that had the potential to inject an undefined exception. For what checks are necessary, just return false and let the normal path handle injecting exceptions * Remove the legacy support for writeable PMCR.N. VMMs must use the vCPU attribute to change the number of counters. * Simplify kvm_pmu_hpmn by relying on kvm_vcpu_on_unsupported_cpu and moving HPMN validation of nr_pmu_counters to the ioctl boundary when it is set. * Disable preemption during context swap * Simplify iteration of counters to context swap by iterating a bitmask * Clear PMOVS flags during load to avoid the possibility of generating a spurious interrupt when writing PMINTEN or PMCNTEN * Make kvm_pmu_apply_event_filter() hyp safe * Cleanly separate interrupt handling so the host driver clears the overflow flags for the host counters only and KVM handles clearing the guest counter flags. * Ensure the guest PMU state is on hardware before checking hardware for the purposes of determining if an overflow should be injected into the guest. * Naming and commit message improvements * Change uAPI to vCPU device attribute selected when other PMU attributes are selected. * Remove some checks for exceptions when accessing invalid counter indices with the Partitioned PMU. Hardware does not guarantee them so the Partitioned PMU can't either. v5: https://lore.kernel.org/kvmarm/20251209205121.1871534-1-coltonlewis@google.com/ v4: https://lore.kernel.org/kvmarm/20250714225917.1396543-1-coltonlewis@google.com/ v3: https://lore.kernel.org/kvm/20250626200459.1153955-1-coltonlewis@google.com/ v2: https://lore.kernel.org/kvm/20250620221326.1261128-1-coltonlewis@google.com/ v1: https://lore.kernel.org/kvm/20250602192702.2125115-1-coltonlewis@google.com/ [1] https://gitlab.com/qemu-project/kvm-forum/-/raw/main/_attachments/2025/Optimizing__itvHkhc.pdf [2] https://www.youtube.com/watch?v=YRzZ8jMIA6M&list=PLW3ep1uCIRfxwmllXTOA2txfDWN6vUOHp&index=9 [3] https://lore.kernel.org/kvmarm/aWjlfl85vSd6sMwT@willie-the-truck/ Colton Lewis (18): arm64: cpufeature: Add cpucap for HPMN0 KVM: arm64: Reorganize PMU functions perf: arm_pmuv3: Introduce method to partition the PMU perf: arm_pmuv3: Generalize counter bitmasks perf: arm_pmuv3: Keep out of guest counter partition KVM: arm64: Set up FGT for Partitioned PMU KVM: arm64: Define access helpers for PMUSERENR and PMSELR KVM: arm64: Write fast path PMU register handlers KVM: arm64: Setup MDCR_EL2 to handle a partitioned PMU KVM: arm64: Context swap Partitioned PMU guest registers KVM: arm64: Enforce PMU event filter at vcpu_load() KVM: arm64: Implement lazy PMU context swaps perf: arm_pmuv3: Handle IRQs for Partitioned PMU guest counters KVM: arm64: Detect overflows for the Partitioned PMU KVM: arm64: Add vCPU device attr to partition the PMU KVM: selftests: Add find_bit to KVM library KVM: arm64: selftests: Add test case for partitioned PMU KVM: arm64: selftests: Relax testing for exceptions when partitioned Marc Zyngier (1): KVM: arm64: Reorganize PMU includes arch/arm/include/asm/arm_pmuv3.h | 28 + arch/arm64/include/asm/arm_pmuv3.h | 12 +- arch/arm64/include/asm/kvm_host.h | 17 +- arch/arm64/include/asm/kvm_types.h | 6 +- arch/arm64/include/uapi/asm/kvm.h | 2 + arch/arm64/kernel/cpufeature.c | 8 + arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/arm.c | 2 + arch/arm64/kvm/config.c | 41 +- arch/arm64/kvm/debug.c | 31 +- arch/arm64/kvm/hyp/vhe/switch.c | 240 ++++++ arch/arm64/kvm/pmu-direct.c | 439 +++++++++++ arch/arm64/kvm/pmu-emul.c | 674 +--------------- arch/arm64/kvm/pmu.c | 717 ++++++++++++++++++ arch/arm64/kvm/sys_regs.c | 9 +- arch/arm64/tools/cpucaps | 1 + arch/arm64/tools/sysreg | 6 +- drivers/perf/arm_pmuv3.c | 149 +++- include/kvm/arm_pmu.h | 126 +++ include/linux/perf/arm_pmu.h | 1 + include/linux/perf/arm_pmuv3.h | 14 +- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/arm64/vpmu_counter_access.c | 112 ++- tools/testing/selftests/kvm/lib/find_bit.c | 1 + 24 files changed, 1889 insertions(+), 750 deletions(-) create mode 100644 arch/arm64/kvm/pmu-direct.c create mode 100644 tools/testing/selftests/kvm/lib/find_bit.c base-commit: 63804fed149a6750ffd28610c5c1c98cce6bd377 -- 2.53.0.rc2.204.g2597b5adb4-goog