All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Elisei <alexandru.elisei@arm.com>
To: will@kernel.org, julien.thierry.kdev@gmail.com, maz@kernel.org,
	suzuki.poulose@arm.com, julien@xen.org,
	linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, james.morse@arm.com,
	andre.przywara@arm.com
Cc: Julien Grall <julien.grall@arm.com>
Subject: [PATCH v3 kvmtool 11/13] arm/arm64: Consolidate RAM initialization in kvm__init_ram()
Date: Wed, 25 May 2022 12:23:43 +0100	[thread overview]
Message-ID: <20220525112345.121321-12-alexandru.elisei@arm.com> (raw)
In-Reply-To: <20220525112345.121321-1-alexandru.elisei@arm.com>

From: Julien Grall <julien.grall@arm.com>

RAM initialization is unnecessarily split between kvm__init_ram() and
kvm__arch_init(). Move all code related to RAM initialization to
kvm__init_ram(), making the code easier to follow and to modify.

One thing to note is that the initialization order is slightly altered:
kvm__arch_enable_mte() and gic__create() are now called before mmap'ing the
guest RAM. That is perfectly fine, as they don't use the host's mapping of
the guest memory.

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

diff --git a/arm/kvm.c b/arm/kvm.c
index bd44aa350796..abcccfabf59e 100644
--- a/arm/kvm.c
+++ b/arm/kvm.c
@@ -26,9 +26,34 @@ bool kvm__arch_cpu_supports_vm(void)
 
 void kvm__init_ram(struct kvm *kvm)
 {
-	int err;
 	u64 phys_start, phys_size;
 	void *host_mem;
+	int err;
+
+	/*
+	 * Allocate guest memory. We must align our buffer to 64K to
+	 * correlate with the maximum guest page size for virtio-mmio.
+	 * If using THP, then our minimal alignment becomes 2M.
+	 * 2M trumps 64K, so let's go with that.
+	 */
+	kvm->ram_size = kvm->cfg.ram_size;
+	kvm->arch.ram_alloc_size = kvm->ram_size + SZ_2M;
+	kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs(kvm,
+						kvm->cfg.hugetlbfs_path,
+						kvm->arch.ram_alloc_size);
+
+	if (kvm->arch.ram_alloc_start == MAP_FAILED)
+		die("Failed to map %lld bytes for guest memory (%d)",
+		    kvm->arch.ram_alloc_size, errno);
+
+	kvm->ram_start = (void *)ALIGN((unsigned long)kvm->arch.ram_alloc_start,
+					SZ_2M);
+
+	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
+		MADV_MERGEABLE);
+
+	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
+		MADV_HUGEPAGE);
 
 	phys_start	= ARM_MEMORY_AREA;
 	phys_size	= kvm->ram_size;
@@ -59,31 +84,6 @@ void kvm__arch_set_cmdline(char *cmdline, bool video)
 
 void kvm__arch_init(struct kvm *kvm)
 {
-	/*
-	 * Allocate guest memory. We must align our buffer to 64K to
-	 * correlate with the maximum guest page size for virtio-mmio.
-	 * If using THP, then our minimal alignment becomes 2M.
-	 * 2M trumps 64K, so let's go with that.
-	 */
-	kvm->ram_size = kvm->cfg.ram_size;
-	kvm->arch.ram_alloc_size = kvm->ram_size + SZ_2M;
-	kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs(kvm,
-						kvm->cfg.hugetlbfs_path,
-						kvm->arch.ram_alloc_size);
-
-	if (kvm->arch.ram_alloc_start == MAP_FAILED)
-		die("Failed to map %lld bytes for guest memory (%d)",
-		    kvm->arch.ram_alloc_size, errno);
-
-	kvm->ram_start = (void *)ALIGN((unsigned long)kvm->arch.ram_alloc_start,
-					SZ_2M);
-
-	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
-		MADV_MERGEABLE);
-
-	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
-		MADV_HUGEPAGE);
-
 	/* Create the virtual GIC. */
 	if (gic__create(kvm, kvm->cfg.arch.irqchip))
 		die("Failed to create virtual GIC");
-- 
2.36.1

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

