From: Leo Yan <leo.yan@linaro.org>
To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
Will Deacon <will.deacon@arm.com>,
Marc Zyngier <marc.zyngier@arm.com>,
Jean-Philippe Brucker <jean-philippe.brucker@arm.com>,
Eric Auger <eric.auger@redhat.com>,
Robin Murphy <robin.murphy@arm.com>
Cc: Leo Yan <leo.yan@linaro.org>
Subject: [PATCH] vfio-pci: Fix MSI IRQ forwarding for without per-vector masking
Date: Fri, 22 Mar 2019 13:23:08 +0800 [thread overview]
Message-ID: <20190322052308.28254-1-leo.yan@linaro.org> (raw)
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 <leo.yan@linaro.org>
---
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
next reply other threads:[~2019-03-22 5:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-22 5:23 Leo Yan [this message]
2019-03-22 5:29 ` [PATCH] vfio-pci: Fix MSI IRQ forwarding for without per-vector masking Leo Yan
2019-04-08 1:34 ` Leo Yan
2019-04-10 12:42 ` Jean-Philippe Brucker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190322052308.28254-1-leo.yan@linaro.org \
--to=leo.yan@linaro.org \
--cc=eric.auger@redhat.com \
--cc=jean-philippe.brucker@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=marc.zyngier@arm.com \
--cc=robin.murphy@arm.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox