Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2575663rdb; Fri, 22 Sep 2023 02:43:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG175OQpI9y1ZYuxkdtUfIa0je+C7LpXtmwfRdu8mf8hhZ+9YAuwq/BvGf/+IPrTDd+77zj X-Received: by 2002:aa7:88d2:0:b0:68c:59cb:2dd9 with SMTP id k18-20020aa788d2000000b0068c59cb2dd9mr3391535pff.1.1695375836824; Fri, 22 Sep 2023 02:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695375836; cv=none; d=google.com; s=arc-20160816; b=TBEju+2g4pF60roTI9BLZCu4pft05wnfTSL9ky8bhLvKkJhtMAExfkzuNMYl+UWEcn JC1TaKkv/gszVCF8IECvAJSkGKB8N54z33XW2gqwy6EaZVYM8OKtATlHH/Oe/+TxQoqC mMbe5/u8TvcgpN5nDDNYVYDSoSNvRJKbfzpXWYvdzYUMLCKV99A82J2ebMQ0plZaClxo QdoMXJntP4eUuICp2AEuwmFJzYjNH3Yi0s3kHcccWciEUmyYbhzvxwRTVAgR5KnNB0b7 ShL/LJxJTptCxUdod3qN6+YzVgqEkqRXkT5+bBibW/S76Fo5b/HcS/Nn3EK44XfNWpmd GhWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/oT88nNiQNdO60Vz7Y3YIUI4gJHlhQxjqQ04Nk/WTPQ=; fh=T9VKCl0Ppm30gx9lQfMQ2aUeZhDNLmq6BNwiKx9E8/w=; b=E8+N3w0GQWExeXg7fH0lRRhVUCQOEPosc1qZ3NKyNiSP1L4XJoVzvo7jH/fOxXmrP8 vaAp0MLjWUtb9Q+dOP0rD4k4ya6UklE/9ifSKJEZYM6fxBMffKnr2XJJvVGTEpP31Geh 78XD2F4PSkmURWE++wPrCZ7cO/tf8PRDHsPSu+j5YT+MmEDqGVFUE+Ts9+hwqdfY53YK RBTQrHdjXNSc/VJ9Lq7mGpQhXJEAWNkjWgrDwq/Z51rvNIYdAKphTb45guNtnKMQKY7D xmotonvepDmoA5w9d01TS1UdIRLeo7AuCAmd6hn/YXhtaXqCa20e/2xVWdkdaEYBqVFv Bmiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=qHzDnWtQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id y127-20020a62ce85000000b00686b62a6dc4si3373030pfg.145.2023.09.22.02.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 02:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=qHzDnWtQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9FAFF81DFD67; Fri, 22 Sep 2023 02:34:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233018AbjIVJeQ (ORCPT + 99 others); Fri, 22 Sep 2023 05:34:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233014AbjIVJeA (ORCPT ); Fri, 22 Sep 2023 05:34:00 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C385ACD2 for ; Fri, 22 Sep 2023 02:33:53 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 6DA581F461; Fri, 22 Sep 2023 09:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1695375232; h=from:from:reply-to: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=/oT88nNiQNdO60Vz7Y3YIUI4gJHlhQxjqQ04Nk/WTPQ=; b=qHzDnWtQsHr42UNv1vhtX0ug8W76HeSkVJvl4raHZMJYDu8vrcHuMjDjSdhVzkdr9EgmNV USWJihfu0JJwkcE/6rMy0wr2TnDSuB5iSHYmqT0lzUp9KCXJO2taQYbTqhedij7sdXwPQG gtYzO9dG0cfJh2TFsbgOf1li5GOx//M= Received: from suse.cz (pmladek.udp.ovpn2.prg.suse.de [10.100.201.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 150202C142; Fri, 22 Sep 2023 09:33:52 +0000 (UTC) Date: Fri, 22 Sep 2023 11:33:51 +0200 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH printk v2 04/11] printk: nbcon: Provide functions to mark atomic write sections Message-ID: References: <20230919230856.661435-1-john.ogness@linutronix.de> <20230919230856.661435-5-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230919230856.661435-5-john.ogness@linutronix.de> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 22 Sep 2023 02:34:16 -0700 (PDT) On Wed 2023-09-20 01:14:49, John Ogness wrote: > From: Thomas Gleixner > > WARN/OOPS/PANIC require printing out immediately since the > regular printing method (and in the future, the printing > threads) might not be able to run. > > Add per-CPU state to denote the priority/urgency of the output > and provide functions to mark the beginning and end of sections > where the urgent messages are generated. > > Note that when a CPU is in a priority elevated state, flushing > only occurs when dropping back to a lower priority. This allows > the full set of printk records (WARN/OOPS/PANIC output) to be > stored in the ringbuffer before beginning to flush the backlog. The above paragraph is a bit confusing. The code added by this patch does not do any flushing. I guess that this last paragraph is supposed to explain why the "nesting" array is needed. I would write something like: "The state also counts nesting of printing contexts per-priority. It will be later used to prevent flushing in nested contexts." That said, I am not sure if the special handling of nested contexts is needed. But let's discuss it in the patch introducing the flush funtions. > --- a/kernel/printk/nbcon.c > +++ b/kernel/printk/nbcon.c > @@ -961,6 +961,95 @@ static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt) > return nbcon_context_exit_unsafe(ctxt); > } > > +/** > + * struct nbcon_cpu_state - Per CPU printk context state > + * @prio: The current context priority level > + * @nesting: Per priority nest counter > + */ > +struct nbcon_cpu_state { > + enum nbcon_prio prio; > + int nesting[NBCON_PRIO_MAX]; > +}; > + > +static DEFINE_PER_CPU(struct nbcon_cpu_state, nbcon_pcpu_state); > +static struct nbcon_cpu_state early_nbcon_pcpu_state __initdata; > + > +/** > + * nbcon_get_cpu_state - Get the per CPU console state pointer > + * > + * Returns either a pointer to the per CPU state of the current CPU or to > + * the init data state during early boot. > + */ > +static __ref struct nbcon_cpu_state *nbcon_get_cpu_state(void) > +{ > + if (!printk_percpu_data_ready()) > + return &early_nbcon_pcpu_state; My first thought, was that this was racy. I was afraid that printk_percpu_data_ready() could change value inside atomit_enter()/exit() area. But it actually could not happen. Anyway, it might worth a comment. Something like: /* * The value of __printk_percpu_data_ready is modified in normal * context. As a result it could never change inside a nbcon * atomic context. */ if (!printk_percpu_data_ready()) return &early_nbcon_pcpu_state; > + > + return this_cpu_ptr(&nbcon_pcpu_state); > +} > + > +/** > + * nbcon_atomic_exit - Exit a context that enforces atomic printing > + * @prio: Priority of the context to leave > + * @prev_prio: Priority of the previous context for restore > + * > + * Context: Any context. Enables migration. > + * > + * @prev_prio is the priority returned by the corresponding > + * nbcon_atomic_enter(). > + */ > +void nbcon_atomic_exit(enum nbcon_prio prio, enum nbcon_prio prev_prio) > +{ > + struct nbcon_cpu_state *cpu_state; > + > + cpu_state = nbcon_get_cpu_state(); I would add a consistency check: WARN_ON_ONCE(cpu_state->nesting[cpu_state->prio] <= 0) > + /* > + * Undo the nesting of nbcon_atomic_enter() at the CPU state > + * priority. > + */ > + cpu_state->nesting[cpu_state->prio]--; > + > + /* > + * Restore the previous priority, which was returned by > + * nbcon_atomic_enter(). > + */ > + cpu_state->prio = prev_prio; > + > + migrate_enable(); > +} Best Regards, Petr