From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org
Subject: [PATCH printk v2 3/4] printk: Skip unfinalized records in panic
Date: Fri, 13 Oct 2023 22:49:39 +0206 [thread overview]
Message-ID: <20231013204340.1112036-4-john.ogness@linutronix.de> (raw)
In-Reply-To: <20231013204340.1112036-1-john.ogness@linutronix.de>
Normally a reader will stop once reaching an unfinalized 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 unfinalized records. This results in panic()
not flushing the panic messages.
Add a special case to printk_get_next_message() to allow
skipping over unfinalized records if on the panic CPU.
Also refine the documentation of the ringbuffer reading
functions to clarify that failure may also be due to an
unfinalized record.
Fixes: 896fbe20b4e2 ("printk: use the lockless ringbuffer")
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
kernel/printk/printk.c | 15 +++++++++++++--
kernel/printk/printk_ringbuffer.c | 9 +++++----
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 19b752880879..56d9b4acbbf2 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2813,8 +2813,19 @@ static bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
else
prb_rec_init_rd(&r, &info, outbuf, outbuf_sz);
- if (!prb_read_valid(prb, seq, &r))
- return false;
+ while (!prb_read_valid(prb, seq, &r)) {
+ if (this_cpu_in_panic() && seq < prb_next_seq(prb)) {
+ /*
+ * The record @seq is not finalized and there may be
+ * more records in the ringbuffer. Since this is the
+ * panic CPU, skip over the unfinalized record and
+ * try to read a finalized record that may follow.
+ */
+ seq++;
+ } else {
+ return false;
+ }
+ }
pmsg->seq = r.info->seq;
pmsg->dropped = r.info->seq - seq;
diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
index 2dc4d5a1f1ff..1bbc008109ef 100644
--- a/kernel/printk/printk_ringbuffer.c
+++ b/kernel/printk/printk_ringbuffer.c
@@ -1876,8 +1876,9 @@ static u64 prb_first_seq(struct printk_ringbuffer *rb)
}
/*
- * Non-blocking read of a record. Updates @seq to the last finalized record
- * (which may have no data available).
+ * Non-blocking read of a record. Updates @seq to the record that was read
+ * (which may have no data available) or was attempted to be read (in case
+ * it was unfinalized or non-existent).
*
* See the description of prb_read_valid() and prb_read_valid_info()
* for details.
@@ -1932,7 +1933,7 @@ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq,
* On success, the reader must check r->info.seq to see which record was
* actually read. This allows the reader to detect dropped records.
*
- * Failure means @seq refers to a not yet written record.
+ * Failure means @seq refers to a not yet finalized or non-existing record.
*/
bool prb_read_valid(struct printk_ringbuffer *rb, u64 seq,
struct printk_record *r)
@@ -1962,7 +1963,7 @@ bool prb_read_valid(struct printk_ringbuffer *rb, u64 seq,
* On success, the reader must check info->seq to see which record meta data
* was actually read. This allows the reader to detect dropped records.
*
- * Failure means @seq refers to a not yet written record.
+ * Failure means @seq refers to a not yet finalized or non-existing record.
*/
bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq,
struct printk_info *info, unsigned int *line_count)
--
2.39.2
next prev parent reply other threads:[~2023-10-13 20:43 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-13 20:43 [PATCH printk v2 0/4] fix console flushing on panic John Ogness
2023-10-13 20:43 ` [PATCH printk v2 1/4] printk: For @suppress_panic_printk check other panic John Ogness
2023-10-16 13:05 ` Petr Mladek
2023-10-13 20:43 ` [PATCH printk v2 2/4] printk: Add this_cpu_in_panic() John Ogness
2023-10-16 13:14 ` Petr Mladek
2023-10-13 20:43 ` John Ogness [this message]
2023-10-17 11:27 ` [PATCH printk v2 3/4] printk: Skip unfinalized records in panic Petr Mladek
2023-10-17 21:25 ` John Ogness
2023-10-18 8:24 ` John Ogness
2023-10-18 13:15 ` Petr Mladek
2023-10-18 12:54 ` Petr Mladek
2023-10-18 13:45 ` John Ogness
2023-10-18 15:27 ` Petr Mladek
2023-10-18 15:50 ` John Ogness
2023-10-19 10:29 ` Petr Mladek
2023-10-18 14:20 ` Petr Mladek
2023-10-23 9:53 ` John Ogness
2023-10-13 20:43 ` [PATCH printk v2 4/4] printk: Ignore waiter on panic John Ogness
2023-10-18 9:56 ` Petr Mladek
2023-10-23 9:15 ` John Ogness
2023-10-13 20:46 ` [PATCH printk v2 0/4] fix console flushing " John Ogness
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231013204340.1112036-4-john.ogness@linutronix.de \
--to=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.