diff mbox series

[kvmtool,08/16] arm: Move anything related to RAM initialization in kvm__init_ram

Message ID 1569245722-23375-9-git-send-email-alexandru.elisei@arm.com (mailing list archive)
State New, archived
Headers show
Series arm: Allow the user to define the memory layout | expand

Commit Message

Alexandru Elisei Sept. 23, 2019, 1:35 p.m. UTC
From: Julien Grall <julien.grall@arm.com>

RAM initialization is currently split between kvm__init_ram and
kvm__arch_init.  Move all code related to RAM initialization to
kvm__init_ram.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arm/kvm.c | 75 +++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 37 insertions(+), 38 deletions(-)

Comments

Andre Przywara Nov. 7, 2019, 1:46 p.m. UTC | #1
On Mon, 23 Sep 2019 14:35:14 +0100
Alexandru Elisei <alexandru.elisei@arm.com> wrote:

> From: Julien Grall <julien.grall@arm.com>
> 
> RAM initialization is currently split between kvm__init_ram and
> kvm__arch_init.  Move all code related to RAM initialization to
> kvm__init_ram.

The diff is a bit confusing to read, but indeed this just moves the code from arch_init() to init_ram() (confirmed by moving the code and comparing).
One thing to note is that this changes the order of initialisation slightly: the GIC is now created before the RAM (since we call arch_init() before init_ram()).

Nevertheless:

> Signed-off-by: Julien Grall <julien.grall@arm.com>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre.

> ---
>  arm/kvm.c | 75 +++++++++++++++++++++++++++++++--------------------------------
>  1 file changed, 37 insertions(+), 38 deletions(-)
> 
> diff --git a/arm/kvm.c b/arm/kvm.c
> index 5decc138fd3e..3e49db7704aa 100644
> --- a/arm/kvm.c
> +++ b/arm/kvm.c
> @@ -29,44 +29,6 @@ void kvm__init_ram(struct kvm *kvm)
>  	int err;
>  	u64 phys_start, phys_size;
>  	void *host_mem;
> -
> -	phys_start	= ARM_MEMORY_AREA;
> -	phys_size	= kvm->ram_size;
> -	host_mem	= kvm->ram_start;
> -
> -	err = kvm__register_ram(kvm, phys_start, phys_size, host_mem);
> -	if (err)
> -		die("Failed to register %lld bytes of memory at physical "
> -		    "address 0x%llx [err %d]", phys_size, phys_start, err);
> -
> -	kvm->arch.memory_guest_start = phys_start;
> -}
> -
> -void kvm__arch_delete_ram(struct kvm *kvm)
> -{
> -	munmap(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size);
> -}
> -
> -void kvm__arch_read_term(struct kvm *kvm)
> -{
> -	serial8250__update_consoles(kvm);
> -	virtio_console__inject_interrupt(kvm);
> -}
> -
> -void kvm__arch_set_cmdline(char *cmdline, bool video)
> -{
> -}
> -
> -void kvm__arch_sanitize_cfg(struct kvm_config *cfg)
> -{
> -	if (cfg->ram_size > ARM_MAX_MEMORY(cfg)) {
> -		cfg->ram_size = ARM_MAX_MEMORY(cfg);
> -		pr_warning("Capping memory to %lluMB", cfg->ram_size >> 20);
> -	}
> -}
> -
> -void kvm__arch_init(struct kvm *kvm)
> -{
>  	unsigned long alignment;
>  	/* Convenience aliases */
>  	const char *hugetlbfs_path = kvm->cfg.hugetlbfs_path;
> @@ -115,6 +77,43 @@ void kvm__arch_init(struct kvm *kvm)
>  	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
>  		MADV_HUGEPAGE);
>  
> +	phys_start	= ARM_MEMORY_AREA;
> +	phys_size	= kvm->ram_size;
> +	host_mem	= kvm->ram_start;
> +
> +	err = kvm__register_ram(kvm, phys_start, phys_size, host_mem);
> +	if (err)
> +		die("Failed to register %lld bytes of memory at physical "
> +		    "address 0x%llx [err %d]", phys_size, phys_start, err);
> +
> +	kvm->arch.memory_guest_start = phys_start;
> +}
> +
> +void kvm__arch_delete_ram(struct kvm *kvm)
> +{
> +	munmap(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size);
> +}
> +
> +void kvm__arch_read_term(struct kvm *kvm)
> +{
> +	serial8250__update_consoles(kvm);
> +	virtio_console__inject_interrupt(kvm);
> +}
> +
> +void kvm__arch_set_cmdline(char *cmdline, bool video)
> +{
> +}
> +
> +void kvm__arch_sanitize_cfg(struct kvm_config *cfg)
> +{
> +	if (cfg->ram_size > ARM_MAX_MEMORY(cfg)) {
> +		cfg->ram_size = ARM_MAX_MEMORY(cfg);
> +		pr_warning("Capping memory to %lluMB", cfg->ram_size >> 20);
> +	}
> +}
> +
> +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");
diff mbox series

