25 Jul, 2019

1 commit

  • The IPI code of x86 needs to evaluate whether the target cpumask is equal
    to the cpu_online_mask or equal except for the calling CPU.

    To replace the current implementation which requires the usage of a
    temporary cpumask, which might involve allocations, add a new function
    which compares a cpumask to the result of two other cpumasks which are
    or'ed together before comparison.

    This allows to make the required decision in one go and the calling code
    then can check for the calling CPU being set in the target mask with
    cpumask_test_cpu().

    Signed-off-by: Thomas Gleixner
    Acked-by: Peter Zijlstra (Intel)
    Link: https://lkml.kernel.org/r/20190722105220.585449120@linutronix.de

    Thomas Gleixner
     

19 Jun, 2019

1 commit

  • Based on 2 normalized pattern(s):

    this source code is licensed under the gnu general public license
    version 2 see the file copying for more details

    this source code is licensed under general public license version 2
    see

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 52 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Enrico Weigelt
    Reviewed-by: Allison Randal
    Reviewed-by: Alexios Zavras
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190602204653.449021192@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

15 May, 2019

4 commits

  • Remove __bitmap_parselist helper and split the function to logical
    parts.

    [ynorov@marvell.com: v5]
    Link: http://lkml.kernel.org/r/20190416063801.20134-3-ynorov@marvell.com
    Link: http://lkml.kernel.org/r/20190405173211.11373-3-ynorov@marvell.com
    Signed-off-by: Yury Norov
    Reviewed-by: Andy Shevchenko
    Cc: Arnd Bergmann
    Cc: Kees Cook
    Cc: Matthew Wilcox
    Cc: Mike Travis
    Cc: Rasmus Villemoes
    Cc: Tetsuo Handa
    Cc: Guenter Roeck
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yury Norov
     
  • Patch series "lib: rework bitmap_parselist and tests", v5.

    bitmap_parselist has been evolved from a pretty simple idea for long and
    now lacks for refactoring. It is not structured, has nested loops and a
    set of opaque-named variables.

    Things are more complicated because bitmap_parselist() is a part of user
    interface, and its behavior should not change.

    In this patchset
    - bitmap_parselist_user() made a wrapper on bitmap_parselist();
    - bitmap_parselist() reworked (patch 2);
    - time measurement in test_bitmap_parselist switched to ktime_get
    (patch 3);
    - new tests introduced (patch 4), and
    - bitmap_parselist_user() testing enabled with the same testset as
    bitmap_parselist() (patch 5).

    This patch (of 5):

    Currently we parse user data byte after byte which leads to
    overcomplification of parsing algorithm. The only user of
    bitmap_parselist_user() is not performance-critical, and so we can
    duplicate user data to kernel buffer and simply call bitmap_parselist().
    This rework lets us unify and simplify bitmap_parselist() and
    bitmap_parselist_user(), which is done in the following patch.

    Link: http://lkml.kernel.org/r/20190405173211.11373-2-ynorov@marvell.com
    Signed-off-by: Yury Norov
    Reviewed-by: Andy Shevchenko
    Cc: Rasmus Villemoes
    Cc: Arnd Bergmann
    Cc: Kees Cook
    Cc: Matthew Wilcox
    Cc: Tetsuo Handa
    Cc: Mike Travis
    Cc: Guenter Roeck
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yury Norov
     
  • The bitmap_remap, _bitremap, _onto and _fold functions are only used,
    via their node_ wrappers, in mm/mempolicy.c, which is only built for
    CONFIG_NUMA. The helper bitmap_ord_to_pos used by these functions is
    global, but its only external caller is node_random() in lib/nodemask.c,
    which is also guarded by CONFIG_NUMA.

    For !CONFIG_NUMA:

    add/remove: 0/6 grow/shrink: 0/0 up/down: 0/-621 (-621)
    Function old new delta
    bitmap_pos_to_ord 20 - -20
    bitmap_ord_to_pos 70 - -70
    bitmap_bitremap 81 - -81
    bitmap_fold 113 - -113
    bitmap_onto 123 - -123
    bitmap_remap 214 - -214
    Total: Before=4776, After=4155, chg -13.00%

    Link: http://lkml.kernel.org/r/20190329205353.6010-2-linux@rasmusvillemoes.dk
    Signed-off-by: Rasmus Villemoes
    Cc: Andy Shevchenko
    Cc: Yury Norov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • AFAICT, there have never been any callers of these functions outside
    mm/mempolicy.c (via their nodemask.h wrappers). In particular, no
    modular code has ever used them, and given their somewhat exotic
    semantics, I highly doubt they will ever find such a use. In any case,
    no need to export them currently.

    Link: http://lkml.kernel.org/r/20190329205353.6010-1-linux@rasmusvillemoes.dk
    Signed-off-by: Rasmus Villemoes
    Cc: Andy Shevchenko
    Cc: Yury Norov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     

