Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp537975rwr; Thu, 20 Apr 2023 03:04:17 -0700 (PDT) X-Google-Smtp-Source: AKy350Zv7dLpE2JiYMnWQKjNXWv8gV9WfRqRchrVbiXpil4ZDIswXoVJJK2GEEGasqRQa4k32u2A X-Received: by 2002:a05:6a00:1582:b0:63d:4142:1a1b with SMTP id u2-20020a056a00158200b0063d41421a1bmr953789pfk.18.1681985057460; Thu, 20 Apr 2023 03:04:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681985057; cv=none; d=google.com; s=arc-20160816; b=VszpAaaUx07aGJeubhuoaFFbqMU1abjURCLbr3x0NEIx0r+VlX09+s8ug5jH/R/Baq /cLwXC+xq/hPPnUv4hmkmua1hAa5Td0FqujHCUoHlT2LMfNYjzjAvhgyp7TxN03D0Ll/ OxVmG0zihWl9hLemaUamvvCNLtdq80/kChnQF+eR/G1J7+JkWa0DbVPB72JRF3ETNxTP zSuVMpkJQTGoQSAu8H8b2u4q7nG4qGmBZVEJGuhpzs62PESkZk2iyGusRVY8UnoGV3Ae xQBDzVHSTBxvc1+30Oc5aNXxB2zLLSh9lJVwjdNkWB99mzdEGnlYoBVuhxaQFpxsK03T yNeA== 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=0vvHoGcNxYy0uIVHhiSfdEl7TfKiCZrxl8XwTzdSqxg=; b=F5uwJSiFusy9I23pKqHpyIvuaTm6Y+Q1fV9utwntLH+kPaPApmxwnyb9mtCaFjkoIW 9fBSvMLhBIxQ6obqvRCglk4dTwF6izVZZX0xF/seELXffPKkYVCoLYneLHW7+cGcR73J QfRWnfhtTOU+3+Od0oqqldauzap1ddLthf30iJ+YaJSvMR2JKpil0uVbD0sWTqMBFY5J KiS09sr1XOCj9vusOSabb3HRz4C0Cg/1oZZ813A3e9rXio2lex6Lls2yjnnl/bgGiDae vrikkOUhG5HWzqiS3k8mBeETJjETJk3Jj7ImDJjMHzOysK/RXLFHJRv7SKZ6Ea1SMddF LCiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="Klvs/oD/"; 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 i28-20020a63221c000000b0051b85b5a3d1si1222080pgi.127.2023.04.20.03.03.40; Thu, 20 Apr 2023 03:04:17 -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="Klvs/oD/"; 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 S234097AbjDTJz5 (ORCPT + 99 others); Thu, 20 Apr 2023 05:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbjDTJzz (ORCPT ); Thu, 20 Apr 2023 05:55:55 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EB63C0 for ; Thu, 20 Apr 2023 02:55:53 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 44BD31FDB5; Thu, 20 Apr 2023 09:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1681984552; 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=0vvHoGcNxYy0uIVHhiSfdEl7TfKiCZrxl8XwTzdSqxg=; b=Klvs/oD/Xxbv5Dk4ihNbe5aX94iEM0KhBhW57Vx5yjpfjNDOwP0N2S8nTBdNc9KpvYZsOM J3AbL+E+/k2oD9K4KLSzFklRO7EUM0J5JvY/F7LFJzMmgolUGy0yHODAcozx/M8EoXmeDK AggEjEttonMMdKIGg8w67Qm0104AaEU= 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 DA0532C141; Thu, 20 Apr 2023 09:55:51 +0000 (UTC) Date: Thu, 20 Apr 2023 11:55:51 +0200 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: port lock: was: Re: [PATCH printk v1 11/18] printk: nobkl: Introduce printer threads Message-ID: References: <20230302195618.156940-1-john.ogness@linutronix.de> <20230302195618.156940-12-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 On Thu 2023-04-06 11:46:37, Petr Mladek wrote: > On Thu 2023-03-02 21:02:11, John Ogness wrote: > > From: Thomas Gleixner > > > > Add the infrastructure to create a printer thread per console along > > with the required thread function, which is takeover/handover aware. > > > --- a/kernel/printk/printk_nobkl.c > > +++ b/kernel/printk/printk_nobkl.c > > +/** > > + * cons_kthread_func - The printk thread function > > + * @__console: Console to operate on > > + */ > > +static int cons_kthread_func(void *__console) > > +{ > > + struct console *con = __console; > > + struct cons_write_context wctxt = { > > + .ctxt.console = con, > > + .ctxt.prio = CONS_PRIO_NORMAL, > > + .ctxt.thread = 1, > > + }; > > + struct cons_context *ctxt = &ACCESS_PRIVATE(&wctxt, ctxt); > > + unsigned long flags; > > + short con_flags; > > + bool backlog; > > + int cookie; > > + int ret; > > + > > + for (;;) { > > + atomic_inc(&con->kthread_waiting); > > + > > + /* > > + * Provides a full memory barrier vs. cons_kthread_wake(). > > + */ > > + ret = rcuwait_wait_event(&con->rcuwait, > > + cons_kthread_should_wakeup(con, ctxt), > > + TASK_INTERRUPTIBLE); > > + > > + atomic_dec(&con->kthread_waiting); > > + > > + if (kthread_should_stop()) > > + break; > > + > > + /* Wait was interrupted by a spurious signal, go back to sleep */ > > + if (ret) > > + continue; > > + > > + for (;;) { > > + cookie = console_srcu_read_lock(); > > + > > + /* > > + * Ensure this stays on the CPU to make handover and > > + * takeover possible. > > + */ > > + if (con->port_lock) > > + con->port_lock(con, true, &flags); > > IMHO, we should use a more generic name. This should be a lock that > provides full synchronization between con->write() and other > operations on the device used by the console. > > "port_lock" is specific for the serial consoles. IMHO, other consoles > might use another lock. IMHO, tty uses "console_lock" internally for > this purpose. netconsole seems to has "target_list_lock" that might > possible have this purpose, s390 consoles are using sclp_con_lock, > sclp_vt220_lock, or get_ccwdev_lock(raw->cdev). > > > Honestly, I expected that we could replace these locks by > cons_acquire_lock(). I know that the new lock is special: sleeping, > timeouting, allows hand-over by priorities. > > But I think that we might implement cons_acquire_lock() that would always > busy wait without any timeout. And use some "priority" that would > never handover the lock a voluntary way at least not with a voluntary > one. The only difference would be that it is sleeping. But it might > be acceptable in many cases. > > Using the new lock instead of port->lock would allow to remove > the tricks with using spin_trylock() when oops_in_progress is set. > > That said, I am not sure if this is possible without major changes. > For example, in case of serial consoles, it would require touching > the layer using port->lock. > > Also it would requere 1:1 relation between struct console and the output > device lock. I am not sure if it is always the case. On the other > hand, adding some infrastructure for this 1:1 relationship would > help to solve smooth transition from the boot to the real console > driver. > > > OK, let's first define what the two locks are supposed to synchronize. > My understanding is that this patchset uses them the following way: > > + The new lock (atomic_state) is used to serialize emiting > messages between different write contexts. It replaces > the functionality of console_lock. > > It is a per-console sleeping lock, allows voluntary and hars > hand-over using priorities and spinning with a timeout. > > > + The port_lock is used to synchronize various operations > of the console driver/device, like probe, init, exit, > configuration update. > > It is typically a per-console driver/device spin lock. > > > I guess that we would want to keep both locks: > > + it might help to do the rework manageable > > + the sleeping lock might complicate some operations; > raw_spin_lock might be necessary at least on > non-RT system. I forgot to check how these two locks are supposed to be used in write_atomic(). It seems that cons_atomic_flush_con() takes only the new lock (atomic_state) and ignores the port_lock(). It should be safe against write_kthread(). But it is not safe against other operations with the console device that are synchronized only by the port_lock(). This looks like a potential source of problems and regressions. Do I miss something, please? Is there any plan how to deal with this? Best Regards, Petr