Commit Graph

206 Commits

Author SHA1 Message Date
Rafael Aquini 1d9d0f7632 mm: remove arguments of show_mem()
JIRA: https://issues.redhat.com/browse/RHEL-27743

This patch is a backport of the following upstream commit:
commit 527ed4f7d902d362471a93e1a4afb604c18ceb48
Author: Kefeng Wang <wangkefeng.wang@huawei.com>
Date:   Fri Jun 30 14:22:52 2023 +0800

    mm: remove arguments of show_mem()

    All callers of show_mem() pass 0 and NULL, so we can remove the two
    arguments by directly calling __show_mem(0, NULL, MAX_NR_ZONES - 1) in
    show_mem().

    Link: https://lkml.kernel.org/r/20230630062253.189440-1-wangkefeng.wang@huawei.com
    Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
    Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Michael Ellerman <mpe@ellerman.id.au>
    Cc: Nicholas Piggin <npiggin@gmail.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2024-10-01 11:17:31 -04:00
Derek Barbosa 79f91ee9b1 Revert "kernel/panic.c: Move the location of bust_spinlocks to prevent hanging."
Upstream Status: RHEL-only

JIRA: https://issues.redhat.com/browse/RHEL-39473

This reverts commit 065095b23d.

Now that the upstream printk code has landed in c9s, remove the
extraneous "bust_spinlock(1)" that remained after merge to prevent the
abrupt "cut off" of call traces during panic.

Revert
commit 065095b23d
Author: Derek Barbosa <debarbos@redhat.com>
Date:   Wed Dec 6 09:09:56 2023 -0500

    kernel/panic.c: Move the location of bust_spinlocks to prevent hanging.

    JIRA: https://issues.redhat.com/browse/RHEL-15897
    Upstream Status: RHEL-Only

    Moving bust_spinlocks() closer to pr_emerge in the panic() function
    (specifically prior to flushing the consoles) addresses the
    issue of the kernel hanging while printing out a call trace during a
    panic.

    Signed-off-by: Derek Barbosa <debarbos@redhat.com>

Signed-off-by: Derek Barbosa <debarbos@redhat.com>
2024-06-21 11:17:34 -04:00
Andrew Halaney 26ae1957c6 panic: Mark emergency section in oops
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 a8eddfddf44cb7a26845ed266a228f660277e4b7
Author: John Ogness <john.ogness@linutronix.de>
Date:   Tue Sep 19 17:07:34 2023 +0000

    panic: Mark emergency section in oops

    Mark an emergency section beginning with oops_enter() until the
    end of oops_exit(). In this section, the CPU will not perform
    console output for the printk() calls. Instead, a flushing of the
    console output will triggered when exiting the emergency section.

    The very end of oops_exit() performs a kmsg_dump(). This is not
    included in the emergency section because it is another
    flushing mechanism that should occur after the consoles have
    been triggered to flush.

    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 e6d32cfcc3 panic: Mark emergency section in warn
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 0e5b7f4158427c921223eb338bd8cdeb7e6f94ba
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Sep 11 15:53:04 2023 +0000

    panic: Mark emergency section in warn

    Mark the full contents of __warn() as an emergency section. In
    this section, the CPU will not perform console output for the
    printk() calls. Instead, a flushing of the console output will
    triggered when exiting the emergency section.

    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 ffd7d74753 printk: Coordinate direct printing 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 da1ef01e278544e6f355dc67afbb8b297ebfcf35
Author: John Ogness <john.ogness@linutronix.de>
Date:   Wed Nov 22 11:56:58 2023 +0000

    printk: Coordinate direct printing in panic

    Perform printing by nbcon consoles on the panic CPU from the
    printk() caller context in order to get panic messages printed
    as soon as possible.

    If legacy and nbcon consoles are registered, the legacy consoles
    will no longer perform direct printing on the panic CPU until
    after the backtrace has been stored. This will give the safe
    nbcon consoles a chance to print the panic messages before
    allowing the unsafe legacy consoles to print.

    If no nbcon consoles are registered, there is no change in
    behavior (i.e. legacy consoles will always attempt to print
    from 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 1b6d7aba50 printk: nbcon: Add unsafe flushing on 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 56ceb90cac5939a9e30555e91c08a1a1dcf6ddae
Author: John Ogness <john.ogness@linutronix.de>
Date:   Fri Oct 20 10:03:42 2023 +0000

    printk: nbcon: Add unsafe flushing on panic

    Add nbcon_atomic_flush_unsafe() to flush all nbcon consoles
    using the write_atomic() callback and allowing unsafe hostile
    takeovers. Call this at the end of panic() as a final attempt
    to flush any pending messages.

    Note that legacy consoles use unsafe methods for flushing
    from the beginning of panic (see bust_spinlocks()). Therefore,
    systems using both legacy and nbcon consoles may still fail to
    see panic messages due to unsafe legacy console usage.

    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 5277972bb0 panic: Flush kernel log buffer at the end
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 db621f13961fb858c2545305b62a569ccf95314e
Author: John Ogness <john.ogness@linutronix.de>
Date:   Thu Dec 14 20:48:23 2023 +0000

    panic: Flush kernel log buffer at the end

    If the kernel crashes in a context where printk() calls always
    defer printing (such as in NMI or inside a printk_safe section)
    then the final panic messages will be deferred to irq_work. But
    if irq_work is not available, the messages will not get printed
    unless explicitly flushed. The result is that the final
    "end Kernel panic" banner does not get printed.

    Add one final flush after the last printk() call to make sure
    the final panic messages make it out as well.

    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:24 -04:00
Andrew Halaney a49daa232b panic: Reenable preemption in WARN slowpath
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit cccd32816506cbac3a4c65d9dff51b3125ef1a03
Author: Lukas Wunner <lukas@wunner.de>
Date:   Fri Sep 15 09:55:39 2023 +0200

    panic: Reenable preemption in WARN slowpath

    Commit:

      5a5d7e9badd2 ("cpuidle: lib/bug: Disable rcu_is_watching() during WARN/BUG")

    amended warn_slowpath_fmt() to disable preemption until the WARN splat
    has been emitted.

    However the commit neglected to reenable preemption in the !fmt codepath,
    i.e. when a WARN splat is emitted without additional format string.

    One consequence is that users may see more splats than intended.  E.g. a
    WARN splat emitted in a work item results in at least two extra splats:

      BUG: workqueue leaked lock or atomic
      (emitted by process_one_work())

      BUG: scheduling while atomic
      (emitted by worker_thread() -> schedule())

    Ironically the point of the commit was to *avoid* extra splats. ;)

    Fix it.

    Fixes: 5a5d7e9badd2 ("cpuidle: lib/bug: Disable rcu_is_watching() during WARN/BUG")
    Signed-off-by: Lukas Wunner <lukas@wunner.de>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Paul E. McKenney <paulmck@kernel.org>
    Link: https://lore.kernel.org/r/3ec48fde01e4ee6505f77908ba351bad200ae3d1.1694763684.git.lukas@wunner.de

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:22 -04:00
Andrew Halaney df181c3518 panic: hide unused global functions
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit 525bb813a995283bef759659cfc00f3fc2d51e81
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Wed May 17 15:10:55 2023 +0200

    panic: hide unused global functions

    Building with W=1 shows warnings about two functions that have no
    declaration or caller in certain configurations:

    kernel/panic.c:688:6: error: no previous prototype for 'warn_slowpath_fmt' [-Werror=missing-prototypes]
    kernel/panic.c:710:6: error: no previous prototype for '__warn_printk' [-Werror=missing-prototypes]

    Enclose the definition in the same #ifdef check as the declaration.

    Link: https://lkml.kernel.org/r/20230517131102.934196-8-arnd@kernel.org
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Cc: Boqun Feng <boqun.feng@gmail.com>
    Cc: Catalin Marinas <catalin.marinas@arm.com>
    Cc: Christoph Lameter <cl@linux.com>
    Cc: Dennis Zhou <dennis@kernel.org>
    Cc: Eric Paris <eparis@redhat.com>
    Cc: Heiko Carstens <hca@linux.ibm.com>
    Cc: Helge Deller <deller@gmx.de>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Michael Ellerman <mpe@ellerman.id.au>
    Cc: Michal Simek <monstr@monstr.eu>
    Cc: Palmer Dabbelt <palmer@dabbelt.com>
    Cc: Paul Moore <paul@paul-moore.com>
    Cc: Pavel Machek <pavel@ucw.cz>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Rafael J. Wysocki <rafael@kernel.org>
    Cc: Russell King <linux@armlinux.org.uk>
    Cc: Tejun Heo <tj@kernel.org>
    Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Waiman Long <longman@redhat.com>
    Cc: Will Deacon <will@kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:21 -04:00
