Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1510429 > unrolled thread
| Started by | Sergey Senozhatsky <sergey.senozhatsky@gmail.com> |
|---|---|
| First post | 2016-10-27 18:00 +0200 |
| Last post | 2016-10-28 06:10 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
[RFC][PATCHv4 0/6] printk: use printk_safe to handle printk() recursive calls Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-10-27 18:00 +0200
Re: [RFC][PATCHv4 0/6] printk: use printk_safe to handle printk() recursive calls Linus Torvalds <torvalds@linux-foundation.org> - 2016-10-28 05:40 +0200
Re: [RFC][PATCHv4 0/6] printk: use printk_safe to handle printk() recursive calls Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-10-28 06:10 +0200
| From | Sergey Senozhatsky <sergey.senozhatsky@gmail.com> |
|---|---|
| Date | 2016-10-27 18:00 +0200 |
| Subject | [RFC][PATCHv4 0/6] printk: use printk_safe to handle printk() recursive calls |
| Message-ID | <swVfX-3Pm-11@gated-at.bofh.it> |
Hello,
RFC
This patch set extends a lock-less NMI per-cpu buffers idea to
handle recursive printk() calls. The basic mechanism is pretty much the
same -- at the beginning of a deadlock-prone section we switch to lock-less
printk callback, and return back to a default printk implementation at the
end; the messages are getting flushed to a logbuf buffer from a safer
context.
Deadlock scenarios that printk_safe can handle:
a) printk recursion from logbuf_lock spin_lock section in printk()
printk()
raw_spin_lock(&logbuf_lock);
WARN_ON(1);
raw_spin_unlock(&logbuf_lock);
b) printk from sem->lock spin_lock section
printk()
console_trylock()
down_trylock()
raw_spin_lock_irqsave(&sem->lock, flags);
WARN_ON(1);
raw_spin_unlock_irqrestore(&sem->lock, flags);
c) printk from logbuf_lock spin_lock section in console_unlock()
printk()
console_unlock()
raw_spin_lock(&logbuf_lock);
WARN_ON(1);
raw_spin_unlock(&logbuf_lock);
d) printk from ->pi_lock from semaphore up
printk()
console_unlock()
up()
try_to_wake_up()
raw_spin_lock_irqsave(&p->pi_lock, flags);
WARN_ON(1);
raw_spin_unlock_irqrestore(&p->pi_lock, flags);
e) printk from console_cont_flush() /*and down the call chain */
printk()
console_unlock()
call_console_drivers()
...
WARN_ON(1);
[[against next-20161027]]
v4:
-- addressed Steven's review points
-- use printk_safe in console_cont_flush()
v3: (review by Petr)
-- renamed to printk_safe
-- !NMI config build fix
-- report lost messages for both printk_sae and printk_nmi
-- dropped recursion reporting patch
-- etc.
v2:
-- fix build error on !NMI configs, reported by Fengguang
-- reworked the series based on Petr's feedback
-- added a new patch to drop zap_locks()
Sergey Senozhatsky (6):
printk: use vprintk_func in vprintk()
printk: rename nmi.c and exported api
printk: introduce per-cpu safe_print seq buffer
printk: report lost messages in printk safe/nmi contexts
printk: use printk_safe buffers
printk: remove zap_locks() function
arch/arm/kernel/smp.c | 4 +-
include/linux/hardirq.h | 4 +-
include/linux/printk.h | 29 ++--
init/Kconfig | 16 ++-
init/main.c | 2 +-
kernel/kexec_core.c | 2 +-
kernel/panic.c | 4 +-
kernel/printk/Makefile | 2 +-
kernel/printk/internal.h | 63 ++++-----
kernel/printk/printk.c | 124 +++++-------------
kernel/printk/{nmi.c => printk_safe.c} | 233 +++++++++++++++++++++++++--------
lib/nmi_backtrace.c | 2 +-
12 files changed, 274 insertions(+), 211 deletions(-)
rename kernel/printk/{nmi.c => printk_safe.c} (54%)
--
2.10.1.502.g6598894
[toc] | [next] | [standalone]
| From | Linus Torvalds <torvalds@linux-foundation.org> |
|---|---|
| Date | 2016-10-28 05:40 +0200 |
| Subject | Re: [RFC][PATCHv4 0/6] printk: use printk_safe to handle printk() recursive calls |
| Message-ID | <sx6bn-2O3-1@gated-at.bofh.it> |
| In reply to | #1510429 |
On Thu, Oct 27, 2016 at 8:49 AM, Sergey Senozhatsky
<sergey.senozhatsky@gmail.com> wrote:
>
> RFC
>
> This patch set extends a lock-less NMI per-cpu buffers idea to
> handle recursive printk() calls. The basic mechanism is pretty much the
> same -- at the beginning of a deadlock-prone section we switch to lock-less
> printk callback, and return back to a default printk implementation at the
> end; the messages are getting flushed to a logbuf buffer from a safer
> context.
This looks very reasonable to me.
Does this also obviate the need for "printk_deferred()" that the
scheduler and the clock code uses? Because that would be a lovely
thing to look at if it doesn't..
LInus
[toc] | [prev] | [next] | [standalone]
| From | Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> |
|---|---|
| Date | 2016-10-28 06:10 +0200 |
| Subject | Re: [RFC][PATCHv4 0/6] printk: use printk_safe to handle printk() recursive calls |
| Message-ID | <sx6Ep-3dL-1@gated-at.bofh.it> |
| In reply to | #1510828 |
Hello,
On (10/27/16 20:30), Linus Torvalds wrote:
> On Thu, Oct 27, 2016 at 8:49 AM, Sergey Senozhatsky
> <sergey.senozhatsky@gmail.com> wrote:
> >
> > RFC
> >
> > This patch set extends a lock-less NMI per-cpu buffers idea to
> > handle recursive printk() calls. The basic mechanism is pretty much the
> > same -- at the beginning of a deadlock-prone section we switch to lock-less
> > printk callback, and return back to a default printk implementation at the
> > end; the messages are getting flushed to a logbuf buffer from a safer
> > context.
>
> This looks very reasonable to me.
>
> Does this also obviate the need for "printk_deferred()" that the
> scheduler and the clock code uses? Because that would be a lovely
> thing to look at if it doesn't..
I wish I could say that we can retire printk_deferred(), but no, we still
need it. it's rather simple to fix printk recursion (that's what the patch
set is doing), but printk deadlocks are much harder to handle. anything that
starts somewhere else but somehow is related printk will deadlock (in the
worst case). I use this backtrace as an example:
SyS_ioctl
do_vfs_ioctl
tty_ioctl
n_tty_ioctl
tty_mode_ioctl
set_termios
tty_set_termios
uart_set_termios
uart_change_speed
FOO_serial_set_termios
spin_lock_irqsave(&port->lock) // lock the output port
....
!! WARN() or pr_err() or printk()
vprintk_emit()
/* console_trylock() */
console_unlock()
call_console_drivers()
FOO_write()
spin_lock_irqsave(&port->lock) // already locked
with the current printk we can't tell for sure how many locks will
be acquired -- printk() can succeed in locking the console_sem and
start invoking console drivers (if any) from console_unlock(), or
it can fail thus we will acquire only logbuf spin_lock and console_sem
spin_lock.
the things can change *a bit* once we switch to async_printk. because
instead of doing console_unlock()->call_console_drivers(), printk()
will just wake_up() the printk_kthread. but still, it won't be enough
to remove printk_deferred() :(
vprintk_emit()
wake_up()
spin_lock rq lock
printk
will be safe. but
wake_up()
spin_lock rq lock
printk
vprintk_emit()
wake_up()
spin_lock rq lock
will deadlock.
we can't even tell for sure what locks are "important" to printk().
a small and reasonable code refactoring somewhere in clock code/etc.
can accidentally change the whole picture by introducing "unsafe"
WARN_ON() or adding yet another lock to the printing path.
need to think more.
p.s.
we are plannig to discuss printk related issues next week in Santa Fe.
-ss
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web