Commit Graph

49 Commits

Author SHA1 Message Date
Andrew Halaney 3f11513ac3 printk: Add kthread for all legacy consoles
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit 7fabc517cee20c37f3b89406d8fcfec2e4f7f1ce
Author: John Ogness <john.ogness@linutronix.de>
Date:   Fri Sep 22 17:35:04 2023 +0000

    printk: Add kthread for all legacy consoles

    The write callback of legacy consoles make use of spinlocks.
    This is not permitted with PREEMPT_RT in atomic contexts.

    Create a new kthread to handle printing of all the legacy
    consoles (and nbcon consoles if boot consoles are registered).

    Since the consoles are printing in a task context, it is no
    longer appropriate to support the legacy handover mechanism.

    These changes exist only for CONFIG_PREEMPT_RT.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:27 -04:00
Andrew Halaney f558729b63 printk: nbcon: Start printing threads
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit ee46afa4539a0cc4148e5731ad69ecadf12e02bd
Author: John Ogness <john.ogness@linutronix.de>
Date:   Tue Dec 5 14:09:31 2023 +0000

    printk: nbcon: Start printing threads

    If there are no boot consoles, the printing threads are started
    in early_initcall.

    If there are boot consoles, the printing threads are started
    after the last boot console has unregistered. The printing
    threads do not need to be concerned about boot consoles because
    boot consoles cannot register once a non-boot console has
    registered.

    Until a printing thread of a console has started, that console
    will print using atomic_write() in the printk() caller context.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:26 -04:00
Andrew Halaney 9885619de2 printk: nbcon: Add printer thread wakeups
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit bf69985496f8cd327b943acfd3db76c4f801faf6
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Sep 26 13:03:52 2023 +0000

    printk: nbcon: Add printer thread wakeups

    Add a function to wakeup the printer threads. Use the new function
    when:

      - records are added to the printk ringbuffer
      - consoles are resumed
      - triggered via printk_trigger_flush()

    The actual waking is performed via irq_work so that the wakeup can
    be triggered from any context.

    Co-developed-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Thomas Gleixner (Intel) <tglx@linutronix.de>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:26 -04:00
Andrew Halaney 5e65ae2032 printk: nbcon: Add context to console_is_usable()
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit 39df1f6eb49929f6d1565234ecd082e5f4669139
Author: John Ogness <john.ogness@linutronix.de>
Date:   Tue Sep 26 14:43:30 2023 +0000

    printk: nbcon: Add context to console_is_usable()

    The nbcon consoles have two callbacks to be used for different
    contexts. In order to determine if an nbcon console is usable,
    console_is_usable() needs to know if it is a context that will
    use the write_atomic() callback or the write_thread() callback.

    Add an extra parameter @use_atomic to specify this.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:26 -04:00
Andrew Halaney 5665c4a0c5 printk: nbcon: Introduce printing kthreads
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit 448e456f0c7e806330cc8ba8f775097fc71817c0
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Fri Sep 22 14:12:21 2023 +0000

    printk: nbcon: Introduce printing kthreads

    Provide the main implementation for running a printer kthread
    per nbcon console that is takeover/handover aware.

    The main print function nbcon_emit_next_record() will generate
    a warning if a task other than the dedicated printer thread
    tries to print using write_thread().

    Co-developed-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Thomas Gleixner (Intel) <tglx@linutronix.de>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:26 -04:00
Andrew Halaney 3b13e5ce7d printk: Avoid console_lock dance if no legacy or boot consoles
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit cf9fd1cc9f710ad5cb9d68887a5b7022383c0898
Author: John Ogness <john.ogness@linutronix.de>
Date:   Tue Sep 26 12:44:07 2023 +0000

    printk: Avoid console_lock dance if no legacy or boot consoles

    Currently the console lock is used to attempt legacy-type
    printing even if there are no legacy or boot consoles registered.
    If no such consoles are registered, the console lock does not
    need to be taken.

    Also, if boot consoles are registered, nbcon consoles must
    perform their atomic printing under the console lock in order
    to be synchronized with boot consoles.

    Add tracking of legacy console registration and use it with
    boot console tracking to avoid unnecessary code paths, i.e.
    do not use the console lock if there are no boot consoles
    and no legacy consoles.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:25 -04:00
Andrew Halaney b3db12eec8 printk: nbcon: Assign priority based on CPU state
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit 7705354adeb79a835d99e3d88414cdfe6cf07f60
Author: John Ogness <john.ogness@linutronix.de>
Date:   Thu Dec 14 14:38:42 2023 +0000

    printk: nbcon: Assign priority based on CPU state

    Use the current state of the CPU to determine which priority to
    assign to the printing context.

    Note: The uart_port wrapper, which is responsible for non-console-
          printing activities, will always use NORMAL priority.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:25 -04:00
Andrew Halaney a821689d57 printk: nbcon: Use nbcon consoles in console_flush_all()
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit 83cb83122d956641ae5d7d798ebc4a160a36db2f
Author: John Ogness <john.ogness@linutronix.de>
Date:   Tue Sep 19 14:33:27 2023 +0000

    printk: nbcon: Use nbcon consoles in console_flush_all()

    Allow nbcon consoles to print messages in the printk() caller
    context by integrating them into console_flush_all(). The
    write_atomic() callback is used for printing.

    Provide nbcon_console_emit_next_record(), which acts as the
    nbcon variant of console_emit_next_record(). Call this variant
    within console_flush_all() for nbcon consoles. Since nbcon
    consoles use their own @nbcon_seq variable to track the next
    record to print, this also must be appropriately handled.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:25 -04:00
Andrew Halaney af38167d3a printk: nbcon: Provide function to flush using write_atomic()
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit d73d9e0532546be3071b7d9badc4b5818f0a4e10
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Sep 12 12:00:08 2023 +0000

    printk: nbcon: Provide function to flush using write_atomic()

    Provide nbcon_atomic_flush_all() to perform flushing of all
    registered nbcon consoles using their write_atomic() callback.
    Like with legacy consoles, the nbcon consoles are flushed one
    record per console. This allows all nbcon consoles to print
    lines pseudo-simultaneously, rather than one console waiting
    for the full ringbuffer to dump to another console before
    printing anything.

    Unlike console_flush_all(), nbcon_atomic_flush_all() will only
    flush up through the newest record at the time of the call.
    This prevents a CPU from printing unbounded when other CPUs are
    adding records.

    Perform nbcon console atomic flushing in
    console_flush_on_panic(). This function is not only used in
    panic() but also other locations where there may be stored
    messages that need to be flushed.

    Co-developed-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Thomas Gleixner (Intel) <tglx@linutronix.de>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:25 -04:00
