Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7618341rwl; Thu, 23 Mar 2023 06:46:18 -0700 (PDT) X-Google-Smtp-Source: AK7set+DkbAm3ellAvEqqLrwIAhus9/mxT/LceiI8Xq0OZBltRBI7gP5QH+xqw89LzoXgEe0/zJP X-Received: by 2002:aa7:d489:0:b0:4ea:a9b0:a511 with SMTP id b9-20020aa7d489000000b004eaa9b0a511mr9200668edr.37.1679579178690; Thu, 23 Mar 2023 06:46:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679579178; cv=none; d=google.com; s=arc-20160816; b=zCXQz1lahkchP9SdVBuM19ht4q7BC0VjCpDDwT3E8MXe3GG4NjcieuMLF4/i0CCx0X 1zUIsCZmxQQz8E/i37cYgEpJo5igDI1pao2VRJ+1Hy+yroxenzLCWImHZMA2cMghrHqD r66zKslBcqnhiPfQzsUL3c0ovQzpZ1CVF9ri9XEXhOBZ/7rQOp0WpqWqmneq3g2/YztL Nl+X1EeLMbWNo1n6s0taLbzh8TJq9NPt714JKrL84q1MlVW5mbUurZAjc4lmtC24xe9J uDFDFyvZNrnPHCmbcbtDTHvJ1Wbl8B6SqE6mu08XZJRDgsUpD+/STjYELYWKnoz+7eGz e/Gw== 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:in-reply-to:subject :cc:to:dkim-signature:dkim-signature:from; bh=wz8CZAPcIfmrZ68A0HMjB0hfrt/dOSiXceUwjv9ZVHg=; b=xLrvuXuGNf7gPXovAHHwv27xFJ8HU+rfNJHBvIFiGYGnhMPZxlUXPeUSmq54akCE8j qNcqDqmdh/JnIijZ1A8IlrDCVxRw9t8PJJxlUTslLrCXAInUIX+kQcjTX0ceiHfKwKA0 vEX+4JwunHnnuZN6Jt5aUgNfayzmTYtlSSPrmpqN9DeQINibf/No+Ok+h5ZRVLjlwBub UuJadbvGPBvmx4dcDNsocNXFG2FTeSj9TrcGVheURqvOkUc7B+LhjidYtDhel3IkOpg5 Wv6pDHnZH6HnLommJy0pju+/XzBBRvPLifXU4sBTwY1yDUPPFvkyAVQYtoMDmqdv9ZZ9 B7bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=liS1kq1a; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=6UW0OIf1; 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 y8-20020a056402134800b005002c6f2f0asi18815303edw.124.2023.03.23.06.45.53; Thu, 23 Mar 2023 06:46:18 -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=liS1kq1a; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=6UW0OIf1; 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 S230372AbjCWNk0 (ORCPT + 99 others); Thu, 23 Mar 2023 09:40:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbjCWNkY (ORCPT ); Thu, 23 Mar 2023 09:40:24 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8753CC05 for ; Thu, 23 Mar 2023 06:40:23 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1679578821; 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; bh=wz8CZAPcIfmrZ68A0HMjB0hfrt/dOSiXceUwjv9ZVHg=; b=liS1kq1aSyvDxntjynw9h90Z9glCIIx9ZM5NF1O8hS1S0JhBwZt4p4SbG1BLe/iSQe1IIb SaG5rp7vIalY65mlQh5QbKYzFrp4cX3mMjociX3mPu7XtEDGTgkIAfSJXsh0XSYkfhOLy7 qAhufqQy7P/TM75Ut10U54gQT6DKuGVuGRJi/9v0KBfYhNrXIBvAnNyalKNLQfLURvFcS0 b+2QA9/uQ7ANUS0ozlB5Bi2+c38+k4KcgTtViGuL1wOGTZVzXBDdthPaxyBrGiW9uJyUUb Ug/vNZlhLsae49TYzIsVl+LmhfieUHY0xaRue2C2ToHEApmQ+uazDerJlhOEsQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1679578821; 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; bh=wz8CZAPcIfmrZ68A0HMjB0hfrt/dOSiXceUwjv9ZVHg=; b=6UW0OIf1XpOZkmfsnjU4cE+ydQLhXYnwjA/x72JHaL5QNLXW2Nom5VF4+yLeLV3UuDU+/a RoVe5n3QfM4z2ZCw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH printk v1 07/18] printk: nobkl: Add buffer management In-Reply-To: Date: Thu, 23 Mar 2023 14:44:43 +0106 Message-ID: <87y1nna8po.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-1.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-03-21, Petr Mladek wrote: >> +static __ref void cons_context_set_pbufs(struct cons_context *ctxt) >> +{ >> + struct console *con = ctxt->console; >> + >> + /* Thread context or early boot? */ >> + if (ctxt->thread) >> + ctxt->pbufs = con->thread_pbufs; >> + else if (!con->pcpu_data) >> + ctxt->pbufs = &early_cons_ctxt_data.pbufs; >> + else >> + ctxt->pbufs = &(this_cpu_ptr(con->pcpu_data)->pbufs); > > What exactly do we need the per-CPU buffers for, please? > Is it for an early boot or panic or another scenario? In case of hostile takeovers, the panic context needs to have a buffer that the previous context (on another CPU) will not scribble in. Currently, hostile takeovers only occur during panics. In early boot there is only 1 CPU. > I would expect that per-console buffer should be enough. > The per-console atomic lock should define who owns > the per-console buffer. The buffer must be accessed > carefully because any context could loose the atomic lock. A context will string-print its message into the buffer. During the string-print it cannot check if it is still the owner. Another CPU may be already actively printing on that console. > Why is kthread special? I believe the idea was that the kthread is not bound to any CPU. But since migration must be disabled when acquiring the console, there is no purpose for the kthread to have its own buffer. I will remove it. > The per-CPU buffer actually looks dangerous. It might > be used by more NOBKL consoles. How is the access synchronized > please? By console_list_lock? It is not obvious to me. Each console has its own set of per-CPU buffers (con->pcpu_data). > On the contrary, we might need 4 static buffers for the early > boot. For example, one atomic console might start printing > in the normal context. Second atomic console might use > the same static buffer in IRQ context. But the first console > will not realize it because it did not loose the per-CPU > atomic lock when the CPU handled the interrupt.. > Or is this handled another way, please? You are correct! Although I think 3 initdata static buffers should suffice. (2 if the system does not support NMI). Your feedback points out that we are allocating a lot of extra memory for the rare case of a hostile takeover from another CPU when in panic. I suppose it would be enough to have a single dedicated panic buffer to use in this case. With all that in mind, we would have 3 initdata early buffers, a single panic buffer, and per-console buffers. So the function would look something like this: static __ref void cons_context_set_pbufs(struct cons_context *ctxt) { struct console *con = ctxt->console; if (atomic_read(&panic_cpu) == smp_processor_id()) ctxt->pbufs = &panic_ctxt_data.pbufs; else if (con->pbufs) ctxt->pbufs = con->pbufs; else ctxt->pbufs = &early_cons_ctxt_data[early_nbcon_nested].pbufs; } It should be enough to increment @early_nbcon_nested in cons_get_wctxt() and decrement it in a new cons_put_wctxt() that is called after cons_atomic_flush_con(). Originally in tglx's design, hostile takeovers were allowed at any time, which requires the per-CPU data per console. His idea was that the policy about hostile takeovers should be implemented outside the nbcons framework. However, with this newly proposed change in order to avoid per-CPU buffers for every console, we are adding an implicit rule that hostile takeovers only occur at panic. Maybe it is ok to hard-code this particular policy. It would certainly save significant buffer space and I not sure if hostile takeovers make sense outside of a panic context. John