From owner-dev-commits-src-main@freebsd.org Sun Jan 10 02:42:00 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CA6EA4EACE9; Sun, 10 Jan 2021 02:42:00 +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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DD1M81RhXz4pYd; Sun, 10 Jan 2021 02:41:56 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 765AA209C7; Sun, 10 Jan 2021 02:41:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10A2ftMs057624; Sun, 10 Jan 2021 02:41:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10A2ft9Q057623; Sun, 10 Jan 2021 02:41:55 GMT (envelope-from git) Date: Sun, 10 Jan 2021 02:41:55 GMT Message-Id: <202101100241.10A2ft9Q057623@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 4daea938130b - main - Lock proctree in around fill_kinfo_proc(). 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/main X-Git-Reftype: branch X-Git-Commit: 4daea938130b4a219e01d678e9499f0bdb715f82 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jan 2021 02:42:01 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4daea938130b4a219e01d678e9499f0bdb715f82 commit 4daea938130b4a219e01d678e9499f0bdb715f82 Author: Konstantin Belousov AuthorDate: 2020-12-31 22:29:40 +0000 Commit: Konstantin Belousov CommitDate: 2021-01-10 02:41:20 +0000 Lock proctree in around fill_kinfo_proc(). Proctree lock is needed for correct calculation and collection of the job-control related data in kinfo_proc. There was even an XXX comment about it. Satisfy locking and lock ordering requirements by taking proctree lock around pass over each bucket in proc_iterate(), and in sysctl_kern_proc() and note_procstat_proc() for individual process reporting. Reviewed by: jilles Tested by: pho MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D27871 --- sys/kern/imgact_elf.c | 2 ++ sys/kern/kern_proc.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index f6482bfcfb21..4f5d5a9a0736 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -2386,8 +2386,10 @@ __elfN(note_procstat_proc)(void *arg, struct sbuf *sb, size_t *sizep) KASSERT(*sizep == size, ("invalid size")); structsize = sizeof(elf_kinfo_proc_t); sbuf_bcat(sb, &structsize, sizeof(structsize)); + sx_slock(&proctree_lock); PROC_LOCK(p); kern_proc_out(p, sb, ELF_KERN_PROC_MASK); + sx_sunlock(&proctree_lock); } *sizep = size; } diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index fab1df795799..c63d136a3046 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1653,6 +1653,7 @@ proc_iterate(int (*cb)(struct proc *, void *), void *cbarg) int error, i, j; for (i = 0; i < pidhashlock + 1; i++) { + sx_slock(&proctree_lock); sx_slock(&pidhashtbl_lock[i]); for (j = i; j <= pidhash; j += pidhashlock + 1) { LIST_FOREACH(p, &pidhashtbl[j], p_hash) { @@ -1662,11 +1663,13 @@ proc_iterate(int (*cb)(struct proc *, void *), void *cbarg) PROC_LOCK_ASSERT(p, MA_NOTOWNED); if (error != 0) { sx_sunlock(&pidhashtbl_lock[i]); + sx_sunlock(&proctree_lock); return (error); } } } sx_sunlock(&pidhashtbl_lock[i]); + sx_sunlock(&proctree_lock); } return (0); } @@ -1792,9 +1795,11 @@ sysctl_kern_proc(SYSCTL_HANDLER_ARGS) error = sysctl_wire_old_buffer(req, 0); if (error) return (error); + sx_slock(&proctree_lock); error = pget((pid_t)name[0], PGET_CANSEE, &p); if (error == 0) error = sysctl_out_proc(p, req, flags); + sx_sunlock(&proctree_lock); return (error); }