From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECFF4C77B6D for ; Tue, 28 Mar 2023 13:59:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjC1N7m (ORCPT ); Tue, 28 Mar 2023 09:59:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232957AbjC1N7b (ORCPT ); Tue, 28 Mar 2023 09:59:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D29E7C651; Tue, 28 Mar 2023 06:59:18 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1680011957; 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=AVBcqEYEGKTnf7WGbkGOAukA8G1Pz6BlAEfJJGZegkE=; b=Qr5nmE8Hzfwst5KZgNjYoFM8HsLQhJkEdDi1f8YG7E2l6RW3I42AYUnd3Hj1dvU5eX6ucE GVg+jehpW7GdmqKghuc5lozEBjGFsuvQffCAWB3VU0HXTrToz1MAwJdoVuMf2ANcPXbKco lhCcdky/Da1Db5huCooHTwdeTfILjgiUjH/GDxsXgH1xX15uImZ9mM3zJv67wmrm+jjGUG Q5lPW37rXRdSYabbj2GV/aaDAsbu2UylovBlnI13TApvcR01HhbVh7P9BjmMcZGUuzmuND cShYSAlNbZ04zECY/+957ip3qCIjIt1ZT6CJ0lscZ3Se7Zdb0ZYpmMJkoFl8Jg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1680011957; 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=AVBcqEYEGKTnf7WGbkGOAukA8G1Pz6BlAEfJJGZegkE=; b=XlMGHhzSeLwTANt8K1piDZMwaiCTaHp3KPSQN9MATRV1Z9q5RIO3cVA0Gj8zfnAzt+Fsrk FK/+1PyuIPZ0BcBw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Aaron Tomlin , Luis Chamberlain , kgdb-bugreport@lists.sourceforge.net, Greg Kroah-Hartman , linux-fsdevel@vger.kernel.org, Andrew Morton , "Guilherme G. Piccoli" , David Gow , Tiezhu Yang , Daniel Vetter , tangmeng , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , rcu@vger.kernel.org Subject: Re: locking API: was: [PATCH printk v1 00/18] serial: 8250: implement non-BKL console In-Reply-To: References: <20230302195618.156940-1-john.ogness@linutronix.de> <87wn3zsz5x.fsf@jogness.linutronix.de> Date: Tue, 28 Mar 2023 16:03:36 +0206 Message-ID: <87a5zxger3.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-03-28, Petr Mladek wrote: >> + if (!__serial8250_clear_IER(up, wctxt, &ier)) >> + return false; >> + >> + if (console_exit_unsafe(wctxt)) { >> + can_print = atomic_print_line(up, wctxt); >> + if (!can_print) >> + atomic_console_reacquire(wctxt, &wctxt_init); > > I am trying to review the 9th patch adding console_can_proceed(), > console_enter_unsafe(), console_exit_unsafe() API. And I wanted > to see how the struct cons_write_context was actually used. First off, I need to post the latest version of the 8250-POC patch. It is not officially part of this series and is still going through changes for the PREEMPT_RT tree. I will post the latest version directly after answering this email. > I am confused now. I do not understand the motivation for the extra > @wctxt_init copy and atomic_console_reacquire(). If an atomic context loses ownership while doing certain activities, it may need to re-acquire ownership in order to finish or cleanup what it started. > Why do we need a copy? When ownership is lost, the context is cleared. In order to re-acquire, an original copy of the context is needed. There is no technical reason to clear the context, so maybe the context should not be cleared after a takeover. Otherwise, many drivers will need to implement the "backup copy" solution. > And why we need to reacquire it? In this particular case the context has disabled interrupts. No other context will re-enable interrupts because the driver is implemented such that the one who disables is the one who enables. So this context must re-acquire ownership in order to re-enable interrupts. > My feeling is that it is needed only to call > console_exit_unsafe(wctxt) later. Or do I miss anything? No. It is only about re-enabling interrupts. The concept of unsafe is not really relevant if a hostile takeover during unsafe occurs. In that case it becomes a "hope and pray" effort at the end of panic(). John