lkml.org 
[lkml]   [2022]   [Nov]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH printk v3 18/40] printk: console_flush_on_panic: use srcu console list iterator
    Date
    With SRCU it is now safe to traverse the console list, even if
    the console_trylock() failed. However, overwriting console->seq
    when console_trylock() failed is still an issue.

    Switch to SRCU iteration and document remaining issue with
    console->seq.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    Reviewed-by: Petr Mladek <pmladek@suse.com>
    ---
    kernel/printk/printk.c | 21 +++++++++++----------
    1 file changed, 11 insertions(+), 10 deletions(-)

    diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
    index c3191dc24742..de86a502b50b 100644
    --- a/kernel/printk/printk.c
    +++ b/kernel/printk/printk.c
    @@ -3002,21 +3002,22 @@ void console_flush_on_panic(enum con_flush_mode mode)
    console_may_schedule = 0;

    if (mode == CONSOLE_REPLAY_ALL) {
    - struct hlist_node *tmp;
    struct console *c;
    + int cookie;
    u64 seq;

    seq = prb_first_valid_seq(prb);
    - /*
    - * This cannot use for_each_console() because it's not established
    - * that the current context has console locked and neither there is
    - * a guarantee that there is no concurrency in that case.
    - *
    - * Open code it for documentation purposes and pretend that
    - * it works.
    - */
    - hlist_for_each_entry_safe(c, tmp, &console_list, node)
    +
    + cookie = console_srcu_read_lock();
    + for_each_console_srcu(c) {
    + /*
    + * If the above console_trylock() failed, this is an
    + * unsynchronized assignment. But in that case, the
    + * kernel is in "hope and pray" mode anyway.
    + */
    c->seq = seq;
    + }
    + console_srcu_read_unlock(cookie);
    }
    console_unlock();
    }
    --
    2.30.2
    \
     
     \ /
      Last update: 2022-11-07 15:18    [W:4.148 / U:0.032 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site