git: 7e139187708a - stable/13 - iommu_gas: don't remove and insert boundary entry

From: Doug Moore <dougm_at_FreeBSD.org>
Date: Wed, 12 Oct 2022 02:32:34 UTC
The branch stable/13 has been updated by dougm:

URL: https://cgit.FreeBSD.org/src/commit/?id=7e139187708a5171d441f1c828d581bda0ab9cdc

commit 7e139187708a5171d441f1c828d581bda0ab9cdc
Author:     Doug Moore <dougm@FreeBSD.org>
AuthorDate: 2022-09-16 20:32:11 +0000
Commit:     Doug Moore <dougm@FreeBSD.org>
CommitDate: 2022-10-12 02:31:18 +0000

    iommu_gas: don't remove and insert boundary entry
    
    Avoid removing an item in iommu_gas_free_region only to reinsert it,
    by avoiding removing an entry that is either first_place or
    last_place.
    
    Reviewed by:    kib
    MFC after:      3 weeks
    Differential Revision:  https://reviews.freebsd.org/D36597
    
    (cherry picked from commit 87cd087a4ae7b272986ce3bcf27ffe4930f15e55)
---
 sys/dev/iommu/iommu_gas.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/sys/dev/iommu/iommu_gas.c b/sys/dev/iommu/iommu_gas.c
index ca5a614060fe..68e22f16c69f 100644
--- a/sys/dev/iommu/iommu_gas.c
+++ b/sys/dev/iommu/iommu_gas.c
@@ -580,7 +580,6 @@ void
 iommu_gas_free_region(struct iommu_map_entry *entry)
 {
 	struct iommu_domain *domain;
-	struct iommu_map_entry *next, *prev;
 
 	domain = entry->domain;
 	KASSERT((entry->flags & (IOMMU_MAP_ENTRY_PLACE | IOMMU_MAP_ENTRY_RMRR |
@@ -588,15 +587,10 @@ iommu_gas_free_region(struct iommu_map_entry *entry)
 	    ("non-RMRR entry %p %p", domain, entry));
 
 	IOMMU_DOMAIN_LOCK(domain);
-	prev = RB_PREV(iommu_gas_entries_tree, &domain->rb_root, entry);
-	next = RB_NEXT(iommu_gas_entries_tree, &domain->rb_root, entry);
-	iommu_gas_rb_remove(domain, entry);
+	if (entry != domain->first_place &&
+	    entry != domain->last_place)
+		iommu_gas_rb_remove(domain, entry);
 	entry->flags &= ~IOMMU_MAP_ENTRY_RMRR;
-
-	if (prev == NULL)
-		iommu_gas_rb_insert(domain, domain->first_place);
-	if (next == NULL)
-		iommu_gas_rb_insert(domain, domain->last_place);
 	IOMMU_DOMAIN_UNLOCK(domain);
 }
 
@@ -608,7 +602,7 @@ iommu_gas_remove_clip_left(struct iommu_domain *domain, iommu_gaddr_t start,
 
 	IOMMU_DOMAIN_ASSERT_LOCKED(domain);
 	MPASS(start <= end);
-	MPASS(end <= domain->last_place->end);
+	MPASS(end <= domain->end);
 
 	/*
 	 * Find an entry which contains the supplied guest's address