04 Apr, 2014

1 commit

  • All in-kernel users of %n in format strings have now been removed and
    the %n directive is ignored. Remove the handling of %n so that it is
    treated the same as any other invalid format string directive. Keep a
    warning in place to deter new instances of %n in format strings.

    Signed-off-by: Ryan Mallon
    Acked-by: Kees Cook
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ryan Mallon
     

27 Feb, 2014

1 commit

  • Sometimes we have a struct resource where we know the type (MEM/IO/etc.)
    and the size, but we haven't assigned address space for it. The
    IORESOURCE_UNSET flag is a way to indicate this situation. For these
    "unset" resources, the start address is meaningless, so print only the
    size, e.g.,

    - pci 0000:0c:00.0: reg 184: [mem 0x00000000-0x00001fff 64bit]
    + pci 0000:0c:00.0: reg 184: [mem size 0x2000 64bit]

    For %pr (printing with raw flags), we still print the address range,
    because %pr is mostly used for debugging anyway.

    Thanks to Fengguang Wu for suggesting
    resource_size().

    Signed-off-by: Bjorn Helgaas

    Bjorn Helgaas
     

24 Jan, 2014

1 commit

  • dma_addr_t's can be either u32 or u64 depending on a CONFIG option.

    There are a few hundred dma_addr_t's printed via either cast to unsigned
    long long, unsigned long or no cast at all.

    Add %pad to be able to emit them without the cast.

    Update Documentation/printk-formats.txt too.

    Signed-off-by: Joe Perches
    Cc: "Shevchenko, Andriy"
    Cc: Rob Landley
    Cc: Laurent Pinchart
    Cc: Julia Lawall
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joe Perches
     

15 Nov, 2013

1 commit

  • This ignores %n in printf again, as was originally documented.
    Implementing %n poses a greater security risk than utility, so it should
    stay ignored. To help anyone attempting to use %n, a warning will be
    emitted if it is encountered.

    Based on an earlier patch by Joe Perches.

    Because %n was designed to write to pointers on the stack, it has been
    frequently used as an attack vector when bugs are found that leak
    user-controlled strings into functions that ultimately process format
    strings. While this class of bug can still be turned into an
    information leak, removing %n eliminates the common method of elevating
    such a bug into an arbitrary kernel memory writing primitive,
    significantly reducing the danger of this class of bug.

    For seq_file users that need to know the length of a written string for
    padding, please see seq_setwidth() and seq_pad() instead.

    Signed-off-by: Kees Cook
    Cc: Joe Perches
    Cc: Tetsuo Handa
    Cc: David Miller
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kees Cook
     

13 Nov, 2013

2 commits

  • Looks like these were added to Documentation/printk-formats.txt but
    not the in-file table.

    Signed-off-by: Olof Johansson
    Cc: Al Viro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Olof Johansson
     
  • Some setuid binaries will allow reading of files which have read
    permission by the real user id. This is problematic with files which
    use %pK because the file access permission is checked at open() time,
    but the kptr_restrict setting is checked at read() time. If a setuid
    binary opens a %pK file as an unprivileged user, and then elevates
    permissions before reading the file, then kernel pointer values may be
    leaked.

    This happens for example with the setuid pppd application on Ubuntu 12.04:

    $ head -1 /proc/kallsyms
    00000000 T startup_32

    $ pppd file /proc/kallsyms
    pppd: In file /proc/kallsyms: unrecognized option 'c1000000'

    This will only leak the pointer value from the first line, but other
    setuid binaries may leak more information.

    Fix this by adding a check that in addition to the current process having
    CAP_SYSLOG, that effective user and group ids are equal to the real ids.
    If a setuid binary reads the contents of a file which uses %pK then the
    pointer values will be printed as NULL if the real user is unprivileged.

    Update the sysctl documentation to reflect the changes, and also correct
    the documentation to state the kptr_restrict=0 is the default.

    This is a only temporary solution to the issue. The correct solution is
    to do the permission check at open() time on files, and to replace %pK
    with a function which checks the open() time permission. %pK uses in
    printk should be removed since no sane permission check can be done, and
    instead protected by using dmesg_restrict.

    Signed-off-by: Ryan Mallon
    Cc: Kees Cook
    Cc: Alexander Viro
    Cc: Joe Perches
    Cc: "Eric W. Biederman"
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ryan Mallon
     

