04 Aug, 2015

1 commit

  • commit 2528a8b8f457d7432552d0e2b6f0f4046bb702f4 upstream.

    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
    Signed-off-by: Greg Kroah-Hartman

    Chris Metcalf
     

17 Apr, 2015

1 commit


14 Feb, 2015

12 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
     
  • On little-endian, there's no reason to have an extra, presumably less
    efficient, way of copying a bitmap.

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

    Rasmus Villemoes
     
  • Make the prototype of bitmap_copy_le the same as bitmap_copy's. All other
    bitmap_* functions take unsigned long* parameters; there's no reason this
    should be special.

    The only current user is the static inline uwb_mas_bm_copy_le, which
    already does the void* laundering, so the end users can pass their u8 or
    __le32 buffers without a cast.

    Furthermore, this allows us to simply let bitmap_copy_le be an alias for
    bitmap_copy on little-endian; see next patch.

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

    Rasmus Villemoes
     

13 Feb, 2015

5 commits

  • Also, rename bits to nbits. Both changes for consistency with other
    bitmap_* functions.

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

    Rasmus Villemoes
     
  • Make the return value and the ord and nbits parameters of
    bitmap_ord_to_pos unsigned.

    Also, simplify the implementation and as a side effect make the result
    fully defined, returning nbits for ord >= weight, in analogy with what
    find_{first,next}_bit does. This is a better sentinel than the former
    ("unofficial") 0. No current users are affected by this change.

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

    Rasmus Villemoes
     
  • The ordinal of a set bit is simply the number of set bits before it;
    counting those doesn't need to be done one bit at a time. While at it,
    update the parameters to unsigned int.

    It is not completely unthinkable that gcc would see pos as compile-time
    constant 0 in one of the uses of bitmap_pos_to_ord. Since the static
    inline frontend bitmap_weight doesn't handle nbits==0 correctly (it would
    behave exactly as if nbits==BITS_PER_LONG), use __bitmap_weight.

    Alternatively, the last line could be spelled bitmap_weight(buf, pos+1)-1,
    but this is simpler.

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

    Rasmus Villemoes
     
  • Change the sz and nbits parameters of bitmap_fold to unsigned int for
    consistency with other bitmap_* functions, and to save another few bytes
    in the generated code.

    [akpm@linux-foundation.org: fix kerneldoc]
    Signed-off-by: Rasmus Villemoes
    Cc: Wu Fengguang
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • Change the nbits parameter of bitmap_onto to unsigned int for consistency
    with other bitmap_* functions.

    [akpm@linux-foundation.org: coding-style fixes]
    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     

15 Dec, 2014

1 commit

  • Pull driver core update from Greg KH:
    "Here's the set of driver core patches for 3.19-rc1.

    They are dominated by the removal of the .owner field in platform
    drivers. They touch a lot of files, but they are "simple" changes,
    just removing a line in a structure.

    Other than that, a few minor driver core and debugfs changes. There
    are some ath9k patches coming in through this tree that have been
    acked by the wireless maintainers as they relied on the debugfs
    changes.

    Everything has been in linux-next for a while"

    * tag 'driver-core-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (324 commits)
    Revert "ath: ath9k: use debugfs_create_devm_seqfile() helper for seq_file entries"
    fs: debugfs: add forward declaration for struct device type
    firmware class: Deletion of an unnecessary check before the function call "vunmap"
    firmware loader: fix hung task warning dump
    devcoredump: provide a one-way disable function
    device: Add dev__once variants
    ath: ath9k: use debugfs_create_devm_seqfile() helper for seq_file entries
    ath: use seq_file api for ath9k debugfs files
    debugfs: add helper function to create device related seq_file
    drivers/base: cacheinfo: remove noisy error boot message
    Revert "core: platform: add warning if driver has no owner"
    drivers: base: support cpu cache information interface to userspace via sysfs
    drivers: base: add cpu_device_create to support per-cpu devices
    topology: replace custom attribute macros with standard DEVICE_ATTR*
    cpumask: factor out show_cpumap into separate helper function
    driver core: Fix unbalanced device reference in drivers_probe
    driver core: fix race with userland in device_add()
    sysfs/kernfs: make read requests on pre-alloc files use the buffer.
    sysfs/kernfs: allow attributes to request write buffer be pre-allocated.
    fs: sysfs: return EGBIG on write if offset is larger than file size
    ...

    Linus Torvalds
     

