Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1884757pxv; Fri, 2 Jul 2021 15:07:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxALYL40nt4aNJryfD8JdYOJ6VRjJGBGdUKfjzbVECmQFjDpljBycASFFfUfQ4ir7bDp6z7 X-Received: by 2002:a05:6402:278a:: with SMTP id b10mr2069548ede.54.1625263674159; Fri, 02 Jul 2021 15:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263674; cv=none; d=google.com; s=arc-20160816; b=hGoAZkPyQWsy1YfHJnsl1byllt4Y+OydrKJdHFUl+HcxPwn677nBrSHjRFgxCvkDOx +aniEPHl4tCpyVVrp07PNTsA2eTjezNsTkTK7sNgrdGgHegi+HiI9e/yrZgcmDJO3Lz9 WKcZSrlxGOH9us3r0Jy+75oxS1GmZbKuJjmM6xngJ/mpjxX1osyJ5xQfXn99+Fxxdq62 r7f68VM4QgS+yc6AZYGXQOjfTnefnyDFO1jd2Gg6qtvphaXG74ty9NC7E3Qp/KgEDttf wDrzsv700dMlYLtvL6D72Kf91rkoSSaksQDxTceP0OONYqqR6s06JtlawIrAFqe/FPRj RZGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lBoA63WUXBPIBNd3SkAq6l3S83r0CEoTwc29yxIfVC0=; b=ET0aehw31DxFXBJAytV9NlPyopKEU17JEKLkaIMZPl7K7dk4XLIPfjFaXMYrSycDMw ER4ur0qsMbQ6I88DYIRhMViCmBO4TKotqMzRmQoO5zHtrZ0aobdiJiP7Ks6T+HV6x8IR sUqJHWKX1+aZnYEX1qK6g1Xzk5Jox+CtDsNKvPdKnM7X87QwEj6lyfU0ELECJ7f5mTsJ wbguuDqgkyKZBwTF/GFNGnD0NcrkniqidPZKJAanNq75WuU9X+dCPx8N2eSN4fK4FkP/ F/oCEIZzxD8fIcXI+B0dQamQyseNQm60G13StE2lnfsbtLP2eRPMU3PS0smFu/fVtc+l tQxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w19si4127927edx.11.2021.07.02.15.07.28; Fri, 02 Jul 2021 15:07:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233425AbhGBWI1 (ORCPT + 99 others); Fri, 2 Jul 2021 18:08:27 -0400 Received: from mga02.intel.com ([134.134.136.20]:51169 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230249AbhGBWH4 (ORCPT ); Fri, 2 Jul 2021 18:07:56 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="195951902" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="195951902" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:23 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814739" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:22 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson Subject: [RFC PATCH v2 21/69] KVM: Add max_vcpus field in common 'struct kvm' Date: Fri, 2 Jul 2021 15:04:27 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/arm64/include/asm/kvm_host.h | 3 --- arch/arm64/kvm/arm.c | 7 ++----- arch/arm64/kvm/vgic/vgic-init.c | 6 +++--- include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 3 ++- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 7cd7d5c8c4bc..96a0dc3a8780 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -106,9 +106,6 @@ struct kvm_arch { /* VTCR_EL2 value for this VM */ u64 vtcr; - /* The maximum number of vCPUs depends on the used GIC model */ - int max_vcpus; - /* Interrupt controller */ struct vgic_dist vgic; diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index e720148232a0..a46306cf3106 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -145,7 +145,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) kvm_vgic_early_init(kvm); /* The maximum number of VCPUs is limited by the host's GIC model */ - kvm->arch.max_vcpus = kvm_arm_default_max_vcpus(); + kvm->max_vcpus = kvm_arm_default_max_vcpus(); set_default_spectre(kvm); @@ -220,7 +220,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_MAX_VCPUS: case KVM_CAP_MAX_VCPU_ID: if (kvm) - r = kvm->arch.max_vcpus; + r = kvm->max_vcpus; else r = kvm_arm_default_max_vcpus(); break; @@ -299,9 +299,6 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) if (irqchip_in_kernel(kvm) && vgic_initialized(kvm)) return -EBUSY; - if (id >= kvm->arch.max_vcpus) - return -EINVAL; - return 0; } diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c index 58cbda00e56d..089ac00c55d7 100644 --- a/arch/arm64/kvm/vgic/vgic-init.c +++ b/arch/arm64/kvm/vgic/vgic-init.c @@ -97,11 +97,11 @@ int kvm_vgic_create(struct kvm *kvm, u32 type) ret = 0; if (type == KVM_DEV_TYPE_ARM_VGIC_V2) - kvm->arch.max_vcpus = VGIC_V2_MAX_CPUS; + kvm->max_vcpus = VGIC_V2_MAX_CPUS; else - kvm->arch.max_vcpus = VGIC_V3_MAX_CPUS; + kvm->max_vcpus = VGIC_V3_MAX_CPUS; - if (atomic_read(&kvm->online_vcpus) > kvm->arch.max_vcpus) { + if (atomic_read(&kvm->online_vcpus) > kvm->max_vcpus) { ret = -E2BIG; goto out_unlock; } diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index e87f07c5c601..ddd4d0f68cdf 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -544,6 +544,7 @@ struct kvm { * and is accessed atomically. */ atomic_t online_vcpus; + int max_vcpus; int created_vcpus; int last_boosted_vcpu; struct list_head vm_list; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index dc752d0bd3ec..52d40ea75749 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -910,6 +910,7 @@ static struct kvm *kvm_create_vm(unsigned long type) mutex_init(&kvm->irq_lock); mutex_init(&kvm->slots_lock); INIT_LIST_HEAD(&kvm->devices); + kvm->max_vcpus = KVM_MAX_VCPUS; BUILD_BUG_ON(KVM_MEM_SLOTS_NUM > SHRT_MAX); @@ -3329,7 +3330,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id) return -EINVAL; mutex_lock(&kvm->lock); - if (kvm->created_vcpus == KVM_MAX_VCPUS) { + if (kvm->created_vcpus >= kvm->max_vcpus) { mutex_unlock(&kvm->lock); return -EINVAL; } -- 2.25.1