KVM: s390: Do not report unusabled IDs via KVM_CAP_MAX_VCPU_ID

KVM_CAP_MAX_VCPU_ID is currently always reporting KVM_MAX_VCPU_ID on all
architectures. However, on s390x, the amount of usable CPUs is determined
during runtime - it is depending on the features of the machine the code
is running on. Since we are using the vcpu_id as an index into the SCA
structures that are defined by the hardware (see e.g. the sca_add_vcpu()
function), it is not only the amount of CPUs that is limited by the hard-
ware, but also the range of IDs that we can use.
Thus KVM_CAP_MAX_VCPU_ID must be determined during runtime on s390x, too.
So the handling of KVM_CAP_MAX_VCPU_ID has to be moved from the common
code into the architecture specific code, and on s390x we have to return
the same value here as for KVM_CAP_MAX_VCPUS.
This problem has been discovered with the kvm_create_max_vcpus selftest.
With this change applied, the selftest now passes on s390x, too.

Reviewed-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20190523164309.13345-9-thuth@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>

authored by Thomas Huth and committed by Christian Borntraeger a86cb413 eb1f2f38

+13 -2
+3
arch/mips/kvm/mips.c
··· 1122 1122 case KVM_CAP_MAX_VCPUS: 1123 1123 r = KVM_MAX_VCPUS; 1124 1124 break; 1125 + case KVM_CAP_MAX_VCPU_ID: 1126 + r = KVM_MAX_VCPU_ID; 1127 + break; 1125 1128 case KVM_CAP_MIPS_FPU: 1126 1129 /* We don't handle systems with inconsistent cpu_has_fpu */ 1127 1130 r = !!raw_cpu_has_fpu;
+3
arch/powerpc/kvm/powerpc.c
··· 657 657 case KVM_CAP_MAX_VCPUS: 658 658 r = KVM_MAX_VCPUS; 659 659 break; 660 + case KVM_CAP_MAX_VCPU_ID: 661 + r = KVM_MAX_VCPU_ID; 662 + break; 660 663 #ifdef CONFIG_PPC_BOOK3S_64 661 664 case KVM_CAP_PPC_GET_SMMU_INFO: 662 665 r = 1;
+1
arch/s390/kvm/kvm-s390.c
··· 539 539 break; 540 540 case KVM_CAP_NR_VCPUS: 541 541 case KVM_CAP_MAX_VCPUS: 542 + case KVM_CAP_MAX_VCPU_ID: 542 543 r = KVM_S390_BSCA_CPU_SLOTS; 543 544 if (!kvm_s390_use_sca_entries()) 544 545 r = KVM_MAX_VCPUS;
+3
arch/x86/kvm/x86.c
··· 3122 3122 case KVM_CAP_MAX_VCPUS: 3123 3123 r = KVM_MAX_VCPUS; 3124 3124 break; 3125 + case KVM_CAP_MAX_VCPU_ID: 3126 + r = KVM_MAX_VCPU_ID; 3127 + break; 3125 3128 case KVM_CAP_PV_MMU: /* obsolete */ 3126 3129 r = 0; 3127 3130 break;
+3
virt/kvm/arm/arm.c
··· 224 224 case KVM_CAP_MAX_VCPUS: 225 225 r = KVM_MAX_VCPUS; 226 226 break; 227 + case KVM_CAP_MAX_VCPU_ID: 228 + r = KVM_MAX_VCPU_ID; 229 + break; 227 230 case KVM_CAP_MSI_DEVID: 228 231 if (!kvm) 229 232 r = -EINVAL;
-2
virt/kvm/kvm_main.c
··· 3151 3151 case KVM_CAP_MULTI_ADDRESS_SPACE: 3152 3152 return KVM_ADDRESS_SPACE_NUM; 3153 3153 #endif 3154 - case KVM_CAP_MAX_VCPU_ID: 3155 - return KVM_MAX_VCPU_ID; 3156 3154 case KVM_CAP_NR_MEMSLOTS: 3157 3155 return KVM_USER_MEM_SLOTS; 3158 3156 default: