From nobody Mon Jun 8 11:07:05 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C87A63C1F51; Fri, 29 May 2026 16:34:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780072471; cv=none; b=QWby/XSwHHKNemLQ20Xnri1lGRh01pzsObEamRuDjxf7bOpwdyBL9Bz1Fv8rSk827ucil4osSHcRBjX6NfNwrJu5MUBo5AkoFewdLT8/8KIQoEyMCAJM4N7mcX6qItCMPIQh5ZX6l4pkK0upwi9OYdBg34M71yPKy060e9sJE80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780072471; c=relaxed/simple; bh=vt6PYzZrS6xNvfuqRGNOeWxBY6igBNfRwzbaTmk73Sw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j/Y1V/9B3WAPf8MjIv5qGqxg+asxotk3DQeHvZYDd6kARjfPV/z9wlPIzwq7SV4JJ40BLzgYWz9pkK+6/X9gZGbEdSvXv2IUuTr9GbIBS9ZGDSf6S5cdRcut5Zm80q+skdbTq/6nsJ6UEUlfkgDRjbPUkOjj6z4RSMGHhr61+Yw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=e7KKtsEm; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="e7KKtsEm" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8mr+2IKRPq6GxrBU0bB4d+jYOkLg4Nyvmg+o4j1Gky0=; b=e7KKtsEmK5GEgkevjN1/FWqXce yGj4xbuBWq9+dqI1XIuKLDgeZiF1i2vmSoLhaf/YU+NmCaN2XDd4lG4zRFnCD7DlSVFi+ynq5T864 XIU2L088v4xTgHMNiTLMY0gDVIrpHBc3Oog+6pj5GstHSrf+gLmFhUQ7lS3DihtPPqMbGC0jhP2so MTYSFntXkTb5VoymwK+bSyCgD8BH34Z0TMPpvj9c++FO4gvjJS5ET3HJ8LRKOGRErpv9cLs2CKMX5 olZx424AZsob9pw4LPi9/TdL4iZTvqhNsED7mecU/LcA/WvBGwNVMrZDzU/1QqKQTYm0aMzpTH3Ly TL2ld/6g==; Received: from [179.118.191.12] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wT0AB-009wov-4i; Fri, 29 May 2026 18:34:23 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 29 May 2026 13:33:53 -0300 Subject: [PATCH v3 1/5] arm64: vdso: Prepare for robust futex unlock support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260529-tonyk-robust_arm-v3-1-a6f02684d4fe@igalia.com> References: <20260529-tonyk-robust_arm-v3-0-a6f02684d4fe@igalia.com> In-Reply-To: <20260529-tonyk-robust_arm-v3-0-a6f02684d4fe@igalia.com> To: Catalin Marinas , Will Deacon , Thomas Gleixner , Mark Rutland , Mathieu Desnoyers , Sebastian Andrzej Siewior , Carlos O'Donell , Peter Zijlstra , Florian Weimer , Rich Felker , Torvald Riegel , Darren Hart , Ingo Molnar , Davidlohr Bueso , Arnd Bergmann , "Liam R . Howlett" , Uros Bizjak , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-dev@igalia.com, LKML , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 There will be a VDSO function to unlock non-contended robust futexes in user space. The unlock sequence is racy vs. clearing the list_pending_op pointer in the task's robust list head. To plug this race the kernel needs to know the critical section window so it can clear the pointer when the task is interrupted within that race window. The window is determined by labels in the inline assembly. Signed-off-by: Andr=C3=A9 Almeida --- Notes: - The diff futex_set_vdso_cs_range() should happen in the commit that introduced it, and rebase will clear it from here - So far I couldn't figure out why current->rseq.event.user_irq is never s= et in aarch64 v3: - Fix adding vdso base addr twice - Call vdso_futex_robust_unlock_update_ips() on remap as well v2: - Fixed linker not finding VDSO symbols --- arch/arm64/kernel/vdso.c | 25 +++++++++++++++++++++++++ arch/arm64/kernel/vdso/vdso.lds.S | 5 +++++ arch/x86/entry/vdso/vma.c | 4 ++-- include/linux/futex.h | 13 ++----------- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 592dd8668de4..76f22ea8e181 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -57,11 +58,31 @@ static struct vdso_abi_info vdso_info[] __ro_after_init= =3D { #endif /* CONFIG_COMPAT_VDSO */ }; =20 +#ifdef CONFIG_FUTEX_ROBUST_UNLOCK +static void vdso_futex_robust_unlock_update_ips(enum vdso_abi abi, struct = mm_struct *mm) +{ + unsigned long vdso =3D (unsigned long) mm->context.vdso; + struct futex_mm_data *fd =3D &mm->futex; + uintptr_t success, end; + + if (abi =3D=3D VDSO_ABI_AA64) { + success =3D (uintptr_t) VDSO_SYMBOL(vdso, futex_list64_try_unlock_cs_suc= cess); + end =3D (uintptr_t) VDSO_SYMBOL(vdso, futex_list64_try_unlock_cs_end); + + futex_set_vdso_cs_range(fd, 0, success, end, false); + } +} +#else +static inline void vdso_futex_robust_unlock_update_ips(enum vdso_abi abi, = struct mm_struct *mm) { } +#endif /* CONFIG_FUTEX_ROBUST_UNLOCK */ + static int vdso_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *new_vma) { current->mm->context.vdso =3D (void *)new_vma->vm_start; =20 + vdso_futex_robust_unlock_update_ips(VDSO_ABI_AA64, current->mm); + return 0; } =20 @@ -134,6 +155,8 @@ static int __setup_additional_pages(enum vdso_abi abi, if (IS_ERR(ret)) goto up_fail; =20 + vdso_futex_robust_unlock_update_ips(abi, mm); + return 0; =20 up_fail: @@ -159,6 +182,8 @@ static int aarch32_sigpage_mremap(const struct vm_speci= al_mapping *sm, { current->mm->context.sigpage =3D (void *)new_vma->vm_start; =20 + vdso_futex_robust_unlock_update_ips(VDSO_ABI_AA32, current->mm); + return 0; } =20 diff --git a/arch/arm64/kernel/vdso/vdso.lds.S b/arch/arm64/kernel/vdso/vds= o.lds.S index 52314be29191..8633aafe6b81 100644 --- a/arch/arm64/kernel/vdso/vdso.lds.S +++ b/arch/arm64/kernel/vdso/vdso.lds.S @@ -104,6 +104,7 @@ VERSION __kernel_clock_gettime; __kernel_clock_getres; __kernel_getrandom; + __vdso_futex_robust_list64_try_unlock; local: *; }; } @@ -112,3 +113,7 @@ VERSION * Make the sigreturn code visible to the kernel. */ VDSO_sigtramp =3D __kernel_rt_sigreturn; + +VDSO_futex_list64_try_unlock_cs_start =3D __futex_list64_try_unlock_cs_sta= rt; +VDSO_futex_list64_try_unlock_cs_success =3D __futex_list64_try_unlock_cs_s= uccess; +VDSO_futex_list64_try_unlock_cs_end =3D __futex_list64_try_unlock_cs_end; diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c index 357e18db0c7a..988568a62a8b 100644 --- a/arch/x86/entry/vdso/vma.c +++ b/arch/x86/entry/vdso/vma.c @@ -85,13 +85,13 @@ static void vdso_futex_robust_unlock_update_ips(void) futex_reset_cs_ranges(fd); =20 #ifdef CONFIG_X86_64 - futex_set_vdso_cs_range(fd, idx, vdso, image->sym___futex_list64_try_unlo= ck_cs_start, + futex_set_vdso_cs_range(fd, idx, image->sym___futex_list64_try_unlock_cs_= start + vdso, image->sym___futex_list64_try_unlock_cs_end, false); idx++; #endif /* CONFIG_X86_64 */ =20 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT) - futex_set_vdso_cs_range(fd, idx, vdso, image->sym___futex_list32_try_unlo= ck_cs_start, + futex_set_vdso_cs_range(fd, idx, image->sym___futex_list32_try_unlock_cs_= start + vdso, image->sym___futex_list32_try_unlock_cs_end, true); #endif /* CONFIG_X86_32 || CONFIG_COMPAT */ } diff --git a/include/linux/futex.h b/include/linux/futex.h index 33524dfb3fe4..cb378872e4e7 100644 --- a/include/linux/futex.h +++ b/include/linux/futex.h @@ -122,14 +122,6 @@ static inline void futex_fixup_robust_unlock(struct pt= _regs *regs) { struct futex_unlock_cs_range *csr; =20 - /* - * Avoid dereferencing current->mm if not returning from interrupt. - * current->rseq.event is going to be used subsequently, so bringing the - * cache line in is not a big deal. - */ - if (!current->rseq.event.user_irq) - return; - csr =3D current->mm->futex.unlock.cs_ranges; =20 /* The loop is optimized out for !COMPAT */ @@ -142,10 +134,9 @@ static inline void futex_fixup_robust_unlock(struct pt= _regs *regs) } =20 static inline void futex_set_vdso_cs_range(struct futex_mm_data *fd, unsig= ned int idx, - unsigned long vdso, unsigned long start, - unsigned long end, bool sz32) + unsigned long start, unsigned long end, bool sz32) { - fd->unlock.cs_ranges[idx].start_ip =3D vdso + start; + fd->unlock.cs_ranges[idx].start_ip =3D start; fd->unlock.cs_ranges[idx].len =3D end - start; fd->unlock.cs_ranges[idx].pop_size32 =3D sz32; } --=20 2.54.0 From nobody Mon Jun 8 11:07:05 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00B693EAC75; Fri, 29 May 2026 16:34:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780072475; cv=none; b=m0x+DABRRXoqne3+UwtSFAJZ/Qn8+Ej92BfbePQfUUEt5AEbrsWYqaE1G8GOToZ1z5dvsAYMEl+CTFpwHB/UpJsEi1Rv66AxbO7ufPObF6WvgQy45BprWWvLmdz+zAl5nyDN7Xt/++l8aNycVlZ/EZtpcyM36xWAsVJH1p9u7g0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780072475; c=relaxed/simple; bh=ad/lOM9pNK+ZEm0pyc2GakKY2Qtcn3HXvPITXZYHmPk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Lh1x4u4wNN2mRTTHG640rZEqQSGh1683RdNX4BPcbxazMKPvBvSlLvyrAaF1EixFSJ6pLGlTWG8631ijfD1VKWNjNGmmaHYA6rgU/StX5WqCBmrn3RDofVKaKAsEvnBatB+x+bVQDNUtRrz0DzQesbOi8HaiAEqnqjrV1uChx00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=S+8GbiJs; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="S+8GbiJs" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=6WcRY4Z+p3MulPsyGPTPfwV8fk5LXzYsNAzXDfEH3i0=; b=S+8GbiJsoZEoxg22jyDYFKHWmg YsZkJ2Q0EJ/pgtlkaCfKEMK/NqGU9RanADVlz3J/JpHEx3mXxREdSq3jZ8TfpJcDJJIA6ECQdc0CU RNamPwkFIP63aqr26BEmdGZh22pVYFL3l32yJ/G0UKg0zzeKzuruWL4kCtBvSMnyB20eHz9JtvtOz X0LYVNUW47Gdc0EYLtyz/2TVmBEt0mzE6JCSq82g4rKCpG9SQpeWcfTHMtmNgcz4N7WiuZwBpZY3P +GURuprrPZCYRym98ft1ps/jGzvyL8SZ2E+cUcwPwI1HrHiLXQI+Byjrv8EZpug8XxMYe11dw6yw9 TzolmJKA==; Received: from [179.118.191.12] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wT0AG-009wov-D4; Fri, 29 May 2026 18:34:28 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 29 May 2026 13:33:54 -0300 Subject: [PATCH v3 2/5] arm64: vdso: Implement __vdso_futex_robust_try_unlock() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260529-tonyk-robust_arm-v3-2-a6f02684d4fe@igalia.com> References: <20260529-tonyk-robust_arm-v3-0-a6f02684d4fe@igalia.com> In-Reply-To: <20260529-tonyk-robust_arm-v3-0-a6f02684d4fe@igalia.com> To: Catalin Marinas , Will Deacon , Thomas Gleixner , Mark Rutland , Mathieu Desnoyers , Sebastian Andrzej Siewior , Carlos O'Donell , Peter Zijlstra , Florian Weimer , Rich Felker , Torvald Riegel , Darren Hart , Ingo Molnar , Davidlohr Bueso , Arnd Bergmann , "Liam R . Howlett" , Uros Bizjak , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-dev@igalia.com, LKML , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 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 cbnz w9, retry __vdso_futex_list64_try_unlock_cs_start: 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 chec= king the condition flag zero: return (regs->user_regs.pstate & PSR_Z_BIT) ? (void __user *) regs->user_regs.regs[2] : NULL; If it's not zero, that means that the comparassion worked and the kernel sh= ould clear op_pending (if userspace didn't managed to) stored at x2. Signed-off-by: Andr=C3=A9 Almeida --- Notes: - Only LL/SC for now but I can add LSE later if this looks good v3: - Managed to get pop to always be stored at x2 --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/futex_robust.h | 20 ++++++++++++++++++++ arch/arm64/kernel/vdso/Makefile | 9 ++++++++- arch/arm64/kernel/vdso/vfutex.c | 34 +++++++++++++++++++++++++++++++= +++ include/vdso/futex.h | 1 + 5 files changed, 64 insertions(+), 1 deletion(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 427151a9db7f..e10cb97a51c7 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -249,6 +249,7 @@ config ARM64 select HAVE_RELIABLE_STACKTRACE select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_FUNCTION_ARG_ACCESS_API + select HAVE_FUTEX_ROBUST_UNLOCK select MMU_GATHER_RCU_TABLE_FREE select HAVE_RSEQ select HAVE_RUST if RUSTC_SUPPORTS_ARM64 diff --git a/arch/arm64/include/asm/futex_robust.h b/arch/arm64/include/asm= /futex_robust.h new file mode 100644 index 000000000000..26b4006c4aeb --- /dev/null +++ b/arch/arm64/include/asm/futex_robust.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ARM64_FUTEX_ROBUST_H +#define _ASM_ARM64_FUTEX_ROBUST_H + +#include + +static __always_inline void __user *arm64_futex_robust_unlock_get_pop(stru= ct pt_regs *regs) +{ + /* + * If Z bit is set then the ll/sc cmpxchg succeeded and the pending op + * pointer needs to be cleared. + */ + return (regs->user_regs.pstate & PSR_Z_BIT) ? + (void __user *) regs->user_regs.regs[2] : NULL; +} + +#define arch_futex_robust_unlock_get_pop(regs) \ + arm64_futex_robust_unlock_get_pop(regs) + +#endif /* _ASM_ARM64_FUTEX_ROBUST_H */ diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makef= ile index 7dec05dd33b7..3c7f220fe783 100644 --- a/arch/arm64/kernel/vdso/Makefile +++ b/arch/arm64/kernel/vdso/Makefile @@ -9,7 +9,8 @@ # Include the generic Makefile to check the built vdso. include $(srctree)/lib/vdso/Makefile.include =20 -obj-vdso :=3D vgettimeofday.o note.o sigreturn.o vgetrandom.o vgetrandom-c= hacha.o +obj-vdso :=3D vgettimeofday.o note.o sigreturn.o vgetrandom.o vgetrandom-c= hacha.o \ + vfutex.o =20 # Build rules targets :=3D $(obj-vdso) vdso.so vdso.so.dbg @@ -45,9 +46,11 @@ CC_FLAGS_ADD_VDSO :=3D -O2 -mcmodel=3Dtiny -fasynchronou= s-unwind-tables =20 CFLAGS_REMOVE_vgettimeofday.o =3D $(CC_FLAGS_REMOVE_VDSO) CFLAGS_REMOVE_vgetrandom.o =3D $(CC_FLAGS_REMOVE_VDSO) +CFLAGS_REMOVE_vfutex.o =3D $(CC_FLAGS_REMOVE_VDSO) =20 CFLAGS_vgettimeofday.o =3D $(CC_FLAGS_ADD_VDSO) CFLAGS_vgetrandom.o =3D $(CC_FLAGS_ADD_VDSO) +CFLAGS_vfutex.o =3D $(CC_FLAGS_ADD_VDSO) =20 ifneq ($(c-gettimeofday-y),) CFLAGS_vgettimeofday.o +=3D -include $(c-gettimeofday-y) @@ -57,6 +60,10 @@ ifneq ($(c-getrandom-y),) CFLAGS_vgetrandom.o +=3D -include $(c-getrandom-y) endif =20 +ifneq ($(c-futex-y),) + CFLAGS_vfutex.o +=3D -include $(c-futex-y) +endif + targets +=3D vdso.lds CPPFLAGS_vdso.lds +=3D -P -C -U$(ARCH) =20 diff --git a/arch/arm64/kernel/vdso/vfutex.c b/arch/arm64/kernel/vdso/vfute= x.c new file mode 100644 index 000000000000..3561b869d8bb --- /dev/null +++ b/arch/arm64/kernel/vdso/vfutex.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#include + +#define LABEL(name, sz) __stringify(__futex_list##sz##_try_unlock_cs_##nam= e) + +#define GLOBLS(sz) ".globl " LABEL(start, sz) ", " LABEL(success, sz) ", "= LABEL(end, sz) "\n" + +__u32 __vdso_futex_robust_list64_try_unlock(__u32 *lock, __u32 tid, __u64 = *pop) +{ + register __u64 *pop_reg asm("x2") =3D pop; + __u32 val, result; + + asm volatile ( + GLOBLS(64) + " prfm pstl1strm, %[lock] \n" + "retry: \n" + " ldxr %w[val], %[lock] \n" + " cmp %w[tid], %w[val] \n" + " bne " LABEL(end, 64)" \n" + " stlxr %w[result], wzr, %[lock] \n" + " cbnz %w[result], retry \n" + LABEL(start, 64)": \n" + LABEL(success, 64)": \n" + " str xzr, %[pop_reg] \n" + LABEL(end, 64)": \n" + + : [val] "=3D&r" (val), [result] "=3D&r" (result) + : [tid] "r" (tid), [lock] "Q" (*lock), [pop_reg] "Q" (*pop_reg) + : "memory" + ); + + return val; +} diff --git a/include/vdso/futex.h b/include/vdso/futex.h index 3cd175eefe64..80934561a10d 100644 --- a/include/vdso/futex.h +++ b/include/vdso/futex.h @@ -4,6 +4,7 @@ =20 #include =20 + /** * __vdso_futex_robust_list64_try_unlock - Try to unlock an uncontended ro= bust futex * with a 64-bit pending op pointer --=20 2.54.0 From nobody Mon Jun 8 11:07:05 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D13ED3EA95A; Fri, 29 May 2026 16:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780072480; cv=none; b=NOINs96MBHhdvkcRkbwUV5sAp5SHAY2zX5iq++BcZZBnTe3Vq5HCRR5Um/890rWvEoSdG81k1QIzUHKeT0fK0SsOOOT0f8r8/CHk+XZv2dkFIgCO0jTnnp8wgQLwflPSR2TAc3/zBs6KPi5Bqd30HPIkOFa3B/KnYyz6cL6dPr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780072480; c=relaxed/simple; bh=Jf3MXEmah84LBaIfjZ34Xy+dzT9nw5Zj55ftuh9NUqo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cFsxuWoTAzh0x4IyFiE1095sfx6sxOkg2X8jP7bKDfyAGPpqrJ83s5ZNnmLFghGr9qFAKAXtX9hf+bsyAKLWNlZE5aDJ25E237ZxBCubbhYR2XLECFPXoQd721CBOR5nzjjzyam5l4qeWL07qLkv2renEUYGN25LeA0177rbUio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=RhlEmFKm; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="RhlEmFKm" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ixuk1kcLyoWXvPuunbj8nY84un+scqW38ghks1QIX1w=; b=RhlEmFKmAPVkA2laIRhN6yTpsn /4V+Glh42oWbPJ8RFtfp5IlAZanw4AMVmJ7s3Q14pKzqEQOcN4p5QiKXvytD/+SCEiIfeL3d2Xanp cRTBgA+qbNr3MhzzeKBQ6lTUbEoc5F3ze2X6ob+W9QieBoRGHwsyoJAfBQcaZs/wWonIrpI0bB1U4 u4mXgS0Nn1ZK1YKzvmFVAsWk3dpL2rUvsGJDMpyslLMiVm56+RH7mzsGUOOd6tLoUGRBad8/DaxGD ewtqvmGFMYdrSKuuzCGG3rOU2mToRnz5CLSvn4h/hPS0Kd4rQVrk6g+GjQurAmfgTKFfJd98ZB6gg /ckWCI3A==; Received: from [179.118.191.12] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wT0AL-009wov-Li; Fri, 29 May 2026 18:34:33 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 29 May 2026 13:33:55 -0300 Subject: [PATCH v3 3/5] selftests: futex: Add support for aarch64 in robust_list_critical Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260529-tonyk-robust_arm-v3-3-a6f02684d4fe@igalia.com> References: <20260529-tonyk-robust_arm-v3-0-a6f02684d4fe@igalia.com> In-Reply-To: <20260529-tonyk-robust_arm-v3-0-a6f02684d4fe@igalia.com> To: Catalin Marinas , Will Deacon , Thomas Gleixner , Mark Rutland , Mathieu Desnoyers , Sebastian Andrzej Siewior , Carlos O'Donell , Peter Zijlstra , Florian Weimer , Rich Felker , Torvald Riegel , Darren Hart , Ingo Molnar , Davidlohr Bueso , Arnd Bergmann , "Liam R . Howlett" , Uros Bizjak , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-dev@igalia.com, LKML , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 Add support for aarch64 for robust_list_critical test. Apart from the arch specific registers, as the cmpxchg is implemented using LL/SC, doing single steps clears the exclusive monitor and then the store fails. To avoid that, insert a breakpoint just after the store and let it run continuously until there. Signed-off-by: Andr=C3=A9 Almeida --- .../futex/functional/robust_list_critical.c | 92 ++++++++++++++++++= ++-- 1 file changed, 87 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/futex/functional/robust_list_critical.= c b/tools/testing/selftests/futex/functional/robust_list_critical.c index b9490d24eb10..a4fe69a21297 100644 --- a/tools/testing/selftests/futex/functional/robust_list_critical.c +++ b/tools/testing/selftests/futex/functional/robust_list_critical.c @@ -65,8 +65,9 @@ static bool pc_is_within(struct user_regs_struct *regs, u= int64_t start, uint64_t =20 #if defined(__x86_64__) pc =3D regs->rip; -#elif defined(__riscv) - pc =3D reg->pc; +#elif defined(__riscv) || defined(__aarch64__) + pc =3D regs->pc; +#else # error Missing ptrace support #endif if (pc >=3D (long) start && pc < end) @@ -219,12 +220,79 @@ enum trace_state { STATE_LEAVE_VDSO, }; =20 +static int ptrace_get_regs(struct user_regs_struct *regs, pid_t child) +{ +#if defined(__x86_64__) + + return ptrace(PTRACE_GETREGS, child, 0, regs); + +#elif defined(__aarch64__) + + struct iovec io; + io.iov_base =3D regs; + io.iov_len =3D sizeof(struct user_regs_struct); + + return ptrace(PTRACE_GETREGSET, child, NT_PRSTATUS, &io); + +#endif +} + +#if defined(__aarch64__) +/* + * A cmpxchg in Arm64 implemented using LL/SC can't single step on every + * instruction. This clears the exclusive monitor and invalidates the stor= e. + * Instead, we need to add a breakpoint just after the store (on the label + * __futex_list64_try_unlock_cs_success) and let it be executed continuous= ly. + */ + +#define AARCH64_BRK 0xD4200000 +static void set_breakpoint(pid_t child, uint64_t *inst) +{ + + long ret; + + ret =3D ptrace(PTRACE_PEEKDATA, child, __futex_list64_try_unlock_cs_succe= ss, 0); + if (ret =3D=3D -1) + err(1, "PTRACE_PEEKDATA"); + + *inst =3D (uint64_t) ret; + + ret =3D ptrace(PTRACE_POKEDATA, child, __futex_list64_try_unlock_cs_succe= ss, AARCH64_BRK); + if (ret =3D=3D -1) + err(1, "PTRACE_POKEDATA"); +} + +static void remove_breakpoint(pid_t child, struct user_regs_struct *regs, = uint64_t inst) +{ + uint64_t addr =3D regs->pc; + int ret; + + ret =3D ptrace(PTRACE_POKEDATA, child, addr, inst); + if (ret =3D=3D -1) + err(1, "PTRACE_POKEDATA"); +} + +#define ptrace_cont() \ + if (ptrace(PTRACE_CONT, child, 0, 0)) \ + err(1, "PTRACE_CONT"); \ + continue; + +#else + +static void set_breakpoint(pid_t child, uint64_t *inst) {} +static void remove_breakpoint(pid_t child, struct user_regs_struct *regs, = uint64_t inst) {} + +#define ptrace_cont() {} + +#endif + static void trace_child(struct __test_metadata *_metadata, pid_t child, bo= ol is_32bit) { int state =3D STATE_WAIT; struct robust_list_head *rhead; size_t sz; - bool do_end =3D false; + bool do_end =3D false, enter_cs =3D false; + uint64_t inst =3D 0; =20 syscall(SYS_get_robust_list, 0, &rhead, &sz); do { @@ -235,6 +303,7 @@ static void trace_child(struct __test_metadata *_metada= ta, pid_t child, bool is_ pid_t rpid; =20 rpid =3D waitpid(child, &wstatus, 0); + if (rpid !=3D child) errx(1, "waitpid"); if (!do_end) { @@ -244,11 +313,15 @@ static void trace_child(struct __test_metadata *_meta= data, pid_t child, bool is_ if (!WIFEXITED(wstatus)) errx(1, "Did not exit, but we are done"); ASSERT_EQ(WEXITSTATUS(wstatus), 0); + + /* check if the code really reached the critical section */ + ASSERT_EQ(enter_cs, true); + return; } =20 - if (ptrace(PTRACE_GETREGS, child, 0, ®s) !=3D 0) - errx(1, "PTRACE_GETREGS"); + if (ptrace_get_regs(®s, child)) + errx(1, "ptrace_get_regs"); =20 if (is_32bit) { in_vdso =3D pc_is_within(®s, (long)frtu32, frtu32_end); @@ -261,6 +334,11 @@ static void trace_child(struct __test_metadata *_metad= ata, pid_t child, bool is_ if (state =3D=3D STATE_WAIT) { state =3D STATE_ENTER_VDSO; =20 + /* set a bp first time we enter vdso */ + set_breakpoint(child, &inst); + + /* and let the execution continue until it reaches the CS */ + ptrace_cont(); } else { if (is_32bit) { if (pc_is_within(®s, __futex_list32_try_unlock_cs_start, @@ -301,8 +379,12 @@ static void trace_child(struct __test_metadata *_metad= ata, pid_t child, bool is_ if (is_32bit) rhead_val &=3D 0xffffffff; =20 + enter_cs =3D true; ASSERT_EQ(rhead_val, 0); ASSERT_EQ(lock_val, 0); + + /* remove the breakpoint and continue execution */ + remove_breakpoint(child, ®s, inst); } =20 if (ptrace(PTRACE_SINGLESTEP, child, 0, 0)) --=20 2.54.0 From nobody Mon Jun 8 11:07:05 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5BFC3EA95A; Fri, 29 May 2026 16:34:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780072485; cv=none; b=muCiy2gajVsclFa0LW1AFtqwoQSI9FqzVchunm3oJ6lNOhzF/VC7rzCQHZEZ7OYTJ3PFjXrfGV7BRyvSeTQVQY4LX42gNX6Cg7EpeB5grQKRLB1k5GvovDD2QVPidC4KZ9Ddux8zTOtefoRBbh9iGUgXHkcVd07jHbZoH94AxNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780072485; c=relaxed/simple; bh=Xx/B3blN0ezhnlwePDTERGZkH7WkdmD/5kul/QrLH24=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MHr0yTvv4RAxVCkJ8vG0neZ/jsrw/eoZeFeKK7WwemKhzGCsfEXRrbmF/3iL2cgRjEwsB3jOU4ogJOFj+6bGfxctfFzJmfTOg1V+TgcU316INkYNBDsh+aTm4j4WjCzs8JFN6WKD/sp/uakjXkHHnwbWgIZox2FQ3G4xQQTgOh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=K00Gh6qG; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="K00Gh6qG" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JLkyHFYC4EoXRqoOpftxW/9hntSQYUBfchvNpjZqZcg=; b=K00Gh6qGDQONRsTBVdIDcKzTPU cq0GiSB+joLO3s7iTn7Hqr42H5nYIbp0qV+hqkdhUc6rut4ZREzsPlmuiyBd2MQF/yN+9118IMAm1 ovV4eyAXyEZHpsFXUsku/hXDFbapTbSvlpRBvBZOPEPhDHs6cXwlquNWlu4SI3Mxg3HJ2TRWPDTIw ffspB0yBF05fIukTEe5NNY4wPCDgJrq2jVwf9CZ8jXBhsbkd0XeOyxyy/ZdLvdg4VWshvy3b9b2ZD fEZZlekjYTnu4HSR93+NFTpCmgSWp6sKX3QGpOjvuTeZnq6WRfZkqcJaRXx/dsL/dZDn/bhwZj5CV 4qHdjRQQ==; Received: from [179.118.191.12] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wT0AQ-009wov-Tk; Fri, 29 May 2026 18:34:39 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 29 May 2026 13:33:56 -0300 Subject: [PATCH v3 4/5] arm64: vdso32: Bring vdso32-offsets.h back Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260529-tonyk-robust_arm-v3-4-a6f02684d4fe@igalia.com> References: <20260529-tonyk-robust_arm-v3-0-a6f02684d4fe@igalia.com> In-Reply-To: <20260529-tonyk-robust_arm-v3-0-a6f02684d4fe@igalia.com> To: Catalin Marinas , Will Deacon , Thomas Gleixner , Mark Rutland , Mathieu Desnoyers , Sebastian Andrzej Siewior , Carlos O'Donell , Peter Zijlstra , Florian Weimer , Rich Felker , Torvald Riegel , Darren Hart , Ingo Molnar , Davidlohr Bueso , Arnd Bergmann , "Liam R . Howlett" , Uros Bizjak , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-dev@igalia.com, LKML , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 Commit c7767f5c43df ("arm64: vdso32: Remove unused vdso32-offsets.h") removed vdso32-offsets.h because it was empty and therefore useless. With the introduction of __vdso_futex_robust_try_unlock(), there is the need to expose offsets again. Signed-off-by: Andr=C3=A9 Almeida --- arch/arm64/Makefile | 2 +- arch/arm64/include/asm/vdso.h | 3 +++ arch/arm64/kernel/vdso32/Makefile | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 73a10f65ce8b..6164d905d402 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -208,7 +208,7 @@ vdso_prepare: prepare0 include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so ifdef CONFIG_COMPAT_VDSO $(Q)$(MAKE) $(build)=3Darch/arm64/kernel/vdso32 \ - arch/arm64/kernel/vdso32/vdso.so + include/generated/vdso32-offsets.h arch/arm64/kernel/vdso32/vdso.so endif endif =20 diff --git a/arch/arm64/include/asm/vdso.h b/arch/arm64/include/asm/vdso.h index 232b46969088..43a214b93524 100644 --- a/arch/arm64/include/asm/vdso.h +++ b/arch/arm64/include/asm/vdso.h @@ -10,6 +10,9 @@ #ifndef __ASSEMBLER__ =20 #include +#ifdef CONFIG_COMPAT_VDSO +#include +#endif =20 #define VDSO_SYMBOL(base, name) \ ({ \ diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/M= akefile index 9d0efed91414..2775843e53cd 100644 --- a/arch/arm64/kernel/vdso32/Makefile +++ b/arch/arm64/kernel/vdso32/Makefile @@ -136,6 +136,14 @@ $(c-obj-vdso-gettimeofday): %.o: %.c FORCE $(asm-obj-vdso): %.o: %.S FORCE $(call if_changed_dep,vdsoas) =20 +# Generate VDSO offsets using helper script +gen-vdsosym :=3D $(src)/../vdso/gen_vdso_offsets.sh +quiet_cmd_vdsosym =3D VDSOSYM $@ + cmd_vdsosym =3D $(NM) $< | $(gen-vdsosym) | LC_ALL=3DC sort > $@ + +include/generated/vdso32-offsets.h: $(obj)/vdso32.so.dbg FORCE + $(call if_changed,vdsosym) + # Actual build commands quiet_cmd_vdsold_and_vdso_check =3D LD32 $@ cmd_vdsold_and_vdso_check =3D $(cmd_vdsold); $(cmd_vdso_check) --=20 2.54.0 From nobody Mon Jun 8 11:07:05 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7EDE3EE1E2; Fri, 29 May 2026 16:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780072490; cv=none; b=JGR4dXzuYIpgwM91OlI5l8MGIEUq2dK4q3UcErFIk8LwTVLDAco5/Rp+inIdagwPp4dA2PH2p0aLohxFmEihxwrIh22VynGisB0YjH0j6P3Mo9l2YCrb9SJxXbZmWnP75Bm8GnpSa5kCD6o8aYVpbtgeD+9bgQS/0YLSDYEB3+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780072490; c=relaxed/simple; bh=VN8/a0WXtzv1qop11YkYAJ89INU4HTueEd34qRetO48=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dToFOyBYb3Jy345DFabTjvgSlmlYyRI2d+OpBUvpBUjlTrwksMsWZXci6v8kPqHRFpjl9bKO8vspEpzCP61qh3yFOkTt3+J1TH0c50CaJ1akzqynz3xWBx32vVRKWHFu/3tCGctjYh0eoajG87TwtDNf1TBBHlyvBRaHFfz/IYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=m5fSKYAb; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="m5fSKYAb" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=R4JTcNVSu0j7h5Ha9fe+aZclKI7tLU2gi4u42f9j99Y=; b=m5fSKYAbPwXMUu3X4JElCGVLc3 heuvdO8lxMeOkeCUDdnoRu7zPsg7dQm3kqu+Cqkc3ei8dMHQ7qqa/XL1nB0qfqb82bubYp9tOJ9sb T/38Cer1Tm7Hhg36ciYLIqjS4s8coExTfc9KXPf918GSh5c3B3tX4QFLVAT1ym0eGiDZ0ptU7gt9A 0h0YcIaVen/PxypG6y6FvHaPhHfsYAKaxgFxoXqvFt9sHNumHDk2yDrbPlrcCmSruQ9o4qMtLMTb9 i4QOHTU9LlSmMQHoQUuZ4Bji4fU5xUEyKOZiV8Dm7BIEM80g/u0TG5dsvwDowYi6E1gLTMT8YMH1F 07c0LLaw==; Received: from [179.118.191.12] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wT0AW-009wov-5J; Fri, 29 May 2026 18:34:44 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 29 May 2026 13:33:57 -0300 Subject: [PATCH v3 5/5] arm64: vdso32: Implement __vdso_futex_robust_try_unlock() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260529-tonyk-robust_arm-v3-5-a6f02684d4fe@igalia.com> References: <20260529-tonyk-robust_arm-v3-0-a6f02684d4fe@igalia.com> In-Reply-To: <20260529-tonyk-robust_arm-v3-0-a6f02684d4fe@igalia.com> To: Catalin Marinas , Will Deacon , Thomas Gleixner , Mark Rutland , Mathieu Desnoyers , Sebastian Andrzej Siewior , Carlos O'Donell , Peter Zijlstra , Florian Weimer , Rich Felker , Torvald Riegel , Darren Hart , Ingo Molnar , Davidlohr Bueso , Arnd Bergmann , "Liam R . Howlett" , Uros Bizjak , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-dev@igalia.com, LKML , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 Based on aarch64 implementation, provide a 32 bit entry point for this vDSO. In order to keep compatibility with arm64_futex_robust_unlock_get_pop(), make sure to store the pop address at r2. Signed-off-by: Andr=C3=A9 Almeida --- arch/arm64/kernel/vdso.c | 9 +++++++++ arch/arm64/kernel/vdso32/Makefile | 2 +- arch/arm64/kernel/vdso32/vdso.lds.S | 5 +++++ arch/arm64/kernel/vdso32/vfutex.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 76f22ea8e181..3ce9d9d79431 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -71,6 +71,15 @@ static void vdso_futex_robust_unlock_update_ips(enum vds= o_abi abi, struct mm_str =20 futex_set_vdso_cs_range(fd, 0, success, end, false); } + +#ifdef CONFIG_COMPAT_VDSO + if (abi =3D=3D VDSO_ABI_AA32) { + success =3D (uintptr_t) VDSO_SYMBOL(vdso, futex_list32_try_unlock_cs_suc= cess); + end =3D (uintptr_t) VDSO_SYMBOL(vdso, futex_list32_try_unlock_cs_end); + + futex_set_vdso_cs_range(fd, 1, success, end, true); + } +#endif } #else static inline void vdso_futex_robust_unlock_update_ips(enum vdso_abi abi, = struct mm_struct *mm) { } diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/M= akefile index 2775843e53cd..cc4248539bec 100644 --- a/arch/arm64/kernel/vdso32/Makefile +++ b/arch/arm64/kernel/vdso32/Makefile @@ -97,7 +97,7 @@ VDSO_LDFLAGS +=3D --orphan-handling=3D$(CONFIG_LD_ORPHAN_= WARN_LEVEL) munge :=3D ../../../arm/vdso/vdsomunge hostprogs :=3D $(munge) =20 -c-obj-vdso :=3D note.o +c-obj-vdso :=3D note.o vfutex.o c-obj-vdso-gettimeofday :=3D vgettimeofday.o =20 ifneq ($(c-gettimeofday-y),) diff --git a/arch/arm64/kernel/vdso32/vdso.lds.S b/arch/arm64/kernel/vdso32= /vdso.lds.S index c374fb0146f3..31e0a3770c32 100644 --- a/arch/arm64/kernel/vdso32/vdso.lds.S +++ b/arch/arm64/kernel/vdso32/vdso.lds.S @@ -87,6 +87,11 @@ VERSION __vdso_clock_getres; __vdso_clock_gettime64; __vdso_clock_getres_time64; + __vdso_futex_robust_list32_try_unlock; local: *; }; } + +VDSO_futex_list32_try_unlock_cs_success =3D __futex_list32_try_unlock_cs_s= uccess; +VDSO_futex_list32_try_unlock_cs_start =3D __futex_list32_try_unlock_cs_sta= rt; +VDSO_futex_list32_try_unlock_cs_end =3D __futex_list32_try_unlock_cs_end; diff --git a/arch/arm64/kernel/vdso32/vfutex.c b/arch/arm64/kernel/vdso32/v= futex.c new file mode 100644 index 000000000000..a347da5ef47f --- /dev/null +++ b/arch/arm64/kernel/vdso32/vfutex.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#include + +#define LABEL(name, sz) __stringify(__futex_list##sz##_try_unlock_cs_##nam= e) + +#define GLOBLS(sz) ".globl " LABEL(start, sz) ", " LABEL(success, sz) ", "= LABEL(end, sz) "\n" + +__u32 __vdso_futex_robust_list32_try_unlock(__u32 *lock, __u32 tid, __u32 = *pop) +{ + register __u32 *pop_reg asm("r2") =3D pop; + __u32 val, result, zero =3D 0; + + asm volatile ( + GLOBLS(32) + "retry: \n" + " ldrex %[val], %[lock] \n" + " cmp %[tid], %[val] \n" + " bne " LABEL(end, 32)" \n" + " strex %[result], %[zero], %[lock] \n" + " cmp %[result], #0 \n" + " bne retry \n" + LABEL(start, 32)": \n" + LABEL(success, 32)": \n" + " str %[zero], %[pop_reg] \n" + LABEL(end, 32)": \n" + : [val] "=3D&r" (val), [result] "=3Dr" (result) + : [tid] "r" (tid), [lock] "Q" (*lock), [pop_reg] "Q" (*pop_reg), [zero] = "r" (zero) + : "memory" + ); + + return val; +} --=20 2.54.0