From: Fuad Tabba <tabba@google.com>
To: kvm@vger.kernel.org
Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com,
alexandru.elisei@arm.com, will@kernel.org, tabba@google.com
Subject: [PATCH kvmtool v1 13/17] Remove struct fields and code used for alignment
Date: Tue, 15 Nov 2022 11:15:45 +0000 [thread overview]
Message-ID: <20221115111549.2784927-14-tabba@google.com> (raw)
In-Reply-To: <20221115111549.2784927-1-tabba@google.com>
Now that the allocator allocates aligned memory, remove
arch-specific code and struct fields used for alignment.
No functional change intended.
Signed-off-by: Fuad Tabba <tabba@google.com>
---
arm/include/arm-common/kvm-arch.h | 7 -------
arm/kvm.c | 31 +++++++++++--------------------
riscv/include/kvm/kvm-arch.h | 7 -------
riscv/kvm.c | 21 +++++++--------------
4 files changed, 18 insertions(+), 48 deletions(-)
diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h
index b2ae373..654abc9 100644
--- a/arm/include/arm-common/kvm-arch.h
+++ b/arm/include/arm-common/kvm-arch.h
@@ -96,13 +96,6 @@ static inline bool arm_addr_in_ioport_region(u64 phys_addr)
}
struct kvm_arch {
- /*
- * We may have to align the guest memory for virtio, so keep the
- * original pointers here for munmap.
- */
- void *ram_alloc_start;
- u64 ram_alloc_size;
-
/*
* Guest addresses for memory layout.
*/
diff --git a/arm/kvm.c b/arm/kvm.c
index 0e5bfad..770075e 100644
--- a/arm/kvm.c
+++ b/arm/kvm.c
@@ -27,7 +27,6 @@ bool kvm__arch_cpu_supports_vm(void)
void kvm__init_ram(struct kvm *kvm)
{
u64 phys_start, phys_size;
- void *host_mem;
int err;
/*
@@ -37,42 +36,34 @@ void kvm__init_ram(struct kvm *kvm)
* 2M trumps 64K, so let's go with that.
*/
kvm->ram_size = kvm->cfg.ram_size;
- kvm->arch.ram_alloc_size = kvm->ram_size;
- kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs_align(kvm,
- kvm->cfg.hugetlbfs_path,
- kvm->arch.ram_alloc_size,
- SZ_2M);
+ kvm->ram_start = mmap_anon_or_hugetlbfs_align(kvm,
+ kvm->cfg.hugetlbfs_path,
+ kvm->ram_size, SZ_2M);
- if (kvm->arch.ram_alloc_start == MAP_FAILED)
+ if (kvm->ram_start == MAP_FAILED)
die("Failed to map %lld bytes for guest memory (%d)",
- kvm->arch.ram_alloc_size, errno);
+ kvm->ram_size, errno);
- kvm->ram_start = kvm->arch.ram_alloc_start;
-
- 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);
+ madvise(kvm->ram_start, kvm->ram_size, MADV_MERGEABLE);
+ madvise(kvm->ram_start, kvm->ram_size, MADV_HUGEPAGE);
phys_start = kvm->cfg.ram_addr;
phys_size = kvm->ram_size;
- host_mem = kvm->ram_start;
- err = kvm__register_ram(kvm, phys_start, phys_size, host_mem);
+ err = kvm__register_ram(kvm, phys_start, phys_size, kvm->ram_start);
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;
- pr_debug("RAM created at 0x%llx - 0x%llx (host_mem 0x%llx)",
- phys_start, phys_start + phys_size - 1, (u64)host_mem);
+ pr_debug("RAM created at 0x%llx - 0x%llx (host ram_start 0x%llx)",
+ phys_start, phys_start + phys_size - 1, (u64)kvm->ram_start);
}
void kvm__arch_delete_ram(struct kvm *kvm)
{
- munmap(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size);
+ munmap(kvm->ram_start, kvm->ram_size);
}
void kvm__arch_read_term(struct kvm *kvm)
diff --git a/riscv/include/kvm/kvm-arch.h b/riscv/include/kvm/kvm-arch.h
index 1e130f5..5bb7eee 100644
--- a/riscv/include/kvm/kvm-arch.h
+++ b/riscv/include/kvm/kvm-arch.h
@@ -56,13 +56,6 @@
struct kvm;
struct kvm_arch {
- /*
- * We may have to align the guest memory for virtio, so keep the
- * original pointers here for munmap.
- */
- void *ram_alloc_start;
- u64 ram_alloc_size;
-
/*
* Guest addresses for memory layout.
*/
diff --git a/riscv/kvm.c b/riscv/kvm.c
index e26b4f0..d05b8e4 100644
--- a/riscv/kvm.c
+++ b/riscv/kvm.c
@@ -48,7 +48,7 @@ void kvm__init_ram(struct kvm *kvm)
void kvm__arch_delete_ram(struct kvm *kvm)
{
- munmap(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size);
+ munmap(kvm->ram_start, kvm->ram_size);
}
void kvm__arch_read_term(struct kvm *kvm)
@@ -70,23 +70,16 @@ void kvm__arch_init(struct kvm *kvm)
* 2M trumps 64K, so let's go with that.
*/
kvm->ram_size = min(kvm->cfg.ram_size, (u64)RISCV_MAX_MEMORY(kvm));
- kvm->arch.ram_alloc_size = kvm->ram_size;
- kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs_align(kvm,
- kvm->cfg.hugetlbfs_path,
- kvm->arch.ram_alloc_size,
- SZ_2M);
+ kvm->ram_start = mmap_anon_or_hugetlbfs_align(kvm,
+ kvm->cfg.hugetlbfs_path,
+ kvm->ram_size, SZ_2M);
- if (kvm->arch.ram_alloc_start == MAP_FAILED)
+ if (kvm->ram_start == MAP_FAILED)
die("Failed to map %lld bytes for guest memory (%d)",
kvm->arch.ram_alloc_size, errno);
- kvm->ram_start = kvm->arch.ram_alloc_start;
-
- 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);
+ madvise(kvm->ram_start, kvm->ram_size, MADV_MERGEABLE);
+ madvise(kvm->ram_start, kvm->ram_size, MADV_HUGEPAGE);
}
#define FDT_ALIGN SZ_4M
--
2.38.1.431.g37b22c650d-goog
next prev parent reply other threads:[~2022-11-15 11:17 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 11:15 [PATCH kvmtool v1 00/17] Use memfd for guest vm memory allocation Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 01/17] Initialize the return value in kvm__for_each_mem_bank() Fuad Tabba
2022-11-15 11:59 ` Andre Przywara
2022-11-23 16:08 ` Alexandru Elisei
2022-11-23 17:43 ` Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 02/17] Make mmap_hugetlbfs() static Fuad Tabba
2022-11-15 17:58 ` Andre Przywara
2022-11-15 11:15 ` [PATCH kvmtool v1 03/17] Rename parameter in mmap_anon_or_hugetlbfs() Fuad Tabba
2022-11-23 16:40 ` Alexandru Elisei
2022-11-23 17:44 ` Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 04/17] Add hostmem va to debug print Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 05/17] Factor out getting the hugetlb block size Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 06/17] Use memfd for hugetlbfs when allocating guest ram Fuad Tabba
2022-11-24 10:19 ` Alexandru Elisei
2022-11-24 10:45 ` Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 07/17] Make blk_size a parameter and pass it to mmap_hugetlbfs() Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 08/17] Use memfd for all guest ram allocations Fuad Tabba
2022-11-24 11:01 ` Alexandru Elisei
2022-11-24 15:19 ` Fuad Tabba
2022-11-24 17:14 ` Alexandru Elisei
2022-11-25 10:43 ` Alexandru Elisei
2022-11-25 10:58 ` Fuad Tabba
2022-11-25 10:44 ` Fuad Tabba
2022-11-25 11:31 ` Alexandru Elisei
2022-11-28 8:49 ` Fuad Tabba
2022-11-29 18:09 ` Alexandru Elisei
2022-11-30 17:54 ` Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 09/17] Allocate pvtime memory with memfd Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 10/17] Allocate vesa " Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 11/17] Add a function that allocates aligned memory if specified Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 12/17] Use new function to align memory Fuad Tabba
2022-11-15 11:15 ` Fuad Tabba [this message]
2022-11-15 11:15 ` [PATCH kvmtool v1 14/17] Replace kvm_arch_delete_ram with kvm_delete_ram Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 15/17] Remove no-longer unused macro Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 16/17] Factor out set_user_memory_region code Fuad Tabba
2022-11-15 11:15 ` [PATCH kvmtool v1 17/17] Pass the memory file descriptor and offset when registering ram Fuad Tabba
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=20221115111549.2784927-14-tabba@google.com \
--to=tabba@google.com \
--cc=alexandru.elisei@arm.com \
--cc=andre.przywara@arm.com \
--cc=julien.thierry.kdev@gmail.com \
--cc=kvm@vger.kernel.org \
--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.