cryptospore / 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

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