From: Quan Xu <quan.xu@intel.com>
To: xen-devel@lists.xen.org
Cc: Quan Xu <quan.xu@intel.com>,
kevin.tian@intel.com, feng.wu@intel.com,
dario.faggioli@citrix.com, jbeulich@suse.com
Subject: [PATCH v10 3/3] vt-d: fix vt-d Device-TLB flush timeout issue
Date: Fri, 22 Apr 2016 18:54:13 +0800 [thread overview]
Message-ID: <1461322453-29216-4-git-send-email-quan.xu@intel.com> (raw)
In-Reply-To: <1461322453-29216-1-git-send-email-quan.xu@intel.com>
If Device-TLB flush timed out, we hide the target ATS device
immediately and crash the domain owning this ATS device. If
impacted domain is hardware domain, just throw out a warning.
By hiding the device, we make sure it can't be assigned to any
domain any longer (see device_assigned).
Signed-off-by: Quan Xu <quan.xu@intel.com>
---
xen/drivers/passthrough/pci.c | 6 +--
xen/drivers/passthrough/vtd/extern.h | 5 ++-
xen/drivers/passthrough/vtd/qinval.c | 71 ++++++++++++++++++++++++++++++++---
xen/drivers/passthrough/vtd/x86/ats.c | 11 +++---
xen/include/xen/pci.h | 1 +
5 files changed, 79 insertions(+), 15 deletions(-)
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 9f1716a..9a214c6 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -420,7 +420,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;
@@ -437,7 +437,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();
@@ -467,7 +467,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 ab7ecad..b54a15c 100644
--- a/xen/drivers/passthrough/vtd/extern.h
+++ b/xen/drivers/passthrough/vtd/extern.h
@@ -60,8 +60,9 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
u64 addr, unsigned int size_order, u64 type);
int __must_check qinval_device_iotlb_sync(struct iommu *iommu,
- u32 max_invs_pend,
- u16 sid, u16 size, u64 addr);
+ u32 max_invs_pend, u16 did,
+ u16 seg, u8 bus, u8 devfn,
+ u16 size, u64 addr);
unsigned int get_cache_line_size(void);
void cacheline_flush(char *);
diff --git a/xen/drivers/passthrough/vtd/qinval.c b/xen/drivers/passthrough/vtd/qinval.c
index 69cc6bf..c795e6b 100644
--- a/xen/drivers/passthrough/vtd/qinval.c
+++ b/xen/drivers/passthrough/vtd/qinval.c
@@ -206,10 +206,71 @@ static int invalidate_sync(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]);
+
+ /*
+ * In case the domain has been freed or the IOMMU domid bitmap is
+ * not valid, the device no longer belongs to this domain.
+ */
+ 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);
+ else
+ printk(XENLOG_WARNING VTDPREFIX
+ " dom%d: ATS device %04x:%02x:%02x.%u flush failed.\n",
+ d->domain_id,
+ seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
+
+ rcu_unlock_domain(d);
+}
+
+int dev_invalidate_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;
+}
+
int __must_check qinval_device_iotlb_sync(struct iommu *iommu,
- u32 max_invs_pend,
- u16 sid, u16 size,
- u64 addr)
+ u32 max_invs_pend, u16 did,
+ u16 seg, u8 bus, u8 devfn,
+ u16 size, u64 addr)
{
unsigned long flags;
unsigned int index;
@@ -227,7 +288,7 @@ int __must_check qinval_device_iotlb_sync(struct iommu *iommu,
qinval_entry->q.dev_iotlb_inv_dsc.lo.res_1 = 0;
qinval_entry->q.dev_iotlb_inv_dsc.lo.max_invs_pend = max_invs_pend;
qinval_entry->q.dev_iotlb_inv_dsc.lo.res_2 = 0;
- qinval_entry->q.dev_iotlb_inv_dsc.lo.sid = sid;
+ qinval_entry->q.dev_iotlb_inv_dsc.lo.sid = PCI_BDF2(bus, devfn);
qinval_entry->q.dev_iotlb_inv_dsc.lo.res_3 = 0;
qinval_entry->q.dev_iotlb_inv_dsc.hi.size = size;
@@ -238,7 +299,7 @@ int __must_check qinval_device_iotlb_sync(struct iommu *iommu,
qinval_update_qtail(iommu, index);
spin_unlock_irqrestore(&iommu->register_lock, flags);
- return invalidate_sync(iommu);
+ return dev_invalidate_sync(iommu, did, seg, bus, devfn);
}
static int __must_check queue_invalidate_iec_sync(struct iommu *iommu,
diff --git a/xen/drivers/passthrough/vtd/x86/ats.c b/xen/drivers/passthrough/vtd/x86/ats.c
index dfa4d30..50190f2 100644
--- a/xen/drivers/passthrough/vtd/x86/ats.c
+++ b/xen/drivers/passthrough/vtd/x86/ats.c
@@ -116,7 +116,6 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
list_for_each_entry( pdev, &ats_devices, list )
{
- u16 sid = PCI_BDF2(pdev->bus, pdev->devfn);
bool_t sbit;
int rc = 0;
@@ -134,8 +133,9 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
/* invalidate all translations: sbit=1,bit_63=0,bit[62:12]=1 */
sbit = 1;
addr = (~0UL << PAGE_SHIFT_4K) & 0x7FFFFFFFFFFFFFFF;
- rc = qinval_device_iotlb_sync(iommu, pdev->ats_queue_depth,
- sid, sbit, addr);
+ rc = qinval_device_iotlb_sync(iommu, pdev->ats_queue_depth, did,
+ pdev->seg, pdev->bus, pdev->devfn,
+ sbit, addr);
break;
case DMA_TLB_PSI_FLUSH:
if ( !device_in_domain(iommu, pdev, did) )
@@ -154,8 +154,9 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
addr |= (((u64)1 << (size_order - 1)) - 1) << PAGE_SHIFT_4K;
}
- rc = qinval_device_iotlb_sync(iommu, pdev->ats_queue_depth,
- sid, sbit, addr);
+ rc = qinval_device_iotlb_sync(iommu, pdev->ats_queue_depth, did,
+ pdev->seg, pdev->bus, pdev->devfn,
+ sbit, addr);
break;
default:
dprintk(XENLOG_WARNING VTDPREFIX, "invalid vt-d flush type\n");
diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h
index 6ed29dd..e4940cd 100644
--- a/xen/include/xen/pci.h
+++ b/xen/include/xen/pci.h
@@ -118,6 +118,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
int pci_remove_device(u16 seg, u8 bus, u8 devfn);
int pci_ro_device(int seg, int bus, int devfn);
int pci_hide_device(int bus, int devfn);
+void pci_hide_existing_device(struct pci_dev *pdev);
struct pci_dev *pci_get_pdev(int seg, int bus, int devfn);
struct pci_dev *pci_get_real_pdev(int seg, int bus, int devfn);
struct pci_dev *pci_get_pdev_by_domain(
--
1.9.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-04-22 10:54 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-22 10:54 [PATCH v10 0/3] VT-d Device-TLB flush issue Quan Xu
2016-04-22 10:54 ` [PATCH v10 1/3] vt-d: add a timeout parameter for Queued Invalidation Quan Xu
2016-05-13 15:27 ` Jan Beulich
2016-05-16 15:25 ` Xu, Quan
2016-05-17 3:19 ` Tian, Kevin
2016-05-17 7:47 ` Jan Beulich
2016-05-18 12:53 ` Xu, Quan
2016-05-18 15:05 ` Jan Beulich
2016-05-19 0:32 ` Tian, Kevin
2016-05-19 1:35 ` Xu, Quan
2016-05-19 6:13 ` Jan Beulich
2016-05-19 11:26 ` Xu, Quan
2016-05-19 11:35 ` Jan Beulich
2016-05-19 15:14 ` Xu, Quan
2016-04-22 10:54 ` [PATCH v10 2/3] vt-d: synchronize for Device-TLB flush one by one Quan Xu
2016-05-17 12:36 ` Jan Beulich
2016-05-18 8:53 ` Xu, Quan
2016-05-18 9:29 ` Jan Beulich
2016-05-18 12:02 ` Xu, Quan
2016-04-22 10:54 ` Quan Xu [this message]
2016-05-17 14:00 ` [PATCH v10 3/3] vt-d: fix vt-d Device-TLB flush timeout issue Jan Beulich
2016-05-18 13:11 ` Xu, Quan
2016-05-20 7:15 ` Xu, Quan
2016-05-20 9:58 ` Jan Beulich
2016-05-23 14: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=1461322453-29216-4-git-send-email-quan.xu@intel.com \
--to=quan.xu@intel.com \
--cc=dario.faggioli@citrix.com \
--cc=feng.wu@intel.com \
--cc=jbeulich@suse.com \
--cc=kevin.tian@intel.com \
--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).