svn commit: r368516 - head/sys/kern

Mateusz Guzik mjg at FreeBSD.org
Thu Dec 10 17:17:23 UTC 2020


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++) {


More information about the svn-src-head mailing list