Andrew Halaney 5d37a399d6 printk: Add @flags argument for console_is_usable()
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit 72ef0acd2e92f18c01dcfc7918af2835b3857952
Author: John Ogness <john.ogness@linutronix.de>
Date:   Tue Sep 12 13:45:33 2023 +0000

    printk: Add @flags argument for console_is_usable()

    The caller of console_is_usable() usually needs @console->flags
    for its own checks. Rather than having console_is_usable() read
    its own copy, make the caller pass in the @flags. This also
    ensures that the caller saw the same @flags value.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:25 -04:00
Andrew Halaney 2e53cd19e5 printk: Let console_is_usable() handle nbcon
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit d2f37f9e4496a237c968e51173e29868d5531646
Author: John Ogness <john.ogness@linutronix.de>
Date:   Tue Sep 12 13:53:21 2023 +0000

    printk: Let console_is_usable() handle nbcon

    The nbcon consoles use a different printing callback. For nbcon
    consoles, check for the write_atomic() callback instead of
    write().

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:25 -04:00
Andrew Halaney 0e4e7f0c8f printk: Make console_is_usable() available to nbcon
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit efdd7f7e45f5b24fca1e6682e14ca1f209a54b50
Author: John Ogness <john.ogness@linutronix.de>
Date:   Tue Sep 12 13:25:41 2023 +0000

    printk: Make console_is_usable() available to nbcon

    Move console_is_usable() as-is into internal.h so that it can
    be used by nbcon printing functions as well.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:24 -04:00
Andrew Halaney 5a45650936 printk: Add this_cpu_in_panic()
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit 9a02d5fda6287d943fc2d58cd1a3dc768d0c4e56
Author: John Ogness <john.ogness@linutronix.de>
Date:   Fri Oct 13 14:30:49 2023 +0000

    printk: Add this_cpu_in_panic()

    There is already panic_in_progress() and other_cpu_in_panic(),
    but checking if the current CPU is the panic CPU must still be
    open coded.

    Add this_cpu_in_panic() to complete the set.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:23 -04:00
Andrew Halaney 014db9f51e printk: nbcon: Add emit function and callback function for atomic printing
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit 3ed6e3169b7533adb444e3116b44094b9c00326e
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Sat Sep 16 21:26:06 2023 +0206

    printk: nbcon: Add emit function and callback function for atomic printing

    Implement an emit function for nbcon consoles to output printk
    messages. It utilizes the lockless printk_get_next_message() and
    console_prepend_dropped() functions to retrieve/build the output
    message. The emit function includes the required safety points to
    check for handover/takeover and calls a new write_atomic callback
    of the console driver to output the message. It also includes
    proper handling for updating the nbcon console sequence number.

    A new nbcon_write_context struct is introduced. This is provided
    to the write_atomic callback and includes only the information
    necessary for performing atomic writes.

    Co-developed-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Thomas Gleixner (Intel) <tglx@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230916192007.608398-8-john.ogness@linutronix.de
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:22 -04:00
Andrew Halaney 7887e28910 printk: nbcon: Add sequence handling
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit 28fac1ea3b9ecdcc1db264094f47ba6a20ed21e9
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Sat Sep 16 21:26:05 2023 +0206

    printk: nbcon: Add sequence handling

    Add an atomic_long_t field @nbcon_seq to the console struct to
    store the sequence number for nbcon consoles. For nbcon consoles
    this will be used instead of the non-atomic @seq field. The new
    field allows for safe atomic sequence number updates without
    requiring any locking.

    On 64bit systems the new field stores the full sequence number.
    On 32bit systems the new field stores the lower 32 bits of the
    sequence number, which are expanded to 64bit as needed by
    folding the values based on the sequence numbers available in
    the ringbuffer.

    For 32bit systems, having a 32bit representation in the console
    is sufficient. If a console ever gets more than 2^31 records
    behind the ringbuffer then this is the least of the problems.

    Co-developed-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Thomas Gleixner (Intel) <tglx@linutronix.de>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230916192007.608398-7-john.ogness@linutronix.de
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:22 -04:00
Andrew Halaney c4904237ed printk: nbcon: Add buffer management
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit eea34fa9a5e6e5ef9b0c2df58e6102128f978177
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Sat Sep 16 21:26:03 2023 +0206

    printk: nbcon: Add buffer management

    In case of hostile takeovers it must be ensured that the previous
    owner cannot scribble over the output buffer of the emergency/panic
    context. This is achieved by:

     - Adding a global output buffer instance for the panic context.
       This is the only situation where hostile takeovers can occur and
       there is always at most 1 panic context.

     - Allocating an output buffer per non-boot console upon console
       registration. This buffer is used by the console owner when not
       in panic context. (For boot consoles, the existing shared global
       legacy output buffer is used instead. Boot console printing will
       be synchronized with legacy console printing.)

     - Choosing the appropriate buffer is handled in the acquire/release
       functions.

    Co-developed-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Thomas Gleixner (Intel) <tglx@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230916192007.608398-5-john.ogness@linutronix.de
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:22 -04:00
Andrew Halaney 7391eb1339 printk: Make static printk buffers available to nbcon
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit 7399878c45c91bbe9a7f3274e35f60a612f52b95
Author: John Ogness <john.ogness@linutronix.de>
Date:   Sat Sep 16 21:26:02 2023 +0206

    printk: Make static printk buffers available to nbcon

    The nbcon boot consoles also need printk buffers that are available
    very early. Since the nbcon boot consoles will also be serialized
    by the console_lock, they can use the same static printk buffers
    that the legacy consoles are using.

    Make the legacy static printk buffers available outside of printk.c
    so they can be used by nbcon.c.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230916192007.608398-4-john.ogness@linutronix.de
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:22 -04:00
Andrew Halaney 0237abe864 printk: Add non-BKL (nbcon) console basic infrastructure
JIRA: https://issues.redhat.com/browse/RHEL-3987
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/

