import kexec-tools-2.0.20-59.el8

This commit is contained in:
CentOS Sources 2021-10-20 04:21:19 +00:00 committed by Stepan Oksanichenko
parent c9234c7b2a
commit 7c131446bc
7 changed files with 1336 additions and 5 deletions

View File

@ -960,12 +960,12 @@ selinux_relabel()
return
fi
for _i in $(find $_path); do
_attr=$(getfattr -m "security.selinux" $_i 2>/dev/null)
while IFS= read -r -d '' _i; do
_attr=$(getfattr -m "security.selinux" "$_i" 2>/dev/null)
if [ -z "$_attr" ]; then
restorecon $_i;
restorecon "$_i";
fi
done
done < <(find "$_path" -print0)
}
check_fence_kdump_config()

View File

@ -0,0 +1,492 @@
From 4149df9005f2cdd2ecf70058dfe7d72f48c3a68c Mon Sep 17 00:00:00 2001
From: John Ogness <john.ogness@linutronix.de>
Date: Wed, 25 Nov 2020 23:26:59 +0106
Subject: [PATCH] printk: add support for lockless ringbuffer
Linux 5.10 moved to a new lockless ringbuffer. The new ringbuffer
is structured completely different to the previous iterations.
Add support for retrieving the ringbuffer using vmcoreinfo. The
new ringbuffer is detected based on the availability of the
"prb" symbol.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
util_lib/elf_info.c | 438 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 437 insertions(+), 1 deletion(-)
diff --git a/util_lib/elf_info.c b/util_lib/elf_info.c
index 7803a94..2f23a44 100644
--- a/util_lib/elf_info.c
+++ b/util_lib/elf_info.c
@@ -27,6 +27,32 @@ static int num_pt_loads;
static char osrelease[4096];
+/* VMCOREINFO symbols for lockless printk ringbuffer */
+static loff_t prb_vaddr;
+static size_t printk_ringbuffer_sz;
+static size_t prb_desc_sz;
+static size_t printk_info_sz;
+static uint64_t printk_ringbuffer_desc_ring_offset;
+static uint64_t printk_ringbuffer_text_data_ring_offset;
+static uint64_t prb_desc_ring_count_bits_offset;
+static uint64_t prb_desc_ring_descs_offset;
+static uint64_t prb_desc_ring_infos_offset;
+static uint64_t prb_data_ring_size_bits_offset;
+static uint64_t prb_data_ring_data_offset;
+static uint64_t prb_desc_ring_head_id_offset;
+static uint64_t prb_desc_ring_tail_id_offset;
+static uint64_t atomic_long_t_counter_offset;
+static uint64_t prb_desc_state_var_offset;
+static uint64_t prb_desc_info_offset;
+static uint64_t prb_desc_text_blk_lpos_offset;
+static uint64_t prb_data_blk_lpos_begin_offset;
+static uint64_t prb_data_blk_lpos_next_offset;
+static uint64_t printk_info_seq_offset;
+static uint64_t printk_info_caller_id_offset;
+static uint64_t printk_info_ts_nsec_offset;
+static uint64_t printk_info_level_offset;
+static uint64_t printk_info_text_len_offset;
+
static loff_t log_buf_vaddr;
static loff_t log_end_vaddr;
static loff_t log_buf_len_vaddr;
@@ -304,6 +330,7 @@ void scan_vmcoreinfo(char *start, size_t size)
size_t len;
loff_t *vaddr;
} symbol[] = {
+ SYMBOL(prb),
SYMBOL(log_buf),
SYMBOL(log_end),
SYMBOL(log_buf_len),
@@ -361,6 +388,119 @@ void scan_vmcoreinfo(char *start, size_t size)
*symbol[i].vaddr = vaddr;
}
+ str = "SIZE(printk_ringbuffer)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ printk_ringbuffer_sz = strtoull(pos + strlen(str),
+ NULL, 10);
+
+ str = "SIZE(prb_desc)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_desc_sz = strtoull(pos + strlen(str), NULL, 10);
+
+ str = "SIZE(printk_info)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ printk_info_sz = strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(printk_ringbuffer.desc_ring)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ printk_ringbuffer_desc_ring_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(printk_ringbuffer.text_data_ring)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ printk_ringbuffer_text_data_ring_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_desc_ring.count_bits)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_desc_ring_count_bits_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_desc_ring.descs)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_desc_ring_descs_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_desc_ring.infos)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_desc_ring_infos_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_data_ring.size_bits)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_data_ring_size_bits_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_data_ring.data)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_data_ring_data_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_desc_ring.head_id)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_desc_ring_head_id_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_desc_ring.tail_id)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_desc_ring_tail_id_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(atomic_long_t.counter)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ atomic_long_t_counter_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_desc.state_var)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_desc_state_var_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_desc.info)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_desc_info_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_desc.text_blk_lpos)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_desc_text_blk_lpos_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_data_blk_lpos.begin)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_data_blk_lpos_begin_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(prb_data_blk_lpos.next)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ prb_data_blk_lpos_next_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(printk_info.seq)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ printk_info_seq_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(printk_info.caller_id)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ printk_info_caller_id_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(printk_info.ts_nsec)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ printk_info_ts_nsec_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(printk_info.level)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ printk_info_level_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
+ str = "OFFSET(printk_info.text_len)=";
+ if (memcmp(str, pos, strlen(str)) == 0)
+ printk_info_text_len_offset =
+ strtoull(pos + strlen(str), NULL, 10);
+
/* Check for "SIZE(printk_log)" or older "SIZE(log)=" */
str = "SIZE(log)=";
if (memcmp(str, pos, strlen(str)) == 0)
@@ -746,9 +886,305 @@ static void dump_dmesg_structured(int fd, void (*handler)(char*, unsigned int))
handler(out_buf, len);
}
+/* convenience struct for passing many values to helper functions */
+struct prb_map {
+ char *prb;
+
+ char *desc_ring;
+ unsigned long desc_ring_count;
+ char *descs;
+
+ char *infos;
+
+ char *text_data_ring;
+ unsigned long text_data_ring_size;
+ char *text_data;
+};
+
+/*
+ * desc_state and DESC_* definitions taken from kernel source:
+ *
+ * kernel/printk/printk_ringbuffer.h
+ *
+ * DESC_* definitions modified to provide 32-bit and 64-bit variants.
+ */
+
+/* The possible responses of a descriptor state-query. */
+enum desc_state {
+ desc_miss = -1, /* ID mismatch (pseudo state) */
+ desc_reserved = 0x0, /* reserved, in use by writer */
+ desc_committed = 0x1, /* committed by writer, could get reopened */
+ desc_finalized = 0x2, /* committed, no further modification allowed */
+ desc_reusable = 0x3, /* free, not yet used by any writer */
+};
+
+#define DESC_SV_BITS (sizeof(uint64_t) * 8)
+#define DESC_FLAGS_SHIFT (DESC_SV_BITS - 2)
+#define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT)
+#define DESC_STATE(sv) (3UL & (sv >> DESC_FLAGS_SHIFT))
+#define DESC_ID_MASK (~DESC_FLAGS_MASK)
+#define DESC_ID(sv) ((sv) & DESC_ID_MASK)
+
+#define DESC32_SV_BITS (sizeof(uint32_t) * 8)
+#define DESC32_FLAGS_SHIFT (DESC32_SV_BITS - 2)
+#define DESC32_FLAGS_MASK (3UL << DESC32_FLAGS_SHIFT)
+#define DESC32_STATE(sv) (3UL & (sv >> DESC32_FLAGS_SHIFT))
+#define DESC32_ID_MASK (~DESC32_FLAGS_MASK)
+#define DESC32_ID(sv) ((sv) & DESC32_ID_MASK)
+
+/*
+ * get_desc_state() taken from kernel source:
+ *
+ * kernel/printk/printk_ringbuffer.c
+ *
+ * get_desc32_state() added as 32-bit variant.
+ */
+
+/* Query the state of a descriptor. */
+static enum desc_state get_desc_state(unsigned long id,
+ uint64_t state_val)
+{
+ if (id != DESC_ID(state_val))
+ return desc_miss;
+
+ return DESC_STATE(state_val);
+}
+
+static enum desc_state get_desc32_state(unsigned long id,
+ uint64_t state_val)
+{
+ if (id != DESC32_ID(state_val))
+ return desc_miss;
+
+ return DESC32_STATE(state_val);
+}
+
+static bool record_committed(unsigned long id, uint64_t state_var)
+{
+ enum desc_state state;
+
+ if (machine_pointer_bits() == 32)
+ state = get_desc32_state(id, state_var);
+ else
+ state = get_desc_state(id, state_var);
+
+ return (state == desc_committed || state == desc_finalized);
+}
+
+static uint64_t id_inc(uint64_t id)
+{
+ id++;
+
+ if (machine_pointer_bits() == 32)
+ return (id & DESC32_ID_MASK);
+
+ return (id & DESC_ID_MASK);
+}
+
+static uint64_t get_ulong(char *addr)
+{
+ if (machine_pointer_bits() == 32)
+ return struct_val_u32(addr, 0);
+ return struct_val_u64(addr, 0);
+}
+
+static uint64_t sizeof_ulong(void)
+{
+ return (machine_pointer_bits() >> 3);
+}
+
+static void dump_record(struct prb_map *m, unsigned long id,
+ void (*handler)(char*, unsigned int))
+{
+#define OUT_BUF_SIZE 4096
+ char out_buf[OUT_BUF_SIZE];
+ imaxdiv_t imaxdiv_usec;
+ imaxdiv_t imaxdiv_sec;
+ uint32_t offset = 0;
+ unsigned short len;
+ uint64_t state_var;
+ uint64_t ts_nsec;
+ uint64_t begin;
+ uint64_t next;
+ char *info;
+ char *text;
+ char *desc;
+ int i;
+
+ desc = m->descs + ((id % m->desc_ring_count) * prb_desc_sz);
+ info = m->infos + ((id % m->desc_ring_count) * printk_info_sz);
+
+ /* skip non-committed record */
+ state_var = get_ulong(desc + prb_desc_state_var_offset +
+ atomic_long_t_counter_offset);
+ if (!record_committed(id, state_var))
+ return;
+
+ begin = get_ulong(desc + prb_desc_text_blk_lpos_offset +
+ prb_data_blk_lpos_begin_offset) %
+ m->text_data_ring_size;
+ next = get_ulong(desc + prb_desc_text_blk_lpos_offset +
+ prb_data_blk_lpos_next_offset) %
+ m->text_data_ring_size;
+
+ ts_nsec = struct_val_u64(info, printk_info_ts_nsec_offset);
+ imaxdiv_sec = imaxdiv(ts_nsec, 1000000000);
+ imaxdiv_usec = imaxdiv(imaxdiv_sec.rem, 1000);
+
+ offset += sprintf(out_buf + offset, "[%5llu.%06llu] ",
+ (long long unsigned int)imaxdiv_sec.quot,
+ (long long unsigned int)imaxdiv_usec.quot);
+
+ /* skip data-less text blocks */
+ if (begin == next)
+ goto out;
+
+ len = struct_val_u16(info, printk_info_text_len_offset);
+
+ /* handle wrapping data block */
+ if (begin > next)
+ begin = 0;
+
+ /* skip over descriptor ID */
+ begin += sizeof_ulong();
+
+ /* handle truncated messages */
+ if (next - begin < len)
+ len = next - begin;
+
+ text = m->text_data + begin;
+
+ /* escape non-printable characters */
+ for (i = 0; i < len; i++) {
+ unsigned char c = text[i];
+
+ if (!isprint(c) && !isspace(c))
+ offset += sprintf(out_buf + offset, "\\x%02x", c);
+ else
+ out_buf[offset++] = c;
+
+ if (offset >= OUT_BUF_SIZE - 64) {
+ if (handler)
+ handler(out_buf, offset);
+ offset = 0;
+ }
+ }
+out:
+ out_buf[offset++] = '\n';
+
+ if (offset && handler)
+ handler(out_buf, offset);
+}
+
+/*
+ * Handle the lockless printk_ringbuffer.
+ */
+static void dump_dmesg_lockless(int fd, void (*handler)(char*, unsigned int))
+{
+ struct prb_map m;
+ uint64_t head_id;
+ uint64_t tail_id;
+ uint64_t kaddr;
+ uint64_t id;
+ int ret;
+
+ /* setup printk_ringbuffer */
+ kaddr = read_file_pointer(fd, vaddr_to_offset(prb_vaddr));
+ m.prb = calloc(1, printk_ringbuffer_sz);
+ if (!m.prb) {
+ fprintf(stderr, "Failed to malloc %lu bytes for prb: %s\n",
+ printk_ringbuffer_sz, strerror(errno));
+ exit(64);
+ }
+ ret = pread(fd, m.prb, printk_ringbuffer_sz, vaddr_to_offset(kaddr));
+ if (ret != printk_ringbuffer_sz) {
+ fprintf(stderr, "Failed to read prb of size %lu bytes: %s\n",
+ printk_ringbuffer_sz, strerror(errno));
+ exit(65);
+ }
+
+ /* setup descriptor ring */
+ m.desc_ring = m.prb + printk_ringbuffer_desc_ring_offset;
+ m.desc_ring_count = 1 << struct_val_u32(m.desc_ring,
+ prb_desc_ring_count_bits_offset);
+ kaddr = get_ulong(m.desc_ring + prb_desc_ring_descs_offset);
+ m.descs = calloc(1, prb_desc_sz * m.desc_ring_count);
+ if (!m.descs) {
+ fprintf(stderr, "Failed to malloc %lu bytes for descs: %s\n",
+ prb_desc_sz * m.desc_ring_count, strerror(errno));
+ exit(64);
+ }
+ ret = pread(fd, m.descs, prb_desc_sz * m.desc_ring_count,
+ vaddr_to_offset(kaddr));
+ if (ret != prb_desc_sz * m.desc_ring_count) {
+ fprintf(stderr,
+ "Failed to read descs of size %lu bytes: %s\n",
+ prb_desc_sz * m.desc_ring_count, strerror(errno));
+ exit(65);
+ }
+
+ /* setup info ring */
+ kaddr = get_ulong(m.prb + prb_desc_ring_infos_offset);
+ m.infos = calloc(1, printk_info_sz * m.desc_ring_count);
+ if (!m.infos) {
+ fprintf(stderr, "Failed to malloc %lu bytes for infos: %s\n",
+ printk_info_sz * m.desc_ring_count, strerror(errno));
+ exit(64);
+ }
+ ret = pread(fd, m.infos, printk_info_sz * m.desc_ring_count,
+ vaddr_to_offset(kaddr));
+ if (ret != printk_info_sz * m.desc_ring_count) {
+ fprintf(stderr,
+ "Failed to read infos of size %lu bytes: %s\n",
+ printk_info_sz * m.desc_ring_count, strerror(errno));
+ exit(65);
+ }
+
+ /* setup text data ring */
+ m.text_data_ring = m.prb + printk_ringbuffer_text_data_ring_offset;
+ m.text_data_ring_size = 1 << struct_val_u32(m.text_data_ring,
+ prb_data_ring_size_bits_offset);
+ kaddr = get_ulong(m.text_data_ring + prb_data_ring_data_offset);
+ m.text_data = calloc(1, m.text_data_ring_size);
+ if (!m.text_data) {
+ fprintf(stderr,
+ "Failed to malloc %lu bytes for text_data: %s\n",
+ m.text_data_ring_size, strerror(errno));
+ exit(64);
+ }
+ ret = pread(fd, m.text_data, m.text_data_ring_size,
+ vaddr_to_offset(kaddr));
+ if (ret != m.text_data_ring_size) {
+ fprintf(stderr,
+ "Failed to read text_data of size %lu bytes: %s\n",
+ m.text_data_ring_size, strerror(errno));
+ exit(65);
+ }
+
+ /* ready to go */
+
+ tail_id = get_ulong(m.desc_ring + prb_desc_ring_tail_id_offset +
+ atomic_long_t_counter_offset);
+ head_id = get_ulong(m.desc_ring + prb_desc_ring_head_id_offset +
+ atomic_long_t_counter_offset);
+
+ for (id = tail_id; id != head_id; id = id_inc(id))
+ dump_record(&m, id, handler);
+
+ /* dump head record */
+ dump_record(&m, id, handler);
+
+ free(m.text_data);
+ free(m.infos);
+ free(m.descs);
+ free(m.prb);
+}
+
void dump_dmesg(int fd, void (*handler)(char*, unsigned int))
{
- if (log_first_idx_vaddr)
+ if (prb_vaddr)
+ dump_dmesg_lockless(fd, handler);
+ else if (log_first_idx_vaddr)
dump_dmesg_structured(fd, handler);
else
dump_dmesg_legacy(fd, handler);
--
2.31.1

View File

@ -0,0 +1,65 @@
From 07b272a07164b902acd7d12794f7be033ebf4525 Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven <geert+renesas@glider.be>
Date: Wed, 17 Mar 2021 13:14:49 +0100
Subject: [PATCH] printk: Use ULL suffix for 64-bit constants
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When compiling for 32-bit:
util_lib/elf_info.c: In function get_desc_state:
util_lib/elf_info.c:923:31: warning: left shift count >= width of type [-Wshift-count-overflow]
923 | #define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT)
| ^~
util_lib/elf_info.c:925:25: note: in expansion of macro DESC_FLAGS_MASK
925 | #define DESC_ID_MASK (~DESC_FLAGS_MASK)
| ^~~~~~~~~~~~~~~
util_lib/elf_info.c:926:30: note: in expansion of macro DESC_ID_MASK
926 | #define DESC_ID(sv) ((sv) & DESC_ID_MASK)
| ^~~~~~~~~~~~
util_lib/elf_info.c:947:12: note: in expansion of macro DESC_ID
947 | if (id != DESC_ID(state_val))
| ^~~~~~~
util_lib/elf_info.c: In function id_inc:
util_lib/elf_info.c:923:31: warning: left shift count >= width of type [-Wshift-count-overflow]
923 | #define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT)
| ^~
util_lib/elf_info.c:925:25: note: in expansion of macro DESC_FLAGS_MASK
925 | #define DESC_ID_MASK (~DESC_FLAGS_MASK)
| ^~~~~~~~~~~~~~~
util_lib/elf_info.c:981:15: note: in expansion of macro DESC_ID_MASK
981 | return (id & DESC_ID_MASK);
| ^~~~~~~~~~~~
Indeed, "unsigned long" constants are 32-bit on 32-bit platforms, and
64-bit on 64-bit platforms.
Fix this by using a "ULL" suffix instead.
Fixes: 4149df9005f2cdd2 ("printk: add support for lockless ringbuffer")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
util_lib/elf_info.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/util_lib/elf_info.c b/util_lib/elf_info.c
index 2f23a44..7c0a2c3 100644
--- a/util_lib/elf_info.c
+++ b/util_lib/elf_info.c
@@ -920,8 +920,8 @@ enum desc_state {
#define DESC_SV_BITS (sizeof(uint64_t) * 8)
#define DESC_FLAGS_SHIFT (DESC_SV_BITS - 2)
-#define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT)
-#define DESC_STATE(sv) (3UL & (sv >> DESC_FLAGS_SHIFT))
+#define DESC_FLAGS_MASK (3ULL << DESC_FLAGS_SHIFT)
+#define DESC_STATE(sv) (3ULL & (sv >> DESC_FLAGS_SHIFT))
#define DESC_ID_MASK (~DESC_FLAGS_MASK)
#define DESC_ID(sv) ((sv) & DESC_ID_MASK)
--
2.31.1

View File

@ -0,0 +1,68 @@
From 82f7de2724c42a6aecc0cff93881b3dfd09363ce Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven <geert+renesas@glider.be>
Date: Wed, 17 Mar 2021 13:14:50 +0100
Subject: [PATCH] printk: Use %zu to format size_t
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When compiling for 32-bit:
util_lib/elf_info.c: In function dump_dmesg_lockless:
util_lib/elf_info.c:1095:39: warning: format %lu expects argument of type long unsigned int, but argument 3 has type size_t {aka unsigned int} [-Wformat=]
1095 | fprintf(stderr, "Failed to malloc %lu bytes for prb: %s\n",
| ~~^
| |
| long unsigned int
| %u
1096 | printk_ringbuffer_sz, strerror(errno));
| ~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka unsigned int}
util_lib/elf_info.c:1101:49: warning: format %lu expects argument of type long unsigned int, but argument 3 has type size_t {aka unsigned int} [-Wformat=]
1101 | fprintf(stderr, "Failed to read prb of size %lu bytes: %s\n",
| ~~^
| |
| long unsigned int
| %u
1102 | printk_ringbuffer_sz, strerror(errno));
| ~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka unsigned int}
Indeed, "size_t" is "unsigned int" on 32-bit platforms, and "unsigned
long" on 64-bit platforms.
Fix this by formatting using "%zu".
Fixes: 4149df9005f2cdd2 ("printk: add support for lockless ringbuffer")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
util_lib/elf_info.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/util_lib/elf_info.c b/util_lib/elf_info.c
index 7c0a2c3..676926c 100644
--- a/util_lib/elf_info.c
+++ b/util_lib/elf_info.c
@@ -1092,13 +1092,13 @@ static void dump_dmesg_lockless(int fd, void (*handler)(char*, unsigned int))
kaddr = read_file_pointer(fd, vaddr_to_offset(prb_vaddr));
m.prb = calloc(1, printk_ringbuffer_sz);
if (!m.prb) {
- fprintf(stderr, "Failed to malloc %lu bytes for prb: %s\n",
+ fprintf(stderr, "Failed to malloc %zu bytes for prb: %s\n",
printk_ringbuffer_sz, strerror(errno));
exit(64);
}
ret = pread(fd, m.prb, printk_ringbuffer_sz, vaddr_to_offset(kaddr));
if (ret != printk_ringbuffer_sz) {
- fprintf(stderr, "Failed to read prb of size %lu bytes: %s\n",
+ fprintf(stderr, "Failed to read prb of size %zu bytes: %s\n",
printk_ringbuffer_sz, strerror(errno));
exit(65);
}
--
2.31.1

View File

@ -0,0 +1,587 @@
From c617ec63339222f3a44d73e36677a9acc8954ccd Mon Sep 17 00:00:00 2001
From: John Ogness <john.ogness@linutronix.de>
Date: Thu, 19 Nov 2020 02:41:21 +0000
Subject: [PATCH 1/2] [PATCH 1/2] printk: add support for lockless ringbuffer
* Required for kernel 5.10
Linux 5.10 introduces a new lockless ringbuffer. The new ringbuffer
is structured completely different to the previous iterations.
Add support for retrieving the ringbuffer from debug information
and/or using vmcoreinfo. The new ringbuffer is detected based on
the availability of the "prb" symbol.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
---
Makefile | 2 +-
dwarf_info.c | 36 ++++++++-
makedumpfile.c | 103 +++++++++++++++++++++++-
makedumpfile.h | 58 ++++++++++++++
printk.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 399 insertions(+), 7 deletions(-)
create mode 100644 printk.c
diff --git a/makedumpfile-1.6.8/Makefile b/makedumpfile-1.6.8/Makefile
index e5ac71a..cb6bd42 100644
--- a/makedumpfile-1.6.8/Makefile
+++ b/makedumpfile-1.6.8/Makefile
@@ -45,7 +45,7 @@ CFLAGS_ARCH += -m32
endif
SRC_BASE = makedumpfile.c makedumpfile.h diskdump_mod.h sadump_mod.h sadump_info.h
-SRC_PART = print_info.c dwarf_info.c elf_info.c erase_info.c sadump_info.c cache.c tools.c
+SRC_PART = print_info.c dwarf_info.c elf_info.c erase_info.c sadump_info.c cache.c tools.c printk.c
OBJ_PART=$(patsubst %.c,%.o,$(SRC_PART))
SRC_ARCH = arch/arm.c arch/arm64.c arch/x86.c arch/x86_64.c arch/ia64.c arch/ppc64.c arch/s390x.c arch/ppc.c arch/sparc64.c
OBJ_ARCH=$(patsubst %.c,%.o,$(SRC_ARCH))
diff --git a/makedumpfile-1.6.8/dwarf_info.c b/makedumpfile-1.6.8/dwarf_info.c
index e42a9f5..543588b 100644
--- a/makedumpfile-1.6.8/dwarf_info.c
+++ b/makedumpfile-1.6.8/dwarf_info.c
@@ -614,6 +614,7 @@ search_structure(Dwarf_Die *die, int *found)
{
int tag;
const char *name;
+ Dwarf_Die die_type;
/*
* If we get to here then we don't have any more
@@ -622,9 +623,31 @@ search_structure(Dwarf_Die *die, int *found)
do {
tag = dwarf_tag(die);
name = dwarf_diename(die);
- if ((tag != DW_TAG_structure_type) || (!name)
- || strcmp(name, dwarf_info.struct_name))
+ if ((!name) || strcmp(name, dwarf_info.struct_name))
+ continue;
+
+ if (tag == DW_TAG_typedef) {
+ if (!get_die_type(die, &die_type)) {
+ ERRMSG("Can't get CU die of DW_AT_type.\n");
+ break;
+ }
+
+ /* Resolve typedefs of typedefs. */
+ while ((tag = dwarf_tag(&die_type)) == DW_TAG_typedef) {
+ if (!get_die_type(&die_type, &die_type)) {
+ ERRMSG("Can't get CU die of DW_AT_type.\n");
+ return;
+ }
+ }
+
+ if (tag != DW_TAG_structure_type)
+ continue;
+ die = &die_type;
+
+ } else if (tag != DW_TAG_structure_type) {
continue;
+ }
+
/*
* Skip if DW_AT_byte_size is not included.
*/
@@ -740,6 +763,15 @@ search_typedef(Dwarf_Die *die, int *found)
ERRMSG("Can't get CU die of DW_AT_type.\n");
break;
}
+
+ /* Resolve typedefs of typedefs. */
+ while ((tag = dwarf_tag(&die_type)) == DW_TAG_typedef) {
+ if (!get_die_type(&die_type, &die_type)) {
+ ERRMSG("Can't get CU die of DW_AT_type.\n");
+ return;
+ }
+ }
+
dwarf_info.struct_size = dwarf_bytesize(&die_type);
if (dwarf_info.struct_size <= 0)
continue;
diff --git a/makedumpfile-1.6.8/makedumpfile.c b/makedumpfile-1.6.8/makedumpfile.c
index cdde040..061741f 100644
--- a/makedumpfile-1.6.8/makedumpfile.c
+++ b/makedumpfile-1.6.8/makedumpfile.c
@@ -1555,6 +1555,7 @@ get_symbol_info(void)
SYMBOL_INIT(node_data, "node_data");
SYMBOL_INIT(pgdat_list, "pgdat_list");
SYMBOL_INIT(contig_page_data, "contig_page_data");
+ SYMBOL_INIT(prb, "prb");
SYMBOL_INIT(log_buf, "log_buf");
SYMBOL_INIT(log_buf_len, "log_buf_len");
SYMBOL_INIT(log_end, "log_end");
@@ -1971,16 +1972,47 @@ get_structure_info(void)
OFFSET_INIT(elf64_phdr.p_memsz, "elf64_phdr", "p_memsz");
SIZE_INIT(printk_log, "printk_log");
- if (SIZE(printk_log) != NOT_FOUND_STRUCTURE) {
+ SIZE_INIT(printk_ringbuffer, "printk_ringbuffer");
+ if ((SIZE(printk_ringbuffer) != NOT_FOUND_STRUCTURE)) {
+ info->flag_use_printk_ringbuffer = TRUE;
+ info->flag_use_printk_log = FALSE;
+
+ OFFSET_INIT(printk_ringbuffer.desc_ring, "printk_ringbuffer", "desc_ring");
+ OFFSET_INIT(printk_ringbuffer.text_data_ring, "printk_ringbuffer", "text_data_ring");
+
+ OFFSET_INIT(prb_desc_ring.count_bits, "prb_desc_ring", "count_bits");
+ OFFSET_INIT(prb_desc_ring.descs, "prb_desc_ring", "descs");
+ OFFSET_INIT(prb_desc_ring.infos, "prb_desc_ring", "infos");
+ OFFSET_INIT(prb_desc_ring.head_id, "prb_desc_ring", "head_id");
+ OFFSET_INIT(prb_desc_ring.tail_id, "prb_desc_ring", "tail_id");
+
+ SIZE_INIT(prb_desc, "prb_desc");
+ OFFSET_INIT(prb_desc.state_var, "prb_desc", "state_var");
+ OFFSET_INIT(prb_desc.text_blk_lpos, "prb_desc", "text_blk_lpos");
+
+ OFFSET_INIT(prb_data_blk_lpos.begin, "prb_data_blk_lpos", "begin");
+ OFFSET_INIT(prb_data_blk_lpos.next, "prb_data_blk_lpos", "next");
+
+ OFFSET_INIT(prb_data_ring.size_bits, "prb_data_ring", "size_bits");
+ OFFSET_INIT(prb_data_ring.data, "prb_data_ring", "data");
+
+ SIZE_INIT(printk_info, "printk_info");
+ OFFSET_INIT(printk_info.ts_nsec, "printk_info", "ts_nsec");
+ OFFSET_INIT(printk_info.text_len, "printk_info", "text_len");
+
+ OFFSET_INIT(atomic_long_t.counter, "atomic_long_t", "counter");
+ } else if (SIZE(printk_log) != NOT_FOUND_STRUCTURE) {
/*
* In kernel 3.11-rc4 the log structure name was renamed
* to "printk_log".
*/
+ info->flag_use_printk_ringbuffer = FALSE;
info->flag_use_printk_log = TRUE;
OFFSET_INIT(printk_log.ts_nsec, "printk_log", "ts_nsec");
OFFSET_INIT(printk_log.len, "printk_log", "len");
OFFSET_INIT(printk_log.text_len, "printk_log", "text_len");
} else {
+ info->flag_use_printk_ringbuffer = FALSE;
info->flag_use_printk_log = FALSE;
SIZE_INIT(printk_log, "log");
OFFSET_INIT(printk_log.ts_nsec, "log", "ts_nsec");
@@ -2191,6 +2223,7 @@ write_vmcoreinfo_data(void)
WRITE_SYMBOL("node_data", node_data);
WRITE_SYMBOL("pgdat_list", pgdat_list);
WRITE_SYMBOL("contig_page_data", contig_page_data);
+ WRITE_SYMBOL("prb", prb);
WRITE_SYMBOL("log_buf", log_buf);
WRITE_SYMBOL("log_buf_len", log_buf_len);
WRITE_SYMBOL("log_end", log_end);
@@ -2222,7 +2255,11 @@ write_vmcoreinfo_data(void)
WRITE_STRUCTURE_SIZE("node_memblk_s", node_memblk_s);
WRITE_STRUCTURE_SIZE("nodemask_t", nodemask_t);
WRITE_STRUCTURE_SIZE("pageflags", pageflags);
- if (info->flag_use_printk_log)
+ if (info->flag_use_printk_ringbuffer) {
+ WRITE_STRUCTURE_SIZE("printk_ringbuffer", printk_ringbuffer);
+ WRITE_STRUCTURE_SIZE("prb_desc", prb_desc);
+ WRITE_STRUCTURE_SIZE("printk_info", printk_info);
+ } else if (info->flag_use_printk_log)
WRITE_STRUCTURE_SIZE("printk_log", printk_log);
else
WRITE_STRUCTURE_SIZE("log", printk_log);
@@ -2268,7 +2305,30 @@ write_vmcoreinfo_data(void)
WRITE_MEMBER_OFFSET("vm_struct.addr", vm_struct.addr);
WRITE_MEMBER_OFFSET("vmap_area.va_start", vmap_area.va_start);
WRITE_MEMBER_OFFSET("vmap_area.list", vmap_area.list);
- if (info->flag_use_printk_log) {
+ if (info->flag_use_printk_ringbuffer) {
+ WRITE_MEMBER_OFFSET("printk_ringbuffer.desc_ring", printk_ringbuffer.desc_ring);
+ WRITE_MEMBER_OFFSET("printk_ringbuffer.text_data_ring", printk_ringbuffer.text_data_ring);
+
+ WRITE_MEMBER_OFFSET("prb_desc_ring.count_bits", prb_desc_ring.count_bits);
+ WRITE_MEMBER_OFFSET("prb_desc_ring.descs", prb_desc_ring.descs);
+ WRITE_MEMBER_OFFSET("prb_desc_ring.infos", prb_desc_ring.infos);
+ WRITE_MEMBER_OFFSET("prb_desc_ring.head_id", prb_desc_ring.head_id);
+ WRITE_MEMBER_OFFSET("prb_desc_ring.tail_id", prb_desc_ring.tail_id);
+
+ WRITE_MEMBER_OFFSET("prb_desc.state_var", prb_desc.state_var);
+ WRITE_MEMBER_OFFSET("prb_desc.text_blk_lpos", prb_desc.text_blk_lpos);
+
+ WRITE_MEMBER_OFFSET("prb_data_blk_lpos.begin", prb_data_blk_lpos.begin);
+ WRITE_MEMBER_OFFSET("prb_data_blk_lpos.next", prb_data_blk_lpos.next);
+
+ WRITE_MEMBER_OFFSET("prb_data_ring.size_bits", prb_data_ring.size_bits);
+ WRITE_MEMBER_OFFSET("prb_data_ring.data", prb_data_ring.data);
+
+ WRITE_MEMBER_OFFSET("printk_info.ts_nsec", printk_info.ts_nsec);
+ WRITE_MEMBER_OFFSET("printk_info.text_len", printk_info.text_len);
+
+ WRITE_MEMBER_OFFSET("atomic_long_t.counter", atomic_long_t.counter);
+ } else if (info->flag_use_printk_log) {
WRITE_MEMBER_OFFSET("printk_log.ts_nsec", printk_log.ts_nsec);
WRITE_MEMBER_OFFSET("printk_log.len", printk_log.len);
WRITE_MEMBER_OFFSET("printk_log.text_len", printk_log.text_len);
@@ -2606,6 +2666,7 @@ read_vmcoreinfo(void)
READ_SYMBOL("node_data", node_data);
READ_SYMBOL("pgdat_list", pgdat_list);
READ_SYMBOL("contig_page_data", contig_page_data);
+ READ_SYMBOL("prb", prb);
READ_SYMBOL("log_buf", log_buf);
READ_SYMBOL("log_buf_len", log_buf_len);
READ_SYMBOL("log_end", log_end);
@@ -2684,12 +2745,43 @@ read_vmcoreinfo(void)
READ_MEMBER_OFFSET("cpu_spec.mmu_features", cpu_spec.mmu_features);
READ_STRUCTURE_SIZE("printk_log", printk_log);
- if (SIZE(printk_log) != NOT_FOUND_STRUCTURE) {
+ READ_STRUCTURE_SIZE("printk_ringbuffer", printk_ringbuffer);
+ if (SIZE(printk_ringbuffer) != NOT_FOUND_STRUCTURE) {
+ info->flag_use_printk_ringbuffer = TRUE;
+ info->flag_use_printk_log = FALSE;
+
+ READ_MEMBER_OFFSET("printk_ringbuffer.desc_ring", printk_ringbuffer.desc_ring);
+ READ_MEMBER_OFFSET("printk_ringbuffer.text_data_ring", printk_ringbuffer.text_data_ring);
+
+ READ_MEMBER_OFFSET("prb_desc_ring.count_bits", prb_desc_ring.count_bits);
+ READ_MEMBER_OFFSET("prb_desc_ring.descs", prb_desc_ring.descs);
+ READ_MEMBER_OFFSET("prb_desc_ring.infos", prb_desc_ring.infos);
+ READ_MEMBER_OFFSET("prb_desc_ring.head_id", prb_desc_ring.head_id);
+ READ_MEMBER_OFFSET("prb_desc_ring.tail_id", prb_desc_ring.tail_id);
+
+ READ_STRUCTURE_SIZE("prb_desc", prb_desc);
+ READ_MEMBER_OFFSET("prb_desc.state_var", prb_desc.state_var);
+ READ_MEMBER_OFFSET("prb_desc.text_blk_lpos", prb_desc.text_blk_lpos);
+
+ READ_MEMBER_OFFSET("prb_data_blk_lpos.begin", prb_data_blk_lpos.begin);
+ READ_MEMBER_OFFSET("prb_data_blk_lpos.next", prb_data_blk_lpos.next);
+
+ READ_MEMBER_OFFSET("prb_data_ring.size_bits", prb_data_ring.size_bits);
+ READ_MEMBER_OFFSET("prb_data_ring.data", prb_data_ring.data);
+
+ READ_STRUCTURE_SIZE("printk_info", printk_info);
+ READ_MEMBER_OFFSET("printk_info.ts_nsec", printk_info.ts_nsec);
+ READ_MEMBER_OFFSET("printk_info.text_len", printk_info.text_len);
+
+ READ_MEMBER_OFFSET("atomic_long_t.counter", atomic_long_t.counter);
+ } else if (SIZE(printk_log) != NOT_FOUND_STRUCTURE) {
+ info->flag_use_printk_ringbuffer = FALSE;
info->flag_use_printk_log = TRUE;
READ_MEMBER_OFFSET("printk_log.ts_nsec", printk_log.ts_nsec);
READ_MEMBER_OFFSET("printk_log.len", printk_log.len);
READ_MEMBER_OFFSET("printk_log.text_len", printk_log.text_len);
} else {
+ info->flag_use_printk_ringbuffer = FALSE;
info->flag_use_printk_log = FALSE;
READ_STRUCTURE_SIZE("log", printk_log);
READ_MEMBER_OFFSET("log.ts_nsec", printk_log.ts_nsec);
@@ -5286,6 +5378,9 @@ dump_dmesg()
if (!initial())
return FALSE;
+ if ((SYMBOL(prb) != NOT_FOUND_SYMBOL))
+ return dump_lockless_dmesg();
+
if ((SYMBOL(log_buf) == NOT_FOUND_SYMBOL)
|| (SYMBOL(log_buf_len) == NOT_FOUND_SYMBOL)) {
ERRMSG("Can't find some symbols for log_buf.\n");
diff --git a/makedumpfile-1.6.8/makedumpfile.h b/makedumpfile-1.6.8/makedumpfile.h
index 698c054..47f7e79 100644
--- a/makedumpfile-1.6.8/makedumpfile.h
+++ b/makedumpfile-1.6.8/makedumpfile.h
@@ -1317,6 +1317,7 @@ struct DumpInfo {
int flag_partial_dmesg; /* dmesg dump only from the last cleared index*/
int flag_mem_usage; /*show the page number of memory in different use*/
int flag_use_printk_log; /* did we read printk_log symbol name? */
+ int flag_use_printk_ringbuffer; /* using lockless printk ringbuffer? */
int flag_nospace; /* the flag of "No space on device" error */
int flag_vmemmap; /* kernel supports vmemmap address space */
int flag_excludevm; /* -e - excluding unused vmemmap pages */
@@ -1602,6 +1603,7 @@ struct symbol_table {
unsigned long long node_data;
unsigned long long pgdat_list;
unsigned long long contig_page_data;
+ unsigned long long prb;
unsigned long long log_buf;
unsigned long long log_buf_len;
unsigned long long log_end;
@@ -1689,6 +1691,13 @@ struct size_table {
long nodemask_t;
long printk_log;
+ /*
+ * for lockless printk ringbuffer
+ */
+ long printk_ringbuffer;
+ long prb_desc;
+ long printk_info;
+
/*
* for Xen extraction
*/
@@ -1864,6 +1873,52 @@ struct offset_table {
long text_len;
} printk_log;
+ /*
+ * for lockless printk ringbuffer
+ */
+ struct printk_ringbuffer_s {
+ long desc_ring;
+ long text_data_ring;
+ long fail;
+ } printk_ringbuffer;
+
+ struct prb_desc_ring_s {
+ long count_bits;
+ long descs;
+ long infos;
+ long head_id;
+ long tail_id;
+ } prb_desc_ring;
+
+ struct prb_desc_s {
+ long state_var;
+ long text_blk_lpos;
+ } prb_desc;
+
+ struct prb_data_blk_lpos_s {
+ long begin;
+ long next;
+ } prb_data_blk_lpos;
+
+ struct printk_info_s {
+ long seq;
+ long ts_nsec;
+ long text_len;
+ long caller_id;
+ long dev_info;
+ } printk_info;
+
+ struct prb_data_ring_s {
+ long size_bits;
+ long data;
+ long head_lpos;
+ long tail_lpos;
+ } prb_data_ring;
+
+ struct atomic_long_t_s {
+ long counter;
+ } atomic_long_t;
+
/*
* symbols on ppc64 arch
*/
@@ -2390,4 +2445,7 @@ int hexadecimal(char *s, int count);
int decimal(char *s, int count);
int file_exists(char *file);
+int open_dump_file(void);
+int dump_lockless_dmesg(void);
+
#endif /* MAKEDUMPFILE_H */
diff --git a/makedumpfile-1.6.8/printk.c b/makedumpfile-1.6.8/printk.c
new file mode 100644
index 0000000..acffb6c
--- /dev/null
+++ b/makedumpfile-1.6.8/printk.c
@@ -0,0 +1,207 @@
+#include "makedumpfile.h"
+#include <ctype.h>
+
+#define DESC_SV_BITS (sizeof(unsigned long) * 8)
+#define DESC_COMMITTED_MASK (1UL << (DESC_SV_BITS - 1))
+#define DESC_REUSE_MASK (1UL << (DESC_SV_BITS - 2))
+#define DESC_FLAGS_MASK (DESC_COMMITTED_MASK | DESC_REUSE_MASK)
+#define DESC_ID_MASK (~DESC_FLAGS_MASK)
+
+/* convenience struct for passing many values to helper functions */
+struct prb_map {
+ char *prb;
+
+ char *desc_ring;
+ unsigned long desc_ring_count;
+ char *descs;
+ char *infos;
+
+ char *text_data_ring;
+ unsigned long text_data_ring_size;
+ char *text_data;
+};
+
+static void
+dump_record(struct prb_map *m, unsigned long id)
+{
+ unsigned long long ts_nsec;
+ unsigned long state_var;
+ unsigned short text_len;
+ unsigned long begin;
+ unsigned long next;
+ char buf[BUFSIZE];
+ ulonglong nanos;
+ int indent_len;
+ int buf_need;
+ char *bufp;
+ char *text;
+ char *desc;
+ char *inf;
+ ulong rem;
+ char *p;
+ int i;
+
+ desc = m->descs + ((id % m->desc_ring_count) * SIZE(prb_desc));
+
+ /* skip non-committed record */
+ state_var = ULONG(desc + OFFSET(prb_desc.state_var) + OFFSET(atomic_long_t.counter));
+ if ((state_var & DESC_FLAGS_MASK) != DESC_COMMITTED_MASK)
+ return;
+
+ begin = ULONG(desc + OFFSET(prb_desc.text_blk_lpos) + OFFSET(prb_data_blk_lpos.begin)) %
+ m->text_data_ring_size;
+ next = ULONG(desc + OFFSET(prb_desc.text_blk_lpos) + OFFSET(prb_data_blk_lpos.next)) %
+ m->text_data_ring_size;
+
+ /* skip data-less text blocks */
+ if (begin == next)
+ return;
+
+ inf = m->infos + ((id % m->desc_ring_count) * SIZE(printk_info));
+
+ text_len = USHORT(inf + OFFSET(printk_info.text_len));
+
+ /* handle wrapping data block */
+ if (begin > next)
+ begin = 0;
+
+ /* skip over descriptor ID */
+ begin += sizeof(unsigned long);
+
+ /* handle truncated messages */
+ if (next - begin < text_len)
+ text_len = next - begin;
+
+ text = m->text_data + begin;
+
+ ts_nsec = ULONGLONG(inf + OFFSET(printk_info.ts_nsec));
+ nanos = (ulonglong)ts_nsec / (ulonglong)1000000000;
+ rem = (ulonglong)ts_nsec % (ulonglong)1000000000;
+
+ bufp = buf;
+ bufp += sprintf(buf, "[%5lld.%06ld] ", nanos, rem/1000);
+ indent_len = strlen(buf);
+
+ /* How much buffer space is needed in the worst case */
+ buf_need = MAX(sizeof("\\xXX\n"), sizeof("\n") + indent_len);
+
+ for (i = 0, p = text; i < text_len; i++, p++) {
+ if (bufp - buf >= sizeof(buf) - buf_need) {
+ if (write(info->fd_dumpfile, buf, bufp - buf) < 0)
+ return;
+ bufp = buf;
+ }
+
+ if (*p == '\n')
+ bufp += sprintf(bufp, "\n%-*s", indent_len, "");
+ else if (isprint(*p) || isspace(*p))
+ *bufp++ = *p;
+ else
+ bufp += sprintf(bufp, "\\x%02x", *p);
+ }
+
+ *bufp++ = '\n';
+
+ write(info->fd_dumpfile, buf, bufp - buf);
+}
+
+int
+dump_lockless_dmesg(void)
+{
+ unsigned long head_id;
+ unsigned long tail_id;
+ unsigned long kaddr;
+ unsigned long id;
+ struct prb_map m;
+ int ret = FALSE;
+
+ /* setup printk_ringbuffer */
+ if (!readmem(VADDR, SYMBOL(prb), &kaddr, sizeof(kaddr))) {
+ ERRMSG("Can't get the prb address.\n");
+ return ret;
+ }
+
+ m.prb = malloc(SIZE(printk_ringbuffer));
+ if (!m.prb) {
+ ERRMSG("Can't allocate memory for prb.\n");
+ return ret;
+ }
+ if (!readmem(VADDR, kaddr, m.prb, SIZE(printk_ringbuffer))) {
+ ERRMSG("Can't get prb.\n");
+ goto out_prb;
+ }
+
+ /* setup descriptor ring */
+ m.desc_ring = m.prb + OFFSET(printk_ringbuffer.desc_ring);
+ m.desc_ring_count = 1 << UINT(m.desc_ring + OFFSET(prb_desc_ring.count_bits));
+
+ kaddr = ULONG(m.desc_ring + OFFSET(prb_desc_ring.descs));
+ m.descs = malloc(SIZE(prb_desc) * m.desc_ring_count);
+ if (!m.descs) {
+ ERRMSG("Can't allocate memory for prb.desc_ring.descs.\n");
+ goto out_prb;
+ }
+ if (!readmem(VADDR, kaddr, m.descs,
+ SIZE(prb_desc) * m.desc_ring_count)) {
+ ERRMSG("Can't get prb.desc_ring.descs.\n");
+ goto out_descs;
+ }
+
+ kaddr = ULONG(m.desc_ring + OFFSET(prb_desc_ring.infos));
+ m.infos = malloc(SIZE(printk_info) * m.desc_ring_count);
+ if (!m.infos) {
+ ERRMSG("Can't allocate memory for prb.desc_ring.infos.\n");
+ goto out_descs;
+ }
+ if (!readmem(VADDR, kaddr, m.infos, SIZE(printk_info) * m.desc_ring_count)) {
+ ERRMSG("Can't get prb.desc_ring.infos.\n");
+ goto out_infos;
+ }
+
+ /* setup text data ring */
+ m.text_data_ring = m.prb + OFFSET(printk_ringbuffer.text_data_ring);
+ m.text_data_ring_size = 1 << UINT(m.text_data_ring + OFFSET(prb_data_ring.size_bits));
+
+ kaddr = ULONG(m.text_data_ring + OFFSET(prb_data_ring.data));
+ m.text_data = malloc(m.text_data_ring_size);
+ if (!m.text_data) {
+ ERRMSG("Can't allocate memory for prb.text_data_ring.data.\n");
+ goto out_infos;
+ }
+ if (!readmem(VADDR, kaddr, m.text_data, m.text_data_ring_size)) {
+ ERRMSG("Can't get prb.text_data_ring.\n");
+ goto out_text_data;
+ }
+
+ /* ready to go */
+
+ tail_id = ULONG(m.desc_ring + OFFSET(prb_desc_ring.tail_id) +
+ OFFSET(atomic_long_t.counter));
+ head_id = ULONG(m.desc_ring + OFFSET(prb_desc_ring.head_id) +
+ OFFSET(atomic_long_t.counter));
+
+ if (!open_dump_file()) {
+ ERRMSG("Can't open output file.\n");
+ goto out_text_data;
+ }
+
+ for (id = tail_id; id != head_id; id = (id + 1) & DESC_ID_MASK)
+ dump_record(&m, id);
+
+ /* dump head record */
+ dump_record(&m, id);
+
+ if (!close_files_for_creating_dumpfile())
+ goto out_text_data;
+
+ ret = TRUE;
+out_text_data:
+ free(m.text_data);
+out_infos:
+ free(m.infos);
+out_descs:
+ free(m.descs);
+out_prb:
+ free(m.prb);
+ return ret;
+}
--
2.31.1

View File

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

View File

@ -1,6 +1,6 @@
Name: kexec-tools
Version: 2.0.20
Release: 57%{?dist}
Release: 59%{?dist}
License: GPLv2
Group: Applications/System
Summary: The kexec/kdump userspace component
@ -112,6 +112,9 @@ Patch610: kexec-tools-2.0.20-arm64-kexec-allocate-memory-space-avoiding-reserved
Patch611: kexec-tools-2.0.20-arm64-kdump-deal-with-a-lot-of-resource-entries-in-p.patch
Patch612: kexec-tools-2.0.20-Remove-duplicated-variable-declarations.patch
Patch613: kexec-tools-2.0.20-eppic-Remove-duplicated-variable-declaration.patch
Patch614: kexec-tools-2.0.20-1-printk-add-support-for-lockless-ringbuffer.patch
Patch615: kexec-tools-2.0.20-2-printk-Use-ULL-suffix-for-64-bit-constants.patch
Patch616: kexec-tools-2.0.20-3-printk-Use-zu-to-format-size_t.patch
# Patches 701 onward for makedumpfile
@ -121,6 +124,8 @@ Patch703: kexec-tools-2.0.20-makedumpfile-Add-shorthand-show-stats-option-to-sho
Patch704: kexec-tools-2.0.20-makedumpfile-Show-write-byte-size-in-report-messages.patch
Patch705: kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch
Patch706: kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-making-ELF-dumpfile.patch
Patch707: kexec-tools-2.0.20-makedumpfile-1-printk-add-support-for-lockless-ringbuffer.patch
Patch708: kexec-tools-2.0.20-makedumpfile-2-printk-use-committed-finalized-state-value.patch
%description
kexec-tools provides /usr/sbin/kexec binary that facilitates a new
@ -149,12 +154,17 @@ tar -z -x -v -f %{SOURCE19}
%patch611 -p1
%patch612 -p1
%patch613 -p1
%patch614 -p1
%patch615 -p1
%patch616 -p1
%patch701 -p1
%patch702 -p1
%patch703 -p1
%patch704 -p1
%patch705 -p1
%patch706 -p1
%patch707 -p1
%patch708 -p1
%ifarch ppc
%define archdef ARCH=ppc
@ -406,6 +416,16 @@ done
%endif
%changelog
* Mon Oct 18 2021 Pingfan Liu <piliu@redhat.com> - 2.0.20-59
- makedumpfile: printk: use committed/finalized state values
- makedumpfile: printk: add support for lockless ringbuffer
- kexec-tools: printk: Use %zu to format size_t
- kexec-tools: printk: Use ULL suffix for 64-bit constants
- kexec-tools: printk: add support for lockless ringbuffer
* Sun Oct 17 2021 Pingfan Liu <piliu@redhat.com> - 2.0.20-58
- kdumpctl: fix fragile loops over find output
* Fri Aug 27 2021 Pingfan Liu <piliu@redhat.com> - 2.0.20-57
- kdumpctl: enable secure boot on ppc64le LPARs