From patchwork Wed Sep 28 18:52:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 9354797 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 DA24D6077B for ; Wed, 28 Sep 2016 18:52:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAFC329789 for ; Wed, 28 Sep 2016 18:52:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC8CF29790; Wed, 28 Sep 2016 18:52:40 +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=-0.0 required=2.0 tests=BAYES_40, 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 C638429789 for ; Wed, 28 Sep 2016 18:52:39 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 624941A1E24; Wed, 28 Sep 2016 11:52:39 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 87CF21A1E24 for ; Wed, 28 Sep 2016 11:52:37 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP; 28 Sep 2016 11:52:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.30,411,1470726000"; d="scan'208"; a="1047099146" Received: from djiang5-desk3.ch.intel.com ([143.182.137.38]) by fmsmga001.fm.intel.com with ESMTP; 28 Sep 2016 11:52:31 -0700 Subject: [PATCH] dev-dax: add support to display badblocks in sysfs for dev-dax From: Dave Jiang To: dan.j.williams@intel.com Date: Wed, 28 Sep 2016 11:52:31 -0700 Message-ID: <147508875131.91583.12624254404354366550.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 Adding support to show badblocks in the pmem region that's provided by the poison_list. This should show up in /sys/class/dax/daxN.N/badblocks as read only. Signed-off-by: Dave Jiang --- drivers/dax/dax.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/dax/dax.c b/drivers/dax/dax.c index 29f600f..c73c494 100644 --- a/drivers/dax/dax.c +++ b/drivers/dax/dax.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include "../nvdimm/nd.h" static int dax_major; static struct class *dax_class; @@ -42,6 +44,7 @@ struct dax_region { unsigned int align; struct resource res; unsigned long pfn_flags; + struct badblocks bb; }; /** @@ -97,6 +100,7 @@ struct dax_region *alloc_dax_region(struct device *parent, int region_id, unsigned long pfn_flags) { struct dax_region *dax_region; + struct nd_region *nd_region = to_nd_region(parent->parent); dax_region = kzalloc(sizeof(*dax_region), GFP_KERNEL); @@ -112,6 +116,10 @@ struct dax_region *alloc_dax_region(struct device *parent, int region_id, dax_region->dev = parent; dax_region->base = addr; + if (devm_init_badblocks(parent, &dax_region->bb)) + return NULL; + nvdimm_badblocks_populate(nd_region, &dax_region->bb, res); + return dax_region; } EXPORT_SYMBOL_GPL(alloc_dax_region); @@ -130,8 +138,20 @@ static ssize_t size_show(struct device *dev, } static DEVICE_ATTR_RO(size); +static ssize_t dax_dev_badblocks_show(struct device *dev, + struct device_attribute *attr, char *page) +{ + struct dax_dev *dax_dev = dev_get_drvdata(dev); + struct dax_region *dax_region = dax_dev->region; + + return badblocks_show(&dax_region->bb, page, 0); +} + +static DEVICE_ATTR(badblocks, S_IRUGO, dax_dev_badblocks_show, NULL); + static struct attribute *dax_device_attributes[] = { &dev_attr_size.attr, + &dev_attr_badblocks.attr, NULL, };