From patchwork Fri May 29 23:41:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 6512081 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8F61F9F1CC for ; Fri, 29 May 2015 23:44:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 36520207B7 for ; Fri, 29 May 2015 23:44:00 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B0D62207AA for ; Fri, 29 May 2015 23:43:58 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8C9741828E1; Fri, 29 May 2015 16:43:58 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ml01.01.org (Postfix) with ESMTP id 0F3BB1828DF for ; Fri, 29 May 2015 16:43:57 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 29 May 2015 16:43:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,520,1427785200"; d="scan'208";a="737656238" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.23.232.36]) by orsmga002.jf.intel.com with ESMTP; 29 May 2015 16:43:57 -0700 Subject: [libnd-for-next PATCH] libnd: miscellaneous sparse fixes From: Dan Williams To: linux-nvdimm@lists.01.org Date: Fri, 29 May 2015 19:41:16 -0400 Message-ID: <20150529233954.36480.99269.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-8-g92dd MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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] * 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] *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] *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 Signed-off-by: Dan Williams --- 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(-) diff --git a/drivers/block/nd/btt.c b/drivers/block/nd/btt.c index a4287b6f4224..932177294f75 100644 --- a/drivers/block/nd/btt.c +++ b/drivers/block/nd/btt.c @@ -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; diff --git a/drivers/block/nd/bus.c b/drivers/block/nd/bus.c index dc69ccfae53a..8d13051714d3 100644 --- a/drivers/block/nd/bus.c +++ b/drivers/block/nd/bus.c @@ -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, diff --git a/drivers/block/nd/label.c b/drivers/block/nd/label.c index 5052db591bec..e0f495e90728 100644 --- a/drivers/block/nd/label.c +++ b/drivers/block/nd/label.c @@ -21,6 +21,10 @@ #include +#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; diff --git a/drivers/block/nd/label.h b/drivers/block/nd/label.h index a26cebc9f389..71fac593e50f 100644 --- a/drivers/block/nd/label.h +++ b/drivers/block/nd/label.h @@ -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( diff --git a/drivers/block/nd/nd-private.h b/drivers/block/nd/nd-private.h index b0571e334af9..e0eb5799ef3f 100644 --- a/drivers/block/nd/nd-private.h +++ b/drivers/block/nd/nd-private.h @@ -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; diff --git a/drivers/block/nd/nd.h b/drivers/block/nd/nd.h index b830801c9892..e826fa3dfeac 100644 --- a/drivers/block/nd/nd.h +++ b/drivers/block/nd/nd.h @@ -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); diff --git a/drivers/block/nd/region.c b/drivers/block/nd/region.c index 75ae27279f0e..5af7701ad6ea 100644 --- a/drivers/block/nd/region.c +++ b/drivers/block/nd/region.c @@ -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); }