Skip to content

Commit 7c151d3

Browse files
author
Markos Chandras
committed
MIPS: Make use of the ERETNC instruction on MIPS R6
The ERETNC instruction, introduced in MIPS R5, is similar to the ERET one, except it does not clear the LLB bit in the LLADDR register. This feature is necessary to safely emulate R2 LL/SC instructions. However, on context switches, we need to clear the LLAddr/LLB bit in order to make sure that an SC instruction from the new thread will never succeed if it happens to interrupt an LL operation on the same address from the previous thread. Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
1 parent b0a668f commit 7c151d3

5 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎arch/mips/include/asm/switch_to.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ do { \
7575
#endif
7676

7777
#define __clear_software_ll_bit() \
78-
do { \
79-
if (!__builtin_constant_p(cpu_has_llsc) || !cpu_has_llsc) \
80-
ll_bit = 0; \
78+
do { if (cpu_has_rw_llb) { \
79+
write_c0_lladdr(0); \
80+
} else { \
81+
if (!__builtin_constant_p(cpu_has_llsc) || !cpu_has_llsc)\
82+
ll_bit = 0; \
83+
} \
8184
} while (0)
8285

8386
#define switch_to(prev, next, last) \

‎arch/mips/include/asm/thread_info.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct thread_info {
2828
unsigned long tp_value; /* thread pointer */
2929
__u32 cpu; /* current CPU */
3030
int preempt_count; /* 0 => preemptable, <0 => BUG */
31-
31+
int r2_emul_return; /* 1 => Returning from R2 emulator */
3232
mm_segment_t addr_limit; /*
3333
* thread address space limit:
3434
* 0x7fffffff for user-thead

‎arch/mips/kernel/asm-offsets.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void output_thread_info_defines(void)
9797
OFFSET(TI_TP_VALUE, thread_info, tp_value);
9898
OFFSET(TI_CPU, thread_info, cpu);
9999
OFFSET(TI_PRE_COUNT, thread_info, preempt_count);
100+
OFFSET(TI_R2_EMUL_RET, thread_info, r2_emul_return);
100101
OFFSET(TI_ADDR_LIMIT, thread_info, addr_limit);
101102
OFFSET(TI_RESTART_BLOCK, thread_info, restart_block);
102103
OFFSET(TI_REGS, thread_info, regs);

‎arch/mips/kernel/entry.S‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ resume_userspace:
4646
local_irq_disable # make sure we dont miss an
4747
# interrupt setting need_resched
4848
# between sampling and return
49+
#ifdef CONFIG_MIPSR2_TO_R6_EMULATOR
50+
lw k0, TI_R2_EMUL_RET($28)
51+
bnez k0, restore_all_from_r2_emul
52+
#endif
53+
4954
LONG_L a2, TI_FLAGS($28) # current->work
5055
andi t0, a2, _TIF_WORK_MASK # (ignoring syscall_trace)
5156
bnez t0, work_pending
@@ -114,6 +119,19 @@ restore_partial: # restore partial frame
114119
RESTORE_SP_AND_RET
115120
.set at
116121

122+
#ifdef CONFIG_MIPSR2_TO_R6_EMULATOR
123+
restore_all_from_r2_emul: # restore full frame
124+
.set noat
125+
sw zero, TI_R2_EMUL_RET($28) # reset it
126+
RESTORE_TEMP
127+
RESTORE_AT
128+
RESTORE_STATIC
129+
RESTORE_SOME
130+
LONG_L sp, PT_R29(sp)
131+
eretnc
132+
.set at
133+
#endif
134+
117135
work_pending:
118136
andi t0, a2, _TIF_NEED_RESCHED # a2 is preloaded with TI_FLAGS
119137
beqz t0, work_notifysig

‎arch/mips/kernel/traps.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,12 +1039,14 @@ asmlinkage void do_ri(struct pt_regs *regs)
10391039
switch (status) {
10401040
case 0:
10411041
case SIGEMT:
1042+
task_thread_info(current)->r2_emul_return = 1;
10421043
return;
10431044
case SIGILL:
10441045
goto no_r2_instr;
10451046
default:
10461047
process_fpemu_return(status,
10471048
&current->thread.cp0_baduaddr);
1049+
task_thread_info(current)->r2_emul_return = 1;
10481050
return;
10491051
}
10501052
}

0 commit comments

Comments
 (0)