commit 4d72508b6543fa21b2ab307bb09a7cbfdc188c3f
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Sat Sep 16 21:26:00 2023 +0206

    printk: Add non-BKL (nbcon) console basic infrastructure

    The current console/printk subsystem is protected by a Big Kernel Lock,
    (aka console_lock) which has ill defined semantics and is more or less
    stateless. This puts severe limitations on the console subsystem and
    makes forced takeover and output in emergency and panic situations a
    fragile endeavour that is based on try and pray.

    The goal of non-BKL (nbcon) consoles is to break out of the console lock
    jail and to provide a new infrastructure that avoids the pitfalls and
    also allows console drivers to be gradually converted over.

    The proposed infrastructure aims for the following properties:

      - Per console locking instead of global locking
      - Per console state that allows to make informed decisions
      - Stateful handover and takeover

    As a first step, state is added to struct console. The per console state
    is an atomic_t using a 32bit bit field.

    Reserve state bits, which will be populated later in the series. Wire
    it up into the console register/unregister functionality.

    It was decided to use a bitfield because using a plain u32 with
    mask/shift operations resulted in uncomprehensible code.

    Co-developed-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Signed-off-by: Thomas Gleixner (Intel) <tglx@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230916192007.608398-2-john.ogness@linutronix.de
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:22 -04:00
Andrew Halaney 826b46afbe printk: Rename abandon_console_lock_in_panic() to other_cpu_in_panic()
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit 132a90d1527fedba2d95085c951ccf00dbbebe41
Author: John Ogness <john.ogness@linutronix.de>
Date:   Mon Jul 17 21:52:07 2023 +0206

    printk: Rename abandon_console_lock_in_panic() to other_cpu_in_panic()

    Currently abandon_console_lock_in_panic() is only used to determine if
    the current CPU should immediately release the console lock because
    another CPU is in panic. However, later this function will be used by
    the CPU to immediately release other resources in this situation.

    Rename the function to other_cpu_in_panic(), which is a better
    description and does not assume it is related to the console lock.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230717194607.145135-8-john.ogness@linutronix.de

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:21 -04:00
Andrew Halaney c423f03e67 printk: adjust string limit macros
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit b0975c47c2178e35038b12ad63f17c64bb522684
Author: John Ogness <john.ogness@linutronix.de>
Date:   Mon Jan 9 11:14:00 2023 +0106

    printk: adjust string limit macros

    The various internal size limit macros have names and/or values that
    do not fit well to their current usage.

    Rename the macros so that their purpose is clear and, if needed,
    provide a more appropriate value. In general, the new macros and
    values will lead to less memory usage. The new macros are...

    PRINTK_MESSAGE_MAX:

    This is the maximum size for a formatted message on a console,
    devkmsg, or syslog. It does not matter which format the message has
    (normal or extended). It replaces the use of CONSOLE_EXT_LOG_MAX for
    console and devkmsg. It replaces the use of CONSOLE_LOG_MAX for
    syslog.

    Historically, normal messages have been allowed to print up to 1kB,
    whereas extended messages have been allowed to print up to 8kB.
    However, the difference in lengths of these message types is not
    significant and in multi-line records, normal messages are probably
    larger. Also, because 1kB is only slightly above the allowed record
    size, multi-line normal messages could be easily truncated during
    formatting.

    This new macro should be significantly larger than the allowed
    record size to allow sufficient space for extended or multi-line
    prefix text. A value of 2kB should be plenty of space. For normal
    messages this represents a doubling of the historically allowed
    amount. For extended messages it reduces the excessive 8kB size,
    thus reducing memory usage needed for message formatting.

    PRINTK_PREFIX_MAX:

    This is the maximum size allowed for a record prefix (used by
    console and syslog). It replaces PREFIX_MAX. The value is left
    unchanged.

    PRINTKRB_RECORD_MAX:

    This is the maximum size allowed to be reserved for a record in the
    ringbuffer. It is used by all readers and writers with the printk
    ringbuffer. It replaces LOG_LINE_MAX.

    Previously this was set to "1kB - PREFIX_MAX", which makes some
    sense if 1kB is the limit for normal message output and prefixes are
    enabled. However, with the allowance of larger output and the
    existence of multi-line records, the value is rather bizarre.

    Round the value up to 1kB.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230109100800.1085541-9-john.ogness@linutronix.de

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:20 -04:00
Andrew Halaney 0301e416be printk: introduce console_prepend_dropped() for dropped messages
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit c4fcc617e148791fc45fd33b124301cb596bcbf6
Author: John Ogness <john.ogness@linutronix.de>
Date:   Mon Jan 9 11:13:58 2023 +0106

    printk: introduce console_prepend_dropped() for dropped messages

    Currently "dropped messages" are separately printed immediately
    before printing the printk message. Since normal consoles are
    now using an output buffer that is much larger than previously,
    the "dropped message" could be prepended to the printk message
    and then output everything in a single write() call.

    Introduce a helper function console_prepend_dropped() to prepend
    an existing message with a "dropped message". This simplifies
    the code by allowing all message formatting to be handled
    together and then only requires a single write() call to output
    the full message. And since this helper does not require any
    locking, it can be used in the future for other console printing
    contexts as well.

    Note that console_prepend_dropped() is defined as a NOP for
    !CONFIG_PRINTK. Although the function will never be called for
    !CONFIG_PRINTK, compiling the function can lead to warnings of
    "always true" conditionals due to the size macro values used
    in !CONFIG_PRINTK.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230109100800.1085541-7-john.ogness@linutronix.de

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:20 -04:00
Andrew Halaney 4f5e52cf34 printk: introduce printk_get_next_message() and printk_message
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit 2830eec14afd18c7af333b5222f47a1244adea11
Author: John Ogness <john.ogness@linutronix.de>
Date:   Mon Jan 9 11:13:57 2023 +0106

    printk: introduce printk_get_next_message() and printk_message

    Code for performing the console output is intermixed with code that
    is formatting the output for that console. Introduce a new helper
    function printk_get_next_message() to handle the reading and
    formatting of the printk text. The helper does not require any
    locking so that in the future it can be used for other printing
    contexts as well.

    This also introduces a new struct printk_message to wrap the struct
    printk_buffers, adding metadata about its contents. This allows
    users of printk_get_next_message() to receive all relevant
    information about the message that was read and formatted.

    Why is struct printk_message a wrapper struct?

    It is intentional that a wrapper struct is introduced instead of
    adding the metadata directly to struct printk_buffers. The upcoming
    atomic consoles support multiple printing contexts per CPU. This
    means that while a CPU is formatting a message, it can be
    interrupted and the interrupting context may also format a (possibly
    different) message. Since the printk buffers are rather large,
    there will only be one struct printk_buffers per CPU and it must be
    shared by the possible contexts of that CPU.

    If the metadata was part of struct printk_buffers, interrupting
    contexts would clobber the metadata being prepared by the
    interrupted context. This could be handled by robustifying the
    message formatting functions to cope with metadata unexpectedly
    changing. However, this would require significant amounts of extra
    data copying, also adding significant complexity to the code.

    Instead, the metadata can live on the stack of the formatting
    context and the message formatting functions do not need to be
    concerned about the metadata changing underneath them.

    Note that the message formatting functions can handle unexpected
    text buffer changes. So it is perfectly OK if a shared text buffer
    is clobbered by an interrupting context. The atomic console
    implementation will recognize the interruption and avoid printing
    the (probably garbage) text buffer.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230109100800.1085541-6-john.ogness@linutronix.de

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:19 -04:00
Andrew Halaney 23be707373 printk: introduce struct printk_buffers
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit daaab5b5bba36a5aef790230b610556b9bbd9cfc
Author: John Ogness <john.ogness@linutronix.de>
Date:   Mon Jan 9 11:13:56 2023 +0106

    printk: introduce struct printk_buffers

    Introduce a new struct printk_buffers to contain all the buffers
    needed to read and format a printk message for output. Putting the
    buffers inside a struct reduces the number of buffer pointers that
    need to be tracked. Also, it allows usage of the sizeof() macro for
    the buffer sizes, rather than expecting certain sized buffers being
    passed in.

    Note that since the output buffer for normal consoles is now
    CONSOLE_EXT_LOG_MAX instead of CONSOLE_LOG_MAX, multi-line
    messages that may have been previously truncated will now be
    printed in full. This should be considered a feature and not a bug
    since the CONSOLE_LOG_MAX restriction was about limiting static
    buffer usage rather than limiting printed text.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230109100800.1085541-5-john.ogness@linutronix.de

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:19 -04:00
Andrew Halaney 3f9d1079a7 printk: move size limit macros into internal.h
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit 2364b406824f1f42026d87c1e26d4dd1ca0f65af
Author: John Ogness <john.ogness@linutronix.de>
Date:   Mon Jan 9 11:13:53 2023 +0106

    printk: move size limit macros into internal.h

    The size limit macros are located further down in printk.c and
    behind ifdef conditionals. This complicates their usage for
    upcoming changes. Move the macros into internal.h so that they
    are still invisible outside of printk, but easily accessible
    for printk.

    Also, the maximum size of formatted extended messages does not
    need to be known by any code outside of printk, so move it to
    internal.h as well. And like CONSOLE_LOG_MAX, for !CONFIG_PRINTK
    set CONSOLE_EXT_LOG_MAX to 0 to reduce the static memory
    footprint.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20230109100800.1085541-2-john.ogness@linutronix.de

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:19 -04:00
Andrew Halaney 19bff33a9f Revert "printk: Bring back the RT bits."
JIRA: https://issues.redhat.com/browse/RHEL-24205
Upstream Status: RHEL only

