Skip to content
Snippets Groups Projects
  1. Sep 26, 2022
  2. Jul 15, 2022
  3. Jul 14, 2022
  4. Jul 12, 2022
  5. Jun 03, 2022
    • Kees Cook's avatar
      bitmap: Fix return values to be unsigned · 005f1700
      Kees Cook authored
      
      Both nodemask and bitmap routines had mixed return values that provided
      potentially signed return values that could never happen. This was
      leading to the compiler getting confusing about the range of possible
      return values (it was thinking things could be negative where they could
      not be). In preparation for fixing nodemask, fix all the bitmap routines
      that should be returning unsigned (or bool) values.
      
      Cc: Yury Norov <yury.norov@gmail.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Christophe de Dinechin <dinechin@redhat.com>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Zhen Lei <thunder.leizhen@huawei.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarYury Norov <yury.norov@gmail.com>
      005f1700
    • Yury Norov's avatar
      lib: add bitmap_{from,to}_arr64 · 0a97953f
      Yury Norov authored
      
      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: default avatarYury Norov <yury.norov@gmail.com>
      0a97953f
    • Mauro Carvalho Chehab's avatar
      lib/bitmap.c make bitmap_print_bitmask_to_buf parseable · 430cd4a2
      Mauro Carvalho Chehab authored
      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: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Signed-off-by: default avatarYury Norov <yury.norov@gmail.com>
      430cd4a2
  6. Mar 24, 2022
    • Randy Dunlap's avatar
      lib: bitmap: fix many kernel-doc warnings · 2699e514
      Randy Dunlap authored
      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: default avatarRandy 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: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      2699e514
  7. Oct 27, 2021
  8. Aug 13, 2021
    • Yury Norov's avatar
      bitmap: extend comment to bitmap_print_bitmask/list_to_buf · 3b35f2a6
      Yury Norov authored
      
      Extend comment to new function to warn potential users about caveats.
      
      Signed-off-by: default avatarYury Norov <yury.norov@gmail.com>
      Signed-off-by: default avatarBarry Song <song.bao.hua@hisilicon.com>
      Link: https://lore.kernel.org/r/20210806110251.560-6-song.bao.hua@hisilicon.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3b35f2a6
    • Tian Tao's avatar
      cpumask: introduce cpumap_print_list/bitmask_to_buf to support large bitmask and list · 1fae5629
      Tian Tao authored
      
      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: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarTian Tao <tiantao6@hisilicon.com>
      Signed-off-by: default avatarBarry Song <song.bao.hua@hisilicon.com>
      Link: https://lore.kernel.org/r/20210806110251.560-2-song.bao.hua@hisilicon.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1fae5629
  9. May 12, 2021
  10. May 10, 2021
  11. May 05, 2021
  12. Mar 08, 2021
  13. Oct 16, 2020
  14. Aug 12, 2020
  15. Jun 11, 2020
  16. May 18, 2020
  17. Apr 20, 2020
  18. Feb 04, 2020
    • Yury Norov's avatar
      lib: rework bitmap_parse() · 2d626158
      Yury Norov authored
      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.com
      
      
      Signed-off-by: default avatarYury 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: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      2d626158
    • Yury Norov's avatar
      lib: make bitmap_parse_user a wrapper on bitmap_parse · e66eda06
      Yury Norov authored
      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.com
      
      
      Signed-off-by: default avatarYury Norov <yury.norov@gmail.com>
      Reviewed-by: default avatarAndy 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: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      e66eda06
  19. Jan 27, 2020
  20. Dec 05, 2019
  21. Jul 25, 2019
  22. Jun 19, 2019
  23. May 15, 2019
  24. Jan 04, 2019
    • Linus Torvalds's avatar
      Remove 'type' argument from access_ok() function · 96d4f267
      Linus Torvalds authored
      
      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: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      96d4f267
  25. Oct 31, 2018
  26. Aug 22, 2018
Loading