Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2971175iog; Mon, 20 Jun 2022 08:31:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u9UWaMWUFPPtQ4fIMaY72xcplYcoCYBm717fX0L/MpCICAPqXbSaOgYmNMGS42c5F1Ju1k X-Received: by 2002:a17:902:d490:b0:167:49df:6e37 with SMTP id c16-20020a170902d49000b0016749df6e37mr24943714plg.50.1655739073700; Mon, 20 Jun 2022 08:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655739073; cv=none; d=google.com; s=arc-20160816; b=x0+KXS6xLOCWaw3awPJbFiy9peV8Cj1YvBAUiWzZlrm3/WvPu6nyw2woEmf4VGCr5j nb6comsOYWbNwRBucqett9ik2rqEwKgVVgYRV89Dz5MOPIVvFibIh0bWPeVqnRsDCpyB gYYolCL4h+f7uGqymDbORa2PKSvF1KnVwMJ2XrVpp6OTCaA039SfxJyIlhPtSz4Ip8on +gUkHAUQ3vWxLSaQaO9sKHCiH2izkKLNpicndw5l9QkmNf7r1+h6di6jTErAOOPp3MSM j7HEO0IPAn8dAUL1nAZKJam4f88rGnc/nQi9ubXT5M49UjevjJppiN2DvvWXcuqe5zVi 58Tg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=SoFB2BpxllfCrWxzKxJln9/E/pmAquuEKo7NBfk0/mo=; b=SmHYBy9QSL7+0uYb/B4rr6v6bDB8jnMUYwIiqmhXjVS/XGAD4oBMEJO172ZdRLjrsz 70/d40uoxiZJTgODgVRHcxILIESwsMcrFu/nIoMCndHK8EGk+6Ovcl9lQr4h0t5UaCQN kzTiSQ8OsWIRrwNIXMKyLBqL3coIoDizwhc9TdepCZ/RLJLc4A1tAQhFxSBo/0j8QzjH o85jIqsqGdsfdZYSwIwT5pH+RqJMA6mWud9jb++u0XYfjT7L93Vg3sxnrevmdGMbia7z FsYv8iaKlWfZwkTOD3ksZnxBA8awi6w9/vWZOQaAE2rt0zR19OC0yJpQz6Jt8TZmMlGQ KiGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=c64UCUWf; 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 g20-20020a056a000b9400b005106eb25aebsi16976356pfj.211.2022.06.20.08.31.01; Mon, 20 Jun 2022 08:31:13 -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=@suse.com header.s=susede1 header.b=c64UCUWf; 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 S244607AbiFTPUq (ORCPT + 99 others); Mon, 20 Jun 2022 11:20:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244576AbiFTPUQ (ORCPT ); Mon, 20 Jun 2022 11:20:16 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22527E08 for ; Mon, 20 Jun 2022 08:14:32 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id D0AD221B35; Mon, 20 Jun 2022 15:14:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1655738070; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SoFB2BpxllfCrWxzKxJln9/E/pmAquuEKo7NBfk0/mo=; b=c64UCUWf/Klbv+y9ypZTy/eWydJDMS8GuKHin38bDkrx44v9oomVEIkxStGW/AmCJUYuSO AEEaLs/+r2fFlSlzXtnB/y4D/Y0zTpRceFppRtyEAPjwv7Z6pG7VatJT7e0AvP7ejaPR5D Y41Ez1RsG0vSMmyanZPOdnyQl1U4OAw= 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 712852C141; Mon, 20 Jun 2022 15:14:29 +0000 (UTC) Date: Mon, 20 Jun 2022 17:14:27 +0200 From: Petr Mladek To: Marek =?iso-8859-1?Q?Beh=FAn?= Cc: Linus Torvalds , John Ogness , Linux Kernel Mailing List , Sergey Senozhatsky , Steven Rostedt , Andy Shevchenko , Rasmus Villemoes , Jan Kara , Peter Zijlstra Subject: [PATCH] printk/console: Enable console kthreads only when there is no boot console left Message-ID: References: <20220619204949.50d9154d@thinkpad> <87r13kwawb.fsf@jogness.linutronix.de> <20220620112936.48fcb2a4@thinkpad> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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,T_SCC_BODY_TEXT_LINE 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 The console kthreads uncovered several races in console drivers. All problems were in situation when a console was being properly initialized and registered while an early console, using the same port, was being used. These problems are pretty hard to debug because they often result into silent boot crashes. It would be nice to fix them but it looks like a can of worms. Prevent these problems by delaying the use of console kthreads after all early consoles are gone. It might later be optimized. But let's close this can of worms with a big hammer for now so that they do not break first impression on the kthreads that solve other real problems. Link: https://lore.kernel.org/r/20220619204949.50d9154d@thinkpad Link: https://lore.kernel.org/r/2a82eae7-a256-f70c-fd82-4e510750906e@samsung.com Reported=by: Marek Beh?n Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b095fb5f5f61..c0c5e2b6b91d 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3551,6 +3551,19 @@ void __init console_init(void) } } +static int __init printk_activate_kthreads(void) +{ + struct console *con; + + console_lock(); + printk_kthreads_available = true; + for_each_console(con) + printk_start_kthread(con); + console_unlock(); + + return 0; +} + /* * Some boot consoles access data that is in the init section and which will * be discarded after the initcalls have been run. To make sure that no code @@ -3567,6 +3580,7 @@ void __init console_init(void) */ static int __init printk_late_init(void) { + bool no_bootcon = true; struct console *con; int ret; @@ -3588,7 +3602,10 @@ static int __init printk_late_init(void) pr_warn("bootconsole [%s%d] uses init memory and must be disabled even before the real one is ready\n", con->name, con->index); unregister_console(con); + continue; } + + no_bootcon = false; } ret = cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL, console_cpu_notify); @@ -3597,23 +3614,18 @@ static int __init printk_late_init(void) console_cpu_notify, NULL); WARN_ON(ret < 0); printk_sysctl_init(); - return 0; -} -late_initcall(printk_late_init); - -static int __init printk_activate_kthreads(void) -{ - struct console *con; - console_lock(); - printk_kthreads_available = true; - for_each_console(con) - printk_start_kthread(con); - console_unlock(); + /* + * Some console drivers are not ready to use the same port with + * boot (early) and normal console in parallel. Stay on the safe + * side and enable kthreads only when there is no boot console. + */ + if (no_bootcon) + printk_activate_kthreads(); return 0; } -early_initcall(printk_activate_kthreads); +late_initcall(printk_late_init); #if defined CONFIG_PRINTK /* If @con is specified, only wait for that console. Otherwise wait for all. */ -- 2.35.3