From nobody Tue Apr 7 22:24:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B1B6C43219 for ; Wed, 19 Oct 2022 15:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232010AbiJSPGN (ORCPT ); Wed, 19 Oct 2022 11:06:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbiJSPF0 (ORCPT ); Wed, 19 Oct 2022 11:05:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98472153835 for ; Wed, 19 Oct 2022 07:59:11 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kDZ6pRjPX3M/aNWQNadxCVy2Ern3rX+BUG+UFbJRacE=; b=vZ++W4VE4AQQNPASVoIgQEv9QFic6MvrPxW9APkzUtJQWlJmpTRafFJlXDcuEug7iTrgAr Q68gq3cOHoYxad58FRzrhkyde3adxE+hwep+0uWLN2/qDedGH7Q7xx1AmRkMh/mK0VoNFv nMsU91BskHVFEannoZwBQZA7Z1nTnh3feCTKpKo/0ocU/OTDbu3KpsM2BSapW5B13XOBk4 XEBAiQvwiu+9W09sKCUpa/szF8Xe08dS43bdhg5WwWcE38dtMvjprltTZX5kT84uDgwvUo ks5/LYqdhSVgBppHnyQB/LpicRRiUXa15t6U5CopyRfzugDG8cvli1d2t8CL9Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kDZ6pRjPX3M/aNWQNadxCVy2Ern3rX+BUG+UFbJRacE=; b=zlEFWao8VJz19cq1+qrdLmGFpWXLPFk4nyCnR24oE/kjsnhlT2viimgpJo1H5sm4DIHUYs PFn0fdw64FnnTOBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 30/38] printk: console_device: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:52 +0206 Message-Id: <20221019145600.1282823-31-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. Signed-off-by: John Ogness --- kernel/printk/printk.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e478cb92e7ba..410ad9d5649c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3025,15 +3025,24 @@ struct tty_driver *console_device(int *index) { struct console *c; struct tty_driver *driver =3D NULL; + int cookie; =20 + /* + * Stop console printing because the device() callback may + * assume the console is not within its write() callback. + */ console_lock(); - for_each_console(c) { + + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(c) { if (!c->device) continue; driver =3D c->device(c, index); if (driver) break; } + console_srcu_read_unlock(cookie); + console_unlock(); return driver; } --=20 2.30.2