1. 07 Aug, 2018 1 commit
  2. 18 Jul, 2018 2 commits
  3. 05 Jun, 2018 1 commit
    • Geert Uytterhoeven's avatar
      lib/vsprintf: Remove atomic-unsafe support for %pCr · 666902e4
      Geert Uytterhoeven authored
      
      
      "%pCr" formats the current rate of a clock, and calls clk_get_rate().
      The latter obtains a mutex, hence it must not be called from atomic
      context.
      
      Remove support for this rarely-used format, as vsprintf() (and e.g.
      printk()) must be callable from any context.
      
      Any remaining out-of-tree users will start seeing the clock's name
      printed instead of its rate.
      Reported-by: default avatarJia-Ju Bai <baijiaju1990@gmail.com>
      Fixes: 900cca29 ("lib/vsprintf: add %pC{,n,r} format specifiers for clocks")
      Link: http://lkml.kernel.org/r/1527845302-12159-5-git-send-email-geert+renesas@glider.be
      
      
      To: Jia-Ju Bai <baijiaju1990@gmail.com>
      To: Jonathan Corbet <corbet@lwn.net>
      To: Michael Turquette <mturquette@baylibre.com>
      To: Stephen Boyd <sboyd@kernel.org>
      To: Zhang Rui <rui.zhang@intel.com>
      To: Eduardo Valentin <edubezval@gmail.com>
      To: Eric Anholt <eric@anholt.net>
      To: Stefan Wahren <stefan.wahren@i2se.com>
      To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: linux-doc@vger.kernel.org
      Cc: linux-clk@vger.kernel.org
      Cc: linux-pm@vger.kernel.org
      Cc: linux-serial@vger.kernel.org
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linux-renesas-soc@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Cc: Geert Uytterhoeven <geert+renesas@glider.be>
      Cc: stable@vger.kernel.org # 4.1+
      Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
      666902e4
  4. 16 May, 2018 1 commit
    • Steven Rostedt (VMware)'s avatar
      vsprintf: Replace memory barrier with static_key for random_ptr_key update · 85f4f12d
      Steven Rostedt (VMware) authored
      Reviewing Tobin's patches for getting pointers out early before
      entropy has been established, I noticed that there's a lone smp_mb() in
      the code. As with most lone memory barriers, this one appears to be
      incorrectly used.
      
      We currently basically have this:
      
      	get_random_bytes(&ptr_key, sizeof(ptr_key));
      	/*
      	 * have_filled_random_ptr_key==true is dependent on get_random_bytes().
      	 * ptr_to_id() needs to see have_filled_random_ptr_key==true
      	 * after get_random_bytes() returns.
      	 */
      	smp_mb();
      	WRITE_ONCE(have_filled_random_ptr_key, true);
      
      And later we have:
      
      	if (unlikely(!have_filled_random_ptr_key))
      		return string(buf, end, "(ptrval)", spec);
      
      /* Missing memory barrier here. */
      
      	hashval = (unsigned long)siphash_1u64((u64)ptr, &ptr_key);
      
      As the CPU can perform speculative loads, we could have a situation
      with the following:
      
      	CPU0				CPU1
      	----				----
      				   load ptr_key = 0
         store ptr_key = random
         smp_mb()
         store have_filled_random_ptr_key
      
      				   load have_filled_random_ptr_key = true
      
      				    BAD BAD BAD! (you're so bad!)
      
      Because nothing prevents CPU1 from loading ptr_key before loading
      have_filled_random_ptr_key.
      
      But this race is very unlikely, but we can't keep an incorrect smp_mb() in
      place. Instead, replace the have_filled_random_ptr_key with a static_branch
      not_filled_random_ptr_key, that is initialized to true and changed to false
      when we get enough entropy. If the update happens in early boot, the
      static_key is updated immediately, otherwise it will have to wait till
      entropy is filled and this happens in an interrupt handler which can't
      enable a static_key, as that requires a preemptible context. In that case, a
      work_queue is used to enable it, as entropy already took too long to
      establish in the first place waiting a little more shouldn't hurt anything.
      
      The benefit of using the static key is that the unlikely branch in
      vsprintf() now becomes a nop.
      
      Link: http://lkml.kernel.org/r/20180515100558.21df515e@gandalf.local.home
      
      Cc: stable@vger.kernel.org
      Fixes: ad67b74d
      
       ("printk: hash addresses printed with %p")
      Acked-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      85f4f12d
  5. 18 Apr, 2018 1 commit
  6. 11 Apr, 2018 8 commits
  7. 06 Apr, 2018 1 commit
  8. 08 Feb, 2018 1 commit
    • Adam Borowski's avatar
      vsprintf: avoid misleading "(null)" for %px · 3a129cc2
      Adam Borowski authored
      Like %pK already does, print "00000000" instead.
      
      This confused people -- the convention is that "(null)" means you tried to
      dereference a null pointer as opposed to printing the address.
      
      Link: http://lkml.kernel.org/r/20180204174521.21383-1-kilobyte@angband.pl
      
      
      To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      To: Steven Rostedt <rostedt@goodmis.org>
      To: linux-kernel@vger.kernel.org
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Joe Perches <joe@perches.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: "Roberts, William C" <william.c.roberts@intel.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: David Laight <David.Laight@ACULAB.COM>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Signed-off-by: default avatarAdam Borowski <kilobyte@angband.pl>
      Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
      3a129cc2
  9. 23 Jan, 2018 1 commit
    • Steven Rostedt (VMware)'s avatar
      vsprintf: Do not have bprintf dereference pointers · 841a915d
      Steven Rostedt (VMware) authored
      When trace_printk() was introduced, it was discussed that making it be as
      low overhead as possible, that the processing of the format string should be
      delayed until it is read. That is, a "trace_printk()" should not convert
      the %d into numbers and so on, but instead, save the fmt string and all the
      args in the buffer at the time of recording. When the trace_printk() data is
      read, it would then parse the format string and do the conversions of the
      saved arguments in the tracing buffer.
      
      The code to perform this was added to vsprintf where vbin_printf() would
      save the arguments of a specified format string in a buffer, then
      bstr_printf() could be used to convert the buffer with the same format
      string into the final output, as if vsprintf() was called in one go.
      
      The issue arises when dereferenced pointers are used. The problem is that
      something like %*pbl which reads a bitmask, will save the pointer to the
      bitmask in the buffer. Then the reading of the buffer via bstr_printf() will
      then look at the pointer to process the final output. Obviously the value of
      that pointer could have changed since the time it was recorded to the time
      the buffer is read. Worse yet, the bitmask could be unmapped, and the
      reading of the trace buffer could actually cause a kernel oops.
      
      Another problem is that user space tools such as perf and trace-cmd do not
      have access to the contents of these pointers, and they become useless when
      the tracing buffer is extracted.
      
      Instead of having vbin_printf() simply save the pointer in the buffer for
      later processing, have it perform the formatting at the time bin_printf() is
      called. This will fix the issue of dereferencing pointers at a later time,
      and has the extra benefit of having user space tools understand these
      values.
      
      Since perf and trace-cmd already can handle %p[sSfF] via saving kallsyms,
      their pointers are saved and not processed during vbin_printf(). If they
      were converted, it would break perf and trace-cmd, as they would not know
      how to deal with the conversion.
      
      Link: http://lkml.kernel.org/r/20171228204025.14a71d8f@gandalf.local.home
      
      Reported-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      841a915d
  10. 09 Jan, 2018 1 commit
    • Sergey Senozhatsky's avatar
      symbol lookup: introduce dereference_symbol_descriptor() · 04b8eb7a
      Sergey Senozhatsky authored
      dereference_symbol_descriptor() invokes appropriate ARCH specific
      function descriptor dereference callbacks:
      - dereference_kernel_function_descriptor() if the pointer is a
        kernel symbol;
      
      - dereference_module_function_descriptor() if the pointer is a
        module symbol.
      
      This is the last step needed to make '%pS/%ps' smart enough to
      handle function descriptor dereference on affected ARCHs and
      to retire '%pF/%pf'.
      
      To refresh it:
        Some architectures (ia64, ppc64, parisc64) use an indirect pointer
        for C function pointers - the function pointer points to a function
        descriptor and we need to dereference it to get the actual function
        pointer.
      
        Function descriptors live in .opd elf section and all affected
        ARCHs (ia64, ppc64, parisc64) handle it properly for kernel and
        modules. So we, technically, can decide if the dereference is
        needed by simply looking at the pointer: if it belongs to .opd
        section then we need to dereference it.
      
        The kernel and modules have their own .opd sections, obviously,
        that's why we need to split dereference_function_descriptor()
        and use separate kernel and module dereference arch callbacks.
      
      Link: http://lkml.kernel.org/r/20171206043649.GB15885@jagdpanzerIV
      
      
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: James Bottomley <jejb@parisc-linux.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Jessica Yu <jeyu@kernel.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: linux-ia64@vger.kernel.org
      Cc: linux-parisc@vger.kernel.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Tested-by: Tony Luck <tony.luck@intel.com> #ia64
      Tested-by: Santosh Sivaraj <santosh@fossix.org> #powerpc
      Tested-by: Helge Deller <deller@gmx.de> #parisc64
      Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
      04b8eb7a
  11. 21 Dec, 2017 2 commits
    • Jonathan Corbet's avatar
      vsprintf: Fix a dangling documentation reference · 27e7c0e8
      Jonathan Corbet authored
      
      
      A reference to printk-formats.txt didn't get updated when the file moved;
      fix that.
      Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
      27e7c0e8
    • Tobin C. Harding's avatar
      doc: convert printk-formats.txt to rst · b3ed2321
      Tobin C. Harding authored
      
      
      Documentation/printk-formats.txt is a candidate for conversion to
      ReStructuredText format. Some effort has already been made to do this
      conversion even thought the suffix is currently .txt
      
      Changes required to complete conversion
      
       - Move printk-formats.txt to core-api/printk-formats.rst
       - Add entry to Documentation/core-api/index.rst
       - Remove entry from Documentation/00-INDEX
       - Fix minor grammatical errors.
       - Order heading adornments as suggested by rst docs.
       - Use 'Passed by reference' uniformly.
       - Update pointer documentation around %px specifier.
       - Fix erroneous double backticks (to commas).
       - Remove extraneous double backticks (suggested by Jonathan Corbet).
       - Simplify documentation for kobject.
      Signed-off-by: default avatarTobin C. Harding <me@tobin.cc>
      [jc: downcased "kernel"]
      Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
      b3ed2321
  12. 29 Nov, 2017 4 commits
    • Linus Torvalds's avatar
      vsprintf: don't use 'restricted_pointer()' when not restricting · ef0010a3
      Linus Torvalds authored
      
      
      Instead, just fall back on the new '%p' behavior which hashes the
      pointer.
      
      Otherwise, '%pK' - that was intended to mark a pointer as restricted -
      just ends up leaking pointers that a normal '%p' wouldn't leak.  Which
      just make the whole thing pointless.
      
      I suspect we should actually get rid of '%pK' entirely, and make it just
      work as '%p' regardless, but this is the minimal obvious fix.  People
      who actually use 'kptr_restrict' should weigh in on which behavior they
      want.
      
      Cc: Tobin Harding <me@tobin.cc>
      Cc: Kees Cook <keescook@chromium.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      ef0010a3
    • Tobin C. Harding's avatar
      vsprintf: add printk specifier %px · 7b1924a1
      Tobin C. Harding authored
      
      
      printk specifier %p now hashes all addresses before printing. Sometimes
      we need to see the actual unmodified address. This can be achieved using
      %lx but then we face the risk that if in future we want to change the
      way the Kernel handles printing of pointers we will have to grep through
      the already existent 50 000 %lx call sites. Let's add specifier %px as a
      clear, opt-in, way to print a pointer and maintain some level of
      isolation from all the other hex integer output within the Kernel.
      
      Add printk specifier %px to print the actual unmodified address.
      Signed-off-by: default avatarTobin C. Harding <me@tobin.cc>
      7b1924a1
    • Tobin C. Harding's avatar
      printk: hash addresses printed with %p · ad67b74d
      Tobin C. Harding authored
      
      
      Currently there exist approximately 14 000 places in the kernel where
      addresses are being printed using an unadorned %p. This potentially
      leaks sensitive information regarding the Kernel layout in memory. Many
      of these calls are stale, instead of fixing every call lets hash the
      address by default before printing. This will of course break some
      users, forcing code printing needed addresses to be updated.
      
      Code that _really_ needs the address will soon be able to use the new
      printk specifier %px to print the address.
      
      For what it's worth, usage of unadorned %p can be broken down as
      follows (thanks to Joe Perches).
      
      $ git grep -E '%p[^A-Za-z0-9]' | cut -f1 -d"/" | sort | uniq -c
         1084 arch
           20 block
           10 crypto
           32 Documentation
         8121 drivers
         1221 fs
          143 include
          101 kernel
           69 lib
          100 mm
         1510 net
           40 samples
            7 scripts
           11 security
          166 sound
          152 tools
            2 virt
      
      Add function ptr_to_id() to map an address to a 32 bit unique
      identifier. Hash any unadorned usage of specifier %p and any malformed
      specifiers.
      Signed-off-by: default avatarTobin C. Harding <me@tobin.cc>
      ad67b74d
    • Tobin C. Harding's avatar
      vsprintf: refactor %pK code out of pointer() · 57e73442
      Tobin C. Harding authored
      
      
      Currently code to handle %pK is all within the switch statement in
      pointer(). This is the wrong level of abstraction. Each of the other switch
      clauses call a helper function, pK should do the same.
      
      Refactor code out of pointer() to new function restricted_pointer().
      Signed-off-by: default avatarTobin C. Harding <me@tobin.cc>
      57e73442
  13. 25 Oct, 2017 1 commit
    • Mark Rutland's avatar
      locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns... · 6aa7de05
      Mark Rutland authored
      
      locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to 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's avatarMark Rutland <mark.rutland@arm.com>
      Signed-off-by: default avatarPaul 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: default avatarIngo Molnar <mingo@kernel.org>
      6aa7de05
  14. 27 Jun, 2017 1 commit
    • Pantelis Antoniou's avatar
      vsprintf: Add %p extension "%pOF" for device tree · ce4fecf1
      Pantelis Antoniou authored
      
      
      90% of the usage of device node's full_name is printing it out in a
      kernel message. However, storing the full path for every node is
      wasteful and redundant. With a custom format specifier, we can generate
      the full path at run-time and eventually remove the full path from every
      node.
      
      For instance typical use is:
      	pr_info("Frobbing node %s\n", node->full_name);
      
      Which can be written now as:
      	pr_info("Frobbing node %pOF\n", node);
      
      '%pO' is the base specifier to represent kobjects with '%pOF'
      representing struct device_node. Currently, struct device_node is the
      only supported type of kobject.
      
      More fine-grained control of formatting includes printing the name,
      flags, path-spec name and others, explained in the documentation entry.
      
      Originally written by Pantelis, but pretty much rewrote the core
      function using existing string/number functions. The 2 passes were
      unnecessary and have been removed. Also, updated the checkpatch.pl
      check. The unittest code was written by Grant Likely.
      Signed-off-by: default avatarPantelis Antoniou <pantelis.antoniou@konsulko.com>
      Acked-by: default avatarJoe Perches <joe@perches.com>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
      ce4fecf1
  15. 05 Jun, 2017 1 commit
  16. 09 May, 2017 1 commit
  17. 02 Apr, 2017 1 commit
  18. 28 Feb, 2017 1 commit
  19. 21 May, 2016 2 commits
    • Andy Shevchenko's avatar
      lib/uuid.c: introduce a few more generic helpers · 2b1b0d66
      Andy Shevchenko authored
      
      
      There are new helpers in this patch:
      
        uuid_is_valid		checks if a UUID is valid
        uuid_be_to_bin	converts from string to binary (big endian)
        uuid_le_to_bin	converts from string to binary (little endian)
      
      They will be used in future, i.e. in the following patches in the series.
      
      This also moves the indices arrays to lib/uuid.c to be shared accross
      modules.
      
      [andriy.shevchenko@linux.intel.com: fix typo]
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Reviewed-by: default avatarMatt Fleming <matt@codeblueprint.co.uk>
      Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
      Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: "Theodore Ts'o" <tytso@mit.edu>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Jens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      2b1b0d66
    • Andy Shevchenko's avatar
      lib/vsprintf: simplify UUID printing · aa4ea1c3
      Andy Shevchenko authored
      
      
      There are few functions here and there along with type definitions that
      provide UUID API.  This series consolidates everything under one hood
      and converts current users.
      
      This has been tested for a while internally, however it doesn't mean we
      covered all possible cases (especially accuracy of UUID constants after
      conversion).  So, please test this as much as you can and provide your
      tag.  We appreciate the effort.
      
      The ACPI conversion is postponed for now to sort more generic things out
      first.
      
      This patch (of 9):
      
      Since we have hex_byte_pack_upper() we may use it directly and avoid
      second loop.
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Reviewed-by: default avatarMatt Fleming <matt@codeblueprint.co.uk>
      Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
      Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: "Theodore Ts'o" <tytso@mit.edu>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Jens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      aa4ea1c3
  20. 17 Mar, 2016 1 commit
    • Jessica Yu's avatar
      sscanf: implement basic character sets · f9310b2f
      Jessica Yu authored
      
      
      Implement basic character sets for the '%[' conversion specifier.
      
      The '%[' conversion specifier matches a nonempty sequence of characters
      from the specified set of accepted (or with '^', rejected) characters
      between the brackets.  The substring matched is to be made up of
      characters in (or not in) the set.  This is useful for matching
      substrings that are delimited by something other than spaces.
      
      This implementation differs from its glibc counterpart in the following ways:
       (1) No support for character ranges (e.g., 'a-z' or '0-9')
       (2) The hyphen '-' is not a special character
       (3) The closing bracket ']' cannot be matched
       (4) No support (yet) for discarding matching input ('%*[')
      
      The bitmap code is largely based upon sample code which was provided by
      Rasmus.
      
      The motivation for adding character set support to sscanf originally
      stemmed from the kernel livepatching project.  An ongoing patchset
      utilizes new livepatch Elf symbol and section names to store important
      metadata livepatch needs to properly apply its patches.  Such metadata
      is stored in these section and symbol names as substrings delimited by
      periods '.' and commas ','.  For example, a livepatch symbol name might
      look like this:
      
      .klp.sym.vmlinux.printk,0
      
      However, sscanf currently can only extract "substrings" delimited by
      whitespace using the "%s" specifier.  Thus for the above symbol name,
      one cannot not use sscanf() to extract substrings "vmlinux" or
      "printk", for example.  A number of discussions on the livepatch
      mailing list dealing with string parsing code for extracting these '.'
      and ',' delimited substrings eventually led to the conclusion that such
      code would be completely unnecessary if the kernel sscanf() supported
      character sets.  Thus only a single sscanf() call would be necessary to
      extract these substrings.  In addition, such an addition to sscanf()
      could benefit other areas of the kernel that might have a similar need
      in the future.
      
      [akpm@linux-foundation.org: 80-col tweaks]
      Signed-off-by: default avatarJessica Yu <jeyu@redhat.com>
      Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Kees Cook <keescook@chromium.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      f9310b2f
  21. 15 Mar, 2016 1 commit
    • Vlastimil Babka's avatar
      mm, printk: introduce new format string for flags · edf14cdb
      Vlastimil Babka authored
      
      
      In mm we use several kinds of flags bitfields that are sometimes printed
      for debugging purposes, or exported to userspace via sysfs.  To make
      them easier to interpret independently on kernel version and config, we
      want to dump also the symbolic flag names.  So far this has been done
      with repeated calls to pr_cont(), which is unreliable on SMP, and not
      usable for e.g.  sysfs export.
      
      To get a more reliable and universal solution, this patch extends
      printk() format string for pointers to handle the page flags (%pGp),
      gfp_flags (%pGg) and vma flags (%pGv).  Existing users of
      dump_flag_names() are converted and simplified.
      
      It would be possible to pass flags by value instead of pointer, but the
      %p format string for pointers already has extensions for various kernel
      structures, so it's a good fit, and the extra indirection in a
      non-critical path is negligible.
      
      [linux@rasmusvillemoes.dk: lots of good implementation suggestions]
      Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
      Acked-by: default avatarMichal Hocko <mhocko@suse.com>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Cc: Minchan Kim <minchan@kernel.org>
      Cc: Sasha Levin <sasha.levin@oracle.com>
      Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
      Cc: Mel Gorman <mgorman@suse.de>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      edf14cdb
  22. 12 Feb, 2016 1 commit
  23. 16 Jan, 2016 5 commits
    • Andy Shevchenko's avatar
      lib/vsprintf: factor out %pN[F] handler as netdev_bits() · 5b17aecf
      Andy Shevchenko authored
      
      
      Move switch case to the netdev_features_string() and rename it to
      netdev_bits().  In the future we can extend it as needed.
      
      Here we replace the fallback of %pN from '%p' with possible flags to
      sticter '0x%p' without any flags variation.
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Joe Perches <joe@perches.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      5b17aecf
    • Andy Shevchenko's avatar
      lib/vsprintf: refactor duplicate code to special_hex_number() · 3cab1e71
      Andy Shevchenko authored
      
      
      special_hex_number() is a helper to print a fixed size type in a hex
      format with '0x' prefix, zero padding, and small letters.  In the module
      we have already several copies of such code.  Consolidate them under
      special_hex_number() helper.
      
      There are couple of differences though.
      
      It seems nobody cared about the output in case of CONFIG_KALLSYMS=n,
      when printing symbol address, because the asked field width is not
      enough to care last 2 characters in the string represantation of the
      pointer.  Fixed here.
      
      The %pNF specifier used to be allowed with a specific field width,
      though there is neither any user of it nor mention the possibility in
      the documentation.
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Joe Perches <joe@perches.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      3cab1e71
    • Rasmus Villemoes's avatar
      lib/vsprintf.c: warn about too large precisions and field widths · 4d72ba01
      Rasmus Villemoes authored
      
      
      The field width is overloaded to pass some extra information for some %p
      extensions (e.g.  #bits for %pb).  But we might silently truncate the
      passed value when we stash it in struct printf_spec (see e.g.
      "lib/vsprintf.c: expand field_width to 24 bits").  Hopefully 23 value
      bits should now be enough for everybody, but if not, let's make some
      noise.
      
      Do the same for the precision.  In both cases, clamping seems more
      sensible than truncating.  While, according to POSIX, "A negative
      precision is taken as if the precision were omitted.", the kernel's
      printf has always treated that case as if the precision was 0, so we use
      that as lower bound.  For the field width, the smallest representable
      value is actually -(1<<23), but a negative field width means 'set the
      LEFT flag and use the absolute value', so we want the absolute value to
      fit.
      Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Al Viro <viro@ZenIV.linux.org.uk>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Joe Perches <joe@perches.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Maurizio Lombardi <mlombard@redhat.com>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      4d72ba01
    • Rasmus Villemoes's avatar
      lib/vsprintf.c: help gcc make number() smaller · 1c7a8e62
      Rasmus Villemoes authored
      
      
      One consequence of the reorganization of struct printf_spec to make
      field_width 24 bits was that number() gained about 180 bytes.  Since
      spec is never passed to other functions, we can help gcc make number()
      lose most of that extra weight by using local variables for the field
      width and precision.
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Al Viro <viro@ZenIV.linux.org.uk>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Joe Perches <joe@perches.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Maurizio Lombardi <mlombard@redhat.com>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      1c7a8e62
    • Rasmus Villemoes's avatar
      lib/vsprintf.c: expand field_width to 24 bits · d0484193
      Rasmus Villemoes authored
      Maurizio Lombardi reported a problem [1] with the %pb extension: It
      doesn't work for sufficiently large bitmaps, since the size is stashed
      in the field_width field of the struct printf_spec, which is currently
      an s16.  Concretely, this manifested itself in
      /sys/bus/pseudo/drivers/scsi_debug/map being empty, since the bitmap
      printer got a size of 0, which is the 16 bit truncation of the actual
      bitmap size.
      
      We do want to keep struct printf_spec at 8 bytes so that it can cheaply
      be passed by value.  The qualifier field is only used for internal
      bookkeeping in format_decode, so we might as well use a local variable
      for that.  This gives us an additional 8 bits, which we can then use for
      the field width.
      
      To stay in 8 bytes, we need to do a little rearranging and make the type
      member a bitfield as well.  For consistency, change all the members to
      bit fields.  gcc doesn't generate much worse code with these changes (in
      fact, bloat-o-meter says we save 300 bytes - which I think is a little
      surprising).
      
      I didn't find a BUILD_BUG/compiletime_assertion/... which would work
      outside function context, so for now I just open-coded it.
      
      [1] http://thread.gmane.org/gmane.linux.kernel/2034835
      
      
      
      [akpm@linux-foundation.org: avoid open-coded BUILD_BUG_ON]
      Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Reported-by: default avatarMaurizio Lombardi <mlombard@redhat.com>
      Acked-by: default avatarTejun Heo <tj@kernel.org>
      Cc: Al Viro <viro@ZenIV.linux.org.uk>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Joe Perches <joe@perches.com>
      Cc: Kees Cook <keescook@chromium.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      d0484193