From: Chao Gao <chao.gao@intel.com>
To: xen-devel@lists.xenproject.org
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Wei Liu" <wei.liu2@citrix.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Chao Gao" <chao.gao@intel.com>
Subject: [PATCH v2] xen/pt: fix some pass-thru devices don't work across reboot
Date: Thu, 15 Nov 2018 09:10:26 +0800 [thread overview]
Message-ID: <1542244226-35003-1-git-send-email-chao.gao@intel.com> (raw)
I find some pass-thru devices don't work any more across guest
reboot. Assigning it to another domain also meets the same issue. And
the only way to make it work again is un-binding and binding it to
pciback. Someone reported this issue one year ago [1].
If the device's driver doesn't disable MSI-X during shutdown or qemu is
killed/crashed before the domain shutdown, this domain's pirq won't be
unmapped. Then xen will unmap all pirq. But pciback has already disabled
meory decoding before xen unmapping pirq. Then when Xen is disabling a
MSI of the device, it has to sets the host_maskall flag and maskall bit
to mask a MSI rather than sets maskbit in MSI-x table. The call trace of
this process is:
->arch_domain_destroy
->free_domain_pirqs
->unmap_domain_pirq (if pirq isn't unmap by qemu)
->pirq_guest_force_unbind
->__pirq_guest_unbind
->mask_msi_irq(=desc->handler->disable())
->the warning in msi_set_mask_bit()
The host_maskall bit will prevent guests from clearing the maskall bit
even the device is assigned to another guest later. Guests cannot
receive interrupts from this device.
To fix this, host_maskall flag is cleared when all MSIs of a device are freed.
It is definitely safely to clear it because no msi is actually set up
for this device. Also, 'msix->warned' is initialized to DOMID_INVALID
rather than 0 to avoid warnings missing for Dom0.
[1]: https://lists.xenproject.org/archives/html/xen-devel/2017-09/msg02520.html
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
xen/arch/x86/msi.c | 18 ++++++++++++++++++
xen/drivers/passthrough/pci.c | 1 +
2 files changed, 19 insertions(+)
diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 5567990..cd570bc 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -637,6 +637,7 @@ int msi_free_irq(struct msi_desc *entry)
{
unsigned int nr = entry->msi_attrib.type != PCI_CAP_ID_MSIX
? entry->msi.nvec : 1;
+ struct pci_dev *pdev = entry->dev;
while ( nr-- )
{
@@ -654,6 +655,23 @@ int msi_free_irq(struct msi_desc *entry)
list_del(&entry->list);
xfree(entry);
+
+ /*
+ * In some cases, the 'host_maskall' is set for safety. Here clear
+ * 'host_maskall' if all MSIs are freed for a msi-x capable device.
+ * Without it, the device's msix keeps disabled even been reassigned
+ * to another domain.
+ */
+ if ( pdev && list_empty(&pdev->msi_list) && pdev->msix )
+ {
+ if ( pdev->msix->host_maskall )
+ printk(XENLOG_G_WARNING
+ "Resetting msix status of %04x:%02x:%02x.%u\n",
+ pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
+ PCI_FUNC(pdev->devfn));
+ pdev->msix->host_maskall = false;
+ pdev->msix->warned = DOMID_INVALID;
+ }
return 0;
}
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index e5b9602..d0ae03d 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -327,6 +327,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn)
return NULL;
}
spin_lock_init(&msix->table_lock);
+ msix->warned = DOMID_INVALID;
pdev->msix = msix;
}
--
1.8.3.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next reply other threads:[~2018-11-15 9:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-15 1:10 Chao Gao [this message]
2018-11-15 10:40 ` [PATCH v2] xen/pt: fix some pass-thru devices don't work across reboot Roger Pau Monné
2018-11-16 7:53 ` Chao Gao
2018-11-16 9:35 ` Roger Pau Monné
2018-11-16 9:59 ` Jan Beulich
2018-11-16 14:30 ` Roger Pau Monné
2018-11-19 12:23 ` Jan Beulich
2018-11-19 12:45 ` Chao Gao
2018-11-19 12:55 ` Jan Beulich
2018-11-19 13:20 ` Chao Gao
2018-12-11 17:03 ` Jan Beulich
2018-12-12 4:20 ` Chao Gao
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=1542244226-35003-1-git-send-email-chao.gao@intel.com \
--to=chao.gao@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/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;
as well as URLs for NNTP newsgroup(s).