git: f363f4a8fa8b - stable/14 - kern_thread: thread_suspend_check(1) must never suspend

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 18 Nov 2025 03:38:50 UTC
The branch stable/14 has been updated by kib:

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

commit f363f4a8fa8b7d7beb79d2f6f70479aad30e7d6f
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-11-06 19:25:23 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-11-18 03:38:29 +0000

    kern_thread: thread_suspend_check(1) must never suspend
    
    PR:     290843
    
    (cherry picked from commit e1c6f4cb9bd29358c2b2fe249af9a2f9626b0670)
---
 sys/kern/kern_thread.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c
index a41e74e1533e..bd81b7472579 100644
--- a/sys/kern/kern_thread.c
+++ b/sys/kern/kern_thread.c
@@ -1451,6 +1451,14 @@ thread_suspend_check(int return_instead)
 			return (TD_SBDRY_INTR(td) ? TD_SBDRY_ERRNO(td) : 0);
 		}
 
+		/*
+		 * We might get here with return_instead == 1 if
+		 * other checks missed it.  Then we must not suspend
+		 * regardless of P_SHOULDSTOP() or debugger request.
+		 */
+		if (return_instead)
+			return (EINTR);
+
 		/*
 		 * If the process is waiting for us to exit,
 		 * this thread should just suicide.
@@ -1488,10 +1496,9 @@ thread_suspend_check(int return_instead)
 		 * gets taken off all queues.
 		 */
 		thread_suspend_one(td);
-		if (return_instead == 0) {
-			p->p_boundary_count++;
-			td->td_flags |= TDF_BOUNDARY;
-		}
+		MPASS(!return_instead);
+		p->p_boundary_count++;
+		td->td_flags |= TDF_BOUNDARY;
 		PROC_SUNLOCK(p);
 		mi_switch(SW_INVOL | SWT_SUSPEND);
 		PROC_LOCK(p);