[PW_SID:1129401] riscv: vdso: Implement __vdso_futex_robust_try_unlock()#2303
[PW_SID:1129401] riscv: vdso: Implement __vdso_futex_robust_try_unlock()#2303linux-riscv-bot wants to merge 6 commits into
Conversation
The compat_vdso Makefile has a custom build rule for *.S files. This is unnecessary, and makes it hard to extend this Makefile to support building *.c files. Switch to standard kbuild rule instead. Signed-off-by: Nam Cao <namcao@linutronix.de> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Extend to support building *.c files. This allows adding futex.c in a follow-up commit. Signed-off-by: Nam Cao <namcao@linutronix.de> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
The -march option is inside COMPAT_CC_FLAGS, making it difficult to extend. Introduce COMPAT_MARCH variable to allow extension. A follow-up commit will take advantage of this to add _zacas to -march. Signed-off-by: Nam Cao <namcao@linutronix.de> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
The compat vdso Makefile does not enable zacas, disallowing source files from using zacas instructions. This is an obstacle to adding robust __vdso_futex_robust_list32_try_unlock() in a follow-up commit. Build with zacas, if compiler supports it. Signed-off-by: Nam Cao <namcao@linutronix.de> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
This is the RISC-V port for __vdso_futex_robust_try_unlock(). It is based on the x86's implementation in commit 61cfc8e ("x86/vdso: Prepare for robust futex unlock support") and commit a2274cc ("x86/vdso: Implement __vdso_futex_robust_try_unlock()"). When the FUTEX_ROBUST_UNLOCK mechanism is used for unlocking (PI-)futexes, the unlock sequence in userspace looks like this: 1) robust_list_set_op_pending(mutex); 2) robust_list_remove(mutex); lval = gettid(); 3) if (atomic_try_cmpxchg(&mutex->lock, lval, 0)) 4) robust_list_clear_op_pending(); else 5) sys_futex(OP,...FUTEX_ROBUST_UNLOCK); That still leaves a minimal race window between #3 and #4 where the mutex could be acquired by some other task which observes that it is the last user and: 1) unmaps the mutex memory 2) maps a different file, which ends up covering the same address When then the original task exits before reaching #4 then the kernel robust list handling observes the pending op entry and tries to fix up user space. In case that the newly mapped data contains the TID of the exiting thread at the address of the mutex/futex the kernel will set the owner died bit in that memory and therefore corrupt unrelated data. Provide a VDSO function which exposes the critical section window in the VDSO symbol table. The resulting addresses are updated in the task's mm when the VDSO is (re)map()'ed. The core code detects when a task was interrupted within the critical section and is about to deliver a signal. It then invokes an architecture specific function which determines whether the pending op pointer has to be cleared or not. The unlock assembly sequence on 64-bit is: mv a5, a0 ; move LOCK to a5 .Lretry lr.w a0, (a5) ; load *LOCK bne a0, a1, 24 .Lend ; if (*LOCK != TID) then exit sc.w.rl t0, zero, (a5) ; try changing *LOCK from TID to zero .Lstart bnez t0, .Lretry ; retry if store-conditional failed sd zero, 0(a2) ; clear POP .Lend sext.w a0,a0 ret So if the kernel sees that the user task is between .Lstart and .Lend, t0 can be checked to determine if the pending op pointer (POP) should be cleared. When the kernel is built with ZACAS, another unlock assembly sequence is provided using ZACAS instructions. If the CPU supports ZACAS, that alternative sequence is used and the critical section is also changed to that. There are two entry points to handle the different robust list pending op pointer sizes: __vdso_futex_robust_list64_try_unlock() __vdso_futex_robust_list32_try_unlock() The 32-bit VDSO and compat VDSO provides __vdso_futex_robust_list32_try_unlock(). Unlike x86, the RISC-V 64-bit VDSO provides only provides __vdso_futex_robust_list64_try_unlock(). Because RISC-V threads can only have one list_op_pending pointer type. Signed-off-by: Nam Cao <namcao@linutronix.de> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 1: "[v3,1/5] riscv: compat_vdso: switch to standard kbuild rule" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 2: "[v3,2/5] riscv: compat_vdso: Allow *.c source files" |
|
Patch 3: "[v3,3/5] riscv: compat_vdso: Introduce COMPAT_MARCH variable" |
|
Patch 3: "[v3,3/5] riscv: compat_vdso: Introduce COMPAT_MARCH variable" |
|
Patch 3: "[v3,3/5] riscv: compat_vdso: Introduce COMPAT_MARCH variable" |
|
Patch 3: "[v3,3/5] riscv: compat_vdso: Introduce COMPAT_MARCH variable" |
|
Patch 3: "[v3,3/5] riscv: compat_vdso: Introduce COMPAT_MARCH variable" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 4: "[v3,4/5] riscv: compat_vdso: Build with zacas if available" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
|
Patch 5: "[v3,5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()" |
8ca72ef to
60e0882
Compare
PR for series 1129401 applied to workflow__riscv__fixes
Name: riscv: vdso: Implement __vdso_futex_robust_try_unlock()
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1129401
Version: 3