Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933227AbdCVCDb (ORCPT ); Tue, 21 Mar 2017 22:03:31 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34169 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758464AbdCVCD2 (ORCPT ); Tue, 21 Mar 2017 22:03:28 -0400 Message-ID: <1490148199.16816.126.camel@edumazet-glaptop3.roam.corp.google.com> Subject: Re: [PATCH 07/17] net: convert sock.sk_refcnt from atomic_t to refcount_t From: Eric Dumazet To: Kees Cook Cc: Peter Zijlstra , Herbert Xu , David Miller , "Reshetova, Elena" , Network Development , bridge@lists.linux-foundation.org, LKML , Alexey Kuznetsov , James Morris , Patrick McHardy , Stephen Hemminger , Hans Liljestrand , David Windsor , Andrew Morton Date: Tue, 21 Mar 2017 19:03:19 -0700 In-Reply-To: References: <1489767196.28631.305.camel@edumazet-glaptop3.roam.corp.google.com> <20170318164759.GA23837@gondor.apana.org.au> <20170318.182121.439615057765380575.davem@davemloft.net> <20170320103937.lq7nfnutupr3gkn7@hirez.programming.kicks-ass.net> <20170320131629.GA26405@gondor.apana.org.au> <20170320132357.acygo3umw6fiwb4p@hirez.programming.kicks-ass.net> <20170320132713.GA26954@gondor.apana.org.au> <20170320134017.h3c2jrsnd4guuyu7@hirez.programming.kicks-ass.net> <1490131389.16816.123.camel@edumazet-glaptop3.roam.corp.google.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 758 Lines: 30 On Tue, 2017-03-21 at 16:51 -0700, Kees Cook wrote: > Am I understanding you correctly that you'd want something like: > > refcount.h: > #ifdef UNPROTECTED_REFCOUNT > #define refcount_inc(x) atomic_inc(x) > ... > #else > void refcount_inc(... > ... > #endif > > some/net.c: > #define UNPROTECTED_REFCOUNT > #include > > or similar? At first, it could be something simple like that yes. Note that we might define two refcount_inc() : One that does whole tests, and refcount_inc_relaxed() that might translate to atomic_inc() on non debug kernels. Then later, maybe provide a dynamic infrastructure so that we can dynamically force the full checks even for refcount_inc_relaxed() on say 1% of the hosts, to get better debug coverage ?