Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1620477img; Wed, 27 Feb 2019 02:32:54 -0800 (PST) X-Google-Smtp-Source: AHgI3IbQMF6jCkb2oQYqNWeyJR4AhbCk7v9+6GE6WRZ21llx+kfmXfgIrIOw+WDTA9I70zzxtG7x X-Received: by 2002:a63:81c1:: with SMTP id t184mr2226285pgd.228.1551263574632; Wed, 27 Feb 2019 02:32:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551263574; cv=none; d=google.com; s=arc-20160816; b=rK/U36FQIke3ddKCmbt+kQi1ckui1BwUIb6/3cI7SGRtNn5I+maJzePsL6mTOKeAAd 8mak4E3ODLyr2PD9Eu9lg/lLWzwzi2fn3qk0wpqTZybJY7o2Qx9YdDQUDkRbBuw+LSJT TsQFZH0DpgZi/LQXUxMQOV7b2608Jov3USt06V3yofF55ws6bKzxSr0glfu9tGF59GQ2 u+TafoX5iQ5lKrOVbLZPvEDhPeH+sQaNNMwDNbxPQBn+DbrTCZoyh5kAZ7TXat02t6Kb OHb/8NCp1K2AqdUyTdiFPKR+cNeoK0bOzor8tJQctb7tSagNKsnyfgsAWUmCDrfKuRrq R98Q== 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=pGsyqmkj/P+9eDuyW2ClXsRfe/nEcQUsSyKT2dL74HY=; b=fEaBSa6SSyvsCMW5SEckaS98BkBQCQFfhyNPRT1OMLdm2X19VU8Ez+YzSdQaCypfiF gJzTe562nJJDrGqLowco/lhqn3NMOKwse0afVO+u+MJJB82JmWmGsbC10odsNJhI1lGI N+AS5q7xBDHqk9qehwhyigzSsdbzZlZihHqXpkM2OFEgugvVJPZJ2vn+5ihs5qOvCFv/ TNNzrCk8vTPGgJI5KCoHN01aQPmM9jpEM3MZ4nwbg015L0D9KmRbklSDd+m26bC8gHOz bt1KU3lY4+2dcPmQEPlsmpRABJKSG/In/nI1ZDkzn9IReXJ3RFHPWRhCKxG8cW1rlak6 MXgw== 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 b25si11375692pgw.424.2019.02.27.02.32.38; Wed, 27 Feb 2019 02:32:54 -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 S1726944AbfB0KcQ (ORCPT + 99 others); Wed, 27 Feb 2019 05:32:16 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:48404 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725993AbfB0KcQ (ORCPT ); Wed, 27 Feb 2019 05:32:16 -0500 Received: from localhost ([127.0.0.1] helo=vostro.local) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1gywVT-0000sI-Ii; Wed, 27 Feb 2019 11:32:07 +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> Date: Wed, 27 Feb 2019 11:32:05 +0100 In-Reply-To: <20190227094655.ecdwhsc2bf5spkqx@pathway.suse.cz> (Petr Mladek's message of "Wed, 27 Feb 2019 10:46:55 +0100") Message-ID: <87zhqhed3u.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. > > It uses console_atomic_lock() added in 18th patch. That one uses > prb_lock() added by 2nd patch. > > Now, prb_lock() allows recursion on the same CPU. But it still needs > to wait until it is released on another CPU. > > [...] > > 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. I could not find any instances where that is the case. nmi_cpu_backtrace() used to do this, but it does not anymore. > But printk() should not make such limitation > to the rest of the system. That is something we have to decide. It is the one factor that makes prb_lock() feel a hell of a lot like BKL. > Not to say, that we would most > likely need to add a lock back into nmi_cpu_backtrace() > to keep the output sane. No. That is why CPU-IDs were added to the output. It is quite sane and easy to read. > Peter Zijlstra several times talked about fully lockless > consoles. He is using the early console for debugging, see > the patchset > https://lkml.kernel.org/r/20170928121823.430053219@infradead.org That is an interesting thread to quote. In that thread Peter actually wrote the exact implementation of prb_lock() as the method to synchronize access to the serial console. > I am not sure if it is always possible. I personally see > the following way: > > 1. Make the printk ring buffer fully lockless. Then we reduce > the problem only to console locking. And we could > have a per-console-driver lock (no the big lock like > prb_lock()). A fully lockless ring buffer is an option. But as you said, it only reduces the window, which is why I decided it is not so important (at least for now). Creating a per-console-driver lock would probably be a good idea anyway as long as we can guarantee the ordering (which shouldn't be a problem as long as emergency console ordering remains fixed and emergency writers always follow that ordering). > 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! John Ogness [0] https://lkml.kernel.org/r/87pnrvs707.fsf@linutronix.de