From: Fuad Tabba <fuad.tabba@linux.dev>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>
Cc: Joey Gouly <joey.gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>, Will Deacon <will@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
Jack Thomson <jackabt@amazon.com>,
Congkai Tan <congkai@amazon.com>,
kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Fuad Tabba <tabba@google.com>
Subject: [PATCH v4 2/2] KVM: arm64: Clear the default PMU when kvm_setup_vcpu() fails
Date: Mon, 2 Nov 2026 07:58:43 +0000 [thread overview]
Message-ID: <20261102075843.2556018-3-fuad.tabba@linux.dev> (raw)
In-Reply-To: <20261102075843.2556018-1-fuad.tabba@linux.dev>
Under KVM_ARM_VCPU_PMU_V3_STRICT, the VM has no PMU until userspace
selects one, and initializing the PMU fails with -ENXIO until then.
However, without STRICT, kvm_setup_vcpu() selects the default PMU
before it prepares the vCPU for nested virtualization, and leaves it
set when that preparation fails. After a retry with STRICT,
initializing the PMU succeeds and the guest gets the PMU of the CPU
the failed INIT ran on.
Drop the PMU and its number of counters along with the VM's feature
bitmap. While KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED is clear, no vCPU
has been initialized and the PMU attributes return -ENODEV, so only
such a failure can have set them. Once the flag is set, every INIT has the
features of the first one that succeeded, which either selected a PMU
or had none to select, so kvm_setup_vcpu() doesn't select another.
Fixes: ad220e275c398 ("KVM: arm64: Add KVM_ARM_VCPU_PMU_V3_STRICT vCPU feature")
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/arm.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 3e91e01b032c4..65194e02cdbc2 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1857,9 +1857,12 @@ static int __kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
ret = kvm_setup_vcpu(vcpu);
if (ret) {
- /* Clear the bitmap if setup fails on the first vCPU to be initialized. */
- if (!test_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED, &kvm->arch.flags))
+ /* Clear the bitmap and PMU if setup fails on the first vCPU to be initialized. */
+ if (!test_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED, &kvm->arch.flags)) {
bitmap_zero(kvm->arch.vcpu_features, KVM_VCPU_MAX_FEATURES);
+ kvm->arch.arm_pmu = NULL;
+ kvm->arch.nr_pmu_counters = 0;
+ }
goto out_unlock;
}
--
2.47.3
next prev parent reply other threads:[~2026-11-02 7:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 7:58 [PATCH v4 0/2] KVM: arm64: Clear VM-wide state " Fuad Tabba
2026-11-02 7:58 ` [PATCH v4 1/2] KVM: arm64: Clear the VM's feature bitmap " Fuad Tabba
2026-11-02 9:24 ` Suzuki K Poulose
2026-11-02 9:42 ` Fuad Tabba
2026-11-02 9:48 ` Suzuki K Poulose
2026-11-02 7:58 ` Fuad Tabba [this message]
2026-11-02 9:56 ` [PATCH v4 2/2] KVM: arm64: Clear the default PMU " Suzuki K Poulose
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261102075843.2556018-3-fuad.tabba@linux.dev \
--to=fuad.tabba@linux.dev \
--cc=congkai@amazon.com \
--cc=jackabt@amazon.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®