[v1,18/18] KVM: selftests/kvm_create_max_vcpus: check KVM_MAX_VCPUS

Message ID 20221024113445.1022147-19-wei.w.wang@intel.com
State New
Headers
Series KVM selftests code consolidation and cleanup |

Commit Message

Wang, Wei W Oct. 24, 2022, 11:34 a.m. UTC
  If the KVM side max vcpu number is larger than the one supported by the
userspace selftests, adjust the max number.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
---
 tools/testing/selftests/kvm/kvm_create_max_vcpus.c | 7 +++++++
 1 file changed, 7 insertions(+)
  

Comments

Sean Christopherson Oct. 27, 2022, 12:22 a.m. UTC | #1
On Mon, Oct 24, 2022, Wei Wang wrote:
> If the KVM side max vcpu number is larger than the one supported by the
> userspace selftests, adjust the max number.

No, this defeats the purpose of the test.  "create max vCPUs" means "create the
maximum number allowed by KVM", not "create the arbitrary max supported by selftests".
  

Patch

diff --git a/tools/testing/selftests/kvm/kvm_create_max_vcpus.c b/tools/testing/selftests/kvm/kvm_create_max_vcpus.c
index 31b3cb24b9a7..bbdb371e21ed 100644
--- a/tools/testing/selftests/kvm/kvm_create_max_vcpus.c
+++ b/tools/testing/selftests/kvm/kvm_create_max_vcpus.c
@@ -50,6 +50,13 @@  int main(int argc, char *argv[])
 
 	pr_info("KVM_CAP_MAX_VCPU_ID: %d\n", kvm_max_vcpu_id);
 	pr_info("KVM_CAP_MAX_VCPUS: %d\n", kvm_max_vcpus);
+	pr_info("selftests KVM_MAX_VCPUS: %d\n", KVM_MAX_VCPUS);
+
+	if (kvm_max_vcpu_id > KVM_MAX_VCPUS)
+		kvm_max_vcpu_id = KVM_MAX_VCPUS;
+
+	if (kvm_max_vcpus > KVM_MAX_VCPUS)
+		kvm_max_vcpus = KVM_MAX_VCPUS;
 
 	/*
 	 * Check that we're allowed to open nr_fds_wanted file descriptors and