You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
libnvdimm: protect nvdimm_{bus|namespace}_add_poison() with nvdimm_bus_lock()
In preparation for making poison list retrieval asynchronus to region registration, add protection for walking and mutating the bus-level poison list. Cc: Vishal Verma <vishal.l.verma@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
This commit is contained in:
+68
-43
@@ -408,6 +408,48 @@ static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len)
|
|||||||
set_badblock(bb, start_sector, num_sectors);
|
set_badblock(bb, start_sector, num_sectors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void namespace_add_poison(struct list_head *poison_list,
|
||||||
|
struct badblocks *bb, struct resource *res)
|
||||||
|
{
|
||||||
|
struct nd_poison *pl;
|
||||||
|
|
||||||
|
if (list_empty(poison_list))
|
||||||
|
return;
|
||||||
|
|
||||||
|
list_for_each_entry(pl, poison_list, list) {
|
||||||
|
u64 pl_end = pl->start + pl->length - 1;
|
||||||
|
|
||||||
|
/* Discard intervals with no intersection */
|
||||||
|
if (pl_end < res->start)
|
||||||
|
continue;
|
||||||
|
if (pl->start > res->end)
|
||||||
|
continue;
|
||||||
|
/* Deal with any overlap after start of the namespace */
|
||||||
|
if (pl->start >= res->start) {
|
||||||
|
u64 start = pl->start;
|
||||||
|
u64 len;
|
||||||
|
|
||||||
|
if (pl_end <= res->end)
|
||||||
|
len = pl->length;
|
||||||
|
else
|
||||||
|
len = res->start + resource_size(res)
|
||||||
|
- pl->start;
|
||||||
|
__add_badblock_range(bb, start - res->start, len);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* Deal with overlap for poison starting before the namespace */
|
||||||
|
if (pl->start < res->start) {
|
||||||
|
u64 len;
|
||||||
|
|
||||||
|
if (pl_end < res->end)
|
||||||
|
len = pl->start + pl->length - res->start;
|
||||||
|
else
|
||||||
|
len = resource_size(res);
|
||||||
|
__add_badblock_range(bb, 0, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nvdimm_namespace_add_poison() - Convert a list of poison ranges to badblocks
|
* nvdimm_namespace_add_poison() - Convert a list of poison ranges to badblocks
|
||||||
* @ndns: the namespace containing poison ranges
|
* @ndns: the namespace containing poison ranges
|
||||||
@@ -426,53 +468,21 @@ void nvdimm_namespace_add_poison(struct nd_namespace_common *ndns,
|
|||||||
struct nd_region *nd_region = to_nd_region(ndns->dev.parent);
|
struct nd_region *nd_region = to_nd_region(ndns->dev.parent);
|
||||||
struct nvdimm_bus *nvdimm_bus;
|
struct nvdimm_bus *nvdimm_bus;
|
||||||
struct list_head *poison_list;
|
struct list_head *poison_list;
|
||||||
u64 ns_start, ns_end, ns_size;
|
struct resource res = {
|
||||||
struct nd_poison *pl;
|
.start = nsio->res.start + offset,
|
||||||
|
.end = nsio->res.end,
|
||||||
ns_size = nvdimm_namespace_capacity(ndns) - offset;
|
};
|
||||||
ns_start = nsio->res.start + offset;
|
|
||||||
ns_end = nsio->res.end;
|
|
||||||
|
|
||||||
nvdimm_bus = to_nvdimm_bus(nd_region->dev.parent);
|
nvdimm_bus = to_nvdimm_bus(nd_region->dev.parent);
|
||||||
poison_list = &nvdimm_bus->poison_list;
|
poison_list = &nvdimm_bus->poison_list;
|
||||||
if (list_empty(poison_list))
|
|
||||||
return;
|
|
||||||
|
|
||||||
list_for_each_entry(pl, poison_list, list) {
|
nvdimm_bus_lock(&nvdimm_bus->dev);
|
||||||
u64 pl_end = pl->start + pl->length - 1;
|
namespace_add_poison(poison_list, bb, &res);
|
||||||
|
nvdimm_bus_unlock(&nvdimm_bus->dev);
|
||||||
/* Discard intervals with no intersection */
|
|
||||||
if (pl_end < ns_start)
|
|
||||||
continue;
|
|
||||||
if (pl->start > ns_end)
|
|
||||||
continue;
|
|
||||||
/* Deal with any overlap after start of the namespace */
|
|
||||||
if (pl->start >= ns_start) {
|
|
||||||
u64 start = pl->start;
|
|
||||||
u64 len;
|
|
||||||
|
|
||||||
if (pl_end <= ns_end)
|
|
||||||
len = pl->length;
|
|
||||||
else
|
|
||||||
len = ns_start + ns_size - pl->start;
|
|
||||||
__add_badblock_range(bb, start - ns_start, len);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Deal with overlap for poison starting before the namespace */
|
|
||||||
if (pl->start < ns_start) {
|
|
||||||
u64 len;
|
|
||||||
|
|
||||||
if (pl_end < ns_end)
|
|
||||||
len = pl->start + pl->length - ns_start;
|
|
||||||
else
|
|
||||||
len = ns_size;
|
|
||||||
__add_badblock_range(bb, 0, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(nvdimm_namespace_add_poison);
|
EXPORT_SYMBOL_GPL(nvdimm_namespace_add_poison);
|
||||||
|
|
||||||
static int __add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
|
static int add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
|
||||||
{
|
{
|
||||||
struct nd_poison *pl;
|
struct nd_poison *pl;
|
||||||
|
|
||||||
@@ -487,12 +497,12 @@ static int __add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nvdimm_bus_add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
|
static int bus_add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
|
||||||
{
|
{
|
||||||
struct nd_poison *pl;
|
struct nd_poison *pl;
|
||||||
|
|
||||||
if (list_empty(&nvdimm_bus->poison_list))
|
if (list_empty(&nvdimm_bus->poison_list))
|
||||||
return __add_poison(nvdimm_bus, addr, length);
|
return add_poison(nvdimm_bus, addr, length);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There is a chance this is a duplicate, check for those first.
|
* There is a chance this is a duplicate, check for those first.
|
||||||
@@ -512,7 +522,18 @@ int nvdimm_bus_add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
|
|||||||
* as any overlapping ranges will get resolved when the list is consumed
|
* as any overlapping ranges will get resolved when the list is consumed
|
||||||
* and converted to badblocks
|
* and converted to badblocks
|
||||||
*/
|
*/
|
||||||
return __add_poison(nvdimm_bus, addr, length);
|
return add_poison(nvdimm_bus, addr, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
int nvdimm_bus_add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
nvdimm_bus_lock(&nvdimm_bus->dev);
|
||||||
|
rc = bus_add_poison(nvdimm_bus, addr, length);
|
||||||
|
nvdimm_bus_unlock(&nvdimm_bus->dev);
|
||||||
|
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(nvdimm_bus_add_poison);
|
EXPORT_SYMBOL_GPL(nvdimm_bus_add_poison);
|
||||||
|
|
||||||
@@ -553,7 +574,11 @@ void nvdimm_bus_unregister(struct nvdimm_bus *nvdimm_bus)
|
|||||||
|
|
||||||
nd_synchronize();
|
nd_synchronize();
|
||||||
device_for_each_child(&nvdimm_bus->dev, NULL, child_unregister);
|
device_for_each_child(&nvdimm_bus->dev, NULL, child_unregister);
|
||||||
|
|
||||||
|
nvdimm_bus_lock(&nvdimm_bus->dev);
|
||||||
free_poison_list(&nvdimm_bus->poison_list);
|
free_poison_list(&nvdimm_bus->poison_list);
|
||||||
|
nvdimm_bus_unlock(&nvdimm_bus->dev);
|
||||||
|
|
||||||
nvdimm_bus_destroy_ndctl(nvdimm_bus);
|
nvdimm_bus_destroy_ndctl(nvdimm_bus);
|
||||||
|
|
||||||
device_unregister(&nvdimm_bus->dev);
|
device_unregister(&nvdimm_bus->dev);
|
||||||
|
|||||||
Reference in New Issue
Block a user