git: bcabd6089f3b - stable/15 - linux/futex: Don't load a timeout when try-locking a mutex

Mark Johnston <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a67ae2b.3900b.8fc8a11__39959.0237460629$1785179736$gmane$org@gitrepo.freebsd.org>
The branch stable/15 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=bcabd6089f3bb7102f32ce40a4d715d50f8093af

commit bcabd6089f3bb7102f32ce40a4d715d50f8093af
Author:     Mark Johnston <[email protected]>
AuthorDate: 2026-07-07 22:52:56 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2026-07-27 17:34:31 +0000

    linux/futex: Don't load a timeout when try-locking a mutex
    
    linux_sys_futex() does not copyin a timespec for the timeout if the
    operation is LINUX_FUTEX_TRYLOCK_PI, presumably because it doesn't make
    sense to specify a timeout for a try-lock operation.  However, this
    means that we pass a userspace timespec pointer to
    linux_umtx_abs_timeout_init().
    
    Modify linux_futex_lock_pi() to not initialize the timeout if we're
    try-locking.
    
    Reviewed by:    kib, dchagin
    Reported by:    Yuxiang Yang, Yizhou Zhao, Ao Wang, Xuewei Feng, Qi Li,
                    and Ke Xu from Tsinghua University using GLM-5.2 from Z.ai
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D58061
    
    (cherry picked from commit 407c7c339adb429efcb6658accd16399031c34ca)
---
 sys/compat/linux/linux_futex.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/sys/compat/linux/linux_futex.c b/sys/compat/linux/linux_futex.c
index 0586eb55a8f3..2e26fb6458a3 100644
--- a/sys/compat/linux/linux_futex.c
+++ b/sys/compat/linux/linux_futex.c
@@ -356,7 +356,7 @@ linux_futex(struct thread *td, struct linux_futex_args *args)
 static int
 linux_futex_lock_pi(struct thread *td, bool try, struct linux_futex_args *args)
 {
-	struct umtx_abs_timeout timo;
+	struct umtx_abs_timeout timo, *timop;
 	struct linux_emuldata *em;
 	struct umtx_pi *pi, *new_pi;
 	struct thread *td1;
@@ -370,8 +370,12 @@ linux_futex_lock_pi(struct thread *td, bool try, struct linux_futex_args *args)
 	    &uq->uq_key);
 	if (error != 0)
 		return (error);
-	if (args->ts != NULL)
-		linux_umtx_abs_timeout_init(&timo, args);
+	if (!try && args->ts != NULL) {
+		timop = &timo;
+		linux_umtx_abs_timeout_init(timop, args);
+	} else {
+		timop = NULL;
+	}
 
 	umtxq_lock(&uq->uq_key);
 	pi = umtx_pi_lookup(&uq->uq_key);
@@ -546,8 +550,7 @@ linux_futex_lock_pi(struct thread *td, bool try, struct linux_futex_args *args)
 
 		/* We set the contested bit, sleep. */
 		error = umtxq_sleep_pi(uq, pi, owner, "futexp",
-		    args->ts == NULL ? NULL : &timo,
-		    (args->flags & FUTEX_SHARED) != 0);
+		    timop, (args->flags & FUTEX_SHARED) != 0);
 		if (error != 0)
 			continue;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.