From patchwork Wed Jan 6 07:23:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 7965071 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 57DDA9F1CC for ; Wed, 6 Jan 2016 07:23:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 56A7C201E4 for ; Wed, 6 Jan 2016 07:23:42 +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 0620D201DD for ; Wed, 6 Jan 2016 07:23:41 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EE3831A2476; Tue, 5 Jan 2016 23:23:40 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by ml01.01.org (Postfix) with ESMTP id CEC351A2476 for ; Tue, 5 Jan 2016 23:23:39 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP; 05 Jan 2016 23:23:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,528,1444719600"; d="scan'208";a="628753656" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.136]) by FMSMGA003.fm.intel.com with ESMTP; 05 Jan 2016 23:23:38 -0800 Subject: [PATCH 5/9] x86, pmem: use __mcsafe_copy() for memcpy_from_pmem() From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 05 Jan 2016 23:23:13 -0800 Message-ID: <20160106072313.40900.12731.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20160106072246.40900.8851.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20160106072246.40900.8851.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 Cc: Tony Luck , x86@kernel.org, Andy Lutomirski , linux-block@vger.kernel.org, Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov 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 In support of large capacity persistent memory use __mcsafe_copy() for pmem I/O. This allows the pmem driver to support an error model similar to disks when machine check recovery is available. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: Borislav Petkov Cc: Tony Luck Cc: Andy Lutomirski Signed-off-by: Dan Williams --- arch/x86/include/asm/pmem.h | 16 ++++++++++++++++ drivers/nvdimm/Kconfig | 1 + drivers/nvdimm/pmem.c | 10 ++++++---- include/linux/pmem.h | 17 +++++++++++++---- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/pmem.h b/arch/x86/include/asm/pmem.h index d8ce3ec816ab..4ef301e78a2b 100644 --- a/arch/x86/include/asm/pmem.h +++ b/arch/x86/include/asm/pmem.h @@ -17,6 +17,7 @@ #include #include #include +#include #ifdef CONFIG_ARCH_HAS_PMEM_API /** @@ -47,6 +48,21 @@ 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 (IS_ENABLED(CONFIG_MCE_KERNEL_RECOVERY)) { + struct mcsafe_ret ret; + + ret = __mcsafe_copy(dst, (void __force *) src, n); + if (ret.remain) + return -EIO; + return 0; + } + memcpy(dst, (void __force *) src, n); + return 0; +} + /** * arch_wmb_pmem - synchronize writes to persistent memory * diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig index 53c11621d5b1..fe5885d01fd8 100644 --- a/drivers/nvdimm/Kconfig +++ b/drivers/nvdimm/Kconfig @@ -22,6 +22,7 @@ config BLK_DEV_PMEM depends on HAS_IOMEM select ND_BTT if BTT select ND_PFN if NVDIMM_PFN + select MCE_KERNEL_RECOVERY if X86_MCE && X86_64 help Memory ranges for PMEM are described by either an NFIT (NVDIMM Firmware Interface Table, see CONFIG_NFIT_ACPI), a diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 8744235b5be2..d8e14e962327 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -62,6 +62,7 @@ static bool is_bad_pmem(struct badblocks *bb, sector_t sector, unsigned int len) static int pmem_do_bvec(struct block_device *bdev, struct page *page, unsigned int len, unsigned int off, int rw, sector_t sector) { + int rc = 0; void *mem = kmap_atomic(page); struct gendisk *disk = bdev->bd_disk; struct pmem_device *pmem = disk->private_data; @@ -71,7 +72,7 @@ static int pmem_do_bvec(struct block_device *bdev, struct page *page, if (rw == READ) { if (unlikely(is_bad_pmem(disk->bb, sector, len))) return -EIO; - memcpy_from_pmem(mem + off, pmem_addr, len); + rc = memcpy_from_pmem(mem + off, pmem_addr, len); flush_dcache_page(page); } else { flush_dcache_page(page); @@ -79,7 +80,7 @@ static int pmem_do_bvec(struct block_device *bdev, struct page *page, } kunmap_atomic(mem); - return 0; + return rc; } static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio) @@ -237,6 +238,7 @@ static int pmem_rw_bytes(struct nd_namespace_common *ndns, resource_size_t offset, void *buf, size_t size, int rw) { struct pmem_device *pmem = dev_get_drvdata(ndns->claim); + int rc = 0; if (unlikely(offset + size > pmem->size)) { dev_WARN_ONCE(&ndns->dev, 1, "request out of range\n"); @@ -244,13 +246,13 @@ static int pmem_rw_bytes(struct nd_namespace_common *ndns, } if (rw == READ) - memcpy_from_pmem(buf, pmem->virt_addr + offset, size); + rc = memcpy_from_pmem(buf, pmem->virt_addr + offset, size); else { memcpy_to_pmem(pmem->virt_addr + offset, buf, size); wmb_pmem(); } - return 0; + return rc; } static int nd_pfn_init(struct nd_pfn *nd_pfn) diff --git a/include/linux/pmem.h b/include/linux/pmem.h index acfea8ce4a07..0e57a5beab21 100644 --- a/include/linux/pmem.h +++ b/include/linux/pmem.h @@ -42,6 +42,13 @@ 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) +{ + BUG(); + return 0; +} + static inline size_t arch_copy_from_iter_pmem(void __pmem *addr, size_t bytes, struct iov_iter *i) { @@ -57,12 +64,14 @@ static inline void arch_clear_pmem(void __pmem *addr, size_t size) /* * 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() and arch_has_wmb_pmem(). + * implementations for arch_memcpy_to_pmem(), arch_memcpy_from_pmem(), + * arch_wmb_pmem(), arch_copy_from_iter_pmem(), arch_clear_pmem() and + * arch_has_wmb_pmem(). */ -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)