Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965632AbcKOIDS (ORCPT ); Tue, 15 Nov 2016 03:03:18 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:44517 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933425AbcKOIDQ (ORCPT ); Tue, 15 Nov 2016 03:03:16 -0500 Date: Tue, 15 Nov 2016 09:03:14 +0100 From: Peter Zijlstra To: Greg KH Cc: keescook@chromium.org, will.deacon@arm.com, elena.reshetova@intel.com, arnd@arndb.de, tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com, dave@progbits.org, linux-kernel@vger.kernel.org Subject: Re: [RFC][PATCH 2/7] kref: Add kref_read() Message-ID: <20161115080314.GD3142@twins.programming.kicks-ass.net> References: <20161114173946.501528675@infradead.org> <20161114174446.486581399@infradead.org> <20161115073322.GC28248@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161115073322.GC28248@kroah.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1612 Lines: 40 On Tue, Nov 15, 2016 at 08:33:22AM +0100, Greg KH wrote: > On Mon, Nov 14, 2016 at 06:39:48PM +0100, Peter Zijlstra wrote: > > --- a/drivers/block/drbd/drbd_req.c > > +++ b/drivers/block/drbd/drbd_req.c > > @@ -520,7 +520,7 @@ static void mod_rq_state(struct drbd_req > > /* Completion does it's own kref_put. If we are going to > > * kref_sub below, we need req to be still around then. */ > > int at_least = k_put + !!c_put; > > - int refcount = atomic_read(&req->kref.refcount); > > + int refcount = kref_read(&req->kref); > > if (refcount < at_least) > > drbd_err(device, > > "mod_rq_state: Logic BUG: %x -> %x: refcount = %d, should be >= %d\n", > > As proof of "things you should never do", here is one such example. > > ugh. > > > > --- a/drivers/block/virtio_blk.c > > +++ b/drivers/block/virtio_blk.c > > @@ -767,7 +767,7 @@ static void virtblk_remove(struct virtio > > /* Stop all the virtqueues. */ > > 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); > > vdev->config->del_vqs(vdev); > > kfree(vblk->vqs); > > And this too, ugh, that's a huge abuse and is probably totally wrong... > > thanks again for digging through this crap. I wonder if we need to name > the kref reference variable "do_not_touch_this_ever" or some such thing > to catch all of the people who try to be "too smart". There's unimaginable bong hits involved in this stuff, in the end I resorted to brute force and scripts to convert all this.