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]

Some passthru devices only support MSI instead of MSI-X. For those
devices the initialization of MSI-X table will fail. Re-add (or in
the MFC case keep) the check erroneously removed in the initial commit. [2]

PR: 260148
Pointed out by: markj [1]
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D33628
Submitted by: (C.Koehne beckhoff.com) [2]
Reviewed by: manu, bz
Differential Revision: https://reviews.freebsd.org/D33728

(cherry picked from commit f1442847c9404d4bc5f5524a0c3362dd39cb14f9)
(cherry picked from commit 338a1be836308f6d807f8bfe9b335463d537abc4)

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
rG50a078f852ab: LinuxKPI: 802.11 fix queue wait
Branches
Unknown
Tags
Unknown