Re: [PATCH v2] KVM: arm64: Restore the VM's feature bitmap when kvm_setup_vcpu() fails
From: Fuad Tabba
Date: Mon Sep 21 2026 - 03:30:01 EST
Hi Oliver,
On Mon, 21 Sep 2026 00:09:17 -0700, Oliver Upton <oupton@xxxxxxxxxx> wrote:
[...]
> > Nothing in the tree loads a vCPU whose init failed, so this is latent.
> > The upcoming series that enables KVM_PRE_FAULT_MEMORY for arm64 exposes
> > it: the generic kvm_vcpu_pre_fault_memory() calls vcpu_load() whether
> > or not the vCPU has been initialised.
>
> That's a bug, not a feature. We should require an initialized vcpu for
> the ioctl.
That one is for Lorenzo then :) I'll reword the message so the stale
bitmap comes first and the pre-fault crash is just how it showed up.
[...]
> The bitmap copy is a bit confusing because there's only two possible
> situations:
>
> - KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED is unset and the bitmap was
> previously zero
>
> - KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED is set and @init->features is
> identical to vcpu_features (see kvm_vcpu_init_changed())
>
> While there's nothing wrong with your diff, I'd prefer if the above
> detail was represented directly.
>
> 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))
> bitmap_zero(kvm->arch.vcpu_features, KVM_VCPU_MAX_FEATURES);
>
> goto out_unlock;
> }
I'd gone for the restore so the failure path didn't depend on the
flag, but those two states are all there is and your version makes
that explicit. I'll use it in v3.
Thanks,
/fuad