git: 42e4938fdbf8 - main - vm_assign_pptdev: only call vm_iommu_map() once

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 09 Apr 2025 12:20:14 UTC
The branch main has been updated by kib:

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

commit 42e4938fdbf8e2b5180e0d6aeb0075c589cf3bca
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-04-09 11:20:30 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-04-09 12:20:08 +0000

    vm_assign_pptdev: only call vm_iommu_map() once
    
    for the first assigned pass-through device.
    
    PR:     285976
    Sponsored by:   The FreeBSD Foundation
---
 sys/amd64/vmm/vmm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c
index bd703f63b557..c42da02d0bf6 100644
--- a/sys/amd64/vmm/vmm.c
+++ b/sys/amd64/vmm/vmm.c
@@ -851,6 +851,7 @@ vm_assign_pptdev(struct vm *vm, int bus, int slot, int func)
 {
 	int error;
 	vm_paddr_t maxaddr;
+	bool map = false;
 
 	/* Set up the IOMMU to do the 'gpa' to 'hpa' translation */
 	if (ppt_assigned_devices(vm) == 0) {
@@ -860,12 +861,12 @@ vm_assign_pptdev(struct vm *vm, int bus, int slot, int func)
 		vm->iommu = iommu_create_domain(maxaddr);
 		if (vm->iommu == NULL)
 			return (ENXIO);
+		map = true;
 	}
 
 	error = ppt_assign_device(vm, bus, slot, func);
-	if (error != 0)
-		return (error);
-	error = vm_iommu_map(vm);
+	if (error == 0 && map)
+		error = vm_iommu_map(vm);
 	return (error);
 }