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

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