05 Jun, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this file is released under the gplv2

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

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

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Armijn Hemel
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190531190114.292346262@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

04 Oct, 2017

1 commit

  • printk_ratelimit() invokes ___ratelimit() which may invoke a normal
    printk() (pr_warn() in this particular case) to warn about suppressed
    output. Given that printk_ratelimit() may be called from anywhere, that
    pr_warn() is dangerous - it may end up deadlocking the system. Fix
    ___ratelimit() by using deferred printk().

    Sasha reported the following lockdep error:

    : Unregister pv shared memory for cpu 8
    : select_fallback_rq: 3 callbacks suppressed
    : process 8583 (trinity-c78) no longer affine to cpu8
    :
    : ======================================================
    : WARNING: possible circular locking dependency detected
    : 4.14.0-rc2-next-20170927+ #252 Not tainted
    : ------------------------------------------------------
    : migration/8/62 is trying to acquire lock:
    : (&port_lock_key){-.-.}, at: serial8250_console_write()
    :
    : but task is already holding lock:
    : (&rq->lock){-.-.}, at: sched_cpu_dying()
    :
    : which lock already depends on the new lock.
    :
    :
    : the existing dependency chain (in reverse order) is:
    :
    : -> #3 (&rq->lock){-.-.}:
    : __lock_acquire()
    : lock_acquire()
    : _raw_spin_lock()
    : task_fork_fair()
    : sched_fork()
    : copy_process.part.31()
    : _do_fork()
    : kernel_thread()
    : rest_init()
    : start_kernel()
    : x86_64_start_reservations()
    : x86_64_start_kernel()
    : verify_cpu()
    :
    : -> #2 (&p->pi_lock){-.-.}:
    : __lock_acquire()
    : lock_acquire()
    : _raw_spin_lock_irqsave()
    : try_to_wake_up()
    : default_wake_function()
    : woken_wake_function()
    : __wake_up_common()
    : __wake_up_common_lock()
    : __wake_up()
    : tty_wakeup()
    : tty_port_default_wakeup()
    : tty_port_tty_wakeup()
    : uart_write_wakeup()
    : serial8250_tx_chars()
    : serial8250_handle_irq.part.25()
    : serial8250_default_handle_irq()
    : serial8250_interrupt()
    : __handle_irq_event_percpu()
    : handle_irq_event_percpu()
    : handle_irq_event()
    : handle_level_irq()
    : handle_irq()
    : do_IRQ()
    : ret_from_intr()
    : native_safe_halt()
    : default_idle()
    : arch_cpu_idle()
    : default_idle_call()
    : do_idle()
    : cpu_startup_entry()
    : rest_init()
    : start_kernel()
    : x86_64_start_reservations()
    : x86_64_start_kernel()
    : verify_cpu()
    :
    : -> #1 (&tty->write_wait){-.-.}:
    : __lock_acquire()
    : lock_acquire()
    : _raw_spin_lock_irqsave()
    : __wake_up_common_lock()
    : __wake_up()
    : tty_wakeup()
    : tty_port_default_wakeup()
    : tty_port_tty_wakeup()
    : uart_write_wakeup()
    : serial8250_tx_chars()
    : serial8250_handle_irq.part.25()
    : serial8250_default_handle_irq()
    : serial8250_interrupt()
    : __handle_irq_event_percpu()
    : handle_irq_event_percpu()
    : handle_irq_event()
    : handle_level_irq()
    : handle_irq()
    : do_IRQ()
    : ret_from_intr()
    : native_safe_halt()
    : default_idle()
    : arch_cpu_idle()
    : default_idle_call()
    : do_idle()
    : cpu_startup_entry()
    : rest_init()
    : start_kernel()
    : x86_64_start_reservations()
    : x86_64_start_kernel()
    : verify_cpu()
    :
    : -> #0 (&port_lock_key){-.-.}:
    : check_prev_add()
    : __lock_acquire()
    : lock_acquire()
    : _raw_spin_lock_irqsave()
    : serial8250_console_write()
    : univ8250_console_write()
    : console_unlock()
    : vprintk_emit()
    : vprintk_default()
    : vprintk_func()
    : printk()
    : ___ratelimit()
    : __printk_ratelimit()
    : select_fallback_rq()
    : sched_cpu_dying()
    : cpuhp_invoke_callback()
    : take_cpu_down()
    : multi_cpu_stop()
    : cpu_stopper_thread()
    : smpboot_thread_fn()
    : kthread()
    : ret_from_fork()
    :
    : other info that might help us debug this:
    :
    : Chain exists of:
    : &port_lock_key --> &p->pi_lock --> &rq->lock
    :
    : Possible unsafe locking scenario:
    :
    : CPU0 CPU1
    : ---- ----
    : lock(&rq->lock);
    : lock(&p->pi_lock);
    : lock(&rq->lock);
    : lock(&port_lock_key);
    :
    : *** DEADLOCK ***
    :
    : 4 locks held by migration/8/62:
    : #0: (&p->pi_lock){-.-.}, at: sched_cpu_dying()
    : #1: (&rq->lock){-.-.}, at: sched_cpu_dying()
    : #2: (printk_ratelimit_state.lock){....}, at: ___ratelimit()
    : #3: (console_lock){+.+.}, at: vprintk_emit()
    :
    : stack backtrace:
    : CPU: 8 PID: 62 Comm: migration/8 Not tainted 4.14.0-rc2-next-20170927+ #252
    : Call Trace:
    : dump_stack()
    : print_circular_bug()
    : check_prev_add()
    : ? add_lock_to_list.isra.26()
    : ? check_usage()
    : ? kvm_clock_read()
    : ? kvm_sched_clock_read()
    : ? sched_clock()
    : ? check_preemption_disabled()
    : __lock_acquire()
    : ? __lock_acquire()
    : ? add_lock_to_list.isra.26()
    : ? debug_check_no_locks_freed()
    : ? memcpy()
    : lock_acquire()
    : ? serial8250_console_write()
    : _raw_spin_lock_irqsave()
    : ? serial8250_console_write()
    : serial8250_console_write()
    : ? serial8250_start_tx()
    : ? lock_acquire()
    : ? memcpy()
    : univ8250_console_write()
    : console_unlock()
    : ? __down_trylock_console_sem()
    : vprintk_emit()
    : vprintk_default()
    : vprintk_func()
    : printk()
    : ? show_regs_print_info()
    : ? lock_acquire()
    : ___ratelimit()
    : __printk_ratelimit()
    : select_fallback_rq()
    : sched_cpu_dying()
    : ? sched_cpu_starting()
    : ? rcutree_dying_cpu()
    : ? sched_cpu_starting()
    : cpuhp_invoke_callback()
    : ? cpu_disable_common()
    : take_cpu_down()
    : ? trace_hardirqs_off_caller()
    : ? cpuhp_invoke_callback()
    : multi_cpu_stop()
    : ? __this_cpu_preempt_check()
    : ? cpu_stop_queue_work()
    : cpu_stopper_thread()
    : ? cpu_stop_create()
    : smpboot_thread_fn()
    : ? sort_range()
    : ? schedule()
    : ? __kthread_parkme()
    : kthread()
    : ? sort_range()
    : ? kthread_create_on_node()
    : ret_from_fork()
    : process 9121 (trinity-c78) no longer affine to cpu8
    : smpboot: CPU 8 is now offline

    Link: http://lkml.kernel.org/r/20170928120405.18273-1-sergey.senozhatsky@gmail.com
    Fixes: 6b1d174b0c27b ("ratelimit: extend to print suppressed messages on release")
    Signed-off-by: Sergey Senozhatsky
    Reported-by: Sasha Levin
    Reviewed-by: Petr Mladek
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Borislav Petkov
    Cc: Steven Rostedt
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sergey Senozhatsky
     

