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

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