08 Jul, 2021

1 commit

  • cpumap needs to set, clear, and test the lowest bit in skb pointer in
    various places. To make these checks less noisy, add pointer friendly
    bitop macros that also do some typechecking to sanitize the argument.

    These wrap the non-atomic bitops __set_bit, __clear_bit, and test_bit
    but for pointer arguments. Pointer's address has to be passed in and it
    is treated as an unsigned long *, since width and representation of
    pointer and unsigned long match on targets Linux supports. They are
    prefixed with double underscore to indicate lack of atomicity.

    Signed-off-by: Kumar Kartikeya Dwivedi
    Signed-off-by: Alexei Starovoitov
    Reviewed-by: Toke Høiland-Jørgensen
    Link: https://lore.kernel.org/bpf/20210702111825.491065-3-memxor@gmail.com

    Kumar Kartikeya Dwivedi
     

07 May, 2021

1 commit

  • Similarly to bitmap functions, users would benefit if we'll handle a case
    of small-size bitmaps that fit into a single word.

    While here, move the find_last_bit() declaration to bitops/find.h where
    other find_*_bit() functions sit.

    Link: https://lkml.kernel.org/r/20210401003153.97325-11-yury.norov@gmail.com
    Signed-off-by: Yury Norov
    Acked-by: Rasmus Villemoes
    Acked-by: Andy Shevchenko
    Cc: Alexey Klimov
    Cc: Arnd Bergmann
    Cc: David Sterba
    Cc: Dennis Zhou
    Cc: Geert Uytterhoeven
    Cc: Jianpeng Ma
    Cc: Joe Perches
    Cc: John Paul Adrian Glaubitz
    Cc: Josh Poimboeuf
    Cc: Rich Felker
    Cc: Stefano Brivio
    Cc: Wei Yang
    Cc: Wolfram Sang
    Cc: Yoshinori Sato
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yury Norov
     

27 Feb, 2021

1 commit


16 Dec, 2020

1 commit

  • kernel.h is being used as a dump for all kinds of stuff for a long time.
    Here is the attempt to start cleaning it up by splitting out
    mathematical helpers.

    At the same time convert users in header and lib folder to use new
    header. Though for time being include new header back to kernel.h to
    avoid twisted indirected includes for existing users.

    [sfr@canb.auug.org.au: fix powerpc build]
    Link: https://lkml.kernel.org/r/20201029150809.13059608@canb.auug.org.au

    Link: https://lkml.kernel.org/r/20201028173212.41768-1-andriy.shevchenko@linux.intel.com
    Signed-off-by: Andy Shevchenko
    Cc: "Paul E. McKenney"
    Cc: Trond Myklebust
    Cc: Jeff Layton
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     

17 Oct, 2020

2 commits


05 Jun, 2020

1 commit

  • Clang normally does not warn about certain issues in inline functions when
    it only happens in an eliminated code path. However if something else
    goes wrong, it does tend to complain about the definition of hweight_long()
    on 32-bit targets:

    include/linux/bitops.h:75:41: error: shift count >= width of type [-Werror,-Wshift-count-overflow]
    return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
    ^~~~~~~~~~~~
    include/asm-generic/bitops/const_hweight.h:29:49: note: expanded from macro 'hweight64'
    define hweight64(w) (__builtin_constant_p(w) ? __const_hweight64(w) : __arch_hweight64(w))
    ^~~~~~~~~~~~~~~~~~~~
    include/asm-generic/bitops/const_hweight.h:21:76: note: expanded from macro '__const_hweight64'
    define __const_hweight64(w) (__const_hweight32(w) + __const_hweight32((w) >> 32))
    ^ ~~
    include/asm-generic/bitops/const_hweight.h:20:49: note: expanded from macro '__const_hweight32'
    define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16))
    ^
    include/asm-generic/bitops/const_hweight.h:19:72: note: expanded from macro '__const_hweight16'
    define __const_hweight16(w) (__const_hweight8(w) + __const_hweight8((w) >> 8 ))
    ^
    include/asm-generic/bitops/const_hweight.h:12:9: note: expanded from macro '__const_hweight8'
    (!!((w) & (1ULL << 2))) + \

    Adding an explicit cast to __u64 avoids that warning and makes it easier
    to read other output.

    Signed-off-by: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Acked-by: Christian Brauner
    Cc: Andy Shevchenko
    Cc: Rasmus Villemoes
    Cc: Josh Poimboeuf
    Cc: Nick Desaulniers
    Link: http://lkml.kernel.org/r/20200505135513.65265-1-arnd@arndb.de
    Signed-off-by: Linus Torvalds

    Arnd Bergmann
     

08 Apr, 2020

1 commit

  • With CONFIG_CC_OPTIMIZE_FOR_SIZE, objtool reports:

    drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: i915_gem_execbuffer2_ioctl()+0x5b7: call to gen8_canonical_addr() with UACCESS enabled

    This means i915_gem_execbuffer2_ioctl() is calling gen8_canonical_addr()
    from the user_access_begin/end critical region (i.e, with SMAP disabled).

    While it's probably harmless in this case, in general we like to avoid
    extra function calls in SMAP-disabled regions because it can open up
    inadvertent security holes.

    Fix the warning by changing the sign extension helpers to __always_inline.
    This convinces GCC to inline gen8_canonical_addr().

    The sign extension functions are trivial anyway, so it makes sense to
    always inline them. With my test optimize-for-size-based config, this
    actually shrinks the text size of i915_gem_execbuffer.o by 45 bytes -- and
    no change for vmlinux.

    Reported-by: Randy Dunlap
    Signed-off-by: Josh Poimboeuf
    Signed-off-by: Andrew Morton
    Cc: Peter Zijlstra
    Cc: Al Viro
    Cc: Chris Wilson
    Link: http://lkml.kernel.org/r/740179324b2b18b750b16295c48357f00b5fa9ed.1582982020.git.jpoimboe@redhat.com
    Signed-off-by: Linus Torvalds

    Josh Poimboeuf
     

