git: 48c288443822 - stable/15 - kern_thread: thread_suspend_check(1) must never suspend

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

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

commit 48c28844382229a7af24941541e89e663b38f75c
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:37:05 +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 3180c66cb42b..4f9053460455 100644
--- a/sys/kern/kern_thread.c
+++ b/sys/kern/kern_thread.c
@@ -1446,6 +1446,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.
@@ -1481,10 +1489,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);