Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3325292rwb; Mon, 3 Oct 2022 13:09:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7VvKEcNmZ0qjJe3WxKa62inGQnfvVErAbjvdjCyvEsad9W8QNTaxsWA1O0nr6ug7/EjFHV X-Received: by 2002:a63:ce17:0:b0:42a:bfb6:f218 with SMTP id y23-20020a63ce17000000b0042abfb6f218mr19867337pgf.484.1664827773570; Mon, 03 Oct 2022 13:09:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664827773; cv=none; d=google.com; s=arc-20160816; b=vsfoh6I+95sqp5qHDlurSuFkpezWSUDkq3RTik7uCdQ7MfLXgf9aI47sAfoydsaRH3 Q/DKfk+6fEKM8yJ5Tf1PXPyisIjubWnw/Csrq0hobXOtE+4gxrEctOPdfahDejAFjoy4 0ym4vPABJtGmtQQORgCAZ/gAh7UtPwjKegJCs64Shj2NFpA2nYzOenIEsVaYwM0S8Jut NNBDcWNyvZo/30xm/8AJADHAwj1916IullWp+4Cmm9fZItosO8w+GqNDjIHEPnlg/WZU CvSsjMbgDwrQsII5ETI7nBnomAQuCTg7Ki26zWr9PTcaNYuDFuCb96+SeCE/7SUHHhp7 bUuw== 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=vH1bRlNlt4Tw6mif6Nwjb+aJreUS4CF9rty//8uLA3U=; b=wIKR5QqIzhrJdqIhqmbkpIG90yu4dnvFKwsR+5RGuxZcDQBCBRC7H4AsHOuj00WIly uH4OxW4P7EaMN9wrraYQj9HE6yDSoqhYXfevbtTGqOXAZMfnhtwfh46g41VJ365EE9Ba ev/ZB1hF2OT2+FjBJ9tq+NT6tnt6Q9Ir3NEdsqh61PjYvR5d9m5hYq/OhrouoXu+CoWF TO/yKAmX7F8HxR4IExCXrja6qhgq3cgz/Knby9+tUOHxotJ/y/QgpAjLBECcHtTgcdvD iC9kMsYpnDcpANRUlojkf5/Je0QTJXeVhZbzFoAjDX0ShRUY1gG95ytkMUN/7gDdvwKf KjkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wevujbBs; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=uULqQ0bx; 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 w3-20020a63f503000000b0042b57ff2893si10590395pgh.195.2022.10.03.13.09.21; Mon, 03 Oct 2022 13:09:33 -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=@linutronix.de header.s=2020 header.b=wevujbBs; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=uULqQ0bx; 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 S229802AbiJCTfi (ORCPT + 99 others); Mon, 3 Oct 2022 15:35:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229934AbiJCTf0 (ORCPT ); Mon, 3 Oct 2022 15:35:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6D9DFAED for ; Mon, 3 Oct 2022 12:35:25 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1664825722; 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=vH1bRlNlt4Tw6mif6Nwjb+aJreUS4CF9rty//8uLA3U=; b=wevujbBshGkiBkMMID2lz+ppLj/tbyfBMRm0Mt0BvGikHT0UEuXp7xMbcuUnzOxUdEraFO 5fnKF2GVeYy9PL4sRoXBhQbnWcWkWBA1AQUo99CVlo8Ssvcf490c3LT8cEmSHXiyr6OMqN deySq+Io4YSSmVcyU+gI/x/pugNKAzJAo7UUJD0+H7oU9SojvwYFviu3iASRxr7iBU38+O RKOyMXonXDEtMRMGTob1HlF/GSi2CtG5CzNLVi0D/ikvtqZOt70FHC97tK3JSdzbLcHw59 Gnx2L1V6MxqkY6e231cwq82R0AgQ83lRXdK/CY4AejDWgT83d4IN4W/+68SGHg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1664825722; 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=vH1bRlNlt4Tw6mif6Nwjb+aJreUS4CF9rty//8uLA3U=; b=uULqQ0bxjPYQW78dimlbXHSh8SM9Kj/rhwvsuJBHNVhU1yWFLc3OQlkxTUFxOobpGCCHr4 AWOLK70m8OsceoDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH printk 06/18] printk: Protect [un]register_console() with a mutex In-Reply-To: References: <20220924000454.3319186-1-john.ogness@linutronix.de> <20220924000454.3319186-7-john.ogness@linutronix.de> <87mtajkqvu.fsf@jogness.linutronix.de> <87leq1uev5.fsf@jogness.linutronix.de> <87zgeg7gnb.fsf@jogness.linutronix.de> Date: Mon, 03 Oct 2022 21:41:22 +0206 Message-ID: <87a66c66px.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-10-03, Petr Mladek wrote: > What is exactly wrong with console_lock, please? It is ambiguously performing multiple tasks: - protecting the console list - protecting individual console fields - serializing console printing - stopping all console printing That last item is actually quite complex because nobody really knows _why_ all consoles need to be stopped. It is mostly because fbdev is using the console_lock to protect itself from its own write() callback. But (as has been mentioned in this thread) there are other code sites where we are not sure which part of the above tasks it is used for and why. > Is the main problem that it is a semaphore? A semaphore has been needed because we are performing global locking for ambiguous reasons in all possible contexts. We should be using fine-grained lock and synchronization mechanisms that are appropriate for their used contexts to precisely lock/synchronize exactly what needs to be locked/synchronized. Your first question is literally, "what is wrong with a BKL". And the answer to that is: A BKL is preventing us from optimizing the kernel by decoupling unrelated activities. > The above proposal suggests that it might be something like: > > register_console() > { > console_list_lock(); > > if (!need_console()) > goto out; > > if (!try_enable_console()) > goto out; > > if (!(con->flags & CON_NOBLK)) > console_lock() Why are you taking the console_lock here? The console_list_lock needs to replace this responsibility. I realize the RFC and this v1 series does not do this. For v2, it will be clear. > add_console_into_the_list(); > > if (!(con->flags & CON_NOBLK)) > console_unlock() I would request that you continue reviewing the later patches in the series. Particularly 13-18. My v2 will involve a significantly reworked version of patches 6-12, not only changing the order of presentation, but also explicitly removing console list update protection by the console_lock. I think having actual code to discuss will greatly help us continue this discussion. Patches 13-18 will not change much for v2, unless I get some feedback otherwise. John