[Bug 260148] passthru stopped working

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 30 Nov 2021 23:56:07 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260148

--- Comment #4 from Bjoern A. Zeeb <bz@FreeBSD.org> ---
okay, here's a fix:@@ -487,6 +487,7 @@ cfginitbar(struct vmctx *ctx, struct
passthru_softc *sc)
        struct pci_bar_io bar;
        enum pcibar_type bartype;
        uint64_t base, size;
+       uint16_t cmd, orig_cmd;

        pi = sc->psc_pi;

@@ -533,11 +534,22 @@ cfginitbar(struct vmctx *ctx, struct passthru_softc *sc)
                sc->psc_bar[i].addr = base;
                sc->psc_bar[i].lobits = 0;

+               orig_cmd = pci_get_cfgdata16(pi, PCIR_COMMAND);
+
                /* Allocate the BAR in the guest I/O or MMIO space */
                error = pci_emul_alloc_bar(pi, i, bartype, size);
                if (error)
                        return (-1);

+               /*
+                * We may need this here and now to enable the BAR
+                * before pci_msix_table_bar() tries to mmap it as
+                * the kernel otherwise returns EBUSY from pci_bar_mmap().
+                */
+               cmd = pci_get_cfgdata16(pi, PCIR_COMMAND);
+               if (cmd != orig_cmd)
+                       write_config(&sc->psc_sel, PCIR_COMMAND, 2, cmd);
+
                /* Use same lobits as physical bar */
                uint8_t lobits = read_config(&sc->psc_sel, PCIR_BAR(i), 0x01);
                if (bartype == PCIBAR_MEM32 || bartype == PCIBAR_MEM64) {




This is very similar to what @jhb is doing in
https://reviews.freebsd.org/D20623 for busmaster.

Unfortunately the combined write at the end of cfginit() is too late these
days.

So we end up with several individual writes to PCIR_COMMAND and possibly
yet-another-one not actually chaning anything anymore after all in cfginit().

-- 
You are receiving this mail because:
You are the assignee for the bug.