14 Dec, 2014

1 commit

  • Add a bitmap_find_next_zero_area_off() function which works like
    bitmap_find_next_zero_area() function except it allows an offset to be
    specified when alignment is checked. This lets caller request a bit such
    that its number plus the offset is aligned according to the mask.

    [gregory.0xf0@gmail.com: Retrieved from https://patchwork.linuxtv.org/patch/6254/ and updated documentation]
    Signed-off-by: Michal Nazarewicz
    Signed-off-by: Kyungmin Park
    Signed-off-by: Marek Szyprowski
    Signed-off-by: Gregory Fong
    Cc: Joonsoo Kim
    Cc: Kukjin Kim
    Cc: Laurent Pinchart
    Cc: Laura Abbott
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michal Nazarewicz
     

08 Nov, 2014

1 commit

  • Many sysfs *_show function use cpu{list,mask}_scnprintf to copy cpumap
    to the buffer aligned to PAGE_SIZE, append '\n' and '\0' to return null
    terminated buffer with newline.

    This patch creates a new helper function cpumap_print_to_pagebuf in
    cpumask.h using newly added bitmap_print_to_pagebuf and consolidates
    most of those sysfs functions using the new helper function.

    Signed-off-by: Sudeep Holla
    Suggested-by: Stephen Boyd
    Tested-by: Stephen Boyd
    Acked-by: "Rafael J. Wysocki"
    Acked-by: Bjorn Helgaas
    Acked-by: Peter Zijlstra (Intel)
    Cc: Greg Kroah-Hartman
    Cc: x86@kernel.org
    Cc: linux-acpi@vger.kernel.org
    Cc: linux-pci@vger.kernel.org
    Signed-off-by: Greg Kroah-Hartman

    Sudeep Holla
     

30 Oct, 2014

1 commit

  • If __bitmap_shift_left() or __bitmap_shift_right() are asked to shift by
    a multiple of BITS_PER_LONG, they will try to shift a long value by
    BITS_PER_LONG bits which is undefined. Change the functions to avoid
    the undefined shift.

    Coverity id: 1192175
    Coverity id: 1192174
    Signed-off-by: Jan Kara
    Cc: Rasmus Villemoes
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Kara
     

08 Oct, 2014

1 commit

  • Pull "trivial tree" updates from Jiri Kosina:
    "Usual pile from trivial tree everyone is so eagerly waiting for"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial: (39 commits)
    Remove MN10300_PROC_MN2WS0038
    mei: fix comments
    treewide: Fix typos in Kconfig
    kprobes: update jprobe_example.c for do_fork() change
    Documentation: change "&" to "and" in Documentation/applying-patches.txt
    Documentation: remove obsolete pcmcia-cs from Changes
    Documentation: update links in Changes
    Documentation: Docbook: Fix generated DocBook/kernel-api.xml
    score: Remove GENERIC_HAS_IOMAP
    gpio: fix 'CONFIG_GPIO_IRQCHIP' comments
    tty: doc: Fix grammar in serial/tty
    dma-debug: modify check_for_stack output
    treewide: fix errors in printk
    genirq: fix reference in devm_request_threaded_irq comment
    treewide: fix synchronize_rcu() in comments
    checkstack.pl: port to AArch64
    doc: queue-sysfs: minor fixes
    init/do_mounts: better syntax description
    MIPS: fix comment spelling
    powerpc/simpleboot: fix comment
    ...

    Linus Torvalds
     

09 Sep, 2014

1 commit


07 Aug, 2014

15 commits