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

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