Re: [PATCH v3 2/5] arm64: vdso: Implement __vdso_futex_robust_try_unlock()

From: André Almeida

Date: Mon Jun 01 2026 - 12:33:59 EST


Em 29/05/2026 14:47, Mathieu Desnoyers escreveu:
On 2026-05-29 12:33, André Almeida wrote:
Based on the x86 implementation, implement the vDSO function for unlocking
a robust futex correctly.

Commit xxxxxxxxxxxx ("x86/vdso: Implement __vdso_futex_robust_try_unlock()") has
the full explanation about why this mechanism is needed.

The unlock assembly sequence for arm64 is:

    __vdso_futex_robust_list64_try_unlock:
    retry:
        ldxr    w8, [x0] // Load the value from *futex
        cmp    w1, w8   // Compare with TID
        b.ne    __vdso_futex_list64_try_unlock_cs_end
        stlxr    w9, wzr, [x0] // Try to zero *futex

So it looks like stlxr can be successful, and the process is killed
right here. This is not within the start/end critical section, so the
fixup is missed ? Or am I missing something ?


As me and Mathieu discussed on IRC, this should be the right thing to do here:

- Move the critical section label one instruction above to include `cbnz` on it
- Use the result register as the check for the store success, not the zero flag register.

So it will look like this:

__vdso_futex_robust_list64_try_unlock:
retry:
ldxr w8, [x0] // Load the value from *futex
cmp w1, w8 // Compare with TID
b.ne __vdso_futex_list64_try_unlock_cs_end
stlxr w9, wzr, [x0] // Try to zero *futex
__vdso_futex_list64_try_unlock_cs_start:
cbnz w9, retry
str xzr, [x2] // After zeroing *futex, zero *op_pending
__vdso_futex_list64_try_unlock_cs_end>:

The decision regarding if the pointer should be cleared or not lies on checking the result register:

return (regs->user_regs[9]) ? NULL :
(void __user *) regs->user_regs.regs[2];

Thanks for the review!