From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB1FF202C48 for ; Tue, 2 Dec 2025 14:33:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764686039; cv=none; b=ofUF0dL1Ahl/9fB/lZ5G0UqW60S7PLCttNegWKBKBsH2HIAb+rZ7o7GCBr57W5+wOs4F/PRSPjL/SoORJ9o/XCxulSGf6/PfqiwmAiieo0JQM9EdpQI3fhnsXM1dnTXKpcjYulySkIzJFN09ZEaNlPFYhxHQCTuqcy5cxtivpAw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764686039; c=relaxed/simple; bh=L695I52ctAz4ws80AZDZwwsS9KIp/MEMjWfnRP2qRCs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=Ggk+k1PLfOfDZ+u63xNTziNELE4PiB984qDuih7iSfeF5Mm1+mxV43ncvQkMm33P0QFbxHG4TQXNePcuH/v4gBrZ0gFoLKLH7SmGI3zsgNuaUBLCmtMTK+7Y0e5z3O9YEVzdjBqsPeRQVpQKB547HDB7AzXiXe5t1u/4wKkrEtE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1DvGH/Ms; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=q9Uv3+OW; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1DvGH/Ms"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="q9Uv3+OW" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1764686035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ChX94tIO4F5AVgFaNDBv+eRZdyX4C0RWh7xUNZbENe8=; b=1DvGH/Ms8RajWMeieHHvc05U81FOOJeB6tWZ4+YpLlMGuSeF4Tj9++A65ZJJshkN/l6UC8 NH8E9FYYEsxQTjDtph55wCwWhAhHaboIIAgXvUZ4Qc5CTeVdMNZSryVym6KNA8DMsAG7hM UezMjjmxpr4F3amCWw1jiUDP+mOwydgd5rXLWMwOYeHbRG9CpBUKIF3nz0tEyrPVnNU6mW S4qaoPi6v9ejcVhIByvmRR7alfFmFW7X7SenljlJ3MuFSxngpdL+kGHLJkiy7IlayBJAY5 Zrq68oxo6Fhr6NgCpzcI8Qj8ra9WePILHkL2fbyIclihOVqthHGRZngJaKkKQw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1764686035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ChX94tIO4F5AVgFaNDBv+eRZdyX4C0RWh7xUNZbENe8=; b=q9Uv3+OWc5BH7qs3/BlgDKohsfbzLxXOjODsrmlEk5SfzDeXUG3qgPzgeUhQ2Za5tRUF1J lNp1G/Q7XFwbpFBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Breno Leitao , linux@armlinux.org.uk, paulmck@kernel.org, usamaarif642@gmail.com, leo.yan@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, rmikey@meta.com, Petr Mladek Subject: Re: [PATCH] printk/nbcon: Restore IRQ in atomic flush after each emitted record In-Reply-To: <20251202135832.156559-1-pmladek@suse.com> References: <20251202135832.156559-1-pmladek@suse.com> Date: Tue, 02 Dec 2025 15:39:54 +0106 Message-ID: <87o6oheywd.fsf@jogness.linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On 2025-12-02, Petr Mladek wrote: > diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c > index 3fa403f9831f..6b8becb6ecd9 100644 > --- a/kernel/printk/nbcon.c > +++ b/kernel/printk/nbcon.c > @@ -1549,6 +1549,7 @@ static int __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq) > { > struct nbcon_write_context wctxt = { }; > struct nbcon_context *ctxt = &ACCESS_PRIVATE(&wctxt, ctxt); > + unsigned long flags; > int err = 0; > > ctxt->console = con; > @@ -1557,18 +1558,31 @@ 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) { > - if (!nbcon_context_try_acquire(ctxt, false)) > + /* > + * 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); > + if (!nbcon_context_try_acquire(ctxt, false)) { > + local_irq_restore(flags); > 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. > */ > - if (!nbcon_emit_next_record(&wctxt, true)) > + if (!nbcon_emit_next_record(&wctxt, true)) { > + local_irq_restore(flags); > return -EAGAIN; > + } > > nbcon_context_release(ctxt); > + local_irq_restore(flags); I am not really happy about all the local_irq_restore() usage. Using guard syntax would be nice here, but AFAICT there is no guard for local_irq_save()/_restore(). :-/ And I could not come up with any other alternative that looked more elegant. So let's just keep it this way. Reviewed-by: John Ogness