VT-d Device-TLB flush issue
v13 cover VT-d Device-TLB flush issue
From: Quan Xu <[email protected]>
This patches fix current timeout concern and also allow limited ATS support.
these patches are the rest ones:
1. move the domain crash logic up to the generic IOMMU layer
2. If Device-TLB flush timed out, we hide the target ATS device immediately. By hiding the device, we make sure it can't be assigned to any domain any longer (see device_assigned).
---
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/x86: use a struct pci_dev* instead of SBDF
IOMMU: add domain crash logic
IOMMU: fix vt-d Device-TLB flush timeout issue
xen/drivers/passthrough/amd/iommu_cmd.c | 13 +++--- xen/drivers/passthrough/amd/pci_amd_iommu.c | 4 +- xen/drivers/passthrough/ats.h | 10 ++--- xen/drivers/passthrough/iommu.c | 51 +++++++++++++++++++++- xen/drivers/passthrough/pci.c | 6 +-- xen/drivers/passthrough/vtd/extern.h | 5 ++- xen/drivers/passthrough/vtd/intremap.c | 8 ++-- xen/drivers/passthrough/vtd/iommu.c | 25 ++++++++--- xen/drivers/passthrough/vtd/qinval.c | 56 ++++++++++++++++++------ xen/drivers/passthrough/vtd/x86/ats.c | 21 +++++---- xen/drivers/passthrough/x86/ats.c | 67 ++++++++++++++++++----------- xen/include/xen/iommu.h | 3 ++ xen/include/xen/pci.h | 1 + 13 files changed, 189 insertions(+), 81 deletions(-)
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v13 1/3 IOMMU/x86: use a struct pci_dev* instead of SBDF
From: Quan Xu <[email protected]>
A struct pci_dev* instead of SBDF is stored inside struct pci_ats_dev and parameter to *_ats_device().
Also use ats_dev for "struct pci_ats_dev" variable, while pdev (_pdev, if there is already a pdev) for "struct pci_dev" in the scope of IOMMU.
---
v13:
1. use ats_dev for "struct pci_ats_dev" variable, while pdev (_pdev, if there is already a pdev) for "struct pci_dev" in the scope of IOMMU.
2. add local variables seg, bus, and devfn, which will greatly reduce the number of changes in *_ats_device().
3. convert SBDF into struct pci_dev* to disable_ats_device() get_ats_device() as well.
(
enable_ats_device() and disable_ats_device() can't have the const added to 'struct pci_dev *pdev', otherwise then compilation fails. also Afaict that would in turn eliminate the need for some of the changes further up. but get_ats_device() can.
)
--- xen/drivers/passthrough/amd/iommu_cmd.c | 13 +++--- xen/drivers/passthrough/amd/pci_amd_iommu.c | 4 +- xen/drivers/passthrough/ats.h | 10 ++--- xen/drivers/passthrough/vtd/intremap.c | 8 ++-- xen/drivers/passthrough/vtd/iommu.c | 14 +++--- xen/drivers/passthrough/vtd/x86/ats.c | 24 +++++++---- xen/drivers/passthrough/x86/ats.c | 67 ++++++++++++++++++----------- 7 files changed, 81 insertions(+), 59 deletions(-)
xen/drivers/passthrough/amd/iommu_cmd.c +6 -7
@@ -294,28 +294,27 @@ void amd_iommu_flush_iotlb(u8 devfn, const struct pci_dev *pdev,if ( !ats_enabled )return ; - ats_pdev =get_ats_device (pdev->seg, pdev->bus, pdev->devfn); + ats_pdev =get_ats_device (pdev);if ( ats_pdev ==NULL )return ; -if ( !pci_ats_enabled (ats_pdev->seg, ats_pdev->bus, ats_pdev->devfn) ) +if ( !pci_ats_enabled (pdev->seg, pdev->bus, pdev->devfn) )return ; - iommu =find_iommu_for_device (ats_pdev->seg, -PCI_BDF2 (ats_pdev->bus, ats_pdev->devfn)); + iommu =find_iommu_for_device (pdev->seg,PCI_BDF2 (pdev->bus, pdev->devfn));if ( !iommu ) {AMD_IOMMU_DEBUG ("%s: Can't find iommu for %04x:%02x:%02x.%u\n" , - __func__, ats_pdev->seg, ats_pdev->bus, -PCI_SLOT (ats_pdev->devfn),PCI_FUNC (ats_pdev->devfn)); + __func__, pdev->seg, pdev->bus, +PCI_SLOT (pdev->devfn),PCI_FUNC (pdev->devfn));return ; }if ( !iommu_has_cap (iommu,PCI_CAP_IOTLB_SHIFT ) )return ; - req_id =get_dma_requestor_id (iommu->seg,PCI_BDF2 (ats_pdev->bus, devfn)); + req_id =get_dma_requestor_id (iommu->seg,PCI_BDF2 (pdev->bus, pdev->devfn)); queueid = req_id; maxpend = ats_pdev->ats_queue_depth &0xff ;
xen/drivers/passthrough/amd/pci_amd_iommu.c +2 -2
@@ -162,7 +162,7 @@ static void amd_iommu_setup_domain_device( !pci_ats_enabled(iommu->seg, bus, pdev->devfn) ) {if ( devfn == pdev->devfn ) -enable_ats_device (iommu->seg, bus, devfn, iommu); +enable_ats_device (iommu, pdev);amd_iommu_flush_iotlb (devfn, pdev,INV_IOMMU_ALL_PAGES_ADDRESS ,0 ); }
@@ -356,7 +356,7 @@ void amd_iommu_disable_domain_device(struct domain *domain,if ( devfn == pdev->devfn &&pci_ats_device (iommu->seg, bus, devfn) &&pci_ats_enabled (iommu->seg, bus, devfn) ) -disable_ats_device (iommu->seg, bus, devfn); +disable_ats_device (pdev); } static int reassign_device(struct domain *source, struct domain *target,
xen/drivers/passthrough/ats.h +4 -6
@@ -19,9 +19,7 @@struct pci_ats_dev {struct list_head list; -u16 seg; -u8 bus; -u8 devfn; +struct pci_dev *pdev;u16 ats_queue_depth;/* ATS device invalidation queue depth */ const void *iommu;/* No common IOMMU struct so use void pointer */ };
@@ -34,9 +32,9 @@ struct pci_ats_dev {extern struct list_head ats_devices;extern bool_t ats_enabled; -int enable_ats_device (int seg,int bus,int devfn,const void *iommu); -void disable_ats_device (int seg,int bus,int devfn); -struct pci_ats_dev *get_ats_device (int seg,int bus,int devfn); +int enable_ats_device (const void *iommu,struct pci_dev *pdev); +void disable_ats_device (struct pci_dev *pdev); +struct pci_ats_dev *get_ats_device (const struct pci_dev *pdev);static inline int pci_ats_enabled (int seg,int bus,int devfn) {
xen/drivers/passthrough/vtd/intremap.c +4 -4
@@ -952,7 +952,7 @@ int pi_update_irte(const struct vcpu *v, const struct pirq *pirq,const struct msi_desc *msi_desc;int remap_index;int rc =0 ; -const struct pci_dev *pci_dev; +const struct pci_dev *pdev;const struct acpi_drhd_unit *drhd;struct iommu *iommu;struct ir_ctrl *ir_ctrl;
@@ -972,8 +972,8 @@ int pi_update_irte(const struct vcpu *v, const struct pirq *pirq, goto unlock_out; } - pci_dev = msi_desc->dev; -if ( !pci_dev ) + pdev = msi_desc->dev; +if ( !pdev ) { rc = -ENODEV ; goto unlock_out;
@@ -990,7 +990,7 @@ int pi_update_irte(const struct vcpu *v, const struct pirq *pirq,* 'struct msi_desc' in some other place, so we don't need to waste * time searching it here. */ - drhd =acpi_find_matched_drhd_unit (pci_dev); + drhd =acpi_find_matched_drhd_unit (pdev);if ( !drhd )return -ENODEV ;
xen/drivers/passthrough/vtd/iommu.c +7 -7
@@ -1461,8 +1461,8 @@ int domain_context_mapping_one(return rc; } -static int domain_context_mapping ( -struct domain *domain,u8 devfn,const struct pci_dev *pdev) +static int domain_context_mapping (struct domain *domain,u8 devfn, +struct pci_dev *pdev) {struct acpi_drhd_unit *drhd;int ret =0 ;
@@ -1498,7 +1498,7 @@ static int domain_context_mapping( ret =domain_context_mapping_one (domain, drhd->iommu, bus, devfn, pdev);if ( !ret && devfn == pdev->devfn &&ats_device (pdev, drhd) >0 ) -enable_ats_device (seg, bus, devfn, drhd->iommu); +enable_ats_device (drhd->iommu, pdev);break ;
@@ -1611,8 +1611,8 @@ int domain_context_unmap_one(return rc; } -static int domain_context_unmap ( -struct domain *domain,u8 devfn,const struct pci_dev *pdev) +static int domain_context_unmap (struct domain *domain,u8 devfn, +struct pci_dev *pdev) {struct acpi_drhd_unit *drhd;struct iommu *iommu;
@@ -1648,7 +1648,7 @@ static int domain_context_unmap( PCI_SLOT(devfn), PCI_FUNC(devfn)); ret =domain_context_unmap_one (domain, iommu, bus, devfn);if ( !ret && devfn == pdev->devfn &&ats_device (pdev, drhd) >0 ) -disable_ats_device (seg, bus, devfn); +disable_ats_device (pdev);break ;
@@ -1994,7 +1994,7 @@ static int intel_iommu_enable_device(struct pci_dev *pdev)if ( ret <=0 )return ret; - ret =enable_ats_device (pdev->seg, pdev->bus, pdev->devfn, drhd->iommu); + ret =enable_ats_device (drhd->iommu, pdev);return ret >=0 ?0 : ret; }
xen/drivers/passthrough/vtd/x86/ats.c +15 -9
@@ -71,12 +71,14 @@ int ats_device(const struct pci_dev *pdev, const struct acpi_drhd_unit *drhd)return pos; } -static int device_in_domain (struct iommu *iommu,struct pci_ats_dev *pdev,u16 did) +static int device_in_domain (struct iommu *iommu,struct pci_ats_dev *ats_dev,u16 did) {struct root_entry *root_entry =NULL ;struct context_entry *ctxt_entry =NULL ;int tt, found =0 ; +struct pci_dev *pdev = ats_dev->pdev; +ASSERT (pdev); root_entry = (struct root_entry *)map_vtd_domain_page (iommu->root_maddr);if ( !root_entry || !root_present (root_entry[pdev->bus]) ) goto out;
@@ -108,37 +110,41 @@ out:int dev_invalidate_iotlb (struct iommu *iommu,u16 did,u64 addr,unsigned int size_order,u64 type) { -struct pci_ats_dev *pdev; +struct pci_ats_dev *ats_dev;int ret =0 ;if ( !ecap_dev_iotlb (iommu->ecap) )return ret; -list_for_each_entry ( pdev, &ats_devices, list ) +list_for_each_entry ( ats_dev, &ats_devices, list ) { -u16 sid =PCI_BDF2 (pdev->bus, pdev->devfn); +struct pci_dev *pdev = ats_dev->pdev; +u16 sid;bool_t sbit;int rc =0 ; +ASSERT (pdev); + sid =PCI_BDF2 (pdev->bus, pdev->devfn); +/* Only invalidate devices that belong to this IOMMU */ -if ( pdev->iommu != iommu ) +if ( ats_dev->iommu != iommu )continue ;switch ( type ) {case DMA_TLB_DSI_FLUSH : -if ( !device_in_domain (iommu, pdev, did) ) +if ( !device_in_domain (iommu, ats_dev, did) )break ;/* fall through if DSI condition met */ case DMA_TLB_GLOBAL_FLUSH :/* 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, + rc =qinval_device_iotlb_sync (iommu, ats_dev->ats_queue_depth, sid, sbit, addr);break ;case DMA_TLB_PSI_FLUSH : -if ( !device_in_domain (iommu, pdev, did) ) +if ( !device_in_domain (iommu, ats_dev, did) )break ;/* if size <= 4K, set sbit = 0, else set sbit = 1 */
@@ -154,7 +160,7 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did, addr |= (((u64 )1 << (size_order -1 )) -1 ) <<PAGE_SHIFT_4K ; } - rc =qinval_device_iotlb_sync (iommu, pdev->ats_queue_depth, + rc =qinval_device_iotlb_sync (iommu, ats_dev->ats_queue_depth, sid, sbit, addr);break ;default :
xen/drivers/passthrough/x86/ats.c +43 -24
124 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v13 1/3] IOMMU/x86: use a struct pci_dev* instead of SBDF
Quoted 12 lines
From: Xu, Quan
Sent: Wednesday, June 29, 2016 2:00 PMFrom: Quan Xu <[email protected]>
A struct pci_dev* instead of SBDF is stored inside struct
pci_ats_devand parameter to*_ats_device().Also use
ats_devfor "structpci_ats_dev" variable, while pdev (_pdev, if there is already a pdev) for "structpci_dev" in the scope of IOMMU.
Quoted 7 lines
Signed-off-by Quan Xu <[email protected]>CC Jan Beulich <[email protected]>CC Kevin Tian <[email protected]>CC Feng Wu <[email protected]>CC Suravee Suthikulpanit <[email protected]>
Quoted 6 lines
xen/drivers/passthrough/amd/iommu_cmd.c +0
-0
xen/drivers/passthrough/amd/iommu_cmd.c void amd_iommu_flush_iotlb(u8 devfn, const struct pci_dev · line 301
Quoted 9 lines
xen/drivers/passthrough/amd/iommu_cmd.c +1
-1@@ -294,28 +294,27 @@ void amd_iommu_flush_iotlb(u8 devfn, const struct pci_dev *pdev, if ( !ats_enabled ) return; - ats_pdev =get_ats_device (pdev->seg, pdev->bus, pdev->devfn); + ats_pdev =get_ats_device (pdev);if ( ats_pdev ==NULL )return ;
To align with other places, better to change ats_pdev to ats_dev too.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v13 1/3] IOMMU/x86: use a struct pci_dev* instead of SBDF
Quoted 32 lines · Kevin
Quoted 12 lines
From: Xu, Quan
Sent: Wednesday, June 29, 2016 2:00 PMFrom: Quan Xu <[email protected]>
A struct pci_dev* instead of SBDF is stored inside struct
pci_ats_devand parameter to*_ats_device().Also use
ats_devfor "structpci_ats_dev" variable, while pdev (_pdev, if there is already a pdev) for "structpci_dev"
in the scope of IOMMU.Quoted 7 lines
Signed-off-by Quan Xu <[email protected]>CC Jan Beulich <[email protected]>CC Kevin Tian <[email protected]>CC Feng Wu <[email protected]>CC Suravee Suthikulpanit <[email protected]>Quoted 10 lines
xen/drivers/passthrough/amd/iommu_cmd.c +0
-0@@ -294,28 +294,27 @@ void amd_iommu_flush_iotlb(u8 devfn, const struct pci_dev *pdev, if ( !ats_enabled ) return;
Quoted 7 lines
xen/drivers/passthrough/amd/iommu_cmd.c void amd_iommu_flush_iotlb(u8 devfn, const struct pci_dev *pdev, · line 300
Quoted 5 lines
xen/drivers/passthrough/amd/iommu_cmd.c +1
-1- ats_pdev =get_ats_device (pdev->seg, pdev->bus, pdev->devfn); + ats_pdev =get_ats_device (pdev);if ( ats_pdev ==NULL )return ;To align with other places, better to change
ats_pdevtoats_devtoo.
Indeed, thanks very much!!
I will update it soon.
- Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v13 2/3 IOMMU: add domain crash logic
In reply to Xu, QuanFrom: Quan Xu <[email protected]>
Add domain crash logic to the generic IOMMU layer to benefit all platforms.
No spamming of the log can occur. For DomU, we avoid logging any message for already dying domains. For Dom0, that'll still be more verbose than we'd really like, but it at least wouldn't outright flood the console.
---
v13: enhance commit message
--- xen/drivers/passthrough/iommu.c | 30 ++++++++++++++++++++++++++++-- xen/drivers/passthrough/vtd/iommu.c | 11 +++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-)
xen/drivers/passthrough/iommu.c +28 -2
@@ -318,21 +318,47 @@ int iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count) {const struct domain_iommu *hd =dom_iommu (d); +int rc;if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush )return 0 ; -return hd->platform_ops->iotlb_flush (d, gfn, page_count); + rc = hd->platform_ops->iotlb_flush (d, gfn, page_count); +if (unlikely (rc) ) + { +if ( !d->is_shutting_down &&printk_ratelimit () ) +printk (XENLOG_ERR +"d%d: IOMMU IOTLB flush failed: %d, gfn %#lx, page count %u\n" , + d->domain_id, rc, gfn, page_count); + +if ( !is_hardware_domain (d) ) +domain_crash (d); + } + +return rc; }int iommu_iotlb_flush_all (struct domain *d) {const struct domain_iommu *hd =dom_iommu (d); +int rc;if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush_all )return 0 ; -return hd->platform_ops->iotlb_flush_all (d); + rc = hd->platform_ops->iotlb_flush_all (d); +if (unlikely (rc) ) + { +if ( !d->is_shutting_down &&printk_ratelimit () ) +printk (XENLOG_ERR +"d%d: IOMMU IOTLB flush all failed: %d\n" , + d->domain_id, rc); + +if ( !is_hardware_domain (d) ) +domain_crash (d); + } + +return rc; }int __init iommu_setup (void )
xen/drivers/passthrough/vtd/iommu.c +11 -0
@@ -1847,6 +1847,17 @@ int iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte, } } +if (unlikely (rc) ) + { +if ( !d->is_shutting_down &&printk_ratelimit () ) + printk(XENLOG_ERR VTDPREFIX +" d%d: IOMMU pages flush failed: %d\n" , + d->domain_id, rc); + +if ( !is_hardware_domain (d) ) +domain_crash (d); + } +return rc; }
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v13 2/3] IOMMU: add domain crash logic
Quoted 8 lines
From: Xu, Quan
Sent: Wednesday, June 29, 2016 2:00 PMFrom: Quan Xu <[email protected]>
Add domain crash logic to the generic IOMMU layer to benefit all platforms.
Quoted 6 lines
No spamming of the log can occur. For DomU, we avoid logging any message for already dying domains. For Dom0, that'll still be more verbose than we'd really like, but it at least wouldn't outright flood the console.
Signed-off-by Quan Xu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v13 3/3 IOMMU: 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. By hiding the device, we make sure it can't be assigned to any domain any longer (see device_assigned).
---
v13:
1. drop domain crash logic, which is added to the vendor independent layer in patch #2.
2. rename dev_invalidate_iotlb_timeout() to iommu_dev_iotlb_flush_timeout() and move it to the vendor independent layer.
--- xen/drivers/passthrough/iommu.c | 21 +++++++++++++ xen/drivers/passthrough/pci.c | 6 ++-- xen/drivers/passthrough/vtd/extern.h | 5 ++-- xen/drivers/passthrough/vtd/qinval.c | 56 +++++++++++++++++++++++++++-------- xen/drivers/passthrough/vtd/x86/ats.c | 11 ++----- xen/include/xen/iommu.h | 3 ++ xen/include/xen/pci.h | 1 + 7 files changed, 76 insertions(+), 27 deletions(-)
xen/drivers/passthrough/iommu.c +21 -0
@@ -361,6 +361,27 @@ int iommu_iotlb_flush_all(struct domain *d)return rc; } +void iommu_dev_iotlb_flush_timeout (struct domain *d, +struct pci_dev *pdev) +{ +pcidevs_lock (); + +ASSERT (pdev->domain); +if ( d != pdev->domain ) +return ; + +list_del (&pdev->domain_list); + pdev->domain =NULL ; +pci_hide_existing_device (pdev); +if ( !d->is_shutting_down &&printk_ratelimit () ) +printk (XENLOG_ERR +"dom%d: ATS device %04x:%02x:%02x.%u flush failed\n" , + d->domain_id, pdev->seg, pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn)); + +pcidevs_unlock (); +} +int __init iommu_setup (void ) {int rc = -ENODEV ;
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
@@ -25,6 +25,7 @@#define VTDPREFIX "[VT-D]" +struct pci_ats_dev ;extern bool_t rwbf_quirk;void print_iommu_regs (struct acpi_drhd_unit *drhd);
@@ -60,8 +61,8 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did, u64 addr, unsigned int size_order, u64 type);int __must_check qinval_device_iotlb_sync (struct iommu *iommu, -u32 max_invs_pend, -u16 sid,u16 size,u64 addr); +struct pci_ats_dev *ats_dev, +u16 did,u16 size,u64 addr);unsigned int get_cache_line_size (void );void cacheline_flush (char *);
xen/drivers/passthrough/vtd/qinval.c +43 -13
116 lines not on this page · raw message
xen/drivers/passthrough/vtd/x86/ats.c +2 -9
@@ -118,14 +118,9 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,list_for_each_entry ( ats_dev, &ats_devices, list ) { -struct pci_dev *pdev = ats_dev->pdev; -u16 sid;bool_t sbit;int rc =0 ; -ASSERT (pdev); - sid =PCI_BDF2 (pdev->bus, pdev->devfn); -/* Only invalidate devices that belong to this IOMMU */ if ( ats_dev->iommu != iommu )continue ;
@@ -140,8 +135,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, ats_dev->ats_queue_depth, - sid, sbit, addr); + rc =qinval_device_iotlb_sync (iommu, ats_dev, did, sbit, addr);break ;case DMA_TLB_PSI_FLUSH :if ( !device_in_domain (iommu, ats_dev, did) )
@@ -160,8 +154,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, ats_dev->ats_queue_depth, - sid, sbit, addr); + rc =qinval_device_iotlb_sync (iommu, ats_dev, did, sbit, addr);break ;default : dprintk(XENLOG_WARNING VTDPREFIX, "invalid vt-d flush type\n");
xen/include/xen/iommu.h +3 -0
@@ -207,6 +207,9 @@ int __must_check iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count);int __must_check iommu_iotlb_flush_all (struct domain *d); +void iommu_dev_iotlb_flush_timeout (struct domain *d, +struct pci_dev *pdev); +/* * The purpose of the iommu_dont_flush_iotlb optional cpu flag is to * avoid unecessary iotlb_flush in the low level IOMMU code.
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 v13 3/3] IOMMU: fix vt-d Device-TLB flush timeout issue
Quoted 38 lines
From: Xu, Quan
Sent: Wednesday, June 29, 2016 2:00 PMFrom: Quan Xu <[email protected]>
If Device-TLB flush timed out, we hide the target ATS device immediately. By hiding the device, we make sure it can't be assigned to any domain any longer (see
device_assigned).Signed-off-by Quan Xu <[email protected]>---
v13:
1. drop domain crash logic, which is added to the vendor independent layer in patch #2.
2. renamedev_invalidate_iotlb_timeout()toiommu_dev_iotlb_flush_timeout()and move it to the vendor independent layer.--- xen/drivers/passthrough/iommu.c | 21 +++++++++++++ xen/drivers/passthrough/pci.c | 6 ++-- xen/drivers/passthrough/vtd/extern.h | 5 ++-- xen/drivers/passthrough/vtd/qinval.c | 56 +++++++++++++++++++++++++++-------- xen/drivers/passthrough/vtd/x86/ats.c | 11 ++----- xen/include/xen/iommu.h | 3 ++ xen/include/xen/pci.h | 1 + 7 files changed, 76 insertions(+), 27 deletions(-)xen/drivers/passthrough/iommu.c +0
-0@@ -361,6 +361,27 @@ int iommu_iotlb_flush_all(struct domain *d)return rc;
xen/drivers/passthrough/iommu.c int iommu_iotlb_flush_all(struct domain *d) · line 371
Quoted 10 lines
xen/drivers/passthrough/iommu.c +8
-0} +void iommu_dev_iotlb_flush_timeout (struct domain *d, +struct pci_dev *pdev) +{ +pcidevs_lock (); + +ASSERT (pdev->domain); +if ( d != pdev->domain ) +return ;
return w/o releasing the lock!
and is above scenario actually possible (a flush timeout is captured when the device doesn't belong to previous domain)? If not, better to move the condition into ASSERT.
xen/drivers/passthrough/iommu.c int iommu_iotlb_flush_all(struct domain *d) · line 382
Quoted 11 lines
xen/drivers/passthrough/iommu.c +11
-0+ +list_del (&pdev->domain_list); + pdev->domain =NULL ; +pci_hide_existing_device (pdev); +if ( !d->is_shutting_down &&printk_ratelimit () ) +printk (XENLOG_ERR +"dom%d: ATS device %04x:%02x:%02x.%u flush failed\n" , + d->domain_id, pdev->seg, pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn)); + +pcidevs_unlock ();
please move above warning out of the lock.
Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v13 3/3] IOMMU: fix vt-d Device-TLB flush timeout issue
Quoted 41 lines · Kevin
Quoted 15 lines
From: Xu, Quan
Sent: Wednesday, June 29, 2016 2:00 PMFrom: Quan Xu <[email protected]>
If Device-TLB flush timed out, we hide the target ATS device immediately. By hiding the device, we make sure it can't be assigned to any domain any longer (see
device_assigned).Signed-off-by Quan Xu <[email protected]>Quoted 5 lines
---
v13:
1. drop domain crash logic, which is added to the vendor independent layer in patch #2.
2. renamedev_invalidate_iotlb_timeout()to
iommu_dev_iotlb_flush_timeout()Quoted 20 lines
and move it to the vendor independent layer.
--- xen/drivers/passthrough/iommu.c | 21 +++++++++++++ xen/drivers/passthrough/pci.c | 6 ++-- xen/drivers/passthrough/vtd/extern.h | 5 ++-- xen/drivers/passthrough/vtd/qinval.c | 56 +++++++++++++++++++++++++++-------- xen/drivers/passthrough/vtd/x86/ats.c | 11 ++----- xen/include/xen/iommu.h | 3 ++ xen/include/xen/pci.h | 1 + 7 files changed, 76 insertions(+), 27 deletions(-)(quoted diff) +0
-0
b/xen/drivers/passthrough/iommu.cindex d793f5d..5db8ae6 100644xen/drivers/passthrough/iommu.c +0
-0@@ -361,6 +361,27 @@ int iommu_iotlb_flush_all(struct domain *d)return rc; }
Quoted 10 lines
xen/drivers/passthrough/iommu.c int iommu_iotlb_flush_all(struct domain *d) · line 371
Quoted 7 lines
xen/drivers/passthrough/iommu.c +7
-0+void iommu_dev_iotlb_flush_timeout (struct domain *d, +struct pci_dev *pdev) { +pcidevs_lock (); + +ASSERT (pdev->domain); +if ( d != pdev->domain ) +return ;return w/o releasing the lock!
Yes, I really need releasing the lock before return.
Quoted 3 lines
and is above scenario actually possible (a flush timeout is captured when the device doesn't belong to previous domain)? If not, better to move the condition into ASSERT.
IMO, this is possible.
-- not all of call trees of device iotlb flush are under pcidevs_lock, (.i.e ...--iommu_iotlb_flush()-- xenmem_add_to_physmap()... ) -- In extreme cases , the domain may has been freed or the device may has been detached or even attached to another domain.
That's also why to introduce a domain point here.
Quoted 15 lines
xen/drivers/passthrough/iommu.c int iommu_iotlb_flush_all(struct domain *d) · line 382
Quoted 12 lines
xen/drivers/passthrough/iommu.c +11
-0+ +list_del (&pdev->domain_list); + pdev->domain =NULL ; +pci_hide_existing_device (pdev); +if ( !d->is_shutting_down &&printk_ratelimit () ) +printk (XENLOG_ERR +"dom%d: ATS device %04x:%02x:%02x.%u flush failed\n" , + d->domain_id, pdev->seg, pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn)); + +pcidevs_unlock ();please move above warning out of the lock.
I think I'm better leave it as is.
as I use 'pdev' to print information, as similar as pci_release_devices().
If I use seg, bus, devfn variables directly, instead of 'pdev', I agree to move out of the lock, as similar as:
iommu_do_pci_domctl()
{
case XEN_DOMCTL_assign_device...
}
.... correct me if I am not right.
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel