[lkml]   [2018]   [Jul]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH] refcount: always allow checked forms
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

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

 \ /
  Last update: 2018-07-04 10:47    [W:0.093 / U:5.292 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site