Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5579934imb; Thu, 7 Mar 2019 20:06:41 -0800 (PST) X-Google-Smtp-Source: APXvYqwaLaWLg86MdRokZWQlmgPFyiRy37vo9qVROL9dFrNfEA+k20nLCAWo0/YfBcMV11s727GX X-Received: by 2002:a17:902:2947:: with SMTP id g65mr16525362plb.258.1552018001766; Thu, 07 Mar 2019 20:06:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552018001; cv=none; d=google.com; s=arc-20160816; b=EV+M5DcL5K55oyU57f0BhwNtFiglwLT8rR/h6u1fITc7F3dXOifl0i8W1Ape/TTaUQ 6Nct0IxA7+aAIrS+fb5crTpf+rVPzQexqc3LBz67NuyxEJ5rfPG9Zi5YUOB76e6cQ8KQ FQUkCAZ5jqHGY59G218LRJa+t0PmO9OF/SkP5tyvbT4vVna2OM6ZuqCJ2jH9RvEyOZVE bVc1a4lwH6tlpChZrxQEg5OorF78EVE0HuGamje5YL/eY/2XLiaZ+Fbu+h9zGV96v6Os g5uZnCiwkSggA8DidmPD607aJ3mNhqxWYBR+UzqWOfpfms2YAwEh7Gt70kvTDZg86B1g xTTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=SgAq/4bylhDldQa36bq3k84AD7WCkkp//u8Hn6U1anw=; b=jDV7W72TAE8Tjbh1+fzu+3biPEr5quGOdXHzHWGFuYS/FD9nXAVyMsg6SoMa2h1ujk 9htO/CVn7mPESvV2ZibFrPHwRNRqXy0BzjGhfde80kPFcRrRX/Tong04jVET4sxFiV0n oHFhL7oKx5u86yd5gCfeW42Wz4cMZVf4xWOsjyBX/w++6w9n8hvrvS3kToyTocaLiYF/ TYlyffV0bye9j0dFevuknivgJJDoJ6I4W4P9fH81P/pXA3kbzo8D7SYfT02szLRmFFhR ZQgeZIuNCV9OqRvimJ/CGQy6rLshg/qrClf1XyHXteCMccgX/aOFVh3WK6d3oDOBfzVh QkFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s75si5772090pfa.217.2019.03.07.20.06.26; Thu, 07 Mar 2019 20:06:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726338AbfCHEFa (ORCPT + 99 others); Thu, 7 Mar 2019 23:05:30 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:59512 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726266AbfCHEF3 (ORCPT ); Thu, 7 Mar 2019 23:05:29 -0500 Received: from localhost ([127.0.0.1] helo=vostro.local) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1h26l0-0000gS-F1; Fri, 08 Mar 2019 05:05:14 +0100 From: John Ogness To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Sergey Senozhatsky , Steven Rostedt , Daniel Wang , Andrew Morton , Linus Torvalds , Greg Kroah-Hartman , Alan Cox , Jiri Slaby , Peter Feiner , linux-serial@vger.kernel.org, Sergey Senozhatsky Subject: Re: [RFC PATCH v1 20/25] serial: 8250: implement write_atomic References: <20190212143003.48446-1-john.ogness@linutronix.de> <20190212143003.48446-21-john.ogness@linutronix.de> <20190227094655.ecdwhsc2bf5spkqx@pathway.suse.cz> <87zhqhed3u.fsf@linutronix.de> <20190227135504.gqtcsdwpy4rd7xvs@pathway.suse.cz> Date: Fri, 08 Mar 2019 05:05:12 +0100 In-Reply-To: <20190227135504.gqtcsdwpy4rd7xvs@pathway.suse.cz> (Petr Mladek's message of "Wed, 27 Feb 2019 14:55:04 +0100") Message-ID: <87a7i6ovt3.fsf@linutronix.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-02-27, Petr Mladek wrote: >>>> Implement a non-sleeping NMI-safe write_atomic console function in >>>> order to support emergency printk messages. >>> >>> OK, it would be safe when prb_lock() is the only lock taken >>> in the NMI handler. >> >> Which is the case. As I wrote to you already [0], NMI contexts are >> _never_ allowed to do things that rely on waiting forever for other >> CPUs. > > Who says _never_? I agree that it is not reasonable. But the > history shows that it happens. Right, which is why it would need to become policy. The emergency messages (aka write_atomic) introduce a new requirement to the kernel because this callback must be callable from any context. The console drivers must have some way of synchronizing. The CPU-reentrant spin lock is the only solution I am aware of. > In principle, there is nothing wrong in using spinlock in NMI > when it is used only in NMI. The CPU-reentrant spin lock _will_ be used in NMI context and potentially could be used from any line of NMI code (if, for example, a panic is triggered). The problem is when you have 2 different spin locks in NMI context and their ordering cannot be guaranteed. And since I am introducing an implicit spin lock that potentially could be locked from any line of code, any explicit use of a spin lock in NMI could would really be adding a 2nd spin lock and thus deadlock potential. If the ringbuffer was fully lockless, we should be able to have per-console CPU-reentrant spin locks as long as the ordering is preserved, which I expect shouldn't be a problem. If any NMI context needed a spin lock for its own purposes, it would need to use the CPU-reentrant spin lock of the first console so as to preserve the ordering in case of a panic. >>> 2. I am afraid that we need to add some locking between CPUs >>> to avoid mixing characters from directly printed messages. >> >> That is exactly what console_atomic_lock() (actually prb_lock) is! > > Sure. But it should not be a common lock for the ring buffer and > all consoles. As long as the ring buffer requires a CPU-reentrant spin lock, I expect that it _must_ be a common lock for all. Consider the situation that the ring buffer writer code causes a panic. I think it is beneficial if at least 1 level of printk recursion is supported so that even these backtraces make it out on the emergency consoles. If the ring buffer becomes fully lockless, then we could move to per-console CPU-reentrant spin locks. John Ogness