VT-d Device-TLB flush issue
v15 cover VT-d Device-TLB flush issue
From: Quan Xu <[email protected]>
these 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).
Quan Xu (3):
IOMMU/ATS: use a struct pci_dev * instead of SBDF
IOMMU: add domain crash logic
VT-d: fix Device-TLB flush timeout issue
---
v15: Carried out my own review comments now that Quan left Intel.
---
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.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v15 1/3 IOMMU/ATS: use a struct pci_dev * instead of SBDF
From: Quan Xu <[email protected]>
Do away with struct pci_ats_dev; integrate the few bits of information in struct pci_dev (and as a result drop get_ats_device() altogether). Hook ATS devices onto a linked list off of each IOMMU instead of on a global one.
---
v15: See rewritten description. Ditch changes to vtd/intremap.c.
xen/drivers/passthrough/amd/iommu_cmd.c +6 -12
@@ -289,35 +289,29 @@ void amd_iommu_flush_iotlb(u8 devfn, conunsigned long flags;struct amd_iommu *iommu;unsigned int req_id, queueid, maxpend; -struct pci_ats_dev *ats_pdev;if ( !ats_enabled )return ; - ats_pdev =get_ats_device (pdev->seg, pdev->bus, pdev->devfn); -if ( ats_pdev ==NULL ) +if ( !pci_ats_enabled (pdev->seg, pdev->bus, pdev->devfn) )return ; -if ( !pci_ats_enabled (ats_pdev->seg, ats_pdev->bus, ats_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, devfn)); queueid = req_id; - maxpend = ats_pdev->ats_queue_depth &0xff ; + maxpend = pdev->ats.queue_depth &0xff ;/* send INVALIDATE_IOTLB_PAGES command */ spin_lock_irqsave (&iommu->lock, flags);
xen/drivers/passthrough/amd/iommu_detect.c +1 -0
@@ -128,6 +128,7 @@ int __init amd_iommu_detect_one_acpi( }spin_lock_init (&iommu->lock); +INIT_LIST_HEAD (&iommu->ats_devices); iommu->seg = ivhd_block->pci_segment_group; iommu->bdf = ivhd_block->header.device_id;
xen/drivers/passthrough/amd/pci_amd_iommu.c +2 -2
@@ -162,7 +162,7 @@ static void amd_iommu_setup_domain_devic !pci_ats_enabled(iommu->seg, bus, pdev->devfn) ) {if ( devfn == pdev->devfn ) -enable_ats_device (iommu->seg, bus, devfn, iommu); +enable_ats_device (pdev, &iommu->ats_devices);amd_iommu_flush_iotlb (devfn, pdev,INV_IOMMU_ALL_PAGES_ADDRESS ,0 ); }
@@ -356,7 +356,7 @@ void amd_iommu_disable_domain_device(strif ( 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 +2 -13
@@ -17,26 +17,15 @@#include <xen/pci_regs.h> -struct pci_ats_dev { -struct list_head list; -u16 seg; -u8 bus; -u8 devfn; -u16 ats_queue_depth;/* ATS device invalidation queue depth */ -const void *iommu;/* No common IOMMU struct so use void pointer */ -}; -#define ATS_REG_CAP 4#define ATS_REG_CTL 6#define ATS_QUEUE_DEPTH_MASK 0x1f#define ATS_ENABLE (1<<15) -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 (struct pci_dev *pdev,struct list_head *ats_list); +void disable_ats_device (struct pci_dev *pdev);static inline int pci_ats_enabled (int seg,int bus,int devfn) {
xen/drivers/passthrough/vtd/iommu.c +8 -7
@@ -1162,6 +1162,7 @@ int __init iommu_alloc(struct acpi_drhd_return -ENOMEM ; iommu->msi.irq =-1 ;/* No irq assigned yet. */ +INIT_LIST_HEAD (&iommu->ats_devices); iommu->intel =alloc_intel_iommu ();if ( iommu->intel ==NULL )
@@ -1461,8 +1462,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 +1499,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 (pdev, &drhd->iommu->ats_devices);break ;
@@ -1611,8 +1612,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 +1649,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 +1995,7 @@ static int intel_iommu_enable_device(strif ( ret <=0 )return ret; - ret =enable_ats_device (pdev->seg, pdev->bus, pdev->devfn, drhd->iommu); + ret =enable_ats_device (pdev, &drhd->iommu->ats_devices);return ret >=0 ?0 : ret; }
xen/drivers/passthrough/vtd/iommu.h +1 -0
@@ -542,6 +542,7 @@ struct iommu {u64 root_maddr;/* root entry machine address */ struct msi_desc msi;struct intel_iommu *intel; +struct list_head ats_devices;unsigned long *domid_bitmap;/* domain id bitmap */ u16 *domid_map;/* domain id mapping array */ };
xen/drivers/passthrough/vtd/x86/ats.c +6 -9
@@ -71,7 +71,8 @@ int ats_device(const struct pci_dev *pdereturn pos; } -static int device_in_domain (struct iommu *iommu,struct pci_ats_dev *pdev,u16 did) +static int device_in_domain (const struct iommu *iommu, +const struct pci_dev *pdev,u16 did) {struct root_entry *root_entry =NULL ;struct context_entry *ctxt_entry =NULL ;
@@ -108,22 +109,18 @@ out:int dev_invalidate_iotlb (struct iommu *iommu,u16 did,u64 addr,unsigned int size_order,u64 type) { -struct pci_ats_dev *pdev; +const struct pci_dev *pdev;int ret =0 ;if ( !ecap_dev_iotlb (iommu->ecap) )return ret; -list_for_each_entry ( pdev, &ats_devices, list ) +list_for_each_entry ( pdev, &iommu->ats_devices, ats.list ) {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 ) -continue ; -switch ( type ) {case DMA_TLB_DSI_FLUSH :
@@ -134,7 +131,7 @@ int dev_invalidate_iotlb(struct iommu *i/* 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, pdev->ats.queue_depth, sid, sbit, addr);break ;case DMA_TLB_PSI_FLUSH :
@@ -154,7 +151,7 @@ int dev_invalidate_iotlb(struct iommu *i 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, pdev->ats.queue_depth, sid, sbit, addr);break ;default :
xen/drivers/passthrough/x86/ats.c +18 -51
115 lines not on this page · raw message
xen/include/asm-x86/amd-iommu.h +2 -0
@@ -104,6 +104,8 @@ struct amd_iommu {uint64_t exclusion_limit;int enabled; + +struct list_head ats_devices; };struct ivrs_mappings {
xen/include/xen/pci.h +5 -0
@@ -78,6 +78,11 @@ struct pci_dev {struct pci_dev_info info;struct arch_pci_dev arch;struct { +struct list_head list; +unsigned int cap_pos; +unsigned int queue_depth; + } ats; +struct {s_time_t time;unsigned int count;#define PT_FAULT_THRESHOLD 10
IOMMU/ATS: use a struct pci_dev * instead of SBDF
From: Quan Xu <[email protected]>
Do away with struct pci_ats_dev; integrate the few bits of information in struct pci_dev (and as a result drop get_ats_device() altogether). Hook ATS devices onto a linked list off of each IOMMU instead of on a global one.
---
v15: See rewritten description. Ditch changes to vtd/intremap.c.
xen/drivers/passthrough/amd/iommu_cmd.c +6 -12
@@ -289,35 +289,29 @@ void amd_iommu_flush_iotlb(u8 devfn, conunsigned long flags;struct amd_iommu *iommu;unsigned int req_id, queueid, maxpend; -struct pci_ats_dev *ats_pdev;if ( !ats_enabled )return ; - ats_pdev =get_ats_device (pdev->seg, pdev->bus, pdev->devfn); -if ( ats_pdev ==NULL ) +if ( !pci_ats_enabled (pdev->seg, pdev->bus, pdev->devfn) )return ; -if ( !pci_ats_enabled (ats_pdev->seg, ats_pdev->bus, ats_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, devfn)); queueid = req_id; - maxpend = ats_pdev->ats_queue_depth &0xff ; + maxpend = pdev->ats.queue_depth &0xff ;/* send INVALIDATE_IOTLB_PAGES command */ spin_lock_irqsave (&iommu->lock, flags);
xen/drivers/passthrough/amd/iommu_detect.c +1 -0
@@ -128,6 +128,7 @@ int __init amd_iommu_detect_one_acpi( }spin_lock_init (&iommu->lock); +INIT_LIST_HEAD (&iommu->ats_devices); iommu->seg = ivhd_block->pci_segment_group; iommu->bdf = ivhd_block->header.device_id;
xen/drivers/passthrough/amd/pci_amd_iommu.c +2 -2
@@ -162,7 +162,7 @@ static void amd_iommu_setup_domain_devic !pci_ats_enabled(iommu->seg, bus, pdev->devfn) ) {if ( devfn == pdev->devfn ) -enable_ats_device (iommu->seg, bus, devfn, iommu); +enable_ats_device (pdev, &iommu->ats_devices);amd_iommu_flush_iotlb (devfn, pdev,INV_IOMMU_ALL_PAGES_ADDRESS ,0 ); }
@@ -356,7 +356,7 @@ void amd_iommu_disable_domain_device(strif ( 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 +2 -13
@@ -17,26 +17,15 @@#include <xen/pci_regs.h> -struct pci_ats_dev { -struct list_head list; -u16 seg; -u8 bus; -u8 devfn; -u16 ats_queue_depth;/* ATS device invalidation queue depth */ -const void *iommu;/* No common IOMMU struct so use void pointer */ -}; -#define ATS_REG_CAP 4#define ATS_REG_CTL 6#define ATS_QUEUE_DEPTH_MASK 0x1f#define ATS_ENABLE (1<<15) -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 (struct pci_dev *pdev,struct list_head *ats_list); +void disable_ats_device (struct pci_dev *pdev);static inline int pci_ats_enabled (int seg,int bus,int devfn) {
xen/drivers/passthrough/vtd/iommu.c +8 -7
@@ -1162,6 +1162,7 @@ int __init iommu_alloc(struct acpi_drhd_return -ENOMEM ; iommu->msi.irq =-1 ;/* No irq assigned yet. */ +INIT_LIST_HEAD (&iommu->ats_devices); iommu->intel =alloc_intel_iommu ();if ( iommu->intel ==NULL )
@@ -1461,8 +1462,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 +1499,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 (pdev, &drhd->iommu->ats_devices);break ;
@@ -1611,8 +1612,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 +1649,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 +1995,7 @@ static int intel_iommu_enable_device(strif ( ret <=0 )return ret; - ret =enable_ats_device (pdev->seg, pdev->bus, pdev->devfn, drhd->iommu); + ret =enable_ats_device (pdev, &drhd->iommu->ats_devices);return ret >=0 ?0 : ret; }
xen/drivers/passthrough/vtd/iommu.h +1 -0
@@ -542,6 +542,7 @@ struct iommu {u64 root_maddr;/* root entry machine address */ struct msi_desc msi;struct intel_iommu *intel; +struct list_head ats_devices;unsigned long *domid_bitmap;/* domain id bitmap */ u16 *domid_map;/* domain id mapping array */ };
xen/drivers/passthrough/vtd/x86/ats.c +6 -9
@@ -71,7 +71,8 @@ int ats_device(const struct pci_dev *pdereturn pos; } -static int device_in_domain (struct iommu *iommu,struct pci_ats_dev *pdev,u16 did) +static int device_in_domain (const struct iommu *iommu, +const struct pci_dev *pdev,u16 did) {struct root_entry *root_entry =NULL ;struct context_entry *ctxt_entry =NULL ;
@@ -108,22 +109,18 @@ out:int dev_invalidate_iotlb (struct iommu *iommu,u16 did,u64 addr,unsigned int size_order,u64 type) { -struct pci_ats_dev *pdev; +const struct pci_dev *pdev;int ret =0 ;if ( !ecap_dev_iotlb (iommu->ecap) )return ret; -list_for_each_entry ( pdev, &ats_devices, list ) +list_for_each_entry ( pdev, &iommu->ats_devices, ats.list ) {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 ) -continue ; -switch ( type ) {case DMA_TLB_DSI_FLUSH :
@@ -134,7 +131,7 @@ int dev_invalidate_iotlb(struct iommu *i/* 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, pdev->ats.queue_depth, sid, sbit, addr);break ;case DMA_TLB_PSI_FLUSH :
@@ -154,7 +151,7 @@ int dev_invalidate_iotlb(struct iommu *i 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, pdev->ats.queue_depth, sid, sbit, addr);break ;default :
xen/drivers/passthrough/x86/ats.c +18 -51
115 lines not on this page · raw message
xen/include/asm-x86/amd-iommu.h +2 -0
@@ -104,6 +104,8 @@ struct amd_iommu {uint64_t exclusion_limit;int enabled; + +struct list_head ats_devices; };struct ivrs_mappings {
xen/include/xen/pci.h +5 -0
@@ -78,6 +78,11 @@ struct pci_dev {struct pci_dev_info info;struct arch_pci_dev arch;struct { +struct list_head list; +unsigned int cap_pos; +unsigned int queue_depth; + } ats; +struct {s_time_t time;unsigned int count;#define PT_FAULT_THRESHOLD 10
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v15 1/3] IOMMU/ATS: use a struct pci_dev * instead of SBDF
Quoted 10 lines
From: Jan Beulich [mailto:[email protected]]
Sent: Friday, July 08, 2016 2:44 PMFrom: Quan Xu <[email protected]>
Do away with struct
pci_ats_dev; integrate the few bits of information in structpci_dev(and as a result dropget_ats_device()altogether). Hook ATS devices onto a linked list off of each IOMMU instead of on a global one.
Quoted 5 lines
Signed-off-by Quan Xu <[email protected]>Signed-off-by Jan Beulich <[email protected]>---
v15: See rewritten description. Ditch changes tovtd/intremap.c.
Thanks. It's a good enhancement:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v15 2/3 IOMMU: add domain crash logic
In reply to Jan BeulichFrom: 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.
xen/drivers/passthrough/iommu.c +28 -2
@@ -318,21 +318,47 @@ int iommu_iotlb_flush(struct domain *d, 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
@@ -1848,6 +1848,17 @@ int iommu_pte_flush(struct domain *d, u6 } } +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; }
IOMMU: add domain crash logic
From: 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.
xen/drivers/passthrough/iommu.c +28 -2
@@ -318,21 +318,47 @@ int iommu_iotlb_flush(struct domain *d, 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
@@ -1848,6 +1848,17 @@ int iommu_pte_flush(struct domain *d, u6 } } +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; }
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v15 3/3 VT-d: fix Device-TLB flush timeout issue
In reply to Jan BeulichFrom: 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).
---
v15: Re-base on heavily changed patch 1. Call disable_ats_device() and
domain_crash() from iommu_dev_iotlb_flush_timeout() and move the function to passthrough/pci.c to fix the ARM build. As a result of calling disable_ats_device() also use list_for_each_entry_safe() in dev_invalidate_iotlb().
xen/drivers/passthrough/pci.c +29 -0
@@ -32,6 +32,7 @@#include <xen/tasklet.h> #include <xsm/xsm.h> #include <asm/msi.h> +#include "ats.h" struct pci_seg {struct list_head alldevs_list;
@@ -1504,6 +1505,34 @@ static int iommu_get_device_group(return i; } +void iommu_dev_iotlb_flush_timeout (struct domain *d,struct pci_dev *pdev) +{ +pcidevs_lock (); + +disable_ats_device (pdev); + +ASSERT (pdev->domain); +if ( d != pdev->domain ) + { +pcidevs_unlock (); +return ; + } + +list_del (&pdev->domain_list); + pdev->domain =NULL ; +_pci_hide_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)); +if ( !is_hardware_domain (d) ) +domain_crash (d); + +pcidevs_unlock (); +} +int iommu_do_pci_domctl (struct xen_domctl *domctl,struct domain *d,XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl)
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 *i 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_dev *pdev, +u16 did,u16 size,u64 addr);unsigned int get_cache_line_size (void );void cacheline_flush (char *);
xen/drivers/passthrough/vtd/qinval.c +42 -14
115 lines not on this page · raw message
xen/drivers/passthrough/vtd/x86/ats.c +4 -7
@@ -109,15 +109,14 @@ out:int dev_invalidate_iotlb (struct iommu *iommu,u16 did,u64 addr,unsigned int size_order,u64 type) { -const struct pci_dev *pdev; +struct pci_dev *pdev, *temp;int ret =0 ;if ( !ecap_dev_iotlb (iommu->ecap) )return ret; -list_for_each_entry ( pdev, &iommu->ats_devices, ats.list ) +list_for_each_entry_safe ( pdev, temp, &iommu->ats_devices, ats.list ) { -u16 sid =PCI_BDF2 (pdev->bus, pdev->devfn);bool_t sbit;int rc =0 ;
@@ -131,8 +130,7 @@ int dev_invalidate_iotlb(struct iommu *i/* 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) )
@@ -151,8 +149,7 @@ int dev_invalidate_iotlb(struct iommu *i 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/iommu.h +2 -0
@@ -207,6 +207,8 @@ int __must_check iommu_iotlb_flush(struc 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.
VT-d: fix Device-TLB flush timeout issue
From: 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).
---
v15: Re-base on heavily changed patch 1. Call disable_ats_device() and
domain_crash() from iommu_dev_iotlb_flush_timeout() and move the function to passthrough/pci.c to fix the ARM build. As a result of calling disable_ats_device() also use list_for_each_entry_safe() in dev_invalidate_iotlb().
xen/drivers/passthrough/pci.c +29 -0
@@ -32,6 +32,7 @@#include <xen/tasklet.h> #include <xsm/xsm.h> #include <asm/msi.h> +#include "ats.h" struct pci_seg {struct list_head alldevs_list;
@@ -1504,6 +1505,34 @@ static int iommu_get_device_group(return i; } +void iommu_dev_iotlb_flush_timeout (struct domain *d,struct pci_dev *pdev) +{ +pcidevs_lock (); + +disable_ats_device (pdev); + +ASSERT (pdev->domain); +if ( d != pdev->domain ) + { +pcidevs_unlock (); +return ; + } + +list_del (&pdev->domain_list); + pdev->domain =NULL ; +_pci_hide_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)); +if ( !is_hardware_domain (d) ) +domain_crash (d); + +pcidevs_unlock (); +} +int iommu_do_pci_domctl (struct xen_domctl *domctl,struct domain *d,XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl)
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 *i 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_dev *pdev, +u16 did,u16 size,u64 addr);unsigned int get_cache_line_size (void );void cacheline_flush (char *);
xen/drivers/passthrough/vtd/qinval.c +42 -14
115 lines not on this page · raw message
xen/drivers/passthrough/vtd/x86/ats.c +4 -7
@@ -109,15 +109,14 @@ out:int dev_invalidate_iotlb (struct iommu *iommu,u16 did,u64 addr,unsigned int size_order,u64 type) { -const struct pci_dev *pdev; +struct pci_dev *pdev, *temp;int ret =0 ;if ( !ecap_dev_iotlb (iommu->ecap) )return ret; -list_for_each_entry ( pdev, &iommu->ats_devices, ats.list ) +list_for_each_entry_safe ( pdev, temp, &iommu->ats_devices, ats.list ) { -u16 sid =PCI_BDF2 (pdev->bus, pdev->devfn);bool_t sbit;int rc =0 ;
@@ -131,8 +130,7 @@ int dev_invalidate_iotlb(struct iommu *i/* 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) )
@@ -151,8 +149,7 @@ int dev_invalidate_iotlb(struct iommu *i 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/iommu.h +2 -0
@@ -207,6 +207,8 @@ int __must_check iommu_iotlb_flush(struc 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-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v15 3/3] VT-d: fix Device-TLB flush timeout issue
Quoted 9 lines
From: Jan Beulich [mailto:[email protected]]
Sent: Friday, July 08, 2016 2:46 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).
Quoted 9 lines
Signed-off-by Quan Xu <[email protected]>Signed-off-by Jan Beulich <[email protected]>---
v15: Re-base on heavily changed patch 1. Calldisable_ats_device()and
domain_crash()fromiommu_dev_iotlb_flush_timeout()and move the function topassthrough/pci.cto fix the ARM build. As a result of callingdisable_ats_device()also uselist_for_each_entry_safe()indev_invalidate_iotlb().
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.07.16 at 08:39, <[email protected]> wrote:
From: Quan Xu <[email protected]>
these 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
Quoted 8 lines
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).Quan Xu (3):
IOMMU/ATS: use a structpci_dev* instead of SBDF
IOMMU: add domain crash logic
VT-d: fix Device-TLB flush timeout issue
I should probably have said somewhere that obviously I didn't test this for the actual ATS case, as I don't have access to any suitable device. Therefore, alongside the necessary ack-s, it would be nice if we could also get a Tested-by from someone who does have an ATS device.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Xu, Quan
Tested-byQuoted 18 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.07.16 at 08:39, <[email protected]> wrote:
From: Quan Xu <[email protected]>
these 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 layerQuoted 8 lines
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).Quan Xu (3):
IOMMU/ATS: use a structpci_dev* instead of SBDF
IOMMU: add domain crash logic
VT-d: fix Device-TLB flush timeout issue
Quoted 5 lines
I should probably have said somewhere that obviously I didn't test this for the actual ATS case, as I don't have access to any suitable device. Therefore, alongside the necessary ack-s, it would be nice if we could also get a Tested-by from someone who does have an ATS device.
(today I just come back to return my laptop and while test it) thanks for your work and education :):)...
Quan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 7 lines · Jan Beulich
From: Quan Xu <[email protected]>
these 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
Quoted 8 lines
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).Quan Xu (3):
IOMMU/ATS: use a structpci_dev* instead of SBDF
IOMMU: add domain crash logic
VT-d: fix Device-TLB flush timeout issue
Committed, thanks.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel