From patchwork Tue Nov 15 00:21:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 9428691 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 2AFD060471 for ; Tue, 15 Nov 2016 00:22:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A2352880A for ; Tue, 15 Nov 2016 00:22:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C67128AF2; Tue, 15 Nov 2016 00:22:14 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id AF5F32880A for ; Tue, 15 Nov 2016 00:22:13 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7B42A81E31; Mon, 14 Nov 2016 16:22:08 -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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EC48881E30 for ; Mon, 14 Nov 2016 16:22:06 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 14 Nov 2016 16:22:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,640,1473145200"; d="scan'208";a="786427314" Received: from djiang5-desk3.ch.intel.com ([143.182.137.38]) by FMSMGA003.fm.intel.com with ESMTP; 14 Nov 2016 16:21:48 -0800 Subject: [PATCH] libnvdimm: clear poison in mem map metadata From: Dave Jiang To: dan.j.williams@intel.com Date: Mon, 14 Nov 2016 17:21:48 -0700 Message-ID: <147916930808.236748.8215175004635279925.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Clearing out the poison in the metadata block of the namespace before we use it. Range from start + 8k to pfn_sb->dataoff. Signed-off-by: Dave Jiang --- drivers/nvdimm/pfn_devs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index cea8350..ff3b55d 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -527,11 +527,35 @@ static struct vmem_altmap *__nvdimm_setup_pfn(struct nd_pfn *nd_pfn, .base_pfn = init_altmap_base(base), .reserve = init_altmap_reserve(base), }; + sector_t sector; + resource_size_t meta_start, meta_size; + long cleared; + unsigned int sz_align; memcpy(res, &nsio->res, sizeof(*res)); res->start += start_pad; res->end -= end_trunc; + meta_start = res->start + SZ_8K; + meta_size = offset - meta_start + 1; + + if (meta_start + meta_size > offset) + return ERR_PTR(-EINVAL); + + sector = meta_start >> 9; + sz_align = ALIGN(meta_size + (meta_start & (512 - 1)), 512); + + if (unlikely(is_bad_pmem(&nsio->bb, sector, sz_align))) { + if (IS_ALIGNED(meta_start, 512) && IS_ALIGNED(meta_size, 512)) { + cleared = nvdimm_clear_poison(&nd_pfn->dev, + meta_start, meta_size); + badblocks_clear(&nsio->bb, sector, cleared >> 9); + if (cleared != meta_size) + return ERR_PTR(-EIO); + } else + return ERR_PTR(-EIO); + } + if (nd_pfn->mode == PFN_MODE_RAM) { if (offset < SZ_8K) return ERR_PTR(-EINVAL);