From patchwork Tue Mar 8 22:58:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 8538251 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E406DC0553 for ; Tue, 8 Mar 2016 22:58:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EC0312017D for ; Tue, 8 Mar 2016 22:58:43 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F38C020142 for ; Tue, 8 Mar 2016 22:58:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 605B51A1EC9; Tue, 8 Mar 2016 14:58:56 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ml01.01.org (Postfix) with ESMTP id B3E3A1A1EC9 for ; Tue, 8 Mar 2016 14:58:54 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 08 Mar 2016 14:58:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,558,1449561600"; d="scan'208";a="666100896" Received: from dwillia2-desk3.jf.intel.com ([10.54.39.14]) by FMSMGA003.fm.intel.com with ESMTP; 08 Mar 2016 14:58:40 -0800 Subject: [PATCH] x86, pmem: use memcpy_mcsafe() for memcpy_from_pmem() From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 08 Mar 2016 14:58:14 -0800 Message-ID: <20160308225750.17292.87254.stgit@dwillia2-desk3.jf.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 Cc: Tony Luck , Andrew Morton , Peter Zijlstra , linux-kernel@vger.kernel.org, Andy Lutomirski , Borislav Petkov , Thomas Gleixner , Linus Torvalds , Ingo Molnar X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Update the definition of memcpy_from_pmem() to return 0 or -EIO on error. Implement x86::arch_memcpy_from_pmem() with memcpy_mcsafe(). Cc: Borislav Petkov Cc: Ingo Molnar Cc: Tony Luck Cc: Thomas Gleixner Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Andrew Morton Cc: Ross Zwisler Cc: Linus Torvalds Signed-off-by: Dan Williams --- Note that this patch is built on a merge of tip/ras/core, tip/x86/asm, and nvdimm/for-4.6/acpi6.1 for the following reasons (respectively): 1/ memcpy_mcsafe() itself 2/ X86_FEATURE_MCE_RECOVERY cpu capability 3/ merge with the new 'clear poison' implementation: https://lists.01.org/pipermail/linux-nvdimm/2016-March/004826.html arch/x86/include/asm/pmem.h | 9 +++++++++ drivers/nvdimm/pmem.c | 4 ++-- include/linux/pmem.h | 14 ++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/pmem.h b/arch/x86/include/asm/pmem.h index bf8b35d2035a..4df3820535c6 100644 --- a/arch/x86/include/asm/pmem.h +++ b/arch/x86/include/asm/pmem.h @@ -47,6 +47,15 @@ static inline void arch_memcpy_to_pmem(void __pmem *dst, const void *src, BUG(); } +static inline int arch_memcpy_from_pmem(void *dst, const void __pmem *src, + size_t n) +{ + if (static_cpu_has(X86_FEATURE_MCE_RECOVERY)) + return memcpy_mcsafe(dst, (void __force *) src, n) ? 0 : -EIO; + memcpy(dst, (void __force *) src, n); + return 0; +} + /** * arch_wmb_pmem - synchronize writes to persistent memory * diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index adc387236fe7..2022d08c60ce 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -98,7 +98,7 @@ static int pmem_do_bvec(struct pmem_device *pmem, struct page *page, if (unlikely(bad_pmem)) rc = -EIO; else { - memcpy_from_pmem(mem + off, pmem_addr, len); + rc = memcpy_from_pmem(mem + off, pmem_addr, len); flush_dcache_page(page); } } else { @@ -295,7 +295,7 @@ static int pmem_rw_bytes(struct nd_namespace_common *ndns, if (unlikely(is_bad_pmem(&pmem->bb, offset / 512, sz_align))) return -EIO; - memcpy_from_pmem(buf, pmem->virt_addr + offset, size); + return memcpy_from_pmem(buf, pmem->virt_addr + offset, size); } else { memcpy_to_pmem(pmem->virt_addr + offset, buf, size); wmb_pmem(); diff --git a/include/linux/pmem.h b/include/linux/pmem.h index 3ec5309e29f3..c46c5cf6538e 100644 --- a/include/linux/pmem.h +++ b/include/linux/pmem.h @@ -66,14 +66,16 @@ static inline void arch_invalidate_pmem(void __pmem *addr, size_t size) #endif /* - * Architectures that define ARCH_HAS_PMEM_API must provide - * implementations for arch_memcpy_to_pmem(), arch_wmb_pmem(), - * arch_copy_from_iter_pmem(), arch_clear_pmem(), arch_wb_cache_pmem() - * and arch_has_wmb_pmem(). + * memcpy_from_pmem - read from persistent memory with error handling + * @dst: destination buffer + * @src: source buffer + * + * Returns 0 on success -EIO on failure. */ -static inline void memcpy_from_pmem(void *dst, void __pmem const *src, size_t size) +static inline int memcpy_from_pmem(void *dst, void __pmem const *src, + size_t size) { - memcpy(dst, (void __force const *) src, size); + return arch_memcpy_from_pmem(dst, src, size); } static inline bool arch_has_pmem_api(void)