From patchwork Thu Dec 20 15:21:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 10739057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8AAE13B5 for ; Thu, 20 Dec 2018 15:21:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C985028CA2 for ; Thu, 20 Dec 2018 15:21:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7CF928CEC; Thu, 20 Dec 2018 15:21:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C81028D2A for ; Thu, 20 Dec 2018 15:21:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387783AbeLTPVp (ORCPT ); Thu, 20 Dec 2018 10:21:45 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57856 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729693AbeLTPVo (ORCPT ); Thu, 20 Dec 2018 10:21:44 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1FE1715AD; Thu, 20 Dec 2018 07:21:44 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0E0AC3F5C0; Thu, 20 Dec 2018 07:21:42 -0800 (PST) From: Julien Grall To: kvm@vger.kernel.org Cc: suzuki.poulose@arm.com, marc.zyngier@arm.com, will.deacon@arm.com, Julien Grall Subject: [PATCH kvmtool v3 4/9] Fold kvm__init_ram call in kvm__arch_init Date: Thu, 20 Dec 2018 15:21:21 +0000 Message-Id: <20181220152126.18741-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181220152126.18741-1-julien.grall@arm.com> References: <20181220152126.18741-1-julien.grall@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The split between kvm__init_ram and kvm__arch_init for setting up the RAM can be quite subttle. By moving the former call in the later, it will be possible to make the RAM initialization easier on Arm with multi RAM banks support. Note that it is necessary to move the call to kvm__arch_init after the initialization of the list kvm->mem_banks because kvm__init_ram is relying on it. Signed-off-by: Julien Grall --- arm/kvm.c | 4 +++- include/kvm/kvm.h | 1 - kvm.c | 4 +--- mips/kvm.c | 4 +++- powerpc/kvm.c | 4 +++- x86/kvm.c | 4 +++- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/arm/kvm.c b/arm/kvm.c index 5a68c9a..b6ff2e2 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -24,7 +24,7 @@ bool kvm__arch_cpu_supports_vm(void) return true; } -void kvm__init_ram(struct kvm *kvm) +static void kvm__init_ram(struct kvm *kvm) { int err; u64 phys_start, phys_size; @@ -97,6 +97,8 @@ void kvm__arch_init(struct kvm *kvm) /* Create the virtual GIC. */ if (gic__create(kvm, kvm->cfg.arch.irqchip)) die("Failed to create virtual GIC"); + + kvm__init_ram(kvm); } #define FDT_ALIGN SZ_2M diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index 2d58ff4..ee2c5ab 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -90,7 +90,6 @@ int kvm__init(struct kvm *kvm); struct kvm *kvm__new(void); int kvm__recommended_cpus(struct kvm *kvm); int kvm__max_cpus(struct kvm *kvm); -void kvm__init_ram(struct kvm *kvm); int kvm__exit(struct kvm *kvm); bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename); bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename, diff --git a/kvm.c b/kvm.c index ea239e7..d4e1f4a 100644 --- a/kvm.c +++ b/kvm.c @@ -388,10 +388,8 @@ int kvm__init(struct kvm *kvm) goto err_vm_fd; } - kvm__arch_init(kvm); - INIT_LIST_HEAD(&kvm->mem_banks); - kvm__init_ram(kvm); + kvm__arch_init(kvm); if (!kvm->cfg.firmware_filename) { if (!kvm__load_kernel(kvm, kvm->cfg.kernel_filename, diff --git a/mips/kvm.c b/mips/kvm.c index e2a0c63..2ccefe8 100644 --- a/mips/kvm.c +++ b/mips/kvm.c @@ -17,7 +17,7 @@ void kvm__arch_read_term(struct kvm *kvm) virtio_console__inject_interrupt(kvm); } -void kvm__init_ram(struct kvm *kvm) +static void kvm__init_ram(struct kvm *kvm) { u64 phys_start, phys_size; void *host_mem; @@ -75,6 +75,8 @@ void kvm__arch_init(struct kvm *kvm) ret = ioctl(kvm->vm_fd, KVM_CREATE_IRQCHIP); if (ret < 0) die_perror("KVM_CREATE_IRQCHIP ioctl"); + + kvm__init_ram(kvm); } void kvm__irq_line(struct kvm *kvm, int irq, int level) diff --git a/powerpc/kvm.c b/powerpc/kvm.c index 034bc46..be99598 100644 --- a/powerpc/kvm.c +++ b/powerpc/kvm.c @@ -60,7 +60,7 @@ bool kvm__arch_cpu_supports_vm(void) return true; } -void kvm__init_ram(struct kvm *kvm) +static void kvm__init_ram(struct kvm *kvm) { u64 phys_start, phys_size; void *host_mem; @@ -139,6 +139,8 @@ void kvm__arch_init(struct kvm *kvm) SPAPR_PCI_MEM_WIN_SIZE, SPAPR_PCI_IO_WIN_ADDR, SPAPR_PCI_IO_WIN_SIZE); + + kvm__init_ram(kvm); } void kvm__arch_delete_ram(struct kvm *kvm) diff --git a/x86/kvm.c b/x86/kvm.c index 5abb41e..a22fa65 100644 --- a/x86/kvm.c +++ b/x86/kvm.c @@ -86,7 +86,7 @@ bool kvm__arch_cpu_supports_vm(void) * a gap between 0xe0000000 and 0x100000000 in the guest virtual mem space. */ -void kvm__init_ram(struct kvm *kvm) +static void kvm__init_ram(struct kvm *kvm) { u64 phys_start, phys_size; void *host_mem; @@ -167,6 +167,8 @@ void kvm__arch_init(struct kvm *kvm) ret = ioctl(kvm->vm_fd, KVM_CREATE_IRQCHIP); if (ret < 0) die_perror("KVM_CREATE_IRQCHIP ioctl"); + + kvm__init_ram(kvm); } void kvm__arch_delete_ram(struct kvm *kvm)