Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2476929lqp; Sun, 24 Mar 2024 22:32:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX2XowfRx6UkKCr7bhBgNAUS4xdjX4sdYMhWCMWBzdQ5nRVJVHMPxB4bxBq6Mb7lWDABzhrtninuyPnsGoa5kGJcva9mqsCG03cfk8/6A== X-Google-Smtp-Source: AGHT+IE6kYpGpL0KD08YpHDeR4d7o6H+Upc1P0DQOz4yzPC93XHUQ5REi+RBYre/eyII0kMOeEjl X-Received: by 2002:a50:9e64:0:b0:568:ac09:4a5c with SMTP id z91-20020a509e64000000b00568ac094a5cmr4072728ede.11.1711344739047; Sun, 24 Mar 2024 22:32:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711344739; cv=pass; d=google.com; s=arc-20160816; b=nGIiFplrqGn89gq+D2OMqsgnXPn+EtgeiwA+OQxmi6b/dSyJs82dSj00XKh2nABSpz 05UsLxa6HdNgJKCFx4rbtp5XQ8amzBK5EGFgqqxotCpESie4zee9ufX/43Dafk4jrmD4 xyM8oEXRLKBjOSLu5T+Z2CgbRhIxlusyd9LE9eihoQR0S1PFsdun08qxy60KdjsW9vBp NyRXosKXzAGoF58yDdxP6S53wB4L5vAlimZOh/mMrCLgs93+uNhNnoL34wVd8/TE32Hg pNiaOYwMHLILAreT6+c64RPA4ADCdIbubNGF08FxTbZdJei7prpgzSMjsFkNzaVEfUby v6gA== ARC-Message-Signature: i=2; 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:from:dkim-signature; bh=QkJtw4w3hRw6M5q7yR+xYbWjph+g6FcTacAs06TyH/c=; fh=j+aMbK7eLMI2KMaRmGMOCTxfEkIc4TPOnxEcnsSirNc=; b=Fa/sW1ocLHs1EhbOk8T5Uwr+pTHcHOjZa9NsCBN20L2Q4ga2jXHF1jxHeuMvIxde3h Gxu4gpJ5llCh4yf6iBlSk8kqzOhaS+MALu1on2B06j+BCl8x8PPnUew1vGS0kiShny2I Mo4RE6fDVmk3zVQp/hHzss3c8twB09RBwuyGWgn2+F5Z4vUFSK9ZYhv/mLl3fk1pnQPA +CxhNld6TDSfIjXDY4LM/h4G1Jb7VN9Gu8/V5OxUmhRNiKNxmPy7H9q8g4TCf5x/opvL dNOXqbMBUfbDcQ0fGNwxacQx76Z5xoiggEYpxQnAE4E8260SQxO5nVEiKh6KabLBxh7r uTzw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IXe9vofX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113667-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113667-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p15-20020a05640243cf00b0056c08d1d9aasi1087353edc.263.2024.03.24.22.32.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 22:32:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113667-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IXe9vofX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113667-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113667-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id D2C751F30E36 for ; Mon, 25 Mar 2024 05:16:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 051F91DE105; Sun, 24 Mar 2024 22:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IXe9vofX" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6162114430E; Sun, 24 Mar 2024 22:50:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320660; cv=none; b=umTaGDmE/5ZKNWPlLTfoPJM9PjBPAn0CARuXbc/zX3Iz4C0tgDO9qT+gXUocRShQ1XTaKbzBjMORZOn/E2jh2U2AWdnT/7I77OnUR7mkOk605g1es7GhfEQnhIhiRorAHOQJgWNrZ27ifaWWfEaulRIZuXuEqYtB6nQ5FmqJCMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320660; c=relaxed/simple; bh=RN/Gjmnw+EceYASHDrod4BrDl4PiVcldLWDVe0b9138=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g/9UsjaYPuvJFWz1M5NJYtEtgJL3fYva87iEHTdjCOBrDfhfwL0lH5oqnwOOUwWTnwG6pVZ8/++XjVX2jYPbyWVNY0f3tF+Nv/ZKYOHmsjiHnAvZwOKe47w7hbjXNjtNtou387ri1OkmcnoP9RS2QVIZX0Nsqyi7nxYuLHEmHHw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IXe9vofX; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3EA7C433F1; Sun, 24 Mar 2024 22:50:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320659; bh=RN/Gjmnw+EceYASHDrod4BrDl4PiVcldLWDVe0b9138=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IXe9vofXqNG3pBqxy3jcDMPibKXY/VKf4JotUeK4jrpG1ZxZSN8B3N6qTmf13jKyi JHWr4N85OliICnRLTHz2kSg7ihHQj0zTLJu1nqMSARyOLKVF9zuGealaaWLvvqVDaH 2ZztYYIvA5i/9Q0hzlzQ2OR3HFQ5DyhtFfqaXhCLB3GmO9N9TYUC356RJTvwK/V9KL EAY2pRrcZgLMvKizYOmF6zoifvFgmiN9ZwVrfEzfE3Piyi3iWD31wtOgUembSluS5c W3nnyBD7uz6DvuuykhJfChnz4deZs0LmVZlwifFy3FWg3qXCNFCRsyr6BCi0fRo1R2 Yq0oOunGtOjAA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: John Ogness , Petr Mladek , Sasha Levin Subject: [PATCH 6.7 221/713] printk: ringbuffer: Skip non-finalized records in panic Date: Sun, 24 Mar 2024 18:39:07 -0400 Message-ID: <20240324224720.1345309-222-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324224720.1345309-1-sashal@kernel.org> References: <20240324224720.1345309-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: John Ogness [ Upstream commit b1c4c67a5e90db8fbdb5b5504fe16e17b564cca8 ] 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 Link: https://lore.kernel.org/r/20240207134103.1357162-11-john.ogness@linutronix.de Signed-off-by: Petr Mladek Signed-off-by: Sasha Levin --- 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 97ec25d227976..3d98232902cfd 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -2087,6 +2087,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) @@ -2109,8 +2113,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; } } -- 2.43.0