04 Sep, 2013

1 commit

  • New formats: %p[dD][234]?. The next pointer is interpreted as struct dentry *
    or struct file * resp. ('d' => dentry, 'D' => file) and the last component(s)
    of pathname are printed (%pd => just the last one, %pd2 => the last two, etc.)

    Signed-off-by: Al Viro

    Al Viro
     

10 Jul, 2013

1 commit

  • Pull networking updates from David Miller:
    "This is a re-do of the net-next pull request for the current merge
    window. The only difference from the one I made the other day is that
    this has Eliezer's interface renames and the timeout handling changes
    made based upon your feedback, as well as a few bug fixes that have
    trickeled in.

    Highlights:

    1) Low latency device polling, eliminating the cost of interrupt
    handling and context switches. Allows direct polling of a network
    device from socket operations, such as recvmsg() and poll().

    Currently ixgbe, mlx4, and bnx2x support this feature.

    Full high level description, performance numbers, and design in
    commit 0a4db187a999 ("Merge branch 'll_poll'")

    From Eliezer Tamir.

    2) With the routing cache removed, ip_check_mc_rcu() gets exercised
    more than ever before in the case where we have lots of multicast
    addresses. Use a hash table instead of a simple linked list, from
    Eric Dumazet.

    3) Add driver for Atheros CQA98xx 802.11ac wireless devices, from
    Bartosz Markowski, Janusz Dziedzic, Kalle Valo, Marek Kwaczynski,
    Marek Puzyniak, Michal Kazior, and Sujith Manoharan.

    4) Support reporting the TUN device persist flag to userspace, from
    Pavel Emelyanov.

    5) Allow controlling network device VF link state using netlink, from
    Rony Efraim.

    6) Support GRE tunneling in openvswitch, from Pravin B Shelar.

    7) Adjust SOCK_MIN_RCVBUF and SOCK_MIN_SNDBUF for modern times, from
    Daniel Borkmann and Eric Dumazet.

    8) Allow controlling of TCP quickack behavior on a per-route basis,
    from Cong Wang.

    9) Several bug fixes and improvements to vxlan from Stephen
    Hemminger, Pravin B Shelar, and Mike Rapoport. In particular,
    support receiving on multiple UDP ports.

    10) Major cleanups, particular in the area of debugging and cookie
    lifetime handline, to the SCTP protocol code. From Daniel
    Borkmann.

    11) Allow packets to cross network namespaces when traversing tunnel
    devices. From Nicolas Dichtel.

    12) Allow monitoring netlink traffic via AF_PACKET sockets, in a
    manner akin to how we monitor real network traffic via ptype_all.
    From Daniel Borkmann.

    13) Several bug fixes and improvements for the new alx device driver,
    from Johannes Berg.

    14) Fix scalability issues in the netem packet scheduler's time queue,
    by using an rbtree. From Eric Dumazet.

    15) Several bug fixes in TCP loss recovery handling, from Yuchung
    Cheng.

    16) Add support for GSO segmentation of MPLS packets, from Simon
    Horman.

    17) Make network notifiers have a real data type for the opaque
    pointer that's passed into them. Use this to properly handle
    network device flag changes in arp_netdev_event(). From Jiri
    Pirko and Timo Teräs.

    18) Convert several drivers over to module_pci_driver(), from Peter
    Huewe.

    19) tcp_fixup_rcvbuf() can loop 500 times over loopback, just use a
    O(1) calculation instead. From Eric Dumazet.

    20) Support setting of explicit tunnel peer addresses in ipv6, just
    like ipv4. From Nicolas Dichtel.

    21) Protect x86 BPF JIT against spraying attacks, from Eric Dumazet.

    22) Prevent a single high rate flow from overruning an individual cpu
    during RX packet processing via selective flow shedding. From
    Willem de Bruijn.

    23) Don't use spinlocks in TCP md5 signing fast paths, from Eric
    Dumazet.

    24) Don't just drop GSO packets which are above the TBF scheduler's
    burst limit, chop them up so they are in-bounds instead. Also
    from Eric Dumazet.

    25) VLAN offloads are missed when configured on top of a bridge, fix
    from Vlad Yasevich.

    26) Support IPV6 in ping sockets. From Lorenzo Colitti.

    27) Receive flow steering targets should be updated at poll() time
    too, from David Majnemer.

    28) Fix several corner case regressions in PMTU/redirect handling due
    to the routing cache removal, from Timo Teräs.

    29) We have to be mindful of ipv4 mapped ipv6 sockets in
    upd_v6_push_pending_frames(). From Hannes Frederic Sowa.

    30) Fix L2TP sequence number handling bugs, from James Chapman."

    * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1214 commits)
    drivers/net: caif: fix wrong rtnl_is_locked() usage
    drivers/net: enic: release rtnl_lock on error-path
    vhost-net: fix use-after-free in vhost_net_flush
    net: mv643xx_eth: do not use port number as platform device id
    net: sctp: confirm route during forward progress
    virtio_net: fix race in RX VQ processing
    virtio: support unlocked queue poll
    net/cadence/macb: fix bug/typo in extracting gem_irq_read_clear bit
    Documentation: Fix references to defunct linux-net@vger.kernel.org
    net/fs: change busy poll time accounting
    net: rename low latency sockets functions to busy poll
    bridge: fix some kernel warning in multicast timer
    sfc: Fix memory leak when discarding scattered packets
    sit: fix tunnel update via netlink
    dt:net:stmmac: Add dt specific phy reset callback support.
    dt:net:stmmac: Add support to dwmac version 3.610 and 3.710
    dt:net:stmmac: Allocate platform data only if its NULL.
    net:stmmac: fix memleak in the open method
    ipv6: rt6_check_neigh should successfully verify neigh if no NUD information are available
    net: ipv6: fix wrong ping_v6_sendmsg return value
    ...

    Linus Torvalds
     

