The branch main has been updated by markj:

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

commit 86150ed98b7903feaba942f01619e74894cd23c4
Author:     Mark Johnston <[email protected]>
AuthorDate: 2026-02-06 15:30:56 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2026-02-06 15:38:51 +0000

    bhyve: Simplify passthru_msix_addr()
    
    It can use the passthru_mmio_map() helper function.  Make that change,
    and also make passthru_mmio_map() use EPRINTLN to fix formatting when
    the guest console is stdio.
    
    Reviewed by:    corvink, jhb
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D55067
---
 usr.sbin/bhyve/pci_passthru.c | 80 ++++++++++++++-----------------------------
 1 file changed, 26 insertions(+), 54 deletions(-)

diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c
index 8ddcd8bd56e8..662390413dbc 100644
--- a/usr.sbin/bhyve/pci_passthru.c
+++ b/usr.sbin/bhyve/pci_passthru.c
@@ -1310,58 +1310,6 @@ passthru_read(struct pci_devinst *pi, int baridx, 
uint64_t offset, int size)
        return (val);
 }
 
-static void
-passthru_msix_addr(struct pci_devinst *pi, int baridx, int enabled,
-    uint64_t address)
-{
-       struct passthru_softc *sc;
-       size_t remaining;
-       uint32_t table_size, table_offset;
-
-       sc = pi->pi_arg;
-       table_offset = rounddown2(pi->pi_msix.table_offset, 4096);
-       if (table_offset > 0) {
-               if (!enabled) {
-                       if (vm_unmap_pptdev_mmio(pi->pi_vmctx,
-                                                sc->psc_sel.pc_bus,
-                                                sc->psc_sel.pc_dev,
-                                                sc->psc_sel.pc_func, address,
-                                                table_offset) != 0)
-                               warnx("pci_passthru: unmap_pptdev_mmio failed");
-               } else {
-                       if (vm_map_pptdev_mmio(pi->pi_vmctx, sc->psc_sel.pc_bus,
-                                              sc->psc_sel.pc_dev,
-                                              sc->psc_sel.pc_func, address,
-                                              table_offset,
-                                              sc->psc_bar[baridx].addr) != 0)
-                               warnx("pci_passthru: map_pptdev_mmio failed");
-               }
-       }
-       table_size = pi->pi_msix.table_offset - table_offset;
-       table_size += pi->pi_msix.table_count * MSIX_TABLE_ENTRY_SIZE;
-       table_size = roundup2(table_size, 4096);
-       remaining = pi->pi_bar[baridx].size - table_offset - table_size;
-       if (remaining > 0) {
-               address += table_offset + table_size;
-               if (!enabled) {
-                       if (vm_unmap_pptdev_mmio(pi->pi_vmctx,
-                                                sc->psc_sel.pc_bus,
-                                                sc->psc_sel.pc_dev,
-                                                sc->psc_sel.pc_func, address,
-                                                remaining) != 0)
-                               warnx("pci_passthru: unmap_pptdev_mmio failed");
-               } else {
-                       if (vm_map_pptdev_mmio(pi->pi_vmctx, sc->psc_sel.pc_bus,
-                                              sc->psc_sel.pc_dev,
-                                              sc->psc_sel.pc_func, address,
-                                              remaining,
-                                              sc->psc_bar[baridx].addr +
-                                              table_offset + table_size) != 0)
-                               warnx("pci_passthru: map_pptdev_mmio failed");
-               }
-       }
-}
-
 static int
 passthru_mmio_map(struct pci_devinst *pi, int baridx, int enabled,
     uint64_t address, uint64_t off, uint64_t size)
@@ -1373,14 +1321,16 @@ passthru_mmio_map(struct pci_devinst *pi, int baridx, 
int enabled,
                if (vm_unmap_pptdev_mmio(pi->pi_vmctx, sc->psc_sel.pc_bus,
                    sc->psc_sel.pc_dev, sc->psc_sel.pc_func, address + off,
                    size) != 0) {
-                       warnx("pci_passthru: unmap_pptdev_mmio failed");
+                       EPRINTLN("pci_passthru: unmap_pptdev_mmio failed: %s",
+                           strerror(errno));
                        return (-1);
                }
        } else {
                if (vm_map_pptdev_mmio(pi->pi_vmctx, sc->psc_sel.pc_bus,
                    sc->psc_sel.pc_dev, sc->psc_sel.pc_func, address + off,
                    size, sc->psc_bar[baridx].addr + off) != 0) {
-                       warnx("pci_passthru: map_pptdev_mmio failed");
+                       EPRINTLN("pci_passthru: map_pptdev_mmio failed: %s",
+                           strerror(errno));
                        return (-1);
                }
        }
@@ -1388,6 +1338,28 @@ passthru_mmio_map(struct pci_devinst *pi, int baridx, 
int enabled,
        return (0);
 }
 
+static void
+passthru_msix_addr(struct pci_devinst *pi, int baridx, int enabled,
+    uint64_t address)
+{
+       size_t remaining;
+       uint32_t table_size, table_offset;
+
+       table_offset = rounddown2(pi->pi_msix.table_offset, 4096);
+       if (table_offset > 0) {
+               (void)passthru_mmio_map(pi, baridx, enabled, address, 0,
+                   table_offset);
+       }
+       table_size = pi->pi_msix.table_offset - table_offset;
+       table_size += pi->pi_msix.table_count * MSIX_TABLE_ENTRY_SIZE;
+       table_size = roundup2(table_size, 4096);
+       remaining = pi->pi_bar[baridx].size - table_offset - table_size;
+       if (remaining > 0) {
+               (void)passthru_mmio_map(pi, baridx, enabled, address,
+                   table_offset + table_size, remaining);
+       }
+}
+
 static void
 passthru_mmio_addr(struct pci_devinst *pi, int baridx, int enabled,
     uint64_t address)

Reply via email to