|
|
@@ -28,6 +28,7 @@
|
|
|
#include <linux/irqbypass.h>
|
|
|
#include <linux/swait.h>
|
|
|
#include <linux/refcount.h>
|
|
|
+#include <linux/nospec.h>
|
|
|
#include <asm/signal.h>
|
|
|
|
|
|
#include <linux/kvm.h>
|
|
|
@@ -491,10 +492,10 @@ static inline struct kvm_io_bus *kvm_get_bus(struct kvm *kvm, enum kvm_bus idx)
|
|
|
|
|
|
static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
|
|
|
{
|
|
|
- /* Pairs with smp_wmb() in kvm_vm_ioctl_create_vcpu, in case
|
|
|
- * the caller has read kvm->online_vcpus before (as is the case
|
|
|
- * for kvm_for_each_vcpu, for example).
|
|
|
- */
|
|
|
+ int num_vcpus = atomic_read(&kvm->online_vcpus);
|
|
|
+ i = array_index_nospec(i, num_vcpus);
|
|
|
+
|
|
|
+ /* Pairs with smp_wmb() in kvm_vm_ioctl_create_vcpu. */
|
|
|
smp_rmb();
|
|
|
return kvm->vcpus[i];
|
|
|
}
|
|
|
@@ -578,6 +579,7 @@ void kvm_put_kvm(struct kvm *kvm);
|
|
|
|
|
|
static inline struct kvm_memslots *__kvm_memslots(struct kvm *kvm, int as_id)
|
|
|
{
|
|
|
+ as_id = array_index_nospec(as_id, KVM_ADDRESS_SPACE_NUM);
|
|
|
return srcu_dereference_check(kvm->memslots[as_id], &kvm->srcu,
|
|
|
lockdep_is_held(&kvm->slots_lock) ||
|
|
|
!refcount_read(&kvm->users_count));
|