From owner-p4-projects@FreeBSD.ORG Thu Jan 18 09:30:11 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3590B16A40F; Thu, 18 Jan 2007 09:30:11 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E9B1316A416 for ; Thu, 18 Jan 2007 09:30:10 +0000 (UTC) (envelope-from rdivacky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id C622613C459 for ; Thu, 18 Jan 2007 09:30:10 +0000 (UTC) (envelope-from rdivacky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id l0I9UAfk024028 for ; Thu, 18 Jan 2007 09:30:10 GMT (envelope-from rdivacky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id l0I9UAlw024022 for perforce@freebsd.org; Thu, 18 Jan 2007 09:30:10 GMT (envelope-from rdivacky@FreeBSD.org) Date: Thu, 18 Jan 2007 09:30:10 GMT Message-Id: <200701180930.l0I9UAlw024022@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to rdivacky@FreeBSD.org using -f From: Roman Divacky To: Perforce Change Reviews Cc: Subject: PERFORCE change 113097 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jan 2007 09:30:11 -0000 http://perforce.freebsd.org/chv.cgi?CH=113097 Change 113097 by rdivacky@rdivacky_witten on 2007/01/18 09:29:19 In linux_fork and linux_vfork create the process in stopped state to be sure that the new process runs with fully initialized emuldata structure [1]. Also fix the vfork (both in linux_clone and linux_vfork) race that could result in never woken up process [2]. Reported by: Scot Hetzel [1] Suggested by: jhb [2] Affected files ... .. //depot/projects/linuxolator/src/sys/amd64/linux32/linux32_machdep.c#23 edit .. //depot/projects/linuxolator/src/sys/i386/linux/linux_machdep.c#16 edit Differences ... ==== //depot/projects/linuxolator/src/sys/amd64/linux32/linux32_machdep.c#23 (text+ko) ==== @@ -474,14 +474,21 @@ linux_fork(struct thread *td, struct linux_fork_args *args) { int error; + struct proc *p2; + struct thread *td2; #ifdef DEBUG if (ldebug(fork)) printf(ARGS(fork, "")); #endif - if ((error = fork(td, (struct fork_args *)args)) != 0) + if ((error = fork1(td, RFFDG | RFPROC | RFSTOPPED, 0, &p2)) != 0) return (error); + + if (error == 0) { + td->td_retval[0] = p2->p_pid; + td->td_retval[1] = 0; + } if (td->td_retval[1] == 1) td->td_retval[0] = 0; @@ -489,6 +496,14 @@ if (error) return (error); + td2 = FIRST_THREAD_IN_PROC(p2); + + /* make it run */ + mtx_lock_spin(&sched_lock); + TD_SET_CAN_RUN(td2); + setrunqueue(td2, SRQ_BORING); + mtx_unlock_spin(&sched_lock); + return (0); } @@ -497,6 +512,7 @@ { int error; struct proc *p2; + struct thread *td2; #ifdef DEBUG if (ldebug(vfork)) @@ -504,7 +520,7 @@ #endif /* exclude RFPPWAIT */ - if ((error = fork1(td, RFFDG | RFPROC | RFMEM, 0, &p2)) != 0) + if ((error = fork1(td, RFFDG | RFPROC | RFMEM | RFSTOPPED, 0, &p2)) != 0) return (error); if (error == 0) { td->td_retval[0] = p2->p_pid; @@ -516,12 +532,23 @@ error = linux_proc_init(td, td->td_retval[0], 0); if (error) return (error); + + p2->p_flag |= P_PPWAIT; + + td2 = FIRST_THREAD_IN_PROC(p2); + + /* make it run */ + mtx_lock_spin(&sched_lock); + TD_SET_CAN_RUN(td2); + setrunqueue(td2, SRQ_BORING); + mtx_unlock_spin(&sched_lock); + /* wait for the children to exit, ie. emulate vfork */ PROC_LOCK(p2); - p2->p_flag |= P_PPWAIT; while (p2->p_flag & P_PPWAIT) msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0); PROC_UNLOCK(p2); + return (0); } @@ -682,6 +709,8 @@ printf(LMSG("clone: successful rfork to %ld, stack %p sig = %d"), (long)p2->p_pid, args->stack, exit_signal); #endif + if (args->flags & CLONE_VFORK) + p2->p_flag |= P_PPWAIT; /* * Make this runnable after we are finished with it. @@ -697,7 +726,6 @@ if (args->flags & CLONE_VFORK) { /* wait for the children to exit, ie. emulate vfork */ PROC_LOCK(p2); - p2->p_flag |= P_PPWAIT; while (p2->p_flag & P_PPWAIT) msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0); PROC_UNLOCK(p2); ==== //depot/projects/linuxolator/src/sys/i386/linux/linux_machdep.c#16 (text+ko) ==== @@ -297,14 +297,21 @@ linux_fork(struct thread *td, struct linux_fork_args *args) { int error; + struct proc *p2; + struct thread *td2; #ifdef DEBUG if (ldebug(fork)) printf(ARGS(fork, "")); #endif - if ((error = fork(td, (struct fork_args *)args)) != 0) + if ((error = fork1(td, RFFDG | RFPROC | RFSTOPPED, 0, &p2)) != 0) return (error); + + if (error == 0) { + td->td_retval[0] = p2->p_pid; + td->td_retval[1] = 0; + } if (td->td_retval[1] == 1) td->td_retval[0] = 0; @@ -312,6 +319,14 @@ if (error) return (error); + td2 = FIRST_THREAD_IN_PROC(p2); + + /* make it run */ + mtx_lock_spin(&sched_lock); + TD_SET_CAN_RUN(td2); + setrunqueue(td2, SRQ_BORING); + mtx_unlock_spin(&sched_lock); + return (0); } @@ -320,6 +335,7 @@ { int error; struct proc *p2; + struct thread *td2; #ifdef DEBUG if (ldebug(vfork)) @@ -327,10 +343,10 @@ #endif /* exclude RFPPWAIT */ - if ((error = fork1(td, RFFDG | RFPROC | RFMEM, 0, &p2)) != 0) + if ((error = fork1(td, RFFDG | RFPROC | RFMEM | RFSTOPPED, 0, &p2)) != 0) return (error); if (error == 0) { - td->td_retval[0] = p2->p_pid; + td->td_retval[0] = p2->p_pid; td->td_retval[1] = 0; } /* Are we the child? */ @@ -339,9 +355,19 @@ error = linux_proc_init(td, td->td_retval[0], 0); if (error) return (error); + + p2->p_flag |= P_PPWAIT; + + td2 = FIRST_THREAD_IN_PROC(p2); + + /* make it run */ + mtx_lock_spin(&sched_lock); + TD_SET_CAN_RUN(td2); + setrunqueue(td2, SRQ_BORING); + mtx_unlock_spin(&sched_lock); + /* wait for the children to exit, ie. emulate vfork */ PROC_LOCK(p2); - p2->p_flag |= P_PPWAIT; while (p2->p_flag & P_PPWAIT) msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0); PROC_UNLOCK(p2); @@ -520,6 +546,8 @@ printf(LMSG("clone: successful rfork to %ld, stack %p sig = %d"), (long)p2->p_pid, args->stack, exit_signal); #endif + if (args->flags & CLONE_VFORK) + p2->p_flag |= P_PPWAIT; /* * Make this runnable after we are finished with it. @@ -535,7 +563,6 @@ if (args->flags & CLONE_VFORK) { /* wait for the children to exit, ie. emulate vfork */ PROC_LOCK(p2); - p2->p_flag |= P_PPWAIT; while (p2->p_flag & P_PPWAIT) msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0); PROC_UNLOCK(p2);