25 Nov, 2019

6 commits

  • The generic implementation of refcount_t should be good enough for
    everybody, so remove ARCH_HAS_REFCOUNT and REFCOUNT_FULL entirely,
    leaving the generic implementation enabled unconditionally.

    Signed-off-by: Will Deacon
    Reviewed-by: Ard Biesheuvel
    Acked-by: Kees Cook
    Tested-by: Hanjun Guo
    Cc: Ard Biesheuvel
    Cc: Elena Reshetova
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: https://lkml.kernel.org/r/20191121115902.2551-9-will@kernel.org
    Signed-off-by: Ingo Molnar

    Will Deacon
     
  • Having the refcount saturation and warnings inline bloats the text,
    despite the fact that these paths should never be executed in normal
    operation.

    Move the refcount saturation and warnings out of line to reduce the
    image size when refcount_t checking is enabled. Relative to an x86_64
    defconfig, the sizes reported by bloat-o-meter are:

    # defconfig+REFCOUNT_FULL, inline saturation (i.e. before this patch)
    Total: Before=14762076, After=14915442, chg +1.04%

    # defconfig+REFCOUNT_FULL, out-of-line saturation (i.e. after this patch)
    Total: Before=14762076, After=14835497, chg +0.50%

    A side-effect of this change is that we now only get one warning per
    refcount saturation type, rather than one per problematic call-site.

    Signed-off-by: Will Deacon
    Reviewed-by: Ard Biesheuvel
    Reviewed-by: Kees Cook
    Tested-by: Hanjun Guo
    Cc: Ard Biesheuvel
    Cc: Elena Reshetova
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: https://lkml.kernel.org/r/20191121115902.2551-7-will@kernel.org
    Signed-off-by: Ingo Molnar

    Will Deacon
     
  • …nux/refcount.h> header

    In an effort to improve performance of the REFCOUNT_FULL implementation,
    move the bulk of its functions into linux/refcount.h. This allows them
    to be inlined in the same way as if they had been provided via
    CONFIG_ARCH_HAS_REFCOUNT.

    Signed-off-by: Will Deacon <will@kernel.org>
    Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
    Reviewed-by: Kees Cook <keescook@chromium.org>
    Tested-by: Hanjun Guo <guohanjun@huawei.com>
    Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
    Cc: Elena Reshetova <elena.reshetova@intel.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lkml.kernel.org/r/20191121115902.2551-5-will@kernel.org
    Signed-off-by: Ingo Molnar <mingo@kernel.org>

    Will Deacon
     
  • The full-fat refcount implementation is exposed via a set of functions
    suffixed with "_checked()", the idea being that code can choose to use
    the more expensive, yet more secure implementation on a case-by-case
    basis.

    In reality, this hasn't happened, so with a grand total of zero users,
    let's remove the checked variants for now by simply dropping the suffix
    and predicating the out-of-line functions on CONFIG_REFCOUNT_FULL=y.

    Signed-off-by: Will Deacon
    Reviewed-by: Ard Biesheuvel
    Reviewed-by: Kees Cook
    Tested-by: Hanjun Guo
    Cc: Ard Biesheuvel
    Cc: Elena Reshetova
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: https://lkml.kernel.org/r/20191121115902.2551-4-will@kernel.org
    Signed-off-by: Ingo Molnar

    Will Deacon
     
  • In preparation for changing the saturation point of REFCOUNT_FULL to
    INT_MIN/2, change the type of integer operands passed into the API
    from 'unsigned int' to 'int' so that we can avoid casting during
    comparisons when we don't want to fall foul of C integral conversion
    rules for signed and unsigned types.

    Since the kernel is compiled with '-fno-strict-overflow', we don't need
    to worry about the UB introduced by signed overflow here. Furthermore,
    we're already making heavy use of the atomic_t API, which operates
    exclusively on signed types.

    Signed-off-by: Will Deacon
    Reviewed-by: Ard Biesheuvel
    Reviewed-by: Kees Cook
    Tested-by: Hanjun Guo
    Cc: Ard Biesheuvel
    Cc: Elena Reshetova
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: https://lkml.kernel.org/r/20191121115902.2551-3-will@kernel.org
    Signed-off-by: Ingo Molnar

    Will Deacon
     
  • The REFCOUNT_FULL implementation uses a different saturation point than
    the x86 implementation, which means that the shared refcount code in
    lib/refcount.c (e.g. refcount_dec_not_one()) needs to be aware of the
    difference.

    Rather than duplicate the definitions from the lkdtm driver, instead
    move them into and update all references accordingly.

    Signed-off-by: Will Deacon
    Reviewed-by: Ard Biesheuvel
    Reviewed-by: Kees Cook
    Tested-by: Hanjun Guo
    Cc: Ard Biesheuvel
    Cc: Elena Reshetova
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: https://lkml.kernel.org/r/20191121115902.2551-2-will@kernel.org
    Signed-off-by: Ingo Molnar

    Will Deacon
     

04 Feb, 2019

1 commit

  • This adds an smp_acquire__after_ctrl_dep() barrier on successful
    decrease of refcounter value from 1 to 0 for refcount_dec(sub)_and_test
    variants and therefore gives stronger memory ordering guarantees than
    prior versions of these functions.

    Co-developed-by: Peter Zijlstra (Intel)
    Signed-off-by: Elena Reshetova
    Signed-off-by: Peter Zijlstra (Intel)
    Reviewed-by: Andrea Parri
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Paul E. McKenney
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Will Deacon
    Cc: dvyukov@google.com
    Cc: keescook@chromium.org
    Cc: stern@rowland.harvard.edu
    Link: https://lkml.kernel.org/r/1548847131-27854-2-git-send-email-elena.reshetova@intel.com
    Signed-off-by: Ingo Molnar

    Elena Reshetova
     

