From patchwork Wed Jan 6 07:23:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 7965121 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 416FF9F1CC for ; Wed, 6 Jan 2016 07:23:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 443F5201EC for ; Wed, 6 Jan 2016 07:23:57 +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 42938201E4 for ; Wed, 6 Jan 2016 07:23:56 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 341A01A1EE5; Tue, 5 Jan 2016 23:23:56 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ml01.01.org (Postfix) with ESMTP id A45AF1A2480 for ; Tue, 5 Jan 2016 23:23:55 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 05 Jan 2016 23:23:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,528,1444719600"; d="scan'208";a="887245221" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.136]) by fmsmga002.fm.intel.com with ESMTP; 05 Jan 2016 23:23:55 -0800 Subject: [PATCH 8/9] libnvdimm, pmem: nvdimm_read_bytes() badblocks support From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 05 Jan 2016 23:23:29 -0800 Message-ID: <20160106072329.40900.41876.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: linux-block@vger.kernel.org, x86@kernel.org 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 Support badblock checking in all the pmem read paths that do not go through the block layer. This protects info block reads (btt or pfn) as well as data reads to a pmem namespace via a btt instance. Signed-off-by: Dan Williams --- drivers/nvdimm/btt.c | 11 +++++++++++ drivers/nvdimm/btt_devs.c | 10 ++++++++++ drivers/nvdimm/pfn_devs.c | 10 ++++++++++ drivers/nvdimm/pmem.c | 9 +++++++-- drivers/nvdimm/region_devs.c | 6 ++++++ include/linux/nd.h | 2 ++ 6 files changed, 46 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c index efb2c1ceef98..0aca7d7edc05 100644 --- a/drivers/nvdimm/btt.c +++ b/drivers/nvdimm/btt.c @@ -1388,6 +1388,7 @@ int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns) { struct nd_btt *nd_btt = to_nd_btt(ndns->claim); struct nd_region *nd_region; + struct badblocks *bb; struct btt *btt; size_t rawsize; @@ -1398,6 +1399,16 @@ int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns) if (rawsize < ARENA_MIN_SIZE) { return -ENXIO; } + + bb = nvdimm_namespace_badblocks(ndns, 0); + if (IS_ERR(bb)) { + if (PTR_ERR(bb) == -ENOENT) + bb = NULL; + else + return PTR_ERR(bb); + } + + ndns->bb = bb; nd_region = to_nd_region(nd_btt->dev.parent); btt = btt_init(nd_btt, rawsize, nd_btt->lbasize, nd_btt->uuid, nd_region); diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c index cb477518dd0e..8257a72b7bfc 100644 --- a/drivers/nvdimm/btt_devs.c +++ b/drivers/nvdimm/btt_devs.c @@ -277,12 +277,22 @@ int nd_btt_probe(struct nd_namespace_common *ndns, void *drvdata) { int rc; struct device *dev; + struct badblocks *bb; struct btt_sb *btt_sb; struct nd_region *nd_region = to_nd_region(ndns->dev.parent); if (ndns->force_raw) return -ENODEV; + bb = nvdimm_namespace_badblocks(ndns, 0); + if (IS_ERR(bb)) { + if (PTR_ERR(bb) == -ENOENT) + bb = NULL; + else + return PTR_ERR(bb); + } + + ndns->bb = bb; nvdimm_bus_lock(&ndns->dev); dev = __nd_btt_create(nd_region, 0, NULL, ndns); nvdimm_bus_unlock(&ndns->dev); diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index 71805a1aa0f3..f154119f1b31 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -305,6 +305,7 @@ int nd_pfn_probe(struct nd_namespace_common *ndns, void *drvdata) { int rc; struct device *dev; + struct badblocks *bb; struct nd_pfn *nd_pfn; struct nd_pfn_sb *pfn_sb; struct nd_region *nd_region = to_nd_region(ndns->dev.parent); @@ -312,6 +313,15 @@ int nd_pfn_probe(struct nd_namespace_common *ndns, void *drvdata) if (ndns->force_raw) return -ENODEV; + bb = nvdimm_namespace_badblocks(ndns, 0); + if (IS_ERR(bb)) { + if (PTR_ERR(bb) == -ENOENT) + bb = NULL; + else + return PTR_ERR(bb); + } + + ndns->bb = bb; nvdimm_bus_lock(&ndns->dev); dev = __nd_pfn_create(nd_region, NULL, PFN_MODE_NONE, ndns); nvdimm_bus_unlock(&ndns->dev); diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 0d1f307175b2..bcd5e777f66d 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -249,9 +249,14 @@ static int pmem_rw_bytes(struct nd_namespace_common *ndns, return -EFAULT; } - if (rw == READ) + if (rw == READ) { + unsigned int sz_align = ALIGN(size + (offset & (512 - 1)), 512); + + if (unlikely(is_bad_pmem(ndns->bb, offset / 512, + sz_align))) + return -EIO; rc = memcpy_from_pmem(buf, pmem->virt_addr + offset, size); - else { + } else { memcpy_to_pmem(pmem->virt_addr + offset, buf, size); wmb_pmem(); } diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index 529f3f02e7b2..20e5352a6461 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -468,6 +468,12 @@ static void nd_region_notify_driver_action(struct nvdimm_bus *nvdimm_bus, to_nd_blk_region(dev)->disable(nvdimm_bus, dev); } + if (dev->parent && is_nd_pmem(dev->parent) && !probe) { + struct nd_namespace_common *ndns = to_ndns(dev); + + /* badblocks list is only valid between ->probe and ->remove */ + ndns->bb = NULL; + } if (dev->parent && is_nd_blk(dev->parent) && probe) { nd_region = to_nd_region(dev->parent); nvdimm_bus_lock(dev); diff --git a/include/linux/nd.h b/include/linux/nd.h index 507e47c86737..afe487433b71 100644 --- a/include/linux/nd.h +++ b/include/linux/nd.h @@ -34,12 +34,14 @@ static inline struct nd_device_driver *to_nd_device_driver( * @force_raw: ignore other personalities for the namespace (e.g. btt) * @dev: device model node * @claim: when set a another personality has taken ownership of the namespace + * @bb: badblocks list only valid while namespace is active * @rw_bytes: access the raw namespace capacity with byte-aligned transfers */ struct nd_namespace_common { int force_raw; struct device dev; struct device *claim; + struct badblocks *bb; int (*rw_bytes)(struct nd_namespace_common *, resource_size_t offset, void *buf, size_t size, int rw); };