From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965000AbcKOHuN (ORCPT ); Tue, 15 Nov 2016 02:50:13 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:43019 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933642AbcKOHuK (ORCPT ); Tue, 15 Nov 2016 02:50:10 -0500 Date: Tue, 15 Nov 2016 08:50:07 +0100 From: Peter Zijlstra To: Kees Cook Cc: Greg KH , Will Deacon , "Reshetova, Elena" , Arnd Bergmann , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , David Windsor , LKML Subject: Re: [RFC][PATCH 5/7] kref: Implement kref_put_lock() Message-ID: <20161115075007.GM3142@twins.programming.kicks-ass.net> References: <20161114173946.501528675@infradead.org> <20161114174446.690415221@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 On Mon, Nov 14, 2016 at 12:35:48PM -0800, Kees Cook wrote: > On Mon, Nov 14, 2016 at 9:39 AM, Peter Zijlstra wrote: > > Because home-rolling your own is _awesome_, stop doing it. Provide > > kref_put_lock(), just like kref_put_mutex() but for a spinlock. > > > > Signed-off-by: Peter Zijlstra (Intel) > > --- > > include/linux/kref.h | 21 +++++++++++++++------ > > net/sunrpc/svcauth.c | 15 ++++++++++----- > > 2 files changed, 25 insertions(+), 11 deletions(-) > > > > --- a/include/linux/kref.h > > +++ b/include/linux/kref.h > > @@ -86,12 +86,21 @@ static inline int kref_put_mutex(struct > > struct mutex *lock) > > { > > WARN_ON(release == NULL); > > This WARN_ON makes sense, yes, though it seems like it should be deal > with differently. If it's NULL, we'll just Oops when we call release() > later... Seems like this should saturate the kref or something else > similar. So I simply took the pattern from the existing kref_put(). But I like it more in these kref_put_{lock,mutex}() variants, because someone will need to unlock. If we simply crash/bug without unlock we'll have broken state the rest of the kernel cannot fix up.