yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-mem-nvdimm-ensure-write-persistence-to-PMEM-in-label.patch

ae23c9
From 3fe466338a4ab4a119933768462d62c6d7b9024e Mon Sep 17 00:00:00 2001
ae23c9
From: "plai@redhat.com" <plai@redhat.com>
ae23c9
Date: Mon, 7 Jan 2019 17:02:20 +0000
ae23c9
Subject: [PATCH 19/22] mem/nvdimm: ensure write persistence to PMEM in label
ae23c9
 emulation
ae23c9
ae23c9
RH-Author: plai@redhat.com
ae23c9
Message-id: <1546880543-24860-8-git-send-email-plai@redhat.com>
ae23c9
Patchwork-id: 83893
ae23c9
O-Subject: [RHEL8.0 qemu-kvm PATCH v7 07/10] mem/nvdimm: ensure write persistence to PMEM in label emulation
ae23c9
Bugzilla: 1539285
ae23c9
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ae23c9
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
ae23c9
ae23c9
From: Junyan He <junyan.he@intel.com>
ae23c9
ae23c9
Guest writes to vNVDIMM labels are intercepted and performed on the
ae23c9
backend by QEMU. When the backend is a real persistent memort, QEMU
ae23c9
needs to take proper operations to ensure its write persistence on the
ae23c9
persistent memory. Otherwise, a host power failure may result in the
ae23c9
loss of guest label configurations.
ae23c9
ae23c9
Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
ae23c9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
ae23c9
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
ae23c9
(cherry picked from commit faf8a13d80de98b43342a7ec9878b4fd76b18327)
ae23c9
Signed-off-by: Paul Lai <plai@redhat.com>
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 hw/mem/nvdimm.c     |  9 ++++++++-
ae23c9
 include/qemu/pmem.h | 30 ++++++++++++++++++++++++++++++
ae23c9
 2 files changed, 38 insertions(+), 1 deletion(-)
ae23c9
 create mode 100644 include/qemu/pmem.h
ae23c9
ae23c9
diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
ae23c9
index acb656b..0c962fd 100644
ae23c9
--- a/hw/mem/nvdimm.c
ae23c9
+++ b/hw/mem/nvdimm.c
ae23c9
@@ -23,6 +23,7 @@
ae23c9
  */
ae23c9
 
ae23c9
 #include "qemu/osdep.h"
ae23c9
+#include "qemu/pmem.h"
ae23c9
 #include "qapi/error.h"
ae23c9
 #include "qapi/visitor.h"
ae23c9
 #include "hw/mem/nvdimm.h"
ae23c9
@@ -155,11 +156,17 @@ static void nvdimm_write_label_data(NVDIMMDevice *nvdimm, const void *buf,
ae23c9
 {
ae23c9
     MemoryRegion *mr;
ae23c9
     PCDIMMDevice *dimm = PC_DIMM(nvdimm);
ae23c9
+    bool is_pmem = object_property_get_bool(OBJECT(dimm->hostmem),
ae23c9
+                                            "pmem", NULL);
ae23c9
     uint64_t backend_offset;
ae23c9
 
ae23c9
     nvdimm_validate_rw_label_data(nvdimm, size, offset);
ae23c9
 
ae23c9
-    memcpy(nvdimm->label_data + offset, buf, size);
ae23c9
+    if (!is_pmem) {
ae23c9
+        memcpy(nvdimm->label_data + offset, buf, size);
ae23c9
+    } else {
ae23c9
+        pmem_memcpy_persist(nvdimm->label_data + offset, buf, size);
ae23c9
+    }
ae23c9
 
ae23c9
     mr = host_memory_backend_get_memory(dimm->hostmem, &error_abort);
ae23c9
     backend_offset = memory_region_size(mr) - nvdimm->label_size + offset;
ae23c9
diff --git a/include/qemu/pmem.h b/include/qemu/pmem.h
ae23c9
new file mode 100644
ae23c9
index 0000000..ebdb070
ae23c9
--- /dev/null
ae23c9
+++ b/include/qemu/pmem.h
ae23c9
@@ -0,0 +1,30 @@
ae23c9
+/*
ae23c9
+ * QEMU header file for libpmem.
ae23c9
+ *
ae23c9
+ * Copyright (c) 2018 Intel Corporation.
ae23c9
+ *
ae23c9
+ * Author: Haozhong Zhang <address@hidden>
ae23c9
+ *
ae23c9
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
ae23c9
+ * See the COPYING file in the top-level directory.
ae23c9
+ */
ae23c9
+
ae23c9
+#ifndef QEMU_PMEM_H
ae23c9
+#define QEMU_PMEM_H
ae23c9
+
ae23c9
+#ifdef CONFIG_LIBPMEM
ae23c9
+#include <libpmem.h>
ae23c9
+#else  /* !CONFIG_LIBPMEM */
ae23c9
+
ae23c9
+static inline void *
ae23c9
+pmem_memcpy_persist(void *pmemdest, const void *src, size_t len)
ae23c9
+{
ae23c9
+    /* If 'pmem' option is 'on', we should always have libpmem support,
ae23c9
+       or qemu will report a error and exit, never come here. */
ae23c9
+    g_assert_not_reached();
ae23c9
+    return NULL;
ae23c9
+}
ae23c9
+
ae23c9
+#endif /* CONFIG_LIBPMEM */
ae23c9
+
ae23c9
+#endif /* !QEMU_PMEM_H */
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9