[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/2] hostmem-file: Add "nopin" option for memory-bac
From: |
Yang Zhong |
Subject: |
[Qemu-devel] [PATCH 1/2] hostmem-file: Add "nopin" option for memory-backend-file |
Date: |
Mon, 16 Oct 2017 16:56:22 +0800 |
Since qemu does not need pin nvdimm memory during the VFIO
hotplug, the new option can be used to avoid pin whole nvdimm
memory. The default value is still "nopin=off" as previous.
Signed-off-by: Yang Zhong <address@hidden>
---
backends/hostmem-file.c | 23 +++++++++++++++++++++++
hw/vfio/common.c | 12 +++++++++++-
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index e44c319..e402077 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -33,6 +33,7 @@ struct HostMemoryBackendFile {
bool share;
bool discard_data;
+ bool nopin;
char *mem_path;
};
@@ -128,6 +129,25 @@ static void file_backend_unparent(Object *obj)
}
}
+static bool file_memory_backend_get_nopin(Object *o, Error **errp)
+{
+ HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o);
+
+ return fb->nopin;
+}
+
+static void file_memory_backend_set_nopin(Object *o, bool value, Error **errp)
+{
+ HostMemoryBackend *backend = MEMORY_BACKEND(o);
+ HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o);
+
+ if (memory_region_size(&backend->mr)) {
+ error_setg(errp, "cannot change property value");
+ return;
+ }
+ fb->nopin = value;
+}
+
static void
file_backend_class_init(ObjectClass *oc, void *data)
{
@@ -142,6 +162,9 @@ file_backend_class_init(ObjectClass *oc, void *data)
object_class_property_add_bool(oc, "discard-data",
file_memory_backend_get_discard_data,
file_memory_backend_set_discard_data,
&error_abort);
+ object_class_property_add_bool(oc, "nopin",
+ file_memory_backend_get_nopin, file_memory_backend_set_nopin,
+ &error_abort);
object_class_property_add_str(oc, "mem-path",
get_mem_path, set_mem_path,
&error_abort);
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 7b2924c..f36ff24 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -408,7 +408,8 @@ static void vfio_listener_region_add(MemoryListener
*listener,
void *vaddr;
int ret;
VFIOHostDMAWindow *hostwin;
- bool hostwin_found;
+ bool hostwin_found, nopin;
+ Object *obj = section->mr->owner;
if (vfio_listener_skipped_section(section)) {
trace_vfio_listener_region_add_skip(
@@ -424,6 +425,15 @@ static void vfio_listener_region_add(MemoryListener
*listener,
return;
}
+ if (obj && object_dynamic_cast(obj, "memory-backend-file")) {
+ nopin = object_property_get_bool(obj, "nopin", NULL);
+ if (nopin) {
+ error_report("warning: If VFIO DMA still map to NVDIMM memory, "
+ "the VM will crash");
+ return;
+ }
+ }
+
iova = TARGET_PAGE_ALIGN(section->offset_within_address_space);
llend = int128_make64(section->offset_within_address_space);
llend = int128_add(llend, section->size);
--
1.9.1
Re: [Qemu-devel] [PATCH 0/2] add "nopin" option in the memory-backend-file, Alex Williamson, 2017/10/16