From nobody Mon Aug  3 00:25:29 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBL1cKsz6mj0n
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 00:25:30 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hCyBK6PJwz4P15
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:29 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785716729;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=2r3/e3/y2XifHd2qBrgnGbStZQusnelc8PkeIWNrz7c=;
	b=K0CAH5k5DtMyFcOncYlfOo6X7JLsP9oZ/tE/6J0Fub2KvYZpEpDHz+9Ap0mZUIm2AHJy4/
	a6QRU/JcSM7egNyLidgzeZ62xantdObYUBiN18sozZDk5KhiHYpsVfze6tkGhF4CtNDa/y
	Ca43bRScuZ57snb6gD/g2+TqQCH7JBl/B1F9iiJGASk+tphE5WJ2Nwql3ZH3AjBptEWJKs
	b+COUSDWZlRW6EqQE05svo3YF2AS5SNzWPM6LQnfQvmTiYgl7Q0whfUiIz8TMlAYU46YUA
	Q5BGGsRc93IgGA09OKJtKH1GwJh+OQ5cXiKB7Ri/Dli1IIqbXXaW66j39M/log==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785716729; a=rsa-sha256; cv=none;
	b=k9eJg7zkST3H/V8Zgb+yNaufj0d3tDcf4zektbRqU0mb+LuddtVLYTMZbQv9izm07wg6Ms
	cvjRZWkLE3mfb4mk7he6JC0tFoT2dWD2BL659FyvySDg5MWSs+Zy3ICl6xviLd6XOR9kt1
	Nfz5HqHeYglUdJbB9FmsIS72FEZBs7jGe5nfcQp5VgoO5HnCoyUZTEtsLyixl8Way8IWwe
	Zf52CwT+baZFuuJBdfxi5RVLrk1yTTeAS34Ut+psqGVQRa5ITx4YkW1VyR/qO7q29KhSXT
	LYYKSeRnPD6Lm4vYh9B7eB573lO+J+PBgl7GkBQ8SnsvnUkXoCLyFTmPWAVI5Q==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785716729;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=2r3/e3/y2XifHd2qBrgnGbStZQusnelc8PkeIWNrz7c=;
	b=gwodZ7ZcvxKrRPGfVtpzAEmzj7iP8az6EAHsz7gxeJ5220gCCVN7tFaaYF1vl/uibgcyxy
	yKMszFnSnoxnVWWoF9kTsWmwAPz/OV8fc2baQ6uS1q1G8lYmXdWveMzjakRA6Hk3mhYwEd
	fLqcgc3D4GjZQwmNPyWW3tGdLrCZHnUXKmjbMcGRNzNoowezFfV26h0z2AF9ibc3BMH5AK
	UnwNnAyBTwQYBrGKdTVVJ9195gttSUDS/uC5slthBMrKhuBf+JNiyZ9s4e41/sd1fOeUN5
	ppxPAJgspLI9paV0S5FxkLt9UHZhVAzt7/9RLvW9MYGAjekVUCYL0KtKlaiRUg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBK52Rrzf0H
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:29 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1ce8c
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 00:25:29 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Konstantin Belousov <kib@FreeBSD.org>
Subject: git: 16015bf932bd - stable/15 - umtx_op(2): add the CVWAIT_UMTX_TIME flag for the UMTX_OP_CV_WAIT_UC request
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kib
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 16015bf932bde4ab4cb174634ba6ef48fdad5fdc
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 00:25:29 +0000
Message-Id: <6a6fdff9.1ce8c.2f76fad7@gitrepo.freebsd.org>

The branch stable/15 has been updated by kib:

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

commit 16015bf932bde4ab4cb174634ba6ef48fdad5fdc
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-25 22:30:37 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-03 00:23:14 +0000

    umtx_op(2): add the CVWAIT_UMTX_TIME flag for the UMTX_OP_CV_WAIT_UC request
    
    (cherry picked from commit d738f66fab9208ee3bccea5fed293d8ce3ee5ca3)
---
 sys/kern/kern_umtx.c | 90 ++++++++++++++++++++++++++++++++--------------------
 sys/sys/umtx.h       |  1 +
 2 files changed, 56 insertions(+), 35 deletions(-)

diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c
index d9798fb2adb6..ab6e578ab380 100644
--- a/sys/kern/kern_umtx.c
+++ b/sys/kern/kern_umtx.c
@@ -2934,11 +2934,10 @@ do_unlock_umutex(struct thread *td, struct umutex *m, bool rb)
 
 static int
 do_cv_wait(struct thread *td, struct ucond *cv, struct umutex *m,
-    struct timespec *timeout, u_long wflags)
+    struct umtx_abs_timeout *timo, u_long wflags)
 {
-	struct umtx_abs_timeout timo;
 	struct umtx_q *uq;
-	uint32_t flags, clockid, hasw;
+	uint32_t flags, hasw;
 	int error;
 
 	uq = td->td_umtxq;
@@ -2949,23 +2948,6 @@ do_cv_wait(struct thread *td, struct ucond *cv, struct umutex *m,
 	if (error != 0)
 		return (error);
 
-	if ((wflags & CVWAIT_CLOCKID) != 0) {
-		error = fueword32(&cv->c_clockid, &clockid);
-		if (error == -1) {
-			umtx_key_release(&uq->uq_key);
-			return (EFAULT);
-		}
-		if ((clockid < CLOCK_REALTIME ||
-		    clockid >= CLOCK_THREAD_CPUTIME_ID) &&
-		    clockid != CLOCK_TAI) {
-			/* hmm, only HW clock id will work. */
-			umtx_key_release(&uq->uq_key);
-			return (EINVAL);
-		}
-	} else {
-		clockid = CLOCK_REALTIME;
-	}
-
 	umtxq_lock(&uq->uq_key);
 	umtxq_busy(&uq->uq_key);
 	umtxq_insert(uq);
@@ -2990,15 +2972,9 @@ do_cv_wait(struct thread *td, struct ucond *cv, struct umutex *m,
 
 	error = do_unlock_umutex(td, m, false);
 
-	if (timeout != NULL)
-		umtx_abs_timeout_init(&timo, clockid,
-		    (wflags & CVWAIT_ABSTIME) != 0, timeout);
-
 	umtxq_lock(&uq->uq_key);
-	if (error == 0) {
-		error = umtxq_sleep(uq, "ucond", timeout == NULL ?
-		    NULL : &timo);
-	}
+	if (error == 0)
+		error = umtxq_sleep(uq, "ucond", timo);
 
 	if ((uq->uq_flags & UQF_UMTXQ) == 0)
 		error = 0;
@@ -4138,19 +4114,63 @@ static int
 __umtx_op_cv_wait(struct thread *td, struct _umtx_op_args *uap,
     const struct umtx_copyops *ops)
 {
+	struct umtx_abs_timeout *timop, timo;
 	struct timespec *ts, timeout;
+	struct _umtx_time umtime;
+	struct ucond *cv;
+	u_long wflags;
+	uint32_t clockid;
 	int error;
 
-	/* Allow a null timespec (wait forever). */
-	if (uap->uaddr2 == NULL)
-		ts = NULL;
-	else {
-		error = ops->copyin_timeout(uap->uaddr2, &timeout);
+	cv = uap->obj;
+	wflags = uap->val;
+	if ((wflags & ~(CVWAIT_CHECK_UNPARKING | CVWAIT_ABSTIME |
+	    CVWAIT_CLOCKID | CVWAIT_UMTX_TIME)) != 0 ||
+	    ((wflags & (CVWAIT_ABSTIME | CVWAIT_CLOCKID)) != 0 &&
+	    (wflags & CVWAIT_UMTX_TIME) != 0))
+		return (EINVAL);
+
+	if ((wflags & CVWAIT_UMTX_TIME) == 0) {
+		/* Allow a null timespec (wait forever). */
+		if (uap->uaddr2 == NULL) {
+			ts = NULL;
+		} else {
+			error = ops->copyin_timeout(uap->uaddr2, &timeout);
+			if (error != 0)
+				return (error);
+			ts = &timeout;
+		}
+		if ((wflags & CVWAIT_CLOCKID) != 0) {
+			error = fueword32(&cv->c_clockid, &clockid);
+			if (error == -1)
+				return (EFAULT);
+		} else {
+			clockid = CLOCK_REALTIME;
+		}
+		if (ts != NULL) {
+			umtx_abs_timeout_init(&timo, clockid,
+			    (wflags & CVWAIT_ABSTIME) != 0, ts);
+			timop = &timo;
+		} else {
+			timop = NULL;
+		}
+	} else {
+		if (uap->uaddr2 == NULL)
+			return (EINVAL);
+		error = ops->copyin_umtx_time(uap->uaddr2, ops->umtx_time_sz,
+		    &umtime);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		timop = &timo;
+		umtx_abs_timeout_init2(timop, &umtime);
 	}
-	return (do_cv_wait(td, uap->obj, uap->uaddr1, ts, uap->val));
+	/* only HW clock id will work. */
+	if (timop != NULL && (timop->clockid < CLOCK_REALTIME ||
+	    timop->clockid >= CLOCK_THREAD_CPUTIME_ID) &&
+	    timop->clockid != CLOCK_TAI)
+		return (EINVAL);
+
+	return (do_cv_wait(td, cv, uap->uaddr1, timop, wflags));
 }
 
 static int
diff --git a/sys/sys/umtx.h b/sys/sys/umtx.h
index f7a69ae772c3..1cd9e2070977 100644
--- a/sys/sys/umtx.h
+++ b/sys/sys/umtx.h
@@ -115,6 +115,7 @@
 #define	CVWAIT_CHECK_UNPARKING	0x01
 #define	CVWAIT_ABSTIME		0x02
 #define	CVWAIT_CLOCKID		0x04
+#define	CVWAIT_UMTX_TIME	0x08
 
 #define	UMTX_ABSTIME		0x01
 

From nobody Mon Aug  3 00:25:31 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBN1XzXz6mhyg
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 00:25:32 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hCyBN09B5z4Nyc
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:32 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785716732;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=jOEm2RWIjMtwifLW7lSFPt2Rh9UfgJJyVwhKOeZ330w=;
	b=Aky2smL4H8o1CqnI56jO/d/XW0wWGOQ7CZbQPvH6qLAolP3GBDfH9UlXLOh535vVTDS6aO
	9XJFg4FX5QekUcF4IoB30gKFWOtv6rIlR/qBXFg4dlARd6/cXiSaXCY4P7ugy1BBBv5bG5
	jKQCyfOx9GmIA79zLXETixFhcIo4s6yewLmH5h+CjlAvuCb9oY5Cs2s1nbmvEY6858CEDT
	sNuSIWnFgbnTa5mvHS94RaPeme3WODhjJz48pGr84To/3uWXkj8nr+3YMxGnRhUd7hOcvI
	7KootJURJN50cqiMYs3/wHrAkvLaLvrrZijBYB3rnWuE1TOfpeTjtCxWrnNoGQ==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785716732; a=rsa-sha256; cv=none;
	b=GruCqmkhwfjgY26YscLui1FxA8SE8FbvzEW2gVtVX0+ir4PRuCIUmrIPixp0Sp9mpgtTI4
	Z3ar2Ds8chPMYxOO1HCjLefzKReVBGzkOwfsU5M4hHgOKB/yVNTljUMkF/5ywdeoEYq3nG
	SYr/amyXAhaEPdiB+5OBTSuc2vdbj7MOMSDQWfCj37EaSAt4+srCyAF30Hcq07Ke5svMxI
	hkEJ8u0RvoJe+5sY6yUVSxhKp+JAarIoT8fdOkDN+WjTU0q4FukOumxNkhtODdbpm2V49M
	Gga8HfFGbkQEvR5+nIlelUcfIoFz2e3kHa2tVVfTqb3Vc8B+NAyCDIkh2FPTsw==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785716732;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=jOEm2RWIjMtwifLW7lSFPt2Rh9UfgJJyVwhKOeZ330w=;
	b=gH/l8a5hZyMS37NLt1Zrh52cqebTlCS1aOdEzy6m83Ciz9Gf2CWlR7sWh2R6T+G6z3SdEH
	qi+DybX++RKRj4/2Xn4XNOlpnr7tC0DYtDbXFvkNIB4BUsBIlswGez1sdLm1lqs+TGdz9U
	WokHDfcNwtn7SF0boqmHsvSfdAbNP5bGhwKRq7wh9RoZi4FF/nNzeoejU2lkoMWRRQk7Gd
	ix05gA5zzZPoEBOL2LOhX/kkwQVFKFStJ8b25GvSaTW2l8HgTVeWQLATQKqu3Re+wdatJr
	r6Mio6PS1OmVn2U+mExKqTWXiyUWzEPiBJFsJ8yqL9+aPXRw9tnW5XrrXGJy3w==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBM6Fg2zf0J
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:31 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1d400
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 00:25:31 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Konstantin Belousov <kib@FreeBSD.org>
Subject: git: 0737ff2da5f4 - stable/15 - libthr/thread/thr_umtx.c: style _thr_ucond_wait()
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kib
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 0737ff2da5f447f581db0ab5fb615820749a3c83
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 00:25:31 +0000
Message-Id: <6a6fdffb.1d400.6bc84fb6@gitrepo.freebsd.org>

The branch stable/15 has been updated by kib:

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

commit 0737ff2da5f447f581db0ab5fb615820749a3c83
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-25 21:37:55 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-03 00:23:15 +0000

    libthr/thread/thr_umtx.c: style _thr_ucond_wait()
    
    (cherry picked from commit 196cc005b197ab8bf5044c3fc457697986a14b39)
---
 lib/libthr/thread/thr_umtx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/libthr/thread/thr_umtx.c b/lib/libthr/thread/thr_umtx.c
index bbc68d0e30c6..db63017a6a13 100644
--- a/lib/libthr/thread/thr_umtx.c
+++ b/lib/libthr/thread/thr_umtx.c
@@ -242,18 +242,18 @@ _thr_ucond_init(struct ucond *cv)
 
 int
 _thr_ucond_wait(struct ucond *cv, struct umutex *m,
-	const struct timespec *timeout, int flags)
+    const struct timespec *timeout, int flags)
 {
 	struct pthread *curthread;
 
-	if (timeout && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 &&
+	if (timeout != NULL && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 &&
 	    timeout->tv_nsec <= 0))) {
 		curthread = _get_curthread();
 		_thr_umutex_unlock(m, TID(curthread));
                 return (ETIMEDOUT);
 	}
 	return (_umtx_op_err(cv, UMTX_OP_CV_WAIT, flags, m,
-	    __DECONST(void*, timeout)));
+	    __DECONST(void *, timeout)));
 }
  
 int

From nobody Mon Aug  3 00:25:30 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBM2KPnz6mhyf
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 00:25:31 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hCyBM08dLz4Nw7
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:31 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785716731;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=fqwwgkW3XkE+iawa5ytAQ2MQqTglGHJuwE1cGKeHCak=;
	b=qqiTibzRMnCDPAgRCtPWIDDihCktQC1LIYK/Op1v7QGp5dWtwHK7dCBjMRoRZwWb6W2KS2
	y5e6afZH+ytx7peFbatpvIx9yqy/14DBzPTT+eksSEMmtt94580+WTEVjciC1Vp21TuiDS
	monTfUcxButb+VkGDl1KwNJrJVkUZ7RRonqqCEluPPmD9TJ51vqJfzJnmlC7iAk2U2fbHT
	OZT+yNf44PWWoMfOFx0WCQ8cHh9TanmVkePr9S5/qVDtyPGrDdp5FE73wiQUVeIeltar7E
	gl3NqJdDLDb14kap83ixJGylCk3IPxxRWdkKtPL/GUUZf+48dxfguYKTzX92nw==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785716731; a=rsa-sha256; cv=none;
	b=jO4BpsWAK5ieou9zTbRfK9mPvsn/yK+zlaOZ8dGfnJX0a2yKnONm0hA7cJ3h89rU6bjXOb
	pfpE47WAA6Qfr90ae15oHHx12+z4Wr7ZtMlMSbfiCaNEdYetO5BWXgbLadvasm9vUQ4tNs
	Pn+T4gOWZI+e3r038Z3u9MZITW+IjhWpSYbYTS9d/I6WWD9SoWPSttNIpqhH4mMznPAv+J
	9ia9aaq2FhJfcMBIt44JlHhoulavdiks1wsVWKIAPjKV1TtkSxhVch8k51rJmbW2DY4rD1
	MI7WrVufn9LE4Iqz2bOgTSUYPKxhLr+TZOeApUMTvO84ehyBW816OAfPn6dDEQ==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785716731;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=fqwwgkW3XkE+iawa5ytAQ2MQqTglGHJuwE1cGKeHCak=;
	b=YPhIuC+w0UteMiLKW81kblw+NxUy1B7ASsdT+oSKSxvNJqUpkUYlUrUubwH+pbfI4OS8LB
	L2TPHrJBXGE27x5+Wm7QFMriXCa/lsEFX2QSfYrr/tw5eOJCeVZua/dAYRgTqQXRBdruwG
	Sai/ZjF3BLLLgTqF+ag/A+YuMj+3xvrlPEZMh5NOuERLxrrVvTULRC+vu/5i3el5yTLhgD
	KSy+YSjklA9eABElAbKyLXq9yK+Bdem9zwnwWyDBbt2abPF67PNRkKuFxJhWkScWA5Q/Ty
	l/wJVy6bOS08omVV7vantD1NBUXgX+E+pvRLtGRy2Id72jFqwnSuseXEK/8qKg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBL60dszdWv
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:30 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1a399
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 00:25:30 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Konstantin Belousov <kib@FreeBSD.org>
Subject: git: 671e2cb6a237 - stable/15 - _umtx_op.2: document the CVWAIT_UMTX_TIME flag for the UMTX_OP_CV_WAIT_UC request
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kib
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 671e2cb6a2376015660441cf5ea97d520621e6ee
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 00:25:30 +0000
Message-Id: <6a6fdffa.1a399.1a2efb87@gitrepo.freebsd.org>

The branch stable/15 has been updated by kib:

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

commit 671e2cb6a2376015660441cf5ea97d520621e6ee
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-26 00:00:30 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-03 00:23:15 +0000

    _umtx_op.2: document the CVWAIT_UMTX_TIME flag for the UMTX_OP_CV_WAIT_UC request
    
    (cherry picked from commit f4a05f37936e422b1e8f4f127253562d3f58f50c)
---
 lib/libsys/_umtx_op.2 | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/lib/libsys/_umtx_op.2 b/lib/libsys/_umtx_op.2
index c590f8e8e0c8..8bdb20fa2178 100644
--- a/lib/libsys/_umtx_op.2
+++ b/lib/libsys/_umtx_op.2
@@ -752,15 +752,21 @@ After wakeup, the
 umutex is not relocked.
 .Pp
 The following flags are defined:
-.Bl -tag -width "CVWAIT_CLOCKID"
+.Bl -tag -width "CVWAIT_UMTX_TIME"
 .It Dv CVWAIT_ABSTIME
 Timeout is absolute.
 .It Dv CVWAIT_CLOCKID
 Clockid is provided.
+.It Dv CVWAIT_UMTX_TIME
+Timeout is specified by
+.Vt struct umtx_time
 .El
 .Pp
 Optionally, a timeout for the request may be specified.
-Unlike other requests, the timeout value is specified directly by a
+If the
+.Dv CVWAIT_UMTX_TIME
+flag is not passed, then, unlike other requests,
+the timeout value is specified directly by a
 .Vt struct timespec ,
 pointed to by the
 .Fa uaddr2
@@ -783,6 +789,19 @@ If the
 flag is supplied, the timeout specifies absolute time value, otherwise
 it denotes a relative time interval.
 .Pp
+Alternatively, if the
+.Dv CVWAIT_UMTX_TIME
+flag is passed, then the
+.Dv CVWAIT_CLOCKID
+and
+.Dv CVWAIT_ABSTIME
+flags must be not passed.
+In this case, the
+.Fa uaddr2
+points to the
+.Va struct umtx_time
+structure which specifes the timeout and clock identifier.
+.Pp
 The request is not restartable.
 An unblocked signal delivered during
 the wait always results in sleep interruption and

From nobody Mon Aug  3 00:25:32 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBP40ssz6mjJW
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 00:25:33 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hCyBP0wrBz4PHT
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:33 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785716733;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=xAyCmc5VGet0nHVXpIeqCqg2kXRCJWwKjaBw7IqGkfw=;
	b=FidOVu1oyceg54VVrLYF3wjx7YX7SGexdNhfunaQSVAmfGP832VWPOacEfCLbmCoLDdhZx
	C0gBMSiF+8K2CxDsRBG7pNdrbAQuUcuYLali0HdMrKhBj47GzwMxHo4QDqWZ/R3Q6sTT0h
	yRP9T0BwE+OmAskiH54SPaYPOX6Aieqmr82+KGFSzOVE/xdTQhkFWkor0AxgTqvvuPGhd/
	XSVAhv5/fEAbfrJxpN7KqPAW87JIC0y7lJvl/G9N5zCHA1jjLrvep2VWNC1S4jiJOPysMw
	2cehrpBxoRQT3j5R2Z1SAUi0Id3tgn3Ek7WV1H3zf7gWOZcLJPM+LjtfR4sMjQ==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785716733; a=rsa-sha256; cv=none;
	b=Ey/sxD5gSUblu2n2/Zbpx6D3jEoHSNFOthNQcAE4xy/MWEf0Vrlbupf+efspPYrjF4sIko
	1icfRkTUT9FQAa1AU2NEdvUvIjr2xOoXABZbVAIzYxXV88kK+aRVoaEZ1YJKCBaO68bS7e
	O5wXrUWsuh2v0RSZHpue1peRpa9MIXHfwHGdDD/zoCZ8/G8yL++NAhtkLV6D85ioiQOcwm
	m/sZaiEZaaPM8bcA7wbGoh2bdDVx6VBVJB0akn2BncyuMRMvT1QAuVv6ctJF/Ic9bAFQho
	s8RyciLW77GrMgISiKnDlh+u/jrXIjmKsjijb5Fblkd5S7jrTeC18s7X2Kkqaw==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785716733;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=xAyCmc5VGet0nHVXpIeqCqg2kXRCJWwKjaBw7IqGkfw=;
	b=Jpxu13UXgQjlKUUuAKFLBS3zNLlMq8/RVXuWUigJ6i5g3LhTfEuGHFtEu6RWUDnAPQXlZx
	sTkFlBxXPN93kxT2E2qbwYIYc4JykilD8uQqP401krqTyI8yXjvCYI1gskdtN4THx51fy9
	DUHpoLeBccsa3LhQfK2YRDvi7AGUF5k1cKPRR00jxWInS6qpWFDU6QIqIxmqOTVHHZLKtZ
	8+VgzaQoQzXna4tOGPzbeaSYkkh2LtiK+o6X40e539p/id7fdE40qhdj0BDEZxFCB8+HgN
	R06djGwI5k0Ig+4T75NiggzOvSWUUZR2jg+s8qn4rCmpb+WhvwAUDPYb8mpigw==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBN6s0czdWw
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:32 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1ca0e
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 00:25:32 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Konstantin Belousov <kib@FreeBSD.org>
Subject: git: d32bf064e951 - stable/15 - libthr/thread/thr_cond.c: some style
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kib
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: d32bf064e951837cf815062afa3bfcc24279ebae
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 00:25:32 +0000
Message-Id: <6a6fdffc.1ca0e.76eae454@gitrepo.freebsd.org>

The branch stable/15 has been updated by kib:

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

commit d32bf064e951837cf815062afa3bfcc24279ebae
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-26 00:07:37 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-03 00:23:15 +0000

    libthr/thread/thr_cond.c: some style
    
    (cherry picked from commit 149d3e5fcb76bff86d4343b7378258e9a6d3e25b)
---
 lib/libthr/thread/thr_cond.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/lib/libthr/thread/thr_cond.c b/lib/libthr/thread/thr_cond.c
index 0eb3dac068ca..f8c9118968bb 100644
--- a/lib/libthr/thread/thr_cond.c
+++ b/lib/libthr/thread/thr_cond.c
@@ -46,11 +46,11 @@ _Static_assert(sizeof(struct pthread_cond) <= THR_PAGE_SIZE_MIN,
 /*
  * Prototypes
  */
-int	__pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
-		       const struct timespec * abstime);
+int __pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
+    const struct timespec * abstime);
 static int cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
 static int cond_wait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
-		    const struct timespec *abstime, int cancel);
+    const struct timespec *abstime, bool cancel);
 static int cond_signal_common(pthread_cond_t *cond);
 static int cond_broadcast_common(pthread_cond_t *cond);
 
@@ -202,7 +202,7 @@ _thr_cond_destroy(pthread_cond_t *cond)
  */
 static int
 cond_wait_kernel(struct pthread_cond *cvp, struct pthread_mutex *mp,
-    const struct timespec *abstime, int cancel)
+    const struct timespec *abstime, bool cancel)
 {
 	struct pthread *curthread;
 	int error, error2, recurse, robust;
@@ -274,7 +274,7 @@ cond_wait_kernel(struct pthread_cond *cvp, struct pthread_mutex *mp,
 
 static int
 cond_wait_user(struct pthread_cond *cvp, struct pthread_mutex *mp,
-    const struct timespec *abstime, int cancel)
+    const struct timespec *abstime, bool cancel)
 {
 	struct pthread *curthread;
 	struct sleepqueue *sq;
@@ -350,12 +350,12 @@ cond_wait_user(struct pthread_cond *cvp, struct pthread_mutex *mp,
 
 static int
 cond_wait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
-	const struct timespec *abstime, int cancel)
+    const struct timespec *abstime, bool cancel)
 {
 	struct pthread	*curthread = _get_curthread();
 	struct pthread_cond *cvp;
 	struct pthread_mutex *mp;
-	int	error;
+	int error;
 
 	CHECK_AND_INIT_COND
 
@@ -381,16 +381,14 @@ cond_wait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
 int
 _thr_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
 {
-
-	return (cond_wait_common(cond, mutex, NULL, 0));
+	return (cond_wait_common(cond, mutex, NULL, false));
 }
 
 int
 __thr_cond_wait(pthread_cond_t * __restrict cond,
     pthread_mutex_t * __restrict mutex)
 {
-
-	return (cond_wait_common(cond, mutex, NULL, 1));
+	return (cond_wait_common(cond, mutex, NULL, true));
 }
 
 int
@@ -398,24 +396,22 @@ _thr_cond_timedwait(pthread_cond_t * __restrict cond,
     pthread_mutex_t * __restrict mutex,
     const struct timespec * __restrict abstime)
 {
-
 	if (abstime == NULL || abstime->tv_sec < 0 || abstime->tv_nsec < 0 ||
 	    abstime->tv_nsec >= 1000000000)
 		return (EINVAL);
 
-	return (cond_wait_common(cond, mutex, abstime, 0));
+	return (cond_wait_common(cond, mutex, abstime, false));
 }
 
 int
 __pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
 		       const struct timespec *abstime)
 {
-
 	if (abstime == NULL || abstime->tv_sec < 0 || abstime->tv_nsec < 0 ||
 	    abstime->tv_nsec >= 1000000000)
 		return (EINVAL);
 
-	return (cond_wait_common(cond, mutex, abstime, 1));
+	return (cond_wait_common(cond, mutex, abstime, true));
 }
 
 static int

From nobody Mon Aug  3 00:25:33 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBQ3kxkz6mjKq
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 00:25:34 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hCyBQ1RNRz4PL0
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:34 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785716734;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=wPktiNDVgKhwMD/gcFt3TK92q+6PkMDXhQmzu8O5kgs=;
	b=eJxnGsMmSxNQa8/KvB6wUhLozfSkA97fwteF9UwMwiahfcRoiyaNpEPk6Mw99uTaRnMW2W
	xT1BAlBNW2asVsEVAPBoqjJKkgqzKMrMaL4NL5K3RRQe6pKugJEpk8V9Rr/QJ2ewAaEq8k
	rerSHbdEunSKhGwaJVBXzlSrDG/y0i4rfkRKqMVE/30vZu7VPcOwFak3tUUJKgs2WfaxmF
	Hs4Eh/nR0rloSQEz3PpJ0ywC7DNIuPFYa82KXkoPvG1Pag+r6uzI+iX+eOiHsPx3UezdC2
	PYGhKZmL79OJbOjtiuMLW8Cc3fsQxYTC+tn9i1A0cPpU8Hx/1BX0oxm0sRf30g==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785716734; a=rsa-sha256; cv=none;
	b=np81H2FgSbuHcgFi5Rs38hhlncheQ1aaZG7cP5ZpmaEx3FJ0K2E1Pzh3CMHC1KAxKkTBlF
	sF1F1mOR9fc1BLvccj/2mBQb22iNLxB5VabSKyy2OhmDuNrNOB4cOngFR2hkZ8cKxJFfAT
	9hpMxZitAx2g7o1ef1xI+WpSGsxUWyCOJBR97hMdZe5DXJYzdXVRCdiGNZVnNikk7U0XP9
	xzSnvYPtU0QK2pxQVmyFSSXhic8K4RWAqOlwzgpASC9W+16DPKXO+oONuNEH7z2IG8YPdj
	IC+zVdrsZPxeGcvHK3IWvSe3PhR6OYXBh/6yu8cNpcCN/VGQfZ8kI4CFcxfDPA==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785716734;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=wPktiNDVgKhwMD/gcFt3TK92q+6PkMDXhQmzu8O5kgs=;
	b=eBJuOwOLlnvb5CsafSw1u2oSmikCDqvdbf9mlgOsqOCczvNxNqyBW+Llm/j/YiZLtVA9Pm
	g8h/0kAXhRh8+5q4fiqs6wAp4TnP7SIAFcUjUdMOJ9Ec8v/8kVhUEZNm4/DN4KVCoTHgBq
	pn1zCPgzA6CRUqk0Fa9sTCelB+m89n9Lar3CSiKWpxKG4tos7woMt7H3e06wok8QQgJaQ1
	1oKSO/U/gTC4fYyXIoFEQWK7u/X6GOANYDuUhmzCA5N2R955vrPlrriVeCmzvyYjPLM7Ww
	1vbBk8mmFC71BFbHZ7Ps+0fyBiLWMC8yqm8D7Ek++eh0WnfNF5WivEu+Si2iXg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBP74mqzdQg
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:33 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1ce90
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 00:25:33 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Konstantin Belousov <kib@FreeBSD.org>
Subject: git: 4dcfa6d003e0 - stable/15 - libthr: implement pthread_cond_clockwait(3)
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kib
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 4dcfa6d003e027be54d78ad14601170ae3a625f2
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 00:25:33 +0000
Message-Id: <6a6fdffd.1ce90.7b841bcd@gitrepo.freebsd.org>

The branch stable/15 has been updated by kib:

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

commit 4dcfa6d003e027be54d78ad14601170ae3a625f2
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-25 23:45:11 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-03 00:23:16 +0000

    libthr: implement pthread_cond_clockwait(3)
    
    (cherry picked from commit e1136fbcab184b8fb87456ca0d115d502bab6643)
---
 include/pthread.h               |  5 ++++
 lib/libthr/pthread.map          |  1 +
 lib/libthr/thread/thr_barrier.c |  6 ++--
 lib/libthr/thread/thr_cond.c    | 64 ++++++++++++++++++++++++++++++-----------
 lib/libthr/thread/thr_umtx.c    | 30 ++++++++++++++-----
 lib/libthr/thread/thr_umtx.h    |  3 +-
 6 files changed, 83 insertions(+), 26 deletions(-)

diff --git a/include/pthread.h b/include/pthread.h
index 311211cb48f1..1686b54314ef 100644
--- a/include/pthread.h
+++ b/include/pthread.h
@@ -199,6 +199,11 @@ int		pthread_condattr_init(pthread_condattr_t *);
 int		pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
 int		pthread_condattr_setpshared(pthread_condattr_t *, int);
 int		pthread_cond_broadcast(pthread_cond_t *);
+#if __POSIX_VISIBLE >= 202405
+int		pthread_cond_clockwait(pthread_cond_t * __restrict,
+		    pthread_mutex_t * __restrict, clockid_t,
+		    const struct timespec * __restrict);
+#endif
 int		pthread_cond_destroy(pthread_cond_t *);
 int		pthread_cond_init(pthread_cond_t * __restrict,
 		    const pthread_condattr_t * __restrict);
diff --git a/lib/libthr/pthread.map b/lib/libthr/pthread.map
index ad0c28de98c1..4fe5f2c28331 100644
--- a/lib/libthr/pthread.map
+++ b/lib/libthr/pthread.map
@@ -344,5 +344,6 @@ FBSD_1.8 {
 };
 
 FBSD_1.9 {
+	 pthread_cond_clockwait;
 	 pthread_tryjoin_np;
 };
diff --git a/lib/libthr/thread/thr_barrier.c b/lib/libthr/thread/thr_barrier.c
index 13dec864e2f6..e15b1627ee5d 100644
--- a/lib/libthr/thread/thr_barrier.c
+++ b/lib/libthr/thread/thr_barrier.c
@@ -76,7 +76,8 @@ _pthread_barrier_destroy(pthread_barrier_t *barrier)
 			return (EBUSY);
 		}
 		if (bar->b_refcount != 0) {
-			_thr_ucond_wait(&bar->b_cv, &bar->b_lock, NULL, 0);
+			_thr_ucond_wait(&bar->b_cv, &bar->b_lock, NULL,
+			    NULL, 0);
 			THR_UMUTEX_LOCK(curthread, &bar->b_lock);
 		} else
 			break;
@@ -158,7 +159,8 @@ _pthread_barrier_wait(pthread_barrier_t *barrier)
 		cycle = bar->b_cycle;
 		bar->b_refcount++;
 		do {
-			_thr_ucond_wait(&bar->b_cv, &bar->b_lock, NULL, 0);
+			_thr_ucond_wait(&bar->b_cv, &bar->b_lock, NULL,
+			    NULL, 0);
 			THR_UMUTEX_LOCK(curthread, &bar->b_lock);
 			/* test cycle to avoid bogus wakeup */
 		} while (cycle == bar->b_cycle);
diff --git a/lib/libthr/thread/thr_cond.c b/lib/libthr/thread/thr_cond.c
index f8c9118968bb..cce2ba7b6c3c 100644
--- a/lib/libthr/thread/thr_cond.c
+++ b/lib/libthr/thread/thr_cond.c
@@ -46,11 +46,14 @@ _Static_assert(sizeof(struct pthread_cond) <= THR_PAGE_SIZE_MIN,
 /*
  * Prototypes
  */
+int __pthread_cond_clockwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
+    clockid_t clockid, const struct timespec *abstime);
 int __pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
     const struct timespec * abstime);
 static int cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
 static int cond_wait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
-    const struct timespec *abstime, bool cancel);
+    clockid_t clockid, const struct timespec *abstime, bool cancel,
+    bool clockwait);
 static int cond_signal_common(pthread_cond_t *cond);
 static int cond_broadcast_common(pthread_cond_t *cond);
 
@@ -64,6 +67,7 @@ __weak_reference(__thr_cond_wait, __pthread_cond_wait);
 __weak_reference(_thr_cond_wait, _pthread_cond_wait);
 __weak_reference(__pthread_cond_timedwait, pthread_cond_timedwait);
 __weak_reference(_thr_cond_timedwait, _pthread_cond_timedwait);
+__weak_reference(__pthread_cond_clockwait, pthread_cond_clockwait);
 __weak_reference(_thr_cond_init, pthread_cond_init);
 __weak_reference(_thr_cond_init, _pthread_cond_init);
 __weak_reference(_thr_cond_destroy, pthread_cond_destroy);
@@ -202,9 +206,11 @@ _thr_cond_destroy(pthread_cond_t *cond)
  */
 static int
 cond_wait_kernel(struct pthread_cond *cvp, struct pthread_mutex *mp,
-    const struct timespec *abstime, bool cancel)
+    clockid_t clockid, const struct timespec *abstime, bool cancel,
+    bool clockwait)
 {
 	struct pthread *curthread;
+	struct _umtx_time utime;
 	int error, error2, recurse, robust;
 
 	curthread = _get_curthread();
@@ -219,8 +225,16 @@ cond_wait_kernel(struct pthread_cond *cvp, struct pthread_mutex *mp,
 
 	if (cancel)
 		_thr_cancel_enter2(curthread, 0);
-	error = _thr_ucond_wait(&cvp->kcond, &mp->m_lock, abstime,
-	    CVWAIT_ABSTIME | CVWAIT_CLOCKID);
+	if (clockwait) {
+		utime._timeout = *abstime;
+		utime._flags = UMTX_ABSTIME;
+		utime._clockid = clockid;
+		error = _thr_ucond_wait(&cvp->kcond, &mp->m_lock, NULL,
+		    &utime, CVWAIT_UMTX_TIME);
+	} else {
+		error = _thr_ucond_wait(&cvp->kcond, &mp->m_lock, abstime,
+		    NULL, CVWAIT_ABSTIME | CVWAIT_CLOCKID);
+	}
 	if (cancel)
 		_thr_cancel_leave(curthread, 0);
 
@@ -274,7 +288,7 @@ cond_wait_kernel(struct pthread_cond *cvp, struct pthread_mutex *mp,
 
 static int
 cond_wait_user(struct pthread_cond *cvp, struct pthread_mutex *mp,
-    const struct timespec *abstime, bool cancel)
+    clockid_t clockid, const struct timespec *abstime, bool cancel)
 {
 	struct pthread *curthread;
 	struct sleepqueue *sq;
@@ -315,7 +329,7 @@ cond_wait_user(struct pthread_cond *cvp, struct pthread_mutex *mp,
 
 		if (cancel)
 			_thr_cancel_enter2(curthread, 0);
-		error = _thr_sleep(curthread, cvp->kcond.c_clockid, abstime);
+		error = _thr_sleep(curthread, clockid, abstime);
 		if (cancel)
 			_thr_cancel_leave(curthread, 0);
 
@@ -350,7 +364,8 @@ cond_wait_user(struct pthread_cond *cvp, struct pthread_mutex *mp,
 
 static int
 cond_wait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
-    const struct timespec *abstime, bool cancel)
+    clockid_t clockid, const struct timespec *abstime, bool cancel,
+    bool clockwait)
 {
 	struct pthread	*curthread = _get_curthread();
 	struct pthread_cond *cvp;
@@ -359,6 +374,9 @@ cond_wait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
 
 	CHECK_AND_INIT_COND
 
+	if (!clockwait)
+		clockid = cvp->kcond.c_clockid;
+
 	if (*mutex == THR_PSHARED_PTR) {
 		mp = __thr_pshared_offpage(mutex, 0);
 		if (mp == NULL)
@@ -372,23 +390,25 @@ cond_wait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
 
 	if (curthread->attr.sched_policy != SCHED_OTHER ||
 	    (mp->m_lock.m_flags & (UMUTEX_PRIO_PROTECT | UMUTEX_PRIO_INHERIT |
-	    USYNC_PROCESS_SHARED)) != 0 || CV_PSHARED(cvp))
-		return (cond_wait_kernel(cvp, mp, abstime, cancel));
-	else
-		return (cond_wait_user(cvp, mp, abstime, cancel));
+	    USYNC_PROCESS_SHARED)) != 0 || CV_PSHARED(cvp)) {
+		return (cond_wait_kernel(cvp, mp, clockid, abstime, cancel,
+		    clockwait));
+	} else {
+		return (cond_wait_user(cvp, mp, clockid, abstime, cancel));
+	}
 }
 
 int
 _thr_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
 {
-	return (cond_wait_common(cond, mutex, NULL, false));
+	return (cond_wait_common(cond, mutex, 0, NULL, false, false));
 }
 
 int
 __thr_cond_wait(pthread_cond_t * __restrict cond,
     pthread_mutex_t * __restrict mutex)
 {
-	return (cond_wait_common(cond, mutex, NULL, true));
+	return (cond_wait_common(cond, mutex, 0, NULL, true, false));
 }
 
 int
@@ -400,18 +420,30 @@ _thr_cond_timedwait(pthread_cond_t * __restrict cond,
 	    abstime->tv_nsec >= 1000000000)
 		return (EINVAL);
 
-	return (cond_wait_common(cond, mutex, abstime, false));
+	return (cond_wait_common(cond, mutex, 0, abstime, false, false));
 }
 
 int
 __pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
-		       const struct timespec *abstime)
+    const struct timespec *abstime)
 {
 	if (abstime == NULL || abstime->tv_sec < 0 || abstime->tv_nsec < 0 ||
 	    abstime->tv_nsec >= 1000000000)
 		return (EINVAL);
 
-	return (cond_wait_common(cond, mutex, abstime, true));
+	return (cond_wait_common(cond, mutex, 0, abstime, true, false));
+}
+
+int
+__pthread_cond_clockwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
+    clockid_t clockid, const struct timespec *abstime)
+{
+
+	if (abstime == NULL || abstime->tv_sec < 0 || abstime->tv_nsec < 0 ||
+	    abstime->tv_nsec >= 1000000000)
+		return (EINVAL);
+
+	return (cond_wait_common(cond, mutex, clockid, abstime, true, true));
 }
 
 static int
diff --git a/lib/libthr/thread/thr_umtx.c b/lib/libthr/thread/thr_umtx.c
index db63017a6a13..edd0dacdaff1 100644
--- a/lib/libthr/thread/thr_umtx.c
+++ b/lib/libthr/thread/thr_umtx.c
@@ -28,6 +28,7 @@
 
 #include "thr_private.h"
 #include "thr_umtx.h"
+#include <assert.h>
 
 void
 _thr_umutex_init(struct umutex *mtx)
@@ -242,20 +243,35 @@ _thr_ucond_init(struct ucond *cv)
 
 int
 _thr_ucond_wait(struct ucond *cv, struct umutex *m,
-    const struct timespec *timeout, int flags)
+    const struct timespec *timeout, const struct _umtx_time *utimep, int flags)
 {
 	struct pthread *curthread;
-
-	if (timeout != NULL && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 &&
-	    timeout->tv_nsec <= 0))) {
+	const struct timespec *ts;
+	void *arg2;
+
+	assert(timeout == NULL || utimep == NULL);
+	if (timeout != NULL) {
+		ts = timeout;
+		arg2 = __DECONST(void *, timeout);
+		assert((flags & CVWAIT_UMTX_TIME) == 0);
+	} else if (utimep != NULL) {
+		ts = &utimep->_timeout;
+		arg2 = __DECONST(void *, utimep);
+		assert((flags & CVWAIT_UMTX_TIME) != 0);
+	} else {
+		ts = NULL;
+		arg2 = NULL;
+		assert((flags & CVWAIT_UMTX_TIME) == 0);
+	}
+	if (ts != NULL && (ts->tv_sec < 0 || (ts->tv_sec == 0 &&
+	    ts->tv_nsec <= 0))) {
 		curthread = _get_curthread();
 		_thr_umutex_unlock(m, TID(curthread));
                 return (ETIMEDOUT);
 	}
-	return (_umtx_op_err(cv, UMTX_OP_CV_WAIT, flags, m,
-	    __DECONST(void *, timeout)));
+	return (_umtx_op_err(cv, UMTX_OP_CV_WAIT, flags, m, arg2));
 }
- 
+
 int
 _thr_ucond_signal(struct ucond *cv)
 {
diff --git a/lib/libthr/thread/thr_umtx.h b/lib/libthr/thread/thr_umtx.h
index 89f70e4ab14f..4e1c08ca64e8 100644
--- a/lib/libthr/thread/thr_umtx.h
+++ b/lib/libthr/thread/thr_umtx.h
@@ -59,7 +59,8 @@ int _thr_umtx_timedwait_uint(volatile u_int *mtx, u_int exp, int clockid,
 	const struct timespec *timeout, int shared) __hidden;
 int _thr_umtx_wake(volatile void *mtx, int count, int shared) __hidden;
 int _thr_ucond_wait(struct ucond *cv, struct umutex *m,
-        const struct timespec *timeout, int flags) __hidden;
+        const struct timespec *timeout, const struct _umtx_time *utimep,
+	int flags) __hidden;
 void _thr_ucond_init(struct ucond *cv) __hidden;
 int _thr_ucond_signal(struct ucond *cv) __hidden;
 int _thr_ucond_broadcast(struct ucond *cv) __hidden;

From nobody Mon Aug  3 00:25:36 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBS6Ztpz6mj42
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 00:25:36 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hCyBS22k4z4P3p
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:36 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785716736;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=5uqHjgCRjrYc0bXUlVKnvN3s0teGYijJf9b45eiqxzo=;
	b=ZT4qp5q+hfAXDKdUNkBTW5zgA6fpntLyKkuueei/LBk6IsGiEXNYLWXPP+x1u9lRh+NcLd
	Ys9J839+PWTKMLFV2JHa2yjHHx17waNHuKxB/8rH8bfp9Tkl6U6YBptFVRssMPk/YE9J5r
	p3LGKCvOdjurXklxc3qexL7HEUWnKfrMl88M3kbgi2JXPv3q2IaFDVpHBl5RfVUKac7zGB
	6j/t3lyIKJ0zq2NzerTVFOx0+KhLdoIQYFNCQ9eXBVgggY52qlcTlWVEvx3rmL3M2tzzNF
	g2cz7T9OScAdC4KZGTKmtqmtXmBx0F4KRmvV2tjyH/189zBNcdJxhiV9NgqhnQ==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785716736; a=rsa-sha256; cv=none;
	b=n/fYsB69ThBocuJ/5iLFRVljCWlHE6Vw3ejbrHL65x7qvIA0Nnx8NW0I5zr99ivag288O/
	tT1bNeiQ91hSwzgabvZ+vtTf0uW76EkwY/uuXiFCWcnMJ7UyVWj6BgTNTn9Mgcuh79b4on
	KFWmrOqKlh1lfG9K6p/TuUyEdv4hYPjUr7WLea/7rWrb6oUx8Rx5lDxs66dypkO63LVYG6
	X6GUdocIEFTF3YN2q7ggRav4XH7UECDO+iJoNs3n/zoXpVySEuIJ7zoUuFPxD8pLStz991
	JWbrmVwrtPfOjTzQLSUcDk1fVfjrcdmWpES+b9n+xmeRrX75NzvFrz1Xelr21w==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785716736;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=5uqHjgCRjrYc0bXUlVKnvN3s0teGYijJf9b45eiqxzo=;
	b=f/lzuAjVOy/PMUoJIKn9VHuHklKVT6kHVWvRXGuB2AFDKy/SMBWp3uLaZNFfAAcM4ifIfz
	5bwRsfaM8et1W2v7jv8bBweguzEIc9adAcnvjz6FV0nX3jJWnks+CWqcO8kkwUapivZCpB
	OdsKnCkKKp9MBH+QbPoD5RHwN3zwbHKKQq62nhEzyimP2grjy5AYbdFkkVgFjavX0f/fUl
	SqxKRh4KFb6C0Hyp2r6FNeQGh6HcnzdJmpTICbfZsXAgPm92ezC5aWifC/0hrP4+Ta3BH/
	WkmBuZ1CSDcZ1Vcs4enM1gdRbsncOFqVK8/s+Iezps7SugrxyN0shrZaNlacVw==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBS0q1szdX0
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:36 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1c70b
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 00:25:36 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Konstantin Belousov <kib@FreeBSD.org>
Subject: git: d62a413e76bd - stable/15 - pthread_cond_timedwait.3: document pthread_cond_clockwait(3)
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kib
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: d62a413e76bdfc8a9c92d4c5b5fea89bb132811c
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 00:25:36 +0000
Message-Id: <6a6fe000.1c70b.662a4f57@gitrepo.freebsd.org>

The branch stable/15 has been updated by kib:

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

commit d62a413e76bdfc8a9c92d4c5b5fea89bb132811c
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-25 23:56:03 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-03 00:23:17 +0000

    pthread_cond_timedwait.3: document pthread_cond_clockwait(3)
    
    (cherry picked from commit e7015a3834abe0956e9a8ec6ec4b8e75ea7d71ab)
---
 share/man/man3/Makefile                 |  1 +
 share/man/man3/pthread_cond_timedwait.3 | 32 ++++++++++++++++++++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/share/man/man3/Makefile b/share/man/man3/Makefile
index cae79b8f8182..2a4dbc426d05 100644
--- a/share/man/man3/Makefile
+++ b/share/man/man3/Makefile
@@ -510,6 +510,7 @@ PTHREAD_MLINKS+=pthread_condattr.3 pthread_condattr_destroy.3 \
 		pthread_condattr.3 pthread_condattr_setclock.3 \
 		pthread_condattr.3 pthread_condattr_getpshared.3 \
 		pthread_condattr.3 pthread_condattr_setpshared.3
+PTHREAD_MLINKS+=pthread_cond_timedwait.3 pthread_cond_clockwait.3
 PTHREAD_MLINKS+=pthread_getconcurrency.3 pthread_setconcurrency.3
 PTHREAD_MLINKS+=pthread_multi_np.3 pthread_single_np.3
 PTHREAD_MLINKS+=pthread_mutexattr.3 pthread_mutexattr_destroy.3 \
diff --git a/share/man/man3/pthread_cond_timedwait.3 b/share/man/man3/pthread_cond_timedwait.3
index 28cc33da1ca2..5a47abed7d99 100644
--- a/share/man/man3/pthread_cond_timedwait.3
+++ b/share/man/man3/pthread_cond_timedwait.3
@@ -41,10 +41,20 @@
 .Fa "pthread_mutex_t *mutex"
 .Fa "const struct timespec *abstime"
 .Fc
+.In time.h
+.Ft int
+.Fo pthread_cond_clockwait
+.Fa "pthread_cond_t *cond"
+.Fa "pthread_mutex_t *mutex"
+.Fa "clockid_t clockid"
+.Fa "const struct timespec *abstime"
+.Fc
 .Sh DESCRIPTION
 The
 .Fn pthread_cond_timedwait
-function atomically blocks the current thread waiting on the condition
+and
+.Fn pthread_cond_clockwait
+functions atomically blocks the current thread waiting on the condition
 variable specified by
 .Fa cond ,
 and releases the mutex specified by
@@ -59,10 +69,22 @@ time specified in
 and the current thread reacquires the lock on
 .Fa mutex .
 .Pp
-The clock used to measure
+The
+.Fn pthread_cond_clockwait
+function is identical to
+.Fn pthread_cond_timedwait ,
+except in the way the clock to measure time-out is named.
+For the
+.Fn pthread_cond_timedwait
+function, the clock used to measure
 .Fa abstime
 can be specified during creation of the condition variable using
 .Xr pthread_condattr_setclock 3 .
+For the
+.Fn pthread_cond_clockwait
+function, the clock is specified by the
+.Fa clockid
+argument.
 .Sh RETURN VALUES
 If successful, the
 .Fn pthread_cond_timedwait
@@ -101,3 +123,9 @@ The
 .Fn pthread_cond_timedwait
 function conforms to
 .St -p1003.1-96 .
+The
+.Fn pthread_cond_clockwait
+function conforms to
+.St -p1003.1-2024
+and appeared in
+.Fx 16.0 .

From nobody Mon Aug  3 00:25:35 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBR4B1hz6mjKs
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 00:25:35 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hCyBR24Sdz4P3n
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:35 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785716735;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=kL3vzkh8SNfUBeElVlyqo2unraJNfpo91avYRcRmdWg=;
	b=DVxh8cz2TAd/s1zaLvppuoCymnAOlRuI2SLaCvGPGKDuIJXnj6B0dJ1GzKC4v+04huaxu2
	RzK7hzFM0usp98Ps8jhjCNPSL10h6Ek5tyTHiGYV+PRQBKetl9Hw1X1sPNPBbfI9cCXN/A
	WcAFdSNQFUTzV0MP2+MMaJG16Q03Mn+RaCdV5SC1mz+eNIPfkeFEiUOVTKCPrz9hBVrtqD
	VtbKz6lBeYqazXAIl93DjJzmFcQ/vU4GU7gbrauac/3Ac631rGC7qeUz3edjhhWgiFEKfn
	4WFt9hJxubJ9g2GzbdCix9HYOsW+1gEM5T9z8P8tUWkoatlSvDv9TUkPMlZggQ==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785716735; a=rsa-sha256; cv=none;
	b=WMztaSbnF1MH6mB/su57rdaBubpzbd7MI3fu62OLFI1Y/QPi6Jme9zgVBXqGE9gmG0dZCe
	c6bND5lUvwlDMBpcFK5YSavD5ANjB/8wemf2BG3GYSouatN9Fixtdb4HEfQCMyBw6MHzV2
	JXr/z1EMRqAKPZn7QrXnHgnLlq7cd2/Si9C37Np+Bu0vHSJ/U4sJsb6bCt4cdgyGT1RzrY
	6jctvbyQHSxLI2QJNoyv1rNc7s6rrPzFIsFIX4d/dduVlyPPfzj2xFLzqYj5DX6bNt8Nr6
	MYgDdnsFbgWZGaY44JGY5++A3DtEDoKh3FRj41l2ubgqBs5Cy09iEZ3HForkIQ==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785716735;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=kL3vzkh8SNfUBeElVlyqo2unraJNfpo91avYRcRmdWg=;
	b=B4iZRTi9VqtUm0FrElAy02HM90/C5OwxyuAs6OzDPy+ajmCZSNMnWYEz3bOuUexaE2pefx
	JYN+w03XHjMmagd4tV1zdyG3KJ7AXATUtYJQIQ5y0pQsQfObS2PuiexFiTzQOlZXfyuCRz
	sCS97aBJc+sDxkipwByzPCuGt14j6jXKhHnsJLI3UdXIDUm84SffFPH+unNNmQRYnUZ25Q
	6YeoJHuYLjiQHZb5GpONzqQegjwpcUkP2LuSGAURqHvDqRwGkcL2thtL3jyIqTVlmyLY93
	NxD1cfi7b1iRyHZNl53SMl+KLhmkAEixGkJisMuV2MTGgBbbryqxIFOagSFGgQ==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBR0T0PzdWy
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:35 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1ccd2
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 00:25:35 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Konstantin Belousov <kib@FreeBSD.org>
Subject: git: ff36771c13e9 - stable/15 - pthread_cond_timedwait.3: use .Fo/.Fc for long arguments list
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kib
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: ff36771c13e993862b6a5c38462f870825b58068
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 00:25:35 +0000
Message-Id: <6a6fdfff.1ccd2.462c700d@gitrepo.freebsd.org>

The branch stable/15 has been updated by kib:

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

commit ff36771c13e993862b6a5c38462f870825b58068
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-25 23:53:11 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-03 00:23:16 +0000

    pthread_cond_timedwait.3: use .Fo/.Fc for long arguments list
    
    (cherry picked from commit 6d3db07a2e2f4288b7e54af8e8371f9a022e751f)
---
 share/man/man3/pthread_cond_timedwait.3 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/share/man/man3/pthread_cond_timedwait.3 b/share/man/man3/pthread_cond_timedwait.3
index d955bf8546cd..28cc33da1ca2 100644
--- a/share/man/man3/pthread_cond_timedwait.3
+++ b/share/man/man3/pthread_cond_timedwait.3
@@ -36,7 +36,11 @@
 .Sh SYNOPSIS
 .In pthread.h
 .Ft int
-.Fn pthread_cond_timedwait "pthread_cond_t *cond" "pthread_mutex_t *mutex" "const struct timespec *abstime"
+.Fo pthread_cond_timedwait
+.Fa "pthread_cond_t *cond"
+.Fa "pthread_mutex_t *mutex"
+.Fa "const struct timespec *abstime"
+.Fc
 .Sh DESCRIPTION
 The
 .Fn pthread_cond_timedwait

From nobody Mon Aug  3 00:25:37 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBT4P2sz6mjG5
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 00:25:37 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hCyBT2zTGz4NsD
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:37 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785716737;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=5qRuwyR1twbNDS6JO8/hC3X+7hG7T05Tr/WaXggmgNg=;
	b=TyUqvYCGth83oFAB3HHziwFi1vbmFUty7dLt4twJkGT24IvlDPjdwtrSi99n/gI2P7W6u0
	ISG5ZmsvNdbMnNvaHZirr6Naea3YMdFyKRi3I6ZFENaiU7+2wUsDDO8efaWcEUZy7oKxUy
	6VZRrWndCdmIQgk88B/kdLI3sE5kuq9653oNUNrZxFjZyxPKpBa3gMU6C3vlvgHeHPWuaN
	Jtnq7el3l43T9DykkApYVbsQl5stNqmVNTYhtFRspOh3QYiYNCFyJmaqRyUSlULbEqRiKk
	LToJa3EtBfOHQ4fDat2RVTxIRBPjqkpv0tNHOxij7dw6Adi7pswqb7UhzTr3gQ==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785716737; a=rsa-sha256; cv=none;
	b=KAhEJv5Ew/f9hHzQqNoktXxR+9P5PkYxgk0F67saUcXJ2fGN4sUOJVFHSo+eEJPAhOBofg
	ODAw2K9ScQnGJXkGjU7NKxV/LmzF2qrleu2g4+HfDo/mh9WwsUZ6T28r4UHCOLc0tYUfgK
	YYB7LAG89jBXSqOpdISsDaYhv1qRIc2q5TUlu1pOP5JtK5TZoiWilYnbDe0rs/Dy7uPpCo
	CiCWhu+YJnF5wjVtr3XKSfZm7mPu5Y1/yRgXJqxQL91dAiKS6Fjlxh1coPfTznVLqKoeJ+
	ITVqIy0vIa6xi9bhDSbKDfro6Cxq+yGA288VooJlf6ZkcOZgkt+pE13bZXpyDQ==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785716737;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=5qRuwyR1twbNDS6JO8/hC3X+7hG7T05Tr/WaXggmgNg=;
	b=qTNdZXQsTI0JlB5ka60bI2Dz//a0IoTPX68DFY6+LUQGFXON4r7vAKebh2dD8aXkKTjB6U
	bpQuPVLudlzwIWtY6UgzHsaJZLWK2A7n81U8yXna/fectsO5+NUegKxo0l0OdO521y5NeI
	2iW/zu8a4H/Nh0azG+HPpvMve/MnuaY4ZM9m+0r/mMFMOPB5hyPVoGMpzKVuVw0tepG62B
	/KUxUlts+TXvwIkE4ypiuq/NZekuSZKVPkjEAl3BYpfbVstnKCW0a/0e23Ca3ywUdzM7ib
	kVKpUprEn2Gno2U3MfAUlBdlTZGshHNIbHkaj+UZg00rV0e6mmmyy7Q9R31X3w==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBT1cvHzdX1
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:37 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1c492
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 00:25:37 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Konstantin Belousov <kib@FreeBSD.org>
Subject: git: 7d243813ca63 - stable/15 - tests/libpthread: add pthread_cond_clockwait(3) tests
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kib
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 7d243813ca639d464b3c7baa1953bc41f89031f9
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 00:25:37 +0000
Message-Id: <6a6fe001.1c492.4fa0ecf7@gitrepo.freebsd.org>

The branch stable/15 has been updated by kib:

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

commit 7d243813ca639d464b3c7baa1953bc41f89031f9
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-26 01:59:05 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-03 00:23:17 +0000

    tests/libpthread: add pthread_cond_clockwait(3) tests
    
    (cherry picked from commit 10ea2300bf29cdcaf12182e8b722f6becb0da1fb)
---
 contrib/netbsd-tests/lib/libpthread/t_condwait.c | 112 +++++++++++++++++++----
 1 file changed, 93 insertions(+), 19 deletions(-)

diff --git a/contrib/netbsd-tests/lib/libpthread/t_condwait.c b/contrib/netbsd-tests/lib/libpthread/t_condwait.c
index 5fdebe868f3f..ead113b7bd97 100644
--- a/contrib/netbsd-tests/lib/libpthread/t_condwait.c
+++ b/contrib/netbsd-tests/lib/libpthread/t_condwait.c
@@ -47,25 +47,41 @@ __RCSID("$NetBSD: t_condwait.c,v 1.8 2019/08/11 11:42:23 martin Exp $");
 
 static const int debug = 1;
 
+struct run_param {
+	clockid_t clck;
+	bool clockwait;
+	bool pshared;
+};
+
 static void *
 run(void *param)
 {
 	struct timespec ts, to, te, twmin, twmax;
-	clockid_t clck;
-	pthread_condattr_t attr;
+	struct run_param *rp;
+	pthread_condattr_t cattr;
 	pthread_cond_t cond;
-	pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+	pthread_mutexattr_t mattr;
+	pthread_mutex_t m;
 	int ret = 0;
 
-
-	clck = *(clockid_t *)param;
-	PTHREAD_REQUIRE(pthread_condattr_init(&attr));
-	PTHREAD_REQUIRE(pthread_condattr_setclock(&attr, clck));
-	pthread_cond_init(&cond, &attr);
+	rp = param;
+
+	PTHREAD_REQUIRE(pthread_condattr_init(&cattr));
+	PTHREAD_REQUIRE(pthread_mutexattr_init(&mattr));
+	if (!rp->clockwait)
+		PTHREAD_REQUIRE(pthread_condattr_setclock(&cattr, rp->clck));
+	if (rp->pshared) {
+		PTHREAD_REQUIRE(pthread_condattr_setpshared(&cattr,
+		    PTHREAD_PROCESS_SHARED));
+		PTHREAD_REQUIRE(pthread_mutexattr_setpshared(&mattr,
+		    PTHREAD_PROCESS_SHARED));
+	}
+	pthread_mutex_init(&m, &mattr);
+	pthread_cond_init(&cond, &cattr);
 
 	ATF_REQUIRE_EQ((ret = pthread_mutex_lock(&m)), 0);
 
-	ATF_REQUIRE_EQ(clock_gettime(clck, &ts), 0);
+	ATF_REQUIRE_EQ(clock_gettime(rp->clck, &ts), 0);
 	to = ts;
 
 	if (debug)
@@ -74,10 +90,14 @@ run(void *param)
 
 	ts.tv_sec += WAITTIME;	/* Timeout wait */
 
-	switch (ret = pthread_cond_timedwait(&cond, &m, &ts)) {
+	if (rp->clockwait)
+		ret = pthread_cond_clockwait(&cond, &m, rp->clck, &ts);
+	else
+		ret = pthread_cond_timedwait(&cond, &m, &ts);
+	switch (ret) {
 	case ETIMEDOUT:
 		/* Timeout */
-		ATF_REQUIRE_EQ(clock_gettime(clck, &te), 0);
+		ATF_REQUIRE_EQ(clock_gettime(rp->clck, &te), 0);
 		timespecsub(&te, &to, &to);
 		if (debug) {
 			printf("timeout: %lld.%09ld sec\n",
@@ -113,12 +133,18 @@ run(void *param)
 }
 
 static void
-cond_wait(clockid_t clck, const char *msg) {
+cond_wait(clockid_t clck, bool clockwait, bool pshared, const char *msg)
+{
 	pthread_t child;
+	struct run_param rp;
+
+	rp.clck = clck;
+	rp.clockwait = clockwait;
+	rp.pshared = pshared;
 
 	if (debug)
 		printf( "**** %s clock wait starting\n", msg);
-	ATF_REQUIRE_EQ(pthread_create(&child, NULL, run, &clck), 0);
+	ATF_REQUIRE_EQ(pthread_create(&child, NULL, run, &rp), 0);
 	ATF_REQUIRE_EQ(pthread_join(child, NULL), 0); /* wait for terminate */
 	if (debug)
 		printf( "**** %s clock wait ended\n", msg);
@@ -127,28 +153,76 @@ cond_wait(clockid_t clck, const char *msg) {
 ATF_TC(cond_wait_real);
 ATF_TC_HEAD(cond_wait_real, tc)
 {
-	atf_tc_set_md_var(tc, "descr", "Checks pthread_cond_timedwait "
-	    "with CLOCK_REALTIME");
+	atf_tc_set_md_var(tc, "descr",
+	    "Checks pthread_cond_timedwait with CLOCK_REALTIME");
 }
 
 ATF_TC_BODY(cond_wait_real, tc) {
-	cond_wait(CLOCK_REALTIME, "CLOCK_REALTIME");
+	cond_wait(CLOCK_REALTIME, false, false, "CLOCK_REALTIME");
 }
 
 ATF_TC(cond_wait_mono);
 ATF_TC_HEAD(cond_wait_mono, tc)
 {
-	atf_tc_set_md_var(tc, "descr", "Checks pthread_cond_timedwait "
-	    "with CLOCK_MONOTONIC");
+	atf_tc_set_md_var(tc, "descr",
+	    "Checks pthread_cond_timedwait with CLOCK_MONOTONIC");
 }
 
 ATF_TC_BODY(cond_wait_mono, tc) {
-	cond_wait(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
+	cond_wait(CLOCK_MONOTONIC, false, false, "CLOCK_MONOTONIC");
+}
+
+ATF_TC(cond_clockwait_real);
+ATF_TC_HEAD(cond_clockwait_real, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Checks pthread_cond_clockwait with CLOCK_REALTIME");
+}
+
+ATF_TC_BODY(cond_clockwait_real, tc) {
+	cond_wait(CLOCK_REALTIME, true, false, "CLOCK_REALTIME");
+}
+
+ATF_TC(cond_clockwait_mono);
+ATF_TC_HEAD(cond_clockwait_mono, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Checks pthread_cond_clockwait with CLOCK_MONOTONIC");
+}
+
+ATF_TC_BODY(cond_clockwait_mono, tc) {
+	cond_wait(CLOCK_MONOTONIC, true, false, "CLOCK_MONOTONIC");
+}
+
+ATF_TC(cond_klockwait_real);
+ATF_TC_HEAD(cond_klockwait_real, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+    "Checks pthread_cond_clockwait with CLOCK_REALTIME calling kernel");
+}
+
+ATF_TC_BODY(cond_klockwait_real, tc) {
+	cond_wait(CLOCK_REALTIME, true, true, "CLOCK_REALTIME");
+}
+
+ATF_TC(cond_klockwait_mono);
+ATF_TC_HEAD(cond_klockwait_mono, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+    "Checks pthread_cond_clockwait with CLOCK_MONOTONIC calling kernel");
+}
+
+ATF_TC_BODY(cond_klockwait_mono, tc) {
+	cond_wait(CLOCK_MONOTONIC, true, true, "CLOCK_MONOTONIC");
 }
 
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, cond_wait_real);
 	ATF_TP_ADD_TC(tp, cond_wait_mono);
+	ATF_TP_ADD_TC(tp, cond_clockwait_real);
+	ATF_TP_ADD_TC(tp, cond_clockwait_mono);
+	ATF_TP_ADD_TC(tp, cond_klockwait_real);
+	ATF_TP_ADD_TC(tp, cond_klockwait_mono);
 	return atf_no_error();
 }

From nobody Mon Aug  3 00:25:38 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBV55Ysz6mj43
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 00:25:38 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hCyBV3ZrNz4P1F
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:38 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785716738;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ssGXTnp60XzCX0dXQQzEpCjn8LflnlCUkjZpxbSHSmY=;
	b=JiiPAr7BuI7ACSIL2CJkeamuTvctIfKuCuWfWyTBT9uq2ZsjGlOXwwKQ5QPcHzW1Q70cmK
	HQte4+dlSLamFouRDqDbg7P7juC2J6QzKhlmD1j0JUEafjTZo945LjA3QvljfSOJlaSOI6
	nZBIT7fLOSh0YxP4cALPc4sTdpwNcO6pzbGsZ1+GtjFTVjgtuRTZHCKoULAKjlwkGqL9zb
	ayGSG+JdpwlS0i9a7tqcF2nO4JB+Sgf8tgEazF9Bj+zpgXD9JhQgdGMTWjW67FU1Sgbnl4
	fhp2ZhgGA9aqjm4B0AnEHQXUXBFXU8HJejeHYzWHTiVkvJhtOS/em7mUhE56/w==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785716738; a=rsa-sha256; cv=none;
	b=Q3Jx5kVcAjOdATAlFbfYo8PvURLmB3IqoZstKg4bpKD9OF/ST18AsPc4HvtTIocHTIhrnA
	Nsn5TYQ7WAIl3TIkWYIcLcRCcXJ+TMSKPT9y2Lhvo2Elq/SxflQTtxC1l/5smw0nPg1EyH
	j3TI2fv5MRqlkdiGoSlixmmnNPebqS+5U+gSpGdG2j1E4soYoWOjFRm3SeiqHrahbWB4Fb
	DvKhkVGwKgm+krCuNk2QgcXtlxasbCSDnrfRaNC1BHf019nR/dstCGA+uWvaXGzIalTwzR
	0qi9kRsivhyur0R5uVdVGzRkmJreesozm1KDP+XY9ji1NZgaqAjKGXiESVrvgQ==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785716738;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ssGXTnp60XzCX0dXQQzEpCjn8LflnlCUkjZpxbSHSmY=;
	b=e3p/kB+whQ+mGcU7VC28LUsglN+j0NJmmAXnVJo+qHQUzDT9fOXP0oK71KgSdZlrEKR62Y
	E1hk2mO51zvoCvKz3u7fbb9DPlEEzeBUevSvIkYyKJZxcPCYLwJiEdWhXfiXJkDiEUYcW1
	iYtoHbokgZAozoZUcXiupEKGQERl4L1iCQhQklTGleErNTbi4CuI4qDOha/ysim6lWOWcW
	Ds4dhbtogds2Le0uMCmgjYfrGlH3h3v3e4995SxR+mKbxv7KlLKkx1F6xGMhTcnE1p0jkk
	mNH5uAyZJyzy1W8sojSDPB4f/LmQvQE0NsmJJJAEfJeNpa8Ey4IcEbt0JjKdBg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hCyBV2NqmzdjW
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 00:25:38 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1cc14
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 00:25:38 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Konstantin Belousov <kib@FreeBSD.org>
Subject: git: 0aa72376d73b - stable/15 - geom_zero(4): reset the uio vector on each uiomove()
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kib
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 0aa72376d73bef2612f308a6de8b33e9584894de
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 00:25:38 +0000
Message-Id: <6a6fe002.1cc14.7ffcf389@gitrepo.freebsd.org>

The branch stable/15 has been updated by kib:

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

commit 0aa72376d73bef2612f308a6de8b33e9584894de
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-26 21:45:07 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-03 00:23:17 +0000

    geom_zero(4): reset the uio vector on each uiomove()
    
    PR:     297062
    
    (cherry picked from commit 34ca5a9e7362b0c820fe339daa2b8d06c58b6fea)
---
 sys/geom/zero/g_zero.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/sys/geom/zero/g_zero.c b/sys/geom/zero/g_zero.c
index 325e12633a31..8244df77b257 100644
--- a/sys/geom/zero/g_zero.c
+++ b/sys/geom/zero/g_zero.c
@@ -83,11 +83,6 @@ g_zero_fill_pages(struct bio *bp)
 	size_t length;
 	vm_offset_t offset;
 
-	aiovec.iov_base = g_zero_buffer;
-	aiovec.iov_len = PAGE_SIZE;
-	auio.uio_iov = &aiovec;
-	auio.uio_iovcnt = 1;
-	auio.uio_offset = 0;
 	auio.uio_segflg = UIO_SYSSPACE;
 	auio.uio_rw = UIO_WRITE;
 	auio.uio_td = curthread;
@@ -101,6 +96,12 @@ g_zero_fill_pages(struct bio *bp)
 	bp->bio_resid = bp->bio_length;
 	offset = bp->bio_ma_offset & PAGE_MASK;
 	for (int i = 0; i < bp->bio_ma_n && bp->bio_resid > 0; i++) {
+		aiovec.iov_base = g_zero_buffer;
+		aiovec.iov_len = PAGE_SIZE;
+		auio.uio_iov = &aiovec;
+		auio.uio_iovcnt = 1;
+		auio.uio_offset = 0;
+
 		length = MIN(PAGE_SIZE - offset, bp->bio_resid);
 		auio.uio_resid = length;
 

From nobody Mon Aug  3 01:05:02 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hCz3z2vkfz6mmk6
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 01:05:03 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hCz3z0fmhz3GgG
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 01:05:03 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785719103;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=YAVMRKYnxQl8UarTKrMld1g70pGw45q42hoPoZdCGRM=;
	b=wUNZV9Jhq+YZeMX+kPTYwCNZO6Ki7nuyjGbI1QfHvaGkI9a9wpF5Kf1D06tdQSk1ufCWY3
	ziEZ/PriIhTk7S3xLRiak3riuWDCiAeLS/ugSmXw2JxNqLdAZo/NCcxZ7TDsqfPsyYLPDG
	30xJd3MUtEyfv2hD7CFNXsN5HcqKatGiq8rQiyYNZ9JqbExPZV6e/WHSPwBC9NQOd9SLHO
	clUhfsx55RFPpVLtaaGcjOzzgbgdX/lHS7DE+HXZL4Im8CHaW9uQjIlY3SMHV+s11LFTFM
	K/oqeM7bxZlO2xnROh3hsYzSL9MM5yJmbqZyF+Fdm2LmmJ2w8sdacEcAjTdYqg==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785719103; a=rsa-sha256; cv=none;
	b=gzTnXIOzMcExmTkFxkZxaYYZBMwgGFuORZoKHAbyho7IvCka0rmUrho0FoDESdAT+AkWbE
	TpMuGw+yKYVhXjdToNl/l4g1OQoXMHf3IF6HwCnq7k2cYjB4Y6Eb3ayT6k3WPks/faw1uW
	vZmF44NaaeKDLE6zLaKurn/5skg/Izzl4BE8ULw6TvTruajiQjGbyHivqK1uD3bOIVBAvu
	oeXJ3fjdnWVlz/Fu+0EwZNb1XJtFCw+Nb+Zta1NqIzcG0Jhbv/2VuSl2OjV9v5m9R7n1PR
	hRgBazv5lAFbq1R51XasiQxpJzK0/y0FPR0rmn4Q9bGsUTHlGlUBzu64smmzbw==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785719103;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=YAVMRKYnxQl8UarTKrMld1g70pGw45q42hoPoZdCGRM=;
	b=vVvTvtzo7VbE3O9jXdxBr3D7+JFdU2X2a4BNWvSWs/4wXnNYuvy08yCn4/o+OoLK5PAHPz
	KnBdC+01drOZMnYVxDb8cAu0VdvbmEeA1E5AzY/mjcg/XO/JN/ChJhs+MPnaHmDcftY+Q8
	BEzhduyGsR+Xqhs/2HMA8nN4ZPr5xk6kds+iG2rNNlEiPARtLiuKq+2pX2nQLRW2m4qRyr
	cA4EqHeHW7Gf3rP8fYIbDhVREt3B5+zJpNqAhFsEpPlUuHxBVzw9sjooUH8ovsquiiqiVk
	Pv/jJnS4hQrx1mr6hk1t4kGmbETQq9KUvi33KMg91HGoJimbjHN/j2p3Fc4Wwg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hCz3y6KzQzfY8
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 01:05:02 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1f9ca
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 01:05:02 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Rick Macklem <rmacklem@FreeBSD.org>
Subject: git: 25d1f68e513b - stable/15 - nfs_commonkrpc.c: Handle NFSERR_DELAY for Sequence correctly
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: rmacklem
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 25d1f68e513bb567497de26cb65840f434f227ee
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 01:05:02 +0000
Message-Id: <6a6fe93e.1f9ca.28e6bb60@gitrepo.freebsd.org>

The branch stable/15 has been updated by rmacklem:

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

commit 25d1f68e513bb567497de26cb65840f434f227ee
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2026-07-27 14:16:29 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2026-08-03 01:01:39 +0000

    nfs_commonkrpc.c: Handle NFSERR_DELAY for Sequence correctly
    
    Unlike RFC5661 (the original NFSv4.1 RFC), RFC8881 specifies
    that a NFS4ERR_DELAY reply to the SEQUENCE operation requires
    a reply using the same slot/sequence#.
    
    This patch fixes handling of this case, so it conforms to
    RFC8881.
    
    (cherry picked from commit 6901cbbd5a2c00d378a7f87426b36d6ee6ce0aa2)
---
 sys/fs/nfs/nfs_commonkrpc.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/sys/fs/nfs/nfs_commonkrpc.c b/sys/fs/nfs/nfs_commonkrpc.c
index f30ae7cbffa2..dd189a4aa909 100644
--- a/sys/fs/nfs/nfs_commonkrpc.c
+++ b/sys/fs/nfs/nfs_commonkrpc.c
@@ -1145,7 +1145,20 @@ tryagain:
 			if ((nmp != NULL && i == NFSV4OP_SEQUENCE && j != 0) ||
 			   (clp != NULL && i == NFSV4OP_CBSEQUENCE && j != 0)) {
 				NFSCL_DEBUG(1, "failed seq=%d\n", j);
-				if (sep != NULL && i == NFSV4OP_SEQUENCE &&
+				KASSERT(slot == -1, ("newnfs_request: slot not"
+				    " -1"));
+				/*
+				 * RFC8881 (unlike RFC5661) specifies that a
+				 * NFSERR_DELAY reply to SEQUENCE is handled
+				 * by a retry with same slot/sequence#.
+				 * (Although not explicit, I will assume this
+				 *  applies to CB_SEQUENCE as well.)
+				 */
+				if (j == NFSERR_DELAY) {
+					nd->nd_repstat =
+					    NFSERR_RETRYUNCACHEDREP;
+				} else if (sep != NULL &&
+				    i == NFSV4OP_SEQUENCE &&
 				    j == NFSERR_SEQMISORDERED) {
 					mtx_lock(&sep->nfsess_mtx);
 					sep->nfsess_badslots |=

From nobody Mon Aug  3 01:10:43 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hCzBd0pdkz6mn0v
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 01:10:49 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hCzBc5pbTz3HCk
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 01:10:48 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785719448;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=p8ZPvyAfqDPTEjgklq0wEqyoLYB5ImajiYz7+Rjj2U0=;
	b=uz4pyZPm0elz/ELJTI4KWi65Z4Ft84SvBfq/KRhTbI9kjXysvcpbQI6P33Oudx7zRR+6lh
	CkuLCTasn4WX39kPGTOhJSfezOvel0ruyOjt+HNq4t08FRKvS9TXofFbes87X/cXomcupl
	Gs9XXvA3nTV7/jmTYxfdIITZHSxoTsl8Y7feBPACXUKNAJUJjIcD2N1ry/OJyGszObycnW
	qaRyKNloWG2Mk2ktdPs+Q0z17a70TF/hvlUd119FpSCadXY+vZ3Hy1b9+wJiS6JiBbxe8W
	E7nw4e2642bbq8l9J1j9AL/y1A5ahwKKKuGWj9AVI/eDLVEcn8NOlRlChwFjzg==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785719448; a=rsa-sha256; cv=none;
	b=MCJRBzvN2rfyTCp0zS4325CagdmTR6S9rUC2Zo4vDBuMttH4t78E6veG4mIntnTi9OfmVn
	ElSmGdbMPvkybK1uNtrJzErMZX1gQ88nnJ1R4u8g+gXHHNHhvtBmQqfkUHGkYjNAqYp/cd
	atPQ8trf80uAPfX0qQm+kqu98Mx6IT7cSBheo9Gwy3cqxr47a2h/X+MHfgcKCiGpvUKBiW
	l64LX+fS5L9ZyHkKhnFweq9+i6V/dKoLLdjKrh+Qvd5YJRX4PaUVTCUw9l/mrU7G0/GfZ8
	4skRQAC1ATtfxKq5iH7ga63jiNxFpRXQLARk8b8KP6/R0n0xAU8ZpP3VGAsNhg==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785719448;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=p8ZPvyAfqDPTEjgklq0wEqyoLYB5ImajiYz7+Rjj2U0=;
	b=q9ZYD/dmSv8jiuB+nU8+s2vyQELZn55l3MUCz2lY5PtrO0PP24LI0h8BWNnjHpLynxHDos
	RHyHxOEHHnq+pKNiKFHf6cFNuwfpwIAeeCIlpKIuk/c8YEMat4O4sMqxk8qBp32LuJFcrS
	VZTCY8Mr/nj3dp1dCoqKyvsuSF06L35DB4nHg4h1AS2H7BOt1LO5JpvC59dNqj1L7KB/To
	4085oBfWQ2blp+btGm16uxfrntr8cdoJykhxRomEjZ61ehTuWduvaNAnuEd4EflxKjsD1b
	IJGZCUeQbAodte6wHCe7Zyho34RPJmIWGYe6Ju63dWuif6zoMHT4xf3jfUFx7g==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hCzBc4m3Hzfhx
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 01:10:48 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 2199d
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 01:10:43 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Rick Macklem <rmacklem@FreeBSD.org>
Subject: git: 3393002307ad - stable/14 - nfs_commonkrpc.c: Handle NFSERR_DELAY for Sequence correctly
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: rmacklem
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 3393002307adefac3ad21482853c32a53d4a424c
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 01:10:43 +0000
Message-Id: <6a6fea93.2199d.50c41481@gitrepo.freebsd.org>

The branch stable/14 has been updated by rmacklem:

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

commit 3393002307adefac3ad21482853c32a53d4a424c
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2026-07-27 14:16:29 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2026-08-03 01:09:08 +0000

    nfs_commonkrpc.c: Handle NFSERR_DELAY for Sequence correctly
    
    Unlike RFC5661 (the original NFSv4.1 RFC), RFC8881 specifies
    that a NFS4ERR_DELAY reply to the SEQUENCE operation requires
    a reply using the same slot/sequence#.
    
    This patch fixes handling of this case, so it conforms to
    RFC8881.
    
    (cherry picked from commit 6901cbbd5a2c00d378a7f87426b36d6ee6ce0aa2)
---
 sys/fs/nfs/nfs_commonkrpc.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/sys/fs/nfs/nfs_commonkrpc.c b/sys/fs/nfs/nfs_commonkrpc.c
index 7a256366de2e..28f83f460245 100644
--- a/sys/fs/nfs/nfs_commonkrpc.c
+++ b/sys/fs/nfs/nfs_commonkrpc.c
@@ -1127,7 +1127,20 @@ tryagain:
 			if ((nmp != NULL && i == NFSV4OP_SEQUENCE && j != 0) ||
 			   (clp != NULL && i == NFSV4OP_CBSEQUENCE && j != 0)) {
 				NFSCL_DEBUG(1, "failed seq=%d\n", j);
-				if (sep != NULL && i == NFSV4OP_SEQUENCE &&
+				KASSERT(slot == -1, ("newnfs_request: slot not"
+				    " -1"));
+				/*
+				 * RFC8881 (unlike RFC5661) specifies that a
+				 * NFSERR_DELAY reply to SEQUENCE is handled
+				 * by a retry with same slot/sequence#.
+				 * (Although not explicit, I will assume this
+				 *  applies to CB_SEQUENCE as well.)
+				 */
+				if (j == NFSERR_DELAY) {
+					nd->nd_repstat =
+					    NFSERR_RETRYUNCACHEDREP;
+				} else if (sep != NULL &&
+				    i == NFSV4OP_SEQUENCE &&
 				    j == NFSERR_SEQMISORDERED) {
 					mtx_lock(&sep->nfsess_mtx);
 					sep->nfsess_badslots |=

From nobody Mon Aug  3 11:38:35 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF701Qjlz6nByV
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:36 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF7013Lrz3RxG
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:36 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757116;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=rREbY6pIKcP9wf6SZEvp2gP8bVg2VzDbkdxiMwNAyMI=;
	b=LA7E2pc331Vqlu+L6OV+TREv2LWDkEuqEHi3OXrrn0TeS71Vuwfh/w9SyL1OjU3ur73O1r
	S6FPNa18jXV3UZnC8mfNL2DOf+qGt60tbX55V4cytoM9GwFyXp2cJR6XtTGDIRav1AC3nF
	VjmeMLnFWCMbIryFHla+QPjh5hMKFgJLXlLqP9I6MsXaRGw6l6JDNcCXdkF5SVFh0mU5UN
	OVEBaRQM/smftddbeD5YniPP7wuTD/scDHolsTFhDys0iVwCefblIJH0js5iXVDnxMsqbL
	h0r2f3VDg+IaMvyWx2OPGXueeEBuH2OWP1JSRd30rW82fjriJJaxYqmxtb/38g==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757116; a=rsa-sha256; cv=none;
	b=TAfxbRHxtkG1LvwvnT0382QZ8gjgJ2GkK3RMGkQspI5ggnbX+2fVOgQMRXKnCCMCY1PRB5
	KWCvMbFK208E/58FoOPXcT9jTBRgNyI5NQQizFzAnqw2xe+IIZyUppubH9Ugoh4LYjT/R+
	SWjpV11EMIZuLsLiOGl3h/aiypeJ/MsnM22RN7xmyHOwLa5UQP3o7HlRcvjLnNac6JU1KA
	1oQ9XcuzQpn6Ltk/gM/37+tqo3wSrDqN4lXzgcMffHZf4Vw2qzQuVexxm4TXxFb6YrL5vC
	wh4WAfzPA96y6AKc5h3JyuBH/hQ5sZ/ZWbpvEtwNKGMRpHokC05niRtKYpNtgw==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757116;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=rREbY6pIKcP9wf6SZEvp2gP8bVg2VzDbkdxiMwNAyMI=;
	b=SlViRzsdATpooWDznYotncSlIoU+mGnsymMVqKQ9NYOwopfzceY33E4VKZx/guUGnHO6Ja
	CQLYQPXbh4xMiEzfFvFDJail/QLDOs0BvA9P7TsAxfDyen2EGI/BF2hWXNFbq1v7V0kf2k
	Zurt5ZEQ+u4fc7fN7oitL9sBX9xAKJJc2x8LnAoHSlXHN+n7s+npPbTUN7GuWH5IUQnWeG
	Ul/DfoParU6/7w+//MIz8tdnz9wV1EnsUkZdl9FyxRg/kUqWFvsoUOXb5o+G3VpDbcE/ne
	kwo1DE3kj1tvIB1iHdCrOXZ9KAhoNLJn0HaitKjapP4LpTFjIZHzLp+cfcdXhA==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF6z6wCczyfK
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:35 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 19623
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:35 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: c4e25212639a - stable/15 - unbound: Update to 1.25.2
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: c4e25212639ad4c219a85415ade68611dee3277e
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:35 +0000
Message-Id: <6a707dbb.19623.64af2666@gitrepo.freebsd.org>

The branch stable/15 has been updated by des:

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

commit c4e25212639ad4c219a85415ade68611dee3277e
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-22 12:23:53 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:11 +0000

    unbound: Update to 1.25.2
    
    Release notes at
            https://community.nlnetlabs.nl/t/unbound-1-25-2-released
    
    Merge commit 'c68e7bcd81d62e9f5364c6da22fd9917976acf85'
    
    Security:       CVE-2026-14586
    Security:       CVE-2026-32665
    Security:       CVE-2026-40691
    Security:       CVE-2026-41637
    Security:       CVE-2026-42955
    Security:       CVE-2026-44621
    Security:       CVE-2026-44687
    Security:       CVE-2026-44690
    Security:       CVE-2026-46582
    Security:       CVE-2026-50045
    Security:       CVE-2026-50046
    Security:       CVE-2026-50243
    Security:       CVE-2026-50248
    Security:       CVE-2026-50251
    Security:       CVE-2026-50252
    Security:       CVE-2026-52863
    Security:       CVE-2026-54478
    Security:       CVE-2026-55708
    Security:       CVE-2026-55717
    Security:       CVE-2026-55973
    Security:       CVE-2026-55990
    Security:       CVE-2026-55991
    Security:       CVE-2026-56416
    Security:       CVE-2026-56444
    (cherry picked from commit e27b1cae848219d07f0a12a48990af0558b4cced)
---
 contrib/unbound/config.guess                   |  17 +-
 contrib/unbound/config.sub                     |  11 +-
 contrib/unbound/configure                      |  48 ++-
 contrib/unbound/configure.ac                   |  21 +-
 contrib/unbound/daemon/daemon.c                |  12 +-
 contrib/unbound/daemon/daemon.h                |   3 +
 contrib/unbound/daemon/remote.c                |  16 +
 contrib/unbound/daemon/worker.c                |  30 +-
 contrib/unbound/daemon/worker.h                |   8 +-
 contrib/unbound/dnscrypt/dnscrypt.c            |  26 +-
 contrib/unbound/dnscrypt/dnscrypt.h            |   3 +-
 contrib/unbound/dnstap/unbound-dnstap-socket.c |   5 +
 contrib/unbound/doc/README                     |   2 +-
 contrib/unbound/doc/example.conf               |   2 +-
 contrib/unbound/doc/example.conf.in            |   2 +-
 contrib/unbound/doc/libunbound.3               |   4 +-
 contrib/unbound/doc/libunbound.3.in            |   4 +-
 contrib/unbound/doc/unbound-anchor.8           |   4 +-
 contrib/unbound/doc/unbound-anchor.8.in        |   4 +-
 contrib/unbound/doc/unbound-checkconf.8        |   4 +-
 contrib/unbound/doc/unbound-checkconf.8.in     |   4 +-
 contrib/unbound/doc/unbound-control.8          |   4 +-
 contrib/unbound/doc/unbound-control.8.in       |   4 +-
 contrib/unbound/doc/unbound-host.1             |   4 +-
 contrib/unbound/doc/unbound-host.1.in          |   4 +-
 contrib/unbound/doc/unbound.8                  |   4 +-
 contrib/unbound/doc/unbound.8.in               |   4 +-
 contrib/unbound/doc/unbound.conf.5             |   4 +-
 contrib/unbound/doc/unbound.conf.5.in          |   4 +-
 contrib/unbound/doc/unbound.conf.rst           |   7 +
 contrib/unbound/iterator/iter_donotq.c         |  12 +
 contrib/unbound/iterator/iterator.c            |  67 +++--
 contrib/unbound/libunbound/libworker.c         |  13 +-
 contrib/unbound/libunbound/libworker.h         |   3 +
 contrib/unbound/respip/respip.c                |   8 +-
 contrib/unbound/services/authzone.c            |  28 +-
 contrib/unbound/services/cache/dns.c           |   4 +-
 contrib/unbound/services/cache/rrset.c         |  44 ++-
 contrib/unbound/services/listen_dnsport.c      | 234 ++++++++++-----
 contrib/unbound/services/listen_dnsport.h      |  37 ++-
 contrib/unbound/services/localzone.h           |   2 +-
 contrib/unbound/services/mesh.c                |  66 ++++-
 contrib/unbound/services/mesh.h                |   8 +-
 contrib/unbound/services/outside_network.c     | 388 ++++++++++++++++++++-----
 contrib/unbound/services/outside_network.h     | 107 ++++++-
 contrib/unbound/smallapp/worker_cb.c           |   6 +
 contrib/unbound/util/data/msgparse.c           |   9 +-
 contrib/unbound/util/data/packed_rrset.c       |   1 +
 contrib/unbound/util/fptr_wlist.c              |   1 +
 contrib/unbound/util/module.h                  |   6 +
 contrib/unbound/util/netevent.c                |  44 ++-
 contrib/unbound/util/netevent.h                |   6 +-
 contrib/unbound/validator/val_sigcrypt.c       |  18 +-
 contrib/unbound/validator/val_utils.c          |  17 +-
 contrib/unbound/validator/val_utils.h          |   4 +
 contrib/unbound/validator/validator.c          |  59 +++-
 lib/libunbound/config.h                        |   8 +-
 57 files changed, 1131 insertions(+), 338 deletions(-)

diff --git a/contrib/unbound/config.guess b/contrib/unbound/config.guess
index a9d01fde4617..c7f4c3294a63 100755
--- a/contrib/unbound/config.guess
+++ b/contrib/unbound/config.guess
@@ -1,10 +1,10 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
-#   Copyright 1992-2025 Free Software Foundation, Inc.
+#   Copyright 1992-2026 Free Software Foundation, Inc.
 
 # shellcheck disable=SC2006,SC2268 # see below for rationale
 
-timestamp='2025-07-10'
+timestamp='2026-05-17'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -60,7 +60,7 @@ version="\
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright 1992-2025 Free Software Foundation, Inc.
+Copyright 1992-2026 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -150,7 +150,7 @@ UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
 UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
 
 case $UNAME_SYSTEM in
-Linux|GNU|GNU/*)
+Ironclad|Linux|GNU|GNU/*)
 	LIBC=unknown
 
 	set_cc_for_build
@@ -167,6 +167,8 @@ Linux|GNU|GNU/*)
 	LIBC=gnu
 	#elif defined(__LLVM_LIBC__)
 	LIBC=llvm
+	#elif defined(__mlibc__)
+	LIBC=mlibc
 	#else
 	#include <stdarg.h>
 	/* First heuristic to detect musl libc.  */
@@ -1186,6 +1188,9 @@ EOF
     sparc:Linux:*:* | sparc64:Linux:*:*)
 	GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
 	;;
+    sw_64:Linux:*:*)
+	GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
+	;;
     tile*:Linux:*:*)
 	GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
 	;;
@@ -1598,10 +1603,10 @@ EOF
 	GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE
 	;;
     x86_64:[Ii]ronclad:*:*|i?86:[Ii]ronclad:*:*)
-	GUESS=$UNAME_MACHINE-pc-ironclad-mlibc
+	GUESS=$UNAME_MACHINE-pc-ironclad-$LIBC
 	;;
     *:[Ii]ronclad:*:*)
-	GUESS=$UNAME_MACHINE-unknown-ironclad-mlibc
+	GUESS=$UNAME_MACHINE-unknown-ironclad-$LIBC
 	;;
 esac
 
diff --git a/contrib/unbound/config.sub b/contrib/unbound/config.sub
index 3d35cde174de..404aa0824443 100755
--- a/contrib/unbound/config.sub
+++ b/contrib/unbound/config.sub
@@ -1,10 +1,10 @@
 #! /bin/sh
 # Configuration validation subroutine script.
-#   Copyright 1992-2025 Free Software Foundation, Inc.
+#   Copyright 1992-2026 Free Software Foundation, Inc.
 
 # shellcheck disable=SC2006,SC2268,SC2162 # see below for rationale
 
-timestamp='2025-07-10'
+timestamp='2026-05-17'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -76,7 +76,7 @@ Report bugs and patches to <config-patches@gnu.org>."
 version="\
 GNU config.sub ($timestamp)
 
-Copyright 1992-2025 Free Software Foundation, Inc.
+Copyright 1992-2026 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -1432,6 +1432,7 @@ case $cpu-$vendor in
 			| sparcv9v \
 			| spu \
 			| sv1 \
+			| sw_64 \
 			| sx* \
 			| tahoe \
 			| thumbv7* \
@@ -1525,7 +1526,7 @@ EOF
 		;;
 	ironclad*)
 		kernel=ironclad
-		os=`echo "$basic_os" | sed -e 's|ironclad|mlibc|'`
+		os=`echo "$basic_os" | sed -e 's|ironclad|gnu|'`
 		;;
 	linux*)
 		kernel=linux
@@ -2220,7 +2221,7 @@ case $kernel-$os-$obj in
 		;;
 	uclinux-uclibc*- | uclinux-gnu*- )
 		;;
-	ironclad-mlibc*-)
+	ironclad-gnu*- | ironclad-mlibc*- )
 		;;
 	managarm-mlibc*- | managarm-kernel*- )
 		;;
diff --git a/contrib/unbound/configure b/contrib/unbound/configure
index 2c48dc207575..9efc0bafd338 100755
--- a/contrib/unbound/configure
+++ b/contrib/unbound/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.71 for unbound 1.25.1.
+# Generated by GNU Autoconf 2.71 for unbound 1.25.2.
 #
 # Report bugs to <unbound-bugs@nlnetlabs.nl or https://github.com/NLnetLabs/unbound/issues>.
 #
@@ -622,8 +622,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='unbound'
 PACKAGE_TARNAME='unbound'
-PACKAGE_VERSION='1.25.1'
-PACKAGE_STRING='unbound 1.25.1'
+PACKAGE_VERSION='1.25.2'
+PACKAGE_STRING='unbound 1.25.2'
 PACKAGE_BUGREPORT='unbound-bugs@nlnetlabs.nl or https://github.com/NLnetLabs/unbound/issues'
 PACKAGE_URL=''
 
@@ -1516,7 +1516,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures unbound 1.25.1 to adapt to many kinds of systems.
+\`configure' configures unbound 1.25.2 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1582,7 +1582,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of unbound 1.25.1:";;
+     short | recursive ) echo "Configuration of unbound 1.25.2:";;
    esac
   cat <<\_ACEOF
 
@@ -1835,7 +1835,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-unbound configure 1.25.1
+unbound configure 1.25.2
 generated by GNU Autoconf 2.71
 
 Copyright (C) 2021 Free Software Foundation, Inc.
@@ -2492,7 +2492,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by unbound $as_me 1.25.1, which was
+It was created by unbound $as_me 1.25.2, which was
 generated by GNU Autoconf 2.71.  Invocation command line was
 
   $ $0$ac_configure_args_raw
@@ -3256,11 +3256,11 @@ UNBOUND_VERSION_MAJOR=1
 
 UNBOUND_VERSION_MINOR=25
 
-UNBOUND_VERSION_MICRO=1
+UNBOUND_VERSION_MICRO=2
 
 
 LIBUNBOUND_CURRENT=9
-LIBUNBOUND_REVISION=37
+LIBUNBOUND_REVISION=38
 LIBUNBOUND_AGE=1
 # 1.0.0 had 0:12:0
 # 1.0.1 had 0:13:0
@@ -3365,6 +3365,7 @@ LIBUNBOUND_AGE=1
 # 1.24.2 had 9:35:1
 # 1.25.0 had 9:36:1
 # 1.25.1 had 9:37:1
+# 1.25.2 had 9:38:1
 
 #   Current  -- the number of the binary API that we're implementing
 #   Revision -- which iteration of the implementation of the binary
@@ -23677,6 +23678,29 @@ printf "%s\n" "no" >&6; }
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
 
+    ac_fn_check_decl "$LINENO" "CLOCK_MONOTONIC
+        " "ac_cv_have_decl_CLOCK_MONOTONIC_________" "$ac_includes_default
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+" "$ac_c_undeclared_builtin_options" "CFLAGS"
+if test "x$ac_cv_have_decl_CLOCK_MONOTONIC_________" = xyes
+then :
+
+
+else $as_nop
+  as_fn_error $? "ngtcp2 for QUIC needs at least CLOCK_MONOTONIC on the system" "$LINENO" 5
+
+fi
+
 fi
 
 # set static linking for uninstalled libraries if requested
@@ -26307,7 +26331,7 @@ printf "%s\n" "#define MAXSYSLOGMSGLEN 10240" >>confdefs.h
 
 
 
-version=1.25.1
+version=1.25.2
 
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for build time" >&5
 printf %s "checking for build time... " >&6; }
@@ -26837,7 +26861,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by unbound $as_me 1.25.1, which was
+This file was extended by unbound $as_me 1.25.2, which was
 generated by GNU Autoconf 2.71.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -26905,7 +26929,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config='$ac_cs_config_escaped'
 ac_cs_version="\\
-unbound config.status 1.25.1
+unbound config.status 1.25.2
 configured by $0, generated by GNU Autoconf 2.71,
   with options \\"\$ac_cs_config\\"
 
diff --git a/contrib/unbound/configure.ac b/contrib/unbound/configure.ac
index f1c5b0419782..a4b6b17bdc65 100644
--- a/contrib/unbound/configure.ac
+++ b/contrib/unbound/configure.ac
@@ -12,14 +12,14 @@ sinclude(dnscrypt/dnscrypt.m4)
 # must be numbers. ac_defun because of later processing
 m4_define([VERSION_MAJOR],[1])
 m4_define([VERSION_MINOR],[25])
-m4_define([VERSION_MICRO],[1])
+m4_define([VERSION_MICRO],[2])
 AC_INIT([unbound],m4_defn([VERSION_MAJOR]).m4_defn([VERSION_MINOR]).m4_defn([VERSION_MICRO]),[unbound-bugs@nlnetlabs.nl or https://github.com/NLnetLabs/unbound/issues],[unbound])
 AC_SUBST(UNBOUND_VERSION_MAJOR, [VERSION_MAJOR])
 AC_SUBST(UNBOUND_VERSION_MINOR, [VERSION_MINOR])
 AC_SUBST(UNBOUND_VERSION_MICRO, [VERSION_MICRO])
 
 LIBUNBOUND_CURRENT=9
-LIBUNBOUND_REVISION=37
+LIBUNBOUND_REVISION=38
 LIBUNBOUND_AGE=1
 # 1.0.0 had 0:12:0
 # 1.0.1 had 0:13:0
@@ -124,6 +124,7 @@ LIBUNBOUND_AGE=1
 # 1.24.2 had 9:35:1
 # 1.25.0 had 9:36:1
 # 1.25.1 had 9:37:1
+# 1.25.2 had 9:38:1
 
 #   Current  -- the number of the binary API that we're implementing
 #   Revision -- which iteration of the implementation of the binary
@@ -1735,6 +1736,22 @@ if test x_$withval = x_yes -o x_$withval != x_no; then
 	AC_MSG_RESULT(no)
     ])
 
+    AC_CHECK_DECL([CLOCK_MONOTONIC]
+        , []
+        , [AC_MSG_ERROR([ngtcp2 for QUIC needs at least CLOCK_MONOTONIC on the system])]
+        , [AC_INCLUDES_DEFAULT
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+        ])
+
 fi
 
 # set static linking for uninstalled libraries if requested
diff --git a/contrib/unbound/daemon/daemon.c b/contrib/unbound/daemon/daemon.c
index ea4e83e70932..51dd51de38d4 100644
--- a/contrib/unbound/daemon/daemon.c
+++ b/contrib/unbound/daemon/daemon.c
@@ -79,6 +79,7 @@
 #include "util/tcp_conn_limit.h"
 #include "util/edns.h"
 #include "services/listen_dnsport.h"
+#include "services/outside_network.h"
 #include "services/cache/rrset.h"
 #include "services/cache/infra.h"
 #include "services/localzone.h"
@@ -813,6 +814,10 @@ daemon_create_workers(struct daemon* daemon)
 		fatal_exit("out of memory during daemon init");
 	numport = daemon_get_shufport(daemon, shufport);
 	verbose(VERB_ALGO, "total of %d outgoing ports available", numport);
+	if(!(daemon->shared_ports = shared_ports_create(daemon->cfg->out_ifs,
+		daemon->cfg->num_out_ifs, daemon->cfg->do_ip4,
+		daemon->cfg->do_ip6, shufport, numport)))
+		fatal_exit("could not setup shared ports: out of memory");
 
 #ifdef HAVE_NGTCP2
 	if (cfg_has_quic(daemon->cfg)) {
@@ -843,10 +848,7 @@ daemon_create_workers(struct daemon* daemon)
 #endif
 	}
 	for(i=0; i<daemon->num; i++) {
-		if(!(daemon->workers[i] = worker_create(daemon, i,
-			shufport+numport*i/daemon->num, 
-			numport*(i+1)/daemon->num - numport*i/daemon->num)))
-			/* the above is not ports/numthr, due to rounding */
+		if(!(daemon->workers[i] = worker_create(daemon, i)))
 			fatal_exit("could not create worker");
 	}
 	/* create per-worker alloc caches if not reusing existing ones. */
@@ -1204,6 +1206,8 @@ daemon_cleanup(struct daemon* daemon)
 	if(!daemon->reuse_cache || daemon->need_to_exit)
 		daemon_clear_allocs(daemon);
 	daemon->num = 0;
+	shared_ports_delete(daemon->shared_ports);
+	daemon->shared_ports = NULL;
 #ifdef USE_DNSTAP
 	dt_delete(daemon->dtenv);
 	daemon->dtenv = NULL;
diff --git a/contrib/unbound/daemon/daemon.h b/contrib/unbound/daemon/daemon.h
index 20386d7fc9a0..e6f099629be1 100644
--- a/contrib/unbound/daemon/daemon.h
+++ b/contrib/unbound/daemon/daemon.h
@@ -62,6 +62,7 @@ struct doq_table;
 struct cookie_secrets;
 struct fast_reload_thread;
 struct fast_reload_printq;
+struct shared_ports;
 
 #include "dnstap/dnstap_config.h"
 #ifdef USE_DNSTAP
@@ -97,6 +98,8 @@ struct daemon {
 	int rc_port;
 	/** listening ports for remote control */
 	struct listen_port* rc_ports;
+	/** the shared ports structure, with random ports numbers. */
+	struct shared_ports* shared_ports;
 	/** remote control connections management (for first worker) */
 	struct daemon_remote* rc;
 	/** ssl context for listening to dnstcp over ssl */
diff --git a/contrib/unbound/daemon/remote.c b/contrib/unbound/daemon/remote.c
index 1eaf90016b88..61beb7c2fa69 100644
--- a/contrib/unbound/daemon/remote.c
+++ b/contrib/unbound/daemon/remote.c
@@ -1658,6 +1658,14 @@ do_view_data_add(RES* ssl, struct worker* worker, char* arg)
 			ssl_printf(ssl,"error out of memory\n");
 			return;
 		}
+		if(!v->isfirst) {
+			/* Global local-zone is not used for this view,
+			 * therefore add defaults to this view-specific
+			 * local-zone. */
+			struct config_file lz_cfg;
+			memset(&lz_cfg, 0, sizeof(lz_cfg));
+			local_zone_enter_defaults(v->local_zones, &lz_cfg);
+		}
 	}
 	do_data_add(ssl, v->local_zones, arg2);
 	lock_rw_unlock(&v->lock);
@@ -1683,6 +1691,14 @@ do_view_datas_add(struct daemon_remote* rc, RES* ssl, struct worker* worker,
 			ssl_printf(ssl,"error out of memory\n");
 			return;
 		}
+		if(!v->isfirst) {
+			/* Global local-zone is not used for this view,
+			 * therefore add defaults to this view-specific
+			 * local-zone. */
+			struct config_file lz_cfg;
+			memset(&lz_cfg, 0, sizeof(lz_cfg));
+			local_zone_enter_defaults(v->local_zones, &lz_cfg);
+		}
 	}
 	/* put the view name in the command buf */
 	(void)snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%s ", arg);
diff --git a/contrib/unbound/daemon/worker.c b/contrib/unbound/daemon/worker.c
index a5dd9bc028e8..765fb2299a55 100644
--- a/contrib/unbound/daemon/worker.c
+++ b/contrib/unbound/daemon/worker.c
@@ -1550,6 +1550,7 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
 				return 0;
 			}
 			query_error(c->buffer, LDNS_RCODE_FORMERR, 0);
+			sldns_buffer_copy(c->dnscrypt_buffer, c->buffer);
 			return 1;
 		}
 		dname_str(qinfo.qname, buf);
@@ -1568,6 +1569,7 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
 			query_error(c->buffer, LDNS_RCODE_SERVFAIL,
 				qinfo.qname_len);
 			worker->stats.num_query_dnscrypt_cleartext++;
+			sldns_buffer_copy(c->dnscrypt_buffer, c->buffer);
 			return 1;
 		}
 		worker->stats.num_query_dnscrypt_cert++;
@@ -1828,7 +1830,13 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
 		server_stats_insquery(&worker->stats, c, qinfo.qtype,
 			qinfo.qclass, &edns, repinfo);
 	if(c->type != comm_udp)
+#ifdef USE_DNSCRYPT
+		edns.udp_size = (c->dnscrypt && repinfo->is_dnscrypted)
+			? sldns_buffer_capacity(c->buffer) - DNSCRYPT_REPLY_HEADER_SIZE
+			: 65535;
+#else
 		edns.udp_size = 65535; /* max size for TCP replies */
+#endif
 	if(qinfo.qclass == LDNS_RR_CLASS_CH && answer_chaos(worker, &qinfo,
 		&edns, repinfo, c->buffer)) {
 		regional_free_all(worker->scratchpad);
@@ -2112,7 +2120,7 @@ send_reply_rc:
 		}
 	}
 #ifdef USE_DNSCRYPT
-	if(!dnsc_handle_uncurved_request(repinfo)) {
+	if(!dnsc_handle_uncurved_request(repinfo, c->buffer)) {
 		return 0;
 	}
 #endif
@@ -2225,23 +2233,16 @@ void worker_probe_timer_cb(void* arg)
 }
 
 struct worker*
-worker_create(struct daemon* daemon, int id, int* ports, int n)
+worker_create(struct daemon* daemon, int id)
 {
 	unsigned int seed;
 	struct worker* worker = (struct worker*)calloc(1,
 		sizeof(struct worker));
 	if(!worker)
 		return NULL;
-	worker->numports = n;
-	worker->ports = (int*)memdup(ports, sizeof(int)*n);
-	if(!worker->ports) {
-		free(worker);
-		return NULL;
-	}
 	worker->daemon = daemon;
 	worker->thread_num = id;
 	if(!(worker->cmd = tube_create())) {
-		free(worker->ports);
 		free(worker);
 		return NULL;
 	}
@@ -2249,7 +2250,6 @@ worker_create(struct daemon* daemon, int id, int* ports, int n)
 	if(!(worker->rndstate = ub_initstate(daemon->rand))) {
 		log_err("could not init random numbers.");
 		tube_delete(worker->cmd);
-		free(worker->ports);
 		free(worker);
 		return NULL;
 	}
@@ -2348,14 +2348,14 @@ worker_init(struct worker* worker, struct config_file *cfg,
 		cfg->out_ifs, cfg->num_out_ifs, cfg->do_ip4, cfg->do_ip6,
 		cfg->do_tcp?cfg->outgoing_num_tcp:0, cfg->ip_dscp,
 		worker->daemon->env->infra_cache, worker->rndstate,
-		cfg->use_caps_bits_for_id, worker->ports, worker->numports,
+		cfg->use_caps_bits_for_id,
 		cfg->unwanted_threshold, cfg->outgoing_tcp_mss,
 		&worker_alloc_cleanup, worker,
 		cfg->do_udp || cfg->udp_upstream_without_downstream,
 		worker->daemon->connect_dot_sslctx, cfg->delay_close,
 		cfg->tls_use_sni, dtenv, cfg->udp_connect,
 		cfg->max_reuse_tcp_queries, cfg->tcp_reuse_timeout,
-		cfg->tcp_auth_query_timeout);
+		cfg->tcp_auth_query_timeout, worker->daemon->shared_ports);
 	if(!worker->back) {
 		log_err("could not create outgoing sockets");
 		worker_delete(worker);
@@ -2506,7 +2506,6 @@ worker_delete(struct worker* worker)
 	tube_delete(worker->cmd);
 	comm_timer_delete(worker->stat_timer);
 	comm_timer_delete(worker->env.probe_timer);
-	free(worker->ports);
 	if(worker->thread_num == 0) {
 #ifdef UB_ON_WINDOWS
 		wsvc_desetup_worker(worker);
@@ -2638,6 +2637,11 @@ void libworker_event_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode),
 	log_assert(0);
 }
 
+void libworker_alloc_cleanup(void* ATTR_UNUSED(arg))
+{
+	log_assert(0);
+}
+
 int context_query_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
 {
 	log_assert(0);
diff --git a/contrib/unbound/daemon/worker.h b/contrib/unbound/daemon/worker.h
index b7bb52fd715b..37f3728efef1 100644
--- a/contrib/unbound/daemon/worker.h
+++ b/contrib/unbound/daemon/worker.h
@@ -104,10 +104,6 @@ struct worker {
 	struct listen_dnsport* front;
 	/** the backside outside network interface to the auth servers */
 	struct outside_network* back;
-	/** ports to be used by this worker. */
-	int* ports;
-	/** number of ports for this worker */
-	int numports;
 	/** the signal handler */
 	struct comm_signal* comsig;
 	/** commpoint to listen to commands. */
@@ -146,11 +142,9 @@ struct worker {
  * with backpointers only. Use worker_init on it later.
  * @param daemon: the daemon that this worker thread is part of.
  * @param id: the thread number from 0.. numthreads-1.
- * @param ports: the ports it is allowed to use, array.
- * @param n: the number of ports.
  * @return: the new worker or NULL on alloc failure.
  */
-struct worker* worker_create(struct daemon* daemon, int id, int* ports, int n);
+struct worker* worker_create(struct daemon* daemon, int id);
 
 /**
  * Initialize worker.
diff --git a/contrib/unbound/dnscrypt/dnscrypt.c b/contrib/unbound/dnscrypt/dnscrypt.c
index 173484cdf0b1..6f1a236ad7e5 100644
--- a/contrib/unbound/dnscrypt/dnscrypt.c
+++ b/contrib/unbound/dnscrypt/dnscrypt.c
@@ -474,10 +474,18 @@ dnscrypt_server_curve(const dnsccert *cert,
     uint8_t *const buf = sldns_buffer_begin(buffer);
     size_t len = sldns_buffer_limit(buffer);
 
+    if(len + DNSCRYPT_REPLY_HEADER_SIZE > sldns_buffer_capacity(buffer))
+	return -1;
+    sldns_buffer_clear(buffer);
+
     if(udp){
         if (max_len > max_reply_size)
             max_len = max_reply_size;
     }
+    if(max_len > sldns_buffer_capacity(buffer))
+	max_len = sldns_buffer_capacity(buffer);
+    if(max_len > 65535)
+	    max_len = 65535;
 
 
     memcpy(nonce, client_nonce, crypto_box_HALF_NONCEBYTES);
@@ -520,6 +528,7 @@ dnscrypt_server_curve(const dnsccert *cert,
                           DNSCRYPT_MAGIC_HEADER_LEN,
                           nonce,
                           crypto_box_NONCEBYTES);
+    sldns_buffer_flip(buffer);
     sldns_buffer_set_limit(buffer, len + DNSCRYPT_REPLY_HEADER_SIZE);
     return 0;
 }
@@ -663,6 +672,8 @@ dnsc_find_cert(struct dnsc_env* dnscenv, struct sldns_buffer* buffer)
 	}
 	dnscrypt_header = (struct dnscrypt_query_header *)sldns_buffer_begin(buffer);
 	for (i = 0U; i < dnscenv->signed_certs_count; i++) {
+		if(!certs[i].keypair)
+			continue;
 		if (memcmp(certs[i].magic_query, dnscrypt_header->magic_query,
                    DNSCRYPT_MAGIC_HEADER_LEN) == 0) {
 			return &certs[i];
@@ -804,6 +815,7 @@ dnsc_parse_keys(struct dnsc_env *env, struct config_file *cfg)
 		sizeof *env->keypairs);
 	env->certs = sodium_allocarray(env->signed_certs_count,
 		sizeof *env->certs);
+	memset(env->certs, 0, env->signed_certs_count * sizeof(*env->certs));
 
 	cert_id = 0U;
 	keypair_id = 0U;
@@ -912,12 +924,13 @@ dnsc_handle_curved_request(struct dnsc_env* dnscenv,
 }
 
 int
-dnsc_handle_uncurved_request(struct comm_reply *repinfo)
+dnsc_handle_uncurved_request(struct comm_reply *repinfo,
+	struct sldns_buffer* buffer)
 {
     if(!repinfo->c->dnscrypt) {
         return 1;
     }
-    sldns_buffer_copy(repinfo->c->dnscrypt_buffer, repinfo->c->buffer);
+    sldns_buffer_copy(repinfo->c->dnscrypt_buffer, buffer);
     if(!repinfo->is_dnscrypted) {
         return 1;
     }
@@ -963,12 +976,19 @@ dnsc_create(void)
 int
 dnsc_apply_cfg(struct dnsc_env *env, struct config_file *cfg)
 {
+    int nkeys;
     if(dnsc_parse_certs(env, cfg) <= 0) {
         fatal_exit("dnsc_apply_cfg: no cert file loaded");
     }
-    if(dnsc_parse_keys(env, cfg) <= 0) {
+    nkeys = dnsc_parse_keys(env, cfg);
+    if(nkeys <= 0) {
         fatal_exit("dnsc_apply_cfg: no key file loaded");
     }
+    if((size_t)nkeys < env->signed_certs_count) {
+	fatal_exit("dnsc_apply_cfg: %u dnscrypt-provider-cert file(s) have no "
+		"matching dnscrypt-secret-key",
+		(unsigned)(env->signed_certs_count - (size_t)nkeys));
+    }
     randombytes_buf(env->hash_key, sizeof env->hash_key);
     env->provider_name = cfg->dnscrypt_provider;
 
diff --git a/contrib/unbound/dnscrypt/dnscrypt.h b/contrib/unbound/dnscrypt/dnscrypt.h
index b0da9b732681..998237d48e83 100644
--- a/contrib/unbound/dnscrypt/dnscrypt.h
+++ b/contrib/unbound/dnscrypt/dnscrypt.h
@@ -128,7 +128,8 @@ int dnsc_handle_curved_request(struct dnsc_env* dnscenv,
  * \return 0 in case of failure.
  */
 
-int dnsc_handle_uncurved_request(struct comm_reply *repinfo);
+int dnsc_handle_uncurved_request(struct comm_reply *repinfo,
+	struct sldns_buffer* buffer);
 
 /**
  * Computes the size of the shared secret cache entry.
diff --git a/contrib/unbound/dnstap/unbound-dnstap-socket.c b/contrib/unbound/dnstap/unbound-dnstap-socket.c
index 90b0f6003ff6..2bf017430fe0 100644
--- a/contrib/unbound/dnstap/unbound-dnstap-socket.c
+++ b/contrib/unbound/dnstap/unbound-dnstap-socket.c
@@ -1735,6 +1735,11 @@ void libworker_event_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode),
 	log_assert(0);
 }
 
+void libworker_alloc_cleanup(void* ATTR_UNUSED(arg))
+{
+	log_assert(0);
+}
+
 int context_query_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
 {
 	log_assert(0);
diff --git a/contrib/unbound/doc/README b/contrib/unbound/doc/README
index 265dc1592f9f..fa60d3b0b570 100644
--- a/contrib/unbound/doc/README
+++ b/contrib/unbound/doc/README
@@ -1,4 +1,4 @@
-README for Unbound 1.25.1
+README for Unbound 1.25.2
 Copyright 2007 NLnet Labs
 http://unbound.net
 
diff --git a/contrib/unbound/doc/example.conf b/contrib/unbound/doc/example.conf
index 82fd100dbbe9..5d4536a71f6e 100644
--- a/contrib/unbound/doc/example.conf
+++ b/contrib/unbound/doc/example.conf
@@ -1,7 +1,7 @@
 #
 # Example configuration file.
 #
-# See unbound.conf(5) man page, version 1.25.1.
+# See unbound.conf(5) man page, version 1.25.2.
 #
 # this is a comment.
 
diff --git a/contrib/unbound/doc/example.conf.in b/contrib/unbound/doc/example.conf.in
index 5514328b1235..e03d41153b36 100644
--- a/contrib/unbound/doc/example.conf.in
+++ b/contrib/unbound/doc/example.conf.in
@@ -1,7 +1,7 @@
 #
 # Example configuration file.
 #
-# See unbound.conf(5) man page, version 1.25.1.
+# See unbound.conf(5) man page, version 1.25.2.
 #
 # this is a comment.
 
diff --git a/contrib/unbound/doc/libunbound.3 b/contrib/unbound/doc/libunbound.3
index 91092e67d898..b9158ef902a7 100644
--- a/contrib/unbound/doc/libunbound.3
+++ b/contrib/unbound/doc/libunbound.3
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "LIBUNBOUND" "3" "May 20, 2026" "1.25.1" "Unbound"
+.TH "LIBUNBOUND" "3" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-libunbound \- Unbound DNS validating resolver 1.25.1 functions.
+libunbound \- Unbound DNS validating resolver 1.25.2 functions.
 .SH SYNOPSIS
 .sp
 \fB#include <unbound.h>\fP
diff --git a/contrib/unbound/doc/libunbound.3.in b/contrib/unbound/doc/libunbound.3.in
index 91092e67d898..b9158ef902a7 100644
--- a/contrib/unbound/doc/libunbound.3.in
+++ b/contrib/unbound/doc/libunbound.3.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "LIBUNBOUND" "3" "May 20, 2026" "1.25.1" "Unbound"
+.TH "LIBUNBOUND" "3" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-libunbound \- Unbound DNS validating resolver 1.25.1 functions.
+libunbound \- Unbound DNS validating resolver 1.25.2 functions.
 .SH SYNOPSIS
 .sp
 \fB#include <unbound.h>\fP
diff --git a/contrib/unbound/doc/unbound-anchor.8 b/contrib/unbound/doc/unbound-anchor.8
index c9e6b2114f9b..09dfafd4b3e7 100644
--- a/contrib/unbound/doc/unbound-anchor.8
+++ b/contrib/unbound/doc/unbound-anchor.8
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-ANCHOR" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-ANCHOR" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-anchor \- Unbound 1.25.1 anchor utility.
+unbound-anchor \- Unbound 1.25.2 anchor utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-anchor\fP [\fBopts\fP]
diff --git a/contrib/unbound/doc/unbound-anchor.8.in b/contrib/unbound/doc/unbound-anchor.8.in
index fa1486d18864..c9810f8f2c03 100644
--- a/contrib/unbound/doc/unbound-anchor.8.in
+++ b/contrib/unbound/doc/unbound-anchor.8.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-ANCHOR" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-ANCHOR" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-anchor \- Unbound 1.25.1 anchor utility.
+unbound-anchor \- Unbound 1.25.2 anchor utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-anchor\fP [\fBopts\fP]
diff --git a/contrib/unbound/doc/unbound-checkconf.8 b/contrib/unbound/doc/unbound-checkconf.8
index 9a42e3c309e1..c5904d52d282 100644
--- a/contrib/unbound/doc/unbound-checkconf.8
+++ b/contrib/unbound/doc/unbound-checkconf.8
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-CHECKCONF" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-CHECKCONF" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-checkconf \- Check Unbound 1.25.1 configuration file for errors.
+unbound-checkconf \- Check Unbound 1.25.2 configuration file for errors.
 .SH SYNOPSIS
 .sp
 \fBunbound\-checkconf\fP [\fB\-hf\fP] [\fB\-o option\fP] [cfgfile]
diff --git a/contrib/unbound/doc/unbound-checkconf.8.in b/contrib/unbound/doc/unbound-checkconf.8.in
index cfc4e2375e47..a3094e486a7b 100644
--- a/contrib/unbound/doc/unbound-checkconf.8.in
+++ b/contrib/unbound/doc/unbound-checkconf.8.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-CHECKCONF" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-CHECKCONF" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-checkconf \- Check Unbound 1.25.1 configuration file for errors.
+unbound-checkconf \- Check Unbound 1.25.2 configuration file for errors.
 .SH SYNOPSIS
 .sp
 \fBunbound\-checkconf\fP [\fB\-hf\fP] [\fB\-o option\fP] [cfgfile]
diff --git a/contrib/unbound/doc/unbound-control.8 b/contrib/unbound/doc/unbound-control.8
index e84d00d03bc5..f50ca271e415 100644
--- a/contrib/unbound/doc/unbound-control.8
+++ b/contrib/unbound/doc/unbound-control.8
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-CONTROL" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-CONTROL" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-control \- Unbound 1.25.1 remote server control utility.
+unbound-control \- Unbound 1.25.2 remote server control utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-control\fP [\fB\-hq\fP] [\fB\-c cfgfile\fP] [\fB\-s server\fP] command
diff --git a/contrib/unbound/doc/unbound-control.8.in b/contrib/unbound/doc/unbound-control.8.in
index faf3534d7af8..c1ad6b8d68c6 100644
--- a/contrib/unbound/doc/unbound-control.8.in
+++ b/contrib/unbound/doc/unbound-control.8.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-CONTROL" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-CONTROL" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-control \- Unbound 1.25.1 remote server control utility.
+unbound-control \- Unbound 1.25.2 remote server control utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-control\fP [\fB\-hq\fP] [\fB\-c cfgfile\fP] [\fB\-s server\fP] command
diff --git a/contrib/unbound/doc/unbound-host.1 b/contrib/unbound/doc/unbound-host.1
index 52185a5bb42c..c674a09545d3 100644
--- a/contrib/unbound/doc/unbound-host.1
+++ b/contrib/unbound/doc/unbound-host.1
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-HOST" "1" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-HOST" "1" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-host \- Unbound 1.25.1 DNS lookup utility.
+unbound-host \- Unbound 1.25.2 DNS lookup utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-host\fP [\fB\-C configfile\fP] [\fB\-vdhr46D\fP] [\fB\-c class\fP]
diff --git a/contrib/unbound/doc/unbound-host.1.in b/contrib/unbound/doc/unbound-host.1.in
index 6f3ef3f2593e..1582fd54813b 100644
--- a/contrib/unbound/doc/unbound-host.1.in
+++ b/contrib/unbound/doc/unbound-host.1.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-HOST" "1" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-HOST" "1" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-host \- Unbound 1.25.1 DNS lookup utility.
+unbound-host \- Unbound 1.25.2 DNS lookup utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-host\fP [\fB\-C configfile\fP] [\fB\-vdhr46D\fP] [\fB\-c class\fP]
diff --git a/contrib/unbound/doc/unbound.8 b/contrib/unbound/doc/unbound.8
index 79f61bd89fed..3fdbc2e90430 100644
--- a/contrib/unbound/doc/unbound.8
+++ b/contrib/unbound/doc/unbound.8
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound \- Unbound DNS validating resolver 1.25.1.
+unbound \- Unbound DNS validating resolver 1.25.2.
 .SH SYNOPSIS
 .sp
 \fBunbound\fP [\fB\-hdpVv\fP] [\fB\-c <cfgfile>\fP]
diff --git a/contrib/unbound/doc/unbound.8.in b/contrib/unbound/doc/unbound.8.in
index a66ee68469a3..cf15d5b2b4a9 100644
--- a/contrib/unbound/doc/unbound.8.in
+++ b/contrib/unbound/doc/unbound.8.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND" "8" "May 20, 2026" "1.25.1" "Unbound"
*** 2768 LINES SKIPPED ***

From nobody Mon Aug  3 11:38:37 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7140kCz6nC3q
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:37 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF711sQBz3RgN
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:37 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757117;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=sAW/W6B7VeQh7U3oN/k2ABVoEboQ60dJYXzNe7Wgmnk=;
	b=TQAhnB5MK03aDbSRySCTr7wcGBxPjepmlYOaMgsb9M3TYOpYMM2ehfiHYU+wZGFjMdx4s7
	Bu9doVyVn/DQaX59vXsitzoxglCZfLcdT55BYkKIwVFkoGjn/+KoK5wUE6zAYqLwkKXoBO
	RTX6g24WdB3fv1uMEVmSOAJMgh0j2nEFFdJwuSYEfNJhpaZnkFJNK+oB3l6+8K3MEKvmXy
	Je2s80q7sEGK512FzXqnbl1/5yUd7wSK1mpElobSL6wKlH/uMDaIlHbLC//xqk+316jzcb
	b2gNyJ33XR9Om5CSU+ilK06SvTB9DGyAvJta3z+3vVblbf6/2SbiPJyecCG6Dw==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757117; a=rsa-sha256; cv=none;
	b=EVOj369lKmST8kpBDNbGjnedR8+RuJdWTEdYBud5scxUUuyT4Kv9/FED6mCsF8cJDpDi8a
	Kq1x+uIyM2aJXDZ2uueLT++ge6IC5ZZmhtnhntzMK9uxblsqdVqkv7o0BvVJW+afUdloyF
	QDanhe5E0dTCpzMVFkCgUWvz/b8QqUn5FvyzzQhHFxIhW0Ih/ZYmqeoDYis/q3gBV6+9GP
	P1uCDykDhh9ayvfvAdi57z3p4ENiGWGEeatAsXXWgBaffKOI7gzsLfPHXf0lAZNvscJlp8
	FcmWtlIHfFIzPZ58dcdeju26YRLqKVxlczY+21lV7oHr8g2baV8bSlxaM98IrA==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757117;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=sAW/W6B7VeQh7U3oN/k2ABVoEboQ60dJYXzNe7Wgmnk=;
	b=VM49aj5cBqlqDDS48q4h5nhTO3JhcUnnBHyxSiuok/DWnFbuARCc6dsura5IU2vQQtniRw
	fiQOyneAXpOy2/gNgVqRFukzX1RVW9kjKjlAd08+JQic7XNhmiBbjClxixiLvLIt+7BNUl
	wVGCBFPal69U4u33xy8dAvHC0/b25qzKrxQjLYqCAPikM6a1H4qAKGQYklifZ6push2vNq
	+Mz7Kq5R9MOSBiZvidXFnLnGYqAViO1qeYN9zWz0aA+/EDcvIzlmO5C6EvFnM4Bdwk7urW
	sh0eAtH6Y7M5pL+tF9+6Ji/TS3YSG6yZFRPlBjPcRq3ZpbL5apYFCz1X2Q7tXw==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF710Yb2zymW
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:37 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1bcbc
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:37 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: eeba99aff03b - stable/15 - kqueue: Fix delivery of unwanted events
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: eeba99aff03b49ade60189fb0567eefb899a8454
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:37 +0000
Message-Id: <6a707dbd.1bcbc.6fb0b795@gitrepo.freebsd.org>

The branch stable/15 has been updated by des:

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

commit eeba99aff03b49ade60189fb0567eefb899a8454
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-23 06:06:32 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:11 +0000

    kqueue: Fix delivery of unwanted events
    
    In both procdesc_kqops_event() and filt_proc(), the event variable can
    have more than one bit set.  This means that:
    
    * We cannot compare it directly with NOTE_EXIT; we must binary-and them
      instead.
    
    * We cannot binary-or it with the report mask; we must binary-and it
      with the request mask first.
    
    MFC after:      1 week
    Fixes:          2a5e58c59694 ("procdesc: add NOTE_PDSIGCHLD")
    Fixes:          b328975b9d7c ("procdesc: report NOTE_PDSIGCHLD for traced and stopped process")
    Reviewed by:    kib, markj
    Differential Revision:  https://reviews.freebsd.org/D58395
    
    (cherry picked from commit 4627fe9e5afc0dce4469f5964f5d4b0e49a24274)
---
 sys/kern/kern_event.c   | 6 +++---
 sys/kern/sys_procdesc.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index 706f0e6d658e..8e2dd0eb3492 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -529,11 +529,11 @@ filt_proc(struct knote *kn, long hint)
 	event = (u_int)hint & NOTE_PCTRLMASK;
 
 	/* If the user is interested in this event, record it. */
-	if (kn->kn_sfflags & event)
-		kn->kn_fflags |= event;
+	if ((kn->kn_sfflags & event) != 0)
+		kn->kn_fflags |= kn->kn_sfflags & event;
 
 	/* Process is gone, so flag the event as finished. */
-	if (event == NOTE_EXIT) {
+	if ((event & NOTE_EXIT) != 0) {
 		kn->kn_flags |= EV_EOF | EV_ONESHOT;
 		kn->kn_ptr.p_proc = NULL;
 		if (kn->kn_fflags & NOTE_EXIT)
diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c
index 9360ec147f8a..a06d29b91ba8 100644
--- a/sys/kern/sys_procdesc.c
+++ b/sys/kern/sys_procdesc.c
@@ -470,8 +470,8 @@ procdesc_kqops_event(struct knote *kn, long hint)
 	}
 
 	/* If the user is interested in this event, record it. */
-	if (kn->kn_sfflags & event)
-		kn->kn_fflags |= event;
+	if ((kn->kn_sfflags & event) != 0)
+		kn->kn_fflags |= kn->kn_sfflags & event;
 
 	/* Process is gone, so flag the event as finished. */
 	if (event == NOTE_EXIT) {

From nobody Mon Aug  3 11:38:38 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF724V4hz6nCFl
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:38 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF722SzWz3RjY
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:38 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757118;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=bgvwBK90p4zaT9k0fXcTXIziviGo1imXi+29WThSsjk=;
	b=GVYgdNCUAruv6zmk5muEJ6U1neVZntnRCjsdqWxziLR/WS8VGD1SRSfnzAbzNjd3hayFNJ
	4yspwq96aJ8bfAcFT743Nhkocs5vxO6E2jclHqGzqKyeZhoqb7igDDZNH78KtfCAP8ZVOg
	eEXjARpQ/bwLt3dnmoklilbuhhugt1LAaTP9huDy4/2Tp9JHE0dcSAkNGJWn3XzA62uZQM
	BNVhmNnSeaE46NoAIg5+6Ndm3cod0Tq3so1eYUbKBlNVLAYMH1be/q+5d0u8TfwRY1Iuxh
	2slmS3okuzTvhrTmwPt8EdoabMouwguyPLZkh4fmCu6joVCgkOEkhVpWgFTZZw==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757118; a=rsa-sha256; cv=none;
	b=Kmsbrd/iLOdwYkddFvZjmT69bXXQrbk3qYBg8s17Hk3BWdG928jA56r8surQoT/PseyCwz
	+ZSlKcr4BR/rvHEy6HJY79OTZ7tsWwmTUhz+SpN0E0UKQZRktFux2jH7BUAxGS5g+OEbHf
	VOOzAJYYbE/okFTJX/HZJwhcO30cat80OVoTZzLE5XQOenPbqhggEvu6c35iOmuLGxag7N
	WlsVWi+oCdW0OhuT6vuV5ows3wj1M+rzFBJojOcOKBIidaunNuddnlQS2qxsrVqPWyf45E
	dzpUv6NBrBW6+e54DG8ec1xWXNYwBsQrZsL2B0LhM1kv/OfXuxKK3c1aSBUEpg==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757118;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=bgvwBK90p4zaT9k0fXcTXIziviGo1imXi+29WThSsjk=;
	b=oxLSsEJQawtWTpkY0p09n2jSumGPXuqNl555urgsqz0wExVS51fQQRtUTGNJszA6JyEfli
	XnBMmN6n6GnYSX73bdcR2i+S1rG3/87t11Dky+mK7Um/a+8wcps79S4PWDM1o2fGlPvpaI
	X/eQ9M8lxCw1nJKY2c+xfPVwXhLyKL29T/ccer7IrNbqTle6+I1wLsIYBJMti4LkfvzMjc
	wNJRVI2TJwraKjniflb7kEOZguvl7ibcseeoF2oxLH4z5KTRClJUjYJOfIIu1sF3ebQiXb
	AdLCh/tHPDIVzbdoXoCaU1nCI6m6cOUnP40FWDl+oSxZL7iRuBBggh2iv/pg9Q==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF720vzfzymX
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:38 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 194dc
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:38 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: c78190d2144e - stable/15 - pwait: Don't use init as a target
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: c78190d2144ec2574bca0ba619a0b26b87371216
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:38 +0000
Message-Id: <6a707dbe.194dc.7f6e9043@gitrepo.freebsd.org>

The branch stable/15 has been updated by des:

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

commit c78190d2144ec2574bca0ba619a0b26b87371216
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-25 12:44:35 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:11 +0000

    pwait: Don't use init as a target
    
    The time_unit test case uses PID 1 as a target for pwait.  This doesn't
    work in a jail.  Since all we need is a process that we know won't die
    while the test is running, we may as well use ourselves.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    ngie
    Differential Revision:  https://reviews.freebsd.org/D58418
    
    (cherry picked from commit 5922e9d7e72bfa8a85b0f37bcfd1a8b5d866ec3b)
---
 bin/pwait/tests/pwait_test.sh | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/bin/pwait/tests/pwait_test.sh b/bin/pwait/tests/pwait_test.sh
index d31ca21cff93..0d4f53d2941d 100644
--- a/bin/pwait/tests/pwait_test.sh
+++ b/bin/pwait/tests/pwait_test.sh
@@ -56,31 +56,29 @@ time_unit_head()
 
 time_unit_body()
 {
-	init=1
-
 	atf_check \
 		-o empty \
 		-e inline:"pwait: timeout unit\n" \
 		-s exit:65 \
-		timeout --preserve-status 2 pwait -t 1d $init
+		timeout --preserve-status 2 pwait -t 1d $$
 
 	atf_check \
 		-o empty \
 		-e inline:"pwait: timeout unit\n" \
 		-s exit:65 \
-		timeout --preserve-status 2 pwait -t 1d $init
+		timeout --preserve-status 2 pwait -t 1d $$
 
 	atf_check \
 		-o empty \
 		-e inline:"pwait: timeout value\n" \
 		-s exit:65 \
-		timeout --preserve-status 2 pwait -t -1 $init
+		timeout --preserve-status 2 pwait -t -1 $$
 
 	atf_check \
 		-o empty \
 		-e inline:"pwait: timeout value\n" \
 		-s exit:65 \
-		timeout --preserve-status 2 pwait -t 100000001 $init
+		timeout --preserve-status 2 pwait -t 100000001 $$
 
 	# These long duration cases are expected to timeout from the
 	# timeout utility rather than pwait -t.
@@ -88,37 +86,37 @@ time_unit_body()
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 100000000 $init
+		timeout --preserve-status 2 pwait -t 100000000 $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 1h $init
+		timeout --preserve-status 2 pwait -t 1h $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 1.5h $init
+		timeout --preserve-status 2 pwait -t 1.5h $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 1m $init
+		timeout --preserve-status 2 pwait -t 1m $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 1.5m $init
+		timeout --preserve-status 2 pwait -t 1.5m $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 0 $init
+		timeout --preserve-status 2 pwait -t 0 $$
 
 	# The rest are fast enough that pwait -t is expected to trigger
 	# the timeout.
@@ -126,31 +124,31 @@ time_unit_body()
 		-o empty \
 		-e empty \
 		-s exit:124 \
-		timeout --preserve-status 2 pwait -t 1s $init
+		timeout --preserve-status 2 pwait -t 1s $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s exit:124 \
-		timeout --preserve-status 2 pwait -t 1.5s $init
+		timeout --preserve-status 2 pwait -t 1.5s $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s exit:124 \
-		timeout --preserve-status 2 pwait -t 1 $init
+		timeout --preserve-status 2 pwait -t 1 $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s exit:124 \
-		timeout --preserve-status 2 pwait -t 1.5 $init
+		timeout --preserve-status 2 pwait -t 1.5 $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s exit:124 \
-		timeout --preserve-status 2 pwait -t 0.5 $init
+		timeout --preserve-status 2 pwait -t 0.5 $$
 }
 
 atf_test_case timeout_trigger_timeout

From nobody Mon Aug  3 11:38:39 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF735XVFz6nCH2
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:39 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF732l0vz3RmF
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:39 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757119;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ueYkRj3dskxAHUeSzvq31t+7pDAPjEs64AIMPht4knQ=;
	b=iKtHcZjUslkielEhyMdEK9V30VCNq8iL7x+WrQDBnVLu22R2oDtBmEqhyqhoxWfk+dwpEZ
	LZcRWH7cDBW8+KGmtmC0HuJPH6QEXjB6WQN4BiS9euyBuBOWAsP0M3d05b8NQFQPpTv5oP
	TSEyNeKUq7JQJOBOxtruK4EKmx3SKes9ZDqm5n4gCJ8jjZlGrLsqatnYoEJ9bz5aLjmpJN
	+ZjWHd1IyghuakuSYxPINvbZHiJV7sDFHe1zkfHQ8dpT6QSv3Z1QF2A9zzpIThFdYDKMY7
	xP4sMr3kQ6xDCTguUmJ5482VkAcSwfrSAHOiIfcMHz26L1OlmoV+08K2QqcHaQ==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757119; a=rsa-sha256; cv=none;
	b=HOQ60PGOFRlJziuYiR1/jM14sqoPwbLxK8c6KpFEgDdxEk9nozxV+nqtPWxZ3ZleCTs86u
	tfw1qHKvxAck7hV7jACEkJtZkppkfSA9y+sPcHVupD+tFu1PHnVyOuBawtdl5UxVLxt91k
	HfijwwirhCNq4hUe77P3yXvdKIZCYdzFSHLvkrOQwZ/SBCEEkWPK4rtXsj4U7qpw3DVREg
	rxS8BckamP2gVcOFYc4CPvNqt2O/azqTii/VhqFJXbluPDbWqYjzQG5CeDk4FzyhmshJIB
	sQ+Vm0FwB6/u304QiP91yRDDt9BuNXqD+Gf7MZe9S9fdf+nwupGWCjuF/xmNSA==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757119;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ueYkRj3dskxAHUeSzvq31t+7pDAPjEs64AIMPht4knQ=;
	b=EHt1UVeak3KUCvw06tYYbpTWBj9lNACTCm//YUqpOsgWC+jtsmhaDW/uU2FfZB/yMVrW9V
	oj8vPEt0xY505b5f0gqVEfXOd96Q1cf/JzC4SZqOYGQ4JSnUIIn/L6U0Cvl6ViQ6nvb1tA
	kySeQIgUj8rozLIcJqgLtv3zENDE0xxUyt8exxOAyoOmaWe9ruBpyPPwtF6DdSl+NQrVol
	Sn4ZytyO+1RHLjWoHEozW4hjdZSoUuMiQJdYsgszDzn52xROHZUF9C/YeYLECDw6WAeC0n
	zEvr8HL4Tt/QWTM18UKICMt86o7o/3DjR2TrzkQLKi+Az1SgtaP0IikEaZFFpQ==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF731lvkzymZ
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:39 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1c6e9
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:39 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 4ce8f2940a6a - stable/15 - kqueue: Add NOTE_REAP
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 4ce8f2940a6a62b4d79b54d9d9a0c1acaca0ad5c
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:39 +0000
Message-Id: <6a707dbf.1c6e9.4a98cdc2@gitrepo.freebsd.org>

The branch stable/15 has been updated by des:

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

commit 4ce8f2940a6a62b4d79b54d9d9a0c1acaca0ad5c
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:15:26 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:12 +0000

    kqueue: Add NOTE_REAP
    
    Add a NOTE_REAP event for EVFILTER_PROC which provides a notification
    when the process is reaped.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    kib, markj
    Differential Revision:  https://reviews.freebsd.org/D58313
    
    (cherry picked from commit 2bacbbecb165dd761ea7ec2fc35630db61508cdf)
---
 lib/libsys/kqueue.2      | 10 ++++++++--
 lib/libsysdecode/flags.c |  4 ++--
 sys/kern/kern_event.c    | 13 ++++++++-----
 sys/kern/kern_exit.c     |  1 +
 sys/kern/sys_procdesc.c  |  9 ++++++---
 sys/sys/event.h          | 11 ++++-------
 6 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/lib/libsys/kqueue.2 b/lib/libsys/kqueue.2
index 6e2d2df40ead..b596a705e08f 100644
--- a/lib/libsys/kqueue.2
+++ b/lib/libsys/kqueue.2
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd January 24, 2026
+.Dd July 22, 2026
 .Dt KQUEUE 2
 .Os
 .Sh NAME
@@ -543,9 +543,15 @@ The exit status will be stored in
 .Va data
 in the same format as the status returned by
 .Xr wait 2 .
+.It Dv NOTE_REAP
+The process has been reaped by a call to the
+.Xr wait 2
+family of functions.
 .It Dv NOTE_FORK
 The process has called
-.Fn fork .
+.Xr fork 2
+or
+.Xr vfork 2 .
 .It Dv NOTE_EXEC
 The process has executed a new process via
 .Xr execve 2
diff --git a/lib/libsysdecode/flags.c b/lib/libsysdecode/flags.c
index f8e26e6a9dae..c46e8ec607b9 100644
--- a/lib/libsysdecode/flags.c
+++ b/lib/libsysdecode/flags.c
@@ -375,8 +375,8 @@ static struct name_table kevent_vnode_fflags[] = {
 };
 
 static struct name_table kevent_proc_fflags[] = {
-	X(NOTE_EXIT) X(NOTE_FORK) X(NOTE_EXEC) X(NOTE_TRACK) X(NOTE_TRACKERR)
-	X(NOTE_CHILD) XEND
+	X(NOTE_EXIT) X(NOTE_FORK) X(NOTE_EXEC) X(NOTE_REAP)
+	X(NOTE_TRACK) X(NOTE_TRACKERR) X(NOTE_CHILD) XEND
 };
 
 static struct name_table kevent_timer_fflags[] = {
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index 8e2dd0eb3492..2a1269ec6e3c 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -445,7 +445,7 @@ filt_procattach(struct knote *kn)
 	bool exiting, immediate;
 
 	exiting = immediate = false;
-	if (kn->kn_sfflags & NOTE_EXIT)
+	if (kn->kn_sfflags & (NOTE_EXIT | NOTE_REAP))
 		p = pfind_any(kn->kn_id);
 	else
 		p = pfind(kn->kn_id);
@@ -470,7 +470,7 @@ filt_procattach(struct knote *kn)
 		kn->kn_flags &= ~EV_FLAG2;
 		kn->kn_data = kn->kn_sdata;		/* ppid */
 		kn->kn_fflags = NOTE_CHILD;
-		kn->kn_sfflags &= ~(NOTE_EXIT | NOTE_EXEC | NOTE_FORK);
+		kn->kn_sfflags &= ~NOTE_PCTRLMASK;
 		immediate = true; /* Force immediate activation of child note. */
 	}
 	/*
@@ -532,12 +532,15 @@ filt_proc(struct knote *kn, long hint)
 	if ((kn->kn_sfflags & event) != 0)
 		kn->kn_fflags |= kn->kn_sfflags & event;
 
+	/* Report exit status */
+	if ((kn->kn_fflags & NOTE_EXIT) != 0)
+		kn->kn_data = KW_EXITCODE(p->p_xexit, p->p_xsig);
+
 	/* Process is gone, so flag the event as finished. */
-	if ((event & NOTE_EXIT) != 0) {
+	if ((event & NOTE_REAP) != 0 ||
+	    ((event & NOTE_EXIT) != 0 && (kn->kn_sfflags & NOTE_REAP) == 0)) {
 		kn->kn_flags |= EV_EOF | EV_ONESHOT;
 		kn->kn_ptr.p_proc = NULL;
-		if (kn->kn_fflags & NOTE_EXIT)
-			kn->kn_data = KW_EXITCODE(p->p_xexit, p->p_xsig);
 		if (kn->kn_fflags == 0)
 			kn->kn_flags |= EV_DROP;
 		return (1);
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 8f9007752b3b..757428826f96 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -1054,6 +1054,7 @@ proc_reap(struct thread *td, struct proc *p, int *status, int options)
 	sx_xunlock(&proctree_lock);
 
 	PROC_LOCK(p);
+	KNOTE_LOCKED(p->p_klist, NOTE_REAP);
 	knlist_detach(p->p_klist);
 	p->p_klist = NULL;
 	PROC_UNLOCK(p);
diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c
index a06d29b91ba8..953816077269 100644
--- a/sys/kern/sys_procdesc.c
+++ b/sys/kern/sys_procdesc.c
@@ -473,11 +473,14 @@ procdesc_kqops_event(struct knote *kn, long hint)
 	if ((kn->kn_sfflags & event) != 0)
 		kn->kn_fflags |= kn->kn_sfflags & event;
 
+	/* Report exit status */
+	if ((kn->kn_fflags & NOTE_EXIT) != 0)
+		kn->kn_data = pd->pd_xstat;
+
 	/* Process is gone, so flag the event as finished. */
-	if (event == NOTE_EXIT) {
+	if ((event & NOTE_REAP) != 0 ||
+	    ((event & NOTE_EXIT) != 0 && (kn->kn_sfflags & NOTE_REAP) == 0)) {
 		kn->kn_flags |= EV_EOF | EV_ONESHOT;
-		if (kn->kn_fflags & NOTE_EXIT)
-			kn->kn_data = pd->pd_xstat;
 		if (kn->kn_fflags == 0)
 			kn->kn_flags |= EV_DROP;
 		return (1);
diff --git a/sys/sys/event.h b/sys/sys/event.h
index a863cd20f45d..16fc829fc8ea 100644
--- a/sys/sys/event.h
+++ b/sys/sys/event.h
@@ -205,7 +205,10 @@ struct freebsd11_kevent32 {
 #define	NOTE_EXIT	0x80000000		/* process exited */
 #define	NOTE_FORK	0x40000000		/* process forked */
 #define	NOTE_EXEC	0x20000000		/* process exec'd */
-#define	NOTE_PCTRLMASK	0xf0000000		/* mask for hint bits */
+#define	NOTE_SIGNAL	0x08000000		/* process received a signal,
+						   shared with EVFIL_SIGNAL */
+#define	NOTE_REAP	0x04000000		/* process reaped */
+#define	NOTE_PCTRLMASK	0xec000000		/* mask for hint bits */
 #define	NOTE_PDATAMASK	0x000fffff		/* mask for pid */
 
 /* additional flags for EVFILT_PROC */
@@ -259,12 +262,6 @@ struct knlist {
 
 #define	KNLIST_EMPTY(list)		SLIST_EMPTY(&(list)->kl_list)
 
-/*
- * Flag indicating hint is a signal.  Used by EVFILT_SIGNAL, and also
- * shared by EVFILT_PROC  (all knotes attached to p->p_klist)
- */
-#define NOTE_SIGNAL	0x08000000
-
 /*
  * Hint values for the optional f_touch event filter.  If f_touch is not set 
  * to NULL and f_isfd is zero the f_touch filter will be called with the type

From nobody Mon Aug  3 11:38:40 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF750WNCz6nCH7
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:41 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF743c42z3RpP
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:40 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757120;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=fyRoM1kJiE5m8shaxpOiTm4rvVl5yT8OyDRts+Xtag0=;
	b=te145kQG85NMa6QgtA7dK9cyvdGw5cAoyDDLAUeaVAspqh32g7oQVGHZNETGLiuKcyBrmA
	Lm7IB0302hCrjfzxTjCFY9YLd08aHz1AGJ/nIYqu++WWutgIAoIcD2Sky75HRRV+mbjSYJ
	/Fc17HCjRCfyXCrHifOgDeslft3pLDy76zBmRBb1bg6kOw/a98hH7ZCrAANJq1k9PBEhrl
	0Tmjq+Jnb9sfuX/INXUYrXj+9Rh7AY6alGuy9sleAuUeqWZmXp92OLsAbKjIgKlrBBOng3
	ZZSB9DIkZKi8xxOpFioeGK9pbzRUyUqv/ZuXcn1E328l34QZ75P6YOlI99JhxA==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757120; a=rsa-sha256; cv=none;
	b=CtbMCgH6AMnYvaKpnfN5hSdKbnEWF96mDkfEPLOHrJuZZSjKNAjLwXnZbp/B6tUhYXtzVf
	rStLP2c2q58oW2rqk9Fgs4WEqWuVBsJkmEuommv6O8W2q7S7E86GHrZeEn5pdzIm8xXiso
	EJnqi1fUtLXKKxxKAJg6BfGazGHEkGVSjNuZxAPJOmjZVq9n3IXHtKEtrmaBsNWQ+OKJXj
	0Wfg3i8myG+nWdiREzyVEQ0ODo1w6t7CMI/AHoL9xN/lqWirfFZZR72Fh6YQY39/baBFA9
	Z0TwKmx5SfiAkB6Ybpa7Txy5G/Om4DAd3Ccjm8z4PagGIXEYowyXPFXYry1obQ==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757120;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=fyRoM1kJiE5m8shaxpOiTm4rvVl5yT8OyDRts+Xtag0=;
	b=M1S751UUKdFG1DiDl6S9CiHm0E+CWzIHjRLlaaZTJKlP62OPOsKWA7UQvEMM7Nh5bvRRS9
	JNh1veP4+oQVHnyFL8AxgKOMbLN1od3DQ5ZTiquW3luaH6dzyBwWa4HdxF38JotIYmyFXD
	cx3a1TlYNSF5qvqU6ktR5+Mx/G917zBTArTbmaDqmaSf0vezGOspL7gnRvDhDozA2t4xBH
	gWoD8ojxGq69EPF3LbEMm+8g7WTEpIoCHO3cF97sCOOikI2gz37vZg/Fa5dedKCntGp2iF
	bf0UxfFGsDhcI4sXFeJmrziSIrMTOTUvNdvevxLtdQMDi03UJuMHOuFqC0h5HQ==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF742RBnzypm
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:40 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 19624
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:40 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 600d57daeaec - stable/15 - pwait: Optionally wait until process is reaped
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 600d57daeaec22c3b459a2a894e30ceca1a9c4cb
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:40 +0000
Message-Id: <6a707dc0.19624.36442487@gitrepo.freebsd.org>

The branch stable/15 has been updated by des:

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

commit 600d57daeaec22c3b459a2a894e30ceca1a9c4cb
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:15:31 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:12 +0000

    pwait: Optionally wait until process is reaped
    
    If the new -r option is specified, wait until the target process not
    only terminates but is reaped.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    kib, markj
    Differential Revision:  https://reviews.freebsd.org/D58314
    
    (cherry picked from commit c8f5e6819d4d81906c4a1641b5c9f02d8730481c)
---
 bin/pwait/pwait.1 | 17 ++++++++++++++---
 bin/pwait/pwait.c | 41 +++++++++++++++++++++++++++++------------
 2 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/bin/pwait/pwait.1 b/bin/pwait/pwait.1
index d92b829b1d6a..2776d3439a31 100644
--- a/bin/pwait/pwait.1
+++ b/bin/pwait/pwait.1
@@ -30,7 +30,7 @@
 .\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 .\" OF SUCH DAMAGE.
 .\"
-.Dd October 22, 2025
+.Dd July 22, 2026
 .Dt PWAIT 1
 .Os
 .Sh NAME
@@ -39,7 +39,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl t Ar duration
-.Op Fl opv
+.Op Fl oprv
 .Ar pid
 \&...
 .Sh DESCRIPTION
@@ -53,6 +53,17 @@ The following option is available:
 Exit when any of the given processes has terminated.
 .It Fl p
 On exit, print a list of processes that have not terminated.
+.It Fl r
+Do not exit until target processes have not only terminated, but been
+reaped by a call to the
+.Xr wait 2
+family of functions.
+Without this flag, target processes may still exist as zombies when
+.Nm
+exits.
+Beware of deadlocks if a target process's reaper (usually its parent)
+is directly or indirectly blocked by
+.Nm .
 .It Fl t Ar duration
 If any process is still running after
 .Ar duration ,
@@ -127,8 +138,8 @@ $ sleep 30 & sleep 40 &
 [2] 1675
 $ pwait -v -t 60 1674 1675
 1674: exited with status 0.
-1675: exited with status 0.
 [1]-  Done                    sleep 30
+1675: exited with status 0.
 [2]+  Done                    sleep 40
 $ echo $?
 0
diff --git a/bin/pwait/pwait.c b/bin/pwait/pwait.c
index 59bf0eb93ced..34aa2b8f53ec 100644
--- a/bin/pwait/pwait.c
+++ b/bin/pwait/pwait.c
@@ -38,6 +38,7 @@
 #include <sys/tree.h>
 #include <sys/wait.h>
 
+#include <assert.h>
 #include <err.h>
 #include <errno.h>
 #include <signal.h>
@@ -66,7 +67,7 @@ RB_GENERATE_STATIC(pidtree, pid, entry, pidcmp);
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: pwait [-t timeout] [-opv] pid ...\n");
+	fprintf(stderr, "usage: pwait [-oprv] [-t timeout] pid ...\n");
 	exit(EX_USAGE);
 }
 
@@ -84,16 +85,17 @@ main(int argc, char *argv[])
 	size_t sz;
 	long pid;
 	pid_t mypid;
-	int i, kq, n, ndone, nleft, opt, pid_max, ret, status;
-	bool oflag, pflag, tflag, verbose;
+	int i, kq, n, ndone, nleft, notes, opt, pid_max, ret, status;
+	bool oflag, pflag, rflag, tflag, verbose;
 
 	oflag = false;
 	pflag = false;
+	rflag = false;
 	tflag = false;
 	verbose = false;
 	memset(&itv, 0, sizeof(itv));
 
-	while ((opt = getopt(argc, argv, "opt:v")) != -1) {
+	while ((opt = getopt(argc, argv, "oprt:v")) != -1) {
 		switch (opt) {
 		case 'o':
 			oflag = true;
@@ -101,6 +103,9 @@ main(int argc, char *argv[])
 		case 'p':
 			pflag = true;
 			break;
+		case 'r':
+			rflag = true;
+			break;
 		case 't':
 			tflag = true;
 			errno = 0;
@@ -163,6 +168,9 @@ main(int argc, char *argv[])
 	}
 	ndone = nleft = 0;
 	mypid = getpid();
+	notes = rflag ? NOTE_REAP : NOTE_EXIT;
+	if (verbose)
+		notes |= NOTE_EXIT;
 	for (n = 0; n < argc; n++) {
 		s = argv[n];
 		/* Undocumented Solaris compat */
@@ -188,7 +196,7 @@ main(int argc, char *argv[])
 			free(p);
 			continue;
 		}
-		EV_SET(e + nleft, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
+		EV_SET(e + nleft, pid, EVFILT_PROC, EV_ADD, notes, 0, NULL);
 		if (kevent(kq, e + nleft, 1, NULL, 0, NULL) == -1) {
 			if (errno != ESRCH)
 				err(EX_OSERR, "kevent()");
@@ -228,9 +236,11 @@ main(int argc, char *argv[])
 					printf("timeout\n");
 				}
 				ret = 124;
+				continue;
 			}
+			assert(e[i].filter == EVFILT_PROC);
 			pid = e[i].ident;
-			if (verbose) {
+			if ((e[i].fflags & NOTE_EXIT) && verbose) {
 				status = e[i].data;
 				if (WIFEXITED(status)) {
 					printf("%ld: exited with status %d.\n",
@@ -242,13 +252,20 @@ main(int argc, char *argv[])
 					printf("%ld: terminated.\n", pid);
 				}
 			}
-			k.pid = pid;
-			if ((p = RB_FIND(pidtree, &pids, &k)) != NULL) {
-				RB_REMOVE(pidtree, &pids, p);
-				free(p);
-				ndone++;
+			if ((e[i].fflags & NOTE_REAP) && verbose) {
+				printf("%ld: reaped.\n", pid);
+			}
+			if ((e[i].fflags & NOTE_REAP) ||
+			    (!rflag && (e[i].fflags & NOTE_EXIT))) {
+				/* this process is done */
+				k.pid = pid;
+				if ((p = RB_FIND(pidtree, &pids, &k)) != NULL) {
+					RB_REMOVE(pidtree, &pids, p);
+					free(p);
+					ndone++;
+				}
+				--nleft;
 			}
-			--nleft;
 		}
 	}
 	if (pflag) {

From nobody Mon Aug  3 11:38:41 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF763XN9z6nC40
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:42 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF755vPSz3Rpk
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:41 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757121;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=/8N+i5q5ZOb5jJyOLgopNJXbltuJpT0aSKIONfv4YBM=;
	b=SxT6vv0fdf2CXDUHENESJAe5AsqU0y1c9XOyZ7B+8eoTlz8FG+rWVaNS59paUEFSaYdEdH
	e+ovzReezEN0gZXDlCooX1Gmdn8k9dbGa6qSjAsmuX7k3ApOAu1NZCWEFOlnPoIB4qXwE7
	w+7lLJyb82fAgxFJtPMBjioXnNygepE2vCJ51H/mTHb+jod0dPefFdevuBw8cXl/wKyX+G
	Wos/44u5SRl/g6ovfiEfkWH1IASVTIvbfpa0x2NPdnPRUGcXgY7gCzrgM9m+AzFthR5NVZ
	Aqp20jEjV6OMkGERcu6Q6HEHC4Fsa3RQc+F7HS3yE9d804MYmmiLkWONqbFy6g==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757121; a=rsa-sha256; cv=none;
	b=QXIEnRUgH/AVhfEvJCfSe8R9KNRqI8UaEK2usVa8N73sGI7aDCxP/ccfz/Yv2aKcrlNn+t
	kvGgw7m9ERNUwx+ZhXPytNrtuIuEJzwXhJCEwWYeho/kxIEDPUqf7Y1lJ+OEVZ07rHo7Qd
	I8wOfFPklUAPCBp2K7q5T+eBwTAlgCgDpCqkcHNQCLxNvI2IL01EdywOCqmeGI8TAeyKA5
	D+pAZVEyWMNvL1QxjfDnktK57F/1YRKOn/vFnvWlANKgUG7OsEYe8z1qpBs8t+2BRTmX6p
	sVnYOy6D5jCAopZRXYDES8WzjiRSKfsZkym3Qt6XfW2/3Zc4hcVbhz8oA76giw==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757121;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=/8N+i5q5ZOb5jJyOLgopNJXbltuJpT0aSKIONfv4YBM=;
	b=Mf5pOJf9ZABdRbM7ywhMKjola8ZLSD48kmYWBnWGIH9D2vADg2IjqfVKFMrRXHtyAdUgrj
	Mozx7+d/RUXKS+as83zHWLzAS7a6PS34bAbtCH5/WQJlTq+J4o1NaxqsUXm6nem4H+BugT
	2+Nd8kikdWjos9lfQ86ts5I5GUoH4pk3JmdPphxNi3NC58XJWo5nb57zQ9S+tUj/JWuaAz
	EM7Lwfz8EUlvM5NGpdGkuKwCg+UiUCt7l5/WKuYok8z1xNQxHkgSPcTWefkWEGMc33WQdz
	mrtpegkjaax95NFpjk/3qxJE1NWgIljTPQnhwifYb2P2PxEu9iYf2tJl99uKzA==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF753F7Xzypp
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:41 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 19742
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:41 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 236794f7c229 - stable/15 - pwait: Add a SIGINFO handler
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 236794f7c22966c2d0612da30b22c8c8737f2aeb
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:41 +0000
Message-Id: <6a707dc1.19742.6461c9a8@gitrepo.freebsd.org>

The branch stable/15 has been updated by des:

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

commit 236794f7c22966c2d0612da30b22c8c8737f2aeb
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:15:36 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:12 +0000

    pwait: Add a SIGINFO handler
    
    On SIGINFO, print a space-separated list or remaining processes to
    standard error.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    kib, markj
    Differential Revision:  https://reviews.freebsd.org/D58386
    
    (cherry picked from commit eddd8aa99ca84c85faea5761af800b5b089d6ba1)
---
 bin/pwait/pwait.1 | 13 +++++++++++++
 bin/pwait/pwait.c | 36 +++++++++++++++++++++++++++++-------
 2 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/bin/pwait/pwait.1 b/bin/pwait/pwait.1
index 2776d3439a31..4bd43257a82b 100644
--- a/bin/pwait/pwait.1
+++ b/bin/pwait/pwait.1
@@ -88,6 +88,18 @@ Print the exit status when each process terminates or
 .Ql timeout
 if the timer goes off earlier.
 .El
+.Pp
+If
+.Nm
+receives
+.Dv SIGINFO
+(see the
+.Sy status
+argument for
+.Xr stty 1 )
+signal,
+a space-separated list of processes still being waited on is printed
+to the standard error output.
 .Sh EXIT STATUS
 The
 .Nm
@@ -148,6 +160,7 @@ $ echo $?
 .Xr kill 1 ,
 .Xr pkill 1 ,
 .Xr ps 1 ,
+.Xr stty 1 ,
 .Xr wait 1 ,
 .Xr kqueue 2
 .Sh NOTES
diff --git a/bin/pwait/pwait.c b/bin/pwait/pwait.c
index 34aa2b8f53ec..a478111e1137 100644
--- a/bin/pwait/pwait.c
+++ b/bin/pwait/pwait.c
@@ -85,7 +85,7 @@ main(int argc, char *argv[])
 	size_t sz;
 	long pid;
 	pid_t mypid;
-	int i, kq, n, ndone, nleft, notes, opt, pid_max, ret, status;
+	int i, kq, n, ndone, nev, nleft, notes, opt, pid_max, ret, status;
 	bool oflag, pflag, rflag, tflag, verbose;
 
 	oflag = false;
@@ -163,10 +163,10 @@ main(int argc, char *argv[])
 	if (sysctlbyname("kern.pid_max", &pid_max, &sz, NULL, 0) != 0) {
 		pid_max = 99999;
 	}
-	if ((e = malloc((argc + tflag) * sizeof(*e))) == NULL) {
+	if ((e = malloc((argc + 1 + tflag) * sizeof(*e))) == NULL) {
 		err(EX_OSERR, "malloc");
 	}
-	ndone = nleft = 0;
+	ndone = nev = nleft = 0;
 	mypid = getpid();
 	notes = rflag ? NOTE_REAP : NOTE_EXIT;
 	if (verbose)
@@ -206,18 +206,28 @@ main(int argc, char *argv[])
 			ndone++;
 		} else {
 			nleft++;
+			nev++;
 		}
 	}
 
+	/*
+	 * Detect SIGINFO so we can print a status.
+	 */
+	EV_SET(e + nev, SIGINFO, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
+	if (kevent(kq, e + nev, 1, NULL, 0, NULL) == -1) {
+		err(EX_OSERR, "kevent");
+	}
+	nev++;
 	if ((ndone == 0 || !oflag) && nleft > 0 && tflag) {
 		/*
 		 * Explicitly detect SIGALRM so that an exit status of 124
 		 * can be returned rather than 142.
 		 */
-		EV_SET(e + nleft, SIGALRM, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
-		if (kevent(kq, e + nleft, 1, NULL, 0, NULL) == -1) {
+		EV_SET(e + nev, SIGALRM, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
+		if (kevent(kq, e + nev, 1, NULL, 0, NULL) == -1) {
 			err(EX_OSERR, "kevent");
 		}
+		nev++;
 		/* Ignore SIGALRM to not interrupt kevent(2). */
 		signal(SIGALRM, SIG_IGN);
 		if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
@@ -225,13 +235,25 @@ main(int argc, char *argv[])
 		}
 	}
 	ret = EX_OK;
+	setvbuf(stderr, NULL, _IOLBF, 0);
 	while ((ndone == 0 || !oflag) && ret == EX_OK && nleft > 0) {
-		n = kevent(kq, NULL, 0, e, nleft + tflag, NULL);
+		n = kevent(kq, NULL, 0, e, nev, NULL);
 		if (n == -1) {
 			err(EX_OSERR, "kevent");
 		}
 		for (i = 0; i < n; i++) {
-			if (e[i].filter == EVFILT_SIGNAL) {
+			if (e[i].filter == EVFILT_SIGNAL &&
+			    e[i].ident == SIGINFO) {
+				p = RB_MIN(pidtree, &pids);
+				fprintf(stderr, "%d", p->pid);
+				while ((p = RB_NEXT(pidtree, &pids, p)) != NULL) {
+					fprintf(stderr, " %d", p->pid);
+				}
+				fprintf(stderr, "\n");
+				continue;
+			}
+			if (e[i].filter == EVFILT_SIGNAL &&
+			    e[i].ident == SIGALRM) {
 				if (verbose) {
 					printf("timeout\n");
 				}

From nobody Mon Aug  3 11:38:41 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF762Y41z6nCG1
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:42 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF752Ydcz3Rk2
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:41 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757121;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=HrDq8mGdOeV0JFmZUW8DBMasA5lWPPzGykh8v0ekeME=;
	b=aXSceAgww1Dn5FRboXWYbKnR0AxsRrfE7k9+5PrQcOmYrexZd9jYuG10qI71929UA3cXON
	8zOjseohPKHKUIAgU1CUFJCN5aHC21TUYinQUKI3+vXrfIWROG4gfsUVVAx9D7DZwWlAxN
	6vP03AFX+8YbYfFuIeTp2886YZjZ84jTnjH5IU+PXCUyyoBboGgTa+3Wcvyx5uFr+wm30X
	bFhCrJj3eIwoYkrVpc9EtDiFWoCDa7TkZar5V9ZvN6y+1tnkoUUJIDX87iBJgmLpXTIlvA
	ySe4iXigKDmLOdmGEG4pTv+r66dNxNCgK57lzooIE/G4stzK1nOMubnJKRaJiA==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757121; a=rsa-sha256; cv=none;
	b=GclgmS/N6YVsDyRVvy6tcFlOfE7UxacGECcQPblNXLGk67T+wumyRIB4DSkueHVtcKUw4Z
	9iswbkxpXHxPYoUE9SqSZHR9Cp9VaEXMBBoRPatZDairBjKNk4+U8ZT/NFKCERFgemEPGz
	DC2PlPxA8puQ7+PEVMMcVOJUgvfTv3UHsU6YdDvcSXSNN8f2G6DsABkp7vaTWMtKz5bb9i
	3i/JNNBjIi1mtbfm/Oz3+YcNtFFxglv062QhAeW9e97/yiyZdpv7suEmvHeZQFF6dKghXI
	c2Gj2QSnWpk7K241z0yWEd6QS1Hu+3Xwaw/QLGcW2CeTyV/nWQSmERFfM2HTEg==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757121;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=HrDq8mGdOeV0JFmZUW8DBMasA5lWPPzGykh8v0ekeME=;
	b=LnxT2ii853Xiqh5B/hjuQZknDQ9/rJzIIIhqKTxl97nzg8n9ThhZ8Sd+OlMXbXqiROL5UH
	O0Z5kkiARl1a+wtRyWc77l8zxDRD+g/+aUZ6R37ZFs9qi+sXImMcop6gDWFqci1mNW8csh
	Cx9+Sx7qJ/1/vQODXfFSlIQAeU4/8P4Cq6O++GAw81SA1fVZszm/rvc9NVYn4JBMdXkdL0
	KyE43QMgksMP95asZSFaAQ7VXI3jjnW7c0SGoxXiwdRdmp4UGf5vh62XmHCHpgzE8eXzPs
	wXjuAe7+3F9WFPj84I/pq1vvP76L7S7UXZvwsgxSOo6JUDXsSQ4/q69zr0MRow==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF751MGDzymb
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:41 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 19840
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:41 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 6bfcca26efbc - stable/14 - unbound: Update to 1.25.2
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 6bfcca26efbc250998cec5c1109d9a4d1a1b0b6f
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:41 +0000
Message-Id: <6a707dc1.19840.47eccab4@gitrepo.freebsd.org>

The branch stable/14 has been updated by des:

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

commit 6bfcca26efbc250998cec5c1109d9a4d1a1b0b6f
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-22 12:23:53 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:13 +0000

    unbound: Update to 1.25.2
    
    Release notes at
            https://community.nlnetlabs.nl/t/unbound-1-25-2-released
    
    Merge commit 'c68e7bcd81d62e9f5364c6da22fd9917976acf85'
    
    Security:       CVE-2026-14586
    Security:       CVE-2026-32665
    Security:       CVE-2026-40691
    Security:       CVE-2026-41637
    Security:       CVE-2026-42955
    Security:       CVE-2026-44621
    Security:       CVE-2026-44687
    Security:       CVE-2026-44690
    Security:       CVE-2026-46582
    Security:       CVE-2026-50045
    Security:       CVE-2026-50046
    Security:       CVE-2026-50243
    Security:       CVE-2026-50248
    Security:       CVE-2026-50251
    Security:       CVE-2026-50252
    Security:       CVE-2026-52863
    Security:       CVE-2026-54478
    Security:       CVE-2026-55708
    Security:       CVE-2026-55717
    Security:       CVE-2026-55973
    Security:       CVE-2026-55990
    Security:       CVE-2026-55991
    Security:       CVE-2026-56416
    Security:       CVE-2026-56444
    (cherry picked from commit e27b1cae848219d07f0a12a48990af0558b4cced)
---
 contrib/unbound/config.guess                   |  17 +-
 contrib/unbound/config.sub                     |  11 +-
 contrib/unbound/configure                      |  48 ++-
 contrib/unbound/configure.ac                   |  21 +-
 contrib/unbound/daemon/daemon.c                |  12 +-
 contrib/unbound/daemon/daemon.h                |   3 +
 contrib/unbound/daemon/remote.c                |  16 +
 contrib/unbound/daemon/worker.c                |  30 +-
 contrib/unbound/daemon/worker.h                |   8 +-
 contrib/unbound/dnscrypt/dnscrypt.c            |  26 +-
 contrib/unbound/dnscrypt/dnscrypt.h            |   3 +-
 contrib/unbound/dnstap/unbound-dnstap-socket.c |   5 +
 contrib/unbound/doc/README                     |   2 +-
 contrib/unbound/doc/example.conf               |   2 +-
 contrib/unbound/doc/example.conf.in            |   2 +-
 contrib/unbound/doc/libunbound.3               |   4 +-
 contrib/unbound/doc/libunbound.3.in            |   4 +-
 contrib/unbound/doc/unbound-anchor.8           |   4 +-
 contrib/unbound/doc/unbound-anchor.8.in        |   4 +-
 contrib/unbound/doc/unbound-checkconf.8        |   4 +-
 contrib/unbound/doc/unbound-checkconf.8.in     |   4 +-
 contrib/unbound/doc/unbound-control.8          |   4 +-
 contrib/unbound/doc/unbound-control.8.in       |   4 +-
 contrib/unbound/doc/unbound-host.1             |   4 +-
 contrib/unbound/doc/unbound-host.1.in          |   4 +-
 contrib/unbound/doc/unbound.8                  |   4 +-
 contrib/unbound/doc/unbound.8.in               |   4 +-
 contrib/unbound/doc/unbound.conf.5             |   4 +-
 contrib/unbound/doc/unbound.conf.5.in          |   4 +-
 contrib/unbound/doc/unbound.conf.rst           |   7 +
 contrib/unbound/iterator/iter_donotq.c         |  12 +
 contrib/unbound/iterator/iterator.c            |  67 +++--
 contrib/unbound/libunbound/libworker.c         |  13 +-
 contrib/unbound/libunbound/libworker.h         |   3 +
 contrib/unbound/respip/respip.c                |   8 +-
 contrib/unbound/services/authzone.c            |  28 +-
 contrib/unbound/services/cache/dns.c           |   4 +-
 contrib/unbound/services/cache/rrset.c         |  44 ++-
 contrib/unbound/services/listen_dnsport.c      | 234 ++++++++++-----
 contrib/unbound/services/listen_dnsport.h      |  37 ++-
 contrib/unbound/services/localzone.h           |   2 +-
 contrib/unbound/services/mesh.c                |  66 ++++-
 contrib/unbound/services/mesh.h                |   8 +-
 contrib/unbound/services/outside_network.c     | 388 ++++++++++++++++++++-----
 contrib/unbound/services/outside_network.h     | 107 ++++++-
 contrib/unbound/smallapp/worker_cb.c           |   6 +
 contrib/unbound/util/data/msgparse.c           |   9 +-
 contrib/unbound/util/data/packed_rrset.c       |   1 +
 contrib/unbound/util/fptr_wlist.c              |   1 +
 contrib/unbound/util/module.h                  |   6 +
 contrib/unbound/util/netevent.c                |  44 ++-
 contrib/unbound/util/netevent.h                |   6 +-
 contrib/unbound/validator/val_sigcrypt.c       |  18 +-
 contrib/unbound/validator/val_utils.c          |  17 +-
 contrib/unbound/validator/val_utils.h          |   4 +
 contrib/unbound/validator/validator.c          |  59 +++-
 lib/libunbound/config.h                        |   8 +-
 57 files changed, 1131 insertions(+), 338 deletions(-)

diff --git a/contrib/unbound/config.guess b/contrib/unbound/config.guess
index a9d01fde4617..c7f4c3294a63 100755
--- a/contrib/unbound/config.guess
+++ b/contrib/unbound/config.guess
@@ -1,10 +1,10 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
-#   Copyright 1992-2025 Free Software Foundation, Inc.
+#   Copyright 1992-2026 Free Software Foundation, Inc.
 
 # shellcheck disable=SC2006,SC2268 # see below for rationale
 
-timestamp='2025-07-10'
+timestamp='2026-05-17'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -60,7 +60,7 @@ version="\
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright 1992-2025 Free Software Foundation, Inc.
+Copyright 1992-2026 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -150,7 +150,7 @@ UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
 UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
 
 case $UNAME_SYSTEM in
-Linux|GNU|GNU/*)
+Ironclad|Linux|GNU|GNU/*)
 	LIBC=unknown
 
 	set_cc_for_build
@@ -167,6 +167,8 @@ Linux|GNU|GNU/*)
 	LIBC=gnu
 	#elif defined(__LLVM_LIBC__)
 	LIBC=llvm
+	#elif defined(__mlibc__)
+	LIBC=mlibc
 	#else
 	#include <stdarg.h>
 	/* First heuristic to detect musl libc.  */
@@ -1186,6 +1188,9 @@ EOF
     sparc:Linux:*:* | sparc64:Linux:*:*)
 	GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
 	;;
+    sw_64:Linux:*:*)
+	GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
+	;;
     tile*:Linux:*:*)
 	GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
 	;;
@@ -1598,10 +1603,10 @@ EOF
 	GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE
 	;;
     x86_64:[Ii]ronclad:*:*|i?86:[Ii]ronclad:*:*)
-	GUESS=$UNAME_MACHINE-pc-ironclad-mlibc
+	GUESS=$UNAME_MACHINE-pc-ironclad-$LIBC
 	;;
     *:[Ii]ronclad:*:*)
-	GUESS=$UNAME_MACHINE-unknown-ironclad-mlibc
+	GUESS=$UNAME_MACHINE-unknown-ironclad-$LIBC
 	;;
 esac
 
diff --git a/contrib/unbound/config.sub b/contrib/unbound/config.sub
index 3d35cde174de..404aa0824443 100755
--- a/contrib/unbound/config.sub
+++ b/contrib/unbound/config.sub
@@ -1,10 +1,10 @@
 #! /bin/sh
 # Configuration validation subroutine script.
-#   Copyright 1992-2025 Free Software Foundation, Inc.
+#   Copyright 1992-2026 Free Software Foundation, Inc.
 
 # shellcheck disable=SC2006,SC2268,SC2162 # see below for rationale
 
-timestamp='2025-07-10'
+timestamp='2026-05-17'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -76,7 +76,7 @@ Report bugs and patches to <config-patches@gnu.org>."
 version="\
 GNU config.sub ($timestamp)
 
-Copyright 1992-2025 Free Software Foundation, Inc.
+Copyright 1992-2026 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -1432,6 +1432,7 @@ case $cpu-$vendor in
 			| sparcv9v \
 			| spu \
 			| sv1 \
+			| sw_64 \
 			| sx* \
 			| tahoe \
 			| thumbv7* \
@@ -1525,7 +1526,7 @@ EOF
 		;;
 	ironclad*)
 		kernel=ironclad
-		os=`echo "$basic_os" | sed -e 's|ironclad|mlibc|'`
+		os=`echo "$basic_os" | sed -e 's|ironclad|gnu|'`
 		;;
 	linux*)
 		kernel=linux
@@ -2220,7 +2221,7 @@ case $kernel-$os-$obj in
 		;;
 	uclinux-uclibc*- | uclinux-gnu*- )
 		;;
-	ironclad-mlibc*-)
+	ironclad-gnu*- | ironclad-mlibc*- )
 		;;
 	managarm-mlibc*- | managarm-kernel*- )
 		;;
diff --git a/contrib/unbound/configure b/contrib/unbound/configure
index 2c48dc207575..9efc0bafd338 100755
--- a/contrib/unbound/configure
+++ b/contrib/unbound/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.71 for unbound 1.25.1.
+# Generated by GNU Autoconf 2.71 for unbound 1.25.2.
 #
 # Report bugs to <unbound-bugs@nlnetlabs.nl or https://github.com/NLnetLabs/unbound/issues>.
 #
@@ -622,8 +622,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='unbound'
 PACKAGE_TARNAME='unbound'
-PACKAGE_VERSION='1.25.1'
-PACKAGE_STRING='unbound 1.25.1'
+PACKAGE_VERSION='1.25.2'
+PACKAGE_STRING='unbound 1.25.2'
 PACKAGE_BUGREPORT='unbound-bugs@nlnetlabs.nl or https://github.com/NLnetLabs/unbound/issues'
 PACKAGE_URL=''
 
@@ -1516,7 +1516,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures unbound 1.25.1 to adapt to many kinds of systems.
+\`configure' configures unbound 1.25.2 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1582,7 +1582,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of unbound 1.25.1:";;
+     short | recursive ) echo "Configuration of unbound 1.25.2:";;
    esac
   cat <<\_ACEOF
 
@@ -1835,7 +1835,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-unbound configure 1.25.1
+unbound configure 1.25.2
 generated by GNU Autoconf 2.71
 
 Copyright (C) 2021 Free Software Foundation, Inc.
@@ -2492,7 +2492,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by unbound $as_me 1.25.1, which was
+It was created by unbound $as_me 1.25.2, which was
 generated by GNU Autoconf 2.71.  Invocation command line was
 
   $ $0$ac_configure_args_raw
@@ -3256,11 +3256,11 @@ UNBOUND_VERSION_MAJOR=1
 
 UNBOUND_VERSION_MINOR=25
 
-UNBOUND_VERSION_MICRO=1
+UNBOUND_VERSION_MICRO=2
 
 
 LIBUNBOUND_CURRENT=9
-LIBUNBOUND_REVISION=37
+LIBUNBOUND_REVISION=38
 LIBUNBOUND_AGE=1
 # 1.0.0 had 0:12:0
 # 1.0.1 had 0:13:0
@@ -3365,6 +3365,7 @@ LIBUNBOUND_AGE=1
 # 1.24.2 had 9:35:1
 # 1.25.0 had 9:36:1
 # 1.25.1 had 9:37:1
+# 1.25.2 had 9:38:1
 
 #   Current  -- the number of the binary API that we're implementing
 #   Revision -- which iteration of the implementation of the binary
@@ -23677,6 +23678,29 @@ printf "%s\n" "no" >&6; }
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
 
+    ac_fn_check_decl "$LINENO" "CLOCK_MONOTONIC
+        " "ac_cv_have_decl_CLOCK_MONOTONIC_________" "$ac_includes_default
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+" "$ac_c_undeclared_builtin_options" "CFLAGS"
+if test "x$ac_cv_have_decl_CLOCK_MONOTONIC_________" = xyes
+then :
+
+
+else $as_nop
+  as_fn_error $? "ngtcp2 for QUIC needs at least CLOCK_MONOTONIC on the system" "$LINENO" 5
+
+fi
+
 fi
 
 # set static linking for uninstalled libraries if requested
@@ -26307,7 +26331,7 @@ printf "%s\n" "#define MAXSYSLOGMSGLEN 10240" >>confdefs.h
 
 
 
-version=1.25.1
+version=1.25.2
 
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for build time" >&5
 printf %s "checking for build time... " >&6; }
@@ -26837,7 +26861,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by unbound $as_me 1.25.1, which was
+This file was extended by unbound $as_me 1.25.2, which was
 generated by GNU Autoconf 2.71.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -26905,7 +26929,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config='$ac_cs_config_escaped'
 ac_cs_version="\\
-unbound config.status 1.25.1
+unbound config.status 1.25.2
 configured by $0, generated by GNU Autoconf 2.71,
   with options \\"\$ac_cs_config\\"
 
diff --git a/contrib/unbound/configure.ac b/contrib/unbound/configure.ac
index f1c5b0419782..a4b6b17bdc65 100644
--- a/contrib/unbound/configure.ac
+++ b/contrib/unbound/configure.ac
@@ -12,14 +12,14 @@ sinclude(dnscrypt/dnscrypt.m4)
 # must be numbers. ac_defun because of later processing
 m4_define([VERSION_MAJOR],[1])
 m4_define([VERSION_MINOR],[25])
-m4_define([VERSION_MICRO],[1])
+m4_define([VERSION_MICRO],[2])
 AC_INIT([unbound],m4_defn([VERSION_MAJOR]).m4_defn([VERSION_MINOR]).m4_defn([VERSION_MICRO]),[unbound-bugs@nlnetlabs.nl or https://github.com/NLnetLabs/unbound/issues],[unbound])
 AC_SUBST(UNBOUND_VERSION_MAJOR, [VERSION_MAJOR])
 AC_SUBST(UNBOUND_VERSION_MINOR, [VERSION_MINOR])
 AC_SUBST(UNBOUND_VERSION_MICRO, [VERSION_MICRO])
 
 LIBUNBOUND_CURRENT=9
-LIBUNBOUND_REVISION=37
+LIBUNBOUND_REVISION=38
 LIBUNBOUND_AGE=1
 # 1.0.0 had 0:12:0
 # 1.0.1 had 0:13:0
@@ -124,6 +124,7 @@ LIBUNBOUND_AGE=1
 # 1.24.2 had 9:35:1
 # 1.25.0 had 9:36:1
 # 1.25.1 had 9:37:1
+# 1.25.2 had 9:38:1
 
 #   Current  -- the number of the binary API that we're implementing
 #   Revision -- which iteration of the implementation of the binary
@@ -1735,6 +1736,22 @@ if test x_$withval = x_yes -o x_$withval != x_no; then
 	AC_MSG_RESULT(no)
     ])
 
+    AC_CHECK_DECL([CLOCK_MONOTONIC]
+        , []
+        , [AC_MSG_ERROR([ngtcp2 for QUIC needs at least CLOCK_MONOTONIC on the system])]
+        , [AC_INCLUDES_DEFAULT
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+        ])
+
 fi
 
 # set static linking for uninstalled libraries if requested
diff --git a/contrib/unbound/daemon/daemon.c b/contrib/unbound/daemon/daemon.c
index ea4e83e70932..51dd51de38d4 100644
--- a/contrib/unbound/daemon/daemon.c
+++ b/contrib/unbound/daemon/daemon.c
@@ -79,6 +79,7 @@
 #include "util/tcp_conn_limit.h"
 #include "util/edns.h"
 #include "services/listen_dnsport.h"
+#include "services/outside_network.h"
 #include "services/cache/rrset.h"
 #include "services/cache/infra.h"
 #include "services/localzone.h"
@@ -813,6 +814,10 @@ daemon_create_workers(struct daemon* daemon)
 		fatal_exit("out of memory during daemon init");
 	numport = daemon_get_shufport(daemon, shufport);
 	verbose(VERB_ALGO, "total of %d outgoing ports available", numport);
+	if(!(daemon->shared_ports = shared_ports_create(daemon->cfg->out_ifs,
+		daemon->cfg->num_out_ifs, daemon->cfg->do_ip4,
+		daemon->cfg->do_ip6, shufport, numport)))
+		fatal_exit("could not setup shared ports: out of memory");
 
 #ifdef HAVE_NGTCP2
 	if (cfg_has_quic(daemon->cfg)) {
@@ -843,10 +848,7 @@ daemon_create_workers(struct daemon* daemon)
 #endif
 	}
 	for(i=0; i<daemon->num; i++) {
-		if(!(daemon->workers[i] = worker_create(daemon, i,
-			shufport+numport*i/daemon->num, 
-			numport*(i+1)/daemon->num - numport*i/daemon->num)))
-			/* the above is not ports/numthr, due to rounding */
+		if(!(daemon->workers[i] = worker_create(daemon, i)))
 			fatal_exit("could not create worker");
 	}
 	/* create per-worker alloc caches if not reusing existing ones. */
@@ -1204,6 +1206,8 @@ daemon_cleanup(struct daemon* daemon)
 	if(!daemon->reuse_cache || daemon->need_to_exit)
 		daemon_clear_allocs(daemon);
 	daemon->num = 0;
+	shared_ports_delete(daemon->shared_ports);
+	daemon->shared_ports = NULL;
 #ifdef USE_DNSTAP
 	dt_delete(daemon->dtenv);
 	daemon->dtenv = NULL;
diff --git a/contrib/unbound/daemon/daemon.h b/contrib/unbound/daemon/daemon.h
index 20386d7fc9a0..e6f099629be1 100644
--- a/contrib/unbound/daemon/daemon.h
+++ b/contrib/unbound/daemon/daemon.h
@@ -62,6 +62,7 @@ struct doq_table;
 struct cookie_secrets;
 struct fast_reload_thread;
 struct fast_reload_printq;
+struct shared_ports;
 
 #include "dnstap/dnstap_config.h"
 #ifdef USE_DNSTAP
@@ -97,6 +98,8 @@ struct daemon {
 	int rc_port;
 	/** listening ports for remote control */
 	struct listen_port* rc_ports;
+	/** the shared ports structure, with random ports numbers. */
+	struct shared_ports* shared_ports;
 	/** remote control connections management (for first worker) */
 	struct daemon_remote* rc;
 	/** ssl context for listening to dnstcp over ssl */
diff --git a/contrib/unbound/daemon/remote.c b/contrib/unbound/daemon/remote.c
index 1eaf90016b88..61beb7c2fa69 100644
--- a/contrib/unbound/daemon/remote.c
+++ b/contrib/unbound/daemon/remote.c
@@ -1658,6 +1658,14 @@ do_view_data_add(RES* ssl, struct worker* worker, char* arg)
 			ssl_printf(ssl,"error out of memory\n");
 			return;
 		}
+		if(!v->isfirst) {
+			/* Global local-zone is not used for this view,
+			 * therefore add defaults to this view-specific
+			 * local-zone. */
+			struct config_file lz_cfg;
+			memset(&lz_cfg, 0, sizeof(lz_cfg));
+			local_zone_enter_defaults(v->local_zones, &lz_cfg);
+		}
 	}
 	do_data_add(ssl, v->local_zones, arg2);
 	lock_rw_unlock(&v->lock);
@@ -1683,6 +1691,14 @@ do_view_datas_add(struct daemon_remote* rc, RES* ssl, struct worker* worker,
 			ssl_printf(ssl,"error out of memory\n");
 			return;
 		}
+		if(!v->isfirst) {
+			/* Global local-zone is not used for this view,
+			 * therefore add defaults to this view-specific
+			 * local-zone. */
+			struct config_file lz_cfg;
+			memset(&lz_cfg, 0, sizeof(lz_cfg));
+			local_zone_enter_defaults(v->local_zones, &lz_cfg);
+		}
 	}
 	/* put the view name in the command buf */
 	(void)snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%s ", arg);
diff --git a/contrib/unbound/daemon/worker.c b/contrib/unbound/daemon/worker.c
index a5dd9bc028e8..765fb2299a55 100644
--- a/contrib/unbound/daemon/worker.c
+++ b/contrib/unbound/daemon/worker.c
@@ -1550,6 +1550,7 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
 				return 0;
 			}
 			query_error(c->buffer, LDNS_RCODE_FORMERR, 0);
+			sldns_buffer_copy(c->dnscrypt_buffer, c->buffer);
 			return 1;
 		}
 		dname_str(qinfo.qname, buf);
@@ -1568,6 +1569,7 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
 			query_error(c->buffer, LDNS_RCODE_SERVFAIL,
 				qinfo.qname_len);
 			worker->stats.num_query_dnscrypt_cleartext++;
+			sldns_buffer_copy(c->dnscrypt_buffer, c->buffer);
 			return 1;
 		}
 		worker->stats.num_query_dnscrypt_cert++;
@@ -1828,7 +1830,13 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
 		server_stats_insquery(&worker->stats, c, qinfo.qtype,
 			qinfo.qclass, &edns, repinfo);
 	if(c->type != comm_udp)
+#ifdef USE_DNSCRYPT
+		edns.udp_size = (c->dnscrypt && repinfo->is_dnscrypted)
+			? sldns_buffer_capacity(c->buffer) - DNSCRYPT_REPLY_HEADER_SIZE
+			: 65535;
+#else
 		edns.udp_size = 65535; /* max size for TCP replies */
+#endif
 	if(qinfo.qclass == LDNS_RR_CLASS_CH && answer_chaos(worker, &qinfo,
 		&edns, repinfo, c->buffer)) {
 		regional_free_all(worker->scratchpad);
@@ -2112,7 +2120,7 @@ send_reply_rc:
 		}
 	}
 #ifdef USE_DNSCRYPT
-	if(!dnsc_handle_uncurved_request(repinfo)) {
+	if(!dnsc_handle_uncurved_request(repinfo, c->buffer)) {
 		return 0;
 	}
 #endif
@@ -2225,23 +2233,16 @@ void worker_probe_timer_cb(void* arg)
 }
 
 struct worker*
-worker_create(struct daemon* daemon, int id, int* ports, int n)
+worker_create(struct daemon* daemon, int id)
 {
 	unsigned int seed;
 	struct worker* worker = (struct worker*)calloc(1,
 		sizeof(struct worker));
 	if(!worker)
 		return NULL;
-	worker->numports = n;
-	worker->ports = (int*)memdup(ports, sizeof(int)*n);
-	if(!worker->ports) {
-		free(worker);
-		return NULL;
-	}
 	worker->daemon = daemon;
 	worker->thread_num = id;
 	if(!(worker->cmd = tube_create())) {
-		free(worker->ports);
 		free(worker);
 		return NULL;
 	}
@@ -2249,7 +2250,6 @@ worker_create(struct daemon* daemon, int id, int* ports, int n)
 	if(!(worker->rndstate = ub_initstate(daemon->rand))) {
 		log_err("could not init random numbers.");
 		tube_delete(worker->cmd);
-		free(worker->ports);
 		free(worker);
 		return NULL;
 	}
@@ -2348,14 +2348,14 @@ worker_init(struct worker* worker, struct config_file *cfg,
 		cfg->out_ifs, cfg->num_out_ifs, cfg->do_ip4, cfg->do_ip6,
 		cfg->do_tcp?cfg->outgoing_num_tcp:0, cfg->ip_dscp,
 		worker->daemon->env->infra_cache, worker->rndstate,
-		cfg->use_caps_bits_for_id, worker->ports, worker->numports,
+		cfg->use_caps_bits_for_id,
 		cfg->unwanted_threshold, cfg->outgoing_tcp_mss,
 		&worker_alloc_cleanup, worker,
 		cfg->do_udp || cfg->udp_upstream_without_downstream,
 		worker->daemon->connect_dot_sslctx, cfg->delay_close,
 		cfg->tls_use_sni, dtenv, cfg->udp_connect,
 		cfg->max_reuse_tcp_queries, cfg->tcp_reuse_timeout,
-		cfg->tcp_auth_query_timeout);
+		cfg->tcp_auth_query_timeout, worker->daemon->shared_ports);
 	if(!worker->back) {
 		log_err("could not create outgoing sockets");
 		worker_delete(worker);
@@ -2506,7 +2506,6 @@ worker_delete(struct worker* worker)
 	tube_delete(worker->cmd);
 	comm_timer_delete(worker->stat_timer);
 	comm_timer_delete(worker->env.probe_timer);
-	free(worker->ports);
 	if(worker->thread_num == 0) {
 #ifdef UB_ON_WINDOWS
 		wsvc_desetup_worker(worker);
@@ -2638,6 +2637,11 @@ void libworker_event_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode),
 	log_assert(0);
 }
 
+void libworker_alloc_cleanup(void* ATTR_UNUSED(arg))
+{
+	log_assert(0);
+}
+
 int context_query_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
 {
 	log_assert(0);
diff --git a/contrib/unbound/daemon/worker.h b/contrib/unbound/daemon/worker.h
index b7bb52fd715b..37f3728efef1 100644
--- a/contrib/unbound/daemon/worker.h
+++ b/contrib/unbound/daemon/worker.h
@@ -104,10 +104,6 @@ struct worker {
 	struct listen_dnsport* front;
 	/** the backside outside network interface to the auth servers */
 	struct outside_network* back;
-	/** ports to be used by this worker. */
-	int* ports;
-	/** number of ports for this worker */
-	int numports;
 	/** the signal handler */
 	struct comm_signal* comsig;
 	/** commpoint to listen to commands. */
@@ -146,11 +142,9 @@ struct worker {
  * with backpointers only. Use worker_init on it later.
  * @param daemon: the daemon that this worker thread is part of.
  * @param id: the thread number from 0.. numthreads-1.
- * @param ports: the ports it is allowed to use, array.
- * @param n: the number of ports.
  * @return: the new worker or NULL on alloc failure.
  */
-struct worker* worker_create(struct daemon* daemon, int id, int* ports, int n);
+struct worker* worker_create(struct daemon* daemon, int id);
 
 /**
  * Initialize worker.
diff --git a/contrib/unbound/dnscrypt/dnscrypt.c b/contrib/unbound/dnscrypt/dnscrypt.c
index 173484cdf0b1..6f1a236ad7e5 100644
--- a/contrib/unbound/dnscrypt/dnscrypt.c
+++ b/contrib/unbound/dnscrypt/dnscrypt.c
@@ -474,10 +474,18 @@ dnscrypt_server_curve(const dnsccert *cert,
     uint8_t *const buf = sldns_buffer_begin(buffer);
     size_t len = sldns_buffer_limit(buffer);
 
+    if(len + DNSCRYPT_REPLY_HEADER_SIZE > sldns_buffer_capacity(buffer))
+	return -1;
+    sldns_buffer_clear(buffer);
+
     if(udp){
         if (max_len > max_reply_size)
             max_len = max_reply_size;
     }
+    if(max_len > sldns_buffer_capacity(buffer))
+	max_len = sldns_buffer_capacity(buffer);
+    if(max_len > 65535)
+	    max_len = 65535;
 
 
     memcpy(nonce, client_nonce, crypto_box_HALF_NONCEBYTES);
@@ -520,6 +528,7 @@ dnscrypt_server_curve(const dnsccert *cert,
                           DNSCRYPT_MAGIC_HEADER_LEN,
                           nonce,
                           crypto_box_NONCEBYTES);
+    sldns_buffer_flip(buffer);
     sldns_buffer_set_limit(buffer, len + DNSCRYPT_REPLY_HEADER_SIZE);
     return 0;
 }
@@ -663,6 +672,8 @@ dnsc_find_cert(struct dnsc_env* dnscenv, struct sldns_buffer* buffer)
 	}
 	dnscrypt_header = (struct dnscrypt_query_header *)sldns_buffer_begin(buffer);
 	for (i = 0U; i < dnscenv->signed_certs_count; i++) {
+		if(!certs[i].keypair)
+			continue;
 		if (memcmp(certs[i].magic_query, dnscrypt_header->magic_query,
                    DNSCRYPT_MAGIC_HEADER_LEN) == 0) {
 			return &certs[i];
@@ -804,6 +815,7 @@ dnsc_parse_keys(struct dnsc_env *env, struct config_file *cfg)
 		sizeof *env->keypairs);
 	env->certs = sodium_allocarray(env->signed_certs_count,
 		sizeof *env->certs);
+	memset(env->certs, 0, env->signed_certs_count * sizeof(*env->certs));
 
 	cert_id = 0U;
 	keypair_id = 0U;
@@ -912,12 +924,13 @@ dnsc_handle_curved_request(struct dnsc_env* dnscenv,
 }
 
 int
-dnsc_handle_uncurved_request(struct comm_reply *repinfo)
+dnsc_handle_uncurved_request(struct comm_reply *repinfo,
+	struct sldns_buffer* buffer)
 {
     if(!repinfo->c->dnscrypt) {
         return 1;
     }
-    sldns_buffer_copy(repinfo->c->dnscrypt_buffer, repinfo->c->buffer);
+    sldns_buffer_copy(repinfo->c->dnscrypt_buffer, buffer);
     if(!repinfo->is_dnscrypted) {
         return 1;
     }
@@ -963,12 +976,19 @@ dnsc_create(void)
 int
 dnsc_apply_cfg(struct dnsc_env *env, struct config_file *cfg)
 {
+    int nkeys;
     if(dnsc_parse_certs(env, cfg) <= 0) {
         fatal_exit("dnsc_apply_cfg: no cert file loaded");
     }
-    if(dnsc_parse_keys(env, cfg) <= 0) {
+    nkeys = dnsc_parse_keys(env, cfg);
+    if(nkeys <= 0) {
         fatal_exit("dnsc_apply_cfg: no key file loaded");
     }
+    if((size_t)nkeys < env->signed_certs_count) {
+	fatal_exit("dnsc_apply_cfg: %u dnscrypt-provider-cert file(s) have no "
+		"matching dnscrypt-secret-key",
+		(unsigned)(env->signed_certs_count - (size_t)nkeys));
+    }
     randombytes_buf(env->hash_key, sizeof env->hash_key);
     env->provider_name = cfg->dnscrypt_provider;
 
diff --git a/contrib/unbound/dnscrypt/dnscrypt.h b/contrib/unbound/dnscrypt/dnscrypt.h
index b0da9b732681..998237d48e83 100644
--- a/contrib/unbound/dnscrypt/dnscrypt.h
+++ b/contrib/unbound/dnscrypt/dnscrypt.h
@@ -128,7 +128,8 @@ int dnsc_handle_curved_request(struct dnsc_env* dnscenv,
  * \return 0 in case of failure.
  */
 
-int dnsc_handle_uncurved_request(struct comm_reply *repinfo);
+int dnsc_handle_uncurved_request(struct comm_reply *repinfo,
+	struct sldns_buffer* buffer);
 
 /**
  * Computes the size of the shared secret cache entry.
diff --git a/contrib/unbound/dnstap/unbound-dnstap-socket.c b/contrib/unbound/dnstap/unbound-dnstap-socket.c
index 90b0f6003ff6..2bf017430fe0 100644
--- a/contrib/unbound/dnstap/unbound-dnstap-socket.c
+++ b/contrib/unbound/dnstap/unbound-dnstap-socket.c
@@ -1735,6 +1735,11 @@ void libworker_event_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode),
 	log_assert(0);
 }
 
+void libworker_alloc_cleanup(void* ATTR_UNUSED(arg))
+{
+	log_assert(0);
+}
+
 int context_query_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
 {
 	log_assert(0);
diff --git a/contrib/unbound/doc/README b/contrib/unbound/doc/README
index 265dc1592f9f..fa60d3b0b570 100644
--- a/contrib/unbound/doc/README
+++ b/contrib/unbound/doc/README
@@ -1,4 +1,4 @@
-README for Unbound 1.25.1
+README for Unbound 1.25.2
 Copyright 2007 NLnet Labs
 http://unbound.net
 
diff --git a/contrib/unbound/doc/example.conf b/contrib/unbound/doc/example.conf
index 82fd100dbbe9..5d4536a71f6e 100644
--- a/contrib/unbound/doc/example.conf
+++ b/contrib/unbound/doc/example.conf
@@ -1,7 +1,7 @@
 #
 # Example configuration file.
 #
-# See unbound.conf(5) man page, version 1.25.1.
+# See unbound.conf(5) man page, version 1.25.2.
 #
 # this is a comment.
 
diff --git a/contrib/unbound/doc/example.conf.in b/contrib/unbound/doc/example.conf.in
index 5514328b1235..e03d41153b36 100644
--- a/contrib/unbound/doc/example.conf.in
+++ b/contrib/unbound/doc/example.conf.in
@@ -1,7 +1,7 @@
 #
 # Example configuration file.
 #
-# See unbound.conf(5) man page, version 1.25.1.
+# See unbound.conf(5) man page, version 1.25.2.
 #
 # this is a comment.
 
diff --git a/contrib/unbound/doc/libunbound.3 b/contrib/unbound/doc/libunbound.3
index 91092e67d898..b9158ef902a7 100644
--- a/contrib/unbound/doc/libunbound.3
+++ b/contrib/unbound/doc/libunbound.3
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "LIBUNBOUND" "3" "May 20, 2026" "1.25.1" "Unbound"
+.TH "LIBUNBOUND" "3" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-libunbound \- Unbound DNS validating resolver 1.25.1 functions.
+libunbound \- Unbound DNS validating resolver 1.25.2 functions.
 .SH SYNOPSIS
 .sp
 \fB#include <unbound.h>\fP
diff --git a/contrib/unbound/doc/libunbound.3.in b/contrib/unbound/doc/libunbound.3.in
index 91092e67d898..b9158ef902a7 100644
--- a/contrib/unbound/doc/libunbound.3.in
+++ b/contrib/unbound/doc/libunbound.3.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "LIBUNBOUND" "3" "May 20, 2026" "1.25.1" "Unbound"
+.TH "LIBUNBOUND" "3" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-libunbound \- Unbound DNS validating resolver 1.25.1 functions.
+libunbound \- Unbound DNS validating resolver 1.25.2 functions.
 .SH SYNOPSIS
 .sp
 \fB#include <unbound.h>\fP
diff --git a/contrib/unbound/doc/unbound-anchor.8 b/contrib/unbound/doc/unbound-anchor.8
index c9e6b2114f9b..09dfafd4b3e7 100644
--- a/contrib/unbound/doc/unbound-anchor.8
+++ b/contrib/unbound/doc/unbound-anchor.8
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-ANCHOR" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-ANCHOR" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-anchor \- Unbound 1.25.1 anchor utility.
+unbound-anchor \- Unbound 1.25.2 anchor utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-anchor\fP [\fBopts\fP]
diff --git a/contrib/unbound/doc/unbound-anchor.8.in b/contrib/unbound/doc/unbound-anchor.8.in
index fa1486d18864..c9810f8f2c03 100644
--- a/contrib/unbound/doc/unbound-anchor.8.in
+++ b/contrib/unbound/doc/unbound-anchor.8.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-ANCHOR" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-ANCHOR" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-anchor \- Unbound 1.25.1 anchor utility.
+unbound-anchor \- Unbound 1.25.2 anchor utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-anchor\fP [\fBopts\fP]
diff --git a/contrib/unbound/doc/unbound-checkconf.8 b/contrib/unbound/doc/unbound-checkconf.8
index 9a42e3c309e1..c5904d52d282 100644
--- a/contrib/unbound/doc/unbound-checkconf.8
+++ b/contrib/unbound/doc/unbound-checkconf.8
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-CHECKCONF" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-CHECKCONF" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-checkconf \- Check Unbound 1.25.1 configuration file for errors.
+unbound-checkconf \- Check Unbound 1.25.2 configuration file for errors.
 .SH SYNOPSIS
 .sp
 \fBunbound\-checkconf\fP [\fB\-hf\fP] [\fB\-o option\fP] [cfgfile]
diff --git a/contrib/unbound/doc/unbound-checkconf.8.in b/contrib/unbound/doc/unbound-checkconf.8.in
index cfc4e2375e47..a3094e486a7b 100644
--- a/contrib/unbound/doc/unbound-checkconf.8.in
+++ b/contrib/unbound/doc/unbound-checkconf.8.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-CHECKCONF" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-CHECKCONF" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-checkconf \- Check Unbound 1.25.1 configuration file for errors.
+unbound-checkconf \- Check Unbound 1.25.2 configuration file for errors.
 .SH SYNOPSIS
 .sp
 \fBunbound\-checkconf\fP [\fB\-hf\fP] [\fB\-o option\fP] [cfgfile]
diff --git a/contrib/unbound/doc/unbound-control.8 b/contrib/unbound/doc/unbound-control.8
index e84d00d03bc5..f50ca271e415 100644
--- a/contrib/unbound/doc/unbound-control.8
+++ b/contrib/unbound/doc/unbound-control.8
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-CONTROL" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-CONTROL" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-control \- Unbound 1.25.1 remote server control utility.
+unbound-control \- Unbound 1.25.2 remote server control utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-control\fP [\fB\-hq\fP] [\fB\-c cfgfile\fP] [\fB\-s server\fP] command
diff --git a/contrib/unbound/doc/unbound-control.8.in b/contrib/unbound/doc/unbound-control.8.in
index faf3534d7af8..c1ad6b8d68c6 100644
--- a/contrib/unbound/doc/unbound-control.8.in
+++ b/contrib/unbound/doc/unbound-control.8.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-CONTROL" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-CONTROL" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-control \- Unbound 1.25.1 remote server control utility.
+unbound-control \- Unbound 1.25.2 remote server control utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-control\fP [\fB\-hq\fP] [\fB\-c cfgfile\fP] [\fB\-s server\fP] command
diff --git a/contrib/unbound/doc/unbound-host.1 b/contrib/unbound/doc/unbound-host.1
index 52185a5bb42c..c674a09545d3 100644
--- a/contrib/unbound/doc/unbound-host.1
+++ b/contrib/unbound/doc/unbound-host.1
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-HOST" "1" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-HOST" "1" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-host \- Unbound 1.25.1 DNS lookup utility.
+unbound-host \- Unbound 1.25.2 DNS lookup utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-host\fP [\fB\-C configfile\fP] [\fB\-vdhr46D\fP] [\fB\-c class\fP]
diff --git a/contrib/unbound/doc/unbound-host.1.in b/contrib/unbound/doc/unbound-host.1.in
index 6f3ef3f2593e..1582fd54813b 100644
--- a/contrib/unbound/doc/unbound-host.1.in
+++ b/contrib/unbound/doc/unbound-host.1.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND-HOST" "1" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND-HOST" "1" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound-host \- Unbound 1.25.1 DNS lookup utility.
+unbound-host \- Unbound 1.25.2 DNS lookup utility.
 .SH SYNOPSIS
 .sp
 \fBunbound\-host\fP [\fB\-C configfile\fP] [\fB\-vdhr46D\fP] [\fB\-c class\fP]
diff --git a/contrib/unbound/doc/unbound.8 b/contrib/unbound/doc/unbound.8
index 79f61bd89fed..3fdbc2e90430 100644
--- a/contrib/unbound/doc/unbound.8
+++ b/contrib/unbound/doc/unbound.8
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND" "8" "May 20, 2026" "1.25.1" "Unbound"
+.TH "UNBOUND" "8" "Jul 22, 2026" "1.25.2" "Unbound"
 .SH NAME
-unbound \- Unbound DNS validating resolver 1.25.1.
+unbound \- Unbound DNS validating resolver 1.25.2.
 .SH SYNOPSIS
 .sp
 \fBunbound\fP [\fB\-hdpVv\fP] [\fB\-c <cfgfile>\fP]
diff --git a/contrib/unbound/doc/unbound.8.in b/contrib/unbound/doc/unbound.8.in
index a66ee68469a3..cf15d5b2b4a9 100644
--- a/contrib/unbound/doc/unbound.8.in
+++ b/contrib/unbound/doc/unbound.8.in
@@ -27,9 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "UNBOUND" "8" "May 20, 2026" "1.25.1" "Unbound"
*** 2768 LINES SKIPPED ***

From nobody Mon Aug  3 11:38:42 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF765c0Qz6nCHJ
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:42 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF763bk3z3RkM
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:42 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757122;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=OrqXxTnD00floaJtSZ1zg6JV80iJJBR4qG7agh4bwN4=;
	b=VMbVVfxAXVx6TeEGVStLLdT5szRhIs53WmddsVr0Ik5eQ0xEbdLWzwzblsMjxtImjlFI1o
	nw2O314ruEVjwnrj1HxtDsAf9txgBYYwusPcXf/pTxcdHXPJRMqkmUpoUVTHmllYfaXeOE
	vSDTf7PxxmgW8PjToYGyoHKnZmr/8UuPehrAMoGy/b08/TJNwsWyjedqgKcci2gkRGtRH+
	G5apqRUgRVoeeFX4J8zG/wT7m71SVguF9kPD93g3tqZ+vq13yd+kA3bGljqOUnbfNscRYw
	0onQLJpaogACBzJ6pxZqZFEdARehFcaH+ShF5NgEMYwxIaAwF/zxQnZvVdjiIw==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757122; a=rsa-sha256; cv=none;
	b=doCoB9R4lWE8+fA4BlZrA8YO7LcmJq/VgrwFN0SL/lGIpm2h2kRkt0As7fiE5hvptjJQAZ
	1/gX//ScR29XOep11ewEZgpAw6Dmcf+2O4Bbk/lRecjfgFdRmBM2XU0cz8CM+owtqBGHSW
	83fKIlczmXjGxrOPsO0q1lgwBQOr/EWNs/ul9xyoF/e8V6NksC5lz91+sfJFhepncBDmdt
	02IVY/aqdu/tgNMroIwReAN5a21G9Iyd/VOzce0eEbPNnys/6AMtSvGG3RYgo4BJ+JXe9a
	gL8VBU+fv8kU2/ehhF3R5Dbkk0nbyPaYopMaIJQO1h9R4ligdt4I6XC1RvCkzg==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757122;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=OrqXxTnD00floaJtSZ1zg6JV80iJJBR4qG7agh4bwN4=;
	b=S4aKF5uAO6jSXBuYQa27cglElyN8mC7wdLNIuUzCmPMKi5BZVIeNTQZnRBSRGxZSyvPPaJ
	g16c7eD4VVhj+J+8CEAdMLIxG9hRH1GoT/WC+G8FwxdIzqH3undQCUXDAVzacxAMNg+MJx
	8Ptt6gQT6KD4Kcru3s7JrllpBz6s/sbAaDqBo+Hu5H0IoL+/CyXMVsuZKNuZ9CggBcu55B
	zcMHEc5YXd/B0BTFM1ieSweNS8Ah9GupwtzfpvUOnqG1C4tgrzG7cQW/qZzxQmoOyshj4s
	eSpKThgiSDptYChbNYB3hcUmH6at3tjETOjrQUZlKGA2DenEzpffOJTWGdCN/Q==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF762211zypq
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:42 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1be75
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:42 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 70b3d322e5b0 - stable/14 - kqueue: Fix delivery of unwanted events
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 70b3d322e5b028e9e098f5cea62164af7d9c6fa3
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:42 +0000
Message-Id: <6a707dc2.1be75.5d04f10c@gitrepo.freebsd.org>

The branch stable/14 has been updated by des:

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

commit 70b3d322e5b028e9e098f5cea62164af7d9c6fa3
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-23 06:06:32 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:13 +0000

    kqueue: Fix delivery of unwanted events
    
    In both procdesc_kqops_event() and filt_proc(), the event variable can
    have more than one bit set.  This means that:
    
    * We cannot compare it directly with NOTE_EXIT; we must binary-and them
      instead.
    
    * We cannot binary-or it with the report mask; we must binary-and it
      with the request mask first.
    
    MFC after:      1 week
    Fixes:          2a5e58c59694 ("procdesc: add NOTE_PDSIGCHLD")
    Fixes:          b328975b9d7c ("procdesc: report NOTE_PDSIGCHLD for traced and stopped process")
    Reviewed by:    kib, markj
    Differential Revision:  https://reviews.freebsd.org/D58395
    
    (cherry picked from commit 4627fe9e5afc0dce4469f5964f5d4b0e49a24274)
---
 sys/kern/kern_event.c   | 6 +++---
 sys/kern/sys_procdesc.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index aaffbfce432c..e2f44aea27b4 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -505,11 +505,11 @@ filt_proc(struct knote *kn, long hint)
 	event = (u_int)hint & NOTE_PCTRLMASK;
 
 	/* If the user is interested in this event, record it. */
-	if (kn->kn_sfflags & event)
-		kn->kn_fflags |= event;
+	if ((kn->kn_sfflags & event) != 0)
+		kn->kn_fflags |= kn->kn_sfflags & event;
 
 	/* Process is gone, so flag the event as finished. */
-	if (event == NOTE_EXIT) {
+	if ((event & NOTE_EXIT) != 0) {
 		kn->kn_flags |= EV_EOF | EV_ONESHOT;
 		kn->kn_ptr.p_proc = NULL;
 		if (kn->kn_fflags & NOTE_EXIT)
diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c
index 515d0365ec61..f1aeb4066fa4 100644
--- a/sys/kern/sys_procdesc.c
+++ b/sys/kern/sys_procdesc.c
@@ -465,8 +465,8 @@ procdesc_kqops_event(struct knote *kn, long hint)
 	}
 
 	/* If the user is interested in this event, record it. */
-	if (kn->kn_sfflags & event)
-		kn->kn_fflags |= event;
+	if ((kn->kn_sfflags & event) != 0)
+		kn->kn_fflags |= kn->kn_sfflags & event;
 
 	/* Process is gone, so flag the event as finished. */
 	if (event == NOTE_EXIT) {

From nobody Mon Aug  3 11:38:43 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF776kKrz6nCGL
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:43 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF774HMxz3Rdx
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:43 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757123;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=QD1FtKcqX47X9kbueXja3WUgICr2o47ZGEY2BvLE+MY=;
	b=L5Ra/zyFvF8syWHNeXwDMZcP2FoTDAK6jdp1Spih8PXw5Eaenxli/Jl7QCOh5c7bA5TMEk
	56uROcuG6g4wbI+1iEOUZbg8zZ0TxW5soZkAcuGc87IhnJdNl490Bed0Zd8BHofG/nezdd
	p3mw7y0JfhFGyxd15WGZzjJxDEd3Pb1oIPDZDwDVldVcru9mOveus3EYAqZTRPUI125lWw
	nte/EO1foNmxTpmr1BhVDb++XBpdeoDHFdcNXQUSWVmgRvK9Ntk5tjmpGLmY2fV3kW4sh8
	NxOJKgiHg+64s1DXHCKiG1IXVZl8TWhdZPAbzvmuU0nTVWdWsS2gj/gvLXGzVA==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757123; a=rsa-sha256; cv=none;
	b=ZMscA9Ju4SiqkHlFn9EkukNzZ9Wq41HHVJhnlWrU7ZfvJAYaBc9pt5OcixAwbrIGNMNHKc
	csvj7Jm4OaA/20O17PfG588qOVZjfGaw52eNeyuMLKGK/ICmPPozj80LFEsN60NrFLsgsA
	qfFOu4zOuWrYZ9eyj5ChuVZwcoCas3NWzYIAvCEiMcE6mlS9PLbG8gx1TFHuzRPC7caE9a
	8vH+Mkgk6X1AjAQWvYhYPIKuMhCxpQVIPaRpfcnxBblAUKx0M3uwCAcrKk6S+XQ+QBYwB4
	oPaqupQqcLVH6IBEJSPLe2NV1/VNH+ODBlkgbzXkdM8A3ZNc0+Rn0swhH6e2LQ==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757123;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=QD1FtKcqX47X9kbueXja3WUgICr2o47ZGEY2BvLE+MY=;
	b=fSXg9FqfhEx3tDWJoD3naWqNl4ggNTF92lGJUZorpEV6GwzYnqAtyqcRhAshPvJ3l1ZdNX
	+74IBY1E54I5u5/0KooKUabuL2JoslSBR/HoN3JWRKBsn2GrnQ6WIbkcbYUlB2fryOfCgn
	6sGICM8ZytcGBwPUrT/jcJgwZqh/1OsO67DaSFuctMwYJ7wLMKvvmd1IFpd3lgABx0u1c0
	tayLMSVpRmhlo6BUrxIyOZsYggyNZyi8wk8je3DqPWz04U3c1cHR5WwGvDPXM2pDtUQTNA
	2KYkJxCgwI5csIXErb0e66qwON/491zBYxsuX6OF/2pvNyvyd3D1oJHUqncDLQ==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF772w2zzykc
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:43 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1c1f5
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:43 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: c4700dbbf9b5 - stable/14 - pwait: Don't use init as a target
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: c4700dbbf9b56887208e2967eacdc98cba34aab2
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:43 +0000
Message-Id: <6a707dc3.1c1f5.2f200a1@gitrepo.freebsd.org>

The branch stable/14 has been updated by des:

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

commit c4700dbbf9b56887208e2967eacdc98cba34aab2
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-25 12:44:35 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:13 +0000

    pwait: Don't use init as a target
    
    The time_unit test case uses PID 1 as a target for pwait.  This doesn't
    work in a jail.  Since all we need is a process that we know won't die
    while the test is running, we may as well use ourselves.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    ngie
    Differential Revision:  https://reviews.freebsd.org/D58418
    
    (cherry picked from commit 5922e9d7e72bfa8a85b0f37bcfd1a8b5d866ec3b)
---
 bin/pwait/tests/pwait_test.sh | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/bin/pwait/tests/pwait_test.sh b/bin/pwait/tests/pwait_test.sh
index d31ca21cff93..0d4f53d2941d 100644
--- a/bin/pwait/tests/pwait_test.sh
+++ b/bin/pwait/tests/pwait_test.sh
@@ -56,31 +56,29 @@ time_unit_head()
 
 time_unit_body()
 {
-	init=1
-
 	atf_check \
 		-o empty \
 		-e inline:"pwait: timeout unit\n" \
 		-s exit:65 \
-		timeout --preserve-status 2 pwait -t 1d $init
+		timeout --preserve-status 2 pwait -t 1d $$
 
 	atf_check \
 		-o empty \
 		-e inline:"pwait: timeout unit\n" \
 		-s exit:65 \
-		timeout --preserve-status 2 pwait -t 1d $init
+		timeout --preserve-status 2 pwait -t 1d $$
 
 	atf_check \
 		-o empty \
 		-e inline:"pwait: timeout value\n" \
 		-s exit:65 \
-		timeout --preserve-status 2 pwait -t -1 $init
+		timeout --preserve-status 2 pwait -t -1 $$
 
 	atf_check \
 		-o empty \
 		-e inline:"pwait: timeout value\n" \
 		-s exit:65 \
-		timeout --preserve-status 2 pwait -t 100000001 $init
+		timeout --preserve-status 2 pwait -t 100000001 $$
 
 	# These long duration cases are expected to timeout from the
 	# timeout utility rather than pwait -t.
@@ -88,37 +86,37 @@ time_unit_body()
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 100000000 $init
+		timeout --preserve-status 2 pwait -t 100000000 $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 1h $init
+		timeout --preserve-status 2 pwait -t 1h $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 1.5h $init
+		timeout --preserve-status 2 pwait -t 1.5h $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 1m $init
+		timeout --preserve-status 2 pwait -t 1m $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 1.5m $init
+		timeout --preserve-status 2 pwait -t 1.5m $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s signal:15 \
-		timeout --preserve-status 2 pwait -t 0 $init
+		timeout --preserve-status 2 pwait -t 0 $$
 
 	# The rest are fast enough that pwait -t is expected to trigger
 	# the timeout.
@@ -126,31 +124,31 @@ time_unit_body()
 		-o empty \
 		-e empty \
 		-s exit:124 \
-		timeout --preserve-status 2 pwait -t 1s $init
+		timeout --preserve-status 2 pwait -t 1s $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s exit:124 \
-		timeout --preserve-status 2 pwait -t 1.5s $init
+		timeout --preserve-status 2 pwait -t 1.5s $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s exit:124 \
-		timeout --preserve-status 2 pwait -t 1 $init
+		timeout --preserve-status 2 pwait -t 1 $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s exit:124 \
-		timeout --preserve-status 2 pwait -t 1.5 $init
+		timeout --preserve-status 2 pwait -t 1.5 $$
 
 	atf_check \
 		-o empty \
 		-e empty \
 		-s exit:124 \
-		timeout --preserve-status 2 pwait -t 0.5 $init
+		timeout --preserve-status 2 pwait -t 0.5 $$
 }
 
 atf_test_case timeout_trigger_timeout

From nobody Mon Aug  3 11:38:42 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF772yrCz6nCHL
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:43 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF765FYfz3Rw4
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:42 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757122;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=WP2hfWok+K4Opl5Z7nWEWc1LEO/6rby3obyMAUAaKoo=;
	b=rfB/2vyhWnDM2zxtLbZHicjnQmank2v8d0WBf50WaP5Yl+XnM3bJVKIzytVOvNf+T4NH7S
	TVIDQ/Q/94S5XJLu3x/wYK7pEVNJbyVXJ8QGCMTXh1fgiSA1F5tdYbpMNFvLYFlCGkre9+
	rM6b3+bEH6mcktmnFNyH4n3HKHUF9+iX5Grw5y5SnX2LRX61t7EnDBzoPaH++ZT5JHw10M
	gqU858qIELY6mwoDWNc5FfnKIAw1UCNRkAQLp/F57b5NjP1DeL0Rl/XViqVuLaVHVJB2xp
	ZKFjWT6LUyfnH0u0lOW/OsPAmrOCuIsw/eQDAuiwVxBasZe2ixDG71pteyg8xg==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757122; a=rsa-sha256; cv=none;
	b=wA/eFYsRzLfmWDPXBjp1IMZVoc3oHgMiT4TaYmQor1ZPSS+C+vi806hzXmSdBwtjdI3Kkn
	0Aexu4H9bJpykgEPByi89kdy8jZfDv5o0JtzMQXVwYqpuRHjKsHlqmZZbJlOJw1XYWrapk
	RmE/AvpgWjQvGiGZJlEicrzSYcuTg6GA61B6u8ZL4TVJEV8Sf2hV03PnBVa1VQgTsMGsn0
	0O3LtRlBt+vqsVTsvJ7llIX1/tBybZx7Sfudqpfr1ZcUmMKJHWoKtd2AU/gzwGafAznFJh
	01zWrdvmj6JcJwGyZRngC2dACILHiX/Hkf6v1pU+eG7ujkb8wwX2D2nRsMbB3w==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757122;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=WP2hfWok+K4Opl5Z7nWEWc1LEO/6rby3obyMAUAaKoo=;
	b=WNMT3EcEgJVoGliyktr+jmIkWUl7labl+ywanIwfn8iHW0PSQyBBui8NIwW7yyryyaYq3q
	2VOBi1HXA3eiqkl5R2Ny2sScQfF51qTSQ/uGpcnYDYm/DsDozGDzUmRmecNkW4FkpnCUqJ
	I7ambDipQOlgeuwa8aiRsj/EdJwSmZjOmTkGJVhrEWEck0oFcZQyNoUSAUnnGgmezLYTJs
	g8CjQJYsIfVWXEyQo9KQeQ3STkOCg7TP8Mxp0itO76IQxyeKByQwsc8UEPkMITg2/RFor/
	aUglNjHqyj8BRifIkGBEIPNPF/xdhon9cvjlbGp8LBfBEfUm3xM6cD1+YDKngg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF763xVkzyhQ
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:42 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1be8f
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:42 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: e87afada8e8a - stable/15 - pwait: Test the new -r option
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: e87afada8e8ad34e9ddb91073ec112835f1ef57d
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:42 +0000
Message-Id: <6a707dc2.1be8f.40e7dc33@gitrepo.freebsd.org>

The branch stable/15 has been updated by des:

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

commit e87afada8e8ad34e9ddb91073ec112835f1ef57d
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:15:41 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:12 +0000

    pwait: Test the new -r option
    
    Test that pwait without -r reports a process as soon as it terminates,
    while pwait with -r does not report it until it has been reaped.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D58385
    
    (cherry picked from commit e115066370dcfec410d914362756d09c268a5b4e)
---
 bin/pwait/tests/Makefile     |   1 +
 bin/pwait/tests/pwait_reap.c | 188 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 189 insertions(+)

diff --git a/bin/pwait/tests/Makefile b/bin/pwait/tests/Makefile
index 4e355ccfe787..0f9359c92593 100644
--- a/bin/pwait/tests/Makefile
+++ b/bin/pwait/tests/Makefile
@@ -1,3 +1,4 @@
+ATF_TESTS_C=	pwait_reap
 ATF_TESTS_SH=	pwait_test
 
 .include <bsd.test.mk>
diff --git a/bin/pwait/tests/pwait_reap.c b/bin/pwait/tests/pwait_reap.c
new file mode 100644
index 000000000000..96c036ba2059
--- /dev/null
+++ b/bin/pwait/tests/pwait_reap.c
@@ -0,0 +1,188 @@
+/*-
+ * Copyright (c) 2026 Dag-Erling Smørgrav
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <sys/wait.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+/*
+ * Wait for a process to terminate, optionally reap it, and verify that it
+ * exited cleanly.
+ */
+static void
+wait_zero(pid_t pid, bool reap)
+{
+	int wstatus;
+	pid_t ret;
+
+	do {
+		ret = waitpid(pid, &wstatus, reap ? 0 : WNOWAIT);
+		ATF_REQUIRE(ret == pid || (ret < 0 && errno == EINTR));
+	} while (ret != pid);
+	ATF_CHECK(WIFEXITED(wstatus));
+	ATF_CHECK_EQ(WEXITSTATUS(wstatus), 0);
+}
+
+/*
+ * Verify that pwait is still waiting for the target process.
+ */
+static void
+pwait_is_waiting(pid_t pwpid, pid_t tpid, int pwout, int pwerr)
+{
+	struct pollfd pfds[2];
+	char line[64] = "", *eol, *rest;
+	ssize_t ret;
+
+	pfds[0].fd = pwout;
+	pfds[0].events = POLLIN;
+	pfds[1].fd = pwerr;
+	pfds[1].events = POLLIN;
+
+	/* loop until we have some output */
+	do {
+		/* send SIGINFO so pwait prints the target PID on stderr */
+		ATF_REQUIRE(kill(pwpid, SIGINFO) == 0);
+	} while ((ret = poll(pfds, 2, 100)) == 0);
+	ATF_REQUIRE_EQ(ret, 1);
+	ATF_REQUIRE_EQ(pfds[1].revents, POLLIN);
+
+	/* read line from stderr */
+	ATF_REQUIRE((ret = read(pwerr, line, sizeof(line) - 1)) > 0);
+
+	/* verify the line */
+	ATF_REQUIRE((eol = strchr(line, '\n')) != NULL);
+	*eol = '\0';
+	ATF_REQUIRE_EQ(strtol(line, &rest, 10), tpid);
+	ATF_REQUIRE_STREQ(rest, "");
+}
+
+/*
+ * Verify that pwait has reported that the target process has terminated,
+ * then reap it.
+ */
+static void
+pwait_is_done(pid_t pwpid, pid_t tpid, int pwout, int pwerr)
+{
+	struct pollfd pfds[2];
+	char line[64] = "", *eol, *rest;
+	ssize_t ret;
+
+	pfds[0].fd = pwout;
+	pfds[0].events = POLLIN;
+	pfds[1].fd = pwerr;
+	pfds[1].events = POLLIN;
+
+	/* loop until we have some output */
+	do {
+		/* nothing */
+	} while ((ret = poll(pfds, 2, 100)) == 0);
+	ATF_REQUIRE_EQ(ret, 1);
+	ATF_REQUIRE_EQ(pfds[0].revents, POLLIN);
+
+	/* read line from stdout */
+	ATF_REQUIRE((ret = read(pwout, line, sizeof(line) - 1)) > 0);
+
+	/* verify the line */
+	ATF_REQUIRE((eol = strchr(line, '\n')) != NULL);
+	*eol = '\0';
+	ATF_REQUIRE_EQ(strtol(line, &rest, 10), tpid);
+	ATF_REQUIRE_STREQ(rest, ": exited with status 0.");
+
+	/* reap pwait */
+	wait_zero(pwpid, true);
+}
+
+static void
+pwait_reap_test(bool reap)
+{
+	char pidstr[16];
+	pid_t tpid, pwpid;
+	int tpipe[2], pwout[2], pwerr[2];
+
+	/* fork target process */
+	ATF_REQUIRE(pipe2(tpipe, O_CLOEXEC) == 0);
+	ATF_REQUIRE((tpid = fork()) >= 0);
+	if (tpid == 0) {
+		(void)close(tpipe[1]);
+		/* block until parent closes its end of the pipe */
+		(void)read(tpipe[0], pidstr, 1);
+		_exit(0);
+	}
+	(void)close(tpipe[0]);
+
+	/* fork pwait */
+	snprintf(pidstr, sizeof(pidstr), "%ld", (long)tpid);
+	ATF_REQUIRE(pipe2(pwout, O_CLOEXEC) == 0);
+	ATF_REQUIRE(pipe2(pwerr, O_CLOEXEC) == 0);
+	ATF_REQUIRE((pwpid = fork()) >= 0);
+	if (pwpid == 0) {
+		(void)dup2(pwout[0], STDOUT_FILENO);
+		(void)dup2(pwerr[0], STDERR_FILENO);
+		execlp("pwait", "pwait", reap ? "-rv" : "-v", pidstr, NULL);
+		_exit(99);
+	}
+
+	/* wait for pwait to become ready */
+	pwait_is_waiting(pwpid, tpid, pwout[1], pwerr[1]);
+
+	/* unblock the target and wait for it to terminate */
+	(void)close(tpipe[1]);
+	wait_zero(tpid, false);
+
+	if (reap) {
+		/* check that pwait is still waiting */
+		pwait_is_waiting(pwpid, tpid, pwout[1], pwerr[1]);
+	} else {
+		/* check that pwait has reported completion */
+		pwait_is_done(pwpid, tpid, pwout[1], pwerr[1]);
+	}
+
+	/* reap the target */
+	wait_zero(tpid, true);
+
+	if (reap) {
+		/* check that pwait has reported completion */
+		pwait_is_done(pwpid, tpid, pwout[1], pwerr[1]);
+	}
+}
+
+ATF_TC(pwait_normal);
+ATF_TC_HEAD(pwait_normal, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test that pwait returns before the "
+	    "target process has been reaped");
+}
+ATF_TC_BODY(pwait_normal, tc)
+{
+	pwait_reap_test(true);
+}
+
+ATF_TC(pwait_reap);
+ATF_TC_HEAD(pwait_reap, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test that pwait -r does not return "
+	    "until the target process has been reaped");
+}
+ATF_TC_BODY(pwait_reap, tc)
+{
+	pwait_reap_test(true);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, pwait_normal);
+	ATF_TP_ADD_TC(tp, pwait_reap);
+	return (atf_no_error());
+}

From nobody Mon Aug  3 11:38:43 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF780zcRz6nCGM
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:44 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF775sK6z3Rxt
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:43 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757123;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ukAqjaBS/b7CVokxUDrsbZ6YV7z3tAoFfxHaRkMfqrg=;
	b=beC+zYhaMFvS/s255JRBoG5l6Iz44fgN0OqNi3gC0Qau42rNWO3E6pbhxyLHafDPMi8ND+
	fUJAJfswRUHK1rMrfEcDeN7uEQRjV/QT+nN4VlDpGx+fL8ME6ib2PiPUdKiCexESaum+cT
	2+d+iryl1eApzGLEMPQuzEOvM7s2Oyw74hVqQ8sQkTrtHG2CFuXaOhDC3PKkM8wXnh68td
	SiE3quO5WymD3TDVpGEdBnwrUybudYYEYANkQyw7sfaSDk2MY5C5WDBCQIKj5wQ+XL2OO7
	TVHN2h0Z9JPWRFpMq5BOVysnSgNieT/HsX6duE74ZQPzV0UJ8DQM6ZZ6qxOUMg==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757123; a=rsa-sha256; cv=none;
	b=Y2EuM0Nmym/63JyyuwUX3QxyPYg8S/NyRuCv8y6rOcG5yEjBeyfs6EdBA0H6+aN/ON5u21
	3ujOr2FweKVReP/kYSJCv32VOsZ31t63Nd3s+77D/QVCS0ebRmngudc7vA2Tpbdfl1Mi+X
	Y4SOKQkAHGdqDef7hR/Oom8/i2hySf6feI+1nkPr25O6mptt7A7O+MZN9rCi1diakaiWJv
	K9CPlVIU8sO+5lF9nYWDo3Sg+LwrPlZ+0tfRfl3J6aJQIWPyd42z4vBzp+GKhHmvZu+Q0q
	Qwgk5LXKO/uhGZ4QH35cQ8TbMY000bYKnyiJDKc1oWIcxems4dqMZ22lnCXr9Q==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757123;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ukAqjaBS/b7CVokxUDrsbZ6YV7z3tAoFfxHaRkMfqrg=;
	b=sA5GC3FFXi4Su8DCxiydyp3tC62CMTjZAs6LMDKt9SILAyOQjjPwUsPPtjTzg/pnSr/eV8
	rH+ahUKSGkkyTcLJJcxa+6YDkxnEUv63NpsIeyAXQMvxjF4HLY2eoVAx3nShGIZOVsN1cV
	W6j9L33BgCTk03KBKRB7C8dg9x0J76ZEll1ET0Ugqtba+21NAOXrOXi+tMAKvPeUeOlCqS
	94oOj/l8/QuHeKvqpnx2MLv3c8EL8h1okYe1yH5aV1s19rkf+YnVT9lCczTAGsSSfwqgHg
	gTHctefIvLA1weqZZJGV0bkdaXhCBSKjyPAUHJErDCY2/K9lP8ZjCxFkox2Kbg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF774qMJzykd
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:43 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 194e0
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:43 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 237ab146975b - stable/15 - rc.subr: Fix premature return from wait_for_pids
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 237ab146975b42472b86ed73ba64bc7a69881092
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:43 +0000
Message-Id: <6a707dc3.194e0.44e5f20b@gitrepo.freebsd.org>

The branch stable/15 has been updated by des:

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

commit 237ab146975b42472b86ed73ba64bc7a69881092
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:15:47 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:12 +0000

    rc.subr: Fix premature return from wait_for_pids
    
    Use pwait's new -r option to wait until the target processes have not
    only terminated, but also been reaped.
    
    PR:             293183
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D58391
    
    (cherry picked from commit 356d0b79cf6fc693ed1a5564232e240ce15ccb8a)
---
 UPDATING                         | 12 ++++++++++++
 libexec/rc/rc.subr               |  4 ++--
 libexec/rc/tests/rc_subr_test.sh | 20 ++++++--------------
 3 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/UPDATING b/UPDATING
index 137d2aa78e6c..1fc355f24faf 100644
--- a/UPDATING
+++ b/UPDATING
@@ -12,6 +12,18 @@ Items affecting the ports and packages system can be found in
 /usr/ports/UPDATING.  Please read that file before updating system packages
 and/or ports.
 
+20260722:
+	The wait_for_pids() function in rc.subr, used by rc scripts
+	when stopping or restarting a service, has been modified to
+	use pwait(1)'s new -r option, which requires kernel support.
+	When upgrading across this change, you should install a new
+	kernel first, then reboot, then install a new world, run
+	etcupdate, and reboot again.  Otherwise, you may find that
+	rc.subr is unable to stop services because the running kernel
+	does not provide the support that the updated pwait(1) needs.
+	Alternatively, if you deem it safe, you may use fastboot(8) to
+	reboot without shutting down services first.
+
 20260512:
 	"bsdinstall script" will now do a pkgbase installation by default.  To
 	revert to the legacy distset installation, set "DISTRIBUTIONS" in
diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr
index 451521c038d8..0c5d616f2c07 100644
--- a/libexec/rc/rc.subr
+++ b/libexec/rc/rc.subr
@@ -793,7 +793,7 @@ sort_lite()
 #
 wait_for_pids()
 {
-	local _list _prefix _j
+	local _list= _prefix= _j=
 
 	for _j in "$@"; do
 		if kill -0 $_j 2>/dev/null; then
@@ -804,7 +804,7 @@ wait_for_pids()
 	while [ -n "$_list" ]; do
 		echo -n ${_prefix:-"Waiting for PIDS: "}$_list
 		_prefix=", "
-		_list=$(pwait -op $_list 2>/dev/null)
+		_list=$(pwait -opr $_list 2>/dev/null)
 	done
 	if [ -n "$_prefix" ]; then
 		echo "."
diff --git a/libexec/rc/tests/rc_subr_test.sh b/libexec/rc/tests/rc_subr_test.sh
index 9ddd13b61a7c..4754ad83c290 100644
--- a/libexec/rc/tests/rc_subr_test.sh
+++ b/libexec/rc/tests/rc_subr_test.sh
@@ -123,20 +123,12 @@ wait_for_pids_progress_head()
 }
 wait_for_pids_progress_body()
 {
-	cat >>script <<'EOF'
-. /etc/rc.subr
-sleep 15 &
-a=$!
-sleep 10 &
-b=$!
-sleep 5 &
-c=$!
-wait_for_pids $a $b $c
-EOF
-	re="^Waiting for PIDS: [0-9]+ [0-9]+ [0-9]+"
-	re="${re}, [0-9]+ [0-9]+"
-	re="${re}, [0-9]+\.$"
-	atf_check -s exit:0 -o match:"${re}" /bin/sh script
+	a=$(sleep 4 >/dev/null & echo $!)
+	b=$(sleep 3 >/dev/null & echo $!)
+	c=$(sleep 2 >/dev/null & echo $!)
+	atf_check \
+	    -o inline:"Waiting for PIDS: $a $b $c, $a $b, $a.\n" \
+	    /bin/sh -c ". /etc/rc.subr; wait_for_pids $a $b $c"
 }
 
 atf_init_test_cases()

From nobody Mon Aug  3 11:38:44 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF792LZHz6nCGS
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:45 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF786g3qz3RhQ
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:44 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757124;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=qNBspkGlRihUiZ7MzYyyq2n9hRb0undLFuKRfbMeeD4=;
	b=lxy6y09udjbLDvjuEXvouHSPTNrOtxKIVDXs7y3qjEeyzUbladJ5Ji733rNNt9SUQgvEPl
	YMyRrSu8Rwc6JnBbbXQSL1TB4aFppWM43rnb4Enjl581seUeBiisKFRbTWn71z2QD9YocK
	P4JY1pH0OUtw9wtPjqYGtN+ekA/MM6gSp5LlmA87MbHNw25Q8BU7F65fSaeJc4ZDn+ScNp
	nOtQLYKWepxVmHViLtHYOnsvPzZeid0GK4BmhQdddqa5H5y7kFKA1QG6sVrmmgqvTUZpEv
	H8U9L8vZsnTRTj2pSH9oam0Xtl4RzXYQfUJBU8S61pqrx1EZKyHLIuIhgob1lA==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757124; a=rsa-sha256; cv=none;
	b=kRU4NoVzw/tI1mkhidRwbAmtNI1J9XR7oBnhuzn/v0PztfaW5lECuto0Q7gDKRMgTBg6xc
	/dqie1DsARFpP/uXxLuvDgGdpb5lgtusQKUQ4axvQMzmIG5M+QfLFAmqpTIXNtd4bYF3U3
	qNU9W/C5ECJTlfWDKUwajMTKvUhjp4P8jl6qLkTCOGlHH5er0stESu6hoft1W7uXzR0Wcb
	3rgAySYzASbHZv+crZmL4WU7loxpOfZjoyoIPLsVXdi3sn1YNdCeY140avMsLKpSXXzrqS
	xuQKjBWimbaJUIP6eJekn6htTk5R8mC2AQDBpb9yNI5UFaCRQZ0RPMXQvtAILA==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757124;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=qNBspkGlRihUiZ7MzYyyq2n9hRb0undLFuKRfbMeeD4=;
	b=oEjjkm4bWz5aHoqaTfhGazGC1jxF8qoCorf6pLV4PGqYZe7cNJxi+VbNR+/7u5O5pe5D6y
	VdWHBN8aPFf6hyFZSOK1idv1T6ikiiLfTKv+rxZQuqyOfNNPh/RxsJ6gWBH2nH+W9g7f21
	BqdWevGeqVylqFfOeZlrk4h1CEMzto7/lq0RV74/Gtz5jfgJ/GnnpCMnAarSQPGYUeFHXF
	tCZZbop14Q67MRtAlHpUWuKaZxLOVxk7GjhDn2kws45vyXT88a4ZufYSqUsypS0FldA2t1
	JzPYAlX+iFqBEYHOhxfeXnMOccbm/WayNc9FPA+HPMFcl6ronsWO3nb0J5H0dQ==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF785ZCVzyRm
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:44 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 18e67
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:44 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 48f73970d1ed - stable/15 - Bump dates
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 48f73970d1edd9fcf0a7e6f702adda107ac55a39
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:44 +0000
Message-Id: <6a707dc4.18e67.bad8794@gitrepo.freebsd.org>

The branch stable/15 has been updated by des:

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

commit 48f73970d1edd9fcf0a7e6f702adda107ac55a39
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:26:41 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:12 +0000

    Bump dates
    
    Fixes:          c8f5e6819d4d ("pwait: Optionally wait until process is reaped")
    Fixes:          eddd8aa99ca8 ("pwait: Add a SIGINFO handler")
    Fixes:          356d0b79cf6f ("rc.subr: Fix premature return from wait_for_pids")
    (cherry picked from commit 9d852922f6687ce9a699efe5e09e3634923b2b60)
---
 UPDATING            | 2 +-
 bin/pwait/pwait.1   | 2 +-
 lib/libsys/kqueue.2 | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/UPDATING b/UPDATING
index 1fc355f24faf..b9dde6ac09f7 100644
--- a/UPDATING
+++ b/UPDATING
@@ -12,7 +12,7 @@ Items affecting the ports and packages system can be found in
 /usr/ports/UPDATING.  Please read that file before updating system packages
 and/or ports.
 
-20260722:
+20260727:
 	The wait_for_pids() function in rc.subr, used by rc scripts
 	when stopping or restarting a service, has been modified to
 	use pwait(1)'s new -r option, which requires kernel support.
diff --git a/bin/pwait/pwait.1 b/bin/pwait/pwait.1
index 4bd43257a82b..dd3e59e25cf0 100644
--- a/bin/pwait/pwait.1
+++ b/bin/pwait/pwait.1
@@ -30,7 +30,7 @@
 .\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 .\" OF SUCH DAMAGE.
 .\"
-.Dd July 22, 2026
+.Dd July 27, 2026
 .Dt PWAIT 1
 .Os
 .Sh NAME
diff --git a/lib/libsys/kqueue.2 b/lib/libsys/kqueue.2
index b596a705e08f..9bba53b31f72 100644
--- a/lib/libsys/kqueue.2
+++ b/lib/libsys/kqueue.2
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd July 22, 2026
+.Dd July 27, 2026
 .Dt KQUEUE 2
 .Os
 .Sh NAME

From nobody Mon Aug  3 11:38:44 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF79162Pz6nByk
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:45 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF784wBxz3RhM
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:44 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757124;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=IPRv0D6ay/2jcbVn1V+miWg11mKPMZMG0F9zTHEqcyo=;
	b=ayXryRobjbsujFPJdo1p/9lZtcvCSl7HPK/qKTSzH13MX6lCcj8NlXllWD/mTYHna1tE1J
	H3XrKm1UavdRfDNSebMmWhoSm4ps+o6YJT2m4iKAzCLNVZZjE6Me0M66Ti8DNkO3tW51KK
	3Umyecuyfi2LrqH3poPGEsFb9xUYI0LRWU27vsEH7JyOnHbyYEx4M9R5bKnM0Cf2kHHsn6
	hmuyMMLV/3Xeqb4BApPk0FzypO9F6b7Y+c2YQOMdM6bD23Zio+nLu0ibEqTkR0RNoECYvk
	/BGf7b66ppbs7ymZPYveFKjpx1S7r1zm4nepRVmqAfwyMTEJWRc6bA7GnJ0kdQ==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757124; a=rsa-sha256; cv=none;
	b=LtsltSrCZn0qY/ZgpsW61oAUmf9RR53gHzNAhyCrHaSzpz3cVyErTiPensZSntMQ8STEiN
	HxgspyfhA+SBfNbIutThIey59EvpSwNQeuip4rl8GnUjAlOmEIm02t+YztR5YZp+WmzdkW
	4nuGfpyDyNADZaybWzyPxqUQPI1dK86tYEap7ilguU1cZF3uJsuwBa/hhxexmqq0Jn9BBb
	Hc/vw28U00POyjDtroOSA/z06WGZnC+t81Ek2/RjMFBPJMsGHhcg3NKH/HKToikawuihT3
	eQi2C1Fq7gN5fLdwe27sYttvACpi3feKEuEDMNQ5JGwu/zrHZA7DSb/R2G4L+w==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757124;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=IPRv0D6ay/2jcbVn1V+miWg11mKPMZMG0F9zTHEqcyo=;
	b=aPrwLWY6t5i/+8rCifqhvfSvGImb4tlVe2gWrki8BsLrSeuLKgeYPKzKoJTuI1XILLcr1E
	yMhJgSnJU6jpIMhVsqu45ZNlNigFq/Gx7l6/j48Iq3W+9r3UmKTb923X+XAa+woF2Q0ZEy
	RIeEBgCrNfuNBuqA36oP7q5Jl/+dHeHmWGvC383ABd5mOKqUsGPmf8ZAPgPcDypDAbPzC3
	y+nYGJ8iTJXeoU4Dy4GE6p5VjDcmtbk4bzRp67y0gDcEtKfhxV0XSot0usu65mAbHuhCdR
	2RB1N0n51jdyk9I5TYa9Rd/MeTWZYB3NWQdc7atGYU9Zk7HuD7ppZra7CGG9sA==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF783gmwzykf
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:44 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1c122
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:44 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: b58c9e8cf6ac - stable/14 - kqueue: Add NOTE_REAP
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: b58c9e8cf6acef2774ebb87dd79eecfa31618d6a
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:44 +0000
Message-Id: <6a707dc4.1c122.4e1cdebd@gitrepo.freebsd.org>

The branch stable/14 has been updated by des:

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

commit b58c9e8cf6acef2774ebb87dd79eecfa31618d6a
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:15:26 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:13 +0000

    kqueue: Add NOTE_REAP
    
    Add a NOTE_REAP event for EVFILTER_PROC which provides a notification
    when the process is reaped.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    kib, markj
    Differential Revision:  https://reviews.freebsd.org/D58313
    
    (cherry picked from commit 2bacbbecb165dd761ea7ec2fc35630db61508cdf)
---
 lib/libc/sys/kqueue.2    | 10 ++++++++--
 lib/libsysdecode/flags.c |  4 ++--
 sys/kern/kern_event.c    | 13 ++++++++-----
 sys/kern/kern_exit.c     |  1 +
 sys/kern/sys_procdesc.c  |  9 ++++++---
 sys/sys/event.h          | 11 ++++-------
 6 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2
index d6e949baa24c..e4e4c85d8a77 100644
--- a/lib/libc/sys/kqueue.2
+++ b/lib/libc/sys/kqueue.2
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd March 26, 2023
+.Dd July 22, 2026
 .Dt KQUEUE 2
 .Os
 .Sh NAME
@@ -516,9 +516,15 @@ The exit status will be stored in
 .Va data
 in the same format as the status returned by
 .Xr wait 2 .
+.It Dv NOTE_REAP
+The process has been reaped by a call to the
+.Xr wait 2
+family of functions.
 .It Dv NOTE_FORK
 The process has called
-.Fn fork .
+.Xr fork 2
+or
+.Xr vfork 2 .
 .It Dv NOTE_EXEC
 The process has executed a new process via
 .Xr execve 2
diff --git a/lib/libsysdecode/flags.c b/lib/libsysdecode/flags.c
index 32829d35dbe0..018dfef5f5c2 100644
--- a/lib/libsysdecode/flags.c
+++ b/lib/libsysdecode/flags.c
@@ -367,8 +367,8 @@ static struct name_table kevent_vnode_fflags[] = {
 };
 
 static struct name_table kevent_proc_fflags[] = {
-	X(NOTE_EXIT) X(NOTE_FORK) X(NOTE_EXEC) X(NOTE_TRACK) X(NOTE_TRACKERR)
-	X(NOTE_CHILD) XEND
+	X(NOTE_EXIT) X(NOTE_FORK) X(NOTE_EXEC) X(NOTE_REAP)
+	X(NOTE_TRACK) X(NOTE_TRACKERR) X(NOTE_CHILD) XEND
 };
 
 static struct name_table kevent_timer_fflags[] = {
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index e2f44aea27b4..a735dfaa97df 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -421,7 +421,7 @@ filt_procattach(struct knote *kn)
 	bool exiting, immediate;
 
 	exiting = immediate = false;
-	if (kn->kn_sfflags & NOTE_EXIT)
+	if (kn->kn_sfflags & (NOTE_EXIT | NOTE_REAP))
 		p = pfind_any(kn->kn_id);
 	else
 		p = pfind(kn->kn_id);
@@ -446,7 +446,7 @@ filt_procattach(struct knote *kn)
 		kn->kn_flags &= ~EV_FLAG2;
 		kn->kn_data = kn->kn_sdata;		/* ppid */
 		kn->kn_fflags = NOTE_CHILD;
-		kn->kn_sfflags &= ~(NOTE_EXIT | NOTE_EXEC | NOTE_FORK);
+		kn->kn_sfflags &= ~NOTE_PCTRLMASK;
 		immediate = true; /* Force immediate activation of child note. */
 	}
 	/*
@@ -508,12 +508,15 @@ filt_proc(struct knote *kn, long hint)
 	if ((kn->kn_sfflags & event) != 0)
 		kn->kn_fflags |= kn->kn_sfflags & event;
 
+	/* Report exit status */
+	if ((kn->kn_fflags & NOTE_EXIT) != 0)
+		kn->kn_data = KW_EXITCODE(p->p_xexit, p->p_xsig);
+
 	/* Process is gone, so flag the event as finished. */
-	if ((event & NOTE_EXIT) != 0) {
+	if ((event & NOTE_REAP) != 0 ||
+	    ((event & NOTE_EXIT) != 0 && (kn->kn_sfflags & NOTE_REAP) == 0)) {
 		kn->kn_flags |= EV_EOF | EV_ONESHOT;
 		kn->kn_ptr.p_proc = NULL;
-		if (kn->kn_fflags & NOTE_EXIT)
-			kn->kn_data = KW_EXITCODE(p->p_xexit, p->p_xsig);
 		if (kn->kn_fflags == 0)
 			kn->kn_flags |= EV_DROP;
 		return (1);
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index baa5cad2bdc8..3cfb55fe3711 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -987,6 +987,7 @@ proc_reap(struct thread *td, struct proc *p, int *status, int options)
 	proc_id_clear(PROC_ID_PID, p->p_pid);
 
 	PROC_LOCK(p);
+	KNOTE_LOCKED(p->p_klist, NOTE_REAP);
 	knlist_detach(p->p_klist);
 	p->p_klist = NULL;
 	PROC_UNLOCK(p);
diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c
index f1aeb4066fa4..c6781aac2523 100644
--- a/sys/kern/sys_procdesc.c
+++ b/sys/kern/sys_procdesc.c
@@ -468,11 +468,14 @@ procdesc_kqops_event(struct knote *kn, long hint)
 	if ((kn->kn_sfflags & event) != 0)
 		kn->kn_fflags |= kn->kn_sfflags & event;
 
+	/* Report exit status */
+	if ((kn->kn_fflags & NOTE_EXIT) != 0)
+		kn->kn_data = pd->pd_xstat;
+
 	/* Process is gone, so flag the event as finished. */
-	if (event == NOTE_EXIT) {
+	if ((event & NOTE_REAP) != 0 ||
+	    ((event & NOTE_EXIT) != 0 && (kn->kn_sfflags & NOTE_REAP) == 0)) {
 		kn->kn_flags |= EV_EOF | EV_ONESHOT;
-		if (kn->kn_fflags & NOTE_EXIT)
-			kn->kn_data = pd->pd_xstat;
 		if (kn->kn_fflags == 0)
 			kn->kn_flags |= EV_DROP;
 		return (1);
diff --git a/sys/sys/event.h b/sys/sys/event.h
index a1cd224a960e..246ebdedd004 100644
--- a/sys/sys/event.h
+++ b/sys/sys/event.h
@@ -203,7 +203,10 @@ struct freebsd11_kevent32 {
 #define	NOTE_EXIT	0x80000000		/* process exited */
 #define	NOTE_FORK	0x40000000		/* process forked */
 #define	NOTE_EXEC	0x20000000		/* process exec'd */
-#define	NOTE_PCTRLMASK	0xf0000000		/* mask for hint bits */
+#define	NOTE_SIGNAL	0x08000000		/* process received a signal,
+						   shared with EVFIL_SIGNAL */
+#define	NOTE_REAP	0x04000000		/* process reaped */
+#define	NOTE_PCTRLMASK	0xec000000		/* mask for hint bits */
 #define	NOTE_PDATAMASK	0x000fffff		/* mask for pid */
 
 /* additional flags for EVFILT_PROC */
@@ -248,12 +251,6 @@ struct knlist {
 
 #define	KNLIST_EMPTY(list)		SLIST_EMPTY(&(list)->kl_list)
 
-/*
- * Flag indicating hint is a signal.  Used by EVFILT_SIGNAL, and also
- * shared by EVFILT_PROC  (all knotes attached to p->p_klist)
- */
-#define NOTE_SIGNAL	0x08000000
-
 /*
  * Hint values for the optional f_touch event filter.  If f_touch is not set 
  * to NULL and f_isfd is zero the f_touch filter will be called with the type

From nobody Mon Aug  3 11:38:45 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7B5h7wz6nCKW
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:46 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF795ZPHz3Rkj
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:45 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757125;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=IpoMp02C00IdIT6aw3Nf/xvkABEt/VRqHb7QeQ2W6Yg=;
	b=YK+gXTFYX+Ak3jTj45z7dazpn0bV7NSEWOBZZOB6vEshfiICuUVbXhPKEmiPqnWbCpT/Im
	nHSBApMcBJ7urrW9w92VQs5npjbe9DM8fcsg5UMZ/O+3zDLsgJl5UzfxN5PIkoWX0TqIO0
	XOK2/AUxb3p3wh4SyFHT0SDvjfWr/4y+QDySAUY0Sr9qP0WqkLgSznmYd3Gpkke7Nx8xpI
	RDUwfJ3vloW9l2sEvLMkF8OvzGtNRfJ8fU+/St5TSUPT+8lIOsERCQXp8sWwDQlPBRaV84
	fi7Jc6FG7e045WYwnW3Z61B3s/44t1KCN/RP7MwokJT9xKcyXNtRwtvRLv3Ttw==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757125; a=rsa-sha256; cv=none;
	b=AzZR0zDpq07yTdsBdM9cSm5FJ1BgAuAXPcO0SjiFnBj4Ano+l23IMRPzvkeho/SZ1lSwpJ
	OVWrLDl3Xyl4vgHU/M46gtBMQfX5IBO9u0e02OwBtOjwiqEswCpfyfZqdpF77Cf9TI/27I
	riTfpWIhz0EkIv+lC2GsDBDohJfOOygfdhe/Ze0LyN0dkGvpOSAMsmbV/Paq/YKfKfmz5S
	uwiA2gluHCwEJzT1glo8L+DPUiw/4dujiay/3BxGdd+juN08wZS+UeZLObqWiPk4aiSYfz
	mLHg5Hb9g5/0yGjtvO5cowvK3aYRdXEPm1V5wS0D6KLQW9kidGzBVcNY+HoNPA==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757125;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=IpoMp02C00IdIT6aw3Nf/xvkABEt/VRqHb7QeQ2W6Yg=;
	b=T6xRUcWolK9Sbn2kzdhtBwqqTQubNrwXSeGN9e2qpVJn2pr5Bb6eo0gQr54dBAGPjZSNtF
	RwxeLzc9/GVl0xS6+EawxPmzzvwW6AOX0sp8eSv1DDg9Ar6fCjV1V8QajZwkvdTZyzNUgG
	aT5jAkItGOf4GBJcMvuDyiv0L8CjKmv/i2jlFAdEti1QIlzQ/Y8cKzwm3encfxjMtofqR6
	eVoue3kuzP7ySus0l99QHGZio8PKw9txvQdWTE20gFoSkuEspX6eRCtlY90nZpeNLAgRIF
	hLChGO65cKtjLsfdf/KQRq5WuNNAjoUKy3sY+wt5rGtLaqW2VST5zZUIpPrHqw==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF794XV1zypt
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:45 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1be73
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:45 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: ae3c852dfbd8 - stable/14 - pwait: Optionally wait until process is reaped
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: ae3c852dfbd883af905f38a6a1c5ebae0224135b
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:45 +0000
Message-Id: <6a707dc5.1be73.20bce329@gitrepo.freebsd.org>

The branch stable/14 has been updated by des:

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

commit ae3c852dfbd883af905f38a6a1c5ebae0224135b
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:15:31 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:13 +0000

    pwait: Optionally wait until process is reaped
    
    If the new -r option is specified, wait until the target process not
    only terminates but is reaped.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    kib, markj
    Differential Revision:  https://reviews.freebsd.org/D58314
    
    (cherry picked from commit c8f5e6819d4d81906c4a1641b5c9f02d8730481c)
---
 bin/pwait/pwait.1 | 17 ++++++++++++++---
 bin/pwait/pwait.c | 41 +++++++++++++++++++++++++++++------------
 2 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/bin/pwait/pwait.1 b/bin/pwait/pwait.1
index c61f6854358b..a80c04a1e688 100644
--- a/bin/pwait/pwait.1
+++ b/bin/pwait/pwait.1
@@ -30,7 +30,7 @@
 .\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 .\" OF SUCH DAMAGE.
 .\"
-.Dd October 22, 2025
+.Dd July 22, 2026
 .Dt PWAIT 1
 .Os
 .Sh NAME
@@ -39,7 +39,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl t Ar duration
-.Op Fl opv
+.Op Fl oprv
 .Ar pid
 \&...
 .Sh DESCRIPTION
@@ -53,6 +53,17 @@ The following option is available:
 Exit when any of the given processes has terminated.
 .It Fl p
 On exit, print a list of processes that have not terminated.
+.It Fl r
+Do not exit until target processes have not only terminated, but been
+reaped by a call to the
+.Xr wait 2
+family of functions.
+Without this flag, target processes may still exist as zombies when
+.Nm
+exits.
+Beware of deadlocks if a target process's reaper (usually its parent)
+is directly or indirectly blocked by
+.Nm .
 .It Fl t Ar duration
 If any process is still running after
 .Ar duration ,
@@ -127,8 +138,8 @@ $ sleep 30 & sleep 40 &
 [2] 1675
 $ pwait -v -t 60 1674 1675
 1674: exited with status 0.
-1675: exited with status 0.
 [1]-  Done                    sleep 30
+1675: exited with status 0.
 [2]+  Done                    sleep 40
 $ echo $?
 0
diff --git a/bin/pwait/pwait.c b/bin/pwait/pwait.c
index 6e9e634b4526..385278dbc991 100644
--- a/bin/pwait/pwait.c
+++ b/bin/pwait/pwait.c
@@ -39,6 +39,7 @@
 #include <sys/tree.h>
 #include <sys/wait.h>
 
+#include <assert.h>
 #include <err.h>
 #include <errno.h>
 #include <signal.h>
@@ -67,7 +68,7 @@ RB_GENERATE_STATIC(pidtree, pid, entry, pidcmp);
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: pwait [-t timeout] [-opv] pid ...\n");
+	fprintf(stderr, "usage: pwait [-oprv] [-t timeout] pid ...\n");
 	exit(EX_USAGE);
 }
 
@@ -85,16 +86,17 @@ main(int argc, char *argv[])
 	size_t sz;
 	long pid;
 	pid_t mypid;
-	int i, kq, n, ndone, nleft, opt, pid_max, ret, status;
-	bool oflag, pflag, tflag, verbose;
+	int i, kq, n, ndone, nleft, notes, opt, pid_max, ret, status;
+	bool oflag, pflag, rflag, tflag, verbose;
 
 	oflag = false;
 	pflag = false;
+	rflag = false;
 	tflag = false;
 	verbose = false;
 	memset(&itv, 0, sizeof(itv));
 
-	while ((opt = getopt(argc, argv, "opt:v")) != -1) {
+	while ((opt = getopt(argc, argv, "oprt:v")) != -1) {
 		switch (opt) {
 		case 'o':
 			oflag = true;
@@ -102,6 +104,9 @@ main(int argc, char *argv[])
 		case 'p':
 			pflag = true;
 			break;
+		case 'r':
+			rflag = true;
+			break;
 		case 't':
 			tflag = true;
 			errno = 0;
@@ -164,6 +169,9 @@ main(int argc, char *argv[])
 	}
 	ndone = nleft = 0;
 	mypid = getpid();
+	notes = rflag ? NOTE_REAP : NOTE_EXIT;
+	if (verbose)
+		notes |= NOTE_EXIT;
 	for (n = 0; n < argc; n++) {
 		s = argv[n];
 		/* Undocumented Solaris compat */
@@ -189,7 +197,7 @@ main(int argc, char *argv[])
 			free(p);
 			continue;
 		}
-		EV_SET(e + nleft, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
+		EV_SET(e + nleft, pid, EVFILT_PROC, EV_ADD, notes, 0, NULL);
 		if (kevent(kq, e + nleft, 1, NULL, 0, NULL) == -1) {
 			if (errno != ESRCH)
 				err(EX_OSERR, "kevent()");
@@ -229,9 +237,11 @@ main(int argc, char *argv[])
 					printf("timeout\n");
 				}
 				ret = 124;
+				continue;
 			}
+			assert(e[i].filter == EVFILT_PROC);
 			pid = e[i].ident;
-			if (verbose) {
+			if ((e[i].fflags & NOTE_EXIT) && verbose) {
 				status = e[i].data;
 				if (WIFEXITED(status)) {
 					printf("%ld: exited with status %d.\n",
@@ -243,13 +253,20 @@ main(int argc, char *argv[])
 					printf("%ld: terminated.\n", pid);
 				}
 			}
-			k.pid = pid;
-			if ((p = RB_FIND(pidtree, &pids, &k)) != NULL) {
-				RB_REMOVE(pidtree, &pids, p);
-				free(p);
-				ndone++;
+			if ((e[i].fflags & NOTE_REAP) && verbose) {
+				printf("%ld: reaped.\n", pid);
+			}
+			if ((e[i].fflags & NOTE_REAP) ||
+			    (!rflag && (e[i].fflags & NOTE_EXIT))) {
+				/* this process is done */
+				k.pid = pid;
+				if ((p = RB_FIND(pidtree, &pids, &k)) != NULL) {
+					RB_REMOVE(pidtree, &pids, p);
+					free(p);
+					ndone++;
+				}
+				--nleft;
 			}
-			--nleft;
 		}
 	}
 	if (pflag) {

From nobody Mon Aug  3 11:38:45 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7C0McXz6nC9M
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:47 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF7B0WLYz3RtH
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:46 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757126;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=NJKdgBPkqnvr8YR5Q6qmOf30yP+yINrqnHlN+57SlFQ=;
	b=fnZbHYNKR+YS5xaf9gmZngTr4YqVc2OCZS+9YZW5bpLqHhuHbNOUvOF2rwQt8QmPf38faO
	M1+otI7fuZ40tkHO5H9N9VQjMfdZPkjCF0Ic3M33L8LvaBTFeESe9fcRNnCHdyHMhE/SVa
	bDQG8eGDcSwHoGtOxPLfDuME6TB2UdgN4w0wtSwsGLWr1hg+uItICMnABiE90CHX9luUI2
	FeFD/cHNFq1nHuEn/LQuNQi5F7rAI5TWROBV/iXqal8hOOe8ZAPKyBCIDk55cDJVO8SxuK
	pYK9gZ6FJd8G5B2WyKZCgidesLjRrexT+x3qSD02cJrw4WYr/TD1K4Or+C92vQ==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757126; a=rsa-sha256; cv=none;
	b=mh77CqL09yFi5eiwVrxoP4U0AG54OWtg92zDMK5+THtjfdW/WmD0gWN+GECqhsrISgFvg+
	rviFDT28cbOdes1bzMp5dehHNsDgbG431IujRqP/4FIADx9PIlsb6QQmlnXA6FJ72ClZDQ
	5TIIhb79v8yNeRNPEcO6UV84q1ml7yeiVY7NO4hc314aZH91Xp0mGOLOCUpkbSK/m3IbS1
	w0oaSnKpNbAv4PjZTP1BUUTVqj5Z2Cc732tQBS7GqYcFm+psPjZWCTEhqw8D/mRSPrKHLk
	C0KoL9VCbbivoIAGa3g2yE9yFI9hzc3W9Ch2RV79VWV9dAxTomiYo4NbzKq36A==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757126;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=NJKdgBPkqnvr8YR5Q6qmOf30yP+yINrqnHlN+57SlFQ=;
	b=fqRmhovQ3mBCuVujVkNvtO6vSU4rUaEAd7Kri/YSDV1b5MbG8gZ+Wi+uyOzUXrVUpK+9SF
	/XJomwDTV+zxP1Yi5PMkkJg0vz/ITijDuu7cPuBONDzE3YfYO1HruQo91rRTT6Q1mwlHGR
	SNV7XYNKwJoijOKRk/kjydov707YP4MIcoapKgYTKWTpp9zxiSj3kTFGSL3mm2q/7icAnl
	uswo607dK3a390D/hR9tfhTnpvyo2KU5KSc+OvsseZYVhrXACak4836iQbNf/E3cvzhLvL
	y8kDZwVHajuEFBTYPWiTW3jV5+xwS5D0b1zUx13ukB6qMlgx5ft6QLLh99mlFQ==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF796MXszypw
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:45 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1c701
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:45 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 6eb614c82fad - stable/15 - pwait: Fix pwait_normal test case
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 6eb614c82fada8e6a19764ebffaffbe228087eb5
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:45 +0000
Message-Id: <6a707dc5.1c701.50a9fc9a@gitrepo.freebsd.org>

The branch stable/15 has been updated by des:

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

commit 6eb614c82fada8e6a19764ebffaffbe228087eb5
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 18:51:50 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:12 +0000

    pwait: Fix pwait_normal test case
    
    Reported by:    markj
    Fixes:          e115066370dc ("pwait: Test the new -r option")
    
    (cherry picked from commit 51c0cdb04919f776516a7fac8529e7279ea5efad)
---
 bin/pwait/tests/pwait_reap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bin/pwait/tests/pwait_reap.c b/bin/pwait/tests/pwait_reap.c
index 96c036ba2059..8402def1a41f 100644
--- a/bin/pwait/tests/pwait_reap.c
+++ b/bin/pwait/tests/pwait_reap.c
@@ -166,7 +166,7 @@ ATF_TC_HEAD(pwait_normal, tc)
 }
 ATF_TC_BODY(pwait_normal, tc)
 {
-	pwait_reap_test(true);
+	pwait_reap_test(false);
 }
 
 ATF_TC(pwait_reap);

From nobody Mon Aug  3 11:38:47 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7D2Q5Rz6nCKl
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:48 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF7D051bz3S64
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:48 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757128;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=9C8WdFZ+14OlvuGiPoDP9PF8lxImweq7rh3Am43RPyU=;
	b=n/9iGM9vBFBwNs/lFVBe0zi7IU0mYTV8JnkFof60OBDr7xMJoi/ZG3+lx3XdWfcGhJ0FQv
	6BW8WhABpHsm0MamTbxGVb+02jSI9GaAha4/hGdm6TQ3+LQeQqcmFNKf2qDXpUjkSggqVY
	0+RctOP00hElCAncG8IW4b3i9WjF9U52RHF6IRY5Td8uOybhDyCo3aRKDNA7LB+S66tTfj
	bPNX4WJ+AQ+GXJ5YDmB5PC71z7s/wY8QkGsXPKIsMX/cSNNOGWPkO556ShXua7g5IzGdJW
	Dpqzves49eC58XvoKrxINTwxHeyagHDLYmEdCK0F8LtVgkfS0QtLFk41n755RQ==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757128; a=rsa-sha256; cv=none;
	b=WTaUzJR4G/BMg5/4W/acG0mvkkML7G3Vod3sVJlrzRVmPIyPsxe5Qx46UZlVm+YNj52Yqm
	/IQuB+9IHZYj6GdfRxKc5RY4nQlUPC7FM8bRwf7WRIGblhZgRPKOu5DRwj1b3pWJ/OdeNb
	lEsDSMS7uyiPH8/BfyFrMkCSbbaheBJ+j7JgGexvUYj4HisgWkSlTqQcI7doL8JbdtxgDM
	0jgE/OnGc+2ITBnXxKbjvmkfOqK0HP6QWRANcpavfnWYFaeJY6NeKh06IRIXtGUBFBN/wC
	JZyjxvXIMh0Uzx2v+u6L1ta572ah2lHE1u9Z76PK2M/MpyuKAOkUvf6Ap9QJ2Q==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757128;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=9C8WdFZ+14OlvuGiPoDP9PF8lxImweq7rh3Am43RPyU=;
	b=eAliKSorlsLVAopzNHBzgltOcnD0JgAu6gyhmgwPN7iHSVKQHuhcUAiLlV+PNDZ41IxTHe
	bve5/FeC4EEkLNvSO0UF5yTIEtlVyubcbXXC59brMmbQc7SdG1YFmNFdyHk0dgNgbJ8lqt
	ATE3Ll1xEHjmxUfhhwdBBVYG5Oqd4UwhYT5smVybrKktD1DnYw4Ya1ALmLAjJ5CXrpyEDe
	ZBLr9qMVBgVtGmOopE8YSU217zabTaIhIlcmXWZuaMLc0XG2HznjjYunYatVC7NdSXO6J8
	gE30cDDUroGfaUJPQS+tDdplwyKC98/rEAyZXtC/KwNiHpzVJ2/3eA/9lc9Uiw==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7C68V9zymj
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:47 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1be7b
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:47 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 4e6679c9c422 - stable/14 - pwait: Test the new -r option
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 4e6679c9c422b0b591a84413181fa4e90beb37a1
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:47 +0000
Message-Id: <6a707dc7.1be7b.2d6b7e1d@gitrepo.freebsd.org>

The branch stable/14 has been updated by des:

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

commit 4e6679c9c422b0b591a84413181fa4e90beb37a1
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:15:41 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:13 +0000

    pwait: Test the new -r option
    
    Test that pwait without -r reports a process as soon as it terminates,
    while pwait with -r does not report it until it has been reaped.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D58385
    
    (cherry picked from commit e115066370dcfec410d914362756d09c268a5b4e)
---
 bin/pwait/tests/Makefile     |   2 +-
 bin/pwait/tests/pwait_reap.c | 188 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 189 insertions(+), 1 deletion(-)

diff --git a/bin/pwait/tests/Makefile b/bin/pwait/tests/Makefile
index 8e916ae47b38..0f9359c92593 100644
--- a/bin/pwait/tests/Makefile
+++ b/bin/pwait/tests/Makefile
@@ -1,4 +1,4 @@
-
+ATF_TESTS_C=	pwait_reap
 ATF_TESTS_SH=	pwait_test
 
 .include <bsd.test.mk>
diff --git a/bin/pwait/tests/pwait_reap.c b/bin/pwait/tests/pwait_reap.c
new file mode 100644
index 000000000000..96c036ba2059
--- /dev/null
+++ b/bin/pwait/tests/pwait_reap.c
@@ -0,0 +1,188 @@
+/*-
+ * Copyright (c) 2026 Dag-Erling Smørgrav
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <sys/wait.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+/*
+ * Wait for a process to terminate, optionally reap it, and verify that it
+ * exited cleanly.
+ */
+static void
+wait_zero(pid_t pid, bool reap)
+{
+	int wstatus;
+	pid_t ret;
+
+	do {
+		ret = waitpid(pid, &wstatus, reap ? 0 : WNOWAIT);
+		ATF_REQUIRE(ret == pid || (ret < 0 && errno == EINTR));
+	} while (ret != pid);
+	ATF_CHECK(WIFEXITED(wstatus));
+	ATF_CHECK_EQ(WEXITSTATUS(wstatus), 0);
+}
+
+/*
+ * Verify that pwait is still waiting for the target process.
+ */
+static void
+pwait_is_waiting(pid_t pwpid, pid_t tpid, int pwout, int pwerr)
+{
+	struct pollfd pfds[2];
+	char line[64] = "", *eol, *rest;
+	ssize_t ret;
+
+	pfds[0].fd = pwout;
+	pfds[0].events = POLLIN;
+	pfds[1].fd = pwerr;
+	pfds[1].events = POLLIN;
+
+	/* loop until we have some output */
+	do {
+		/* send SIGINFO so pwait prints the target PID on stderr */
+		ATF_REQUIRE(kill(pwpid, SIGINFO) == 0);
+	} while ((ret = poll(pfds, 2, 100)) == 0);
+	ATF_REQUIRE_EQ(ret, 1);
+	ATF_REQUIRE_EQ(pfds[1].revents, POLLIN);
+
+	/* read line from stderr */
+	ATF_REQUIRE((ret = read(pwerr, line, sizeof(line) - 1)) > 0);
+
+	/* verify the line */
+	ATF_REQUIRE((eol = strchr(line, '\n')) != NULL);
+	*eol = '\0';
+	ATF_REQUIRE_EQ(strtol(line, &rest, 10), tpid);
+	ATF_REQUIRE_STREQ(rest, "");
+}
+
+/*
+ * Verify that pwait has reported that the target process has terminated,
+ * then reap it.
+ */
+static void
+pwait_is_done(pid_t pwpid, pid_t tpid, int pwout, int pwerr)
+{
+	struct pollfd pfds[2];
+	char line[64] = "", *eol, *rest;
+	ssize_t ret;
+
+	pfds[0].fd = pwout;
+	pfds[0].events = POLLIN;
+	pfds[1].fd = pwerr;
+	pfds[1].events = POLLIN;
+
+	/* loop until we have some output */
+	do {
+		/* nothing */
+	} while ((ret = poll(pfds, 2, 100)) == 0);
+	ATF_REQUIRE_EQ(ret, 1);
+	ATF_REQUIRE_EQ(pfds[0].revents, POLLIN);
+
+	/* read line from stdout */
+	ATF_REQUIRE((ret = read(pwout, line, sizeof(line) - 1)) > 0);
+
+	/* verify the line */
+	ATF_REQUIRE((eol = strchr(line, '\n')) != NULL);
+	*eol = '\0';
+	ATF_REQUIRE_EQ(strtol(line, &rest, 10), tpid);
+	ATF_REQUIRE_STREQ(rest, ": exited with status 0.");
+
+	/* reap pwait */
+	wait_zero(pwpid, true);
+}
+
+static void
+pwait_reap_test(bool reap)
+{
+	char pidstr[16];
+	pid_t tpid, pwpid;
+	int tpipe[2], pwout[2], pwerr[2];
+
+	/* fork target process */
+	ATF_REQUIRE(pipe2(tpipe, O_CLOEXEC) == 0);
+	ATF_REQUIRE((tpid = fork()) >= 0);
+	if (tpid == 0) {
+		(void)close(tpipe[1]);
+		/* block until parent closes its end of the pipe */
+		(void)read(tpipe[0], pidstr, 1);
+		_exit(0);
+	}
+	(void)close(tpipe[0]);
+
+	/* fork pwait */
+	snprintf(pidstr, sizeof(pidstr), "%ld", (long)tpid);
+	ATF_REQUIRE(pipe2(pwout, O_CLOEXEC) == 0);
+	ATF_REQUIRE(pipe2(pwerr, O_CLOEXEC) == 0);
+	ATF_REQUIRE((pwpid = fork()) >= 0);
+	if (pwpid == 0) {
+		(void)dup2(pwout[0], STDOUT_FILENO);
+		(void)dup2(pwerr[0], STDERR_FILENO);
+		execlp("pwait", "pwait", reap ? "-rv" : "-v", pidstr, NULL);
+		_exit(99);
+	}
+
+	/* wait for pwait to become ready */
+	pwait_is_waiting(pwpid, tpid, pwout[1], pwerr[1]);
+
+	/* unblock the target and wait for it to terminate */
+	(void)close(tpipe[1]);
+	wait_zero(tpid, false);
+
+	if (reap) {
+		/* check that pwait is still waiting */
+		pwait_is_waiting(pwpid, tpid, pwout[1], pwerr[1]);
+	} else {
+		/* check that pwait has reported completion */
+		pwait_is_done(pwpid, tpid, pwout[1], pwerr[1]);
+	}
+
+	/* reap the target */
+	wait_zero(tpid, true);
+
+	if (reap) {
+		/* check that pwait has reported completion */
+		pwait_is_done(pwpid, tpid, pwout[1], pwerr[1]);
+	}
+}
+
+ATF_TC(pwait_normal);
+ATF_TC_HEAD(pwait_normal, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test that pwait returns before the "
+	    "target process has been reaped");
+}
+ATF_TC_BODY(pwait_normal, tc)
+{
+	pwait_reap_test(true);
+}
+
+ATF_TC(pwait_reap);
+ATF_TC_HEAD(pwait_reap, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test that pwait -r does not return "
+	    "until the target process has been reaped");
+}
+ATF_TC_BODY(pwait_reap, tc)
+{
+	pwait_reap_test(true);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, pwait_normal);
+	ATF_TP_ADD_TC(tp, pwait_reap);
+	return (atf_no_error());
+}

From nobody Mon Aug  3 11:38:46 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7C3LhBz6nCCm
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:47 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF7B6fN9z3S5m
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:46 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757126;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=lTtQz2wQUtK7w7Q8iyhXG/FXqTSPhtu/UO9vyHrnlgw=;
	b=b6g7lhGkICzff+eFgrZcpgPuynxPbD4UTVZeRxG2Ni8So5vddUm/g2QraxAscuBLYJ4m8t
	4chH721tc/TATKT0TTCs5wf4nf9s99mP//Tfm7PBcb+MVA9CcyJZaG1yX6TPwTqoqTpwi4
	+lPZEIHHZChLkIjEjB4lrqgPYDo4C66bQ5rSNGjOUszLVo4HyG4Qpot/SGwlWbBzWPrO7m
	gLmWki2/DbOLrdwRrJOcvlKdLUW0+Fmhngul/EDXty11UjQ5Xm9FClfpH1EbVVeim6lnKy
	RSDGzLv1mByWolkC/VwWLr2yDvNHoyO6ktAxXZ3Jo17rdvMSSCeoMOM+Whygvw==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757126; a=rsa-sha256; cv=none;
	b=WbYwppTzDBVNDOn8wHEY5q5Dat5QzeF9vghGyp7fy1boGe9HaDF28nIbASsnyfcRbHalRp
	l7VnDlKPQfycIfrj/XNuFCvr/u1SxQbR3GSuNtVGXcVFTZHRPfRH56HxDy3wWbkz73Vj9Y
	PFbzW6OjBM5reVHnXZJm+g5T4E7m8HH/u6Kf2n/U4b80JjOB+7Mk6nHXJ/XBrgcxZL43Kq
	xbNbsLqN11khQ037Yp59ToXrd394h18sDYfb5QWvU6hMjetaTctbiUOnEYNu0EHsru6nzy
	1Vq31AR3JuamWAuoo+Ge/6txjVxE6RU35qLqhChv7ToFPEvPzVeMmKGV/eGu4g==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757126;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=lTtQz2wQUtK7w7Q8iyhXG/FXqTSPhtu/UO9vyHrnlgw=;
	b=LNlTR1C55X4b7pMnzPpCKWnl9SlLBKA5SW3RUwKkxAyQM12ChtDef2wuaTkrUx8dsUV20T
	2xjnDxHruZFUZQ19/eGaoJzpVuRHyzLxhPiulwE2g1KxmajRMbOh8VGjK8d2jCvjftTdBR
	ANDa6ZcHdHAmDzLgj9tvzuLdtInykgvPNxAt8bou/5HNaMw8ykfTIka2BIGsFQJMGtLa/D
	c8qNhy9VWS5z3YeFpV4PMzIEveJZ3OpgcLPGl3zZ7gYWO1BcBm6PV7BfBwBvsBlnEhG1nn
	s29AHqMQZJL1tZ7ET53SXM/aU69GR/w2eg8meLhYLwkYKTzr+RDU2IASwg/mjg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7B5KgjzyfQ
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:46 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 19628
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:46 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 19723c77825e - stable/14 - pwait: Add a SIGINFO handler
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 19723c77825e90dd2669ca371250966e5303e83d
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:46 +0000
Message-Id: <6a707dc6.19628.2de1b305@gitrepo.freebsd.org>

The branch stable/14 has been updated by des:

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

commit 19723c77825e90dd2669ca371250966e5303e83d
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:15:36 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:13 +0000

    pwait: Add a SIGINFO handler
    
    On SIGINFO, print a space-separated list or remaining processes to
    standard error.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    kib, markj
    Differential Revision:  https://reviews.freebsd.org/D58386
    
    (cherry picked from commit eddd8aa99ca84c85faea5761af800b5b089d6ba1)
---
 bin/pwait/pwait.1 | 13 +++++++++++++
 bin/pwait/pwait.c | 36 +++++++++++++++++++++++++++++-------
 2 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/bin/pwait/pwait.1 b/bin/pwait/pwait.1
index a80c04a1e688..738f11aa5468 100644
--- a/bin/pwait/pwait.1
+++ b/bin/pwait/pwait.1
@@ -88,6 +88,18 @@ Print the exit status when each process terminates or
 .Ql timeout
 if the timer goes off earlier.
 .El
+.Pp
+If
+.Nm
+receives
+.Dv SIGINFO
+(see the
+.Sy status
+argument for
+.Xr stty 1 )
+signal,
+a space-separated list of processes still being waited on is printed
+to the standard error output.
 .Sh EXIT STATUS
 The
 .Nm
@@ -148,6 +160,7 @@ $ echo $?
 .Xr kill 1 ,
 .Xr pkill 1 ,
 .Xr ps 1 ,
+.Xr stty 1 ,
 .Xr wait 1 ,
 .Xr kqueue 2
 .Sh NOTES
diff --git a/bin/pwait/pwait.c b/bin/pwait/pwait.c
index 385278dbc991..7a08425700e6 100644
--- a/bin/pwait/pwait.c
+++ b/bin/pwait/pwait.c
@@ -86,7 +86,7 @@ main(int argc, char *argv[])
 	size_t sz;
 	long pid;
 	pid_t mypid;
-	int i, kq, n, ndone, nleft, notes, opt, pid_max, ret, status;
+	int i, kq, n, ndone, nev, nleft, notes, opt, pid_max, ret, status;
 	bool oflag, pflag, rflag, tflag, verbose;
 
 	oflag = false;
@@ -164,10 +164,10 @@ main(int argc, char *argv[])
 	if (sysctlbyname("kern.pid_max", &pid_max, &sz, NULL, 0) != 0) {
 		pid_max = 99999;
 	}
-	if ((e = malloc((argc + tflag) * sizeof(*e))) == NULL) {
+	if ((e = malloc((argc + 1 + tflag) * sizeof(*e))) == NULL) {
 		err(EX_OSERR, "malloc");
 	}
-	ndone = nleft = 0;
+	ndone = nev = nleft = 0;
 	mypid = getpid();
 	notes = rflag ? NOTE_REAP : NOTE_EXIT;
 	if (verbose)
@@ -207,18 +207,28 @@ main(int argc, char *argv[])
 			ndone++;
 		} else {
 			nleft++;
+			nev++;
 		}
 	}
 
+	/*
+	 * Detect SIGINFO so we can print a status.
+	 */
+	EV_SET(e + nev, SIGINFO, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
+	if (kevent(kq, e + nev, 1, NULL, 0, NULL) == -1) {
+		err(EX_OSERR, "kevent");
+	}
+	nev++;
 	if ((ndone == 0 || !oflag) && nleft > 0 && tflag) {
 		/*
 		 * Explicitly detect SIGALRM so that an exit status of 124
 		 * can be returned rather than 142.
 		 */
-		EV_SET(e + nleft, SIGALRM, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
-		if (kevent(kq, e + nleft, 1, NULL, 0, NULL) == -1) {
+		EV_SET(e + nev, SIGALRM, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
+		if (kevent(kq, e + nev, 1, NULL, 0, NULL) == -1) {
 			err(EX_OSERR, "kevent");
 		}
+		nev++;
 		/* Ignore SIGALRM to not interrupt kevent(2). */
 		signal(SIGALRM, SIG_IGN);
 		if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
@@ -226,13 +236,25 @@ main(int argc, char *argv[])
 		}
 	}
 	ret = EX_OK;
+	setvbuf(stderr, NULL, _IOLBF, 0);
 	while ((ndone == 0 || !oflag) && ret == EX_OK && nleft > 0) {
-		n = kevent(kq, NULL, 0, e, nleft + tflag, NULL);
+		n = kevent(kq, NULL, 0, e, nev, NULL);
 		if (n == -1) {
 			err(EX_OSERR, "kevent");
 		}
 		for (i = 0; i < n; i++) {
-			if (e[i].filter == EVFILT_SIGNAL) {
+			if (e[i].filter == EVFILT_SIGNAL &&
+			    e[i].ident == SIGINFO) {
+				p = RB_MIN(pidtree, &pids);
+				fprintf(stderr, "%d", p->pid);
+				while ((p = RB_NEXT(pidtree, &pids, p)) != NULL) {
+					fprintf(stderr, " %d", p->pid);
+				}
+				fprintf(stderr, "\n");
+				continue;
+			}
+			if (e[i].filter == EVFILT_SIGNAL &&
+			    e[i].ident == SIGALRM) {
 				if (verbose) {
 					printf("timeout\n");
 				}

From nobody Mon Aug  3 11:38:48 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7G2KGNz6nCD9
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:50 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF7F2kHYz3SBs
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:49 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757129;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=wjeOBEr9RoP1Oqxuc6XAupnKvdBBke2lFgxlTZQEKBs=;
	b=bPtnsig7JyE83mDW4WwXuiMPejfP7ZZiCDYjNFkHrC9uUYg+NSQUSWCvYD41BfQ/0GxfiT
	4HoXBZeU3g/LNUE7wZxdayrB5N5o7s3Vpq8aJoUK4wDnfb/V1HzKc6nLvfEPtbBWZmiISX
	y391L8Jjj3YFXpalN2dsY8eBwQQY6WE8sdqFiGDOfP+swL+8bhWJk3mEzWpKt36t6rbKFk
	Hp65M1jE749KKWUTsDmu02xX/pEuoKVv6E02kFuNz++Ykd27aX8oory64eDS5slfi+SDW+
	2yrlwVxMzV5h9SSBD1JnhYNgvfXshXGlFkb1OMLJx5WqvB8iVwgzyIXPnUQd4A==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757129; a=rsa-sha256; cv=none;
	b=k7TsUUi8eZr6LEb5fDRYIOE+ASioD7qAzmlq3FAwND7AQJv8+rrCwAxOlgmdjw0d6eGDiX
	EZmYCfC96EbWDYX9NKl+RBETdzM/H2mVCg+P8721pU51Q4O+Hlpbs8z87qrrRoeZBNZa24
	P9+K2UDXTBpBDDCXe9W3LWpzM8QWIqIU/dqIExqN5Gn8NBE9ZYPOI8PnNqqgnZ74+xyD4S
	EH+RC1h/rHJnM8GSfLijYhv070C4XMSTT6d14oM8TAyG60FJTUra24pTMkZ4DD1XSQmahC
	TKTDylhzV+9kcOZL8hGVlINp2fkE8yXwsdxZk5asEYCEbgZq7hlaEayNsp80TA==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757129;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=wjeOBEr9RoP1Oqxuc6XAupnKvdBBke2lFgxlTZQEKBs=;
	b=bIMkGBhjwOTJx6LcMy28y1gPPP1sjoF6Neiftb240+8Z/jpSGKFCTNdPwep95+0G2Gs0fq
	Y/t2t1KY5pp3T2gvy7TM7pgxEOiDZwCqH7KdvTtNmZX65R1N/bpbi6D4Al3bnahCrQLnab
	SvuFMrn74gCnerXF2jH+osijml94MXxBQ+9ajqpq7E3JiKhHY6qSIT3h38uXzZEJkIK9DI
	7tfNxtTZusRJLx4o9P50ouQJ8pO0AEiy3eErSugIuv1neNegpHgCC4n0Tx94XKd+FBmgfb
	440O+NqyaTVgKiUn8sNiIeeUG/R4wbRwxaogH+1z4UgMXqBve/SkBdmyrPB30g==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7D731Pzyq0
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:48 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1bdc7
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:48 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 934fde21fa2b - stable/14 - rc.subr: Fix premature return from wait_for_pids
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 934fde21fa2b84298cde99649d28454caceebf93
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:48 +0000
Message-Id: <6a707dc8.1bdc7.424d02cc@gitrepo.freebsd.org>

The branch stable/14 has been updated by des:

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

commit 934fde21fa2b84298cde99649d28454caceebf93
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:15:47 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:14 +0000

    rc.subr: Fix premature return from wait_for_pids
    
    Use pwait's new -r option to wait until the target processes have not
    only terminated, but also been reaped.
    
    PR:             293183
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D58391
    
    (cherry picked from commit 356d0b79cf6fc693ed1a5564232e240ce15ccb8a)
---
 UPDATING                         | 12 ++++++++++++
 libexec/rc/rc.subr               |  4 ++--
 libexec/rc/tests/rc_subr_test.sh | 20 ++++++--------------
 3 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/UPDATING b/UPDATING
index 4c3ea27970cb..eb1d65b8f455 100644
--- a/UPDATING
+++ b/UPDATING
@@ -12,6 +12,18 @@ Items affecting the ports and packages system can be found in
 /usr/ports/UPDATING.  Please read that file before updating system packages
 and/or ports.
 
+20260722:
+	The wait_for_pids() function in rc.subr, used by rc scripts
+	when stopping or restarting a service, has been modified to
+	use pwait(1)'s new -r option, which requires kernel support.
+	When upgrading across this change, you should install a new
+	kernel first, then reboot, then install a new world, run
+	etcupdate, and reboot again.  Otherwise, you may find that
+	rc.subr is unable to stop services because the running kernel
+	does not provide the support that the updated pwait(1) needs.
+	Alternatively, if you deem it safe, you may use fastboot(8) to
+	reboot without shutting down services first.
+
 20260116:
 	Bump __FreeBSD_version to 1403508 for various LinuxKPI changes
 	so they could be detected if needed.
diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr
index 2cc664cf473d..669fd0107181 100644
--- a/libexec/rc/rc.subr
+++ b/libexec/rc/rc.subr
@@ -634,7 +634,7 @@ sort_lite()
 #
 wait_for_pids()
 {
-	local _list _prefix _j
+	local _list= _prefix= _j=
 
 	for _j in "$@"; do
 		if kill -0 $_j 2>/dev/null; then
@@ -645,7 +645,7 @@ wait_for_pids()
 	while [ -n "$_list" ]; do
 		echo -n ${_prefix:-"Waiting for PIDS: "}$_list
 		_prefix=", "
-		_list=$(pwait -op $_list 2>/dev/null)
+		_list=$(pwait -opr $_list 2>/dev/null)
 	done
 	if [ -n "$_prefix" ]; then
 		echo "."
diff --git a/libexec/rc/tests/rc_subr_test.sh b/libexec/rc/tests/rc_subr_test.sh
index d453338a7ea3..44ad9bf43fd5 100644
--- a/libexec/rc/tests/rc_subr_test.sh
+++ b/libexec/rc/tests/rc_subr_test.sh
@@ -125,20 +125,12 @@ wait_for_pids_progress_head()
 }
 wait_for_pids_progress_body()
 {
-	cat >>script <<'EOF'
-. /etc/rc.subr
-sleep 15 &
-a=$!
-sleep 10 &
-b=$!
-sleep 5 &
-c=$!
-wait_for_pids $a $b $c
-EOF
-	re="^Waiting for PIDS: [0-9]+ [0-9]+ [0-9]+"
-	re="${re}, [0-9]+ [0-9]+"
-	re="${re}, [0-9]+\.$"
-	atf_check -s exit:0 -o match:"${re}" /bin/sh script
+	a=$(sleep 4 >/dev/null & echo $!)
+	b=$(sleep 3 >/dev/null & echo $!)
+	c=$(sleep 2 >/dev/null & echo $!)
+	atf_check \
+	    -o inline:"Waiting for PIDS: $a $b $c, $a $b, $a.\n" \
+	    /bin/sh -c ". /etc/rc.subr; wait_for_pids $a $b $c"
 }
 
 atf_init_test_cases()

From nobody Mon Aug  3 11:38:51 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7H4471z6nC9d
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:51 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF7H2W5Dz3SFP
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:51 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757131;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=+ZNVHyH1Z1b2oKm/HLlHhTYoE75OIpb3pxjDdlcuwOY=;
	b=OdRSFDy/E1VtvKjqHHw+NI2FBO+657qsPYYS0w9LdL8tZxc/rbJ/M0T65xFsa0NWOkKMrn
	yrH/59rfLLamID1xn47SqL50Ku3ApN2Z91DVnbjNxrWZTBSzwl/TOqFrOAt9F/CpA2abkS
	LtTfNH7/4ohzxatFzGto7+ZDsWoRonZ30t2C44SyQASRT45XpaKMAF+FzN0iDaz3dYew5W
	szIcZSrQHhUgkbCcuyd3z/M8auAAbOSepjVJLjrDHUkt/fvY3aWQIj7NBxeUfqydNFzjux
	8JD4HQPQgk+TzdGGtuuT+7gU1TGbp1zJhcJYrzhVGShkfo/0AqL2aweo3V3uUg==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757131; a=rsa-sha256; cv=none;
	b=XbdeoMZ/2HnrTSKx5GPO05dw30Tnn0v5ImXS8An8ERk+P/xmC3f0Lfy/f5GH+TMIMoDRJQ
	jYodZDP90N93u6zx7NHuoQ1A2A5zWG3clO4e224qYwsg1oLPgvtSTzhORzCAtvgnnjTkZu
	PYTBC4G0asBzmG7QqFa7XtH5TLqWUgyCFTOrdFY76FKZ2w52Xekr/WpepeneYdD9Rh2evA
	paicRjUSA1BuNqpMBcTtLPChSzM/1xEEDo/NqkGBUN5WV/W5LgNPCIXX7sZoyeEzXZS/lx
	8LZ/xp15cmFxF4KELaoplfZ3yfY3A5nKyw5csinhkECjOFO8QsI/ke8qagRCsg==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757131;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=+ZNVHyH1Z1b2oKm/HLlHhTYoE75OIpb3pxjDdlcuwOY=;
	b=lSSWKAWroylITHU7OhV5bvkGmtw6Knc5Oqr0b4kt4YShhxT9qvRjljFUx9L097oSQINt8T
	Dk5CGFEbVv+hUMOF/9+IuLGJgMEP18BzxiwoPMqGT85JMMEwC9DAzjBfjwUGyUENzRD+eP
	7He1b73zewpOX0CTaP7NKpOwNmC6Ad2ZnYL7z0bWOchhaEToeu9NE1TEKDhIiiyJCIS2Ie
	5Q6v2YQXC6+HVR+bP6NjBktY4cceEZioSSV1x+YIXTlbwpvb8p5zUPxoO4y3s1LrH5Un9/
	S3jGh0/2MscPnFEvED8/xl/bEC1uu8XuuznIojFsrR647qVku1xReMqveVSiow==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7H1Y0vzy9G
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:51 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 19566
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:51 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 58c826d72918 - stable/14 - pwait: Fix pwait_normal test case
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 58c826d7291813f385ad87107474aa73fb1d938d
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:51 +0000
Message-Id: <6a707dcb.19566.5a34569@gitrepo.freebsd.org>

The branch stable/14 has been updated by des:

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

commit 58c826d7291813f385ad87107474aa73fb1d938d
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 18:51:50 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:14 +0000

    pwait: Fix pwait_normal test case
    
    Reported by:    markj
    Fixes:          e115066370dc ("pwait: Test the new -r option")
    
    (cherry picked from commit 51c0cdb04919f776516a7fac8529e7279ea5efad)
---
 bin/pwait/tests/pwait_reap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bin/pwait/tests/pwait_reap.c b/bin/pwait/tests/pwait_reap.c
index 96c036ba2059..8402def1a41f 100644
--- a/bin/pwait/tests/pwait_reap.c
+++ b/bin/pwait/tests/pwait_reap.c
@@ -166,7 +166,7 @@ ATF_TC_HEAD(pwait_normal, tc)
 }
 ATF_TC_BODY(pwait_normal, tc)
 {
-	pwait_reap_test(true);
+	pwait_reap_test(false);
 }
 
 ATF_TC(pwait_reap);

From nobody Mon Aug  3 11:38:50 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7G5Shjz6nCDC
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 11:38:50 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDF7G2bm3z3S1h
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:50 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785757130;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=k+qZMozrt7d4ogEL2hLp1JpxLJfu6P2UEcjjq5uQGXg=;
	b=fvrSpOX0aBYUc0bnlG5lggrVVpm0IT+J1iHh7+5gpliPkeSboT6tDR91iOmVeUXCjLFsfR
	5uExkQYdXiiXmiZ8i3s+UbH5WehLMAwhCE+KKmr5fmMQERVSR7GzaD0q8vdNjv2ypWuD62
	vXsF1FjDDQjUJRPOA9uyO8uDy2Ky3rcV651/iyomy3KORXSahphfgLi9kIB1nn4D8R3t6r
	PNdlCsVeUhtuS4FLqPYpQvtVpGayw8cTvkeWzdsz2L5wRQ91IF0py4mO0F+Xz+HYM08b3y
	kGtRLiArZu/HBm86oKL2c40PoMuxvGTVDDPEk3K1Xe7zxW+ZW0h8KYS+snZnMw==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757130; a=rsa-sha256; cv=none;
	b=IY58KcdnxAE7qQegQfEdXCZ0++Z0KDVK3/XaHJnvDhW698wxYZRRF/Dqq0pup+rmX/T4nb
	9An3KIald8TwK+2p4uGHWA/NJejcp+fxICODKAbu0iObN9xEKVHPqkeaXb4TbZd+I5FH6d
	/+GvNwowoBWSEo+rAfij4tfw6LKfrHPYzK35j3IV0vjUB0GBA/suUNqgAySVety9L3dqW8
	oNqR8QvfyxpkKOPMEj0P/i4dQ7aXqBFSXhjPgyeVPNVA72aSsMXaCILmk2Ch49BL6Xc9mM
	U4OwdB0iC3LTahBWW3UMtK0v3pl79buarQONSn0sqrAr74aW7AKit6o17Kyx/g==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785757130;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=k+qZMozrt7d4ogEL2hLp1JpxLJfu6P2UEcjjq5uQGXg=;
	b=Qy17Stsm3Mwe7ZjNaU8WvsvZ5oRBkAtQYeOr5nNTheoG6YAzYXv6YdPNmd4gY8b6d3CIJ0
	dHpNoIV86dYswxIdkpcQf6MtEWJ84BpFJdSaHnWDa+3TjOP53vBIJifeT3N9hRma4qN/gl
	cbJPCEduq62DgqydgnZij/3OcrNxOMTqN1MdHy4Y5MoUQCU5SN8ecSNuavfMpi77+hNzVk
	rPZnQVIob0gM0IMpz/0yv8Wm+5OCdCkC/rKOJ2zJI56C+BoKohLtKEWDQxz+eED7ahs1Nh
	GFcRbrMgv5WJ4dak/38EyaKff6ZYKUuRZLB+2mAJs57kA4Dr6x8zwviBZtmlqA==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF7G0kXnzy9F
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 11:38:50 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 1a034
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 11:38:50 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
Subject: git: 04753df6c7de - stable/14 - Bump dates
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: des
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 04753df6c7de6f4300a9545b7199ee1bc6ede0d9
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 11:38:50 +0000
Message-Id: <6a707dca.1a034.36b1742a@gitrepo.freebsd.org>

The branch stable/14 has been updated by des:

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

commit 04753df6c7de6f4300a9545b7199ee1bc6ede0d9
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-07-27 10:26:41 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-03 11:32:14 +0000

    Bump dates
    
    Fixes:          c8f5e6819d4d ("pwait: Optionally wait until process is reaped")
    Fixes:          eddd8aa99ca8 ("pwait: Add a SIGINFO handler")
    Fixes:          356d0b79cf6f ("rc.subr: Fix premature return from wait_for_pids")
    (cherry picked from commit 9d852922f6687ce9a699efe5e09e3634923b2b60)
---
 UPDATING              | 2 +-
 bin/pwait/pwait.1     | 2 +-
 lib/libc/sys/kqueue.2 | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/UPDATING b/UPDATING
index eb1d65b8f455..0e3fd5317bb0 100644
--- a/UPDATING
+++ b/UPDATING
@@ -12,7 +12,7 @@ Items affecting the ports and packages system can be found in
 /usr/ports/UPDATING.  Please read that file before updating system packages
 and/or ports.
 
-20260722:
+20260727:
 	The wait_for_pids() function in rc.subr, used by rc scripts
 	when stopping or restarting a service, has been modified to
 	use pwait(1)'s new -r option, which requires kernel support.
diff --git a/bin/pwait/pwait.1 b/bin/pwait/pwait.1
index 738f11aa5468..04a33c646fd3 100644
--- a/bin/pwait/pwait.1
+++ b/bin/pwait/pwait.1
@@ -30,7 +30,7 @@
 .\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 .\" OF SUCH DAMAGE.
 .\"
-.Dd July 22, 2026
+.Dd July 27, 2026
 .Dt PWAIT 1
 .Os
 .Sh NAME
diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2
index e4e4c85d8a77..861c69a5c621 100644
--- a/lib/libc/sys/kqueue.2
+++ b/lib/libc/sys/kqueue.2
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd July 22, 2026
+.Dd July 27, 2026
 .Dt KQUEUE 2
 .Os
 .Sh NAME

From nobody Mon Aug  3 17:29:43 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDNw76w5pz6mbdN
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 17:29:43 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDNw760jLz3lYf
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:29:43 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785778183;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=jw4y4GhiOQ8f+Ntk8O+WrBVzJyBHrOIK2hoqrp5h+xE=;
	b=fGWEJ3XD4k0Ld8VUGa8j6vGyxHgUpyfhZ5Zugnrr47w+ViBL1riOPalHu4BnpQi/VdzpvA
	ge+Of7ae6O1GkmgleaCx3jud7bRTQ9CezHFeCFTlwd2tF9EuR6k5Ja+mP8ZOfkD55SKH35
	BfZbIxkrxGQAj7CUon4i0Ll2q5Ur0O/vVb0Wi1mgcT0vgcZiHUy5VtuhYOG7pGB4TFyHNY
	cBsuTKoUa76OHklmDNOQ2CWsZ5DRn5uvs2Z29zTP3D92bOQhH9y0/S0xT5U/jIqJcSf+Zt
	uS2Ydb1OfwYiVMWqxW0Zqv6zJ07vVccATN6SmaVFRhZFl/1ufuGvoltzVGBiGQ==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785778183; a=rsa-sha256; cv=none;
	b=e3tFe4rx/Js9mQUMdCH16IyTd8I5RJMZKXvs2DQGWUXfGHy5RFnSvJudxCFAxSO4P1t5Tt
	2BrD6nzsvh1kCBnOHa6nUbzHfnNW/PgUd7+KGk8mwpOJ0JaTpm0hSSZDb0hGGu/m0M5QVU
	og24LPzwMN1DzeDxEaD+zFyYh1aBm/GR2f/CoblgDVDPNGHsX8FJzdcO5Zulsqnt5jxL1G
	GK/anwkp09wVIXkE/Zl4ImdFWCVKGlMm9f+M3nENKZL8u0eJeJBWPM4g/GIilcQgAoMHbt
	F49fakLzGwcna4zAehLYEi56WNC6/ZM6FfXPjfuzg7hzRKTgON6ASn8DSFcl0g==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785778183;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=jw4y4GhiOQ8f+Ntk8O+WrBVzJyBHrOIK2hoqrp5h+xE=;
	b=oqekgFj0SwOFrycZ3TOe7C/NbHIT5FUdhfCJjKFknSC3GX7DZq4MCKu6zYCXLAUeur6J/f
	23LSyXUefl6XTcpgE39+uWf2P1EGAHzhSVxR5e1LqMHUTkX3611tj0v2zwPUfmZPwGcZ1k
	QUhcURmbZQwJ2xnLbnZdmPj/O3OXCzh/2Wl/1kW9CwU1lraOEp93B7bltz1amquiPZQ9K2
	MPvS7kDRrR/VktZv1d+rQUoM8YF63N+KK0sVaf4syEhUkAl2ByiPK1SwYw+5MkzVcLEXx+
	Wd8rV/oI1my54YKjK0cHi0iyqW+es7s7h3gsrzJ5GdM445DxhNCw+qbghwtOXg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDNw74T5Xz18l2
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:29:43 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 47043
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 17:29:43 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Alexander Leidinger <netchild@FreeBSD.org>
Subject: git: 1e0ae0d055d2 - stable/15 - hwpmc: handle counter wraparound for process-mode counting PMCs
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: netchild
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 1e0ae0d055d2f91db5a9c2cf19459621b470b294
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 17:29:43 +0000
Message-Id: <6a70d007.47043.295ac39e@gitrepo.freebsd.org>

The branch stable/15 has been updated by netchild:

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

commit 1e0ae0d055d2f91db5a9c2cf19459621b470b294
Author:     Alexander Leidinger <netchild@FreeBSD.org>
AuthorDate: 2026-07-19 07:38:52 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2026-08-03 17:29:24 +0000

    hwpmc: handle counter wraparound for process-mode counting PMCs
    
    The accumulated count of a process-mode counting PMC is kept in a
    64-bit software counter and seeded into the hardware counter at every
    context switch in.  Hardware counters are narrower than that - each
    PMC class discovers and records its own counter width, e.g. 48 bits
    on current x86 (queried from CPUID on Intel, architectural on AMD) -
    so once the accumulated count approaches the end of the hardware
    counter range, the counter wraps during a time slice and the value
    read back at switch out is smaller than the value seeded.  The
    increment was computed assuming a full 64-bit counter: on INVARIANTS
    kernels a long enough counting run panics with "negative increment"
    the moment the accumulated count first crosses the hardware counter
    range, and on other kernels the totals silently lose a full counter
    range per wrap.
    
    Compute the increment modulo the per-class hardware counter width
    instead, in both places that accumulate switch-out deltas.
    
    Reviewed by:            adrian
    MFC after:              2 weeks
    Assisted-by:            Claude Code (Fable 5)
    Differential Revision:  https://reviews.freebsd.org/D58340
    
    (cherry picked from commit e42703f5c4b2d3a869b17e2cb8670f1b6359c8cf)
---
 sys/dev/hwpmc/hwpmc_mod.c | 46 ++++++++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index 04e23ae24c31..c8b193eee944 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -1589,6 +1589,24 @@ pmc_process_csw_in(struct thread *td)
 	critical_exit();
 }
 
+/*
+ * Compute the change in a counter's value since it was last written.
+ * The hardware counter is only pcd_width bits wide and wraps around,
+ * while the value seeded into it may occupy the full 64-bit range, so
+ * take the difference modulo the counter width.
+ */
+static pmc_value_t
+pmc_delta(const struct pmc_classdep *pcd, pmc_value_t newvalue,
+    pmc_value_t oldvalue)
+{
+	pmc_value_t delta;
+
+	delta = newvalue - oldvalue;
+	if (pcd->pcd_width < 64)
+		delta &= ((pmc_value_t)1 << pcd->pcd_width) - 1;
+	return (delta);
+}
+
 /*
  * Thread context switch OUT.
  */
@@ -1601,8 +1619,7 @@ pmc_process_csw_out(struct thread *td)
 	struct pmc_process *pp;
 	struct pmc_thread *pt = NULL;
 	struct proc *p;
-	pmc_value_t newvalue;
-	int64_t tmp;
+	pmc_value_t newvalue, tmp;
 	enum pmc_mode mode;
 	int cpu;
 	u_int adjri, ri;
@@ -1740,23 +1757,19 @@ pmc_process_csw_out(struct thread *td)
 				}
 				mtx_pool_unlock_spin(pmc_mtxpool, pm);
 			} else {
-				tmp = newvalue - PMC_PCPU_SAVED(cpu, ri);
+				/*
+				 * For counting process-virtual PMCs, the
+				 * hardware counter's value increases
+				 * monotonically modulo the counter width;
+				 * pmc_delta() recovers the increment even
+				 * when the counter wrapped during the run.
+				 */
+				tmp = pmc_delta(pcd, newvalue,
+				    PMC_PCPU_SAVED(cpu, ri));
 
 				PMCDBG3(CSW,SWO,1,"cpu=%d ri=%d tmp=%jd (count)",
 				    cpu, ri, tmp);
 
-				/*
-				 * For counting process-virtual PMCs,
-				 * we expect the count to be
-				 * increasing monotonically, modulo a 64
-				 * bit wraparound.
-				 */
-				KASSERT(tmp >= 0,
-				    ("[pmc,%d] negative increment cpu=%d "
-				     "ri=%d newvalue=%jx saved=%jx "
-				     "incr=%jx", __LINE__, cpu, ri,
-				     newvalue, PMC_PCPU_SAVED(cpu, ri), tmp));
-
 				mtx_pool_lock_spin(pmc_mtxpool, pm);
 				pm->pm_gv.pm_savedvalue += tmp;
 				pp->pp_pmcs[ri].pp_pmcval += tmp;
@@ -5067,7 +5080,8 @@ pmc_process_exit(void *arg __unused, struct proc *p)
 				if (PMC_TO_MODE(pm) == PMC_MODE_TC) {
 					pcd->pcd_read_pmc(cpu, adjri, pm,
 					    &newvalue);
-					tmp = newvalue - PMC_PCPU_SAVED(cpu, ri);
+					tmp = pmc_delta(pcd, newvalue,
+					    PMC_PCPU_SAVED(cpu, ri));
 
 					mtx_pool_lock_spin(pmc_mtxpool, pm);
 					pm->pm_gv.pm_savedvalue += tmp;

From nobody Mon Aug  3 17:29:44 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDNw86vZHz6mbYQ
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 17:29:44 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDNw85zZpz3lc0
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:29:44 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785778184;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=C2svC5HXgnOQwJA8BJL9qOG8vXPI8jGvpRlBiv3l2HU=;
	b=bkYVlHpZOqkSpIY6ozHQVdJLtLWD8+4rz0aZAN5IHW0a0JPTb3jPZKqpwKTbD1PoKsFDd2
	uVFmBfEbtTrgMcWk9yCHqig//F9Gyqd2O0F5crNWKWlya1klyFHi2UIx3R8AZjb5yPno0q
	rXLE6fLYSauVz7pdc3KMHrg4vrpqw5namAWZSXLoCNdhSO/EN7uJa4LBhLJPPnp7I2n2GQ
	eFGOqjJC2vchzhbl6F4+Ib6Ng0IxqPQn3Z+mMNNOU/yIXpOfvowDvYTBG5HDJf/zwj79rT
	S0A0x7bET6B3iyVq+ynjn3JFX0kV7iu+wvc/h5Rh7skEDfENdlKWlYiMHzNV9Q==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785778184; a=rsa-sha256; cv=none;
	b=tM9Z006Q6CqT8+eRermSM8/yEno5M4Km3KJMoYvcggLs30RHysO8CF+UlWEd0wv5ywCsje
	nPkcgJY+JBM5CmYGyIg0d7GjRTHy80BA4+Lb++hSYfpbAhbE84XGkGHKcQIy8qWmL075Ea
	5N+QilGqhv48xBsfG573NiCnrvtJ1nQga7JpDea8V9FuFqezk3tW2t9itgxDgLi5dqUNIy
	At8cuR5lcpq7b/vPKcKYDIW63Hr+fQwV7BsODqlG66fF23lFhUn4z4vSuSxXekrv2oQVnz
	ubRs6UIKvUZs3T7SlZPtsBz+UfljN59YVyQR+NkgqTaWHQXuJwTMZOxrtjRpjw==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785778184;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=C2svC5HXgnOQwJA8BJL9qOG8vXPI8jGvpRlBiv3l2HU=;
	b=vNnOAYhriUz90CvAiljpsSKdS5v7ddhUYT6OchlPs5D9HP/4m5lJXCzaGS49cDofDchcET
	jpSVZMQymIhc97IBI8utZSilSblKt+VxNF3thUReFbldroMQ27VDdp7ZIaAUJ/m/5diRsV
	+H8PB+22u4r8eysUPoyDKSezhm16v9F0q5WViiAcYgsaxjlqSLyT4UO5av2LUWeortyLMY
	WKw83gBgfoj7MA49VYYaZE73QH+58Cvm92tUfXwakvnRXiLt2cRX7qwXntAg6nMC2Z31A8
	+p9uH2Ro8ODJYAkt3LJiKd/1ZjcZsrsmkqsuC0dMdqxx/VxQ9H4CCMVv8oqI9A==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDNw84T7qz19Gq
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:29:44 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 45df3
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 17:29:44 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Alexander Leidinger <netchild@FreeBSD.org>
Subject: git: 6f7bdac868c7 - stable/15 - hwpmc: add regression tests for counting-PMC counter wraparound
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: netchild
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 6f7bdac868c7cae2806331f0f13925a5dda4f36e
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 17:29:44 +0000
Message-Id: <6a70d008.45df3.461d90d4@gitrepo.freebsd.org>

The branch stable/15 has been updated by netchild:

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

commit 6f7bdac868c7cae2806331f0f13925a5dda4f36e
Author:     Alexander Leidinger <netchild@FreeBSD.org>
AuthorDate: 2026-07-19 08:08:48 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2026-08-03 17:29:25 +0000

    hwpmc: add regression tests for counting-PMC counter wraparound
    
    Exercise a process-mode counting PMC whose accumulated count crosses,
    or already exceeds, the range of the underlying hardware counter.
    Before the previous commit, the first context switch after the
    hardware counter wrapped panicked INVARIANTS kernels with "negative
    increment" and silently corrupted the accumulated count on other
    kernels.
    
    The tests need a hardware counting event backed by a counter narrower
    than 64 bits and skip where none is available (hwpmc(4) not loaded,
    or a VM without a vPMU).
    
    Reviewed by:            adrian
    MFC after:              2 weeks
    Assisted-by:            Claude Code (Fable 5)
    Differential Revision:  https://reviews.freebsd.org/D58341
    
    (cherry picked from commit 2cfd82f747c04f68f679824ba627460e87ab3848)
---
 etc/mtree/BSD.tests.dist      |   2 +
 tests/sys/Makefile            |   1 +
 tests/sys/pmc/Makefile        |   7 ++
 tests/sys/pmc/pmc_wrap_test.c | 216 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 226 insertions(+)

diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index d346ae29a4d6..a0007a357630 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -971,6 +971,8 @@
             utimensat
             ..
         ..
+        pmc
+        ..
         posixshm
         ..
         ses
diff --git a/tests/sys/Makefile b/tests/sys/Makefile
index 535e627d22cb..e3589efa14c3 100644
--- a/tests/sys/Makefile
+++ b/tests/sys/Makefile
@@ -29,6 +29,7 @@ TESTS_SUBDIRS+=		netlink
 TESTS_SUBDIRS+=		netmap
 TESTS_SUBDIRS+=		netpfil
 TESTS_SUBDIRS+=		opencrypto
+TESTS_SUBDIRS+=		pmc
 TESTS_SUBDIRS+=		posixshm
 TESTS_SUBDIRS+=		ses
 TESTS_SUBDIRS+=		sound
diff --git a/tests/sys/pmc/Makefile b/tests/sys/pmc/Makefile
new file mode 100644
index 000000000000..403acd0311ce
--- /dev/null
+++ b/tests/sys/pmc/Makefile
@@ -0,0 +1,7 @@
+TESTSDIR=	${TESTSBASE}/sys/pmc
+
+ATF_TESTS_C=	pmc_wrap_test
+
+LIBADD+=	pmc
+
+.include <bsd.test.mk>
diff --git a/tests/sys/pmc/pmc_wrap_test.c b/tests/sys/pmc/pmc_wrap_test.c
new file mode 100644
index 000000000000..58e7b3ef416a
--- /dev/null
+++ b/tests/sys/pmc/pmc_wrap_test.c
@@ -0,0 +1,216 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 Alexander Leidinger <netchild@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other advertising materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Regression tests for process-mode counting PMCs whose accumulated
+ * count is close to, or beyond, the range of the underlying hardware
+ * counter.  Hardware counters are narrower than the 64-bit software
+ * counter (48 bits on modern x86), and the increment collected when a
+ * counter is read out (at context switch and at process exit) must be
+ * computed modulo the hardware width.
+ *
+ * Before the fix these tests panicked INVARIANTS kernels with
+ * "[pmc,...] negative increment" once the hardware counter wrapped,
+ * and silently corrupted the accumulated count on other kernels.
+ *
+ * The counter is attached to a short-lived child process which spins
+ * to advance it; the child exits before the PMC is released, so the
+ * accounting is torn down cleanly (the accumulation is collected on
+ * the exit path, which is one of the two sites the fix touches).
+ *
+ * The tests need a hardware counting event whose counter is narrower
+ * than 64 bits; they skip on systems without one (e.g. VMs without a
+ * vPMU, or with hwpmc(4) not loaded).
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <errno.h>
+#include <pmc.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+/*
+ * High-rate events; at least one of these should be allocatable on
+ * any x86 or arm64 system with a vPMU.  All of them count while the
+ * child's spin loop runs.
+ */
+static const char *wrap_test_events[] = {
+	"instructions",
+	"cycles",
+	"branches",
+	"unhalted-core-cycles",
+	"inst_retired.any",
+	"cpu_clk_unhalted.thread",
+	"ls_not_halted_cyc",
+	NULL
+};
+
+/* The child generates well more than this many events past the seed. */
+#define	WRAP_MARGIN	((uint64_t)1 << 20)
+
+/* Spin iterations: comfortably more than WRAP_MARGIN events, still < 1s. */
+#define	SPIN_ITERS	((uint64_t)200 * 1000 * 1000)
+
+/* Upper bound on events a single test run can plausibly generate. */
+#define	SANITY_BOUND	((uint64_t)1 << 40)
+
+/*
+ * Child: wait for the parent to start the PMC (one byte on the pipe),
+ * spin to advance the counter across the end of its range, then exit.
+ */
+static void __attribute__((noinline))
+child_spin(int startfd)
+{
+	volatile uint64_t sink = 0;
+	uint64_t i;
+	char c;
+
+	(void)read(startfd, &c, 1);
+	for (i = 0; i < SPIN_ITERS; i++)
+		sink += i;
+	_exit((int)(sink & 0x7f));
+}
+
+/*
+ * Allocate a process-mode counting PMC for the first available event
+ * backed by a counter narrower than 64 bits, attach it to a child,
+ * seed it with the given value, let the child spin past the end of
+ * the counter range, and check that the accumulated count stayed sane.
+ */
+static void
+wrap_test(bool seed_beyond_width)
+{
+	pmc_id_t pmcid;
+	pmc_value_t final;
+	uint64_t seed;
+	uint32_t width;
+	pid_t child;
+	int i, pfd[2], status;
+
+	if (pmc_init() != 0)
+		atf_tc_skip("hwpmc(4) is not available: %s", strerror(errno));
+
+	width = 0;
+	pmcid = PMC_ID_INVALID;
+	for (i = 0; wrap_test_events[i] != NULL; i++) {
+		if (pmc_allocate(wrap_test_events[i], PMC_MODE_TC, 0,
+		    PMC_CPU_ANY, &pmcid, 0) != 0)
+			continue;
+		ATF_REQUIRE(pmc_width(pmcid, &width) == 0);
+		if (width >= 32 && width < 64)
+			break;
+		ATF_REQUIRE(pmc_release(pmcid) == 0);
+		pmcid = PMC_ID_INVALID;
+	}
+	if (pmcid == PMC_ID_INVALID)
+		atf_tc_skip("no allocatable counting event with a hardware "
+		    "counter narrower than 64 bits");
+
+	if (seed_beyond_width) {
+		/* Accumulated count that no longer fits the counter at all. */
+		seed = ((uint64_t)1 << width) + 12345;
+	} else {
+		/* Just below the end of the counter range; the child crosses it. */
+		seed = ((uint64_t)1 << width) - WRAP_MARGIN;
+	}
+
+	ATF_REQUIRE(pipe(pfd) == 0);
+	child = fork();
+	ATF_REQUIRE(child >= 0);
+	if (child == 0) {
+		close(pfd[1]);
+		child_spin(pfd[0]);
+		/* NOTREACHED */
+	}
+	close(pfd[0]);
+
+	ATF_REQUIRE(pmc_attach(pmcid, child) == 0);
+	ATF_REQUIRE(pmc_write(pmcid, seed) == 0);
+	ATF_REQUIRE(pmc_start(pmcid) == 0);
+
+	/* Release the child, which spins and exits. */
+	ATF_REQUIRE(write(pfd[1], "g", 1) == 1);
+	close(pfd[1]);
+	ATF_REQUIRE(waitpid(child, &status, 0) == child);
+
+	/*
+	 * The child is gone: its final increment was collected on the
+	 * exit path.  Read the accumulated 64-bit count and stop.
+	 */
+	ATF_REQUIRE(pmc_read(pmcid, &final) == 0);
+	(void)pmc_stop(pmcid);
+
+	ATF_CHECK_MSG(final >= seed,
+	    "accumulated count went backwards: seed 0x%jx, final 0x%jx "
+	    "(width %u)", (uintmax_t)seed, (uintmax_t)final, width);
+	ATF_CHECK_MSG(final - seed < SANITY_BOUND,
+	    "accumulated count jumped implausibly: seed 0x%jx, final 0x%jx "
+	    "(width %u)", (uintmax_t)seed, (uintmax_t)final, width);
+
+	ATF_REQUIRE(pmc_release(pmcid) == 0);
+}
+
+ATF_TC(counting_pmc_wraps_hardware_counter);
+ATF_TC_HEAD(counting_pmc_wraps_hardware_counter, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "A process-mode counting PMC survives its hardware counter "
+	    "wrapping around while the counted process runs");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(counting_pmc_wraps_hardware_counter, tc)
+{
+	wrap_test(false);
+}
+
+ATF_TC(counting_pmc_beyond_hardware_width);
+ATF_TC_HEAD(counting_pmc_beyond_hardware_width, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "A process-mode counting PMC keeps counting correctly once "
+	    "its accumulated count exceeds the hardware counter range");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(counting_pmc_beyond_hardware_width, tc)
+{
+	wrap_test(true);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, counting_pmc_wraps_hardware_counter);
+	ATF_TP_ADD_TC(tp, counting_pmc_beyond_hardware_width);
+
+	return (atf_no_error());
+}

From nobody Mon Aug  3 17:29:45 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDNwB2rblz6mbVV
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 17:29:46 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDNw96mmCz3lc5
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:29:45 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785778186;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=FHvVaKJ4Oqkg0gFtVppWoq1A9ZKvyH4FKH/9CqkjO8I=;
	b=QJ+WTSRRJD6tvJQP0A9DfWG7XoeH+RhY6u0+PsZncb22sjYBMFFljAZdyjOu+xygaeux/E
	0CELqw5Uzwu3d10k4WNegcL9jMXTIR7n67bRl4tmZBakVp7chEZnD+XvppXcz/qWu1aGaf
	2CQgGIkipKyVquQYjFs9Zc/p9lrnATr6+Jto59JgSC1mw44hkWLRepINmDTldaos/PK3+E
	BJmGLLhs604f/wrGXckFvQfXDX6+aNMuh8usoKxHdm0u3PLKO5zeCK9fSDAi1dN1IE+anO
	Sxw6rE/ZI5zix5pSZimbmgLQhx7if3qfGXoID7MYyhJUTX/rIgjexmnata8Xkg==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785778186; a=rsa-sha256; cv=none;
	b=oO1LMmfsVEjCoKMl/JogeFcT+gm2LVkhTYzlr1qnZQqQKvAhr6PTgYCtEhrAC4sKkzd+wl
	+5nwfwiFaZEQoWWIf3TzNQcTYkc1Uu+xnhtCpx13O05ZsXkotzs0Ol6yvcgrpJYVi40+co
	Lb3GGolSBlGhu39dFk1k10uiv7p5pwSKW4YTdZ3uUpF2wuRPwe3cJkb68/3qq7HrbBz7Tj
	dCboHRmXa1g9BFt4skzN22Qppnku7Wbu/021IR5EJmZqK8nhI8spl4qIa+PIFSLewzWpqi
	FodAncVP4V86iZD5ggqlKfJ8TFh7dOA7e70+EVuvQk6SnVRk7nuOC6KpUq2Xhg==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785778186;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=FHvVaKJ4Oqkg0gFtVppWoq1A9ZKvyH4FKH/9CqkjO8I=;
	b=Sa9au5VLpOKveMjg2k/agSQtCtS9jrfTEZvbojx/ZdBSRTGriwYT21qScrNCPlIctiKPrt
	lp4D+L03gzd28SJPIhJp5HpJgfa3vFezY5FqQaeP1+an0591ZhDxa3/0eigxgYoFrJ6wD9
	CO0fiOkA2mLgZ9WRE5WjYIaQP0n1zRi5FNYkmLEFN3YyXbDPjCPxq24iMYDC9m988124BI
	Wo1xwUHzkPT9vG7gBWWtaLqu53uai2Y0B1vzHw7k98adHe1n+ZHcmdIKVWN8Znw8bOBVKP
	DKZbQzPUqdbIWcFs40nY4jFzcQt1wwhYx3KW/Pn7UzFFjgfveuo7ohkeZauXNg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDNw953cnz19KD
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:29:45 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 47d97
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 17:29:45 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Alexander Leidinger <netchild@FreeBSD.org>
Subject: git: 48c9e91856c3 - stable/15 - hwpmc: drain a process-mode PMC's runcount when a live target detaches
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: netchild
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 48c9e91856c32424c96c737564d05d89f5e730e9
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 17:29:45 +0000
Message-Id: <6a70d009.47d97.7ba53672@gitrepo.freebsd.org>

The branch stable/15 has been updated by netchild:

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

commit 48c9e91856c32424c96c737564d05d89f5e730e9
Author:     Alexander Leidinger <netchild@FreeBSD.org>
AuthorDate: 2026-07-19 11:39:27 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2026-08-03 17:29:25 +0000

    hwpmc: drain a process-mode PMC's runcount when a live target detaches
    
    A process-mode PMC's runcount tracks how many CPUs currently have it
    loaded in hardware.  It is decremented only by the context-switch-out
    and process-exit reclaim paths, both of which the scheduler invokes
    only for processes flagged P_HWPMC.  Detaching a target that still has
    the PMC live in hardware dropped the target and cleared P_HWPMC without
    taking the PMC off the hardware or dropping the runcount reference, so
    the reference leaked.  A subsequent release then spun in
    pmc_wait_for_pmc_idle() forever waiting for the runcount to reach zero:
    on an INVARIANTS kernel this panics ("waiting too long for pmc to be
    free"), otherwise it is an unkillable loop holding the hwpmc lock.  Any
    process able to allocate a PMC can trigger this by attaching a counting
    PMC to itself and detaching it before releasing.
    
    Take the PMC off the hardware and drop the runcount reference as part
    of detaching, before P_HWPMC is cleared: reclaim it from the detaching
    thread's own CPU directly, and, when the detach removes the PMC's last
    target, wait for any references held by the target's other threads to
    drain while P_HWPMC is still set (they can no longer reload it).
    
    Reviewed by:            adrian
    MFC after:              2 weeks
    Assisted-by:            Claude Code (Fable 5)
    Differential Revision:  https://reviews.freebsd.org/D58342
    
    (cherry picked from commit 86fa065f1862f3b638efa1868523878d9db14ada)
---
 sys/dev/hwpmc/hwpmc_mod.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index c8b193eee944..70c974857f5c 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -220,6 +220,8 @@ static int	pmc_detach_one_process(struct proc *p, struct pmc *pm,
 static void	pmc_destroy_owner_descriptor(struct pmc_owner *po);
 static void	pmc_destroy_pmc_descriptor(struct pmc *pm);
 static void	pmc_destroy_process_descriptor(struct pmc_process *pp);
+static void	pmc_reclaim_pmc_from_cpu(struct pmc *pm,
+    struct pmc_process *pp, int cpu);
 static struct pmc_owner *pmc_find_owner_descriptor(struct proc *p);
 static int	pmc_find_pmc(pmc_id_t pmcid, struct pmc **pm);
 static struct pmc *pmc_find_pmc_descriptor_in_process(struct pmc_owner *po,
@@ -1236,6 +1238,21 @@ pmc_detach_one_process(struct proc *p, struct pmc *pm, int flags)
 	if (pp->pp_pmcs[ri].pp_pmc != pm)
 		return (EINVAL);
 
+	/*
+	 * If this is a process-virtual PMC that is still loaded on the
+	 * hardware of the CPU we are running on (the common case when a
+	 * process detaches a PMC from itself), take it off and drop its
+	 * runcount reference now.  The reference is otherwise only
+	 * dropped by the switch-out reclaim, which the scheduler stops
+	 * calling once P_HWPMC is cleared below - leaking it and later
+	 * wedging pmc_wait_for_pmc_idle() at release time.
+	 */
+	if (PMC_IS_VIRTUAL_MODE(PMC_TO_MODE(pm))) {
+		critical_enter();
+		pmc_reclaim_pmc_from_cpu(pm, pp, curthread->td_oncpu);
+		critical_exit();
+	}
+
 	pmc_unlink_target_process(pm, pp);
 
 	/* Issue a detach entry if a log file is configured */
@@ -1254,6 +1271,22 @@ pmc_detach_one_process(struct proc *p, struct pmc *pm, int flags)
 	if (pp->pp_refcnt != 0)	/* still a target of some PMC */
 		return (0);
 
+	/*
+	 * This detach removed the process' last PMC and we are about to
+	 * clear P_HWPMC.  If the detached PMC was its last target and is
+	 * still loaded on other CPUs (e.g. sibling threads of a
+	 * multi-threaded target, or a target running on another CPU),
+	 * drain those references first: the target is already unlinked so
+	 * it cannot reload the PMC, and P_HWPMC is still set so those
+	 * CPUs' switch-out reclaim still runs.  Bounded by the target
+	 * threads being scheduled out.
+	 */
+	if (PMC_IS_VIRTUAL_MODE(PMC_TO_MODE(pm)) &&
+	    LIST_EMPTY(&pm->pm_targets)) {
+		while (counter_u64_fetch(pm->pm_runcount) > 0)
+			pmc_force_context_switch();
+	}
+
 	pmc_remove_process_descriptor(pp);
 
 	if (flags & PMC_FLAG_REMOVE)
@@ -1607,6 +1640,61 @@ pmc_delta(const struct pmc_classdep *pcd, pmc_value_t newvalue,
 	return (delta);
 }
 
+/*
+ * Take a process-virtual PMC off the hardware of 'cpu' if it is
+ * currently loaded there for process 'pp', accumulating its final
+ * count and dropping its runcount reference.  This is the same reclaim
+ * that context switch out and process exit perform, factored out so it
+ * can also run when a target is detached while the PMC may still be
+ * live: the runcount reference is decremented by the switch-out reclaim
+ * only, which the scheduler gates on P_HWPMC, so a detach that clears
+ * P_HWPMC without draining would leak the reference and later wedge
+ * pmc_wait_for_pmc_idle().  Must be called in a critical section.
+ */
+static void
+pmc_reclaim_pmc_from_cpu(struct pmc *pm, struct pmc_process *pp, int cpu)
+{
+	struct pmc_classdep *pcd;
+	struct pmc *phw_pm;
+	pmc_value_t newvalue, tmp;
+	u_int adjri, ri;
+
+	ri = PMC_TO_ROWINDEX(pm);
+	pcd = pmc_ri_to_classdep(md, ri, &adjri);
+
+	/* Only reclaim if this PMC is actually loaded on this CPU. */
+	phw_pm = NULL;
+	(void)(*pcd->pcd_get_config)(cpu, adjri, &phw_pm);
+	if (phw_pm != pm)
+		return;
+
+	KASSERT(counter_u64_fetch(pm->pm_runcount) > 0,
+	    ("[pmc,%d] pm=%p runcount %ju", __LINE__, pm,
+	    (uintmax_t)counter_u64_fetch(pm->pm_runcount)));
+
+	if (pm->pm_pcpu_state[cpu].pps_cpustate) {
+		pm->pm_pcpu_state[cpu].pps_cpustate = 0;
+		if (pm->pm_pcpu_state[cpu].pps_stalled == 0) {
+			(void)pcd->pcd_stop_pmc(cpu, adjri, pm);
+
+			if (PMC_TO_MODE(pm) == PMC_MODE_TC) {
+				(void)pcd->pcd_read_pmc(cpu, adjri, pm,
+				    &newvalue);
+				tmp = pmc_delta(pcd, newvalue,
+				    PMC_PCPU_SAVED(cpu, ri));
+
+				mtx_pool_lock_spin(pmc_mtxpool, pm);
+				pm->pm_gv.pm_savedvalue += tmp;
+				pp->pp_pmcs[ri].pp_pmcval += tmp;
+				mtx_pool_unlock_spin(pmc_mtxpool, pm);
+			}
+		}
+	}
+
+	counter_u64_add(pm->pm_runcount, -1);
+	(void)pcd->pcd_config_pmc(cpu, adjri, NULL);
+}
+
 /*
  * Thread context switch OUT.
  */

From nobody Mon Aug  3 17:29:46 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDNwD1Q1Gz6mbVW
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 17:29:48 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDNwC0qCSz3lhf
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:29:47 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785778187;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=SupZjt8PgqfcG7X7nnFqSIk0vsZBX+UnhjEEKFggCeA=;
	b=SqEED7dWrO5LSRK50tMbVYMw0iXzU48jZDH/nKYxWkeM4QMfCI06dtINiUy71tvYRb8VJg
	T1iP0c7vN7cNyHagmphi5L6WP35ojPY/WOpl7R95tIHH5FbBLFMyevIWL5BaD0pcO5O2jv
	eR6rHbfCNNLgKQIZ28wbYQfHgNQZ3U/yXWBcijEDCcEtSjyuwEvfnr0k9ZyExnrOiBPc8P
	IRlS8hs3a4pf7S0Y9Pvs24K3hACe1sN6aqZikvdJknfEKXXunQ7RaOtDo72fFopLLpin3Q
	8zNG6qnht/knT5jw3FBsJRgwHbS4QG33NCidjFEyuYAE9tzwarFFyZr2DKMdvA==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785778187; a=rsa-sha256; cv=none;
	b=G6V2gjT1VWmHLp754YBbgHvaYa9jK0WmxJrOVAAgauCMyRlVncl8x0ibx1r+j5G1+cyLd/
	N2yYptF8TeRIV9k+q6E4+tg5LcYMVmT3gk6dDO5fztAzn2DHFy8qJX1+DBGn2Qai5yfB8p
	d7WH2oUusqiK+0v32pu0fSyE+NR5nfhfq9iSdqoKgc+dN/HpRoa22rfwWzJlmUFGdPrNhc
	jfOKPa7p4v4xNTeXFZhM9dVQFAOhVbNN98xp2/PEZc1Jb9Fk6iHFuTNt3pp8o59hcEW+0K
	FIv7jM44DNy5Lxy0292sfLbCTkclWLVS+KLdYuPg4ea9gKPDHace3Xo2E2an1A==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785778187;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=SupZjt8PgqfcG7X7nnFqSIk0vsZBX+UnhjEEKFggCeA=;
	b=KiJKd0BHEWunh3SX1q6dZ/EFc5YyZI7PIg1s/cBmdEK9DpDN9AmJmLAs6iJHHLvyKghtM6
	aZw9ibqXopGtXC/uoOoLvA/dKpxdmz5GA5BNs+vRyLQC3zchyNJc2uOwiQdiX+GCK+8eSP
	Fzx7G6+R9engT29PI8ZapX3gCtG56/BFS0IGkACghkPVmTvAspFAnlx1ow1YO8Dp2cIEmT
	VeqCc2H8E/wFnkpvKY5tlf0HUiiE+qO3xa0n8ayteoIhd4FOcdBw1vKWKCBNEuA8DJi799
	CoISZTMA5z+rzFWBqp2ys3YDy+A0qsHdoL9HWcauCnZsMFSThqKCAaoghDUeBA==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDNwB5j24z19KG
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:29:46 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 46165
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 17:29:46 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Alexander Leidinger <netchild@FreeBSD.org>
Subject: git: d5e51b56c248 - stable/15 - hwpmc: add regression tests for detaching a live process-mode PMC
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: netchild
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: d5e51b56c248e179dca588089ab349c72160d6bd
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 17:29:46 +0000
Message-Id: <6a70d00a.46165.5332cba2@gitrepo.freebsd.org>

The branch stable/15 has been updated by netchild:

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

commit d5e51b56c248e179dca588089ab349c72160d6bd
Author:     Alexander Leidinger <netchild@FreeBSD.org>
AuthorDate: 2026-07-19 12:15:20 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2026-08-03 17:29:26 +0000

    hwpmc: add regression tests for detaching a live process-mode PMC
    
    Attach a process-mode counting PMC to the current process, start it,
    then detach and release it while it is still loaded on the hardware -
    the case that previously leaked the PMC's runcount reference and
    wedged pmc_wait_for_pmc_idle() at release.  A second case does the same
    from a multi-threaded process so the sibling threads' references have
    to be drained too.
    
    The tests need an allocatable process-mode counting event and skip
    where none is available (hwpmc(4) not loaded, or a VM without a vPMU).
    
    Reviewed by:            adrian
    MFC after:              2 weeks
    Assisted-by:            Claude Code (Fable 5)
    Differential Revision:  https://reviews.freebsd.org/D58343
    
    (cherry picked from commit 3c3f886e4bc7619f7847ad0d0f996088ddf5915a)
---
 tests/sys/pmc/Makefile          |   2 +
 tests/sys/pmc/pmc_detach_test.c | 178 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 180 insertions(+)

diff --git a/tests/sys/pmc/Makefile b/tests/sys/pmc/Makefile
index 403acd0311ce..305a3e65c8b3 100644
--- a/tests/sys/pmc/Makefile
+++ b/tests/sys/pmc/Makefile
@@ -1,7 +1,9 @@
 TESTSDIR=	${TESTSBASE}/sys/pmc
 
 ATF_TESTS_C=	pmc_wrap_test
+ATF_TESTS_C+=	pmc_detach_test
 
 LIBADD+=	pmc
+LIBADD.pmc_detach_test+=	pthread
 
 .include <bsd.test.mk>
diff --git a/tests/sys/pmc/pmc_detach_test.c b/tests/sys/pmc/pmc_detach_test.c
new file mode 100644
index 000000000000..05fda61b2836
--- /dev/null
+++ b/tests/sys/pmc/pmc_detach_test.c
@@ -0,0 +1,178 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 Alexander Leidinger <netchild@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other advertising materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Regression tests for detaching a process-mode PMC from a target that
+ * still has it loaded on hardware.  The runcount reference for a live
+ * PMC is dropped only by the context-switch-out reclaim, which the
+ * scheduler gates on P_HWPMC; detaching used to clear P_HWPMC without
+ * draining the reference, so the following release spun forever in
+ * pmc_wait_for_pmc_idle() - a panic ("waiting too long for pmc to be
+ * free") on an INVARIANTS kernel, an unkillable loop holding the hwpmc
+ * lock otherwise.
+ *
+ * The failure is deterministic: attaching a counting PMC to the current
+ * (running) thread and detaching it before release always left the
+ * reference live.  On a kernel that carries the fix these tests complete
+ * immediately; run against a kernel that lacks it they would wedge, so
+ * (like any hwpmc regression test) they ship alongside the fix.
+ *
+ * They need an allocatable process-mode counting event, and skip where
+ * none is available (hwpmc(4) not loaded, or a VM without a vPMU).
+ */
+
+#include <sys/types.h>
+
+#include <errno.h>
+#include <pmc.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static const char *counting_events[] = {
+	"instructions",
+	"cycles",
+	"branches",
+	"unhalted-core-cycles",
+	"inst_retired.any",
+	"cpu_clk_unhalted.thread",
+	"ls_not_halted_cyc",
+	NULL
+};
+
+static volatile int spin_stop;
+
+static void *
+spinner(void *arg __unused)
+{
+	volatile unsigned long s = 0;
+
+	while (spin_stop == 0)
+		s += 1;
+	return (NULL);
+}
+
+static void
+burn_cpu(void)
+{
+	volatile unsigned long s = 0;
+	int i;
+
+	for (i = 0; i < 1000000; i++)
+		s += i;
+}
+
+/* Allocate the first available process-mode counting PMC, or skip. */
+static pmc_id_t
+alloc_counting_pmc(void)
+{
+	pmc_id_t id;
+	int i;
+
+	if (pmc_init() != 0)
+		atf_tc_skip("hwpmc(4) is not available: %s", strerror(errno));
+
+	for (i = 0; counting_events[i] != NULL; i++) {
+		id = PMC_ID_INVALID;
+		if (pmc_allocate(counting_events[i], PMC_MODE_TC, 0,
+		    PMC_CPU_ANY, &id, 0) == 0)
+			return (id);
+	}
+	atf_tc_skip("no allocatable process-mode counting event "
+	    "(no vPMU?)");
+	return (PMC_ID_INVALID); /* not reached */
+}
+
+ATF_TC(detach_live_self);
+ATF_TC_HEAD(detach_live_self, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Detaching a running counting PMC from the current thread and "
+	    "then releasing it does not leak its runcount reference");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(detach_live_self, tc)
+{
+	pmc_id_t id;
+
+	id = alloc_counting_pmc();
+
+	ATF_REQUIRE(pmc_attach(id, 0) == 0);	/* 0 == current process */
+	ATF_REQUIRE(pmc_start(id) == 0);
+	burn_cpu();				/* make the counter live */
+
+	/* Detach while still loaded on this CPU, then release. */
+	ATF_REQUIRE(pmc_detach(id, 0) == 0);
+	ATF_REQUIRE(pmc_release(id) == 0);	/* wedged before the fix */
+}
+
+ATF_TC(detach_live_multithread);
+ATF_TC_HEAD(detach_live_multithread, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Detaching a running process-scope counting PMC drains the "
+	    "references held by the process' other threads");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(detach_live_multithread, tc)
+{
+	pthread_t th[3];
+	pmc_id_t id;
+	int i, n;
+
+	id = alloc_counting_pmc();
+
+	/* Sibling threads keep the process-scope PMC live on other CPUs. */
+	spin_stop = 0;
+	for (n = 0; n < 3; n++)
+		ATF_REQUIRE(pthread_create(&th[n], NULL, spinner, NULL) == 0);
+
+	ATF_REQUIRE(pmc_attach(id, 0) == 0);
+	ATF_REQUIRE(pmc_start(id) == 0);
+	burn_cpu();
+	/* Let the siblings be scheduled and pick up the PMC. */
+	usleep(200 * 1000);
+
+	ATF_REQUIRE(pmc_detach(id, 0) == 0);
+	ATF_REQUIRE(pmc_release(id) == 0);	/* must drain the siblings */
+
+	spin_stop = 1;
+	for (i = 0; i < n; i++)
+		pthread_join(th[i], NULL);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, detach_live_self);
+	ATF_TP_ADD_TC(tp, detach_live_multithread);
+
+	return (atf_no_error());
+}

From nobody Mon Aug  3 17:29:47 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDNwD3ctvz6mbmQ
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 17:29:48 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDNwD0WLvz3lcY
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:29:48 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785778188;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=xSTqzW3axDCiFleWwYnYudHxDCOPNcsGWgBpoX3+MGU=;
	b=joVve8ggJS0BXPVxSOrywH7+t3CsjlYHLEnGIHsVUmcR/maK2CY8ci7+J6xtVzG+hh1HCY
	A88RTGvQ0m9LhSVUjmJxhcVEdvAaxpXiledHE0jF4MQ9Bi+A2aUxsXU/lx3fSyIFngkWQi
	R62wytTFouyZ2MW2GMeGS+dMUbReIyvxZNuHz0S8MINF68nzYjOsX6vuajYOUF3klGnm8g
	87QLHN8aCq16XS9D+nylhYxq0mpTs8kVGliWqOaCbCTWIMfbb5viQrDV6jILJF0xyT2Owe
	/YCIsDRiZZ98YEFIfGXdtgl66WrLeBMlZVR5PGeVE3Tsic39Vw4nCEyt1aeIDg==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785778188; a=rsa-sha256; cv=none;
	b=DcZBa79Ozt7d880Qb7a6nyA+Iad8gJ2UwFQZ3vkmo+sHVWKHMRu0tYKsWI44BTQYAma6+T
	YzaWsG6U9yXFv7VyZtrh+TDxzFxAzc677JeManPLNTHneCM7qdkWmhv9jShnc4/CzaQkHm
	ZqLG90pSldeV/x/eNy/FJ7d59vdd904+1/2+L4F/qhWzYUa5W3TwjrvGWOMp2D7rjRojDW
	eyNArn85A8UExua/BbQossvxouf3bfCa5rv+liWt06IRoB1S5iJbbx6Y/eK0ezWdnWefOb
	kp9TqvBw5af4CDNlXtYddAnWX5cg8p6pQfjJDghfrk6GZDLQOhZ+oyIjY1refw==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785778188;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=xSTqzW3axDCiFleWwYnYudHxDCOPNcsGWgBpoX3+MGU=;
	b=FoBLub/42cBCpfnrddTuYwwKnCFYYVMRW8bdEl0qpDJm67P1U1viUvtusUBquDuvg+QJ2b
	CYTjqAvJgUeuvB4oiDQn3myhgjCiMHrRmE7ErFOJReak4Okws0JgEVW0yvlCAqUBwkJ9+W
	U6lYgF+JsoTVG2bWZVu3iceyKeWgoJKWHfaxLYKAs7Iw6QqRNDe0goRA8cXHEbB8vjRXxa
	dmyvqOzdJH5iGv+FKxUJD2m3LlbSG0LgxFk+cjzbVf6x0JAE+PIhyEauoyXF+MCDoDZgLK
	bC3u7bdCD1Tuil6SopJc1Mj32L+2wLFFzRyeOhU+DURRKbVC/OzLIzzSPOVnzg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDNwC66qKz18qc
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:29:47 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 47047
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 17:29:47 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Cc: Enji Cooper <ngie@FreeBSD.org>
From: Alexander Leidinger <netchild@FreeBSD.org>
Subject: git: 7503cd109bff - stable/15 - tests/sys/pmc: only build if MK_PMC != no
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: netchild
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: 7503cd109bff5882779788c9864030f461445375
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 17:29:47 +0000
Message-Id: <6a70d00b.47047.7e13ec25@gitrepo.freebsd.org>

The branch stable/15 has been updated by netchild:

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

commit 7503cd109bff5882779788c9864030f461445375
Author:     Enji Cooper <ngie@FreeBSD.org>
AuthorDate: 2026-07-22 19:53:31 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2026-08-03 17:29:26 +0000

    tests/sys/pmc: only build if MK_PMC != no
    
    This unbreaks the build when pmc support is explicitly disabled via the
    aforementioned build knob.
    
    MFC after:      10 days
    Fixes:          2cfd82f74 ("hwpmc: add regression tests for ...")
    Differential Revision:  https://reviews.freebsd.org/D58401
    
    (cherry picked from commit a18e773d2776a65c1a2a0418cbec9cf5ef526b53)
---
 tests/sys/Makefile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/sys/Makefile b/tests/sys/Makefile
index e3589efa14c3..438625683360 100644
--- a/tests/sys/Makefile
+++ b/tests/sys/Makefile
@@ -29,7 +29,7 @@ TESTS_SUBDIRS+=		netlink
 TESTS_SUBDIRS+=		netmap
 TESTS_SUBDIRS+=		netpfil
 TESTS_SUBDIRS+=		opencrypto
-TESTS_SUBDIRS+=		pmc
+TESTS_SUBDIRS+=		${_pmc}
 TESTS_SUBDIRS+=		posixshm
 TESTS_SUBDIRS+=		ses
 TESTS_SUBDIRS+=		sound
@@ -50,6 +50,10 @@ _cddl=	cddl
 _netgraph= netgraph
 .endif
 
+.if ${MK_PMC} != "no"
+_pmc=	pmc
+.endif
+
 # Items not integrated into kyua runs by default
 SUBDIR+=		pjdfstest
 

From nobody Mon Aug  3 17:31:14 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDNxv3V8rz6mbrM
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 17:31:15 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDNxv13xpz3nCY
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:31:15 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785778275;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=wT1hgiHEvitS4zgz1pJwnCXwkH0KMSElavkFJ/Y9V2Q=;
	b=up6GvvlQMK1L06qIMTVfDNFqTb2b8+gI/jmsZx198G+Lp3b0spwciaXelb7jtgFyuM2bmT
	dApBBQz1WRLvrPRXj3+ia0xbVOBUJQ56b1TwPbKOwM7cdViPNc/iYbgVwjXCKSMAAzrFBb
	5tOUQytvGAtv5pfgbNCE9u29mrrGRci5xBZst3oWLA0FKzoh11CsnPH/KdlPjHjgi7Y/B/
	TiZBswfsKXL0yMRVooFku3c0b1ht+VZGkW9D9B4UMuxG439ug8w9w123RFgq9tS6la19C8
	Jixx8MEeOrIwwSZkTXwPGD6Cy7aEMcIJzd9lKvwsF7ytl8CnnR4tX2/uLOUudA==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785778275; a=rsa-sha256; cv=none;
	b=BxjXmJIQpzDls6mhNa7+K/FQEjNFUQYlWnkR3BCSE9626bndLNUJklBTFDn8oqCmqOF4wA
	7tby7YPrwb5hbc5lxOelE4sHAibRXW0M7juYLlXZ7kuOJ26PBPrqebL49PWsz9ENEKMuQY
	lbsfHsI2eepyLIdUKI7xgnEwfWLKnRfz1J4boi1ehpgg93iuKMKwptAr+w3SoNT+ZGtoIZ
	Y8LoIrY3fD2bZBB6WE5KjcgI66hQYc3zpNB3uW5Me2TNNfmkSn+vSiEb9HY0nYdhQtBOUq
	scdmz5lNxuHDbOlc+mF8M3iLNBFl2u8hi3VZJ7NNXaZrekruUGp6AfKCYzCKtg==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785778275;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=wT1hgiHEvitS4zgz1pJwnCXwkH0KMSElavkFJ/Y9V2Q=;
	b=PllvnBG+/lVD2LBxqTFCdaBgLp7N8r1bIZqEv2tjqRFsDObO8kTkWwrYpF0X5ozETR8cdY
	A/67g0kqM8xaesCRMfp88gLWSBJliFQwBgH6EJfbwPn64rTl5ZTTXnkTt/ZF6VtmXJKNpt
	TtPhmEZeMOTVAp5Gd9mS/xUVnwbiJm3y7rfvO/FBPz3KrOL+c9o6iyr3MEwrnIF2HVlgjM
	dc70NpHotpc25L/VLbQcTU5bL4sLh0aVA5TbXeHZy9A6l9dbX/OeBSbn1eLdVaMUMfRCiy
	/MV/WRFDzL38IosPwCO/PrS+Tn8MT76R+qNZ3lz9RrCSXWtIOcxIwRcIxMCISg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDNxt6pMKz18v5
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:31:14 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 18f02
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 17:31:14 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Alexander Leidinger <netchild@FreeBSD.org>
Subject: git: 4ca8afd1d15c - stable/14 - hwpmc: handle counter wraparound for process-mode counting PMCs
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: netchild
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 4ca8afd1d15c35923b136b0d8e4a3cff49c8417a
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 17:31:14 +0000
Message-Id: <6a70d062.18f02.2ae36ca0@gitrepo.freebsd.org>

The branch stable/14 has been updated by netchild:

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

commit 4ca8afd1d15c35923b136b0d8e4a3cff49c8417a
Author:     Alexander Leidinger <netchild@FreeBSD.org>
AuthorDate: 2026-07-19 07:38:52 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2026-08-03 17:31:02 +0000

    hwpmc: handle counter wraparound for process-mode counting PMCs
    
    The accumulated count of a process-mode counting PMC is kept in a
    64-bit software counter and seeded into the hardware counter at every
    context switch in.  Hardware counters are narrower than that - each
    PMC class discovers and records its own counter width, e.g. 48 bits
    on current x86 (queried from CPUID on Intel, architectural on AMD) -
    so once the accumulated count approaches the end of the hardware
    counter range, the counter wraps during a time slice and the value
    read back at switch out is smaller than the value seeded.  The
    increment was computed assuming a full 64-bit counter: on INVARIANTS
    kernels a long enough counting run panics with "negative increment"
    the moment the accumulated count first crosses the hardware counter
    range, and on other kernels the totals silently lose a full counter
    range per wrap.
    
    Compute the increment modulo the per-class hardware counter width
    instead, in both places that accumulate switch-out deltas.
    
    Reviewed by:            adrian
    MFC after:              2 weeks
    Assisted-by:            Claude Code (Fable 5)
    Differential Revision:  https://reviews.freebsd.org/D58340
    
    (cherry picked from commit e42703f5c4b2d3a869b17e2cb8670f1b6359c8cf)
---
 sys/dev/hwpmc/hwpmc_mod.c | 46 ++++++++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index 54fcc2dafb4f..3ca5540b9623 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -1592,6 +1592,24 @@ pmc_process_csw_in(struct thread *td)
 	critical_exit();
 }
 
+/*
+ * Compute the change in a counter's value since it was last written.
+ * The hardware counter is only pcd_width bits wide and wraps around,
+ * while the value seeded into it may occupy the full 64-bit range, so
+ * take the difference modulo the counter width.
+ */
+static pmc_value_t
+pmc_delta(const struct pmc_classdep *pcd, pmc_value_t newvalue,
+    pmc_value_t oldvalue)
+{
+	pmc_value_t delta;
+
+	delta = newvalue - oldvalue;
+	if (pcd->pcd_width < 64)
+		delta &= ((pmc_value_t)1 << pcd->pcd_width) - 1;
+	return (delta);
+}
+
 /*
  * Thread context switch OUT.
  */
@@ -1604,8 +1622,7 @@ pmc_process_csw_out(struct thread *td)
 	struct pmc_process *pp;
 	struct pmc_thread *pt = NULL;
 	struct proc *p;
-	pmc_value_t newvalue;
-	int64_t tmp;
+	pmc_value_t newvalue, tmp;
 	enum pmc_mode mode;
 	int cpu;
 	u_int adjri, ri;
@@ -1743,23 +1760,19 @@ pmc_process_csw_out(struct thread *td)
 				}
 				mtx_pool_unlock_spin(pmc_mtxpool, pm);
 			} else {
-				tmp = newvalue - PMC_PCPU_SAVED(cpu, ri);
+				/*
+				 * For counting process-virtual PMCs, the
+				 * hardware counter's value increases
+				 * monotonically modulo the counter width;
+				 * pmc_delta() recovers the increment even
+				 * when the counter wrapped during the run.
+				 */
+				tmp = pmc_delta(pcd, newvalue,
+				    PMC_PCPU_SAVED(cpu, ri));
 
 				PMCDBG3(CSW,SWO,1,"cpu=%d ri=%d tmp=%jd (count)",
 				    cpu, ri, tmp);
 
-				/*
-				 * For counting process-virtual PMCs,
-				 * we expect the count to be
-				 * increasing monotonically, modulo a 64
-				 * bit wraparound.
-				 */
-				KASSERT(tmp >= 0,
-				    ("[pmc,%d] negative increment cpu=%d "
-				     "ri=%d newvalue=%jx saved=%jx "
-				     "incr=%jx", __LINE__, cpu, ri,
-				     newvalue, PMC_PCPU_SAVED(cpu, ri), tmp));
-
 				mtx_pool_lock_spin(pmc_mtxpool, pm);
 				pm->pm_gv.pm_savedvalue += tmp;
 				pp->pp_pmcs[ri].pp_pmcval += tmp;
@@ -5070,7 +5083,8 @@ pmc_process_exit(void *arg __unused, struct proc *p)
 				if (PMC_TO_MODE(pm) == PMC_MODE_TC) {
 					pcd->pcd_read_pmc(cpu, adjri, pm,
 					    &newvalue);
-					tmp = newvalue - PMC_PCPU_SAVED(cpu, ri);
+					tmp = pmc_delta(pcd, newvalue,
+					    PMC_PCPU_SAVED(cpu, ri));
 
 					mtx_pool_lock_spin(pmc_mtxpool, pm);
 					pm->pm_gv.pm_savedvalue += tmp;

From nobody Mon Aug  3 17:31:16 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDNxw4Vprz6mbwt
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 17:31:16 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDNxw1Xy2z3n80
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:31:16 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785778276;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ytC1Ey0XCvVh8QlhS+oynPmdCjdG+fL0pKKJR2G3i30=;
	b=WCSzDMAtRhh5P0jodpD7cyrSfc+nrYQBlx3L5aZ+O+dU63yTEb/NcjYILLp9eV/ElDnrcI
	tOKRHduWKUfQirL2xYlAe9hQzcXFwVlXcbRrqmR9tEyew32zJ9pYx7Qon/ynJUT9pDT7k9
	Of/UYFeWCnp+yQec1H8QGSPb8rrKb4cVx4QsN32BhIz5bwWJv0SLngR3aRUu8akndXofQE
	DA57pUtFqRYQq6xA/xpjCPdwIYiKuMgS5ytVdCwXVtyaIqNB2IGezfbKllxYa9BNcdZEr9
	mUqc/4YCo1fb1pFlYW3eVj/UqxV5oZBLnRb3BdyEpI+s4QRTrWLi/G1/pyd8Cw==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785778276; a=rsa-sha256; cv=none;
	b=ABlR8oEUF7KI0n0oLdKQDvBg5zEDvKkjuYIZPe1Nsgw4Dm8Y5nfFGsTovUaa11oLVb3ZJ4
	0U9QGOQ0y1M1PDgz4jShXrkw0lIVSifZAfasMifiU9xpgTKKU5nNPk2Of0WbDUkw2lcjKZ
	Q23xzrNGZ5hzA1pPJ2Zt0OkI7Q6OEBXzSWcw52jEytI7J8kwndzlryQQ+0Q078MELbuL7k
	c7mZNblGJg9h375RIdeliNzUZOWn4G4+Megn4xEk+deNZjCBriNZgXBEUwHXQyVLnLwKmR
	QYX6GLRPaZDEQ1E9w3irTUKb/1SWIm7H/7DBXt0jc0Bp3C1CvaCpata2VhgF1g==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785778276;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ytC1Ey0XCvVh8QlhS+oynPmdCjdG+fL0pKKJR2G3i30=;
	b=RxrGNhs2vaQszSRcElTINx4SexHkWFuDrw3FHAJrq3Jys/Zr0HYmhnBN65QT1XTtoOQQp9
	pV9WKIgxou3a+pxCW4JT9CLm+ITYfYu/mot3xJ5KKhk3DU70Mm6XbD/TsDMHeI9o9oTdeL
	0Ybh9uVwTP1301qTWuqQSUr3bxwEbF1DmExDdaafye3SHSOECgpVk3IoPinawMPw+dQcFy
	FgoRsp8vQeTeq28GKjkPisFs6hmfjsvuqcMkijwm2O32+gftqqGv4ZkWAsGHmKuL62IhGX
	ig2CGurRhyHPMajZpvVYsl0aCWvebTIC3j3MFYLSODam5Gk635iKUY90klvWHQ==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDNxw0ZGnz19H6
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:31:16 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 19281
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 17:31:16 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Alexander Leidinger <netchild@FreeBSD.org>
Subject: git: ac3d63e50862 - stable/14 - hwpmc: add regression tests for counting-PMC counter wraparound
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: netchild
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: ac3d63e50862b6031feb839932c88b1a4c5a5c1f
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 17:31:16 +0000
Message-Id: <6a70d064.19281.710d0c08@gitrepo.freebsd.org>

The branch stable/14 has been updated by netchild:

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

commit ac3d63e50862b6031feb839932c88b1a4c5a5c1f
Author:     Alexander Leidinger <netchild@FreeBSD.org>
AuthorDate: 2026-07-19 08:08:48 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2026-08-03 17:31:02 +0000

    hwpmc: add regression tests for counting-PMC counter wraparound
    
    Exercise a process-mode counting PMC whose accumulated count crosses,
    or already exceeds, the range of the underlying hardware counter.
    Before the previous commit, the first context switch after the
    hardware counter wrapped panicked INVARIANTS kernels with "negative
    increment" and silently corrupted the accumulated count on other
    kernels.
    
    The tests need a hardware counting event backed by a counter narrower
    than 64 bits and skip where none is available (hwpmc(4) not loaded,
    or a VM without a vPMU).
    
    Reviewed by:            adrian
    MFC after:              2 weeks
    Assisted-by:            Claude Code (Fable 5)
    Differential Revision:  https://reviews.freebsd.org/D58341
    
    (cherry picked from commit 2cfd82f747c04f68f679824ba627460e87ab3848)
---
 etc/mtree/BSD.tests.dist      |   2 +
 tests/sys/Makefile            |   1 +
 tests/sys/pmc/Makefile        |   7 ++
 tests/sys/pmc/pmc_wrap_test.c | 216 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 226 insertions(+)

diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index 1df5af7dccf4..41944b275fcc 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -923,6 +923,8 @@
             utimensat
             ..
         ..
+        pmc
+        ..
         posixshm
         ..
         sound
diff --git a/tests/sys/Makefile b/tests/sys/Makefile
index 8fa5844fc47b..7b7a97fd1359 100644
--- a/tests/sys/Makefile
+++ b/tests/sys/Makefile
@@ -30,6 +30,7 @@ TESTS_SUBDIRS+=		netlink
 TESTS_SUBDIRS+=		netmap
 TESTS_SUBDIRS+=		netpfil
 TESTS_SUBDIRS+=		opencrypto
+TESTS_SUBDIRS+=		pmc
 TESTS_SUBDIRS+=		posixshm
 TESTS_SUBDIRS+=		ses
 TESTS_SUBDIRS+=		sound
diff --git a/tests/sys/pmc/Makefile b/tests/sys/pmc/Makefile
new file mode 100644
index 000000000000..403acd0311ce
--- /dev/null
+++ b/tests/sys/pmc/Makefile
@@ -0,0 +1,7 @@
+TESTSDIR=	${TESTSBASE}/sys/pmc
+
+ATF_TESTS_C=	pmc_wrap_test
+
+LIBADD+=	pmc
+
+.include <bsd.test.mk>
diff --git a/tests/sys/pmc/pmc_wrap_test.c b/tests/sys/pmc/pmc_wrap_test.c
new file mode 100644
index 000000000000..58e7b3ef416a
--- /dev/null
+++ b/tests/sys/pmc/pmc_wrap_test.c
@@ -0,0 +1,216 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 Alexander Leidinger <netchild@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other advertising materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Regression tests for process-mode counting PMCs whose accumulated
+ * count is close to, or beyond, the range of the underlying hardware
+ * counter.  Hardware counters are narrower than the 64-bit software
+ * counter (48 bits on modern x86), and the increment collected when a
+ * counter is read out (at context switch and at process exit) must be
+ * computed modulo the hardware width.
+ *
+ * Before the fix these tests panicked INVARIANTS kernels with
+ * "[pmc,...] negative increment" once the hardware counter wrapped,
+ * and silently corrupted the accumulated count on other kernels.
+ *
+ * The counter is attached to a short-lived child process which spins
+ * to advance it; the child exits before the PMC is released, so the
+ * accounting is torn down cleanly (the accumulation is collected on
+ * the exit path, which is one of the two sites the fix touches).
+ *
+ * The tests need a hardware counting event whose counter is narrower
+ * than 64 bits; they skip on systems without one (e.g. VMs without a
+ * vPMU, or with hwpmc(4) not loaded).
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <errno.h>
+#include <pmc.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+/*
+ * High-rate events; at least one of these should be allocatable on
+ * any x86 or arm64 system with a vPMU.  All of them count while the
+ * child's spin loop runs.
+ */
+static const char *wrap_test_events[] = {
+	"instructions",
+	"cycles",
+	"branches",
+	"unhalted-core-cycles",
+	"inst_retired.any",
+	"cpu_clk_unhalted.thread",
+	"ls_not_halted_cyc",
+	NULL
+};
+
+/* The child generates well more than this many events past the seed. */
+#define	WRAP_MARGIN	((uint64_t)1 << 20)
+
+/* Spin iterations: comfortably more than WRAP_MARGIN events, still < 1s. */
+#define	SPIN_ITERS	((uint64_t)200 * 1000 * 1000)
+
+/* Upper bound on events a single test run can plausibly generate. */
+#define	SANITY_BOUND	((uint64_t)1 << 40)
+
+/*
+ * Child: wait for the parent to start the PMC (one byte on the pipe),
+ * spin to advance the counter across the end of its range, then exit.
+ */
+static void __attribute__((noinline))
+child_spin(int startfd)
+{
+	volatile uint64_t sink = 0;
+	uint64_t i;
+	char c;
+
+	(void)read(startfd, &c, 1);
+	for (i = 0; i < SPIN_ITERS; i++)
+		sink += i;
+	_exit((int)(sink & 0x7f));
+}
+
+/*
+ * Allocate a process-mode counting PMC for the first available event
+ * backed by a counter narrower than 64 bits, attach it to a child,
+ * seed it with the given value, let the child spin past the end of
+ * the counter range, and check that the accumulated count stayed sane.
+ */
+static void
+wrap_test(bool seed_beyond_width)
+{
+	pmc_id_t pmcid;
+	pmc_value_t final;
+	uint64_t seed;
+	uint32_t width;
+	pid_t child;
+	int i, pfd[2], status;
+
+	if (pmc_init() != 0)
+		atf_tc_skip("hwpmc(4) is not available: %s", strerror(errno));
+
+	width = 0;
+	pmcid = PMC_ID_INVALID;
+	for (i = 0; wrap_test_events[i] != NULL; i++) {
+		if (pmc_allocate(wrap_test_events[i], PMC_MODE_TC, 0,
+		    PMC_CPU_ANY, &pmcid, 0) != 0)
+			continue;
+		ATF_REQUIRE(pmc_width(pmcid, &width) == 0);
+		if (width >= 32 && width < 64)
+			break;
+		ATF_REQUIRE(pmc_release(pmcid) == 0);
+		pmcid = PMC_ID_INVALID;
+	}
+	if (pmcid == PMC_ID_INVALID)
+		atf_tc_skip("no allocatable counting event with a hardware "
+		    "counter narrower than 64 bits");
+
+	if (seed_beyond_width) {
+		/* Accumulated count that no longer fits the counter at all. */
+		seed = ((uint64_t)1 << width) + 12345;
+	} else {
+		/* Just below the end of the counter range; the child crosses it. */
+		seed = ((uint64_t)1 << width) - WRAP_MARGIN;
+	}
+
+	ATF_REQUIRE(pipe(pfd) == 0);
+	child = fork();
+	ATF_REQUIRE(child >= 0);
+	if (child == 0) {
+		close(pfd[1]);
+		child_spin(pfd[0]);
+		/* NOTREACHED */
+	}
+	close(pfd[0]);
+
+	ATF_REQUIRE(pmc_attach(pmcid, child) == 0);
+	ATF_REQUIRE(pmc_write(pmcid, seed) == 0);
+	ATF_REQUIRE(pmc_start(pmcid) == 0);
+
+	/* Release the child, which spins and exits. */
+	ATF_REQUIRE(write(pfd[1], "g", 1) == 1);
+	close(pfd[1]);
+	ATF_REQUIRE(waitpid(child, &status, 0) == child);
+
+	/*
+	 * The child is gone: its final increment was collected on the
+	 * exit path.  Read the accumulated 64-bit count and stop.
+	 */
+	ATF_REQUIRE(pmc_read(pmcid, &final) == 0);
+	(void)pmc_stop(pmcid);
+
+	ATF_CHECK_MSG(final >= seed,
+	    "accumulated count went backwards: seed 0x%jx, final 0x%jx "
+	    "(width %u)", (uintmax_t)seed, (uintmax_t)final, width);
+	ATF_CHECK_MSG(final - seed < SANITY_BOUND,
+	    "accumulated count jumped implausibly: seed 0x%jx, final 0x%jx "
+	    "(width %u)", (uintmax_t)seed, (uintmax_t)final, width);
+
+	ATF_REQUIRE(pmc_release(pmcid) == 0);
+}
+
+ATF_TC(counting_pmc_wraps_hardware_counter);
+ATF_TC_HEAD(counting_pmc_wraps_hardware_counter, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "A process-mode counting PMC survives its hardware counter "
+	    "wrapping around while the counted process runs");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(counting_pmc_wraps_hardware_counter, tc)
+{
+	wrap_test(false);
+}
+
+ATF_TC(counting_pmc_beyond_hardware_width);
+ATF_TC_HEAD(counting_pmc_beyond_hardware_width, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "A process-mode counting PMC keeps counting correctly once "
+	    "its accumulated count exceeds the hardware counter range");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(counting_pmc_beyond_hardware_width, tc)
+{
+	wrap_test(true);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, counting_pmc_wraps_hardware_counter);
+	ATF_TP_ADD_TC(tp, counting_pmc_beyond_hardware_width);
+
+	return (atf_no_error());
+}

From nobody Mon Aug  3 17:31:17 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDNxx5YXMz6mbx1
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 17:31:17 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDNxx2LF1z3mvn
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:31:17 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785778277;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=B3RlzcAINuzZsG2Mc3KS8qadZ9Yl8kwzCe99+Gv+/uM=;
	b=i57OnbaffBeYK+T6dfVJna09q7nAPk2Kmpo4RfMb8eEDW+0Hlwolvel4uSiVfQwX6r/ylM
	+0ovmvmaB+RVxQ+T5TWjIjfngLNmQP5jiNjeA5Nb2GNTWMYpIF514ksGhbcXBe6dXP2VD+
	OD8TcTItGid0NR6jQlauaIWIGRNV56d+Tqm/9/zeu/HCT0DIdVKiAzIZUYZKVpaVttgGeP
	5w6KKXiGmX824/5iRPn68i9kTG2wZUhGPP6UYHOAAjVSu/0/3P2lQBPhiKUbOFozMNY8Gk
	YF+r++Lf8JnrpKhltL0PnNuv6EG86hQ/gA00Kg++gjOtBEV+TBJNZg1a0YJoNA==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785778277; a=rsa-sha256; cv=none;
	b=mFHOGAND1JxUn86k9CnOfFjTxcMEBBoEMtHCiIErSmCF7pPtL0vwlTjgWLrNca3w1m6sz2
	osdNK82A1hP4pqNOYqWp/uObonaHhcyY8WS+0Ws2anHGR+2yVaFZ0WqzuuUcyvamYM8Evq
	mGMkEV9fQMO3xGvT9rTKDdIn/FyUTFbPz97a35rk7kd+9kaUcxz3NTeoFOaVVTm1jDTyVb
	PhFBBDkm6UE/1kYcOfgcgptMgBdr3EiDprr1xnlddvolXaG0+vjrUpl+/N2jqG4BhRQGfg
	JjdexadfJcHnkHdIGBqq5Sfg7LQ1x0XjmK8WfeBGlsb3WVBO9sndPBGVG+mJZg==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785778277;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=B3RlzcAINuzZsG2Mc3KS8qadZ9Yl8kwzCe99+Gv+/uM=;
	b=YUV91yWhCBUAcPL+u7+au715ogMolq0pWXbEIrUPzE6euK6zHTOiApztK96tOvYXenJDlI
	e5dwO152GnddynPHqqoDZj7GjtdA5kncpLT5XcxgqHLj4OEbPg19lShbSEqyq4MJyeJ+Ci
	N4icms1nqosDzZ54YzMJB1mhJ6Fn46eMvipLcc41TaK4AL4CkR7eQGZSoNZ67i9IJMKF+q
	9uVMV5GNcizK8GDz+tLWqkIcEW2k/8dsCUrB3+cE6UUbJHDMMXLmDThl+4fG2BOVNACCtw
	SXV+QUxQQ5YQJJqHs9inNi27TvWfvnMKy8X4ZTe7DuBMZCpKcOUEHFf73OZ3Ig==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDNxx15Dtz19H8
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:31:17 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 19680
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 17:31:17 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Alexander Leidinger <netchild@FreeBSD.org>
Subject: git: 34afb930b25e - stable/14 - hwpmc: drain a process-mode PMC's runcount when a live target detaches
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: netchild
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 34afb930b25e9469424166146533f7a32359cfc0
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 17:31:17 +0000
Message-Id: <6a70d065.19680.1c9353c3@gitrepo.freebsd.org>

The branch stable/14 has been updated by netchild:

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

commit 34afb930b25e9469424166146533f7a32359cfc0
Author:     Alexander Leidinger <netchild@FreeBSD.org>
AuthorDate: 2026-07-19 11:39:27 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2026-08-03 17:31:03 +0000

    hwpmc: drain a process-mode PMC's runcount when a live target detaches
    
    A process-mode PMC's runcount tracks how many CPUs currently have it
    loaded in hardware.  It is decremented only by the context-switch-out
    and process-exit reclaim paths, both of which the scheduler invokes
    only for processes flagged P_HWPMC.  Detaching a target that still has
    the PMC live in hardware dropped the target and cleared P_HWPMC without
    taking the PMC off the hardware or dropping the runcount reference, so
    the reference leaked.  A subsequent release then spun in
    pmc_wait_for_pmc_idle() forever waiting for the runcount to reach zero:
    on an INVARIANTS kernel this panics ("waiting too long for pmc to be
    free"), otherwise it is an unkillable loop holding the hwpmc lock.  Any
    process able to allocate a PMC can trigger this by attaching a counting
    PMC to itself and detaching it before releasing.
    
    Take the PMC off the hardware and drop the runcount reference as part
    of detaching, before P_HWPMC is cleared: reclaim it from the detaching
    thread's own CPU directly, and, when the detach removes the PMC's last
    target, wait for any references held by the target's other threads to
    drain while P_HWPMC is still set (they can no longer reload it).
    
    Reviewed by:            adrian
    MFC after:              2 weeks
    Assisted-by:            Claude Code (Fable 5)
    Differential Revision:  https://reviews.freebsd.org/D58342
    
    (cherry picked from commit 86fa065f1862f3b638efa1868523878d9db14ada)
---
 sys/dev/hwpmc/hwpmc_mod.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index 3ca5540b9623..916b86c4d0e8 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -221,6 +221,8 @@ static int	pmc_detach_one_process(struct proc *p, struct pmc *pm,
 static void	pmc_destroy_owner_descriptor(struct pmc_owner *po);
 static void	pmc_destroy_pmc_descriptor(struct pmc *pm);
 static void	pmc_destroy_process_descriptor(struct pmc_process *pp);
+static void	pmc_reclaim_pmc_from_cpu(struct pmc *pm,
+    struct pmc_process *pp, int cpu);
 static struct pmc_owner *pmc_find_owner_descriptor(struct proc *p);
 static int	pmc_find_pmc(pmc_id_t pmcid, struct pmc **pm);
 static struct pmc *pmc_find_pmc_descriptor_in_process(struct pmc_owner *po,
@@ -1239,6 +1241,21 @@ pmc_detach_one_process(struct proc *p, struct pmc *pm, int flags)
 	if (pp->pp_pmcs[ri].pp_pmc != pm)
 		return (EINVAL);
 
+	/*
+	 * If this is a process-virtual PMC that is still loaded on the
+	 * hardware of the CPU we are running on (the common case when a
+	 * process detaches a PMC from itself), take it off and drop its
+	 * runcount reference now.  The reference is otherwise only
+	 * dropped by the switch-out reclaim, which the scheduler stops
+	 * calling once P_HWPMC is cleared below - leaking it and later
+	 * wedging pmc_wait_for_pmc_idle() at release time.
+	 */
+	if (PMC_IS_VIRTUAL_MODE(PMC_TO_MODE(pm))) {
+		critical_enter();
+		pmc_reclaim_pmc_from_cpu(pm, pp, curthread->td_oncpu);
+		critical_exit();
+	}
+
 	pmc_unlink_target_process(pm, pp);
 
 	/* Issue a detach entry if a log file is configured */
@@ -1257,6 +1274,22 @@ pmc_detach_one_process(struct proc *p, struct pmc *pm, int flags)
 	if (pp->pp_refcnt != 0)	/* still a target of some PMC */
 		return (0);
 
+	/*
+	 * This detach removed the process' last PMC and we are about to
+	 * clear P_HWPMC.  If the detached PMC was its last target and is
+	 * still loaded on other CPUs (e.g. sibling threads of a
+	 * multi-threaded target, or a target running on another CPU),
+	 * drain those references first: the target is already unlinked so
+	 * it cannot reload the PMC, and P_HWPMC is still set so those
+	 * CPUs' switch-out reclaim still runs.  Bounded by the target
+	 * threads being scheduled out.
+	 */
+	if (PMC_IS_VIRTUAL_MODE(PMC_TO_MODE(pm)) &&
+	    LIST_EMPTY(&pm->pm_targets)) {
+		while (counter_u64_fetch(pm->pm_runcount) > 0)
+			pmc_force_context_switch();
+	}
+
 	pmc_remove_process_descriptor(pp);
 
 	if (flags & PMC_FLAG_REMOVE)
@@ -1610,6 +1643,61 @@ pmc_delta(const struct pmc_classdep *pcd, pmc_value_t newvalue,
 	return (delta);
 }
 
+/*
+ * Take a process-virtual PMC off the hardware of 'cpu' if it is
+ * currently loaded there for process 'pp', accumulating its final
+ * count and dropping its runcount reference.  This is the same reclaim
+ * that context switch out and process exit perform, factored out so it
+ * can also run when a target is detached while the PMC may still be
+ * live: the runcount reference is decremented by the switch-out reclaim
+ * only, which the scheduler gates on P_HWPMC, so a detach that clears
+ * P_HWPMC without draining would leak the reference and later wedge
+ * pmc_wait_for_pmc_idle().  Must be called in a critical section.
+ */
+static void
+pmc_reclaim_pmc_from_cpu(struct pmc *pm, struct pmc_process *pp, int cpu)
+{
+	struct pmc_classdep *pcd;
+	struct pmc *phw_pm;
+	pmc_value_t newvalue, tmp;
+	u_int adjri, ri;
+
+	ri = PMC_TO_ROWINDEX(pm);
+	pcd = pmc_ri_to_classdep(md, ri, &adjri);
+
+	/* Only reclaim if this PMC is actually loaded on this CPU. */
+	phw_pm = NULL;
+	(void)(*pcd->pcd_get_config)(cpu, adjri, &phw_pm);
+	if (phw_pm != pm)
+		return;
+
+	KASSERT(counter_u64_fetch(pm->pm_runcount) > 0,
+	    ("[pmc,%d] pm=%p runcount %ju", __LINE__, pm,
+	    (uintmax_t)counter_u64_fetch(pm->pm_runcount)));
+
+	if (pm->pm_pcpu_state[cpu].pps_cpustate) {
+		pm->pm_pcpu_state[cpu].pps_cpustate = 0;
+		if (pm->pm_pcpu_state[cpu].pps_stalled == 0) {
+			(void)pcd->pcd_stop_pmc(cpu, adjri, pm);
+
+			if (PMC_TO_MODE(pm) == PMC_MODE_TC) {
+				(void)pcd->pcd_read_pmc(cpu, adjri, pm,
+				    &newvalue);
+				tmp = pmc_delta(pcd, newvalue,
+				    PMC_PCPU_SAVED(cpu, ri));
+
+				mtx_pool_lock_spin(pmc_mtxpool, pm);
+				pm->pm_gv.pm_savedvalue += tmp;
+				pp->pp_pmcs[ri].pp_pmcval += tmp;
+				mtx_pool_unlock_spin(pmc_mtxpool, pm);
+			}
+		}
+	}
+
+	counter_u64_add(pm->pm_runcount, -1);
+	(void)pcd->pcd_config_pmc(cpu, adjri, NULL);
+}
+
 /*
  * Thread context switch OUT.
  */

From nobody Mon Aug  3 17:31:18 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDNxy4Dcmz6mc2X
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 17:31:18 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDNxy2tYzz3nSn
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:31:18 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785778278;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ud5WWf34UEtynwVPdR+kxaFD79AARvIFxq6uCHJCPF4=;
	b=HpfkiKap2yrbufMQwxNJGrBTckzjayASH0F65KivjnG3apkVLHY5hWNZp2T+5gkLxQUShN
	azR9om884rtG/m+xkHHZpWmeYPbb0QDcYl4DLmhdCb10/hw417cwcHty9AuMWmzV5Spegm
	ND+MP7w0CVmIUukzFU4v+a4GCegAuTajsIKNpqp9dgc/b3ZWrSJ/a7Y5k9XSeFuVhc9URc
	al7mBWc8AOMfUNCfD0uLwxqOl+PRPiqxLnlUVgRGI6Spf+rsUeuHIPo58ls9xlTPSo5t2u
	KPOuLpG2OeEKTFUi+oaKk+Jw/VGv/nVzB5MZwphH5tQGYBnajaKLcl2ybennFA==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785778278; a=rsa-sha256; cv=none;
	b=Oz8CEv00ZPQLORwMtvf6MZZt2bZrA5dMSKiR2QmUzKjVAygA0re9z0mMeNKoZHK3hStKAG
	zbfwoq6q9u1t4YkIUmMxMG1BRnvzWKPSdgWYomQUo0dkJkGbRWQxCtnWZNz5T5T7H2wfyk
	Lj6w0eUGgaMRRHw2i99bHKce+uOx6ciDdYsU4Lrz6JRjzMhQtqyGH8CzRCJe3Zub6U2I9R
	jIsyoQ/sN1wtqmtIJbSfsMr59vWIIog/l/A6gom6GBiC/VLtVe3d6pSBjxUgY3QMBAYqCV
	Rwqd0y9qvYW9MtrQRzxHy/SbZQEVN5imyfw/UZu4a95NxWXT51bPQZjFczwR7Q==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785778278;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ud5WWf34UEtynwVPdR+kxaFD79AARvIFxq6uCHJCPF4=;
	b=GGKIQ6npyPykwgiQ4mnc2leKVPUZfFe8LvI81p/5AlcdXIuNofVrNWH2s4ZgRTgZnjJsrD
	uL0OyxYpilGCJLnbt1gmXGFx8qmt1aJfvEaYydEePF0KFBquVbdUXkOcECKUUdQNakFSuL
	ePgdLQUnNlHfsm5UHJ153mlSjrrZ3VM7EKFpy0jmVR/DzA6LXRXygGVBv+0ug5zgrrKD/A
	TuGnfK+Q3YRPRLCatxIKoMn5Q3dShN0tWdwWLdLY+vBS40603mL6KYYZXswm0T7GIRcL/m
	jSoYRGqAsoRzTRXvl300HKGUgYXzFcEl2ptMKlkOX9zTNCQDWf17eWW30t/YMw==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDNxy1y3lz195p
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:31:18 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 18c9f
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 17:31:18 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
From: Alexander Leidinger <netchild@FreeBSD.org>
Subject: git: 6d85b0a8761f - stable/14 - hwpmc: add regression tests for detaching a live process-mode PMC
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: netchild
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 6d85b0a8761fcd8ca838ecf408a796885569ddac
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 17:31:18 +0000
Message-Id: <6a70d066.18c9f.1ef8b6b4@gitrepo.freebsd.org>

The branch stable/14 has been updated by netchild:

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

commit 6d85b0a8761fcd8ca838ecf408a796885569ddac
Author:     Alexander Leidinger <netchild@FreeBSD.org>
AuthorDate: 2026-07-19 12:15:20 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2026-08-03 17:31:03 +0000

    hwpmc: add regression tests for detaching a live process-mode PMC
    
    Attach a process-mode counting PMC to the current process, start it,
    then detach and release it while it is still loaded on the hardware -
    the case that previously leaked the PMC's runcount reference and
    wedged pmc_wait_for_pmc_idle() at release.  A second case does the same
    from a multi-threaded process so the sibling threads' references have
    to be drained too.
    
    The tests need an allocatable process-mode counting event and skip
    where none is available (hwpmc(4) not loaded, or a VM without a vPMU).
    
    Reviewed by:            adrian
    MFC after:              2 weeks
    Assisted-by:            Claude Code (Fable 5)
    Differential Revision:  https://reviews.freebsd.org/D58343
    
    (cherry picked from commit 3c3f886e4bc7619f7847ad0d0f996088ddf5915a)
---
 tests/sys/pmc/Makefile          |   2 +
 tests/sys/pmc/pmc_detach_test.c | 178 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 180 insertions(+)

diff --git a/tests/sys/pmc/Makefile b/tests/sys/pmc/Makefile
index 403acd0311ce..305a3e65c8b3 100644
--- a/tests/sys/pmc/Makefile
+++ b/tests/sys/pmc/Makefile
@@ -1,7 +1,9 @@
 TESTSDIR=	${TESTSBASE}/sys/pmc
 
 ATF_TESTS_C=	pmc_wrap_test
+ATF_TESTS_C+=	pmc_detach_test
 
 LIBADD+=	pmc
+LIBADD.pmc_detach_test+=	pthread
 
 .include <bsd.test.mk>
diff --git a/tests/sys/pmc/pmc_detach_test.c b/tests/sys/pmc/pmc_detach_test.c
new file mode 100644
index 000000000000..05fda61b2836
--- /dev/null
+++ b/tests/sys/pmc/pmc_detach_test.c
@@ -0,0 +1,178 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 Alexander Leidinger <netchild@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other advertising materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Regression tests for detaching a process-mode PMC from a target that
+ * still has it loaded on hardware.  The runcount reference for a live
+ * PMC is dropped only by the context-switch-out reclaim, which the
+ * scheduler gates on P_HWPMC; detaching used to clear P_HWPMC without
+ * draining the reference, so the following release spun forever in
+ * pmc_wait_for_pmc_idle() - a panic ("waiting too long for pmc to be
+ * free") on an INVARIANTS kernel, an unkillable loop holding the hwpmc
+ * lock otherwise.
+ *
+ * The failure is deterministic: attaching a counting PMC to the current
+ * (running) thread and detaching it before release always left the
+ * reference live.  On a kernel that carries the fix these tests complete
+ * immediately; run against a kernel that lacks it they would wedge, so
+ * (like any hwpmc regression test) they ship alongside the fix.
+ *
+ * They need an allocatable process-mode counting event, and skip where
+ * none is available (hwpmc(4) not loaded, or a VM without a vPMU).
+ */
+
+#include <sys/types.h>
+
+#include <errno.h>
+#include <pmc.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static const char *counting_events[] = {
+	"instructions",
+	"cycles",
+	"branches",
+	"unhalted-core-cycles",
+	"inst_retired.any",
+	"cpu_clk_unhalted.thread",
+	"ls_not_halted_cyc",
+	NULL
+};
+
+static volatile int spin_stop;
+
+static void *
+spinner(void *arg __unused)
+{
+	volatile unsigned long s = 0;
+
+	while (spin_stop == 0)
+		s += 1;
+	return (NULL);
+}
+
+static void
+burn_cpu(void)
+{
+	volatile unsigned long s = 0;
+	int i;
+
+	for (i = 0; i < 1000000; i++)
+		s += i;
+}
+
+/* Allocate the first available process-mode counting PMC, or skip. */
+static pmc_id_t
+alloc_counting_pmc(void)
+{
+	pmc_id_t id;
+	int i;
+
+	if (pmc_init() != 0)
+		atf_tc_skip("hwpmc(4) is not available: %s", strerror(errno));
+
+	for (i = 0; counting_events[i] != NULL; i++) {
+		id = PMC_ID_INVALID;
+		if (pmc_allocate(counting_events[i], PMC_MODE_TC, 0,
+		    PMC_CPU_ANY, &id, 0) == 0)
+			return (id);
+	}
+	atf_tc_skip("no allocatable process-mode counting event "
+	    "(no vPMU?)");
+	return (PMC_ID_INVALID); /* not reached */
+}
+
+ATF_TC(detach_live_self);
+ATF_TC_HEAD(detach_live_self, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Detaching a running counting PMC from the current thread and "
+	    "then releasing it does not leak its runcount reference");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(detach_live_self, tc)
+{
+	pmc_id_t id;
+
+	id = alloc_counting_pmc();
+
+	ATF_REQUIRE(pmc_attach(id, 0) == 0);	/* 0 == current process */
+	ATF_REQUIRE(pmc_start(id) == 0);
+	burn_cpu();				/* make the counter live */
+
+	/* Detach while still loaded on this CPU, then release. */
+	ATF_REQUIRE(pmc_detach(id, 0) == 0);
+	ATF_REQUIRE(pmc_release(id) == 0);	/* wedged before the fix */
+}
+
+ATF_TC(detach_live_multithread);
+ATF_TC_HEAD(detach_live_multithread, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Detaching a running process-scope counting PMC drains the "
+	    "references held by the process' other threads");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(detach_live_multithread, tc)
+{
+	pthread_t th[3];
+	pmc_id_t id;
+	int i, n;
+
+	id = alloc_counting_pmc();
+
+	/* Sibling threads keep the process-scope PMC live on other CPUs. */
+	spin_stop = 0;
+	for (n = 0; n < 3; n++)
+		ATF_REQUIRE(pthread_create(&th[n], NULL, spinner, NULL) == 0);
+
+	ATF_REQUIRE(pmc_attach(id, 0) == 0);
+	ATF_REQUIRE(pmc_start(id) == 0);
+	burn_cpu();
+	/* Let the siblings be scheduled and pick up the PMC. */
+	usleep(200 * 1000);
+
+	ATF_REQUIRE(pmc_detach(id, 0) == 0);
+	ATF_REQUIRE(pmc_release(id) == 0);	/* must drain the siblings */
+
+	spin_stop = 1;
+	for (i = 0; i < n; i++)
+		pthread_join(th[i], NULL);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, detach_live_self);
+	ATF_TP_ADD_TC(tp, detach_live_multithread);
+
+	return (atf_no_error());
+}

From nobody Mon Aug  3 17:31:19 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDNy00GDXz6mcH4
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 17:31:20 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDNxz5QqPz3nT7
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:31:19 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785778279;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=5T1uVXaFVSzneCNXHdK4h65FwS/fp1U3JNzpOu/gg1E=;
	b=gSPgCtIdkshHTQ3aj9cINXFaVsKSnB+qurt/2vGm2S/2mXc2cdvuCoIXSHXXpdSesTMHtm
	6u3uhizxKqvJ9k+GVasYx/ygyW7Gb01oF8++8QiCi2ekrCz5CXN/NuSaUHJ0ATU2tnmP8d
	cfYnzHYiEDUEI/xKqGo7lVz+CGyhgq384m9cUDcFRN2AiRMs2D9gBWibtOr/GZ+JAH5WyX
	g+Wzjmxoi0EhlUGt97CyA6vL8TQfDFGslaGgHnBbiqUN6Mg0oifReZ0tM6GWiloyLMsSsC
	CbM2K8S9Y9axMuiJF54pyUKov3A7TC1eB8T44S0VQBGT/O4gC01UDVUDzXadnA==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785778279; a=rsa-sha256; cv=none;
	b=XZ/4AWsrUuxQaGQskTdSs9ETgxJ9RX+eHQXbAC4eY5uQW5hySKRoQL2yAaw6qgKoFpKVtG
	DxSm70W9BSayHBZaJlqvQDFRUDRRJIi+9jaiecR/5/kv+FC2NNf/aEdtn6PJFEGkz6asC4
	sd4KUN1/SaCbFQ2VgMsgn9gko+OITigoigcSWTe8bgYFHHuqJvKFQ6hWwooStx4Dxw4k7L
	w98tiGhBbK+2GC4LH+sSlVgEm6UVt085iM8tjSVO6mMWxfOSTTQgT1EbeKpr2QqXdwrchh
	r4p5IoctluiRaRrrRmpNaMmJ/TPqCsJd6U6AS8/gqF8oDHWIU2K14bmyTVmEgQ==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785778279;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=5T1uVXaFVSzneCNXHdK4h65FwS/fp1U3JNzpOu/gg1E=;
	b=SjHQqCP49Wg/QP0uabf+1Mh/FWmkor5I9XGn4NIWVbNVFcYmHpIKIufEF/DLYc17uLDyuL
	2FQEjP7ZWbtA4fEqoJf0YpX7xUG5C7h7TTqzA70rzqj0onVdWk07OhPzu0l2us+nxDaEym
	613bWDeLycUIyYMeXC73VDXmIvWtI4ZgC6j1R98CpNyH+IUfE5G73rfub5zMdLYyPDCf/B
	idA19RG0tKOLg+9CcOs4QUQCqe3+aBQgpJf3KlvVeM3TNS9RLqtexY9PDA5eUKsliAb1bF
	ti1vCIHcmCpYOsHimFPQcCgM70XoOpmPYztpiSWt71AKDFPoR/dH/iZXOol72w==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDNxz2SVqz18l8
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 17:31:19 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 47ceb
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 17:31:19 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Cc: Enji Cooper <ngie@FreeBSD.org>
From: Alexander Leidinger <netchild@FreeBSD.org>
Subject: git: f7fd5a57b08c - stable/14 - tests/sys/pmc: only build if MK_PMC != no
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: netchild
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: f7fd5a57b08c2cf1d243296b953f1f0b7dc8cfd4
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 17:31:19 +0000
Message-Id: <6a70d067.47ceb.79f2cc77@gitrepo.freebsd.org>

The branch stable/14 has been updated by netchild:

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

commit f7fd5a57b08c2cf1d243296b953f1f0b7dc8cfd4
Author:     Enji Cooper <ngie@FreeBSD.org>
AuthorDate: 2026-07-22 19:53:31 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2026-08-03 17:31:04 +0000

    tests/sys/pmc: only build if MK_PMC != no
    
    This unbreaks the build when pmc support is explicitly disabled via the
    aforementioned build knob.
    
    MFC after:      10 days
    Fixes:          2cfd82f74 ("hwpmc: add regression tests for ...")
    Differential Revision:  https://reviews.freebsd.org/D58401
    
    (cherry picked from commit a18e773d2776a65c1a2a0418cbec9cf5ef526b53)
---
 tests/sys/Makefile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/sys/Makefile b/tests/sys/Makefile
index 7b7a97fd1359..59d4965cb796 100644
--- a/tests/sys/Makefile
+++ b/tests/sys/Makefile
@@ -30,7 +30,7 @@ TESTS_SUBDIRS+=		netlink
 TESTS_SUBDIRS+=		netmap
 TESTS_SUBDIRS+=		netpfil
 TESTS_SUBDIRS+=		opencrypto
-TESTS_SUBDIRS+=		pmc
+TESTS_SUBDIRS+=		${_pmc}
 TESTS_SUBDIRS+=		posixshm
 TESTS_SUBDIRS+=		ses
 TESTS_SUBDIRS+=		sound
@@ -51,6 +51,10 @@ _cddl=	cddl
 _netgraph= netgraph
 .endif
 
+.if ${MK_PMC} != "no"
+_pmc=	pmc
+.endif
+
 # Items not integrated into kyua runs by default
 SUBDIR+=		pjdfstest
 

From nobody Mon Aug  3 21:38:48 2026
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hDVRf2nnkz6n4Tn
	for <dev-commits-src-branches@mlmmj.nyi.freebsd.org>; Mon, 03 Aug 2026 21:38:54 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4hDVRf1pFHz3DNM
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 21:38:54 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1785793134;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=1R0BTeH4yPeVc34BrJSdhMJKdOORLvwK2MpKAdWoaI8=;
	b=iZ2pXc3yXvaPVJ3qSskTdBt8C1qKs7Q2e7e1EEb+0QvbryINEmGvl+DOnMUU77yjyYuTFD
	DglBcO9TfNeQ+dYiMh7l7JKD/3hetIaNa8g7bxVlnB4/zmPIds70prDZPhGmt2JQXbqr/p
	eCZLSIMU+cKooVj6FfIoZ9xE3MBNkq0sE2lvnAtfN/WSRBwjzHqgfOCqt0r5Hgyj8vT+US
	sTVUQgR5ZNW2TsS+CuBkl4EDtTKPKC9yY7Hu+yrph9GbwMpPjpp05jSTcxeHCTUJKQxsQM
	r5SwN2jjcqnOoIRhcNgUJ9gLzoMoBzaIhP374w8SixfjHNQ977mjKnYpgryKNg==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785793134; a=rsa-sha256; cv=none;
	b=kLMY+fuKGPSrb8xSZMO9qQ+jfrROOo80tQbGoA4zcN6kQH0Xs5w+39CBLDFGsPbsvfX9Lb
	qG0nEJ5YihAXR2rmIpwznUt3s2W9okxOgjR+qITcBia6fqbHS5nJEx0snj2cLsMaXphJqL
	5riZm489dUtK0wl8Bv9g6cTky1FsyqMMQklNwPIM6osUlC9fEetiKzn+Y2JIklqP8fBOSm
	ZGjzLOtKShflfcruzAA6K82WKc9lEcUiBCEnVHWVojoMHvYOAgrxlo8ZKyP0275+Fh1jCi
	XK9e9TZ48TQUR1WXOQqXQz2I75IySEW22n+wsju0tVz+OPxO+icNeTqaQPzqaA==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1785793134;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=1R0BTeH4yPeVc34BrJSdhMJKdOORLvwK2MpKAdWoaI8=;
	b=jdFYsSX0FdJzzrSG0J1NuPCvmGjj0rLSii4zAZIF33Vzwo1Bm/5h8e5oxRmKx3bRkhL6AE
	U9PJZUiIBY5v5WuhxFUhzX+1fKT9A4ciLOrPuvijNPNO9vKJp9tUWdyB6derem/l2NE2RI
	uIsPieV8SfZoqfYysmrNNHc7Qm8GpR5of5g/u2jjH0Mh9KgfQ4d75Ox8XrN1aExVO5w3Re
	oKN9DmCIGE0RhBmaoPMQixGfp3IhWnARjtmaTXgsgUOX1KEl/M72iLjh2HovAOzcPeMMS4
	aRxQY7Iwnl2faGhmj+Kw/KyujGElUDsHdKS5Bzm05p5/G6df9PS3/FtAN5Pfbg==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDVRf0fyPz3cp
	for <dev-commits-src-branches@FreeBSD.org>; Mon, 03 Aug 2026 21:38:54 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from git (uid 1279)
	(envelope-from git@FreeBSD.org)
	id 3b614
	by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org);
	Mon, 03 Aug 2026 21:38:48 +0000
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Cc: Kristofer Peterson <kris@tranception.com>
From: Jilles Tjoelker <jilles@FreeBSD.org>
Subject: git: e96ecc712e85 - stable/15 - bin/sh: Fix history long line truncation/corruption
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
X-BeenThere: dev-commits-src-branches@freebsd.org
Sender: owner-dev-commits-src-branches@FreeBSD.org
List-Id: <dev-commits-src-branches.FreeBSD.org>
List-Post: <mailto:dev-commits-src-branches@FreeBSD.org>
List-Help: <mailto:dev-commits-src-branches+help@FreeBSD.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@FreeBSD.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@FreeBSD.org>
List-Owner: <mailto:postmaster@FreeBSD.org>
Precedence: list
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: jilles
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/15
X-Git-Reftype: branch
X-Git-Commit: e96ecc712e85af65a728f70a84ca46df7c8a5d67
Auto-Submitted: auto-generated
Date: Mon, 03 Aug 2026 21:38:48 +0000
Message-Id: <6a710a68.3b614.75937726@gitrepo.freebsd.org>

The branch stable/15 has been updated by jilles:

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

commit e96ecc712e85af65a728f70a84ca46df7c8a5d67
Author:     Kristofer Peterson <kris@tranception.com>
AuthorDate: 2026-02-16 15:53:47 +0000
Commit:     Jilles Tjoelker <jilles@FreeBSD.org>
CommitDate: 2026-08-03 21:37:37 +0000

    bin/sh: Fix history long line truncation/corruption
    
    When reading from standard input with editline history enabled, increase
    buffer size to accomodate long lines so that history is recorded
    correctly. Cleanup el_gets() handling avoiding potentially dangerous
    retention of pointers to editline buffers across calls.  Ensure struct
    parsefile objects are properly zero initialised when created. Remove
    push argument from setinputstring() and simplify logic as it was always
    called with a value of one and as was written was potentially dangerous
    if ever called with a value of zero.
    
    This commit does not fix long lines when history is enabled but editing
    is not (e.g. if there is no terminal).
    
    MFC after:      3 weeks
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2028
    Signed-off-by: Kristofer Peterson <kris@tranception.com>
    (cherry picked from commit 95e4fce8f0c4fc6bf828288b1d63faf0f1300198)
---
 bin/sh/eval.c   |   2 +-
 bin/sh/input.c  | 146 ++++++++++++++++++++++++++++----------------------------
 bin/sh/input.h  |   2 +-
 bin/sh/parser.c |   4 +-
 4 files changed, 76 insertions(+), 78 deletions(-)

diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index fdc7a2560694..466193e20bb2 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -151,7 +151,7 @@ evalstring(const char *s, int flags)
 	flags &= ~EV_EXIT;
 	any = 0;
 	setstackmark(&smark);
-	setinputstring(s, 1);
+	setinputstring(s);
 	while ((n = parsecmd(0)) != NEOF) {
 		if (n != NULL && !nflag) {
 			if (flags_exit && preadateof())
diff --git a/bin/sh/input.c b/bin/sh/input.c
index 26f233ebf7b6..64bbae04149b 100644
--- a/bin/sh/input.c
+++ b/bin/sh/input.c
@@ -79,6 +79,7 @@ struct parsefile {
 	int lleft;		/* number of lines left in this buffer */
 	const char *nextc;	/* next char in buffer */
 	char *buf;		/* input buffer */
+	size_t bufsize;		/* input buffer size */
 	struct strpush *strpush; /* for pushing strings at this level */
 	struct strpush basestrpush; /* so pushing one is fast */
 };
@@ -91,7 +92,8 @@ const char *parsenextc;		/* copy of parsefile->nextc */
 static char basebuf[BUFSIZ + 1];/* buffer for top level input file */
 static struct parsefile basepf = {	/* top level input file */
 	.nextc = basebuf,
-	.buf = basebuf
+	.buf = basebuf,
+	.bufsize = sizeof(basebuf),
 };
 static struct parsefile *parsefile = &basepf;	/* current input file */
 int whichprompt;		/* 1 == PS1, 2 == PS2 */
@@ -125,52 +127,61 @@ static int
 preadfd(void)
 {
 	int nr;
-	parsenextc = parsefile->buf;
 
 retry:
 #ifndef NO_HISTORY
 	if (parsefile->fd == 0 && el) {
-		static const char *rl_cp;
-		static int el_len;
-
-		if (rl_cp == NULL) {
-			el_resize(el);
-			rl_cp = el_gets(el, &el_len);
-		}
-		if (rl_cp == NULL)
-			nr = el_len == 0 ? 0 : -1;
-		else {
-			nr = el_len;
-			if (nr > BUFSIZ)
-				nr = BUFSIZ;
-			memcpy(parsefile->buf, rl_cp, nr);
-			if (nr != el_len) {
-				el_len -= nr;
-				rl_cp += nr;
-			} else
-				rl_cp = NULL;
+		const char *line;
+
+		el_resize(el);
+		line = el_gets(el, &nr);
+		if (nr > 0 && parsefile->bufsize < (size_t)nr + 1) {
+			size_t bufsize;
+
+			INTOFF;
+			if (parsefile->buf != basebuf) {
+				ckfree(parsefile->buf);
+				parsefile->buf = NULL;
+				parsefile->bufsize = 0;
+			}
+			bufsize = (size_t)nr + BUFSIZ + 1;
+			bufsize -= bufsize % BUFSIZ;
+			parsefile->buf = ckmalloc(bufsize);
+			parsefile->bufsize = bufsize;
+			INTON;
 		}
+		if (nr > 0 && line != NULL)
+			memcpy(parsefile->buf, line, nr);
+		else
+			nr = nr ? -1 : 0;
 	} else
 #endif
-		nr = read(parsefile->fd, parsefile->buf, BUFSIZ);
-
-	if (nr <= 0) {
-                if (nr < 0) {
-                        if (errno == EINTR)
-                                goto retry;
-                        if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
-                                int flags = fcntl(0, F_GETFL, 0);
-                                if (flags >= 0 && flags & O_NONBLOCK) {
-                                        flags &=~ O_NONBLOCK;
-                                        if (fcntl(0, F_SETFL, flags) >= 0) {
-						out2fmt_flush("sh: turning off NDELAY mode\n");
-                                                goto retry;
-                                        }
-                                }
-                        }
+	nr = read(parsefile->fd, parsefile->buf, parsefile->bufsize - 1);
+
+	if (nr < 0)
+		switch (errno) {
+			int flags;
+
+		case EINTR:
+			goto retry;
+		case EWOULDBLOCK:
+			if (parsefile->fd != 0)
+				break;
+			if ((flags = fcntl(0, F_GETFL, 0)) < 0)
+				break;
+			if (!(flags & O_NONBLOCK))
+				break;
+			if (fcntl(0, F_SETFL, flags & ~O_NONBLOCK) < 0)
+				break;
+			out2fmt_flush("sh: turning off NDELAY mode\n");
+			goto retry;
                 }
-                nr = -1;
-	}
+	else if (nr > 0)
+		parsefile->buf[nr] = '\0';
+	else
+		nr = -1;
+
+	parsenextc = parsefile->buf;
 	return nr;
 }
 
@@ -187,7 +198,8 @@ retry:
 int
 preadbuffer(void)
 {
-	char *p, *q, *r, *end;
+	const char *end;
+	char *q, *r;
 	char savec;
 
 	while (parsefile->strpush) {
@@ -206,31 +218,22 @@ preadbuffer(void)
 		return PEOF;
 
 again:
-	if (parselleft <= 0) {
-		if ((parselleft = preadfd()) == -1) {
-			parselleft = parsenleft = EOF_NLEFT;
-			return PEOF;
-		}
+	if (parselleft <= 0 && (parselleft = preadfd()) == -1) {
+		parselleft = parsenleft = EOF_NLEFT;
+		return (PEOF);
 	}
-
-	p = parsefile->buf + (parsenextc - parsefile->buf);
-	end = p + parselleft;
-	*end = '\0';
-	q = strchrnul(p, '\n');
-	if (q != end && *q == '\0') {
+	end = parsenextc + parselleft;
+	q = strchrnul(parsenextc, '\n');
+	if (*q == '\0' && q != end) {
 		/* delete nul characters */
-		for (r = q; q != end; q++) {
+		for (r = q++; q != end; q++)
 			if (*q != '\0')
 				*r++ = *q;
-		}
-		parselleft -= end - r;
-		if (parselleft == 0)
-			goto again;
-		end = p + parselleft;
-		*end = '\0';
-		q = strchrnul(p, '\n');
+		*r = '\0';
+		parselleft = r - parsenextc;
+		goto again;
 	}
-	if (q == end) {
+	if (*q == '\0') {
 		parsenleft = parselleft;
 		parselleft = 0;
 	} else /* *q == '\n' */ {
@@ -305,7 +308,7 @@ pushstring(const char *s, int len, struct alias *ap)
 	INTOFF;
 /*out2fmt_flush("*** calling pushstring: %s, %d\n", s, len);*/
 	if (parsefile->strpush) {
-		sp = ckmalloc(sizeof (struct strpush));
+		sp = ckmalloc(sizeof(struct strpush));
 		sp->prev = parsefile->strpush;
 		parsefile->strpush = sp;
 	} else
@@ -389,15 +392,15 @@ setinputfile(const char *fname, int push, int verify)
 void
 setinputfd(int fd, int push)
 {
-	if (push) {
+	if (push)
 		pushfile();
-		parsefile->buf = ckmalloc(BUFSIZ + 1);
-	}
 	if (parsefile->fd > 0)
 		close(parsefile->fd);
 	parsefile->fd = fd;
-	if (parsefile->buf == NULL)
+	if (parsefile->buf == NULL) {
 		parsefile->buf = ckmalloc(BUFSIZ + 1);
+		parsefile->bufsize = BUFSIZ + 1;
+	}
 	parselleft = parsenleft = 0;
 	plinno = 1;
 }
@@ -408,14 +411,12 @@ setinputfd(int fd, int push)
  */
 
 void
-setinputstring(const char *string, int push)
+setinputstring(const char *string)
 {
 	INTOFF;
-	if (push)
-		pushfile();
+	pushfile();
 	parsenextc = string;
 	parselleft = parsenleft = strlen(string);
-	parsefile->buf = NULL;
 	plinno = 1;
 	INTON;
 }
@@ -432,15 +433,12 @@ pushfile(void)
 {
 	struct parsefile *pf;
 
+	pf = (struct parsefile *)ckmalloc(sizeof(struct parsefile));
+	*pf = (struct parsefile){ .prev = parsefile, .fd = -1 };
 	parsefile->nleft = parsenleft;
 	parsefile->lleft = parselleft;
 	parsefile->nextc = parsenextc;
 	parsefile->linno = plinno;
-	pf = (struct parsefile *)ckmalloc(sizeof (struct parsefile));
-	pf->prev = parsefile;
-	pf->fd = -1;
-	pf->strpush = NULL;
-	pf->basestrpush.prev = NULL;
 	parsefile = pf;
 }
 
diff --git a/bin/sh/input.h b/bin/sh/input.h
index 8cf4df1e4044..f98b592c4c6b 100644
--- a/bin/sh/input.h
+++ b/bin/sh/input.h
@@ -52,7 +52,7 @@ void pungetc(void);
 void pushstring(const char *, int, struct alias *);
 void setinputfile(const char *, int, int);
 void setinputfd(int, int);
-void setinputstring(const char *, int);
+void setinputstring(const char *);
 void popfile(void);
 struct parsefile *getcurrentfile(void);
 void popfilesupto(struct parsefile *);
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index 0c1b7a91c257..68d4238c00ad 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -1165,7 +1165,7 @@ parsebackq(char *out, struct nodelist **pbqlist,
 		INTOFF;
 		ostr = ckmalloc(olen);
 		memcpy(ostr, stackblock(), olen);
-		setinputstring(ostr, 1);
+		setinputstring(ostr);
 		INTON;
         }
 	nlpp = pbqlist;
@@ -2244,7 +2244,7 @@ expandstr(const char *ps)
 	if (!setjmp(jmploc.loc)) {
 		handler = &jmploc;
 		parser_temp = NULL;
-		setinputstring(ps, 1);
+		setinputstring(ps);
 		doprompt = 0;
 		readtoken1(pgetc(), DQSYNTAX, NOEOFMARK, 0);
 		if (backquotelist != NULL)

