Blame SOURCES/kexec-tools-2.0.20-makedumpfile-2-printk-use-committed-finalized-state-value.patch

c43617
From 44b073b7ec467aee0d7de381d455b8ace1199184 Mon Sep 17 00:00:00 2001
c43617
From: John Ogness <john.ogness@linutronix.de>
c43617
Date: Wed, 25 Nov 2020 10:10:31 +0106
c43617
Subject: [PATCH 2/2] [PATCH 2/2] printk: use committed/finalized state values
c43617
c43617
* Required for kernel 5.10
c43617
c43617
The ringbuffer entries use 2 state values (committed and finalized)
c43617
rather than a single flag to represent being available for reading.
c43617
Copy the definitions and state lookup function directly from the
c43617
kernel source and use the new states.
c43617
c43617
Signed-off-by: John Ogness <john.ogness@linutronix.de>
c43617
---
c43617
 printk.c | 48 +++++++++++++++++++++++++++++++++++++++++-------
c43617
 1 file changed, 41 insertions(+), 7 deletions(-)
c43617
c43617
diff --git a/makedumpfile-1.6.8/printk.c b/makedumpfile-1.6.8/printk.c
c43617
index acffb6c..2af8562 100644
c43617
--- a/makedumpfile-1.6.8/printk.c
c43617
+++ b/makedumpfile-1.6.8/printk.c
c43617
@@ -1,12 +1,6 @@
c43617
 #include "makedumpfile.h"
c43617
 #include <ctype.h>
c43617
 
c43617
-#define DESC_SV_BITS		(sizeof(unsigned long) * 8)
c43617
-#define DESC_COMMITTED_MASK	(1UL << (DESC_SV_BITS - 1))
c43617
-#define DESC_REUSE_MASK		(1UL << (DESC_SV_BITS - 2))
c43617
-#define DESC_FLAGS_MASK		(DESC_COMMITTED_MASK | DESC_REUSE_MASK)
c43617
-#define DESC_ID_MASK		(~DESC_FLAGS_MASK)
c43617
-
c43617
 /* convenience struct for passing many values to helper functions */
c43617
 struct prb_map {
c43617
 	char		*prb;
c43617
@@ -21,12 +15,51 @@ struct prb_map {
c43617
 	char		*text_data;
c43617
 };
c43617
 
c43617
+/*
c43617
+ * desc_state and DESC_* definitions taken from kernel source:
c43617
+ *
c43617
+ * kernel/printk/printk_ringbuffer.h
c43617
+ */
c43617
+
c43617
+/* The possible responses of a descriptor state-query. */
c43617
+enum desc_state {
c43617
+	desc_miss	=  -1,	/* ID mismatch (pseudo state) */
c43617
+	desc_reserved	= 0x0,	/* reserved, in use by writer */
c43617
+	desc_committed	= 0x1,	/* committed by writer, could get reopened */
c43617
+	desc_finalized	= 0x2,	/* committed, no further modification allowed */
c43617
+	desc_reusable	= 0x3,	/* free, not yet used by any writer */
c43617
+};
c43617
+
c43617
+#define DESC_SV_BITS		(sizeof(unsigned long) * 8)
c43617
+#define DESC_FLAGS_SHIFT	(DESC_SV_BITS - 2)
c43617
+#define DESC_FLAGS_MASK		(3UL << DESC_FLAGS_SHIFT)
c43617
+#define DESC_STATE(sv)		(3UL & (sv >> DESC_FLAGS_SHIFT))
c43617
+#define DESC_ID_MASK		(~DESC_FLAGS_MASK)
c43617
+#define DESC_ID(sv)		((sv) & DESC_ID_MASK)
c43617
+
c43617
+/*
c43617
+ * get_desc_state() taken from kernel source:
c43617
+ *
c43617
+ * kernel/printk/printk_ringbuffer.c
c43617
+ */
c43617
+
c43617
+/* Query the state of a descriptor. */
c43617
+static enum desc_state get_desc_state(unsigned long id,
c43617
+				      unsigned long state_val)
c43617
+{
c43617
+	if (id != DESC_ID(state_val))
c43617
+		return desc_miss;
c43617
+
c43617
+	return DESC_STATE(state_val);
c43617
+}
c43617
+
c43617
 static void
c43617
 dump_record(struct prb_map *m, unsigned long id)
c43617
 {
c43617
 	unsigned long long ts_nsec;
c43617
 	unsigned long state_var;
c43617
 	unsigned short text_len;
c43617
+	enum desc_state state;
c43617
 	unsigned long begin;
c43617
 	unsigned long next;
c43617
 	char buf[BUFSIZE];
c43617
@@ -45,7 +78,8 @@ dump_record(struct prb_map *m, unsigned long id)
c43617
 
c43617
 	/* skip non-committed record */
c43617
 	state_var = ULONG(desc + OFFSET(prb_desc.state_var) + OFFSET(atomic_long_t.counter));
c43617
-	if ((state_var & DESC_FLAGS_MASK) != DESC_COMMITTED_MASK)
c43617
+	state = get_desc_state(id, state_var);
c43617
+	if (state != desc_committed && state != desc_finalized)
c43617
 		return;
c43617
 
c43617
 	begin = ULONG(desc + OFFSET(prb_desc.text_blk_lpos) + OFFSET(prb_data_blk_lpos.begin)) %
c43617
-- 
c43617
2.31.1
c43617