git: dfabdacb279c - main - iommu_gas: Avoid double unmapping on error

From: Alan Cox <alc_at_FreeBSD.org>
Date: Thu, 21 Jul 2022 07:01:25 UTC
The branch main has been updated by alc:

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

commit dfabdacb279ca603d008a0e7e952c5c59ac51da4
Author:     Alan Cox <alc@FreeBSD.org>
AuthorDate: 2022-07-21 06:53:54 +0000
Commit:     Alan Cox <alc@FreeBSD.org>
CommitDate: 2022-07-21 07:00:46 +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
---
 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 10e7476b35eb..67e82fe43e58 100644
--- a/sys/dev/iommu/busdma_iommu.c
+++ b/sys/dev/iommu/busdma_iommu.c
@@ -1055,7 +1055,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]);