WARNING: multiple messages have this Message-ID (diff)
From: Alexandru Elisei <alexandru.elisei@arm.com>
To: will@kernel.org, julien.thierry.kdev@gmail.com, maz@kernel.org,
	suzuki.poulose@arm.com, julien@xen.org,
	linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, james.morse@arm.com,
	andre.przywara@arm.com
Cc: Julien Grall <julien.grall@arm.com>
Subject: [PATCH v3 kvmtool 11/13] arm/arm64: Consolidate RAM initialization in kvm__init_ram()
Date: Wed, 25 May 2022 12:23:43 +0100	[thread overview]
Message-ID: <20220525112345.121321-12-alexandru.elisei@arm.com> (raw)
In-Reply-To: <20220525112345.121321-1-alexandru.elisei@arm.com>

From: Julien Grall <julien.grall@arm.com>

RAM initialization is unnecessarily split between kvm__init_ram() and
kvm__arch_init(). Move all code related to RAM initialization to
kvm__init_ram(), making the code easier to follow and to modify.

One thing to note is that the initialization order is slightly altered:
kvm__arch_enable_mte() and gic__create() are now called before mmap'ing the
guest RAM. That is perfectly fine, as they don't use the host's mapping of
the guest memory.

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

diff --git a/arm/kvm.c b/arm/kvm.c
index bd44aa350796..abcccfabf59e 100644
--- a/arm/kvm.c
+++ b/arm/kvm.c
@@ -26,9 +26,34 @@ bool kvm__arch_cpu_supports_vm(void)
 
 void kvm__init_ram(struct kvm *kvm)
 {
-	int err;
 	u64 phys_start, phys_size;
 	void *host_mem;
+	int err;
+
+	/*
+	 * Allocate guest memory. We must align our buffer to 64K to
+	 * correlate with the maximum guest page size for virtio-mmio.
+	 * If using THP, then our minimal alignment becomes 2M.
+	 * 2M trumps 64K, so let's go with that.
+	 */
+	kvm->ram_size = kvm->cfg.ram_size;
+	kvm->arch.ram_alloc_size = kvm->ram_size + SZ_2M;
+	kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs(kvm,
+						kvm->cfg.hugetlbfs_path,
+						kvm->arch.ram_alloc_size);
+
+	if (kvm->arch.ram_alloc_start == MAP_FAILED)
+		die("Failed to map %lld bytes for guest memory (%d)",
+		    kvm->arch.ram_alloc_size, errno);
+
+	kvm->ram_start = (void *)ALIGN((unsigned long)kvm->arch.ram_alloc_start,
+					SZ_2M);
+
+	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
+		MADV_MERGEABLE);
+
+	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
+		MADV_HUGEPAGE);
 
 	phys_start	= ARM_MEMORY_AREA;
 	phys_size	= kvm->ram_size;
@@ -59,31 +84,6 @@ void kvm__arch_set_cmdline(char *cmdline, bool video)
 
 void kvm__arch_init(struct kvm *kvm)
 {
-	/*
-	 * Allocate guest memory. We must align our buffer to 64K to
-	 * correlate with the maximum guest page size for virtio-mmio.
-	 * If using THP, then our minimal alignment becomes 2M.
-	 * 2M trumps 64K, so let's go with that.
-	 */
-	kvm->ram_size = kvm->cfg.ram_size;
-	kvm->arch.ram_alloc_size = kvm->ram_size + SZ_2M;
-	kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs(kvm,
-						kvm->cfg.hugetlbfs_path,
-						kvm->arch.ram_alloc_size);
-
-	if (kvm->arch.ram_alloc_start == MAP_FAILED)
-		die("Failed to map %lld bytes for guest memory (%d)",
-		    kvm->arch.ram_alloc_size, errno);
-
-	kvm->ram_start = (void *)ALIGN((unsigned long)kvm->arch.ram_alloc_start,
-					SZ_2M);
-
-	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
-		MADV_MERGEABLE);
-
-	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
-		MADV_HUGEPAGE);
-
 	/* Create the virtual GIC. */
 	if (gic__create(kvm, kvm->cfg.arch.irqchip))
 		die("Failed to create virtual GIC");
