KVM: x86: hyperv: enforce vp_index < KVM_MAX_VCPUS
authorVitaly Kuznetsov <vkuznets@redhat.com>
Wed, 22 Aug 2018 10:18:28 +0000 (12:18 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 16 Sep 2019 06:21:49 +0000 (08:21 +0200)
commit0b535f7b95af9fa030a03243f62f29774eb5ff90
tree6f38f75f9e840fc27a37a2fce5309d1e1fd00b1e
parent8e91cc7f7f916d5ce310026591d549aa5bf5952d
KVM: x86: hyperv: enforce vp_index < KVM_MAX_VCPUS

[ Upstream commit 9170200ec0ebad70e5b9902bc93e2b1b11456a3b ]

Hyper-V TLFS (5.0b) states:

> Virtual processors are identified by using an index (VP index). The
> maximum number of virtual processors per partition supported by the
> current implementation of the hypervisor can be obtained through CPUID
> leaf 0x40000005. A virtual processor index must be less than the
> maximum number of virtual processors per partition.

Forbid userspace to set VP_INDEX above KVM_MAX_VCPUS. get_vcpu_by_vpidx()
can now be optimized to bail early when supplied vpidx is >= KVM_MAX_VCPUS.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/kvm/hyperv.c