This reverts commit 0990e82f88.

The RT team wants the printk series updated, so let's pop off anything
from the current series before upgrading the TTY subsystem (to aid in
upgrading the printk series).

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:24:08 -04:00
Juri Lelli 0990e82f88 printk: Bring back the RT bits.
Bugzilla: https://bugzilla.redhat.com/2171995
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git

commit b576ab7eadbf1835eddfa5a47eea0a57d3f5b74f
Author:    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date:      Tue Jul 19 20:08:01 2022 +0200

    printk: Bring back the RT bits.

    This is a revert of the commits:
    | 07a22b61946f0 Revert "printk: add functions to prefer direct printing"
    | 5831788afb17b Revert "printk: add kthread console printers"
    | 2d9ef940f89e0 Revert "printk: extend console_lock for per-console locking"
    | 007eeab7e9f03 Revert "printk: remove @console_locked"
    | 05c96b3713aa2 Revert "printk: Block console kthreads when direct printing will be required"
    | 20fb0c8272bbb Revert "printk: Wait for the global console lock when the system is going down"

    which is needed for the atomic consoles which are used on PREEMPT_RT.

    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Signed-off-by: Juri Lelli <juri.lelli@redhat.com>
2023-02-27 13:46:09 +01:00
David Arcari b24b77e481 Revert "printk: Wait for the global console lock when the system is going down"
Bugzilla: https://bugzilla.redhat.com/2117494

commit 20fb0c8272bbb102d15bdd11aa64f828619dd7cc
Author: Petr Mladek <pmladek@suse.com>
Date:   Thu Jun 23 16:51:52 2022 +0200

    Revert "printk: Wait for the global console lock when the system is going down"

    This reverts commit b87f02307d3cfbda768520f0687c51ca77e14fc3.

    The testing of 5.19 release candidates revealed missing synchronization
    between early and regular console functionality.

    It would be possible to start the console kthreads later as a workaround.
    But it is clear that console lock serialized console drivers between
    each other. It opens a big area of possible problems that were not
    considered by people involved in the development and review.

    printk() is crucial for debugging kernel issues and console output is
    very important part of it. The number of consoles is huge and a proper
    review would take some time. As a result it need to be reverted for 5.19.

    Link: https://lore.kernel.org/r/YrBdjVwBOVgLfHyb@alley
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20220623145157.21938-2-pmladek@suse.com

Signed-off-by: David Arcari <darcari@redhat.com>
2022-09-15 08:47:34 -04:00
David Arcari 8fb70f6a0c printk: Wait for the global console lock when the system is going down
Bugzilla: https://bugzilla.redhat.com/2117494

