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

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