From nobody Sat Sep 09 08:27:58 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 4RjR1p5LZmz4sPcK; Sat, 9 Sep 2023 08:27:58 +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 4RjR1p4Z36z4NLB; Sat, 9 Sep 2023 08:27:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694248078; 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=6ZPhH98oFnvpZqK5kErgaIptB+9Sn+kMDYmoar3acTI=; b=YxTSB6Vq2iTjZFzuJ0OoJxQoqDTIlfIAWHlfftkFchhWqm9rnUA1FqHSx0q/fNDdMAdefd MiYGv+oPEdp5cuUff+uM1vB+tu6YDVQ537gRc9W48HrS3cPEsHni5YpgJuy4MkDJFqp4ll gKYRlnI/GZAjNvqLEaPV1MfK7yTWwBz8LZ/7eMI9sW+pfd7OtOjwh4g8YBZfMgnj9bMV9o tPO8ZixOn7KN8X2Ua2UNCZFRIQoI+63+Q7BRbiBb8GNNXTiMNmpnzwY3LDvPx7xTq+waUm mzZOSjIqPsC1SEbptkvPq4qxLEs3ogTZEiYSO0Ppx9hgcN+EvP3IYpZpIaf8bQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694248078; a=rsa-sha256; cv=none; b=lwxw9B9OTE1+mf2CRMAm/vQ/JfwKf6yZ6JcGwOF0QJztNExtCnV7Mx77eJrJ71yQMhZGNu WEY5gGlgZjJHUz2avuTg8gj8p2N/lxXZydaKNfS6eDxlvUMH5Ia4bZn552vnm1qMZMq7yc xQXvJjnyKtDNzp3zga2KMuDM3OqxWXP8O04MpCl5D0s0MstBTWg79WQiMC6zCn2ddJ02W0 6gaqk2LfO32ebhs90KwOTM9C4/KPNEMCWxwdCcWYIJI3A2r5If+pxIz7cw0Tgb+hfiLPyu 2thyyKeT1cuMo+B78sEPP6VrTyJJ7Iz+Y/dQ6bGIQB/S2vduAJvu7hZT3MhA3Q== 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=1694248078; 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=6ZPhH98oFnvpZqK5kErgaIptB+9Sn+kMDYmoar3acTI=; b=pA2QRLJCzgaQdt9CqGqawD2Inv/cFhZ8FlkovpFCMOLX3eSXIRDf/vkPJtpS4ePQybhP9A ypj4ko5LYHRYMuxYPKLaZykhsa23ZydCltJhpDDuQQobdLTLScqkDxYjG9PYIw52qhBKqe KWDKulzAtpE0E6ALuUi+J4TjlDhFwYIBRE2N8Uq3gMdTfQZyO7Thrug9SuBv5ovkB0V7dr 0SrMcJXVZ5mni873bfszwEjcP8ssZMBp6ciPQQd/iJ3vjFnWFwyA6VqK/GLS7nnL2w7VQv nFtj+K4gj9uI3xYkHhOc57QX00N97uTmPEHt68rT88ylEeuKFtFP8/GjBEycKw== 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 4RjR1p3bRWz3Bb; Sat, 9 Sep 2023 08:27:58 +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 3898Rw04054050; Sat, 9 Sep 2023 08:27:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3898Rw09054047; Sat, 9 Sep 2023 08:27:58 GMT (envelope-from git) Date: Sat, 9 Sep 2023 08:27:58 GMT Message-Id: <202309090827.3898Rw09054047@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: a39c6d1ce008 - stable/13 - kern_kthread: fork1() does not handle locked Giant 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a39c6d1ce008180059ec32facdba92e1468b44b0 Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a39c6d1ce008180059ec32facdba92e1468b44b0 commit a39c6d1ce008180059ec32facdba92e1468b44b0 Author: Konstantin Belousov AuthorDate: 2023-09-02 07:16:48 +0000 Commit: Konstantin Belousov CommitDate: 2023-09-09 08:27:32 +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) {