[PATCH v4 1/2] KVM: arm64: Clear the VM's feature bitmap when kvm_setup_vcpu() fails

Suzuki K Poulose suzuki.poulose at arm.com
Mon Nov 2 01:24:15 PST 2026


On 02/11/2026 07:58, Fuad Tabba wrote:
> KVM_ARM_VCPU_INIT records the requested features in the VM-wide bitmap
> before kvm_setup_vcpu() runs, and leaves them there when setup fails
> (e.g., HAS_EL2_E2H0 on a host without FEAT_NV1). The PMU attributes
> read that bitmap before the vCPU is initialized, so after such a
> failure with PMU_V3 requested, KVM_SET_DEVICE_ATTR on the PMU group no
> longer returns -ENODEV.
> 
> Until an INIT has succeeded, every INIT that gets past the feature
> checks rewrites the bitmap. After that, kvm_vcpu_init_changed()
> requires the requested features to match it, so the copy is a no-op.
> Clear the bitmap on failure while KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED
> is clear.
> 
> Fixes: 427733579744e ("KVM: arm64: Select default PMU in KVM_ARM_VCPU_INIT handler")
> Suggested-by: Oliver Upton <oupton at kernel.org>
> Reviewed-by: Lorenzo Stoakes (ARM) <ljs at kernel.org>
> Signed-off-by: Fuad Tabba <fuad.tabba at linux.dev>
> ---
>   arch/arm64/kvm/arm.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index 157bf4b812020..3e91e01b032c4 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -1856,8 +1856,13 @@ static int __kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
>   	bitmap_copy(kvm->arch.vcpu_features, &features, KVM_VCPU_MAX_FEATURES);
>   
>   	ret = kvm_setup_vcpu(vcpu);
> -	if (ret)
> +	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))

Is this check necessary ? We go into kvm_setup_vcpu() only if the bit is
cleared and we do this under the config_lock mutex. The flag is only set
after we have finished the kvm_setup_vcpu() successfully, later down.

Otherwise,

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


> +			bitmap_zero(kvm->arch.vcpu_features, KVM_VCPU_MAX_FEATURES);
> +
>   		goto out_unlock;
> +	}
>   
>   	/* Now we know what it is, we can reset it. */
>   	kvm_reset_vcpu(vcpu);




More information about the linux-arm-kernel mailing list