diff mbox

dev-dax: add support to display badblocks in sysfs for dev-dax

Message ID 147508875131.91583.12624254404354366550.stgit@djiang5-desk3.ch.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dave Jiang Sept. 28, 2016, 6:52 p.m. UTC
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 <dave.jiang@intel.com>
---
 drivers/dax/dax.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Verma, Vishal L Sept. 28, 2016, 6:57 p.m. UTC | #1
On Wed, 2016-09-28 at 11:52 -0700, Dave Jiang wrote:
> 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.


I think we can allow error injection by making this read/write. See
badblocks_store and how it is used in disk_badblocks_store, and that
will allow badblock injection for testing/debug purposes.

> 

> Signed-off-by: Dave Jiang <dave.jiang@intel.com>

> ---

>  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 <linux/dax.h>

>  #include <linux/fs.h>

>  #include <linux/mm.h>

> +#include <linux/badblocks.h>

> +#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,

>  };

>  

> 

> _______________________________________________

> Linux-nvdimm mailing list

> Linux-nvdimm@lists.01.org

> https://lists.01.org/mailman/listinfo/linux-nvdimm
Dan Williams Sept. 28, 2016, 8:50 p.m. UTC | #2
On Wed, Sep 28, 2016 at 11:52 AM, Dave Jiang <dave.jiang@intel.com> wrote:
> 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 <dave.jiang@intel.com>
> ---
>  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 <linux/dax.h>
>  #include <linux/fs.h>
>  #include <linux/mm.h>
> +#include <linux/badblocks.h>
> +#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);

This will show the badblocks for the entire region...

> +}
> +
> +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,

...but we want it to be limited per-device.

So the errors in the region need to be reconciled into the individual
resources that get assigned to the device instance.  This becomes more
important when we allow carving a dax region into multiple devices.

devm_create_dax_dev() takes a lists of resources that make up the
given instance.  Those may be discontiguous and the per-device
badblocks instance would need to account for that.
diff mbox

Patch

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 <linux/dax.h>
 #include <linux/fs.h>
 #include <linux/mm.h>
+#include <linux/badblocks.h>
+#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,
 };