Message ID | 20221019145600.1282823-31-john.ogness@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp379208wrs; Wed, 19 Oct 2022 08:10:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5I3l7tejRpgd3AuLzJVvrWUESgeTnL5dad374eza0+I1APSkFmCvYKN5C3tl16Qw5bvNd9 X-Received: by 2002:a05:6402:40c4:b0:45c:c718:54d1 with SMTP id z4-20020a05640240c400b0045cc71854d1mr7960568edb.319.1666192229826; Wed, 19 Oct 2022 08:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192229; cv=none; d=google.com; s=arc-20160816; b=Qav4jNVvJGkaDRc/gBGTMVMyWubVPyflnCgaIecJw3KhLK1zSB3opjD8gtQ5hx4LhL c2HsfLMND7Ozdig0YQl+5+GCO7yJB3pcG9XkpmN1rbgLsQup63a1ZiSfgX1SJhJAhxm9 3SWCJ3o/LOh5Ys7aQ6CDkcu7FT3hvROJ/ulcS4X5XlAFKbYsfZ8mlI+WsTCybB7BROmV Raj667LYsvt//OoLq0QLROBcQ7D9Sbd+12KjLNYtLr2zGNaoWB5HvZIkGW0YUkAsXfKh KvgXO9Dx+kCX/Q/8hdYqJQa2q98zENMIJnz/8DHIMxNYvglG+JLU/bEV2qY08tTBWiiy zCJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=kDZ6pRjPX3M/aNWQNadxCVy2Ern3rX+BUG+UFbJRacE=; b=IblqMgAHge4oNGFouCeyG5+rIv/XWIio7AfxcMZprD41/FXLRhSyrf90Brqwya58Gf Iqy4v3+P1vVHNVDkOGriCf46O8dwBYfbKonS+Lm0cx9dyt/7nLspwKFpSWkghZg/WVxC mJgJDwJv7a2j4vqPNeV2OGdgxfyAYE+fw7mqesvBzMwB8EBCTHBZJ7lyGrs4b3M1XHlU HrWGBTQ1e4PlfEuA5AUe649F3jWVpT3v6rR+Aq6wxt3RpbmyfdCwMMB+v0+VhvzryIqY wegQRKkjEX7+/LcPsa9eVBdj+DJBLpu8ezhE5gBHBcDsn0VKX7UMGJUwqFKaPYHhlz9f lakQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vZ++W4VE; dkim=neutral (no key) header.i=@linutronix.de header.b=zlEFWao8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hg6-20020a1709072cc600b00791a41d1b39si3160435ejc.656.2022.10.19.08.09.44; Wed, 19 Oct 2022 08:10:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vZ++W4VE; dkim=neutral (no key) header.i=@linutronix.de header.b=zlEFWao8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232000AbiJSPGM (ORCPT <rfc822;samuel.l.nystrom@gmail.com> + 99 others); Wed, 19 Oct 2022 11:06:12 -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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; Wed, 19 Oct 2022 07:59:11 -0700 (PDT) From: John Ogness <john.ogness@linutronix.de> 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 <pmladek@suse.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>, Steven Rostedt <rostedt@goodmis.org>, Thomas Gleixner <tglx@linutronix.de>, 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: 8bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747129183622784547?= X-GMAIL-MSGID: =?utf-8?q?1747129183622784547?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Oct. 19, 2022, 2:55 p.m. UTC
Use srcu console list iteration for console list traversal.
Document why the console_lock is still necessary.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
kernel/printk/printk.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
Comments
On Wed 2022-10-19 17:01:52, John Ogness wrote: > Use srcu console list iteration for console list traversal. > > Document why the console_lock is still necessary. > > Signed-off-by: John Ogness <john.ogness@linutronix.de> > --- > 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 = NULL; > + int cookie; > > + /* > + * Stop console printing because the device() callback may > + * assume the console is not within its write() callback. Again, I would like to know more details about the possible races with the write() callback. It is not that obvious. > + */ > console_lock(); > - for_each_console(c) { > + > + cookie = console_srcu_read_lock(); > + for_each_console_srcu(c) { > if (!c->device) > continue; > driver = c->device(c, index); > if (driver) > break; > } > + console_srcu_read_unlock(cookie); > + > console_unlock(); > return driver; Otherwise, the change looks good. Best Regards, Petr
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 = NULL; + int cookie; + /* + * Stop console printing because the device() callback may + * assume the console is not within its write() callback. + */ console_lock(); - for_each_console(c) { + + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { if (!c->device) continue; driver = c->device(c, index); if (driver) break; } + console_srcu_read_unlock(cookie); + console_unlock(); return driver; }