From nobody Thu Dec 21 13:43:51 2023 X-Original-To: dev-commits-src-all@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 4Sws8m0Sxqz54pZg; Thu, 21 Dec 2023 13:43:52 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Sws8l68bqz4P3p; Thu, 21 Dec 2023 13:43:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703166231; 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=9rkVRlJQMtwi9lF4hmZpbfebS3gnbTclqKWJVskU2XM=; b=c2yJO51t0CptJyWdDGDi3LGmyTQbN//55OOt385fnIDV+SyD2FIB0BHAomohX74fsWdiVf 7oh8CQE5F5+z54eJrApgGPDGeYCTb6Q3rkndJ7YgmtdtVqT7eXddsLO1mrzxh/SAZ/5E4Q BNvb+zGt0+ijunqFOO0Jzo4Ydle000oqeUTsfEJURKUBt80mVUhHVlKtjKzvbNAyedx2PW I15U9+MtLUg5+VJNkRHe1iXa26JEehEuvHnAWdFqbB1cj3QrgF3zE/7/bSzvfOfWcWCDbK cor4BbwbnoqN4sccFgnSWabI+atu8YMx9/cxwAhusIKMaSCRThGvXCw5NWUY1Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703166231; a=rsa-sha256; cv=none; b=VIsKkAGzK83NXmZBmGPmN0wWjAXQ74+qogTbpHopnRSQtW+XqRjs9Yrey8U+aQJEE2DSUt 9/l3XaV3lDStBQV+TOC9L4WrjPErEtZMEiFk+SjgUKt2JBPzgjaNu45uzazl7pqa9PxPlt xHxC/olU3q1Z0MhlJ21kPeWnSuqrKR5TI6MdPyNZR3kFaxcXcXs1vrHhwZIWN35HVQiq67 F69GkU3154cc4HWB5fVpgKiW8Xz775o/k4SCBEWXduIOkXfrl6ODWe2HMhHk1Am297p4mC aeotX5ulBjk13y2MEykDz59frr/GV6pH0bEwZMePoKtml7aeJBiqoZU0wt3X/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=1703166231; 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=9rkVRlJQMtwi9lF4hmZpbfebS3gnbTclqKWJVskU2XM=; b=m13KLrio5deTUwWOFyWfIfv6A9NAksRk6jWqAKq0rWF32k/pIPi5WiXJQLDSaijTGjJH+F Lvg7kldueT9QIgkHSmkZw8GjJ0mrUIgRmLyTqFtVIjxQGDqy1CuBiMVd+jXT04r4THBNiG iDdJiV0AgmHW2dpYa4CfJa3fbH4yz7kmruDg7GhyFCtp8snzMMF7VEdcDgX78SlfdMyASm vCLTexXwnp+6zOYfER3+ZGuS2lVe1YNYOw7o17Wm1Wg4hAxeXaEiXnJhM3ceIhvbc6n6Rb 6nN92EpKCgax6rDDHCRUUnC6IGklD7V83Sh3vDHLjihtD8sjgGehAxiy8a6O3A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Sws8l54t2zZdJ; Thu, 21 Dec 2023 13:43:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BLDhpLj079768; Thu, 21 Dec 2023 13:43:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BLDhpx8079765; Thu, 21 Dec 2023 13:43:51 GMT (envelope-from git) Date: Thu, 21 Dec 2023 13:43:51 GMT Message-Id: <202312211343.3BLDhpx8079765@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 037c104ca4a7 - stable/13 - Ensure "init" (PID 1) also executes userret() initially List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 037c104ca4a71b7510799c6fff5fa031c070319f Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=037c104ca4a71b7510799c6fff5fa031c070319f commit 037c104ca4a71b7510799c6fff5fa031c070319f Author: Olivier Certner AuthorDate: 2023-10-10 17:36:20 +0000 Commit: Olivier Certner CommitDate: 2023-12-21 13:39:18 +0000 Ensure "init" (PID 1) also executes userret() initially Calling userret() from fork_return() misses the first return to userspace of the "init" (PID 1) process. The latter is indeed created by fork1() followed by a call to cpu_fork_kthread_handler() call that replaces fork_return() by start_init() as the function to execute after fork. A new process' initial return to userspace in the end always happens through returning from fork_exit(), so move userret() there instead to fix the omission. This problem was discovered as part of a revamp of scheduling priorities that lead to experimenting with asserting and sometimes resetting priorities in sched_userret(), in the course of which the author stumbled on panics being triggered only in init() or only in other processes, depending on the modifications to sched_userret(). This change currently has no practical effect but will have some in the near future. Reviewed by: markj, kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42257 (cherry picked from commit eac624207ccf3a16225368d226861b06e3631d0d) Approved by: markj (mentor) --- sys/kern/kern_fork.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 59ffcce70966..114eeeb2a943 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1161,9 +1161,15 @@ fork_exit(void (*callout)(void *, struct trapframe *), void *arg, } mtx_assert(&Giant, MA_NOTOWNED); + /* + * Now going to return to userland. + */ + if (p->p_sysent->sv_schedtail != NULL) (p->p_sysent->sv_schedtail)(td); td->td_pflags &= ~TDP_FORKING; + + userret(td, frame); } /* @@ -1214,8 +1220,6 @@ fork_return(struct thread *td, struct trapframe *frame) if (!prison_isalive(td->td_ucred->cr_prison)) exit1(td, 0, SIGKILL); - userret(td, frame); - #ifdef KTRACE if (KTRPOINT(td, KTR_SYSRET)) ktrsysret(td->td_sa.code, 0, 0);