diff --git a/.crash.metadata b/.crash.metadata index 1238fca..7381cdc 100644 --- a/.crash.metadata +++ b/.crash.metadata @@ -1,2 +1,2 @@ -35a06244e58606ebf2b5612fbfcb51301bd5877a SOURCES/crash-7.3.0.tar.gz +f230368e17058e61a0be4c22f0969bed76cd6c29 SOURCES/crash-7.3.1.tar.gz 026f4c9e1c8152a2773354551c523acd32d7f00e SOURCES/gdb-7.6.tar.gz diff --git a/.gitignore b/.gitignore index 169176a..d19e76b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -SOURCES/crash-7.3.0.tar.gz +SOURCES/crash-7.3.1.tar.gz SOURCES/gdb-7.6.tar.gz diff --git a/SOURCES/0001-Fix-pvops-Xen-detection-for-arm-machine.patch b/SOURCES/0001-Fix-pvops-Xen-detection-for-arm-machine.patch new file mode 100644 index 0000000..7b6b236 --- /dev/null +++ b/SOURCES/0001-Fix-pvops-Xen-detection-for-arm-machine.patch @@ -0,0 +1,70 @@ +From 5c4f786450ea61b87d4db0092288df83dd5cb454 Mon Sep 17 00:00:00 2001 +From: Qi Zheng +Date: Tue, 21 Dec 2021 15:40:31 +0800 +Subject: [PATCH 01/11] Fix pvops Xen detection for arm machine + +Since the xen_start_info on the arm/arm64 platform points to a static +variable '_xen_start_info'(see its definition as below), which makes +that the address of xen_start_info will never be null. + +arch/arm/xen/enlighten.c:40:static struct start_info _xen_start_info; +arch/arm/xen/enlighten.c:41:struct start_info *xen_start_info = &_xen_start_info; +arch/arm/xen/enlighten.c:42:EXPORT_SYMBOL(xen_start_info); + +As a result, the is_pvops_xen() in commit 4badc6229c69 ("Fix pvops +Xen detection for kernels >= v4.20") always returns TRUE because it +can always read out the non-null address of xen_start_info, finally +the following error will be reported on arm/arm64 platform(non-Xen +environment) because p2m_mid_missing and xen_p2m_addr are not defined: + + crash: cannot resolve "p2m_top" + +For the arm/arm64 platform, fix it by using xen_vcpu_info instead of +xen_start_info to detect Xen dumps. + +In addition, also explicitly narrow the scope of the xen_start_info +check to x86 with the machine_type(), there is no need to check it on +other architectures. + +Fixes: 4badc6229c69 ("Fix pvops Xen detection for kernels >= v4.20") +Signed-off-by: Qi Zheng +Acked-by: Kazuhito Hagio +Signed-off-by: Lianbo Jiang +--- + kernel.c | 20 +++++++++++++++----- + 1 file changed, 15 insertions(+), 5 deletions(-) + +diff --git a/kernel.c b/kernel.c +index 8ae9e0c169ff..a637dd0eb8f8 100644 +--- a/kernel.c ++++ b/kernel.c +@@ -10754,11 +10754,21 @@ is_pvops_xen(void) + STREQ(sym, "paravirt_patch_default"))) + return TRUE; + +- if (symbol_exists("xen_start_info") && +- readmem(symbol_value("xen_start_info"), KVADDR, &addr, +- sizeof(void *), "xen_start_info", RETURN_ON_ERROR) && +- addr != 0) +- return TRUE; ++ if (machine_type("X86") || machine_type("X86_64")) { ++ if (symbol_exists("xen_start_info") && ++ readmem(symbol_value("xen_start_info"), KVADDR, &addr, ++ sizeof(void *), "xen_start_info", RETURN_ON_ERROR) && ++ addr != 0) ++ return TRUE; ++ } ++ ++ if (machine_type("ARM") || machine_type("ARM64")) { ++ if (symbol_exists("xen_vcpu_info") && ++ readmem(symbol_value("xen_vcpu_info"), KVADDR, &addr, ++ sizeof(void *), "xen_vcpu_info", RETURN_ON_ERROR) && ++ addr != 0) ++ return TRUE; ++ } + + return FALSE; + } +-- +2.20.1 + diff --git a/SOURCES/0001-arm64-Support-overflow-stack-panic.patch b/SOURCES/0001-arm64-Support-overflow-stack-panic.patch new file mode 100644 index 0000000..e8cb3ac --- /dev/null +++ b/SOURCES/0001-arm64-Support-overflow-stack-panic.patch @@ -0,0 +1,379 @@ +From c05db8d7d83389a342664073547bd29eda900158 Mon Sep 17 00:00:00 2001 +From: Hong YANG +Date: Mon, 15 Nov 2021 15:41:01 +0800 +Subject: [PATCH 1/2] arm64: Support overflow stack panic + +Kernel commit <872d8327ce89> ("arm64: add VMAP_STACK overflow detection") +has supported the overflow stack exception handling. Without the patch, the +"bt" command will make crash generate a core dump because of segmentation +fault. With the patch, the "bt" command can display the overflow stack. + +Before: +crash> bt +PID: 3607 TASK: ffffffcbf9a4da00 CPU: 2 COMMAND: "sh" +Segmentation fault (core dumped) + +After: +crash> bt +PID: 3607 TASK: ffffffcbf9a4da00 CPU: 2 COMMAND: "sh" + #0 [ffffffccbfd85f50] __delay at ffffff8008ceded8 +... + #5 [ffffffccbfd85fd0] emergency_restart at ffffff80080d49fc + #6 [ffffffccbfd86140] panic at ffffff80080af4c0 + #7 [ffffffccbfd86150] nmi_panic at ffffff80080af150 + #8 [ffffffccbfd86190] handle_bad_stack at ffffff800808b0b8 + #9 [ffffffccbfd862d0] __bad_stack at ffffff800808285c + PC: ffffff8008082e80 [el1_sync] + LR: ffffff8000d6c214 [stack_overflow_demo+84] + SP: ffffff1a79930070 PSTATE: 204003c5 + X29: ffffff8011b03d00 X28: ffffffcbf9a4da00 X27: ffffff8008e02000 + X26: 0000000000000040 X25: 0000000000000124 X24: ffffffcbf9a4da00 + X23: 0000007daec2e288 X22: ffffffcbfe03b800 X21: 0000007daec2e288 + X20: 0000000000000002 X19: 0000000000000002 X18: 0000000000000002 + X17: 00000000000003e7 X16: 0000000000000000 X15: 0000000000000000 + X14: ffffffcc17facb00 X13: ffffffccb4c25c00 X12: 0000000000000000 + X11: ffffffcc17fad660 X10: 0000000000000af0 X9: 0000000000000000 + X8: ffffff1a799334f0 X7: 0000000000000000 X6: 000000000000003f + X5: 0000000000000040 X4: 0000000000000010 X3: 00000065981d07f0 + X2: 00000065981d07f0 X1: 0000000000000000 X0: ffffff1a799334f0 + +Signed-off-by: Hong YANG +--- + arm64.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++------ + defs.h | 6 ++ + 2 files changed, 159 insertions(+), 16 deletions(-) + +diff --git a/arm64.c b/arm64.c +index 94681d1a37db..23c3d75d85aa 100644 +--- a/arm64.c ++++ b/arm64.c +@@ -45,6 +45,7 @@ static int arm64_vtop_3level_4k(ulong, ulong, physaddr_t *, int); + static int arm64_vtop_4level_4k(ulong, ulong, physaddr_t *, int); + static ulong arm64_get_task_pgd(ulong); + static void arm64_irq_stack_init(void); ++static void arm64_overflow_stack_init(void); + static void arm64_stackframe_init(void); + static int arm64_eframe_search(struct bt_info *); + static int arm64_is_kernel_exception_frame(struct bt_info *, ulong); +@@ -63,6 +64,7 @@ static int arm64_get_dumpfile_stackframe(struct bt_info *, struct arm64_stackfra + static int arm64_in_kdump_text(struct bt_info *, struct arm64_stackframe *); + static int arm64_in_kdump_text_on_irq_stack(struct bt_info *); + static int arm64_switch_stack(struct bt_info *, struct arm64_stackframe *, FILE *); ++static int arm64_switch_stack_from_overflow(struct bt_info *, struct arm64_stackframe *, FILE *); + static int arm64_get_stackframe(struct bt_info *, struct arm64_stackframe *); + static void arm64_get_stack_frame(struct bt_info *, ulong *, ulong *); + static void arm64_gen_hidden_frame(struct bt_info *bt, ulong, struct arm64_stackframe *); +@@ -78,8 +80,11 @@ static int arm64_get_smp_cpus(void); + static void arm64_clear_machdep_cache(void); + static int arm64_on_process_stack(struct bt_info *, ulong); + static int arm64_in_alternate_stack(int, ulong); ++static int arm64_in_alternate_stackv(int cpu, ulong stkptr, ulong *stacks, ulong stack_size); + static int arm64_on_irq_stack(int, ulong); ++static int arm64_on_overflow_stack(int, ulong); + static void arm64_set_irq_stack(struct bt_info *); ++static void arm64_set_overflow_stack(struct bt_info *); + static void arm64_set_process_stack(struct bt_info *); + static int arm64_get_kvaddr_ranges(struct vaddr_range *); + static void arm64_get_crash_notes(void); +@@ -463,6 +468,7 @@ arm64_init(int when) + machdep->hz = 100; + + arm64_irq_stack_init(); ++ arm64_overflow_stack_init(); + arm64_stackframe_init(); + break; + +@@ -1715,6 +1721,49 @@ arm64_irq_stack_init(void) + } + } + ++/* ++ * Gather Overflow stack values. ++ * ++ * Overflow stack supported since 4.14, in commit 872d8327c ++ */ ++static void ++arm64_overflow_stack_init(void) ++{ ++ int i; ++ struct syment *sp; ++ struct gnu_request request, *req; ++ struct machine_specific *ms = machdep->machspec; ++ req = &request; ++ ++ if (symbol_exists("overflow_stack") && ++ (sp = per_cpu_symbol_search("overflow_stack")) && ++ get_symbol_type("overflow_stack", NULL, req)) { ++ if (CRASHDEBUG(1)) { ++ fprintf(fp, "overflow_stack: \n"); ++ fprintf(fp, " type: %x, %s\n", ++ (int)req->typecode, ++ (req->typecode == TYPE_CODE_ARRAY) ? ++ "TYPE_CODE_ARRAY" : "other"); ++ fprintf(fp, " target_typecode: %x, %s\n", ++ (int)req->target_typecode, ++ req->target_typecode == TYPE_CODE_INT ? ++ "TYPE_CODE_INT" : "other"); ++ fprintf(fp, " target_length: %ld\n", ++ req->target_length); ++ fprintf(fp, " length: %ld\n", req->length); ++ } ++ ++ if (!(ms->overflow_stacks = (ulong *)malloc((size_t)(kt->cpus * sizeof(ulong))))) ++ error(FATAL, "cannot malloc overflow_stack addresses\n"); ++ ++ ms->overflow_stack_size = ARM64_OVERFLOW_STACK_SIZE; ++ machdep->flags |= OVERFLOW_STACKS; ++ ++ for (i = 0; i < kt->cpus; i++) ++ ms->overflow_stacks[i] = kt->__per_cpu_offset[i] + sp->value; ++ } ++} ++ + /* + * Gather and verify all of the backtrace requirements. + */ +@@ -1960,6 +2009,7 @@ static char *arm64_exception_functions[] = { + "do_mem_abort", + "do_el0_irq_bp_hardening", + "do_sp_pc_abort", ++ "handle_bad_stack", + NULL + }; + +@@ -1978,7 +2028,10 @@ arm64_in_exception_text(ulong ptr) + if ((ptr >= ms->__exception_text_start) && + (ptr < ms->__exception_text_end)) + return TRUE; +- } else if ((name = closest_symbol(ptr))) { /* Linux 5.5 and later */ ++ } ++ ++ name = closest_symbol(ptr); ++ if (name != NULL) { /* Linux 5.5 and later */ + for (func = &arm64_exception_functions[0]; *func; func++) { + if (STREQ(name, *func)) + return TRUE; +@@ -2252,15 +2305,14 @@ arm64_unwind_frame(struct bt_info *bt, struct arm64_stackframe *frame) + if ((frame->fp == 0) && (frame->pc == 0)) + return FALSE; + +- if (!(machdep->flags & IRQ_STACKS)) +- return TRUE; +- +- if (!(machdep->flags & IRQ_STACKS)) ++ if (!(machdep->flags & (IRQ_STACKS | OVERFLOW_STACKS))) + return TRUE; + + if (machdep->flags & UNW_4_14) { +- if ((bt->flags & BT_IRQSTACK) && +- !arm64_on_irq_stack(bt->tc->processor, frame->fp)) { ++ if (((bt->flags & BT_IRQSTACK) && ++ !arm64_on_irq_stack(bt->tc->processor, frame->fp)) || ++ ((bt->flags & BT_OVERFLOW_STACK) && ++ !arm64_on_overflow_stack(bt->tc->processor, frame->fp))) { + if (arm64_on_process_stack(bt, frame->fp)) { + arm64_set_process_stack(bt); + +@@ -2677,6 +2729,9 @@ arm64_back_trace_cmd(struct bt_info *bt) + if (arm64_on_irq_stack(bt->tc->processor, bt->frameptr)) { + arm64_set_irq_stack(bt); + bt->flags |= BT_IRQSTACK; ++ } else if (arm64_on_overflow_stack(bt->tc->processor, bt->frameptr)) { ++ arm64_set_overflow_stack(bt); ++ bt->flags |= BT_OVERFLOW_STACK; + } + stackframe.sp = bt->stkptr; + stackframe.pc = bt->instptr; +@@ -2731,7 +2786,9 @@ arm64_back_trace_cmd(struct bt_info *bt) + break; + + if (arm64_in_exception_text(bt->instptr) && INSTACK(stackframe.fp, bt)) { +- if (!(bt->flags & BT_IRQSTACK) || ++ if (bt->flags & BT_OVERFLOW_STACK) { ++ exception_frame = stackframe.fp - KERN_EFRAME_OFFSET; ++ } else if (!(bt->flags & BT_IRQSTACK) || + ((stackframe.sp + SIZE(pt_regs)) < bt->stacktop)) { + if (arm64_is_kernel_exception_frame(bt, stackframe.fp - KERN_EFRAME_OFFSET)) + exception_frame = stackframe.fp - KERN_EFRAME_OFFSET; +@@ -2745,6 +2802,12 @@ arm64_back_trace_cmd(struct bt_info *bt) + break; + } + ++ if ((bt->flags & BT_OVERFLOW_STACK) && ++ !arm64_on_overflow_stack(bt->tc->processor, stackframe.fp)) { ++ bt->flags &= ~BT_OVERFLOW_STACK; ++ if (arm64_switch_stack_from_overflow(bt, &stackframe, ofp) == USER_MODE) ++ break; ++ } + + level++; + } +@@ -3131,6 +3194,43 @@ arm64_switch_stack(struct bt_info *bt, struct arm64_stackframe *frame, FILE *ofp + return KERNEL_MODE; + } + ++static int ++arm64_switch_stack_from_overflow(struct bt_info *bt, struct arm64_stackframe *frame, FILE *ofp) ++{ ++ int i; ++ ulong stacktop, words, addr; ++ ulong *stackbuf; ++ char buf[BUFSIZE]; ++ struct machine_specific *ms = machdep->machspec; ++ ++ if (bt->flags & BT_FULL) { ++ stacktop = ms->overflow_stacks[bt->tc->processor] + ms->overflow_stack_size; ++ words = (stacktop - bt->bptr) / sizeof(ulong); ++ stackbuf = (ulong *)GETBUF(words * sizeof(ulong)); ++ readmem(bt->bptr, KVADDR, stackbuf, words * sizeof(long), ++ "top of overflow stack", FAULT_ON_ERROR); ++ ++ addr = bt->bptr; ++ for (i = 0; i < words; i++) { ++ if (!(i & 1)) ++ fprintf(ofp, "%s %lx: ", i ? "\n" : "", addr); ++ fprintf(ofp, "%s ", format_stack_entry(bt, buf, stackbuf[i], 0)); ++ addr += sizeof(ulong); ++ } ++ fprintf(ofp, "\n"); ++ FREEBUF(stackbuf); ++ } ++ fprintf(ofp, "--- ---\n"); ++ ++ if (frame->fp == 0) ++ return USER_MODE; ++ ++ if (!(machdep->flags & UNW_4_14)) ++ arm64_print_exception_frame(bt, frame->sp, KERNEL_MODE, ofp); ++ ++ return KERNEL_MODE; ++} ++ + static int + arm64_get_dumpfile_stackframe(struct bt_info *bt, struct arm64_stackframe *frame) + { +@@ -3682,6 +3782,16 @@ arm64_display_machine_stats(void) + machdep->machspec->irq_stacks[i]); + } + } ++ if (machdep->machspec->overflow_stack_size) { ++ fprintf(fp, "OVERFLOW STACK SIZE: %ld\n", ++ machdep->machspec->overflow_stack_size); ++ fprintf(fp, " OVERFLOW STACKS:\n"); ++ for (i = 0; i < kt->cpus; i++) { ++ pad = (i < 10) ? 3 : (i < 100) ? 2 : (i < 1000) ? 1 : 0; ++ fprintf(fp, "%s CPU %d: %lx\n", space(pad), i, ++ machdep->machspec->overflow_stacks[i]); ++ } ++ } + } + + static int +@@ -3875,24 +3985,41 @@ arm64_on_process_stack(struct bt_info *bt, ulong stkptr) + } + + static int +-arm64_on_irq_stack(int cpu, ulong stkptr) ++arm64_in_alternate_stackv(int cpu, ulong stkptr, ulong *stacks, ulong stack_size) + { +- return arm64_in_alternate_stack(cpu, stkptr); ++ if ((cpu >= kt->cpus) || (stacks == NULL) || !stack_size) ++ return FALSE; ++ ++ if ((stkptr >= stacks[cpu]) && ++ (stkptr < (stacks[cpu] + stack_size))) ++ return TRUE; ++ ++ return FALSE; + } + + static int + arm64_in_alternate_stack(int cpu, ulong stkptr) ++{ ++ return (arm64_on_irq_stack(cpu, stkptr) || ++ arm64_on_overflow_stack(cpu, stkptr)); ++} ++ ++static int ++arm64_on_irq_stack(int cpu, ulong stkptr) + { + struct machine_specific *ms = machdep->machspec; + +- if (!ms->irq_stack_size || (cpu >= kt->cpus)) +- return FALSE; ++ return arm64_in_alternate_stackv(cpu, stkptr, ++ ms->irq_stacks, ms->irq_stack_size); ++} + +- if ((stkptr >= ms->irq_stacks[cpu]) && +- (stkptr < (ms->irq_stacks[cpu] + ms->irq_stack_size))) +- return TRUE; ++static int ++arm64_on_overflow_stack(int cpu, ulong stkptr) ++{ ++ struct machine_specific *ms = machdep->machspec; + +- return FALSE; ++ return arm64_in_alternate_stackv(cpu, stkptr, ++ ms->overflow_stacks, ms->overflow_stack_size); + } + + static void +@@ -3905,6 +4032,16 @@ arm64_set_irq_stack(struct bt_info *bt) + alter_stackbuf(bt); + } + ++static void ++arm64_set_overflow_stack(struct bt_info *bt) ++{ ++ struct machine_specific *ms = machdep->machspec; ++ ++ bt->stackbase = ms->overflow_stacks[bt->tc->processor]; ++ bt->stacktop = bt->stackbase + ms->overflow_stack_size; ++ alter_stackbuf(bt); ++} ++ + static void + arm64_set_process_stack(struct bt_info *bt) + { +diff --git a/defs.h b/defs.h +index 43eff46b105d..caaa11e50c87 100644 +--- a/defs.h ++++ b/defs.h +@@ -3218,6 +3218,7 @@ typedef signed int s32; + #define UNW_4_14 (0x200) + #define FLIPPED_VM (0x400) + #define HAS_PHYSVIRT_OFFSET (0x800) ++#define OVERFLOW_STACKS (0x1000) + + /* + * Get kimage_voffset from /dev/crash +@@ -3260,6 +3261,7 @@ typedef signed int s32; + + #define ARM64_STACK_SIZE (16384) + #define ARM64_IRQ_STACK_SIZE ARM64_STACK_SIZE ++#define ARM64_OVERFLOW_STACK_SIZE (4096) + + #define _SECTION_SIZE_BITS 30 + #define _SECTION_SIZE_BITS_5_12 27 +@@ -3332,6 +3334,9 @@ struct machine_specific { + char *irq_stackbuf; + ulong __irqentry_text_start; + ulong __irqentry_text_end; ++ ulong overflow_stack_size; ++ ulong *overflow_stacks; ++ char *overflow_stackbuf; + /* for exception vector code */ + ulong exp_entry1_start; + ulong exp_entry1_end; +@@ -5778,6 +5783,7 @@ ulong cpu_map_addr(const char *type); + #define BT_CPUMASK (0x1000000000000ULL) + #define BT_SHOW_ALL_REGS (0x2000000000000ULL) + #define BT_REGS_NOT_FOUND (0x4000000000000ULL) ++#define BT_OVERFLOW_STACK (0x8000000000000ULL) + #define BT_SYMBOL_OFFSET (BT_SYMBOLIC_ARGS) + + #define BT_REF_HEXVAL (0x1) +-- +2.30.2 + diff --git a/SOURCES/0002-Handle-blk_mq_ctx-member-changes-for-kernels-5.16-rc.patch b/SOURCES/0002-Handle-blk_mq_ctx-member-changes-for-kernels-5.16-rc.patch new file mode 100644 index 0000000..b9091cc --- /dev/null +++ b/SOURCES/0002-Handle-blk_mq_ctx-member-changes-for-kernels-5.16-rc.patch @@ -0,0 +1,101 @@ +From 78255e3b33f8d51eb893e662dd1b05a008246b9d Mon Sep 17 00:00:00 2001 +From: Lianbo Jiang +Date: Fri, 24 Dec 2021 18:56:35 +0800 +Subject: [PATCH 02/11] Handle blk_mq_ctx member changes for kernels 5.16-rc1 + and later + +Kernel commit 9a14d6ce4135 ("block: remove debugfs blk_mq_ctx +dispatched/merged/completed attributes") removed the member +rq_dispatched and rq_completed from struct blk_mq_ctx. Without +the patch, "dev -d|-D" options will fail with the following error: + +crash> dev -d +MAJOR GENDISK NAME REQUEST_QUEUE TOTAL ASYNC SYNC + +dev: invalid structure member offset: blk_mq_ctx_rq_dispatched + FILE: dev.c LINE: 4229 FUNCTION: get_one_mctx_diskio() + +Signed-off-by: Lianbo Jiang +Signed-off-by: Kazuhito Hagio +--- + dev.c | 57 +++++++++++++++++++++++++++++++++++++++------------------ + 1 file changed, 39 insertions(+), 18 deletions(-) + +diff --git a/dev.c b/dev.c +index effe789f38d8..a493e51ac95c 100644 +--- a/dev.c ++++ b/dev.c +@@ -4246,6 +4246,10 @@ get_mq_diskio(unsigned long q, unsigned long *mq_count) + unsigned long mctx_addr; + struct diskio tmp; + ++ if (INVALID_MEMBER(blk_mq_ctx_rq_dispatched) || ++ INVALID_MEMBER(blk_mq_ctx_rq_completed)) ++ return; ++ + memset(&tmp, 0x00, sizeof(struct diskio)); + + readmem(q + OFFSET(request_queue_queue_ctx), KVADDR, &queue_ctx, +@@ -4475,24 +4479,41 @@ display_one_diskio(struct iter *i, unsigned long gendisk, ulong flags) + && (io.read + io.write == 0)) + return; + +- fprintf(fp, "%s%s%s %s%s%s%s %s%5d%s%s%s%s%s", +- mkstring(buf0, 5, RJUST|INT_DEC, (char *)(unsigned long)major), +- space(MINSPACE), +- mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, (char *)gendisk), +- space(MINSPACE), +- mkstring(buf2, 10, LJUST, disk_name), +- space(MINSPACE), +- mkstring(buf3, VADDR_PRLEN <= 11 ? 11 : VADDR_PRLEN, +- LJUST|LONG_HEX, (char *)queue_addr), +- space(MINSPACE), +- io.read + io.write, +- space(MINSPACE), +- mkstring(buf4, 5, RJUST|INT_DEC, +- (char *)(unsigned long)io.read), +- space(MINSPACE), +- mkstring(buf5, 5, RJUST|INT_DEC, +- (char *)(unsigned long)io.write), +- space(MINSPACE)); ++ if (use_mq_interface(queue_addr) && ++ (INVALID_MEMBER(blk_mq_ctx_rq_dispatched) || ++ INVALID_MEMBER(blk_mq_ctx_rq_completed))) ++ fprintf(fp, "%s%s%s %s%s%s%s %s%s%s", ++ mkstring(buf0, 5, RJUST|INT_DEC, (char *)(unsigned long)major), ++ space(MINSPACE), ++ mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, (char *)gendisk), ++ space(MINSPACE), ++ mkstring(buf2, 10, LJUST, disk_name), ++ space(MINSPACE), ++ mkstring(buf3, VADDR_PRLEN <= 11 ? 11 : VADDR_PRLEN, ++ LJUST|LONG_HEX, (char *)queue_addr), ++ space(MINSPACE), ++ mkstring(buf4, 17, RJUST, "(not supported)"), ++ space(MINSPACE)); ++ ++ else ++ fprintf(fp, "%s%s%s %s%s%s%s %s%5d%s%s%s%s%s", ++ mkstring(buf0, 5, RJUST|INT_DEC, (char *)(unsigned long)major), ++ space(MINSPACE), ++ mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, (char *)gendisk), ++ space(MINSPACE), ++ mkstring(buf2, 10, LJUST, disk_name), ++ space(MINSPACE), ++ mkstring(buf3, VADDR_PRLEN <= 11 ? 11 : VADDR_PRLEN, ++ LJUST|LONG_HEX, (char *)queue_addr), ++ space(MINSPACE), ++ io.read + io.write, ++ space(MINSPACE), ++ mkstring(buf4, 5, RJUST|INT_DEC, ++ (char *)(unsigned long)io.read), ++ space(MINSPACE), ++ mkstring(buf5, 5, RJUST|INT_DEC, ++ (char *)(unsigned long)io.write), ++ space(MINSPACE)); + + if (VALID_MEMBER(request_queue_in_flight)) { + if (!use_mq_interface(queue_addr)) { +-- +2.20.1 + diff --git a/SOURCES/0002-defs.h-fix-breakage-of-compatibility-of-struct-symbo.patch b/SOURCES/0002-defs.h-fix-breakage-of-compatibility-of-struct-symbo.patch new file mode 100644 index 0000000..1415a8c --- /dev/null +++ b/SOURCES/0002-defs.h-fix-breakage-of-compatibility-of-struct-symbo.patch @@ -0,0 +1,41 @@ +From a0eec39c14ee1db95a6c1a649a8f69b97e260dc6 Mon Sep 17 00:00:00 2001 +From: HATAYAMA Daisuke +Date: Wed, 8 Dec 2021 12:07:34 +0000 +Subject: [PATCH 2/2] defs.h: fix breakage of compatibility of struct + symbol_table_data for extension modules + +Commit <3ab39203ddd9> ("symbols: Implement install and remove operations +for mod_symname_hash") added new member variable mod_symname_hash in the +middle of struct symbol_table_date, which breaks compatibility of struct +symbol_table_data for extension modules. As the result, crash trace command +results in segmentation fault. + +Fixes: 3ab39203ddd9 ("symbols: Implement install and remove operations for mod_symname_hash") +Signed-off-by: HATAYAMA Daisuke +--- + defs.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/defs.h b/defs.h +index caaa11e50c87..41b6cbc6cc85 100644 +--- a/defs.h ++++ b/defs.h +@@ -2753,7 +2753,6 @@ struct symbol_table_data { + double val_hash_searches; + double val_hash_iterations; + struct syment *symname_hash[SYMNAME_HASH]; +- struct syment *mod_symname_hash[SYMNAME_HASH]; + struct symbol_namespace kernel_namespace; + struct syment *ext_module_symtable; + struct syment *ext_module_symend; +@@ -2780,6 +2779,7 @@ struct symbol_table_data { + ulong kaiser_init_vmlinux; + int kernel_symbol_type; + ulong linux_banner_vmlinux; ++ struct syment *mod_symname_hash[SYMNAME_HASH]; + }; + + /* flags for st */ +-- +2.30.2 + diff --git a/SOURCES/0003-Fix-for-timer-r-option-to-display-all-the-per-CPU-cl.patch b/SOURCES/0003-Fix-for-timer-r-option-to-display-all-the-per-CPU-cl.patch new file mode 100644 index 0000000..4a95e79 --- /dev/null +++ b/SOURCES/0003-Fix-for-timer-r-option-to-display-all-the-per-CPU-cl.patch @@ -0,0 +1,59 @@ +From c48177972f351d7853abb2a57709628c75ee38bc Mon Sep 17 00:00:00 2001 +From: Lianbo Jiang +Date: Thu, 6 Jan 2022 22:34:26 +0800 +Subject: [PATCH 03/11] Fix for "timer -r" option to display all the per-CPU + clocks + +Currently, the hrtimer_max_clock_bases is hard-coded to 3, which +makes that crash only prints three clocks, and the rest of clocks +are not displayed. + +Without the patch: +crash> timer -r -C 11 +CPU: 11 HRTIMER_CPU_BASE: ffff9a775f95ee00 + CLOCK: 0 HRTIMER_CLOCK_BASE: ffff9a775f95ee80 [ktime_get] + (empty) + + CLOCK: 1 HRTIMER_CLOCK_BASE: ffff9a775f95ef00 [ktime_get_real] + (empty) + + CLOCK: 2 HRTIMER_CLOCK_BASE: ffff9a775f95ef80 [ktime_get_boottime] + (empty) + +With the patch: +crash> timer -r -C 11 +CPU: 11 HRTIMER_CPU_BASE: ffff9a775f95ee00 + CLOCK: 0 HRTIMER_CLOCK_BASE: ffff9a775f95ee80 [ktime_get] + (empty) + + CLOCK: 1 HRTIMER_CLOCK_BASE: ffff9a775f95ef00 [ktime_get_real] + (empty) + + CLOCK: 2 HRTIMER_CLOCK_BASE: ffff9a775f95ef80 [ktime_get_boottime] + (empty) +... + CLOCK: 7 HRTIMER_CLOCK_BASE: ffff9a775f95f200 [ktime_get_clocktai] + (empty) + +Signed-off-by: Lianbo Jiang +--- + kernel.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/kernel.c b/kernel.c +index a637dd0eb8f8..a44a9c52ace0 100644 +--- a/kernel.c ++++ b/kernel.c +@@ -7672,7 +7672,8 @@ dump_hrtimer_data(const ulong *cpus) + if (VALID_STRUCT(hrtimer_clock_base)) { + hrtimer_max_clock_bases = 2; + if (symbol_exists("ktime_get_boottime")) +- hrtimer_max_clock_bases = 3; ++ hrtimer_max_clock_bases = MEMBER_SIZE("hrtimer_cpu_base", "clock_base") / ++ SIZE(hrtimer_clock_base); + } else if (VALID_STRUCT(hrtimer_base)) { + max_hrtimer_bases = 2; + } else +-- +2.20.1 + diff --git a/SOURCES/0004-Fix-for-bt-v-option-to-display-the-stack-end-address.patch b/SOURCES/0004-Fix-for-bt-v-option-to-display-the-stack-end-address.patch new file mode 100644 index 0000000..0c56e07 --- /dev/null +++ b/SOURCES/0004-Fix-for-bt-v-option-to-display-the-stack-end-address.patch @@ -0,0 +1,69 @@ +From 1706f8b6ab50cd25e8fdabe8d50a37ce89bd60e0 Mon Sep 17 00:00:00 2001 +From: Lianbo Jiang +Date: Thu, 6 Jan 2022 12:01:17 +0800 +Subject: [PATCH 04/11] Fix for "bt -v" option to display the stack-end address + correctly + +The "bt -v" command prints incorrect stack-end address when the +"CONFIG_THREAD_INFO_IN_TASK=y" is enabled in kernel, the "bt -v" +command output shows that the value stored at 0xffff8dee0312c198 +is 0xffffffffc076400a, however, the value stored actually at +0xffff8dee0312c198 is NULL(0x0000000000000000), the stack-end +address is incorrect. + +Without the patch: +crash> bt -v +PID: 28642 TASK: ffff8dee0312c180 CPU: 0 COMMAND: "insmod" + possible stack overflow: ffff8dee0312c198: ffffffffc076400a != STACK_END_MAGIC + ^^^^^^^^^^^^^^^^ + +crash> rd 0xffff8dee0312c198 +ffff8dee0312c198: 0000000000000000 ........ + ^^^^^^^^^^^^^^^^ + +With the patch: +crash> bt -v +PID: 28642 TASK: ffff8dee0312c180 CPU: 0 COMMAND: "insmod" + possible stack overflow: ffff991340bc0000: ffffffffc076400a != STACK_END_MAGIC + +crash> rd 0xffff991340bc0000 +ffff991340bc0000: ffffffffc076400a .@v..... + +Signed-off-by: Lianbo Jiang +--- + task.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/task.c b/task.c +index bb6a5da8ad33..b5ddc88e0acb 100644 +--- a/task.c ++++ b/task.c +@@ -11202,7 +11202,7 @@ check_stack_overflow(void) + { + int i, overflow, cpu_size, cpu, total; + char buf[BUFSIZE]; +- ulong magic, task, stackbase; ++ ulong magic, task, stackbase, location; + struct task_context *tc; + + if (!tt->stack_end_magic && +@@ -11286,9 +11286,15 @@ check_stack_end_magic: + if (magic != STACK_END_MAGIC) { + if (!overflow) + print_task_header(fp, tc, 0); ++ ++ if (tt->flags & THREAD_INFO_IN_TASK) ++ location = task_to_stackbase(tc->task); ++ else ++ location = tc->thread_info + SIZE(thread_info); ++ + fprintf(fp, + " possible stack overflow: %lx: %lx != STACK_END_MAGIC\n", +- tc->thread_info + SIZE(thread_info), magic); ++ location, magic); + overflow++, total++; + } + +-- +2.20.1 + diff --git a/SOURCES/0005-Fix-for-HZ-calculation-on-Linux-5.14-and-later.patch b/SOURCES/0005-Fix-for-HZ-calculation-on-Linux-5.14-and-later.patch new file mode 100644 index 0000000..f249f72 --- /dev/null +++ b/SOURCES/0005-Fix-for-HZ-calculation-on-Linux-5.14-and-later.patch @@ -0,0 +1,35 @@ +From f5637f341533ef2b28e2d6a6b12fcfb00d0fff2d Mon Sep 17 00:00:00 2001 +From: Lianbo Jiang +Date: Mon, 10 Jan 2022 17:25:06 +0800 +Subject: [PATCH 05/11] Fix for HZ calculation on Linux 5.14 and later + +Kernel commit 3e9a99eba058 ("block/mq-deadline: Rename dd_init_queue() +and dd_exit_queue()") renamed dd_init_queue to dd_init_sched. Without +the patch, the 'help -m' may print incorrect hz value as follows: + +crash> help -m | grep hz + hz: 1000 <---The correct hz value on ppc64le machine is 100. + ^^^^ + +Fixes: b93027ce5c75 ("Add alternate HZ calculation using write_expire") +Signed-off-by: Lianbo Jiang +--- + task.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/task.c b/task.c +index b5ddc88e0acb..76e184ae70b1 100644 +--- a/task.c ++++ b/task.c +@@ -440,6 +440,8 @@ task_init(void) + } + } else if ((symbol_exists("dd_init_queue") && + gdb_set_crash_scope(symbol_value("dd_init_queue"), "dd_init_queue")) || ++ (symbol_exists("dd_init_sched") && ++ gdb_set_crash_scope(symbol_value("dd_init_sched"), "dd_init_sched")) || + (symbol_exists("deadline_init_queue") && + gdb_set_crash_scope(symbol_value("deadline_init_queue"), "deadline_init_queue"))) { + char buf[BUFSIZE]; +-- +2.20.1 + diff --git a/SOURCES/0006-memory-Handle-struct-slab-changes-on-Linux-5.17-rc1-.patch b/SOURCES/0006-memory-Handle-struct-slab-changes-on-Linux-5.17-rc1-.patch new file mode 100644 index 0000000..7407306 --- /dev/null +++ b/SOURCES/0006-memory-Handle-struct-slab-changes-on-Linux-5.17-rc1-.patch @@ -0,0 +1,40 @@ +From a392b27653e4e75460753522af0f006006b4dc4e Mon Sep 17 00:00:00 2001 +From: Alexander Egorenkov +Date: Mon, 6 Dec 2021 16:04:19 +0100 +Subject: [PATCH 06/11] memory: Handle struct slab changes on Linux 5.17-rc1 + and later + +Since kernel commit d122019bf061 ("mm: Split slab into its own type"), +the struct slab is used for both SLAB and SLUB. Therefore, don't depend +on the non-presence of the struct slab to decide whether SLAB implementation +should be chosen and use the member variable "cpu_slab" of the struct +kmem_cache instead, it should be present only in SLUB. + +Without the patch, crash fails to start with the error message: + + crash: invalid structure member offset: kmem_cache_s_num + FILE: memory.c LINE: 9619 FUNCTION: kmem_cache_init() + +Signed-off-by: Alexander Egorenkov +Signed-off-by: Lianbo Jiang +--- + memory.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/memory.c b/memory.c +index 86c02c132890..5af45fd7d834 100644 +--- a/memory.c ++++ b/memory.c +@@ -576,7 +576,8 @@ vm_init(void) + STRUCT_SIZE_INIT(cpucache_s, "cpucache_s"); + + } else if (!VALID_STRUCT(kmem_slab_s) && +- !VALID_STRUCT(slab_s) && ++ !VALID_STRUCT(slab_s) && ++ !MEMBER_EXISTS("kmem_cache", "cpu_slab") && + (VALID_STRUCT(slab) || (vt->flags & SLAB_OVERLOAD_PAGE))) { + vt->flags |= PERCPU_KMALLOC_V2; + +-- +2.20.1 + diff --git a/SOURCES/0007-Move-the-initialization-of-boot_date-to-task_init.patch b/SOURCES/0007-Move-the-initialization-of-boot_date-to-task_init.patch new file mode 100644 index 0000000..c8d8227 --- /dev/null +++ b/SOURCES/0007-Move-the-initialization-of-boot_date-to-task_init.patch @@ -0,0 +1,75 @@ +From fa0b6453a05c5600849e4e531c94594ed9c90270 Mon Sep 17 00:00:00 2001 +From: Lianbo Jiang +Date: Mon, 17 Jan 2022 15:14:00 +0800 +Subject: [PATCH 07/11] Move the initialization of "boot_date" to task_init() + +The "boot_date" is initialized conditionally in the cmd_log(), which may +display incorrect "boot_date" value with the following command before +running the "log -T" command: + +crash> help -k | grep date + date: Wed Dec 22 13:39:29 IST 2021 + boot_date: Thu Jan 1 05:30:00 IST 1970 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The calculation of "boot_date" depends on the HZ value, and the HZ will +be calculated in task_init() at the latest, so let's move it here. + +Signed-off-by: Lianbo Jiang +--- + kernel.c | 18 +++--------------- + task.c | 10 ++++++++++ + 2 files changed, 13 insertions(+), 15 deletions(-) + +diff --git a/kernel.c b/kernel.c +index a44a9c52ace0..9afddc0c918c 100644 +--- a/kernel.c ++++ b/kernel.c +@@ -5026,21 +5026,9 @@ cmd_log(void) + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + +- if (msg_flags & SHOW_LOG_CTIME) { +- if (pc->flags & MINIMAL_MODE) { +- error(WARNING, "the option '-T' is not available in minimal mode\n"); +- return; +- } +- +- if (kt->boot_date.tv_sec == 0) { +- ulonglong uptime_jiffies; +- ulong uptime_sec; +- +- get_uptime(NULL, &uptime_jiffies); +- uptime_sec = (uptime_jiffies)/(ulonglong)machdep->hz; +- kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec; +- kt->boot_date.tv_nsec = 0; +- } ++ if (msg_flags & SHOW_LOG_CTIME && pc->flags & MINIMAL_MODE) { ++ error(WARNING, "the option '-T' is not available in minimal mode\n"); ++ return; + } + + if (msg_flags & SHOW_LOG_AUDIT) { +diff --git a/task.c b/task.c +index 76e184ae70b1..263a8344dd94 100644 +--- a/task.c ++++ b/task.c +@@ -692,6 +692,16 @@ task_init(void) + + stack_overflow_check_init(); + ++ if (machdep->hz) { ++ ulonglong uptime_jiffies; ++ ulong uptime_sec; ++ ++ get_uptime(NULL, &uptime_jiffies); ++ uptime_sec = (uptime_jiffies)/(ulonglong)machdep->hz; ++ kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec; ++ kt->boot_date.tv_nsec = 0; ++ } ++ + tt->flags |= TASK_INIT_DONE; + } + +-- +2.20.1 + diff --git a/SOURCES/0008-Remove-ptype-command-from-ps-t-option-to-reduce-memo.patch b/SOURCES/0008-Remove-ptype-command-from-ps-t-option-to-reduce-memo.patch new file mode 100644 index 0000000..ee7a5cd --- /dev/null +++ b/SOURCES/0008-Remove-ptype-command-from-ps-t-option-to-reduce-memo.patch @@ -0,0 +1,79 @@ +From bbd5a5c1f5db3bde04628e75396155260333e53e Mon Sep 17 00:00:00 2001 +From: Kazuhito Hagio +Date: Wed, 19 Jan 2022 16:24:49 +0900 +Subject: [PATCH 08/11] Remove ptype command from "ps -t" option to reduce + memory and time + +With some vmlinux e.g. RHEL9 ones, the first execution of the gdb ptype +command heavily consumes memory and time. The "ps -t" option uses it in +start_time_timespec(), and it can be replaced with the crash macros. + +This can reduce about 1.4 GB memory and 6 seconds time comsumption in +the following test: + + $ echo "ps -t" | time crash vmlinux vmcore + + Without the patch: + 11.60user 0.43system 0:11.94elapsed 100%CPU (0avgtext+0avgdata 1837964maxresident)k + 0inputs+400outputs (0major+413636minor)pagefaults 0swaps + + With the patch: + 5.40user 0.16system 0:05.46elapsed 101%CPU (0avgtext+0avgdata 417896maxresident)k + 0inputs+384outputs (0major+41528minor)pagefaults 0swaps + +Although the ptype command and similar ones cannot be fully removed, +but removing some of them will make the use of crash safer, especially +for an automatic crash reporter. + +Signed-off-by: Kazuhito Hagio +Signed-off-by: Lianbo Jiang +--- + task.c | 25 +++++-------------------- + 1 file changed, 5 insertions(+), 20 deletions(-) + +diff --git a/task.c b/task.c +index 263a8344dd94..a79ed0d96fb5 100644 +--- a/task.c ++++ b/task.c +@@ -4662,8 +4662,6 @@ show_task_times(struct task_context *tcp, ulong flags) + static int + start_time_timespec(void) + { +- char buf[BUFSIZE]; +- + switch(tt->flags & (TIMESPEC | NO_TIMESPEC | START_TIME_NSECS)) + { + case TIMESPEC: +@@ -4677,24 +4675,11 @@ start_time_timespec(void) + + tt->flags |= NO_TIMESPEC; + +- open_tmpfile(); +- sprintf(buf, "ptype struct task_struct"); +- if (!gdb_pass_through(buf, NULL, GNU_RETURN_ON_ERROR)) { +- close_tmpfile(); +- return FALSE; +- } +- +- rewind(pc->tmpfile); +- while (fgets(buf, BUFSIZE, pc->tmpfile)) { +- if (strstr(buf, "start_time;")) { +- if (strstr(buf, "struct timespec")) { +- tt->flags &= ~NO_TIMESPEC; +- tt->flags |= TIMESPEC; +- } +- } +- } +- +- close_tmpfile(); ++ if (VALID_MEMBER(task_struct_start_time) && ++ STREQ(MEMBER_TYPE_NAME("task_struct", "start_time"), "timespec")) { ++ tt->flags &= ~NO_TIMESPEC; ++ tt->flags |= TIMESPEC; ++ } + + if ((tt->flags & NO_TIMESPEC) && (SIZE(task_struct_start_time) == 8)) { + tt->flags &= ~NO_TIMESPEC; +-- +2.20.1 + diff --git a/SOURCES/0009-Improve-the-ps-performance-for-vmcores-with-large-nu.patch b/SOURCES/0009-Improve-the-ps-performance-for-vmcores-with-large-nu.patch new file mode 100644 index 0000000..c398eb8 --- /dev/null +++ b/SOURCES/0009-Improve-the-ps-performance-for-vmcores-with-large-nu.patch @@ -0,0 +1,150 @@ +From d52cccfaa96ed6f61ff9d53da88715296e31db80 Mon Sep 17 00:00:00 2001 +From: Tao Liu +Date: Fri, 21 Jan 2022 13:43:09 +0800 +Subject: [PATCH 09/11] Improve the ps performance for vmcores with large + number of threads + +Previously, the ps command will iterate over all threads which +have the same tgid, to accumulate their rss value, in order to +get a thread/process's final rss value as part of the final output. + +For non-live systems, the rss accumulation values are identical for +threads which have the same tgid, so there is no need to do the +iteration and accumulation repeatly, thus a lot of readmem calls are +skipped. Otherwise it will be the performance bottleneck if the +vmcores have a large number of threads. + +In this patch, the rss accumulation value will be stored in a cache, +next time a thread with the same tgid will take it directly without +the iteration. + +For example, we can monitor the performance issue when a vmcore has +~65k processes, most of which are threads for several specific +processes. Without the patch, it will take ~7h for ps command +to finish. With the patch, ps command will finish in 1min. + +Signed-off-by: Tao Liu +Signed-off-by: Lianbo Jiang +--- + defs.h | 1 + + memory.c | 70 +++++++++++++++++++++++++++++++------------------------- + task.c | 1 + + 3 files changed, 41 insertions(+), 31 deletions(-) + +diff --git a/defs.h b/defs.h +index 41b6cbc6cc85..77e76f27cddb 100644 +--- a/defs.h ++++ b/defs.h +@@ -830,6 +830,7 @@ struct task_context { /* context stored for each task */ + struct tgid_context { /* tgid and task stored for each task */ + ulong tgid; + ulong task; ++ long rss_cache; + }; + + struct task_table { /* kernel/local task table data */ +diff --git a/memory.c b/memory.c +index 5af45fd7d834..e80c59ea4534 100644 +--- a/memory.c ++++ b/memory.c +@@ -4665,7 +4665,7 @@ void + get_task_mem_usage(ulong task, struct task_mem_usage *tm) + { + struct task_context *tc; +- long rss = 0; ++ long rss = 0, rss_cache = 0; + + BZERO(tm, sizeof(struct task_mem_usage)); + +@@ -4730,38 +4730,46 @@ get_task_mem_usage(ulong task, struct task_mem_usage *tm) + (last->tgid == (last + 1)->tgid)) + last++; + +- while (first <= last) +- { +- /* count 0 -> filepages */ +- if (!readmem(first->task + +- OFFSET(task_struct_rss_stat) + +- OFFSET(task_rss_stat_count), KVADDR, +- &sync_rss, +- sizeof(int), +- "task_struct rss_stat MM_FILEPAGES", +- RETURN_ON_ERROR)) +- continue; +- +- rss += sync_rss; +- +- /* count 1 -> anonpages */ +- if (!readmem(first->task + +- OFFSET(task_struct_rss_stat) + +- OFFSET(task_rss_stat_count) + +- sizeof(int), +- KVADDR, &sync_rss, +- sizeof(int), +- "task_struct rss_stat MM_ANONPAGES", +- RETURN_ON_ERROR)) +- continue; +- +- rss += sync_rss; +- +- if (first == last) +- break; +- first++; ++ /* ++ * Using rss cache for dumpfile is more beneficial than live debug ++ * because its value never changes in dumpfile. ++ */ ++ if (ACTIVE() || last->rss_cache == UNINITIALIZED) { ++ while (first <= last) ++ { ++ /* count 0 -> filepages */ ++ if (!readmem(first->task + ++ OFFSET(task_struct_rss_stat) + ++ OFFSET(task_rss_stat_count), KVADDR, ++ &sync_rss, ++ sizeof(int), ++ "task_struct rss_stat MM_FILEPAGES", ++ RETURN_ON_ERROR)) ++ continue; ++ ++ rss_cache += sync_rss; ++ ++ /* count 1 -> anonpages */ ++ if (!readmem(first->task + ++ OFFSET(task_struct_rss_stat) + ++ OFFSET(task_rss_stat_count) + ++ sizeof(int), ++ KVADDR, &sync_rss, ++ sizeof(int), ++ "task_struct rss_stat MM_ANONPAGES", ++ RETURN_ON_ERROR)) ++ continue; ++ ++ rss_cache += sync_rss; ++ ++ if (first == last) ++ break; ++ first++; ++ } ++ last->rss_cache = rss_cache; + } + ++ rss += last->rss_cache; + tt->last_tgid = last; + } + } +diff --git a/task.c b/task.c +index a79ed0d96fb5..864c838637ee 100644 +--- a/task.c ++++ b/task.c +@@ -2947,6 +2947,7 @@ add_context(ulong task, char *tp) + tg = tt->tgid_array + tt->running_tasks; + tg->tgid = *tgid_addr; + tg->task = task; ++ tg->rss_cache = UNINITIALIZED; + + if (do_verify && !verify_task(tc, do_verify)) { + error(INFO, "invalid task address: %lx\n", tc->task); +-- +2.20.1 + diff --git a/SOURCES/0010-arm64-Fix-segfault-by-bt-command-with-offline-cpus.patch b/SOURCES/0010-arm64-Fix-segfault-by-bt-command-with-offline-cpus.patch new file mode 100644 index 0000000..1c4040f --- /dev/null +++ b/SOURCES/0010-arm64-Fix-segfault-by-bt-command-with-offline-cpus.patch @@ -0,0 +1,59 @@ +From 1a1fd21c625cb2ca335e626eb50426f13c4160f7 Mon Sep 17 00:00:00 2001 +From: Kazuhito Hagio +Date: Wed, 26 Jan 2022 06:07:00 +0000 +Subject: [PATCH 10/11] arm64: Fix segfault by "bt" command with offline cpus + +Currently on arm64, NT_PRSTATUS notes in dumpfile are not mapped to +online cpus and machine_specific->panic_task_regs correctly. As a +result, the "bt" command can cause a segmentation fault. + + crash> bt -c 0 + PID: 0 TASK: ffff8000117fa240 CPU: 0 COMMAND: "swapper/0" + Segmentation fault (core dumped) + +To fix this, +1) make map_cpus_to_prstatus_kdump_cmprs() map the notes to + dd->nt_prstatus_percpu also on arm64, and +2) move arm64_get_crash_notes() to machdep_init(POST_INIT) in order + to apply the mapping to machine_specific->panic_task_regs. + +Resolves: https://github.com/crash-utility/crash/issues/105 +Reported-by: xuchunmei000 +Signed-off-by: Kazuhito Hagio +Tested-by: David Wysochanski +Signed-off-by: Lianbo Jiang +--- + arm64.c | 2 +- + diskdump.c | 3 +-- + 2 files changed, 2 insertions(+), 3 deletions(-) + +diff --git a/arm64.c b/arm64.c +index 23c3d75d85aa..4f2c2b5104a1 100644 +--- a/arm64.c ++++ b/arm64.c +@@ -472,7 +472,7 @@ arm64_init(int when) + arm64_stackframe_init(); + break; + +- case POST_VM: ++ case POST_INIT: + /* + * crash_notes contains machine specific information about the + * crash. In particular, it contains CPU registers at the time +diff --git a/diskdump.c b/diskdump.c +index 112f769f8949..690b42443ed2 100644 +--- a/diskdump.c ++++ b/diskdump.c +@@ -111,8 +111,7 @@ map_cpus_to_prstatus_kdump_cmprs(void) + if (pc->flags2 & QEMU_MEM_DUMP_COMPRESSED) /* notes exist for all cpus */ + goto resize_note_pointers; + +- if (!(online = get_cpus_online()) || (online == kt->cpus) || +- machine_type("ARM64")) ++ if (!(online = get_cpus_online()) || (online == kt->cpus)) + goto resize_note_pointers; + + if (CRASHDEBUG(1)) +-- +2.20.1 + diff --git a/SOURCES/0011-Fix-for-kmem-s-S-and-bt-F-F-on-Linux-5.17-rc1.patch b/SOURCES/0011-Fix-for-kmem-s-S-and-bt-F-F-on-Linux-5.17-rc1.patch new file mode 100644 index 0000000..1bd6774 --- /dev/null +++ b/SOURCES/0011-Fix-for-kmem-s-S-and-bt-F-F-on-Linux-5.17-rc1.patch @@ -0,0 +1,89 @@ +From 86446eaba408807e00cf2310d5748aa6b7511284 Mon Sep 17 00:00:00 2001 +From: Kazuhito Hagio +Date: Wed, 2 Feb 2022 02:14:56 +0000 +Subject: [PATCH 11/11] Fix for "kmem -s|-S" and "bt -F[F]" on Linux 5.17-rc1 + +Since the following kernel commits split slab info from struct page +into struct slab, crash cannot get several slab related offsets from +struct page. + + d122019bf061 ("mm: Split slab into its own type") + 07f910f9b729 ("mm: Remove slab from struct page") + +Without the patch, "kmem -s|-S" and "bt -F[F]" options cannot work +correctly with the following errors: + + crash> kmem -s kmem_cache + CACHE OBJSIZE ALLOCATED TOTAL SLABS SSIZE NAME + kmem: page_to_nid: invalid page: ffff9454afc35020 + kmem: kmem_cache: cannot gather relevant slab data + ffff945140042000 216 ? ? ? 8k kmem_cache + + crash> bt -F + ... + bt: invalid structure member offset: page_slab + FILE: memory.c LINE: 9477 FUNCTION: vaddr_to_kmem_cache() + +Signed-by: Kazuhito Hagio +Signed-off-by: Lianbo Jiang +--- + memory.c | 13 +++++++++++++ + 1 file changed, 13 insertions(+) + +diff --git a/memory.c b/memory.c +index e80c59ea4534..8448ddc3a16c 100644 +--- a/memory.c ++++ b/memory.c +@@ -421,6 +421,8 @@ vm_init(void) + MEMBER_OFFSET_INIT(page_prev, "page", "prev"); + if (INVALID_MEMBER(page_next)) + ANON_MEMBER_OFFSET_INIT(page_next, "page", "next"); ++ if (INVALID_MEMBER(page_next)) ++ MEMBER_OFFSET_INIT(page_next, "slab", "next"); + + MEMBER_OFFSET_INIT(page_list, "page", "list"); + if (VALID_MEMBER(page_list)) { +@@ -747,11 +749,15 @@ vm_init(void) + MEMBER_OFFSET_INIT(kmem_cache_random, "kmem_cache", "random"); + MEMBER_OFFSET_INIT(kmem_cache_cpu_freelist, "kmem_cache_cpu", "freelist"); + MEMBER_OFFSET_INIT(kmem_cache_cpu_page, "kmem_cache_cpu", "page"); ++ if (INVALID_MEMBER(kmem_cache_cpu_page)) ++ MEMBER_OFFSET_INIT(kmem_cache_cpu_page, "kmem_cache_cpu", "slab"); + MEMBER_OFFSET_INIT(kmem_cache_cpu_node, "kmem_cache_cpu", "node"); + MEMBER_OFFSET_INIT(kmem_cache_cpu_partial, "kmem_cache_cpu", "partial"); + MEMBER_OFFSET_INIT(page_inuse, "page", "inuse"); + if (INVALID_MEMBER(page_inuse)) + ANON_MEMBER_OFFSET_INIT(page_inuse, "page", "inuse"); ++ if (INVALID_MEMBER(page_inuse)) ++ MEMBER_OFFSET_INIT(page_inuse, "slab", "inuse"); + MEMBER_OFFSET_INIT(page_offset, "page", "offset"); + if (INVALID_MEMBER(page_offset)) + ANON_MEMBER_OFFSET_INIT(page_offset, "page", "offset"); +@@ -763,6 +769,9 @@ vm_init(void) + if (INVALID_MEMBER(page_slab)) + ANON_MEMBER_OFFSET_INIT(page_slab, "page", "slab_cache"); + } ++ if (INVALID_MEMBER(page_slab)) ++ MEMBER_OFFSET_INIT(page_slab, "slab", "slab_cache"); ++ + MEMBER_OFFSET_INIT(page_slab_page, "page", "slab_page"); + if (INVALID_MEMBER(page_slab_page)) + ANON_MEMBER_OFFSET_INIT(page_slab_page, "page", "slab_page"); +@@ -772,10 +781,14 @@ vm_init(void) + MEMBER_OFFSET_INIT(page_freelist, "page", "freelist"); + if (INVALID_MEMBER(page_freelist)) + ANON_MEMBER_OFFSET_INIT(page_freelist, "page", "freelist"); ++ if (INVALID_MEMBER(page_freelist)) ++ MEMBER_OFFSET_INIT(page_freelist, "slab", "freelist"); + if (INVALID_MEMBER(kmem_cache_objects)) { + MEMBER_OFFSET_INIT(kmem_cache_oo, "kmem_cache", "oo"); + /* NOTE: returns offset of containing bitfield */ + ANON_MEMBER_OFFSET_INIT(page_objects, "page", "objects"); ++ if (INVALID_MEMBER(page_objects)) ++ ANON_MEMBER_OFFSET_INIT(page_objects, "slab", "objects"); + } + if (VALID_MEMBER(kmem_cache_node)) { + ARRAY_LENGTH_INIT(len, NULL, "kmem_cache.node", NULL, 0); +-- +2.20.1 + diff --git a/SOURCES/lzo_snappy.patch b/SOURCES/lzo_snappy.patch deleted file mode 100644 index 1ae83e6..0000000 --- a/SOURCES/lzo_snappy.patch +++ /dev/null @@ -1,26 +0,0 @@ -diff --git crash-7.3.0/Makefile crash-7.3.0/Makefile -index 745541012f43..d0574d8f07d3 100644 ---- crash-7.3.0/Makefile -+++ crash-7.3.0/Makefile -@@ -228,7 +228,7 @@ all: make_configure - gdb_merge: force - @if [ ! -f ${GDB}/README ]; then \ - make --no-print-directory gdb_unzip; fi -- @echo "${LDFLAGS} -lz -ldl -rdynamic" > ${GDB}/gdb/mergelibs -+ @echo "${LDFLAGS} -lz -llzo2 -lsnappy -ldl -rdynamic" > ${GDB}/gdb/mergelibs - @echo "../../${PROGRAM} ../../${PROGRAM}lib.a" > ${GDB}/gdb/mergeobj - @rm -f ${PROGRAM} - @if [ ! -f ${GDB}/config.status ]; then \ -diff --git crash-7.3.0/diskdump.c crash-7.3.0/diskdump.c -index e88243e616cc..9ccf7039231b 100644 ---- crash-7.3.0/diskdump.c -+++ crash-7.3.0/diskdump.c -@@ -23,6 +23,8 @@ - * GNU General Public License for more details. - */ - -+#define LZO -+#define SNAPPY - #include "defs.h" - #include "diskdump.h" - #include "xen_dom0.h" diff --git a/SOURCES/lzo_snappy_zstd.patch b/SOURCES/lzo_snappy_zstd.patch new file mode 100644 index 0000000..4813ed0 --- /dev/null +++ b/SOURCES/lzo_snappy_zstd.patch @@ -0,0 +1,23 @@ +--- crash-7.3.1/Makefile.orig ++++ crash-7.3.1/Makefile +@@ -230,7 +230,7 @@ all: make_configure + gdb_merge: force + @if [ ! -f ${GDB}/README ]; then \ + make --no-print-directory gdb_unzip; fi +- @echo "${LDFLAGS} -lz -ldl -rdynamic" > ${GDB}/gdb/mergelibs ++ @echo "${LDFLAGS} -lz -llzo2 -lsnappy -lzstd -ldl -rdynamic" > ${GDB}/gdb/mergelibs + @echo "../../${PROGRAM} ../../${PROGRAM}lib.a" > ${GDB}/gdb/mergeobj + @rm -f ${PROGRAM} + @if [ ! -f ${GDB}/config.status ]; then \ +--- crash-7.3.1/diskdump.c.orig ++++ crash-7.3.1/diskdump.c +@@ -23,6 +23,9 @@ + * GNU General Public License for more details. + */ + ++#define LZO ++#define SNAPPY ++#define ZSTD + #include "defs.h" + #include "diskdump.h" + #include "xen_dom0.h" diff --git a/SOURCES/rhel8_arm64_52_bit_fix.patch b/SOURCES/rhel8_arm64_52_bit_fix.patch deleted file mode 100644 index c37ea03..0000000 --- a/SOURCES/rhel8_arm64_52_bit_fix.patch +++ /dev/null @@ -1,1043 +0,0 @@ -From 1bc151ee1304318ecb36d6158afe40852bc4b7f4 Mon Sep 17 00:00:00 2001 -From: Bhupesh Sharma -Date: Tue, 1 Dec 2020 02:23:53 +0530 -Subject: [PATCH] arm64 crash fix for older kernels - -Signed-off-by: Bhupesh Sharma ---- - arm64.c | 512 +++++++++++--------------------------------------------- - defs.h | 18 +- - 2 files changed, 102 insertions(+), 428 deletions(-) - -diff --git a/arm64.c b/arm64.c -index 4787fa61e3e5..68347b131aef 100644 ---- a/arm64.c -+++ b/arm64.c -@@ -27,13 +27,9 @@ - static struct machine_specific arm64_machine_specific = { 0 }; - static int arm64_verify_symbol(const char *, ulong, char); - static void arm64_parse_cmdline_args(void); --static int arm64_search_for_kimage_voffset(ulong); --static int verify_kimage_voffset(void); - static void arm64_calc_kimage_voffset(void); - static void arm64_calc_phys_offset(void); --static void arm64_calc_physvirt_offset(void); - static void arm64_calc_virtual_memory_ranges(void); --static void arm64_get_section_size_bits(void); - static int arm64_kdump_phys_base(ulong *); - static ulong arm64_processor_speed(void); - static void arm64_init_kernel_pgd(void); -@@ -82,10 +78,9 @@ static int arm64_on_irq_stack(int, ulong); - static void arm64_set_irq_stack(struct bt_info *); - static void arm64_set_process_stack(struct bt_info *); - static int arm64_get_kvaddr_ranges(struct vaddr_range *); --static void arm64_get_crash_notes(void); -+static int arm64_get_crash_notes(void); - static void arm64_calc_VA_BITS(void); - static int arm64_is_uvaddr(ulong, struct task_context *); --static void arm64_calc_KERNELPACMASK(void); - - - /* -@@ -149,12 +144,6 @@ arm64_init(int when) - if (kernel_symbol_exists("kimage_voffset")) - machdep->flags |= NEW_VMEMMAP; - -- if (!machdep->pagesize && -- (string = pc->read_vmcoreinfo("PAGESIZE"))) { -- machdep->pagesize = atoi(string); -- free(string); -- } -- - if (!machdep->pagesize) { - /* - * Kerneldoc Documentation/arm64/booting.txt describes -@@ -181,16 +170,17 @@ arm64_init(int when) - - } - -- /* -- * This code section will only be executed if the kernel is -- * earlier than Linux 4.4 (if there is no vmcoreinfo) -- */ - if (!machdep->pagesize && - kernel_symbol_exists("swapper_pg_dir") && - kernel_symbol_exists("idmap_pg_dir")) { -- value = symbol_value("swapper_pg_dir") - -- symbol_value("idmap_pg_dir"); -+ if (kernel_symbol_exists("tramp_pg_dir")) -+ value = symbol_value("tramp_pg_dir"); -+ else if (kernel_symbol_exists("reserved_ttbr0")) -+ value = symbol_value("reserved_ttbr0"); -+ else -+ value = symbol_value("swapper_pg_dir"); - -+ value -= symbol_value("idmap_pg_dir"); - /* - * idmap_pg_dir is 2 pages prior to 4.1, - * and 3 pages thereafter. Only 4K and 64K -@@ -215,21 +205,13 @@ arm64_init(int when) - machdep->pagemask = ~((ulonglong)machdep->pageoffset); - - arm64_calc_VA_BITS(); -- arm64_calc_KERNELPACMASK(); - ms = machdep->machspec; -- if (ms->VA_BITS_ACTUAL) { -- ms->page_offset = ARM64_PAGE_OFFSET_ACTUAL; -- machdep->identity_map_base = ARM64_PAGE_OFFSET_ACTUAL; -- machdep->kvbase = ARM64_PAGE_OFFSET_ACTUAL; -- ms->userspace_top = ARM64_USERSPACE_TOP_ACTUAL; -- } else { -- ms->page_offset = ARM64_PAGE_OFFSET; -- machdep->identity_map_base = ARM64_PAGE_OFFSET; -- machdep->kvbase = ARM64_VA_START; -- ms->userspace_top = ARM64_USERSPACE_TOP; -- } -+ ms->page_offset = ARM64_PAGE_OFFSET; -+ machdep->identity_map_base = ARM64_PAGE_OFFSET; -+ machdep->kvbase = ARM64_VA_START; - machdep->is_kvaddr = generic_is_kvaddr; - machdep->kvtop = arm64_kvtop; -+ ms->userspace_top = ARM64_USERSPACE_TOP; - if (machdep->flags & NEW_VMEMMAP) { - struct syment *sp; - -@@ -238,15 +220,11 @@ arm64_init(int when) - sp = kernel_symbol_search("_end"); - ms->kimage_end = (sp ? sp->value : 0); - -- if (ms->VA_BITS_ACTUAL) { -- ms->modules_vaddr = (st->_stext_vmlinux & TEXT_OFFSET_MASK) - ARM64_MODULES_VSIZE; -- ms->modules_end = ms->modules_vaddr + ARM64_MODULES_VSIZE -1; -- } else { -- ms->modules_vaddr = ARM64_VA_START; -- if (kernel_symbol_exists("kasan_init")) -- ms->modules_vaddr += ARM64_KASAN_SHADOW_SIZE; -- ms->modules_end = ms->modules_vaddr + ARM64_MODULES_VSIZE -1; -- } -+ ms->modules_vaddr = ARM64_VA_START; -+ if (kernel_symbol_exists("kasan_init")) -+ ms->modules_vaddr += ARM64_KASAN_SHADOW_SIZE; -+ ms->modules_end = ms->modules_vaddr -+ + ARM64_MODULES_VSIZE -1; - - ms->vmalloc_start_addr = ms->modules_end + 1; - -@@ -338,6 +316,10 @@ arm64_init(int when) - - machdep->uvtop = arm64_uvtop; - machdep->is_uvaddr = arm64_is_uvaddr; -+ if (kernel_symbol_exists("vabits_user") && -+ readmem(symbol_value("vabits_user"), KVADDR, -+ &value, sizeof(ulong), "vabits_user", RETURN_ON_ERROR)) -+ machdep->machspec->vabits_user = value; - machdep->eframe_search = arm64_eframe_search; - machdep->back_trace = arm64_back_trace_cmd; - machdep->in_alternate_stack = arm64_in_alternate_stack; -@@ -365,7 +347,6 @@ arm64_init(int when) - - /* use machdep parameters */ - arm64_calc_phys_offset(); -- arm64_calc_physvirt_offset(); - - if (CRASHDEBUG(1)) { - if (machdep->flags & NEW_VMEMMAP) -@@ -373,15 +354,13 @@ arm64_init(int when) - machdep->machspec->kimage_voffset); - fprintf(fp, "phys_offset: %lx\n", - machdep->machspec->phys_offset); -- fprintf(fp, "physvirt_offset: %lx\n", machdep->machspec->physvirt_offset); - } - - break; - - case POST_GDB: - arm64_calc_virtual_memory_ranges(); -- arm64_get_section_size_bits(); -- -+ machdep->section_size_bits = _SECTION_SIZE_BITS; - if (!machdep->max_physmem_bits) { - if ((string = pc->read_vmcoreinfo("NUMBER(MAX_PHYSMEM_BITS)"))) { - machdep->max_physmem_bits = atol(string); -@@ -393,24 +372,8 @@ arm64_init(int when) - else - machdep->max_physmem_bits = _MAX_PHYSMEM_BITS; - } -- - ms = machdep->machspec; - -- if (CRASHDEBUG(1)) { -- if (ms->VA_BITS_ACTUAL) { -- fprintf(fp, "CONFIG_ARM64_VA_BITS: %ld\n", ms->CONFIG_ARM64_VA_BITS); -- fprintf(fp, " VA_BITS_ACTUAL: %ld\n", ms->VA_BITS_ACTUAL); -- fprintf(fp, "(calculated) VA_BITS: %ld\n", ms->VA_BITS); -- fprintf(fp, " PAGE_OFFSET: %lx\n", ARM64_PAGE_OFFSET_ACTUAL); -- fprintf(fp, " VA_START: %lx\n", ms->VA_START); -- fprintf(fp, " modules: %lx - %lx\n", ms->modules_vaddr, ms->modules_end); -- fprintf(fp, " vmalloc: %lx - %lx\n", ms->vmalloc_start_addr, ms->vmalloc_end); -- fprintf(fp, "kernel image: %lx - %lx\n", ms->kimage_text, ms->kimage_end); -- fprintf(fp, " vmemmap: %lx - %lx\n\n", ms->vmemmap_vaddr, ms->vmemmap_end); -- } -- } -- -- - if (THIS_KERNEL_VERSION >= LINUX(4,0,0)) { - ms->__SWP_TYPE_BITS = 6; - ms->__SWP_TYPE_SHIFT = 2; -@@ -470,17 +433,18 @@ arm64_init(int when) - * of the crash. We need this information to extract correct - * backtraces from the panic task. - */ -- if (!LIVE()) -- arm64_get_crash_notes(); -+ if (!LIVE() && !arm64_get_crash_notes()) -+ error(WARNING, -+ "cannot retrieve registers for active task%s\n\n", -+ kt->cpus > 1 ? "s" : ""); -+ - break; - - case LOG_ONLY: - machdep->machspec = &arm64_machine_specific; - arm64_calc_VA_BITS(); -- arm64_calc_KERNELPACMASK(); - arm64_calc_phys_offset(); - machdep->machspec->page_offset = ARM64_PAGE_OFFSET; -- arm64_calc_physvirt_offset(); - break; - } - } -@@ -657,20 +621,9 @@ arm64_dump_machdep_table(ulong arg) - - fprintf(fp, " machspec: %lx\n", (ulong)ms); - fprintf(fp, " VA_BITS: %ld\n", ms->VA_BITS); -- fprintf(fp, " CONFIG_ARM64_VA_BITS: %ld\n", ms->CONFIG_ARM64_VA_BITS); -- fprintf(fp, " VA_START: "); -- if (ms->VA_START) -- fprintf(fp, "%lx\n", ms->VA_START); -- else -- fprintf(fp, "(unused)\n"); -- fprintf(fp, " VA_BITS_ACTUAL: "); -- if (ms->VA_BITS_ACTUAL) -- fprintf(fp, "%ld\n", ms->VA_BITS_ACTUAL); -- else -- fprintf(fp, "(unused)\n"); -- fprintf(fp, "CONFIG_ARM64_KERNELPACMASK: "); -- if (ms->CONFIG_ARM64_KERNELPACMASK) -- fprintf(fp, "%lx\n", ms->CONFIG_ARM64_KERNELPACMASK); -+ fprintf(fp, " vabits_user: "); -+ if (ms->vabits_user) -+ fprintf(fp, "%ld\n", ms->vabits_user); - else - fprintf(fp, "(unused)\n"); - fprintf(fp, " userspace_top: %016lx\n", ms->userspace_top); -@@ -759,14 +712,12 @@ arm64_parse_machdep_arg_l(char *argstring, char *param, ulong *value) - int flags = RETURN_ON_ERROR | QUIET; - int err = 0; - -- if (STRNEQ(argstring, "max_physmem_bits")) { -- *value = dtol(p, flags, &err); -- } else if (STRNEQ(argstring, "vabits_actual")) { -- *value = dtol(p, flags, &err); -- } else if (megabytes) { -+ if (megabytes) { - *value = dtol(p, flags, &err); - if (!err) - *value = MEGABYTES(*value); -+ } else if (STRNEQ(argstring, "max_physmem_bits")) { -+ *value = dtol(p, flags, &err); - } else { - *value = htol(p, flags, &err); - } -@@ -832,12 +783,6 @@ arm64_parse_cmdline_args(void) - "setting max_physmem_bits to: %ld\n\n", - machdep->max_physmem_bits); - continue; -- } else if (arm64_parse_machdep_arg_l(arglist[i], "vabits_actual", -- &machdep->machspec->VA_BITS_ACTUAL)) { -- error(NOTE, -- "setting vabits_actual to: %ld\n\n", -- machdep->machspec->VA_BITS_ACTUAL); -- continue; - } - - error(WARNING, "ignoring --machdep option: %s\n", -@@ -846,60 +791,11 @@ arm64_parse_cmdline_args(void) - } - } - --#define MIN_KIMG_ALIGN (0x00200000) /* kimage load address must be aligned 2M */ --/* -- * Traverse the entire dumpfile to find/verify kimage_voffset. -- */ --static int --arm64_search_for_kimage_voffset(ulong phys_base) --{ -- ulong kimage_load_addr; -- ulong phys_end; -- struct machine_specific *ms = machdep->machspec; -- -- if (!arm_kdump_phys_end(&phys_end)) -- return FALSE; -- -- for (kimage_load_addr = phys_base; -- kimage_load_addr <= phys_end; kimage_load_addr += MIN_KIMG_ALIGN) { -- ms->kimage_voffset = ms->vmalloc_start_addr - kimage_load_addr; -- -- if ((kt->flags2 & KASLR) && (kt->flags & RELOC_SET)) -- ms->kimage_voffset += (kt->relocate * - 1); -- -- if (verify_kimage_voffset()) { -- if (CRASHDEBUG(1)) -- error(INFO, -- "dumpfile searched for kimage_voffset: %lx\n\n", -- ms->kimage_voffset); -- break; -- } -- } -- -- if (kimage_load_addr > phys_end) -- return FALSE; -- -- return TRUE; --} -- --static int --verify_kimage_voffset(void) --{ -- ulong kimage_voffset; -- -- if (!readmem(symbol_value("kimage_voffset"), KVADDR, &kimage_voffset, -- sizeof(kimage_voffset), "verify kimage_voffset", QUIET|RETURN_ON_ERROR)) -- return FALSE; -- -- return (machdep->machspec->kimage_voffset == kimage_voffset); --} -- - static void - arm64_calc_kimage_voffset(void) - { - struct machine_specific *ms = machdep->machspec; -- ulong phys_addr = 0; -- int errflag; -+ ulong phys_addr; - - if (ms->kimage_voffset) /* vmcoreinfo, ioctl, or --machdep override */ - return; -@@ -907,6 +803,7 @@ arm64_calc_kimage_voffset(void) - if (ACTIVE()) { - char buf[BUFSIZE]; - char *p1; -+ int errflag; - FILE *iomem; - ulong kimage_voffset, vaddr; - -@@ -947,24 +844,9 @@ arm64_calc_kimage_voffset(void) - if (errflag) - return; - -- } else if (KDUMP_DUMPFILE()) { -- errflag = 1; -- if (arm_kdump_phys_base(&phys_addr)) { /* Get start address of first memory block */ -- ms->kimage_voffset = ms->vmalloc_start_addr - phys_addr; -- if ((kt->flags2 & KASLR) && (kt->flags & RELOC_SET)) -- ms->kimage_voffset += (kt->relocate * -1); -- if (verify_kimage_voffset() || arm64_search_for_kimage_voffset(phys_addr)) -- errflag = 0; -- } -- -- if (errflag) { -- error(WARNING, -- "kimage_voffset cannot be determined from the dumpfile.\n"); -- error(CONT, -- "Try using the command line option: --machdep kimage_voffset=\n"); -- } -- return; -- } else { -+ } else if (KDUMP_DUMPFILE()) -+ arm_kdump_phys_base(&phys_addr); /* Get start address of first memory block */ -+ else { - error(WARNING, - "kimage_voffset cannot be determined from the dumpfile.\n"); - error(CONT, -@@ -980,25 +862,6 @@ arm64_calc_kimage_voffset(void) - ms->kimage_voffset += (kt->relocate * -1); - } - --static void --arm64_calc_physvirt_offset(void) --{ -- struct machine_specific *ms = machdep->machspec; -- ulong physvirt_offset; -- struct syment *sp; -- -- ms->physvirt_offset = ms->phys_offset - ms->page_offset; -- -- if ((sp = kernel_symbol_search("physvirt_offset")) && -- machdep->machspec->kimage_voffset) { -- if (READMEM(pc->mfd, &physvirt_offset, sizeof(physvirt_offset), -- sp->value, sp->value - -- machdep->machspec->kimage_voffset) > 0) { -- ms->physvirt_offset = physvirt_offset; -- } -- } --} -- - static void - arm64_calc_phys_offset(void) - { -@@ -1022,16 +885,10 @@ arm64_calc_phys_offset(void) - physaddr_t paddr; - ulong vaddr; - struct syment *sp; -- char *string; - - if ((machdep->flags & NEW_VMEMMAP) && - ms->kimage_voffset && (sp = kernel_symbol_search("memstart_addr"))) { - if (pc->flags & PROC_KCORE) { -- if ((string = pc->read_vmcoreinfo("NUMBER(PHYS_OFFSET)"))) { -- ms->phys_offset = htol(string, QUIET, NULL); -- free(string); -- return; -- } - vaddr = symbol_value_from_proc_kallsyms("memstart_addr"); - if (vaddr == BADVAL) - vaddr = sp->value; -@@ -1094,31 +951,6 @@ arm64_calc_phys_offset(void) - fprintf(fp, "using %lx as phys_offset\n", ms->phys_offset); - } - --/* -- * Determine SECTION_SIZE_BITS either by reading VMCOREINFO or the kernel -- * config, otherwise use the 64-bit ARM default definiton. -- */ --static void --arm64_get_section_size_bits(void) --{ -- int ret; -- char *string; -- -- machdep->section_size_bits = _SECTION_SIZE_BITS; -- -- if ((string = pc->read_vmcoreinfo("NUMBER(SECTION_SIZE_BITS)"))) { -- machdep->section_size_bits = atol(string); -- free(string); -- } else if (kt->ikconfig_flags & IKCONFIG_AVAIL) { -- if ((ret = get_kernel_config("CONFIG_MEMORY_HOTPLUG", NULL)) == IKCONFIG_Y) { -- if ((ret = get_kernel_config("CONFIG_HOTPLUG_SIZE_BITS", &string)) == IKCONFIG_STR) -- machdep->section_size_bits = atol(string); -- } -- } -- -- if (CRASHDEBUG(1)) -- fprintf(fp, "SECTION_SIZE_BITS: %ld\n", machdep->section_size_bits); --} - - /* - * Determine PHYS_OFFSET either by reading VMCOREINFO or the kernel -@@ -1174,14 +1006,9 @@ ulong - arm64_VTOP(ulong addr) - { - if (machdep->flags & NEW_VMEMMAP) { -- if (machdep->machspec->VA_START && -- (addr >= machdep->machspec->kimage_text) && -- (addr <= machdep->machspec->kimage_end)) { -- return addr - machdep->machspec->kimage_voffset; -- } -- - if (addr >= machdep->machspec->page_offset) -- return addr + machdep->machspec->physvirt_offset; -+ return machdep->machspec->phys_offset -+ + (addr - machdep->machspec->page_offset); - else if (machdep->machspec->kimage_voffset) - return addr - machdep->machspec->kimage_voffset; - else /* no randomness */ -@@ -1255,11 +1082,6 @@ arm64_uvtop(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbos - } - } - --#define PTE_ADDR_LOW ((((1UL) << (48 - machdep->pageshift)) - 1) << machdep->pageshift) --#define PTE_ADDR_HIGH ((0xfUL) << 12) --#define PTE_TO_PHYS(pteval) (machdep->max_physmem_bits == 52 ? \ -- (((pteval & PTE_ADDR_LOW) | ((pteval & PTE_ADDR_HIGH) << 36))) : (pteval & PTE_ADDR_LOW)) -- - #define PUD_TYPE_MASK 3 - #define PUD_TYPE_SECT 1 - #define PMD_TYPE_MASK 3 -@@ -1355,7 +1177,7 @@ arm64_vtop_3level_64k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) - * #define __PAGETABLE_PUD_FOLDED - */ - -- pmd_base = (ulong *)PTOV(PTE_TO_PHYS(pgd_val)); -+ pmd_base = (ulong *)PTOV(pgd_val & PHYS_MASK & (s32)machdep->pagemask); - FILL_PMD(pmd_base, KVADDR, PTRS_PER_PMD_L3_64K * sizeof(ulong)); - pmd_ptr = pmd_base + (((vaddr) >> PMD_SHIFT_L3_64K) & (PTRS_PER_PMD_L3_64K - 1)); - pmd_val = ULONG(machdep->pmd + PAGEOFFSET(pmd_ptr)); -@@ -1365,7 +1187,7 @@ arm64_vtop_3level_64k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) - goto no_page; - - if ((pmd_val & PMD_TYPE_MASK) == PMD_TYPE_SECT) { -- ulong sectionbase = PTE_TO_PHYS(pmd_val) & SECTION_PAGE_MASK_512MB; -+ ulong sectionbase = (pmd_val & SECTION_PAGE_MASK_512MB) & PHYS_MASK; - if (verbose) { - fprintf(fp, " PAGE: %lx (512MB)\n\n", sectionbase); - arm64_translate_pte(pmd_val, 0, 0); -@@ -1374,7 +1196,7 @@ arm64_vtop_3level_64k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) - return TRUE; - } - -- pte_base = (ulong *)PTOV(PTE_TO_PHYS(pmd_val)); -+ pte_base = (ulong *)PTOV(pmd_val & PHYS_MASK & (s32)machdep->pagemask); - FILL_PTBL(pte_base, KVADDR, PTRS_PER_PTE_L3_64K * sizeof(ulong)); - pte_ptr = pte_base + (((vaddr) >> machdep->pageshift) & (PTRS_PER_PTE_L3_64K - 1)); - pte_val = ULONG(machdep->ptbl + PAGEOFFSET(pte_ptr)); -@@ -1384,7 +1206,7 @@ arm64_vtop_3level_64k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) - goto no_page; - - if (pte_val & PTE_VALID) { -- *paddr = PTE_TO_PHYS(pte_val) + PAGEOFFSET(vaddr); -+ *paddr = (PAGEBASE(pte_val) & PHYS_MASK) + PAGEOFFSET(vaddr); - if (verbose) { - fprintf(fp, " PAGE: %lx\n\n", PAGEBASE(*paddr)); - arm64_translate_pte(pte_val, 0, 0); -@@ -1696,11 +1518,10 @@ arm64_stackframe_init(void) - machdep->machspec->kern_eframe_offset = SIZE(pt_regs); - } - -- if ((sp1 = kernel_symbol_search("__exception_text_start")) && -- (sp2 = kernel_symbol_search("__exception_text_end"))) { -- machdep->machspec->__exception_text_start = sp1->value; -- machdep->machspec->__exception_text_end = sp2->value; -- } -+ machdep->machspec->__exception_text_start = -+ symbol_value("__exception_text_start"); -+ machdep->machspec->__exception_text_end = -+ symbol_value("__exception_text_end"); - if ((sp1 = kernel_symbol_search("__irqentry_text_start")) && - (sp2 = kernel_symbol_search("__irqentry_text_end"))) { - machdep->machspec->__irqentry_text_start = sp1->value; -@@ -1826,14 +1647,13 @@ static int - arm64_is_kernel_exception_frame(struct bt_info *bt, ulong stkptr) - { - struct arm64_pt_regs *regs; -- struct machine_specific *ms = machdep->machspec; - - regs = (struct arm64_pt_regs *)&bt->stackbuf[(ulong)(STACK_OFFSET_TYPE(stkptr))]; - - if (INSTACK(regs->sp, bt) && INSTACK(regs->regs[29], bt) && - !(regs->pstate & (0xffffffff00000000ULL | PSR_MODE32_BIT)) && - is_kernel_text(regs->pc) && -- is_kernel_text(regs->regs[30] | ms->CONFIG_ARM64_KERNELPACMASK)) { -+ is_kernel_text(regs->regs[30])) { - switch (regs->pstate & PSR_MODE_MASK) - { - case PSR_MODE_EL1t: -@@ -1910,38 +1730,20 @@ arm64_eframe_search(struct bt_info *bt) - return count; - } - --static char *arm64_exception_functions[] = { -- "do_undefinstr", -- "do_sysinstr", -- "do_debug_exception", -- "do_mem_abort", -- "do_el0_irq_bp_hardening", -- "do_sp_pc_abort", -- NULL --}; -- - static int - arm64_in_exception_text(ulong ptr) - { - struct machine_specific *ms = machdep->machspec; -- char *name, **func; -+ -+ if ((ptr >= ms->__exception_text_start) && -+ (ptr < ms->__exception_text_end)) -+ return TRUE; - - if (ms->__irqentry_text_start && ms->__irqentry_text_end && - ((ptr >= ms->__irqentry_text_start) && - (ptr < ms->__irqentry_text_end))) - return TRUE; - -- if (ms->__exception_text_start && ms->__exception_text_end) { -- if ((ptr >= ms->__exception_text_start) && -- (ptr < ms->__exception_text_end)) -- return TRUE; -- } else if ((name = closest_symbol(ptr))) { /* Linux 5.5 and later */ -- for (func = &arm64_exception_functions[0]; *func; func++) { -- if (STREQ(name, *func)) -- return TRUE; -- } -- } -- - return FALSE; - } - -@@ -1977,7 +1779,6 @@ arm64_print_stackframe_entry(struct bt_info *bt, int level, struct arm64_stackfr - * See, for example, "bl schedule" before ret_to_user(). - */ - branch_pc = frame->pc - 4; -- - name = closest_symbol(branch_pc); - name_plus_offset = NULL; - -@@ -2189,7 +1990,7 @@ arm64_unwind_frame(struct bt_info *bt, struct arm64_stackframe *frame) - unsigned long stack_mask; - unsigned long irq_stack_ptr, orig_sp; - struct arm64_pt_regs *ptregs; -- struct machine_specific *ms = machdep->machspec; -+ struct machine_specific *ms; - - stack_mask = (unsigned long)(ARM64_STACK_SIZE) - 1; - fp = frame->fp; -@@ -2203,8 +2004,6 @@ arm64_unwind_frame(struct bt_info *bt, struct arm64_stackframe *frame) - frame->sp = fp + 0x10; - frame->fp = GET_STACK_ULONG(fp); - frame->pc = GET_STACK_ULONG(fp + 8); -- if (is_kernel_text(frame->pc | ms->CONFIG_ARM64_KERNELPACMASK)) -- frame->pc |= ms->CONFIG_ARM64_KERNELPACMASK; - - if ((frame->fp == 0) && (frame->pc == 0)) - return FALSE; -@@ -2256,6 +2055,7 @@ arm64_unwind_frame(struct bt_info *bt, struct arm64_stackframe *frame) - * irq_stack_ptr = IRQ_STACK_PTR(raw_smp_processor_id()); - * orig_sp = IRQ_STACK_TO_TASK_STACK(irq_stack_ptr); (pt_regs pointer on process stack) - */ -+ ms = machdep->machspec; - irq_stack_ptr = ms->irq_stacks[bt->tc->processor] + ms->irq_stack_size - 16; - - if (frame->sp == irq_stack_ptr) { -@@ -2857,8 +2657,6 @@ arm64_print_text_symbols(struct bt_info *bt, struct arm64_stackframe *frame, FIL - char buf2[BUFSIZE]; - char *name; - ulong start; -- ulong val; -- struct machine_specific *ms = machdep->machspec; - - if (bt->flags & BT_TEXT_SYMBOLS_ALL) - start = bt->stackbase; -@@ -2873,10 +2671,8 @@ arm64_print_text_symbols(struct bt_info *bt, struct arm64_stackframe *frame, FIL - - for (i = (start - bt->stackbase)/sizeof(ulong); i < LONGS_PER_STACK; i++) { - up = (ulong *)(&bt->stackbuf[i*sizeof(ulong)]); -- val = *up; -- if (is_kernel_text(val | ms->CONFIG_ARM64_KERNELPACMASK)) { -- val |= ms->CONFIG_ARM64_KERNELPACMASK; -- name = closest_symbol(val); -+ if (is_kernel_text(*up)) { -+ name = closest_symbol(*up); - fprintf(ofp, " %s[%s] %s at %lx", - bt->flags & BT_ERROR_MASK ? - " " : "", -@@ -2885,13 +2681,13 @@ arm64_print_text_symbols(struct bt_info *bt, struct arm64_stackframe *frame, FIL - MKSTR(bt->stackbase + - (i * sizeof(long)))), - bt->flags & BT_SYMBOL_OFFSET ? -- value_to_symstr(val, buf2, bt->radix) : -- name, val); -- if (module_symbol(val, NULL, &lm, NULL, 0)) -+ value_to_symstr(*up, buf2, bt->radix) : -+ name, *up); -+ if (module_symbol(*up, NULL, &lm, NULL, 0)) - fprintf(ofp, " [%s]", lm->mod_name); - fprintf(ofp, "\n"); - if (BT_REFERENCE_CHECK(bt)) -- arm64_do_bt_reference_check(bt, val, name); -+ arm64_do_bt_reference_check(bt, *up, name); - } - } - } -@@ -3194,7 +2990,6 @@ arm64_print_exception_frame(struct bt_info *bt, ulong pt_regs, int mode, FILE *o - struct syment *sp; - ulong LR, SP, offset; - char buf[BUFSIZE]; -- struct machine_specific *ms = machdep->machspec; - - if (CRASHDEBUG(1)) - fprintf(ofp, "pt_regs: %lx\n", pt_regs); -@@ -3210,8 +3005,6 @@ arm64_print_exception_frame(struct bt_info *bt, ulong pt_regs, int mode, FILE *o - rows = 4; - } else { - LR = regs->regs[30]; -- if (is_kernel_text (LR | ms->CONFIG_ARM64_KERNELPACMASK)) -- LR |= ms->CONFIG_ARM64_KERNELPACMASK; - SP = regs->sp; - top_reg = 29; - is_64_bit = TRUE; -@@ -3359,7 +3152,7 @@ arm64_translate_pte(ulong pte, void *physaddr, ulonglong unused) - char *arglist[MAXARGS]; - int page_present; - -- paddr = PTE_TO_PHYS(pte); -+ paddr = pte & PHYS_MASK & (s32)machdep->pagemask; - page_present = pte & (PTE_VALID | machdep->machspec->PTE_PROT_NONE); - - if (physaddr) { -@@ -3625,8 +3418,8 @@ arm64_display_machine_stats(void) - fprintf(fp, " HZ: %d\n", machdep->hz); - fprintf(fp, " PAGE SIZE: %d\n", PAGESIZE()); - fprintf(fp, "KERNEL VIRTUAL BASE: %lx\n", machdep->machspec->page_offset); -- fprintf(fp, "KERNEL MODULES BASE: %lx\n", machdep->machspec->modules_vaddr); - fprintf(fp, "KERNEL VMALLOC BASE: %lx\n", machdep->machspec->vmalloc_start_addr); -+ fprintf(fp, "KERNEL MODULES BASE: %lx\n", machdep->machspec->modules_vaddr); - fprintf(fp, "KERNEL VMEMMAP BASE: %lx\n", machdep->machspec->vmemmap_vaddr); - fprintf(fp, " KERNEL STACK SIZE: %ld\n", STACKSIZE()); - if (machdep->machspec->irq_stack_size) { -@@ -3656,7 +3449,7 @@ arm64_get_smp_cpus(void) - /* - * Retrieve task registers for the time of the crash. - */ --static void -+static int - arm64_get_crash_notes(void) - { - struct machine_specific *ms = machdep->machspec; -@@ -3665,10 +3458,10 @@ arm64_get_crash_notes(void) - ulong offset; - char *buf, *p; - ulong *notes_ptrs; -- ulong i, found; -+ ulong i; - - if (!symbol_exists("crash_notes")) -- return; -+ return FALSE; - - crash_notes = symbol_value("crash_notes"); - -@@ -3680,9 +3473,9 @@ arm64_get_crash_notes(void) - */ - if (!readmem(crash_notes, KVADDR, ¬es_ptrs[kt->cpus-1], - sizeof(notes_ptrs[kt->cpus-1]), "crash_notes", RETURN_ON_ERROR)) { -- error(WARNING, "cannot read \"crash_notes\"\n"); -+ error(WARNING, "cannot read crash_notes\n"); - FREEBUF(notes_ptrs); -- return; -+ return FALSE; - } - - if (symbol_exists("__per_cpu_offset")) { -@@ -3698,11 +3491,12 @@ arm64_get_crash_notes(void) - if (!(ms->panic_task_regs = calloc((size_t)kt->cpus, sizeof(struct arm64_pt_regs)))) - error(FATAL, "cannot calloc panic_task_regs space\n"); - -- for (i = found = 0; i < kt->cpus; i++) { -+ for (i = 0; i < kt->cpus; i++) { -+ - if (!readmem(notes_ptrs[i], KVADDR, buf, SIZE(note_buf), - "note_buf_t", RETURN_ON_ERROR)) { -- error(WARNING, "cpu %d: cannot read NT_PRSTATUS note\n", i); -- continue; -+ error(WARNING, "failed to read note_buf_t\n"); -+ goto fail; - } - - /* -@@ -3732,24 +3526,19 @@ arm64_get_crash_notes(void) - note->n_descsz == notesz) - BCOPY((char *)note, buf, notesz); - } else { -- error(WARNING, "cpu %d: cannot find NT_PRSTATUS note\n", i); -+ error(WARNING, -+ "cannot find NT_PRSTATUS note for cpu: %d\n", i); - continue; - } - } - -- /* -- * Check the sanity of NT_PRSTATUS note only for each online cpu. -- * If this cpu has invalid note, continue to find the crash notes -- * for other online cpus. -- */ - if (note->n_type != NT_PRSTATUS) { -- error(WARNING, "cpu %d: invalid NT_PRSTATUS note (n_type != NT_PRSTATUS)\n", i); -- continue; -+ error(WARNING, "invalid note (n_type != NT_PRSTATUS)\n"); -+ goto fail; - } -- -- if (!STRNEQ(p, "CORE")) { -- error(WARNING, "cpu %d: invalid NT_PRSTATUS note (name != \"CORE\")\n", i); -- continue; -+ if (p[0] != 'C' || p[1] != 'O' || p[2] != 'R' || p[3] != 'E') { -+ error(WARNING, "invalid note (name != \"CORE\"\n"); -+ goto fail; - } - - /* -@@ -3762,17 +3551,18 @@ arm64_get_crash_notes(void) - - BCOPY(p + OFFSET(elf_prstatus_pr_reg), &ms->panic_task_regs[i], - sizeof(struct arm64_pt_regs)); -- -- found++; - } - - FREEBUF(buf); - FREEBUF(notes_ptrs); -+ return TRUE; - -- if (!found) { -- free(ms->panic_task_regs); -- ms->panic_task_regs = NULL; -- } -+fail: -+ FREEBUF(buf); -+ FREEBUF(notes_ptrs); -+ free(ms->panic_task_regs); -+ ms->panic_task_regs = NULL; -+ return FALSE; - } - - static void -@@ -3896,13 +3686,9 @@ arm64_IS_VMALLOC_ADDR(ulong vaddr) - (vaddr <= machdep->machspec->kimage_end)) - return FALSE; - -- if (ms->VA_START && (vaddr >= ms->VA_START)) -- return TRUE; -- - return ((vaddr >= ms->vmalloc_start_addr && vaddr <= ms->vmalloc_end) || - ((machdep->flags & VMEMMAP) && -- ((vaddr >= ms->vmemmap_vaddr && vaddr <= ms->vmemmap_end) || -- (vaddr >= ms->vmalloc_end && vaddr <= ms->vmemmap_vaddr))) || -+ (vaddr >= ms->vmemmap_vaddr && vaddr <= ms->vmemmap_end)) || - (vaddr >= ms->modules_vaddr && vaddr <= ms->modules_end)); - } - -@@ -3911,57 +3697,9 @@ arm64_calc_VA_BITS(void) - { - int bitval; - struct syment *sp; -- ulong vabits_actual, value; -+ ulong value; - char *string; - -- if ((string = pc->read_vmcoreinfo("NUMBER(VA_BITS)"))) { -- value = atol(string); -- free(string); -- machdep->machspec->CONFIG_ARM64_VA_BITS = value; -- } -- -- if (kernel_symbol_exists("vabits_actual")) { -- if (pc->flags & PROC_KCORE) { -- vabits_actual = symbol_value_from_proc_kallsyms("vabits_actual"); -- if ((vabits_actual != BADVAL) && (READMEM(pc->mfd, &value, sizeof(ulong), -- vabits_actual, KCORE_USE_VADDR) > 0)) { -- if (CRASHDEBUG(1)) -- fprintf(fp, -- "/proc/kcore: vabits_actual: %ld\n", value); -- machdep->machspec->VA_BITS_ACTUAL = value; -- machdep->machspec->VA_BITS = value; -- machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL); -- } else -- error(FATAL, "/proc/kcore: cannot read vabits_actual\n"); -- } else if (ACTIVE()) -- error(FATAL, "cannot determine VA_BITS_ACTUAL: please use /proc/kcore\n"); -- else { -- if ((string = pc->read_vmcoreinfo("NUMBER(TCR_EL1_T1SZ)"))) { -- /* See ARMv8 ARM for the description of -- * TCR_EL1.T1SZ and how it can be used -- * to calculate the vabits_actual -- * supported by underlying kernel. -- * -- * Basically: -- * vabits_actual = 64 - T1SZ; -- */ -- value = 64 - strtoll(string, NULL, 0); -- if (CRASHDEBUG(1)) -- fprintf(fp, "vmcoreinfo : vabits_actual: %ld\n", value); -- free(string); -- machdep->machspec->VA_BITS_ACTUAL = value; -- machdep->machspec->VA_BITS = value; -- machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL); -- } else if (machdep->machspec->VA_BITS_ACTUAL) { -- machdep->machspec->VA_BITS = machdep->machspec->VA_BITS_ACTUAL; -- machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL); -- } else -- error(FATAL, "cannot determine VA_BITS_ACTUAL\n"); -- } -- -- return; -- } -- - if (!(sp = symbol_search("swapper_pg_dir")) && - !(sp = symbol_search("idmap_pg_dir")) && - !(sp = symbol_search("_text")) && -@@ -3990,12 +3728,14 @@ arm64_calc_VA_BITS(void) - /* - * Verify against dumpfiles that export VA_BITS in vmcoreinfo - */ -- if (machdep->machspec->CONFIG_ARM64_VA_BITS && -- (machdep->machspec->VA_BITS != machdep->machspec->CONFIG_ARM64_VA_BITS)) { -- error(WARNING, "VA_BITS: calculated: %ld vmcoreinfo: %ld\n", -- machdep->machspec->VA_BITS, machdep->machspec->CONFIG_ARM64_VA_BITS); -- machdep->machspec->VA_BITS = machdep->machspec->CONFIG_ARM64_VA_BITS; -- } -+ if ((string = pc->read_vmcoreinfo("NUMBER(VA_BITS)"))) { -+ value = atol(string); -+ free(string); -+ if (machdep->machspec->VA_BITS != value) -+ error(WARNING, "VA_BITS: calculated: %ld vmcoreinfo: %ld\n", -+ machdep->machspec->VA_BITS, value); -+ } -+ - - if (CRASHDEBUG(1)) - fprintf(fp, "VA_BITS: %ld\n", machdep->machspec->VA_BITS); -@@ -4013,15 +3753,6 @@ arm64_calc_VA_BITS(void) - * - * Since VMEMMAP_SIZE is dependent upon the size of a struct page, - * the two ranges cannot be determined until POST_GDB. -- * -- * Since 52-bit VA was introduced: -- * -- * #define STRUCT_PAGE_MAX_SHIFT 6 -- * #define VMEMMAP_SIZE (UL(1) << (VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT)) -- * #define VMEMMAP_START (-VMEMMAP_SIZE) -- * #define VMALLOC_START (MODULES_END) -- * #define VMALLOC_END (- PUD_SIZE - VMEMMAP_SIZE - SZ_64K) -- * #define vmemmap ((struct page *)VMEMMAP_START - (memstart_addr >> PAGE_SHIFT)) - */ - - #define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) -@@ -4033,23 +3764,10 @@ static void - arm64_calc_virtual_memory_ranges(void) - { - struct machine_specific *ms = machdep->machspec; -- ulong value, vmemmap_start, vmemmap_end, vmemmap_size, vmalloc_end; -- char *string; -- int ret; -+ ulong vmemmap_start, vmemmap_end, vmemmap_size; -+ ulong vmalloc_end; - ulong PUD_SIZE = UNINITIALIZED; - -- if (!machdep->machspec->CONFIG_ARM64_VA_BITS) { -- if ((string = pc->read_vmcoreinfo("NUMBER(VA_BITS)"))) { -- value = atol(string); -- free(string); -- machdep->machspec->CONFIG_ARM64_VA_BITS = value; -- } else if (kt->ikconfig_flags & IKCONFIG_AVAIL) { -- if ((ret = get_kernel_config("CONFIG_ARM64_VA_BITS", -- &string)) == IKCONFIG_STR) -- machdep->machspec->CONFIG_ARM64_VA_BITS = atol(string); -- } -- } -- - if (THIS_KERNEL_VERSION < LINUX(3,17,0)) /* use original hardwired values */ - return; - -@@ -4068,24 +3786,8 @@ arm64_calc_virtual_memory_ranges(void) - break; - } - --#define STRUCT_PAGE_MAX_SHIFT 6 -- -- if (ms->VA_BITS_ACTUAL) { -- ulong va_bits_min = 48; -- -- if (machdep->machspec->CONFIG_ARM64_VA_BITS < 48) -- va_bits_min = ms->CONFIG_ARM64_VA_BITS; -- -- vmemmap_size = (1UL) << (va_bits_min - machdep->pageshift - 1 + STRUCT_PAGE_MAX_SHIFT); -- vmalloc_end = (- PUD_SIZE - vmemmap_size - KILOBYTES(64)); -- vmemmap_start = (-vmemmap_size - MEGABYTES(2)); -- ms->vmalloc_end = vmalloc_end - 1; -- ms->vmemmap_vaddr = vmemmap_start; -- ms->vmemmap_end = -1; -- return; -- } -- - if (machdep->flags & NEW_VMEMMAP) -+#define STRUCT_PAGE_MAX_SHIFT 6 - vmemmap_size = 1UL << (ms->VA_BITS - machdep->pageshift - 1 - + STRUCT_PAGE_MAX_SHIFT); - else -@@ -4109,7 +3811,7 @@ arm64_calc_virtual_memory_ranges(void) - static int - arm64_is_uvaddr(ulong addr, struct task_context *tc) - { -- return (addr < machdep->machspec->userspace_top); -+ return (addr < ARM64_USERSPACE_TOP); - } - - -@@ -4134,20 +3836,6 @@ arm64_swp_offset(ulong pte) - return pte; - } - --static void arm64_calc_KERNELPACMASK(void) --{ -- ulong value; -- char *string; -- -- if ((string = pc->read_vmcoreinfo("NUMBER(KERNELPACMASK)"))) { -- value = htol(string, QUIET, NULL); -- free(string); -- machdep->machspec->CONFIG_ARM64_KERNELPACMASK = value; -- if (CRASHDEBUG(1)) -- fprintf(fp, "CONFIG_ARM64_KERNELPACMASK: %lx\n", value); -- } --} -- - #endif /* ARM64 */ - - -diff --git a/defs.h b/defs.h -index 396d61aaf532..897386160abd 100644 ---- a/defs.h -+++ b/defs.h -@@ -3087,7 +3087,7 @@ typedef u64 pte_t; - #define MACHINE_TYPE "ARM64" - - #define PTOV(X) \ -- ((unsigned long)(X) - (machdep->machspec->physvirt_offset)) -+ ((unsigned long)(X)-(machdep->machspec->phys_offset)+(machdep->machspec->page_offset)) - - #define VTOP(X) arm64_VTOP((ulong)(X)) - -@@ -3221,17 +3221,9 @@ typedef signed int s32; - */ - #define ARM64_VA_START ((0xffffffffffffffffUL) \ - << machdep->machspec->VA_BITS) --#define _VA_START(va) ((0xffffffffffffffffUL) - \ -- ((1UL) << ((va) - 1)) + 1) --#define TEXT_OFFSET_MASK (~((MEGABYTES(2UL))-1)) -- - #define ARM64_PAGE_OFFSET ((0xffffffffffffffffUL) \ - << (machdep->machspec->VA_BITS - 1)) --#define ARM64_PAGE_OFFSET_ACTUAL ((0xffffffffffffffffUL) \ -- - ((1UL) << machdep->machspec->VA_BITS_ACTUAL) + 1) -- - #define ARM64_USERSPACE_TOP ((1UL) << machdep->machspec->VA_BITS) --#define ARM64_USERSPACE_TOP_ACTUAL ((1UL) << machdep->machspec->VA_BITS_ACTUAL) - - /* only used for v4.6 or later */ - #define ARM64_MODULES_VSIZE MEGABYTES(128) -@@ -3334,11 +3326,7 @@ struct machine_specific { - ulong kern_eframe_offset; - ulong machine_kexec_start; - ulong machine_kexec_end; -- ulong VA_BITS_ACTUAL; -- ulong CONFIG_ARM64_VA_BITS; -- ulong VA_START; -- ulong CONFIG_ARM64_KERNELPACMASK; -- ulong physvirt_offset; -+ ulong vabits_user; - }; - - struct arm64_stackframe { -@@ -3626,8 +3614,6 @@ struct arm64_stackframe { - machdep->machspec->last_p4d_read = (ulong)(P4D); \ - } - --#define MAX_POSSIBLE_PHYSMEM_BITS 52 -- - /* - * PHYSICAL_PAGE_MASK changed (enlarged) between 2.4 and 2.6, so - * for safety, use the 2.6 values to generate it. --- -2.17.1 - diff --git a/SOURCES/rhel8_build.patch b/SOURCES/rhel8_build.patch index b1c9eae..55560b8 100644 --- a/SOURCES/rhel8_build.patch +++ b/SOURCES/rhel8_build.patch @@ -1,8 +1,6 @@ -diff --git crash-7.3.0/Makefile crash-7.3.0/Makefile -index d0574d8f07d3..9dbb61d0dbc8 100644 ---- crash-7.3.0/Makefile -+++ crash-7.3.0/Makefile -@@ -198,7 +198,7 @@ GDB_FLAGS= +--- crash-7.3.1/Makefile.orig ++++ crash-7.3.1/Makefile +@@ -200,7 +200,7 @@ GDB_FLAGS= # TARGET_CFLAGS will be configured automatically by configure TARGET_CFLAGS= @@ -11,20 +9,18 @@ index d0574d8f07d3..9dbb61d0dbc8 100644 GPL_FILES= TAR_FILES=${SOURCE_FILES} Makefile ${GPL_FILES} README .rh_rpm_package crash.8 \ -@@ -228,7 +228,7 @@ all: make_configure +@@ -230,7 +230,7 @@ all: make_configure gdb_merge: force @if [ ! -f ${GDB}/README ]; then \ make --no-print-directory gdb_unzip; fi -- @echo "${LDFLAGS} -lz -llzo2 -lsnappy -ldl -rdynamic" > ${GDB}/gdb/mergelibs -+ @echo "${LDFLAGS} -lz -llzo2 -lsnappy -ldl -rdynamic -Wl,-z,now -fpie" > ${GDB}/gdb/mergelibs +- @echo "${LDFLAGS} -lz -llzo2 -lsnappy -lzstd -ldl -rdynamic" > ${GDB}/gdb/mergelibs ++ @echo "${LDFLAGS} -lz -llzo2 -lsnappy -lzstd -ldl -rdynamic -Wl,-z,now -fpie" > ${GDB}/gdb/mergelibs @echo "../../${PROGRAM} ../../${PROGRAM}lib.a" > ${GDB}/gdb/mergeobj @rm -f ${PROGRAM} @if [ ! -f ${GDB}/config.status ]; then \ -diff --git crash-7.3.0/configure.c crash-7.3.0/configure.c -index 75006e881f5a..06c94d58c56c 100644 ---- crash-7.3.0/configure.c -+++ crash-7.3.0/configure.c -@@ -780,7 +780,8 @@ build_configure(struct supported_gdb_version *sp) +--- crash-7.3.1/configure.c.orig ++++ crash-7.3.1/configure.c +@@ -800,7 +800,8 @@ build_configure(struct supported_gdb_version *sp) fprintf(fp2, "%s\n", sp->GDB); sprintf(target_data.gdb_version, "%s", &sp->GDB[4]); } else if (strncmp(buf, "LDFLAGS=", strlen("LDFLAGS=")) == 0) { @@ -33,3 +29,4 @@ index 75006e881f5a..06c94d58c56c 100644 + fprintf(fp2, "LDFLAGS=%s\n", ldflags ? ldflags : ""); } else fprintf(fp2, "%s", buf); + diff --git a/SOURCES/rhel8_freepointer.patch b/SOURCES/rhel8_freepointer.patch new file mode 100644 index 0000000..e7aded5 --- /dev/null +++ b/SOURCES/rhel8_freepointer.patch @@ -0,0 +1,29 @@ +From e09e3c038c853f9a332cf05a17e5fdee1c7837e0 Mon Sep 17 00:00:00 2001 +From: Lianbo Jiang +Date: Thu, 18 Nov 2021 09:55:45 +0800 +Subject: [PATCH] fix freepointer issue + +Signed-off-by: Lianbo Jiang +--- + memory.c | 5 ++--- + 1 file changed, 2 insertions(+), 3 deletions(-) + +diff --git a/memory.c b/memory.c +index a3cf8a86728d..81db9c7bee9f 100644 +--- a/memory.c ++++ b/memory.c +@@ -19340,9 +19340,8 @@ freelist_ptr(struct meminfo *si, ulong ptr, ulong ptr_addr) + if (VALID_MEMBER(kmem_cache_random)) { + /* CONFIG_SLAB_FREELIST_HARDENED */ + +- if (THIS_KERNEL_VERSION >= LINUX(5,7,0)) +- ptr_addr = (sizeof(long) == 8) ? bswap_64(ptr_addr) +- : bswap_32(ptr_addr); ++ ptr_addr = (sizeof(long) == 8) ? bswap_64(ptr_addr) ++ : bswap_32(ptr_addr); + return (ptr ^ si->random ^ ptr_addr); + } else + return ptr; +-- +2.30.2 + diff --git a/SPECS/crash.spec b/SPECS/crash.spec index 2c3f833..52e8b12 100644 --- a/SPECS/crash.spec +++ b/SPECS/crash.spec @@ -3,8 +3,8 @@ # Summary: Kernel analysis utility for live systems, netdump, diskdump, kdump, LKCD or mcore dumpfiles Name: crash -Version: 7.3.0 -Release: 2%{?dist} +Version: 7.3.1 +Release: 5%{?dist} License: GPLv3 Group: Development/Debuggers Source0: https://github.com/crash-utility/crash/archive/crash-%{version}.tar.gz @@ -13,12 +13,25 @@ URL: https://crash-utility.github.io ExclusiveOS: Linux ExclusiveArch: %{ix86} ia64 x86_64 ppc ppc64 s390 s390x %{arm} aarch64 ppc64le Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot-%(%{__id_u} -n) -BuildRequires: ncurses-devel zlib-devel lzo-devel bison snappy-devel +BuildRequires: ncurses-devel zlib-devel lzo-devel bison snappy-devel libzstd-devel Requires: binutils Provides: bundled(gdb) = 7.6 -Patch0: lzo_snappy.patch +Patch0: lzo_snappy_zstd.patch Patch1: rhel8_build.patch -Patch2: rhel8_arm64_52_bit_fix.patch +Patch2: rhel8_freepointer.patch +Patch3: 0001-arm64-Support-overflow-stack-panic.patch +Patch4: 0002-defs.h-fix-breakage-of-compatibility-of-struct-symbo.patch +Patch5: 0001-Fix-pvops-Xen-detection-for-arm-machine.patch +Patch6: 0002-Handle-blk_mq_ctx-member-changes-for-kernels-5.16-rc.patch +Patch7: 0003-Fix-for-timer-r-option-to-display-all-the-per-CPU-cl.patch +Patch8: 0004-Fix-for-bt-v-option-to-display-the-stack-end-address.patch +Patch9: 0005-Fix-for-HZ-calculation-on-Linux-5.14-and-later.patch +Patch10: 0006-memory-Handle-struct-slab-changes-on-Linux-5.17-rc1-.patch +Patch11: 0007-Move-the-initialization-of-boot_date-to-task_init.patch +Patch12: 0008-Remove-ptype-command-from-ps-t-option-to-reduce-memo.patch +Patch13: 0009-Improve-the-ps-performance-for-vmcores-with-large-nu.patch +Patch14: 0010-arm64-Fix-segfault-by-bt-command-with-offline-cpus.patch +Patch15: 0011-Fix-for-kmem-s-S-and-bt-F-F-on-Linux-5.17-rc1.patch %description The core analysis suite is a self-contained tool that can be used to @@ -39,9 +52,22 @@ offered by Mission Critical Linux, or the LKCD kernel patch. %prep %setup -n %{name}-%{version} -q -%patch0 -p1 -b lzo_snappy.patch +%patch0 -p1 -b lzo_snappy_zstd.patch %patch1 -p1 -b rhel8_build.patch -%patch2 -p1 -b rhel8_arm64_52_bit_fix.patch +%patch2 -p1 -b rhel8_freepointer.patch +%patch3 -p1 +%patch4 -p1 +%patch5 -p1 +%patch6 -p1 +%patch7 -p1 +%patch8 -p1 +%patch9 -p1 +%patch10 -p1 +%patch11 -p1 +%patch12 -p1 +%patch13 -p1 +%patch14 -p1 +%patch15 -p1 %build cp %{SOURCE1} . @@ -72,6 +98,31 @@ rm -rf %{buildroot} %{_includedir}/* %changelog +* Tue Feb 08 2022 Lianbo Jiang - 7.3.1-5 +- Rebuild for osci badfuncs issue + +* Mon Feb 07 2022 Lianbo Jiang - 7.3.1-4 +- Fix segfault on aarch64 for "bt -a|-c" command +- Fix HZ calculation on Linux 5.14 and later +- Fix for "timer -r" option to display all the per-CPU clocks + +* Mon Dec 13 2021 Lianbo Jiang - 7.3.1-3 +- Fix segmentation fault caused by crash extension modules +- Support the overflow stack exception handling on aarch64 + +* Tue Dec 07 2021 Lianbo Jiang - 7.3.1-2 +- Enable ZSTD feature support + +* Fri Nov 26 2021 Lianbo Jiang - 7.3.1-1 +- Rebase to the latest crash-7.3.1 + +* Thu Nov 18 2021 Lianbo Jiang - 7.3.0-3 +- Fix for "sched: Change task_struct::state" +- Fix for "sched: move CPU field back into thread_info if THREAD_INFO_IN_TASK=y" +- Fix live debugging with lockdown=integrity +- Fix 'waitq' command for Linux 4.13 and later kernels +- Fix for "kmem -s|-S" option on Linux 5.7 and later kernels + * Fri May 14 2021 Lianbo Jiang - 7.3.0-2 - Update the sha512 hash in the sources file to solve the compilation issues @@ -90,7 +141,7 @@ rm -rf %{buildroot} - Also minimize the rhel-only patches to the bare minimum. Resolves: rhbz#1881854 -* Wed Nov 5 2020 Bhupesh Sharma - 7.2.8-8 +* Thu Nov 5 2020 Bhupesh Sharma - 7.2.8-8 - crash/arm64: Fix arm64 read error with 'idmap_ptrs_per_pgd' symbol with debug kernel Resolves: rhbz#1876039