06 Jul, 2017

1 commit

  • Pull printk updates from Petr Mladek:

    - Store printk() messages into the main log buffer directly even in NMI
    when the lock is available. It is the best effort to print even large
    chunk of text. It is handy, for example, when all ftrace messages are
    printed during the system panic in NMI.

    - Add missing annotations to calm down compiler warnings

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk:
    printk: add __printf attributes to internal functions
    printk: Use the main logbuf in NMI when logbuf_lock is available

    Linus Torvalds
     

03 Jul, 2017

1 commit


20 Jun, 2017

1 commit


13 Jun, 2017

1 commit

  • When compiling with -Wsuggest-attribute=format, gcc complains that some
    functions in kernel/printk/printk_safe.c transmit their argument to
    printf-like functions without having a printf attribute. Silence these
    warnings by adding relevant __printf attributes.

    Link: http://lkml.kernel.org/r/20170524054950.6722-1-nicolas.iooss_linux@m4x.org
    Cc: Steven Rostedt
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Nicolas Iooss
    Reviewed-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Nicolas Iooss
     

09 Jun, 2017

1 commit

  • Pull printk fix from Petr Mladek:
    "This reverts a fix added into 4.12-rc1. It caused the kernel log to be
    printed on another console when two consoles of the same type were
    defined, e.g. console=ttyS0 console=ttyS1.

    This configuration was never supported by kernel itself, but it
    started to make sense with systemd. In other words, the commit broke
    userspace"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk:
    Revert "printk: fix double printing with earlycon"

    Linus Torvalds
     

08 Jun, 2017

1 commit

  • This reverts commit cf39bf58afdaabc0b86f141630fb3fd18190294e.

    The commit regression to users that define both console=ttyS1
    and console=ttyS0 on the command line, see
    https://lkml.kernel.org/r/20170509082915.GA13236@bistromath.localdomain

    The kernel log messages always appeared only on one serial port. It is
    even documented in Documentation/admin-guide/serial-console.rst:

    "Note that you can only define one console per device type (serial,
    video)."

    The above mentioned commit changed the order in which the command line
    parameters are searched. As a result, the kernel log messages go to
    the last mentioned ttyS* instead of the first one.

    We long thought that using two console=ttyS* on the command line
    did not make sense. But then we realized that console= parameters
    were handled also by systemd, see
    http://0pointer.de/blog/projects/serial-console.html

    "By default systemd will instantiate one serial-getty@.service on
    the main kernel console, if it is not a virtual terminal."

    where

    "[4] If multiple kernel consoles are used simultaneously, the main
    console is the one listed first in /sys/class/tty/console/active,
    which is the last one listed on the kernel command line."

    This puts the original report into another light. The system is running
    in qemu. The first serial port is used to store the messages into a file.
    The second one is used to login to the system via a socket. It depends
    on systemd and the historic kernel behavior.

    By other words, systemd causes that it makes sense to define both
    console=ttyS1 console=ttyS0 on the command line. The kernel fix
    caused regression related to userspace (systemd) and need to be
    reverted.

    In addition, it went out that the fix helped only partially.
    The messages still were duplicated when the boot console was
    removed early by late_initcall(printk_late_init). Then the entire
    log was replayed when the same console was registered as a normal one.

    Link: 20170606160339.GC7604@pathway.suse.cz
    Cc: Aleksey Makarov
    Cc: Sabrina Dubroca
    Cc: Sudeep Holla
    Cc: Greg Kroah-Hartman
    Cc: Peter Hurley
    Cc: Jiri Slaby
    Cc: Robin Murphy ,
    Cc: Steven Rostedt
    Cc: "Nair, Jayachandran"
    Cc: linux-serial@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Reported-by: Sabrina Dubroca
    Acked-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Petr Mladek
     

23 May, 2017

1 commit

  • To enable smp_processor_id() and might_sleep() debug checks earlier, it's
    required to add system states between SYSTEM_BOOTING and SYSTEM_RUNNING.

    Adjust the system_state check in boot_delay_msec() to handle the extra
    states.

    Tested-by: Mark Rutland
    Signed-off-by: Thomas Gleixner
    Signed-off-by: Peter Zijlstra (Intel)
    Reviewed-by: Steven Rostedt (VMware)
    Cc: Greg Kroah-Hartman
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Link: http://lkml.kernel.org/r/20170516184736.027534895@linutronix.de
    Signed-off-by: Ingo Molnar

    Thomas Gleixner
     

19 May, 2017

