Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Jul 2020 21:57:03 +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: r363112 - head/sys/kern
Message-ID:  <202007112157.06BLv32u086316@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Sat Jul 11 21:57:03 2020
New Revision: 363112
URL: https://svnweb.freebsd.org/changeset/base/363112

Log:
  fd: stop looping in pwd_hold
  
  We don't expect to fail acquiring the reference unless running into a corner
  case. Just in case ensure forward progress by taking the lock.
  
  Reviewed by:	kib, markj
  Differential Revision: https://reviews.freebsd.org/D25616

Modified:
  head/sys/kern/kern_descrip.c

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Sat Jul 11 20:56:57 2020	(r363111)
+++ head/sys/kern/kern_descrip.c	Sat Jul 11 21:57:03 2020	(r363112)
@@ -3347,13 +3347,17 @@ pwd_hold(struct thread *td)
 	fdp = td->td_proc->p_fd;
 
 	smr_enter(pwd_smr);
-	for (;;) {
-		pwd = smr_entered_load(&fdp->fd_pwd, pwd_smr);
-		MPASS(pwd != NULL);
-		if (refcount_acquire_if_not_zero(&pwd->pwd_refcount))
-			break;
+	pwd = smr_entered_load(&fdp->fd_pwd, pwd_smr);
+	MPASS(pwd != NULL);
+	if (__predict_true(refcount_acquire_if_not_zero(&pwd->pwd_refcount))) {
+		smr_exit(pwd_smr);
+		return (pwd);
 	}
 	smr_exit(pwd_smr);
+	FILEDESC_SLOCK(fdp);
+	pwd = pwd_hold_filedesc(fdp);
+	MPASS(pwd != NULL);
+	FILEDESC_SUNLOCK(fdp);
 	return (pwd);
 }
 



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