-- 
2.36.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-05-25 11:24 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-25 11:23 [PATCH v3 kvmtool 00/13] arm64: Allow the user to set RAM base address Alexandru Elisei
2022-05-25 11:23 ` Alexandru Elisei
2022-05-25 11:23 ` [PATCH v3 kvmtool 01/13] Use MB for megabytes consistently Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-05-25 11:23 ` [PATCH v3 kvmtool 02/13] sizes.h: Make all sizes 64bit Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-05-30 15:05   ` Andre Przywara
2022-05-30 15:05     ` Andre Przywara
2022-06-15 16:01     ` Alexandru Elisei
2022-06-15 16:01       ` Alexandru Elisei
2022-05-25 11:23 ` [PATCH v3 kvmtool 03/13] builtin-run: Always use RAM size in bytes Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-05-25 11:23 ` [PATCH v3 kvmtool 04/13] builtin-run: Rework RAM size validation Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-05-30 17:13   ` Andre Przywara
2022-05-30 17:13     ` Andre Przywara
2022-05-25 11:23 ` [PATCH v3 kvmtool 05/13] builtin-run: Add arch hook to validate VM configuration Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-05-25 11:23 ` [PATCH v3 kvmtool 06/13] arm/arm64: Fail if RAM size is too large for 32-bit guests Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-06-01 11:09   ` Andre Przywara
2022-06-01 11:09     ` Andre Przywara
2022-05-25 11:23 ` [PATCH v3 kvmtool 07/13] arm/arm64: Kill the ARM_MAX_MEMORY() macro Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-06-01 11:14   ` Andre Przywara
2022-06-01 11:14     ` Andre Przywara
2022-05-25 11:23 ` [PATCH v3 kvmtool 08/13] arm/arm64: Kill the ARM_HIMAP_MAX_MEMORY() macro Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-06-01 11:16   ` Andre Przywara
2022-06-01 11:16     ` Andre Przywara
2022-05-25 11:23 ` [PATCH v3 kvmtool 09/13] builtin_run: Allow standard size specifiers for memory Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-06-01 13:39   ` Andre Przywara
2022-06-01 13:39     ` Andre Przywara
2022-06-01 14:17     ` Alexandru Elisei
2022-06-01 14:17       ` Alexandru Elisei
2022-06-01 16:14       ` Andre Przywara
2022-06-01 16:14         ` Andre Przywara
2022-06-01 19:39         ` Alexandru Elisei
2022-06-01 19:39           ` Alexandru Elisei
2022-06-01 19:42           ` Alexandru Elisei
2022-06-01 19:42             ` Alexandru Elisei
2022-06-01 20:13           ` Alexandru Elisei
2022-06-01 20:13             ` Alexandru Elisei
2022-06-06 10:53             ` Andre Przywara
2022-06-06 10:53               ` Andre Przywara
2022-05-25 11:23 ` [PATCH v3 kvmtool 10/13] kvm__arch_init: Remove hugetlbfs_path and ram_size as parameters Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-06-01 13:13   ` Andre Przywara
2022-06-01 13:13     ` Andre Przywara
2022-05-25 11:23 ` Alexandru Elisei [this message]
2022-05-25 11:23   ` [PATCH v3 kvmtool 11/13] arm/arm64: Consolidate RAM initialization in kvm__init_ram() Alexandru Elisei
2022-06-01 13:20   ` Andre Przywara
2022-06-01 13:20     ` Andre Przywara
2022-05-25 11:23 ` [PATCH v3 kvmtool 12/13] Introduce kvm__arch_default_ram_address() Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-06-01 13:21   ` Andre Przywara
2022-06-01 13:21     ` Andre Przywara
2022-05-25 11:23 ` [PATCH v3 kvmtool 13/13] arm64: Allow the user to specify the RAM base address Alexandru Elisei
2022-05-25 11:23   ` Alexandru Elisei
2022-06-01 13:39   ` Andre Przywara
2022-06-01 13:39     ` Andre Przywara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220525112345.121321-12-alexandru.elisei@arm.com \
    --to=alexandru.elisei@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=james.morse@arm.com \
    --cc=julien.grall@arm.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=julien@xen.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.