From: Quan Xu <quan.xu@intel.com>
To: jbeulich@suse.com, kevin.tian@intel.com
Cc: feng.wu@intel.com, ian.campbell@citrix.com,
george.dunlap@eu.citrix.com, andrew.cooper3@citrix.com,
dario.faggioli@citrix.com, tim@xen.org, xen-devel@lists.xen.org,
stefano.stabellini@citrix.com, Aravind.Gopalakrishnan@amd.com,
jun.nakajima@intel.com, jinsong.liu@alibaba-inc.com,
Quan Xu <quan.xu@intel.com>,
keir@xen.org, suravee.suthikulpanit@amd.com
Subject: [PATCH v6 5/5] VT-d: Fix vt-d Device-TLB flush timeout issue
Date: Wed, 2 Mar 2016 22:31:29 +0800 [thread overview]
Message-ID: <1456929089-17414-6-git-send-email-quan.xu@intel.com> (raw)
In-Reply-To: <1456929089-17414-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 | 6 ++--
xen/drivers/passthrough/vtd/extern.h | 2 ++
xen/drivers/passthrough/vtd/qinval.c | 65 ++++++++++++++++++++++++++++++++---
xen/drivers/passthrough/vtd/x86/ats.c | 12 +++++++
xen/include/xen/pci.h | 1 +
5 files changed, 78 insertions(+), 8 deletions(-)
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index d7e94e1..53b382a 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -414,7 +414,7 @@ static void free_pdev(struct pci_seg *pseg, struct pci_dev *pdev)
xfree(pdev);
}
-static void _pci_hide_device(struct pci_dev *pdev)
+void pci_hide_existing_device(struct pci_dev *pdev)
{
if ( pdev->domain )
return;
@@ -431,7 +431,7 @@ int __init pci_hide_device(int bus, int devfn)
pdev = alloc_pdev(get_pseg(0), bus, devfn);
if ( pdev )
{
- _pci_hide_device(pdev);
+ pci_hide_existing_device(pdev);
rc = 0;
}
pcidevs_unlock();
@@ -461,7 +461,7 @@ int __init pci_ro_device(int seg, int bus, int devfn)
}
__set_bit(PCI_BDF2(bus, devfn), pseg->ro_map);
- _pci_hide_device(pdev);
+ pci_hide_existing_device(pdev);
return 0;
}
diff --git a/xen/drivers/passthrough/vtd/extern.h b/xen/drivers/passthrough/vtd/extern.h
index 507c2e9..dac1e5a 100644
--- a/xen/drivers/passthrough/vtd/extern.h
+++ b/xen/drivers/passthrough/vtd/extern.h
@@ -58,6 +58,8 @@ 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_sync(struct iommu *iommu, u16 did,
+ u16 seg, u8 bus, u8 devfn);
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 882b9f4..8ff2d94 100644
--- a/xen/drivers/passthrough/vtd/qinval.c
+++ b/xen/drivers/passthrough/vtd/qinval.c
@@ -233,6 +233,57 @@ 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)
+{
+ 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;
+
+ pcidevs_lock();
+ 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;
+ pci_hide_existing_device(pdev);
+ break;
+ }
+ }
+
+ pcidevs_unlock();
+
+ 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)
+{
+ 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);
+ }
+
+ return rc;
+}
+
static void queue_invalidate_iec(struct iommu *iommu, u8 granu, u8 im, u16 iidx)
{
unsigned long flags;
@@ -342,8 +393,6 @@ static int flush_iotlb_qi(
if ( qi_ctrl->qinval_maddr != 0 )
{
- int rc;
-
/* use queued invalidation */
if (cap_write_drain(iommu->cap))
dw = 1;
@@ -353,11 +402,17 @@ static int flush_iotlb_qi(
queue_invalidate_iotlb(iommu,
type >> DMA_TLB_FLUSH_GRANU_OFFSET, dr,
dw, did, size_order, 0, addr);
+
+ /*
+ * Before Device-TLB invalidation we need to synchronize
+ * invalidation completions with hardware.
+ */
+ ret = invalidate_sync(iommu);
+ if ( ret )
+ return ret;
+
if ( flush_dev_iotlb )
ret = dev_invalidate_iotlb(iommu, did, addr, size_order, type);
- rc = invalidate_sync(iommu);
- if ( !ret )
- ret = rc;
}
return ret;
}
diff --git a/xen/drivers/passthrough/vtd/x86/ats.c b/xen/drivers/passthrough/vtd/x86/ats.c
index 7c797f6..a79a95a 100644
--- a/xen/drivers/passthrough/vtd/x86/ats.c
+++ b/xen/drivers/passthrough/vtd/x86/ats.c
@@ -162,6 +162,18 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
return -EOPNOTSUPP;
}
+ /*
+ * Synchronize with hardware for Device-TLB invalidate
+ * descriptor.
+ */
+ rc = dev_invalidate_iotlb_sync(iommu, did, pdev->seg,
+ pdev->bus, pdev->devfn);
+ if ( rc )
+ printk(XENLOG_ERR
+ "Flush error %d on device %04x:%02x:%02x.%u.\n",
+ ret, pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
+ PCI_FUNC(pdev->devfn));
+
if ( !ret )
ret = rc;
}
diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h
index 017aa0b..118d8fd 100644
--- a/xen/include/xen/pci.h
+++ b/xen/include/xen/pci.h
@@ -115,6 +115,7 @@ const unsigned long *pci_get_ro_map(u16 seg);
int pci_add_device(u16 seg, u8 bus, u8 devfn,
const struct pci_dev_info *, nodeid_t node);
int pci_remove_device(u16 seg, u8 bus, u8 devfn);
+void pci_hide_existing_device(struct pci_dev *pdev);
int pci_ro_device(int seg, int bus, int devfn);
int pci_hide_device(int bus, int devfn);
struct pci_dev *pci_get_pdev(int seg, int bus, int devfn);
--
1.9.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
prev parent reply other threads:[~2016-03-02 14:31 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-02 14:31 [PATCH v6 0/5] VT-d Device-TLB flush issue Quan Xu
2016-03-02 14:31 ` [PATCH v6 1/5] IOMMU/MMU: Adjust top level functions for VT-d Device-TLB flush error Quan Xu
2016-03-02 14:31 ` [PATCH v6 2/5] IOMMU/MMU: Adjust low " Quan Xu
2016-03-02 14:31 ` [PATCH v6 3/5] IOMMU: Make the pcidevs_lock a recursive one Quan Xu
2016-03-03 23:59 ` Dario Faggioli
2016-03-04 2:45 ` Xu, Quan
2016-03-04 9:29 ` Jan Beulich
2016-03-04 11:54 ` Xu, Quan
2016-03-04 13:59 ` Dario Faggioli
2016-03-04 14:09 ` Jan Beulich
2016-03-07 7:05 ` Xu, Quan
2016-03-07 11:14 ` Jan Beulich
2016-03-07 11:23 ` Xu, Quan
2016-03-07 11:36 ` Jan Beulich
2016-03-07 11:42 ` Xu, Quan
2016-03-07 11:49 ` Jan Beulich
2016-03-07 11:55 ` Xu, Quan
2016-03-02 14:31 ` [PATCH v6 4/5] VT-d: Reduce spin timeout to 1ms, which can be boot-time changed Quan Xu
2016-03-04 0:11 ` Dario Faggioli
2016-03-04 9:32 ` Jan Beulich
2016-03-02 14:31 ` Quan Xu [this message]
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=1456929089-17414-6-git-send-email-quan.xu@intel.com \
--to=quan.xu@intel.com \
--cc=Aravind.Gopalakrishnan@amd.com \
--cc=andrew.cooper3@citrix.com \
--cc=dario.faggioli@citrix.com \
--cc=feng.wu@intel.com \
--cc=george.dunlap@eu.citrix.com \
--cc=ian.campbell@citrix.com \
--cc=jbeulich@suse.com \
--cc=jinsong.liu@alibaba-inc.com \
--cc=jun.nakajima@intel.com \
--cc=keir@xen.org \
--cc=kevin.tian@intel.com \
--cc=stefano.stabellini@citrix.com \
--cc=suravee.suthikulpanit@amd.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).