churchers / vm-bhyve

Shell based, minimal dependency bhyve manager
BSD 2-Clause "Simplified" License
839 stars 179 forks source link

Make it possible to customize "-s X:Y," for passthru0 option in vm config #203

Closed kaN5300 closed 6 years ago

kaN5300 commented 6 years ago

When host is using bge driver, passthru will work with bhyve only if -s matches hosts function number:

https://lists.freebsd.org/pipermail/freebsd-virtualization/2014-January/001976.html

My case:

cat /boot/loader.conf | grep ppt pptdevs="3/0/1"

tail vm-bhyve.log Mar 12 16:34:31: [utctime: no] Mar 12 16:34:31: [debug mode: 1] Mar 12 16:34:31: [primary disk: FreeBSD-11.1-RELEASE-amd64.raw] Mar 12 16:34:31: [primary disk dev: file] Mar 12 16:34:31: booting Mar 12 16:34:31: bhyveload -c /dev/nmdm5A -S -m 256M -e autoboot_delay=3 -d /usr/vm/vm4/FreeBSD-11.1-RELEASE-amd64.raw vm4 Mar 12 16:34:34: [bhyve options: -c 1 -m 256M -AHP -U 43157865-e6ed-11e7-8139-6451060e7679 -S] Mar 12 16:34:34: [bhyve devices: -s 0,hostbridge -s 31,lpc -s 4:0,virtio-blk,/usr/vm/vm4/FreeBSD-11.1-RELEASE-amd64.raw -s 5:0,passthru,3/0/1] Mar 12 16:34:34: [bhyve console: -l com1,/dev/nmdm5A] Mar 12 16:34:34: starting bhyve (run 1)

vm conf:

loader="bhyveload" cpu=1 memory=256M passthru0="3/0/1" disk0_type="virtio-blk" disk0_name="FreeBSD-11.1-RELEASE-amd64.raw" uuid="43157865-e6ed-11e7-8139-6451060e7679" debug="1"

vm console:

bge0: <HP Ethernet 1Gb 2-port 332i Adapter, ASIC rev. 0x5720000> mem 0xc0010000-0xc001ffff,0xc0020000-0xc002ffff,0xc0030000-0xc003ffff irq 18 at device 5.0 on pci0 bge0: APE FW version: NCSI v1.2.46.0 bge0: CHIP ID 0x05720000; ASIC REV 0x5720; CHIP REV 0x57200; PCI-E bge0: Try again bge0: Try again bge0: Try again bge0: Try again bge0: attaching PHYs failed device_attach: bge0 attach returned 6

I am trying to run by hand:

bhyveload -c /dev/nmdm5A -S -m 256M -e autoboot_delay=3 -d /usr/vm/vm4/FreeBSD-11.1-RELEASE-amd64.raw vm4 bhyve -c 1 -m 256M -AHPS -U 43157865-e6ed-11e7-8139-6451060e7679 -s 0,hostbridge -s 31,lpc -s 4:0,virtio-blk,/usr/vm/vm4/FreeBSD-11.1-RELEASE-amd64.raw -s 3:1,passthru,3/0/1 vm4

but having troubles with console access

nihr43 commented 6 years ago

I have not tested this particular use , but it looks like you need to get rid of "passthru0" and passthrough manually with.. bhyve_options="-s 3:1,passthru,3/0/1"

bhyve_options Specify any additional command line arguments to pass to the bhyve command. This allows the use of options such as cpu pinning or debug that are not exposed by vm-bhyve."

churchers commented 6 years ago

In this case using bhyve_options seems like the most straight forward fix. Fortunately your device in on slot 3, and vm-bhyve starts creating devices at slot 4.

To fully support specifying the slot/function would likely require making sure that slot is not used for any vm-bhyve devices. I'd have to put a bit more consideration into how best to implement it.

churchers commented 6 years ago

In the latest dev version (which should become 1.3) I now have a new syntax for passthru

passthru0="4/0/0"     # will pass 4/0/0 using next available vm-bhyve slot
passthru1="6/0/0=2:0" # will put device 6/0/0 on 2:0 in bhyve

Note that vm-bhyve starts at slot 4 when generating its own device string (3 if there's an install ISO) so there's no guarantee the slot you want to use will be free. If a specific slot is required it's worth running the guest then checking vm-bhyve.log to see which slots are already being allocated. I have added install_slot and start_slot configuration options to make this configurable.