04 Jan, 2019

1 commit

  • Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
    of the user address range verification function since we got rid of the
    old racy i386-only code to walk page tables by hand.

    It existed because the original 80386 would not honor the write protect
    bit when in kernel mode, so you had to do COW by hand before doing any
    user access. But we haven't supported that in a long time, and these
    days the 'type' argument is a purely historical artifact.

    A discussion about extending 'user_access_begin()' to do the range
    checking resulted this patch, because there is no way we're going to
    move the old VERIFY_xyz interface to that model. And it's best done at
    the end of the merge window when I've done most of my merges, so let's
    just get this done once and for all.

    This patch was mostly done with a sed-script, with manual fix-ups for
    the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.

    There were a couple of notable cases:

    - csky still had the old "verify_area()" name as an alias.

    - the iter_iov code had magical hardcoded knowledge of the actual
    values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
    really used it)

    - microblaze used the type argument for a debug printout

    but other than those oddities this should be a total no-op patch.

    I tried to fix up all architectures, did fairly extensive grepping for
    access_ok() uses, and the changes are trivial, but I may have missed
    something. Any missed conversion should be trivially fixable, though.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

31 Oct, 2018

3 commits

  • len is guaranteed to lie in [1, PAGE_SIZE]. If scnprintf is called with a
    buffer size of 1, it is guaranteed to return 0. So in the extremely
    unlikely case of having just one byte remaining in the page, let's just
    call scnprintf anyway. The only difference is that this will write a '\0'
    to that final byte in the page, but that's an improvement: We now
    guarantee that after the call, buf is a properly terminated C string of
    length exactly the return value.

    Link: http://lkml.kernel.org/r/20180818131623.8755-8-linux@rasmusvillemoes.dk
    Signed-off-by: Rasmus Villemoes
    Reviewed-by: Andy Shevchenko
    Cc: Yury Norov
    Cc: Rasmus Villemoes
    Cc: Sudeep Holla
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • For various alignments of buf, the current expression computes

    4096 ok
    4095 ok
    8190
    8189
    ...
    4097

    i.e., if the caller has already written two bytes into the page buffer,
    len is 8190 rather than 4094, because PTR_ALIGN aligns up to the next
    boundary. So if the printed version of the bitmap is huge, scnprintf()
    ends up writing beyond the page boundary.

    I don't think any current callers actually write anything before
    bitmap_print_to_pagebuf, but the API seems to be designed to allow it.

    [akpm@linux-foundation.org: use offset_in_page(), per Andy]
    [akpm@linux-foundation.org: include mm.h for offset_in_page()]
    Link: http://lkml.kernel.org/r/20180818131623.8755-7-linux@rasmusvillemoes.dk
    Signed-off-by: Rasmus Villemoes
    Reviewed-by: Andy Shevchenko
    Cc: Yury Norov
    Cc: Rasmus Villemoes
    Cc: Sudeep Holla
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • This promise is violated in a number of places, e.g. already in the
    second function below this paragraph. Since I don't think anybody relies
    on this being true, and since actually honouring it would hurt performance
    and code size in various places, just remove the paragraph.

    Link: http://lkml.kernel.org/r/20180818131623.8755-2-linux@rasmusvillemoes.dk
    Signed-off-by: Rasmus Villemoes
    Reviewed-by: Andy Shevchenko
    Cc: Yury Norov
    Cc: Rasmus Villemoes
    Cc: Sudeep Holla
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     

23 Aug, 2018

1 commit


19 Aug, 2018

