From patchwork Mon Nov 6 21:07:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 162197 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2928414vqu; Mon, 6 Nov 2023 13:08:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkztvXW4zx4VwIiNYsSF1P3ssRR6RApSYIjPXnNVFwvMCuGjFr+S//KF2PyqmNhKCN9/Gq X-Received: by 2002:a54:4e8c:0:b0:3b2:e60d:27e3 with SMTP id c12-20020a544e8c000000b003b2e60d27e3mr29342934oiy.30.1699304917261; Mon, 06 Nov 2023 13:08:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699304917; cv=none; d=google.com; s=arc-20160816; b=AyjE/SeYUoCgqAS60VRvY3Ot+h78AULuKnXS9CcP0KR5sdvBNsz3O4asXbV0oRrSN3 H6FBEkTz+fiV1FytUS48Am+SMElzxFQypcTCAubuIqzp+rk68ACrna34CJHWVAqQgJOo qEWTexVNEFXtKmeOKFQQqsMEQDZzCW1MdhnFCvc45k7EgVmouqxUl2MER2EvdNHtor/3 SqUI+k3q24bSFlQ258zvkgE2uuFy9LDsGILZqidio4pfhHRb2mTETdOq59VFU5wUEXlB GXOvuvhx7sq0VyL2tn8nRXE1alnUIFoeV32M9kO9Oa4POkDLmXHDiwTsq5Zm2HABCs2d STZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=gPyZTcWZWhXXvYtKbCYSzlUC2oh3LgQ1z4Pk6pXNprY=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=r0jb2jU5mjIvYqC8nuSxPWeW1+q0zX1S8Yj44RQRtD5CnU9Nwv9FddenAC5FQ51Apk 5MGr2HMJxJemDyDdmCHy0HtBk5sRzds4/723eAh8T0nAbfnCnhI0nlRPy9cAbhPAWmI5 pMbcKZ2NzIN/TwFcmTynydXnX+8m2R8JoURa/sjaQT7hXvdezF3lO8qbRgvl5GLeGDSp 2a9cvofYs4cobFxhH4WcQqJRDswhO9VpF57RisvEx8To/T/Hysh/ORiruTOpsikSiXnX tIWdXDfoB22yQzuxiNRoOhwKaDO7WkxH7BpkQOczcyUCI9seQU+Kl+9LYKB9DNCiSrY8 YZJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JiSkeIhK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id fa15-20020a056a002d0f00b006935df3019esi8978792pfb.235.2023.11.06.13.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 13:08:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JiSkeIhK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 631288048E7B; Mon, 6 Nov 2023 13:08:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233191AbjKFVH5 (ORCPT + 34 others); Mon, 6 Nov 2023 16:07:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233110AbjKFVHk (ORCPT ); Mon, 6 Nov 2023 16:07:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DAFAD75 for ; Mon, 6 Nov 2023 13:07:38 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1699304855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gPyZTcWZWhXXvYtKbCYSzlUC2oh3LgQ1z4Pk6pXNprY=; b=JiSkeIhKiFvecS2FXzSEnPYPxGF/LN+OykA0vVJaX1Q93NZlyyXg/o98rXaFU+8hcdtPZM 7EonEjJzEiMLX+gD9ZBIB+cNXvR0yRgSTc4ctPifNmogqolc8y7pyMW/WxCrXAJt/1JT/B EDS8mYvTBp6DoBgri33uPStc3KKUaSjqvXFWValpM9Vcs/SK79Yg4W1XN10UE2ALuE6zwV upeHCakfbHiKt2rF4V1c/tuxH83VzGSX/Z2hRy3mdfCzBl47TMpAKdSjX3mQqI8ORYXLhg ERVNPeJDQk1R2ORZcaqyFdVWl+hE7D4StmRdsSmksY1BBjnXvKlp85R2JSoM8g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1699304855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gPyZTcWZWhXXvYtKbCYSzlUC2oh3LgQ1z4Pk6pXNprY=; b=yFI+fvbcrINRbTXEB4WeODLJn6Vn4DYrIh3V7Z7kHof5vRGsQCN1/t6qrayYoKMVVkGGzv 6OwczLGJ8aIDuqCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 7/9] printk: Skip non-finalized records in panic Date: Mon, 6 Nov 2023 22:13:28 +0106 Message-Id: <20231106210730.115192-8-john.ogness@linutronix.de> In-Reply-To: <20231106210730.115192-1-john.ogness@linutronix.de> References: <20231106210730.115192-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Mon, 06 Nov 2023 13:08:25 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781850352812205811 X-GMAIL-MSGID: 1781850352812205811 Normally a reader will stop once reaching a non-finalized record. However, when a panic happens, writers from other CPUs (or an interrupted context on the panic CPU) may have been writing a record and were unable to finalize it. The panic CPU will reserve/commit/finalize its panic records, but these will be located after the non-finalized records. This results in panic() not flushing the panic messages. Extend _prb_read_valid() to skip over non-finalized records if on the panic CPU. Fixes: 896fbe20b4e2 ("printk: use the lockless ringbuffer") Signed-off-by: John Ogness --- kernel/printk/printk_ringbuffer.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index dc83569d3a3a..584d2b213876 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -2116,6 +2116,10 @@ u64 prb_next_reserve_seq(struct printk_ringbuffer *rb) * * On failure @seq is updated to a record that is not yet available to the * reader, but it will be the next record available to the reader. + * + * Note: When the current CPU is in panic, this function will skip over any + * non-existent/non-finalized records in order to allow the panic CPU + * to print any and all records that have been finalized. */ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq, struct printk_record *r, unsigned int *line_count) @@ -2138,8 +2142,22 @@ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq, (*seq)++; } else { - /* Non-existent/non-finalized record. Must stop. */ - return false; + /* + * Non-existent/non-finalized record. Must stop. + * + * For panic situations it cannot be expected that + * non-finalized records will become finalized. But + * there may be other finalized records beyond that + * need to be printed for a panic situation. If this + * is the panic CPU, skip this + * non-existent/non-finalized record unless it is + * at or beyond the head, in which case it is not + * possible to continue. + */ + if (this_cpu_in_panic() && ((*seq + 1) < prb_next_reserve_seq(rb))) + (*seq)++; + else + return false; } }