03 Aug, 2016

1 commit

  • Extend the ratelimiting facility to print the amount of suppressed lines
    when it is being released.

    This use case is aimed at short-termed, burst-like users for which we
    want to output the suppressed lines stats only once, after it has been
    disposed of. For an example, see /dev/kmsg usage in a follow-on patch.

    Also, change the printk() line we issue on release to not use
    "callbacks" as it is misleading: we're not suppressing callbacks but
    printk() calls.

    This has been separated from a previous patch by Linus.

    Link: http://lkml.kernel.org/r/20160716061745.15795-2-bp@alien8.de
    Signed-off-by: Borislav Petkov
    Cc: Dave Young
    Cc: Franck Bui
    Cc: Greg Kroah-Hartman
    Cc: Ingo Molnar
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: Uwe Kleine-König
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Borislav Petkov
     

22 Jan, 2016

1 commit

  • rs->begin in ratelimit is set in two cases.
    1) when rs->begin was not initialized
    2) when rs->interval was passed

    For case #2, current ratelimit sets the begin to 0. This incurrs
    improper suppression. The begin value will be set in the next ratelimit
    call by 1). Then the time interval check will be always false, and
    rs->printed will not be initialized. Although enough time passed,
    ratelimit may return 0 if rs->printed is not less than rs->burst. To
    reset interval properly, begin should be jiffies rather than 0.

    For an example code below:

    static DEFINE_RATELIMIT_STATE(mylimit, 1, 1);
    for (i = 1; i
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jaewon Kim
     

08 Mar, 2012

1 commit


13 Sep, 2011

1 commit

  • The logbuf_lock lock can be taken in atomic context and therefore
    cannot be preempted on -rt - annotate it.

    In mainline this change documents the low level nature of
    the lock - otherwise there's no functional difference. Lockdep
    and Sparse checking will work as usual.

    Signed-off-by: Thomas Gleixner
    [ merged and fixed it ]
    Signed-off-by: Ingo Molnar

    Thomas Gleixner
     

07 Apr, 2010

2 commits


23 Oct, 2009

1 commit

  • Today I got:

    [39648.224782] Registered led device: iwl-phy0::TX
    [40676.545099] __ratelimit: 246 callbacks suppressed
    [40676.545103] abcdef[23675]: segfault at 0 ...

    as you can see the ratelimit message contains a function prefix.
    Since this is always __ratelimit, this wont help much.

    This patch changes __ratelimit and printk_ratelimit to print the
    function name that calls ratelimit.

    This will pinpoint the responsible function, as long as not several
    different places call ratelimit with the same ratelimit state at
    the same time. In that case we catch only one random function that
    calls ratelimit after the wait period.

    Signed-off-by: Christian Borntraeger
    Cc: Dave Young
    Cc: Linus Torvalds
    CC: Andrew Morton
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Christian Borntraeger
     

22 Sep, 2009

3 commits

  • Decouple kernel.h from ratelimit.h: the global declaration of
    printk's ratelimit_state is not needed, and it leads to messy
    circular dependencies due to ratelimit.h's (new) adding of a
    spinlock_types.h include.

    Cc: Peter Zijlstra
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: David S. Miller
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • I'd like to use printk_ratelimit() in NMI context, but it's not
    robust right now due to spinlock usage in lib/ratelimit.c. If an
    NMI is unlucky enough to hit just that spot we might lock up trying
    to take the spinlock again.

    Fix that by using a trylock variant. If we contend on that lock we
    can genuinely skip the message because the state is just being
    accessed by another CPU (or by this CPU).

    ( We could use atomics for the suppressed messages field, but
    i doubt it matters in practice and it makes the code heavier. )

    Cc: Peter Zijlstra
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: David S. Miller
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • I'd like to use printk_ratelimit() in atomic context, but that's
    not possible right now due to the spinlock usage this commit
    introduced more than a year ago:

    717115e: printk ratelimiting rewrite

    As a first step push the lock into the ratelimit state structure.
    This allows us to deal with locking failures to be considered as an
    event related to that state being too busy.

    Also clean up the code a bit (without changing functionality):

    - tidy up the definitions

    - clean up the code flow

    This also shrinks the code a tiny bit:

    text data bss dec hex filename
    264 0 4 268 10c ratelimit.o.before
    255 0 0 255 ff ratelimit.o.after

    ( Whole-kernel data size got a bit larger, because we have
    two ratelimit-state data structures right now. )

    Cc: Peter Zijlstra
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: David S. Miller
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Ingo Molnar
     

29 Jul, 2008

1 commit


26 Jul, 2008

1 commit

  • All ratelimit user use same jiffies and burst params, so some messages
    (callbacks) will be lost.

    For example:
    a call printk_ratelimit(5 * HZ, 1)
    b call printk_ratelimit(5 * HZ, 1) before the 5*HZ timeout of a, then b will
    will be supressed.

    - rewrite __ratelimit, and use a ratelimit_state as parameter. Thanks for
    hints from andrew.

    - Add WARN_ON_RATELIMIT, update rcupreempt.h

    - remove __printk_ratelimit

    - use __ratelimit in net_ratelimit

    Signed-off-by: Dave Young
    Cc: "David S. Miller"
    Cc: "Paul E. McKenney"
    Cc: Dave Young
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dave Young
     

29 Apr, 2008

1 commit

  • Due to the rcupreempt.h WARN_ON trigged, I got 2G syslog file. For some
    serious complaining of kernel, we need repeat the warnings, so here I isolate
    the ratelimit part of printk.c to a standalone file.

    Signed-off-by: Dave Young
    Acked-by: Paul E. McKenney
    Tested-by: Paul E. McKenney
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dave Young