msix: fix msix_vector_masked
PATCH 1/1 msix: fix msix_vector_masked
commit 428c3ece97179557f2753071fb0ca97a03437267 ("fix MSI injection on Xen") inadvertently enabled the xen-specific logic unconditionally. Limit it to only when xen is enabled.
Additionally, msix data should be read with pci_get_log
since the format is pci little-endian.
--- hw/pci/msix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/pci/msix.c +2 -2
@@ -80,10 +80,10 @@ static void msix_clr_pending(PCIDevice *dev, int vector)static bool msix_vector_masked (PCIDevice *dev,unsigned int vector,bool fmask) {unsigned offset = vector *PCI_MSIX_ENTRY_SIZE ; -uint32_t *data = (uint32_t *)&dev->msix_table[offset +PCI_MSIX_ENTRY_DATA ]; +uint8_t *data = &dev->msix_table[offset +PCI_MSIX_ENTRY_DATA ];/* MSIs on Xen can be remapped into pirqs. In those cases, masking * and unmasking go through the PV evtchn path. */ -if (xen_is_pirq_msi (*data)) { +if (xen_enabled () &&xen_is_pirq_msi (pci_get_long (data))) {return false; } return fmask || dev->msix_table[offset + PCI_MSIX_ENTRY_VECTOR_CTRL] &
Signature · 1 line
MST
Quoted 9 lines · Michael S. Tsirkin
commit
428c3ece97179557f2753071fb0ca97a03437267("fix MSI injection on Xen") inadvertently enabled the xen-specific logic unconditionally. Limit it to only when xen is enabled.
Additionally, msix data should be read withpci_get_log
since the format is pci little-endian.Reported-by "Daniel P. Berrange" <[email protected]>Cc Stefano Stabellini <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>
Thanks Daniel for finding the issue and thanks Michael for fixing my bug, sorry about that.
Quoted 10 lines
hw/pci/msix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/pci/msix.c +0
-0@@ -80,10 +80,10 @@ static void msix_clr_pending(PCIDevice *dev, int vector)static bool msix_vector_masked (PCIDevice *dev,unsigned int vector,bool fmask) {
hw/pci/msix.c static void msix_clr_pending(PCIDevice *dev, int vector) · line 89
Quoted 10 lines
hw/pci/msix.c +2
-2unsigned offset = vector *PCI_MSIX_ENTRY_SIZE ; -uint32_t *data = (uint32_t *)&dev->msix_table[offset +PCI_MSIX_ENTRY_DATA ]; +uint8_t *data = &dev->msix_table[offset +PCI_MSIX_ENTRY_DATA ];/* MSIs on Xen can be remapped into pirqs. In those cases, masking * and unmasking go through the PV evtchn path. */ -if (xen_is_pirq_msi (*data)) { +if (xen_enabled () &&xen_is_pirq_msi (pci_get_long (data))) {return false; } return fmask || dev->msix_table[offset + PCI_MSIX_ENTRY_VECTOR_CTRL] &
I think this is good, but moving the xen_enabled() check inside xen_is_pirq_msi is even be better, so that we cover all call sites at once.
xen-hvm.c +2 -1
@@ -151,7 +151,8 @@ int xen_is_pirq_msi(uint32_t msi_data)/* If vector is 0, the msi is remapped into a pirq, passed as * dest_id. */ -return ((msi_data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ) ==0 ; +return xen_enabled () && + ((msi_data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ) ==0 ; }void xen_hvm_inject_msi (uint64_t addr,uint32_t data)
Quoted 31 lines · Stefano Stabellini
Quoted 9 lines · Michael S. Tsirkin
commit
428c3ece97179557f2753071fb0ca97a03437267("fix MSI injection on Xen") inadvertently enabled the xen-specific logic unconditionally. Limit it to only when xen is enabled.
Additionally, msix data should be read withpci_get_log
since the format is pci little-endian.Reported-by "Daniel P. Berrange" <[email protected]>Cc Stefano Stabellini <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Thanks Daniel for finding the issue and thanks Michael for fixing my bug, sorry about that.
Quoted 16 lines
hw/pci/msix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/pci/msix.c +1
-2@@ -80,10 +80,10 @@ static void msix_clr_pending(PCIDevice *dev, int vector)static bool msix_vector_masked (PCIDevice *dev,unsigned int vector,bool fmask) {unsigned offset = vector *PCI_MSIX_ENTRY_SIZE ; -uint32_t *data = (uint32_t *)&dev->msix_table[offset +PCI_MSIX_ENTRY_DATA ]; +uint8_t *data = &dev->msix_table[offset +PCI_MSIX_ENTRY_DATA ];/* MSIs on Xen can be remapped into pirqs. In those cases, masking * and unmasking go through the PV evtchn path. */ -if (xen_is_pirq_msi (*data)) {
Quoted 8 lines
hw/pci/msix.c static void msix_clr_pending(PCIDevice *dev, int vector) · line 89
Quoted 4 lines
hw/pci/msix.c +1
-0+if (xen_enabled () &&xen_is_pirq_msi (pci_get_long (data))) {return false; } return fmask || dev->msix_table[offset + PCI_MSIX_ENTRY_VECTOR_CTRL] &I think this is good, but moving the
xen_enabled()check insidexen_is_pirq_msiis even be better, so that we cover all call sites at once.
Feel free to post a patch on top.
Quoted 15 lines
xen-hvm.c +2
-1@@ -151,7 +151,8 @@ int xen_is_pirq_msi(uint32_t msi_data)/* If vector is 0, the msi is remapped into a pirq, passed as * dest_id. */ -return ((msi_data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ) ==0 ; +return xen_enabled () && + ((msi_data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ) ==0 ; }void xen_hvm_inject_msi (uint64_t addr,uint32_t data)
Quoted 9 lines · Michael S. Tsirkin
commit
428c3ece97179557f2753071fb0ca97a03437267("fix MSI injection on Xen") inadvertently enabled the xen-specific logic unconditionally. Limit it to only when xen is enabled.
Additionally, msix data should be read withpci_get_log
since the format is pci little-endian.Reported-by "Daniel P. Berrange" <[email protected]>Cc Stefano Stabellini <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>
Fixes ivshmem-test /x86_64/ivshmem/server-msi. Not run by "make check" unless you add SPEED=slow. Quick reproducer:
$ make tests/ivshmem-test && QTEST_QEMU_BINARY='x86_64-softmmu/qemu-system-x86_64' QTEST_QEMU_IMG=qemu-img MALLOC_PERTURB_=${MALLOC_PERTURB_:-$((RANDOM % 255 + 1))} gtester -k --verbose -m slow tests/ivshmem-testAdding this to the commit message wouldn't hurt.
Thanks!