Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Dec 2020 17:17:23 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r368516 - head/sys/kern
Message-ID:  <202012101717.0BAHHNZh077672@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Thu Dec 10 17:17:22 2020
New Revision: 368516
URL: https://svnweb.freebsd.org/changeset/base/368516

Log:
  fd: make serialization in fdescfree_fds conditional on hold count
  
  p_fd nullification in fdescfree serializes against new threads transitioning
  the count 1 -> 2, meaning that fdescfree_fds observing the count of 1 can
  safely assume there is nobody else using the table. Losing the race and
  observing > 1 is harmless.
  
  Reviewed by:	markj
  Differential Revision:	https://reviews.freebsd.org/D27522

Modified:
  head/sys/kern/kern_descrip.c

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Thu Dec 10 13:32:51 2020	(r368515)
+++ head/sys/kern/kern_descrip.c	Thu Dec 10 17:17:22 2020	(r368516)
@@ -2466,9 +2466,13 @@ fdescfree_fds(struct thread *td, struct filedesc *fdp,
 	KASSERT(refcount_load(&fdp->fd_refcnt) == 0,
 	    ("%s: fd table %p carries references", __func__, fdp));
 
-	/* Serialize with threads iterating over the table. */
-	FILEDESC_XLOCK(fdp);
-	FILEDESC_XUNLOCK(fdp);
+	/*
+	 * Serialize with threads iterating over the table, if any.
+	 */
+	if (refcount_load(&fdp->fd_holdcnt) > 1) {
+		FILEDESC_XLOCK(fdp);
+		FILEDESC_XUNLOCK(fdp);
+	}
 
 	lastfile = fdlastfile_single(fdp);
 	for (i = 0; i <= lastfile; i++) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012101717.0BAHHNZh077672>