02 Jul, 2013

1 commit

  • In order to avoid making code that deals with printing both, IPv4 and
    IPv6 addresses, unnecessary complicated as for example ...

    if (sa.sa_family == AF_INET6)
    printk("... %pI6 ...", ..sin6_addr);
    else
    printk("... %pI4 ...", ..sin_addr.s_addr);

    ... it would be better to introduce a format specifier that can deal
    with those kind of situations internally; just as we have a "struct
    sockaddr" for generic mapping into "struct sockaddr_in" or "struct
    sockaddr_in6" as e.g. done in "union sctp_addr". Then, we could
    reduce the above statement into something like:

    printk("... %pIS ..", &sockaddr);

    In case our pointer is NULL, pointer() then deals with that already at
    an earlier point in time internally. While we're at it, support for both
    %piS/%pIS, where 'S' stands for sockaddr, comes (almost) for free.

    Additionally to that, postfix specifiers 'p', 'f' and 's' are supported
    as suggested and initially implemented in 2009 by Joe Perches [1].
    Handling of those additional specifiers orientate on the initial RFC that
    was proposed. Also we support IPv6 compressed format specified by 'c' and
    various other IPv4 extensions as stated in the documentation part.

    Likely, there are many other areas than just SCTP in the kernel to make
    use of this extension as well.

    [1] http://patchwork.ozlabs.org/patch/31480/

    Signed-off-by: Daniel Borkmann
    CC: Joe Perches
    CC: linux-kernel@vger.kernel.org
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

29 May, 2013

1 commit


01 May, 2013

1 commit

  • print_symbol takes a long and converts it to a function
    name and offset. %pS does something similar, but doesn't
    translate the address via __builtin_extract_return_addr.
    %pSR does the translation.

    This will enable replacing multiple calls like
    printk(...);
    printk_symbol(addr);
    printk("\n");
    with a single non-interleavable in dmesg
    printk("... %pSR\n", (void *)addr);

    Update documentation too.

    Signed-off-by: Joe Perches
    Signed-off-by: Jiri Kosina

    Joe Perches
     

