[PATCH 5/5] riscv: vdso: Implement __vdso_futex_robust_try_unlock()

Nam Cao namcao at linutronix.de
Wed Jul 8 13:46:34 PDT 2026


Nam Cao <namcao at linutronix.de> writes:
> André Almeida <andrealmeid at igalia.com> writes:
>> So if the build has support for CAS, the function overwrite what it had 
>> just set. Why do it even writes it in the first place then, can't this 
>> be an if/else?
>
> Functionally speaking, an if/else makes more sense. However, I cannot
> figure out how to do that without creating a complete mess, since
> *_try_unlock_cs_cas_start and *_try_unlock_cs_cas_end are not always
> available. If you have a suggestion, please do let me know. But doing
> it this way only costs us a few more instructions.

Look at this again, we can do something like below. Let me send v3.

#if defined(CONFIG_RISCV_ISA_ZACAS) && defined(CONFIG_TOOLCHAIN_HAS_ZACAS)
#define FUTEX_CAS_SET_VDSO_CS_RANGE(vdso, fd, idx, xlen, symbol)                                \
{                                                                                               \
        void *start = symbol(vdso, CONCAT3(futex_list, xlen, _try_unlock_cs_cas_start));        \
        void *end   = symbol(vdso, CONCAT3(futex_list, xlen, _try_unlock_cs_cas_end));          \
                                                                                                \
        futex_set_vdso_cs_range(fd, idx, (uintptr_t)start, (uintptr_t)end, xlen == 32);         \
}
#else
#define FUTEX_CAS_SET_VDSO_CS_RANGE(...) BUILD_BUG()
#endif

#define FUTEX_LRSC_SET_VDSO_CS_RANGE(vdso, fd, idx, xlen, symbol)                               \
{                                                                                              \
        void *start = symbol(vdso, CONCAT3(futex_list, xlen, _try_unlock_cs_lrsc_start));       \
        void *end   = symbol(vdso, CONCAT3(futex_list, xlen, _try_unlock_cs_lrsc_end));         \
                                                                                                \
        futex_set_vdso_cs_range(fd, idx, (uintptr_t)start, (uintptr_t)end, xlen == 32);         \
}

#define FUTEX_SET_VDSO_CS_RANGE(vdso, fd, idx, xlen, symbol)                                    \
{                                                                                               \
        if (cpu_supports_zacas()) {                                                             \
                FUTEX_CAS_SET_VDSO_CS_RANGE(vdso, fd, idx, xlen, symbol);                       \
        } else {                                                                                \
                FUTEX_LRSC_SET_VDSO_CS_RANGE(vdso, fd, idx, xlen, symbol);                      \
        }                                                                                       \
}



More information about the linux-riscv mailing list