commit b87f02307d3cfbda768520f0687c51ca77e14fc3
Author: Petr Mladek <pmladek@suse.com>
Date:   Wed Jun 15 18:28:05 2022 +0200

    printk: Wait for the global console lock when the system is going down

    There are reports that the console kthreads block the global console
    lock when the system is going down, for example, reboot, panic.

    First part of the solution was to block kthreads in these problematic
    system states so they stopped handling newly added messages.

    Second part of the solution is to wait when for the kthreads when
    they are actively printing. It solves the problem when a message
    was printed before the system entered the problematic state and
    the kthreads managed to step in.

    A busy waiting has to be used because panic() can be called in any
    context and in an unknown state of the scheduler.

    There must be a timeout because the kthread might get stuck or sleeping
    and never release the lock. The timeout 10s is an arbitrary value
    inspired by the softlockup timeout.

    Link: https://lore.kernel.org/r/20220610205038.GA3050413@paulmck-ThinkPad-P17-Gen-1
    Link: https://lore.kernel.org/r/CAMdYzYpF4FNTBPZsEFeWRuEwSies36QM_As8osPWZSr2q-viEA@mail.gmail.com
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Tested-by: Paul E. McKenney <paulmck@kernel.org>
    Link: https://lore.kernel.org/r/20220615162805.27962-3-pmladek@suse.com

Signed-off-by: David Arcari <darcari@redhat.com>
2022-09-15 08:47:34 -04:00
David Arcari 4ecdd9108c printk: fix build warning when CONFIG_PRINTK=n
Bugzilla: https://bugzilla.redhat.com/2117494

commit fdcd4073fccc6f989308be3f1d61d8a68cd990ce
Author: Xiaoming Ni <nixiaoming@huawei.com>
Date:   Fri Jan 21 22:13:34 2022 -0800

    printk: fix build warning when CONFIG_PRINTK=n

    build warning when CONFIG_PRINTK=n

            kernel/printk/printk.c:175:5: warning: no previous prototype for
             'devkmsg_sysctl_set_loglvl' [-Wmissing-prototypes]

    devkmsg_sysctl_set_loglvl() is only used in sysctl.c when
    CONFIG_PRINTK=y, but it participates in the build when CONFIG_PRINTK=n.
    So add compile dependency CONFIG_PRINTK=y && CONFIG_SYSCTL=y to fix the
    build warning.

    Link: https://lkml.kernel.org/r/20211129211943.640266-5-mcgrof@kernel.org
    Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
    Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
    Cc: Al Viro <viro@zeniv.linux.org.uk>
    Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
    Cc: Antti Palosaari <crope@iki.fi>
    Cc: Christian Brauner <christian.brauner@ubuntu.com>
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: Eric Biederman <ebiederm@xmission.com>
    Cc: Eric Biggers <ebiggers@google.com>
    Cc: Iurii Zaikin <yzaikin@google.com>
    Cc: Kees Cook <keescook@chromium.org>
    Cc: Lukas Middendorf <kernel@tuxforce.de>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: "Naveen N. Rao" <naveen.n.rao@linux.ibm.com>
    Cc: Stephen Kitt <steve@sk2.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-09-15 08:47:32 -04:00
David Arcari 5f21fda948 printk: move printk sysctl to printk/sysctl.c
Bugzilla: https://bugzilla.redhat.com/2117494
Conflicts: RHEL is missing a number of kernel/systcl.c commits,
	   rather than bring all of those I merely retained the
	   use of "static const int two" in kernel/printf/sysctl.c
	   There is no functional difference.

commit faaa357a55e03490fb280ac211be2298e635b220
Author: Xiaoming Ni <nixiaoming@huawei.com>
Date:   Fri Jan 21 22:12:33 2022 -0800

    printk: move printk sysctl to printk/sysctl.c

    kernel/sysctl.c is a kitchen sink where everyone leaves their dirty
    dishes, this makes it very difficult to maintain.

    To help with this maintenance let's start by moving sysctls to places
    where they actually belong.  The proc sysctl maintainers do not want to
    know what sysctl knobs you wish to add for your own piece of code, we
    just care about the core logic.

    So move printk sysctl from kernel/sysctl.c to kernel/printk/sysctl.c.
    Use register_sysctl() to register the sysctl interface.

    [mcgrof@kernel.org: fixed compile issues when PRINTK is not set, commit log update]

    Link: https://lkml.kernel.org/r/20211124231435.1445213-6-mcgrof@kernel.org
    Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
    Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
    Cc: Al Viro <viro@zeniv.linux.org.uk>
    Cc: Amir Goldstein <amir73il@gmail.com>
    Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Cc: Antti Palosaari <crope@iki.fi>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
    Cc: Benjamin LaHaise <bcrl@kvack.org>
    Cc: Clemens Ladisch <clemens@ladisch.de>
    Cc: David Airlie <airlied@linux.ie>
    Cc: Douglas Gilbert <dgilbert@interlog.com>
    Cc: Eric Biederman <ebiederm@xmission.com>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Iurii Zaikin <yzaikin@google.com>
    Cc: James E.J. Bottomley <jejb@linux.ibm.com>
    Cc: Jani Nikula <jani.nikula@intel.com>
    Cc: Jani Nikula <jani.nikula@linux.intel.com>
    Cc: Jan Kara <jack@suse.cz>
    Cc: Joel Becker <jlbec@evilplan.org>
    Cc: John Ogness <john.ogness@linutronix.de>
    Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
    Cc: Joseph Qi <joseph.qi@linux.alibaba.com>
    Cc: Julia Lawall <julia.lawall@inria.fr>
    Cc: Kees Cook <keescook@chromium.org>
    Cc: Lukas Middendorf <kernel@tuxforce.de>
    Cc: Mark Fasheh <mark@fasheh.com>
    Cc: Martin K. Petersen <martin.petersen@oracle.com>
    Cc: Paul Turner <pjt@google.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Petr Mladek <pmladek@suse.com>
    Cc: Phillip Potter <phil@philpotter.co.uk>
    Cc: Qing Wang <wangqing@vivo.com>
    Cc: "Rafael J. Wysocki" <rafael@kernel.org>
    Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
    Cc: Sebastian Reichel <sre@kernel.org>
    Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
    Cc: Stephen Kitt <steve@sk2.org>
    Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
    Cc: Suren Baghdasaryan <surenb@google.com>
    Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
    Cc: "Theodore Ts'o" <tytso@mit.edu>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-09-15 08:46:42 -04:00
