mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: Fuad Tabba <fuad.tabba@linux.dev>, Marc Zyngier <maz@kernel.org>,
	Oliver Upton <oupton@kernel.org>
Cc: Joey Gouly <joey.gouly@arm.com>,
	Steffen Eiden <seiden@linux.ibm.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: Re: [PATCH v4 2/2] KVM: arm64: Clear the default PMU when kvm_setup_vcpu() fails
Date: Mon, 2 Nov 2026 09:56:53 +0000	[thread overview]
Message-ID: <5f82a68f-cb2c-4155-8f9f-cf287d5b00d6@arm.com> (raw)
In-Reply-To: <20261102075843.2556018-3-fuad.tabba@linux.dev>

On 02/11/2026 07:58, Fuad Tabba wrote:
> 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;
> +		}

minor nit: While the above works, it looks a bit too much extracting the 
PMU details to arm.c. Alternatively we could do something like this:


diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index e2b28dbc0451..7a669cccf912 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -1088,6 +1088,11 @@ int kvm_arm_set_default_pmu(struct kvm *kvm)
         return 0;
  }

+int kvm_arm_clear_default_pmu(struct kvm *kvm)
+{
+       kvm_arm_set_pmu(kvm, NULL);
+}
+
diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
index 6b4a118d17ca..571c0ba8507c 100644
--- a/include/kvm/arm_pmu.h
+++ b/include/kvm/arm_pmu.h
@@ -92,6 +92,7 @@ void kvm_vcpu_pmu_resync_el0(void);
  u8 kvm_arm_pmu_get_pmuver_limit(void);
  u64 kvm_pmu_evtyper_mask(struct kvm *kvm);
  int kvm_arm_set_default_pmu(struct kvm *kvm);
+int kvm_arm_clear_default_pmu(struct kvm *kvm);
  u8 kvm_arm_pmu_get_max_counters(struct kvm *kvm);

  u64 kvm_vcpu_read_pmcr(struct kvm_vcpu *vcpu);



Either ways,

Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com


      reply	other threads:[~2026-11-02  9:56 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 ` [PATCH v4 2/2] KVM: arm64: Clear the default PMU " Fuad Tabba
2026-11-02  9:56   ` Suzuki K Poulose [this message]

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=5f82a68f-cb2c-4155-8f9f-cf287d5b00d6@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=congkai@amazon.com \
    --cc=fuad.tabba@linux.dev \
    --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=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®