IOMMU, vtd and iotlb flush rework (v2)
In one of my previous email I detailed a bug I was seeing when passing through a Intel GPU on a guest that has more that 4G or RAM.
Allen suggested that I go for the Plan B but after a discussion with Tim we agreed that Plan B was way to disruptive in term of code change.
This patch series implements Plan A.
http://xen.1045712.n5.nabble.com/VTD-Intel-iommu-IOTLB-flush-really-slow-td4952866.html
Changes between v1 and v2:
- Move size in struct xen_add_to_physmap in padding between .domid and .space.
- Store iommu_dont_flush per cpu
- Change the code in hvmloader to relocate by batch of 64K, .size is now 16 bits.
Jean Guyader (6):
vtd: Refactor iotlb flush code
iommu: Introduce iommu_flush and iommu_flush_all.
add_to_physmap: Move the code for XENMEM_add_to_physmap.
mm: New XENMEM, XENMEM_add_to_physmap_gmfn_range
hvmloader: Change memory relocation loop when overlap with PCI hole. Introduce per cpu flag (iommu_dont_flush_iotlb) to avoid unnecessary iotlb flush
tools/firmware/hvmloader/pci.c | 20 +++- xen/arch/x86/mm.c | 203 +++++++++++++++++++++-------------- xen/drivers/passthrough/iommu.c | 25 +++++ xen/drivers/passthrough/vtd/iommu.c | 100 ++++++++++-------- xen/include/public/memory.h | 5 +- xen/include/xen/iommu.h | 7 ++ 6 files changed, 230 insertions(+), 130 deletions(-)
Jean
PATCH 1/6 vtd: Refactor iotlb flush code
Factorize the iotlb flush code from map_page and unmap_page into it's own function.
--- xen/drivers/passthrough/vtd/iommu.c | 86 +++++++++++++++++----------------- 1 files changed, 43 insertions(+), 43 deletions(-)
xen/drivers/passthrough/vtd/iommu.c +43 -43
@@ -578,16 +578,53 @@ static void iommu_flush_all(void) } } +static void __intel_iommu_iotlb_flush (struct domain *d,unsigned long gfn, +int dma_old_pte_present,unsigned int page_count) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); +struct acpi_drhd_unit *drhd; +struct iommu *iommu; +int flush_dev_iotlb; +int iommu_domid; + +/* +* No need pcideves_lock here because we have flush +* when assign/deassign device +*/ +for_each_drhd_unit ( drhd ) + { + iommu = drhd->iommu; + +if ( !test_bit (iommu->index, &hd->iommu_bitmap) ) +continue ; + + flush_dev_iotlb =find_ats_dev_drhd (iommu) ?1 :0 ; + iommu_domid=domain_iommu_domid (d, iommu); +if ( iommu_domid ==-1 ) +continue ; + +if ( page_count >1 || gfn ==-1 ) + { +if (iommu_flush_iotlb_dsi (iommu, iommu_domid, +0 , flush_dev_iotlb) ) +iommu_flush_write_buffer (iommu); + } +else + { +if (iommu_flush_iotlb_psi (iommu, iommu_domid, + (paddr_t )gfn <<PAGE_SHIFT_4K ,0 , + !dma_old_pte_present, flush_dev_iotlb) ) +iommu_flush_write_buffer (iommu); + } + } +} +/* clear one page's page table */ static void dma_pte_clear_one (struct domain *domain,u64 addr) {struct hvm_iommu *hd =domain_hvm_iommu (domain); -struct acpi_drhd_unit *drhd; -struct iommu *iommu;struct dma_pte *page =NULL , *pte =NULL ;u64 pg_maddr; -int flush_dev_iotlb; -int iommu_domid;struct mapped_rmrr *mrmrr;spin_lock (&hd->mapping_lock);
@@ -613,21 +650,7 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr)spin_unlock (&hd->mapping_lock);iommu_flush_cache_entry (pte,sizeof (struct dma_pte )); -/* No need pcidevs_lock here since do that on assign/deassign device*/ -for_each_drhd_unit ( drhd ) - { - iommu = drhd->iommu; -if (test_bit (iommu->index, &hd->iommu_bitmap) ) - { - flush_dev_iotlb =find_ats_dev_drhd (iommu) ?1 :0 ; - iommu_domid=domain_iommu_domid (domain, iommu); -if ( iommu_domid ==-1 ) -continue ; -if (iommu_flush_iotlb_psi (iommu, iommu_domid, addr, -0 ,0 , flush_dev_iotlb) ) -iommu_flush_write_buffer (iommu); - } - } +__intel_iommu_iotlb_flush (domain, addr >>PAGE_SHIFT_4K ,0 ,1 );unmap_vtd_domain_page (page);
@@ -1677,12 +1700,8 @@ static int intel_iommu_map_page( unsigned int flags) {struct hvm_iommu *hd =domain_hvm_iommu (d); -struct acpi_drhd_unit *drhd; -struct iommu *iommu;struct dma_pte *page =NULL , *pte =NULL , old, new = {0 };u64 pg_maddr; -int flush_dev_iotlb; -int iommu_domid;/* Do nothing if VT-d shares EPT page table */ if (iommu_use_hap_pt (d) )
@@ -1724,26 +1743,7 @@ static int intel_iommu_map_page(spin_unlock (&hd->mapping_lock);unmap_vtd_domain_page (page); -/* -* No need pcideves_lock here because we have flush -* when assign/deassign device -*/ -for_each_drhd_unit ( drhd ) - { - iommu = drhd->iommu; - -if ( !test_bit (iommu->index, &hd->iommu_bitmap) ) -continue ; - - flush_dev_iotlb =find_ats_dev_drhd (iommu) ?1 :0 ; - iommu_domid=domain_iommu_domid (d, iommu); -if ( iommu_domid ==-1 ) -continue ; -if (iommu_flush_iotlb_psi (iommu, iommu_domid, - (paddr_t )gfn <<PAGE_SHIFT_4K ,0 , - !dma_pte_present (old), flush_dev_iotlb) ) -iommu_flush_write_buffer (iommu); - } +__intel_iommu_iotlb_flush (d, gfn,dma_pte_present (old),1 );return 0 ; }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 2/6 iommu: Introduce iommu_flush and iommu_flush_all.
--- xen/drivers/passthrough/iommu.c | 20 ++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 12 ++++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 37 insertions(+), 0 deletions(-)
xen/drivers/passthrough/iommu.c +20 -0
@@ -301,6 +301,26 @@ int iommu_unmap_page(struct domain *d, unsigned long gfn)return hd->platform_ops->unmap_page (d, gfn); } +void iommu_iotlb_flush (struct domain *d,unsigned long gfn,unsigned int page_count) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); + +if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush ) +return ; + + hd->platform_ops->iotlb_flush (d, gfn, page_count); +} + +void iommu_iotlb_flush_all (struct domain *d) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); + +if ( !iommu_enabled || !hd->platform_ops ) +return ; + + hd->platform_ops->iotlb_flush_all (d); +} +/* caller should hold the pcidevs_lock */ int deassign_device (struct domain *d,u16 seg,u8 bus,u8 devfn) {
xen/drivers/passthrough/vtd/iommu.c +12 -0
@@ -619,6 +619,16 @@ static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, } } +static void intel_iommu_iotlb_flush (struct domain *d,unsigned long gfn,unsigned int page_count) +{ +__intel_iommu_iotlb_flush (d, gfn,1 , page_count); +} + +static void intel_iommu_iotlb_flush_all (struct domain *d) +{ +__intel_iommu_iotlb_flush (d,0 ,0 ,0 ); +} +/* clear one page's page table */ static void dma_pte_clear_one (struct domain *domain,u64 addr) {
@@ -2329,6 +2339,8 @@ const struct iommu_ops intel_iommu_ops = { .resume = vtd_resume, .share_p2m = iommu_set_pgd, .crash_shutdown = vtd_crash_shutdown, + .iotlb_flush = intel_iommu_iotlb_flush, + .iotlb_flush_all = intel_iommu_iotlb_flush_all, };/*
xen/include/xen/iommu.h +5 -0
@@ -139,6 +139,8 @@ struct iommu_ops {void (*resume)(void );void (*share_p2m)(struct domain *d);void (*crash_shutdown)(void ); +void (*iotlb_flush)(struct domain *d,unsigned long gfn,unsigned int page_count); +void (*iotlb_flush_all)(struct domain *d); };void iommu_update_ire_from_apic (unsigned int apic,unsigned int reg,unsigned int value);
@@ -155,4 +157,7 @@ void iommu_share_p2m_table(struct domain *d);int iommu_do_domctl (struct xen_domctl *,XEN_GUEST_HANDLE (xen_domctl_t )); +void iommu_iotlb_flush (struct domain *d,unsigned long gfn,unsigned int page_count); +void iommu_iotlb_flush_all (struct domain *d); +#endif /* _IOMMU_H_ */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 3/6 add_to_physmap: Move the code for XENMEM_add_to_physmap.
Move the code for the XENMEM_add_to_physmap case into it's own function (xenmem_add_to_physmap).
--- xen/arch/x86/mm.c | 188 ++++++++++++++++++++++++++++------------------------- 1 files changed, 99 insertions(+), 89 deletions(-)
xen/arch/x86/mm.c +99 -89
@@ -4592,119 +4592,129 @@ static int handle_iomem_range(unsigned long s, unsigned long e, void *p)return 0 ; } -long arch_memory_op (int op,XEN_GUEST_HANDLE (void ) arg) +static int xenmem_add_to_physmap (struct domain *d,struct xen_add_to_physmap xatp) {struct page_info *page =NULL ; +unsigned long prev_mfn, mfn =0 , gpfn;int rc; -switch ( op ) - { -case XENMEM_add_to_physmap: +switch ( xatp.space ) { -struct xen_add_to_physmap xatp; -unsigned long prev_mfn, mfn =0 , gpfn; -struct domain *d; - -if (copy_from_guest (&xatp, arg,1 ) ) -return -EFAULT ; +case XENMAPSPACE_shared_info: +if ( xatp.idx ==0 ) + mfn =virt_to_mfn (d->shared_info); +break ; +case XENMAPSPACE_grant_table: +spin_lock (&d->grant_table->lock); - rc =rcu_lock_target_domain_by_id (xatp.domid, &d); -if ( rc !=0 ) -return rc; +if ( d->grant_table->gt_version ==0 ) + d->grant_table->gt_version =1 ; -if (xsm_add_to_physmap (current->domain, d) ) +if ( d->grant_table->gt_version ==2 && + (xatp.idx & XENMAPIDX_grant_table_status) ) { -rcu_unlock_domain (d); -return -EPERM ; + xatp.idx &= ~XENMAPIDX_grant_table_status; +if ( xatp.idx <nr_status_frames (d->grant_table) ) + mfn =virt_to_mfn (d->grant_table->status[xatp.idx]); + } +else + { +if ( (xatp.idx >=nr_grant_frames (d->grant_table)) && + (xatp.idx < max_nr_grant_frames) ) +gnttab_grow_table (d, xatp.idx +1 ); + +if ( xatp.idx <nr_grant_frames (d->grant_table) ) + mfn =virt_to_mfn (d->grant_table->shared_raw[xatp.idx]); } -switch ( xatp.space ) +spin_unlock (&d->grant_table->lock); +break ; +case XENMAPSPACE_gmfn: + { +p2m_type_t p2mt; + + xatp.idx =mfn_x (gfn_to_mfn_unshare (d, xatp.idx, &p2mt)); +/* If the page is still shared, exit early */ +if (p2m_is_shared (p2mt) ) { -case XENMAPSPACE_shared_info: -if ( xatp.idx ==0 ) - mfn =virt_to_mfn (d->shared_info); +rcu_unlock_domain (d); +return -ENOMEM ; + } +if ( !get_page_from_pagenr (xatp.idx, d) )break ; -case XENMAPSPACE_grant_table: -spin_lock (&d->grant_table->lock); + mfn = xatp.idx; + page =mfn_to_page (mfn); +break ; + } +default : +break ; + } -if ( d->grant_table->gt_version ==0 ) - d->grant_table->gt_version =1 ; +if ( !paging_mode_translate (d) || (mfn ==0 ) ) + { +if ( page ) +put_page (page); +rcu_unlock_domain (d); +return -EINVAL ; + } -if ( d->grant_table->gt_version ==2 && - (xatp.idx & XENMAPIDX_grant_table_status) ) - { - xatp.idx &= ~XENMAPIDX_grant_table_status; -if ( xatp.idx <nr_status_frames (d->grant_table) ) - mfn =virt_to_mfn (d->grant_table->status[xatp.idx]); - } -else - { -if ( (xatp.idx >=nr_grant_frames (d->grant_table)) && - (xatp.idx < max_nr_grant_frames) ) -gnttab_grow_table (d, xatp.idx +1 ); +domain_lock (d); -if ( xatp.idx <nr_grant_frames (d->grant_table) ) - mfn =virt_to_mfn (d->grant_table->shared_raw[xatp.idx]); - } +if ( page ) +put_page (page); -spin_unlock (&d->grant_table->lock); -break ; -case XENMAPSPACE_gmfn: - { -p2m_type_t p2mt; +/* Remove previously mapped page if it was present. */ + prev_mfn =gmfn_to_mfn (d, xatp.gpfn); +if (mfn_valid (prev_mfn) ) + { +if (is_xen_heap_mfn (prev_mfn) ) +/* Xen heap frames are simply unhooked from this phys slot. */ +guest_physmap_remove_page (d, xatp.gpfn, prev_mfn,0 ); +else +/* Normal domain memory is freed, to avoid leaking memory. */ +guest_remove_page (d, xatp.gpfn); + } - xatp.idx =mfn_x (gfn_to_mfn_unshare (d, xatp.idx, &p2mt)); -/* If the page is still shared, exit early */ -if (p2m_is_shared (p2mt) ) - { -rcu_unlock_domain (d); -return -ENOMEM ; - } -if ( !get_page_from_pagenr (xatp.idx, d) ) -break ; - mfn = xatp.idx; - page =mfn_to_page (mfn); -break ; - } -default : -break ; - } +/* Unmap from old location, if any. */ + gpfn =get_gpfn_from_mfn (mfn); +ASSERT ( gpfn !=SHARED_M2P_ENTRY ); +if ( gpfn !=INVALID_M2P_ENTRY ) +guest_physmap_remove_page (d, gpfn, mfn,0 ); -if ( !paging_mode_translate (d) || (mfn ==0 ) ) - { -if ( page ) -put_page (page); -rcu_unlock_domain (d); -return -EINVAL ; - } +/* Map at new location. */ + rc =guest_physmap_add_page (d, xatp.gpfn, mfn,0 ); -domain_lock (d); +domain_unlock (d); -if ( page ) -put_page (page); +return rc; +} -/* Remove previously mapped page if it was present. */ - prev_mfn =gmfn_to_mfn (d, xatp.gpfn); -if (mfn_valid (prev_mfn) ) - { -if (is_xen_heap_mfn (prev_mfn) ) -/* Xen heap frames are simply unhooked from this phys slot. */ -guest_physmap_remove_page (d, xatp.gpfn, prev_mfn,0 ); -else -/* Normal domain memory is freed, to avoid leaking memory. */ -guest_remove_page (d, xatp.gpfn); - } -/* Unmap from old location, if any. */ - gpfn =get_gpfn_from_mfn (mfn); -ASSERT ( gpfn !=SHARED_M2P_ENTRY ); -if ( gpfn !=INVALID_M2P_ENTRY ) -guest_physmap_remove_page (d, gpfn, mfn,0 ); +long arch_memory_op (int op,XEN_GUEST_HANDLE (void ) arg) +{ +int rc; + +switch ( op ) + { +case XENMEM_add_to_physmap: + { +struct xen_add_to_physmap xatp; +struct domain *d; -/* Map at new location. */ - rc =guest_physmap_add_page (d, xatp.gpfn, mfn,0 ); +if (copy_from_guest (&xatp, arg,1 ) ) +return -EFAULT ; + + rc =rcu_lock_target_domain_by_id (xatp.domid, &d); +if ( rc !=0 ) +return rc; + +if (xsm_add_to_physmap (current->domain, d) ) + { +rcu_unlock_domain (d); +return -EPERM ; + } -domain_unlock (d); +xenmem_add_to_physmap (d, xatp);rcu_unlock_domain (d);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 4/6 mm: New XENMEM, XENMEM_add_to_physmap_gmfn_range
XENMEM_add_to_physmap_gmfn_range is like XENMEM_add_to_physmap on the gmfn space but the number of pages on which xen will iterate.
Use the 16 bits padding between .domid and .space in struct xen_add_to_physmap to keep compatibility with older versions.
--- xen/arch/x86/mm.c | 22 +++++++++++++++++++++- xen/include/public/memory.h | 5 ++++- 2 files changed, 25 insertions(+), 2 deletions(-)
xen/arch/x86/mm.c +21 -1
@@ -4714,9 +4714,29 @@ long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg)return -EPERM ; } -xenmem_add_to_physmap (d, xatp); +if ( xatp.space != XENMAPSPACE_gmfn_range ) + xatp.size =1 ; + +for ( ; xatp.size >0 ; xatp.size-- ) + { +if (hypercall_preempt_check () ) + { + rc = -EAGAIN ; +break ; + } +xenmem_add_to_physmap (d, xatp); + xatp.idx++; + xatp.gpfn++; + }rcu_unlock_domain (d); +if ( rc == -EAGAIN ) + { +if (copy_to_guest (arg, &xatp,1 ) ) +return -EFAULT ; + rc =hypercall_create_continuation ( + __HYPERVISOR_memory_op,"ih" , op, arg); + }return rc; }
xen/include/public/memory.h +4 -1
@@ -208,10 +208,14 @@ struct xen_add_to_physmap {/* Which domain to change the mapping for. */ domid_t domid; +/* Number of pages to go through for gmfn_range */ +uint16_t size; +/* Source mapping space. */ #define XENMAPSPACE_shared_info 0/* shared info page */ #define XENMAPSPACE_grant_table 1/* grant table page */ #define XENMAPSPACE_gmfn 2/* GMFN */ +#define XENMAPSPACE_gmfn_range 3/* GMFN_range */ unsigned int space;#define XENMAPIDX_grant_table_status 0x80000000
@@ -290,7 +294,6 @@ typedef struct xen_pod_target xen_pod_target_t;* The call never fails. */ #define XENMEM_get_sharing_freed_pages 18 -#endif /* __XEN_PUBLIC_MEMORY_H__ */ /*
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 5/6 hvmloader: Change memory relocation loop when overlap with PCI hole.
Change the way we relocate the memory page if they overlap with pci hole. Use new map space (XENMAPSPACE_gmfn_range) to move the loop into xen.
This code usually get triggered when a device is pass through to a guest and the PCI hole has to be extended to have enough room to map the device BARs. The PCI hole will starts lower and it might overlap with some RAM that has been alocated for the guest. That usually happen if the guest has more than 4G of RAM. We have to relocate those pages in high mem otherwise they won't be accessible.
--- tools/firmware/hvmloader/pci.c | 20 ++++++++++++++------ 1 files changed, 14 insertions(+), 6 deletions(-)
tools/firmware/hvmloader/pci.c +14 -6
@@ -50,6 +50,7 @@ void pci_setup(void)uint32_t devfn, bar_reg, bar_sz; } *bars = (struct bars *)scratch_start;unsigned int i, nr_bars =0 ; +unsigned long pci_mem_start_pg;/* Program PCI-ISA bridge with appropriate link routes. */ isa_irq =0 ;
@@ -185,17 +186,24 @@ void pci_setup(void) ((pci_mem_start << 1) != 0) ) pci_mem_start <<=1 ; -while ( (pci_mem_start >>PAGE_SHIFT ) < hvm_info->low_mem_pgend ) +/* Relocate RAM that overlaps (in 64K chunks) */ + pci_mem_start_pg = (pci_mem_start >>PAGE_SHIFT ); +while (pci_mem_start_pg < hvm_info->low_mem_pgend) {struct xen_add_to_physmap xatp; -if ( hvm_info->high_mem_pgend ==0 ) - hvm_info->high_mem_pgend =1ull << (32 -PAGE_SHIFT ); +unsigned int size = hvm_info->low_mem_pgend - pci_mem_start_pg; xatp.domid =DOMID_SELF ; - xatp.space = XENMAPSPACE_gmfn; - xatp.idx = --hvm_info->low_mem_pgend; - xatp.gpfn = hvm_info->high_mem_pgend++; + xatp.space = XENMAPSPACE_gmfn_range; + xatp.idx = pci_mem_start_pg; + xatp.gpfn = hvm_info->high_mem_pgend; + size = size > ((1 <<16 ) -1 ) ? ((1 <<16 ) -1 ) : size; + xatp.size = size; +if (hypercall_memory_op (XENMEM_add_to_physmap, &xatp) !=0 )BUG (); + pci_mem_start_pg += size; + hvm_info->high_mem_pgend += size; + hvm_info->low_mem_pgend = pci_mem_start_pg; } mem_resource.base = pci_mem_start;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 6/6 Introduce per cpu flag (iommu_dont_flush_iotlb) to avoid unnecessary iotlb flush
Add cpu flag that will be checked by the iommu low level code to skip iotlb flushes. iommu_iotlb_flush shall be called explicitly.
--- xen/arch/x86/mm.c | 15 ++++++++++++++- xen/drivers/passthrough/iommu.c | 5 +++++ xen/drivers/passthrough/vtd/iommu.c | 6 ++++-- xen/include/xen/iommu.h | 2 ++ 4 files changed, 25 insertions(+), 3 deletions(-)
xen/arch/x86/mm.c +14 -1
@@ -4698,7 +4698,7 @@ long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg) {case XENMEM_add_to_physmap: { -struct xen_add_to_physmap xatp; +struct xen_add_to_physmap xatp, start_xatp;struct domain *d;if (copy_from_guest (&xatp, arg,1 ) )
@@ -4716,7 +4716,13 @@ long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg)if ( xatp.space != XENMAPSPACE_gmfn_range ) xatp.size =1 ; +else + { +if (need_iommu (d) ) +this_cpu (iommu_dont_flush_iotlb) =1 ; + } + start_xatp = xatp;for ( ; xatp.size >0 ; xatp.size-- ) {if (hypercall_preempt_check () )
@@ -4729,6 +4735,13 @@ long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg) xatp.gpfn++; } +if ( xatp.space == XENMAPSPACE_gmfn_range &&need_iommu (d) ) + { +this_cpu (iommu_dont_flush_iotlb) =0 ; +iommu_iotlb_flush (d, start_xatp.idx, start_xatp.size - xatp.size); +iommu_iotlb_flush (d, start_xatp.gpfn, start_xatp.size - xatp.size); + } +rcu_unlock_domain (d);if ( rc == -EAGAIN ) {
xen/drivers/passthrough/iommu.c +5 -0
@@ -52,6 +52,8 @@ bool_t __read_mostly iommu_hap_pt_share = 1;bool_t __read_mostly iommu_debug;bool_t __read_mostly amd_iommu_perdev_intremap; +DEFINE_PER_CPU (bool_t, iommu_dont_flush_iotlb); +static void __init parse_iommu_param (char *s) {char *ss;
@@ -227,6 +229,7 @@ static int iommu_populate_page_table(struct domain *d)spin_lock (&d->page_alloc_lock); +this_cpu (iommu_dont_flush_iotlb) =1 ; page_list_for_each ( page, &d->page_list ) { if ( is_hvm_domain(d) ||
@@ -244,6 +247,8 @@ static int iommu_populate_page_table(struct domain *d) } } } +this_cpu (iommu_dont_flush_iotlb) =0 ; +iommu_iotlb_flush_all (d);spin_unlock (&d->page_alloc_lock);return 0 ; }
xen/drivers/passthrough/vtd/iommu.c +4 -2
@@ -660,7 +660,8 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr)spin_unlock (&hd->mapping_lock);iommu_flush_cache_entry (pte,sizeof (struct dma_pte )); -__intel_iommu_iotlb_flush (domain, addr >>PAGE_SHIFT_4K ,0 ,1 ); +if ( !this_cpu (iommu_dont_flush_iotlb) ) +__intel_iommu_iotlb_flush (domain, addr >>PAGE_SHIFT_4K ,0 ,1 );unmap_vtd_domain_page (page);
@@ -1753,7 +1754,8 @@ static int intel_iommu_map_page(spin_unlock (&hd->mapping_lock);unmap_vtd_domain_page (page); -__intel_iommu_iotlb_flush (d, gfn,dma_pte_present (old),1 ); +if ( !this_cpu (iommu_dont_flush_iotlb) ) +__intel_iommu_iotlb_flush (d, gfn,dma_pte_present (old),1 );return 0 ; }
xen/include/xen/iommu.h +2 -0
@@ -160,4 +160,6 @@ int iommu_do_domctl(struct xen_domctl *, XEN_GUEST_HANDLE(xen_domctl_t));void iommu_iotlb_flush (struct domain *d,unsigned long gfn,unsigned int page_count);void iommu_iotlb_flush_all (struct domain *d); +DECLARE_PER_CPU (bool_t, iommu_dont_flush_iotlb); +#endif /* _IOMMU_H_ */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 4/6] mm: New XENMEM, XENMEM_add_to_physmap_gmfn_range
In reply to Jean GuyaderQuoted 9 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
XENMEM_add_to_physmap_gmfn_rangeis likeXENMEM_add_to_physmapon the gmfn space but the number of pages on which xen will iterate.Use the 16 bits padding between .domid and .space in struct
xen_add_to_physmap
to keep compatibility with older versions.
Quoted 5 lines
Signed-off-by Jean Guyader <[email protected]>--- xen/arch/x86/mm.c | 22 +++++++++++++++++++++- xen/include/public/memory.h | 5 ++++- 2 files changed, 25 insertions(+), 2 deletions(-)
Please remove the stray last hunk of the patch (the newline there should stay).
Jan
Re: [PATCH 4/6] mm: New XENMEM, XENMEM_add_to_physmap_gmfn_range
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
XENMEM_add_to_physmap_gmfn_rangeis likeXENMEM_add_to_physmapon the gmfn space but the number of pages on which xen will iterate.Use the 16 bits padding between .domid and .space in struct
xen_add_to_physmap
to keep compatibility with older versions.
Quoted 9 lines
Quoted 5 lines
Signed-off-by Jean Guyader <[email protected]>--- xen/arch/x86/mm.c | 22 +++++++++++++++++++++- xen/include/public/memory.h | 5 ++++- 2 files changed, 25 insertions(+), 2 deletions(-)Please remove the stray last hunk of the patch (the newline there should stay).
Yes, it shouldn't be there. I've updated the patch.
Thanks,
Jean
Re: [PATCH 2/6] iommu: Introduce iommu_flush and iommu_flush_all.
In reply to Jean GuyaderQuoted 8 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Signed-off-by Jean Guyader <[email protected]>--- xen/drivers/passthrough/iommu.c | 20 ++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 12 ++++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 37 insertions(+), 0 deletions(-)
In iommu_iotlb_flush() you check whether the to-be-called function pointer is NULL, whereas in iommu_iotlb_flush_all() you don't. I actually think the second behavior is the correct one, but that implies that you need to also implement respective AMD IOMMU functions.
Jan
Re: [PATCH 2/6] iommu: Introduce iommu_flush and iommu_flush_all.
Quoted 9 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Signed-off-by Jean Guyader <[email protected]>--- xen/drivers/passthrough/iommu.c | 20 ++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 12 ++++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 37 insertions(+), 0 deletions(-)
Quoted 6 lines
In
iommu_iotlb_flush()you check whether the to-be-called function pointer is NULL, whereas iniommu_iotlb_flush_all()you don't. I actually think the second behavior is the correct one, but that implies that you need to also implement respective AMD IOMMU functions.
Yes, It's an error on my part. I've updated the patch to check for the present of iotlb_flush_all before I call it now.
Thanks,
Jean
Re: [PATCH 2/6] iommu: Introduce iommu_flush and iommu_flush_all.
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Quoted 9 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Signed-off-by Jean Guyader <[email protected]>--- xen/drivers/passthrough/iommu.c | 20 ++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 12 ++++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 37 insertions(+), 0 deletions(-)Quoted 6 lines
In
iommu_iotlb_flush()you check whether the to-be-called function pointer is NULL, whereas iniommu_iotlb_flush_all()you don't. I actually think the second behavior is the correct one, but that implies that you need to also implement respective AMD IOMMU functions.
Quoted 2 lines
Yes, It's an error on my part. I've updated the patch to check for the present of
iotlb_flush_allbefore I call it now.
But as said, I don't think this is the right solution: How can it be correct on non-Intel hardware to have these functions simply do nothing?
Jan
Re: [PATCH 2/6] iommu: Introduce iommu_flush and iommu_flush_all.
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Quoted 15 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Signed-off-by Jean Guyader <[email protected]>--- xen/drivers/passthrough/iommu.c | 20 ++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 12 ++++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 37 insertions(+), 0 deletions(-)In
iommu_iotlb_flush()you check whether the to-be-called function pointer is NULL, whereas iniommu_iotlb_flush_all()you don't. I actually think the second behavior is the correct one, but that implies that you need to also implement respective AMD IOMMU functions.
Quoted 7 lines
Quoted 2 lines
Yes, It's an error on my part. I've updated the patch to check for the present of
iotlb_flush_allbefore I call it now.But as said, I don't think this is the right solution: How can it be correct on non-Intel hardware to have these functions simply do nothing?
These functions are only here to counter balance the dont_flush_iotlb_flag. If they don't acknowlage this flag doing nothing is the right thing to do.
That said I can probably implement a naive version for the AMD iommu that will use amd_iommu_flush_pages once or in a loop.
Obviously I will remove the check for the non existing callback if I do that as it become mandatory.
Jean
Re: [PATCH 2/6] iommu: Introduce iommu_flush and iommu_flush_all.
Quoted 28 lines · On Tuesday 08 November 2011 11:25:15 Jean Guyader wrote:
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 2 lines
Quoted 2 lines
On 07.11.11 at 18:06, Jean Guyader <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
On 07.11.11 at 16:16, Jean Guyader <[email protected]> wrote:
Signed-off-by Jean Guyader <[email protected]>--- xen/drivers/passthrough/iommu.c | 20 ++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 12 ++++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 37 insertions(+), 0 deletions(-)In
iommu_iotlb_flush()you check whether the to-be-called function pointer is NULL, whereas iniommu_iotlb_flush_all()you don't. I actually think the second behavior is the correct one, but that implies that you need to also implement respective AMD IOMMU functions.Quoted 6 lines
Quoted 2 lines
Yes, It's an error on my part. I've updated the patch to check for the present of
iotlb_flush_allbefore I call it now.But as said, I don't think this is the right solution: How can it be correct on non-Intel hardware to have these functions simply do nothing?
Quoted 5 lines
These functions are only here to counter balance the
dont_flush_iotlb_flag. If they don't acknowlage this flag doing nothing is the right thing to do.That said I can probably implement a naive version for the AMD iommu that will use
amd_iommu_flush_pagesonce or in a loop.
There are some pending patches that enable ats / iotlb flush for amd iommu. Then, you might want to use functions: amd_iommu_flush_iotlb and amd_iommu_flush_all_iotlbs for this.
Thanks,
Wei
Quoted 9 lines
Obviously I will remove the check for the non existing callback if I do that as it become mandatory.
Jean
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 2/6] iommu: Introduce iommu_flush and iommu_flush_all.
Quoted 32 lines · On 08/11 10:39, Wei Wang2 wrote:
Quoted 31 lines · On Tuesday 08 November 2011 11:25:15 Jean Guyader wrote:
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 2 lines
Quoted 2 lines
On 07.11.11 at 18:06, Jean Guyader <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
On 07.11.11 at 16:16, Jean Guyader <[email protected]> wrote:
Signed-off-by Jean Guyader <[email protected]>--- xen/drivers/passthrough/iommu.c | 20 ++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 12 ++++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 37 insertions(+), 0 deletions(-)In
iommu_iotlb_flush()you check whether the to-be-called function pointer is NULL, whereas iniommu_iotlb_flush_all()you don't. I actually think the second behavior is the correct one, but that implies that you need to also implement respective AMD IOMMU functions.Quoted 6 lines
Quoted 2 lines
Yes, It's an error on my part. I've updated the patch to check for the present of
iotlb_flush_allbefore I call it now.But as said, I don't think this is the right solution: How can it be correct on non-Intel hardware to have these functions simply do nothing?
These functions are only here to counter balance the
dont_flush_iotlb_flag. If they don't acknowlage this flag doing nothing is the right thing to do.
Quoted 9 lines
Quoted 2 lines
That said I can probably implement a naive version for the AMD iommu that will use
amd_iommu_flush_pagesonce or in a loop.There are some pending patches that enable ats / iotlb flush for amd iommu. Then, you might want to use functions:
amd_iommu_flush_iotlbandamd_iommu_flush_all_iotlbsfor this.
Thanks,
Wei
Ok, I'll do that in the next version.
Thanks,
Jean
Re: [PATCH 2/6] iommu: Introduce iommu_flush and iommu_flush_all.
In reply to Jean GuyaderQuoted 23 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Quoted 21 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Quoted 9 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Jean Guyader
Signed-off-by Jean Guyader <[email protected]>--- xen/drivers/passthrough/iommu.c | 20 ++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 12 ++++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 37 insertions(+), 0 deletions(-)Quoted 6 lines
In
iommu_iotlb_flush()you check whether the to-be-called function pointer is NULL, whereas iniommu_iotlb_flush_all()you don't. I actually think the second behavior is the correct one, but that implies that you need to also implement respective AMD IOMMU functions.Yes, It's an error on my part. I've updated the patch to check for the present of
iotlb_flush_allbefore I call it now.
Quoted 7 lines
Quoted 4 lines
But as said, I don't think this is the right solution: How can it be correct on non-Intel hardware to have these functions simply do nothing?
These functions are only here to counter balance the
dont_flush_iotlb_flag. If they don't acknowlage this flag doing nothing is the right thing to do.
Ah, okay, I overlooked this aspect. Might be worth a comment in the header file.
Jan
Quoted 7 lines
That said I can probably implement a naive version for the AMD iommu that will use
amd_iommu_flush_pagesonce or in a loop.Obviously I will remove the check for the non existing callback if I do that as it become mandatory.
Jean