[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 5/7] mem/nvdimm: ensure write persistence to PMEM in
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 5/7] mem/nvdimm: ensure write persistence to PMEM in label emulation |
Date: |
Mon, 20 Aug 2018 23:24:48 +0300 |
From: Junyan He <address@hidden>
Guest writes to vNVDIMM labels are intercepted and performed on the
backend by QEMU. When the backend is a real persistent memort, QEMU
needs to take proper operations to ensure its write persistence on the
persistent memory. Otherwise, a host power failure may result in the
loss of guest label configurations.
Signed-off-by: Haozhong Zhang <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Igor Mammedov <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
---
include/qemu/pmem.h | 30 ++++++++++++++++++++++++++++++
hw/mem/nvdimm.c | 9 ++++++++-
2 files changed, 38 insertions(+), 1 deletion(-)
create mode 100644 include/qemu/pmem.h
diff --git a/include/qemu/pmem.h b/include/qemu/pmem.h
new file mode 100644
index 0000000000..ebdb070210
--- /dev/null
+++ b/include/qemu/pmem.h
@@ -0,0 +1,30 @@
+/*
+ * QEMU header file for libpmem.
+ *
+ * Copyright (c) 2018 Intel Corporation.
+ *
+ * Author: Haozhong Zhang <address@hidden>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_PMEM_H
+#define QEMU_PMEM_H
+
+#ifdef CONFIG_LIBPMEM
+#include <libpmem.h>
+#else /* !CONFIG_LIBPMEM */
+
+static inline void *
+pmem_memcpy_persist(void *pmemdest, const void *src, size_t len)
+{
+ /* If 'pmem' option is 'on', we should always have libpmem support,
+ or qemu will report a error and exit, never come here. */
+ g_assert_not_reached();
+ return NULL;
+}
+
+#endif /* CONFIG_LIBPMEM */
+
+#endif /* !QEMU_PMEM_H */
diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index 021d1c3997..1c6674c4ed 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -23,6 +23,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/pmem.h"
#include "qapi/error.h"
#include "qapi/visitor.h"
#include "hw/mem/nvdimm.h"
@@ -164,11 +165,17 @@ static void nvdimm_write_label_data(NVDIMMDevice *nvdimm,
const void *buf,
{
MemoryRegion *mr;
PCDIMMDevice *dimm = PC_DIMM(nvdimm);
+ bool is_pmem = object_property_get_bool(OBJECT(dimm->hostmem),
+ "pmem", NULL);
uint64_t backend_offset;
nvdimm_validate_rw_label_data(nvdimm, size, offset);
- memcpy(nvdimm->label_data + offset, buf, size);
+ if (!is_pmem) {
+ memcpy(nvdimm->label_data + offset, buf, size);
+ } else {
+ pmem_memcpy_persist(nvdimm->label_data + offset, buf, size);
+ }
mr = host_memory_backend_get_memory(dimm->hostmem);
backend_offset = memory_region_size(mr) - nvdimm->label_size + offset;
--
MST
- [Qemu-devel] [PULL 0/7] pc: fixes, Michael S. Tsirkin, 2018/08/20
- [Qemu-devel] [PULL 1/7] memory, exec: Expose all memory block related flags., Michael S. Tsirkin, 2018/08/20
- [Qemu-devel] [PULL 3/7] configure: add libpmem support, Michael S. Tsirkin, 2018/08/20
- [Qemu-devel] [PULL 2/7] memory, exec: switch file ram allocation functions to 'flags' parameters, Michael S. Tsirkin, 2018/08/20
- [Qemu-devel] [PULL 4/7] hostmem-file: add the 'pmem' option, Michael S. Tsirkin, 2018/08/20
[Qemu-devel] [PULL 5/7] mem/nvdimm: ensure write persistence to PMEM in label emulation,
Michael S. Tsirkin <=
[Qemu-devel] [PULL 6/7] migration/ram: Add check and info message to nvdimm post copy., Michael S. Tsirkin, 2018/08/20
[Qemu-devel] [PULL 7/7] migration/ram: ensure write persistence on loading all data to PMEM., Michael S. Tsirkin, 2018/08/20
Re: [Qemu-devel] [PULL 0/7] pc: fixes, Peter Maydell, 2018/08/21