Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Dec 2015 08:44:12 -0800
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-virtualization@freebsd.org, "G. Amanakis" <g_amanakis@yahoo.com>
Subject:   Re: BAR and pci passthrough
Message-ID:  <2573974.qrpbG8qZMs@ralph.baldwin.cx>
In-Reply-To: <D887B227-2518-47E8-AD70-E18C9FBF0838@yahoo.com>
References:  <4F251D2F-8C0C-46FF-B5E1-D88DE84904D8@yahoo.com> <CAFgRE9H0_h1Dxzjn19n6Tjc9Nt8Ze6ugWnKQiZGRV363Q1z22g@mail.gmail.com> <D887B227-2518-47E8-AD70-E18C9FBF0838@yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Saturday, December 12, 2015 02:04:17 PM G. Amanakis via freebsd-virtualization wrote:
> Changing
> #define	PCIM_BAR_MEM_BASE	0xfffffffffffffff0ULL
> to
> #define	PCIM_BAR_MEM_BASE	0xfffffffffffff000ULL
> in
> sys/dev/PCI/pcireg.h makes the min size of a memory BAR equal to 0x1000 or 4096 bytes and it lets me passthrough the device. Any objections to this strategy?

This constant defines the spec as implemented in hardware.  You will break
real hardware on bare metal if you make this change.  As Neel notes, this is
hard to fix properly.  The proper fix is to modify the ppt(4) driver so that
it asks the PCI bus to allocate a full page for BARs that are smaller than a
page.  Unfortunately the PCI bus driver doesn't currently provide a way to do
that.  Even if it did it would not necessarily always work since the device
may be behind a PCI-PCI bridge whose windows can't grow due to existing
allocations of adjacent addresses.  Alternatively the hypervisor could trap
all accesses to this page and only permit accesses to the range that contains
the BAR, but that would be quite slow.

> On December 2, 2015 11:54:03 PM GMT+01:00, Neel Natu <neelnatu@gmail.com> wrote:
> >On Wed, Dec 2, 2015 at 3:13 AM, G. Amanakis via freebsd-virtualization
> ><freebsd-virtualization@freebsd.org> wrote:
> >> I am facing the following problem:
> >>     on a X9SCM with an E3-1220Lv2 I am trying to passthrough the
> >onboard usb controllers. I disable the usb module from the kernel
> >config and using pptdev the controllers are assigned to ppt devices.
> >However running bhyve on FreeBSD 10.2 with:
> >>
> >>     sudo bhyve -AI -H -P -s 0:0,hostbridge -s 1:0,lpc -s
> >2:0,virtio-net,tap0 -s 3:0,virtio-blk,./linux.img -s
> >4:0,passthru,0/29/0 -l com1,stdio -c 2 -m 2048M linuxguest
> >>
> >> returns :
> >>
> >>     passthru device 0/29/0 BAR 0: base 0xdf823000 or size 0x400 not
> >page aligned
> >>
> >> The problem probably that the length of the bar is smaller and not
> >aligned with the pagesize. Could the length of the BAR be modified in
> >order to perform the pci passthrough?
> >
> >Yes, that's correct - the size of the BAR is not a multiple of the
> >page size which leads to the error. If this BAR is mapped into the
> >guest's address space then it will "leak" an additional 3K into the
> >guest (since the minimum nested mapping is 4KB in size).
> >
> >It is hard to fix this in the general case if you want to truly
> >passthrough the BAR to the guest.
> >
> >best
> >Neel
> >
> >> --
> >> Sent from my Android device with K-9 Mail. Please excuse my brevity.
> >> _______________________________________________
> >> freebsd-virtualization@freebsd.org mailing list
> >> https://lists.freebsd.org/mailman/listinfo/freebsd-virtualization
> >> To unsubscribe, send any mail to
> >"freebsd-virtualization-unsubscribe@freebsd.org"
> 
> 


-- 
John Baldwin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2573974.qrpbG8qZMs>