Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6944121rwb; Tue, 15 Nov 2022 05:51:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf5h6EE/WnUnNNqcHRI8X2m20piDUYSXhXIvuyFKpN1fCNCWz2SDL/1nxdGCRLsZ8kQ7mqA4 X-Received: by 2002:a17:90a:9a8d:b0:212:e996:704d with SMTP id e13-20020a17090a9a8d00b00212e996704dmr2377223pjp.132.1668520286248; Tue, 15 Nov 2022 05:51:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668520286; cv=none; d=google.com; s=arc-20160816; b=IXTychDNzK8YOqnqvQKG3wL86DbOYeNWAvg1ZT5a+O22DXbxqJaClR9dRE5zOvyNyF /ta9a1VjRi6znLUimMIj3BBTrnb85atEwvyBcOcpWocajam2u0yYSwVsmIAr1rDfPpgw 57snQ76HR7vOQxRI7f6/kg2UslDlPIUsLBtIhJhXdih7uyENMk7rjv1q52tRH9kuvvnX /cHptpNg0JBJMghPk7ycTRFmanyB30YH1X/I+5LgjjsblikZ1bz6lhbbBrYJDcRLDLQj 6jRdOdbQAlAwnQSutY04AW0DByXMajEaenbzhl9wtenQAkfvr2cVYe5y36BodRttQUj1 p+Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QmX7RJNNVBj1FU2joU/lqNhMfCU9lMkhGvr+3DdJhfg=; b=TIIl6wtYMcqELB9DC5djk0csX03dY59fLpCjl2nv1CObC0CGp/x7l2zcytWEq79Zze B0++QxXmbYTbzQWpJE0PdtUZErzcvRXSoxyYP1FrLdperlUqRG0/cUbYJEnKf0MR/YLZ lVGChbxCukX1Ir5dB9nF9V2ZwYh66tzQXxBjpxc9AGL8YyofeagA7s1YHMMWjBzgVLv4 bnVXLmCf39tzHXcOaL4U/qiUQUZxxScBb+BPiv+ALI5ITdnOkvlHRabp+VzDH2ZMkSLk T9V+IaSTyyVVctE+5d++E+0eflM2L5BSJlYSGgVtRsQEiZactrIkFEO6mVXg7vIz3wHb oCUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=iRMOUOKO; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f11-20020a056a00228b00b00541505b05dbsi12976635pfe.31.2022.11.15.05.51.13; Tue, 15 Nov 2022 05:51:26 -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=@suse.com header.s=susede1 header.b=iRMOUOKO; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232569AbiKONWU (ORCPT + 89 others); Tue, 15 Nov 2022 08:22:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230123AbiKONWS (ORCPT ); Tue, 15 Nov 2022 08:22:18 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00792DEC6; Tue, 15 Nov 2022 05:22:17 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id AFDB21F8CD; Tue, 15 Nov 2022 13:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1668518536; h=from:from:reply-to: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=QmX7RJNNVBj1FU2joU/lqNhMfCU9lMkhGvr+3DdJhfg=; b=iRMOUOKOWNnBtw6+eGOtN4tmTznrw3/yio0CZFdwk76Npxu5xZrQMnLuPWOJZaZRJhr8bU OuFgBhGGQMQLaOoIJ2fF/z9dxbUcOLYu0CaEHVNetJKx8C7V4C0b5tqrI+hjNkNq+mQ5x8 2G+HZgSGsI5B+D3aEntVGEYNZsUZGT4= Received: from suse.cz (unknown [10.100.208.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 6B80D2C142; Tue, 15 Nov 2022 13:22:16 +0000 (UTC) Date: Tue, 15 Nov 2022 14:22:15 +0100 From: Petr Mladek To: John Ogness 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 Message-ID: References: <20221114162932.141883-1-john.ogness@linutronix.de> <20221114162932.141883-32-john.ogness@linutronix.de> <87mt8tfh6x.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87mt8tfh6x.fsf@jogness.linutronix.de> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 On Mon 2022-11-14 20:57:18, John Ogness wrote: > 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... > > > --- 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. Great catch! > It would be nice if we could fold this in. Sorry. I have missed it as well :-/ > 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); With this change: Reviewed-by: Petr Mladek Best Regards, Petr