From patchwork Thu Dec 14 21:41:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178921 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8871577dys; Thu, 14 Dec 2023 13:45:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2p+QZ7+7voLMcrSlxjFtmm5KDwxXzEgNUxB1utLScIs43OQTPF6DBubsrVtCugsWXu4Zb X-Received: by 2002:ad4:5f0f:0:b0:67a:91bf:28f0 with SMTP id fo15-20020ad45f0f000000b0067a91bf28f0mr12667301qvb.16.1702590338128; Thu, 14 Dec 2023 13:45:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590338; cv=none; d=google.com; s=arc-20160816; b=EJgi9G2RIlkFTjD96SkHJT9XRvJkbYXXcIt0V266RCgBKALBQ/h1g7rGo0sLtZ4KWY JUr5VevnJTYzB1s9qvqVSUo4Q1n34g17lAV4mAM3PG5Dq+mwHgk8Oca08OPEOUPjAzei 9MG++3T28T9ZyM6923ZDJtI55w7/cJ+oF6RZR46oHsa8VG61ZDDTT6lba+yqsC+H17J8 JdKqF6/pb4LkHYQe+OTmylJY/b/ewRp4MPr3/ktuoV9T7l8AIVMmUWB1c/lJvZ5qrdZf QEA4BgrNofqRcA+6Gi4Jge9ym6cWzrpmFSZe5vD0wY44x1uIVLgpDgUf2dDGc28qRWdH X+dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=AOpz80KH0gOIPorBUANVFFuEUm2IlzR04QH0UC2n8ec=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=GKdyTtYKWQBhTYs/kIfAwnCX6m0uK4DLQJcQmsBxYcRVIuLETqY9mI+BQA4JrGkmT9 7dtOASyUbCND1bKgxCNOcTSqnGif2X6w0jbHbBrfjD0QUoO6x6zqim59+gW2an3cfWQ4 IVIgS5c3nluiXJyIeA9dB9yCyW2Sq/8nv3rF+7syCWI2hvxfWXoCtiotfYSQmJNJ9klO uqLkq9X+y0JwbK/2pbjdYPalAifKcCf1/O6GlVdzDKL623J+i7dKBXYYjMbP0lYfrWvX YdezllfDX+TNQQVnm6xOaI5qC7XGfPWMDUd3yEvCAKx8P6luX/AXNr316/YutF0bpfQk 38OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3XPgKbTY; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-153-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id dz12-20020ad4588c000000b0067ef8d281bfsi4565524qvb.19.2023.12.14.13.45.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:45:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3XPgKbTY; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-153-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E57461C21D23 for ; Thu, 14 Dec 2023 21:45:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9B512C68D; Thu, 14 Dec 2023 21:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3XPgKbTY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="y8/Gtj27" X-Original-To: linux-kernel@vger.kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42E446E2D9 for ; Thu, 14 Dec 2023 21:42:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702590127; 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=AOpz80KH0gOIPorBUANVFFuEUm2IlzR04QH0UC2n8ec=; b=3XPgKbTYjsOSZZI8Z0yrQGgswsqfMiaE7LTZuoZlvjGuK0QB2uH+6eWXptBrjF0N1QXiNz XZ2QDMG0/8fkf4dRt8pddUR6G1VYuX2DjCbBCMX8gYVUUcM8YnZH9ZNil23NZ3KV7NIEAV oUXhE88cRwHF4MzdPo45kcwPU/vppvgtM8XkZdCtxDkeqEaIw3dD1t/nV6i41/WK7M58fn mGLa4m71D/jZOOCzeKiEbdBbVTAUPUHQqPVz7Rps+6UBq4XFf7GhhrIOAfhAxZ1VMy4mw3 lVw2boR0W/FUVmYQ17ZoQ8oOdAV2wh/pto+a4EDaVr00NGltAoAWE6pvIMEf4w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590127; 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=AOpz80KH0gOIPorBUANVFFuEUm2IlzR04QH0UC2n8ec=; b=y8/Gtj27CBD6NJc0FZUEREShj5VIVtIJaLWUgTsuCtS9F+eakMLN6S2Rqku02qW3KLc87y aGeNAXVmuQ5UbiAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 10/14] printk: ringbuffer: Skip non-finalized records in panic Date: Thu, 14 Dec 2023 22:47:57 +0106 Message-Id: <20231214214201.499426-11-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785295366389041241 X-GMAIL-MSGID: 1785295366389041241 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 Reviewed-by: Petr Mladek --- kernel/printk/printk_ringbuffer.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index b7748d7c44c1..d6ed33683b8b 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -2107,6 +2107,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) @@ -2129,8 +2133,28 @@ 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. + * + * Note that new messages printed on panic CPU are + * finalized when we are here. The only exception + * might be the last message without trailing newline. + * But it would have the sequence number returned + * by "prb_next_reserve_seq() - 1". + */ + if (this_cpu_in_panic() && ((*seq + 1) < prb_next_reserve_seq(rb))) + (*seq)++; + else + return false; } }