summaryrefslogtreecommitdiff
path: root/drivers/nvdimm
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2016-01-04 23:50:23 -0800
committerDan Williams <dan.j.williams@intel.com>2016-01-09 08:39:04 -0800
commitb95f5f4391fad65f1819c2404080b05ca95bdd92 (patch)
tree677c1af2ab624785340dc655b3414a21dc51a930 /drivers/nvdimm
parent87ba05dff3510f9e058b35d3c3fa222b6f406ecc (diff)
libnvdimm: convert to statically allocated badblocks
If a device will ever have badblocks it should always have a badblocks instance available. So, similar to md, embed a badblocks instance in pmem_device. This reduces pointer chasing in the i/o fast path, and simplifies the init path. Reported-by: Vishal Verma <vishal.l.verma@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers/nvdimm')
-rw-r--r--drivers/nvdimm/core.c57
-rw-r--r--drivers/nvdimm/nd.h4
-rw-r--r--drivers/nvdimm/pmem.c10
3 files changed, 24 insertions, 47 deletions
diff --git a/drivers/nvdimm/core.c b/drivers/nvdimm/core.c
index e419d661e294..2e2832b83c93 100644
--- a/drivers/nvdimm/core.c
+++ b/drivers/nvdimm/core.c
@@ -11,6 +11,7 @@
* General Public License for more details.
*/
#include <linux/libnvdimm.h>
+#include <linux/badblocks.h>
#include <linux/export.h>
#include <linux/module.h>
#include <linux/blkdev.h>
@@ -360,21 +361,19 @@ struct nvdimm_bus *__nvdimm_bus_register(struct device *parent,
}
EXPORT_SYMBOL_GPL(__nvdimm_bus_register);
-static void set_badblock(struct gendisk *disk, sector_t s, int num)
+static void set_badblock(struct badblocks *bb, sector_t s, int num)
{
- struct device *dev = disk->driverfs_dev;
-
- dev_dbg(dev, "Found a poison range (0x%llx, 0x%llx)\n",
+ dev_dbg(bb->dev, "Found a poison range (0x%llx, 0x%llx)\n",
(u64) s * 512, (u64) num * 512);
/* this isn't an error as the hardware will still throw an exception */
- if (disk_set_badblocks(disk, s, num))
- dev_info_once(dev, "%s: failed for sector %llx\n",
+ if (badblocks_set(bb, s, num, 1))
+ dev_info_once(bb->dev, "%s: failed for sector %llx\n",
__func__, (u64) s);
}
/**
* __add_badblock_range() - Convert a physical address range to bad sectors
- * @disk: the disk associated with the namespace
+ * @bb: badblocks instance to populate
* @ns_offset: namespace offset where the error range begins (in bytes)
* @len: number of bytes of poison to be added
*
@@ -382,25 +381,18 @@ static void set_badblock(struct gendisk *disk, sector_t s, int num)
* the bounds of physical addresses for this namespace, i.e. lies in the
* interval [ns_start, ns_start + ns_size)
*/
-static int __add_badblock_range(struct gendisk *disk, u64 ns_offset, u64 len)
+static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len)
{
- unsigned int sector_size = queue_logical_block_size(disk->queue);
+ const unsigned int sector_size = 512;
sector_t start_sector;
u64 num_sectors;
u32 rem;
- int rc;
start_sector = div_u64(ns_offset, sector_size);
num_sectors = div_u64_rem(len, sector_size, &rem);
if (rem)
num_sectors++;
- if (!disk->bb) {
- rc = disk_alloc_badblocks(disk);
- if (rc)
- return rc;
- }
-
if (unlikely(num_sectors > (u64)INT_MAX)) {
u64 remaining = num_sectors;
sector_t s = start_sector;
@@ -408,33 +400,27 @@ static int __add_badblock_range(struct gendisk *disk, u64 ns_offset, u64 len)
while (remaining) {
int done = min_t(u64, remaining, INT_MAX);
- set_badblock(disk, s, done);
+ set_badblock(bb, s, done);
remaining -= done;
s += done;
}
} else
- set_badblock(disk, start_sector, num_sectors);
-
- return 0;
+ set_badblock(bb, start_sector, num_sectors);
}
/**
* nvdimm_namespace_add_poison() - Convert a list of poison ranges to badblocks
- * @disk: the gendisk associated with the namespace where badblocks
- * will be stored
- * @offset: offset at the start of the namespace before 'sector 0'
* @ndns: the namespace containing poison ranges
+ * @bb: badblocks instance to populate
+ * @offset: offset at the start of the namespace before 'sector 0'
*
* The poison list generated during NFIT initialization may contain multiple,
* possibly overlapping ranges in the SPA (System Physical Address) space.
* Compare each of these ranges to the namespace currently being initialized,
* and add badblocks to the gendisk for all matching sub-ranges
- *
- * Return:
- * 0 - Success
*/
-int nvdimm_namespace_add_poison(struct gendisk *disk, resource_size_t offset,
- struct nd_namespace_common *ndns)
+void nvdimm_namespace_add_poison(struct nd_namespace_common *ndns,
+ struct badblocks *bb, resource_size_t offset)
{
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
struct nd_region *nd_region = to_nd_region(ndns->dev.parent);
@@ -442,7 +428,6 @@ int nvdimm_namespace_add_poison(struct gendisk *disk, resource_size_t offset,
struct list_head *poison_list;
u64 ns_start, ns_end, ns_size;
struct nd_poison *pl;
- int rc;
ns_size = nvdimm_namespace_capacity(ndns) - offset;
ns_start = nsio->res.start + offset;
@@ -451,7 +436,7 @@ int nvdimm_namespace_add_poison(struct gendisk *disk, resource_size_t offset,
nvdimm_bus = to_nvdimm_bus(nd_region->dev.parent);
poison_list = &nvdimm_bus->poison_list;
if (list_empty(poison_list))
- return 0;
+ return;
list_for_each_entry(pl, poison_list, list) {
u64 pl_end = pl->start + pl->length - 1;
@@ -470,10 +455,7 @@ int nvdimm_namespace_add_poison(struct gendisk *disk, resource_size_t offset,
len = pl->length;
else
len = ns_start + ns_size - pl->start;
-
- rc = __add_badblock_range(disk, start - ns_start, len);
- if (rc)
- return rc;
+ __add_badblock_range(bb, start - ns_start, len);
continue;
}
/* Deal with overlap for poison starting before the namespace */
@@ -484,14 +466,9 @@ int nvdimm_namespace_add_poison(struct gendisk *disk, resource_size_t offset,
len = pl->start + pl->length - ns_start;
else
len = ns_size;
-
- rc = __add_badblock_range(disk, 0, len);
- if (rc)
- return rc;
+ __add_badblock_range(bb, 0, len);
}
}
-
- return 0;
}
EXPORT_SYMBOL_GPL(nvdimm_namespace_add_poison);
diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h
index 198933da83e5..288d96ec7233 100644
--- a/drivers/nvdimm/nd.h
+++ b/drivers/nvdimm/nd.h
@@ -268,8 +268,8 @@ int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns);
int nvdimm_namespace_detach_btt(struct nd_namespace_common *ndns);
const char *nvdimm_namespace_disk_name(struct nd_namespace_common *ndns,
char *name);
-int nvdimm_namespace_add_poison(struct gendisk *disk, resource_size_t offset,
- struct nd_namespace_common *ndns);
+void nvdimm_namespace_add_poison(struct nd_namespace_common *ndns,
+ struct badblocks *bb, resource_size_t offset);
int nd_blk_region_init(struct nd_region *nd_region);
void __nd_iostat_start(struct bio *bio, unsigned long *start);
static inline bool nd_iostat_start(struct bio *bio, unsigned long *start)
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 65b2056e7540..2b1f3009f827 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -23,6 +23,7 @@
#include <linux/module.h>
#include <linux/memory_hotplug.h>
#include <linux/moduleparam.h>
+#include <linux/badblocks.h>
#include <linux/vmalloc.h>
#include <linux/slab.h>
#include <linux/pmem.h>
@@ -41,6 +42,7 @@ struct pmem_device {
phys_addr_t data_offset;
void __pmem *virt_addr;
size_t size;
+ struct badblocks bb;
};
static int pmem_major;
@@ -168,7 +170,6 @@ static int pmem_attach_disk(struct device *dev,
{
int nid = dev_to_node(dev);
struct gendisk *disk;
- int ret;
pmem->pmem_queue = blk_alloc_queue_node(GFP_KERNEL, nid);
if (!pmem->pmem_queue)
@@ -196,10 +197,9 @@ static int pmem_attach_disk(struct device *dev,
disk->driverfs_dev = dev;
set_capacity(disk, (pmem->size - pmem->data_offset) / 512);
pmem->pmem_disk = disk;
-
- ret = nvdimm_namespace_add_poison(disk, pmem->data_offset, ndns);
- if (ret)
- return ret;
+ if (devm_init_badblocks(dev, &pmem->bb))
+ return -ENOMEM;
+ nvdimm_namespace_add_poison(ndns, &pmem->bb, pmem->data_offset);
add_disk(disk);
revalidate_disk(disk);