22 Feb, 2013

1 commit

  • Add the %pa format specifier for printing a phys_addr_t type and its
    derivative types (such as resource_size_t), since the physical address
    size on some platforms can vary based on build options, regardless of
    the native integer type.

    Signed-off-by: Stepan Moskovchenko
    Cc: Rob Landley
    Cc: George Spelvin
    Cc: Andy Shevchenko
    Cc: Stephen Boyd
    Cc: Andrei Emeltchenko
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Stepan Moskovchenko
     

18 Dec, 2012

3 commits

  • Update the documentation for simple_strto* to reflect that it has been
    obsoleted and advise the usage of kstrto*.

    Signed-off-by: Eldad Zack
    Cc: J. Bruce Fields
    Cc: Joe Perches
    Cc: Randy Dunlap
    Cc: Alexey Dobriyan
    Cc: Rob Landley
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eldad Zack
     
  • This is another step towards better standard conformance. Rather than
    adding a local buffer to store the specified portion of the string (with
    the need to enforce an arbitrary maximum supported width to limit the
    buffer size), do a maximum width conversion and then drop as much of it as
    is necessary to meet the caller's request.

    Also fail on negative field widths.

    Uses the deprecated simple_strto*() functions because kstrtoXX() fail on
    non-zero terminated strings.

    Signed-off-by: Jan Beulich
    Cc: Alexey Dobriyan
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Beulich
     
  • Documentation/printk-formats.txt says to use %zd for a ssize_t argument
    and some drivers do. Unfortunately this prints a positive number for
    negative values eg:

    tpm_tis 70030000.tpm_tis: tpm_transmit: tpm_send: error 4294967234

    Add a case to va_args a ssize_t type if the interpretation should be
    signed.

    Tested on PPC32.

    Signed-off-by: Jason Gunthorpe
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jason Gunthorpe
     

06 Oct, 2012

6 commits

  • Xen's pciback points out a couple of deficiencies with vsscanf()'s
    standard conformance:

    - Trailing character matching cannot be checked by the caller: With a
    format string of "(%x:%x.%x) %n" absence of the closing parenthesis
    cannot be checked, as input of "(00:00.0)" doesn't cause the %n to be
    evaluated (because of the code not skipping white space before the
    trailing %n).

    - The parameter corresponding to a trailing %n could get filled even if
    there was a matching error: With a format string of "(%x:%x.%x)%n",
    input of "(00:00.0]" would still fill the respective variable pointed to
    (and hence again make the mismatch non-detectable by the caller).

    This patch aims at fixing those, but leaves other non-conforming aspects
    of it untouched, among them these possibly relevant ones:

    - improper handling of the assignment suppression character '*' (blindly
    discarding all succeeding non-white space from the format and input
    strings),

    - not honoring conversion specifiers for %n, - not recognizing the C99
    conversion specifier 't' (recognized by vsprintf()).

    Signed-off-by: Jan Beulich
    Cc: Konrad Rzeszutek Wilk
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Beulich
     
  • Acked-by: Andrei Emeltchenko
    Signed-off-by: Andy Shevchenko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     
  • Numbering the 8 potential digits 2 though 9 never did make a lot of sense.

    Signed-off-by: George Spelvin
    Cc: Denys Vlasenko
    Cc: Michal Nazarewicz
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    George Spelvin
     
  • If you're going to have a conditional branch after each 32x32->64-bit
    multiply, might as well shrink the code and make it a loop.

    This also avoids using the long multiply for small integers.

    (This leaves the comments in a confusing state, but that's a separate
    patch to make review easier.)

    Signed-off-by: George Spelvin
    Cc: Denys Vlasenko
    Cc: Michal Nazarewicz
    Cc: Rabin Vincent
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    George Spelvin
     
  • The same multiply-by-inverse technique can be used to convert division by
    10000 to a 32x32->64-bit multiply.

    Signed-off-by: George Spelvin
    Cc: Denys Vlasenko
    Cc: Michal Nazarewicz
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    George Spelvin
     
  • Shrink the reciprocal approximations used in put_dec_full4() based on the
    comments in put_dec_full9().

    Signed-off-by: George Spelvin
    Cc: Denys Vlasenko
    Cc: Michal Nazarewicz
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    George Spelvin
     

