Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1994844rwb; Fri, 11 Nov 2022 03:37:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf5wT7yGeEoHJwDo3nfEUKsKQlOipAgGh+DeEOkRCZzoLam/KJqQgj1BCWAZSMQ1R5YrdZpG X-Received: by 2002:a17:902:8d8f:b0:179:f94a:6fda with SMTP id v15-20020a1709028d8f00b00179f94a6fdamr2132925plo.118.1668166651467; Fri, 11 Nov 2022 03:37:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668166651; cv=none; d=google.com; s=arc-20160816; b=Q33yIyGGy8OHysmNcZO7RsE7VZk7CHYi4CFZy6cXT74MmTdQd//aZ30WBOZgLeSB1c 5vL7+Aa8rshHW9g/e5te0ikWgsD99BmGqVdK1Ech0emUS9XsM9fF9Id2MLyziQK1/yJL YQS7lJ0+SKcAMfcpTWQE56nRBTcAppw1Hg/d2ucUO5nh/TTL6UwU7O9zgDWWRR31bvtD ZR7lRC99rs1Q1K8iC5AFIx2tRqtEUvPPz/8e4H7h46rDF8yjPRNne3RvkNeb+0bDThmh K3CL6wyUFMQSKtITqR3lic9Sink/UVXQBzFkU1tzwZd4EdP3GMMV2DJn62gSXzJPG+u8 iANg== 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=6WEAmxBHjoiaTFMT7VLwFHXkqROAYQK5hPFehSseOMw=; b=K4KoTuKfuDjdTDTgbjmCO0zJoz4v2w6U4XgzQh8aVXSlNMKaRft0ZnGwv0zjW0Bqw6 gvkUt72bzcOFkd5+ZUNIbap/4B+U3pjgplHGUKH5Lc6nOX+DlmcKo5hl2EF91MrysvSF bEvBMLfCgSA17kPuuaau34CBOISX25JEVyZGwqRf8WujZNaw/EU0k/AJTaQfSz0qSUAu CRaZlaW9SXfT2S8z1TCtV5rPoRgrmWZGsGUDU2LhH4somfFJoNF2U0r6LYzHP6RJGG6Q Hzs6vv5dWv5OkzAnNNmHpEQ5djZOlOtZJxX2yenp/GCtTXDJF7nnLVqVbypUpI2RiVfb LDFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=rFyyoP0Y; 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 z11-20020aa7888b000000b0055fa098c388si2519632pfe.259.2022.11.11.03.37.19; Fri, 11 Nov 2022 03:37:31 -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=rFyyoP0Y; 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 S233264AbiKKKsI (ORCPT + 92 others); Fri, 11 Nov 2022 05:48:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231681AbiKKKsG (ORCPT ); Fri, 11 Nov 2022 05:48:06 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A538064CF; Fri, 11 Nov 2022 02:48:05 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 4868320199; Fri, 11 Nov 2022 10:48:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1668163684; 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=6WEAmxBHjoiaTFMT7VLwFHXkqROAYQK5hPFehSseOMw=; b=rFyyoP0Yfoo8+wN9p4PS9adB9qj15yDj1qh832osE3tT6fbVlQqKp+AA2zdn2vX/16O6t3 4JjnVaU8nu9z7XBWkvf39A9eNBEboLxOrEtCBfy1txRk7oaDWt3LCwJLsD3+v/y6FMZNRr 0xlDN7KMqZ493cLJ05VM0gSLOo3da9c= 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 CD94A2C143; Fri, 11 Nov 2022 10:48:03 +0000 (UTC) Date: Fri, 11 Nov 2022 11:48:03 +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; One more thing. It would make sense to check that it has really been called under console_list_lock(): lockdep_assert_console_list_lock_held(); > + > + if (!console_is_registered_locked(con)) > + return; > + > + cur_pref_con = console_first(); > + > + /* Already preferred? */ > + if (cur_pref_con == con) > + return; > + Best Regards, Petr