Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp945949rwb; Thu, 10 Nov 2022 09:12:39 -0800 (PST) X-Google-Smtp-Source: AMsMyM4+/1xw9bmF/QDCc/TiaEPfNvaGpeSj2UJzd9cuXj6TQlNWOwtZK/SlcviTqGUucesN1tt3 X-Received: by 2002:a17:902:e84a:b0:186:ba52:1dc7 with SMTP id t10-20020a170902e84a00b00186ba521dc7mr1533046plg.41.1668100358889; Thu, 10 Nov 2022 09:12:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668100358; cv=none; d=google.com; s=arc-20160816; b=LNDdNEsV/tGAj0ftYpa8hSOEYq8q25weJuNhmphuZq9TfTI2e8t9rv4l0OOEWcZ8Dd 5zC85x8GXDwOW8+IDcJEcYuZLi0Uvwwoi/7MxN9p7W2o+g+LbhbIb4AuGg7pCMdEwAry 7XgKe/IAL3/YkZO79mS0QAihFavID98xC0DR+jtox/jTqlSNXx8IIAExOtAnVsZYHKpz cmDd+xuIGw1roEuehz2PYNl1grlBBEZS81+nGs5vNDLwRX/4mWNFfHJkoFjr30Elu/Vw Uct4pRh5eIYW6+TvvqAsRMjrATlNsufY1pbQLsgzufmC5ynPShlmYT6ho+Tys5RpLZXO nJ4A== 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=bEnHdqT3DcxO4MFxMqMVX1EoQDRxqFNIevVZKsxI/LU=; b=B94mlEuz7tYt2nS+YLFXVG4cSediisSMBXjGjxz1GRpy71XAgqG5yYee8/HyfPqGW0 rUqTwHt5RbBcjoiCbP3yZEqrqGtZHmgpw0FitzKe2JczV95tko4QP8YIOU9MKi5kYHI1 ioZRgx/B5Aj4xl5Y6IvnIRM9Z39s67lIe9/tDdd02nhwKuJXd/xhZwXb3tQ8Qo/bwCIy xVyk9cQm1XmltbRbZAEC++fMX+w7kOvVpFAIIghcjEcefFu2jmzSeiju9q4GZINbTrIq yTBoRATvHFXoIsrlFYu8aaQtZUynDoO/rHwZhM6pOQiGFXNkd3TVsObj9qJC6aX/Ea8L x5yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=oeljd555; 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 z1-20020a056a00240100b0056ed0d3538csi20629840pfh.311.2022.11.10.09.12.25; Thu, 10 Nov 2022 09:12:38 -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=oeljd555; 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 S230183AbiKJPfD (ORCPT + 92 others); Thu, 10 Nov 2022 10:35:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbiKJPen (ORCPT ); Thu, 10 Nov 2022 10:34:43 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EBB76307; Thu, 10 Nov 2022 07:34:33 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id F11F01FB23; Thu, 10 Nov 2022 15:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1668094471; 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=bEnHdqT3DcxO4MFxMqMVX1EoQDRxqFNIevVZKsxI/LU=; b=oeljd555OxLi7NkR4t4QIAONG3HeiofBo3qDfkpKApXXFzPPSuFTVvdTbmHaHfD+5pvN0K k8yIVvOdjerAWOH9reqwqRHFL91yEnyVYozzgEqXgVyxW5DfV0oy7Mo1lpOEeNXWxzvdtS HGPa2+4O2MEJLyq0fZ44v+PZcohZDgc= Received: from suse.cz (unknown [10.100.201.202]) (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 A89862C141; Thu, 10 Nov 2022 15:34:31 +0000 (UTC) Date: Thu, 10 Nov 2022 16:34:31 +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 v3 33/40] printk, xen: fbfront: create/use safe function for forcing preferred Message-ID: References: <20221107141638.3790965-1-john.ogness@linutronix.de> <20221107141638.3790965-34-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221107141638.3790965-34-john.ogness@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-07 15:22:31, John Ogness wrote: > With commit 9e124fe16ff2("xen: Enable console tty by default in domU > if it's not a dummy") a hack was implemented to make sure that the > tty console remains the console behind the /dev/console device. The > main problem with the hack is that, after getting the console pointer > to the tty console, it is assumed the pointer is still valid after > releasing the console_sem. This assumption is incorrect and unsafe. > > Make the hack safe by introducing a new function > console_force_preferred_locked() and perform the full operation > under the console_list_lock. > > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -3457,6 +3458,43 @@ 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; > + > + hlist_del_init_rcu(&con->node); We actually should re-initialize the node only after all existing console list walks are finished. Se we should use here: 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. The comment is right ;-) > + */ > + synchronize_srcu(&console_srcu); > + > + con->flags |= CON_CONSDEV; > + WARN_ON(!con->device); > + > + /* Only the new head can have CON_CONSDEV set. */ > + WRITE_ONCE(cur_pref_con->flags, cur_pref_con->flags & ~CON_CONSDEV); As mentioned in the reply for 7th patch, I would prefer to hide this WRITE_ONCE into a wrapper, e.g. console_set_flag(). It might also check that the console_list_lock is taken... > + hlist_add_behind_rcu(&con->node, console_list.first); > +} > +EXPORT_SYMBOL(console_force_preferred_locked); > + > /* > * Initialize the console device. This is called *early*, so > * we can't necessarily depend on lots of kernel help here. Best Regards, Petr