17 Jul, 2018

1 commit


13 Jul, 2018

1 commit

  • 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
    Reviewed-by: David Sterba
    Acked-by: Kees Cook
    Acked-by: Will Deacon
    Cc: Boqun Feng
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/20180711093607.1644-1-mark.rutland@arm.com
    Signed-off-by: Ingo Molnar

    Mark Rutland
     

22 Jun, 2018

1 commit

  • Debloat 's dependencies:

    - is not needed, but is.
    - is not needed, only a forward declaration of "struct mutex".
    - is not needed, is enough.

    Signed-off-by: Alexey Dobriyan
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Paul E. McKenney
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Will Deacon
    Link: https://lkml.kernel.org/lkml/20180331220036.GA7676@avx2
    Signed-off-by: Ingo Molnar

    Alexey Dobriyan
     

13 Jun, 2018

1 commit

  • There are in-tree users of refcount_dec_and_lock() which must acquire the
    spin lock with interrupts disabled. To workaround the lack of an irqsave
    variant of refcount_dec_and_lock() they use local_irq_save() at the call
    site. This causes extra code and creates in some places unneeded long
    interrupt disabled times. These places need also extra treatment for
    PREEMPT_RT due to the disconnect of the irq disabling and the lock
    function.

    Implement the missing irqsave variant of the function.

    Signed-off-by: Anna-Maria Gleixner
    Signed-off-by: Sebastian Andrzej Siewior
    Signed-off-by: Thomas Gleixner
    Acked-by: Peter Zijlstra (Intel)
    Link: https://lkml.kernel.org/r20180612161621.22645-4-bigeasy@linutronix.de

    [bigeasy: s@atomic_dec_and_lock@refcount_dec_and_lock@g]

    Anna-Maria Gleixner
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

29 Jun, 2017

1 commit

  • Many subsystems will not use refcount_t unless there is a way to build the
    kernel so that there is no regression in speed compared to atomic_t. This
    adds CONFIG_REFCOUNT_FULL to enable the full refcount_t implementation
    which has the validation but is slightly slower. When not enabled,
    refcount_t uses the basic unchecked atomic_t routines, which results in
    no code changes compared to just using atomic_t directly.

    Signed-off-by: Kees Cook
    Acked-by: Greg Kroah-Hartman
    Cc: Alexey Dobriyan
    Cc: Andrew Morton
    Cc: Arnd Bergmann
    Cc: Christoph Hellwig
    Cc: David S. Miller
    Cc: David Windsor
    Cc: Davidlohr Bueso
    Cc: Elena Reshetova
    Cc: Eric Biggers
    Cc: Eric W. Biederman
    Cc: Hans Liljestrand
    Cc: James Bottomley
    Cc: Jann Horn
    Cc: Josh Poimboeuf
    Cc: Linus Torvalds
    Cc: Manfred Spraul
    Cc: Peter Zijlstra
    Cc: Rik van Riel
    Cc: Serge E. Hallyn
    Cc: Thomas Gleixner
    Cc: arozansk@redhat.com
    Cc: axboe@kernel.dk
    Cc: linux-arch
    Link: http://lkml.kernel.org/r/20170621200026.GA115679@beast
    Signed-off-by: Ingo Molnar

    Kees Cook
     

07 May, 2017

1 commit

  • Now that kref is using the refcount apis, the _GPL markings are getting
    exported to places that it previously wasn't. Now kref.h is GPLv2
    licensed, so any non-GPL code using it better be talking to some
    lawyers, but changing api markings isn't considered "nice", so let's fix
    this up.

    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Linus Torvalds

    Greg Kroah-Hartman
     

23 Mar, 2017

1 commit

  • Generates better code (GCC-6.2.1):

    text filename
    1576 defconfig-build/lib/refcount.o.pre
    1488 defconfig-build/lib/refcount.o.post

    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Andrew Morton
    Cc: Andy Lutomirski
    Cc: Borislav Petkov
    Cc: Brian Gerst
    Cc: Denys Vlasenko
    Cc: H. Peter Anvin
    Cc: Josh Poimboeuf
    Cc: Linus Torvalds
    Cc: Paul E. McKenney
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

13 Mar, 2017

1 commit


01 Mar, 2017

1 commit

  • Linus noticed that the new refcount.h APIs used WARN(), which would turn
    into a dmesg DoS if it triggers frequently on some buggy driver.

    So make sure we only warn once. These warnings are never supposed to happen,
    so it's typically not a problem to lose subsequent warnings.

    Suggested-by: Linus Torvalds
    Cc: Peter Zijlstra (Intel)
    Cc: Elena Reshetova
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/CA+55aFzbYUTZ=oqZ2YgDjY0C2_n6ODhTfqj6V+m5xWmDxsuB0w@mail.gmail.com
    Signed-off-by: Ingo Molnar

    Ingo Molnar
     

24 Feb, 2017

1 commit

  • Linus asked to please make this real C code.

    And since size then isn't an issue what so ever anymore, remove the
    debug knob and make all WARN()s unconditional.

    Suggested-by: Linus Torvalds
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: dwindsor@gmail.com
    Cc: elena.reshetova@intel.com
    Cc: gregkh@linuxfoundation.org
    Cc: ishkamiel@gmail.com
    Cc: keescook@chromium.org
    Signed-off-by: Ingo Molnar

    Peter Zijlstra