David Arcari 2fe61436d1 printk: Rework parse_prefix into printk_parse_prefix
Bugzilla: https://bugzilla.redhat.com/2117494

commit f3d75cf537db57f7918a17a75527951de850e5ec
Author: Chris Down <chris@chrisdown.name>
Date:   Tue Jun 15 17:52:51 2021 +0100

    printk: Rework parse_prefix into printk_parse_prefix

    parse_prefix is needed externally by later patches, so move it into a
    context where it can be used as such. Also give it the printk_ prefix to
    reduce the chance of collisions.

    Signed-off-by: Chris Down <chris@chrisdown.name>
    Cc: Petr Mladek <pmladek@suse.com>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/b22ba314a860e5c7f887958f1eab2649f9bd1d06.1623775748.git.chris@chrisdown.name

Signed-off-by: David Arcari <darcari@redhat.com>
2022-09-12 13:17:58 -04:00
David Arcari f87562a1ae printk: Straighten out log_flags into printk_info_flags
Bugzilla: https://bugzilla.redhat.com/2117494

commit a1ad4b8a19566b11e0306f8b197f2fd4567340e5
Author: Chris Down <chris@chrisdown.name>
Date:   Tue Jun 15 17:52:48 2021 +0100

    printk: Straighten out log_flags into printk_info_flags

    In the past, `enum log_flags` was part of `struct log`, hence the name.
    `struct log` has since been reworked and now this struct is stored
    inside `struct printk_info`. However, the name was never updated, which
    is somewhat confusing -- especially since these flags operate at the
    record level rather than at the level of an abstract log.

    printk_info_flags also joins its other metadata struct friends in
    printk_ringbuffer.h.

    Signed-off-by: Chris Down <chris@chrisdown.name>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/3dd801982f02603e6e3aa4f8bc4f5ebb830a4949.1623775748.git.chris@chrisdown.name

Signed-off-by: David Arcari <darcari@redhat.com>
2022-09-12 13:17:54 -04:00
Prarit Bhargava 5c73d5ae60 printk: remove NMI tracking
Bugzilla: http://bugzilla.redhat.com/2023082

