08 Sep, 2020

1 commit

  • This kills using the do_each_thread/while_each_thread combo to
    iterate all threads and uses for_each_process_thread() instead,
    maintaining semantics. while_each_thread() is ultimately racy
    and deprecated; although in this particular case there is no
    concurrency so it doesn't matter. Still lets trivially get rid
    of two more users.

    Acked-by: Oleg Nesterov
    Signed-off-by: Davidlohr Bueso
    Link: https://lore.kernel.org/r/20200907203206.21293-1-dave@stgolabs.net
    Signed-off-by: Daniel Thompson

    Davidlohr Bueso
     

10 Jun, 2020

2 commits

  • Now the last users of show_stack() got converted to use an explicit log
    level, show_stack_loglvl() can drop it's redundant suffix and become once
    again well known show_stack().

    Signed-off-by: Dmitry Safonov
    Signed-off-by: Andrew Morton
    Link: http://lkml.kernel.org/r/20200418201944.482088-51-dima@arista.com
    Signed-off-by: Linus Torvalds

    Dmitry Safonov
     
  • Print the stack trace with KERN_EMERG - it should be always visible.

    Playing with console_loglevel is a bad idea as there may be more messages
    printed than wanted. Also the stack trace might be not printed at all if
    printk() was deferred and console_loglevel was raised back before the
    trace got flushed.

    Unfortunately, after rebasing on commit 2277b492582d ("kdb: Fix stack
    crawling on 'running' CPUs that aren't the master"), kdb_show_stack() uses
    now kdb_dump_stack_on_cpu(), which for now won't be converted as it uses
    dump_stack() instead of show_stack().

    Convert for now the branch that uses show_stack() and remove
    console_loglevel exercise from that case.

    Signed-off-by: Dmitry Safonov
    Signed-off-by: Andrew Morton
    Reviewed-by: Douglas Anderson
    Acked-by: Daniel Thompson
    Cc: Jason Wessel
    Link: http://lkml.kernel.org/r/20200418201944.482088-48-dima@arista.com
    Signed-off-by: Linus Torvalds

    Dmitry Safonov
     

01 Feb, 2020

1 commit

  • Some (but not all?) of the kdb backtrace paths would cause the
    kdb_current_task and kdb_current_regs to remain changed. As discussed
    in a review of a previous patch [1], this doesn't seem intuitive, so
    let's fix that.

    ...but, it turns out that there's actually no longer any reason to set
    the current task / current regs while backtracing anymore anyway. As
    of commit 2277b492582d ("kdb: Fix stack crawling on 'running' CPUs
    that aren't the master") if we're backtracing on a task running on a
    CPU we ask that CPU to do the backtrace itself. Linux can do that
    without anything fancy. If we're doing backtrace on a sleeping task
    we can also do that fine without updating globals. So this patch
    mostly just turns into deleting a bunch of code.

    [1] https://lore.kernel.org/r/20191010150735.dhrj3pbjgmjrdpwr@holly.lan

    Signed-off-by: Douglas Anderson
    Link: https://lore.kernel.org/r/20191109111624.4.Ibc3d982bbeb9e46872d43973ba808cd4c79537c7@changeid
    Signed-off-by: Daniel Thompson

    Douglas Anderson
     

28 Oct, 2019

1 commit

  • kdb_read() contains special case logic to force it exit after reading
    a single character. We can remove all the special case logic by directly
    calling the function to read a single character instead. This also
    allows us to tidy up the function prototype which, because it now matches
    getchar(), we can also rename in order to make its role clearer.

    This does involve some extra code to handle btaprompt properly but we
    don't mind the new lines of code here because the old code had some
    interesting problems (bad newline handling, treating unexpected
    characters like ).

    Signed-off-by: Daniel Thompson
    Reviewed-by: Douglas Anderson
    Link: https://lore.kernel.org/r/20191025073328.643-4-daniel.thompson@linaro.org

    Daniel Thompson
     

10 Oct, 2019

3 commits

  • In kdb when you do 'btc' (back trace on CPU) it doesn't necessarily
    give you the right info. Specifically on many architectures
    (including arm64, where I tested) you can't dump the stack of a
    "running" process that isn't the process running on the current CPU.
    This can be seen by this:

    echo SOFTLOCKUP > /sys/kernel/debug/provoke-crash/DIRECT
    # wait 2 seconds
    g

    Here's what I see now on rk3399-gru-kevin. I see the stack crawl for
    the CPU that handled the sysrq but everything else just shows me stuck
    in __switch_to() which is bogus:

    ======

    [0]kdb> btc
    btc: cpu status: Currently on cpu 0
    Available cpus: 0, 1-3(I), 4, 5(I)
    Stack traceback for pid 0
    0xffffff801101a9c0 0 0 1 0 R 0xffffff801101b3b0 *swapper/0
    Call trace:
    dump_backtrace+0x0/0x138
    ...
    kgdb_compiled_brk_fn+0x34/0x44
    ...
    sysrq_handle_dbg+0x34/0x5c
    Stack traceback for pid 0
    0xffffffc0f175a040 0 0 1 1 I 0xffffffc0f175aa30 swapper/1
    Call trace:
    __switch_to+0x1e4/0x240
    0xffffffc0f65616c0
    Stack traceback for pid 0
    0xffffffc0f175d040 0 0 1 2 I 0xffffffc0f175da30 swapper/2
    Call trace:
    __switch_to+0x1e4/0x240
    0xffffffc0f65806c0
    Stack traceback for pid 0
    0xffffffc0f175b040 0 0 1 3 I 0xffffffc0f175ba30 swapper/3
    Call trace:
    __switch_to+0x1e4/0x240
    0xffffffc0f659f6c0
    Stack traceback for pid 1474
    0xffffffc0dde8b040 1474 727 1 4 R 0xffffffc0dde8ba30 bash
    Call trace:
    __switch_to+0x1e4/0x240
    __schedule+0x464/0x618
    0xffffffc0dde8b040
    Stack traceback for pid 0
    0xffffffc0f17b0040 0 0 1 5 I 0xffffffc0f17b0a30 swapper/5
    Call trace:
    __switch_to+0x1e4/0x240
    0xffffffc0f65dd6c0

    ===

    The problem is that 'btc' eventually boils down to
    show_stack(task_struct, NULL);

    ...and show_stack() doesn't work for "running" CPUs because their
    registers haven't been stashed.

    On x86 things might work better (I haven't tested) because kdb has a
    special case for x86 in kdb_show_stack() where it passes the stack
    pointer to show_stack(). This wouldn't work on arm64 where the stack
    crawling function seems needs the "fp" and "pc", not the "sp" which is
    presumably why arm64's show_stack() function totally ignores the "sp"
    parameter.

    NOTE: we _can_ get a good stack dump for all the cpus if we manually
    switch each one to the kdb master and do a back trace. AKA:
    cpu 4
    bt
    ...will give the expected trace. That's because now arm64's
    dump_backtrace will now see that "tsk == current" and go through a
    different path.

    In this patch I fix the problems by catching a request to stack crawl
    a task that's running on a CPU and then I ask that CPU to do the stack
    crawl.

    NOTE: this will (presumably) change what stack crawls are printed for
    x86 machines. Now kdb functions will show up in the stack crawl.
    Presumably this is OK but if it's not we can go back and add a special
    case for x86 again.

    Signed-off-by: Douglas Anderson
    Acked-by: Will Deacon
    Signed-off-by: Daniel Thompson

    Douglas Anderson
     
  • I noticed that when I did "btc " and the CPU I passed in hadn't
    rounded up that I'd crash. I was going to copy the same fix from
    commit 162bc7f5afd7 ("kdb: Don't back trace on a cpu that didn't round
    up") into the "not all the CPUs" case, but decided it'd be better to
    clean things up a little bit.

    This consolidates the two code paths. It is _slightly_ wasteful in in
    that the checks for "cpu" being too small or being offline isn't
    really needed when we're iterating over all online CPUs, but that
    really shouldn't hurt. Better to have the same code path.

    While at it, eliminate at least one slightly ugly (and totally
    needless) recursive use of kdb_parse().

    Signed-off-by: Douglas Anderson
    Acked-by: Will Deacon
    Signed-off-by: Daniel Thompson

    Douglas Anderson
     
  • The kdb_bt1() had a mysterious "argcount" parameter passed in (always
    the number 5, by the way) and never used. Presumably this is just old
    cruft. Remove it. While at it, upgrade the btaprompt parameter to a
    full fledged bool instead of an int.

    Signed-off-by: Douglas Anderson
    Acked-by: Will Deacon
    Signed-off-by: Daniel Thompson

    Douglas Anderson
     

30 Dec, 2018

1 commit

  • If you have a CPU that fails to round up and then run 'btc' you'll end
    up crashing in kdb becaue we dereferenced NULL. Let's add a check.
    It's wise to also set the task to NULL when leaving the debugger so
    that if we fail to round up on a later entry into the debugger we
    won't backtrace a stale task.

    Signed-off-by: Douglas Anderson
    Acked-by: Daniel Thompson
    Signed-off-by: Daniel Thompson

    Douglas Anderson
     

14 Nov, 2018

1 commit

  • On a powerpc 8xx, 'btc' fails as follows:

    Entering kdb (current=0x(ptrval), pid 282) due to Keyboard Entry
    kdb> btc
    btc: cpu status: Currently on cpu 0
    Available cpus: 0
    kdb_getarea: Bad address 0x0

    when booting the kernel with 'debug_boot_weak_hash', it fails as well

    Entering kdb (current=0xba99ad80, pid 284) due to Keyboard Entry
    kdb> btc
    btc: cpu status: Currently on cpu 0
    Available cpus: 0
    kdb_getarea: Bad address 0xba99ad80

    On other platforms, Oopses have been observed too, see
    https://github.com/linuxppc/linux/issues/139

    This is due to btc calling 'btt' with %p pointer as an argument.

    This patch replaces %p by %px to get the real pointer value as
    expected by 'btt'

    Fixes: ad67b74d2469 ("printk: hash addresses printed with %p")
    Cc:
    Signed-off-by: Christophe Leroy
    Reviewed-by: Daniel Thompson
    Signed-off-by: Daniel Thompson

    Christophe Leroy
     

02 Mar, 2017

2 commits


05 Jun, 2014

1 commit

  • ... instead of naked numbers.

    Stuff in sysrq.c used to set it to 8 which is supposed to mean above
    default level so set it to DEBUG instead as we're terminating/killing all
    tasks and we want to be verbose there.

    Also, correct the check in x86_64_start_kernel which should be >= as
    we're clearly issuing the string there for all debug levels, not only
    the magical 10.

    Signed-off-by: Borislav Petkov
    Acked-by: Kees Cook
    Acked-by: Randy Dunlap
    Cc: Joe Perches
    Cc: Valdis Kletnieks
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Borislav Petkov
     

12 Oct, 2012

1 commit


29 Mar, 2012

1 commit


02 Aug, 2011

1 commit


21 May, 2010

2 commits

  • Certain calls from the kdb shell will call out to printk(), and any of
    these calls should get vectored back to the kdb_printf() so that the
    kdb pager and processing can be used, as well as to properly channel
    I/O to the polled I/O devices.

    CC: Randy Dunlap
    Signed-off-by: Jason Wessel
    Acked-by: Andrew Morton

    Jason Wessel
     
  • This patch contains only the kdb core. Because the change set was
    large, it was split. The next patch in the series includes the
    instrumentation into the core kernel which are mainly helper functions
    for kdb.

    This work is directly derived from kdb v4.4 found at:

    ftp://oss.sgi.com/projects/kdb/download/v4.4/

    The kdb internals have been re-organized to make them mostly platform
    independent and to connect everything to the debug core which is used by
    gdbstub (which has long been known as kgdb).

    The original version of kdb was 58,000 lines worth of changes to
    support x86. From that implementation only the kdb shell, and basic
    commands for memory access, runcontrol, lsmod, and dmesg where carried
    forward.

    This is a generic implementation which aims to cover all the current
    architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
    blackfin. More archictectures can be added by implementing the
    architecture specific kgdb functions.

    [mort@sgi.com: Compile fix with hugepages enabled]
    [mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
    [mort@sgi.com: fix new line after printing registers]
    [mort@sgi.com: Remove the concept of global vs. local breakpoints]
    [mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
    [mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
    [sfr@canb.auug.org.au: include fixup to include linux/slab.h]

    CC: linux-arch@vger.kernel.org
    Signed-off-by: Jason Wessel
    Signed-off-by: Martin Hicks

    Jason Wessel