From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754883AbcKUT1p convert rfc822-to-8bit (ORCPT ); Mon, 21 Nov 2016 14:27:45 -0500 Received: from mga03.intel.com ([134.134.136.65]:18723 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754852AbcKUT1o (ORCPT ); Mon, 21 Nov 2016 14:27:44 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,528,1473145200"; d="scan'208";a="34024861" From: "Reshetova, Elena" To: Peter Zijlstra CC: David Windsor , Alexei Starovoitov , Kees Cook , Greg KH , Will Deacon , "Arnd Bergmann" , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , LKML , Daniel Borkmann Subject: RE: [RFC][PATCH 2/7] kref: Add kref_read() Thread-Topic: [RFC][PATCH 2/7] kref: Add kref_read() Thread-Index: AQHSQEVANqFGs6lR9EeBqDMncz0eH6Dc36YAgAB8mgCAAaU8QIAEaLeAgAAvbYCAAAN0gIAAA0eAgAA5GEA= Date: Mon, 21 Nov 2016 19:27:29 +0000 Message-ID: <2236FBA76BA1254E88B949DDB74E612B41C156AE@IRSMSX102.ger.corp.intel.com> References: <20161117085342.GB3142@twins.programming.kicks-ass.net> <20161117161937.GA46515@ast-mbp.thefacebook.com> <2236FBA76BA1254E88B949DDB74E612B41C14BB4@IRSMSX102.ger.corp.intel.com> <2236FBA76BA1254E88B949DDB74E612B41C15583@IRSMSX102.ger.corp.intel.com> <20161121154915.GB3124@twins.programming.kicks-ass.net> <20161121160059.GB3174@twins.programming.kicks-ass.net> In-Reply-To: <20161121160059.GB3174@twins.programming.kicks-ass.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Mon, Nov 21, 2016 at 04:49:15PM +0100, Peter Zijlstra wrote: > > > Speaking of non-fitting patterns. This one is quite common in > > > networking code for refcounters: > > > > > > if (atomic_cmpxchg(&cur->refcnt, 1, 0) == 1) {} This is from > > > net/netfilter/nfnetlink_acct.c, but there are similar ones in other > > > places. > > > > Cute, but weird it doesn't actually decrement if not 1. > > Hurgh.. creative refcounting that. The question is how much of that do > we want to support? It really must not decrement there. And one more creative usage: http://lxr.free-electrons.com/source/net/ipv4/udp.c#L1940 if (!sk || !atomic_inc_not_zero_hint(&sk->sk_refcnt, 2)) return; I didn't even guess anyone is using atomic_inc_not_zero_hint... But network code keeps surprising me today :) So, yes, I guess the question is what to do with these cases really?