Message ID | 20230510140410.1093987-1-mhal@rbox.co (mailing list archive) |
---|---|
Headers | show |
Series | KVM: vcpu_array[0] races | expand |
On 5/10/23 16:04, Michal Luczaj wrote: > When online_vcpus=0, any call to kvm_get_vcpu() goes through > array_index_nospec() and ends with an attempt to xa_load(vcpu_array, 0): > > int num_vcpus = atomic_read(&kvm->online_vcpus); > i = array_index_nospec(i, num_vcpus); > return xa_load(&kvm->vcpu_array, i); > > Similarly, when online_vcpus=0, a kvm_for_each_vcpu() does not iterate over > an "empty" range, but actually [0, ULONG_MAX]: > > xa_for_each_range(&kvm->vcpu_array, idx, vcpup, 0, \ > (atomic_read(&kvm->online_vcpus) - 1)) > > In both cases, such online_vcpus=0 edge case, even if leading to > unnecessary calls to XArray API, should not be an issue; requesting > unpopulated indexes/ranges is handled by xa_load() and xa_for_each_range(). > > However, this means that when the first vCPU is created and inserted in > vcpu_array *and* before online_vcpus is incremented, code calling > kvm_get_vcpu()/kvm_for_each_vcpu() already has access to that first vCPU. Queued, thanks. I added Fixes: c5b077549136 ("KVM: Convert the kvm->vcpus array to a xarray", 2021-12-08) Cc: stable@vger.kernel.org