Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4051876rwb; Fri, 30 Sep 2022 12:04:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5eNAgMgSSqNr4e4aSj5ZmAudRmJx4kFtWaywwISvAVjMnK4uYY+lavidxz063UvWxfVGmZ X-Received: by 2002:aa7:c9cf:0:b0:452:e416:644d with SMTP id i15-20020aa7c9cf000000b00452e416644dmr8818730edt.163.1664564680867; Fri, 30 Sep 2022 12:04:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664564680; cv=none; d=google.com; s=arc-20160816; b=wQHDDghC8l0azzEt3NwBb+ICWQNhqTbpbKGJDJyj6ukS16xd7eD/qj8+Sw521c2jKh H3LEPc3ds5qfwZkqLZnHN3PQmnOKI/xilw4JZmmKC1U01qXPu86HzmLWs+sgZHho4tik evjPUqy+w09wyjdcl2zp0/HcyYUcFe+2N34Vx0SSJMF2pxhEOuAapXkwB10YkmBAY7nT 0hbObggch0AtVDYjhezq/1m11gBXMPPZPIfBMiFu0i/WDmk2whwkEv8Hkbk+K6CiP2wE fqWd9qpPMuhjCp/idlZrWYM1mT4dF2rpaV0A2WpImt5X6IR39s2UGGYGI/JlCUSdU4CI uzGw== 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=VY+CGNq75eXMTzG8QjYZs4jrMV1oGOoUUANHZTEjaTA=; b=JFBN7HQ6HmsD7+vDLvzK17poeg5HZqCFxJK25gZSPTlsEM/HMcMsN93Q5rqtyvKGu0 hBmCvohU9Ld0M4/xf4R4/Ua9aQMYBbXGWdPW9lWS/wQsBgNX22aG3y4/uK6wFinWlB7Q I3cLz+LeNbbRtd6rsASThWLK6CYw2K9KH7kZ2Dbm4QUicybV9BwtDftnBX75s+64wYpL cnz2V+2NKqxWlcRk+AF2beInIr7TzkiH3o2lLU3E8XqILyAWu6Bpeny7ZTsx1KNUDEip fs/36K299Ht3eMh009oNOSb9D2drGZjxlnBG+fG4B30IhtRg/EKOcMdmE2HeG+R2U50r DR0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=qc3H+b+R; 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 hd40-20020a17090796a800b00731468ef97esi2480100ejc.31.2022.09.30.12.04.15; Fri, 30 Sep 2022 12:04:40 -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=qc3H+b+R; 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 S231718AbiI3SFA (ORCPT + 99 others); Fri, 30 Sep 2022 14:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231817AbiI3SE5 (ORCPT ); Fri, 30 Sep 2022 14:04:57 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2552E3B718 for ; Fri, 30 Sep 2022 11:04:49 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 0E7A8218A8; Fri, 30 Sep 2022 18:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664561088; 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=VY+CGNq75eXMTzG8QjYZs4jrMV1oGOoUUANHZTEjaTA=; b=qc3H+b+RQjR8vPulEcDK8Z7+s7Gj2KfiYnKC86MR1h8tyXc7LuhF3BHyg/0CFnHhvgKdCb 0UtOX6li4tpIfAsJuoB/9IteALHJ+Thl2XU7oyeoxrmuJTzughIy3lJySu7iiswOkr4286 JNH+lZvyyUFYheS2NpBl5Ppeah8nT/M= 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 B3F8E2C161; Fri, 30 Sep 2022 18:04:47 +0000 (UTC) Date: Fri, 30 Sep 2022 20:04:44 +0200 From: Petr Mladek To: John Ogness 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 Message-ID: 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87leq1uev5.fsf@jogness.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 Fri 2022-09-30 16:22:30, John Ogness wrote: > On 2022-09-30, Petr Mladek wrote: > > You know, the more locks we have, the bigger is the risk of > > deadlocks, and the more hacks would be needed in > > console_flush_on_panic(). And I am afraid > > that console_lock() will be with us for many years and > > maybe forever. > > Sure. Removing console_lock() will be a long battle involving many > drivers. I am not trying to fight that battle right now. I just want > console_lock() out of the way of NOBKL consoles. There is some misunderstanding. I am going to think more about your arguments over the weekend. But maybe, the above is important. You want to get cosole_lock() out of the way of NOBLK consoles. What does it exactly mean, please? What code paths are important to achieve this? From my POV, the most important code path is the kthread. But it should use SRCU. I mean that the kthread will take neither cosnole_lock() nor console_list_lock(). Is there any other code path where console_list_lock() will help you to get console_lock() out of the way? From my POV, the proposed code does: register_console() { console_list_lock(); console_lock(); /* manipulate struct console and the console_list */ console_unlock(); console_list_unlock(); } register_console() { console_list_lock(); console_lock(); /* manipulate struct console and the console_list */ console_unlock(); console_list_unlock(); } printk_kthread() { while() { srcu_read_lock(); if (read_flags_srcu()) /* print line */ srcu_read_unlock(); } } vprintk_emit() { /* store message */ if (do_not_allow_sync_mode) return; if (console_trylock()) { console_flush_all(); __console_unlock(); } } some_other_func() { console_list_lock(); /* do something with all registered consoles */ console_list_unlock(); } console_flush_all() { do_something_with_all_consoles(); do_something_else_with_all_consoles(); } What if? do_something_with_all_consoles() { console_list_lock(); /* do something */ console_list_unlock(); } Wait, there is a possible ABBA deadlock because do_something_with_all_consoles() takes console_list_lock() under console_lock(). And register_console() does it the other way around. But it is less obvious because these are different locks. From my POV, both locks serialize the same things (console_list manipulation). SRCU walk should be enough for most iterations over the list. And I do not see which code path would really benefit from having the new console_list_lock() instead of console_lock(). Best Regards, Petr