From owner-svn-src-all@freebsd.org  Sat Jul 27 16:11:05 2019
Return-Path: <owner-svn-src-all@freebsd.org>
Delivered-To: svn-src-all@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 84610BCC35;
 Sat, 27 Jul 2019 16:11:05 +0000 (UTC)
 (envelope-from markj@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)
 server-signature RSA-PSS (4096 bits)
 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 672448B2F7;
 Sat, 27 Jul 2019 16:11:05 +0000 (UTC)
 (envelope-from markj@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2610:1c1:1:6068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 389701CA3;
 Sat, 27 Jul 2019 16:11:05 +0000 (UTC)
 (envelope-from markj@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x6RGB5Li032306;
 Sat, 27 Jul 2019 16:11:05 GMT (envelope-from markj@FreeBSD.org)
Received: (from markj@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id x6RGB4cJ032303;
 Sat, 27 Jul 2019 16:11:04 GMT (envelope-from markj@FreeBSD.org)
Message-Id: <201907271611.x6RGB4cJ032303@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: markj set sender to
 markj@FreeBSD.org using -f
From: Mark Johnston <markj@FreeBSD.org>
Date: Sat, 27 Jul 2019 16:11:04 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject: svn commit: r350373 - in stable/12/sys: kern sys
X-SVN-Group: stable-12
X-SVN-Commit-Author: markj
X-SVN-Commit-Paths: in stable/12/sys: kern sys
X-SVN-Commit-Revision: 350373
X-SVN-Commit-Repository: base
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Rspamd-Queue-Id: 672448B2F7
X-Spamd-Bar: --
Authentication-Results: mx1.freebsd.org
X-Spamd-Result: default: False [-2.95 / 15.00];
 local_wl_from(0.00)[FreeBSD.org];
 NEURAL_HAM_MEDIUM(-1.00)[-1.000,0];
 NEURAL_HAM_LONG(-1.00)[-1.000,0];
 NEURAL_HAM_SHORT(-0.95)[-0.951,0];
 ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]
X-BeenThere: svn-src-all@freebsd.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "SVN commit messages for the entire src tree \(except for &quot;
 user&quot; and &quot; projects&quot; \)" <svn-src-all.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-all>,
 <mailto:svn-src-all-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-all/>
List-Post: <mailto:svn-src-all@freebsd.org>
List-Help: <mailto:svn-src-all-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-all>,
 <mailto:svn-src-all-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Jul 2019 16:11:05 -0000

Author: markj
Date: Sat Jul 27 16:11:04 2019
New Revision: 350373
URL: https://svnweb.freebsd.org/changeset/base/350373

Log:
  MFC r350310:
  Fix the turnstile_lock() KPI.

Modified:
  stable/12/sys/kern/subr_epoch.c
  stable/12/sys/kern/subr_turnstile.c
  stable/12/sys/sys/turnstile.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/kern/subr_epoch.c
==============================================================================
--- stable/12/sys/kern/subr_epoch.c	Sat Jul 27 15:04:10 2019	(r350372)
+++ stable/12/sys/kern/subr_epoch.c	Sat Jul 27 16:11:04 2019	(r350373)
@@ -440,26 +440,20 @@ epoch_block_handler_preempt(struct ck_epoch *global __
 			 */
 			critical_enter();
 			thread_unlock(td);
-			owner = turnstile_lock(ts, &lock);
-			/*
-			 * The owner pointer indicates that the lock succeeded.
-			 * Only in case we hold the lock and the turnstile we
-			 * locked is still the one that curwaittd is blocked on
-			 * can we continue. Otherwise the turnstile pointer has
-			 * been changed out from underneath us, as in the case
-			 * where the lock holder has signalled curwaittd,
-			 * and we need to continue.
-			 */
-			if (owner != NULL && ts == curwaittd->td_blocked) {
-				MPASS(TD_IS_INHIBITED(curwaittd) &&
-				    TD_ON_LOCK(curwaittd));
-				critical_exit();
-				turnstile_wait(ts, owner, curwaittd->td_tsqueue);
-				counter_u64_add(turnstile_count, 1);
-				thread_lock(td);
-				return;
-			} else if (owner != NULL)
+
+			if (turnstile_lock(ts, &lock, &owner)) {
+				if (ts == curwaittd->td_blocked) {
+					MPASS(TD_IS_INHIBITED(curwaittd) &&
+					    TD_ON_LOCK(curwaittd));
+					critical_exit();
+					turnstile_wait(ts, owner,
+					    curwaittd->td_tsqueue);
+					counter_u64_add(turnstile_count, 1);
+					thread_lock(td);
+					return;
+				}
 				turnstile_unlock(ts, lock);
+			}
 			thread_lock(td);
 			critical_exit();
 			KASSERT(td->td_locks == locksheld,

Modified: stable/12/sys/kern/subr_turnstile.c
==============================================================================
--- stable/12/sys/kern/subr_turnstile.c	Sat Jul 27 15:04:10 2019	(r350372)
+++ stable/12/sys/kern/subr_turnstile.c	Sat Jul 27 16:11:04 2019	(r350373)
@@ -566,24 +566,26 @@ turnstile_trywait(struct lock_object *lock)
 	return (ts);
 }
 
-struct thread *
-turnstile_lock(struct turnstile *ts, struct lock_object **lockp)
+bool
+turnstile_lock(struct turnstile *ts, struct lock_object **lockp,
+    struct thread **tdp)
 {
 	struct turnstile_chain *tc;
 	struct lock_object *lock;
 
 	if ((lock = ts->ts_lockobj) == NULL)
-		return (NULL);
+		return (false);
 	tc = TC_LOOKUP(lock);
 	mtx_lock_spin(&tc->tc_lock);
 	mtx_lock_spin(&ts->ts_lock);
 	if (__predict_false(lock != ts->ts_lockobj)) {
 		mtx_unlock_spin(&tc->tc_lock);
 		mtx_unlock_spin(&ts->ts_lock);
-		return (NULL);
+		return (false);
 	}
 	*lockp = lock;
-	return (ts->ts_owner);
+	*tdp = ts->ts_owner;
+	return (true);
 }
 
 void

Modified: stable/12/sys/sys/turnstile.h
==============================================================================
--- stable/12/sys/sys/turnstile.h	Sat Jul 27 15:04:10 2019	(r350372)
+++ stable/12/sys/sys/turnstile.h	Sat Jul 27 16:11:04 2019	(r350373)
@@ -100,7 +100,8 @@ int	turnstile_signal(struct turnstile *, int);
 struct turnstile *turnstile_trywait(struct lock_object *);
 void	turnstile_unpend(struct turnstile *);
 void	turnstile_wait(struct turnstile *, struct thread *, int);
-struct thread *turnstile_lock(struct turnstile *, struct lock_object **);
+bool	turnstile_lock(struct turnstile *, struct lock_object **,
+	    struct thread **);
 void	turnstile_unlock(struct turnstile *, struct lock_object *);
 void	turnstile_assert(struct turnstile *);
 #endif	/* _KERNEL */