From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35117C433EF for ; Fri, 3 Sep 2021 14:41:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 133FD610E5 for ; Fri, 3 Sep 2021 14:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349484AbhICOms (ORCPT ); Fri, 3 Sep 2021 10:42:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:35842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230332AbhICOmr (ORCPT ); Fri, 3 Sep 2021 10:42:47 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6319D610CF; Fri, 3 Sep 2021 14:41:47 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mMAO1-008rk1-Cn; Fri, 03 Sep 2021 15:41:45 +0100 Date: Fri, 03 Sep 2021 15:41:44 +0100 Message-ID: <871r65wwk7.wl-maz@kernel.org> From: Marc Zyngier To: Juergen Gross Cc: kvm@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ehabkost@redhat.com, James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , kvmarm@lists.cs.columbia.edu Subject: Re: [PATCH v2 5/6] kvm: allocate vcpu pointer array separately In-Reply-To: <20210903130808.30142-6-jgross@suse.com> References: <20210903130808.30142-1-jgross@suse.com> <20210903130808.30142-6-jgross@suse.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: jgross@suse.com, kvm@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ehabkost@redhat.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, kvmarm@lists.cs.columbia.edu X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 03 Sep 2021 14:08:06 +0100, Juergen Gross wrote: > > Prepare support of very large vcpu numbers per guest by moving the > vcpu pointer array out of struct kvm. > > Signed-off-by: Juergen Gross > --- > V2: > - rebase to new kvm_arch_free_vm() implementation > --- > arch/arm64/kvm/arm.c | 21 +++++++++++++++++++-- > arch/x86/include/asm/kvm_host.h | 5 +---- > arch/x86/kvm/x86.c | 18 ++++++++++++++++++ > include/linux/kvm_host.h | 17 +++++++++++++++-- > 4 files changed, 53 insertions(+), 8 deletions(-) > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 38fff5963d9f..8bb5caeba007 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -293,10 +293,27 @@ long kvm_arch_dev_ioctl(struct file *filp, > > struct kvm *kvm_arch_alloc_vm(void) > { > + struct kvm *kvm; > + > + if (!has_vhe()) > + kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL); > + else > + kvm = vzalloc(sizeof(struct kvm)); > + > + if (!kvm) > + return NULL; > + > if (!has_vhe()) > - return kzalloc(sizeof(struct kvm), GFP_KERNEL); > + kvm->vcpus = kcalloc(KVM_MAX_VCPUS, sizeof(void *), GFP_KERNEL); > + else > + kvm->vcpus = vzalloc(KVM_MAX_VCPUS * sizeof(void *)); > + > + if (!kvm->vcpus) { > + kvm_arch_free_vm(kvm); > + kvm = NULL; > + } > > - return vzalloc(sizeof(struct kvm)); > + return kvm; > } > > int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index f16fadfc030a..6c28d0800208 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1517,10 +1517,7 @@ static inline void kvm_ops_static_call_update(void) > } > > #define __KVM_HAVE_ARCH_VM_ALLOC > -static inline struct kvm *kvm_arch_alloc_vm(void) > -{ > - return __vmalloc(kvm_x86_ops.vm_size, GFP_KERNEL_ACCOUNT | __GFP_ZERO); > -} > +struct kvm *kvm_arch_alloc_vm(void); > > #define __KVM_HAVE_ARCH_VM_FREE > void kvm_arch_free_vm(struct kvm *kvm); > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index cc552763f0e4..ff142b6dd00c 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -11126,6 +11126,24 @@ void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) > static_call(kvm_x86_sched_in)(vcpu, cpu); > } > > +struct kvm *kvm_arch_alloc_vm(void) > +{ > + struct kvm *kvm; > + > + kvm = __vmalloc(kvm_x86_ops.vm_size, GFP_KERNEL_ACCOUNT | __GFP_ZERO); > + if (!kvm) > + return NULL; > + > + kvm->vcpus = __vmalloc(KVM_MAX_VCPUS * sizeof(void *), > + GFP_KERNEL_ACCOUNT | __GFP_ZERO); > + if (!kvm->vcpus) { > + vfree(kvm); > + kvm = NULL; > + } > + > + return kvm; > +} > + > void kvm_arch_free_vm(struct kvm *kvm) > { > kfree(to_kvm_hv(kvm)->hv_pa_pg); > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index d75e9c2a00b1..9e2a5f1c6f54 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -536,7 +536,7 @@ struct kvm { > struct mutex slots_arch_lock; > struct mm_struct *mm; /* userspace tied to this vm */ > struct kvm_memslots __rcu *memslots[KVM_ADDRESS_SPACE_NUM]; > - struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; > + struct kvm_vcpu **vcpus; At this stage, I really wonder why we are not using an xarray instead. I wrote this [1] a while ago, and nothing caught fire. It was also a net deletion of code... M. [1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/log/?h=kvm-arm64/vcpu-xarray -- Without deviation from the norm, progress is not possible. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EAEEC433EF for ; Fri, 3 Sep 2021 14:41:54 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 97F3C610E9 for ; Fri, 3 Sep 2021 14:41:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 97F3C610E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 387AC4B1F5; Fri, 3 Sep 2021 10:41:53 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QjhNWuuvX0EI; Fri, 3 Sep 2021 10:41:51 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 0FCB14B1E4; Fri, 3 Sep 2021 10:41:51 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id D4AE64B1E4 for ; Fri, 3 Sep 2021 10:41:49 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dc7VAg7uqSae for ; Fri, 3 Sep 2021 10:41:48 -0400 (EDT) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 80E2C4B119 for ; Fri, 3 Sep 2021 10:41:48 -0400 (EDT) Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6319D610CF; Fri, 3 Sep 2021 14:41:47 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mMAO1-008rk1-Cn; Fri, 03 Sep 2021 15:41:45 +0100 Date: Fri, 03 Sep 2021 15:41:44 +0100 Message-ID: <871r65wwk7.wl-maz@kernel.org> From: Marc Zyngier To: Juergen Gross Subject: Re: [PATCH v2 5/6] kvm: allocate vcpu pointer array separately In-Reply-To: <20210903130808.30142-6-jgross@suse.com> References: <20210903130808.30142-1-jgross@suse.com> <20210903130808.30142-6-jgross@suse.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: jgross@suse.com, kvm@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ehabkost@redhat.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, kvmarm@lists.cs.columbia.edu X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Cc: Wanpeng Li , ehabkost@redhat.com, kvm@vger.kernel.org, Catalin Marinas , Joerg Roedel , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Will Deacon , Ingo Molnar , Sean Christopherson , Borislav Petkov , Paolo Bonzini , Vitaly Kuznetsov , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Jim Mattson X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Fri, 03 Sep 2021 14:08:06 +0100, Juergen Gross wrote: > > Prepare support of very large vcpu numbers per guest by moving the > vcpu pointer array out of struct kvm. > > Signed-off-by: Juergen Gross > --- > V2: > - rebase to new kvm_arch_free_vm() implementation > --- > arch/arm64/kvm/arm.c | 21 +++++++++++++++++++-- > arch/x86/include/asm/kvm_host.h | 5 +---- > arch/x86/kvm/x86.c | 18 ++++++++++++++++++ > include/linux/kvm_host.h | 17 +++++++++++++++-- > 4 files changed, 53 insertions(+), 8 deletions(-) > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 38fff5963d9f..8bb5caeba007 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -293,10 +293,27 @@ long kvm_arch_dev_ioctl(struct file *filp, > > struct kvm *kvm_arch_alloc_vm(void) > { > + struct kvm *kvm; > + > + if (!has_vhe()) > + kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL); > + else > + kvm = vzalloc(sizeof(struct kvm)); > + > + if (!kvm) > + return NULL; > + > if (!has_vhe()) > - return kzalloc(sizeof(struct kvm), GFP_KERNEL); > + kvm->vcpus = kcalloc(KVM_MAX_VCPUS, sizeof(void *), GFP_KERNEL); > + else > + kvm->vcpus = vzalloc(KVM_MAX_VCPUS * sizeof(void *)); > + > + if (!kvm->vcpus) { > + kvm_arch_free_vm(kvm); > + kvm = NULL; > + } > > - return vzalloc(sizeof(struct kvm)); > + return kvm; > } > > int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index f16fadfc030a..6c28d0800208 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1517,10 +1517,7 @@ static inline void kvm_ops_static_call_update(void) > } > > #define __KVM_HAVE_ARCH_VM_ALLOC > -static inline struct kvm *kvm_arch_alloc_vm(void) > -{ > - return __vmalloc(kvm_x86_ops.vm_size, GFP_KERNEL_ACCOUNT | __GFP_ZERO); > -} > +struct kvm *kvm_arch_alloc_vm(void); > > #define __KVM_HAVE_ARCH_VM_FREE > void kvm_arch_free_vm(struct kvm *kvm); > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index cc552763f0e4..ff142b6dd00c 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -11126,6 +11126,24 @@ void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) > static_call(kvm_x86_sched_in)(vcpu, cpu); > } > > +struct kvm *kvm_arch_alloc_vm(void) > +{ > + struct kvm *kvm; > + > + kvm = __vmalloc(kvm_x86_ops.vm_size, GFP_KERNEL_ACCOUNT | __GFP_ZERO); > + if (!kvm) > + return NULL; > + > + kvm->vcpus = __vmalloc(KVM_MAX_VCPUS * sizeof(void *), > + GFP_KERNEL_ACCOUNT | __GFP_ZERO); > + if (!kvm->vcpus) { > + vfree(kvm); > + kvm = NULL; > + } > + > + return kvm; > +} > + > void kvm_arch_free_vm(struct kvm *kvm) > { > kfree(to_kvm_hv(kvm)->hv_pa_pg); > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index d75e9c2a00b1..9e2a5f1c6f54 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -536,7 +536,7 @@ struct kvm { > struct mutex slots_arch_lock; > struct mm_struct *mm; /* userspace tied to this vm */ > struct kvm_memslots __rcu *memslots[KVM_ADDRESS_SPACE_NUM]; > - struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; > + struct kvm_vcpu **vcpus; At this stage, I really wonder why we are not using an xarray instead. I wrote this [1] a while ago, and nothing caught fire. It was also a net deletion of code... M. [1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/log/?h=kvm-arm64/vcpu-xarray -- Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 635B0C433F5 for ; Fri, 3 Sep 2021 14:43:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 30DEA610E9 for ; Fri, 3 Sep 2021 14:43:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 30DEA610E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5xWjxAd8gb9aZuUAAAg2b81pk3IdZmuKpDkaJfGxTio=; b=Awgth/Mt7jIrsi rbrLdJ232i+ypaFK+Acck4MVHHmhhPG2vvEVGc3ZpFaHc0tpt0WV2686OWtobUdW3aNZ6fW+NXwLV IfxGkTbQOKIjMG+gDsR5JAfWZ+0xG9wkgqzPeC6rJo1mEqjqXd7zfXROY1VkN6XtSRJiJrnTN/nGL y5a5NPcooMrc7lRTNNTy5tm+8Q0RiZt7tqvjNpEgNxsht6SvHtsKNc74UfOdw9ulZtXZAEJUtTwdz TjwxFzPK0wgI8TCN7aJj8y/YqvL2KgRnNy/PibbMN60b14v4Jd+QIKxZV6W4tZlG36S+STKKDNx8e 0RdDXXqwThodgZp+3GiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mMAO8-00CDqf-3y; Fri, 03 Sep 2021 14:41:52 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mMAO3-00CDpm-Sk for linux-arm-kernel@lists.infradead.org; Fri, 03 Sep 2021 14:41:49 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6319D610CF; Fri, 3 Sep 2021 14:41:47 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mMAO1-008rk1-Cn; Fri, 03 Sep 2021 15:41:45 +0100 Date: Fri, 03 Sep 2021 15:41:44 +0100 Message-ID: <871r65wwk7.wl-maz@kernel.org> From: Marc Zyngier To: Juergen Gross Cc: kvm@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ehabkost@redhat.com, James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , kvmarm@lists.cs.columbia.edu Subject: Re: [PATCH v2 5/6] kvm: allocate vcpu pointer array separately In-Reply-To: <20210903130808.30142-6-jgross@suse.com> References: <20210903130808.30142-1-jgross@suse.com> <20210903130808.30142-6-jgross@suse.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: jgross@suse.com, kvm@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ehabkost@redhat.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, kvmarm@lists.cs.columbia.edu X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210903_074148_006762_68C7E592 X-CRM114-Status: GOOD ( 27.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 03 Sep 2021 14:08:06 +0100, Juergen Gross wrote: > > Prepare support of very large vcpu numbers per guest by moving the > vcpu pointer array out of struct kvm. > > Signed-off-by: Juergen Gross > --- > V2: > - rebase to new kvm_arch_free_vm() implementation > --- > arch/arm64/kvm/arm.c | 21 +++++++++++++++++++-- > arch/x86/include/asm/kvm_host.h | 5 +---- > arch/x86/kvm/x86.c | 18 ++++++++++++++++++ > include/linux/kvm_host.h | 17 +++++++++++++++-- > 4 files changed, 53 insertions(+), 8 deletions(-) > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 38fff5963d9f..8bb5caeba007 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -293,10 +293,27 @@ long kvm_arch_dev_ioctl(struct file *filp, > > struct kvm *kvm_arch_alloc_vm(void) > { > + struct kvm *kvm; > + > + if (!has_vhe()) > + kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL); > + else > + kvm = vzalloc(sizeof(struct kvm)); > + > + if (!kvm) > + return NULL; > + > if (!has_vhe()) > - return kzalloc(sizeof(struct kvm), GFP_KERNEL); > + kvm->vcpus = kcalloc(KVM_MAX_VCPUS, sizeof(void *), GFP_KERNEL); > + else > + kvm->vcpus = vzalloc(KVM_MAX_VCPUS * sizeof(void *)); > + > + if (!kvm->vcpus) { > + kvm_arch_free_vm(kvm); > + kvm = NULL; > + } > > - return vzalloc(sizeof(struct kvm)); > + return kvm; > } > > int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index f16fadfc030a..6c28d0800208 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1517,10 +1517,7 @@ static inline void kvm_ops_static_call_update(void) > } > > #define __KVM_HAVE_ARCH_VM_ALLOC > -static inline struct kvm *kvm_arch_alloc_vm(void) > -{ > - return __vmalloc(kvm_x86_ops.vm_size, GFP_KERNEL_ACCOUNT | __GFP_ZERO); > -} > +struct kvm *kvm_arch_alloc_vm(void); > > #define __KVM_HAVE_ARCH_VM_FREE > void kvm_arch_free_vm(struct kvm *kvm); > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index cc552763f0e4..ff142b6dd00c 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -11126,6 +11126,24 @@ void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) > static_call(kvm_x86_sched_in)(vcpu, cpu); > } > > +struct kvm *kvm_arch_alloc_vm(void) > +{ > + struct kvm *kvm; > + > + kvm = __vmalloc(kvm_x86_ops.vm_size, GFP_KERNEL_ACCOUNT | __GFP_ZERO); > + if (!kvm) > + return NULL; > + > + kvm->vcpus = __vmalloc(KVM_MAX_VCPUS * sizeof(void *), > + GFP_KERNEL_ACCOUNT | __GFP_ZERO); > + if (!kvm->vcpus) { > + vfree(kvm); > + kvm = NULL; > + } > + > + return kvm; > +} > + > void kvm_arch_free_vm(struct kvm *kvm) > { > kfree(to_kvm_hv(kvm)->hv_pa_pg); > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index d75e9c2a00b1..9e2a5f1c6f54 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -536,7 +536,7 @@ struct kvm { > struct mutex slots_arch_lock; > struct mm_struct *mm; /* userspace tied to this vm */ > struct kvm_memslots __rcu *memslots[KVM_ADDRESS_SPACE_NUM]; > - struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; > + struct kvm_vcpu **vcpus; At this stage, I really wonder why we are not using an xarray instead. I wrote this [1] a while ago, and nothing caught fire. It was also a net deletion of code... M. [1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/log/?h=kvm-arm64/vcpu-xarray -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel