git: e9711ea5e2f5 - stable/13 - iommu_gas: Avoid double unmapping on error

From: Doug Moore <dougm_at_FreeBSD.org>
Date: Mon, 08 Aug 2022 03:22:03 UTC
The branch stable/13 has been updated by dougm:

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

commit e9711ea5e2f5749e0dc6602ae109c786c728d6f5
Author:     Alan Cox <alc@FreeBSD.org>
AuthorDate: 2022-07-21 06:53:54 +0000
Commit:     Doug Moore <dougm@FreeBSD.org>
CommitDate: 2022-08-08 03:16:49 +0000

    iommu_gas: Avoid double unmapping on error
    
    In the extremely unlikely case that the iommu_gas_map_region() call in
    bus_dma_iommu_load_ident() failed, we would attempt to unmap the failed
    entry twice, first in iommu_gas_map_region(), and a second time in the
    caller.  Once is enough, and twice is problematic because it leads to a
    second RB_REMOVE call on the same tree node.  Like it or not, RB_TREE
    does not handle that possibility.
    
    Reviewed by:    kib
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D35869
    
    (cherry picked from commit dfabdacb279ca603d008a0e7e952c5c59ac51da4)
---
 sys/dev/iommu/busdma_iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/dev/iommu/busdma_iommu.c b/sys/dev/iommu/busdma_iommu.c
index 594e685e074a..33549b4af011 100644
--- a/sys/dev/iommu/busdma_iommu.c
+++ b/sys/dev/iommu/busdma_iommu.c
@@ -1047,7 +1047,7 @@ bus_dma_iommu_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map1,
 		TAILQ_INSERT_TAIL(&map->map_entries, entry, dmamap_link);
 		IOMMU_DMAMAP_UNLOCK(map);
 	} else {
-		iommu_domain_unload_entry(entry, true);
+		iommu_gas_free_entry(domain, entry);
 	}
 	for (i = 0; i < atop(length); i++)
 		vm_page_putfake(ma[i]);