1 commit

  • Pull input updates from Dmitry Torokhov:

    - a new driver for Rohm BU21029 touch controller

    - new bitmap APIs: bitmap_alloc, bitmap_zalloc and bitmap_free

    - updates to Atmel, eeti. pxrc and iforce drivers

    - assorted driver cleanups and fixes.

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (57 commits)
    MAINTAINERS: Add PhoenixRC Flight Controller Adapter
    Input: do not use WARN() in input_alloc_absinfo()
    Input: mark expected switch fall-throughs
    Input: raydium_i2c_ts - use true and false for boolean values
    Input: evdev - switch to bitmap API
    Input: gpio-keys - switch to bitmap_zalloc()
    Input: elan_i2c_smbus - cast sizeof to int for comparison
    bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free()
    md: Avoid namespace collision with bitmap API
    dm: Avoid namespace collision with bitmap API
    Input: pm8941-pwrkey - add resin entry
    Input: pm8941-pwrkey - abstract register offsets and event code
    Input: iforce - reorganize joystick configuration lists
    Input: atmel_mxt_ts - move completion to after config crc is updated
    Input: atmel_mxt_ts - don't report zero pressure from T9
    Input: atmel_mxt_ts - zero terminate config firmware file
    Input: atmel_mxt_ts - refactor config update code to add context struct
    Input: atmel_mxt_ts - config CRC may start at T71
    Input: atmel_mxt_ts - remove unnecessary debug on ENOMEM
    Input: atmel_mxt_ts - remove duplicate setup of ABS_MT_PRESSURE
    ...

    Linus Torvalds
     

02 Aug, 2018

1 commit

  • A lot of code become ugly because of open coding allocations for bitmaps.

    Introduce three helpers to allow users be more clear of intention
    and keep their code neat.

    Note, due to multiple circular dependencies we may not provide
    the helpers as inliners. For now we keep them exported and, perhaps,
    at some point in the future we will sort out header inclusion and
    inheritance.

    Signed-off-by: Andy Shevchenko
    Signed-off-by: Dmitry Torokhov

    Andy Shevchenko
     

08 Jun, 2018

1 commit

  • Use BITS_TO_LONGS() macro to avoid calculation of reminder (bits %
    BITS_PER_LONG) On ARM64 it saves 5 instruction for function - 16 before
    and 11 after.

    Link: http://lkml.kernel.org/r/20180411145914.6011-1-ynorov@caviumnetworks.com
    Signed-off-by: Yury Norov
    Reviewed-by: Andrew Morton
    Cc: Matthew Wilcox
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yury Norov
     

06 Apr, 2018

