The MSI-X resource shouldn't be assumed to be always on BAR1.
The Virtio v1.1 Spec did not specify that MSI-X table and PBA BAR has to
be BAR1 either.
Reported by: Yuan Rui <number201724@me.com>
MFC after: 2 weeks
Differential D26933
virtio_pci: Use the table BAR and PBA BAR from MSI-X cap khng on Oct 24 2020, 4:22 PM. Authored by Tags None Referenced Files
Subscribers
Details
Diff Detail
Event TimelineComment Actions Looks fine to me. If this compiles, these pointers are effectively unused other than for cleanup, and the whole point is the side effect of activating the resource(s). The MSI-X doc explicitly says Table structure and PBA array may occupy the same, or distinct, BARs. So this is more correct than assuming both are in BAR 1.
Comment Actions This looks odd to me having to push this down into the driver. I don't really like how to code flows with the 'msix_load' variable. I'm not sure what your VMM here is, but I'd much rather only apply this to transitional or modern devices.
Comment Actions Where else would you put it? It's hard to do in the PCI bus itself because the resource is often used for other things in the driver and you can only bus_alloc_resource() "once" for a given BAR. Most hardware stores the table and PBA in fixed locations which don't require quite this amount of dynamic behavior. In terms of VirtIO drivers, this file seems like the right place to do it? In terms of msix_load, it's perhaps not ideal, but to replace it you would need something quite convoluted like: table_rid = pci_msix_table_bar(dev); ... pba_rid = pci_msix_pba_bar(dev); ... if ((table_rid == PCI_BAR(0) || sc->vtpci_msix_table_res != NULL) && (pba_rid == PCI_BAR(0) || pba_rid == table_rid || sc->vtpci_msix_pba_res != NULL)) sc->vtpci_flags &= ~VTPCI_FLAG_NO_MSIX; That seems like quite a mouthful compared to msix_load. Another way to handle it perhaps would be to not set VTPCI_FLAG_NO_MSIX by default but instead only set it if either of the bus_alloc_resource_any calls fail and in the else case when PCIY_MSIX is not present.
Comment Actions OK
My suggestion is to hoist the this MSIX related code into a separate function, that can do early returns instead of this counter-flow-control, so the attach method would read like if (vtpci_something_msix(sc) != 0) { sc->vtpci_flags |= VTPCI_FLAG_NO_MSIX; } Comment Actions
I would address this at the morning in my timezone. Comment Actions This looks ok to me. I would probably make it return bool, shorten the name, and invert the condition though so that the code in attach reads as: if (!vtpci_probe_msix(dev, sc)) sc->vtpci_flags |= VTPCI_FLAG_NO_MSIX; We've generally taken to using bool for new code in the kernel when it makes sense. I think it's also a bit clearer if the function returns true when MSI-X is ok, rather than returning true when it is busted. Comment Actions The diff is only the latest change instead of the total change I think, but I assume that was just due to the way it was uploaded. Comment Actions can we get it committed and merge before 13.0 release? This patch will support the FreeBSD operating system running on alibabacloud's VM. And need another patch: D26915 Comment Actions Hi! |