From: "Xu, Quan" <quan.xu@intel.com>
To: xen-devel@lists.xen.org
Cc: Kevin Tian <kevin.tian@intel.com>,
dario.faggioli@citrix.com, Feng Wu <feng.wu@intel.com>,
Jan Beulich <jbeulich@suse.com>, Quan Xu <quan.xu@intel.com>
Subject: [PATCH v12 6/6] vt-d: fix vt-d Device-TLB flush timeout issue
Date: Fri, 24 Jun 2016 13:51:58 +0800 [thread overview]
Message-ID: <1466747518-54402-7-git-send-email-quan.xu@intel.com> (raw)
In-Reply-To: <1466747518-54402-1-git-send-email-quan.xu@intel.com>
From: Quan Xu <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>
CC: Jan Beulich <jbeulich@suse.com>
CC: Kevin Tian <kevin.tian@intel.com>
CC: Feng Wu <feng.wu@intel.com>
---
v12:
1. a forward declaration struct pci_ats_dev*, instead of
including ats.h.
2. eliminate the loop.
3. use the same logic for logging and crashing as I did in
other series (despite I have moved the domain crash logic
up to the generic IOMMU layer, I think I am better still
leave it as is).
4. enhance dev_invalidate_sync() with ASSERT().
---
xen/drivers/passthrough/pci.c | 6 +--
xen/drivers/passthrough/vtd/extern.h | 5 ++-
xen/drivers/passthrough/vtd/qinval.c | 75 +++++++++++++++++++++++++++++------
xen/drivers/passthrough/vtd/x86/ats.c | 9 +----
xen/include/xen/pci.h | 1 +
5 files changed, 71 insertions(+), 25 deletions(-)
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 98936f55c..843dc88 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -419,7 +419,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;
@@ -436,7 +436,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();
@@ -466,7 +466,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 45357f2..efaff28 100644
--- a/xen/drivers/passthrough/vtd/extern.h
+++ b/xen/drivers/passthrough/vtd/extern.h
@@ -25,6 +25,7 @@
#define VTDPREFIX "[VT-D]"
+struct pci_ats_dev;
extern bool_t rwbf_quirk;
void print_iommu_regs(struct acpi_drhd_unit *drhd);
@@ -60,8 +61,8 @@ 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);
+ struct pci_ats_dev *ats_dev,
+ u16 did, 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 4492b29..e4e2771 100644
--- a/xen/drivers/passthrough/vtd/qinval.c
+++ b/xen/drivers/passthrough/vtd/qinval.c
@@ -27,11 +27,11 @@
#include "dmar.h"
#include "vtd.h"
#include "extern.h"
+#include "../ats.h"
#define VTD_QI_TIMEOUT 1
-static int __must_check invalidate_sync(struct iommu *iommu,
- bool_t flush_dev_iotlb);
+static int __must_check invalidate_sync(struct iommu *iommu);
static void print_qi_regs(struct iommu *iommu)
{
@@ -103,7 +103,7 @@ static int __must_check queue_invalidate_context_sync(struct iommu *iommu,
unmap_vtd_domain_page(qinval_entries);
- return invalidate_sync(iommu, 0);
+ return invalidate_sync(iommu);
}
static int __must_check queue_invalidate_iotlb_sync(struct iommu *iommu,
@@ -140,7 +140,7 @@ static int __must_check queue_invalidate_iotlb_sync(struct iommu *iommu,
qinval_update_qtail(iommu, index);
spin_unlock_irqrestore(&iommu->register_lock, flags);
- return invalidate_sync(iommu, 0);
+ return invalidate_sync(iommu);
}
static int __must_check queue_invalidate_wait(struct iommu *iommu,
@@ -199,24 +199,73 @@ static int __must_check queue_invalidate_wait(struct iommu *iommu,
return -EOPNOTSUPP;
}
-static int __must_check invalidate_sync(struct iommu *iommu,
- bool_t flush_dev_iotlb)
+static int __must_check invalidate_sync(struct iommu *iommu)
{
struct qi_ctrl *qi_ctrl = iommu_qi_ctrl(iommu);
ASSERT(qi_ctrl->qinval_maddr);
- return queue_invalidate_wait(iommu, 0, 1, 1, flush_dev_iotlb);
+ return queue_invalidate_wait(iommu, 0, 1, 1, 0);
+}
+
+static void dev_invalidate_iotlb_timeout(struct iommu *iommu, u16 did,
+ struct pci_dev *pdev)
+{
+ struct domain *d = NULL;
+
+ 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();
+ ASSERT(pdev->domain);
+ list_del(&pdev->domain_list);
+ pdev->domain = NULL;
+ pci_hide_existing_device(pdev);
+ pcidevs_unlock();
+
+ if ( !d->is_shutting_down && printk_ratelimit() )
+ printk(XENLOG_WARNING VTDPREFIX
+ " dom%d: ATS device %04x:%02x:%02x.%u flush failed\n",
+ d->domain_id, pdev->seg, pdev->bus,
+ PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
+
+ if ( !is_hardware_domain(d) )
+ domain_crash(d);
+
+ rcu_unlock_domain(d);
+}
+
+static int __must_check dev_invalidate_sync(struct iommu *iommu, u16 did,
+ struct pci_dev *pdev)
+{
+ struct qi_ctrl *qi_ctrl = iommu_qi_ctrl(iommu);
+ int rc;
+
+ ASSERT(qi_ctrl->qinval_maddr);
+ rc = queue_invalidate_wait(iommu, 0, 1, 1, 1);
+
+ if ( rc == -ETIMEDOUT )
+ dev_invalidate_iotlb_timeout(iommu, did, pdev);
+
+ return rc;
}
int qinval_device_iotlb_sync(struct iommu *iommu,
- u32 max_invs_pend,
- u16 sid, u16 size, u64 addr)
+ struct pci_ats_dev *ats_dev,
+ u16 did, u16 size, u64 addr)
{
unsigned long flags;
unsigned int index;
u64 entry_base;
struct qinval_entry *qinval_entry, *qinval_entries;
+ struct pci_dev *pdev = ats_dev->pci_dev;
spin_lock_irqsave(&iommu->register_lock, flags);
index = qinval_next_index(iommu);
@@ -227,9 +276,9 @@ int qinval_device_iotlb_sync(struct iommu *iommu,
qinval_entry->q.dev_iotlb_inv_dsc.lo.type = TYPE_INVAL_DEVICE_IOTLB;
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.max_invs_pend = ats_dev->ats_queue_depth;
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(pdev->bus, pdev->devfn);
qinval_entry->q.dev_iotlb_inv_dsc.lo.res_3 = 0;
qinval_entry->q.dev_iotlb_inv_dsc.hi.size = size;
@@ -240,7 +289,7 @@ int qinval_device_iotlb_sync(struct iommu *iommu,
qinval_update_qtail(iommu, index);
spin_unlock_irqrestore(&iommu->register_lock, flags);
- return invalidate_sync(iommu, 1);
+ return dev_invalidate_sync(iommu, did, pdev);
}
static int __must_check queue_invalidate_iec_sync(struct iommu *iommu,
@@ -271,7 +320,7 @@ static int __must_check queue_invalidate_iec_sync(struct iommu *iommu,
qinval_update_qtail(iommu, index);
spin_unlock_irqrestore(&iommu->register_lock, flags);
- ret = invalidate_sync(iommu, 0);
+ ret = invalidate_sync(iommu);
/*
* reading vt-d architecture register will ensure
diff --git a/xen/drivers/passthrough/vtd/x86/ats.c b/xen/drivers/passthrough/vtd/x86/ats.c
index a6c53ea..be2a155 100644
--- a/xen/drivers/passthrough/vtd/x86/ats.c
+++ b/xen/drivers/passthrough/vtd/x86/ats.c
@@ -121,15 +121,12 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
list_for_each_entry( pdev, &ats_devices, list )
{
struct pci_dev *pci_dev = pdev->pci_dev;
- u16 sid;
bool_t sbit;
int rc = 0;
if ( !pci_dev )
continue;
- sid = PCI_BDF2(pci_dev->bus, pci_dev->devfn);
-
/* Only invalidate devices that belong to this IOMMU */
if ( pdev->iommu != iommu )
continue;
@@ -144,8 +141,7 @@ 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, did, sbit, addr);
break;
case DMA_TLB_PSI_FLUSH:
if ( !device_in_domain(iommu, pdev, did) )
@@ -164,8 +160,7 @@ 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, did, 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-06-24 5:51 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-24 5:51 [PATCH v12 0/6] VT-d Device-TLB flush issue Xu, Quan
2016-06-24 5:51 ` [PATCH v12 1/6] IOMMU: add a timeout parameter for device IOTLB invalidation Xu, Quan
2016-06-24 11:30 ` Tian, Kevin
2016-06-27 8:03 ` Jan Beulich
2016-06-27 8:19 ` Xu, Quan
2016-06-27 8:28 ` Jan Beulich
2016-06-27 8:34 ` Xu, Quan
2016-06-24 5:51 ` [PATCH v12 2/6] vt-d: synchronize for Device-TLB flush one by one Xu, Quan
2016-06-24 11:33 ` Tian, Kevin
2016-06-24 5:51 ` [PATCH v12 3/6] vt-d: convert conditionals of qi_ctrl->qinval_maddr into ASSERT()s Xu, Quan
2016-06-24 11:35 ` Tian, Kevin
2016-06-24 5:51 ` [PATCH v12 4/6] IOMMU/x86: using a struct pci_dev* instead of SBDF Xu, Quan
2016-06-24 11:46 ` Tian, Kevin
2016-06-26 8:57 ` Xu, Quan
2016-06-26 10:32 ` Xu, Quan
2016-06-29 1:59 ` Tian, Kevin
2016-06-27 8:17 ` Jan Beulich
2016-06-27 8:25 ` Jan Beulich
2016-06-27 11:11 ` Xu, Quan
2016-06-27 15:19 ` Jan Beulich
2016-06-28 1:31 ` Xu, Quan
2016-06-24 5:51 ` [PATCH v12 5/6] IOMMU: move the domain crash logic up to the generic IOMMU layer Xu, Quan
2016-06-24 11:48 ` Tian, Kevin
2016-06-26 8:58 ` Xu, Quan
2016-06-27 8:18 ` Jan Beulich
2016-06-24 5:51 ` Xu, Quan [this message]
2016-06-24 11:55 ` [PATCH v12 6/6] vt-d: fix vt-d Device-TLB flush timeout issue Tian, Kevin
2016-06-24 12:54 ` Jan Beulich
2016-06-26 9:18 ` Xu, Quan
2016-06-27 7:56 ` Jan Beulich
2016-06-27 8:24 ` Jan Beulich
2016-06-27 12:56 ` Xu, Quan
2016-06-27 15:21 ` Jan Beulich
2016-06-28 7:06 ` Xu, Quan
2016-06-28 7:24 ` Jan Beulich
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=1466747518-54402-7-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).