vfio/pci: Fix unmaskable MSI
cover vfio/pci: Fix unmaskable MSI
Patch 1 fixes an issue reported by Vivek, when assigning a device that supports classic MSI without maskable vectors.
Patch 2 adds some comments and renames the states, because the MSI code is difficult to understand. I haven't found a way to simplify it but this should at least help people debug it.
Jean-Philippe Brucker (2):
vfio/pci: Initialize MSI vectors unmasked
vfio/pci: Clarify the MSI states
include/kvm/vfio.h | 8 ++--- vfio/pci.c | 86 ++++++++++++++++++++++++++++------------------ 2 files changed, 57 insertions(+), 37 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/2 vfio/pci: Initialize MSI vectors unmasked
MSI vectors can be masked and unmasked individually when using the MSI-X capability, or when the classic MSI capability supports Per-Vector Masking. At the moment we incorrectly initialize the guest's view of the vectors (virt_state) as masked, so when using a MSI capability without Per-Vector Masking, the vectors are never unmasked and MSIs don't work. Initialize them unmasked instead.
Since VFIO doesn't support per-vector masking we implement it by disconnecting the irqfd, and keep track of it with the vector's phys_state. Initially the irqfd is not connected so phys_state is masked.
--- vfio/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
vfio/pci.c +1 -1
@@ -1182,7 +1182,7 @@ static int vfio_pci_init_msis(struct kvm *kvm, struct vfio_device *vdev, entry = &msis->entries[i]; entry->gsi =-1 ; entry->eventfd =-1 ; -msi_set_masked (entry->virt_state, true); +msi_set_masked (entry->virt_state, false);msi_set_masked (entry->phys_state, true); eventfds[i] =-1 ; }
Signature · 1 line
2.41.0
PATCH 2/2 vfio/pci: Clarify the MSI states
In reply to Jean-Philippe BruckerThe MSI and MSI-X implementations is a bit complex, because it keeps track of capability and vector states as seen by both the guest and the host. Add a few comments about those states and rename them to something more accurate.
What's called phys_state at the moment represents the software state maintained by VFIO and kvmtool, rather than the physical MSI capability, so host_state is more correct. To be consistent, rename virt_state to guest_state as well.
--- include/kvm/vfio.h | 8 ++--- vfio/pci.c | 86 ++++++++++++++++++++++++++++------------------ 2 files changed, 57 insertions(+), 37 deletions(-)
include/kvm/vfio.h +4 -4
@@ -36,8 +36,8 @@ struct vfio_pci_msi_entry {struct msix_table config;int gsi;int eventfd; -u8 phys_state; -u8 virt_state; +u8 guest_state; +u8 host_state; };struct vfio_pci_msix_table {
@@ -57,8 +57,8 @@ struct vfio_pci_msix_pba {/* Common data for MSI and MSI-X */ struct vfio_pci_msi_common {off_t pos; -u8 virt_state; -u8 phys_state; +u8 guest_state; +u8 host_state;struct mutex mutex;struct vfio_irq_info info;struct vfio_irq_set *irq_set;
vfio/pci.c +53 -33
194 lines not on this page · raw message
Signature · 1 line
2.41.0
Will Deacon
AppliedQuoted 8 lines · Jean-Philippe Brucker
Patch 1 fixes an issue reported by Vivek, when assigning a device that supports classic MSI without maskable vectors.
Patch 2 adds some comments and renames the states, because the MSI code is difficult to understand. I haven't found a way to simplify it but this should at least help people debug it.
[...]
Applied to kvmtool (master), thanks!
[1/2] vfio/pci: Initialize MSI vectors unmasked
https://git.kernel.org/will/kvmtool/c/3a36d3410e99 [2/2] vfio/pci: Clarify the MSI states https://git.kernel.org/will/kvmtool/c/0b5e55fc032d
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev