Skip to content

Commit 7153d4b

Browse files
xwsongmpe
authored andcommitted
powerpc/traps: Enhance readability for trap types
Define macros to list ppc interrupt types in interttupt.h, replace the reference of the trap hex values with these macros. Referred the hex numbers in arch/powerpc/kernel/exceptions-64e.S, arch/powerpc/kernel/exceptions-64s.S, arch/powerpc/kernel/head_*.S, arch/powerpc/kernel/head_booke.h and arch/powerpc/include/asm/kvm_asm.h. Signed-off-by: Xiongwei Song <sxwjean@gmail.com> [mpe: Resolve conflicts in nmi_disables_ftrace(), fix 40x build] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/1618398033-13025-1-git-send-email-sxwjean@me.com
1 parent 7de21e6 commit 7153d4b

File tree

10 files changed

+84
-30
lines changed

10 files changed

+84
-30
lines changed

arch/powerpc/include/asm/interrupt.h

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,50 @@
99
#include <asm/kprobes.h>
1010
#include <asm/runlatch.h>
1111

12+
/* BookE/4xx */
13+
#define INTERRUPT_CRITICAL_INPUT 0x100
14+
15+
/* BookE */
16+
#define INTERRUPT_DEBUG 0xd00
17+
#ifdef CONFIG_BOOKE
18+
#define INTERRUPT_PERFMON 0x260
19+
#define INTERRUPT_DOORBELL 0x280
20+
#endif
21+
22+
/* BookS/4xx/8xx */
23+
#define INTERRUPT_MACHINE_CHECK 0x200
24+
25+
/* BookS/8xx */
26+
#define INTERRUPT_SYSTEM_RESET 0x100
27+
28+
/* BookS */
29+
#define INTERRUPT_DATA_SEGMENT 0x380
30+
#define INTERRUPT_INST_SEGMENT 0x480
31+
#define INTERRUPT_TRACE 0xd00
32+
#define INTERRUPT_H_DATA_STORAGE 0xe00
33+
#define INTERRUPT_H_FAC_UNAVAIL 0xf80
34+
#ifdef CONFIG_PPC_BOOK3S
35+
#define INTERRUPT_DOORBELL 0xa00
36+
#define INTERRUPT_PERFMON 0xf00
37+
#endif
38+
39+
/* BookE/BookS/4xx/8xx */
40+
#define INTERRUPT_DATA_STORAGE 0x300
41+
#define INTERRUPT_INST_STORAGE 0x400
42+
#define INTERRUPT_ALIGNMENT 0x600
43+
#define INTERRUPT_PROGRAM 0x700
44+
#define INTERRUPT_SYSCALL 0xc00
45+
46+
/* BookE/BookS/44x */
47+
#define INTERRUPT_FP_UNAVAIL 0x800
48+
49+
/* BookE/BookS/44x/8xx */
50+
#define INTERRUPT_DECREMENTER 0x900
51+
52+
#ifndef INTERRUPT_PERFMON
53+
#define INTERRUPT_PERFMON 0x0
54+
#endif
55+
1256
static inline void nap_adjust_return(struct pt_regs *regs)
1357
{
1458
#ifdef CONFIG_PPC_970_NAP
@@ -65,7 +109,7 @@ static inline void interrupt_enter_prepare(struct pt_regs *regs, struct interrup
65109
* CT_WARN_ON comes here via program_check_exception,
66110
* so avoid recursion.
67111
*/
68-
if (TRAP(regs) != 0x700)
112+
if (TRAP(regs) != INTERRUPT_PROGRAM)
69113
CT_WARN_ON(ct_state() != CONTEXT_KERNEL);
70114
}
71115
#endif
@@ -131,13 +175,13 @@ static inline bool nmi_disables_ftrace(struct pt_regs *regs)
131175
{
132176
/* Allow DEC and PMI to be traced when they are soft-NMI */
133177
if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) {
134-
if (TRAP(regs) == 0x900)
178+
if (TRAP(regs) == INTERRUPT_DECREMENTER)
135179
return false;
136-
if (TRAP(regs) == 0xf00)
180+
if (TRAP(regs) == INTERRUPT_PERFMON)
137181
return false;
138182
}
139183
if (IS_ENABLED(CONFIG_PPC_BOOK3E)) {
140-
if (TRAP(regs) == 0x260)
184+
if (TRAP(regs) == INTERRUPT_PERFMON)
141185
return false;
142186
}
143187

arch/powerpc/kernel/fadump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ void crash_fadump(struct pt_regs *regs, const char *str)
728728
* If we came in via system reset, wait a while for the secondary
729729
* CPUs to enter.
730730
*/
731-
if (TRAP(&(fdh->regs)) == 0x100) {
731+
if (TRAP(&(fdh->regs)) == INTERRUPT_SYSTEM_RESET) {
732732
msecs = CRASH_TIMEOUT;
733733
while ((atomic_read(&cpus_in_fadump) < ncpus) && (--msecs > 0))
734734
mdelay(1);

arch/powerpc/kernel/interrupt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsign
447447
* CT_WARN_ON comes here via program_check_exception,
448448
* so avoid recursion.
449449
*/
450-
if (TRAP(regs) != 0x700)
450+
if (TRAP(regs) != INTERRUPT_PROGRAM)
451451
CT_WARN_ON(ct_state() == CONTEXT_USER);
452452

453453
kuap = kuap_get_and_assert_locked();

arch/powerpc/kernel/process.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,9 @@ static void __show_regs(struct pt_regs *regs)
14671467
trap = TRAP(regs);
14681468
if (!trap_is_syscall(regs) && cpu_has_feature(CPU_FTR_CFAR))
14691469
pr_cont("CFAR: "REG" ", regs->orig_gpr3);
1470-
if (trap == 0x200 || trap == 0x300 || trap == 0x600) {
1470+
if (trap == INTERRUPT_MACHINE_CHECK ||
1471+
trap == INTERRUPT_DATA_STORAGE ||
1472+
trap == INTERRUPT_ALIGNMENT) {
14711473
if (IS_ENABLED(CONFIG_4xx) || IS_ENABLED(CONFIG_BOOKE))
14721474
pr_cont("DEAR: "REG" ESR: "REG" ", regs->dar, regs->dsisr);
14731475
else

arch/powerpc/kernel/traps.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static void oops_end(unsigned long flags, struct pt_regs *regs,
221221
/*
222222
* system_reset_excption handles debugger, crash dump, panic, for 0x100
223223
*/
224-
if (TRAP(regs) == 0x100)
224+
if (TRAP(regs) == INTERRUPT_SYSTEM_RESET)
225225
return;
226226

227227
crash_fadump(regs, "die oops");
@@ -289,7 +289,7 @@ void die(const char *str, struct pt_regs *regs, long err)
289289
/*
290290
* system_reset_excption handles debugger, crash dump, panic, for 0x100
291291
*/
292-
if (TRAP(regs) != 0x100) {
292+
if (TRAP(regs) != INTERRUPT_SYSTEM_RESET) {
293293
if (debugger(regs))
294294
return;
295295
}
@@ -1691,7 +1691,7 @@ DEFINE_INTERRUPT_HANDLER(facility_unavailable_exception)
16911691
u8 status;
16921692
bool hv;
16931693

1694-
hv = (TRAP(regs) == 0xf80);
1694+
hv = (TRAP(regs) == INTERRUPT_H_FAC_UNAVAIL);
16951695
if (hv)
16961696
value = mfspr(SPRN_HFSCR);
16971697
else

arch/powerpc/kexec/crash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <asm/smp.h>
2525
#include <asm/setjmp.h>
2626
#include <asm/debug.h>
27+
#include <asm/interrupt.h>
2728

2829
/*
2930
* The primary CPU waits a while for all secondary CPUs to enter. This is to
@@ -336,7 +337,7 @@ void default_machine_crash_shutdown(struct pt_regs *regs)
336337
* If we came in via system reset, wait a while for the secondary
337338
* CPUs to enter.
338339
*/
339-
if (TRAP(regs) == 0x100)
340+
if (TRAP(regs) == INTERRUPT_SYSTEM_RESET)
340341
mdelay(PRIMARY_TIMEOUT);
341342

342343
crash_kexec_prepare_cpus(crashing_cpu);

arch/powerpc/mm/book3s64/hash_utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ unsigned int hash_page_do_lazy_icache(unsigned int pp, pte_t pte, int trap)
11561156

11571157
/* page is dirty */
11581158
if (!test_bit(PG_dcache_clean, &page->flags) && !PageReserved(page)) {
1159-
if (trap == 0x400) {
1159+
if (trap == INTERRUPT_INST_STORAGE) {
11601160
flush_dcache_icache_page(page);
11611161
set_bit(PG_dcache_clean, &page->flags);
11621162
} else
@@ -1556,7 +1556,7 @@ DEFINE_INTERRUPT_HANDLER_RET(__do_hash_fault)
15561556
if (user_mode(regs) || (region_id == USER_REGION_ID))
15571557
access &= ~_PAGE_PRIVILEGED;
15581558

1559-
if (TRAP(regs) == 0x400)
1559+
if (TRAP(regs) == INTERRUPT_INST_STORAGE)
15601560
access |= _PAGE_EXEC;
15611561

15621562
err = hash_page_mm(mm, ea, access, TRAP(regs), flags);

arch/powerpc/mm/fault.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static int mm_fault_error(struct pt_regs *regs, unsigned long addr,
197197
static bool bad_kernel_fault(struct pt_regs *regs, unsigned long error_code,
198198
unsigned long address, bool is_write)
199199
{
200-
int is_exec = TRAP(regs) == 0x400;
200+
int is_exec = TRAP(regs) == INTERRUPT_INST_STORAGE;
201201

202202
/* NX faults set DSISR_PROTFAULT on the 8xx, DSISR_NOEXEC_OR_G on others */
203203
if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT |
@@ -391,7 +391,7 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address,
391391
struct vm_area_struct * vma;
392392
struct mm_struct *mm = current->mm;
393393
unsigned int flags = FAULT_FLAG_DEFAULT;
394-
int is_exec = TRAP(regs) == 0x400;
394+
int is_exec = TRAP(regs) == INTERRUPT_INST_STORAGE;
395395
int is_user = user_mode(regs);
396396
int is_write = page_fault_is_write(error_code);
397397
vm_fault_t fault, major = 0;
@@ -574,20 +574,20 @@ static void __bad_page_fault(struct pt_regs *regs, int sig)
574574
/* kernel has accessed a bad area */
575575

576576
switch (TRAP(regs)) {
577-
case 0x300:
578-
case 0x380:
579-
case 0xe00:
577+
case INTERRUPT_DATA_STORAGE:
578+
case INTERRUPT_DATA_SEGMENT:
579+
case INTERRUPT_H_DATA_STORAGE:
580580
pr_alert("BUG: %s on %s at 0x%08lx\n",
581581
regs->dar < PAGE_SIZE ? "Kernel NULL pointer dereference" :
582582
"Unable to handle kernel data access",
583583
is_write ? "write" : "read", regs->dar);
584584
break;
585-
case 0x400:
586-
case 0x480:
585+
case INTERRUPT_INST_STORAGE:
586+
case INTERRUPT_INST_SEGMENT:
587587
pr_alert("BUG: Unable to handle kernel instruction fetch%s",
588588
regs->nip < PAGE_SIZE ? " (NULL pointer?)\n" : "\n");
589589
break;
590-
case 0x600:
590+
case INTERRUPT_ALIGNMENT:
591591
pr_alert("BUG: Unable to handle kernel unaligned access at 0x%08lx\n",
592592
regs->dar);
593593
break;

arch/powerpc/perf/core-book3s.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <asm/firmware.h>
1818
#include <asm/ptrace.h>
1919
#include <asm/code-patching.h>
20+
#include <asm/interrupt.h>
2021

2122
#ifdef CONFIG_PPC64
2223
#include "internal.h"
@@ -168,7 +169,7 @@ static bool regs_use_siar(struct pt_regs *regs)
168169
* they have not been setup using perf_read_regs() and so regs->result
169170
* is something random.
170171
*/
171-
return ((TRAP(regs) == 0xf00) && regs->result);
172+
return ((TRAP(regs) == INTERRUPT_PERFMON) && regs->result);
172173
}
173174

174175
/*
@@ -347,7 +348,7 @@ static inline void perf_read_regs(struct pt_regs *regs)
347348
* hypervisor samples as well as samples in the kernel with
348349
* interrupts off hence the userspace check.
349350
*/
350-
if (TRAP(regs) != 0xf00)
351+
if (TRAP(regs) != INTERRUPT_PERFMON)
351352
use_siar = 0;
352353
else if ((ppmu->flags & PPMU_NO_SIAR))
353354
use_siar = 0;

arch/powerpc/xmon/xmon.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <asm/code-patching.h>
5555
#include <asm/sections.h>
5656
#include <asm/inst.h>
57+
#include <asm/interrupt.h>
5758

5859
#ifdef CONFIG_PPC64
5960
#include <asm/hvcall.h>
@@ -605,7 +606,7 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
605606
* debugger break (IPI). This is similar to
606607
* crash_kexec_secondary().
607608
*/
608-
if (TRAP(regs) != 0x100 || !wait_for_other_cpus(ncpus))
609+
if (TRAP(regs) != INTERRUPT_SYSTEM_RESET || !wait_for_other_cpus(ncpus))
609610
smp_send_debugger_break();
610611

611612
wait_for_other_cpus(ncpus);
@@ -615,7 +616,7 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
615616

616617
if (!locked_down) {
617618
/* for breakpoint or single step, print curr insn */
618-
if (bp || TRAP(regs) == 0xd00)
619+
if (bp || TRAP(regs) == INTERRUPT_TRACE)
619620
ppc_inst_dump(regs->nip, 1, 0);
620621
printf("enter ? for help\n");
621622
}
@@ -684,7 +685,7 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
684685
disable_surveillance();
685686
if (!locked_down) {
686687
/* for breakpoint or single step, print current insn */
687-
if (bp || TRAP(regs) == 0xd00)
688+
if (bp || TRAP(regs) == INTERRUPT_TRACE)
688689
ppc_inst_dump(regs->nip, 1, 0);
689690
printf("enter ? for help\n");
690691
}
@@ -1769,9 +1770,12 @@ static void excprint(struct pt_regs *fp)
17691770
printf(" sp: %lx\n", fp->gpr[1]);
17701771
printf(" msr: %lx\n", fp->msr);
17711772

1772-
if (trap == 0x300 || trap == 0x380 || trap == 0x600 || trap == 0x200) {
1773+
if (trap == INTERRUPT_DATA_STORAGE ||
1774+
trap == INTERRUPT_DATA_SEGMENT ||
1775+
trap == INTERRUPT_ALIGNMENT ||
1776+
trap == INTERRUPT_MACHINE_CHECK) {
17731777
printf(" dar: %lx\n", fp->dar);
1774-
if (trap != 0x380)
1778+
if (trap != INTERRUPT_DATA_SEGMENT)
17751779
printf(" dsisr: %lx\n", fp->dsisr);
17761780
}
17771781

@@ -1785,7 +1789,7 @@ static void excprint(struct pt_regs *fp)
17851789
current->pid, current->comm);
17861790
}
17871791

1788-
if (trap == 0x700)
1792+
if (trap == INTERRUPT_PROGRAM)
17891793
print_bug_trap(fp);
17901794

17911795
printf(linux_banner);
@@ -1837,7 +1841,9 @@ static void prregs(struct pt_regs *fp)
18371841
printf("ctr = "REG" xer = "REG" trap = %4lx\n",
18381842
fp->ctr, fp->xer, fp->trap);
18391843
trap = TRAP(fp);
1840-
if (trap == 0x300 || trap == 0x380 || trap == 0x600)
1844+
if (trap == INTERRUPT_DATA_STORAGE ||
1845+
trap == INTERRUPT_DATA_SEGMENT ||
1846+
trap == INTERRUPT_ALIGNMENT)
18411847
printf("dar = "REG" dsisr = %.8lx\n", fp->dar, fp->dsisr);
18421848
}
18431849

0 commit comments

Comments
 (0)