Commit 7a2c1b27 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
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
parents 353c6f43 9bd18e12
Loading
Loading
Loading
Loading
+18 −20
Original line number Diff line number Diff line
@@ -1557,18 +1557,27 @@ static int __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
	ctxt->allow_unsafe_takeover	= nbcon_allow_unsafe_takeover();

	while (nbcon_seq_read(con) < stop_seq) {
		/*
		 * Atomic flushing does not use console driver synchronization
		 * (i.e. it does not hold the port lock for uart consoles).
		 * Therefore IRQs must be disabled to avoid being interrupted
		 * and then calling into a driver that will deadlock trying
		 * to acquire console ownership.
		 */
		scoped_guard(irqsave) {
			if (!nbcon_context_try_acquire(ctxt, false))
				return -EPERM;

			/*
		 * nbcon_emit_next_record() returns false when the console was
		 * handed over or taken over. In both cases the context is no
		 * longer valid.
			 * nbcon_emit_next_record() returns false when
			 * the console was handed over or taken over.
			 * In both cases the context is no longer valid.
			 */
			if (!nbcon_emit_next_record(&wctxt, true))
				return -EAGAIN;

			nbcon_context_release(ctxt);
		}

		if (!ctxt->backlog) {
			/* 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)
static void nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
{
	struct console_flush_type ft;
	unsigned long flags;
	int err;

again:
	/*
	 * Atomic flushing does not use console driver synchronization (i.e.
	 * it does not hold the port lock for uart consoles). Therefore IRQs
	 * must be disabled to avoid being interrupted and then calling into
	 * a driver that will deadlock trying to acquire console ownership.
	 */
	local_irq_save(flags);

	err = __nbcon_atomic_flush_pending_con(con, stop_seq);

	local_irq_restore(flags);

	/*
	 * If there was a new owner (-EPERM, -EAGAIN), that context is
	 * responsible for completing.