From nobody Tue Jan  2 00:42:44 2024
X-Original-To: dev-commits-src-branches@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 4T3vFw68bKz560HF;
	Tue,  2 Jan 2024 00:42:44 +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
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4T3vFw3Pntz3S3g;
	Tue,  2 Jan 2024 00:42:44 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1704156164;
	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=9Yc4gvPJfIxc2l8d9i84EOH4yYtIlSZC/BQAmnW4amg=;
	b=yrU3ziLha3OtNvI4ktTarCkWbo7A5LKLwg7/Ky4kE79oxMTHjU6hL+sxQfGMdCeGQGWwFL
	xegXUe/kYdhSRBSivNE3qN2bWC2ZvxTTRtFe3PS2m7mJgtWKwp0FanvEcAiJuZYr+TvUQD
	xQ66OkCqt/f0G8xSdfLQP5d1AzyL+GGyp1p3hLlX1TBizXZwZ38dS12qeYvzjZMEMws9pl
	BJ+WgSINdtAnm0DafbEF8Xr3dqmOh7qlcSWd8acHmgouqaN5iXW5ojozouBsfX5Z3qcHl0
	yPk1iGIoclliye6DZ9xv5d8p3X/KXKXFZyi19+7LUydE2KWdFJKxCiKoOq/Z7A==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704156164; a=rsa-sha256; cv=none;
	b=lJLQShihg/354mTzc/cvhWwAdCNeUAfQLbI4qTxx7G6IvXX9lKSKDMNhhC0OXFb6flIpOS
	n3OROFoSWBQ1l9XKFQHhLS2QULWR8TquLl+lRRyFrcBJZ9y4RjwtvRcO+bMpOSD5o+fN6r
	yGaW2ngBUgZwudxYRUvifjLKt5oi4nbyiKRc1QOMuI7zHH+m0+C8MCo9SV6BAyi99xX9NI
	DZplR9PkU37DtnnVQBYtj33KxAgouJzLGs2T/CBVbuA73xcXIeEPlbUbipG+BTPKUGFxgI
	QO0v65EJJ7l3IegcZSFqKb2hGS/4W39JeNi272KtqbSMLj/CPzHPHi00ZIZ9vA==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1704156164;
	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=9Yc4gvPJfIxc2l8d9i84EOH4yYtIlSZC/BQAmnW4amg=;
	b=KpfrpxpFDF9f0MreU+pG4+8NmhInpcTJPAVuIFd36D/UVuhKXkC3eRr6r/fuLVb66Hsxce
	sul16crOseYjJgj3GxhDTHoE6Ne76LQL2xkoW5M144uQEXXzSIy4yn12AlF5IzxtF3biGt
	mp15L2cj3A1M3BwSmkqHjzT8x2eT+i7EIb2vR/YMYVmBy/wQgF+UcGHJQO6jQ9H2FZDyEz
	ENON1rGWf45N5Vw3y432ZkkllkmhogO0376Jkrjufw0kQeO0i+ZGX7zXoknuLtplD0eN9a
	p/OoJgEhpTZAwfwkvlFHZK3uvzkgzvWPd30dJpRcSsx384jlEbNPbrA17GUyZA==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	(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)
	(Client did not present a certificate)
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4T3vFw2WFszfv6;
	Tue,  2 Jan 2024 00:42:44 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org ([127.0.1.44])
	by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4020giCT004163;
	Tue, 2 Jan 2024 00:42:44 GMT
	(envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
	by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4020gijP004159;
	Tue, 2 Jan 2024 00:42:44 GMT
	(envelope-from git)
Date: Tue, 2 Jan 2024 00:42:44 GMT
Message-Id: <202401020042.4020gijP004159@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
        dev-commits-src-branches@FreeBSD.org
From: Konstantin Belousov <kib@FreeBSD.org>
Subject: git: 9f39aabec76c - stable/13 - iommu: add
  iommu_gas_remove_locked()
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
Sender: owner-dev-commits-src-branches@freebsd.org
X-BeenThere: dev-commits-src-branches@freebsd.org
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/stable/13
X-Git-Reftype: branch
X-Git-Commit: 9f39aabec76ca4152cd6bbd808b816b80cf6b421
Auto-Submitted: auto-generated

The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=9f39aabec76ca4152cd6bbd808b816b80cf6b421

commit 9f39aabec76ca4152cd6bbd808b816b80cf6b421
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-12-14 02:41:31 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-01-02 00:42:13 +0000

    iommu: add iommu_gas_remove_locked()
    
    (cherry picked from commit 273b4de3462d7825ebe4ace7a1930f098311287f)
---
 sys/dev/iommu/iommu_gas.c | 83 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 57 insertions(+), 26 deletions(-)

diff --git a/sys/dev/iommu/iommu_gas.c b/sys/dev/iommu/iommu_gas.c
index dc850747512a..9a74854f926f 100644
--- a/sys/dev/iommu/iommu_gas.c
+++ b/sys/dev/iommu/iommu_gas.c
@@ -708,28 +708,20 @@ iommu_gas_remove_unmap(struct iommu_domain *domain,
 	TAILQ_INSERT_TAIL(gcp, entry, dmamap_link);
 }
 
-/*
- * Remove specified range from the GAS of the domain.  Note that the
- * removal is not guaranteed to occur upon the function return, it
- * might be finalized some time after, when hardware reports that
- * (queued) IOTLB invalidation was performed.
- */
-void
-iommu_gas_remove(struct iommu_domain *domain, iommu_gaddr_t start,
-    iommu_gaddr_t size)
+static void
+iommu_gas_remove_locked(struct iommu_domain *domain,
+    iommu_gaddr_t start, iommu_gaddr_t size,
+    struct iommu_map_entries_tailq *gc,
+    struct iommu_map_entry **r1, struct iommu_map_entry **r2)
 {
-	struct iommu_map_entry *entry, *nentry, *r1, *r2;
-	struct iommu_map_entries_tailq gc;
+	struct iommu_map_entry *entry, *nentry;
 	iommu_gaddr_t end;
 
-	end = start + size;
-	r1 = iommu_gas_alloc_entry(domain, IOMMU_PGF_WAITOK);
-	r2 = iommu_gas_alloc_entry(domain, IOMMU_PGF_WAITOK);
-	TAILQ_INIT(&gc);
+	IOMMU_DOMAIN_ASSERT_LOCKED(domain);
 
-	IOMMU_DOMAIN_LOCK(domain);
+	end = start + size;
 
-	nentry = iommu_gas_remove_clip_left(domain, start, end, &r1);
+	nentry = iommu_gas_remove_clip_left(domain, start, end, r1);
 	RB_FOREACH_FROM(entry, iommu_gas_entries_tree, nentry) {
 		if (entry->start >= end)
 			break;
@@ -738,11 +730,11 @@ iommu_gas_remove(struct iommu_domain *domain, iommu_gaddr_t start,
 		    entry->start, entry->end, start));
 		if ((entry->flags & IOMMU_MAP_ENTRY_RMRR) != 0)
 			continue;
-		iommu_gas_remove_unmap(domain, entry, &gc);
+		iommu_gas_remove_unmap(domain, entry, gc);
 	}
-	if (iommu_gas_remove_clip_right(domain, end, entry, r2)) {
-		iommu_gas_remove_unmap(domain, r2, &gc);
-		r2 = NULL;
+	if (iommu_gas_remove_clip_right(domain, end, entry, *r2)) {
+		iommu_gas_remove_unmap(domain, *r2, gc);
+		*r2 = NULL;
 	}
 
 #ifdef INVARIANTS
@@ -755,13 +747,52 @@ iommu_gas_remove(struct iommu_domain *domain, iommu_gaddr_t start,
 		    entry->start, entry->end, start, end));
 	}
 #endif
