From: Quan Xu <quan.xu@intel.com>
To: jbeulich@suse.com, kevin.tian@intel.com
Cc: feng.wu@intel.com, george.dunlap@eu.citrix.com,
andrew.cooper3@citrix.com, tim@xen.org, xen-devel@lists.xen.org,
Quan Xu <quan.xu@intel.com>
Subject: [PATCH v5 7/7] VT-d: Fix vt-d Device-TLB flush timeout issue.
Date: Fri, 5 Feb 2016 18:18:27 +0800 [thread overview]
Message-ID: <1454667507-79751-8-git-send-email-quan.xu@intel.com> (raw)
In-Reply-To: <1454667507-79751-1-git-send-email-quan.xu@intel.com>
If Device-TLB flush is timeout, we'll hide the target ATS
device and crash the domain owning this ATS device.
If impacted domain is hardware domain, just throw out a warning.
The hidden device will be disallowed to be further assigned to
any domain.
Signed-off-by: Quan Xu <quan.xu@intel.com>
---
xen/drivers/passthrough/pci.c | 2 +-
xen/drivers/passthrough/vtd/extern.h | 8 +++-
xen/drivers/passthrough/vtd/qinval.c | 77 ++++++++++++++++++++++++++++++++++-
xen/drivers/passthrough/vtd/x86/ats.c | 14 ++++++-
4 files changed, 95 insertions(+), 6 deletions(-)
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 27b3ca7..2d7dc59 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -407,7 +407,7 @@ static void _pci_hide_device(struct pci_dev *pdev)
list_add(&pdev->domain_list, &dom_xen->arch.pdev_list);
}
-int __init pci_hide_device(int bus, int devfn)
+int pci_hide_device(int bus, int devfn)
{
struct pci_dev *pdev;
int rc = -ENOMEM;
diff --git a/xen/drivers/passthrough/vtd/extern.h b/xen/drivers/passthrough/vtd/extern.h
index ec9c513..a129460 100644
--- a/xen/drivers/passthrough/vtd/extern.h
+++ b/xen/drivers/passthrough/vtd/extern.h
@@ -56,8 +56,12 @@ struct acpi_drhd_unit * find_ats_dev_drhd(struct iommu *iommu);
int ats_device(const struct pci_dev *, const struct acpi_drhd_unit *);
-int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
- u64 addr, unsigned int size_order, u64 type);
+int dev_invalidate_iotlb(struct iommu *iommu, u16 did, u64 addr,
+ unsigned int size_order, u64 type,
+ unsigned int lock);
+int dev_invalidate_iotlb_sync(struct iommu *iommu, u16 did,
+ u16 seg, u8 bus, u8 devfn,
+ unsigned int lock);
int qinval_device_iotlb(struct iommu *iommu,
u32 max_invs_pend, u16 sid, u16 size, u64 addr);
diff --git a/xen/drivers/passthrough/vtd/qinval.c b/xen/drivers/passthrough/vtd/qinval.c
index f2e7ffb..76046a7 100644
--- a/xen/drivers/passthrough/vtd/qinval.c
+++ b/xen/drivers/passthrough/vtd/qinval.c
@@ -229,6 +229,69 @@ int qinval_device_iotlb(struct iommu *iommu,
return 0;
}
+static void dev_invalidate_iotlb_timeout(struct iommu *iommu, u16 did,
+ u16 seg, u8 bus, u8 devfn,
+ unsigned int lock)
+{
+ struct domain *d = NULL;
+ struct pci_dev *pdev;
+
+ if ( test_bit(did, iommu->domid_bitmap) )
+ d = rcu_lock_domain_by_id(iommu->domid_map[did]);
+
+ if ( d == NULL )
+ return;
+
+ for_each_pdev(d, pdev)
+ {
+ if ( (pdev->seg == seg) &&
+ (pdev->bus == bus) &&
+ (pdev->devfn == devfn) )
+ {
+ ASSERT ( pdev->domain );
+ list_del(&pdev->domain_list);
+ pdev->domain = NULL;
+
+ if ( !(lock & PCIDEVS_LOCK) )
+ spin_lock(&pcidevs_lock);
+
+ if ( pci_hide_device(bus, devfn) )
+ {
+ printk(XENLOG_ERR
+ "IOMMU hide device %04x:%02x:%02x.%02x error.",
+ seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
+ }
+
+ if ( !(lock & PCIDEVS_LOCK) )
+ spin_unlock(&pcidevs_lock);
+
+ break;
+ }
+ }
+
+ if ( !is_hardware_domain(d) )
+ domain_crash(d);
+ rcu_unlock_domain(d);
+}
+
+int dev_invalidate_iotlb_sync(struct iommu *iommu, u16 did,
+ u16 seg, u8 bus, u8 devfn,
+ unsigned int lock)
+{
+ struct qi_ctrl *qi_ctrl = iommu_qi_ctrl(iommu);
+ int rc = 0;
+
+ if ( qi_ctrl->qinval_maddr )
+ {
+ rc = queue_invalidate_wait(iommu, 0, 1, 1);
+ if ( rc == -ETIMEDOUT )
+ dev_invalidate_iotlb_timeout(iommu, did,
+ seg, bus, devfn, lock);
+ }
+
+ return rc;
+}
+
static void queue_invalidate_iec(struct iommu *iommu, u8 granu, u8 im, u16 iidx)
{
unsigned long flags;
@@ -350,9 +413,19 @@ static int flush_iotlb_qi(
queue_invalidate_iotlb(iommu,
type >> DMA_TLB_FLUSH_GRANU_OFFSET, dr,
dw, did, size_order, 0, addr);
- if ( flush_dev_iotlb )
- ret = dev_invalidate_iotlb(iommu, did, addr, size_order, type);
+
+ /*
+ * Before Device-TLB invalidation we need to synchronize
+ * invalidation completions with hardware.
+ */
rc = invalidate_sync(iommu);
+ if ( rc )
+ return rc;
+
+ if ( flush_dev_iotlb )
+ ret = dev_invalidate_iotlb(iommu, did, addr, size_order,
+ type, lock);
+
if ( !ret )
ret = rc;
}
diff --git a/xen/drivers/passthrough/vtd/x86/ats.c b/xen/drivers/passthrough/vtd/x86/ats.c
index 7c797f6..dcc3394 100644
--- a/xen/drivers/passthrough/vtd/x86/ats.c
+++ b/xen/drivers/passthrough/vtd/x86/ats.c
@@ -106,7 +106,7 @@ out:
}
int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
- u64 addr, unsigned int size_order, u64 type)
+ u64 addr, unsigned int size_order, u64 type, unsigned int lock)
{
struct pci_ats_dev *pdev;
int ret = 0;
@@ -162,6 +162,18 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
return -EOPNOTSUPP;
}
+ /*
+ * Synchronize with hardware for Device-TLB invalidate
+ * descriptor.
+ */
+ ret = dev_invalidate_iotlb_sync(iommu, did, pdev->seg,
+ pdev->bus, pdev->devfn, lock);
+ if ( ret )
+ printk(XENLOG_ERR
+ "Flush error %d on device %04x:%02x:%02x.%02x \n",
+ ret, pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
+ PCI_FUNC(pdev->devfn));
+
if ( !ret )
ret = rc;
}
--
1.9.1
next prev parent reply other threads:[~2016-02-05 10:18 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-05 10:18 [PATCH v5 0/7] VT-d Device-TLB flush issue Quan Xu
2016-02-05 10:18 ` [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part) Quan Xu
2016-02-10 17:01 ` Jan Beulich
2016-02-16 10:50 ` Xu, Quan
2016-02-16 11:06 ` Jan Beulich
2016-02-17 12:49 ` Xu, Quan
2016-02-17 13:05 ` Jan Beulich
2016-02-17 13:38 ` Xu, Quan
2016-02-18 6:15 ` Tian, Kevin
2016-02-18 6:33 ` Xu, Quan
2016-02-18 6:37 ` Tian, Kevin
2016-02-18 6:42 ` Xu, Quan
2016-02-23 11:43 ` Xu, Quan
2016-02-23 15:53 ` Jan Beulich
2016-02-05 10:18 ` [PATCH v5 2/7] VT-d: Check VT-d Device-TLB flush error(MMU part) Quan Xu
2016-02-17 14:02 ` Jan Beulich
2016-02-05 10:18 ` [PATCH v5 3/7] VT-d: Reduce spin timeout to 1ms, which can be boot-time changed Quan Xu
2016-02-17 14:06 ` Jan Beulich
2016-02-05 10:18 ` [PATCH v5 4/7] VT-d: Refactor iommu_ops .iotlb_flush() and iotlb_flush_all() Quan Xu
2016-02-17 14:19 ` Jan Beulich
2016-02-18 8:50 ` Xu, Quan
2016-02-05 10:18 ` [PATCH v5 5/7] VT-d: Refactor iommu_ops .map_page() and unmap_page() Quan Xu
2016-02-17 14:23 ` Jan Beulich
2016-02-05 10:18 ` [PATCH v5 6/7] VT-d: Refactor iommu_flush .iotlb() Quan Xu
2016-02-05 10:18 ` Quan Xu [this message]
2016-02-17 14:40 ` [PATCH v5 7/7] VT-d: Fix vt-d Device-TLB flush timeout issue Jan Beulich
2016-02-18 7:36 ` Xu, Quan
2016-02-18 8:35 ` Jan Beulich
2016-02-18 8:47 ` Xu, Quan
2016-02-18 9:21 ` Jan Beulich
2016-02-18 10:00 ` Xu, Quan
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=1454667507-79751-8-git-send-email-quan.xu@intel.com \
--to=quan.xu@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=feng.wu@intel.com \
--cc=george.dunlap@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=kevin.tian@intel.com \
--cc=tim@xen.org \
--cc=xen-devel@lists.xen.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).