git: 5e9bba94bd7f - main - fork_norfproc(): unlock p1 before retrying

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sat, 20 Aug 2022 17:34:59 UTC
The branch main has been updated by kib:

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

commit 5e9bba94bd7f6b61d6c9fcef239e963e55c1a87a
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-08-10 17:03:31 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-08-20 17:33:18 +0000

    fork_norfproc(): unlock p1 before retrying
    
    Reported and reviewed by:       markj
    Tested by:      pho
    Syzkaller:      647212368c3f32c6f13f
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 weeks
    Differential revision:  https://reviews.freebsd.org/D36207
---
 sys/kern/kern_fork.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 434c5a6290fe..c71a0422b1e2 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -323,13 +323,11 @@ again:
 	if ((p1->p_flag & (P_HADTHREADS | P_SYSTEM)) == P_HADTHREADS &&
 	    ((flags & (RFCFDG | RFFDG)) != 0 || (flags & RFMEM) == 0)) {
 		PROC_LOCK(p1);
-		while (p1->p_singlethr > 0) {
+		if (p1->p_singlethr > 0) {
 			error = msleep(&p1->p_singlethr, &p1->p_mtx,
-			    PWAIT | PCATCH, "rfork1t", 0);
-			if (error != 0) {
-				PROC_UNLOCK(p1);
+			    PWAIT | PCATCH | PDROP, "rfork1t", 0);
+			if (error != 0)
 				return (ERESTART);
-			}
 			goto again;
 		}
 		if (thread_single(p1, SINGLE_BOUNDARY)) {