[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v2 16/21] physmem: Introduce ram_block_convert_range()
From: |
Xiaoyao Li |
Subject: |
[RFC PATCH v2 16/21] physmem: Introduce ram_block_convert_range() |
Date: |
Wed, 13 Sep 2023 23:51:12 -0400 |
It's used for discarding oppsite memory after memory conversion to
shared/private.
Note, private-shared page conversion is done at 4KB granularity. Don't
check alignment with rb->page_size, instead qemu_host_page_size, which
is 4K.
Originally-from: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
include/exec/cpu-common.h | 2 ++
softmmu/physmem.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 87dc9a752c9a..558684b9f246 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -157,6 +157,8 @@ typedef int (RAMBlockIterFunc)(RAMBlock *rb, void *opaque);
int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque);
int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length);
+int ram_block_convert_range(RAMBlock *rb, uint64_t start, size_t length,
+ bool shared_to_private);
#endif
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 6ee6bc794f44..dab3247d461c 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -3733,3 +3733,39 @@ bool ram_block_discard_is_required(void)
return qatomic_read(&ram_block_discard_required_cnt) ||
qatomic_read(&ram_block_coordinated_discard_required_cnt);
}
+
+int ram_block_convert_range(RAMBlock *rb, uint64_t start, size_t length,
+ bool shared_to_private)
+{
+ int fd;
+
+ if (!rb || rb->gmem_fd < 0) {
+ return -1;
+ }
+
+ if (!QEMU_PTR_IS_ALIGNED(start, qemu_host_page_size) ||
+ !QEMU_PTR_IS_ALIGNED(length, qemu_host_page_size)) {
+ return -1;
+ }
+
+ if (!length) {
+ return -1;
+ }
+
+ if (start + length > rb->max_length) {
+ return -1;
+ }
+
+ if (shared_to_private) {
+ void *host_startaddr = rb->host + start;
+
+ if (!QEMU_PTR_IS_ALIGNED(host_startaddr, qemu_host_page_size)) {
+ return -1;
+ }
+ fd = rb->fd;
+ } else {
+ fd = rb->gmem_fd;
+ }
+
+ return ram_block_discard_range_fd(rb, start, length, fd);
+}
--
2.34.1
- Re: [RFC PATCH v2 07/21] i386/pc: Drop pc_machine_kvm_type(), (continued)
- [RFC PATCH v2 08/21] target/i386: Implement mc->kvm_type() to get VM type, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 09/21] target/i386: Introduce kvm_confidential_guest_init(), Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 10/21] i386/kvm: Implement kvm_sw_protected_vm_init() for sw-protcted-vm specific functions, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 11/21] kvm: Introduce support for memory_attributes, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 12/21] kvm/memory: Introduce the infrastructure to set the default shared/private value, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 13/21] i386/kvm: Set memory to default private for KVM_X86_SW_PROTECTED_VM, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 14/21] physmem: replace function name with __func__ in ram_block_discard_range(), Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 15/21] physmem: extract ram_block_discard_range_fd() from ram_block_discard_range(), Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 17/21] kvm: handle KVM_EXIT_MEMORY_FAULT, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 16/21] physmem: Introduce ram_block_convert_range(),
Xiaoyao Li <=
- [RFC PATCH v2 18/21] trace/kvm: Add trace for page convertion between shared and private, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 19/21] pci-host/q35: Move PAM initialization above SMRAM initialization, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 20/21] q35: Introduce smm_ranges property for q35-pci-host, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 21/21] i386: Disable SMM mode for X86_SW_PROTECTED_VM, Xiaoyao Li, 2023/09/13
- Re: [RFC PATCH v2 00/21] QEMU gmem implemention, David Hildenbrand, 2023/09/14
- Re: [RFC PATCH v2 00/21] QEMU gmem implemention, Xiaoyao Li, 2023/09/14