From nobody Thu May 02 13:26:48 2024 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 4VVZTj45mRz5JJfr; Thu, 2 May 2024 13:26:49 +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 4VVZTj08Yjz49yw; Thu, 2 May 2024 13:26:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714656409; 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=HcH3TwMFSvHOfBYB1QCvh0T2vOHHVf9dnRMYngrZse8=; b=iOixDyo3IH9P07mF+Z60yqCbBKLw8i9ZEVBGBc+UKNAPCph8flvRZ6QH1uwcvPkMnTz7GH 2418AxkTjpWZzxO1gKzBdmLXNlA0tGPy0h2EqOn3ujkw9EsQveW/dI7W2PB+yZgZhOg62l tavr65Y3nbHthcYIqXkIqESZl1nnJ/syFnR5c2mJomtr5ZszN7qzdRG22Fqp4S4FCiYRpH 9NP3wTPgbqQhJ47OPp5JKNPoDnFOHtyLgB4fhfR6KZkq+H0rO3+pjdwkdjjQQlA9I4Og/K mAb+gDT02zqFOYjdmSGiyltq2IBQBkggSn4z2mBOKHF9VxCxiMYgFFAlHMGtSA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714656409; a=rsa-sha256; cv=none; b=vK3nA85O+OfNIThSn9dZVNlB8B38kT50Fu7Jnx6wf+/3qstXLXFvh2HjM7wDz10AjtSK12 sySRL64zfaoKq8MyiqffsdlDHAuZs1UoDOfvc1O9xusyryJku2jCrdGXX3QttIh6ioxvW5 Npt71Hol/8v0eaqdMUHcZdI+IaLGxw03b4K8udcvZ141OYzjnTYl0ht9YlFTsG1sjcncZx qs3sjRkQSnPIC0/spuCBoqlJQvc8O8JJmDmTDzveyLOQ+49nHG8b5tXRkFAZDJ5980Pfb9 oeuARg3T22zz4bQvaT1/wjFA6K1g+UXC0fktNdqICA0WPXyCs6J+f8s5uY0C/A== 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=1714656409; 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=HcH3TwMFSvHOfBYB1QCvh0T2vOHHVf9dnRMYngrZse8=; b=hfN/lp170RPGrwsikedVJbJoW5m7t0ZtqB9uDItc8jFzY6g6RgmeDs5uug/eVPtQpZuqQj evS1lrGQV6aUBFtHMAy3YcPqZIBCEK02VZ17NnEnuGxKZL4JuAojmhjIq7DxdaWhm8naCG Z2AxdMWFNfgguXVE+rNhQEZlA/OYYLYK7Llpuog39mDNnuCs9hoySiWKEH3w85LLYWuyaV NbzlV5ZRlzvwARbdLSH4pM1vmGijk4pgGz5LoIRUDT8MVHIb2RafXW5HXwMBORzJExCVpt n4Cfhbz6RXzkavAL374l7Gm972Qw4vaCTTaFS4r2SMzfdR8a5UqJPWIvvKRyIg== 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 4VVZTh6tYMz14HR; Thu, 2 May 2024 13:26:48 +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 442DQmsg080875; Thu, 2 May 2024 13:26:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 442DQml0080872; Thu, 2 May 2024 13:26:48 GMT (envelope-from git) Date: Thu, 2 May 2024 13:26:48 GMT Message-Id: <202405021326.442DQml0080872@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 19e335596658 - stable/14 - kthread: Set *tdptr earlier in kproc_kthread_add() 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/stable/14 X-Git-Reftype: branch X-Git-Commit: 19e335596658bf1ced262f769a0ed2d72f847766 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=19e335596658bf1ced262f769a0ed2d72f847766 commit 19e335596658bf1ced262f769a0ed2d72f847766 Author: Mark Johnston AuthorDate: 2024-04-25 13:35:38 +0000 Commit: Mark Johnston CommitDate: 2024-05-02 13:25:10 +0000 kthread: Set *tdptr earlier in kproc_kthread_add() See commit ae77041e0714 ("kthread: Set *newtdp earlier in kthread_add1()") for details. That commit was incomplete since g_init()'s first call to kproc_kthread_add() will cause kproc_kthread_add() to take the `*procptr == NULL` branch, which avoids kthread_create(). To ensure that the thread pointer is initialized before the thread starts running, we have to start the kernel process with RFSTOPPED. We could perhaps go further and use RFSTOPPED only when tdptr != NULL, but it's probably better to have consistent behaviour. Reviewed by: olce, kib Reported by: syzbot+e91e798f3c088215ace6@syzkaller.appspotmail.com MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D44927 (cherry picked from commit d66399326cb4f89d1565fb62c1c07974886893c5) --- sys/kern/kern_kthread.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c index 9cbc74658432..00a264d57a21 100644 --- a/sys/kern/kern_kthread.c +++ b/sys/kern/kern_kthread.c @@ -496,13 +496,21 @@ kproc_kthread_add(void (*func)(void *), void *arg, struct thread *td; if (*procptr == NULL) { + /* + * Use RFSTOPPED to ensure that *tdptr is initialized before the + * thread starts running. + */ error = kproc_create(func, arg, - procptr, flags, pages, "%s", procname); + procptr, flags | RFSTOPPED, pages, "%s", procname); if (error) return (error); td = FIRST_THREAD_IN_PROC(*procptr); if (tdptr) *tdptr = td; + if ((flags & RFSTOPPED) == 0) { + thread_lock(td); + sched_add(td, SRQ_BORING); + } va_start(ap, fmt); vsnprintf(td->td_name, sizeof(td->td_name), fmt, ap); va_end(ap);