On 01/03/2018 16:06, Rodney W. Grimes wrote:
> Due to the design of the IOMMU you can only manage IO space in page
> (4096 on x86) granually sizes.  The device your trying to pass in
> has a 1024 byte memory region that is part of a 4096 byte page that
> may have other things in it.
> 
> At this time bhyve does not have any way to deal with this, though some
> other hypervisors have techniques that make this work.
> 
> I do not have or know of any list of USB controller cards that
> have 4k aligned and 4k sized BAR's.

I have this local hack for that problem.
It comes without any warranty and its use is completely at your own risk.

commit 74e0a8d1ae01c7aaabd7d965958b735c7cf18871
Author: Andriy Gapon <[email protected]>
Date:   Fri Nov 17 20:17:57 2017 +0200

    bhyve: allow BAR sizes that are not page aligned by rounding them up

    This is based on the assumption that drivers won't access the added space.

diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c
index f314679d912b0..14c1384c6c8f8 100644
--- a/usr.sbin/bhyve/pci_passthru.c
+++ b/usr.sbin/bhyve/pci_passthru.c
@@ -563,13 +563,20 @@ cfginitbar(struct vmctx *ctx, struct passthru_softc *sc)
                size = bar.pbi_length;

                if (bartype != PCIBAR_IO) {
-                       if (((base | size) & PAGE_MASK) != 0) {
+                       if ((base & PAGE_MASK) != 0) {
                                warnx("passthru device %d/%d/%d BAR %d: "
-                                   "base %#lx or size %#lx not page aligned\n",
+                                   "base %#lx not page aligned\n",
                                    sc->psc_sel.pc_bus, sc->psc_sel.pc_dev,
-                                   sc->psc_sel.pc_func, i, base, size);
+                                   sc->psc_sel.pc_func, i, base);
                                return (-1);
                        }
+                       if ((size & PAGE_MASK) != 0) {
+                               warnx("passthru device %d/%d/%d BAR %d: "
+                                   "size %#lx not page aligned\n",
+                                   sc->psc_sel.pc_bus, sc->psc_sel.pc_dev,
+                                   sc->psc_sel.pc_func, i, size);
+                               size = round_page(size);
+                       }
                }

                /* Cache information about the "real" BAR */


-- 
Andriy Gapon
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-virtualization
To unsubscribe, send any mail to 
"[email protected]"

Reply via email to