From nobody Sat Sep 9 08:27:01 2023 X-Original-To: dev-commits-src-branches@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 4RjR0j4C7fz4sNwP; Sat, 9 Sep 2023 08:27:01 +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 4RjR0j3NG9z4Lsv; Sat, 9 Sep 2023 08:27:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694248021; 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=Y/Wevc37xAgbYx0wgA0tnychBrFFM4fuGbOU6o28fv0=; b=o3WlhqFejWNkd/80mRzmL7GpjTAwui4FSIp1m+IiZUs2W3YvWriggaKfJbF7Sw0qCXGjyV I9xaRe9oJKUoadYRGfAjC2PuLL3aRMFzisYBoyCAQBMQETsxv3BNDQn1zLaDd8ue1vkbUW yt/3ZQ1nL2ab5HXNox+w5l0AORnsZA+s+UkOoo/dyzmdCgKV4OWIJ2JDD24CrBABCLjQkW zpEZJbxHRVEL1zc523aksaBKTOwN/Z9gJXeoIMV81qCTCYSVxtnaVm2LyJsk2dJ7JMab45 SBdIR7DLCc6vpG082+tUYbnPAF0NF5nvvdPU38JHMD3HMxN4PRPuVkxI5VS2ag== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694248021; a=rsa-sha256; cv=none; b=nVki6hCLXxD3D07ts5gEpjesU+3PfzrtkTz8q9WHRV9j6hVJXymfLUgB4bXIHaydWp0xIZ 87lgPuKb6FCDDT0N7tk1c9Nfdds09HHsJN0VTPDitwrnrS5uBW1eUcC/2jWWMQr4Uutibg IpPHCL4vb7GnVbNcVvVaGtzhwkIsC36Ak3tws63NMzWVRP0lX4R5FaiOHUtUVNfjCNM5yd It2LAxLGIxRVGur1Qr6xvLXz6UgOmM3N46MVf2aJAugiiT/vi8DGnvEYX9cvuX7E1OxGz5 yHABgZX80P+EeS6Qz+18hZwpFtjgi6uBce5XHmdmH7du46XACm7tbHCStFpqLg== 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=1694248021; 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=Y/Wevc37xAgbYx0wgA0tnychBrFFM4fuGbOU6o28fv0=; b=ddzZQ8Iw0oSVRaudLYZN/maKkq51s4FCysSkCdu87F8X2hnOWXp4gH823iPxMMCpV4D+kd etKjLtxQ9bE4ra6d9XuE7sYvnm0fnQz9Q7GG6WYHZx8L6wcXIMq7ZZRgVfWpBgOW2lcQ1w 7/BY/C9wQliAcmAx0vkpWyomzPZPlWOPjDuOaBkfd3Rf/GN4/3QWYnXxW1g0uruO9p6EJp sbH7PgccA9R7f49NPKHK6KOk0g7vQwhsoKhYbhQLGX+41v7ezs5ILMJG9HvBU4SKSOLVQL EX//zPwG23tXOobPaOAk/YDUmR8Uc2/3zA2X0nFMKyIWaptP3wUrizV8FS9iwA== 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 4RjR0j2Qskz2X3; Sat, 9 Sep 2023 08:27:01 +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 3898R1Ia053649; Sat, 9 Sep 2023 08:27:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3898R1wO053646; Sat, 9 Sep 2023 08:27:01 GMT (envelope-from git) Date: Sat, 9 Sep 2023 08:27:01 GMT Message-Id: <202309090827.3898R1wO053646@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 689e7b5a86b9 - stable/14 - kern_kthread: fork1() does not handle locked Giant List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 689e7b5a86b9950944a961487aeb620611584e4d Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=689e7b5a86b9950944a961487aeb620611584e4d commit 689e7b5a86b9950944a961487aeb620611584e4d Author: Konstantin Belousov AuthorDate: 2023-09-02 07:16:48 +0000 Commit: Konstantin Belousov CommitDate: 2023-09-09 08:26:33 +0000 kern_kthread: fork1() does not handle locked Giant (cherry picked from commit 525bc87f54f288793a95abbcd0a845efddb8c41b) --- sys/kern/kern_kthread.c | 60 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c index 3604d63531da..5e32aea1f56d 100644 --- a/sys/kern/kern_kthread.c +++ b/sys/kern/kern_kthread.c @@ -78,13 +78,12 @@ kproc_start(const void *udata) * flags are flags to fork1 (in unistd.h) * fmt and following will be *printf'd into (*newpp)->p_comm (for ps, etc.). */ -int -kproc_create(void (*func)(void *), void *arg, - struct proc **newpp, int flags, int pages, const char *fmt, ...) +static int +kproc_create1(void (*func)(void *), void *arg, + struct proc **newpp, int flags, int pages, const char *tdname) { struct fork_req fr; int error; - va_list ap; struct thread *td; struct proc *p2; @@ -105,13 +104,9 @@ kproc_create(void (*func)(void *), void *arg, *newpp = p2; /* set up arg0 for 'ps', et al */ - va_start(ap, fmt); - vsnprintf(p2->p_comm, sizeof(p2->p_comm), fmt, ap); - va_end(ap); + strcpy(p2->p_comm, tdname); td = FIRST_THREAD_IN_PROC(p2); - va_start(ap, fmt); - vsnprintf(td->td_name, sizeof(td->td_name), fmt, ap); - va_end(ap); + strcpy(td->td_name, tdname); #ifdef KTR sched_clear_tdname(td); #endif @@ -142,6 +137,23 @@ kproc_create(void (*func)(void *), void *arg, return (0); } +int +kproc_create(void (*func)(void *), void *arg, + struct proc **newpp, int flags, int pages, const char *fmt, ...) +{ + va_list ap; + int error; + char tdname[MAXCOMLEN + 1]; + + va_start(ap, fmt); + vsnprintf(tdname, sizeof(tdname), fmt, ap); + va_end(ap); + DROP_GIANT(); + error = kproc_create1(func, arg, newpp, flags, pages, tdname); + PICKUP_GIANT(); + return (error); +} + void kproc_exit(int ecode) { @@ -250,11 +262,10 @@ kthread_start(const void *udata) * ** XXX fix this --> flags are flags to fork1 (in unistd.h) * fmt and following will be *printf'd into (*newtd)->td_name (for ps, etc.). */ -int -kthread_add(void (*func)(void *), void *arg, struct proc *p, - struct thread **newtdp, int flags, int pages, const char *fmt, ...) +static int +kthread_add1(void (*func)(void *), void *arg, struct proc *p, + struct thread **newtdp, int flags, int pages, const char *tdname) { - va_list ap; struct thread *newtd, *oldtd; if (!proc0.p_stats) @@ -278,9 +289,7 @@ kthread_add(void (*func)(void *), void *arg, struct proc *p, __rangeof(struct thread, td_startcopy, td_endcopy)); /* set up arg0 for 'ps', et al */ - va_start(ap, fmt); - vsnprintf(newtd->td_name, sizeof(newtd->td_name), fmt, ap); - va_end(ap); + strcpy(newtd->td_name, tdname); TSTHREAD(newtd, newtd->td_name); @@ -323,6 +332,23 @@ kthread_add(void (*func)(void *), void *arg, struct proc *p, return (0); } +int +kthread_add(void (*func)(void *), void *arg, struct proc *p, + struct thread **newtdp, int flags, int pages, const char *fmt, ...) +{ + va_list ap; + int error; + char tdname[MAXCOMLEN + 1]; + + va_start(ap, fmt); + vsnprintf(tdname, sizeof(tdname), fmt, ap); + va_end(ap); + DROP_GIANT(); + error = kthread_add1(func, arg, p, newtdp, flags, pages, tdname); + PICKUP_GIANT(); + return (error); +} + void kthread_exit(void) {