[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:48:30 PST 2026


On 02/11/2026 09:42, Fuad Tabba wrote:
> Hi Suzuki,
> 
> On Mon, 02 Nov 2026 09:24:15 +0000, Suzuki K Poulose
> <suzuki.poulose at arm.com> wrote:
> [...]
>>> diff --git 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.
> 
> It is. An INIT on a second vCPU with the same features also calls
> kvm_setup_vcpu(), with the flag already set, and
> kvm_vcpu_init_nested() can return -ENOMEM there.


Sorry, my bad. I missed the second condition after the flag check
in.

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



/me Where's coffee!

> 
> Thanks,
> /fuad




More information about the linux-arm-kernel mailing list