1 commit

  • The commit 42a0bb3f71383b457a7d ("printk/nmi: generic solution for safe
    printk in NMI") caused that printk stores messages into a temporary
    buffer in NMI context.

    The buffer is per-CPU and therefore the size is rather limited.
    It works quite well for NMI backtraces. But there are longer logs
    that might get printed in NMI context, for example, lockdep
    warnings, ftrace_dump_on_oops.

    The temporary buffer is used to avoid deadlocks caused by
    logbuf_lock. Also it is needed to avoid races with the other
    temporary buffer that is used when PRINTK_SAFE_CONTEXT is entered.
    But the main buffer can be used in NMI if the lock is available
    and we did not interrupt PRINTK_SAFE_CONTEXT.

    The lock is checked using raw_spin_is_locked(). It might cause
    false negatives when the lock is taken on another CPU and
    this CPU is in the safe context from other reasons. Note that
    the safe context is used also to get console semaphore or when
    calling console drivers. For this reason, we do the check in
    printk_nmi_enter(). It makes the handling consistent for
    the entire NMI handler and avoids reshuffling of the messages.

    The patch also defines special printk context that allows
    to use printk_deferred() in NMI. Note that we could not flush
    the messages to the consoles because console drivers might use
    many other internal locks.

    The newly created vprintk_deferred() disables the preemption
    only around the irq work handling. It is needed there to keep
    the consistency between the two per-CPU variables. But there
    is no reason to disable preemption around vprintk_emit().

    Finally, the patch puts back explicit serialization of the NMI
    backtraces from different CPUs. It was removed by the
    commit a9edc88093287183ac934b ("x86/nmi: Perform a safe
    NMI stack trace on all CPUs"). It was not needed because
    the flushing of the temporary per-CPU buffers was serialized.

    Link: http://lkml.kernel.org/r/1493912763-24873-1-git-send-email-pmladek@suse.com
    Cc: Steven Rostedt
    Cc: Andrew Morton
    Cc: Peter Zijlstra
    Cc: Russell King
    Cc: Daniel Thompson
    Cc: Ingo Molnar
    Cc: Thomas Gleixner
    Cc: Chris Metcalf
    Cc: x86@kernel.org
    Cc: linux-arm-kernel@lists.infradead.org
    Cc: linux-kernel@vger.kernel.org
    Suggested-by: Sergey Senozhatsky
    Acked-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Petr Mladek
     

09 May, 2017

2 commits

  • Pull tty/serial updates from Greg KH:
    "Here is the "big" TTY/Serial patch updates for 4.12-rc1

    Not a lot of new things here, the normal number of serial driver
    updates and additions, tiny bugs fixed, and some core files split up
    to make future changes a bit easier for Nicolas's "tiny-tty" work.

    All of these have been in linux-next for a while"

    * tag 'tty-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (62 commits)
    serial: small Makefile reordering
    tty: split job control support into a file of its own
    tty: move baudrate handling code to a file of its own
    console: move console_init() out of tty_io.c
    serial: 8250_early: Add earlycon support for Palmchip UART
    tty: pl011: use "qdf2400_e44" as the earlycon name for QDF2400 E44
    vt: make mouse selection of non-ASCII consistent
    vt: set mouse selection word-chars to gpm's default
    imx-serial: Reduce RX DMA startup latency when opening for reading
    serial: omap: suspend device on probe errors
    serial: omap: fix runtime-pm handling on unbind
    tty: serial: omap: add UPF_BOOT_AUTOCONF flag for DT init
    serial: samsung: Remove useless spinlock
    serial: samsung: Add missing checks for dma_map_single failure
    serial: samsung: Use right device for DMA-mapping calls
    serial: imx: setup DCEDTE early and ensure DCD and RI irqs to be off
    tty: fix comment typo s/repsonsible/responsible/
    tty: amba-pl011: Fix spurious TX interrupts
    serial: xuartps: Enable clocks in the pm disable case also
    serial: core: Re-use struct uart_port {name} field
    ...

    Linus Torvalds
     
  • Patch series "kexec/fadump: remove dependency with CONFIG_KEXEC and
    reuse crashkernel parameter for fadump", v4.

    Traditionally, kdump is used to save vmcore in case of a crash. Some
    architectures like powerpc can save vmcore using architecture specific
    support instead of kexec/kdump mechanism. Such architecture specific
    support also needs to reserve memory, to be used by dump capture kernel.
    crashkernel parameter can be a reused, for memory reservation, by such
    architecture specific infrastructure.

    This patchset removes dependency with CONFIG_KEXEC for crashkernel
    parameter and vmcoreinfo related code as it can be reused without kexec
    support. Also, crashkernel parameter is reused instead of
    fadump_reserve_mem to reserve memory for fadump.

    The first patch moves crashkernel parameter parsing and vmcoreinfo
    related code under CONFIG_CRASH_CORE instead of CONFIG_KEXEC_CORE. The
    second patch reuses the definitions of append_elf_note() & final_note()
    functions under CONFIG_CRASH_CORE in IA64 arch code. The third patch
    removes dependency on CONFIG_KEXEC for firmware-assisted dump (fadump)
    in powerpc. The next patch reuses crashkernel parameter for reserving
    memory for fadump, instead of the fadump_reserve_mem parameter. This
    has the advantage of using all syntaxes crashkernel parameter supports,
    for fadump as well. The last patch updates fadump kernel documentation
    about use of crashkernel parameter.

    This patch (of 5):

    Traditionally, kdump is used to save vmcore in case of a crash. Some
    architectures like powerpc can save vmcore using architecture specific
    support instead of kexec/kdump mechanism. Such architecture specific
    support also needs to reserve memory, to be used by dump capture kernel.
    crashkernel parameter can be a reused, for memory reservation, by such
    architecture specific infrastructure.

    But currently, code related to vmcoreinfo and parsing of crashkernel
    parameter is built under CONFIG_KEXEC_CORE. This patch introduces
    CONFIG_CRASH_CORE and moves the above mentioned code under this config,
    allowing code reuse without dependency on CONFIG_KEXEC. There is no
    functional change with this patch.

    Link: http://lkml.kernel.org/r/149035338104.6881.4550894432615189948.stgit@hbathini.in.ibm.com
    Signed-off-by: Hari Bathini
    Acked-by: Dave Young
    Cc: Fenghua Yu
    Cc: Tony Luck
    Cc: Eric Biederman
    Cc: Mahesh Salgaonkar
    Cc: Vivek Goyal
    Cc: Michael Ellerman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Hari Bathini
     

04 May, 2017

1 commit

  • Pull printk updates from Petr Mladek:

    - There is a situation when early console is not deregistered because
    the preferred one matches a wrong entry. It caused messages to appear
    twice.

    This is the 2nd attempt to fix it. The first one was wrong, see the
    commit c6c7d83b9c9e ('Revert "console: don't prefer first registered
    if DT specifies stdout-path"').

    The fix is coupled with some small code clean up. Well, the console
    registration code would deserve a big one. We need to think about it.

    - Do not lose information about the preemtive context when the console
    semaphore is re-taken.

    - Do not block CPU hotplug when someone else is already pushing
    messages to the console.

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk:
    printk: fix double printing with earlycon
    printk: rename selected_console -> preferred_console
    printk: fix name/type/scope of preferred_console var
    printk: Correctly handle preemption in console_unlock()
    printk: use console_trylock() in console_cpu_notify()

    Linus Torvalds
     

19 Apr, 2017

1 commit


12 Apr, 2017

3 commits

  • If a console was specified by ACPI SPCR table _and_ command line
    parameters like "console=ttyAMA0" _and_ "earlycon" were specified,
    then log messages appear twice.

    The root cause is that the code traverses the list of specified
    consoles (the `console_cmdline` array) and stops at the first match.
    But it may happen that the same console is referred by the elements
    of this array twice:

    pl011,mmio,0x87e024000000,115200 -- from SPCR
    ttyAMA0 -- from command line

    but in this case `preferred_console` points to the second entry and
    the flag CON_CONSDEV is not set, so bootconsole is not deregistered.

    To fix that, introduce an invariant "The last non-braille console
    is always the preferred one" on the entries of the console_cmdline
    array. Then traverse it in reverse order to be sure that if
    the console is preferred then it will be the first matching entry.
    Introduce variable console_cmdline_cnt that keeps the number
    of elements of the console_cmdline array (Petr Mladek). It helps
    to get rid of the loop that searches for the end of this array.

    Link: http://lkml.kernel.org/r/20170405202006.18234-1-aleksey.makarov@linaro.org
    Cc: Steven Rostedt
    Cc: Greg Kroah-Hartman
    Cc: Peter Hurley
    Cc: Jiri Slaby
    Cc: Robin Murphy
    Cc: "Nair, Jayachandran"
    Cc: linux-serial@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Aleksey Makarov
    Reported-by: Sudeep Holla
    Acked-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Aleksey Makarov
     
  • The variable selected_console is set in __add_preferred_console()
    to point to the last console parameter that was added to the
    console_cmdline array.

    Rename it to preferred_console so that the name reflects the usage.

    Petr Mladek:
    "[..] the selected_console/preferred_console
    value is used to keep the console first in the console_drivers list.
    IMHO, the main effect is that each line will first appear on this
    console, see call_console_drivers(). But the message will still
    appear also on all other enabled consoles. From this point,
    the name "preferred" sounds better to me. More consoles
    are selected (enabled) and only one is preferred (first)."

    Link: http://lkml.kernel.org/r/20170315102854.1763-3-aleksey.makarov@linaro.org
    Cc: Sudeep Holla
    Cc: Greg Kroah-Hartman
    Cc: Jiri Slaby
    Cc: Robin Murphy
    Cc: "Nair, Jayachandran"
    Cc: linux-serial@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Aleksey Makarov
    Suggested-by: Peter Hurley
    Acked-by: Steven Rostedt (VMware)
    Reviewed-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Aleksey Makarov
     
  • The variable preferred_console is used only inside register_console()
    and its semantics is boolean. It is negative when no console has been
    made preferred.

    Make it static bool and rename to has_preferred.

    Renaming was suggested by Peter Hurley

    Link: http://lkml.kernel.org/r/20170315102854.1763-2-aleksey.makarov@linaro.org
    Cc: Sudeep Holla
    Cc: Greg Kroah-Hartman
    Cc: Peter Hurley
    Cc: Jiri Slaby
    Cc: Robin Murphy
    Cc: "Nair, Jayachandran"
    Cc: linux-serial@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Aleksey Makarov
    Reviewed-by: Steven Rostedt (VMware)
    Reviewed-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Aleksey Makarov
     

04 Apr, 2017

1 commit

  • Some console drivers code calls console_conditional_schedule()
    that looks at @console_may_schedule. The value must be cleared
    when the drivers are called from console_unlock() with
    interrupts disabled. But rescheduling is fine when the same
    code is called, for example, from tty operations where the
    console semaphore is taken via console_lock().

    This is why @console_may_schedule is cleared before calling console
    drivers. The original value is stored to decide if we could sleep
    between lines.

    Now, @console_may_schedule is not cleared when we call
    console_trylock() and jump back to the "again" goto label.
    This has become a problem, since the commit 6b97a20d3a7909daa066
    ("printk: set may_schedule for some of console_trylock() callers").
    @console_may_schedule might get enabled now.

    There is also the opposite problem. console_lock() can be called
    only from preemptive context. It can always enable scheduling in
    the console code. But console_trylock() is not able to detect it
    when CONFIG_PREEMPT_COUNT is disabled. Therefore we should use the
    original @console_may_schedule value after re-acquiring
    the console semaphore in console_unlock().

    This patch solves both problems by moving the "again" goto label.

    Alternative solution was to clear and restore the value around
    call_console_drivers(). Then console_conditional_schedule() could
    be used also inside console_unlock(). But there was a potential race
    with console_flush_on_panic() as reported by Sergey Senozhatsky.
    That function should be called only where there is only one CPU
    and with interrupts disabled. But better be on the safe side
    because stopping CPUs might fail.

    Fixes: 6b97a20d3a7909 ("printk: set may_schedule for some of console_trylock() callers")
    Link: http://lkml.kernel.org/r/1490372045-22288-1-git-send-email-pmladek@suse.com
    Suggested-by: Tetsuo Handa
    Cc: Steven Rostedt
    Cc: Peter Zijlstra
    Cc: Andrew Morton
    Cc: Greg Kroah-Hartman
    Cc: Jiri Slaby
    Cc: linux-fbdev@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Reviewed-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Petr Mladek
     

31 Mar, 2017

1 commit

  • commit bbeddf52adc1 ("printk: move braille console support into
    separate braille.[ch] files") introduced _braille_console_setup()
    to outline the braille initialization code. There was however some
    confusion over the value it was supposed to return. commit 2cfe6c4ac7ee
    ("printk: Fix return of braille_register_console()") tried to fix it
    but failed to.

    This fixes and documents the returned value according to the use
    in printk.c: non-zero return means a parsing error, and thus this
    console configuration should be ignored.

    Signed-off-by: Samuel Thibault
    Cc: Aleksey Makarov
    Cc: Joe Perches
    Cc: Ming Lei
    Cc: Steven Rostedt
    Acked-by: Petr Mladek
    Signed-off-by: Greg Kroah-Hartman

    Samuel Thibault
     

24 Mar, 2017

1 commit

  • There is no need to always call blocking console_lock() in
    console_cpu_notify(), it's quite possible that console_sem can
    be locked by other CPU on the system, either already printing
    or soon to begin printing the messages. console_lock() in this
    case can simply block CPU hotplug for unknown period of time
    (console_unlock() is time unbound). Not that hotplug is very
    fast, but still, with other CPUs being online and doing
    printk() console_cpu_notify() can stuck.

    Use console_trylock() instead and opt-out if console_sem is
    already acquired from another CPU, since that CPU will do
    the printing for us.

    Link: http://lkml.kernel.org/r/20170121104729.8585-1-sergey.senozhatsky@gmail.com
    Cc: Steven Rostedt
    Cc: Andrew Morton
    Cc: Thomas Gleixner
    Cc: Sebastian Andrzej Siewior
    Cc: Ingo Molnar
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Sergey Senozhatsky
     

02 Mar, 2017

3 commits


23 Feb, 2017

1 commit

  • Pull printk updates from Petr Mladek:

    - Add Petr Mladek, Sergey Senozhatsky as printk maintainers, and Steven
    Rostedt as the printk reviewer. This idea came up after the
    discussion about printk issues at Kernel Summit. It was formulated
    and discussed at lkml[1].

    - Extend a lock-less NMI per-cpu buffers idea to handle recursive
    printk() calls by Sergey Senozhatsky[2]. It is the first step in
    sanitizing printk as discussed at Kernel Summit.

    The change allows to see messages that would normally get ignored or
    would cause a deadlock.

    Also it allows to enable lockdep in printk(). This already paid off.
    The testing in linux-next helped to discover two old problems that
    were hidden before[3][4].

    - Remove unused parameter by Sergey Senozhatsky. Clean up after a past
    change.

    [1] http://lkml.kernel.org/r/1481798878-31898-1-git-send-email-pmladek@suse.com
    [2] http://lkml.kernel.org/r/20161227141611.940-1-sergey.senozhatsky@gmail.com
    [3] http://lkml.kernel.org/r/20170215044332.30449-1-sergey.senozhatsky@gmail.com
    [4] http://lkml.kernel.org/r/20170217015932.11898-1-sergey.senozhatsky@gmail.com

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk:
    printk: drop call_console_drivers() unused param
    printk: convert the rest to printk-safe
    printk: remove zap_locks() function
    printk: use printk_safe buffers in printk
    printk: report lost messages in printk safe/nmi contexts
    printk: always use deferred printk when flush printk_safe lines
    printk: introduce per-cpu safe_print seq buffer
    printk: rename nmi.c and exported api
    printk: use vprintk_func in vprintk()
    MAINTAINERS: Add printk maintainers

    Linus Torvalds
     

19 Feb, 2017

1 commit

  • Use rcuidle console tracepoint because, apparently, it may be issued
    from an idle CPU:

    hw-breakpoint: Failed to enable monitor mode on CPU 0.
    hw-breakpoint: CPU 0 failed to disable vector catch

    ===============================
    [ ERR: suspicious RCU usage. ]
    4.10.0-rc8-next-20170215+ #119 Not tainted
    -------------------------------
    ./include/trace/events/printk.h:32 suspicious rcu_dereference_check() usage!

    other info that might help us debug this:

    RCU used illegally from idle CPU!
    rcu_scheduler_active = 2, debug_locks = 0
    RCU used illegally from extended quiescent state!
    2 locks held by swapper/0/0:
    #0: (cpu_pm_notifier_lock){......}, at: [] cpu_pm_exit+0x10/0x54
    #1: (console_lock){+.+.+.}, at: [] vprintk_emit+0x264/0x474

    stack backtrace:
    CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.10.0-rc8-next-20170215+ #119
    Hardware name: Generic OMAP4 (Flattened Device Tree)
    console_unlock
    vprintk_emit
    vprintk_default
    printk
    reset_ctrl_regs
    dbg_cpu_pm_notify
    notifier_call_chain
    cpu_pm_exit
    omap_enter_idle_coupled
    cpuidle_enter_state
    cpuidle_enter_state_coupled
    do_idle
    cpu_startup_entry
    start_kernel

    This RCU warning, however, is suppressed by lockdep_off() in printk().
    lockdep_off() increments the ->lockdep_recursion counter and thus
    disables RCU_LOCKDEP_WARN() and debug_lockdep_rcu_enabled(), which want
    lockdep to be enabled "current->lockdep_recursion == 0".

    Link: http://lkml.kernel.org/r/20170217015932.11898-1-sergey.senozhatsky@gmail.com
    Signed-off-by: Sergey Senozhatsky
    Reported-by: Tony Lindgren
    Tested-by: Tony Lindgren
    Acked-by: Paul E. McKenney
    Acked-by: Steven Rostedt (VMware)
    Cc: Petr Mladek
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Tony Lindgren
    Cc: Russell King
    Cc: [3.4+]
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sergey Senozhatsky
     

08 Feb, 2017

9 commits

  • We do suppress_message_printing() check before we call
    call_console_drivers() now, so `level' param is not needed
    anymore.

    Link: http://lkml.kernel.org/r/20161224140902.1962-2-sergey.senozhatsky@gmail.com
    Cc: Andrew Morton
    Cc: Steven Rostedt
    Cc: Peter Hurley
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Sergey Senozhatsky
     
  • This patch converts the rest of logbuf users (which are
    out of printk recursion case, but can deadlock in printk).
    To make printk-safe usage easier the patch introduces 4
    helper macros:
    - logbuf_lock_irq()/logbuf_unlock_irq()
    lock/unlock the logbuf lock and disable/enable local IRQ

    - logbuf_lock_irqsave(flags)/logbuf_unlock_irqrestore(flags)
    lock/unlock the logbuf lock and saves/restores local IRQ state

    Link: http://lkml.kernel.org/r/20161227141611.940-9-sergey.senozhatsky@gmail.com
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Steven Rostedt
    Cc: Jan Kara
    Cc: Tejun Heo
    Cc: Calvin Owens
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Andy Lutomirski
    Cc: Peter Hurley
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Sergey Senozhatsky
     
  • We use printk-safe now which makes printk-recursion detection code
    in vprintk_emit() unreachable. The tricky thing here is that, apart
    from detecting and reporting printk recursions, that code also used
    to zap_locks() in case of panic() from the same CPU. However,
    zap_locks() does not look to be needed anymore:

    1) Since commit 08d78658f393 ("panic: release stale console lock to
    always get the logbuf printed out") panic flushing of `logbuf' to
    console ignores the state of `console_sem' by doing
    panic()
    console_trylock();
    console_unlock();

    2) Since commit cf9b1106c81c ("printk/nmi: flush NMI messages on the
    system panic") panic attempts to zap the `logbuf_lock' spin_lock to
    successfully flush nmi messages to `logbuf'.

    Basically, it seems that we either already do what zap_locks() used to
    do but in other places or we ignore the state of the lock. The only
    reaming difference is that we don't re-init the console semaphore in
    printk_safe_flush_on_panic(), but this is not necessary because we
    don't call console drivers from printk_safe_flush_on_panic() due to
    the fact that we are using a deferred printk() version (as was
    suggested by Petr Mladek).

    Link: http://lkml.kernel.org/r/20161227141611.940-8-sergey.senozhatsky@gmail.com
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Steven Rostedt
    Cc: Jan Kara
    Cc: Tejun Heo
    Cc: Calvin Owens
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Andy Lutomirski
    Cc: Peter Hurley
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Sergey Senozhatsky
     
  • Use printk_safe per-CPU buffers in printk recursion-prone blocks:
    -- around logbuf_lock protected sections in vprintk_emit() and
    console_unlock()
    -- around down_trylock_console_sem() and up_console_sem()

    Note that this solution addresses deadlocks caused by printk()
    recursive calls only. That is vprintk_emit() and console_unlock().
    The rest will be converted in a followup patch.

    Another thing to note is that we now keep lockdep enabled in printk,
    because we are protected against the printk recursion caused by
    lockdep in vprintk_emit() by the printk-safe mechanism - we first
    switch to per-CPU buffers and only then access the deadlock-prone
    locks.

    Examples:

    1) printk() from logbuf_lock spin_lock section

    Assume the following code:
    printk()
    raw_spin_lock(&logbuf_lock);
    WARN_ON(1);
    raw_spin_unlock(&logbuf_lock);

    which now produces:

    ------------[ cut here ]------------
    WARNING: CPU: 0 PID: 366 at kernel/printk/printk.c:1811 vprintk_emit
    CPU: 0 PID: 366 Comm: bash
    Call Trace:
    warn_slowpath_null+0x1d/0x1f
    vprintk_emit+0x1cd/0x438
    vprintk_default+0x1d/0x1f
    printk+0x48/0x50
    [..]

    2) printk() from semaphore sem->lock spin_lock section

    Assume the following code

    printk()
    console_trylock()
    down_trylock()
    raw_spin_lock_irqsave(&sem->lock, flags);
    WARN_ON(1);
    raw_spin_unlock_irqrestore(&sem->lock, flags);

    which now produces:

    ------------[ cut here ]------------
    WARNING: CPU: 1 PID: 363 at kernel/locking/semaphore.c:141 down_trylock
    CPU: 1 PID: 363 Comm: bash
    Call Trace:
    warn_slowpath_null+0x1d/0x1f
    down_trylock+0x3d/0x62
    ? vprintk_emit+0x3f9/0x414
    console_trylock+0x31/0xeb
    vprintk_emit+0x3f9/0x414
    vprintk_default+0x1d/0x1f
    printk+0x48/0x50
    [..]

    3) printk() from console_unlock()

    Assume the following code:

    printk()
    console_unlock()
    raw_spin_lock(&logbuf_lock);
    WARN_ON(1);
    raw_spin_unlock(&logbuf_lock);

    which now produces:

    ------------[ cut here ]------------
    WARNING: CPU: 1 PID: 329 at kernel/printk/printk.c:2384 console_unlock
    CPU: 1 PID: 329 Comm: bash
    Call Trace:
    warn_slowpath_null+0x18/0x1a
    console_unlock+0x12d/0x559
    ? trace_hardirqs_on_caller+0x16d/0x189
    ? trace_hardirqs_on+0xd/0xf
    vprintk_emit+0x363/0x374
    vprintk_default+0x18/0x1a
    printk+0x43/0x4b
    [..]

    4) printk() from try_to_wake_up()

    Assume the following code:

    printk()
    console_unlock()
    up()
    try_to_wake_up()
    raw_spin_lock_irqsave(&p->pi_lock, flags);
    WARN_ON(1);
    raw_spin_unlock_irqrestore(&p->pi_lock, flags);

    which now produces:

    ------------[ cut here ]------------
    WARNING: CPU: 3 PID: 363 at kernel/sched/core.c:2028 try_to_wake_up
    CPU: 3 PID: 363 Comm: bash
    Call Trace:
    warn_slowpath_null+0x1d/0x1f
    try_to_wake_up+0x7f/0x4f7
    wake_up_process+0x15/0x17
    __up.isra.0+0x56/0x63
    up+0x32/0x42
    __up_console_sem+0x37/0x55
    console_unlock+0x21e/0x4c2
    vprintk_emit+0x41c/0x462
    vprintk_default+0x1d/0x1f
    printk+0x48/0x50
    [..]

    5) printk() from call_console_drivers()

    Assume the following code:
    printk()
    console_unlock()
    call_console_drivers()
    ...
    WARN_ON(1);

    which now produces:

    ------------[ cut here ]------------
    WARNING: CPU: 2 PID: 305 at kernel/printk/printk.c:1604 call_console_drivers
    CPU: 2 PID: 305 Comm: bash
    Call Trace:
    warn_slowpath_null+0x18/0x1a
    call_console_drivers.isra.6.constprop.16+0x3a/0xb0
    console_unlock+0x471/0x48e
    vprintk_emit+0x1f4/0x206
    vprintk_default+0x18/0x1a
    vprintk_func+0x6e/0x70
    printk+0x3e/0x46
    [..]

    6) unsupported placeholder in printk() format now prints an actual
    warning from vscnprintf(), instead of
    'BUG: recent printk recursion!'.

    ------------[ cut here ]------------
    WARNING: CPU: 5 PID: 337 at lib/vsprintf.c:1900 format_decode
    Please remove unsupported %
    in format string
    CPU: 5 PID: 337 Comm: bash
    Call Trace:
    dump_stack+0x4f/0x65
    __warn+0xc2/0xdd
    warn_slowpath_fmt+0x4b/0x53
    format_decode+0x22c/0x308
    vsnprintf+0x89/0x3b7
    vscnprintf+0xd/0x26
    vprintk_emit+0xb4/0x238
    vprintk_default+0x1d/0x1f
    vprintk_func+0x6c/0x73
    printk+0x43/0x4b
    [..]

    Link: http://lkml.kernel.org/r/20161227141611.940-7-sergey.senozhatsky@gmail.com
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Jan Kara
    Cc: Tejun Heo
    Cc: Calvin Owens
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Andy Lutomirski
    Cc: Peter Hurley
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek
    Reviewed-by: Steven Rostedt (VMware)

    Sergey Senozhatsky
     
  • Account lost messages in pritk-safe and printk-safe-nmi
    contexts and report those numbers during printk_safe_flush().

    The patch also moves lost message counter to struct
    `printk_safe_seq_buf' instead of having dedicated static
    counters - this simplifies the code.

    Link: http://lkml.kernel.org/r/20161227141611.940-6-sergey.senozhatsky@gmail.com
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Steven Rostedt
    Cc: Jan Kara
    Cc: Tejun Heo
    Cc: Calvin Owens
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Andy Lutomirski
    Cc: Peter Hurley
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Sergey Senozhatsky
     
  • Always use printk_deferred() in printk_safe_flush_line().
    Flushing can be done from NMI or printk_safe contexts (when
    we are in panic), so we can't call console drivers, yet still
    want to store the messages in the logbuf buffer. Therefore we
    use a deferred printk version.

    Link: http://lkml.kernel.org/r/20170206164253.GA463@tigerII.localdomain
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Jan Kara
    Cc: Tejun Heo
    Cc: Calvin Owens
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Andy Lutomirski
    Cc: Peter Hurley
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Suggested-by: Petr Mladek
    Signed-off-by: Petr Mladek
    Reviewed-by: Steven Rostedt (VMware)

    Sergey Senozhatsky
     
  • This patch extends the idea of NMI per-cpu buffers to regions
    that may cause recursive printk() calls and possible deadlocks.
    Namely, printk() can't handle printk calls from schedule code
    or printk() calls from lock debugging code (spin_dump() for instance);
    because those may be called with `sem->lock' already taken or any
    other `critical' locks (p->pi_lock, etc.). An example of deadlock
    can be

    vprintk_emit()
    console_unlock()
    up() << raw_spin_lock_irqsave(&sem->lock, flags);
    wake_up_process()
    try_to_wake_up()
    ttwu_queue()
    ttwu_activate()
    activate_task()
    enqueue_task()
    enqueue_task_fair()
    cfs_rq_of()
    task_of()
    WARN_ON_ONCE(!entity_is_task(se))
    vprintk_emit()
    console_trylock()
    down_trylock()
    raw_spin_lock_irqsave(&sem->lock, flags)
    ^^^^ deadlock

    and some other cases.

    Just like in NMI implementation, the solution uses a per-cpu
    `printk_func' pointer to 'redirect' printk() calls to a 'safe'
    callback, that store messages in a per-cpu buffer and flushes
    them back to logbuf buffer later.

    Usage example:

    printk()
    printk_safe_enter_irqsave(flags)
    //
    // any printk() call from here will endup in vprintk_safe(),
    // that stores messages in a special per-CPU buffer.
    //
    printk_safe_exit_irqrestore(flags)

    The 'redirection' mechanism, though, has been reworked, as suggested
    by Petr Mladek. Instead of using a per-cpu @print_func callback we now
    keep a per-cpu printk-context variable and call either default or nmi
    vprintk function depending on its value. printk_nmi_entrer/exit and
    printk_safe_enter/exit, thus, just set/celar corresponding bits in
    printk-context functions.

    The patch only adds printk_safe support, we don't use it yet.

    Link: http://lkml.kernel.org/r/20161227141611.940-4-sergey.senozhatsky@gmail.com
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Jan Kara
    Cc: Tejun Heo
    Cc: Calvin Owens
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Andy Lutomirski
    Cc: Peter Hurley
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek
    Reviewed-by: Steven Rostedt (VMware)

    Sergey Senozhatsky
     
  • A preparation patch for printk_safe work. No functional change.
    - rename nmi.c to print_safe.c
    - add `printk_safe' prefix to some (which used both by printk-safe
    and printk-nmi) of the exported functions.

    Link: http://lkml.kernel.org/r/20161227141611.940-3-sergey.senozhatsky@gmail.com
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Jan Kara
    Cc: Tejun Heo
    Cc: Calvin Owens
    Cc: Steven Rostedt
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Andy Lutomirski
    Cc: Peter Hurley
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Sergey Senozhatsky
     
  • vprintk(), just like printk(), better be using per-cpu printk_func
    instead of direct vprintk_emit() call. Just in case if vprintk()
    will ever be called from NMI, or from any other context that can
    deadlock in printk().

    Link: http://lkml.kernel.org/r/20161227141611.940-2-sergey.senozhatsky@gmail.com
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Jan Kara
    Cc: Tejun Heo
    Cc: Calvin Owens
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Andy Lutomirski
    Cc: Peter Hurley
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Reviewed-by: Steven Rostedt
    Signed-off-by: Petr Mladek

    Sergey Senozhatsky
     

25 Dec, 2016

1 commit


17 Dec, 2016

1 commit

  • Pull vfs updates from Al Viro:

    - more ->d_init() stuff (work.dcache)

    - pathname resolution cleanups (work.namei)

    - a few missing iov_iter primitives - copy_from_iter_full() and
    friends. Either copy the full requested amount, advance the iterator
    and return true, or fail, return false and do _not_ advance the
    iterator. Quite a few open-coded callers converted (and became more
    readable and harder to fuck up that way) (work.iov_iter)

    - several assorted patches, the big one being logfs removal

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    logfs: remove from tree
    vfs: fix put_compat_statfs64() does not handle errors
    namei: fold should_follow_link() with the step into not-followed link
    namei: pass both WALK_GET and WALK_MORE to should_follow_link()
    namei: invert WALK_PUT logics
    namei: shift interpretation of LOOKUP_FOLLOW inside should_follow_link()
    namei: saner calling conventions for mountpoint_last()
    namei.c: get rid of user_path_parent()
    switch getfrag callbacks to ..._full() primitives
    make skb_add_data,{_nocache}() and skb_copy_to_page_nocache() advance only on success
    [iov_iter] new primitives - copy_from_iter_full() and friends
    don't open-code file_inode()
    ceph: switch to use of ->d_init()
    ceph: unify dentry_operations instances
    lustre: switch to use of ->d_init()

    Linus Torvalds
     

16 Dec, 2016

1 commit

  • If CONFIG_PRINTK=n:

    kernel/printk/printk.c:1893: warning: ‘cont’ defined but not used

    Note that there are actually two different struct cont definitions and
    objects: the first one is used if CONFIG_PRINTK=y, the second one became
    unused by removing console_cont_flush().

    Fixes: 5c2992ee7fd8 ("printk: remove console flushing special cases for partial buffered lines")
    Signed-off-by: Geert Uytterhoeven
    Acked-by: Petr Mladek
    [ I do the occasional "allnoconfig" builds, but apparently not often
    enough - Linus ]
    Signed-off-by: Linus Torvalds

    Geert Uytterhoeven
     

15 Dec, 2016

3 commits

  • It actively hurts proper merging, and makes for a lot of special cases.
    There was a good(ish) reason for doing it originally, but it's getting
    too painful to maintain. And most of the original reasons for it are
    long gone.

    So instead of having special code to flush partial lines to the console
    (as opposed to the record buffers), do _all_ the console writing from
    the record buffer, and be done with it.

    If an oops happens (or some other synchronous event), we will flush the
    partial lines due to the oops printing activity, so this does not affect
    that. It does mean that if you have a completely hung machine, a
    partial preceding line may not have been printed out.

    That was some of the original reason for this complexity, in fact, back
    when we used to test for the historical i386 "halt" instruction problem
    by doing

    pr_info("Checking 'hlt' instruction... ");

    if (!boot_cpu_data.hlt_works_ok) {
    pr_cont("disabled\n");
    return;
    }
    halt();
    halt();
    halt();
    halt();
    pr_cont("OK\n");

    and that model no longer works (it the 'hlt' instruction kills the
    machine, the partial line won't have been flushed, so you won't even see
    it).

    Of course, that was also back in the days when people actually had
    textual console output rather than a graphical splash-screen at bootup.
    How times change..

    Cc: Sergey Senozhatsky
    Cc: Joe Perches
    Cc: Steven Rostedt
    Tested-by: Petr Mladek
    Tested-by: Geert Uytterhoeven
    Tested-by: Mark Rutland
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     
  • The record logging code looks at the previous record flags in various
    ways, and they are all wrong.

    You can't use the previous record flags to determine anything about the
    next record, because they may simply not be related. In particular, the
    reason the previous record was a continuation record may well be exactly
    _because_ the new record was printed by a different process, which is
    why the previous record was flushed.

    So all those games are simply wrong, and make the code hard to
    understand (because the code fundamentally cdoes not make sense).

    So remove it.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     
  • kdb_trap_printk allows to pass normal printk() messages to kdb via
    vkdb_printk(). For example, it is used to get backtrace using the
    classic show_stack(), see kdb_show_stack().

    vkdb_printf() tries to avoid a potential infinite loop by disabling the
    trap. But this approach is racy, for example:

    CPU1 CPU2

    vkdb_printf()
    // assume that kdb_trap_printk == 0
    saved_trap_printk = kdb_trap_printk;
    kdb_trap_printk = 0;

    kdb_show_stack()
    kdb_trap_printk++;

    Problem1: Now, a nested printk() on CPU0 calls vkdb_printf()
    even when it should have been disabled. It will not
    cause a deadlock but...

    // using the outdated saved value: 0
    kdb_trap_printk = saved_trap_printk;

    kdb_trap_printk--;

    Problem2: Now, kdb_trap_printk == -1 and will stay like this.
    It means that all messages will get passed to kdb from
    now on.

    This patch removes the racy saved_trap_printk handling. Instead, the
    recursion is prevented by a check for the locked CPU.

    The solution is still kind of racy. A non-related printk(), from
    another process, might get trapped by vkdb_printf(). And the wanted
    printk() might not get trapped because kdb_printf_cpu is assigned. But
    this problem existed even with the original code.

    A proper solution would be to get_cpu() before setting kdb_trap_printk
    and trap messages only from this CPU. I am not sure if it is worth the
    effort, though.

    In fact, the race is very theoretical. When kdb is running any of the
    commands that use kdb_trap_printk there is a single active CPU and the
    other CPUs should be in a holding pen inside kgdb_cpu_enter().

    The only time this is violated is when there is a timeout waiting for
    the other CPUs to report to the holding pen.

    Finally, note that the situation is a bit schizophrenic. vkdb_printf()
    explicitly allows recursion but only from KDB code that calls
    kdb_printf() directly. On the other hand, the generic printk()
    recursion is not allowed because it might cause an infinite loop. This
    is why we could not hide the decision inside vkdb_printf() easily.

    Link: http://lkml.kernel.org/r/1480412276-16690-4-git-send-email-pmladek@suse.com
    Signed-off-by: Petr Mladek
    Cc: Daniel Thompson
    Cc: Jason Wessel
    Cc: Peter Zijlstra
    Cc: Sergey Senozhatsky
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Petr Mladek
     

13 Dec, 2016

2 commits

  • Merge updates from Andrew Morton:

    - various misc bits

    - most of MM (quite a lot of MM material is awaiting the merge of
    linux-next dependencies)

    - kasan

    - printk updates

    - procfs updates

    - MAINTAINERS

    - /lib updates

    - checkpatch updates

    * emailed patches from Andrew Morton : (123 commits)
    init: reduce rootwait polling interval time to 5ms
    binfmt_elf: use vmalloc() for allocation of vma_filesz
    checkpatch: don't emit unified-diff error for rename-only patches
    checkpatch: don't check c99 types like uint8_t under tools
    checkpatch: avoid multiple line dereferences
    checkpatch: don't check .pl files, improve absolute path commit log test
    scripts/checkpatch.pl: fix spelling
    checkpatch: don't try to get maintained status when --no-tree is given
    lib/ida: document locking requirements a bit better
    lib/rbtree.c: fix typo in comment of ____rb_erase_color
    lib/Kconfig.debug: make CONFIG_STRICT_DEVMEM depend on CONFIG_DEVMEM
    MAINTAINERS: add drm and drm/i915 irc channels
    MAINTAINERS: add "C:" for URI for chat where developers hang out
    MAINTAINERS: add drm and drm/i915 bug filing info
    MAINTAINERS: add "B:" for URI where to file bugs
    get_maintainer: look for arbitrary letter prefixes in sections
    printk: add Kconfig option to set default console loglevel
    printk/sound: handle more message headers
    printk/btrfs: handle more message headers
    printk/kdb: handle more message headers
    ...

    Linus Torvalds
     
  • Pull smp hotplug updates from Thomas Gleixner:
    "This is the final round of converting the notifier mess to the state
    machine. The removal of the notifiers and the related infrastructure
    will happen around rc1, as there are conversions outstanding in other
    trees.

    The whole exercise removed about 2000 lines of code in total and in
    course of the conversion several dozen bugs got fixed. The new
    mechanism allows to test almost every hotplug step standalone, so
    usage sites can exercise all transitions extensively.

    There is more room for improvement, like integrating all the
    pointlessly different architecture mechanisms of synchronizing,
    setting cpus online etc into the core code"

    * 'smp-hotplug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (60 commits)
    tracing/rb: Init the CPU mask on allocation
    soc/fsl/qbman: Convert to hotplug state machine
    soc/fsl/qbman: Convert to hotplug state machine
    zram: Convert to hotplug state machine
    KVM/PPC/Book3S HV: Convert to hotplug state machine
    arm64/cpuinfo: Convert to hotplug state machine
    arm64/cpuinfo: Make hotplug notifier symmetric
    mm/compaction: Convert to hotplug state machine
    iommu/vt-d: Convert to hotplug state machine
    mm/zswap: Convert pool to hotplug state machine
    mm/zswap: Convert dst-mem to hotplug state machine
    mm/zsmalloc: Convert to hotplug state machine
    mm/vmstat: Convert to hotplug state machine
    mm/vmstat: Avoid on each online CPU loops
    mm/vmstat: Drop get_online_cpus() from init_cpu_node_state/vmstat_cpu_dead()
    tracing/rb: Convert to hotplug state machine
    oprofile/nmi timer: Convert to hotplug state machine
    net/iucv: Use explicit clean up labels in iucv_init()
    x86/pci/amd-bus: Convert to hotplug state machine
    x86/oprofile/nmi: Convert to hotplug state machine
    ...

    Linus Torvalds