1 commit

  • syzbot is catching stalls at __bitmap_parselist()
    (https://syzkaller.appspot.com/bug?id=ad7e0351fbc90535558514a71cd3edc11681997a).
    The trigger is

    unsigned long v = 0;
    bitmap_parselist("7:,", &v, BITS_PER_LONG);

    which results in hitting infinite loop at

    while (a
    Reported-by: Tetsuo Handa
    Reported-by: syzbot
    Cc: Noam Camus
    Cc: Rasmus Villemoes
    Cc: Matthew Wilcox
    Cc: Mauro Carvalho Chehab
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yury Norov
     

07 Feb, 2018

2 commits

  • with bitmap_{from,to}_arr32 over the kernel. Additionally to it:
    * __check_eq_bitmap() now takes single nbits argument.
    * __check_eq_u32_array is not used in new test but may be used in
    future. So I don't remove it here, but annotate as __used.

    Tested on arm64 and 32-bit BE mips.

    [arnd@arndb.de: perf: arm_dsu_pmu: convert to bitmap_from_arr32]
    Link: http://lkml.kernel.org/r/20180201172508.5739-2-ynorov@caviumnetworks.com
    [ynorov@caviumnetworks.com: fix net/core/ethtool.c]
    Link: http://lkml.kernel.org/r/20180205071747.4ekxtsbgxkj5b2fz@yury-thinkpad
    Link: http://lkml.kernel.org/r/20171228150019.27953-2-ynorov@caviumnetworks.com
    Signed-off-by: Yury Norov
    Signed-off-by: Arnd Bergmann
    Cc: Ben Hutchings
    Cc: David Decotigny ,
    Cc: David S. Miller ,
    Cc: Geert Uytterhoeven
    Cc: Matthew Wilcox
    Cc: Rasmus Villemoes
    Cc: Heiner Kallweit
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yury Norov
     
  • This patchset replaces bitmap_{to,from}_u32array with more simple and
    standard looking copy-like functions.

    bitmap_from_u32array() takes 4 arguments (bitmap_to_u32array is similar):
    - unsigned long *bitmap, which is destination;
    - unsigned int nbits, the length of destination bitmap, in bits;
    - const u32 *buf, the source; and
    - unsigned int nwords, the length of source buffer in ints.

    In description to the function it is detailed like:
    * copy min(nbits, 32*nwords) bits from @buf to @bitmap, remaining
    * bits between nword and nbits in @bitmap (if any) are cleared.

    Having two size arguments looks unneeded and potentially dangerous.

    It is unneeded because normally user of copy-like function should take
    care of the size of destination and make it big enough to fit source
    data.

    And it is dangerous because function may hide possible error if user
    doesn't provide big enough bitmap, and data becomes silently dropped.

    That's why all copy-like functions have 1 argument for size of copying
    data, and I don't see any reason to make bitmap_from_u32array()
    different.

    One exception that comes in mind is strncpy() which also provides size
    of destination in arguments, but it's strongly argued by the possibility
    of taking broken strings in source. This is not the case of
    bitmap_{from,to}_u32array().

    There is no many real users of bitmap_{from,to}_u32array(), and they all
    very clearly provide size of destination matched with the size of
    source, so additional functionality is not used in fact. Like this:
    bitmap_from_u32array(to->link_modes.supported,
    __ETHTOOL_LINK_MODE_MASK_NBITS,
    link_usettings.link_modes.supported,
    __ETHTOOL_LINK_MODE_MASK_NU32);
    Where:
    #define __ETHTOOL_LINK_MODE_MASK_NU32 \
    DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32)

    In this patch, bitmap_copy_safe and bitmap_{from,to}_arr32 are introduced.

    'Safe' in bitmap_copy_safe() stands for clearing unused bits in bitmap
    beyond last bit till the end of last word. It is useful for hardening
    API when bitmap is assumed to be exposed to userspace.

    bitmap_{from,to}_arr32 functions are replacements for
    bitmap_{from,to}_u32array. They don't take unneeded nwords argument, and
    so simpler in implementation and understanding.

    This patch suggests optimization for 32-bit systems - aliasing
    bitmap_{from,to}_arr32 to bitmap_copy_safe.

    Other possible optimization is aliasing 64-bit LE bitmap_{from,to}_arr32 to
    more generic function(s). But I didn't end up with the function that would
    be helpful by itself, and can be used to alias 64-bit LE
    bitmap_{from,to}_arr32, like bitmap_copy_safe() does. So I preferred to
    leave things as is.

    The following patch switches kernel to new API and introduces test for it.

    Discussion is here: https://lkml.org/lkml/2017/11/15/592

    [ynorov@caviumnetworks.com: rename bitmap_copy_safe to bitmap_copy_clear_tail]
    Link: http://lkml.kernel.org/r/20180201172508.5739-3-ynorov@caviumnetworks.com
    Link: http://lkml.kernel.org/r/20171228150019.27953-1-ynorov@caviumnetworks.com
    Signed-off-by: Yury Norov
    Cc: Ben Hutchings
    Cc: David Decotigny ,
    Cc: David S. Miller ,
    Cc: Geert Uytterhoeven
    Cc: Matthew Wilcox
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yury Norov
     

20 Oct, 2017

1 commit

  • There are some good comments about bitmap operations in lib/bitmap.c
    and include/linux/bitmap.h, so format them for document generation and
    pull them into core-api/kernel-api.rst.

    I converted the "tables" of functions from using tabs to using spaces
    so that they are more readable in the source file and in the generated
    output.

    Signed-off-by: Randy Dunlap
    Signed-off-by: Jonathan Corbet

    Randy Dunlap
     

09 Sep, 2017

1 commit

  • Current implementation of bitmap_parselist() uses a static variable to
    save local state while setting bits in the bitmap. It is obviously wrong
    if we assume execution in multiprocessor environment. Fortunately, it's
    possible to rewrite this portion of code to avoid using the static
    variable.

    It is also possible to set bits in the mask per-range with bitmap_set(),
    not per-bit, as it is implemented now, with set_bit(); which is way
    faster.

    The important side effect of this change is that setting bits in this
    function from now is not per-bit atomic and less memory-ordered. This is
    because set_bit() guarantees the order of memory accesses, while
    bitmap_set() does not. I think that it is the advantage of the new
    approach, because the bitmap_parselist() is intended to initialise bit
    arrays, and user should protect the whole bitmap during initialisation if
    needed. So protecting individual bits looks expensive and useless. Also,
    other range-oriented functions in lib/bitmap.c don't worry much about
    atomicity.

    With all that, setting 2k bits in map with the pattern like 0-2047:128/256
    becomes ~50 times faster after applying the patch in my testing
    environment (arm64 hosted on qemu).

    The second patch of the series adds the test for bitmap_parselist(). It's
    not intended to cover all tricky cases, just to make sure that I didn't
    screw up during rework.

    Link: http://lkml.kernel.org/r/20170807225438.16161-1-ynorov@caviumnetworks.com
    Signed-off-by: Yury Norov
    Cc: Noam Camus
    Cc: Rasmus Villemoes
    Cc: Matthew Wilcox
    Cc: Mauro Carvalho Chehab
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yury Norov
     

11 Jul, 2017

1 commit

  • We have eight users calling bitmap_clear for a single bit and seventeen
    calling bitmap_set for a single bit. Rather than fix all of them to
    call __clear_bit or __set_bit, turn bitmap_clear and bitmap_set into
    inline functions and make this special case efficient.

    Link: http://lkml.kernel.org/r/20170628153221.11322-3-willy@infradead.org
    Signed-off-by: Matthew Wilcox
    Acked-by: Rasmus Villemoes
    Cc: Martin Schwidefsky
    Cc: Matthew Wilcox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Matthew Wilcox
     

03 Apr, 2017

1 commit

  • Fix the following issues:

    ./lib/bitmap.c:869: WARNING: Definition list ends without a blank line; unexpected unindent.
    ./lib/bitmap.c:876: WARNING: Inline emphasis start-string without end-string.
    ./lib/bitmap.c:508: ERROR: Unexpected indentation.

    And make sure that a table and a footnote will use the right tags.

    Signed-off-by: Mauro Carvalho Chehab
    Signed-off-by: Jonathan Corbet

    mchehab@s-opensource.com
     

12 Oct, 2016

1 commit

  • Today there are platforms with many CPUs (up to 4K). Trying to boot only
    part of the CPUs may result in too long string.

    For example lets take NPS platform that is part of arch/arc. This
    platform have SMP system with 256 cores each with 16 HW threads (SMT
    machine) where HW thread appears as CPU to the kernel. In this example
    there is total of 4K CPUs. When one tries to boot only part of the HW
    threads from each core the string representing the map may be long... For
    example if for sake of performance we decided to boot only first half of
    HW threads of each core the map will look like:
    0-7,16-23,32-39,...,4080-4087

    This patch introduce new syntax to accommodate with such use case. I
    added an optional postfix to a range of CPUs which will choose according
    to given modulo the desired range of reminders i.e.:

    :sed_size/group_size

    For example, above map can be described in new syntax like this:
    0-4095:8/16

    Note that this patch is backward compatible with current syntax.

    [akpm@linux-foundation.org: rework documentation]
    Link: http://lkml.kernel.org/r/1473579629-4283-1-git-send-email-noamca@mellanox.com
    Signed-off-by: Noam Camus
    Cc: David Decotigny
    Cc: Ben Hutchings
    Cc: David S. Miller
    Cc: Pan Xinhui
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Noam Camus
     

15 Jul, 2016

1 commit

  • struct thread_info is a legacy mess. To prepare for its partial removal,
    move thread_info::addr_limit out.

    As an added benefit, this way is simpler.

    Signed-off-by: Andy Lutomirski
    Cc: Borislav Petkov
    Cc: Brian Gerst
    Cc: Denys Vlasenko
    Cc: H. Peter Anvin
    Cc: Josh Poimboeuf
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/15bee834d09402b47ac86f2feccdf6529f9bc5b0.1468527351.git.luto@kernel.org
    Signed-off-by: Ingo Molnar

    Andy Lutomirski
     

20 Feb, 2016

1 commit


11 Sep, 2015

3 commits

  • In __bitmap_parselist we can accept whitespaces on head or tail during
    every parsing procedure. If input has valid ranges, there is no reason to
    reject the user.

    For example, bitmap_parselist(" 1-3, 5, ", &mask, nmaskbits). After
    separating the string, we get " 1-3", " 5", and " ". It's possible and
    reasonable to accept such string as long as the parsing result is correct.

    Signed-off-by: Pan Xinhui
    Cc: Yury Norov
    Cc: Chris Metcalf
    Cc: Rasmus Villemoes
    Cc: Sudeep Holla
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pan Xinhui
     
  • If string end with '-', for exapmle, bitmap_parselist("1,0-",&mask,
    nmaskbits), It is not in a valid pattern, so add a check after loop.
    Return -EINVAL on such condition.

    Signed-off-by: Pan Xinhui
    Cc: Yury Norov
    Cc: Chris Metcalf
    Cc: Rasmus Villemoes
    Cc: Sudeep Holla
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pan Xinhui
     
  • We can avoid in-loop incrementation of ndigits. Save current totaldigits
    to ndigits before loop, and check ndigits against totaldigits after the
    loop.

    Signed-off-by: Pan Xinhui
    Cc: Yury Norov
    Cc: Chris Metcalf
    Cc: Rasmus Villemoes
    Cc: Sudeep Holla
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pan Xinhui
     

26 Jun, 2015

2 commits

  • bitmap_print_to_pagebuf uses scnprintf to copy the cpumask/list to page
    buffer. It handles the newline and trailing null character explicitly.

    It's unnecessary and also partially duplicated as scnprintf already adds
    trailing null character. The newline can be passed through format
    string to scnprintf. This patch does that simplification.

    However theoretically there's one behavior difference: when the buffer
    is too small, the original code would still output '\n' at the end while
    the new code(with this patch) would just continue to print the formatted
    string. Since this function is dealing with only page buffers, it's
    highly unlikely to hit that corner case.

    This patch will help in auditing the users of bitmap_print_to_pagebuf to
    verify that the buffer passed is large enough and get rid of it
    completely by replacing them with direct scnprintf()

    [akpm@linux-foundation.org: tweak comment]
    Signed-off-by: Sudeep Holla
    Suggested-by: Pawel Moll
    Cc: Tejun Heo
    Cc: "Peter Zijlstra (Intel)"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sudeep Holla
     
  • bitmap_parselist("", &mask, nmaskbits) will erroneously set bit zero in
    the mask. The same bug is visible in cpumask_parselist() since it is
    layered on top of the bitmask code, e.g. if you boot with "isolcpus=",
    you will actually end up with cpu zero isolated.

    The bug was introduced in commit 4b060420a596 ("bitmap, irq: add
    smp_affinity_list interface to /proc/irq") when bitmap_parselist() was
    generalized to support userspace as well as kernelspace.

    Fixes: 4b060420a596 ("bitmap, irq: add smp_affinity_list interface to /proc/irq")
    Signed-off-by: Chris Metcalf
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Chris Metcalf
     

17 Apr, 2015

1 commit


14 Feb, 2015

10 commits

  • Now that all bitmap formatting usages have been converted to
    '%*pb[l]', the separate formatting functions are unnecessary. The
    following functions are removed.

    * bitmap_scn[list]printf()
    * cpumask_scnprintf(), cpulist_scnprintf()
    * [__]nodemask_scnprintf(), [__]nodelist_scnprintf()
    * seq_bitmap[_list](), seq_cpumask[_list](), seq_nodemask[_list]()
    * seq_buf_bitmask()

    Signed-off-by: Tejun Heo
    Cc: Rusty Russell
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tejun Heo
     
  • printk and friends can now format bitmaps using '%*pb[l]'. cpumask
    and nodemask also provide cpumask_pr_args() and nodemask_pr_args()
    respectively which can be used to generate the two printf arguments
    necessary to format the specified cpu/nodemask.

    Signed-off-by: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tejun Heo
     
  • bitmap and its derivatives such as cpumask and nodemask currently only
    provide formatting functions which put the output string into the
    provided buffer; however, how long this buffer should be isn't defined
    anywhere and given that some of these bitmaps can be too large to be
    formatted into an on-stack buffer it users sometimes are unnecessarily
    forced to come up with creative solutions and compromises for the
    buffer just to printk these bitmaps.

    There have been a couple different attempts at making this easier.

    1. Way back, PeterZ tried printk '%pb' extension with the precision
    for bit width - '%.*pb'. This was intuitive and made sense but
    unfortunately triggered a compile warning about using precision
    for a pointer.

    http://lkml.kernel.org/g/1336577562.2527.58.camel@twins

    2. I implemented bitmap_pr_cont[_list]() and its wrappers for cpumask
    and nodemask. This works but PeterZ pointed out that pr_cont's
    tendency to produce broken lines when multiple CPUs are printing is
    bothering considering the usages.

    http://lkml.kernel.org/g/1418226774-30215-3-git-send-email-tj@kernel.org

    So, this patch is another attempt at teaching printk and friends how
    to print bitmaps. It's almost identical to what PeterZ tried with
    precision but it uses the field width for the number of bits instead
    of precision. The format used is '%*pb[l]', with the optional
    trailing 'l' specifying list format instead of hex masks.

    This is a valid format string and doesn't trigger compiler warnings;
    however, it does make it impossible to specify output field width when
    printing bitmaps. I think this is an acceptable trade-off given how
    much easier it makes printing bitmaps and that we don't have any
    in-kernel user which is using the field width specification. If any
    future user wants to use field width with a bitmap, it'd have to
    format the bitmap into a string buffer and then print that buffer with
    width spec, which isn't different from how it should be done now.

    This patch implements bitmap[_list]_string() which are called from the
    vsprintf pointer() formatting function. The implementation is mostly
    identical to bitmap_scn[list]printf() except that the output is
    performed in the vsprintf way. These functions handle formatting into
    too small buffers and sprintf() family of functions report the correct
    overrun output length.

    bitmap_scn[list]printf() are now thin wrappers around scnprintf().

    Signed-off-by: Tejun Heo
    Acked-by: Peter Zijlstra (Intel)
    Cc: "David S. Miller"
    Cc: "James E.J. Bottomley"
    Cc: "John W. Linville"
    Cc: "Paul E. McKenney"
    Cc: Benjamin Herrenschmidt
    Cc: Chris Metcalf
    Cc: Chris Zankel
    Cc: Christoph Lameter
    Cc: Dmitry Torokhov
    Cc: Fenghua Yu
    Cc: Greg Kroah-Hartman
    Cc: Ingo Molnar
    Cc: Li Zefan
    Cc: Max Filippov
    Cc: Mike Travis
    Cc: Pekka Enberg
    Cc: Russell King
    Cc: Rusty Russell
    Cc: Steffen Klassert
    Cc: Steven Rostedt
    Cc: Thomas Gleixner
    Cc: Tony Luck
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tejun Heo
     
  • The first of these conditionals is completely redundant: If k == lim-1, we
    must have off==0, so the second conditional will also trigger and then it
    wouldn't matter if upper had some high bits set. But the second
    conditional is in fact also redundant, since it only serves to clear out
    some high-order "don't care" bits of dst, about which no guarantee is
    made.

    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • We can shift the bits from lower and upper into place before assembling
    dst[k + off]; moving the shift of lower into the branch where we already
    know that rem is non-zero allows us to remove a conditional.

    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • gcc can generate slightly better code for stuff like "nbits %
    BITS_PER_LONG" when it knows nbits is not negative. Since negative size
    bitmaps or shift amounts don't make sense, change these parameters of
    bitmap_shift_right to unsigned.

    If off >= lim (which requires shift >= nbits), k is initialized with a
    large positive value, but since I've let k continue to be signed, the loop
    will never run and dst will be zeroed as expected. Inside the loop, k is
    guaranteed to be non-negative, so the fact that it is promoted to unsigned
    in the various expressions it appears in is harmless.

    Also use "shift" and "nbits" consistently for the parameter names.

    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • If left is 0, we can just let mask be ~0UL, so that anding with it is a
    no-op. Conveniently, BITMAP_LAST_WORD_MASK provides precisely what we
    need, and we can eliminate left.

    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • If the condition k==lim-1 is true, we must have off == 0 (otherwise, k
    could never become that big). But in that case we have upper == 0 and
    hence dst[k] == (src[k] & mask) >> rem. Since mask consists of a
    consecutive range of bits starting from the LSB, anding dst[k] with mask
    is a no-op.

    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • We can shift the bits from lower and upper into place before assembling
    dst[k]; moving the shift of upper into the branch where we already know
    that rem is non-zero allows us to remove a conditional.

    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • I've previously changed the nbits parameter of most bitmap_* functions to
    unsigned; now it is bitmap_shift_{left,right}'s turn. This alone saves
    some .text, but while at it I found that there were a few other things one
    could do. The end result of these seven patches is

    $ scripts/bloat-o-meter /tmp/bitmap.o.{old,new}
    add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-328 (-328)
    function old new delta
    __bitmap_shift_right 384 226 -158
    __bitmap_shift_left 306 136 -170

    and less importantly also a smaller stack footprint

    $ stack-o-meter.pl master bitmap
    file function old new delta
    lib/bitmap.o __bitmap_shift_right 24 8 -16
    lib/bitmap.o __bitmap_shift_left 24 0 -24

    For each pair of 0
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes