HomeFreeBSD

bhyve: passthru: enable BARs before possibly mmap(2)ing them

Description

bhyve: passthru: enable BARs before possibly mmap(2)ing them

The first time we start bhyve with a passthru device everything is fine
as on boot we do enable BARs. If a driver (unload) inside bhyve disables
the BAR(s) as some Linux drivers do, we need to make sure we re-enable
them on next bhyve start.

If we are trying to mmap a disabled BAR for MSI-X (PCIOCBARMMAP)
the kernel will give us an EBUSY.
While we were re-enabling the BAR(s) in the current code loop
cfginit() was writing the changes out too late to the real hardware.

Move the call to init_msix_table() after the register on the real
hardware was updated. That way the kernel will be happy and the
mmap will succeed and bhyve will start.
Also simplify the code given the last argument to init_msix_table()
is unused we do not need to do checks for each bar. [1]

MFC after: 3 days
PR: 260148
Pointed out by: markj [1]
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D33628

Details

Provenance
bzAuthored on Dec 23 2021, 2:59 PM
Reviewer
markj
Differential Revision
D33628: bhyve: passthru: enable BARs before possibly mmap(2)ing them
Parents
rGb4a58b3d5831: igc: Remove redundant IFCAP_VLAN_HWTAGGING check
Branches
Unknown
Tags
Unknown