Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp375738lqg; Fri, 1 Mar 2024 07:50:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV31CI6LOIgQ6eWmA6oiT7tgK+97XvQQR71XEeTSaZ2aAsWdtmoCSa/2K1XWWEanomGZqnpUD6qXYHuxXxM7qiUGuCFgV5rToRaDuh0LA== X-Google-Smtp-Source: AGHT+IHSnzZMZBSJZMZHrPoe24OjsURQVab8HXA76QFkOqEQMz23eVzmF7Mw8lcieC8OqGUtuvAa X-Received: by 2002:a05:6a00:8d4a:b0:6e5:d66b:bf29 with SMTP id il10-20020a056a008d4a00b006e5d66bbf29mr564231pfb.34.1709308205372; Fri, 01 Mar 2024 07:50:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709308205; cv=pass; d=google.com; s=arc-20160816; b=msJynoqZLZHQrgknld80WjGfMBmt9oIYUYWpF+U7QooopAlf4oZ+RmMIr4Jo2Lf5Y0 aiCpfcAl5nVxJyUbYS9IdN2CeaVlkNithwlESpUtfAqjDqJ7rwsOpEHTHInMfdLihUz+ oXTX3Xd23g0wa3DQG+FjjmofZ6xY+HSopnO1uo8AsVmg6+Vd/quysB6lJ4wU5SZYDx8L YGEgVSwC4Swd2Oo2HwsphrYb4uq6fj7ymbJ8BrvlGnuPiUb4Kpiv+5MS7jahKvHulCuQ ktX8Mz7hESBcHuTXQTEo2hMkKIFf9MPwBk6YJGzEC3igKBRVli5jIcKDLfQZt6wLEXKS LX+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=VUzFdeN53i9tXm7MXEexoS0+mcu1uT+SkLKy7PDIFlc=; fh=m2UxXxYrXbkRRnQ1zvb78ESJgU7SEawkRfVb5KmsbU4=; b=RBEGb+yry29tGrFRLDVIKdV054nJNUtIWfp+dQpqEMvvqL7lGP1JED76lOYtXD+ygH QCOKRdfiPxCVffRaT0dulh6UufSDuyWttTVY2HazKWJfazbjUI4YTNVBnwf2eYQdbLZX S03jjxDT4590+FBoShDJqUBGth1OaSV65f1LLU4o2xiE6hCeZw3OCgWozr80VMnMbawd aSQ4vUnl/sL+qOD411TGvyV8vchUSSdP9U78Obh2JsXTScO4boTRg8/MWKyoZgcKJ82K wuW1EqtGzXlecXZfHFl31xXO2dX4FbdWIgc3GLyPQLMJHu6NUEXYiv818buuqcZHU2ok ttSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=EZod3tO4; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-88639-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88639-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w19-20020aa78593000000b006e5078ce5f5si3580743pfn.35.2024.03.01.07.50.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 07:50:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88639-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=EZod3tO4; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-88639-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88639-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B0ACC28501D for ; Fri, 1 Mar 2024 15:50:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D1BB70033; Fri, 1 Mar 2024 15:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="EZod3tO4" Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4B0C1F95F for ; Fri, 1 Mar 2024 15:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709308198; cv=none; b=KaByxJybsC+36zUy3IcY6Is1fHkKpyA3TuFU9TVRlIFIL0hOG/BfI4rEkjvu3xHEWBrHsJPIAw/mj5D/i5OgRYzTvp7OPPNMyp60JeaWQ7G1HbrWzv5NgNOJxMuB24dIv0eXdgMWRZ6X2Pzp/bmsx3+ymKnMaJj/MHiNhrqqhuY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709308198; c=relaxed/simple; bh=B32SD+v2fJY1qKDCGPDCH8R7sgMnBptIxaY0yF0bLMo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KsY830At50USrlfPK+3sFq1DbQMJYeNOKk6QrOyNdXhIk4H77sp+1s5Vn/T6o9e/ahZMFXIEntjtKij7cIY4rGbYQv5HPPzYasRWxneeptXIKkJmMlmj3Z0LZI9DotcSHSLE+h5mys++7QpH5WB5hX5v1PMJ89ygrgvWSWyRjSE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=EZod3tO4; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a4429c556efso377018366b.0 for ; Fri, 01 Mar 2024 07:49:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1709308194; x=1709912994; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VUzFdeN53i9tXm7MXEexoS0+mcu1uT+SkLKy7PDIFlc=; b=EZod3tO4AhibPQ7p5z5JbIj+zA7STJOz/jBKKK1u/YnYLAQx37SJcDA32vgwVt0WU6 2GO3lpzHnE0uK3Q37rjdRiJHKmsvCTJCqWq/k+03qBZmxLZUjjk+YAa9cuUKQBlld7F7 ShEIsUkKKMnvG7a2TGQvmbZPIHWWHrrvcDYnO9y07y/vVkD07Xnll9ddCNIicCz1zJyJ DuqVKXMvCSWqUKVHRIggEBbqiI9tBMR5W16w17C9xQpfWc7ulQpBkgqYUEux5TD8/AD4 /KxoDGP7nhJixoV4q/b7cDYwX4afTxMCWcgMj/+pru4qCnPqV8ndQMV279fkKtIwuOS7 +4hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709308194; x=1709912994; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=VUzFdeN53i9tXm7MXEexoS0+mcu1uT+SkLKy7PDIFlc=; b=EE0peiEeXGCblvmSCp2HUA9s8VH0frDD1Q7SDmJ8SLIhDjG6P6pvQz8I0HuYxrr1Md NnOIBqGmU5r1Dzq06sXWgKCndVmwZansXgYJhe/yHnP5W7kJAdg72i3yGJkk89w8sgb4 Jz+lazf7gyFcvE4+DAELBBUKLRR+mBKFPV2EMOn+DkTx6/u5VsfrniYMFo8hdCQw6eZQ ujTnseuzJRPycQnqYEBhd6V+XAUID1/4OvRJ95hN28mrAAkrsMsp4HBvQqMFMkTcindY K+QS5NliXJituEvd7Xjf0LdlmwcE9BvG0RNGldqDKv4N60OJU/zE6FgStXMNXXXdn2bm E+Yw== X-Forwarded-Encrypted: i=1; AJvYcCXs+6BuQFjRgQ7RKjem+GGrlcbwKfakVqXyTLQ2NwlTGqwZ/RBe/RpVl45AdALX358J0yxvNcmv2XSWk7KlJM51t4XqMh6QYhvtHUga X-Gm-Message-State: AOJu0YwSQS7nCOOs928LaVhTGsts/gLGUk2Jy0Eze292I4Z/V8ZHVmKX ZhVq/bXtPna0XaA29Cs+ASbd+7GDXKroAaTx2Jkf0SwMxsOwefGmS1a2JhrjvLg= X-Received: by 2002:a17:906:4148:b0:a44:f89:a04e with SMTP id l8-20020a170906414800b00a440f89a04emr1878722ejk.35.1709308194170; Fri, 01 Mar 2024 07:49:54 -0800 (PST) Received: from alley ([176.114.240.50]) by smtp.gmail.com with ESMTPSA id vw3-20020a170907a70300b00a42ee2af521sm1795253ejc.137.2024.03.01.07.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 07:49:53 -0800 (PST) Date: Fri, 1 Mar 2024 16:49:52 +0100 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: flush was: Re: [PATCH printk v2 22/26] printk: nbcon: Implement emergency sections Message-ID: References: <20240218185726.1994771-1-john.ogness@linutronix.de> <20240218185726.1994771-23-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240218185726.1994771-23-john.ogness@linutronix.de> On Sun 2024-02-18 20:03:22, John Ogness wrote: > From: Thomas Gleixner > > In emergency situations (something has gone wrong but the > system continues to operate), usually important information > (such as a backtrace) is generated via printk(). Each > individual printk record has little meaning. It is the > collection of printk messages that is most often needed by > developers and users. > > In order to help ensure that the collection of printk messages > in an emergency situation are all stored to the ringbuffer as > quickly as possible, disable console output for that CPU while > it is in the emergency situation. When exiting the emergency > situation, trigger the consoles to be flushed. > > Add per-CPU emergency nesting tracking because an emergency > can arise while in an emergency situation. > > Add functions to mark the beginning and end of emergency > sections where the urgent messages are generated. > > Do not print if the current CPU is in an emergency state. > > Trigger console flushing when exiting all emergency nesting. > > Note that the emergency state is not system-wide. While one CPU > is in an emergency state, another CPU may continue to print > console messages. > > --- a/kernel/printk/nbcon.c > +++ b/kernel/printk/nbcon.c > @@ -1105,6 +1134,58 @@ void nbcon_atomic_flush_unsafe(void) > __nbcon_atomic_flush_all(prb_next_reserve_seq(prb), true); > } > > +/** > + * nbcon_cpu_emergency_enter - Enter an emergency section where printk() > + * messages for that CPU are only stored > + * > + * Upon exiting the emergency section, all stored messages are flushed. > + * > + * Context: Any context. Disables preemption. > + * > + * When within an emergency section, no printing occurs on that CPU. This > + * is to allow all emergency messages to be dumped into the ringbuffer before > + * flushing the ringbuffer. The actual printing occurs when exiting the > + * outermost emergency section. > + */ > +void nbcon_cpu_emergency_enter(void) > +{ > + unsigned int *cpu_emergency_nesting; > + > + preempt_disable(); > + > + cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting(); > + (*cpu_emergency_nesting)++; > +} > + > +/** > + * nbcon_cpu_emergency_exit - Exit an emergency section and flush the > + * stored messages > + * > + * Flushing only occurs when exiting all nesting for the CPU. > + * > + * Context: Any context. Enables preemption. > + */ > +void nbcon_cpu_emergency_exit(void) > +{ > + unsigned int *cpu_emergency_nesting; > + bool do_trigger_flush = false; > + > + cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting(); > + > + WARN_ON_ONCE(*cpu_emergency_nesting == 0); > + > + if (*cpu_emergency_nesting == 1) > + do_trigger_flush = true; > + > + /* Undo the nesting count of nbcon_cpu_emergency_enter(). */ > + (*cpu_emergency_nesting)--; > + > + preempt_enable(); > + > + if (do_trigger_flush) > + printk_trigger_flush(); Just an idea. printk_trigger_flush() calls defer_console_output(). It always moves the flushing into IRQ context. It might make sense to add a flush() function which would try to flush the messages directly from this context and queue the IRQ work only when it fails. Something like: void printk_emergency_flush() { /* nbcon consoles could be flushed in any context. */ if (have_nbcon_console) nbcon_flush_all(); if (have_legacy_console) { if (console_trylock()) console_unlock(); else defer_console_output(); } } But wait, nbcon_flush_all() might have troubles to get the per-console lock because it would be called with NBCON_PRIO_NORMAL. Wait, wait, wait. defer_console_output() schedules wake_up_klogd_work_func(). It flushes only legacy consoles. It means that even emergency messages would need to wait for the printk kthread. By other words, it seems that the emergency context does not have any effect for nbcon consoles. It brings a question if any code would need to acquire the emergency context at all. I quess that this does not work as expected. Or do I miss anything, please? Best Regards, Petr