LoongArch: Better backtraces
Subsystems (2)
WANG Xuerui
reviewerv5 cover LoongArch: Better backtraces
From: WANG Xuerui <[email protected]>
Hi,
Here are a bunch of tweaks to the backtrace code, so the Quality of Life for unfortunate LoongArch kernel devs (including but not limited to, myself) could be marginally improved by relieving them of having to mentally decode the register names and CSR bitfields.
Finally, the long-awaited bikeshedding has happened after v4 was posted, although outside of the mailing lists because everyone else preferred to talk in Chinese real-time ;-) Notably v5 has retained the 4x8 grid layout of GPRs because many developers on Loongson hardware are used to the previous style. The CSR names and the name for the CPUCFG.PRID leaf are also shown in upper-case for consistency with the official manuals.
Before:
Quoted 9 lines
[ 17.879976] $ 0 : 0000000000000000 9000000000cc980c 90000001002cc000 90000001002cfe30 [ 17.887936] $ 4 : 0000000000000010 9000000000f1f770 90000001002cc000 9000000000cc3468 [ 17.895895] $ 8 : 900000010028fd00 0000000000000001 000055558e569190 0000000000000004 [ 17.903853] $12 : 0000000000000000 0000000000000004 9000000001026000 900000000132b2d8 [ 17.911811] $16 : 9000000001026000 000000006674b539 9000000000d51d10 0000000000000001 [ 17.919769] $20 : 0000000000000000 900000000025c27c 0000000000000004 0000000000000002 [ 17.927727] $24 : 900000000102e5b0 900000000102e508 0000000000000000 0000000000000004 [ 17.935686] $28 : 9000000009007840 0000000000000004 0000000000000000 0000000000000004 [ 17.943644] era : 90000000002215a0 __arch_cpu_idle+0x20/0x24
Quoted 8 lines
[ 17.949438] ra : 9000000000cc980c default_idle_call+0x34/0x5c [ 17.955406] CSR crmd: 000000b0 [ 17.955408] CSR prmd: 00000004 [ 17.958521] CSR euen: 00000000 [ 17.961635] CSR ecfg: 00071c1c [ 17.964748] CSR estat: 00001000 [ 17.971062] ExcCode : 0 (SubCode 0) [ 17.974522] PrId : 0014c010 (Loongson-64bit)
After:
Quoted 8 lines
[ 187.882746] ra 9000000002ea8e30 tp 9000000003294000 sp 9000000003297db0 [ 187.891047] a0 0000000000000000 a1 900000000318ede8 a2 0000000000000001 a3 000000000000000a [ 187.899347] a4 9000000100297e00 a5 0000000000000001 a6 000000000000002d a7 0000000000000004 [ 187.907646] t0 0000000000000000 t1 0000000000000001 t2 0000000000003c00 t3 0000000000cccccd [ 187.915946] t4 ffffffffffffffff t5 000000045f5d556c t6 0000000000000000 t7 0000000000000001 [ 187.924245] t8 0000000000000000 u0 0000002b6fd7b000 s9 90000000031d02f0 s0 0000000000000004 [ 187.932543] s1 90000000032ae5d0 s2 90000000032ae528 s3 0000000000000000 s4 0000000000000004 [ 187.940842] s5 9000000000571880 s6 90000000005718b2 s7 0000000000000000 s8 90000000031d02f0
Quoted 8 lines
[ 187.949141] ERA: 9000000002351640 __arch_cpu_idle+0x20/0x24 [ 187.954852] ra: 9000000002ea8e30 arch_cpu_idle+0x1c/0x34 [ 187.960391] CRMD: 000000b0 (-WE DACM=CC DACF=CC +PG -DA -IE PLV0) [ 187.966542] PRMD: 00000004 (-PWE +PIE PPLV0) [ 187.970871] EUEN: 00000000 (-BTE -ASXE -SXE -FPE) [ 187.975633] ECFG: 00071c1d (VS=7 LIE=0,2-4,10-12) [ 187.980394] ESTAT: 00000004 [INT] (EsubCode=0 ECode=0 IS=2) [ 187.985931] PRID: 0014c010 (Loongson-64bit)
Changes in v5:
- rebased on top of current loongarch-next
- reverted to 4x8 layout for the GPRs
- show $ra twice (once in the GPRs, once below with symbol info) for prettier grid
- use upper-case field names where applicable
Changes in v4:
- rebased on top of current loongarch-next
- show CSR.BADV in case of BCE too
Changes in v3:
- rebased and tested on top of v6.2-rc8
- restored the "era" name for PC per review suggestion
- show "u0" in case of r21 according to kernel register convention
- removed redundant print of $ra
- print the syscall restart flag if non-zero
Changes in v2:
- rebased and tested on top of next-20221226
- removed the mass symbol renamings per Huacai's suggestion (but the output still uses the ISA manual names because users are expected to be more familiar with those)
WANG Xuerui (12):
LoongArch: Clean up the architectural interrupt definitions
LoongArch: Add exception subcode definitions for the watchpoint
exception
LoongArch: Print GPRs with ABI names when showing registers
LoongArch: Print symbol info for CSR.ERA and $ra only for kernel-mode
contexts
LoongArch: Fix format of CSR lines during show_regs
LoongArch: Humanize the CRMD line when showing registers
LoongArch: Humanize the PRMD line when showing registers
LoongArch: Humanize the EUEN line when showing registers
LoongArch: Humanize the ECFG line when showing registers
LoongArch: Humanize the ESTAT line when showing registers
LoongArch: Use ISA manual names for BADV and CPUCFG.PRID lines in
show_regs
LoongArch: Include CSR.BADV in show_regs in case of BCE exceptions
arch/loongarch/include/asm/loongarch.h | 51 +++--- arch/loongarch/kernel/irq.c | 2 +- arch/loongarch/kernel/perf_event.c | 2 +- arch/loongarch/kernel/time.c | 2 +- arch/loongarch/kernel/traps.c | 225 +++++++++++++++++++++---- 5 files changed, 222 insertions(+), 60 deletions(-)
Signature · 1 line
2.40.0
WANG Xuerui
reviewerPATCH v5 1/12 LoongArch: Clean up the architectural interrupt definitions
From: WANG Xuerui <[email protected]>
While interrupts are assigned ECodes 64 + interrupt number, all existing use sites of interrupt numbers want the 64 subtracted. Re-arrange the definitions so that the actual interrupt number is used everywhere, and make EXCCODE_INT_END inclusive as it is more intuitive that way.
While at it, according to the asm/loongarch.h definitions, the total number of architectural interrupts should be 14 instead of 13. Relevant bitfields and masks have been adjusted as well.
--- arch/loongarch/include/asm/loongarch.h | 47 ++++++++++++++------------ arch/loongarch/kernel/irq.c | 2 +- arch/loongarch/kernel/perf_event.c | 2 +- arch/loongarch/kernel/time.c | 2 +- arch/loongarch/kernel/traps.c | 2 +- 5 files changed, 29 insertions(+), 26 deletions(-)
arch/loongarch/include/asm/loongarch.h +25 -22
@@ -311,8 +311,8 @@ static __always_inline void iocsr_write64(u64 val, u32 reg)#define CSR_ECFG_VS_WIDTH 3#define CSR_ECFG_VS (_ULCAST_(0x7) << CSR_ECFG_VS_SHIFT)#define CSR_ECFG_IM_SHIFT 0 -#define CSR_ECFG_IM_WIDTH 13 -#define CSR_ECFG_IM (_ULCAST_(0x1fff) << CSR_ECFG_IM_SHIFT) +#define CSR_ECFG_IM_WIDTH 14 +#define CSR_ECFG_IM (_ULCAST_(0x3fff) << CSR_ECFG_IM_SHIFT)#define LOONGARCH_CSR_ESTAT 0x5/* Exception status */ #define CSR_ESTAT_ESUBCODE_SHIFT 22
@@ -322,8 +322,8 @@ static __always_inline void iocsr_write64(u64 val, u32 reg)#define CSR_ESTAT_EXC_WIDTH 6#define CSR_ESTAT_EXC (_ULCAST_(0x3f) << CSR_ESTAT_EXC_SHIFT)#define CSR_ESTAT_IS_SHIFT 0 -#define CSR_ESTAT_IS_WIDTH 15 -#define CSR_ESTAT_IS (_ULCAST_(0x7fff) << CSR_ESTAT_IS_SHIFT) +#define CSR_ESTAT_IS_WIDTH 14 +#define CSR_ESTAT_IS (_ULCAST_(0x3fff) << CSR_ESTAT_IS_SHIFT)#define LOONGARCH_CSR_ERA 0x6/* ERA */
@@ -1090,7 +1090,7 @@ static __always_inline void iocsr_write64(u64 val, u32 reg)#define ECFGF_IPI (_ULCAST_(1) << ECFGB_IPI)#define ECFGF (hwirq) (_ULCAST_(1) << hwirq) -#define ESTATF_IP 0x00001fff +#define ESTATF_IP 0x00003fff#define LOONGARCH_IOCSR_FEATURES 0x8#define IOCSRF_TEMP BIT_ULL(0)
@@ -1418,23 +1418,26 @@ __BUILD_CSR_OP(tlbidx)#define EXCSUBCODE_GCHC 1/* Hardware caused */ #define EXCCODE_SE 25/* Security */ -#define EXCCODE_INT_START 64 -#define EXCCODE_SIP0 64 -#define EXCCODE_SIP1 65 -#define EXCCODE_IP0 66 -#define EXCCODE_IP1 67 -#define EXCCODE_IP2 68 -#define EXCCODE_IP3 69 -#define EXCCODE_IP4 70 -#define EXCCODE_IP5 71 -#define EXCCODE_IP6 72 -#define EXCCODE_IP7 73 -#define EXCCODE_PMC 74/* Performance Counter */ -#define EXCCODE_TIMER 75 -#define EXCCODE_IPI 76 -#define EXCCODE_NMI 77 -#define EXCCODE_INT_END 78 -#define EXCCODE_INT_NUM (EXCCODE_INT_END - EXCCODE_INT_START) +/* Interrupt numbers */ +#define INT_SWI0 0/* Software Interrupts */ +#define INT_SWI1 1 +#define INT_HWI0 2/* Hardware Interrupts */ +#define INT_HWI1 3 +#define INT_HWI2 4 +#define INT_HWI3 5 +#define INT_HWI4 6 +#define INT_HWI5 7 +#define INT_HWI6 8 +#define INT_HWI7 9 +#define INT_PCOV 10/* Performance Counter Overflow */ +#define INT_TI 11/* Timer */ +#define INT_IPI 12 +#define INT_NMI 13 + +/* ExcCodes corresponding to interrupts */ +#define EXCCODE_INT_NUM (INT_NMI + 1) +#define EXCCODE_INT_START 64 +#define EXCCODE_INT_END (EXCCODE_INT_START + EXCCODE_INT_NUM - 1)/* FPU register names */ #define LOONGARCH_FCSR0 $r0
arch/loongarch/kernel/irq.c +1 -1
@@ -92,7 +92,7 @@ static int __init get_ipi_irq(void)struct irq_domain *d =irq_find_matching_fwnode (cpuintc_handle,DOMAIN_BUS_ANY );if (d) -return irq_create_mapping (d,EXCCODE_IPI -EXCCODE_INT_START ); +return irq_create_mapping (d,INT_IPI );return -EINVAL ; }
arch/loongarch/kernel/perf_event.c +1 -1
@@ -461,7 +461,7 @@ static int get_pmc_irq(void)struct irq_domain *d =irq_find_matching_fwnode (cpuintc_handle,DOMAIN_BUS_ANY );if (d) -return irq_create_mapping (d,EXCCODE_PMC -EXCCODE_INT_START ); +return irq_create_mapping (d,INT_PCOV );return -EINVAL ; }
arch/loongarch/kernel/time.c +1 -1
@@ -133,7 +133,7 @@ static int get_timer_irq(void)struct irq_domain *d =irq_find_matching_fwnode (cpuintc_handle,DOMAIN_BUS_ANY );if (d) -return irq_create_mapping (d,EXCCODE_TIMER -EXCCODE_INT_START ); +return irq_create_mapping (d,INT_TI );return -EINVAL ; }
arch/loongarch/kernel/traps.c +1 -1
@@ -792,7 +792,7 @@ void __init trap_init(void)long i;/* Set interrupt vector handler */ -for (i =EXCCODE_INT_START ; i <EXCCODE_INT_END ; i++) +for (i =EXCCODE_INT_START ; i <=EXCCODE_INT_END ; i++)set_handler (i *VECSIZE , handle_vint,VECSIZE );set_handler (EXCCODE_ADE *VECSIZE , handle_ade,VECSIZE );
Signature · 1 line
2.40.0
WANG Xuerui
reviewerPATCH v5 2/12 LoongArch: Add exception subcode definitions for the watchpoint exception
In reply to WANG XueruiFrom: WANG Xuerui <[email protected]>
Add them to enable matching the sub-exceptions for humanization purposes later.
--- arch/loongarch/include/asm/loongarch.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/loongarch/include/asm/loongarch.h +3 -1
@@ -1408,7 +1408,9 @@ __BUILD_CSR_OP(tlbidx)#define EXCCODE_FPE 18/* Floating Point Exception */ #define EXCSUBCODE_FPE 0/* Floating Point Exception */ #define EXCSUBCODE_VFPE 1/* Vector Exception */ -#define EXCCODE_WATCH 19/* Watch address reference */ +#define EXCCODE_WATCH 19/* WatchPoint Exception */ +#define EXCSUBCODE_WPEF 0/* ... on instruction Fetch */ +#define EXCSUBCODE_WPEM 1/* ... on Memory access */ #define EXCCODE_BTDIS 20/* Binary Trans. Disabled */ #define EXCCODE_BTE 21/* Binary Trans. Exception */ #define EXCCODE_PSI 22/* Guest Privileged Error */
Signature · 1 line
2.40.0
WANG Xuerui
reviewerPATCH v5 3/12 LoongArch: Print GPRs with ABI names when showing registers
In reply to WANG XueruiFrom: WANG Xuerui <[email protected]>
And show the syscall restart flag (in place of the saved "$zero") if non-zero.
--- arch/loongarch/kernel/traps.c | 36 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)
arch/loongarch/kernel/traps.c +23 -13
@@ -158,22 +158,32 @@ static void __show_regs(const struct pt_regs *regs)const int field =2 *sizeof (unsigned long );unsigned int excsubcode;unsigned int exccode; -int i;show_regs_print_info (KERN_DEFAULT ); -/* -* Saved main processor registers -*/ -for (i =0 ; i <32 ; ) { -if ((i %4 ) ==0 ) -printk ("$%2d :" , i); -pr_cont (" %0*lx" , field, regs->regs[i]); - - i++; -if ((i %4 ) ==0 ) -pr_cont ("\n" ); - } +/* Print GPRs except $zero, maintaining a grid layout */ +#define GPR_FIELD (x) field, regs->regs[x] +pr_cont ("%*c ra %0*lx tp %0*lx sp %0*lx\n" , +3 + field,' ' ,GPR_FIELD (1 ),GPR_FIELD (2 ),GPR_FIELD (3 )); +pr_cont ("a0 %0*lx a1 %0*lx a2 %0*lx a3 %0*lx\n" , +GPR_FIELD (4 ),GPR_FIELD (5 ),GPR_FIELD (6 ),GPR_FIELD (7 )); +pr_cont ("a4 %0*lx a5 %0*lx a6 %0*lx a7 %0*lx\n" , +GPR_FIELD (8 ),GPR_FIELD (9 ),GPR_FIELD (10 ),GPR_FIELD (11 )); +pr_cont ("t0 %0*lx t1 %0*lx t2 %0*lx t3 %0*lx\n" , +GPR_FIELD (12 ),GPR_FIELD (13 ),GPR_FIELD (14 ),GPR_FIELD (15 )); +pr_cont ("t4 %0*lx t5 %0*lx t6 %0*lx t7 %0*lx\n" , +GPR_FIELD (16 ),GPR_FIELD (17 ),GPR_FIELD (18 ),GPR_FIELD (19 )); +pr_cont ("t8 %0*lx u0 %0*lx s9 %0*lx s0 %0*lx\n" , +GPR_FIELD (20 ),GPR_FIELD (21 ),GPR_FIELD (22 ),GPR_FIELD (23 )); +pr_cont ("s1 %0*lx s2 %0*lx s3 %0*lx s4 %0*lx\n" , +GPR_FIELD (24 ),GPR_FIELD (25 ),GPR_FIELD (26 ),GPR_FIELD (27 )); +pr_cont ("s5 %0*lx s6 %0*lx s7 %0*lx s8 %0*lx\n" , +GPR_FIELD (28 ),GPR_FIELD (29 ),GPR_FIELD (30 ),GPR_FIELD (31 )); + +/* The slot for $zero is reused as the syscall restart flag */ +if (regs->regs[0 ]) +pr_cont ("syscall restart flag: %0*lx\n" ,GPR_FIELD (0 )); +#undef GPR_FIELD/* * Saved csr registers
Signature · 1 line
2.40.0
WANG Xuerui
reviewerPATCH v5 4/12 LoongArch: Print symbol info for CSR.ERA and $ra only for kernel-mode contexts
In reply to WANG XueruiFrom: WANG Xuerui <[email protected]>
Otherwise the addresses wouldn't make sense at all.
While at it, align the "map keys" to maintain right-alignment with the "estat:" line too.
--- arch/loongarch/kernel/traps.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/loongarch/kernel/traps.c +8 -8
@@ -183,15 +183,15 @@ static void __show_regs(const struct pt_regs *regs)/* The slot for $zero is reused as the syscall restart flag */ if (regs->regs[0 ])pr_cont ("syscall restart flag: %0*lx\n" ,GPR_FIELD (0 )); -#undef GPR_FIELD -/* -* Saved csr registers -*/ -printk ("era : %0*lx %pS\n" , field, regs->csr_era, - (void *) regs->csr_era); -printk ("ra : %0*lx %pS\n" , field, regs->regs[1 ], - (void *) regs->regs[1 ]); +if (user_mode (regs)) { +pr_cont (" ERA: %0*lx\n" , field, regs->csr_era); +pr_cont (" ra: %0*lx\n" ,GPR_FIELD (1 )); + }else { +pr_cont (" ERA: %0*lx %pS\n" , field, regs->csr_era, (void *) regs->csr_era); +pr_cont (" ra: %0*lx %pS\n" ,GPR_FIELD (1 ), (void *) regs->regs[1 ]); + } +#undef GPR_FIELDprintk ("CSR crmd: %08lx " , regs->csr_crmd);printk ("CSR prmd: %08lx " , regs->csr_prmd);
Signature · 1 line
2.40.0
WANG Xuerui
reviewerPATCH v5 5/12 LoongArch: Fix format of CSR lines during show_regs
In reply to WANG XueruiFrom: WANG Xuerui <[email protected]>
Use uppercase CSR names throughout for consistency with the manual wording, and right-align the keys. The "CSR" part is inferrable from context, hence dropped for more horizontal space.
--- arch/loongarch/kernel/traps.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
arch/loongarch/kernel/traps.c +6 -7
@@ -193,13 +193,12 @@ static void __show_regs(const struct pt_regs *regs) }#undef GPR_FIELD -printk ("CSR crmd: %08lx " , regs->csr_crmd); -printk ("CSR prmd: %08lx " , regs->csr_prmd); -printk ("CSR euen: %08lx " , regs->csr_euen); -printk ("CSR ecfg: %08lx " , regs->csr_ecfg); -printk ("CSR estat: %08lx " , regs->csr_estat); - -pr_cont ("\n" ); +/* Print important CSRs */ +pr_cont (" CRMD: %08lx\n" , regs->csr_crmd); +pr_cont (" PRMD: %08lx\n" , regs->csr_prmd); +pr_cont (" EUEN: %08lx\n" , regs->csr_euen); +pr_cont (" ECFG: %08lx\n" , regs->csr_ecfg); +pr_cont ("ESTAT: %08lx\n" , regs->csr_estat); exccode = ((regs->csr_estat) &CSR_ESTAT_EXC ) >>CSR_ESTAT_EXC_SHIFT ; excsubcode = ((regs->csr_estat) &CSR_ESTAT_ESUBCODE ) >>CSR_ESTAT_ESUBCODE_SHIFT ;
Signature · 1 line
2.40.0
WANG Xuerui
reviewerPATCH v5 6/12 LoongArch: Humanize the CRMD line when showing registers
In reply to WANG XueruiFrom: WANG Xuerui <[email protected]>
Example output looks like:
[ xx.xxxxxx] CRMD: 000000b0 (-WE DACM=CC DACF=CC +PG -DA -IE PLV0)
Some initial machinery for this pretty-printing format has been included in this patch as well.
--- arch/loongarch/kernel/traps.c | 46 ++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
arch/loongarch/kernel/traps.c +45 -1
@@ -3,6 +3,7 @@* Author: Huacai Chen <[email protected]> * Copyright (C) 2020-2022 Loongson Technology Corporation Limited */ +#include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/bug.h> #include <linux/compiler.h>
@@ -153,6 +154,49 @@ static void show_code(unsigned int *pc, bool user)pr_cont ("\n" ); } +static void print_bool_fragment (const char *key,unsigned long val,bool first) +{ +/* e.g. "+PG", "-DA" */ +pr_cont ("%s%c%s" , first ?"" :" " , val ?'+' :'-' , key); +} + +static void print_plv_fragment (const char *key,int val) +{ +/* e.g. "PLV0", "PPLV3" */ +pr_cont (" %s%d" , key, val); +} + +static void print_memory_type_fragment (const char *key,unsigned long val) +{ +/* e.g. "DATM=WUC" */ +const char *humanized_type =NULL ; + +switch (val) { +case 0 : humanized_type ="SUC" ;break ; +case 1 : humanized_type ="CC" ;break ; +case 2 : humanized_type ="WUC" ;break ; + } + +if (humanized_type) { +pr_cont (" %s=%s" , key, humanized_type); + }else { +pr_cont (" %s=Reserved(%lu)" , key, val); + } +} + +static void print_crmd (unsigned long x) +{ +pr_cont (" CRMD: %08lx (" , x); +print_bool_fragment ("WE" ,FIELD_GET (CSR_CRMD_WE , x), true); +print_memory_type_fragment ("DACM" ,FIELD_GET (CSR_CRMD_DACM , x)); +print_memory_type_fragment ("DACF" ,FIELD_GET (CSR_CRMD_DACF , x)); +print_bool_fragment ("PG" ,FIELD_GET (CSR_CRMD_PG , x), false); +print_bool_fragment ("DA" ,FIELD_GET (CSR_CRMD_DA , x), false); +print_bool_fragment ("IE" ,FIELD_GET (CSR_CRMD_IE , x), false); +print_plv_fragment ("PLV" , (int )FIELD_GET (CSR_CRMD_PLV , x)); +pr_cont (")\n" ); +} +static void __show_regs (const struct pt_regs *regs) {const int field =2 *sizeof (unsigned long );
@@ -194,7 +238,7 @@ static void __show_regs(const struct pt_regs *regs)#undef GPR_FIELD/* Print important CSRs */ -pr_cont (" CRMD: %08lx\n" , regs->csr_crmd); +print_crmd (regs->csr_crmd);pr_cont (" PRMD: %08lx\n" , regs->csr_prmd);pr_cont (" EUEN: %08lx\n" , regs->csr_euen);pr_cont (" ECFG: %08lx\n" , regs->csr_ecfg);
Signature · 1 line
2.40.0
WANG Xuerui
reviewerPATCH v5 7/12 LoongArch: Humanize the PRMD line when showing registers
In reply to WANG XueruiFrom: WANG Xuerui <[email protected]>
Example output looks like:
[ xx.xxxxxx] PRMD: 00000004 (-PWE +PIE PPLV0)
--- arch/loongarch/kernel/traps.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/loongarch/kernel/traps.c +10 -1
@@ -197,6 +197,15 @@ static void print_crmd(unsigned long x)pr_cont (")\n" ); } +static void print_prmd (unsigned long x) +{ +pr_cont (" PRMD: %08lx (" , x); +print_bool_fragment ("PWE" ,FIELD_GET (CSR_PRMD_PWE , x), true); +print_bool_fragment ("PIE" ,FIELD_GET (CSR_PRMD_PIE , x), false); +print_plv_fragment ("PPLV" , (int )FIELD_GET (CSR_PRMD_PPLV , x)); +pr_cont (")\n" ); +} +static void __show_regs (const struct pt_regs *regs) {const int field =2 *sizeof (unsigned long );
@@ -239,7 +248,7 @@ static void __show_regs(const struct pt_regs *regs)/* Print important CSRs */ print_crmd (regs->csr_crmd); -pr_cont (" PRMD: %08lx\n" , regs->csr_prmd); +print_prmd (regs->csr_prmd);pr_cont (" EUEN: %08lx\n" , regs->csr_euen);pr_cont (" ECFG: %08lx\n" , regs->csr_ecfg);pr_cont ("ESTAT: %08lx\n" , regs->csr_estat);
Signature · 1 line
2.40.0
WANG Xuerui
reviewerPATCH v5 8/12 LoongArch: Humanize the EUEN line when showing registers
In reply to WANG XueruiFrom: WANG Xuerui <[email protected]>
Example output looks like:
[ xx.xxxxxx] EUEN: 00000000 (-BTE -ASXE -SXE -FPE)
--- arch/loongarch/kernel/traps.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
arch/loongarch/kernel/traps.c +11 -1
@@ -206,6 +206,16 @@ static void print_prmd(unsigned long x)pr_cont (")\n" ); } +static void print_euen (unsigned long x) +{ +pr_cont (" EUEN: %08lx (" , x); +print_bool_fragment ("BTE" ,FIELD_GET (CSR_EUEN_LBTEN , x), true); +print_bool_fragment ("ASXE" ,FIELD_GET (CSR_EUEN_LASXEN , x), false); +print_bool_fragment ("SXE" ,FIELD_GET (CSR_EUEN_LSXEN , x), false); +print_bool_fragment ("FPE" ,FIELD_GET (CSR_EUEN_FPEN , x), false); +pr_cont (")\n" ); +} +static void __show_regs (const struct pt_regs *regs) {const int field =2 *sizeof (unsigned long );
@@ -249,7 +259,7 @@ static void __show_regs(const struct pt_regs *regs)/* Print important CSRs */ print_crmd (regs->csr_crmd);print_prmd (regs->csr_prmd); -pr_cont (" EUEN: %08lx\n" , regs->csr_euen); +print_euen (regs->csr_euen);pr_cont (" ECFG: %08lx\n" , regs->csr_ecfg);pr_cont ("ESTAT: %08lx\n" , regs->csr_estat);
Signature · 1 line
2.40.0
Huacai Chen
maintainerRe: [PATCH v5 08/12] LoongArch: Humanize the EUEN line when showing registers
Hi, Xuerui,
Quoted 17 lines · WANG Xuerui
From: WANG Xuerui <[email protected]>
Example output looks like:
[ xx.xxxxxx] EUEN: 00000000 (-BTE -ASXE -SXE -FPE)
Signed-off-by WANG Xuerui <[email protected]>--- arch/loongarch/kernel/traps.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +0
-0
arch/loongarch/kernel/traps.c static void print_prmd(unsigned long x) · line 215
Quoted 10 lines
arch/loongarch/kernel/traps.c +7
-0@@ -206,6 +206,16 @@ static void print_prmd(unsigned long x)pr_cont (")\n" ); } +static void print_euen (unsigned long x) +{ +pr_cont (" EUEN: %08lx (" , x); +print_bool_fragment ("BTE" ,FIELD_GET (CSR_EUEN_LBTEN , x), true); +print_bool_fragment ("ASXE" ,FIELD_GET (CSR_EUEN_LASXEN , x), false); +print_bool_fragment ("SXE" ,FIELD_GET (CSR_EUEN_LSXEN , x), false); +print_bool_fragment ("FPE" ,FIELD_GET (CSR_EUEN_FPEN , x), false);
Please print from LSB to MSB for all CSRs, this can also makes ECode be displayed before ESubCode in ESTAT.
Huacai
Quoted 18 lines
arch/loongarch/kernel/traps.c +4
-2+pr_cont (")\n" ); +} +static void __show_regs (const struct pt_regs *regs) {const int field =2 *sizeof (unsigned long );@@ -249,7 +259,7 @@ static void __show_regs(const struct pt_regs *regs)/* Print important CSRs */ print_crmd (regs->csr_crmd);print_prmd (regs->csr_prmd); -pr_cont (" EUEN: %08lx\n" , regs->csr_euen); +print_euen (regs->csr_euen);pr_cont (" ECFG: %08lx\n" , regs->csr_ecfg);pr_cont ("ESTAT: %08lx\n" , regs->csr_estat); --2.40.0
WANG Xuerui
reviewerRe: [PATCH v5 08/12] LoongArch: Humanize the EUEN line when showing registers
Quoted 22 lines · Huacai Chen
Hi, Xuerui,
Quoted 19 lines · WANG Xuerui
From: WANG Xuerui <[email protected]>
Example output looks like:
[ xx.xxxxxx] EUEN: 00000000 (-BTE -ASXE -SXE -FPE)
Signed-off-by WANG Xuerui <[email protected]>--- arch/loongarch/kernel/traps.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +0
-0@@ -206,6 +206,16 @@ static void print_prmd(unsigned long x)pr_cont (")\n" ); }
Quoted 9 lines
arch/loongarch/kernel/traps.c static void print_prmd(unsigned long x) · line 215
Quoted 7 lines
arch/loongarch/kernel/traps.c +7
-0+static void print_euen (unsigned long x) +{ +pr_cont (" EUEN: %08lx (" , x); +print_bool_fragment ("BTE" ,FIELD_GET (CSR_EUEN_LBTEN , x), true); +print_bool_fragment ("ASXE" ,FIELD_GET (CSR_EUEN_LASXEN , x), false); +print_bool_fragment ("SXE" ,FIELD_GET (CSR_EUEN_LSXEN , x), false); +print_bool_fragment ("FPE" ,FIELD_GET (CSR_EUEN_FPEN , x), false);Please print from LSB to MSB for all CSRs, this can also makes ECode be displayed before ESubCode in ESTAT.
After some consideration, I think it's even more unfortunate to have all other CSRs printed backwards, just to make ECode appear before EsubCode. I'll change the ESTAT line alone in favor of keeping the display order of other CSRs' fields consistent with the accompanying hex notation.
Signature · 3 lines
WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
Huacai Chen
maintainerRe: [PATCH v5 08/12] LoongArch: Humanize the EUEN line when showing registers
Quoted 34 lines · WANG Xuerui
Quoted 22 lines · Huacai Chen
Hi, Xuerui,
Quoted 19 lines · WANG Xuerui
From: WANG Xuerui <[email protected]>
Example output looks like:
[ xx.xxxxxx] EUEN: 00000000 (-BTE -ASXE -SXE -FPE)
Signed-off-by WANG Xuerui <[email protected]>--- arch/loongarch/kernel/traps.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +0
-0@@ -206,6 +206,16 @@ static void print_prmd(unsigned long x)pr_cont (")\n" ); }Quoted 9 lines
arch/loongarch/kernel/traps.c static void print_prmd(unsigned long x) · line 215
Quoted 7 lines
arch/loongarch/kernel/traps.c +7
-0+static void print_euen (unsigned long x) +{ +pr_cont (" EUEN: %08lx (" , x); +print_bool_fragment ("BTE" ,FIELD_GET (CSR_EUEN_LBTEN , x), true); +print_bool_fragment ("ASXE" ,FIELD_GET (CSR_EUEN_LASXEN , x), false); +print_bool_fragment ("SXE" ,FIELD_GET (CSR_EUEN_LSXEN , x), false); +print_bool_fragment ("FPE" ,FIELD_GET (CSR_EUEN_FPEN , x), false);Please print from LSB to MSB for all CSRs, this can also makes ECode be displayed before ESubCode in ESTAT.
Quoted 4 lines
After some consideration, I think it's even more unfortunate to have all other CSRs printed backwards, just to make ECode appear before EsubCode. I'll change the ESTAT line alone in favor of keeping the display order of other CSRs' fields consistent with the accompanying hex notation.
No, it is also more natural for EUEN if it is displayed in FPE, SXE, ASXE, BTE order.
Huacai
Quoted 6 lines
--
WANG "xen0n" Xuerui
Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
WANG Xuerui
reviewerPATCH v5 9/12 LoongArch: Humanize the ECFG line when showing registers
In reply to WANG XueruiFrom: WANG Xuerui <[email protected]>
Example output looks like:
[ xx.xxxxxx] ECFG: 00071c1c (VS=7 LIE=2-4,10-12)
--- arch/loongarch/kernel/traps.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
arch/loongarch/kernel/traps.c +14 -1
@@ -184,6 +184,12 @@ static void print_memory_type_fragment(const char *key, unsigned long val) } } +static void print_intr_fragment (const char *key,unsigned long val) +{ +/* e.g. "LIE=0-1,3,5-7" */ +pr_cont (" %s=%*pbl" , key,EXCCODE_INT_NUM , &val); +} +static void print_crmd (unsigned long x) {pr_cont (" CRMD: %08lx (" , x);
@@ -216,6 +222,13 @@ static void print_euen(unsigned long x)pr_cont (")\n" ); } +static void print_ecfg (unsigned long x) +{ +pr_cont (" ECFG: %08lx (VS=%d" , x, (int )FIELD_GET (CSR_ECFG_VS , x)); +print_intr_fragment ("LIE" ,FIELD_GET (CSR_ECFG_IM , x)); +pr_cont (")\n" ); +} +static void __show_regs (const struct pt_regs *regs) {const int field =2 *sizeof (unsigned long );
@@ -260,7 +273,7 @@ static void __show_regs(const struct pt_regs *regs)print_crmd (regs->csr_crmd);print_prmd (regs->csr_prmd);print_euen (regs->csr_euen); -pr_cont (" ECFG: %08lx\n" , regs->csr_ecfg); +print_ecfg (regs->csr_ecfg);pr_cont ("ESTAT: %08lx\n" , regs->csr_estat); exccode = ((regs->csr_estat) &CSR_ESTAT_EXC ) >>CSR_ESTAT_EXC_SHIFT ;
Signature · 1 line
2.40.0
WANG Xuerui
reviewerPATCH v5 10/12 LoongArch: Humanize the ESTAT line when showing registers
In reply to WANG XueruiFrom: WANG Xuerui <[email protected]>
Example output looks like:
[ xx.xxxxxx] ESTAT: 00001000 [INT] (EsubCode=0 ECode=0 IS=12)
--- arch/loongarch/kernel/traps.c | 86 ++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 7 deletions(-)
arch/loongarch/kernel/traps.c +79 -7
@@ -229,11 +229,87 @@ static void print_ecfg(unsigned long x)pr_cont (")\n" ); } +static const char *humanize_exc_name (unsigned int ecode,unsigned int esubcode) +{ +/* +* Right now the kernel source refers to the exceptions using mostly +* MIPS-esque names, but LoongArch users and developers are probably +* more familiar with those in the ISA manual, so we are going to +* print out the latter. Expect much friction between the two sides +* below... +*/ +switch (ecode) { +case EXCCODE_RSV :return "INT" ; +case EXCCODE_TLBL :return "PIL" ; +case EXCCODE_TLBS :return "PIS" ; +case EXCCODE_TLBI :return "PIF" ; +case EXCCODE_TLBM :return "PME" ; +case EXCCODE_TLBNR :return "PNR" ; +case EXCCODE_TLBNX :return "PNX" ; +case EXCCODE_TLBPE :return "PPI" ; +case EXCCODE_ADE : +switch (esubcode) { +case EXSUBCODE_ADEF :return "ADEF" ; +case EXSUBCODE_ADEM :return "ADEM" ; + } +break ; +case EXCCODE_ALE :return "ALE" ; +case EXCCODE_OOB :return "BCE" ; +case EXCCODE_SYS :return "SYS" ; +case EXCCODE_BP :return "BRK" ; +case EXCCODE_INE :return "INE" ; +case EXCCODE_IPE :return "IPE" ; +case EXCCODE_FPDIS :return "FPD" ; +case EXCCODE_LSXDIS :return "SXD" ; +case EXCCODE_LASXDIS :return "ASXD" ; +case EXCCODE_FPE : +switch (esubcode) { +case EXCSUBCODE_FPE :return "FPE" ; +case EXCSUBCODE_VFPE :return "VFPE" ; + } +break ; +case EXCCODE_WATCH : +switch (esubcode) { +case EXCSUBCODE_WPEF :return "WPEF" ; +case EXCSUBCODE_WPEM :return "WPEM" ; + } +break ; +case EXCCODE_BTDIS :return "BTD" ; +case EXCCODE_BTE :return "BTE" ; +case EXCCODE_PSI :return "GSPR" ; +case EXCCODE_HYP :return "HVC" ; +case EXCCODE_GCM : +switch (esubcode) { +case EXCSUBCODE_GCSC :return "GCSC" ; +case EXCSUBCODE_GCHC :return "GCHC" ; + } +break ; +/* +* The manual did not mention the EXCCODE_SE case, but print out it +* nevertheless. +*/ +case EXCCODE_SE :return "SE" ; + } + +return "???" ; +} + +static void print_estat (unsigned long x) +{ +unsigned int ecode =FIELD_GET (CSR_ESTAT_EXC , x); +unsigned int esubcode =FIELD_GET (CSR_ESTAT_ESUBCODE , x); + +pr_cont ("ESTAT: %08lx [%s] (EsubCode=%d ECode=%d" , x, +humanize_exc_name (ecode, esubcode), (int ) esubcode, + (int ) ecode); +print_intr_fragment ("IS" ,FIELD_GET (CSR_ESTAT_IS , x)); +pr_cont (")\n" ); +} +static void __show_regs (const struct pt_regs *regs) {const int field =2 *sizeof (unsigned long ); -unsigned int excsubcode; -unsigned int exccode; +unsigned int exccode =FIELD_GET (CSR_ESTAT_EXC , regs->csr_estat);show_regs_print_info (KERN_DEFAULT );
@@ -274,11 +350,7 @@ static void __show_regs(const struct pt_regs *regs)print_prmd (regs->csr_prmd);print_euen (regs->csr_euen);print_ecfg (regs->csr_ecfg); -pr_cont ("ESTAT: %08lx\n" , regs->csr_estat); - - exccode = ((regs->csr_estat) &CSR_ESTAT_EXC ) >>CSR_ESTAT_EXC_SHIFT ; - excsubcode = ((regs->csr_estat) &CSR_ESTAT_ESUBCODE ) >>CSR_ESTAT_ESUBCODE_SHIFT ; -printk ("ExcCode : %x (SubCode %x)\n" , exccode, excsubcode); +print_estat (regs->csr_estat);if (exccode >=EXCCODE_TLBL && exccode <=EXCCODE_ALE )printk ("BadVA : %0*lx\n" , field, regs->csr_badvaddr);
Signature · 1 line
2.40.0
WANG Xuerui
reviewerPATCH v5 11/12 LoongArch: Use ISA manual names for BADV and CPUCFG.PRID lines in show_regs
In reply to WANG XueruiFrom: WANG Xuerui <[email protected]>
While at it, also change the printk to pr_cont.
--- arch/loongarch/kernel/traps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/loongarch/kernel/traps.c +2 -2
@@ -353,9 +353,9 @@ static void __show_regs(const struct pt_regs *regs)print_estat (regs->csr_estat);if (exccode >=EXCCODE_TLBL && exccode <=EXCCODE_ALE ) -printk ("BadVA : %0*lx\n" , field, regs->csr_badvaddr); +pr_cont (" BADV: %0*lx\n" , field, regs->csr_badvaddr); -printk ("PrId : %08x (%s)\n" ,read_cpucfg (LOONGARCH_CPUCFG0 ), +pr_cont (" PRID: %08x (%s)\n" ,read_cpucfg (LOONGARCH_CPUCFG0 ),cpu_family_string ()); }
Signature · 1 line
2.40.0
WANG Xuerui
reviewerPATCH v5 12/12 LoongArch: Include CSR.BADV in show_regs in case of BCE exceptions
In reply to WANG XueruiFrom: WANG Xuerui <[email protected]>
According to the LoongArch ISA Manual's description for CSR.BADV (Volume 1, Section 7.4.8), CSR.BADV is supposed to be updated in case of BCE [Bound checking error] too, in addition to the current implemented list of exceptions.
Note: in my experiments CSR.BADV actually does *not* seem to reflect the offending out-of-bounds value at all, regardless of the instruction used (neither asrt{gt,le} nor {ld,st}{gt,le}). My wild guess is that when the assertion fails, the execution of the instruction has not proceeded to MEM stage yet, and that only in this stage is CSR.BADV potentially updated. We show it nevertheless because it does not hurt and it is generally better to maintain consistency with the manuals.
--- arch/loongarch/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/loongarch/kernel/traps.c +1 -1
@@ -352,7 +352,7 @@ static void __show_regs(const struct pt_regs *regs)print_ecfg (regs->csr_ecfg);print_estat (regs->csr_estat); -if (exccode >=EXCCODE_TLBL && exccode <=EXCCODE_ALE ) +if (exccode >=EXCCODE_TLBL && exccode <=EXCCODE_OOB )pr_cont (" BADV: %0*lx\n" , field, regs->csr_badvaddr); pr_cont(" PRID: %08x (%s)\n", read_cpucfg(LOONGARCH_CPUCFG0),
Signature · 1 line
2.40.0
Huacai Chen
maintainerHi, Xuerui,
Quoted 37 lines · WANG Xuerui
From: WANG Xuerui <[email protected]>
Hi,
Here are a bunch of tweaks to the backtrace code, so the Quality of Life for unfortunate LoongArch kernel devs (including but not limited to, myself) could be marginally improved by relieving them of having to mentally decode the register names and CSR bitfields.
Finally, the long-awaited bikeshedding has happened after v4 was posted, although outside of the mailing lists because everyone else preferred to talk in Chinese real-time ;-) Notably v5 has retained the 4x8 grid layout of GPRs because many developers on Loongson hardware are used to the previous style. The CSR names and the name for the CPUCFG.PRID leaf are also shown in upper-case for consistency with the official manuals.
Before:
Quoted 9 lines
[ 17.879976] $ 0 : 0000000000000000 9000000000cc980c 90000001002cc000 90000001002cfe30 [ 17.887936] $ 4 : 0000000000000010 9000000000f1f770 90000001002cc000 9000000000cc3468 [ 17.895895] $ 8 : 900000010028fd00 0000000000000001 000055558e569190 0000000000000004 [ 17.903853] $12 : 0000000000000000 0000000000000004 9000000001026000 900000000132b2d8 [ 17.911811] $16 : 9000000001026000 000000006674b539 9000000000d51d10 0000000000000001 [ 17.919769] $20 : 0000000000000000 900000000025c27c 0000000000000004 0000000000000002 [ 17.927727] $24 : 900000000102e5b0 900000000102e508 0000000000000000 0000000000000004 [ 17.935686] $28 : 9000000009007840 0000000000000004 0000000000000000 0000000000000004 [ 17.943644] era : 90000000002215a0 __arch_cpu_idle+0x20/0x24Quoted 8 lines
[ 17.949438] ra : 9000000000cc980c default_idle_call+0x34/0x5c [ 17.955406] CSR crmd: 000000b0 [ 17.955408] CSR prmd: 00000004 [ 17.958521] CSR euen: 00000000 [ 17.961635] CSR ecfg: 00071c1c [ 17.964748] CSR estat: 00001000 [ 17.971062] ExcCode : 0 (SubCode 0) [ 17.974522] PrId : 0014c010 (Loongson-64bit)
Quoted 3 lines
After:
Quoted 1 line
[ 187.882746] ra 9000000002ea8e30 tp 9000000003294000 sp 9000000003297db0
I think we can fill this blank with pc, as in an early version.
Quoted 9 lines
Quoted 9 lines
[ 187.891047] a0 0000000000000000 a1 900000000318ede8 a2 0000000000000001 a3 000000000000000a [ 187.899347] a4 9000000100297e00 a5 0000000000000001 a6 000000000000002d a7 0000000000000004 [ 187.907646] t0 0000000000000000 t1 0000000000000001 t2 0000000000003c00 t3 0000000000cccccd [ 187.915946] t4 ffffffffffffffff t5 000000045f5d556c t6 0000000000000000 t7 0000000000000001 [ 187.924245] t8 0000000000000000 u0 0000002b6fd7b000 s9 90000000031d02f0 s0 0000000000000004 [ 187.932543] s1 90000000032ae5d0 s2 90000000032ae528 s3 0000000000000000 s4 0000000000000004 [ 187.940842] s5 9000000000571880 s6 90000000005718b2 s7 0000000000000000 s8 90000000031d02f0 [ 187.949141] ERA: 9000000002351640 __arch_cpu_idle+0x20/0x24 [ 187.954852] ra: 9000000002ea8e30 arch_cpu_idle+0x1c/0x34
If ra should be in lower case, try to exchange it with the ERA line.
Quoted 63 lines
Quoted 6 lines
[ 187.960391] CRMD: 000000b0 (-WE DACM=CC DACF=CC +PG -DA -IE PLV0) [ 187.966542] PRMD: 00000004 (-PWE +PIE PPLV0) [ 187.970871] EUEN: 00000000 (-BTE -ASXE -SXE -FPE) [ 187.975633] ECFG: 00071c1d (VS=7 LIE=0,2-4,10-12) [ 187.980394] ESTAT: 00000004 [INT] (EsubCode=0 ECode=0 IS=2) [ 187.985931] PRID: 0014c010 (Loongson-64bit)Changes in v5:
- rebased on top of current loongarch-next
- reverted to 4x8 layout for the GPRs
- show $ra twice (once in the GPRs, once below with symbol info) for prettier grid
- use upper-case field names where applicableChanges in v4:
- rebased on top of current loongarch-next
- show CSR.BADV in case of BCE tooChanges in v3:
- rebased and tested on top of v6.2-rc8
- restored the "era" name for PC per review suggestion
- show "u0" in case of r21 according to kernel register convention
- removed redundant print of $ra
- print the syscall restart flag if non-zeroChanges in v2:
- rebased and tested on top of next-20221226
- removed the mass symbol renamings per Huacai's suggestion (but the output still uses the ISA manual names because users are expected to be more familiar with those)WANG Xuerui (12):
LoongArch: Clean up the architectural interrupt definitions
LoongArch: Add exception subcode definitions for the watchpoint
exception
LoongArch: Print GPRs with ABI names when showing registers
LoongArch: Print symbol info for CSR.ERA and $ra only for kernel-mode
contexts
LoongArch: Fix format of CSR lines duringshow_regs
LoongArch: Humanize the CRMD line when showing registers
LoongArch: Humanize the PRMD line when showing registers
LoongArch: Humanize the EUEN line when showing registers
LoongArch: Humanize the ECFG line when showing registers
LoongArch: Humanize the ESTAT line when showing registers
LoongArch: Use ISA manual names for BADV and CPUCFG.PRID lines in
show_regs
LoongArch: Include CSR.BADV inshow_regsin case of BCE exceptionsarch/loongarch/include/asm/loongarch.h | 51 +++--- arch/loongarch/kernel/irq.c | 2 +- arch/loongarch/kernel/perf_event.c | 2 +- arch/loongarch/kernel/time.c | 2 +- arch/loongarch/kernel/traps.c | 225 +++++++++++++++++++++---- 5 files changed, 222 insertions(+), 60 deletions(-)--
2.40.0