From nobody Wed Nov 04 16:23:21 2026 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 4jKW2d45YYz6y9nZ for ; Wed, 04 Nov 2026 16:23:21 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jKW2d20zmz4kJx for ; Wed, 04 Nov 2026 16:23:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793809401; 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=LQzj557bDM8M27nw1p1QvuNC/KL+KO0s6WE2OnQpj2M=; b=MXQ3uhy2kbSE9esu39kS9iu14jutcNNKYiHCWB0W65gHle1R1jG7DTdyTNTyYI5PVQ33Dq F+bHepGXklcoCC0Jqwr4lG4saIpDsnhYf8HiXgrThJ3oSYQ9+eZZYlfxjKnolBGLRs+5ZX WfzZKl1vwFDeMFVTl4ZAGuaFxg9rdDKcXrcAbOq5j15WRSl4sQKJrQxPJdrldzB+fvVCrP 40TOiwDKSfB496dD8OitirB7uU7QIdtGAeefxtg+LZfHPcnjq8ZXllQcew2NkzXqn/L+wt 0tOpmoLgawgwZYWY+cfpxaLqTp2JG1CPSHW7IGgb2oTdnCPHuzCrhihpTAtp1g== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793809401; b=pgTGqVBFXc68e5eB4dwxQtC9MR8Pe+Q3rpiHohqzg7za43lxuQVnquUFBNf7LbrDB0hRsk UaAl0LWWj86NE38y9jMBJ9NzzP5okpoEd3zjS69ZCdDYMuHFeTtL9TW4Kmibc0yOfxvAHP vTkI8UFMC2u6hgHS3JJmTTiTewC51SsAQlkzuyHsev82DFBj4/zC773UKRuGHaK+MxkHnN fcrDox8Ck90o6+mILNJlE+L+Xjysh4/dD6Yf947/uttZzpalKk9sEZPX16hXYlD4gVgGtq FKDq9F5Y4lCdQHAQ2U9AQAjCaQpGgaxnEP3sM9IY9KFq2ApX7vipb1QmS725mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793809401; 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=LQzj557bDM8M27nw1p1QvuNC/KL+KO0s6WE2OnQpj2M=; b=FqXyuKJVposSZTsR4dQOVLMjG/2Hky/xpDprW0SUc6sd2My1imfUL3cKVrJ48izTn22qzp 26LLrLB7Fjtjij+mDNELOu8xkfbs5ZqTfnQb6FOdyOuMsPv1iibreXyxXXvh05XyK5SyZh n6l8SYC2P6NCrSLK+5ybNytw4T0N6cN29JZsrdBialDV+ON6GAmC+ZLoVaUYuWRRPYvH3h dfpVbAlVyml0pUzBAT1cfwZSRECrZs8niMbGbFgptOS5I2oqUl706EgRyy3dIUaZcvMD1M AyMBw9hIa3/f2lzFeTPE2YZrGD8MO39Oh0k2hK7YCc1LtQ/Fr2hGbK2D9X74mw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jKW2d1MCMz18tk for ; Wed, 04 Nov 2026 16:23:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 20224 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 04 Nov 2026 16:23:21 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 5276fba9fd55 - main - pwddesc: add sharecount List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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: 5276fba9fd55bf2e79c54df18a70b46d11cc15a1 Auto-Submitted: auto-generated Date: Wed, 04 Nov 2026 16:23:21 +0000 Message-Id: <6aeb5bf9.20224.79702c90@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=5276fba9fd55bf2e79c54df18a70b46d11cc15a1 commit 5276fba9fd55bf2e79c54df18a70b46d11cc15a1 Author: Konstantin Belousov AuthorDate: 2026-10-21 22:54:59 +0000 Commit: Konstantin Belousov CommitDate: 2026-11-04 16:23:11 +0000 pwddesc: add sharecount The pd_refcount field counts both sharing processes and the transient pdhold() references taken by sysctls and mountcheckdirs(), so it cannot answer "is this pwddesc shared". As a result pdunshare() made needless copies while the pwddesc was held, and a copy made while mountcheckdirs() held it lost the cwd/root update. Add pd_sharecount, counting only processes using the pwddesc, and use it for the sharing decision. Existing pd_refcount still manages the lifetime. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D60963 --- sys/kern/kern_descrip.c | 9 ++++++++- sys/sys/filedesc.h | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 0aafaa8bdb9f..0fa8210b71c0 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -2446,6 +2446,7 @@ pdinit(struct pwddesc *pdp, bool keeplock) PWDDESC_LOCK_INIT(newpdp); refcount_init(&newpdp->pd_refcount, 1); + refcount_init(&newpdp->pd_sharecount, 1); newpdp->pd_cmask = CMASK; if (pdp == NULL) { @@ -2527,6 +2528,7 @@ pddrop(struct pwddesc *pdp) PWDDESC_XUNLOCK(pdp); return; } + MPASS(refcount_load(&pdp->pd_sharecount) == 0); pwd = PWDDESC_XLOCKED_LOAD_PWD(pdp); pwd_set(pdp, NULL); PWDDESC_XUNLOCK(pdp); @@ -2553,7 +2555,11 @@ fdshare(struct filedesc *fdp) struct pwddesc * pdshare(struct pwddesc *pdp) { + u_int old __diagused; + refcount_acquire(&pdp->pd_refcount); + old = refcount_acquire(&pdp->pd_sharecount); + MPASS(old > 0); return (pdp); } @@ -2585,7 +2591,7 @@ pdunshare(struct thread *td) p = td->td_proc; /* Not shared. */ - if (refcount_load(&p->p_pd->pd_refcount) == 1) + if (refcount_load(&p->p_pd->pd_sharecount) == 1) return; pdp = pdcopy(p->p_pd); @@ -2871,6 +2877,7 @@ pdescfree(struct thread *td) atomic_thread_fence_seq_cst(); PROC_WAIT_UNLOCKED(p); + (void)refcount_release(&pdp->pd_sharecount); pddrop(pdp); } diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index a2bb6c671dbb..d985641eb475 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -103,7 +103,8 @@ typedef SMR_POINTER(struct pwd *) smrpwd_t; struct pwddesc { struct mtx pd_lock; /* protects members of this struct */ smrpwd_t pd_pwd; /* directories */ - u_int pd_refcount; + u_int pd_refcount; /* lifetime */ + u_int pd_sharecount; /* processes sharing the descriptor */ u_short pd_cmask; /* mask for file creation */ };