+}
+
+static void
+iommu_gas_remove_init(struct iommu_domain *domain,
+    struct iommu_map_entries_tailq *gc, struct iommu_map_entry **r1,
+    struct iommu_map_entry **r2)
+{
+	TAILQ_INIT(gc);
+	*r1 = iommu_gas_alloc_entry(domain, IOMMU_PGF_WAITOK);
+	*r2 = iommu_gas_alloc_entry(domain, IOMMU_PGF_WAITOK);
+}
 
+static void
+iommu_gas_remove_cleanup(struct iommu_domain *domain,
+    struct iommu_map_entries_tailq *gc, struct iommu_map_entry **r1,
+    struct iommu_map_entry **r2)
+{
+	if (*r1 != NULL) {
+		iommu_gas_free_entry(*r1);
+		*r1 = NULL;
+	}
+	if (*r2 != NULL) {
+		iommu_gas_free_entry(*r2);
+		*r2 = NULL;
+	}
+	iommu_domain_unload(domain, gc, true);
+}
+
+/*
+ * Remove specified range from the GAS of the domain.  Note that the
+ * removal is not guaranteed to occur upon the function return, it
+ * might be finalized some time after, when hardware reports that
+ * (queued) IOTLB invalidation was performed.
+ */
+void
+iommu_gas_remove(struct iommu_domain *domain, iommu_gaddr_t start,
+    iommu_gaddr_t size)
+{
+	struct iommu_map_entry *r1, *r2;
+	struct iommu_map_entries_tailq gc;
+
+	iommu_gas_remove_init(domain, &gc, &r1, &r2);
+	IOMMU_DOMAIN_LOCK(domain);
+	iommu_gas_remove_locked(domain, start, size, &gc, &r1, &r2);
 	IOMMU_DOMAIN_UNLOCK(domain);
-	if (r1 != NULL)
-		iommu_gas_free_entry(r1);
-	if (r2 != NULL)
-		iommu_gas_free_entry(r2);
-	iommu_domain_unload(domain, &gc, true);
+	iommu_gas_remove_cleanup(domain, &gc, &r1, &r2);
 }
 
 int