[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 07/66] physmem: Introduce ram_block_discard_guest_memfd_range(
|
From: |
Xiaoyao Li |
|
Subject: |
[PATCH v4 07/66] physmem: Introduce ram_block_discard_guest_memfd_range() |
|
Date: |
Wed, 24 Jan 2024 22:22:29 -0500 |
When memory page is converted from private to shared, the original
private memory is back'ed by guest_memfd. Introduce
ram_block_discard_guest_memfd_range() for discarding memory in
guest_memfd.
Originally-from: Isaku Yamahata <isaku.yamahata@intel.com>
Codeveloped-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
Changes in in v4:
- Drop ram_block_convert_range() and open code its implementation in the
next Patch.
---
include/exec/cpu-common.h | 2 ++
system/physmem.c | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index fef3138d29fc..05610efa8b4f 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -175,6 +175,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_discard_guest_memfd_range(RAMBlock *rb, uint64_t start,
+ size_t length);
#endif
diff --git a/system/physmem.c b/system/physmem.c
index 4735b0462ed9..fc59470191ef 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -3626,6 +3626,29 @@ err:
return ret;
}
+int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_t start,
+ size_t length)
+{
+ int ret = -1;
+
+#ifdef CONFIG_FALLOCATE_PUNCH_HOLE
+ ret = fallocate(rb->guest_memfd, FALLOC_FL_PUNCH_HOLE |
FALLOC_FL_KEEP_SIZE,
+ start, length);
+
+ if (ret) {
+ ret = -errno;
+ error_report("%s: Failed to fallocate %s:%" PRIx64 " +%zx (%d)",
+ __func__, rb->idstr, start, length, ret);
+ }
+#else
+ ret = -ENOSYS;
+ error_report("%s: fallocate not available %s:%" PRIx64 " +%zx (%d)",
+ __func__, rb->idstr, start, length, ret);
+#endif
+
+ return ret;
+}
+
bool ramblock_is_pmem(RAMBlock *rb)
{
return rb->flags & RAM_PMEM;
--
2.34.1
- [PATCH v4 02/66] RAMBlock: Add support of KVM private guest memfd, (continued)
- [PATCH v4 02/66] RAMBlock: Add support of KVM private guest memfd, Xiaoyao Li, 2024/01/24
- [PATCH v4 03/66] HostMem: Add mechanism to opt in kvm guest memfd via MachineState, Xiaoyao Li, 2024/01/24
- [PATCH v4 04/66] trace/kvm: Split address space and slot id in trace_kvm_set_user_memory(), Xiaoyao Li, 2024/01/24
- [PATCH v4 06/66] kvm: Introduce support for memory_attributes, Xiaoyao Li, 2024/01/24
- [PATCH v4 05/66] kvm: Enable KVM_SET_USER_MEMORY_REGION2 for memslot, Xiaoyao Li, 2024/01/24
- [PATCH v4 08/66] kvm: handle KVM_EXIT_MEMORY_FAULT, Xiaoyao Li, 2024/01/24
- [PATCH v4 01/66] linux-headers: Update to Linux v6.8-rc1, Xiaoyao Li, 2024/01/24
- [PATCH v4 07/66] physmem: Introduce ram_block_discard_guest_memfd_range(),
Xiaoyao Li <=
- [PATCH v4 10/66] *** HACK *** linux-headers: Update headers to pull in TDX API changes, Xiaoyao Li, 2024/01/24
- [PATCH v4 09/66] trace/kvm: Add trace for page convertion between shared and private, Xiaoyao Li, 2024/01/24
- [PATCH v4 12/66] target/i386: Implement mc->kvm_type() to get VM type, Xiaoyao Li, 2024/01/24
- [PATCH v4 11/66] i386: Introduce tdx-guest object, Xiaoyao Li, 2024/01/24
- [PATCH v4 13/66] target/i386: Introduce kvm_confidential_guest_init(), Xiaoyao Li, 2024/01/24
- [PATCH v4 15/66] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES, Xiaoyao Li, 2024/01/24
- [PATCH v4 14/66] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context, Xiaoyao Li, 2024/01/24
- [PATCH v4 16/66] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object, Xiaoyao Li, 2024/01/24