VT-d Device-TLB flush issue
v9 cover VT-d Device-TLB flush issue
This patches fix current timeout concern and also allow limited ATS support:
1. Add a command line parameter for Queued Invalidation
The command line parameter 'vtd_qi_timeout' specifies the timeout of the VT-d Queued Invalidation in milliseconds. By default, the timeout is 1ms, which can be boot-time changed.
Add a __must_check annotation. The followup patch titled 'VT-d IOTLB/Context/IEC flush issue' addresses the __mustcheck. That is the other callers of this routine (two or three levels up) ignore the return code. This patch does not address this but the other does.
2. wrap a _sync version for all VT-d flush interfaces
The dev_invalidate_iotlb() scans ats_devices list to flush ATS devices, and the invalidate_sync() is put after dev_invalidate_iotlb() to synchronize with hardware for flush status. If we assign multiple ATS devices to a domain, the flush status is about all these multiple ATS devices. Once flush timeout expires, we couldn't find out which one is the buggy ATS device.
Then, The invalidate_sync() variant (We need to pass down the device's SBDF to hide the ATS device) is put within dev_invalidate_iotlb() to synchronize for the flush status one by one. If flush timeout expires, we could find out the buggy ATS device and hide it. However, for other VT-d flush interfaces, the invalidate_sync() is still put after at present. This is inconsistent.
So we wrap a _sync version for all VT-d flush interfaces. It simplifies caller logic and makes code more readable as well.
3. Fix vt-d Device-TLB flush timeout issue
If Device-TLB flush timed out, we would hide the target ATS device and crash the domain owning this ATS device. If impacted domain is hardware domain, just throw out a warning (done in queue_invalidate_wait).
By hiding the device, we make sure it can't be assigned to any domain any longer (see device_assigned).
**NOTE**
This patch set should base on one prereq patch sets:
a). Check VT-d Device-TLB flush error.
----
Not covered in this series:
a) Eliminate the panic() in IOMMU_WAIT_OP, used only in VT-d register read/write. Further discussion is required on whether and how to improve it.
b) Handle IOTLB/Context/IEC flush timeout.
--Changes in v9:
#patch 1
* Enhance the commit message and docs/misc/xen-command-line.markdown.
#patch 2
* Enhance the commit message.
* Add function declaration at the head of file, and then we don't need pure code movement.
#patch 3
* Enhance the commit message.
* 'ASSERT ( pdev->domain )' to 'ASSERT(pdev->domain)'
Quan Xu (3):
VT-d: add a command line parameter for Queued Invalidation
VT-d: wrap a _sync version for all VT-d flush interfaces
VT-d: Fix vt-d Device-TLB flush timeout issue
docs/misc/xen-command-line.markdown | 18 +++++ xen/drivers/passthrough/pci.c | 6 +- xen/drivers/passthrough/vtd/extern.h | 3 + xen/drivers/passthrough/vtd/qinval.c | 131 ++++++++++++++++++++++++++++------ xen/drivers/passthrough/vtd/x86/ats.c | 15 ++-- xen/include/xen/pci.h | 1 + 6 files changed, 141 insertions(+), 33 deletions(-)
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v9 1/3 VT-d: add a command line parameter for Queued Invalidation
The command line parameter 'vtd_qi_timeout' specifies the timeout of the VT-d Queued Invalidation in milliseconds. By default, the timeout is 1ms, which can be boot-time changed.
Add a __must_check annotation. The followup patch titled 'VT-d IOTLB/Context/IEC flush issue' addresses the __mustcheck. That is the other callers of this routine (two or three levels up) ignore the return code. This patch does not address this but the other does.
--- docs/misc/xen-command-line.markdown | 18 ++++++++++++++++++ xen/drivers/passthrough/vtd/qinval.c | 17 ++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-)
docs/misc/xen-command-line.markdown +18 -0
@@ -1532,6 +1532,24 @@ Note that if **watchdog** option is also specified vpmu will be turned off. As the virtualisation is not 100% safe, don't use the vpmu flag on production systems (see http://xenbits.xen.org/xsa/advisory-163.html)! +### vtd\_qi\_timeout (VT-d) +> `= <integer>` + +> Default: `1` + +Specify the timeout of the VT-d Queued Invalidation in milliseconds. +By default, the spin timeout is 1ms, which can be boot-time changed. + +In current code, VT-d Queued Invalidation includes Device-TLB, IOTLB, +Context and IEC flush. If Device-TLB flush timed out, we would hide +the target ATS device and crash the domain owning this ATS device. +If impacted domain is hardware domain, just throw out a warning (done +in queue\_invalidate\_wait). IOTLB, Context and IEC flush timeout are +still in TODO-list. + +When you see error 'Queue invalidate wait descriptor timed out', try +increasing the vtd\_qi\_timeout to 10ms or more. + ### watchdog > `= force | <boolean>`
xen/drivers/passthrough/vtd/qinval.c +12 -5
@@ -28,6 +28,11 @@#include "vtd.h" #include "extern.h" +static unsigned int __read_mostly vtd_qi_timeout =1 ; +integer_param ("vtd_qi_timeout" , vtd_qi_timeout); + +#define IOMMU_QI_TIMEOUT (vtd_qi_timeout * MILLISECS(1)) +static void print_qi_regs (struct iommu *iommu) {u64 val;
@@ -130,10 +135,10 @@ static void queue_invalidate_iotlb(struct iommu *iommu,spin_unlock_irqrestore (&iommu->register_lock, flags); } -static int queue_invalidate_wait (struct iommu *iommu, +static int __must_check queue_invalidate_wait (struct iommu *iommu,u8 iflag,u8 sw,u8 fn) { -s_time_t start_time; +s_time_t timeout;volatile u32 poll_slot =QINVAL_STAT_INIT ;unsigned int index;unsigned long flags;
@@ -164,13 +169,15 @@ static int queue_invalidate_wait(struct iommu *iommu,if ( sw ) {/* In case all wait descriptor writes to same addr with same data */ - start_time =NOW (); + timeout =NOW () +IOMMU_QI_TIMEOUT ;while ( poll_slot !=QINVAL_STAT_DONE ) { -if (NOW () > (start_time +DMAR_OPERATION_TIMEOUT ) ) +if (NOW () > timeout ) {print_qi_regs (iommu); -panic ("queue invalidate wait descriptor was not executed" ); + printk(XENLOG_WARNING VTDPREFIX + "Queue invalidate wait descriptor timed out.\n"); +return -ETIMEDOUT ; }cpu_relax (); }
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v9 1/3] VT-d: add a command line parameter for Queued Invalidation
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
The subject should mention "timeout", perhaps either in addition to or in place of "command line".
docs/misc/xen-command-line.markdown Note that if **watchdog** option is also specified vpmu will be turned off. · line 1541
Quoted 13 lines
docs/misc/xen-command-line.markdown +7
-0@@ -1532,6 +1532,24 @@ Note that if **watchdog** option is also specified vpmu will be turned off. As the virtualisation is not 100% safe, don't use the vpmu flag on production systems (see http://xenbits.xen.org/xsa/advisory-163.html)! +### vtd\_qi\_timeout (VT-d) +> `= <integer>` + +> Default: `1` + +Specify the timeout of the VT-d Queued Invalidation in milliseconds. +By default, the spin timeout is 1ms, which can be boot-time changed.
Especially the part after the comma makes little sense considering which file we're in.
docs/misc/xen-command-line.markdown Note that if **watchdog** option is also specified vpmu will be turned off. · line 1548
Quoted 6 lines
docs/misc/xen-command-line.markdown +6
-0+In current code, VT-d Queued Invalidation includes Device-TLB, IOTLB, +Context and IEC flush. If Device-TLB flush timed out, we would hide +the target ATS device and crash the domain owning this ATS device. +If impacted domain is hardware domain, just throw out a warning (done +in queue\_invalidate\_wait). IOTLB, Context and IEC flush timeout are +still in TODO-list.
Much of this doesn't seem to belong here either.
docs/misc/xen-command-line.markdown Note that if **watchdog** option is also specified vpmu will be turned off. · line 1551
Quoted 2 lines
docs/misc/xen-command-line.markdown +2
-0+When you see error 'Queue invalidate wait descriptor timed out', try +increasing the vtd\_qi\_timeout to 10ms or more.
Why 10ms? (If there's no specific reason, I think you'd better drop any explicit number.) Also there's no reason the spell out the command line option again here - the context makes clear which value needs increasing.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v9 1/3] VT-d: add a command line parameter for Queued Invalidation
Quoted 5 lines · On April 05, 2016 5:09pm, <[email protected]> wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
The subject should mention "timeout", perhaps either in addition to or in place of "command line".
I prefer "VT-d: add a timeout parameter for Queued Invalidation".
Quoted 7 lines
docs/misc/xen-command-line.markdown Note that if **watchdog** option is also
Quoted 3 lines
docs/misc/xen-command-line.markdown +0
-0@@ -1532,6 +1532,24 @@ Note that if **watchdog** option is alsospecified vpmu will be turned off.
Quoted 3 lines
docs/misc/xen-command-line.markdown +0
-0As the virtualisation is not 100% safe, don't use the vpmu flag onproduction systems (see http://xenbits.xen.org/xsa/advisory-163.html)!
Quoted 10 lines
docs/misc/xen-command-line.markdown Note that if **watchdog** option is also specified vpmu will be turned off. · line 1541
Quoted 7 lines
docs/misc/xen-command-line.markdown +7
-0+### vtd\_qi\_timeout (VT-d) +> `= <integer>` + +> Default: `1` + +Specify the timeout of the VT-d Queued Invalidation in milliseconds. +By default, the spin timeout is 1ms, which can be boot-time changed.Especially the part after the comma makes little sense considering which file we're in.
Agreed.
Quoted 10 lines
docs/misc/xen-command-line.markdown Note that if **watchdog** option is also specified vpmu will be turned off. · line 1548
Quoted 7 lines
docs/misc/xen-command-line.markdown +6
-0+In current code, VT-d Queued Invalidation includes Device-TLB, IOTLB, +Context and IEC flush. If Device-TLB flush timed out, we would hide +the target ATS device and crash the domain owning this ATS device. +If impacted domain is hardware domain, just throw out a warning (done +in queue\_invalidate\_wait). IOTLB, Context and IEC flush timeout are +still in TODO-list.Much of this doesn't seem to belong here either.
Could I drop it?
Quoted 5 lines
docs/misc/xen-command-line.markdown Note that if **watchdog** option is also specified vpmu will be turned off. · line 1551
Quoted 2 lines
docs/misc/xen-command-line.markdown +2
-0+When you see error 'Queue invalidate wait descriptor timed out', try +increasing the vtd\_qi\_timeout to 10ms or more.Why 10ms? (If there's no specific reason, I think you'd better drop any explicit number.)
Yes, no specific reason.
Also there's no reason the spell out the command line option again
Quoted 2 lines
here - the context makes clear which value needs increasing.
Agreed.
Then, the new description of xen-command-line.markdown:
+### vtd\_qi\_timeout (VT-d)
+> = <integer>
+
+> Default: 1
+
+Specify the timeout of the VT-d Queued Invalidation in milliseconds. +By default, the timeout is 1ms.
+
+When you see error 'Queue invalidate wait descriptor timed out', try +increasing this value.
+
Any more suggestion?
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v9 1/3] VT-d: add a command line parameter for Queued Invalidation
Quoted 15 lines
From: Xu, Quan
Sent: Thursday, April 07, 2016 9:49 AMQuoted 10 lines
docs/misc/xen-command-line.markdown Note that if **watchdog** option is also specified vpmu will be turned off. · line 1548
Quoted 7 lines
docs/misc/xen-command-line.markdown +6
-0+In current code, VT-d Queued Invalidation includes Device-TLB, IOTLB, +Context and IEC flush. If Device-TLB flush timed out, we would hide +the target ATS device and crash the domain owning this ATS device. +If impacted domain is hardware domain, just throw out a warning (done +in queue\_invalidate\_wait). IOTLB, Context and IEC flush timeout are +still in TODO-list.Much of this doesn't seem to belong here either.
Quoted 1 line
Could I drop it?
yes, please do it. Above belongs to either a patch commit or code comment.
Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v9 2/3 VT-d: wrap a _sync version for all VT-d flush interfaces
In reply to Quan XuThe dev_invalidate_iotlb() scans ats_devices list to flush ATS devices, and the invalidate_sync() is put after dev_invalidate_iotlb() to synchronize with hardware for flush status. If we assign multiple ATS devices to a domain, the flush status is about all these multiple ATS devices. Once flush timeout expires, we couldn't find out which one is the buggy ATS device.
Then, The invalidate_sync() variant (We need to pass down the device's SBDF to hide the ATS device) is put within dev_invalidate_iotlb() to synchronize for the flush status one by one. If flush timeout expires, we could find out the buggy ATS device and hide it. However, for other VT-d flush interfaces, the invalidate_sync() is still put after at present. This is inconsistent.
So we wrap a _sync version for all VT-d flush interfaces. It simplifies caller logic and makes code more readable as well.
--- xen/drivers/passthrough/vtd/extern.h | 2 ++ xen/drivers/passthrough/vtd/qinval.c | 60 +++++++++++++++++++++++++---------- xen/drivers/passthrough/vtd/x86/ats.c | 12 +++---- 3 files changed, 50 insertions(+), 24 deletions(-)
xen/drivers/passthrough/vtd/extern.h +2 -0
@@ -61,6 +61,8 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,int qinval_device_iotlb (struct iommu *iommu,u32 max_invs_pend,u16 sid,u16 size,u64 addr); +int qinval_device_iotlb_sync (struct iommu *iommu,u32 max_invs_pend, +u16 sid,u16 size,u64 addr);unsigned int get_cache_line_size (void );void cacheline_flush (char *);
xen/drivers/passthrough/vtd/qinval.c +44 -16
121 lines not on this page · raw message
xen/drivers/passthrough/vtd/x86/ats.c +4 -8
@@ -118,7 +118,6 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did, {u16 sid =PCI_BDF2 (pdev->bus, pdev->devfn);bool_t sbit; -int rc =0 ;/* Only invalidate devices that belong to this IOMMU */ if ( pdev->iommu != iommu )
@@ -134,8 +133,8 @@ 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 (iommu, pdev->ats_queue_depth, - sid, sbit, addr); + ret =qinval_device_iotlb_sync (iommu, pdev->ats_queue_depth, + sid, sbit, addr);break ;case DMA_TLB_PSI_FLUSH :if ( !device_in_domain (iommu, pdev, did) )
@@ -154,16 +153,13 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did, addr |= (((u64 )1 << (size_order -1 )) -1 ) <<PAGE_SHIFT_4K ; } - rc =qinval_device_iotlb (iommu, pdev->ats_queue_depth, - sid, sbit, addr); + ret =qinval_device_iotlb_sync (iommu, pdev->ats_queue_depth, + sid, sbit, addr);break ;default : dprintk(XENLOG_WARNING VTDPREFIX, "invalid vt-d flush type\n");return -EOPNOTSUPP ; } - -if ( !ret ) - ret = rc; }return ret;
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v9 2/3] VT-d: wrap a _sync version for all VT-d flush interfaces
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
The
dev_invalidate_iotlb()scansats_deviceslist to flush ATS devices, and theinvalidate_sync()is put afterdev_invalidate_iotlb()to synchronize with hardware for flush status. If we assign multiple ATS devices to a domain, the flush status is about all these multiple ATS devices. Once flush timeout expires, we couldn't find out which one is the buggy ATS device.
Is that true? Or is that just a limitation of our implementation?
Quoted 3 lines
Then, The
invalidate_sync()variant (We need to pass down the device's SBDF to hide the ATS device) is put withindev_invalidate_iotlb()to synchronize for the flush status one by one.
I don't think this is stating current state of things. So ...
Quoted 4 lines
If flush timeout expires,
we could find out the buggy ATS device and hide it. However, for other VT-d flush interfaces, theinvalidate_sync()is still put after at present. This is inconsistent.
... taken together, what is inconsistent here needs to be described better, as well as what it is you do to eliminate the inconsistency. Note that you should not refer back (or imply knowledge of) the previous discussion on the earlier version. In any of that discussion is useful here, you need to summarize it instead.
xen/drivers/passthrough/vtd/extern.h int dev_invalidate_iotlb(struct iommu *iommu, u16 did, · line 65
Quoted 8 lines
xen/drivers/passthrough/vtd/extern.h +2
-0@@ -61,6 +61,8 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,int qinval_device_iotlb (struct iommu *iommu,u32 max_invs_pend,u16 sid,u16 size,u64 addr); +int qinval_device_iotlb_sync (struct iommu *iommu,u32 max_invs_pend, +u16 sid,u16 size,u64 addr);
So are then both functions needed to be externally accessible? That would seem contrary to the last paragraph of the patch description.
xen/drivers/passthrough/vtd/qinval.c integer_param("vtd_qi_timeout", vtd_qi_timeout); · line 37
Quoted 8 lines
xen/drivers/passthrough/vtd/qinval.c +2
-0@@ -33,6 +33,10 @@ integer_param("vtd_qi_timeout", vtd_qi_timeout);#define IOMMU_QI_TIMEOUT (vtd_qi_timeout * MILLISECS(1)) +static int __must_check queue_invalidate_wait (struct iommu *iommu, +u8 iflag,u8 sw,u8 fn);
Indentation.
xen/drivers/passthrough/vtd/qinval.c static void queue_invalidate_context(struct iommu *iommu, · line 109
Quoted 5 lines
xen/drivers/passthrough/vtd/qinval.c +1
-0@@ -102,6 +106,15 @@ static void queue_invalidate_context(struct iommu *iommu,unmap_vtd_domain_page (qinval_entries); } +static int queue_invalidate_context_sync(struct iommu *iommu,
__must_check?
xen/drivers/passthrough/vtd/qinval.c static void queue_invalidate_context(struct iommu *iommu, · line 110
Quoted 1 line
xen/drivers/passthrough/vtd/qinval.c +1
-0+ u16 did, u16 source_id, u8 function_mask, u8 granu)
Indentation again.
xen/drivers/passthrough/vtd/qinval.c static void queue_invalidate_context(struct iommu *iommu, · line 116
Quoted 6 lines
xen/drivers/passthrough/vtd/qinval.c +6
-0+{ +queue_invalidate_context (iommu, did, source_id, + function_mask, granu); + +return invalidate_sync (iommu); +}
Further down you replace the only call to queue_invalidate_context() - why keep both functions instead of just making the existing one do the sync? (That would the likely also apply to qinval_device_iotlb() and others below.)
Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c +0
-2@@ -338,23 +365,24 @@ static int flush_iotlb_qi(if ( qi_ctrl->qinval_maddr !=0 ) { -int rc; -/* use queued invalidation */ if (cap_write_drain (iommu->cap)) dw =1 ;if (cap_read_drain (iommu->cap))
xen/drivers/passthrough/vtd/qinval.c static int flush_iotlb_qi( · line 378
Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c +5
-3dr =1 ;/* Need to conside the ih bit later */ -queue_invalidate_iotlb (iommu, - type >>DMA_TLB_FLUSH_GRANU_OFFSET , dr, - dw, did, size_order,0 , addr); + ret =queue_invalidate_iotlb_sync (iommu, + type >>DMA_TLB_FLUSH_GRANU_OFFSET , dr, dw, did, + size_order,0 , addr); + +/* TODO: Timeout error handling to be added later */
As of today queue_invalidate_wait() panics, so this comment is not very helpful as there is not timeout that could possibly be detected here.
xen/drivers/passthrough/vtd/qinval.c static int flush_iotlb_qi( · line 384
Quoted 9 lines
xen/drivers/passthrough/vtd/qinval.c +3
-3+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; }
I think leaving the existing logic as is would be better - best effort invalidation even when an error has occurred.
Quoted 28 lines
xen/drivers/passthrough/vtd/x86/ats.c +3
-5@@ -118,7 +118,6 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did, {u16 sid =PCI_BDF2 (pdev->bus, pdev->devfn);bool_t sbit; -int rc =0 ;/* Only invalidate devices that belong to this IOMMU */ if ( pdev->iommu != iommu )@@ -134,8 +133,8 @@ 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 (iommu, pdev->ats_queue_depth, - sid, sbit, addr); + ret =qinval_device_iotlb_sync (iommu, pdev->ats_queue_depth, + sid, sbit, addr);break ;case DMA_TLB_PSI_FLUSH :if ( !device_in_domain (iommu, pdev, did) )@@ -154,16 +153,13 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did, addr |= (((u64 )1 << (size_order -1 )) -1 ) <<PAGE_SHIFT_4K ; } - rc =qinval_device_iotlb (iommu, pdev->ats_queue_depth, - sid, sbit, addr); + ret = qinval_device_iotlb_sync(iommu, pdev->ats_queue_depth,
xen/drivers/passthrough/vtd/x86/ats.c int dev_invalidate_iotlb(struct iommu *iommu, u16 did, · line 163
Quoted 10 lines
xen/drivers/passthrough/vtd/x86/ats.c +1
-3+ sid, sbit, addr);break ;default : dprintk(XENLOG_WARNING VTDPREFIX, "invalid vt-d flush type\n");return -EOPNOTSUPP ; } - -if ( !ret ) - ret = rc; }
The removal of "rc" (which btw is unrelated to the purpose of your patch) means that if an earlier iteration encountering an error is followed by later successful ones, no error would get reported to the caller. Hence this part of the change needs to be undone.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v9 2/3] VT-d: wrap a _sync version for all VT-d flush interfaces
Quoted 10 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
The
dev_invalidate_iotlb()scansats_deviceslist to flush ATS devices, and theinvalidate_sync()is put afterdev_invalidate_iotlb()to synchronize with hardware for flush status. If we assign multiple ATS devices to a domain, the flush status is about all these multiple ATS devices. Once flush timeout expires, we couldn't find out which one is the buggy ATS device.Is that true? Or is that just a limitation of our implementation?
IMO, both.
I hope vt-d maintainers help me double check it.
Quoted 11 lines
Quoted 3 lines
Then, The
invalidate_sync()variant (We need to pass down the device's SBDF to hide the ATS device) is put withindev_invalidate_iotlb()to synchronize for the flush status one by one.I don't think this is stating current state of things. So ...
Quoted 4 lines
If flush timeout expires,
we could find out the buggy ATS device and hide it. However, for other VT-d flush interfaces, theinvalidate_sync()is still put after at present. This is inconsistent.
Quoted 6 lines
... taken together, what is inconsistent here needs to be described better, as well as what it is you do to eliminate the inconsistency. Note that you should not refer back (or imply knowledge of) the previous discussion on the earlier version.
In any of that discussion is useful here, you need to summarize it instead.
I will continue to summarize it and send out later.
Quoted 5 lines
Quoted 5 lines
xen/drivers/passthrough/vtd/extern.h +0
-0@@ -61,6 +61,8 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
Quoted 9 lines
xen/drivers/passthrough/vtd/extern.h int dev_invalidate_iotlb(struct iommu *iommu, u16 did, · line 65
Quoted 5 lines
xen/drivers/passthrough/vtd/extern.h +2
-0int qinval_device_iotlb (struct iommu *iommu,u32 max_invs_pend,u16 sid,u16 size,u64 addr); +int qinval_device_iotlb_sync (struct iommu *iommu,u32 max_invs_pend, +u16 sid,u16 size,u64 addr);So are then both functions needed to be externally accessible? That would seem contrary to the last paragraph of the patch description.
I was aware of this. I'd better make the qinval_device_iotlb() a static one in next v10.
[...]
Quoted 4 lines
xen/drivers/passthrough/vtd/extern.h int dev_invalidate_iotlb(struct iommu *iommu, u16 · line 68
Quoted 1 line
xen/drivers/passthrough/vtd/extern.h +1
-0+static int queue_invalidate_context_sync(struct iommu *iommu,
__must_check?
Agreed.
[...]
Quoted 12 lines
xen/drivers/passthrough/vtd/extern.h int dev_invalidate_iotlb(struct iommu *iommu, u16
Quoted 6 lines
xen/drivers/passthrough/vtd/extern.h +6
-0+{ +queue_invalidate_context (iommu, did, source_id, + function_mask, granu); + +return invalidate_sync (iommu); +}Further down you replace the only call to
queue_invalidate_context()- why keep both functions instead of just making the existing one do the sync? (That would the likely also apply toqinval_device_iotlb()and others below.)
It is optional.
I think:
1. in the long term, we may need no _sync version.
2. At least, the current wrap looks good to me. e.g. queue_invalidate_context() is for context-cache Invalidate Descriptor, and the invalidate_sync() is for Invalidation Wait Descriptor. It is much clearer.
Quoted 22 lines
Quoted 4 lines
xen/drivers/passthrough/vtd/extern.h +0
-0@@ -338,23 +365,24 @@ static int flush_iotlb_qi(if ( qi_ctrl->qinval_maddr !=0 ) {xen/drivers/passthrough/vtd/extern.h static int flush_iotlb_qi( · line 350
Quoted 10 lines
xen/drivers/passthrough/vtd/extern.h +0
-4-int rc; -/* use queued invalidation */ if (cap_write_drain (iommu->cap)) dw =1 ;if (cap_read_drain (iommu->cap)) dr =1 ;/* Need to conside the ih bit later */ - queue_invalidate_iotlb(iommu, - type >>
DMA_TLB_FLUSH_GRANU_OFFSET, dr,xen/drivers/passthrough/vtd/extern.h static int flush_iotlb_qi( · line 378
Quoted 6 lines
xen/drivers/passthrough/vtd/extern.h +5
-1- dw, did, size_order, 0, addr); + ret =queue_invalidate_iotlb_sync (iommu, + type >>DMA_TLB_FLUSH_GRANU_OFFSET , dr, dw, did, + size_order,0 , addr); + +/* TODO: Timeout error handling to be added later */
Quoted 3 lines
As of today
queue_invalidate_wait()panics, so this comment is not very helpful as there is not timeout that could possibly be detected here.
Okay, I will drop it.
Quoted 10 lines
xen/drivers/passthrough/vtd/extern.h static int flush_iotlb_qi( · line 384
Quoted 9 lines
xen/drivers/passthrough/vtd/extern.h +3
-3+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; }
Quoted 3 lines
I think leaving the existing logic as is would be better - best effort invalidation even when an error has occurred.
I have an open:
As vt-d spec(:Queued Invalidation Ordering Considerations) said,
1. If the Fence(FN) flag is 1 in a inv_wait_dsc, hardware must execute descriptors following the inv_wait_dsc only after wait command is completed.
2. when a Device-TLB invalidation timeout is detected, hardware must not complete any pending inv_wait_dsc commands.
In current code, the Fence(FN) is always 1.
if a Device-TLB invalidation timeout is detected, this additional inv_wait_dsc is not completed.__iiuc__,
the new coming descriptors, in that queue, _might_ be not executed any more, waiting for this additional inv_wait_dsc which is not completed. is it true?
Quoted 45 lines
xen/drivers/passthrough/vtd/x86/ats.c int dev_invalidate_iotlb(struct iommu *iommu, u16
Quoted 3 lines
xen/drivers/passthrough/vtd/x86/ats.c +0
-0@@ -118,7 +118,6 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16did,
xen/drivers/passthrough/vtd/x86/ats.c int dev_invalidate_iotlb(struct iommu *iommu, u16
Quoted 8 lines
xen/drivers/passthrough/vtd/x86/ats.c +0
-1{u16 sid =PCI_BDF2 (pdev->bus, pdev->devfn);bool_t sbit; -int rc =0 ;/* Only invalidate devices that belong to this IOMMU */ if ( pdev->iommu != iommu )@@ -134,8 +133,8 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16did,
xen/drivers/passthrough/vtd/x86/ats.c int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
Quoted 6 lines
xen/drivers/passthrough/vtd/x86/ats.c +1
-2/* invalidate all translations: sbit=1,bit_63=0,bit[62:12]=1 */ sbit =1 ; addr = (~0UL <<PAGE_SHIFT_4K ) &0x7FFFFFFFFFFFFFFF ; - rc =qinval_device_iotlb (iommu, pdev->ats_queue_depth, - sid, sbit, addr); + ret = qinval_device_iotlb_sync(iommu,
pdev->ats_queue_depth,xen/drivers/passthrough/vtd/x86/ats.c int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
Quoted 6 lines
xen/drivers/passthrough/vtd/x86/ats.c +2
-0+ sid, sbit, addr);break ;case DMA_TLB_PSI_FLUSH : if ( !device_in_domain(iommu, pdev, did) ) @@ -154,16 +153,13 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did, addr |= (((u64)1 << (size_order - 1)) - 1) <<
PAGE_SHIFT_4K;xen/drivers/passthrough/vtd/x86/ats.c int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
Quoted 5 lines
}xen/drivers/passthrough/vtd/x86/ats.c +1
-2- rc =qinval_device_iotlb (iommu, pdev->ats_queue_depth, - sid, sbit, addr); + ret = qinval_device_iotlb_sync(iommu,
pdev->ats_queue_depth,Quoted 4 lines
+ sid, sbit, addr);
break;
default:
dprintk(XENLOG_WARNING VTDPREFIX, "invalid vt-d flushtype\n");
xen/drivers/passthrough/vtd/x86/ats.c
Quoted 6 lines
return -EOPNOTSUPP; }xen/drivers/passthrough/vtd/x86/ats.c +0
-3- -if ( !ret ) - ret = rc; }
Quoted 5 lines
The removal of "rc" (which btw is unrelated to the purpose of your patch) means that if an earlier iteration encountering an error is followed by later successful ones, no error would get reported to the caller. Hence this part of the change needs to be undone.
Agreed.
I tried to drop rc, as the ret was always zero in previous code.
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v9 2/3] VT-d: wrap a _sync version for all VT-d flush interfaces
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 09:44, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
xen/drivers/passthrough/vtd/qinval.c static void queue_invalidate_context(struct iommu *iommu, · line 116
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +6
-0+{ +queue_invalidate_context (iommu, did, source_id, + function_mask, granu); + +return invalidate_sync (iommu); +}Further down you replace the only call to
queue_invalidate_context()- why keep both functions instead of just makingthe
Quoted 3 lines
existing one do the sync? (That would the likely also apply to
qinval_device_iotlb()and others below.)
Quoted 7 lines
It is optional.
I think:
1. in the long term, we may need no_syncversion.
2. At least, the current wrap looks good to me. e.g.queue_invalidate_context()is for context-cache Invalidate Descriptor, and theinvalidate_sync()is for Invalidation Wait Descriptor. It is much clearer.
I don't really agree, but will leave it to the VT-d maintainers to judge.
Quoted 15 lines
Quoted 11 lines
xen/drivers/passthrough/vtd/qinval.c static int flush_iotlb_qi( · line 384
Quoted 9 lines
xen/drivers/passthrough/vtd/qinval.c +3
-3+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; }I think leaving the existing logic as is would be better - best effort
invalidation
Quoted 2 lines
even when an error has occurred.
Quoted 13 lines
I have an open:
As vt-d spec(:Queued Invalidation Ordering Considerations) said,
1. If the Fence(FN) flag is 1 in ainv_wait_dsc, hardware must execute
descriptors following theinv_wait_dsconly after wait command is completed.
2. when a Device-TLB invalidation timeout is detected, hardware must
not complete any pendinginv_wait_dsccommands.
In current code, the Fence(FN) is always 1.
if a Device-TLB invalidation timeout is detected, this additionalinv_wait_dscis not completed.__iiuc__,
the new coming descriptors, in that queue, _might_ be not executed any more, waiting for this additionalinv_wait_dscwhich is not completed. is it true?
That's not a question to me, is it?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v9 2/3] VT-d: wrap a _sync version for all VT-d flush interfaces
Quoted 25 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 09:44, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
xen/drivers/passthrough/vtd/qinval.c static void queue_invalidate_context(struct iommu *iommu,
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +5
-0+{ +queue_invalidate_context (iommu, did, source_id, + function_mask, granu); + +return invalidate_sync (iommu); }Further down you replace the only call to
queue_invalidate_context()- why keep both functions instead of just makingthe
Quoted 3 lines
existing one do the sync? (That would the likely also apply to
qinval_device_iotlb()and others below.)Quoted 7 lines
It is optional.
I think:
1. in the long term, we may need no_syncversion.
2. At least, the current wrap looks good to me. e.g.queue_invalidate_context()is for context-cache Invalidate Descriptor, and theinvalidate_sync()is for Invalidation Wait Descriptor. It is much clearer.
Quoted 2 lines
I don't really agree, but will leave it to the VT-d maintainers to judge.
+to Kevin and Feng, I am open for it.
Quoted 32 lines
Quoted 5 lines
Quoted 5 lines
xen/drivers/passthrough/vtd/qinval.c static int flush_iotlb_qi(
Quoted 5 lines
xen/drivers/passthrough/vtd/qinval.c +3
-0+if ( ret ) +return ret; +if ( flush_dev_iotlb ) ret = dev_invalidate_iotlb(iommu, did, addr, size_order,type);
Quoted 7 lines
Quoted 7 lines
xen/drivers/passthrough/vtd/qinval.c static int flush_iotlb_qi( · line 384
Quoted 4 lines
xen/drivers/passthrough/vtd/qinval.c +0
-3- rc =invalidate_sync (iommu); -if ( !ret ) - ret = rc; }I think leaving the existing logic as is would be better - best effort
Quoted 8 lines
invalidation
Quoted 2 lines
even when an error has occurred.
I have an open:
As vt-d spec(:Queued Invalidation Ordering Considerations) said,
1. If the Fence(FN) flag is 1 in ainv_wait_dsc, hardware must
execute descriptors following theinv_wait_dsconly after wait command iscompleted.
Quoted 9 lines
2. when a Device-TLB invalidation timeout is detected, hardware
must not complete any pendinginv_wait_dsccommands.
In current code, the Fence(FN) is always 1.
if a Device-TLB invalidation timeout is detected, this additionalinv_wait_dscis not completed.__iiuc__,
the new coming descriptors, in that queue, _might_ be not executed any more, waiting for this additionalinv_wait_dscwhich is not completed. is it true?
Quoted 1 line
That's not a question to me, is it?
To community, but vt-d maintainers are someone who can explain to me.
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v9 2/3] VT-d: wrap a _sync version for all VT-d flush interfaces
Quoted 29 lines
From: Xu, Quan
Sent: Friday, April 08, 2016 10:21 AMQuoted 25 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 09:44, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
xen/drivers/passthrough/vtd/qinval.c static void queue_invalidate_context(struct iommu *iommu,
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +5
-0+{ +queue_invalidate_context (iommu, did, source_id, + function_mask, granu); + +return invalidate_sync (iommu); }Further down you replace the only call to
queue_invalidate_context()- why keep both functions instead of just makingthe
Quoted 3 lines
existing one do the sync? (That would the likely also apply to
qinval_device_iotlb()and others below.)It is optional.
I think:
1. in the long term, we may need no_syncversion.
2. At least, the current wrap looks good to me. e.g.queue_invalidate_context()is for context-cache Invalidate Descriptor, and theinvalidate_sync()is for Invalidation Wait Descriptor. It is much clearer.
Quoted 4 lines
Quoted 2 lines
I don't really agree, but will leave it to the VT-d maintainers to judge.
+to Kevin and Feng, I am open for it.
Let's just change existing one to _sync.
Quoted 34 lines
Quoted 34 lines
Quoted 7 lines
Quoted 7 lines
xen/drivers/passthrough/vtd/qinval.c static int flush_iotlb_qi(
Quoted 7 lines
xen/drivers/passthrough/vtd/qinval.c +3
-0+if ( ret ) +return ret; +if ( flush_dev_iotlb ) ret = dev_invalidate_iotlb(iommu, did, addr, size_order,type);
Quoted 7 lines
Quoted 7 lines
xen/drivers/passthrough/vtd/qinval.c static int flush_iotlb_qi( · line 384
Quoted 4 lines
xen/drivers/passthrough/vtd/qinval.c +0
-3- rc =invalidate_sync (iommu); -if ( !ret ) - ret = rc; }I think leaving the existing logic as is would be better - best effort
Quoted 8 lines
invalidation
Quoted 2 lines
even when an error has occurred.
I have an open:
As vt-d spec(:Queued Invalidation Ordering Considerations) said,
1. If the Fence(FN) flag is 1 in ainv_wait_dsc, hardware must
execute descriptors following theinv_wait_dsconly after wait command iscompleted.
Quoted 9 lines
2. when a Device-TLB invalidation timeout is detected, hardware
must not complete any pendinginv_wait_dsccommands.
In current code, the Fence(FN) is always 1.
if a Device-TLB invalidation timeout is detected, this additionalinv_wait_dscis not completed.__iiuc__,
the new coming descriptors, in that queue, _might_ be not executed any more, waiting for this additionalinv_wait_dscwhich is not completed. is it true?
Quoted 4 lines
Quoted 1 line
That's not a question to me, is it?
To community, but vt-d maintainers are someone who can explain to me.
'not completed' here means 'abort', so your timeout check will be hit since the status is never 'done' then.
But I'm not sure how your question is related to Jan's comment, which looks reasonable to me. :-)
Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v9 2/3] VT-d: wrap a _sync version for all VT-d flush interfaces
Quoted 29 lines · Kevin
Quoted 29 lines
From: Xu, Quan
Sent: Friday, April 08, 2016 10:21 AMQuoted 25 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 09:44, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
xen/drivers/passthrough/vtd/qinval.c static void queue_invalidate_context(struct iommu *iommu,
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +5
-0+{ +queue_invalidate_context (iommu, did, source_id, + function_mask, granu); + +return invalidate_sync (iommu); }Further down you replace the only call to
queue_invalidate_context()- why keep both functions instead of just makingthe
Quoted 3 lines
existing one do the sync? (That would the likely also apply to
qinval_device_iotlb()and others below.)It is optional.
I think:
1. in the long term, we may need no_syncversion.
2. At least, the current wrap looks good to me. e.g.queue_invalidate_context()is for context-cache Invalidate Descriptor, and theinvalidate_sync()is for Invalidation Wait Descriptor. It is much clearer.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I don't really agree, but will leave it to the VT-d maintainers to judge.
+to Kevin and Feng, I am open for it.
Let's just change existing one to
_sync.
Agreed.
Quoted 38 lines
Quoted 38 lines
Quoted 37 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
xen/drivers/passthrough/vtd/qinval.c +3
-0+if ( ret ) +return ret; +if ( flush_dev_iotlb ) ret = dev_invalidate_iotlb(iommu, did, addr,
size_order,type);
Quoted 8 lines
Quoted 7 lines
xen/drivers/passthrough/vtd/qinval.c static int flush_iotlb_qi( · line 384
Quoted 4 lines
xen/drivers/passthrough/vtd/qinval.c +0
-3- rc =invalidate_sync (iommu); -if ( !ret ) - ret = rc; }I think leaving the existing logic as is would be better - best effort
invalidation
Quoted 8 lines
Quoted 2 lines
even when an error has occurred.
I have an open:
As vt-d spec(:Queued Invalidation Ordering Considerations) said,
1. If the Fence(FN) flag is 1 in ainv_wait_dsc, hardware
must execute descriptors following theinv_wait_dsconly after wait command iscompleted.
Quoted 9 lines
2. when a Device-TLB invalidation timeout is detected,
hardware must not complete any pendinginv_wait_dsccommands. In current code, the Fence(FN) is always 1.
if a Device-TLB invalidation timeout is detected, this additionalinv_wait_dscis not completed.__iiuc__,
the new coming descriptors, in that queue, _might_ be not executed any more, waiting for this additionalinv_wait_dscwhich is not completed. is it true?That's not a question to me, is it?
Quoted 9 lines
Quoted 2 lines
To community, but vt-d maintainers are someone who can explain to me.
'not completed' here means 'abort', so your timeout check will be hit since the status is never 'done' then.
But I'm not sure how your question is related to Jan's comment, which looks reasonable to me. :-)
I will take Jan's suggestion.
For this open, at least, to remind myself, I should consider software behavior and hardware behavior. Let's ignore my open.
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v9 2/3] VT-d: wrap a _sync version for all VT-d flush interfaces
In reply to Xu, QuanQuoted 12 lines
From: Xu, Quan
Sent: Thursday, April 07, 2016 3:45 PMQuoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
The
dev_invalidate_iotlb()scansats_deviceslist to flush ATS devices, and theinvalidate_sync()is put afterdev_invalidate_iotlb()to synchronize with hardware for flush status. If we assign multiple ATS devices to a domain, the flush status is about all these multiple ATS devices. Once flush timeout expires, we couldn't find out which one is the buggy ATS device.
Quoted 5 lines
Quoted 2 lines
Is that true? Or is that just a limitation of our implementation?
IMO, both.
I hope vt-d maintainers help me double check it.
Just a limitation of our implementation. Now dev_invalidate_iotlb puts all possible IOTLB flush requests to the queue, and then invalidate_sync pushes a wait descriptor w/ timeout to detect error. VT-d spec says one or more descriptors may be fetched together by hardware. So when a timeout is triggered, we cannot tell which flush request actually has problem by reading queue head register. If we change the implementation to one-invalidation-sync-per-request, then we can tell. I discussed with Quan not to go that complexity though.
Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v9 2/3] VT-d: wrap a _sync version for all VT-d flush interfaces
Quoted 18 lines · Kevin
Quoted 12 lines
From: Xu, Quan
Sent: Thursday, April 07, 2016 3:45 PMQuoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
The
dev_invalidate_iotlb()scansats_deviceslist to flush ATS devices, and theinvalidate_sync()is put afterdev_invalidate_iotlb()to synchronize with hardware for flush status. If we assign multiple ATS devices to a domain, the flush status is about all these multiple ATS devices. Once flush timeout expires, we couldn't find out which one is the buggy ATS device.Quoted 5 lines
Quoted 2 lines
Is that true? Or is that just a limitation of our implementation?
IMO, both.
I hope vt-d maintainers help me double check it.
Quoted 9 lines
Just a limitation of our implementation. Now
dev_invalidate_iotlbputs all possible IOTLB flush requests to the queue, and theninvalidate_syncpushes a wait descriptor w/ timeout to detect error. VT-d spec says one or more descriptors may be fetched together by hardware. So when a timeout is triggered, we cannot tell which flush request actually has problem by reading queue head register. If we change the implementation to one-invalidation-sync-per-request, then we can tell. I discussed with Quan not to go that complexity though.
Thanks for your correction!
I will enhance the commit log and send out later.
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v9 3/3 VT-d: Fix vt-d Device-TLB flush timeout issue
In reply to Quan XuIf Device-TLB flush timed out, we would hide the target ATS device and crash the domain owning this ATS device. If impacted domain is hardware domain, just throw out a warning (done in queue_invalidate_wait).
By hiding the device, we make sure it can't be assigned to any domain any longer (see device_assigned).
--- xen/drivers/passthrough/pci.c | 6 ++-- xen/drivers/passthrough/vtd/extern.h | 3 +- xen/drivers/passthrough/vtd/qinval.c | 58 +++++++++++++++++++++++++++++++++-- xen/drivers/passthrough/vtd/x86/ats.c | 11 ++++--- xen/include/xen/pci.h | 1 + 5 files changed, 68 insertions(+), 11 deletions(-)
xen/drivers/passthrough/pci.c +3 -3
@@ -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 ; }
xen/drivers/passthrough/vtd/extern.h +2 -1
@@ -62,7 +62,8 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,int qinval_device_iotlb (struct iommu *iommu,u32 max_invs_pend,u16 sid,u16 size,u64 addr);int qinval_device_iotlb_sync (struct iommu *iommu,u32 max_invs_pend, -u16 sid,u16 size,u64 addr); +u16 did,u16 seg,u8 bus,u8 devfn, +u16 size,u64 addr);unsigned int get_cache_line_size (void );void cacheline_flush (char *);
xen/drivers/passthrough/vtd/qinval.c +56 -2
73 lines not on this page · raw message
xen/drivers/passthrough/vtd/x86/ats.c +6 -5
@@ -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;/* Only invalidate devices that belong to this IOMMU */
@@ -133,8 +132,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 ; - ret =qinval_device_iotlb_sync (iommu, pdev->ats_queue_depth, - sid, sbit, addr); + ret =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) )
@@ -153,8 +153,9 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did, addr |= (((u64 )1 << (size_order -1 )) -1 ) <<PAGE_SHIFT_4K ; } - ret =qinval_device_iotlb_sync (iommu, pdev->ats_queue_depth, - sid, sbit, addr); + ret =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");
xen/include/xen/pci.h +1 -0
@@ -116,6 +116,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);
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] VT-d: Fix vt-d Device-TLB flush timeout issue
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
If Device-TLB flush timed out, we would hide the target ATS
Please re-consider the use of the word "would" in all your patch descriptions.
Quoted 7 lines
xen/drivers/passthrough/vtd/qinval.c +1
-0@@ -217,6 +217,58 @@ static int invalidate_sync(struct iommu *iommu)return 0 ; } +static void dev_invalidate_iotlb_timeout(struct iommu *iommu, u16 did,
xen/drivers/passthrough/vtd/qinval.c static int invalidate_sync(struct iommu *iommu) · line 230
Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c +10
-0+ 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 ;
This should be accompanied by a comment explaining why returning here without indicating any error is okay.
xen/drivers/passthrough/vtd/qinval.c static int invalidate_sync(struct iommu *iommu) · line 238
Quoted 7 lines
xen/drivers/passthrough/vtd/qinval.c +7
-0+pcidevs_lock (); + +for_each_pdev (d, pdev) + { +if ( ( pdev->seg == seg ) && + ( pdev->bus == bus ) && + ( pdev->devfn == devfn ) )
Stray blanks.
xen/drivers/passthrough/vtd/qinval.c static int invalidate_sync(struct iommu *iommu) · line 251
Quoted 13 lines
xen/drivers/passthrough/vtd/qinval.c +13
-0+ { +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();
xen/drivers/passthrough/vtd/qinval.c int qinval_device_iotlb(struct iommu *iommu, · line 308
Quoted 8 lines
xen/drivers/passthrough/vtd/qinval.c +2
-1@@ -251,11 +303,13 @@ int qinval_device_iotlb(struct iommu *iommu, }int 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) { +u16 sid =PCI_BDF2 (bus, devfn);
Pointless local variable (but being a matter of taste, the VT-d maintainers will have the final say).
xen/include/xen/pci.h const unsigned long *pci_get_ro_map(u16 seg); · line 121
Quoted 9 lines
xen/include/xen/pci.h +1
-0@@ -116,6 +116,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);
Please move the addition here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] VT-d: Fix vt-d Device-TLB flush timeout issue
Quoted 4 lines · Jan Beulich
Review
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
(quoted diff) +2
-0+static void dev_invalidate_iotlb_timeout(struct iommu *iommu, u16 did, + u16 seg, u8 bus, u8 devfn){
Quoted 12 lines
xen/drivers/passthrough/vtd/qinval.c static int invalidate_sync(struct iommu *iommu) · line 230
Quoted 8 lines
xen/drivers/passthrough/vtd/qinval.c +8
-0+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 ;This should be accompanied by a comment explaining why returning here without indicating any error is okay.
I'd say:
"The domain has been freed, and the device no longer belongs to this domain."
Quoted 7 lines
Quoted 7 lines
xen/drivers/passthrough/vtd/qinval.c +7
-0+ { +ASSERT (pdev->domain); +list_del (&pdev->domain_list); + pdev->domain =NULL ; +pci_hide_existing_device (pdev); +break ; + }
Quoted 9 lines
xen/drivers/passthrough/vtd/qinval.c static int invalidate_sync(struct iommu *iommu) · line 251
Quoted 6 lines
xen/drivers/passthrough/vtd/qinval.c +6
-0+ } + +pcidevs_unlock (); + +if ( !is_hardware_domain (d) ) +domain_crash (d);else
printk();
As I mentioned in commit log "If impacted domain is hardware domain, just throw out a warning (done in queue_invalidate_wait).", I am not sure whether we really need a printk() at this point or not.
Quoted 12 lines
xen/drivers/passthrough/vtd/qinval.c int qinval_device_iotlb(struct iommu *iommu, } · line 308
Quoted 8 lines
xen/drivers/passthrough/vtd/qinval.c +3
-1@@ -251,11 +303,13 @@ int qinval_device_iotlb(struct iommu *iommu, }int 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) { +u16 sid =PCI_BDF2 (bus, devfn);Pointless local variable (but being a matter of taste, the VT-d maintainers will have the final say).
I will drop this local variable.
Quoted 12 lines
xen/include/xen/pci.h const unsigned long *pci_get_ro_map(u16 seg); int · line 121
Quoted 9 lines
xen/include/xen/pci.h +1
-0@@ -116,6 +116,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); intpci_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);Please move the addition here.
Agreed.
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v9 3/3] VT-d: Fix vt-d Device-TLB flush timeout issue
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 10.04.16 at 16:28, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 16:47, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +3
-0+ { +ASSERT (pdev->domain); +list_del (&pdev->domain_list);xen/drivers/passthrough/vtd/qinval.c static int invalidate_sync(struct iommu *iommu) · line 251
Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c +10
-0+ pdev->domain =NULL ; +pci_hide_existing_device (pdev); +break ; + } + } + +pcidevs_unlock (); + +if ( !is_hardware_domain (d) ) +domain_crash (d);else
printk();
Quoted 3 lines
As I mentioned in commit log "If impacted domain is hardware domain, just throw out a warning (done in
queue_invalidate_wait).",
I am not sure whether we really need aprintk()at this point or not.
I think the printk() belongs here; I do agree there's no need for two printk()s on the same call tree.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel