@@ -863,6 +863,7 @@ static int lba_to_arena(struct btt *btt, sector_t sector, __u32 *premap,
* readability, since they index into an array of locks
*/
static void lock_map(struct arena_info *arena, u32 premap)
+ __acquires(&arena->map_locks[idx].lock)
{
u32 idx = (premap * MAP_ENT_SIZE / L1_CACHE_BYTES) % arena->nfree;
@@ -870,6 +871,7 @@ static void lock_map(struct arena_info *arena, u32 premap)
}
static void unlock_map(struct arena_info *arena, u32 premap)
+ __releases(&arena->map_locks[idx].lock)
{
u32 idx = (premap * MAP_ENT_SIZE / L1_CACHE_BYTES) % arena->nfree;
@@ -337,7 +337,7 @@ static ssize_t devtype_show(struct device *dev, struct device_attribute *attr,
{
return sprintf(buf, "%s\n", dev->type->name);
}
-DEVICE_ATTR_RO(devtype);
+static DEVICE_ATTR_RO(devtype);
static struct attribute *nd_device_attributes[] = {
&dev_attr_modalias.attr,
@@ -374,7 +374,7 @@ void nd_bus_destroy_ndctl(struct nd_bus *nd_bus)
device_destroy(nd_class, MKDEV(nd_bus_major, nd_bus->id));
}
-static const struct nd_cmd_desc const __nd_cmd_dimm_descs[] = {
+static const struct nd_cmd_desc __nd_cmd_dimm_descs[] = {
[ND_CMD_IMPLEMENTED] = { },
[ND_CMD_SMART] = {
.out_num = 2,
@@ -420,7 +420,7 @@ const struct nd_cmd_desc *nd_cmd_dimm_desc(int cmd)
}
EXPORT_SYMBOL_GPL(nd_cmd_dimm_desc);
-static const struct nd_cmd_desc const __nd_cmd_bus_descs[] = {
+static const struct nd_cmd_desc __nd_cmd_bus_descs[] = {
[ND_CMD_IMPLEMENTED] = { },
[ND_CMD_ARS_CAP] = {
.in_num = 2,
@@ -21,6 +21,10 @@
#include <asm-generic/io-64-nonatomic-lo-hi.h>
+#ifndef __io_virt
+#define __io_virt(x) ((void __force *) (x))
+#endif
+
static u32 best_seq(u32 a, u32 b)
{
a &= NSINDEX_SEQ_MASK;
@@ -114,7 +118,7 @@ int nd_label_validate(struct nd_dimm_drvdata *ndd)
}
sum_save = readq(&nsindex[i]->checksum);
writeq(0, &nsindex[i]->checksum);
- sum = nd_fletcher64((void * __force) nsindex[i],
+ sum = nd_fletcher64(__io_virt(nsindex[i]),
sizeof_namespace_index(ndd), 1);
writeq(sum_save, &nsindex[i]->checksum);
if (sum != sum_save) {
@@ -190,21 +194,17 @@ void nd_label_copy(struct nd_dimm_drvdata *ndd,
struct nd_namespace_index __iomem *dst,
struct nd_namespace_index __iomem *src)
{
- void *s, *d;
-
if (dst && src)
/* pass */;
else
return;
- d = (void * __force) dst;
- s = (void * __force) src;
- memcpy(d, s, sizeof_namespace_index(ndd));
+ memcpy(__io_virt(dst), __io_virt(src), sizeof_namespace_index(ndd));
}
static struct nd_namespace_label __iomem *nd_label_base(struct nd_dimm_drvdata *ndd)
{
- void *base = to_namespace_index(ndd, 0);
+ void __iomem *base = to_namespace_index(ndd, 0);
return base + 2 * sizeof_namespace_index(ndd);
}
@@ -224,20 +224,23 @@ static int to_slot(struct nd_dimm_drvdata *ndd,
* preamble_index - common variable initialization for nd_label_* routines
* @nd_dimm: dimm container for the relevant label set
* @idx: namespace_index index
- * @nsindex: on return set to the currently active namespace index
+ * @nsindex_out: on return set to the currently active namespace index
* @free: on return set to the free label bitmap in the index
* @nslot: on return set to the number of slots in the label space
*/
static bool preamble_index(struct nd_dimm_drvdata *ndd, int idx,
- struct nd_namespace_index **nsindex,
+ struct nd_namespace_index __iomem **nsindex_out,
unsigned long **free, u32 *nslot)
{
- *nsindex = to_namespace_index(ndd, idx);
- if (*nsindex == NULL)
+ struct nd_namespace_index __iomem *nsindex;
+
+ nsindex = to_namespace_index(ndd, idx);
+ if (nsindex == NULL)
return false;
- *free = (unsigned long __force *) (*nsindex)->free;
- *nslot = readl(&(*nsindex)->nslot);
+ *free = __io_virt(nsindex->free);
+ *nslot = readl(&nsindex->nslot);
+ *nsindex_out = nsindex;
return true;
}
@@ -252,7 +255,7 @@ char *nd_label_gen_id(struct nd_label_id *label_id, u8 *uuid, u32 flags)
}
static bool preamble_current(struct nd_dimm_drvdata *ndd,
- struct nd_namespace_index **nsindex,
+ struct nd_namespace_index __iomem **nsindex,
unsigned long **free, u32 *nslot)
{
return preamble_index(ndd, ndd->ns_current, nsindex,
@@ -260,7 +263,7 @@ static bool preamble_current(struct nd_dimm_drvdata *ndd,
}
static bool preamble_next(struct nd_dimm_drvdata *ndd,
- struct nd_namespace_index **nsindex,
+ struct nd_namespace_index __iomem **nsindex,
unsigned long **free, u32 *nslot)
{
return preamble_index(ndd, ndd->ns_next, nsindex,
@@ -420,12 +423,13 @@ u32 nd_label_nfree(struct nd_dimm_drvdata *ndd)
static int nd_label_write_index(struct nd_dimm_drvdata *ndd, int index, u32 seq,
unsigned long flags)
{
- struct nd_namespace_index *nsindex = to_namespace_index(ndd, index);
+ struct nd_namespace_index __iomem *nsindex;
unsigned long offset;
u64 checksum;
u32 nslot;
int rc;
+ nsindex = to_namespace_index(ndd, index);
if (flags & ND_NSINDEX_INIT)
nslot = nd_dimm_num_label_slots(ndd);
else
@@ -450,7 +454,7 @@ static int nd_label_write_index(struct nd_dimm_drvdata *ndd, int index, u32 seq,
writew(1, &nsindex->minor);
writeq(0, &nsindex->checksum);
if (flags & ND_NSINDEX_INIT) {
- unsigned long *free = (unsigned long __force *) nsindex->free;
+ unsigned long *free = __io_virt(nsindex->free);
u32 nfree = ALIGN(nslot, BITS_PER_LONG);
int last_bits, i;
@@ -458,11 +462,11 @@ static int nd_label_write_index(struct nd_dimm_drvdata *ndd, int index, u32 seq,
for (i = 0, last_bits = nfree - nslot; i < last_bits; i++)
clear_bit_le(nslot + i, free);
}
- checksum = nd_fletcher64((void * __force) nsindex,
+ checksum = nd_fletcher64(__io_virt(nsindex),
sizeof_namespace_index(ndd), 1);
writeq(checksum, &nsindex->checksum);
rc = nd_dimm_set_config_data(ndd, readq(&nsindex->myoff),
- nsindex, sizeof_namespace_index(ndd));
+ __io_virt(nsindex), sizeof_namespace_index(ndd));
if (rc < 0)
return rc;
@@ -526,7 +530,7 @@ static int __pmem_label_update(struct nd_region *nd_region,
/* update label */
offset = nd_label_offset(ndd, nd_label);
- rc = nd_dimm_set_config_data(ndd, offset, nd_label,
+ rc = nd_dimm_set_config_data(ndd, offset, __io_virt(nd_label),
sizeof(struct nd_namespace_label));
if (rc < 0)
return rc;
@@ -552,7 +556,7 @@ static int __pmem_label_update(struct nd_region *nd_region,
static void del_label(struct nd_mapping *nd_mapping, int l)
{
- struct nd_namespace_label __iomem *next_label, __iomem *nd_label;
+ struct nd_namespace_label __iomem *next_label, *nd_label;
struct nd_dimm_drvdata *ndd = to_ndd(nd_mapping);
unsigned int slot;
int j;
@@ -709,7 +713,7 @@ static int __blk_label_update(struct nd_region *nd_region,
/* update label */
offset = nd_label_offset(ndd, nd_label);
- rc = nd_dimm_set_config_data(ndd, offset, nd_label,
+ rc = nd_dimm_set_config_data(ndd, offset, __io_virt(nd_label),
sizeof(struct nd_namespace_label));
if (rc < 0)
goto abort;
@@ -124,8 +124,8 @@ static inline int nd_label_next_nsindex(int index)
struct nd_dimm_drvdata;
int nd_label_validate(struct nd_dimm_drvdata *ndd);
void nd_label_copy(struct nd_dimm_drvdata *ndd,
- struct nd_namespace_index *dst,
- struct nd_namespace_index *src);
+ struct nd_namespace_index __iomem *dst,
+ struct nd_namespace_index __iomem *src);
size_t sizeof_namespace_index(struct nd_dimm_drvdata *ndd);
int nd_label_active_count(struct nd_dimm_drvdata *ndd);
struct nd_namespace_label __iomem *nd_label_active(
@@ -73,11 +73,6 @@ static inline void nd_btt_notify_ndio(struct nd_bus *nd_bus, struct nd_io *ndio)
struct nd_bus *walk_to_nd_bus(struct device *nd_dev);
int __init nd_bus_init(void);
void nd_bus_exit(void);
-int __init nd_dimm_init(void);
-int __init nd_region_init(void);
-void __init nd_region_init_locks(void);
-void nd_dimm_exit(void);
-int nd_region_exit(void);
void nd_region_probe_start(struct nd_bus *nd_bus, struct device *dev);
void nd_region_probe_end(struct nd_bus *nd_bus, struct device *dev, int rc);
struct nd_region;
@@ -231,6 +231,10 @@ void nd_init_ndio(struct nd_io *ndio, nd_rw_bytes_fn rw_bytes,
void ndio_del_claim(struct nd_io_claim *ndio_claim);
struct nd_io_claim *ndio_add_claim(struct nd_io *ndio, struct device *holder,
ndio_notify_remove_fn notify_remove);
+int __init nd_dimm_init(void);
+int __init nd_region_init(void);
+void nd_dimm_exit(void);
+void nd_region_exit(void);
struct nd_dimm;
struct nd_dimm_drvdata *to_ndd(struct nd_mapping *nd_mapping);
int nd_dimm_init_nsarea(struct nd_dimm_drvdata *ndd);
@@ -180,7 +180,7 @@ int __init nd_region_init(void)
return nd_driver_register(&nd_region_driver);
}
-void __exit nd_region_exit(void)
+void nd_region_exit(void)
{
driver_unregister(&nd_region_driver.drv);
}
It seems 0day is slowly leaking out new sparse reports for libnd. Indeed running sparse locally reveals a small trove. Most are straightforward but there are a few that remain open: "drivers/block/nd/region.c:74:9: warning: context imbalance in 'nd_region_acquire_lane' - wrong count at exit drivers/block/nd/region.c:88:36: warning: context imbalance in 'nd_region_release_lane' - unexpected unlock" Not sure how to tell sparse that nd_region_acquire_lane() may nest, conditionally acquires the lock at the top level, but only conditionally if we have more cpus than we have lanes. "drivers/block/nd/label.c:105:26: warning: Initializer entry defined twice drivers/block/nd/label.c:105:33: also defined here drivers/block/nd/pmem.c:166:25: warning: incorrect type in assignment (different address spaces) drivers/block/nd/pmem.c:166:25: expected void *virt_addr drivers/block/nd/pmem.c:166:25: got void [noderef] <asn:2>* drivers/block/nd/pmem.c:198:21: warning: incorrect type in argument 1 (different address spaces) drivers/block/nd/pmem.c:198:21: expected void volatile [noderef] <asn:2>*addr drivers/block/nd/pmem.c:198:21: got void *virt_addr drivers/block/nd/pmem.c:212:21: warning: incorrect type in argument 1 (different address spaces) drivers/block/nd/pmem.c:212:21: expected void volatile [noderef] <asn:2>*addr drivers/block/nd/pmem.c:212:21: got void *virt_addr" These are the result of ioremap() vs memcpy() where we know the virtual address returned by ioremap() has no io side effects. The plan is to introduce memremap() for these cases, as other users of ioremap() in the kernel have this same problem. Reported-by: kbuild test robot <fengguang.wu@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- drivers/block/nd/btt.c | 2 ++ drivers/block/nd/bus.c | 6 +++-- drivers/block/nd/label.c | 48 ++++++++++++++++++++++------------------- drivers/block/nd/label.h | 4 ++- drivers/block/nd/nd-private.h | 5 ---- drivers/block/nd/nd.h | 4 +++ drivers/block/nd/region.c | 2 +- 7 files changed, 38 insertions(+), 33 deletions(-)