04 Feb, 2020

1 commit

  • Introduce BITS_TO_U64, BITS_TO_U32 and BITS_TO_BYTES as they are handy in
    the following patches (BITS_TO_U32 specifically). Reimplement tools/
    version of the macros according to the kernel implementation.

    Also fix indentation for BITS_PER_TYPE definition.

    Link: http://lkml.kernel.org/r/20200102043031.30357-3-yury.norov@gmail.com
    Signed-off-by: Yury Norov
    Reviewed-by: Andy Shevchenko
    Cc: Amritha Nambiar
    Cc: Arnaldo Carvalho de Melo
    Cc: Chris Wilson
    Cc: Kees Cook
    Cc: Matthew Wilcox
    Cc: Miklos Szeredi
    Cc: Rasmus Villemoes
    Cc: Steffen Klassert
    Cc: "Tobin C . Harding"
    Cc: Vineet Gupta
    Cc: Will Deacon
    Cc: Willem de Bruijn
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yury Norov
     

01 Feb, 2020

1 commit

  • There are users already and will be more of BITS_TO_BYTES() macro. Move
    it to bitops.h for wider use.

    In the case of ocfs2 the replacement is identical.

    As for bnx2x, there are two places where floor version is used. In the
    first case to calculate the amount of structures that can fit one memory
    page. In this case obviously the ceiling variant is correct and
    original code might have a potential bug, if amount of bits % 8 is not
    0. In the second case the macro is used to calculate bytes transmitted
    in one microsecond. This will work for all speeds which is multiply of
    1Gbps without any change, for the rest new code will give ceiling value,
    for instance 100Mbps will give 13 bytes, while old code gives 12 bytes
    and the arithmetically correct one is 12.5 bytes. Further the value is
    used to setup timer threshold which in any case has its own margins due
    to certain resolution. I don't see here an issue with slightly shifting
    thresholds for low speed connections, the card is supposed to utilize
    highest available rate, which is usually 10Gbps.

    Link: http://lkml.kernel.org/r/20200108121316.22411-1-andriy.shevchenko@linux.intel.com
    Signed-off-by: Andy Shevchenko
    Reviewed-by: Joseph Qi
    Acked-by: Sudarsana Reddy Kalluru
    Cc: Mark Fasheh
    Cc: Joel Becker
    Cc: Junxiao Bi
    Cc: Changwei Ge
    Cc: Gang He
    Cc: Jun Piao
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     

05 Dec, 2019

1 commit

  • Pach series "Introduce the for_each_set_clump8 macro", v18.

    While adding GPIO get_multiple/set_multiple callback support for various
    drivers, I noticed a pattern of looping manifesting that would be useful
    standardized as a macro.

    This patchset introduces the for_each_set_clump8 macro and utilizes it
    in several GPIO drivers. The for_each_set_clump macro8 facilitates a
    for-loop syntax that iterates over a memory region entire groups of set
    bits at a time.

    For example, suppose you would like to iterate over a 32-bit integer 8
    bits at a time, skipping over 8-bit groups with no set bit, where
    XXXXXXXX represents the current 8-bit group:

    Example: 10111110 00000000 11111111 00110011
    First loop: 10111110 00000000 11111111 XXXXXXXX
    Second loop: 10111110 00000000 XXXXXXXX 00110011
    Third loop: XXXXXXXX 00000000 11111111 00110011

    Each iteration of the loop returns the next 8-bit group that has at
    least one set bit.

    The for_each_set_clump8 macro has four parameters:

    * start: set to the bit offset of the current clump
    * clump: set to the current clump value
    * bits: bitmap to search within
    * size: bitmap size in number of bits

    In this version of the patchset, the for_each_set_clump macro has been
    reimplemented and simplified based on the suggestions provided by Rasmus
    Villemoes and Andy Shevchenko in the version 4 submission.

    In particular, the function of the for_each_set_clump macro has been
    restricted to handle only 8-bit clumps; the drivers that use the
    for_each_set_clump macro only handle 8-bit ports so a generic
    for_each_set_clump implementation is not necessary. Thus, a solution
    for large clumps (i.e. those larger than the width of a bitmap word)
    can be postponed until a driver appears that actually requires such a
    generic for_each_set_clump implementation.

    For what it's worth, a semi-generic for_each_set_clump (i.e. for clumps
    smaller than the width of a bitmap word) can be implemented by simply
    replacing the hardcoded '8' and '0xFF' instances with respective
    variables. I have not yet had a need for such an implementation, and
    since it falls short of a true generic for_each_set_clump function, I
    have decided to forgo such an implementation for now.

    In addition, the bitmap_get_value8 and bitmap_set_value8 functions are
    introduced to get and set 8-bit values respectively. Their use is based
    on the behavior suggested in the patchset version 4 review.

    This patch (of 14):

    This macro iterates for each 8-bit group of bits (clump) with set bits,
    within a bitmap memory region. For each iteration, "start" is set to
    the bit offset of the found clump, while the respective clump value is
    stored to the location pointed by "clump". Additionally, the
    bitmap_get_value8 and bitmap_set_value8 functions are introduced to
    respectively get and set an 8-bit value in a bitmap memory region.

    [gustavo@embeddedor.com: fix potential sign-extension overflow]
    Link: http://lkml.kernel.org/r/20191015184657.GA26541@embeddedor
    [akpm@linux-foundation.org: s/ULL/UL/, per Joe]
    [vilhelm.gray@gmail.com: add for_each_set_clump8 documentation]
    Link: http://lkml.kernel.org/r/20191016161825.301082-1-vilhelm.gray@gmail.com
    Link: http://lkml.kernel.org/r/893c3b4f03266c9496137cc98ac2b1bd27f92c73.1570641097.git.vilhelm.gray@gmail.com
    Signed-off-by: William Breathitt Gray
    Signed-off-by: Gustavo A. R. Silva
    Suggested-by: Andy Shevchenko
    Suggested-by: Rasmus Villemoes
    Suggested-by: Lukas Wunner
    Tested-by: Andy Shevchenko
    Cc: Arnd Bergmann
    Cc: Linus Walleij
    Cc: Bartosz Golaszewski
    Cc: Masahiro Yamada
    Cc: Geert Uytterhoeven
    Cc: Phil Reid
    Cc: Geert Uytterhoeven
    Cc: Mathias Duckeck
    Cc: Morten Hein Tiljeset
    Cc: Sean Nyekjaer
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    William Breathitt Gray
     

