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

From: Thomas Weißschuh

Date: Fri Jul 17 2026 - 08:37:35 EST


On Fri, Jul 17, 2026 at 10:06:38AM +0200, Nam Cao wrote:
(...)

> Signed-off-by: Nam Cao <namcao@xxxxxxxxxxxxx>

One question about the toolchain detection.
With that cleared up:

Reviewed-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>

(Minus the asm bits...)

> ---
> arch/riscv/Kconfig | 1 +
> arch/riscv/include/asm/cpufeature-macros.h | 2 +
> arch/riscv/include/asm/futex_robust.h | 16 +++++
> arch/riscv/include/asm/vdso/futex.h | 14 ++++
> arch/riscv/kernel/compat_vdso/Makefile | 7 +-
> arch/riscv/kernel/compat_vdso/futex.c | 3 +
> arch/riscv/kernel/vdso.c | 61 ++++++++++++++++
> arch/riscv/kernel/vdso/Makefile | 14 +++-
> arch/riscv/kernel/vdso/futex.c | 84 ++++++++++++++++++++++
> arch/riscv/kernel/vdso/vdso.lds.S | 8 +++
> 10 files changed, 208 insertions(+), 2 deletions(-)
> create mode 100644 arch/riscv/include/asm/futex_robust.h
> create mode 100644 arch/riscv/include/asm/vdso/futex.h
> create mode 100644 arch/riscv/kernel/compat_vdso/futex.c
> create mode 100644 arch/riscv/kernel/vdso/futex.c

(...)

> diff --git a/arch/riscv/include/asm/futex_robust.h b/arch/riscv/include/asm/futex_robust.h
> new file mode 100644
> index 000000000000..16ec58e925c8
> --- /dev/null
> +++ b/arch/riscv/include/asm/futex_robust.h
> @@ -0,0 +1,16 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _ASM_RISCV_FUTEX_ROBUST_H
> +#define _ASM_RISCV_FUTEX_ROBUST_H
> +
> +#include <asm/ptrace.h>
> +#include <asm/vdso/futex.h>
> +
> +static inline void __user *arch_futex_robust_unlock_get_pop(struct pt_regs *regs)
> +{
> + if (cpu_supports_zacas())
> + return (regs->a0 == regs->a1) ? (void __user *)regs->a2 : NULL;
> + else
> + return (regs->t0 == 0) ? (void __user *)regs->a2 : NULL;
> +}

Can it ever happen that the toolchain has differing zacas support between
32-bit and 64-bit? Then cpu_supports_zacas() may not be sufficient.
If it is guaranteed to be in sync I would prefer to reuse
CONFIG_TOOLCHAIN_HAS_ZACAS instead of the cc-option check in the Makefile
to make that clear and error out early if it should ever change.

Also this assumes that compat vDSO alternative patching works.
But this is not the case. My series [0] to implement it has not yet been
applied. This revision is missing the note about this dependency.

[0] https://lore.kernel.org/all/20260630-riscv-vdso32-alternative-v1-0-a32fd89b7b1c@xxxxxxxxxxxxx/

> +#endif /* _ASM_RISCV_FUTEX_ROBUST_H */

(...)

> diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile
> index 8dbf2532a573..d4238db8c6d3 100644
> --- a/arch/riscv/kernel/vdso/Makefile
> +++ b/arch/riscv/kernel/vdso/Makefile
> @@ -27,12 +27,24 @@ asflags-y += -DVDSO_CFI=1
> endif
>
> # Files to link into the vdso
> -obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o
> +obj-vdso := $(patsubst %, %.o, $(vdso-syms)) note.o
>
> ifdef CONFIG_VDSO_GETRANDOM
> obj-vdso += vgetrandom-chacha.o
> endif
>
> +ifdef CONFIG_FUTEX_ROBUST_UNLOCK
> +
> +obj-vdso += futex.o
> +
> +ifdef CONFIG_64BIT
> +vdso-syms += __vdso_futex_robust_list64_try_unlock
> +else
> +vdso-syms += __vdso_futex_robust_list32_try_unlock
> +endif

Could be :

vdso-syms += __vdso_futex_robust_list$(BITS)_try_unlock

> +
> +endif
> +
> ccflags-y := -fno-stack-protector
> ccflags-y += -DDISABLE_BRANCH_PROFILING
> ccflags-y += -fno-builtin

(...)