HomeFreeBSD

bhyve: Avoid holding /dev/pci open unnecessarily

Description

bhyve: Avoid holding /dev/pci open unnecessarily

Some device models, LPC in particular, will call pci_host_read_config()
when probing for devices. Currently this results in pcifd_init()
opening /dev/pci, and thus bhyve holds the fd open even when it's not
needed.

Modify pci_host_{read,write}_config() to open /dev/pci independent of
the global pcifd. This means that these routines can only be used
during VM initialization, as capsicum will prevent further opens
afterward. Introduce internal wrappers which use the global pcifd,
intended for the passthru code.

Reviewed by: jhb
MFC after: 3 weeks
Fixes: 563fd2240e13 ("bhyve: export funcs for read/write pci config")
Differential Revision: https://reviews.freebsd.org/D48908