Merge miscellaneous libnvdimm updates for 4.21
* Use common helpers, bitmap_zalloc() and kstrndup(), to replace open coded versions. * Clarify the comments around hotplug vs initial init case for the nfit driver. * Cleanup the libnvdimm init path.
这个提交包含在:
@@ -350,12 +350,12 @@ struct nvdimm_bus *nvdimm_bus_register(struct device *parent,
|
||||
INIT_LIST_HEAD(&nvdimm_bus->mapping_list);
|
||||
init_waitqueue_head(&nvdimm_bus->probe_wait);
|
||||
nvdimm_bus->id = ida_simple_get(&nd_ida, 0, 0, GFP_KERNEL);
|
||||
mutex_init(&nvdimm_bus->reconfig_mutex);
|
||||
badrange_init(&nvdimm_bus->badrange);
|
||||
if (nvdimm_bus->id < 0) {
|
||||
kfree(nvdimm_bus);
|
||||
return NULL;
|
||||
}
|
||||
mutex_init(&nvdimm_bus->reconfig_mutex);
|
||||
badrange_init(&nvdimm_bus->badrange);
|
||||
nvdimm_bus->nd_desc = nd_desc;
|
||||
nvdimm_bus->dev.parent = parent;
|
||||
nvdimm_bus->dev.release = nvdimm_bus_release;
|
||||
|
@@ -944,8 +944,7 @@ static int __blk_label_update(struct nd_region *nd_region,
|
||||
victims = 0;
|
||||
if (old_num_resources) {
|
||||
/* convert old local-label-map to dimm-slot victim-map */
|
||||
victim_map = kcalloc(BITS_TO_LONGS(nslot), sizeof(long),
|
||||
GFP_KERNEL);
|
||||
victim_map = bitmap_zalloc(nslot, GFP_KERNEL);
|
||||
if (!victim_map)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -968,7 +967,7 @@ static int __blk_label_update(struct nd_region *nd_region,
|
||||
/* don't allow updates that consume the last label */
|
||||
if (nfree - alloc < 0 || nfree - alloc + victims < 1) {
|
||||
dev_info(&nsblk->common.dev, "insufficient label space\n");
|
||||
kfree(victim_map);
|
||||
bitmap_free(victim_map);
|
||||
return -ENOSPC;
|
||||
}
|
||||
/* from here on we need to abort on error */
|
||||
@@ -1140,7 +1139,7 @@ static int __blk_label_update(struct nd_region *nd_region,
|
||||
|
||||
out:
|
||||
kfree(old_res_list);
|
||||
kfree(victim_map);
|
||||
bitmap_free(victim_map);
|
||||
return rc;
|
||||
|
||||
abort:
|
||||
|
@@ -270,11 +270,10 @@ static ssize_t __alt_name_store(struct device *dev, const char *buf,
|
||||
if (dev->driver || to_ndns(dev)->claim)
|
||||
return -EBUSY;
|
||||
|
||||
input = kmemdup(buf, len + 1, GFP_KERNEL);
|
||||
input = kstrndup(buf, len, GFP_KERNEL);
|
||||
if (!input)
|
||||
return -ENOMEM;
|
||||
|
||||
input[len] = '\0';
|
||||
pos = strim(input);
|
||||
if (strlen(pos) + 1 > NSLABEL_NAME_LEN) {
|
||||
rc = -EINVAL;
|
||||
|
@@ -168,6 +168,8 @@ resource_size_t nd_pmem_available_dpa(struct nd_region *nd_region,
|
||||
struct nd_mapping *nd_mapping, resource_size_t *overlap);
|
||||
resource_size_t nd_blk_available_dpa(struct nd_region *nd_region);
|
||||
resource_size_t nd_region_available_dpa(struct nd_region *nd_region);
|
||||
int nd_region_conflict(struct nd_region *nd_region, resource_size_t start,
|
||||
resource_size_t size);
|
||||
resource_size_t nvdimm_allocated_dpa(struct nvdimm_drvdata *ndd,
|
||||
struct nd_label_id *label_id);
|
||||
int alias_dpa_busy(struct device *dev, void *data);
|
||||
|
@@ -649,14 +649,47 @@ static u64 phys_pmem_align_down(struct nd_pfn *nd_pfn, u64 phys)
|
||||
ALIGN_DOWN(phys, nd_pfn->align));
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if pmem collides with 'System RAM', or other regions when
|
||||
* section aligned. Trim it accordingly.
|
||||
*/
|
||||
static void trim_pfn_device(struct nd_pfn *nd_pfn, u32 *start_pad, u32 *end_trunc)
|
||||
{
|
||||
struct nd_namespace_common *ndns = nd_pfn->ndns;
|
||||
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
|
||||
struct nd_region *nd_region = to_nd_region(nd_pfn->dev.parent);
|
||||
const resource_size_t start = nsio->res.start;
|
||||
const resource_size_t end = start + resource_size(&nsio->res);
|
||||
resource_size_t adjust, size;
|
||||
|
||||
*start_pad = 0;
|
||||
*end_trunc = 0;
|
||||
|
||||
adjust = start - PHYS_SECTION_ALIGN_DOWN(start);
|
||||
size = resource_size(&nsio->res) + adjust;
|
||||
if (region_intersects(start - adjust, size, IORESOURCE_SYSTEM_RAM,
|
||||
IORES_DESC_NONE) == REGION_MIXED
|
||||
|| nd_region_conflict(nd_region, start - adjust, size))
|
||||
*start_pad = PHYS_SECTION_ALIGN_UP(start) - start;
|
||||
|
||||
/* Now check that end of the range does not collide. */
|
||||
adjust = PHYS_SECTION_ALIGN_UP(end) - end;
|
||||
size = resource_size(&nsio->res) + adjust;
|
||||
if (region_intersects(start, size, IORESOURCE_SYSTEM_RAM,
|
||||
IORES_DESC_NONE) == REGION_MIXED
|
||||
|| !IS_ALIGNED(end, nd_pfn->align)
|
||||
|| nd_region_conflict(nd_region, start, size + adjust))
|
||||
*end_trunc = end - phys_pmem_align_down(nd_pfn, end);
|
||||
}
|
||||
|
||||
static int nd_pfn_init(struct nd_pfn *nd_pfn)
|
||||
{
|
||||
u32 dax_label_reserve = is_nd_dax(&nd_pfn->dev) ? SZ_128K : 0;
|
||||
struct nd_namespace_common *ndns = nd_pfn->ndns;
|
||||
u32 start_pad = 0, end_trunc = 0;
|
||||
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
|
||||
resource_size_t start, size;
|
||||
struct nd_namespace_io *nsio;
|
||||
struct nd_region *nd_region;
|
||||
u32 start_pad, end_trunc;
|
||||
struct nd_pfn_sb *pfn_sb;
|
||||
unsigned long npfns;
|
||||
phys_addr_t offset;
|
||||
@@ -688,30 +721,7 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
|
||||
|
||||
memset(pfn_sb, 0, sizeof(*pfn_sb));
|
||||
|
||||
/*
|
||||
* Check if pmem collides with 'System RAM' when section aligned and
|
||||
* trim it accordingly
|
||||
*/
|
||||
nsio = to_nd_namespace_io(&ndns->dev);
|
||||
start = PHYS_SECTION_ALIGN_DOWN(nsio->res.start);
|
||||
size = resource_size(&nsio->res);
|
||||
if (region_intersects(start, size, IORESOURCE_SYSTEM_RAM,
|
||||
IORES_DESC_NONE) == REGION_MIXED) {
|
||||
start = nsio->res.start;
|
||||
start_pad = PHYS_SECTION_ALIGN_UP(start) - start;
|
||||
}
|
||||
|
||||
start = nsio->res.start;
|
||||
size = PHYS_SECTION_ALIGN_UP(start + size) - start;
|
||||
if (region_intersects(start, size, IORESOURCE_SYSTEM_RAM,
|
||||
IORES_DESC_NONE) == REGION_MIXED
|
||||
|| !IS_ALIGNED(start + resource_size(&nsio->res),
|
||||
nd_pfn->align)) {
|
||||
size = resource_size(&nsio->res);
|
||||
end_trunc = start + size - phys_pmem_align_down(nd_pfn,
|
||||
start + size);
|
||||
}
|
||||
|
||||
trim_pfn_device(nd_pfn, &start_pad, &end_trunc);
|
||||
if (start_pad + end_trunc)
|
||||
dev_info(&nd_pfn->dev, "%s alignment collision, truncate %d bytes\n",
|
||||
dev_name(&ndns->dev), start_pad + end_trunc);
|
||||
@@ -722,7 +732,7 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
|
||||
* implementation will limit the pfns advertised through
|
||||
* ->direct_access() to those that are included in the memmap.
|
||||
*/
|
||||
start += start_pad;
|
||||
start = nsio->res.start + start_pad;
|
||||
size = resource_size(&nsio->res);
|
||||
npfns = PFN_SECTION_ALIGN_UP((size - start_pad - end_trunc - SZ_8K)
|
||||
/ PAGE_SIZE);
|
||||
|
@@ -1189,6 +1189,47 @@ int nvdimm_has_cache(struct nd_region *nd_region)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(nvdimm_has_cache);
|
||||
|
||||
struct conflict_context {
|
||||
struct nd_region *nd_region;
|
||||
resource_size_t start, size;
|
||||
};
|
||||
|
||||
static int region_conflict(struct device *dev, void *data)
|
||||
{
|
||||
struct nd_region *nd_region;
|
||||
struct conflict_context *ctx = data;
|
||||
resource_size_t res_end, region_end, region_start;
|
||||
|
||||
if (!is_memory(dev))
|
||||
return 0;
|
||||
|
||||
nd_region = to_nd_region(dev);
|
||||
if (nd_region == ctx->nd_region)
|
||||
return 0;
|
||||
|
||||
res_end = ctx->start + ctx->size;
|
||||
region_start = nd_region->ndr_start;
|
||||
region_end = region_start + nd_region->ndr_size;
|
||||
if (ctx->start >= region_start && ctx->start < region_end)
|
||||
return -EBUSY;
|
||||
if (res_end > region_start && res_end <= region_end)
|
||||
return -EBUSY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nd_region_conflict(struct nd_region *nd_region, resource_size_t start,
|
||||
resource_size_t size)
|
||||
{
|
||||
struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev);
|
||||
struct conflict_context ctx = {
|
||||
.nd_region = nd_region,
|
||||
.start = start,
|
||||
.size = size,
|
||||
};
|
||||
|
||||
return device_for_each_child(&nvdimm_bus->dev, &ctx, region_conflict);
|
||||
}
|
||||
|
||||
void __exit nd_region_devs_exit(void)
|
||||
{
|
||||
ida_destroy(®ion_ida);
|
||||
|
在新工单中引用
屏蔽一个用户