The IOV topo lock being Giant is kind of awkward, this is a stop gap until that can be looked at deeper.
The M_WAITOK allocations in pci_iov_build_status() can sleep and drop
Giant. Concurrent VF deletion or reconfiguration can then invalidate
cached device pointers or change the count used to index the arrays.
Allocate both scratch arrays outside Giant, then reload the IOV state
and verify that the arrays cover the current VF count before collecting
any device pointers. Retry allocation only when the count outgrows the
allocated capacity; a smaller count can use the existing arrays.
Reject queries while IOV configuration or teardown is busy, and return
ENXIO if detach has already cleared the IOV state. The snapshot builder
remains non-sleeping under Giant, and packing and copyout still occur
after releasing it.
Fixes: 6f8b3be1fbd6 ("pci: Add SR-IOV status reporting")