01 Oct, 2019

1 commit

  • A common pattern for syscall extensions is increasing the size of a
    struct passed from userspace, such that the zero-value of the new fields
    result in the old kernel behaviour (allowing for a mix of userspace and
    kernel vintages to operate on one another in most cases).

    While this interface exists for communication in both directions, only
    one interface is straightforward to have reasonable semantics for
    (userspace passing a struct to the kernel). For kernel returns to
    userspace, what the correct semantics are (whether there should be an
    error if userspace is unaware of a new extension) is very
    syscall-dependent and thus probably cannot be unified between syscalls
    (a good example of this problem is [1]).

    Previously there was no common lib/ function that implemented
    the necessary extension-checking semantics (and different syscalls
    implemented them slightly differently or incompletely[2]). Future
    patches replace common uses of this pattern to make use of
    copy_struct_from_user().

    Some in-kernel selftests that insure that the handling of alignment and
    various byte patterns are all handled identically to memchr_inv() usage.

    [1]: commit 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and
    robustify sched_read_attr() ABI logic and code")

    [2]: For instance {sched_setattr,perf_event_open,clone3}(2) all do do
    similar checks to copy_struct_from_user() while rt_sigprocmask(2)
    always rejects differently-sized struct arguments.

    Suggested-by: Rasmus Villemoes
    Signed-off-by: Aleksa Sarai
    Reviewed-by: Kees Cook
    Reviewed-by: Christian Brauner
    Link: https://lore.kernel.org/r/20191001011055.19283-2-cyphar@cyphar.com
    Signed-off-by: Christian Brauner

    Aleksa Sarai
     

15 May, 2019

