Skip to content

Commit 7a2c1b2

Browse files
committed
Merge tag 'printk-for-6.19-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux
Pull printk fix from Petr Mladek: - Prevent softlockup by restoring IRQs in atomic flush after each record * tag 'printk-for-6.19-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux: printk/nbcon: Restore IRQ in atomic flush after each emitted record
2 parents 353c6f4 + 9bd18e1 commit 7a2c1b2

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

kernel/printk/nbcon.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,18 +1557,27 @@ static int __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
15571557
ctxt->allow_unsafe_takeover = nbcon_allow_unsafe_takeover();
15581558

15591559
while (nbcon_seq_read(con) < stop_seq) {
1560-
if (!nbcon_context_try_acquire(ctxt, false))
1561-
return -EPERM;
1562-
15631560
/*
1564-
* nbcon_emit_next_record() returns false when the console was
1565-
* handed over or taken over. In both cases the context is no
1566-
* longer valid.
1561+
* Atomic flushing does not use console driver synchronization
1562+
* (i.e. it does not hold the port lock for uart consoles).
1563+
* Therefore IRQs must be disabled to avoid being interrupted
1564+
* and then calling into a driver that will deadlock trying
1565+
* to acquire console ownership.
15671566
*/
1568-
if (!nbcon_emit_next_record(&wctxt, true))
1569-
return -EAGAIN;
1567+
scoped_guard(irqsave) {
1568+
if (!nbcon_context_try_acquire(ctxt, false))
1569+
return -EPERM;
15701570

1571-
nbcon_context_release(ctxt);
1571+
/*
1572+
* nbcon_emit_next_record() returns false when
1573+
* the console was handed over or taken over.
1574+
* In both cases the context is no longer valid.
1575+
*/
1576+
if (!nbcon_emit_next_record(&wctxt, true))
1577+
return -EAGAIN;
1578+
1579+
nbcon_context_release(ctxt);
1580+
}
15721581

15731582
if (!ctxt->backlog) {
15741583
/* Are there reserved but not yet finalized records? */
@@ -1595,22 +1604,11 @@ static int __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
15951604
static void nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
15961605
{
15971606
struct console_flush_type ft;
1598-
unsigned long flags;
15991607
int err;
16001608

16011609
again:
1602-
/*
1603-
* Atomic flushing does not use console driver synchronization (i.e.
1604-
* it does not hold the port lock for uart consoles). Therefore IRQs
1605-
* must be disabled to avoid being interrupted and then calling into
1606-
* a driver that will deadlock trying to acquire console ownership.
1607-
*/
1608-
local_irq_save(flags);
1609-
16101610
err = __nbcon_atomic_flush_pending_con(con, stop_seq);
16111611

1612-
local_irq_restore(flags);
1613-
16141612
/*
16151613
* If there was a new owner (-EPERM, -EAGAIN), that context is
16161614
* responsible for completing.

0 commit comments

Comments
 (0)