Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2096590rwb; Mon, 7 Nov 2022 09:06:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf4GqDoNdpCZ5R3XQ+xcsSELscbxf2WweWsKB3IC1+ikJT/g2qt1JIPI6XCUFZsvnsk5xmX5 X-Received: by 2002:a17:906:4c92:b0:7ae:5a45:a732 with SMTP id q18-20020a1709064c9200b007ae5a45a732mr10922181eju.18.1667840807977; Mon, 07 Nov 2022 09:06:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667840807; cv=none; d=google.com; s=arc-20160816; b=a6jempE/nQS9dsf+aHYhrhtA1dJMe5xOzQiuaLP3kZLu/CBPs1tCchmJUzZOXp1DOr n4qwDORp9z/HaqELo+p+DthzXRbT0cwVBzsQ3ZrCGGCPAfcU86lRHRY4UxZBMQ+qKj3z OrWWvgwTItcz2FnDyELfh+Q5tk1MSp71INtXY89AfkW7Zrg3LhbUbtT6K6sTxAdbUM0/ oSv4ZdR4g64HW6USsLlFb47tfbXjk4wQ3TENTRtvUZ8v5LLw45UDYcWjzeKCCdY9cv6j VkoquHMLI6oKeenSiS5cYhyk/FWUiJHFQwJS7DNiEov5sRIaP4Qe52Pxo/hJaqOG1C/v 1PWw== 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=L4sUpwP8dk3i0wHw3GqyNgDqqSt5iy8yfrZ+H4hTCuM=; b=r3V8egIo3ZLhLtZbqi8bmBD+wWn9h4KteU0fGCDjhvCtud2crOJVggwwpE5iRnTp1L w81cSr4VIjj1K/eKoA+19CD9L6X3mqklCGaQIqZSN2MdbTrlytE9Uy4ki/H6a/dAHmRm /Ntn5AlRo6c3FQnam4+Zv9ilNufFyrQdEKJCKpLAE5z1S1UzE6MqTyzdcMXG+5+Or0q/ nwt7/kUK07oA4CqiOm04pUDPVy276f/PgwrdEH7FYrOOvS0kG7Q0OMm/coh/ysQGh2pJ Oscr+1SzG5gEVlPQF40VyG7Y0lcNKttoiVevnSs2u5csa62MencE5QU1sgRpEp6yEXKj +Ckw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=z7MSggwv; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bimstmKx; 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 hq35-20020a1709073f2300b007add269f2c4si11240559ejc.740.2022.11.07.09.06.17; Mon, 07 Nov 2022 09:06:47 -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=z7MSggwv; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bimstmKx; 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 S232517AbiKGQc5 (ORCPT + 92 others); Mon, 7 Nov 2022 11:32:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232494AbiKGQce (ORCPT ); Mon, 7 Nov 2022 11:32:34 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39B642656E for ; Mon, 7 Nov 2022 08:30:51 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667838649; 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=L4sUpwP8dk3i0wHw3GqyNgDqqSt5iy8yfrZ+H4hTCuM=; b=z7MSggwv/tpw0jOGQo4tlAQlF0EFYw7CE/SANbF/+wjfeGKkqWFYut1T+THTKM9CY6XM7E wpLqJ6K9YcpDKElYc1lkZU9Mb741nqad4crQt6atRYIma2frV5yBvMlNJIrw8UZU15EDi+ JQfYKU3UO2GHeE172C/5ehi2N0Cynsb74/iL1+xdYPllyYRjXg4RzLuAm3BsR5nFe31IZv gK3tNpG2q7IAR5jhGK72ylbfo8LRbCfGMBwWKRDLeWuvROBfr+BvqpB/gIiUacZGTD4k9W bQHxo7cWXINEWazlvLsq3M5fzS0fY1FOaiy03g6/mebo1zv58NLCvNzXf6kk5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667838649; 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=L4sUpwP8dk3i0wHw3GqyNgDqqSt5iy8yfrZ+H4hTCuM=; b=bimstmKxlVRzf6FmJc/1c4t/+NiaiolMrCbZMj68Le8FWkdj25yVnqE5BplMjnEeEnGjmR /Tz+vzxxDlKWQODA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH printk v3 39/40] printk: relieve console_lock of list synchronization duties In-Reply-To: <20221107141638.3790965-40-john.ogness@linutronix.de> References: <20221107141638.3790965-1-john.ogness@linutronix.de> <20221107141638.3790965-40-john.ogness@linutronix.de> Date: Mon, 07 Nov 2022 17:36:48 +0106 Message-ID: <87r0ye916v.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 On 2022-11-07, John Ogness wrote: > @@ -3344,7 +3340,6 @@ void register_console(struct console *newcon) > * Put this console in the list - keep the > * preferred driver at the head of the list. > */ > - console_lock(); > if (hlist_empty(&console_list)) { > /* Ensure CON_CONSDEV is always set for the head. */ > newcon->flags |= CON_CONSDEV; > @@ -3358,7 +3353,6 @@ void register_console(struct console *newcon) > } else { > hlist_add_behind_rcu(&newcon->node, console_list.first); > } > - console_unlock(); > > /* > * No need to synchronize SRCU here! The caller does not rely I just realized that because of the new @seq initialization (patch 5/40) that we cannot completely remove the console_lock from register_console(). It will still be needed for @seq synchronization when registering non-boot/non-printbuffer consoles. So something like the patch below will need to be folded into this one. I am not happy with this. If an enabled boot console is behind, the console_unlock() will probably catch it up and we will end up with some repeat messages. But maybe this is "good enough" until we implement some real coordination between boot console and normal console takeovers. John Ogness diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 17765166ac42..bb119001df56 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3328,12 +3328,21 @@ void register_console(struct console *newcon) * that message instead. That boot console will be * unregistered shortly and may be the same device. */ + + /* + * Hold the console_lock to guarantee safe access to + * console->seq. + */ + console_lock(); + for_each_console(con) { if ((con->flags & (CON_BOOT | CON_ENABLED)) == (CON_BOOT | CON_ENABLED) && con->seq < newcon->seq) { newcon->seq = con->seq; } } + + console_unlock(); } /*