Skip to content

Commit

Permalink
[PATCH 1/2] printk: add support for lockless ringbuffer
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
jogness authored and k-hagio committed Nov 26, 2020
1 parent 0188ea9 commit c617ec6
Show file tree
Hide file tree
Showing 5 changed files with 399 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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))
Expand Down
36 changes: 34 additions & 2 deletions dwarf_info.c
Expand Up @@ -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
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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;
Expand Down
103 changes: 99 additions & 4 deletions makedumpfile.c
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
58 changes: 58 additions & 0 deletions makedumpfile.h
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 */

0 comments on commit c617ec6

Please sign in to comment.