git: 8c13acc68517 - main - umtxq_sleep(): do not wait forever for zero absolute timeouts

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 10 Nov 2026 00:22:04 UTC
The branch main has been updated by kib:

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

commit 8c13acc68517f785df4b6c4b016dfd1c6f38c8cf
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-06 00:09:12 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-10 00:21:18 +0000

    umtxq_sleep(): do not wait forever for zero absolute timeouts
    
    For msleep(), zero sbt means no timeout. If the timeout was specified as
    absolute {0, 0} on MONOTONIC/UPTIME clocks, consider the call timed out
    immediately, instead of sleeping until a signal is delivered.
    
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D61253
---
 sys/kern/kern_umtx.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c
index 9182b13cba5a..fb8fba030b23 100644
--- a/sys/kern/kern_umtx.c
+++ b/sys/kern/kern_umtx.c
@@ -888,6 +888,15 @@ umtxq_sleep(struct umtx_q *uq, const char *wmesg,
 			error = umtx_abs_timeout_getsbt(timo, &sbt, &flags);
 			if (error != 0)
 				break;
+
+			/*
+			 * msleep() treats zero timeout as no timeout,
+			 * return ETIMEDOUT right away.
+			 */
+			if ((flags & C_ABSOLUTE) != 0 && sbt == 0) {
+				error = ETIMEDOUT;
+				break;
+			}
 		}
 		error = msleep_sbt(uq, &uc->uc_lock, PCATCH | PDROP, wmesg,
 		    sbt, 0, flags);