Skip to content

Commit

Permalink
ARC: pt_regs: create seperate type for ecr
Browse files Browse the repository at this point in the history
Reduces duplication in each ISA specific pt_regs

Tested-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202308151342.ROQ9Urvv-lkp@intel.com
Signed-off-by: Vineet Gupta <vgupta@kernel.org>
  • Loading branch information
Vineet Gupta committed Aug 18, 2023
1 parent d4624bf commit 58d9ceb
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 45 deletions.
47 changes: 18 additions & 29 deletions arch/arc/include/asm/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

#ifndef __ASSEMBLY__

typedef union {
struct {
#ifdef CONFIG_CPU_BIG_ENDIAN
unsigned long state:8, vec:8, cause:8, param:8;
#else
unsigned long param:8, cause:8, vec:8, state:8;
#endif
};
unsigned long full;
} ecr_reg;

/* THE pt_regs: Defines how regs are saved during entry into kernel */

#ifdef CONFIG_ISA_ARCOMPACT
Expand Down Expand Up @@ -40,40 +51,18 @@ struct pt_regs {
* Last word used by Linux for extra state mgmt (syscall-restart)
* For interrupts, use artificial ECR values to note current prio-level
*/
union {
struct {
#ifdef CONFIG_CPU_BIG_ENDIAN
unsigned long state:8, ecr_vec:8,
ecr_cause:8, ecr_param:8;
#else
unsigned long ecr_param:8, ecr_cause:8,
ecr_vec:8, state:8;
#endif
};
unsigned long event;
};
ecr_reg ecr;
};

#define MAX_REG_OFFSET offsetof(struct pt_regs, event)
#define MAX_REG_OFFSET offsetof(struct pt_regs, ecr)

#else

