locking/atomic, kref: Add kref_read()

Since we need to change the implementation, stop exposing internals.

Provide kref_read() to read the current reference count; typically
used for debug messages.

Kills two anti-patterns:

	atomic_read(&kref->refcount)
	kref->refcount.counter

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
Peter Zijlstra
2016-11-14 17:29:48 +01:00
committed by Ingo Molnar
parent 1e24edca05
commit 2c935bc572
56 changed files with 121 additions and 117 deletions
+1 -1
View File
@@ -520,7 +520,7 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m,
/* Completion does it's own kref_put. If we are going to /* Completion does it's own kref_put. If we are going to
* kref_sub below, we need req to be still around then. */ * kref_sub below, we need req to be still around then. */
int at_least = k_put + !!c_put; int at_least = k_put + !!c_put;
int refcount = atomic_read(&req->kref.refcount); int refcount = kref_read(&req->kref);
if (refcount < at_least) if (refcount < at_least)
drbd_err(device, drbd_err(device,
"mod_rq_state: Logic BUG: %x -> %x: refcount = %d, should be >= %d\n", "mod_rq_state: Logic BUG: %x -> %x: refcount = %d, should be >= %d\n",
+4 -4
View File
@@ -1535,7 +1535,7 @@ static bool obj_request_overlaps_parent(struct rbd_obj_request *obj_request)
static void rbd_obj_request_get(struct rbd_obj_request *obj_request) static void rbd_obj_request_get(struct rbd_obj_request *obj_request)
{ {
dout("%s: obj %p (was %d)\n", __func__, obj_request, dout("%s: obj %p (was %d)\n", __func__, obj_request,
atomic_read(&obj_request->kref.refcount)); kref_read(&obj_request->kref));
kref_get(&obj_request->kref); kref_get(&obj_request->kref);
} }
@@ -1544,14 +1544,14 @@ static void rbd_obj_request_put(struct rbd_obj_request *obj_request)
{ {
rbd_assert(obj_request != NULL); rbd_assert(obj_request != NULL);
dout("%s: obj %p (was %d)\n", __func__, obj_request, dout("%s: obj %p (was %d)\n", __func__, obj_request,
atomic_read(&obj_request->kref.refcount)); kref_read(&obj_request->kref));
kref_put(&obj_request->kref, rbd_obj_request_destroy); kref_put(&obj_request->kref, rbd_obj_request_destroy);
} }
static void rbd_img_request_get(struct rbd_img_request *img_request) static void rbd_img_request_get(struct rbd_img_request *img_request)
{ {
dout("%s: img %p (was %d)\n", __func__, img_request, dout("%s: img %p (was %d)\n", __func__, img_request,
atomic_read(&img_request->kref.refcount)); kref_read(&img_request->kref));
kref_get(&img_request->kref); kref_get(&img_request->kref);
} }
@@ -1562,7 +1562,7 @@ static void rbd_img_request_put(struct rbd_img_request *img_request)
{ {
rbd_assert(img_request != NULL); rbd_assert(img_request != NULL);
dout("%s: img %p (was %d)\n", __func__, img_request, dout("%s: img %p (was %d)\n", __func__, img_request,
atomic_read(&img_request->kref.refcount)); kref_read(&img_request->kref));
if (img_request_child_test(img_request)) if (img_request_child_test(img_request))
kref_put(&img_request->kref, rbd_parent_request_destroy); kref_put(&img_request->kref, rbd_parent_request_destroy);
else else
+1 -1
View File
@@ -767,7 +767,7 @@ static void virtblk_remove(struct virtio_device *vdev)
/* Stop all the virtqueues. */ /* Stop all the virtqueues. */
vdev->config->reset(vdev); vdev->config->reset(vdev);
refc = atomic_read(&disk_to_dev(vblk->disk)->kobj.kref.refcount); refc = kref_read(&disk_to_dev(vblk->disk)->kobj.kref);
put_disk(vblk->disk); put_disk(vblk->disk);
vdev->config->del_vqs(vdev); vdev->config->del_vqs(vdev);
kfree(vblk->vqs); kfree(vblk->vqs);
+1 -1
View File
@@ -376,7 +376,7 @@ void drm_gem_cma_describe(struct drm_gem_cma_object *cma_obj,
off = drm_vma_node_start(&obj->vma_node); off = drm_vma_node_start(&obj->vma_node);
seq_printf(m, "%2d (%2d) %08llx %pad %p %zu", seq_printf(m, "%2d (%2d) %08llx %pad %p %zu",
obj->name, obj->refcount.refcount.counter, obj->name, kref_read(&obj->refcount),
off, &cma_obj->paddr, cma_obj->vaddr, obj->size); off, &cma_obj->paddr, cma_obj->vaddr, obj->size);
seq_printf(m, "\n"); seq_printf(m, "\n");
+1 -1
View File
@@ -118,7 +118,7 @@ static int drm_gem_one_name_info(int id, void *ptr, void *data)
seq_printf(m, "%6d %8zd %7d %8d\n", seq_printf(m, "%6d %8zd %7d %8d\n",
obj->name, obj->size, obj->name, obj->size,
obj->handle_count, obj->handle_count,
atomic_read(&obj->refcount.refcount)); kref_read(&obj->refcount));
return 0; return 0;
} }
+2 -2
View File
@@ -159,7 +159,7 @@ EXPORT_SYMBOL(drm_mode_object_find);
void drm_mode_object_unreference(struct drm_mode_object *obj) void drm_mode_object_unreference(struct drm_mode_object *obj)
{ {
if (obj->free_cb) { if (obj->free_cb) {
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount)); DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, kref_read(&obj->refcount));
kref_put(&obj->refcount, obj->free_cb); kref_put(&obj->refcount, obj->free_cb);
} }
} }
@@ -176,7 +176,7 @@ EXPORT_SYMBOL(drm_mode_object_unreference);
void drm_mode_object_reference(struct drm_mode_object *obj) void drm_mode_object_reference(struct drm_mode_object *obj)
{ {
if (obj->free_cb) { if (obj->free_cb) {
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount)); DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, kref_read(&obj->refcount));
kref_get(&obj->refcount); kref_get(&obj->refcount);
} }
} }
+1 -1
View File
@@ -486,7 +486,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
seq_printf(m, "%08x: %c %2d (%2d) %08lx %p %zd\n", seq_printf(m, "%08x: %c %2d (%2d) %08lx %p %zd\n",
etnaviv_obj->flags, is_active(etnaviv_obj) ? 'A' : 'I', etnaviv_obj->flags, is_active(etnaviv_obj) ? 'A' : 'I',
obj->name, obj->refcount.refcount.counter, obj->name, kref_read(&obj->refcount),
off, etnaviv_obj->vaddr, obj->size); off, etnaviv_obj->vaddr, obj->size);
rcu_read_lock(); rcu_read_lock();
+1 -1
View File
@@ -256,7 +256,7 @@ extern void drm_gem_object_unreference_unlocked(struct drm_gem_object *);
static inline bool static inline bool
i915_gem_object_is_dead(const struct drm_i915_gem_object *obj) i915_gem_object_is_dead(const struct drm_i915_gem_object *obj)
{ {
return atomic_read(&obj->base.refcount.refcount) == 0; return kref_read(&obj->base.refcount) == 0;
} }
static inline bool static inline bool
+1 -1
View File
@@ -640,7 +640,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
seq_printf(m, "%08x: %c %2d (%2d) %08llx %p\t", seq_printf(m, "%08x: %c %2d (%2d) %08llx %p\t",
msm_obj->flags, is_active(msm_obj) ? 'A' : 'I', msm_obj->flags, is_active(msm_obj) ? 'A' : 'I',
obj->name, obj->refcount.refcount.counter, obj->name, kref_read(&obj->refcount),
off, msm_obj->vaddr); off, msm_obj->vaddr);
for (id = 0; id < priv->num_aspaces; id++) for (id = 0; id < priv->num_aspaces; id++)
+1 -1
View File
@@ -527,7 +527,7 @@ static bool nouveau_fence_no_signaling(struct dma_fence *f)
* caller should have a reference on the fence, * caller should have a reference on the fence,
* else fence could get freed here * else fence could get freed here
*/ */
WARN_ON(atomic_read(&fence->base.refcount.refcount) <= 1); WARN_ON(kref_read(&fence->base.refcount) <= 1);
/* /*
* This needs uevents to work correctly, but dma_fence_add_callback relies on * This needs uevents to work correctly, but dma_fence_add_callback relies on
+1 -1
View File
@@ -1033,7 +1033,7 @@ void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
off = drm_vma_node_start(&obj->vma_node); off = drm_vma_node_start(&obj->vma_node);
seq_printf(m, "%08x: %2d (%2d) %08llx %pad (%2d) %p %4d", seq_printf(m, "%08x: %2d (%2d) %08llx %pad (%2d) %p %4d",
omap_obj->flags, obj->name, obj->refcount.refcount.counter, omap_obj->flags, obj->name, kref_read(&obj->refcount),
off, &omap_obj->paddr, omap_obj->paddr_cnt, off, &omap_obj->paddr, omap_obj->paddr_cnt,
omap_obj->vaddr, omap_obj->roll); omap_obj->vaddr, omap_obj->roll);
+2 -2
View File
@@ -140,8 +140,8 @@ static void ttm_bo_release_list(struct kref *list_kref)
struct ttm_bo_device *bdev = bo->bdev; struct ttm_bo_device *bdev = bo->bdev;
size_t acc_size = bo->acc_size; size_t acc_size = bo->acc_size;
BUG_ON(atomic_read(&bo->list_kref.refcount)); BUG_ON(kref_read(&bo->list_kref));
BUG_ON(atomic_read(&bo->kref.refcount)); BUG_ON(kref_read(&bo->kref));
BUG_ON(atomic_read(&bo->cpu_writers)); BUG_ON(atomic_read(&bo->cpu_writers));
BUG_ON(bo->mem.mm_node != NULL); BUG_ON(bo->mem.mm_node != NULL);
BUG_ON(!list_empty(&bo->lru)); BUG_ON(!list_empty(&bo->lru));
+1 -1
View File
@@ -304,7 +304,7 @@ bool ttm_ref_object_exists(struct ttm_object_file *tfile,
* Verify that the ref->obj pointer was actually valid! * Verify that the ref->obj pointer was actually valid!
*/ */
rmb(); rmb();
if (unlikely(atomic_read(&ref->kref.refcount) == 0)) if (unlikely(kref_read(&ref->kref) == 0))
goto out_false; goto out_false;
rcu_read_unlock(); rcu_read_unlock();
+3 -3
View File
@@ -55,14 +55,14 @@
#define put_ep(ep) { \ #define put_ep(ep) { \
PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \ PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \
ep, atomic_read(&((ep)->kref.refcount))); \ ep, kref_read(&((ep)->kref))); \
WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \ WARN_ON(kref_read(&((ep)->kref)) < 1); \
kref_put(&((ep)->kref), __free_ep); \ kref_put(&((ep)->kref), __free_ep); \
} }
#define get_ep(ep) { \ #define get_ep(ep) { \
PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \ PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \
ep, atomic_read(&((ep)->kref.refcount))); \ ep, kref_read(&((ep)->kref))); \
kref_get(&((ep)->kref)); \ kref_get(&((ep)->kref)); \
} }
+1 -1
View File
@@ -961,7 +961,7 @@ int iwch_modify_qp(struct iwch_dev *rhp, struct iwch_qp *qhp,
case IWCH_QP_STATE_RTS: case IWCH_QP_STATE_RTS:
switch (attrs->next_state) { switch (attrs->next_state) {
case IWCH_QP_STATE_CLOSING: case IWCH_QP_STATE_CLOSING:
BUG_ON(atomic_read(&qhp->ep->com.kref.refcount) < 2); BUG_ON(kref_read(&qhp->ep->com.kref) < 2);
qhp->attr.state = IWCH_QP_STATE_CLOSING; qhp->attr.state = IWCH_QP_STATE_CLOSING;
if (!internal) { if (!internal) {
abort=0; abort=0;
+3 -3
View File
@@ -654,14 +654,14 @@ enum c4iw_mmid_state {
#define c4iw_put_ep(ep) { \ #define c4iw_put_ep(ep) { \
PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \ PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \
ep, atomic_read(&((ep)->kref.refcount))); \ ep, kref_read(&((ep)->kref))); \
WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \ WARN_ON(kref_read(&((ep)->kref)) < 1); \
kref_put(&((ep)->kref), _c4iw_free_ep); \ kref_put(&((ep)->kref), _c4iw_free_ep); \
} }
#define c4iw_get_ep(ep) { \ #define c4iw_get_ep(ep) { \
PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \ PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \
ep, atomic_read(&((ep)->kref.refcount))); \ ep, kref_read(&((ep)->kref))); \
kref_get(&((ep)->kref)); \ kref_get(&((ep)->kref)); \
} }
void _c4iw_free_ep(struct kref *kref); void _c4iw_free_ep(struct kref *kref);
+1 -1
View File
@@ -1503,7 +1503,7 @@ int c4iw_modify_qp(struct c4iw_dev *rhp, struct c4iw_qp *qhp,
case C4IW_QP_STATE_RTS: case C4IW_QP_STATE_RTS:
switch (attrs->next_state) { switch (attrs->next_state) {
case C4IW_QP_STATE_CLOSING: case C4IW_QP_STATE_CLOSING:
BUG_ON(atomic_read(&qhp->ep->com.kref.refcount) < 2); BUG_ON(kref_read(&qhp->ep->com.kref) < 2);
t4_set_wq_in_error(&qhp->wq); t4_set_wq_in_error(&qhp->wq);
set_state(qhp, C4IW_QP_STATE_CLOSING); set_state(qhp, C4IW_QP_STATE_CLOSING);
ep = qhp->ep; ep = qhp->ep;
+3 -3
View File
@@ -80,7 +80,7 @@ usnic_ib_show_config(struct device *device, struct device_attribute *attr,
left = PAGE_SIZE; left = PAGE_SIZE;
mutex_lock(&us_ibdev->usdev_lock); mutex_lock(&us_ibdev->usdev_lock);
if (atomic_read(&us_ibdev->vf_cnt.refcount) > 0) { if (kref_read(&us_ibdev->vf_cnt) > 0) {
char *busname; char *busname;
/* /*
@@ -99,7 +99,7 @@ usnic_ib_show_config(struct device *device, struct device_attribute *attr,
PCI_FUNC(us_ibdev->pdev->devfn), PCI_FUNC(us_ibdev->pdev->devfn),
netdev_name(us_ibdev->netdev), netdev_name(us_ibdev->netdev),
us_ibdev->ufdev->mac, us_ibdev->ufdev->mac,
atomic_read(&us_ibdev->vf_cnt.refcount)); kref_read(&us_ibdev->vf_cnt));
UPDATE_PTR_LEFT(n, ptr, left); UPDATE_PTR_LEFT(n, ptr, left);
for (res_type = USNIC_VNIC_RES_TYPE_EOL; for (res_type = USNIC_VNIC_RES_TYPE_EOL;
@@ -147,7 +147,7 @@ usnic_ib_show_max_vf(struct device *device, struct device_attribute *attr,
us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev);
return scnprintf(buf, PAGE_SIZE, "%u\n", return scnprintf(buf, PAGE_SIZE, "%u\n",
atomic_read(&us_ibdev->vf_cnt.refcount)); kref_read(&us_ibdev->vf_cnt));
} }
static ssize_t static ssize_t
+2 -2
View File
@@ -291,11 +291,11 @@ int usnic_ib_query_device(struct ib_device *ibdev,
qp_per_vf = max(us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_WQ], qp_per_vf = max(us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_WQ],
us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_RQ]); us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_RQ]);
props->max_qp = qp_per_vf * props->max_qp = qp_per_vf *
atomic_read(&us_ibdev->vf_cnt.refcount); kref_read(&us_ibdev->vf_cnt);
props->device_cap_flags = IB_DEVICE_PORT_ACTIVE_EVENT | props->device_cap_flags = IB_DEVICE_PORT_ACTIVE_EVENT |
IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_BLOCK_MULTICAST_LOOPBACK;
props->max_cq = us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_CQ] * props->max_cq = us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_CQ] *
atomic_read(&us_ibdev->vf_cnt.refcount); kref_read(&us_ibdev->vf_cnt);
props->max_pd = USNIC_UIOM_MAX_PD_CNT; props->max_pd = USNIC_UIOM_MAX_PD_CNT;
props->max_mr = USNIC_UIOM_MAX_MR_CNT; props->max_mr = USNIC_UIOM_MAX_MR_CNT;
props->local_ca_ack_delay = 0; props->local_ca_ack_delay = 0;
+1 -1
View File
@@ -1396,7 +1396,7 @@ int genwqe_device_remove(struct genwqe_dev *cd)
* application which will decrease this reference from * application which will decrease this reference from
* 1/unused to 0/illegal and not from 2/used 1/empty. * 1/unused to 0/illegal and not from 2/used 1/empty.
*/ */
rc = atomic_read(&cd->cdev_genwqe.kobj.kref.refcount); rc = kref_read(&cd->cdev_genwqe.kobj.kref);
if (rc != 1) { if (rc != 1) {
dev_err(&pci_dev->dev, dev_err(&pci_dev->dev,
"[%s] err: cdev_genwqe...refcount=%d\n", __func__, rc); "[%s] err: cdev_genwqe...refcount=%d\n", __func__, rc);

Some files were not shown because too many files have changed in this diff Show More