Andrew Halaney 79419fe986 panic: fix the panic_print NMI backtrace setting
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit b905039e428d639adeebb719b76f98865ea38d4d
Author: Guilherme G. Piccoli <gpiccoli@igalia.com>
Date:   Sun Feb 26 13:08:38 2023 -0300

    panic: fix the panic_print NMI backtrace setting

    Commit 8d470a45d1a6 ("panic: add option to dump all CPUs backtraces in
    panic_print") introduced a setting for the "panic_print" kernel parameter
    to allow users to request a NMI backtrace on panic.  Problem is that the
    panic_print handling happens after the secondary CPUs are already
    disabled, hence this option ended-up being kind of a no-op - kernel skips
    the NMI trace in idling CPUs, which is the case of offline CPUs.

    Fix it by checking the NMI backtrace bit in the panic_print prior to the
    CPU disabling function.

    Link: https://lkml.kernel.org/r/20230226160838.414257-1-gpiccoli@igalia.com
    Fixes: 8d470a45d1a6 ("panic: add option to dump all CPUs backtraces in panic_print")
    Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
    Cc: <stable@vger.kernel.org>
    Cc: Baoquan He <bhe@redhat.com>
    Cc: Dave Young <dyoung@redhat.com>
    Cc: Feng Tang <feng.tang@intel.com>
    Cc: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
    Cc: Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>
    Cc: Kees Cook <keescook@chromium.org>
    Cc: Michael Kelley <mikelley@microsoft.com>
    Cc: Petr Mladek <pmladek@suse.com>
    Cc: Vivek Goyal <vgoyal@redhat.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:20 -04:00
Andrew Halaney 9a9a0dae51 exit: Use READ_ONCE() for all oops/warn limit reads
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit 7535b832c6399b5ebfc5b53af5c51dd915ee2538
Author: Kees Cook <keescook@chromium.org>
Date:   Fri Dec 16 12:26:57 2022 -0800

    exit: Use READ_ONCE() for all oops/warn limit reads

    Use a temporary variable to take full advantage of READ_ONCE() behavior.
    Without this, the report (and even the test) might be out of sync with
    the initial test.

    Reported-by: Peter Zijlstra <peterz@infradead.org>
    Link: https://lore.kernel.org/lkml/Y5x7GXeluFmZ8E0E@hirez.programming.kicks-ass.net
    Fixes: 9fc9e278a5c0 ("panic: Introduce warn_limit")
    Fixes: d4ccd54d28d3 ("exit: Put an upper limit on how often we can oops")
    Cc: "Eric W. Biederman" <ebiederm@xmission.com>
    Cc: Jann Horn <jannh@google.com>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Petr Mladek <pmladek@suse.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Luis Chamberlain <mcgrof@kernel.org>
    Cc: Marco Elver <elver@google.com>
    Cc: tangmeng <tangmeng@uniontech.com>
    Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
    Signed-off-by: Kees Cook <keescook@chromium.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:19 -04:00
Andrew Halaney 74852e1c95 panic: use str_enabled_disabled() helper
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit 5d5dd3e4a86a64cc69fa0fdd32f769b1d97a9a83
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Sat Oct 8 22:59:14 2022 +0300

    panic: use str_enabled_disabled() helper

    Use str_enabled_disabled() helper instead of open coding the same.

    Link: https://lkml.kernel.org/r/20221008195914.54199-1-andriy.shevchenko@linux.intel.com
    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:19 -04:00
Andrew Halaney a16b4e5e01 panic: move panic_print before kmsg dumpers
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit f953f140f318a641c443b0b8c618155ed90a7a10
Author: Guilherme G. Piccoli <gpiccoli@igalia.com>
Date:   Wed Mar 23 16:07:09 2022 -0700

    panic: move panic_print before kmsg dumpers

    The panic_print setting allows users to collect more information in a
    panic event, like memory stats, tasks, CPUs backtraces, etc.  This is an
    interesting debug mechanism, but currently the print event happens *after*
    kmsg_dump(), meaning that pstore, for example, cannot collect a dmesg with
    the panic_print extra information.

    This patch changes that in 2 steps:

    (a) The panic_print setting allows to replay the existing kernel log
        buffer to the console (bit 5), besides the extra information dump.
        This functionality makes sense only at the end of the panic()
        function.  So, we hereby allow to distinguish the two situations by a
        new boolean parameter in the function panic_print_sys_info().

    (b) With the above change, we can safely call panic_print_sys_info()
        before kmsg_dump(), allowing to dump the extra information when using
        pstore or other kmsg dumpers.

    The additional messages from panic_print could overwrite the oldest
    messages when the buffer is full.  The only reasonable solution is to use
    a large enough log buffer, hence we added an advice into the kernel
    parameters documentation about that.

    Link: https://lkml.kernel.org/r/20220214141308.841525-1-gpiccoli@igalia.com
    Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
    Acked-by: Baoquan He <bhe@redhat.com>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
    Cc: Feng Tang <feng.tang@intel.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:19 -04:00
Andrew Halaney 61e1511392 panic: add option to dump all CPUs backtraces in panic_print
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit 8d470a45d1a65e6a308aeee5da7f5b37d3303c04
Author: Guilherme G. Piccoli <gpiccoli@igalia.com>
Date:   Wed Mar 23 16:07:06 2022 -0700

    panic: add option to dump all CPUs backtraces in panic_print

    Currently the "panic_print" parameter/sysctl allows some interesting debug
    information to be printed during a panic event.  This is useful for
    example in cases the user cannot kdump due to resource limits, or if the
    user collects panic logs in a serial output (or pstore) and prefers a fast
    reboot instead of a kdump.

    Happens that currently there's no way to see all CPUs backtraces in a
    panic using "panic_print" on architectures that support that.  We do have
    "oops_all_cpu_backtrace" sysctl, but although partially overlapping in the
    functionality, they are orthogonal in nature: "panic_print" is a panic
    tuning (and we have panics without oopses, like direct calls to panic() or
    maybe other paths that don't go through oops_enter() function), and the
    original purpose of "oops_all_cpu_backtrace" is to provide more
    information on oopses for cases in which the users desire to continue
    running the kernel even after an oops, i.e., used in non-panic scenarios.

    So, we hereby introduce an additional bit for "panic_print" to allow
    dumping the CPUs backtraces during a panic event.

    Link: https://lkml.kernel.org/r/20211109202848.610874-3-gpiccoli@igalia.com
    Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
    Reviewed-by: Feng Tang <feng.tang@intel.com>
    Cc: Iurii Zaikin <yzaikin@google.com>
    Cc: Kees Cook <keescook@chromium.org>
    Cc: Luis Chamberlain <mcgrof@kernel.org>
    Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:19 -04:00
Andrew Halaney 5bc772d99f panic: remove oops_id
JIRA: https://issues.redhat.com/browse/RHEL-3987

commit e83a4472bf9f556d01984048e398e64246c4dd6f
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date:   Wed Jan 19 18:09:59 2022 -0800

    panic: remove oops_id

    The oops id has been added as part of the end of trace marker for the
    kerneloops.org project.  The id is used to automatically identify
    duplicate submissions of the same report.  Identical looking reports
    with different a id can be considered as the same oops occurred again.

    The early initialisation of the oops_id can create a warning if the
    random core is not yet fully initialized.  On PREEMPT_RT it is
    problematic if the id is initialized on demand from non preemptible
    context.

    The kernel oops project is not available since 2017.  Remove the oops_id
    and use 0 in the output in case parser rely on it.

    Link: https://bugs.debian.org/953172
    Link: https://lkml.kernel.org/r/Ybdi16aP2NEugWHq@linutronix.de
    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Cc: Arjan van de Ven <arjan@linux.intel.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:18 -04:00
Andrew Halaney f5a6422002 panic: use error_report_end tracepoint on warnings
JIRA: https://issues.redhat.com/browse/RHEL-3987
Conflicts: Context diff due to cs9's
           33208366c8 ("cpuidle: lib/bug: Disable rcu_is_watching() during WARN/BUG")

commit 23b36fec7e14f8cf1c17e832e53dd4761e0dfe83
Author: Marco Elver <elver@google.com>
Date:   Wed Jan 19 18:09:56 2022 -0800

    panic: use error_report_end tracepoint on warnings

    Introduce the error detector "warning" to the error_report event and use
    the error_report_end tracepoint at the end of a warning report.

    This allows in-kernel tests but also userspace to more easily determine
    if a warning occurred without polling kernel logs.

    [akpm@linux-foundation.org: add comma to enum list, per Andy]

    Link: https://lkml.kernel.org/r/20211115085630.1756817-1-elver@google.com
    Signed-off-by: Marco Elver <elver@google.com>
    Cc: Steven Rostedt <rostedt@goodmis.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Alexander Potapenko <glider@google.com>
    Cc: Petr Mladek <pmladek@suse.com>
    Cc: Luis Chamberlain <mcgrof@kernel.org>
    Cc: Wei Liu <wei.liu@kernel.org>
    Cc: Mike Rapoport <rppt@kernel.org>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: John Ogness <john.ogness@linutronix.de>
    Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Cc: Alexander Popov <alex.popov@linux.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:26:18 -04:00
Andrew Halaney 292a64606b kernel/panic: Drop unblank_screen call
JIRA: https://issues.redhat.com/browse/RHEL-24205

commit 0a64ce6e5442bbd96cbe9057d9ba1edab244f25b
Author: Daniel Vetter <daniel.vetter@ffwll.ch>
Date:   Tue Aug 30 16:50:04 2022 +0200

    kernel/panic: Drop unblank_screen call

    console_unblank() does this too (called in both places right after),
    and with a lot more confidence inspiring approach to locking.

    Reconstructing this story is very strange:

    In b61312d353 ("oops handling: ensure that any oops is flushed to
    the mtdoops console") it is claimed that a printk(" "); flushed out
    the console buffer, which was removed in e3e8a75d2a ("[PATCH]
    Extract and use wake_up_klogd()"). In todays kernels this is done way
    earlier in console_flush_on_panic with some really nasty tricks. I
    didn't bother to fully reconstruct this all, least because the call to
    bust_spinlock(0); gets moved every few years, depending upon how the
    wind blows (or well, who screamed loudest about the various issue each
    call site caused).

    Before that commit the only calls to console_unblank() where in s390
    arch code.

    The other side here is the console->unblank callback, which was
    introduced in 2.1.31 for the vt driver. Which predates the
    console_unblank() function by a lot, which was added (without users)
    in 2.4.14.3. So pretty much impossible to guess at any motivation
    here. Also afaict the vt driver is the only (and always was the only)
    console driver implementing the unblank callback, so no idea why a
    call to console_unblank() was added for the mtdooops driver - the
    action actually flushing out the console buffers is done from
    console_unlock() only.

    Note that as prep for the s390 users the locking was adjusted in
    2.5.22 (I couldn't figure out how to properly reference the BK commit
    from the historical git trees) from a normal semaphore to a trylock.

    Note that a copy of the direct unblank_screen() call was added to
    panic() in c7c3f05e34 ("panic: avoid deadlocks in re-entrant console
    drivers"), which partially inlined the bust_spinlocks(0); call.

    Long story short, I have no idea why the direct call to unblank_screen
    survived for so long (the infrastructure to do it properly existed for
    years), nor why it wasn't removed when the console_unblank() call was
    finally added. But it makes a ton more sense to finally do that than
    not - it's just better encapsulation to go through the console
    functions instead of doing a direct call, so let's dare. Plus it
    really does not make much sense to call the only unblank
    implementation there is twice, once without, and once with appropriate
    locking.

    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Jiri Slaby <jirislaby@kernel.org>
    Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
    Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
    Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
    Cc: Xuezhi Zhang <zhangxuezhi1@coolpad.com>
    Cc: Yangxi Xiang <xyangxi5@gmail.com>
    Cc: nick black <dankamongmen@gmail.com>
    Cc: Petr Mladek <pmladek@suse.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Luis Chamberlain <mcgrof@kernel.org>
    Cc: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
    Cc: Marco Elver <elver@google.com>
    Cc: John Ogness <john.ogness@linutronix.de>
    Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Cc: David Gow <davidgow@google.com>
    Cc: tangmeng <tangmeng@uniontech.com>
    Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
    Cc: Chris Wilson <chris@chris-wilson.co.uk>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Link: https://lore.kernel.org/r/20220830145004.430545-1-daniel.vetter@ffwll.ch
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-09 11:25:06 -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
Andrew Halaney 202bd0d0d2 Revert "printk: add infrastucture for atomic consoles"
JIRA: https://issues.redhat.com/browse/RHEL-24205
Upstream Status: RHEL only
Conflicts:
	kernel/panic.c

This reverts commit 053f15e112.

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:23:16 -04:00
Audra Mitchell 3b441176d7 panic: Expose "warn_count" to sysfs
JIRA: https://issues.redhat.com/browse/RHEL-27739
Conflicts:
    Dropping chunk in MAINTAINERS file as we do not maintain this file.
    Minor context difference in kernel/panic.c due to out of order backport of
    33208366c8 ("cpuidle: lib/bug: Disable rcu_is_watching() during WARN/BUG")
    And missing patch:
    23b36fec7e14 ("panic: use error_report_end tracepoint on warnings")

This patch is a backport of the following upstream commit:
commit 8b05aa26336113c4cea25f1c333ee8cd4fc212a6
Author: Kees Cook <keescook@chromium.org>
Date:   Thu Nov 17 15:43:26 2022 -0800

    panic: Expose "warn_count" to sysfs

    Since Warn count is now tracked and is a fairly interesting signal, add
    the entry /sys/kernel/warn_count to expose it to userspace.

    Cc: Petr Mladek <pmladek@suse.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: tangmeng <tangmeng@uniontech.com>
    Cc: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
    Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
    Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Link: https://lore.kernel.org/r/20221117234328.594699-6-keescook@chromium.org

Signed-off-by: Audra Mitchell <audra@redhat.com>
2024-04-09 09:43:00 -04:00
Audra Mitchell dd703babed panic: Introduce warn_limit
JIRA: https://issues.redhat.com/browse/RHEL-27739

This patch is a backport of the following upstream commit:
commit 9fc9e278a5c0b708eeffaf47d6eb0c82aa74ed78
Author: Kees Cook <keescook@chromium.org>
Date:   Thu Nov 17 15:43:25 2022 -0800

    panic: Introduce warn_limit

    Like oops_limit, add warn_limit for limiting the number of warnings when
    panic_on_warn is not set.

    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
    Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
    Cc: Eric Biggers <ebiggers@google.com>
    Cc: Huang Ying <ying.huang@intel.com>
    Cc: Petr Mladek <pmladek@suse.com>
    Cc: tangmeng <tangmeng@uniontech.com>
    Cc: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
    Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
    Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Cc: linux-doc@vger.kernel.org
    Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Link: https://lore.kernel.org/r/20221117234328.594699-5-keescook@chromium.org

Signed-off-by: Audra Mitchell <audra@redhat.com>
2024-04-09 09:43:00 -04:00
Audra Mitchell 21ede44837 panic: Separate sysctl logic from CONFIG_SMP
JIRA: https://issues.redhat.com/browse/RHEL-27739

This patch is a backport of the following upstream commit:
commit 9360d035a579d95d1e76c471061b9065b18a0eb1
Author: Kees Cook <keescook@chromium.org>
Date:   Thu Nov 17 15:43:21 2022 -0800

    panic: Separate sysctl logic from CONFIG_SMP

    In preparation for adding more sysctls directly in kernel/panic.c, split
    CONFIG_SMP from the logic that adds sysctls.

    Cc: Petr Mladek <pmladek@suse.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: tangmeng <tangmeng@uniontech.com>
    Cc: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
    Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
    Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Link: https://lore.kernel.org/r/20221117234328.594699-1-keescook@chromium.org

Signed-off-by: Audra Mitchell <audra@redhat.com>
2024-04-09 09:43:00 -04:00
Audra Mitchell 5523d221b3 kernel/panic: move panic sysctls to its own file
JIRA: https://issues.redhat.com/browse/RHEL-27739

This patch is a backport of the following upstream commit:
commit 9df918698408fd914493aba0b7858fef50eba63a
Author: tangmeng <tangmeng@uniontech.com>
Date:   Fri Feb 18 18:59:12 2022 +0800

    kernel/panic: move panic sysctls to its own file

    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.

    All filesystem syctls now get reviewed by fs folks. This commit
    follows the commit of fs, move the oops_all_cpu_backtrace sysctl to
    its own file, kernel/panic.c.

    Signed-off-by: tangmeng <tangmeng@uniontech.com>
    Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

Signed-off-by: Audra Mitchell <audra@redhat.com>
2024-04-09 09:43:00 -04:00
Audra Mitchell 0f85367c44 panic: Consolidate open-coded panic_on_warn checks
JIRA: https://issues.redhat.com/browse/RHEL-27739

This patch is a backport of the following upstream commit:
commit 79cc1ba7badf9e7a12af99695a557e9ce27ee967
Author: Kees Cook <keescook@chromium.org>
Date:   Thu Nov 17 15:43:24 2022 -0800

    panic: Consolidate open-coded panic_on_warn checks

    Several run-time checkers (KASAN, UBSAN, KFENCE, KCSAN, sched) roll
    their own warnings, and each check "panic_on_warn". Consolidate this
    into a single function so that future instrumentation can be added in
    a single location.

    Cc: Marco Elver <elver@google.com>
    Cc: Dmitry Vyukov <dvyukov@google.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Juri Lelli <juri.lelli@redhat.com>
    Cc: Vincent Guittot <vincent.guittot@linaro.org>
    Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
    Cc: Steven Rostedt <rostedt@goodmis.org>
    Cc: Ben Segall <bsegall@google.com>
    Cc: Mel Gorman <mgorman@suse.de>
    Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
    Cc: Valentin Schneider <vschneid@redhat.com>
    Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
    Cc: Alexander Potapenko <glider@google.com>
    Cc: Andrey Konovalov <andreyknvl@gmail.com>
    Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: David Gow <davidgow@google.com>
    Cc: tangmeng <tangmeng@uniontech.com>
    Cc: Jann Horn <jannh@google.com>
    Cc: Shuah Khan <skhan@linuxfoundation.org>
    Cc: Petr Mladek <pmladek@suse.com>
    Cc: "Paul E. McKenney" <paulmck@kernel.org>
    Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Cc: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
    Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
    Cc: kasan-dev@googlegroups.com
    Cc: linux-mm@kvack.org
    Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Reviewed-by: Marco Elver <elver@google.com>
    Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
    Link: https://lore.kernel.org/r/20221117234328.594699-4-keescook@chromium.org

Signed-off-by: Audra Mitchell <audra@redhat.com>
2024-04-09 09:43:00 -04:00
Prarit Bhargava 6e1d2f48c1 cpu: Mark nmi_panic_self_stop() __noreturn
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflicts: Minor drift issues.

commit 27dea14c7f05106f39850a9239874cd38703b405
Author: Josh Poimboeuf <jpoimboe@kernel.org>
Date:   Wed Apr 12 16:49:36 2023 -0700

    cpu: Mark nmi_panic_self_stop() __noreturn

    In preparation for improving objtool's handling of weak noreturn
    functions, mark nmi_panic_self_stop() __noreturn.

    Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/316fc6dfab5a8c4e024c7185484a1ee5fb0afb79.1681342859.git.jpoimboe@kernel.org

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:02 -04:00
Prarit Bhargava 3fc130ee28 cpu: Mark panic_smp_self_stop() __noreturn
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 7412a60decec2a6744cf773280ff17a0f89e8395
Author: Josh Poimboeuf <jpoimboe@kernel.org>
Date:   Wed Apr 12 16:49:35 2023 -0700

    cpu: Mark panic_smp_self_stop() __noreturn

    In preparation for improving objtool's handling of weak noreturn
    functions, mark panic_smp_self_stop() __noreturn.

    Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/92d76ab5c8bf660f04fdcd3da1084519212de248.1681342859.git.jpoimboe@kernel.org

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:02 -04:00
Prarit Bhargava fdf0296fbf randstruct: Reorganize Kconfigs and attribute macros
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflicts: Minor drift in deleted Kconfig

commit 595b893e2087de306d0781795fb8ec47873596a6
Author: Kees Cook <keescook@chromium.org>
Date:   Tue May 3 13:55:00 2022 -0700

    randstruct: Reorganize Kconfigs and attribute macros

    In preparation for Clang supporting randstruct, reorganize the Kconfigs,
    move the attribute macros, and generalize the feature to be named
    CONFIG_RANDSTRUCT for on/off, CONFIG_RANDSTRUCT_FULL for the full
    randomization mode, and CONFIG_RANDSTRUCT_PERFORMANCE for the cache-line
    sized mode.

    Cc: linux-hardening@vger.kernel.org
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Link: https://lore.kernel.org/r/20220503205503.3054173-4-keescook@chromium.org

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:42:34 -04:00
Derek Barbosa 065095b23d kernel/panic.c: Move the location of bust_spinlocks to prevent hanging.
JIRA: https://issues.redhat.com/browse/RHEL-15897
Upstream Status: RHEL-Only

Moving bust_spinlocks() closer to pr_emerge in the panic() function
(specifically prior to flushing the consoles) addresses the
issue of the kernel hanging while printing out a call trace during a
panic.

Signed-off-by: Derek Barbosa <debarbos@redhat.com>
2023-12-11 11:03:23 -05:00
Chris von Recklinghausen f31f1f2fd0 panic: unset panic_on_warn inside panic()
JIRA: https://issues.redhat.com/browse/RHEL-1848

commit 1a2383e8b84c0451fd9b1eec3b9aab16f30b597c
Author: Tiezhu Yang <yangtiezhu@loongson.cn>
Date:   Wed Mar 23 16:06:51 2022 -0700

    panic: unset panic_on_warn inside panic()

    In the current code, the following three places need to unset
    panic_on_warn before calling panic() to avoid recursive panics:

    kernel/kcsan/report.c: print_report()
    kernel/sched/core.c: __schedule_bug()
    mm/kfence/report.c: kfence_report_error()

    In order to avoid copy-pasting "panic_on_warn = 0" all over the places,
    it is better to move it inside panic() and then remove it from the other
    places.

    Link: https://lkml.kernel.org/r/1644324666-15947-4-git-send-email-yangtiezhu@loongson.cn
    Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
    Reviewed-by: Marco Elver <elver@google.com>
    Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
    Cc: Baoquan He <bhe@redhat.com>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Xuefeng Li <lixuefeng@loongson.cn>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
2023-10-20 06:12:37 -04:00
Nico Pache da77c4d524 panic: Taint kernel if tests are run
Conflicts: Utilize one of the reserved tainted for the new type
       include/linux/panic.h
       kernel/panic.c

commit 2852ca7fba9f77b204f0fe953b31fadd0057c936
Author: David Gow <davidgow@google.com>
Date:   Fri Jul 1 16:47:41 2022 +0800

    panic: Taint kernel if tests are run

    Most in-kernel tests (such as KUnit tests) are not supposed to run on
    production systems: they may do deliberately illegal things to trigger
    errors, and have security implications (for example, KUnit assertions
    will often deliberately leak kernel addresses).

    Add a new taint type, TAINT_TEST to signal that a test has been run.
    This will be printed as 'N' (originally for kuNit, as every other
    sensible letter was taken.)

    This should discourage people from running these tests on production
    systems, and to make it easier to tell if tests have been run
    accidentally (by loading the wrong configuration, etc.)

    Acked-by: Luis Chamberlain <mcgrof@kernel.org>
    Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
    Signed-off-by: David Gow <davidgow@google.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2168378
Signed-off-by: Nico Pache <npache@redhat.com>
2023-04-17 11:47:36 -06:00
Waiman Long 33208366c8 cpuidle: lib/bug: Disable rcu_is_watching() during WARN/BUG
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2169516
Conflicts: A merge conflict in adding include file
	   <linux/context_tracking.h> to kernel/panic.c due to missing
	   upstream commit 23b36fec7e14 ("panic: use error_report_end
	   tracepoint on warnings") and commit 8b05aa263361 ("panic:
	   Expose "warn_count" to sysfs").

commit 5a5d7e9badd2cb8065db171961bd30bd3595e4b6
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Thu, 26 Jan 2023 16:08:31 +0100

    cpuidle: lib/bug: Disable rcu_is_watching() during WARN/BUG

    In order to avoid WARN/BUG from generating nested or even recursive
    warnings, force rcu_is_watching() true during
    WARN/lockdep_rcu_suspicious().

    Notably things like unwinding the stack can trigger rcu_dereference()
    warnings, which then triggers more unwinding which then triggers more
    warnings etc..

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/r/20230126151323.408156109@infradead.org

Signed-off-by: Waiman Long <longman@redhat.com>
2023-03-30 08:48:17 -04:00
Juri Lelli 053f15e112 printk: add infrastucture for atomic consoles
Bugzilla: https://bugzilla.redhat.com/2171995
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git

commit 2fb6932cc839ab486cd873c920402b83b79c3284
Author:    John Ogness <john.ogness@linutronix.de>
Date:      Fri Feb 4 16:01:17 2022 +0106

    printk: add infrastucture for atomic consoles

    Many times it is not possible to see the console output on
    panic because printing threads cannot be scheduled and/or the
    console is already taken and forcibly overtaking/busting the
    locks does provide the hoped results.

    Introduce a new infrastructure to support "atomic consoles".
    A new optional callback in struct console, write_atomic(), is
    available for consoles to provide an implemention for writing
    console messages. The implementation must be NMI safe if they
    can run on an architecture where NMIs exist.

    Console drivers implementing the write_atomic() callback must
    also select CONFIG_HAVE_ATOMIC_CONSOLE in order to enable the
    atomic console code within the printk subsystem.

    If atomic consoles are available, panic() will flush the kernel
    log only to the atomic consoles (before busting spinlocks).
    Afterwards, panic() will continue  as before, which includes
    attempting to flush the other (non-atomic) consoles.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    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
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
Alice Mitchell 9d2f3e527d Add taint flag for partner supported GPL modules
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2038999
Upstream Status: RHEL-only

Signed-off-by: Alice Mitchell <ajmitchell@redhat.com>
2023-01-20 14:07:53 +00: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
Tomas Henzl 8a9bf88e9d kernel: add SUPPORT_REMOVED kernel taint
Message-id: <e9a9812a-6a4c-a205-e66a-1d47de58306a@redhat.com>
Patchwork-id: 226423
O-Subject: [RHEL-8.0 V4 01/10] kernel: add SUPPORT_REMOVED kernel taint
Bugzilla: 1602033
RH-Acked-by: Maurizio Lombardi <mlombard@redhat.com>
RH-Acked-by: Jiri Benc <jbenc@redhat.com>
RH-Acked-by: Rob Evers <revers@redhat.com>

Upstream Status: RHEL only

rh_taint, pci : add information about removed hardware

Upstream Status: RHEL only
Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2021-08-30 14:29:36 -04:00
Eugene Syromiatnikov 9ce398ab77 bpf: set unprivileged_bpf_disabled to 1 by default, add a boot parameter
Message-id: <133022c6c389ca16060bd20ef69199de0800200b.1528991396.git.esyr@redhat.com>
Patchwork-id: 8250
O-Subject: [kernel team] [RHEL8 PATCH v4 2/5] [bpf] bpf: set unprivileged_bpf_disabled to 1 by default, add a boot parameter
Bugzilla: 1561171
RH-Acked-by: Jiri Benc <jbenc@redhat.com>
RH-Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>

This patch sets kernel.unprivileged_bpf_disabled sysctl knob to 1
by default, and provides an ability (in a form of a boot-time parameter)
to reset it to 0, as it is impossible to do so in runtime.  Since
unprivileged BPF is considered unsupported, it also taints the kernel.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1561171
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=16716594
Upstream: RHEL only.  The patch (in a more generic form) has been
          proposed upstream[1] and subsequently rejected.

[1] https://lkml.org/lkml/2018/5/21/344

Upstream Status: RHEL only
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2021-08-30 14:29:35 -04:00
Eugene Syromiatnikov d3c11e8d59 add Red Hat-specific taint flags
Message-id: <56f71e5f8cf63afd0cdb1c4550c625cc90d59a75.1528991395.git.esyr@redhat.com>
Patchwork-id: 8249
O-Subject: [kernel team] [RHEL8 PATCH v4 1/5] kernel: add Red Hat-specific taint flags
Bugzilla: 1559877
RH-Acked-by: Jiri Benc <jbenc@redhat.com>
RH-Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>

Based on RHEL 7 commit "Backport RH specific TAINT flags" by Prarit
Bhargava.

Upstream Status: RHEL only
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1559877
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=16716594
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2021-08-30 14:29:34 -04:00
Andy Shevchenko f39650de68 kernel.h: split out panic and oops helpers
kernel.h is being used as a dump for all kinds of stuff for a long time.
Here is the attempt to start cleaning it up by splitting out panic and
oops helpers.

There are several purposes of doing this:
- dropping dependency in bug.h
- dropping a loop by moving out panic_notifier.h
- unload kernel.h from something which has its own domain

At the same time convert users tree-wide to use new headers, although for
the time being include new header back to kernel.h to avoid twisted
indirected includes for existing users.

[akpm@linux-foundation.org: thread_info.h needs limits.h]
[andriy.shevchenko@linux.intel.com: ia64 fix]
  Link: https://lkml.kernel.org/r/20210520130557.55277-1-andriy.shevchenko@linux.intel.com

Link: https://lkml.kernel.org/r/20210511074137.33666-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Co-developed-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Mike Rapoport <rppt@linux.ibm.com>
Acked-by: Corey Minyard <cminyard@mvista.com>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Wei Liu <wei.liu@kernel.org>
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Sebastian Reichel <sre@kernel.org>
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Acked-by: Stephen Boyd <sboyd@kernel.org>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Acked-by: Helge Deller <deller@gmx.de> # parisc
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-07-01 11:06:04 -07:00
Christophe Leroy 2f31ad64a9 panic: don't dump stack twice on warn
Before commit 3f388f2863 ("panic: dump registers on panic_on_warn"),
__warn() was calling show_regs() when regs was not NULL, and show_stack()
otherwise.

After that commit, show_stack() is called regardless of whether
show_regs() has been called or not, leading to duplicated Call Trace:

  ------------[ cut here ]------------
  WARNING: CPU: 0 PID: 1 at arch/powerpc/mm/nohash/8xx.c:186 mmu_mark_initmem_nx+0x24/0x94
  CPU: 0 PID: 1 Comm: swapper Not tainted 5.10.0-rc2-s3k-dev-01375-gf46ec0d3ecbd-dirty #4092
  NIP:  c00128b4 LR: c0010228 CTR: 00000000
  REGS: c9023e40 TRAP: 0700   Not tainted  (5.10.0-rc2-s3k-dev-01375-gf46ec0d3ecbd-dirty)
  MSR:  00029032 <EE,ME,IR,DR,RI>  CR: 24000424  XER: 00000000

  GPR00: c0010228 c9023ef8 c2100000 0074c000 ffffffff 00000000 c2151000 c07b3880
  GPR08: ff000900 0074c000 c8000000 c33b53a8 24000822 00000000 c0003a20 00000000
  GPR16: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  GPR24: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00800000
  NIP [c00128b4] mmu_mark_initmem_nx+0x24/0x94
  LR [c0010228] free_initmem+0x20/0x58
  Call Trace:
    free_initmem+0x20/0x58
    kernel_init+0x1c/0x114
    ret_from_kernel_thread+0x14/0x1c
  Instruction dump:
  7d291850 7d234b78 4e800020 9421ffe0 7c0802a6 bfc10018 3fe0c060 3bff0000
  3fff4080 3bffffff 90010024 57ff0010 <0fe00000> 392001cd 7c3e0b78 953e0008
  CPU: 0 PID: 1 Comm: swapper Not tainted 5.10.0-rc2-s3k-dev-01375-gf46ec0d3ecbd-dirty #4092
  Call Trace:
    __warn+0x8c/0xd8 (unreliable)
    report_bug+0x11c/0x154
    program_check_exception+0x1dc/0x6e0
    ret_from_except_full+0x0/0x4
  --- interrupt: 700 at mmu_mark_initmem_nx+0x24/0x94
      LR = free_initmem+0x20/0x58
    free_initmem+0x20/0x58
    kernel_init+0x1c/0x114
    ret_from_kernel_thread+0x14/0x1c
  ---[ end trace 31702cd2a9570752 ]---

Only call show_stack() when regs is NULL.

Fixes: 3f388f2863 ("panic: dump registers on panic_on_warn")
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Link: https://lkml.kernel.org/r/e8c055458b080707f1bc1a98ff8bea79d0cec445.1604748361.git.christophe.leroy@csgroup.eu
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-11-14 11:26:04 -08:00
Alexey Kardashevskiy 3f388f2863 panic: dump registers on panic_on_warn
Currently we print stack and registers for ordinary warnings but we do not
for panic_on_warn which looks as oversight - panic() will reboot the
machine but won't print registers.

This moves printing of registers and modules earlier.

This does not move the stack dumping as panic() dumps it.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: Douglas Anderson <dianders@chromium.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Rafael Aquini <aquini@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Link: https://lkml.kernel.org/r/20200804095054.68724-1-aik@ozlabs.ru
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-16 11:11:22 -07:00
Yue Hu 63037f7472 panic: make print_oops_end_marker() static
Since print_oops_end_marker() is not used externally, also remove it in
kernel.h at the same time.

Signed-off-by: Yue Hu <huyue2@yulong.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Kees Cook <keescook@chromium.org>
Link: http://lkml.kernel.org/r/20200724011516.12756-1-zbestahu@gmail.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-08-12 10:58:02 -07:00
Tiezhu Yang 79076e1241 kernel/panic.c: make oops_may_print() return bool
The return value of oops_may_print() is true or false, so change its type
to reflect that.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: Xuefeng Li <lixuefeng@loongson.cn>
Link: http://lkml.kernel.org/r/1591103358-32087-1-git-send-email-yangtiezhu@loongson.cn
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-08-12 10:58:01 -07:00
Thomas Gleixner 5916d5f9b3 bug: Annotate WARN/BUG/stackfail as noinstr safe
Warnings, bugs and stack protection fails from noinstr sections, e.g. low
level and early entry code, are likely to be fatal.

Mark them as "safe" to be invoked from noinstr protected code to avoid
annotating all usage sites. Getting the information out is important.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200505134100.376598577@linutronix.de
2020-06-11 15:14:36 +02:00
Guilherme G. Piccoli 60c958d8df panic: add sysctl to dump all CPUs backtraces on oops event
Usually when the kernel reaches an oops condition, it's a point of no
return; in case not enough debug information is available in the kernel
splat, one of the last resorts would be to collect a kernel crash dump
and analyze it.  The problem with this approach is that in order to
collect the dump, a panic is required (to kexec-load the crash kernel).
When in an environment of multiple virtual machines, users may prefer to
try living with the oops, at least until being able to properly shutdown
their VMs / finish their important tasks.

This patch implements a way to collect a bit more debug details when an
oops event is reached, by printing all the CPUs backtraces through the
usage of NMIs (on architectures that support that).  The sysctl added
(and documented) here was called "oops_all_cpu_backtrace", and when set
will (as the name suggests) dump all CPUs backtraces.

Far from ideal, this may be the last option though for users that for
some reason cannot panic on oops.  Most of times oopses are clear enough
to indicate the kernel portion that must be investigated, but in virtual
environments it's possible to observe hypervisor/KVM issues that could
lead to oopses shown in other guests CPUs (like virtual APIC crashes).
This patch hence aims to help debug such complex issues without
resorting to kdump.

Signed-off-by: Guilherme G. Piccoli <gpiccoli@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Iurii Zaikin <yzaikin@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Matthew Wilcox <willy@infradead.org>
Link: http://lkml.kernel.org/r/20200327224116.21030-1-gpiccoli@canonical.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-08 11:05:56 -07:00
Rafael Aquini db38d5c106 kernel: add panic_on_taint
Analogously to the introduction of panic_on_warn, this patch introduces
a kernel option named panic_on_taint in order to provide a simple and
generic way to stop execution and catch a coredump when the kernel gets
tainted by any given flag.

This is useful for debugging sessions as it avoids having to rebuild the
kernel to explicitly add calls to panic() into the code sites that
introduce the taint flags of interest.

For instance, if one is interested in proceeding with a post-mortem
analysis at the point a given code path is hitting a bad page (i.e.
unaccount_page_cache_page(), or slab_bug()), a coredump can be collected
by rebooting the kernel with 'panic_on_taint=0x20' amended to the
command line.

Another, perhaps less frequent, use for this option would be as a means
for assuring a security policy case where only a subset of taints, or no
single taint (in paranoid mode), is allowed for the running system.  The
optional switch 'nousertaint' is handy in this particular scenario, as
it will avoid userspace induced crashes by writes to sysctl interface
/proc/sys/kernel/tainted causing false positive hits for such policies.

[akpm@linux-foundation.org: tweak kernel-parameters.txt wording]

Suggested-by: Qian Cai <cai@lca.pw>
Signed-off-by: Rafael Aquini <aquini@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Cc: Dave Young <dyoung@redhat.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Kees Cook <keescook@chromium.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Adrian Bunk <bunk@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Laura Abbott <labbott@redhat.com>
Cc: Jeff Mahoney <jeffm@suse.com>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: Takashi Iwai <tiwai@suse.de>
Link: http://lkml.kernel.org/r/20200515175502.146720-1-aquini@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-08 11:05:56 -07:00
Will Deacon 2f30b36943 locking/refcount: Remove unused 'refcount_error_report()' function
'refcount_error_report()' has no callers. Remove it.

Signed-off-by: Will Deacon <will@kernel.org>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Kees Cook <keescook@chromium.org>
Tested-by: Hanjun Guo <guohanjun@huawei.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Elena Reshetova <elena.reshetova@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20191121115902.2551-10-will@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2019-11-25 09:15:42 +01:00
Will Deacon 20bb759a66 panic: ensure preemption is disabled during panic()
Calling 'panic()' on a kernel with CONFIG_PREEMPT=y can leave the
calling CPU in an infinite loop, but with interrupts and preemption
enabled.  From this state, userspace can continue to be scheduled,
despite the system being "dead" as far as the kernel is concerned.

This is easily reproducible on arm64 when booting with "nosmp" on the
command line; a couple of shell scripts print out a periodic "Ping"
message whilst another triggers a crash by writing to
/proc/sysrq-trigger:

  | sysrq: Trigger a crash
  | Kernel panic - not syncing: sysrq triggered crash
  | CPU: 0 PID: 1 Comm: init Not tainted 5.2.15 #1
  | Hardware name: linux,dummy-virt (DT)
  | Call trace:
  |  dump_backtrace+0x0/0x148
  |  show_stack+0x14/0x20
  |  dump_stack+0xa0/0xc4
  |  panic+0x140/0x32c
  |  sysrq_handle_reboot+0x0/0x20
  |  __handle_sysrq+0x124/0x190
  |  write_sysrq_trigger+0x64/0x88
  |  proc_reg_write+0x60/0xa8
  |  __vfs_write+0x18/0x40
  |  vfs_write+0xa4/0x1b8
  |  ksys_write+0x64/0xf0
  |  __arm64_sys_write+0x14/0x20
  |  el0_svc_common.constprop.0+0xb0/0x168
  |  el0_svc_handler+0x28/0x78
  |  el0_svc+0x8/0xc
  | Kernel Offset: disabled
  | CPU features: 0x0002,24002004
  | Memory Limit: none
  | ---[ end Kernel panic - not syncing: sysrq triggered crash ]---
  |  Ping 2!
  |  Ping 1!
  |  Ping 1!
  |  Ping 2!

The issue can also be triggered on x86 kernels if CONFIG_SMP=n,
otherwise local interrupts are disabled in 'smp_send_stop()'.

Disable preemption in 'panic()' before re-enabling interrupts.

Link: http://lkml.kernel.org/r/20191002123538.22609-1-will@kernel.org
Link: https://lore.kernel.org/r/BX1W47JXPMR8.58IYW53H6M5N@dragonstone
Signed-off-by: Will Deacon <will@kernel.org>
Reported-by: Xogium <contact@xogium.me>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Feng Tang <feng.tang@intel.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-10-07 15:47:19 -07:00
Kees Cook 2da1ead4d5 bug: consolidate __WARN_FLAGS usage
Instead of having separate tests for __WARN_FLAGS, merge the two #ifdef
blocks and replace the synonym WANT_WARN_ON_SLOWPATH macro.

Link: http://lkml.kernel.org/r/20190819234111.9019-7-keescook@chromium.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Christophe Leroy <christophe.leroy@c-s.fr>
Cc: Drew Davenport <ddavenport@chromium.org>
Cc: Feng Tang <feng.tang@intel.com>
Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Cc: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-09-25 17:51:41 -07:00
Kees Cook d38aba49a9 bug: lift "cut here" out of __warn()
In preparation for cleaning up "cut here", move the "cut here" logic up
out of __warn() and into callers that pass non-NULL args.  For anyone
looking closely, there are two callers that pass NULL args: one already
explicitly prints "cut here".  The remaining case is covered by how a WARN
is built, which will be cleaned up in the next patch.

Link: http://lkml.kernel.org/r/20190819234111.9019-5-keescook@chromium.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Christophe Leroy <christophe.leroy@c-s.fr>
Cc: Drew Davenport <ddavenport@chromium.org>
Cc: Feng Tang <feng.tang@intel.com>
Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Cc: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-09-25 17:51:40 -07:00