31 Jul, 2012

4 commits

  • There are many places in the kernel where the drivers print small buffers
    as a hex string. This patch adds a support of the variable width buffer
    to print it as a hex string with a delimiter. The idea came from Pavel
    Roskin here: http://www.digipedia.pl/usenet/thread/18835/17449/

    Sample output of
    pr_info("buf[%d:%d] %*phC\n", from, len, len, &buf[from]);
    could be look like this:
    [ 0.726130] buf[51:8] e8:16:b6:ef:e3:74:45:6e
    [ 0.750736] buf[59:15] 31:81:b8:3f:35:49:06:ae:df:32:06:05:4a:af:55
    [ 0.757602] buf[17:5] ac:16:d5:2c:ef

    Signed-off-by: Andy Shevchenko
    Cc: Joe Perches
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     
  • When using ALT+SysRq+Q all the pointers are replaced with "pK-error" like
    this:

    [23153.208033] .base: pK-error

    with echo h > /proc/sysrq-trigger it works:

    [23107.776363] .base: ffff88023e60d540

    The intent behind this behavior was to return "pK-error" in cases where
    the %pK format specifier was used in interrupt context, because the
    CAP_SYSLOG check wouldn't be meaningful. Clearly this should only apply
    when kptr_restrict is actually enabled though.

    Reported-by: Stevie Trujillo
    Signed-off-by: Dan Rosenberg
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dan Rosenberg
     
  • Cc: Randy Dunlap
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     
  • Bluetooth uses mostly LE byte order which is reversed for visual
    interpretation. Currently in Bluetooth in use unsafe batostr function.

    This is a slightly modified version of Joe's patch (sent Sat, Dec 4,
    2010).

    Signed-off-by: Andrei Emeltchenko
    Cc: Joe Perches
    Cc: Marcel Holtmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrei Emeltchenko
     

01 Jun, 2012

