VT-d Device-TLB flush issue
v11 cover VT-d Device-TLB flush issue
From: Quan Xu <[email protected]>
This patches fix current timeout concern and also allow limited ATS support:
1. add a timeout parameter for device IOTLB invalidation
The parameter 'iommu_dev_iotlb_timeout' specifies the timeout of the device IOTLB invalidation in milliseconds. By default, the timeout is 1ms, which can be boot-time changed.
2. Synchronize for Device-TLB flush one by one
Today we do Device-TLB flush synchronization after issuing flush requests for all ATS devices belonging to a VM. Doing so however imposes a limitation, i.e. that we can not figure out which flush request is blocked in the flush queue list, based on VT-d spec.
To prepare correct Device-TLB flush timeout handling in next patch, we change the behavior to synchronize for every Device-TLB flush request. So the Device-TLB flush interface is changed a little bit, by checking timeout within the function instead of outside of function.
Accordingly we also do a similar change for flush interfaces of IOTLB/IEC/Context, i.e. moving synchronization into the function. Since there is no user of a non-synced interface, we just rename existing ones with _sync suffix.
3. Fix vt-d Device-TLB flush timeout issue
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).
**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.
Quan Xu (3):
IOMMU: add a timeout parameter for device IOTLB invalidation
vt-d: synchronize for Device-TLB flush one by one
vt-d: fix vt-d Device-TLB flush timeout issue
docs/misc/xen-command-line.markdown | 9 ++ xen/drivers/passthrough/iommu.c | 3 + xen/drivers/passthrough/pci.c | 6 +- xen/drivers/passthrough/vtd/extern.h | 6 +- xen/drivers/passthrough/vtd/qinval.c | 157 ++++++++++++++++++++++++++-------- xen/drivers/passthrough/vtd/x86/ats.c | 7 +- xen/include/xen/iommu.h | 2 + xen/include/xen/pci.h | 1 + 8 files changed, 144 insertions(+), 47 deletions(-)
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v11 1/3 IOMMU: add a timeout parameter for device IOTLB invalidation
From: Quan Xu <[email protected]>
The parameter 'iommu_dev_iotlb_timeout' specifies the timeout of the device IOTLB 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.
v11: Change the timeout parameter from 'vtd_qi_timeout' to
'iommu_dev_iotlb_timeout', which is not only for VT-d device IOTLB invalidation, but also for other IOMMU implementations.
--- docs/misc/xen-command-line.markdown | 9 +++++++++ xen/drivers/passthrough/iommu.c | 3 +++ xen/drivers/passthrough/vtd/qinval.c | 34 +++++++++++++++++++++++----------- xen/include/xen/iommu.h | 2 ++ 4 files changed, 37 insertions(+), 11 deletions(-)
docs/misc/xen-command-line.markdown +9 -0
@@ -996,6 +996,15 @@ debug hypervisor only). >> Enable IOMMU debugging code (implies `verbose`). +### iommu\_dev\_iotlb\_timeout +> `= <integer>` + +> Default: `1` + +Specify the timeout of the device IOTLB invalidation in milliseconds. +By default, the timeout is 1 ms. When you see error 'Queue invalidate +wait descriptor timed out', try increasing this value. + ### iommu\_inclusive\_mapping (VT-d) > `= <boolean>`
xen/drivers/passthrough/iommu.c +3 -0
@@ -24,6 +24,9 @@static void parse_iommu_param (char *s);static void iommu_dump_p2m_table (unsigned char key); +unsigned int __read_mostly iommu_dev_iotlb_timeout =1 ; +integer_param ("iommu_dev_iotlb_timeout" , iommu_dev_iotlb_timeout); +/* * The 'iommu' parameter enables the IOMMU. Optional comma separated * value may contain:
xen/drivers/passthrough/vtd/qinval.c +23 -11
@@ -28,6 +28,8 @@#include "vtd.h" #include "extern.h" +#define IOMMU_QI_TIMEOUT MILLISECS(1) +static void print_qi_regs (struct iommu *iommu) {u64 val;
@@ -130,10 +132,10 @@ static void queue_invalidate_iotlb(struct iommu *iommu,spin_unlock_irqrestore (&iommu->register_lock, flags); } -static int queue_invalidate_wait (struct iommu *iommu, -u8 iflag,u8 sw,u8 fn) +static int __must_check queue_invalidate_wait (struct iommu *iommu, +u8 iflag,u8 sw,u8 fn, +bool_t flush_dev_iotlb) { -s_time_t start_time;volatile u32 poll_slot =QINVAL_STAT_INIT ;unsigned int index;unsigned long flags;
@@ -163,14 +165,21 @@ static int queue_invalidate_wait(struct iommu *iommu,/* Now we don't support interrupt method */ if ( sw ) { +s_time_t timeout; +/* In case all wait descriptor writes to same addr with same data */ - start_time =NOW (); + timeout = flush_dev_iotlb ? + (NOW () + iommu_dev_iotlb_timeout *MILLISECS (1 )) : + (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 (); }
@@ -180,12 +189,14 @@ static int queue_invalidate_wait(struct iommu *iommu,return -EOPNOTSUPP ; } -static int invalidate_sync (struct iommu *iommu) +static int __must_check invalidate_sync (struct iommu *iommu, +bool_t flush_dev_iotlb) {struct qi_ctrl *qi_ctrl =iommu_qi_ctrl (iommu);if ( qi_ctrl->qinval_maddr ) -return queue_invalidate_wait (iommu,0 ,1 ,1 ); +return queue_invalidate_wait (iommu,0 ,1 ,1 , flush_dev_iotlb); +return 0 ; }
@@ -254,7 +265,7 @@ static int __iommu_flush_iec(struct iommu *iommu, u8 granu, u8 im, u16 iidx)int ret;queue_invalidate_iec (iommu, granu, im, iidx); - ret =invalidate_sync (iommu); + ret =invalidate_sync (iommu,0 );/* * reading vt-d architecture register will ensure * draining happens in implementation independent way.
@@ -300,7 +311,7 @@ static int __must_check flush_context_qi(void *_iommu, u16 did, {queue_invalidate_context (iommu, did, sid, fm, type >>DMA_CCMD_INVL_GRANU_OFFSET ); - ret =invalidate_sync (iommu); + ret =invalidate_sync (iommu,0 ); }return ret; }
@@ -344,10 +355,11 @@ static int __must_check flush_iotlb_qi(void *_iommu, u16 did, u64 addr, dw, did, size_order, 0, addr);if ( flush_dev_iotlb ) ret =dev_invalidate_iotlb (iommu, did, addr, size_order, type); - rc =invalidate_sync (iommu); + rc =invalidate_sync (iommu, flush_dev_iotlb);if ( !ret ) ret = rc; } +return ret; }
xen/include/xen/iommu.h +2 -0
@@ -35,6 +35,8 @@ extern bool_t iommu_hap_pt_share;extern bool_t iommu_debug;extern bool_t amd_iommu_perdev_intremap; +extern unsigned int iommu_dev_iotlb_timeout; +#define IOMMU_PAGE_SIZE (sz) (1UL << PAGE_SHIFT_##sz)#define IOMMU_PAGE_MASK (sz) (~(u64)0 << PAGE_SHIFT_##sz)#define IOMMU_PAGE_ALIGN (sz, addr) (((addr) + ~PAGE_MASK_##sz) & PAGE_MASK_##sz)
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [Patch v11 1/3] IOMMU: add a timeout parameter for device IOTLB invalidation
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 01.06.16 at 11:05, <[email protected]> wrote:
From: Quan Xu <[email protected]>
The parameter '
iommu_dev_iotlb_timeout' specifies the timeout of the device IOTLB invalidation in milliseconds. By default, the timeout is 1ms, which can be boot-time changed.
Quoted 5 lines
Add a
__must_checkannotation. 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.
The description really needs to mention that the dropping of the panic() is intentional, and why.
Quoted 3 lines
v11: Change the timeout parameter from '
vtd_qi_timeout' to
'iommu_dev_iotlb_timeout', which is not only for VT-d device IOTLB invalidation, but also for other IOMMU implementations.
This goes after the first --- separator.
docs/misc/xen-command-line.markdown debug hypervisor only). · line 1002
Quoted 10 lines
docs/misc/xen-command-line.markdown +4
-0@@ -996,6 +996,15 @@ debug hypervisor only). >> Enable IOMMU debugging code (implies `verbose`). +### iommu\_dev\_iotlb\_timeout +> `= <integer>` + +> Default: `1`
So on v10 I had made clear that any timeout reduction from its current value is, for the ATS case, not acceptable, unless you have proof that this lower value will fit all past, present, and future devices. Otherwise we're risking a regression here.
xen/drivers/passthrough/vtd/qinval.c line 31
Quoted 7 lines
xen/drivers/passthrough/vtd/qinval.c +1
-0@@ -28,6 +28,8 @@#include "vtd.h" #include "extern.h" +#define IOMMU_QI_TIMEOUT MILLISECS(1)
May I suggest VTD_QI_TIMEOUT (but see also below)?
xen/drivers/passthrough/vtd/qinval.c static int queue_invalidate_wait(struct iommu *iommu, · line 172
Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c +4
-1@@ -163,14 +165,21 @@ static int queue_invalidate_wait(struct iommu *iommu,/* Now we don't support interrupt method */ if ( sw ) { +s_time_t timeout; +/* In case all wait descriptor writes to same addr with same data */ - start_time =NOW (); + timeout = flush_dev_iotlb ? + (NOW() + iommu_dev_iotlb_timeout * MILLISECS(1)) :
MILLISECS(iommu_dev_iotlb_timeout)
xen/drivers/passthrough/vtd/qinval.c static int queue_invalidate_wait(struct iommu *iommu, · line 173
Quoted 1 line
xen/drivers/passthrough/vtd/qinval.c +1
-0+ (NOW () +IOMMU_QI_TIMEOUT );
Or really the whole expression should probably simply become
timeout = NOW() + MILLISECS(flush_dev_iotlb ? iommu_dev_iotlb_timeout : VTD_QI_TIMEOUT);
(of course with VTD_QI_TIMEOUT having its MILLISECS() dropped, and suitably line wrapped).
xen/drivers/passthrough/vtd/qinval.c static int __must_check flush_iotlb_qi(void *_iommu, u16 did, u64 addr, · line 363
Quoted 11 lines
xen/drivers/passthrough/vtd/qinval.c +2
-1@@ -344,10 +355,11 @@ static int __must_check flush_iotlb_qi(void *_iommu, u16 did, u64 addr, dw, did, size_order, 0, addr);if ( flush_dev_iotlb ) ret =dev_invalidate_iotlb (iommu, did, addr, size_order, type); - rc =invalidate_sync (iommu); + rc =invalidate_sync (iommu, flush_dev_iotlb);if ( !ret ) ret = rc; } +return ret;
Once again an addition of a blank line that doesn't belong here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Patch v11 1/3] IOMMU: add a timeout parameter for device IOTLB invalidation
Quoted 8 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 01.06.16 at 11:05, <[email protected]> wrote:
From: Quan Xu <[email protected]>
v11: Change the timeout parameter from 'vtd_qi_timeout' to
'iommu_dev_iotlb_timeout', which is not only for VT-d device IOTLB invalidation, but also for other IOMMU implementations.This goes after the first --- separator.
Got it. It should be:
---
v11:
- ...
- ...
---
Quoted 6 lines
Quoted 6 lines
docs/misc/xen-command-line.markdown +0
-0@@ -996,6 +996,15 @@ debug hypervisor only). >> Enable IOMMU debugging code (implies `verbose`).
Quoted 10 lines
docs/misc/xen-command-line.markdown debug hypervisor only). · line 1002
Quoted 4 lines
docs/misc/xen-command-line.markdown +4
-0+### iommu\_dev\_iotlb\_timeout +> `= <integer>` + +> Default: `1`So on v10 I had made clear that any timeout reduction from its current value is, for the ATS case, not acceptable, unless you have proof that this lower value will fit all past, present, and future devices. Otherwise we're risking a regression here.
I really misunderstood the 'current value', which should be about 'DMAR_OPERATION_TIMEOUT MILLISECS(1000) ', instead of ' IOMMU_QI_TIMEOUT MILLISECS(1)' in my patch. So the default is 1000.
Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c line 31
Quoted 7 lines
xen/drivers/passthrough/vtd/qinval.c +1
-0@@ -28,6 +28,8 @@#include "vtd.h" #include "extern.h" +#define IOMMU_QI_TIMEOUT MILLISECS(1)May I suggest
VTD_QI_TIMEOUT(but see also below)?
Agreed. VTD_QI_TIMEOUT is a better one.
Quoted 16 lines
xen/drivers/passthrough/vtd/qinval.c static int queue_invalidate_wait(struct iommu
Quoted 1 line
xen/drivers/passthrough/vtd/qinval.c +0
-0@@ -163,14 +165,21 @@ static int queue_invalidate_wait(struct iommu*iommu,
xen/drivers/passthrough/vtd/qinval.c static int queue_invalidate_wait(struct iommu *iommu, · line 172
Quoted 9 lines
xen/drivers/passthrough/vtd/qinval.c +4
-1/* Now we don't support interrupt method */ if ( sw ) { +s_time_t timeout; +/* In case all wait descriptor writes to same addr with same data */ - start_time =NOW (); + timeout = flush_dev_iotlb ? + (NOW() + iommu_dev_iotlb_timeout * MILLISECS(1)) :
MILLISECS(iommu_dev_iotlb_timeout)xen/drivers/passthrough/vtd/qinval.c static int queue_invalidate_wait(struct iommu *iommu, · line 173
Quoted 1 line
xen/drivers/passthrough/vtd/qinval.c +1
-0+ (NOW () +IOMMU_QI_TIMEOUT );
Quoted 8 lines
Or really the whole expression should probably simply become
timeout =
NOW()+ MILLISECS(flush_dev_iotlb ?iommu_dev_iotlb_timeout:VTD_QI_TIMEOUT);(of course with
VTD_QI_TIMEOUThaving itsMILLISECS()dropped, and suitably line wrapped).
I prefer this later one.
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v11 2/3 vt-d: synchronize for Device-TLB flush one by one
In reply to Xu, QuanFrom: Quan Xu <[email protected]>
Today we do Device-TLB flush synchronization after issuing flush requests for all ATS devices belonging to a VM. Doing so however imposes a limitation, i.e. that we can not figure out which flush request is blocked in the flush queue list, based on VT-d spec.
To prepare correct Device-TLB flush timeout handling in next patch, we change the behavior to synchronize for every Device-TLB flush request. So the Device-TLB flush interface is changed a little bit, by checking timeout within the function instead of outside of function.
Accordingly we also do a similar change for flush interfaces of IOTLB/IEC/Context, i.e. moving synchronization into the function. Since there is no user of a non-synced interface, we just rename existing ones with _sync suffix.
v11:
1. Add __must_check annotation to invalidate_sync().
2. Remove the redundant invalidate_sync() in flush_iotlb_qi().
3. Refactor invalidate_sync() to indicate whether we need to flush device IOTLB or not (I'll change it back in next patch, as I'll add a specific function - dev_invalidate_sync() for device IOTLB invalidation).
--- xen/drivers/passthrough/vtd/extern.h | 5 +-- xen/drivers/passthrough/vtd/qinval.c | 65 ++++++++++++++++++++--------------- xen/drivers/passthrough/vtd/x86/ats.c | 8 ++--- 3 files changed, 45 insertions(+), 33 deletions(-)
xen/drivers/passthrough/vtd/extern.h +3 -2
@@ -59,8 +59,9 @@ 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 qinval_device_iotlb (struct iommu *iommu, -u32 max_invs_pend,u16 sid,u16 size,u64 addr); +int __must_check 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 +38 -27
142 lines not on this page · raw message
xen/drivers/passthrough/vtd/x86/ats.c +4 -4
@@ -134,8 +134,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); + rc =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,8 +154,8 @@ 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); + rc =qinval_device_iotlb_sync (iommu, pdev->ats_queue_depth, + sid, sbit, addr);break ;default : dprintk(XENLOG_WARNING VTDPREFIX, "invalid vt-d flush type\n");
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [Patch v11 2/3] vt-d: synchronize for Device-TLB flush one by one
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 01.06.16 at 11:05, <[email protected]> wrote:
From: Quan Xu <[email protected]>
Today we do Device-TLB flush synchronization after issuing flush requests for all ATS devices belonging to a VM. Doing so however imposes a limitation, i.e. that we can not figure out which flush request is blocked in the flush queue list, based on VT-d spec.
To prepare correct Device-TLB flush timeout handling in next patch, we change the behavior to synchronize for every Device-TLB flush request. So the Device-TLB flush interface is changed a little bit, by checking timeout within the function instead of outside of function.
Accordingly we also do a similar change for flush interfaces of IOTLB/IEC/Context, i.e. moving synchronization into the function. Since there is no user of a non-synced interface, we just rename existing ones with
_syncsuffix.v11:
1. Add__must_checkannotation toinvalidate_sync().
2. Remove the redundantinvalidate_sync()inflush_iotlb_qi().
3. Refactorinvalidate_sync()to indicate whether we need to flush device IOTLB or not (I'll change it back in next patch, as I'll add a specific function -dev_invalidate_sync()for device IOTLB invalidation).
Quoted 1 line
Signed-off-by Quan Xu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v11 3/3 vt-d: fix vt-d Device-TLB flush timeout issue
In reply to Xu, QuanFrom: Quan Xu <[email protected]>
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).
v11:
1. Pass down struct pci_dev *, instead of SBDF inside struct pci_ats_dev.
2. change invalidate_sync() back as I add a specific function
- dev_invalidate_sync() for device IOTLB.
--- xen/drivers/passthrough/pci.c | 6 +-- xen/drivers/passthrough/vtd/extern.h | 5 +- xen/drivers/passthrough/vtd/qinval.c | 86 +++++++++++++++++++++++++++++------ xen/drivers/passthrough/vtd/x86/ats.c | 7 +-- xen/include/xen/pci.h | 1 + 5 files changed, 82 insertions(+), 23 deletions(-)
xen/drivers/passthrough/pci.c +3 -3
@@ -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 ; }
xen/drivers/passthrough/vtd/extern.h +3 -2
@@ -21,6 +21,7 @@#define _VTD_EXTERN_H_#include "dmar.h" +#include "../ats.h" #include <xen/keyhandler.h> #define VTDPREFIX "[VT-D]"
@@ -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 *);
xen/drivers/passthrough/vtd/qinval.c +73 -13
138 lines not on this page · raw message
xen/drivers/passthrough/vtd/x86/ats.c +2 -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;int rc =0 ;
@@ -134,8 +133,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) )
@@ -154,8 +152,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");
xen/include/xen/pci.h +1 -0
@@ -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(
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [Patch v11 3/3] vt-d: fix vt-d Device-TLB flush timeout issue
xen/drivers/passthrough/vtd/extern.h line 24
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 01.06.16 at 11:05, <[email protected]> wrote:
xen/drivers/passthrough/vtd/extern.h +1
-0@@ -21,6 +21,7 @@#define _VTD_EXTERN_H_#include "dmar.h" +#include "../ats.h"
Why? You don't de-reference struct pci_ats_dev * in this file, so all you'd need is a forward declaration. But then this is not in line with your v11 change description above, so I wonder whether you actually sent a stale patch. After all I thought the v10 discussion (see
http://lists.xenproject.org/archives/html/xen-devel/2016-05/msg02208.html
) had made clear that this passing down, besides reducing the number of arguments of some function, would also be meant to eliminate ...
Quoted 23 lines
xen/drivers/passthrough/vtd/extern.h +23
-0+static void dev_invalidate_iotlb_timeout (struct iommu *iommu,u16 did, +struct pci_ats_dev *ats_dev) +{ +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 == ats_dev->seg) && + (pdev->bus == ats_dev->bus) && + (pdev->devfn == ats_dev->devfn) )
xen/drivers/passthrough/vtd/extern.h
Quoted 10 lines
xen/drivers/passthrough/vtd/extern.h +10
-0+ { +ASSERT (pdev->domain); +list_del (&pdev->domain_list); + pdev->domain =NULL ; +pci_hide_existing_device (pdev); +break ; + } + } + +pcidevs_unlock ();
... this loop (and locking). (Of course such a change may better be done in another preparatory patch.)
xen/drivers/passthrough/vtd/extern.h
Quoted 7 lines
xen/drivers/passthrough/vtd/extern.h +7
-0+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, ats_dev->seg, ats_dev->bus, +PCI_SLOT (ats_dev->devfn),PCI_FUNC (ats_dev->devfn));
Please use the same logic for logging and crashing as you do in the other series, so that at least on average a resulting DomU crash will be accompanied with some indication of the reason beyond just the source file name and line number.
Quoted 6 lines
xen/drivers/passthrough/vtd/extern.h +6
-0+static int __must_check dev_invalidate_sync (struct iommu *iommu,u16 did, +struct pci_ats_dev *ats_dev) +{ +struct qi_ctrl *qi_ctrl =iommu_qi_ctrl (iommu); +int rc =0 ; +
xen/drivers/passthrough/vtd/extern.h
Quoted 10 lines
xen/drivers/passthrough/vtd/extern.h +10
-0+if ( qi_ctrl->qinval_maddr ) + { + rc =queue_invalidate_wait (iommu,0 ,1 ,1 ,1 ); + +if ( rc == -ETIMEDOUT ) +dev_invalidate_iotlb_timeout (iommu, did, ats_dev); + } + +return rc; +}
I've never really understood why invalidate_sync() returns success when it didn't do anything. Now that you copy this same behavior here, I really need to ask you to explain that.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Patch v11 3/3] vt-d: fix vt-d Device-TLB flush timeout issue
(* I will CC arm/amd maintainer after this vt-d specific discussion, and then send out my proposal...)
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 01.06.16 at 11:05, <[email protected]> wrote:
xen/drivers/passthrough/vtd/extern.h +0
-0@@ -21,6 +21,7 @@#define _VTD_EXTERN_H_
Quoted 6 lines
xen/drivers/passthrough/vtd/extern.h line 24
Quoted 2 lines
xen/drivers/passthrough/vtd/extern.h +1
-0#include "dmar.h" +#include "../ats.h" Why? You don't de-reference struct
pci_ats_dev* in this file, so all you'd need is a forward declaration. But then this is not in line with your v11 change description above, so I wonder whether you actually sent a stale patch.
Sorry, this patch is really strange to me.
Quoted 4 lines
After all I thought the v10 discussion (see
http://lists.xenproject.org/archives/html/xen-devel/2016-
05/msg02208.html
) had made clear that this passing down,
Sure, what you said is very clear. But I read these code again, I found a pci_get_pdev_by_domain() Can also get *pdev without below loop.. (also hardware domain calls pci_get_pdev_by_domain() to get pdev.)
To be honest, now I don't like to add a struct pci_dev * inside struct pci_ats_dev, as I need to change ' struct pci_ats_dev *pdev' to ' struct pci_ats_dev * pci_ats_dev ' in some functions as well.
Quoted 31 lines
besides reducing the number of
arguments of some function, would also be meant to eliminate ...Quoted 28 lines
xen/drivers/passthrough/vtd/extern.h +28
-0+static void dev_invalidate_iotlb_timeout (struct iommu *iommu,u16 did, +struct pci_ats_dev *ats_dev) +{ +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 == ats_dev->seg) && + (pdev->bus == ats_dev->bus) && + (pdev->devfn == ats_dev->devfn) ) + { +ASSERT (pdev->domain); +list_del (&pdev->domain_list); + pdev->domain =NULL ; +pci_hide_existing_device (pdev);
Quoted 9 lines
xen/drivers/passthrough/vtd/extern.h
Quoted 5 lines
xen/drivers/passthrough/vtd/extern.h +5
-0+break ; + } + } + +pcidevs_unlock ();... this loop (and locking). (Of course such a change may better be done in another preparatory patch.)
To eliminate the locking? I am afraid the locking is still a must here even without the loop, also referring to device_assigned()..
Quoted 14 lines
Quoted 2 lines
+static int
__must_checkdev_invalidate_sync(struct iommu *iommu, u16did,
Quoted 11 lines
xen/drivers/passthrough/vtd/extern.h +11
-0+struct pci_ats_dev +*ats_dev) { +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 ,1 ); + +if ( rc == -ETIMEDOUT ) +dev_invalidate_iotlb_timeout (iommu, did, ats_dev);
Quoted 9 lines
xen/drivers/passthrough/vtd/extern.h
Quoted 4 lines
xen/drivers/passthrough/vtd/extern.h +4
-0+ } + +return rc; +}I've never really understood why
invalidate_sync()returns success when it didn't do anything. Now that you copy this same behavior here, I really need to ask you to explain that.
It is acceptable to me, returning success when it didn't do anything -- this is worth reflection and criticism:(.. It is better:
+ if ( qi_ctrl->qinval_maddr )
+ ...
+ else
+ rc = -ENOENT;
A question:
I find the page related to qi_ctrl->qinval_maddr is not freed at all. IMO, In disable_qinval (), we need to do:
- free the page related to qi_ctrl->qinval_maddr.
- qi_ctrl->qinval_maddr = 0;
Right?
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Patch v11 3/3] vt-d: fix vt-d Device-TLB flush timeout issue
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 16.06.16 at 10:42, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 01.06.16 at 11:05, <[email protected]> wrote:
xen/drivers/passthrough/vtd/extern.h +0
-0@@ -21,6 +21,7 @@#define _VTD_EXTERN_H_
Quoted 8 lines
Quoted 6 lines
xen/drivers/passthrough/vtd/extern.h line 24
Quoted 2 lines
xen/drivers/passthrough/vtd/extern.h +1
-0#include "dmar.h" +#include "../ats.h" Why? You don't de-reference struct
pci_ats_dev* in this file, so all you'd need is a forward declaration. But then this is not in line with your v11 change description above, so I wonder whether you actually sent a stale patch.Sorry, this patch is really strange to me.
Well, it's yours, so you ought to be able to explain it.
Quoted 9 lines
Quoted 4 lines
After all I thought the v10 discussion (see
http://lists.xenproject.org/archives/html/xen-devel/2016-
05/msg02208.html
) had made clear that this passing down,Sure, what you said is very clear. But I read these code again, I found a
pci_get_pdev_by_domain()
Can also get *pdev without below loop.. (also hardware domain callspci_get_pdev_by_domain()to get pdev.)
Which would not eliminate the loop - pci_get_pdev_by_domain() does have a loop itself.
Quoted 4 lines
To be honest, now I don't like to add a struct
pci_dev* inside structpci_ats_dev, as I need to change
' structpci_ats_dev*pdev' to ' structpci_ats_dev*pci_ats_dev' in some functions as well.
I don't see why variables would need renaming. If you need a variable of type struct pci_dev * in a function which already has a variable named pdev, simply name the new variable differently (e.g. pci_dev).
Quoted 41 lines
Quoted 31 lines
besides reducing the number of
arguments of some function, would also be meant to eliminate ...Quoted 28 lines
xen/drivers/passthrough/vtd/extern.h +28
-0+static void dev_invalidate_iotlb_timeout (struct iommu *iommu,u16 did, +struct pci_ats_dev *ats_dev) +{ +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 == ats_dev->seg) && + (pdev->bus == ats_dev->bus) && + (pdev->devfn == ats_dev->devfn) ) + { +ASSERT (pdev->domain); +list_del (&pdev->domain_list); + pdev->domain =NULL ; +pci_hide_existing_device (pdev);Quoted 9 lines
xen/drivers/passthrough/vtd/extern.h
Quoted 5 lines
xen/drivers/passthrough/vtd/extern.h +5
-0+break ; + } + } + +pcidevs_unlock ();... this loop (and locking). (Of course such a change may better be done in another preparatory patch.)
Quoted 2 lines
To eliminate the locking? I am afraid the locking is still a must here even without the loop, also referring to
device_assigned()..
If the entire loop gets eliminated, what would be left is
pcidevs_lock();
pcidevs_unlock();which I don't think does any good.
Quoted 26 lines
Quoted 13 lines
Quoted 1 line
+static int
__must_checkdev_invalidate_sync(struct iommu *iommu, u16did,
Quoted 11 lines
xen/drivers/passthrough/vtd/extern.h +11
-0+struct pci_ats_dev +*ats_dev) { +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 ,1 ); + +if ( rc == -ETIMEDOUT ) +dev_invalidate_iotlb_timeout (iommu, did, ats_dev);Quoted 9 lines
xen/drivers/passthrough/vtd/extern.h
Quoted 4 lines
xen/drivers/passthrough/vtd/extern.h +4
-0+ } + +return rc; +}I've never really understood why
invalidate_sync()returns success when it didn't do anything. Now that you copy this same behavior here, I really need to ask you to explain that.It is acceptable to me, returning success when it didn't do anything -- this is worth reflection and criticism:(..
It is better:
Review
Quoted 4 lines
(quoted diff) +4
-0+ if ( qi_ctrl->qinval_maddr ) + ... + else + rc = -ENOENT;
Right. And perhaps a separate patch to make invalidate_sync() do the same. Question is whether this really ought to be a conditional, or whether instead this code is unreachable when qinval is not in use, in which case these conditionals would imo better be converted to ASSERT()s.
Quoted 5 lines
A question:
I find the page related toqi_ctrl->qinval_maddris not freed at all. IMO, Indisable_qinval(), we need to do:
- free the page related toqi_ctrl->qinval_maddr.
-qi_ctrl->qinval_maddr= 0;
Well, that's a correct observation, but not a big problem imo: If this was a per-domain resource, it surely would need fixing. But if freeing a couple of these pages (one per IOMMU) causes synchronization headaches (e.g. because there may still be dangling references to it), then I think freeing them is not a must. But if freeing them is safe (like you seem to imply), then I'm certainly fine with you fixing this (not that my opinion would matter much here, as I'm not the maintainer of this code).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Patch v11 3/3] vt-d: fix vt-d Device-TLB flush timeout issue
Quoted 44 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 16.06.16 at 10:42, <[email protected]> wrote:
Quoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 01.06.16 at 11:05, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +28
-0+static void dev_invalidate_iotlb_timeout (struct iommu *iommu,u16 did, +struct pci_ats_dev +*ats_dev) { +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 == ats_dev->seg) && + (pdev->bus == ats_dev->bus) && + (pdev->devfn == ats_dev->devfn) ) + { +ASSERT (pdev->domain); +list_del (&pdev->domain_list); + pdev->domain =NULL ; +pci_hide_existing_device (pdev);Quoted 9 lines
xen/drivers/passthrough/vtd/qinval.c static int __must_check queue_invalidate_wait(struct iommu *iommu, · line 244
Quoted 5 lines
xen/drivers/passthrough/vtd/qinval.c +5
-0+break ; + } + } + +pcidevs_unlock ();... this loop (and locking). (Of course such a change may better be done in another preparatory patch.)
Quoted 2 lines
To eliminate the locking? I am afraid the locking is still a must here even without the loop, also referring to
device_assigned()..
Quoted 7 lines
If the entire loop gets eliminated, what would be left is
pcidevs_lock(); pcidevs_unlock();which I don't think does any good.
Why? I can't follow it..
Quoted 32 lines
Quoted 27 lines
Quoted 14 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+static int __must_check dev_invalidate_sync(struct iommu *iommu, +u16did,
Quoted 11 lines
xen/drivers/passthrough/vtd/qinval.c +11
-0+struct pci_ats_dev +*ats_dev) { +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 ,1 ); + +if ( rc == -ETIMEDOUT ) +dev_invalidate_iotlb_timeout (iommu, did, ats_dev);Quoted 9 lines
xen/drivers/passthrough/vtd/qinval.c static int __must_check queue_invalidate_wait(struct iommu *iommu, · line 272
Quoted 4 lines
xen/drivers/passthrough/vtd/qinval.c +4
-0+ } + +return rc; +}I've never really understood why
invalidate_sync()returns success when it didn't do anything. Now that you copy this same behavior here, I really need to ask you to explain that.It is acceptable to me, returning success when it didn't do anything -- this is worth reflection and criticism:(..
It is better:Review
Quoted 4 lines
(quoted diff) +4
-0+ if ( qi_ctrl->qinval_maddr ) + ... + else + rc = -ENOENT;
Quoted 1 line
Right. And perhaps a separate patch to make
invalidate_sync()do the same.
Agreed.
Quoted 4 lines
Question is whether this really ought to be a conditional, or whether instead this code is unreachable when qinval is not in use, in which case these conditionals would imo better be converted to ASSERT()s.
IMO, this should be a conditional.
As mentioned below, strictly speaking, this is a bug. We can't ASSERT() based on a bug.. A coming patch may fix it..
Quoted 6 lines
Quoted 5 lines
A question:
I find the page related toqi_ctrl->qinval_maddris not freed at all. IMO, Indisable_qinval(), we need to do:
- free the page related toqi_ctrl->qinval_maddr.
-qi_ctrl->qinval_maddr= 0;
Quoted 8 lines
Well, that's a correct observation, but not a big problem imo: If this was a per- domain resource, it surely would need fixing. But if freeing a couple of these pages (one per IOMMU) causes synchronization headaches (e.g. because there may still be dangling references to it), then I think freeing them is not a must. But if freeing them is safe (like you seem to imply), then I'm certainly fine with you fixing this (not that my opinion would matter much here, as I'm not the maintainer of this code).
Agreed, thanks for your explanation. At least I will leave it as is in this patch set.
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Patch v11 3/3] vt-d: fix vt-d Device-TLB flush timeout issue
Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 17.06.16 at 08:08, <[email protected]> wrote:
Quoted 44 lines · Jan Beulich
Quoted 43 lines
Quoted 1 line
Quoted 1 line · On 16.06.16 at 10:42, <[email protected]> wrote:
Quoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 01.06.16 at 11:05, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +28
-0+static void dev_invalidate_iotlb_timeout (struct iommu *iommu,u16 did, +struct pci_ats_dev +*ats_dev) { +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 == ats_dev->seg) && + (pdev->bus == ats_dev->bus) && + (pdev->devfn == ats_dev->devfn) ) + { +ASSERT (pdev->domain); +list_del (&pdev->domain_list); + pdev->domain =NULL ; +pci_hide_existing_device (pdev);Quoted 9 lines
xen/drivers/passthrough/vtd/qinval.c static int __must_check queue_invalidate_wait(struct iommu *iommu, · line 244
Quoted 5 lines
xen/drivers/passthrough/vtd/qinval.c +5
-0+break ; + } + } + +pcidevs_unlock ();... this loop (and locking). (Of course such a change may better be done in another preparatory patch.)
To eliminate the locking? I am afraid the locking is still a must here even without the loop, also referring to
device_assigned()..
Quoted 8 lines
Quoted 6 lines
If the entire loop gets eliminated, what would be left is
pcidevs_lock(); pcidevs_unlock();which I don't think does any good.
Why? I can't follow it..
I don't understand your question. Can you explain what use above code sequence is, in your opinion? Or else - what does the "why" refer to?
Quoted 38 lines
Quoted 32 lines
Quoted 27 lines
Quoted 14 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+static int __must_check dev_invalidate_sync(struct iommu *iommu, +u16did,
Quoted 11 lines
xen/drivers/passthrough/vtd/qinval.c +11
-0+struct pci_ats_dev +*ats_dev) { +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 ,1 ); + +if ( rc == -ETIMEDOUT ) +dev_invalidate_iotlb_timeout (iommu, did, ats_dev);Quoted 9 lines
xen/drivers/passthrough/vtd/qinval.c static int __must_check queue_invalidate_wait(struct iommu *iommu, · line 272
Quoted 4 lines
xen/drivers/passthrough/vtd/qinval.c +4
-0+ } + +return rc; +}I've never really understood why
invalidate_sync()returns success when it didn't do anything. Now that you copy this same behavior here, I really need to ask you to explain that.It is acceptable to me, returning success when it didn't do anything -- this is worth reflection and criticism:(..
It is better:Review
Quoted 4 lines
(quoted diff) +4
-0+ if ( qi_ctrl->qinval_maddr ) + ... + else + rc = -ENOENT;Quoted 1 line
Right. And perhaps a separate patch to make
invalidate_sync()do the same.Agreed.
Quoted 1 line
Question is whether this really ought to be a conditional, or whether
instead
Quoted 8 lines
Quoted 3 lines
this code is unreachable when qinval is not in use, in which case these conditionals would imo better be converted to ASSERT()s.
IMO, this should be a conditional.
As mentioned below, strictly speaking, this is a bug. We can'tASSERT()based on a bug..
A coming patch may fix it..
And again I don't understand: ASSERT()s are to verify assumed state. If static code analysis resulted in understanding a function is unreachable when qi_ctrl->qinval_maddr is zero (because qinval ought to have got disabled if any of the table setup failed), then adding ASSERT() would (a) document that and (b) allow to know quickly if something broke that assumption.
But then again I may simply misunderstand your wording: "We can't ASSERT() based on a bug" is really pretty unclear to me.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Patch v11 3/3] vt-d: fix vt-d Device-TLB flush timeout issue
Quoted 54 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 17.06.16 at 08:08, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 16.06.16 at 10:42, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 01.06.16 at 11:05, <[email protected]> wrote:
+static void dev_invalidate_iotlb_timeout(struct iommu *iommu, u16
did,
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c static int __must_check queue_invalidate_wait(struct iommu *iommu,
Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c +10
-0+struct pci_ats_dev +*ats_dev) { +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
Quoted 35 lines
Quoted 35 lines
Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
xen/drivers/passthrough/vtd/qinval.c +17
-0+* not valid, the device no longer belongs to this domain. +*/ +if ( d ==NULL ) +return ; + +pcidevs_lock (); + +for_each_pdev (d, pdev) + { +if ( (pdev->seg == ats_dev->seg) && + (pdev->bus == ats_dev->bus) && + (pdev->devfn == ats_dev->devfn) ) + { +ASSERT (pdev->domain); +list_del (&pdev->domain_list); + pdev->domain =NULL ; +pci_hide_existing_device (pdev);Quoted 9 lines
xen/drivers/passthrough/vtd/qinval.c static int __must_check queue_invalidate_wait(struct iommu *iommu, · line 244
Quoted 5 lines
xen/drivers/passthrough/vtd/qinval.c +5
-0+break ; + } + } + +pcidevs_unlock ();... this loop (and locking). (Of course such a change may better be done in another preparatory patch.)
Quoted 2 lines
To eliminate the locking? I am afraid the locking is still a must here even without the loop, also referring to
device_assigned()..If the entire loop gets eliminated, what would be left is
pcidevs_lock(); pcidevs_unlock();
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
which I don't think does any good.
Why? I can't follow it..
I don't understand your question. Can you explain what use above code sequence is, in your opinion? Or else - what does the "why" refer to?
Ah, there may be a gap between us. without this loop, these pdev operation should be still there, such as,
+ ASSERT(pdev->domain); + list_del(&pdev->domain_list); + pdev->domain = NULL; + pci_hide_existing_device(pdev);
So, the left is not only:
pcidevs_lock();
pcidevs_unlock();
Quoted 50 lines
Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
Quoted 15 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+static int __must_check dev_invalidate_sync(struct iommu +*iommu, +u16did,
Quoted 11 lines
xen/drivers/passthrough/vtd/qinval.c +11
-0+struct pci_ats_dev +*ats_dev) { +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 ,1 ); + +if ( rc == -ETIMEDOUT ) +dev_invalidate_iotlb_timeout (iommu, did, ats_dev);Quoted 9 lines
xen/drivers/passthrough/vtd/qinval.c static int __must_check queue_invalidate_wait(struct iommu *iommu, · line 272
Quoted 4 lines
xen/drivers/passthrough/vtd/qinval.c +4
-0+ } + +return rc; +}I've never really understood why
invalidate_sync()returns success when it didn't do anything. Now that you copy this same behavior here, I really need to ask you to explain that.It is acceptable to me, returning success when it didn't do anything
-- this is worth reflection and criticism:(..
It is better:(quoted diff) +4
-0+ if ( qi_ctrl->qinval_maddr ) + ... + else + rc = -ENOENT;Quoted 1 line
Quoted 1 line
Right. And perhaps a separate patch to make
invalidate_sync()do thesame.
Quoted 5 lines
Agreed.
Quoted 1 line
Question is whether this really ought to be a conditional, or whether
instead
Quoted 8 lines
Quoted 3 lines
this code is unreachable when qinval is not in use, in which case these conditionals would imo better be converted to ASSERT()s.
IMO, this should be a conditional.
As mentioned below, strictly speaking, this is a bug. We can'tASSERT()based on a bug..
A coming patch may fix it..
Quoted 6 lines
And again I don't understand: ASSERT()s are to verify assumed state. If static code analysis resulted in understanding a function is unreachable when
qi_ctrl->qinval_maddris zero (because qinval ought to have got disabled if any of the table setup failed), then addingASSERT()would (a) document that and
(b) allow to know quickly if something broke that assumption.
You are right. A separate patch does this.
Quoted 3 lines
But then again I may simply misunderstand your wording: "We can't
ASSERT()based on a bug" is really pretty unclear to me.
I supposed the variable in ASSERT() is always true, but disable_qinval() needs to make qi_ctrl->qinval_maddr zero, but today it doesn't do this -- a bug.
With your explanation, I got it now. Thanks.
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Patch v11 3/3] vt-d: fix vt-d Device-TLB flush timeout issue
Quoted 74 lines
Quoted 1 line
Quoted 1 line · On 17.06.16 at 10:15, <[email protected]> wrote:
Quoted 54 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 17.06.16 at 08:08, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 16.06.16 at 10:42, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 01.06.16 at 11:05, <[email protected]> wrote:
+static void dev_invalidate_iotlb_timeout(struct iommu *iommu, u16
did,
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Review
Quoted 10 lines
(quoted diff) +10
-0+ struct pci_ats_dev +*ats_dev) { + 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 bitmapis
Quoted 35 lines
Quoted 35 lines
Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
(quoted diff) +17
-0+ * not valid, the device no longer belongs to this domain. + */ + if ( d == NULL ) + return; + + pcidevs_lock(); + + for_each_pdev(d, pdev) + { + if ( (pdev->seg == ats_dev->seg) && + (pdev->bus == ats_dev->bus) && + (pdev->devfn == ats_dev->devfn) ) + { + ASSERT(pdev->domain); + list_del(&pdev->domain_list); + pdev->domain = NULL; + pci_hide_existing_device(pdev);Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ break; + } + } + + pcidevs_unlock();... this loop (and locking). (Of course such a change may better be done in another preparatory patch.)
Quoted 2 lines
To eliminate the locking? I am afraid the locking is still a must here even without the loop, also referring to
device_assigned()..If the entire loop gets eliminated, what would be left is
pcidevs_lock(); pcidevs_unlock();Quoted 8 lines
Quoted 3 lines
Quoted 1 line
which I don't think does any good.
Why? I can't follow it..
I don't understand your question. Can you explain what use above code sequence is, in your opinion? Or else - what does the "why" refer to?
Ah, there may be a gap between us. without this loop, these pdev operation should be still there, such as,
(quoted diff) +4
-0+ ASSERT(pdev->domain); + list_del(&pdev->domain_list); + pdev->domain = NULL; + pci_hide_existing_device(pdev);
Quoted 3 lines
So, the left is not only:
pcidevs_lock(); pcidevs_unlock();
Oh, indeed. My bad.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Patch v11 3/3] vt-d: fix vt-d Device-TLB flush timeout issue
In reply to Jan BeulichQuoted 5 lines · Jan Beulich
And again I don't understand: ASSERT()s are to verify assumed state. If static code analysis resulted in understanding a function is unreachable when
qi_ctrl->qinval_maddris zero (because qinval ought to have got disabled if any of the table setup failed), then addingASSERT()would (a) document that and
(b) allow to know quickly if something broke that assumption.
other than enable_qinval() -- yes, I need to convert conditionals of qi_ctrl->qinval_maddr into
ASSERT()s..
But in enable_qinval(), I am still not quite sure whether I need to convert these conditionals of
qi_ctrl->qinval_maddr into ASSERT()s or not.
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Patch v11 3/3] vt-d: fix vt-d Device-TLB flush timeout issue
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 22.06.16 at 17:54, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
And again I don't understand: ASSERT()s are to verify assumed state. If
static
Quoted 2 lines
code analysis resulted in understanding a function is unreachable when
qi_ctrl->qinval_maddris zero (because qinval ought to have got disabled ifany
Quoted 2 lines
of the table setup failed), then adding
ASSERT()would (a) document that and
(b) allow to know quickly if something broke that assumption.
Quoted 6 lines
other than
enable_qinval()-- yes, I need to convert conditionals ofqi_ctrl->qinval_maddrinto
ASSERT()s..
But inenable_qinval(), I am still not quite sure whether I need to convert these conditionals of
qi_ctrl->qinval_maddrinto ASSERT()s or not.
No, I don't think you want to so there - you'd bring the system down in case of an actual initialization error. ASSERT()s should only be used on conditions controlled entirely by the hypervisor.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Patch v11 3/3] vt-d: fix vt-d Device-TLB flush timeout issue
Quoted 19 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 22.06.16 at 17:54, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
And again I don't understand: ASSERT()s are to verify assumed state. If
static
Quoted 3 lines
code analysis resulted in understanding a function is unreachable when
qi_ctrl->qinval_maddris zero (because qinval ought to have got disabled ifany
Quoted 3 lines
of the table setup failed), then adding
ASSERT()would (a) document that and
(b) allow to know quickly if something broke that assumption.Quoted 5 lines
other than
enable_qinval()-- yes, I need to convert conditionals ofqi_ctrl->qinval_maddrinto ASSERT()s..
But inenable_qinval(), I am still not quite sure whether I need to convert these conditionals ofqi_ctrl->qinval_maddrinto ASSERT()s or not.
Quoted 4 lines
No, I don't think you want to so there - you'd bring the system down in case of an actual initialization error. ASSERT()s should only be used on conditions controlled entirely by the hypervisor.
Jan, thank you. Now I am clear.
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel