Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp556797imm; Wed, 4 Jul 2018 01:48:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfQRiiUsROaBk65W19WylEsTbeoXO6Gb0K7n1Bp53uJ1Ori6OL6A7quO8gNC9pVEaLgnyt6 X-Received: by 2002:a63:1811:: with SMTP id y17-v6mr1092435pgl.356.1530694103595; Wed, 04 Jul 2018 01:48:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530694103; cv=none; d=google.com; s=arc-20160816; b=zY7Cr28iGDdFXjBxiCJqHh427WQuZ8m39/oHHZ7gvk3m4Dm/7o1Z1ZwTLqLHdWEmcQ yxm09JOdYsz9zspJHwFafdk1ZtePDeIn+elB5RI1t22Z+aIusdxIZ2IpJGDbe9xR8fYu kpxWnM4KhMW+Buu5f8DuEN1omagoDUaPwyQmEwiLaGVisTpyDNxU1hPXjFx3voWG7Wa5 hbhvS2tdpxclTqVvs3Q6mXfGdcBTG75q/WBNJOwYUQBGUuhLhWnAtP/q63KzrP7p9mKP qYM0/5U2qr2tnJWOaV6HhS2MDhCLGew991i7HA4tWmOFR96o6q/Oo3YQZAfIWq5aG7Y6 3aWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=i8HTml0TKzhaI4BDFIE2CiaiaUMOwfAjXBxkp3/4fco=; b=XzhipoCnYlq9GsZnawsaoRmi/z4BhlPgjdvefrzNcQlMw7CLW7y4T97PZo1GbUCOdH DaMhOi+A647zXlxetEAFFVFMNPeLHLI9sD41AZFdo3LQhGI//djwmLtBb7k3jhZjiBFa ieakxmW9uHfJIG3yqt/OeSgOn+0KmK2wuvdm6ZCUq/kJkSiGrnnkCMywf6p4oEnWLrti +4BwByBaLgiMO09AywloA3adNHYjhIqNtnJXy6dy+3/oUlwsyto296oV6CSj1MVd9dK5 Is4cTX4eVkx2a3g5J3YfzlAI8xxrOTYr+bQxVn7BYZjJD6E8rRdaACRN330lJMSzzzr1 9WkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2-v6si2715001pgt.611.2018.07.04.01.48.09; Wed, 04 Jul 2018 01:48:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934120AbeGDIqp (ORCPT + 99 others); Wed, 4 Jul 2018 04:46:45 -0400 Received: from mx2.suse.de ([195.135.220.15]:37190 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932148AbeGDIqo (ORCPT ); Wed, 4 Jul 2018 04:46:44 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 29DC3AFF3; Wed, 4 Jul 2018 08:46:43 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id D574EDAA1D; Wed, 4 Jul 2018 10:46:41 +0200 (CEST) Date: Wed, 4 Jul 2018 10:46:41 +0200 From: David Sterba To: Mark Rutland Cc: linux-kernel@vger.kernel.org, Will Deacon , Kees Cook , Boqun Feng , Peter Zijlstra , Ingo Molnar Subject: Re: [PATCH] refcount: always allow checked forms Message-ID: <20180704084641.GL3126@suse.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Mark Rutland , linux-kernel@vger.kernel.org, Will Deacon , Kees Cook , Boqun Feng , Peter Zijlstra , Ingo Molnar References: <20180703100102.16615-1-mark.rutland@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180703100102.16615-1-mark.rutland@arm.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 03, 2018 at 11:01:02AM +0100, Mark Rutland wrote: > In many cases, it would be useful to be able to use the full > sanity-checked refcount helpers regardless of CONFIG_REFCOUNT_FULL, as > this would help to avoid duplicate warnings where callers try to > sanity-check refcount manipulation. > > This patch refactors things such that the full refcount helpers were > always built, as refcount_${op}_checked(), such that they can be used > regardless of CONFIG_REFCOUNT_FULL. This will allow code which *always* > wants a checked refcount to opt-in, avoiding the need to duplicate the > logic for warnings. > > There should be no functional change as a result of this patch. > > Signed-off-by: Mark Rutland > Cc: Boqun Feng > Cc: David Sterba > Cc: Ingo Molnar > Cc: Kees Cook > Cc: Peter Zijlstra > Cc: Peter Zijlstra > Cc: Will Deacon I dare to give it my Reviewed-by: David Sterba as my POC implementations were crap and Mark's version is much better. > --- > include/linux/refcount.h | 27 +++++++++++++++++------- > lib/refcount.c | 53 +++++++++++++++++++++++------------------------- > 2 files changed, 45 insertions(+), 35 deletions(-) > > Dave pointed out that it would be useful to be able to opt-in to full checks > regardless of CONFIG_REFCOUNT_FULL, so that we can simplify callsites where we > always want checks. I've spotted a few of these in code which is still awaiting > conversion. The motivation was code like WARN_ON(refcount_read(&ref)); if (refcount_dec_and_test(&ref)) { ... } so the warning is redundant for REFCOUNT_FULL, but I'm going to use the _checked versions everywhere the performance of refcounts is not critical.