Patch

diff --git a/arm/kvm.c b/arm/kvm.c
index 5decc138fd3e..3e49db7704aa 100644
--- a/arm/kvm.c
+++ b/arm/kvm.c
@@ -29,44 +29,6 @@  void kvm__init_ram(struct kvm *kvm)
 	int err;
 	u64 phys_start, phys_size;
 	void *host_mem;
-
-	phys_start	= ARM_MEMORY_AREA;
-	phys_size	= kvm->ram_size;
-	host_mem	= kvm->ram_start;
-
-	err = kvm__register_ram(kvm, phys_start, phys_size, host_mem);
-	if (err)
-		die("Failed to register %lld bytes of memory at physical "
-		    "address 0x%llx [err %d]", phys_size, phys_start, err);
-
-	kvm->arch.memory_guest_start = phys_start;
-}
-
-void kvm__arch_delete_ram(struct kvm *kvm)
-{
-	munmap(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size);
-}
-
-void kvm__arch_read_term(struct kvm *kvm)
-{
-	serial8250__update_consoles(kvm);
-	virtio_console__inject_interrupt(kvm);
-}
-
-void kvm__arch_set_cmdline(char *cmdline, bool video)
-{
-}
-
-void kvm__arch_sanitize_cfg(struct kvm_config *cfg)
-{
-	if (cfg->ram_size > ARM_MAX_MEMORY(cfg)) {
-		cfg->ram_size = ARM_MAX_MEMORY(cfg);
-		pr_warning("Capping memory to %lluMB", cfg->ram_size >> 20);
-	}
-}
-
-void kvm__arch_init(struct kvm *kvm)
-{
 	unsigned long alignment;
 	/* Convenience aliases */
 	const char *hugetlbfs_path = kvm->cfg.hugetlbfs_path;
@@ -115,6 +77,43 @@  void kvm__arch_init(struct kvm *kvm)
 	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
 		MADV_HUGEPAGE);
 
+	phys_start	= ARM_MEMORY_AREA;
+	phys_size	= kvm->ram_size;
+	host_mem	= kvm->ram_start;
+
+	err = kvm__register_ram(kvm, phys_start, phys_size, host_mem);
+	if (err)
+		die("Failed to register %lld bytes of memory at physical "
+		    "address 0x%llx [err %d]", phys_size, phys_start, err);
+
+	kvm->arch.memory_guest_start = phys_start;
+}
+
+void kvm__arch_delete_ram(struct kvm *kvm)
+{
+	munmap(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size);
+}
+
+void kvm__arch_read_term(struct kvm *kvm)
+{
+	serial8250__update_consoles(kvm);
+	virtio_console__inject_interrupt(kvm);
+}
+
+void kvm__arch_set_cmdline(char *cmdline, bool video)
+{
+}
+
+void kvm__arch_sanitize_cfg(struct kvm_config *cfg)
+{
+	if (cfg->ram_size > ARM_MAX_MEMORY(cfg)) {
+		cfg->ram_size = ARM_MAX_MEMORY(cfg);
+		pr_warning("Capping memory to %lluMB", cfg->ram_size >> 20);
+	}
+}
+
+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");