2 commits

  • Previous code was using optimizations which were developed to work well
    even on narrow-word CPUs (by today's standards). But Linux runs only on
    32-bit and wider CPUs. We can use that.

    First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
    divide by 10 much larger numbers, and thus we can print groups of 9 digits
    instead of groups of 5 digits.

    Next: there are two algorithms to print larger numbers. One is generic:
    divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
    It's conceptually simple, but requires an (unsigned long long) /
    1000000000 division.

    Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
    manipulates them cleverly and generates groups of 4 decimal digits. It so
    happens that it does NOT require long long division.

    If long is > 32 bits, division of 64-bit values is relatively easy, and we
    will use the first algorithm. If long long is > 64 bits (strange
    architecture with VERY large long long), second algorithm can't be used,
    and we again use the first one.

    Else (if long is 32 bits and long long is 64 bits) we use second one.

    And third: there is a simple optimization which takes fast path not only
    for zero as was done before, but for all one-digit numbers.

    In all tested cases new code is faster than old one, in many cases by 30%,
    in few cases by more than 50% (for example, on x86-32, conversion of
    12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
    case.

    This patch is based upon an original from Michal Nazarewicz.

    [akpm@linux-foundation.org: checkpatch fixes]
    Signed-off-by: Michal Nazarewicz
    Signed-off-by: Denys Vlasenko
    Cc: Douglas W Jones
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Denys Vlasenko
     
  • The '%p' output of the kernel's vsprintf() uses spec.field_width to
    determine how many digits to output based on 2 * sizeof(void*) so that all
    digits of a pointer are shown. ie. a pointer will be output as
    "001A2B3C" instead of "1A2B3C". However, if the '#' flag is used in the
    format (%#p), then the code doesn't take into account the width of the
    '0x' prefix and will end up outputing "0x1A2B3C" instead of "0x001A2B3C".

    This patch reworks the "pointer()" format hook to include 2 characters for
    the '0x' prefix if the '#' flag is included.

    [akpm@linux-foundation.org: checkpatch fixes]
    Signed-off-by: Grant Likely
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Grant Likely
     

30 May, 2012

2 commits

  • number()'s behaviour is slighly changed: 0 becomes "0" instead of "00"
    when using the flag SPECIAL and base 8.

    Before:
    Number\Format %o %#o %x %#x
    0 0 00 0 0x0
    1 1 01 1 0x1
    16 20 020 10 0x10

    After:
    Number\Format %o %#o %x %#x
    0 0 0 0 0x0
    1 1 01 1 0x1
    16 20 020 10 0x10

    Signed-off-by: Pierre Carrier
    Acked-by: Stephen Rothwell
    Cc: Joe Perches
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pierre Carrier
     
  • Using %ps in a printk format will sometimes fail silently and print the
    empty string if the address passed in does not match a symbol that
    kallsyms knows about. But using %pS will fall back to printing the full
    address if kallsyms can't find the symbol. Make %ps act the same as %pS
    by falling back to printing the address.

    While we're here also make %ps print the module that a symbol comes from
    so that it matches what %pS already does. Take this simple function for
    example (in a module):

    static void test_printk(void)
    {
    int test;
    pr_info("with pS: %pS\n", &test);
    pr_info("with ps: %ps\n", &test);
    }

    Before this patch:

    with pS: 0xdff7df44
    with ps:

    After this patch:

    with pS: 0xdff7df44
    with ps: 0xdff7df44

    Signed-off-by: Stephen Boyd
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Stephen Boyd
     

25 Mar, 2012

1 commit

  • Pull cleanup of fs/ and lib/ users of module.h from Paul Gortmaker:
    "Fix up files in fs/ and lib/ dirs to only use module.h if they really
    need it.

    These are trivial in scope vs the work done previously. We now have
    things where any few remaining cleanups can be farmed out to arch or
    subsystem maintainers, and I have done so when possible. What is
    remaining here represents the bits that don't clearly lie within a
    single arch/subsystem boundary, like the fs dir and the lib dir.

    Some duplicate includes arising from overlapping fixes from
    independent subsystem maintainer submissions are also quashed."

    Fix up trivial conflicts due to clashes with other include file cleanups
    (including some due to the previous bug.h cleanup pull).

    * tag 'module-for-3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux:
    lib: reduce the use of module.h wherever possible
    fs: reduce the use of module.h wherever possible
    includecheck: delete any duplicate instances of module.h

    Linus Torvalds
     

24 Mar, 2012

1 commit

  • == stat_check.py
    num = 0
    with open("/proc/stat") as f:
    while num < 1000 :
    data = f.read()
    f.seek(0, 0)
    num = num + 1
    ==

    perf shows

    20.39% stat_check.py [kernel.kallsyms] [k] format_decode
    13.41% stat_check.py [kernel.kallsyms] [k] number
    12.61% stat_check.py [kernel.kallsyms] [k] vsnprintf
    10.85% stat_check.py [kernel.kallsyms] [k] memcpy
    4.85% stat_check.py [kernel.kallsyms] [k] radix_tree_lookup
    4.43% stat_check.py [kernel.kallsyms] [k] seq_printf

    This patch removes most of calls to vsnprintf() by adding num_to_str()
    and seq_print_decimal_ull(), which prints decimal numbers without rich
    functions provided by printf().

    On my 8cpu box.
    == Before patch ==
    [root@bluextal test]# time ./stat_check.py

    real 0m0.150s
    user 0m0.026s
    sys 0m0.121s

    == After patch ==
    [root@bluextal test]# time ./stat_check.py

    real 0m0.055s
    user 0m0.022s
    sys 0m0.030s

    [akpm@linux-foundation.org: remove incorrect comment, use less statck in num_to_str(), move comment from .h to .c, simplify seq_put_decimal_ull()]
    [andrea@betterlinux.com: avoid breaking the ABI in /proc/stat]
    Signed-off-by: KAMEZAWA Hiroyuki
    Signed-off-by: Andrea Righi
    Cc: Eric Dumazet
    Cc: Glauber Costa
    Cc: Peter Zijlstra
    Cc: Ingo Molnar
    Cc: Paul Turner
    Cc: Russell King
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    KAMEZAWA Hiroyuki
     

08 Mar, 2012

1 commit


07 Mar, 2012

1 commit

  • kasprintf() (and potentially other functions that I didn't run across so
    far) want to evaluate argument lists twice. Caring to do so for the
    primary list is obviously their job, but they can't reasonably be
    expected to check the format string for instances of %pV, which however
    need special handling too: On architectures like x86-64 (as opposed to
    e.g. ix86), using the same argument list twice doesn't produce the
    expected results, as an internally managed cursor gets updated during
    the first run.

    Fix the problem by always acting on a copy of the original list when
    handling %pV.

    Signed-off-by: Jan Beulich
    Signed-off-by: Linus Torvalds

    Jan Beulich
     

17 Nov, 2011

1 commit


01 Nov, 2011

2 commits

  • As suggested by Andrew Morton in [1] there is better to have most
    significant part first in the function name.

    [1] https://lkml.org/lkml/2011/9/20/22

    There is no functional change.

    Signed-off-by: Andy Shevchenko
    Cc: Jesper Nilsson
    Cc: David Howells
    Cc: Koichi Yasutake
    Cc: Jason Wessel
    Cc: Mimi Zohar
    Cc: James Morris
    Cc: OGAWA Hirofumi
    Cc: "John W. Linville"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     
  • Currently termination logic (\0 or \n\0) is hardcoded in _kstrtoull(),
    avoid that for code reuse between kstrto*() and simple_strtoull().
    Essentially, make them different only in termination logic.

    simple_strtoull() (and scanf(), BTW) ignores integer overflow, that's a
    bug we currently don't have guts to fix, making KSTRTOX_OVERFLOW hack
    necessary.

    Almost forgot: patch shrinks code size by about ~80 bytes on x86_64.

    Signed-off-by: Alexey Dobriyan
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

26 Jul, 2011

2 commits

  • * Merge akpm patch series: (122 commits)
    drivers/connector/cn_proc.c: remove unused local
    Documentation/SubmitChecklist: add RCU debug config options
    reiserfs: use hweight_long()
    reiserfs: use proper little-endian bitops
    pnpacpi: register disabled resources
    drivers/rtc/rtc-tegra.c: properly initialize spinlock
    drivers/rtc/rtc-twl.c: check return value of twl_rtc_write_u8() in twl_rtc_set_time()
    drivers/rtc: add support for Qualcomm PMIC8xxx RTC
    drivers/rtc/rtc-s3c.c: support clock gating
    drivers/rtc/rtc-mpc5121.c: add support for RTC on MPC5200
    init: skip calibration delay if previously done
    misc/eeprom: add eeprom access driver for digsy_mtc board
    misc/eeprom: add driver for microwire 93xx46 EEPROMs
    checkpatch.pl: update $logFunctions
    checkpatch: make utf-8 test --strict
    checkpatch.pl: add ability to ignore various messages
    checkpatch: add a "prefer __aligned" check
    checkpatch: validate signature styles and To: and Cc: lines
    checkpatch: add __rcu as a sparse modifier
    checkpatch: suggest using min_t or max_t
    ...

    Did this as a merge because of (trivial) conflicts in
    - Documentation/feature-removal-schedule.txt
    - arch/xtensa/include/asm/uaccess.h
    that were just easier to fix up in the merge than in the patch series.

    Linus Torvalds
     
  • This function is required by *printf and kstrto* functions that are
    located in the different modules. This patch makes _tolower() public.
    However, it's good idea to not use the helper outside of mentioned
    functions.

    [akpm@linux-foundation.org: coding-style fixes]
    Signed-off-by: Andy Shevchenko
    Acked-by: Alexey Dobriyan
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     

15 Jul, 2011

1 commit


10 Jun, 2011

1 commit