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 B074D2989B4 for ; Wed, 3 Dec 2025 12:27:41 +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=1764764863; cv=none; b=dC8/sCeB+zgce6IkFLRTJyRyF/C7vRp3N+h7wGdlvqLEivF2LGrgqZZEL6mhm7BELQ4BLIXZ+2ihjD1+aN7VVoT/RHuVE9a4VZXXH6cn/xrC2s+wanyQTmAqs3F6dOmDskDgnYoD6WCOD+7A3pbGtwcm4qh8w/1fv/0bmsfrzko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764764863; c=relaxed/simple; bh=EN5gnlWKGDwAtN8gFAOQTejmrci+kIG5pcG0+MTQVes=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=C6tKwSMv1GKAszNlxdrFJjyI/RT3ygemh4khVmlEi/6UkZMfrGOZxH0+SnLUo7dWHYiDr5uM6hoqVqSq1UDEndP4PvKBuIF2P+9TdhMFKUR8/yjn1Kx7jF8ZER8xT6FO+hWigURUjX9yF0jq2hHx/7mm3kUIN0A/jj+NlK+j/UM= 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=s5XnOUxv; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=krdpQ07T; 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="s5XnOUxv"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="krdpQ07T" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1764764859; 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=XLsoqwdEviZsSAhPhXvYsITNQwIlBAfFrwBEQrfP0F8=; b=s5XnOUxvBKImp785ZeZn8F4vU9FWeqNhti0naCZYeMKenfYV5HpDUBafe65SY1ng132nuN GSyrmVcUQw85nWtsmw/IWst7jwY9eIRo7n0WxPcF/EqUB1HKkZqrRKIPXaYLNPHQ07eGdL K1Jix/ke6/4Jlbshgib90I8ZpmNvo582/0J7pONaAl+V8/g8jmQfuNyph8vjYGLqs4xfBu 3EtRKfctow0G7bJFlywc0M9z8PLG5++zwrb9CZQ/wfEmdwwwLaaNDvELS3D43mxmBEF7sx C0tUGvhPxFRCeJkXSVc0U+kXyBp6YNR+7aRRk78SeLBRGoUCW1ZquXLO7K6BKQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1764764859; 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=XLsoqwdEviZsSAhPhXvYsITNQwIlBAfFrwBEQrfP0F8=; b=krdpQ07T87hXQTR7t8oaZmz8ipj7q2Q16g70ZUJrkGA+qn/FlRdtLwc26n9ONyMNoHH1vb rM5qIegXjZDiZlCg== To: Leo Yan Cc: Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Breno Leitao , linux@armlinux.org.uk, paulmck@kernel.org, usamaarif642@gmail.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, rmikey@meta.com Subject: Re: [PATCH] printk/nbcon: Restore IRQ in atomic flush after each emitted record In-Reply-To: <20251202162639.GD724103@e132581.arm.com> References: <20251202135832.156559-1-pmladek@suse.com> <87o6oheywd.fsf@jogness.linutronix.de> <20251202162639.GD724103@e132581.arm.com> Date: Wed, 03 Dec 2025 13:33:38 +0106 Message-ID: <87ikenyclh.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, Leo Yan wrote: >> 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(). > > Sorry for suddenly jumping in. Wouldn't guard(irqsave)() be helpful > here? Thanks, I was not aware of the irqsave variant. We would want the scoped version. So something like this? $ git diff -w diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 3fa403f9831f..55beb64c4f4a 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1557,6 +1557,14 @@ 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; @@ -1569,6 +1577,7 @@ static int __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq) return -EAGAIN; nbcon_context_release(ctxt); + } if (!ctxt->backlog) { /* Are there reserved but not yet finalized records? */ John