From 1356ffc2d4507dd8f2216a6a3d2843e0d2303e62 Mon Sep 17 00:00:00 2001 From: huskarTang Date: Fri, 30 Dec 2022 10:22:18 +0800 Subject: [PATCH] Four fixes for MIPS kernels --- 0012-Four-fixes-for-MIPS-kernel.patch | 122 ++++++++++++++++++++++++++ crash.spec | 6 +- 2 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 0012-Four-fixes-for-MIPS-kernel.patch diff --git a/0012-Four-fixes-for-MIPS-kernel.patch b/0012-Four-fixes-for-MIPS-kernel.patch new file mode 100644 index 0000000..ec51b6a --- /dev/null +++ b/0012-Four-fixes-for-MIPS-kernel.patch @@ -0,0 +1,122 @@ +From e8f86454409c78d5b4571082167cbadea2890939 Mon Sep 17 00:00:00 2001 +From: huskarTang +Date: Fri, 30 Dec 2022 09:56:11 +0800 +Subject: [PATCH] Four fix for MIPS platform + +Four fixes for MIPS kernels: + 1) 'irq' command with option '-d' always fails, caused by CANN'T + determine the IRQ number. + 2) Add machine_type() check for MIPS64 to support ramdumps. + 3) Add machine_type() check in context invoking crash with -d1, + get the correct dump note offsets, avoiding processing stuck. + 4) Fix the refernece file path in structure in pt_regs. +--- + defs.h | 2 +- + diskdump.c | 2 +- + mips.c | 10 ++++++++-- + mips64.c | 14 ++++++++++++++ + ramdump.c | 2 +- + 5 files changed, 25 insertions(+), 5 deletions(-) + +diff --git a/defs.h b/defs.h +index b253579..575ca0b 100644 +--- a/defs.h ++++ b/defs.h +@@ -6494,7 +6494,7 @@ void mips64_dump_machdep_table(ulong); + #define display_idt_table() \ + error(FATAL, "-d option is not applicable to MIPS64 architecture\n") + +-/* from arch/mips/include/uapi/asm/ptrace.h */ ++/* from arch/mips/include/asm/ptrace.h */ + struct mips64_register { + ulong regs[45]; + }; +diff --git a/diskdump.c b/diskdump.c +index d7339bc..b47a677 100644 +--- a/diskdump.c ++++ b/diskdump.c +@@ -1702,7 +1702,7 @@ dump_note_offsets(FILE *fp) + qemu = FALSE; + if (machine_type("X86_64") || machine_type("S390X") || + machine_type("ARM64") || machine_type("PPC64") || +- machine_type("SPARC64")) { ++ machine_type("SPARC64") || machine_type("MIPS64")) { + note64 = (void *)dd->notes_buf + tot; + len = sizeof(Elf64_Nhdr); + if (STRNEQ((char *)note64 + len, "QEMU")) +diff --git a/mips.c b/mips.c +index f73dfad..d6602e3 100644 +--- a/mips.c ++++ b/mips.c +@@ -1126,8 +1126,14 @@ mips_init(int when) + machdep->get_irq_affinity = generic_get_irq_affinity; + machdep->section_size_bits = _SECTION_SIZE_BITS; + machdep->max_physmem_bits = _MAX_PHYSMEM_BITS; +- ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc, +- "irq_desc", NULL, 0); ++ ++ if (symbol_exists("irq_desc")) ++ ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc, ++ "irq_desc", NULL, 0); ++ else if (kernel_symbol_exists("nr_irqs")) ++ get_symbol_data("nr_irqs", sizeof(unsigned int), ++ &machdep->nr_irqs); ++ + mips_stackframe_init(); + + if (!machdep->hz) +diff --git a/mips64.c b/mips64.c +index 62ed799..b1d6acf 100644 +--- a/mips64.c ++++ b/mips64.c +@@ -1160,6 +1160,9 @@ mips64_dump_machdep_table(ulong arg) + fprintf(fp, " is_task_addr: mips64_is_task_addr()\n"); + fprintf(fp, " verify_symbol: mips64_verify_symbol()\n"); + fprintf(fp, " dis_filter: generic_dis_filter()\n"); ++ fprintf(fp, " dump_irq: generic_dump_irq()\n"); ++ fprintf(fp, " show_interrupts: generic_show_interrupts()\n"); ++ fprintf(fp, " get_irq_affinity: generic_get_irq_affinity()\n"); + fprintf(fp, " cmd_mach: mips64_cmd_mach()\n"); + fprintf(fp, " get_smp_cpus: mips64_get_smp_cpus()\n"); + fprintf(fp, " is_kvaddr: generic_is_kvaddr()\n"); +@@ -1246,6 +1249,9 @@ mips64_init(int when) + machdep->is_task_addr = mips64_is_task_addr; + machdep->get_smp_cpus = mips64_get_smp_cpus; + machdep->dis_filter = generic_dis_filter; ++ machdep->dump_irq = generic_dump_irq; ++ machdep->show_interrupts = generic_show_interrupts; ++ machdep->get_irq_affinity = generic_get_irq_affinity; + machdep->value_to_symbol = generic_machdep_value_to_symbol; + machdep->init_kernel_pgd = NULL; + break; +@@ -1257,6 +1263,14 @@ mips64_init(int when) + mips64_stackframe_init(); + if (!machdep->hz) + machdep->hz = 250; ++ ++ if (symbol_exists("irq_desc")) ++ ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc, ++ "irq_desc", NULL, 0); ++ else if (kernel_symbol_exists("nr_irqs")) ++ get_symbol_data("nr_irqs", sizeof(unsigned int), ++ &machdep->nr_irqs); ++ + MEMBER_OFFSET_INIT(elf_prstatus_pr_reg, "elf_prstatus", + "pr_reg"); + STRUCT_SIZE_INIT(note_buf, "note_buf_t"); +diff --git a/ramdump.c b/ramdump.c +index 4c4a920..a206fcb 100644 +--- a/ramdump.c ++++ b/ramdump.c +@@ -184,7 +184,7 @@ char *ramdump_to_elf(void) + e_machine = EM_ARM; + else if (machine_type("ARM64")) + e_machine = EM_AARCH64; +- else if (machine_type("MIPS")) ++ else if (machine_type("MIPS") || machine_type("MIPS64")) + e_machine = EM_MIPS; + else if (machine_type("X86_64")) + e_machine = EM_X86_64; +-- +2.7.4 + diff --git a/crash.spec b/crash.spec index 11f53c1..bf43753 100644 --- a/crash.spec +++ b/crash.spec @@ -1,6 +1,6 @@ Name: crash Version: 7.3.0 -Release: 11 +Release: 12 Summary: Linux kernel crash utility. License: GPLv3 URL: https://crash-utility.github.io @@ -21,6 +21,7 @@ Patch9: 0008-arm64-fix-backtraces-of-KASAN-kernel-dumpfile-truncated.patch Patch10: 0009-Add-lowercase-tcr_el1_t1sz.patch Patch11: 0010-Fix-kmem-option-on-Linux-5.7-and-later.patch Patch12: 0011-Fix-macro-TIF_SIGPENDING-values.patch +Patch13: 0012-Four-fixes-for-MIPS-kernel.patch BuildRequires: ncurses-devel zlib-devel lzo-devel snappy-devel BuildRequires: gcc gcc-c++ bison m4 @@ -86,6 +87,9 @@ install -D -m 0644 defs.h %{buildroot}%{_includedir}/%{name}/defs.h %{_mandir}/man8/crash.8* %changelog +* Fri Dec 30 2022 huskartang - 7.3.0-12 +- Four fixes for MIPS platform + * Thu Dec 29 2022 huskartang - 7.3.0-11 - Fix the value of TIF_SIGPENDING macro -- Gitee