From patchwork Tue Jul 10 10:30:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: junyan.he@gmx.com X-Patchwork-Id: 10516829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5BCF0603D7 for ; Tue, 10 Jul 2018 10:35:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CA0928D32 for ; Tue, 10 Jul 2018 10:35:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40A5C28D30; Tue, 10 Jul 2018 10:35:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A935628D32 for ; Tue, 10 Jul 2018 10:35:05 +0000 (UTC) Received: from localhost ([::1]:46992 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcpz6-0007Bt-AX for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Jul 2018 06:35:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcpum-0003mz-Lt for qemu-devel@nongnu.org; Tue, 10 Jul 2018 06:30:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcpul-00085W-KH for qemu-devel@nongnu.org; Tue, 10 Jul 2018 06:30:36 -0400 Received: from mga03.intel.com ([134.134.136.65]:54550) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fcpul-0007jf-A8 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 06:30:35 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2018 03:30:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,334,1526367600"; d="scan'208";a="73605352" Received: from natrouter.sh.intel.com (HELO robinhe-hp.domain) ([10.239.13.3]) by orsmga002.jf.intel.com with ESMTP; 10 Jul 2018 03:30:32 -0700 From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2018 18:30:18 +0800 Message-Id: <1531218620-14645-6-git-send-email-junyan.he@gmx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531218620-14645-1-git-send-email-junyan.he@gmx.com> References: <1531218620-14645-1-git-send-email-junyan.he@gmx.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH 5/7 V9] mem/nvdimm: ensure write persistence to PMEM in label emulation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haozhong Zhang , xiaoguangrong.eric@gmail.com, crosthwaite.peter@gmail.com, mst@redhat.com, dgilbert@redhat.com, ehabkost@redhat.com, quintela@redhat.com, Junyan He , stefanha@redhat.com, pbonzini@redhat.com, imammedo@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Junyan He 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 Reviewed-by: Stefan Hajnoczi Reviewed-by: Igor Mammedov --- hw/mem/nvdimm.c | 9 ++++++++- include/qemu/pmem.h | 23 +++++++++++++++++++++++ stubs/Makefile.objs | 1 + stubs/pmem.c | 19 +++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 include/qemu/pmem.h create mode 100644 stubs/pmem.c diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index 021d1c3..1c6674c 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; diff --git a/include/qemu/pmem.h b/include/qemu/pmem.h new file mode 100644 index 0000000..00d6680 --- /dev/null +++ b/include/qemu/pmem.h @@ -0,0 +1,23 @@ +/* + * QEMU header file for libpmem. + * + * Copyright (c) 2018 Intel Corporation. + * + * Author: Haozhong Zhang + * + * 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 +#else /* !CONFIG_LIBPMEM */ + +void *pmem_memcpy_persist(void *pmemdest, const void *src, size_t len); + +#endif /* CONFIG_LIBPMEM */ + +#endif /* !QEMU_PMEM_H */ diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 53d3f32..be9a042 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -43,3 +43,4 @@ stub-obj-y += xen-common.o stub-obj-y += xen-hvm.o stub-obj-y += pci-host-piix.o stub-obj-y += ram-block.o +stub-obj-$(call lnot,$(CONFIG_LIBPMEM)) += pmem.o \ No newline at end of file diff --git a/stubs/pmem.c b/stubs/pmem.c new file mode 100644 index 0000000..b4ec72d --- /dev/null +++ b/stubs/pmem.c @@ -0,0 +1,19 @@ +/* + * Stubs for libpmem. + * + * Copyright (c) 2018 Intel Corporation. + * + * Author: Haozhong Zhang + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include + +#include "qemu/pmem.h" + +void *pmem_memcpy_persist(void *pmemdest, const void *src, size_t len) +{ + return memcpy(pmemdest, src, len); +}