struct pt_regs {

unsigned long orig_r0;

union {
struct {
#ifdef CONFIG_CPU_BIG_ENDIAN
unsigned long state:8, ecr_vec:8,
ecr_cause:8, ecr_param:8;
#else
unsigned long ecr_param:8, ecr_cause:8,
ecr_vec:8, state:8;
#endif
};
unsigned long event;
};
ecr_reg ecr; /* Exception Cause Reg */

unsigned long bta; /* erbta */

Expand Down Expand Up @@ -131,13 +120,13 @@ struct callee_regs {
/* return 1 if PC in delay slot */
#define delay_mode(regs) ((regs->status32 & STATUS_DE_MASK) == STATUS_DE_MASK)

#define in_syscall(regs) ((regs->ecr_vec == ECR_V_TRAP) && !regs->ecr_param)
#define in_brkpt_trap(regs) ((regs->ecr_vec == ECR_V_TRAP) && regs->ecr_param)
#define in_syscall(regs) ((regs->ecr.vec == ECR_V_TRAP) && !regs->ecr.param)
#define in_brkpt_trap(regs) ((regs->ecr.vec == ECR_V_TRAP) && regs->ecr.param)

#define STATE_SCALL_RESTARTED 0x01

#define syscall_wont_restart(reg) (reg->state |= STATE_SCALL_RESTARTED)
#define syscall_restartable(reg) !(reg->state & STATE_SCALL_RESTARTED)
#define syscall_wont_restart(regs) (regs->ecr.state |= STATE_SCALL_RESTARTED)
#define syscall_restartable(regs) !(regs->ecr.state & STATE_SCALL_RESTARTED)

#define current_pt_regs() \
({ \
Expand Down
2 changes: 1 addition & 1 deletion arch/arc/kernel/asm-offsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(void)
BLANK();

DEFINE(PT_status32, offsetof(struct pt_regs, status32));
DEFINE(PT_event, offsetof(struct pt_regs, event));
DEFINE(PT_event, offsetof(struct pt_regs, ecr));
DEFINE(PT_bta, offsetof(struct pt_regs, bta));
DEFINE(PT_sp, offsetof(struct pt_regs, sp));
DEFINE(PT_r0, offsetof(struct pt_regs, r0));
Expand Down
2 changes: 1 addition & 1 deletion arch/arc/kernel/kgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void kgdb_trap(struct pt_regs *regs)
* with trap_s 4 (compiled) breakpoints, continuation needs to
* start after the breakpoint.
*/
if (regs->ecr_param == 3)
if (regs->ecr.param == 3)
instruction_pointer(regs) -= BREAK_INSTR_SIZE;

kgdb_handle_exception(1, SIGTRAP, 0, regs);
Expand Down
4 changes: 2 additions & 2 deletions arch/arc/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ static const struct pt_regs_offset regoffset_table[] = {
REG_OFFSET_NAME(r0),
REG_OFFSET_NAME(sp),
REG_OFFSET_NAME(orig_r0),
REG_OFFSET_NAME(event),
REG_OFFSET_NAME(ecr),
REG_OFFSET_END,
};

#else

static const struct pt_regs_offset regoffset_table[] = {
REG_OFFSET_NAME(orig_r0),
REG_OFFSET_NAME(event),
REG_OFFSET_NAME(ecr),
REG_OFFSET_NAME(bta),
REG_OFFSET_NAME(r26),
REG_OFFSET_NAME(fp),
Expand Down
4 changes: 1 addition & 3 deletions arch/arc/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ void do_machine_check_fault(unsigned long address, struct pt_regs *regs)
*/
void do_non_swi_trap(unsigned long address, struct pt_regs *regs)
{
unsigned int param = regs->ecr_param;

switch (param) {
switch (regs->ecr.param) {
case 1:
trap_is_brkpt(address, regs);
break;
Expand Down
13 changes: 7 additions & 6 deletions arch/arc/kernel/troubleshoot.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ static void show_ecr_verbose(struct pt_regs *regs)
/* For Data fault, this is data address not instruction addr */
address = current->thread.fault_address;

vec = regs->ecr_vec;
cause_code = regs->ecr_cause;
vec = regs->ecr.vec;
cause_code = regs->ecr.cause;

/* For DTLB Miss or ProtV, display the memory involved too */
if (vec == ECR_V_DTLB_MISS) {
Expand Down Expand Up @@ -154,7 +154,7 @@ static void show_ecr_verbose(struct pt_regs *regs)
pr_cont("Misaligned r/w from 0x%08lx\n", address);
#endif
} else if (vec == ECR_V_TRAP) {
if (regs->ecr_param == 5)
if (regs->ecr.param == 5)
pr_cont("gcc generated __builtin_trap\n");
} else {
pr_cont("Check Programmer's Manual\n");
Expand Down Expand Up @@ -184,9 +184,10 @@ void show_regs(struct pt_regs *regs)
if (user_mode(regs))
show_faulting_vma(regs->ret); /* faulting code, not data */

pr_info("ECR: 0x%08lx EFA: 0x%08lx ERET: 0x%08lx\nSTAT: 0x%08lx",
regs->event, current->thread.fault_address, regs->ret,
regs->status32);
pr_info("ECR: 0x%08lx EFA: 0x%08lx ERET: 0x%08lx\n",
regs->ecr.full, current->thread.fault_address, regs->ret);

pr_info("STAT32: 0x%08lx", regs->status32);

#define STS_BIT(r, bit) r->status32 & STATUS_##bit##_MASK ? #bit" " : ""

Expand Down
6 changes: 3 additions & 3 deletions arch/arc/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ void do_page_fault(unsigned long address, struct pt_regs *regs)
if (faulthandler_disabled() || !mm)
goto no_context;

if (regs->ecr_cause & ECR_C_PROTV_STORE) /* ST/EX */
if (regs->ecr.cause & ECR_C_PROTV_STORE) /* ST/EX */
write = 1;
else if ((regs->ecr_vec == ECR_V_PROTV) &&
(regs->ecr_cause == ECR_C_PROTV_INST_FETCH))
else if ((regs->ecr.vec == ECR_V_PROTV) &&
(regs->ecr.cause == ECR_C_PROTV_INST_FETCH))
exec = 1;

flags = FAULT_FLAG_DEFAULT;
Expand Down

0 comments on commit 58d9ceb

Please sign in to comment.