Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2341187rwl; Thu, 13 Apr 2023 05:19:36 -0700 (PDT) X-Google-Smtp-Source: AKy350blBLpVIoH6HyyHDGcbCYU7g3jf01S7k9tz08WNagNFgRmLXwC8pHiQEBLV2Tw8GtgzE2TL X-Received: by 2002:a17:90a:470e:b0:246:da2a:49be with SMTP id h14-20020a17090a470e00b00246da2a49bemr1809487pjg.20.1681388376638; Thu, 13 Apr 2023 05:19:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681388376; cv=none; d=google.com; s=arc-20160816; b=iP4qpnAaIJGizWKf+H5hBRWUSmo2v+vaqxS5RIWA5ww95LqGhqMk4HLiM8OWNN2Wj4 ar5MbCvuOShCqg+jHpLQt+waB0rgDnU2qQr3Tpq1XUUhSZIHG3Te7SCILPZtvwvDKRx4 MhfJk37E7ylmp/UajVC35h2+tIa4JmX91aN/BCl+xthadFoZd/maEZX8TQ6uokIPY9cY BgcBSgjQcPdePGYGwQ/rP7HqAtfQfhiAnHLhgtYVJeNxDaGBJzq5nGPRi38rDXfBr6gE 6fiGOjW+dtaNF/DvumYdj3yUudnK4RrqoZ62NJShbCRT7NnSwHwofQUNyN6cur3tliem FYxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=B8+nVKITZkaZhX5qchviUfDT0l6q7J7IjVYSeriSWWc=; b=yZC/ieOmRjse809r3ClI6UdwGgNJd4BGHHkb4EWT2Tzncmw7oAHa0kPMP0JQiEdEte HKBD58hODM8kqavFMkG8pwZXe8zB37/i7XFUQp4yFHKLOG463XmJjGCtF2VXwhBW/rwA G4AOuZ+OGtqv5SOM7vfKRVGgIxk2+avwveG4menRzoP42OrF4MRvBW7VkGsT7OoGKCnR qDBvMOueluB7hNnLubDNhGFmlLOtItH2+8U0FwJto7IcGku32ibI0r0m7JtdNKh2fZBG b8oxPdZNh3QU6uKbsyCTdztg7xuLrrPVj/BTSR4P/b3j7s8e0o42Nbn4mVhMSkNdNWMT fx1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MyKYLr2X; dkim=neutral (no key) header.i=@linutronix.de; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m19-20020a170902bb9300b001a5d5b97c74si1889455pls.259.2023.04.13.05.19.24; Thu, 13 Apr 2023 05:19:36 -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=@linutronix.de header.s=2020 header.b=MyKYLr2X; dkim=neutral (no key) header.i=@linutronix.de; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229936AbjDMMP0 (ORCPT + 99 others); Thu, 13 Apr 2023 08:15:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230009AbjDMMPO (ORCPT ); Thu, 13 Apr 2023 08:15:14 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 330F072A8 for ; Thu, 13 Apr 2023 05:15:08 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1681388106; 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=B8+nVKITZkaZhX5qchviUfDT0l6q7J7IjVYSeriSWWc=; b=MyKYLr2XbSRKxtTEtLuQUkdmgKnD5AMrgY7jJTpbo9QzkQ1909ga/hQSzXP7bxY1gMNcl/ O9zwRy2ltwTn6uuImxUrdrtrQW2BXD4LZ2b3UykAP7j6E26A5YYi/WRrWKgF5TwKFBfefZ vlmTfPurVJWuJh7nXcrCL6HOJ6wsc0rDRPYZ/wKe58Y0deQTDtKOO6972BlELV/Cgs7Oxu H1cgIkLhH5e9WzcYgoDu7eul7lthsw+G59ptr4KSyaSI1Bhu8VS220zLi3Ij/uHVofw3eJ Hi9vrOASZTZNS4NecD4NTnb77vZqcvJ9UsEf9PBV+Du200rbzQsEiRlg+be9GQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1681388106; 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=B8+nVKITZkaZhX5qchviUfDT0l6q7J7IjVYSeriSWWc=; b=1PrtC0cyfYTClBUFVLuQoUrdmL2kQfcddFGeh3Zf8vjzYqbPRseemYhEPoSJRr33tHzTRr m5vBhvtB8iUMhuBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Andrew Morton , "Guilherme G. Piccoli" , Luis Chamberlain , David Gow , Tiezhu Yang , Daniel Vetter , tangmeng Subject: Re: [PATCH printk v1 16/18] kernel/panic: Add atomic write enforcement to warn/panic In-Reply-To: References: <20230302195618.156940-1-john.ogness@linutronix.de> <20230302195618.156940-17-john.ogness@linutronix.de> Date: Thu, 13 Apr 2023 14:19:13 +0206 Message-ID: <87h6tk3rqe.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 2023-04-13, Petr Mladek wrote: >> --- a/kernel/panic.c >> +++ b/kernel/panic.c >> @@ -329,6 +332,8 @@ void panic(const char *fmt, ...) >> if (_crash_kexec_post_notifiers) >> __crash_kexec(NULL); >> >> + cons_atomic_flush(NULL, true); > > Do we need to explicitly flush the messages here? This is where the atomic printing actually starts (after the full dump has been inserted into the ringbuffer). > cons_atomic_flush() is called also from vprintk_emit(). And there are > many messages printed with the PANIC priority above. vprintk_emit() does not print in this case. From cons_atomic_flush(): /* * When in an elevated priority, the printk() calls are not * individually flushed. This is to allow the full output to * be dumped to the ringbuffer before starting with printing * the backlog. */ if (cpu_state->prio > NBCON_PRIO_NORMAL && printk_caller_wctxt) return; > This makes an assumption that either printk() in PANIC context > does not try to show the messages immediately or that this > explicit console_atomic_flush() tries harder. I think > that both assumptions are wrong. Both assumptions are correct, because until this point there has been no effort to print. >> @@ -353,6 +358,7 @@ void panic(const char *fmt, ...) >> * We can't use the "normal" timers since we just panicked. >> */ >> pr_emerg("Rebooting in %d seconds..\n", panic_timeout); >> + cons_atomic_flush(NULL, true); > > Same here. This flush is just to make sure the rebooting message is output. For nbcon consoles printk() calls are never synchronous except for during early boot (before kthreads are ready). The same goes for the other cons_atomic_flush() calls in this function. >> disabled_wait(); >> #endif >> pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf); >> >> /* Do not scroll important messages printed above */ >> suppress_printk = 1; >> + >> + cons_atomic_exit(CONS_PRIO_PANIC, prev_prio); > > On the contrary, I would explicitly call cons_atomic_flush(NULL, false) > here instead of hiding it in cons_atomic_exit(). It is not hiding there. That is the semantic. After entering an atomic block all printk's are only writing to the ringbuffer. On exiting the atomic block the ringbuffer is flushed via atomic printing. Exiting CONS_PRIO_PANIC has a special condition that it first tries to safely flush all consoles, then will try the unsafe variant for consoles that were not flushed. > Also I think that we want to set the EMERGENCY prio also in > oops_enter()? Agreed. John