From nobody Thu Nov 2 13:40:04 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 4SLlP02YVPz50Ldq; Thu, 2 Nov 2023 13:40:04 +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 4SLlP01yJLz4Ny8; Thu, 2 Nov 2023 13:40:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698932404; 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=Jz8DVO2nWXgsNUZ6yq0NkCVEixaTbKgGJcem9ntebPA=; b=xXUuZ7yBocLbVXIayzRLF9RbZfuJBfKhAgCmdHXB2O/1HfDcVtAxjUwmB6YuNv4XSokSa8 b7WCCuR3GVzOSiCR71BJe5DByvClTBoBiqbyWbjcnRRoQGXERE9fvL6su6ckH5x/L4MLMi pcVUsTXJCwJHGv5ANDV9LSo4bPjHZTyWtEx8aq9pNTRcOkw3E5zZwapPhLMtYtKiYhh709 F2Vp7oJaQsbKaJWKLCFEBNQE/3vGfpr6jOMyPLSW2H4SeL4oVcGra7KZmNb25DW3ANMxWM 3fuvRP+csToOTE79p8vu/s6rP9+TkgfVZsLSMQ1u6ald7WBrHE1mciMInxut4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698932404; 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=Jz8DVO2nWXgsNUZ6yq0NkCVEixaTbKgGJcem9ntebPA=; b=krrLfzfjZl7zDRPkTVFk6kURGzq8uaMpHy70CMte9TcGwQ9qMioeNBmvu8phr1cObHwv+z jkv/p4lM1ulg5Z/FuWSBpjx4zibpl2Zy9VuSu8LwYMRAdrT9CoIqejw+AMhoIZYfPh/Vjn kJAjoowSQMwqZYbtbl4GbbcBPDWUkihEVDp8ZWKJ/7P1Q2Bh5WcNfCeqV7VXAKYh1Ji1IA jRR0nNdYA8RS+8GzusdQ/FX4c4hGOiccM+a2SNwD9TFwVD3cbNI5ExgYXSLA226ObcOXLR tJiBxw1f4naC5IjPUtNRE7kLyzpmzkpQOT8qWJIka6rxrXRKfO1rFkUJi9mLcg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698932404; a=rsa-sha256; cv=none; b=lZ/SZ0qlz4NeT6muT75NyHjHgY2N5zvOV8ungIQFdfB2cZdfN439HZWVa5hJWWIOp35TK6 YtwnltlJ5ezvH/zk4mCHwQ/FHnIcdL37+GbuE910zohb3TVCg/qW08xA7K89roNw0PaK5J z8KqXdO83eat42fvrftGr+qWUxrne0rGZxofpVYVpdNZ5jNFnrZxIThprwHXH3ooNBmaGh wRj05sYbkoB52+8cRhBDVFSrw3ATkEh4Vh0Ue2vyOvchpiosH9CNzLXXTBbmVI+P814nVd LAKtwxjtKxIGpQ9SG5UoaSo6eySravoKETkxDiizo+25S5NF3XYeLB6fvUnHUA== 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 4SLlP013FHzXCD; Thu, 2 Nov 2023 13:40:04 +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 3A2De4nq027640; Thu, 2 Nov 2023 13:40:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3A2De4ko027635; Thu, 2 Nov 2023 13:40:04 GMT (envelope-from git) Date: Thu, 2 Nov 2023 13:40:04 GMT Message-Id: <202311021340.3A2De4ko027635@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: eac624207ccf - main - 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: eac624207ccf3a16225368d226861b06e3631d0d Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=eac624207ccf3a16225368d226861b06e3631d0d commit eac624207ccf3a16225368d226861b06e3631d0d Author: Olivier Certner AuthorDate: 2023-10-10 17:36:20 +0000 Commit: Mark Johnston CommitDate: 2023-11-02 13:30:03 +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 MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42257 --- 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 3080bd11123d..6127b7f05fe0 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1170,8 +1170,14 @@ 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); + + userret(td, frame); } /* @@ -1222,8 +1228,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);