From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leo Yan Subject: [PATCH] vfio-pci: Fix MSI IRQ forwarding for without per-vector masking Date: Fri, 22 Mar 2019 13:23:08 +0800 Message-ID: <20190322052308.28254-1-leo.yan@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: Leo Yan To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Will Deacon , Marc Zyngier , Jean-Philippe Brucker , Eric Auger , Robin Murphy Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu List-Id: kvm.vger.kernel.org If MSI doesn't support per-vector masking capability and PCI_MSI_FLAGS_MASKBIT isn't set in message control field, the function vfio_pci_msi_vector_write() will directly bail out for this case and every vector's 'virt_state' keeps setting bit VFIO_PCI_MSI_STATE_MASKED. This results in the state maintained in 'virt_state' cannot really reflect the MSI hardware state; finally it will mislead the function vfio_pci_update_msi_entry() to skip IRQ forwarding with below flow: vfio_pci_update_msi_entry() { [...] if (msi_is_masked(entry->virt_state) == msi_is_masked(entry->phys_state)) return 0; ==> skip IRQ forwarding [...] } To fix this issue, when detect PCI_MSI_FLAGS_MASKBIT is not set in the message control field, this patch simply clears bit VFIO_PCI_MSI_STATE_MASKED for all vectors 'virt_state'; at the end vfio_pci_update_msi_entry() can forward MSI IRQ successfully. Signed-off-by: Leo Yan --- vfio/pci.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/vfio/pci.c b/vfio/pci.c index ba971eb..4fd24ac 100644 --- a/vfio/pci.c +++ b/vfio/pci.c @@ -363,8 +363,18 @@ static int vfio_pci_msi_vector_write(struct kvm *kvm, struct vfio_device *vdev, struct vfio_pci_device *pdev = &vdev->pci; struct msi_cap_64 *msi_cap_64 = PCI_CAP(&pdev->hdr, pdev->msi.pos); - if (!(msi_cap_64->ctrl & PCI_MSI_FLAGS_MASKBIT)) + if (!(msi_cap_64->ctrl & PCI_MSI_FLAGS_MASKBIT)) { + /* + * If MSI doesn't support per-vector masking capability, + * simply unmask for all vectors. + */ + for (i = 0; i < pdev->msi.nr_entries; i++) { + entry = &pdev->msi.entries[i]; + msi_set_masked(entry->virt_state, false); + } + return 0; + } if (msi_cap_64->ctrl & PCI_MSI_FLAGS_64BIT) mask_pos = PCI_MSI_MASK_64; -- 2.19.1