Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5994544rwb; Mon, 14 Nov 2022 12:35:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4p/SnWmOftIW6I4rMZWrFgEieVfpe8iFRj/mS5z8XB0+BR90Y6OaXA5efncq61Dq2rhSYS X-Received: by 2002:a17:90a:fd14:b0:213:2030:123f with SMTP id cv20-20020a17090afd1400b002132030123fmr15234479pjb.3.1668458142233; Mon, 14 Nov 2022 12:35:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668458142; cv=none; d=google.com; s=arc-20160816; b=ToDQONPSbKRGUBNmJ+33CzMUAAwneTCIieF83nzixRGrFdnJ1dXy4rqc+4WEvcZUIJ creIcZ2La6rjJppximz9gi5VVNoYmtZ1uNPJNfT5XoNciFZTDYhrrEzoizY+KXfbhABU jssldNqYx/eYnUmTEx+8LceXzz9Aviu8hdH6+CA90O/Dkr2bGZ+qsiarnz8CFKXk14lt d3nH5H6LT4XiFJq7O8lH0pIkrNP81kDKrZpSL2EMzEP8keeMWdPKiZBDgIMaBlaH5cMh MI2nzOB9jrQhPLnWhssGWseLgBeFrdfnfn4nlWBUvIWs2ZuCvidWi3O9Gsz6ncMjx8LS FvwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=PfwmN3gCUQ+9TAw/6+bki3KtgpMLZgBklmxHfTgDw4o=; b=Wc7eeBoTizhN0dk88jsO194Sv9yiM7HRgSsJTbE1L+Oq1icqOicCKI5LvFNSmr9dvG 91Cmq3wQ3CW6xrb9n8Q1Oobo5DvSJDAJXyc+/tsPxciuC3uM0HwXoggvsyghwQo9aAeH NBmIN/lOeIJeWeP6sr3qAP7vbD6Xf48dqWMDl6qNP91k4b24+aTFm0v2IuxVLJxx+cmf qBpENrZ/ieUT1e5UvnRYqG7Aj+yZns4J7P5rUvs8Hn1rux1WfTyO272f5P8kNGAMi41/ jjP1aEOg5r+k9/WHhE923IZiU0g665cIppLZ132fF0FAw5aXcpWNAiLsM9ajCEIzsGb+ pDLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=iMGGVuDK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 2-20020a630402000000b0042bc2bd5797si9652363pge.278.2022.11.14.12.35.31; Mon, 14 Nov 2022 12:35:42 -0800 (PST) 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=iMGGVuDK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S236201AbiKNTv0 (ORCPT + 88 others); Mon, 14 Nov 2022 14:51:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235813AbiKNTvV (ORCPT ); Mon, 14 Nov 2022 14:51:21 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5193AC16; Mon, 14 Nov 2022 11:51:20 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668455478; 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=PfwmN3gCUQ+9TAw/6+bki3KtgpMLZgBklmxHfTgDw4o=; b=iMGGVuDKNStmNor0UI3iTAYJ0AUO55XogBClFvM6B+tx0AU7fG2GCFY1lB/NC6Tb3UDkHT wjMXw+7S+KKxg6nci2jZINQSPEpVH8/S75n8xpxWvbZB9TxM/doLt1grp8dJYSQNe4gcu2 DqQPQFAS80ZUU4gsK6dxxarHe2nXdRbTQa10ScIZY9lfZD459n/D+zboV2n4sGBx1lblni JnLYd56MPxPaQR/+Mg3f7wjXIhTMsGxmrmPTrYXYKM4AA9jm8M7zDoQPx6vcpAWYDQ7x6x bqOsfc0s5Ggddqj32cmnHa27cCEyV5ocQGudIreuupfSYr3csW2a8Zggd4jVgw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668455478; 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=PfwmN3gCUQ+9TAw/6+bki3KtgpMLZgBklmxHfTgDw4o=; b=dncJ14jVrz1LFCtglE+whx9TPp6GS0vWhsUTBrHNZGXicNcXkFVwyCGWGQtJhi1XDLy5gW vPUxufgOngSBI2Bw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Helge Deller , Greg Kroah-Hartman , Javier Martinez Canillas , Thomas Zimmermann , Juergen Gross , Boris Ostrovsky , Tom Rix , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: Re: [PATCH printk v4 31/39] printk, xen: fbfront: create/use safe function for forcing preferred In-Reply-To: <20221114162932.141883-32-john.ogness@linutronix.de> References: <20221114162932.141883-1-john.ogness@linutronix.de> <20221114162932.141883-32-john.ogness@linutronix.de> Date: Mon, 14 Nov 2022 20:57:18 +0106 Message-ID: <87mt8tfh6x.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain 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: X-Mailing-List: linux-kernel@vger.kernel.org Hi, After more detailed runtime testing I discovered that I didn't re-insert the console to the correct place in the list. More below... On 2022-11-14, John Ogness wrote: > diff --git a/include/linux/console.h b/include/linux/console.h > index f716e1dd9eaf..9cea254b34b8 100644 > --- a/include/linux/console.h > +++ b/include/linux/console.h > @@ -291,6 +291,7 @@ enum con_flush_mode { > }; > > extern int add_preferred_console(char *name, int idx, char *options); > +extern void console_force_preferred_locked(struct console *con); > extern void register_console(struct console *); > extern int unregister_console(struct console *); > extern void console_lock(void); > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index e770b1ede6c9..dff76c1cef80 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -3461,6 +3462,48 @@ int unregister_console(struct console *console) > } > EXPORT_SYMBOL(unregister_console); > > +/** > + * console_force_preferred_locked - force a registered console preferred > + * @con: The registered console to force preferred. > + * > + * Must be called under console_list_lock(). > + */ > +void console_force_preferred_locked(struct console *con) > +{ > + struct console *cur_pref_con; > + > + if (!console_is_registered_locked(con)) > + return; > + > + cur_pref_con = console_first(); > + > + /* Already preferred? */ > + if (cur_pref_con == con) > + return; > + > + /* > + * Delete, but do not re-initialize the entry. This allows the console > + * to continue to appear registered (via any hlist_unhashed_lockless() > + * checks), even though it was briefly removed from the console list. > + */ > + hlist_del_rcu(&con->node); > + > + /* > + * Ensure that all SRCU list walks have completed so that the console > + * can be added to the beginning of the console list and its forward > + * list pointer can be re-initialized. > + */ > + synchronize_srcu(&console_srcu); > + > + con->flags |= CON_CONSDEV; > + WARN_ON(!con->device); > + > + /* Only the new head can have CON_CONSDEV set. */ > + console_srcu_write_flags(cur_pref_con, cur_pref_con->flags & ~CON_CONSDEV); > + hlist_add_behind_rcu(&con->node, console_list.first); This is adding the console as the 2nd item. It should be the new head. The patch below fixes it. I have done careful runtime testing with this fixup. After the force_preferred, the console is the new head and sending data to /dev/console redirects to that console. It would be nice if we could fold this in. Sorry. John Ogness diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 8d635467882f..4b77586cf4cb 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3494,7 +3494,7 @@ void console_force_preferred_locked(struct console *con) /* Only the new head can have CON_CONSDEV set. */ console_srcu_write_flags(cur_pref_con, cur_pref_con->flags & ~CON_CONSDEV); - hlist_add_behind_rcu(&con->node, console_list.first); + hlist_add_head_rcu(&con->node, &console_list); } EXPORT_SYMBOL(console_force_preferred_locked);