1 commit

  • The ror32 implementation (word >> shift) | (word << (32 - shift) has
    undefined behaviour if shift is outside the [1, 31] range. Similarly
    for the 64 bit variants. Most callers pass a compile-time constant
    (naturally in that range), but there's an UBSAN report that these may
    actually be called with a shift count of 0.

    Instead of special-casing that, we can make them DTRT for all values of
    shift while also avoiding UB. For some reason, this was already partly
    done for rol32 (which was well-defined for [0, 31]). gcc 8 recognizes
    these patterns as rotates, so for example

    __u32 rol32(__u32 word, unsigned int shift)
    {
    return (word << (shift & 31)) | (word >> ((-shift) & 31));
    }

    compiles to

    0000000000000020 :
    20: 89 f8 mov %edi,%eax
    22: 89 f1 mov %esi,%ecx
    24: d3 c0 rol %cl,%eax
    26: c3 retq

    Older compilers unfortunately do not do as well, but this only affects
    the small minority of users that don't pass constants.

    Due to integer promotions, ro[lr]8 were already well-defined for shifts
    in [0, 8], and ro[lr]16 were mostly well-defined for shifts in [0, 16]
    (only mostly - u16 gets promoted to _signed_ int, so if bit 15 is set,
    word << 16 is undefined). For consistency, update those as well.

    Link: http://lkml.kernel.org/r/20190410211906.2190-1-linux@rasmusvillemoes.dk
    Signed-off-by: Rasmus Villemoes
    Reported-by: Ido Schimmel
    Tested-by: Ido Schimmel
    Reviewed-by: Will Deacon
    Cc: Vadim Pasternak
    Cc: Andrey Ryabinin
    Cc: Jacek Anaszewski
    Cc: Pavel Machek
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     

08 Mar, 2019

1 commit

  • | > Also, set_mask_bits is used in fs quite a bit and we can possibly come up
    | > with a generic llsc based implementation (w/o the cmpxchg loop)
    |
    | May I also suggest changing the return value of set_mask_bits() to old.
    |
    | You can compute the new value given old, but you cannot compute the old
    | value given new, therefore old is the better return value. Also, no
    | current user seems to use the return value, so changing it is without
    | risk.

    Link: http://lkml.kernel.org/g/20150807110955.GH16853@twins.programming.kicks-ass.net
    Link: http://lkml.kernel.org/r/1548275584-18096-4-git-send-email-vgupta@synopsys.com
    Signed-off-by: Vineet Gupta
    Suggested-by: Peter Zijlstra
    Reviewed-by: Anthony Yznaga
    Acked-by: Will Deacon
    Cc: Miklos Szeredi
    Cc: Ingo Molnar
    Cc: Jani Nikula
    Cc: Chris Wilson
    Cc: Alexander Viro
    Cc: Oleg Nesterov
    Cc: Theodore Ts'o
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Vineet Gupta
     

15 Oct, 2018

2 commits

  • Unprotected naming of local variables within bit_clear_unless() can easily
    lead to using the wrong scope.

    Noticed this by code review after having hit this issue in set_mask_bits()

    Signed-off-by: Miklos Szeredi
    Fixes: 85ad1d13ee9b ("md: set MD_CHANGE_PENDING in a atomic region")
    Cc: Guoqing Jiang

    Miklos Szeredi
     
  • Unprotected naming of local variables within the set_mask_bits() can easily
    lead to using the wrong scope.

    Noticed this when "set_mask_bits(&foo->bar, 0, mask)" behaved as no-op.

    Signed-off-by: Miklos Szeredi
    Fixes: 00a1a053ebe5 ("ext4: atomically set inode->i_flags in ext4_set_inode_flags()")
    Cc: Theodore Ts'o

    Miklos Szeredi
     

23 Aug, 2018

1 commit

  • net_dim.h has a rather useful extension to BITS_PER_BYTE to compute the
    number of bits in a type (BITS_PER_BYTE * sizeof(T)), so promote the macro
    to bitops.h, alongside BITS_PER_BYTE, for wider usage.

    Link: http://lkml.kernel.org/r/20180706094458.14116-1-chris@chris-wilson.co.uk
    Signed-off-by: Chris Wilson
    Reviewed-by: Jani Nikula
    Cc: Randy Dunlap
    Cc: Andy Gospodarek
    Cc: David S. Miller
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Chris Wilson
     

21 Jun, 2018

1 commit

  • In preparation for implementing the asm-generic atomic bitops in terms
    of atomic_long_*(), we need to prevent implementations from
    pulling in . A common reason for this include is for the
    BITS_PER_BYTE definition, so move this and some other BIT() and masking
    macros into a new header file, .

    Signed-off-by: Will Deacon
    Acked-by: Peter Zijlstra (Intel)
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: linux-arm-kernel@lists.infradead.org
    Cc: yamada.masahiro@socionext.com
    Link: https://lore.kernel.org/lkml/1529412794-17720-4-git-send-email-will.deacon@arm.com
    Signed-off-by: Ingo Molnar

    Will Deacon
     

15 Nov, 2017

1 commit

  • Pull GPIO updates from Linus Walleij:
    "This is the bulk of GPIO changes for the v4.15 kernel cycle:

    Core:

    - Fix the semantics of raw GPIO to actually be raw. No inversion
    semantics as before, but also no open draining, and allow the raw
    operations to affect lines used for interrupts as the caller
    supposedly knows what they are doing if they are getting the big
    hammer.

    - Rewrote the __inner_function() notation calls to names that make
    more sense. I just find this kind of code disturbing.

    - Drop the .irq_base() field from the gpiochip since now all IRQs are
    mapped dynamically. This is nice.

    - Support for .get_multiple() in the core driver API. This allows us
    to read several GPIO lines with a single register read. This has
    high value for some usecases: it can be used to create
    oscilloscopes and signal analyzers and other things that rely on
    reading several lines at exactly the same instant. Also a generally
    nice optimization. This uses the new assign_bit() macro from the
    bitops lib that was ACKed by Andrew Morton and is implemented for
    two drivers, one of them being the generic MMIO driver so everyone
    using that will be able to benefit from this.

    - Do not allow requests of Open Drain and Open Source setting of a
    GPIO line simultaneously. If the hardware actually supports
    enabling both at the same time the electrical result would be
    disastrous.

    - A new interrupt chip core helper. This will be helpful to deal with
    "banked" GPIOs, which means GPIO controllers with several logical
    blocks of GPIO inside them. This is several gpiochips per device in
    the device model, in contrast to the case when there is a 1-to-1
    relationship between a device and a gpiochip.

    New drivers:

    - Maxim MAX3191x industrial serializer, a very interesting piece of
    professional I/O hardware.

    - Uniphier GPIO driver. This is the GPIO block from the recent
    Socionext (ex Fujitsu and Panasonic) platform.

    - Tegra 186 driver. This is based on the new banked GPIO
    infrastructure.

    Other improvements:

    - Some documentation improvements.

    - Wakeup support for the DesignWare DWAPB GPIO controller.

    - Reset line support on the DesignWare DWAPB GPIO controller.

    - Several non-critical bug fixes and improvements for the Broadcom
    BRCMSTB driver.

    - Misc non-critical bug fixes like exotic errorpaths, removal of dead
    code etc.

    - Explicit comments on fall-through switch() statements"

    * tag 'gpio-v4.15-1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (65 commits)
    gpio: tegra186: Remove tegra186_gpio_lock_class
    gpio: rcar: Add r8a77995 (R-Car D3) support
    pinctrl: bcm2835: Fix some merge fallout
    gpio: Fix undefined lock_dep_class
    gpio: Automatically add lockdep keys
    gpio: Introduce struct gpio_irq_chip.first
    gpio: Disambiguate struct gpio_irq_chip.nested
    gpio: Add Tegra186 support
    gpio: Export gpiochip_irq_{map,unmap}()
    gpio: Implement tighter IRQ chip integration
    gpio: Move lock_key into struct gpio_irq_chip
    gpio: Move irq_valid_mask into struct gpio_irq_chip
    gpio: Move irq_nested into struct gpio_irq_chip
    gpio: Move irq_chained_parent to struct gpio_irq_chip
    gpio: Move irq_default_type to struct gpio_irq_chip
    gpio: Move irq_handler to struct gpio_irq_chip
    gpio: Move irqdomain into struct gpio_irq_chip
    gpio: Move irqchip into struct gpio_irq_chip
    gpio: Introduce struct gpio_irq_chip
    pinctrl: armada-37xx: remove unused variable
    ...

    Linus Torvalds
     

07 Nov, 2017

1 commit


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
     

25 Oct, 2017

1 commit

  • …READ_ONCE()/WRITE_ONCE()

    Please do not apply this to mainline directly, instead please re-run the
    coccinelle script shown below and apply its output.

    For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
    preference to ACCESS_ONCE(), and new code is expected to use one of the
    former. So far, there's been no reason to change most existing uses of
    ACCESS_ONCE(), as these aren't harmful, and changing them results in
    churn.

    However, for some features, the read/write distinction is critical to
    correct operation. To distinguish these cases, separate read/write
    accessors must be used. This patch migrates (most) remaining
    ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
    coccinelle script:

    ----
    // Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
    // WRITE_ONCE()

    // $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch

    virtual patch

    @ depends on patch @
    expression E1, E2;
    @@

    - ACCESS_ONCE(E1) = E2
    + WRITE_ONCE(E1, E2)

    @ depends on patch @
    expression E;
    @@

    - ACCESS_ONCE(E)
    + READ_ONCE(E)
    ----

    Signed-off-by: Mark Rutland <mark.rutland@arm.com>
    Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: davem@davemloft.net
    Cc: linux-arch@vger.kernel.org
    Cc: mpe@ellerman.id.au
    Cc: shuah@kernel.org
    Cc: snitzer@redhat.com
    Cc: thor.thayer@linux.intel.com
    Cc: tj@kernel.org
    Cc: viro@zeniv.linux.org.uk
    Cc: will.deacon@arm.com
    Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com
    Signed-off-by: Ingo Molnar <mingo@kernel.org>

    Mark Rutland
     

20 Oct, 2017

1 commit

  • A common idiom is to assign a value to a bit with:

    if (value)
    set_bit(nr, addr);
    else
    clear_bit(nr, addr);

    Likewise common is the one-line expression variant:

    value ? set_bit(nr, addr) : clear_bit(nr, addr);

    Commit 9a8ac3ae682e ("dm mpath: cleanup QUEUE_IF_NO_PATH bit
    manipulation by introducing assign_bit()") introduced assign_bit()
    to the md subsystem for brevity.

    Make it available to others, specifically gpiolib and the upcoming
    driver for Maxim MAX3191x industrial serializer chips.

    As requested by Peter Zijlstra, change the argument order to reflect
    traditional "dst = src" in C, hence "assign_bit(nr, addr, value)".

    Cc: Bart Van Assche
    Cc: Alasdair Kergon
    Cc: Mike Snitzer
    Cc: Linus Walleij
    Cc: Neil Brown
    Cc: Peter Zijlstra
    Cc: Ingo Molnar
    Cc: Theodore Ts'o
    Cc: Borislav Petkov
    Cc: "H. Peter Anvin"
    Cc: Denys Vlasenko
    Acked-by: Andrew Morton
    Signed-off-by: Lukas Wunner
    Signed-off-by: Linus Walleij

    Lukas Wunner
     

09 Sep, 2017

1 commit

  • GENMASK(_ULL) performs a left-shift of ~0UL(L), which technically
    results in an integer overflow. clang raises a warning if the overflow
    occurs in a preprocessor expression. Clear the low-order bits through a
    substraction instead of the left-shift to avoid the overflow.

    (akpm: no change in .text size in my testing)

    Link: http://lkml.kernel.org/r/20170803212020.24939-1-mka@chromium.org
    Signed-off-by: Matthias Kaehlcke
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Matthias Kaehlcke
     

08 Oct, 2016

1 commit

  • It causes double align requirement for __get_vm_area_node() if parameter
    size is power of 2 and VM_IOREMAP is set in parameter flags, for example
    size=0x10000 -> fls_long(0x10000)=17 -> align=0x20000

    get_count_order_long() is implemented and can be used instead of
    fls_long() for fixing the bug, for example size=0x10000 ->
    get_count_order_long(0x10000)=16 -> align=0x10000

    [akpm@linux-foundation.org: s/get_order_long()/get_count_order_long()/]
    [zijun_hu@zoho.com: fixes]
    Link: http://lkml.kernel.org/r/57AABC8B.1040409@zoho.com
    [akpm@linux-foundation.org: locate get_count_order_long() next to get_count_order()]
    [akpm@linux-foundation.org: move get_count_order[_long] definitions to pick up fls_long()]
    [zijun_hu@htc.com: move out get_count_order[_long]() from __KERNEL__ scope]
    Link: http://lkml.kernel.org/r/57B2C4CE.80303@zoho.com
    Link: http://lkml.kernel.org/r/fc045ecf-20fa-0722-b3ac-9a6140488fad@zoho.com
    Signed-off-by: zijun_hu
    Cc: Tejun Heo
    Cc: Johannes Weiner
    Cc: Minchan Kim
    Cc: David Rientjes
    Signed-off-by: zijun_hu
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    zijun_hu
     

10 May, 2016

1 commit

  • Some code waits for a metadata update by:

    1. flagging that it is needed (MD_CHANGE_DEVS or MD_CHANGE_CLEAN)
    2. setting MD_CHANGE_PENDING and waking the management thread
    3. waiting for MD_CHANGE_PENDING to be cleared

    If the first two are done without locking, the code in md_update_sb()
    which checks if it needs to repeat might test if an update is needed
    before step 1, then clear MD_CHANGE_PENDING after step 2, resulting
    in the wait returning early.

    So make sure all places that set MD_CHANGE_PENDING are atomicial, and
    bit_clear_unless (suggested by Neil) is introduced for the purpose.

    Cc: Martin Kepplinger
    Cc: Andrew Morton
    Cc: Denys Vlasenko
    Cc: Sasha Levin
    Cc:
    Reviewed-by: NeilBrown
    Signed-off-by: Guoqing Jiang
    Signed-off-by: Shaohua Li

    Guoqing Jiang
     

10 Dec, 2015

1 commit

  • ROL on a 32 bit integer with a shift of 32 or more is undefined and the
    result is arch-dependent. Avoid this by handling the trivial case of
    roling by 0 correctly.

    The trivial solution of checking if shift is 0 breaks gcc's detection
    of this code as a ROL instruction, which is unacceptable.

    This bug was reported and fixed in GCC
    (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57157):

    The standard rotate idiom,

    (x << n) | (x >> (32 - n))

    is recognized by gcc (for concreteness, I discuss only the case that x
    is an uint32_t here).

    However, this is portable C only for n in the range 0 < n < 32. For n
    == 0, we get x >> 32 which gives undefined behaviour according to the
    C standard (6.5.7, Bitwise shift operators). To portably support n ==
    0, one has to write the rotate as something like

    (x << n) | (x >> ((-n) & 31))

    And this is apparently not recognized by gcc.

    Note that this is broken on older GCCs and will result in slower ROL.

    Acked-by: Linus Torvalds
    Signed-off-by: Sasha Levin
    Signed-off-by: Linus Torvalds

    Sasha Levin
     

07 Nov, 2015

2 commits

  • Months back, this was discussed, see https://lkml.org/lkml/2015/1/18/289
    The result was the 64-bit version being "likely fine", "valuable" and
    "correct". The discussion fell asleep but since there are possible users,
    let's add it.

    Signed-off-by: Martin Kepplinger
    Cc: Peter Zijlstra
    Cc: Ingo Molnar
    Cc: Arnaldo Carvalho de Melo
    Cc: Thomas Gleixner
    Cc: "H. Peter Anvin"
    Cc: George Spelvin
    Cc: Rasmus Villemoes
    Cc: Maxime Coquelin
    Cc: Denys Vlasenko
    Cc: Yury Norov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Martin Kepplinger
     
  • It is often overlooked that sign_extend32(), despite its name, is safe to
    use for 16 and 8 bit types as well. This should help prevent sign
    extension being done manually some other way.

    Signed-off-by: Martin Kepplinger
    Cc: Peter Zijlstra
    Cc: Ingo Molnar
    Cc: Arnaldo Carvalho de Melo
    Cc: Thomas Gleixner
    Cc: "H. Peter Anvin"
    Cc: George Spelvin
    Cc: Rasmus Villemoes
    Cc: Maxime Coquelin
    Cc: Denys Vlasenko
    Cc: Yury Norov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Martin Kepplinger
     

05 Aug, 2015

1 commit

  • With this config:

    http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os

    gcc-4.7.2 generates many copies of these tiny functions:

    bitmap_weight (55 copies):
    55 push %rbp
    48 89 e5 mov %rsp,%rbp
    e8 3f 3a 8b 00 callq __bitmap_weight
    5d pop %rbp
    c3 retq

    hweight_long (23 copies):
    55 push %rbp
    e8 b5 65 8e 00 callq __sw_hweight64
    48 89 e5 mov %rsp,%rbp
    5d pop %rbp
    c3 retq

    See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

    This patch fixes this via s/inline/__always_inline/

    While at it, replaced two "__inline__" with usual "inline"
    (the rest of the source file uses the latter).

    text data bss dec filename
    86971357 17195880 36659200 140826437 vmlinux.before
    86971120 17195912 36659200 140826232 vmlinux

    Signed-off-by: Denys Vlasenko
    Cc: Andrew Morton
    Cc: David Rientjes
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Thomas Graf
    Cc: linux-kernel@vger.kernel.org
    Link: http://lkml.kernel.org/r/1438697716-28121-1-git-send-email-dvlasenk@redhat.com
    Signed-off-by: Ingo Molnar

    Denys Vlasenko
     

17 Apr, 2015

1 commit

  • This patchset does rework to find_bit function family to achieve better
    performance, and decrease size of text. All rework is done in patch 1.
    Patches 2 and 3 are about code moving and renaming.

    It was boot-tested on x86_64 and MIPS (big-endian) machines.
    Performance tests were ran on userspace with code like this:

    /* addr[] is filled from /dev/urandom */
    start = clock();
    while (ret < nbits)
    ret = find_next_bit(addr, nbits, ret + 1);

    end = clock();
    printf("%ld\t", (unsigned long) end - start);

    On Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz measurements are: (for
    find_next_bit, nbits is 8M, for find_first_bit - 80K)

    find_next_bit: find_first_bit:
    new current new current
    26932 43151 14777 14925
    26947 43182 14521 15423
    26507 43824 15053 14705
    27329 43759 14473 14777
    26895 43367 14847 15023
    26990 43693 15103 15163
    26775 43299 15067 15232
    27282 42752 14544 15121
    27504 43088 14644 14858
    26761 43856 14699 15193
    26692 43075 14781 14681
    27137 42969 14451 15061
    ... ...

    find_next_bit performance gain is 35-40%;
    find_first_bit - no measurable difference.

    On ARM machine, there is arch-specific implementation for find_bit.

    Thanks a lot to George Spelvin and Rasmus Villemoes for hints and
    helpful discussions.

    This patch (of 3):

    New implementations takes less space in source file (see diffstat) and in
    object. For me it's 710 vs 453 bytes of text. It also shows better
    performance.

    find_last_bit description fixed due to obvious typo.

    [akpm@linux-foundation.org: include linux/bitmap.h, per Rasmus]
    Signed-off-by: Yury Norov
    Reviewed-by: Rasmus Villemoes
    Reviewed-by: George Spelvin
    Cc: Alexey Klimov
    Cc: David S. Miller
    Cc: Daniel Borkmann
    Cc: Hannes Frederic Sowa
    Cc: Lai Jiangshan
    Cc: Mark Salter
    Cc: AKASHI Takahiro
    Cc: Thomas Graf
    Cc: Valentin Rothberg
    Cc: Chris Wilson
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yury Norov
     

16 Nov, 2014

1 commit

  • On some 32 bits architectures, including x86, GENMASK(31, 0) returns 0
    instead of the expected ~0UL.

    This is the same on some 64 bits architectures with GENMASK_ULL(63, 0).

    This is due to an overflow in the shift operand, 1 << 32 for GENMASK,
    1 << 64 for GENMASK_ULL.

    Reported-by: Eric Paire
    Suggested-by: Rasmus Villemoes
    Signed-off-by: Maxime Coquelin
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: # v3.13+
    Cc: linux@rasmusvillemoes.dk
    Cc: gong.chen@linux.intel.com
    Cc: John Sullivan
    Cc: Linus Torvalds
    Cc: Paul E. McKenney
    Cc: Theodore Ts'o
    Fixes: 10ef6b0dffe4 ("bitops: Introduce a more generic BITMASK macro")
    Link: http://lkml.kernel.org/r/1415267659-10563-1-git-send-email-maxime.coquelin@st.com
    Signed-off-by: Ingo Molnar

    Maxime COQUELIN
     

13 Aug, 2014

1 commit

  • Its been a while and there are no in-tree users left, so remove the
    deprecated barriers.

    Signed-off-by: Peter Zijlstra
    Cc: Chen, Gong
    Cc: Jacob Pan
    Cc: Joe Perches
    Cc: John Sullivan
    Cc: Linus Torvalds
    Cc: Paul E. McKenney
    Cc: Srinivas Pandruvada
    Cc: Theodore Ts'o
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

18 Apr, 2014

1 commit

  • Since the smp_mb__{before,after}*() ops are fundamentally dependent on
    how an arch can implement atomics it doesn't make sense to have 3
    variants of them. They must all be the same.

    Furthermore, the 3 variants suggest they're only valid for those 3
    atomic ops, while we have many more where they could be applied.

    So move away from
    smp_mb__{before,after}_{atomic,clear}_{dec,inc,bit}() and reduce the
    interface to just the two: smp_mb__{before,after}_atomic().

    This patch prepares the way by introducing default implementations in
    asm-generic/barrier.h that default to a full barrier and providing
    __deprecated inlines for the previous 6 barriers if they're not
    provided by the arch.

    This should allow for a mostly painless transition (lots of deprecated
    warns in the interim).

    Signed-off-by: Peter Zijlstra
    Acked-by: Paul E. McKenney
    Link: http://lkml.kernel.org/n/tip-wr59327qdyi9mbzn6x937s4e@git.kernel.org
    Cc: Arnd Bergmann
    Cc: "Chen, Gong"
    Cc: John Sullivan
    Cc: Linus Torvalds
    Cc: Mauro Carvalho Chehab
    Cc: Srinivas Pandruvada
    Cc: "Theodore Ts'o"
    Cc: linux-arch@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

31 Mar, 2014

1 commit

  • Use cmpxchg() to atomically set i_flags instead of clearing out the
    S_IMMUTABLE, S_APPEND, etc. flags and then setting them from the
    EXT4_IMMUTABLE_FL, EXT4_APPEND_FL flags, since this opens up a race
    where an immutable file has the immutable flag cleared for a brief
    window of time.

    Reported-by: John Sullivan
    Signed-off-by: "Theodore Ts'o"
    Cc: stable@kernel.org
    Signed-off-by: Linus Torvalds

    Theodore Ts'o
     

14 Nov, 2013

1 commit

  • Pull ACPI and power management updates from Rafael J Wysocki:

    - New power capping framework and the the Intel Running Average Power
    Limit (RAPL) driver using it from Srinivas Pandruvada and Jacob Pan.

    - Addition of the in-kernel switching feature to the arm_big_little
    cpufreq driver from Viresh Kumar and Nicolas Pitre.

    - cpufreq support for iMac G5 from Aaro Koskinen.

    - Baytrail processors support for intel_pstate from Dirk Brandewie.

    - cpufreq support for Midway/ECX-2000 from Mark Langsdorf.

    - ARM vexpress/TC2 cpufreq support from Sudeep KarkadaNagesha.

    - ACPI power management support for the I2C and SPI bus types from Mika
    Westerberg and Lv Zheng.

    - cpufreq core fixes and cleanups from Viresh Kumar, Srivatsa S Bhat,
    Stratos Karafotis, Xiaoguang Chen, Lan Tianyu.

    - cpufreq drivers updates (mostly fixes and cleanups) from Viresh
    Kumar, Aaro Koskinen, Jungseok Lee, Sudeep KarkadaNagesha, Lukasz
    Majewski, Manish Badarkhe, Hans-Christian Egtvedt, Evgeny Kapaev.

    - intel_pstate updates from Dirk Brandewie and Adrian Huang.

    - ACPICA update to version 20130927 includig fixes and cleanups and
    some reduction of divergences between the ACPICA code in the kernel
    and ACPICA upstream in order to improve the automatic ACPICA patch
    generation process. From Bob Moore, Lv Zheng, Tomasz Nowicki, Naresh
    Bhat, Bjorn Helgaas, David E Box.

    - ACPI IPMI driver fixes and cleanups from Lv Zheng.

    - ACPI hotplug fixes and cleanups from Bjorn Helgaas, Toshi Kani, Zhang
    Yanfei, Rafael J Wysocki.

    - Conversion of the ACPI AC driver to the platform bus type and
    multiple driver fixes and cleanups related to ACPI from Zhang Rui.

    - ACPI processor driver fixes and cleanups from Hanjun Guo, Jiang Liu,
    Bartlomiej Zolnierkiewicz, Mathieu Rhéaume, Rafael J Wysocki.

    - Fixes and cleanups and new blacklist entries related to the ACPI
    video support from Aaron Lu, Felipe Contreras, Lennart Poettering,
    Kirill Tkhai.

    - cpuidle core cleanups from Viresh Kumar and Lorenzo Pieralisi.

    - cpuidle drivers fixes and cleanups from Daniel Lezcano, Jingoo Han,
    Bartlomiej Zolnierkiewicz, Prarit Bhargava.

    - devfreq updates from Sachin Kamat, Dan Carpenter, Manish Badarkhe.

    - Operation Performance Points (OPP) core updates from Nishanth Menon.

    - Runtime power management core fix from Rafael J Wysocki and update
    from Ulf Hansson.

    - Hibernation fixes from Aaron Lu and Rafael J Wysocki.

    - Device suspend/resume lockup detection mechanism from Benoit Goby.

    - Removal of unused proc directories created for various ACPI drivers
    from Lan Tianyu.

    - ACPI LPSS driver fix and new device IDs for the ACPI platform scan
    handler from Heikki Krogerus and Jarkko Nikula.

    - New ACPI _OSI blacklist entry for Toshiba NB100 from Levente Kurusa.

    - Assorted fixes and cleanups related to ACPI from Andy Shevchenko, Al
    Stone, Bartlomiej Zolnierkiewicz, Colin Ian King, Dan Carpenter,
    Felipe Contreras, Jianguo Wu, Lan Tianyu, Yinghai Lu, Mathias Krause,
    Liu Chuansheng.

    - Assorted PM fixes and cleanups from Andy Shevchenko, Thierry Reding,
    Jean-Christophe Plagniol-Villard.

    * tag 'pm+acpi-3.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (386 commits)
    cpufreq: conservative: fix requested_freq reduction issue
    ACPI / hotplug: Consolidate deferred execution of ACPI hotplug routines
    PM / runtime: Use pm_runtime_put_sync() in __device_release_driver()
    ACPI / event: remove unneeded NULL pointer check
    Revert "ACPI / video: Ignore BIOS initial backlight value for HP 250 G1"
    ACPI / video: Quirk initial backlight level 0
    ACPI / video: Fix initial level validity test
    intel_pstate: skip the driver if ACPI has power mgmt option
    PM / hibernate: Avoid overflow in hibernate_preallocate_memory()
    ACPI / hotplug: Do not execute "insert in progress" _OST
    ACPI / hotplug: Carry out PCI root eject directly
    ACPI / hotplug: Merge device hot-removal routines
    ACPI / hotplug: Make acpi_bus_hot_remove_device() internal
    ACPI / hotplug: Simplify device ejection routines
    ACPI / hotplug: Fix handle_root_bridge_removal()
    ACPI / hotplug: Refuse to hot-remove all objects with disabled hotplug
    ACPI / scan: Start matching drivers after trying scan handlers
    ACPI: Remove acpi_pci_slot_init() headers from internal.h
    ACPI / blacklist: fix name of ThinkPad Edge E530
    PowerCap: Fix build error with option -Werror=format-security
    ...

    Conflicts:
    arch/arm/mach-omap2/opp.c
    drivers/Kconfig
    drivers/spi/spi.c

    Linus Torvalds
     

22 Oct, 2013

1 commit

  • GENMASK is used to create a contiguous bitmask([hi:lo]). It is
    implemented twice in current kernel. One is in EDAC driver, the other
    is in SiS/XGI FB driver. Move it to a more generic place for other
    usage.

    Signed-off-by: Chen, Gong
    Cc: Borislav Petkov
    Cc: Thomas Winischhofer
    Cc: Jean-Christophe Plagniol-Villard
    Cc: Tomi Valkeinen
    Acked-by: Borislav Petkov
    Acked-by: Mauro Carvalho Chehab
    Signed-off-by: Tony Luck

    Chen, Gong
     

17 Oct, 2013

1 commit

  • Adding BIT(x) equivalent for unsigned long long type, BIT_ULL(x). Also
    added BIT_ULL_MASK and BIT_ULL_WORD.

    Suggested-by: Joe Perches
    Signed-off-by: Srinivas Pandruvada
    Signed-off-by: Jacob Pan
    Signed-off-by: Rafael J. Wysocki

    Srinivas Pandruvada
     

24 Mar, 2012

2 commits

  • Introduce for_each_clear_bit() and for_each_clear_bit_from(). They are
    similar to for_each_set_bit() and list_for_each_set_bit_from(), but they
    iterate over all the cleared bits in a memory region.

    Signed-off-by: Akinobu Mita
    Cc: Robert Richter
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: "H. Peter Anvin"
    Cc: David Woodhouse
    Cc: Martin Schwidefsky
    Cc: Heiko Carstens
    Cc: Stefano Panella
    Cc: David Vrabel
    Cc: Sergei Shtylyov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Akinobu Mita
     
  • Remove for_each_set_bit_cont() after confirming that no one uses
    for_each_set_bit_cont() anymore.

    [sfr@canb.auug.org.au: regmap: cope with bitops API change]
    Signed-off-by: Akinobu Mita
    Signed-off-by: Stephen Rothwell
    Cc: Robert Richter
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: "H. Peter Anvin"
    Cc: Mark Brown
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Akinobu Mita