Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARCv2: entry: push out the Z flag unclobber from common EXCEPTION_PROLOGUE

Upon a taken interrupt/exception from User mode, HS hardware auto sets Z flag.
This helps shave a few instructions from EXCEPTION_PROLOGUE by eliding
re-reading ERSTATUS and some bit fiddling.

However TLB Miss Exception handler can clobber the CPU flags and still end
up in EXCEPTION_PROLOGUE in the slow path handling TLB handling case:

EV_TLBMissD
do_slow_path_pf
EV_TLBProtV (aliased to call_do_page_fault)
EXCEPTION_PROLOGUE

As a result, EXCEPTION_PROLOGUE need to "unclobber" the Z flag which this
patch changes. It is now pushed out to TLB Miss Exception handler.
The reasons beings:

- The flag restoration is only needed for slowpath TLB Miss Exception
handling, but currently being in EXCEPTION_PROLOGUE penalizes all
exceptions such as ProtV and syscall Trap, where Z flag is already
as expected.

- Pushing unclobber out to where it was clobbered is much cleaner and
also serves to document the fact.

- Makes EXCEPTION_PROLGUE similar to INTERRUPT_PROLOGUE so easier to
refactor the common parts which is what this series aims to do

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>

+11 -8
-8
arch/arc/include/asm/entry-arcv2.h
··· 225 225 226 226 ; -- for interrupts, regs above are auto-saved by h/w in that order -- 227 227 ; Now do what ISR prologue does (manually save r12, sp, fp, gp, r25) 228 - ; 229 - ; Set Z flag if this was from U mode (expected by INTERRUPT_PROLOGUE) 230 - ; Although H/w exception micro-ops do set Z flag for U mode (just like 231 - ; for interrupts), it could get clobbered in case we soft land here from 232 - ; a TLB Miss exception handler (tlbex.S) 233 - 234 - and r10, r10, STATUS_U_MASK 235 - xor.f 0, r10, STATUS_U_MASK 236 228 237 229 INTERRUPT_PROLOGUE exception 238 230
+11
arch/arc/mm/tlbex.S
··· 393 393 ;-------- Common routine to call Linux Page Fault Handler ----------- 394 394 do_slow_path_pf: 395 395 396 + #ifdef CONFIG_ISA_ARCV2 397 + ; Set Z flag if exception in U mode. Hardware micro-ops do this on any 398 + ; taken interrupt/exception, and thus is already the case at the entry 399 + ; above, but ensuing code would have already clobbered. 400 + ; EXCEPTION_PROLOGUE called in slow path, relies on correct Z flag set 401 + 402 + lr r2, [erstatus] 403 + and r2, r2, STATUS_U_MASK 404 + bxor.f 0, r2, STATUS_U_BIT 405 + #endif 406 + 396 407 ; Restore the 4-scratch regs saved by fast path miss handler 397 408 TLBMISS_RESTORE_REGS 398 409