All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-4.10] passthrough/vtd: Don't DMA to the stack in queue_invalidate_wait()
@ 2017-10-19 11:26 Andrew Cooper
  2017-10-19 12:11 ` Jan Beulich
  2017-10-19 16:22 ` [PATCH for-4.10 v2] " Andrew Cooper
  0 siblings, 2 replies; 12+ messages in thread
From: Andrew Cooper @ 2017-10-19 11:26 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Kevin Tian, Julien Grall, Jan Beulich

DMA-ing to the stack is generally considered bad practice.  In this case, if a
timeout occurs because of a sluggish device which is processing the request,
the completion notification will corrupt the stack of a subsequent deeper call
tree.

Place the poll_slot in a percpu area and DMA to that instead.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Kevin Tian <kevin.tian@intel.com>
CC: Julien Grall <julien.grall@arm.com>

Julien: This wants backporting to all releases, and therefore should be
considered for 4.10 at this point.
---
 xen/drivers/passthrough/vtd/qinval.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/xen/drivers/passthrough/vtd/qinval.c b/xen/drivers/passthrough/vtd/qinval.c
index e95dc54..0ddda00 100644
--- a/xen/drivers/passthrough/vtd/qinval.c
+++ b/xen/drivers/passthrough/vtd/qinval.c
@@ -147,7 +147,8 @@ static int __must_check queue_invalidate_wait(struct iommu *iommu,
                                               u8 iflag, u8 sw, u8 fn,
                                               bool_t flush_dev_iotlb)
 {
-    volatile u32 poll_slot = QINVAL_STAT_INIT;
+    static DEFINE_PER_CPU(u32, poll_slot);
+    volatile u32 *this_poll_slot = &this_cpu(poll_slot);
     unsigned int index;
     unsigned long flags;
     u64 entry_base;
@@ -167,7 +168,7 @@ static int __must_check queue_invalidate_wait(struct iommu *iommu,
     qinval_entry->q.inv_wait_dsc.lo.res_1 = 0;
     qinval_entry->q.inv_wait_dsc.lo.sdata = QINVAL_STAT_DONE;
     qinval_entry->q.inv_wait_dsc.hi.res_1 = 0;
-    qinval_entry->q.inv_wait_dsc.hi.saddr = virt_to_maddr(&poll_slot) >> 2;
+    qinval_entry->q.inv_wait_dsc.hi.saddr = virt_to_maddr(this_poll_slot) >> 2;
 
     unmap_vtd_domain_page(qinval_entries);
     qinval_update_qtail(iommu, index);
@@ -182,7 +183,7 @@ static int __must_check queue_invalidate_wait(struct iommu *iommu,
         timeout = NOW() + MILLISECS(flush_dev_iotlb ?
                                     iommu_dev_iotlb_timeout : VTD_QI_TIMEOUT);
 
-        while ( poll_slot != QINVAL_STAT_DONE )
+        while ( *this_poll_slot != QINVAL_STAT_DONE )
         {
             if ( NOW() > timeout )
             {
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-10-23  8:06 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-19 11:26 [PATCH for-4.10] passthrough/vtd: Don't DMA to the stack in queue_invalidate_wait() Andrew Cooper
2017-10-19 12:11 ` Jan Beulich
2017-10-19 12:54   ` Andrew Cooper
2017-10-19 13:25     ` Jan Beulich
2017-10-19 13:31       ` Andrew Cooper
2017-10-19 16:22 ` [PATCH for-4.10 v2] " Andrew Cooper
2017-10-20  7:12   ` Jan Beulich
2017-10-20 17:55     ` Andrew Cooper
2017-10-23  7:05       ` Tian, Kevin
     [not found]       ` <AADFC41AFE54684AB9EE6CBC0274A5D190E3101C@SHSMSX101.ccr.corp.intel.com>
2017-10-23  7:06         ` Tian, Kevin
2017-10-23  7:18       ` Jan Beulich
2017-10-23  8:06         ` Andrew Cooper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.