1. 03 6月, 2022 2 次提交
    • Y
      lib: add bitmap_{from,to}_arr64 · 0a97953f
      Yury Norov 提交于
      Manipulating 64-bit arrays with bitmap functions is potentially dangerous
      because on 32-bit BE machines the order of halfwords doesn't match.
      Another issue is that compiler may throw a warning about out-of-boundary
      access.
      
      This patch adds bitmap_{from,to}_arr64 functions in addition to existing
      bitmap_{from,to}_arr32.
      
      CC: Alexander Gordeev <agordeev@linux.ibm.com>
      CC: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      CC: Christian Borntraeger <borntraeger@linux.ibm.com>
      CC: Claudio Imbrenda <imbrenda@linux.ibm.com>
      CC: David Hildenbrand <david@redhat.com>
      CC: Heiko Carstens <hca@linux.ibm.com>
      CC: Janosch Frank <frankja@linux.ibm.com>
      CC: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      CC: Sven Schnelle <svens@linux.ibm.com>
      CC: Vasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: NYury Norov <yury.norov@gmail.com>
      0a97953f
    • M
      lib/bitmap.c make bitmap_print_bitmask_to_buf parseable · 430cd4a2
      Mauro Carvalho Chehab 提交于
      The documentation of such function is not on a proper ReST format,
      as reported by Sphinx:
      
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:532: WARNING: Unexpected indentation.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:526: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:532: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:532: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:533: WARNING: Block quote ends without a blank line; unexpected unindent.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:536: WARNING: Definition list ends without a blank line; unexpected unindent.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:542: WARNING: Unexpected indentation.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:536: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:536: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:543: WARNING: Block quote ends without a blank line; unexpected unindent.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:552: WARNING: Unexpected indentation.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:545: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:545: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:552: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:552: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:554: WARNING: Block quote ends without a blank line; unexpected unindent.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:556: WARNING: Definition list ends without a blank line; unexpected unindent.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:580: WARNING: Unexpected indentation.
      
      So, the produced output at:
      
      	https://www.kernel.org/doc/html/latest/core-api/kernel-api.html?#c.bitmap_print_bitmask_to_buf
      
      is broken. Fix it by adding spaces and marking the literal blocks.
      Signed-off-by: NMauro Carvalho Chehab <mchehab@kernel.org>
      Reviewed-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
      Signed-off-by: NYury Norov <yury.norov@gmail.com>
      430cd4a2
  2. 24 3月, 2022 1 次提交
    • R
      lib: bitmap: fix many kernel-doc warnings · 2699e514
      Randy Dunlap 提交于
      Fix kernel-doc warings in lib/bitmap.c:
      
        lib/bitmap.c:498: warning: Function parameter or member 'buf' not described in 'bitmap_print_to_buf'
        lib/bitmap.c:498: warning: Function parameter or member 'maskp' not described in 'bitmap_print_to_buf'
        lib/bitmap.c:498: warning: Function parameter or member 'nmaskbits' not described in 'bitmap_print_to_buf'
        lib/bitmap.c:498: warning: Function parameter or member 'off' not described in 'bitmap_print_to_buf'
        lib/bitmap.c:498: warning: Function parameter or member 'count' not described in 'bitmap_print_to_buf'
        lib/bitmap.c:561: warning: contents before sections
        lib/bitmap.c:606: warning: Function parameter or member 'buf' not described in 'bitmap_print_list_to_buf'
        lib/bitmap.c:606: warning: Function parameter or member 'maskp' not described in 'bitmap_print_list_to_buf'
        lib/bitmap.c:606: warning: Function parameter or member 'nmaskbits' not described in 'bitmap_print_list_to_buf'
        lib/bitmap.c:606: warning: Function parameter or member 'off' not described in 'bitmap_print_list_to_buf'
        lib/bitmap.c:606: warning: Function parameter or member 'count' not described in 'bitmap_print_list_to_buf'
        lib/bitmap.c:819: warning: missing initial short description on line:
         * bitmap_parselist_user()
      
      This still leaves 15 warnings for function return values not described,
      similar to this one:
      
        bitmap.c:890: warning: No description found for return value of 'bitmap_parse'
      
      Link: https://lkml.kernel.org/r/20220306065823.5153-1-rdunlap@infradead.org
      Fixes: 1fae5629 ("cpumask: introduce cpumap_print_list/bitmask_to_buf to support large bitmask and list")
      Fixes: 4b060420 ("bitmap, irq: add smp_affinity_list interface to /proc/irq")
      Signed-off-by: NRandy Dunlap <rdunlap@infradead.org>
      Cc: Yury Norov <yury.norov@gmail.com>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Tian Tao <tiantao6@hisilicon.com>
      Cc: Mike Travis <mike.travis@hpe.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      2699e514
  3. 27 10月, 2021 1 次提交
  4. 13 8月, 2021 2 次提交
    • Y
      bitmap: extend comment to bitmap_print_bitmask/list_to_buf · 3b35f2a6
      Yury Norov 提交于
      Extend comment to new function to warn potential users about caveats.
      Signed-off-by: NYury Norov <yury.norov@gmail.com>
      Signed-off-by: NBarry Song <song.bao.hua@hisilicon.com>
      Link: https://lore.kernel.org/r/20210806110251.560-6-song.bao.hua@hisilicon.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3b35f2a6
    • T
      cpumask: introduce cpumap_print_list/bitmask_to_buf to support large bitmask and list · 1fae5629
      Tian Tao 提交于
      The existing cpumap_print_to_pagebuf() is used by cpu topology and other
      drivers to export hexadecimal bitmask and decimal list to userspace by
      sysfs ABI.
      
      Right now, those drivers are using a normal attribute for this kind of
      ABIs. A normal attribute typically has show entry as below:
      
      static ssize_t example_dev_show(struct device *dev,
                      struct device_attribute *attr, char *buf)
      {
      	...
      	return cpumap_print_to_pagebuf(true, buf, &pmu_mmdc->cpu);
      }
      show entry of attribute has no offset and count parameters and this
      means the file is limited to one page only.
      
      cpumap_print_to_pagebuf() API works terribly well for this kind of
      normal attribute with buf parameter and without offset, count:
      
      static inline ssize_t
      cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask)
      {
      	return bitmap_print_to_pagebuf(list, buf, cpumask_bits(mask),
      				       nr_cpu_ids);
      }
      
      The problem is once we have many cpus, we have a chance to make bitmask
      or list more than one page. Especially for list, it could be as complex
      as 0,3,5,7,9,...... We have no simple way to know it exact size.
      
      It turns out bin_attribute is a way to break this limit. bin_attribute
      has show entry as below:
      static ssize_t
      example_bin_attribute_show(struct file *filp, struct kobject *kobj,
                   struct bin_attribute *attr, char *buf,
                   loff_t offset, size_t count)
      {
      	...
      }
      
      With the new offset and count parameters, this makes sysfs ABI be able
      to support file size more than one page. For example, offset could be
      >= 4096.
      
      This patch introduces cpumap_print_bitmask/list_to_buf() and their bitmap
      infrastructure bitmap_print_bitmask/list_to_buf() so that those drivers
      can move to bin_attribute to support large bitmask and list. At the same
      time, we have to pass those corresponding parameters such as offset, count
      from bin_attribute to this new API.
      
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: Stefano Brivio <sbrivio@redhat.com>
      Cc: Alexander Gordeev <agordeev@linux.ibm.com>
      Cc: "Ma, Jianpeng" <jianpeng.ma@intel.com>
      Cc: Yury Norov <yury.norov@gmail.com>
      Cc: Valentin Schneider <valentin.schneider@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
      Reviewed-by: NJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: NTian Tao <tiantao6@hisilicon.com>
      Signed-off-by: NBarry Song <song.bao.hua@hisilicon.com>
      Link: https://lore.kernel.org/r/20210806110251.560-2-song.bao.hua@hisilicon.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1fae5629
  5. 12 5月, 2021 1 次提交
  6. 11 5月, 2021 1 次提交
  7. 05 5月, 2021 2 次提交
  8. 09 3月, 2021 3 次提交
  9. 17 10月, 2020 1 次提交
  10. 13 8月, 2020 1 次提交
  11. 11 6月, 2020 1 次提交
  12. 18 5月, 2020 1 次提交
  13. 21 4月, 2020 1 次提交
  14. 04 2月, 2020 2 次提交
    • Y
      lib: rework bitmap_parse() · 2d626158
      Yury Norov 提交于
      bitmap_parse() is ineffective and full of opaque variables and opencoded
      parts.  It leads to hard understanding and usage of it.  This rework
      includes:
      
      - remove bitmap_shift_left() call from the cycle.  Now it makes the
        complexity of the algorithm as O(nbits^2).  In the suggested approach
        the input string is parsed in reverse direction, so no shifts needed;
      
      - relax requirement on a single comma and no white spaces between
        chunks.  It is considered useful in scripting, and it aligns with
        bitmap_parselist();
      
      - split bitmap_parse() to small readable helpers;
      
      - make an explicit calculation of the end of input line at the
        beginning, so users of the bitmap_parse() won't bother doing this.
      
      Link: http://lkml.kernel.org/r/20200102043031.30357-6-yury.norov@gmail.comSigned-off-by: NYury Norov <yury.norov@gmail.com>
      Cc: Amritha Nambiar <amritha.nambiar@intel.com>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Chris Wilson <chris@chris-wilson.co.uk>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Miklos Szeredi <mszeredi@redhat.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Steffen Klassert <steffen.klassert@secunet.com>
      Cc: "Tobin C . Harding" <tobin@kernel.org>
      Cc: Vineet Gupta <vineet.gupta1@synopsys.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Willem de Bruijn <willemb@google.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      2d626158
    • Y
      lib: make bitmap_parse_user a wrapper on bitmap_parse · e66eda06
      Yury Norov 提交于
      Currently we parse user data byte after byte which leads to
      overcomplicating of parsing algorithm.  There are no performance critical
      users of bitmap_parse_user(), and so we can duplicate user data to kernel
      buffer and simply call bitmap_parselist().  This rework lets us unify and
      simplify bitmap_parse() and bitmap_parse_user(), which is done in the
      following patch.
      
      Link: http://lkml.kernel.org/r/20200102043031.30357-5-yury.norov@gmail.comSigned-off-by: NYury Norov <yury.norov@gmail.com>
      Reviewed-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Amritha Nambiar <amritha.nambiar@intel.com>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Chris Wilson <chris@chris-wilson.co.uk>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Miklos Szeredi <mszeredi@redhat.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Steffen Klassert <steffen.klassert@secunet.com>
      Cc: "Tobin C . Harding" <tobin@kernel.org>
      Cc: Vineet Gupta <vineet.gupta1@synopsys.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Willem de Bruijn <willemb@google.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      e66eda06
  15. 27 1月, 2020 1 次提交
  16. 05 12月, 2019 1 次提交
  17. 25 7月, 2019 1 次提交
  18. 19 6月, 2019 1 次提交
  19. 15 5月, 2019 4 次提交
  20. 04 1月, 2019 1 次提交
    • L
      Remove 'type' argument from access_ok() function · 96d4f267
      Linus Torvalds 提交于
      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: NLinus Torvalds <torvalds@linux-foundation.org>
      96d4f267
  21. 31 10月, 2018 3 次提交
  22. 23 8月, 2018 1 次提交
  23. 02 8月, 2018 1 次提交
  24. 08 6月, 2018 1 次提交
  25. 06 4月, 2018 1 次提交
  26. 07 2月, 2018 2 次提交
    • Y
      bitmap: replace bitmap_{from,to}_u32array · 3aa56885
      Yury Norov 提交于
      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.comSigned-off-by: NYury Norov <ynorov@caviumnetworks.com>
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Cc: Ben Hutchings <ben@decadent.org.uk>
      Cc: David Decotigny <decot@googlers.com>,
      Cc: David S. Miller <davem@davemloft.net>,
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Matthew Wilcox <mawilcox@microsoft.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Heiner Kallweit <hkallweit1@gmail.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      3aa56885
    • Y
      bitmap: new bitmap_copy_safe and bitmap_{from,to}_arr32 · c724f193
      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.comSigned-off-by: NYury Norov <ynorov@caviumnetworks.com>
      Cc: Ben Hutchings <ben@decadent.org.uk>
      Cc: David Decotigny <decot@googlers.com>,
      Cc: David S. Miller <davem@davemloft.net>,
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Matthew Wilcox <mawilcox@microsoft.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      c724f193
  27. 20 10月, 2017 1 次提交
  28. 09 9月, 2017 1 次提交
    • Y
      lib/bitmap.c: make bitmap_parselist() thread-safe and much faster · 0a5ce083
      Yury Norov 提交于
      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.comSigned-off-by: NYury Norov <ynorov@caviumnetworks.com>
      Cc: Noam Camus <noamca@mellanox.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Matthew Wilcox <mawilcox@microsoft.com>
      Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      0a5ce083