commit 85e3e7fbbb720b9897fba9a99659e31cbd1c082e
Author: John Ogness <john.ogness@linutronix.de>
Date:   Thu Jul 15 21:39:57 2021 +0206

    printk: remove NMI tracking

    All NMI contexts are handled the same as the safe context: store the
    message and defer printing. There is no need to have special NMI
    context tracking for this. Using in_nmi() is enough.

    There are several parts of the kernel that are manually calling into
    the printk NMI context tracking in order to cause general printk
    deferred printing:

        arch/arm/kernel/smp.c
        arch/powerpc/kexec/crash.c
        kernel/trace/trace.c

    For arm/kernel/smp.c and powerpc/kexec/crash.c, provide a new
    function pair printk_deferred_enter/exit that explicitly achieves the
    same objective.

    For ftrace, remove the printk context manipulation completely. It was
    added in commit 03fc7f9c99 ("printk/nmi: Prevent deadlock when
    accessing the main log buffer in NMI"). The purpose was to enforce
    storing messages directly into the ring buffer even in NMI context.
    It really should have only modified the behavior in NMI context.
    There is no need for a special behavior any longer. All messages are
    always stored directly now. The console deferring is handled
    transparently in vprintk().

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    [pmladek@suse.com: Remove special handling in ftrace.c completely.
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20210715193359.25946-5-john.ogness@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2022-01-11 09:45:30 -05:00
Prarit Bhargava 78720a8d2e printk: remove safe buffers
Bugzilla: http://bugzilla.redhat.com/2023082

commit 93d102f094be9beab28e5afb656c188b16a3793b
Author: John Ogness <john.ogness@linutronix.de>
Date:   Thu Jul 15 21:39:56 2021 +0206

    printk: remove safe buffers

    With @logbuf_lock removed, the high level printk functions for
    storing messages are lockless. Messages can be stored from any
    context, so there is no need for the NMI and safe buffers anymore.
    Remove the NMI and safe buffers.

    Although the safe buffers are removed, the NMI and safe context
    tracking is still in place. In these contexts, store the message
    immediately but still use irq_work to defer the console printing.

    Since printk recursion tracking is in place, safe context tracking
    for most of printk is not needed. Remove it. Only safe context
    tracking relating to the console and console_owner locks is left
    in place. This is because the console and console_owner locks are
    needed for the actual printing.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Signed-off-by: Petr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20210715193359.25946-4-john.ogness@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2022-01-11 09:45:30 -05:00
Rasmus Villemoes 28e1745b9f printk: rename vprintk_func to vprintk
The printk code is already hard enough to understand. Remove an
unnecessary indirection by renaming vprintk_func to vprintk (adding
the asmlinkage annotation), and removing the vprintk definition from
printk.c. That way, printk is implemented in terms of vprintk as one
would expect, and there's no "vprintk_func, what's that? Some function
pointer that gets set where?"

The declaration of vprintk in linux/printk.h already has the
__printf(1,0) attribute, there's no point repeating that with the
definition - it's for diagnostics in callers.

linux/printk.h already contains a static inline {return 0;} definition
of vprintk when !CONFIG_PRINTK.

Since the corresponding stub definition of vprintk_func was not marked
"static inline", any translation unit including internal.h would get a
definition of vprintk_func - it just so happens that for
!CONFIG_PRINTK, there is precisely one such TU, namely printk.c. Had
there been more, it would be a link error; now it's just a silly waste
of a few bytes of .text, which one must assume are rather precious to
anyone disabling PRINTK.

$ objdump -dr kernel/printk/printk.o
00000330 <vprintk_func>:
 330:   31 c0                   xor    %eax,%eax
 332:   c3                      ret
 333:   8d b4 26 00 00 00 00    lea    0x0(%esi,%eiz,1),%esi
 33a:   8d b6 00 00 00 00       lea    0x0(%esi),%esi

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20210323144201.486050-1-linux@rasmusvillemoes.dk
2021-03-30 15:21:18 +02:00
John Ogness 996e966640 printk: remove logbuf_lock
Since the ringbuffer is lockless, there is no need for it to be
protected by @logbuf_lock. Remove @logbuf_lock.

@console_seq, @exclusive_console_stop_seq, @console_dropped are
protected by @console_lock.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20210303101528.29901-14-john.ogness@linutronix.de
2021-03-08 11:43:32 +01:00
John Ogness 74caba7f2a printk: move dictionary keys to dev_printk_info
Dictionaries are only used for SUBSYSTEM and DEVICE properties. The
current implementation stores the property names each time they are
used. This requires more space than otherwise necessary. Also,
because the dictionary entries are currently considered optional,
it cannot be relied upon that they are always available, even if the
writer wanted to store them. These issues will increase should new
dictionary properties be introduced.

Rather than storing the subsystem and device properties in the
dict ring, introduce a struct dev_printk_info with separate fields
to store only the property values. Embed this struct within the
struct printk_info to provide guaranteed availability.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/87mu1jl6ne.fsf@jogness.linutronix.de
2020-09-22 11:27:48 +02:00
Petr Mladek 8c4e93c362 printk: Prepare for nested printk_nmi_enter()
There is plenty of space in the printk_context variable. Reserve one byte
there for the NMI context to be on the safe side.

It should never overflow. The BUG_ON(in_nmi() == NMI_MASK) in nmi_enter()
will trigger much earlier.

Signed-off-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Link: https://lkml.kernel.org/r/20200505134100.681374113@linutronix.de
2020-05-19 15:51:16 +02:00
Sergey Senozhatsky ab6f762f0f printk: queue wake_up_klogd irq_work only if per-CPU areas are ready
printk_deferred(), similarly to printk_safe/printk_nmi, does not
immediately attempt to print a new message on the consoles, avoiding
calls into non-reentrant kernel paths, e.g. scheduler or timekeeping,
which potentially can deadlock the system.

Those printk() flavors, instead, rely on per-CPU flush irq_work to print
messages from safer contexts.  For same reasons (recursive scheduler or
timekeeping calls) printk() uses per-CPU irq_work in order to wake up
user space syslog/kmsg readers.

However, only printk_safe/printk_nmi do make sure that per-CPU areas
have been initialised and that it's safe to modify per-CPU irq_work.
This means that, for instance, should printk_deferred() be invoked "too
early", that is before per-CPU areas are initialised, printk_deferred()
will perform illegal per-CPU access.

Lech Perczak [0] reports that after commit 1b710b1b10 ("char/random:
silence a lockdep splat with printk()") user-space syslog/kmsg readers
are not able to read new kernel messages.

The reason is printk_deferred() being called too early (as was pointed
out by Petr and John).

Fix printk_deferred() and do not queue per-CPU irq_work before per-CPU
areas are initialized.

Link: https://lore.kernel.org/lkml/aa0732c6-5c4e-8a8b-a1c1-75ebe3dca05b@camlintechnologies.com/
Reported-by: Lech Perczak <l.perczak@camlintechnologies.com>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Tested-by: Jann Horn <jannh@google.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-04-10 13:18:57 -07:00
Thomas Gleixner 1ccea77e2a treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 13
Based on 2 normalized pattern(s):

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license as published by
  the free software foundation either version 2 of the license or at
  your option any later version this program is distributed in the
  hope that it will be useful but without any warranty without even
  the implied warranty of merchantability or fitness for a particular
  purpose see the gnu general public license for more details you
  should have received a copy of the gnu general public license along
  with this program if not see http www gnu org licenses

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license as published by
  the free software foundation either version 2 of the license or at
  your option any later version this program is distributed in the
  hope that it will be useful but without any warranty without even
  the implied warranty of merchantability or fitness for a particular
  purpose see the gnu general public license for more details [based]
  [from] [clk] [highbank] [c] you should have received a copy of the
  gnu general public license along with this program if not see http
  www gnu org licenses

extracted by the scancode license scanner the SPDX license identifier

  GPL-2.0-or-later

has been chosen to replace the boilerplate/reference in 355 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Jilayne Lovejoy <opensource@jilayne.com>
Reviewed-by: Steve Winslow <swinslow@gmail.com>
Reviewed-by: Allison Randal <allison@lohutok.net>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190519154041.837383322@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-05-21 11:28:45 +02:00
Petr Mladek 03fc7f9c99 printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
The commit 719f6a7040 ("printk: Use the main logbuf in NMI
when logbuf_lock is available") brought back the possible deadlocks
in printk() and NMI.

The check of logbuf_lock is done only in printk_nmi_enter() to prevent
mixed output. But another CPU might take the lock later, enter NMI, and:

      + Both NMIs might be serialized by yet another lock, for example,
	the one in nmi_cpu_backtrace().

      + The other CPU might get stopped in NMI, see smp_send_stop()
	in panic().

The only safe solution is to use trylock when storing the message
into the main log-buffer. It might cause reordering when some lines
go to the main lock buffer directly and others are delayed via
the per-CPU buffer. It means that it is not useful in general.

This patch replaces the problematic NMI deferred context with NMI
direct context. It can be used to mark a code that might produce
many messages in NMI and the risk of losing them is more critical
than problems with eventual reordering.

The context is then used when dumping trace buffers on oops. It was
the primary motivation for the original fix. Also the reordering is
even smaller issue there because some traces have their own time stamps.

Finally, nmi_cpu_backtrace() need not longer be serialized because
it will always us the per-CPU buffers again.

Fixes: 719f6a7040 ("printk: Use the main logbuf in NMI when logbuf_lock is available")
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/20180627142028.11259-1-pmladek@suse.com
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
2018-07-09 14:10:40 +02:00
Petr Mladek 719f6a7040 printk: Use the main logbuf in NMI when logbuf_lock is available
The commit 42a0bb3f71 ("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 a9edc88093 ("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 <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russell King <rack+kernel@arm.linux.org.uk>
Cc: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Cc: x86@kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Suggested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
2017-05-19 14:42:19 +02:00
Sergey Senozhatsky ddb9baa822 printk: report lost messages in printk safe/nmi contexts
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 <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Tejun Heo <tj@kernel.org>
Cc: Calvin Owens <calvinowens@fb.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Hurley <peter@hurleysoftware.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
2017-02-08 13:50:05 +01:00
Sergey Senozhatsky 099f1c84c0 printk: introduce per-cpu safe_print seq buffer
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 <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Tejun Heo <tj@kernel.org>
Cc: Calvin Owens <calvinowens@fb.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Hurley <peter@hurleysoftware.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
2017-02-08 11:07:11 +01:00
Linus Torvalds a0cba2179e Revert "printk: create pr_<level> functions"
This reverts commit 874f9c7da9.

Geert Uytterhoeven reports:
 "This change seems to have an (unintendent?) side-effect.

  Before, pr_*() calls without a trailing newline characters would be
  printed with a newline character appended, both on the console and in
  the output of the dmesg command.

  After this commit, no new line character is appended, and the output
  of the next pr_*() call of the same type may be appended, like in:

    - Truncating RAM at 0x0000000040000000-0x00000000c0000000 to -0x0000000070000000
    - Ignoring RAM at 0x0000000200000000-0x0000000240000000 (!CONFIG_HIGHMEM)
    + Truncating RAM at 0x0000000040000000-0x00000000c0000000 to -0x0000000070000000Ignoring RAM at 0x0000000200000000-0x0000000240000000 (!CONFIG_HIGHMEM)"

Joe Perches says:
 "No, that is not intentional.

  The newline handling code inside vprintk_emit is a bit involved and
  for now I suggest a revert until this has all the same behavior as
  earlier"

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Requested-by: Joe Perches <joe@perches.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-08-09 10:48:18 -07:00
Joe Perches 874f9c7da9 printk: create pr_<level> functions
Using functions instead of macros can reduce overall code size by
eliminating unnecessary "KERN_SOH<digit>" prefixes from format strings.

  defconfig x86-64:

  $ size vmlinux*
     text    data     bss      dec     hex  filename
  10193570 4331464 1105920 15630954  ee826a vmlinux.new
  10192623 4335560 1105920 15634103  ee8eb7 vmlinux.old

As the return value are unimportant and unused in the kernel tree, these
new functions return void.

Miscellanea:

 - change pr_<level> macros to call new __pr_<level> functions
 - change vprintk_nmi and vprintk_default to add LOGLEVEL_<level> argument

[akpm@linux-foundation.org: fix LOGLEVEL_INFO, per Joe]
Link: http://lkml.kernel.org/r/e16cc34479dfefcae37c98b481e6646f0f69efc3.1466718827.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-08-02 19:35:04 -04:00
Petr Mladek cf9b1106c8 printk/nmi: flush NMI messages on the system panic
In NMI context, printk() messages are stored into per-CPU buffers to
avoid a possible deadlock.  They are normally flushed to the main ring
buffer via an IRQ work.  But the work is never called when the system
calls panic() in the very same NMI handler.

This patch tries to flush NMI buffers before the crash dump is
generated.  In this case it does not risk a double release and bails out
when the logbuf_lock is already taken.  The aim is to get the messages
into the main ring buffer when possible.  It makes them better
accessible in the vmcore.

Then the patch tries to flush the buffers second time when other CPUs
are down.  It might be more aggressive and reset logbuf_lock.  The aim
is to get the messages available for the consequent kmsg_dump() and
console_flush_on_panic() calls.

The patch causes vprintk_emit() to be called even in NMI context again.
But it is done via printk_deferred() so that the console handling is
skipped.  Consoles use internal locks and we could not prevent a
deadlock easily.  They are explicitly called later when the crash dump
is not generated, see console_flush_on_panic().

Signed-off-by: Petr Mladek <pmladek@suse.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Daniel Thompson <daniel.thompson@linaro.org>
Cc: David Miller <davem@davemloft.net>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jiri Kosina <jkosina@suse.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-05-20 17:58:30 -07:00
Petr Mladek b522deabc6 printk/nmi: warn when some message has been lost in NMI context
We could not resize the temporary buffer in NMI context.  Let's warn if
a message is lost.

This is rather theoretical.  printk() should not be used in NMI.  The
only sensible use is when we want to print backtrace from all CPUs.  The
current buffer should be enough for this purpose.

[akpm@linux-foundation.org: whitespace fixlet]
Signed-off-by: Petr Mladek <pmladek@suse.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Jiri Kosina <jkosina@suse.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: David Miller <davem@davemloft.net>
Cc: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-05-20 17:58:30 -07:00
Petr Mladek 42a0bb3f71 printk/nmi: generic solution for safe printk in NMI
printk() takes some locks and could not be used a safe way in NMI
context.

The chance of a deadlock is real especially when printing stacks from
all CPUs.  This particular problem has been addressed on x86 by the
commit a9edc88093 ("x86/nmi: Perform a safe NMI stack trace on all
CPUs").

The patchset brings two big advantages.  First, it makes the NMI
backtraces safe on all architectures for free.  Second, it makes all NMI
messages almost safe on all architectures (the temporary buffer is
limited.  We still should keep the number of messages in NMI context at
minimum).

Note that there already are several messages printed in NMI context:
WARN_ON(in_nmi()), BUG_ON(in_nmi()), anything being printed out from MCE
handlers.  These are not easy to avoid.

This patch reuses most of the code and makes it generic.  It is useful
for all messages and architectures that support NMI.

The alternative printk_func is set when entering and is reseted when
leaving NMI context.  It queues IRQ work to copy the messages into the
main ring buffer in a safe context.

__printk_nmi_flush() copies all available messages and reset the buffer.
Then we could use a simple cmpxchg operations to get synchronized with
writers.  There is also used a spinlock to get synchronized with other
flushers.

We do not longer use seq_buf because it depends on external lock.  It
would be hard to make all supported operations safe for a lockless use.
It would be confusing and error prone to make only some operations safe.

The code is put into separate printk/nmi.c as suggested by Steven
Rostedt.  It needs a per-CPU buffer and is compiled only on
architectures that call nmi_enter().  This is achieved by the new
HAVE_NMI Kconfig flag.

The are MN10300 and Xtensa architectures.  We need to clean up NMI
handling there first.  Let's do it separately.

The patch is heavily based on the draft from Peter Zijlstra, see

  https://lkml.org/lkml/2015/6/10/327

[arnd@arndb.de: printk-nmi: use %zu format string for size_t]
[akpm@linux-foundation.org: min_t->min - all types are size_t here]
Signed-off-by: Petr Mladek <pmladek@suse.com>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Jan Kara <jack@suse.cz>
Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>	[arm part]
Cc: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Jiri Kosina <jkosina@suse.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: David Miller <davem@davemloft.net>
Cc: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-05-20 17:58:30 -07:00