parisc: Rewrite light-weight syscall and futex code
PATCH RESEND 1/1 parisc: Rewrite light-weight syscall and futex code
The parisc architecture lacks general hardware support for compare and swap. Particularly for userspace, it is difficult to implement software atomic support. Page faults in critical regions can cause processes to sleep and block the forward progress of other processes. Thus, it is essential that page faults be disabled in critical regions. For performance reasons, we also need to disable external interrupts in critical regions.
In order to do this, we need a mechanism to trigger COW breaks outside the critical region. Fortunately, parisc has the "stbys,e" instruction. When the leftmost byte of a word is addressed, this instruction triggers all the exceptions of a normal store but it does not write to memory. Thus, we can use it to trigger COW breaks outside the critical region without modifying the data that is to be updated atomically.
COW breaks occur randomly. So even if we have priviously executed a "stbys,e" instruction, we still need to disable pagefaults around the critical region. If a fault occurs in the critical region, we return -EAGAIN. I had to add a wrapper around _arch_futex_atomic_op_inuser() as I found in testing that returning -EAGAIN caused problems for some processes even though it is listed as a possible return value.
The patch implements the above. The code no longer attempts to sleep with interrupts disabled and I haven't seen any stalls with the change.
I have attempted to merge common code and streamline the fast path. In the futex code, we only compute the spinlock address once.
I eliminated some debug code in the original CAS routine that just made the flow more complicated.
I have added two new LWS routines - lws_atomic_xchg and lws_atomic_store. These are simpler than the CAS operations. Currently, we use the CAS operations for atomic stores. This is inefficient.
I don't clip the arguments when called from wide mode. As a result, the LWS routines should work when called from 64-bit processes.
I fixed a couple of bugs. The completer in the "or,ev %r1,%r30,%r30" was reversed, so we were
not clipping the LWS number. The spinlock index was also computed incorrectly in the futex code. The mask "0x3f8" only selected seven bits.
I defined a new depi_safe macro. The depi instruction suffers from same issue as extru. There are probably more places where it could be used.
I defined TASK_PAGEFAULT_DISABLED offset for use in the lws_pagefault_disable and lws_pagefault_enable macros.
I modified the code in handle_interruption() so faulthandler_disabled() is only called once. Maybe do_page_fault() can now be optimized.
Since we now disable interrupts on the gateway page where necessary, it might be possible to allow processes to be scheduled when they are on the gateway page.
Change has been tested on c8000 and rp3440.
---
arch/parisc/include/asm/assembly.h +10 -0
@@ -158,6 +158,16 @@#endif .endm +/* The depi instruction leaves the most significant 32 bits of the +* target register in an undefined state on PA 2.0 systems. */ + .macro depi_safe i, p, len, t +#ifdef CONFIG_64BIT + depdi \i, 32+(\p), \len, \t +#else + depi \i, \p, \len, \t +#endif + .endm +/* load 32-bit 'value' into 'reg' compensating for the ldil * sign-extension when running in wide mode. * WARNING!! neither 'value' nor 'reg' can be expressions
arch/parisc/include/asm/futex.h +77 -24
163 lines not on this page · raw message
arch/parisc/kernel/asm-offsets.c +1 -0
@@ -37,6 +37,7 @@ int main(void) { DEFINE(TASK_TI_FLAGS, offsetof(struct task_struct, thread_info.flags));DEFINE (TASK_STACK , offsetof(struct task_struct , stack)); +DEFINE (TASK_PAGEFAULT_DISABLED , offsetof(struct task_struct , pagefault_disabled));BLANK (); DEFINE(TASK_REGS, offsetof(struct task_struct, thread.regs)); DEFINE(TASK_PT_PSW, offsetof(struct task_struct, thread.regs.gr[ 0]));
arch/parisc/kernel/syscall.S +582 -192
968 lines not on this page · raw message
arch/parisc/kernel/traps.c +1 -1
@@ -783,7 +783,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)* unless pagefault_disable() was called before. */ -if (fault_space ==0 && !faulthandler_disabled ()) +if (faulthandler_disabled () || fault_space ==0 ) {/* Clean up and return if in exception table. */ if (fixup_exception (regs))