Convert the intel iommu driver to the dma-iommu api
Subsystems (4)
Lu Baolu
maintainerv4 cover Convert the intel iommu driver to the dma-iommu api
Hi,
The previous post of this series could be found here.
https://lore.kernel.org/linux-iommu/[email protected]/
This version introduce a new patch [4/7] to fix an issue reported here.
https://lore.kernel.org/linux-iommu/[email protected]/
There aren't any other changes.
Please help to test and review.
Best regards,
baolu
Lu Baolu (3):
iommu: Add quirk for Intel graphic devices in map_sg iommu/vt-d: Update domain geometry in iommu_ops.at(de)tach_dev iommu/vt-d: Cleanup after converting to dma-iommu ops
Tom Murphy (4):
iommu: Handle freelists when using deferred flushing in iommu drivers
iommu: Add iommu_dma_free_cpu_cached_iovas()
iommu: Allow the dma-iommu api to use bounce buffers iommu/vt-d: Convert intel iommu driver to the iommu ops
.../admin-guide/kernel-parameters.txt | 5 - drivers/iommu/dma-iommu.c | 228 ++++- drivers/iommu/intel/Kconfig | 1 + drivers/iommu/intel/iommu.c | 901 +++--------------- include/linux/dma-iommu.h | 8 + include/linux/iommu.h | 1 + 6 files changed, 336 insertions(+), 808 deletions(-)
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Lu Baolu
maintainerPATCH v4 1/7 iommu: Handle freelists when using deferred flushing in iommu drivers
From: Tom Murphy <[email protected]>
Allow the iommu_unmap_fast to return newly freed page table pages and pass the freelist to queue_iova in the dma-iommu ops path.
This is useful for iommu drivers (in this case the intel iommu driver) which need to wait for the ioTLB to be flushed before newly free/unmapped page table pages can be freed. This way we can still batch ioTLB free operations and handle the freelists.
--- drivers/iommu/dma-iommu.c | 29 +++++++++++++------ drivers/iommu/intel/iommu.c | 55 ++++++++++++++++++++++++------------- include/linux/iommu.h | 1 + 3 files changed, 58 insertions(+), 27 deletions(-)
drivers/iommu/dma-iommu.c +21 -8
@@ -50,6 +50,18 @@ struct iommu_dma_cookie {struct iommu_domain *fq_domain; }; +static void iommu_dma_entry_dtor (unsigned long data) +{ +struct page *freelist = (struct page *)data; + +while (freelist) { +unsigned long p = (unsigned long )page_address (freelist); + + freelist = freelist->freelist; +free_page (p); + } +} +static inline size_t cookie_msi_granule (struct iommu_dma_cookie *cookie) {if (cookie->type ==IOMMU_DMA_IOVA_COOKIE )
@@ -344,7 +356,7 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,if (!cookie->fq_domain && !iommu_domain_get_attr (domain,DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE , &attr) && attr) {if (init_iova_flush_queue (iovad, iommu_dma_flush_iotlb_all, -NULL )) + iommu_dma_entry_dtor))pr_warn ("iova flush queue initialization failed\n" );else cookie->fq_domain = domain;
@@ -441,7 +453,7 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, }static void iommu_dma_free_iova (struct iommu_dma_cookie *cookie, -dma_addr_t iova,size_t size) +dma_addr_t iova,size_t size,struct page *freelist) {struct iova_domain *iovad = &cookie->iovad;
@@ -450,7 +462,8 @@ static void iommu_dma_free_iova(struct iommu_dma_cookie *cookie, cookie->msi_iova -= size; else if (cookie->fq_domain) /* non-strict mode */ queue_iova(iovad, iova_pfn(iovad, iova), - size >> iova_shift(iovad), 0); + size >> iova_shift(iovad), + (unsigned long)freelist); elsefree_iova_fast (iovad ,iova_pfn (iovad ,iova ), size >> iova_shift(iovad));
@@ -475,7 +488,7 @@ static void __iommu_dma_unmap(struct device *dev, dma_addr_t dma_addr,if (!cookie->fq_domain)iommu_iotlb_sync (domain, &iotlb_gather); -iommu_dma_free_iova (cookie, dma_addr, size); +iommu_dma_free_iova (cookie, dma_addr, size, iotlb_gather.freelist); } static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys,
@@ -497,7 +510,7 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys,return DMA_MAPPING_ERROR ;if (iommu_map_atomic (domain, iova, phys - iova_off, size, prot)) { -iommu_dma_free_iova (cookie, iova, size); +iommu_dma_free_iova (cookie, iova, size,NULL );return DMA_MAPPING_ERROR ; }return iova + iova_off;
@@ -649,7 +662,7 @@ static void *iommu_dma_alloc_remap(struct device *dev, size_t size, out_free_sg:sg_free_table (&sgt); out_free_iova: -iommu_dma_free_iova (cookie, iova, size); +iommu_dma_free_iova (cookie, iova, size,NULL ); out_free_pages:__iommu_dma_free_pages (pages, count);return NULL ;
@@ -900,7 +913,7 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,return __finalise_sg (dev, sg, nents, iova); out_free_iova: -iommu_dma_free_iova (cookie, iova, iova_len); +iommu_dma_free_iova (cookie, iova, iova_len,NULL ); out_restore_sg:__invalidate_sg (sg, nents);return 0 ;
@@ -1194,7 +1207,7 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev,return msi_page; out_free_iova: -iommu_dma_free_iova (cookie, iova, size); +iommu_dma_free_iova (cookie, iova, size,NULL ); out_free_page:kfree (msi_page);return NULL ;
drivers/iommu/intel/iommu.c +36 -19
112 lines not on this page · raw message
include/linux/iommu.h +1 -0
@@ -180,6 +180,7 @@ struct iommu_iotlb_gather {unsigned long start;unsigned long end;size_t pgsize; +struct page *freelist; };/**
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Lu Baolu
maintainerPATCH v4 2/7 iommu: Add iommu_dma_free_cpu_cached_iovas()
In reply to Lu BaoluFrom: Tom Murphy <[email protected]>
Add a iommu_dma_free_cpu_cached_iovas function to allow drivers which use the dma-iommu ops to free cached cpu iovas.
--- drivers/iommu/dma-iommu.c | 9 +++++++++ include/linux/dma-iommu.h | 8 ++++++++ 2 files changed, 17 insertions(+)
drivers/iommu/dma-iommu.c +9 -0
@@ -50,6 +50,15 @@ struct iommu_dma_cookie {struct iommu_domain *fq_domain; }; +void iommu_dma_free_cpu_cached_iovas (unsigned int cpu, +struct iommu_domain *domain) +{ +struct iommu_dma_cookie *cookie = domain->iova_cookie; +struct iova_domain *iovad = &cookie->iovad; + +free_cpu_cached_iovas (cpu, iovad); +} +static void iommu_dma_entry_dtor (unsigned long data) {struct page *freelist = (struct page *)data;
include/linux/dma-iommu.h +8 -0
@@ -37,6 +37,9 @@ void iommu_dma_compose_msi_msg(struct msi_desc *desc,void iommu_dma_get_resv_regions (struct device *dev,struct list_head *list); +void iommu_dma_free_cpu_cached_iovas (unsigned int cpu, +struct iommu_domain *domain); +#else /* CONFIG_IOMMU_DMA */ struct iommu_domain ;
@@ -78,5 +81,10 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he { } +static inline void iommu_dma_free_cpu_cached_iovas (unsigned int cpu, +struct iommu_domain *domain) +{ +} +#endif /* CONFIG_IOMMU_DMA */ #endif /* __DMA_IOMMU_H */
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Lu Baolu
maintainerPATCH v4 3/7 iommu: Allow the dma-iommu api to use bounce buffers
In reply to Lu BaoluFrom: Tom Murphy <[email protected]>
Allow the dma-iommu api to use bounce buffers for untrusted devices. This is a copy of the intel bounce buffer code.
--- drivers/iommu/dma-iommu.c | 163 +++++++++++++++++++++++++++++++++++--- 1 file changed, 150 insertions(+), 13 deletions(-)
drivers/iommu/dma-iommu.c +150 -13
@@ -21,9 +21,11 @@#include <linux/mm.h> #include <linux/mutex.h> #include <linux/pci.h> +#include <linux/swiotlb.h> #include <linux/scatterlist.h> #include <linux/vmalloc.h> #include <linux/crash_dump.h> +#include <linux/dma-direct.h> struct iommu_dma_msi_page {struct list_head list;
@@ -500,6 +502,31 @@ static void __iommu_dma_unmap(struct device *dev, dma_addr_t dma_addr,iommu_dma_free_iova (cookie, dma_addr, size, iotlb_gather.freelist); } +static void __iommu_dma_unmap_swiotlb (struct device *dev,dma_addr_t dma_addr, +size_t size,enum dma_data_direction dir, +unsigned long attrs) +{ +struct iommu_domain *domain =iommu_get_dma_domain (dev); +struct iommu_dma_cookie *cookie = domain->iova_cookie; +struct iova_domain *iovad = &cookie->iovad; +phys_addr_t phys; + + phys =iommu_iova_to_phys (domain, dma_addr); +if (WARN_ON (!phys)) +return ; + +__iommu_dma_unmap (dev, dma_addr, size); + +if (unlikely (is_swiotlb_buffer (phys))) +swiotlb_tbl_unmap_single (dev, phys, size, +iova_align (iovad, size), dir, attrs); +} + +static bool dev_is_untrusted (struct device *dev) +{ +return dev_is_pci (dev) &&to_pci_dev (dev)->untrusted; +} +static dma_addr_t __iommu_dma_map (struct device *dev,phys_addr_t phys,size_t size,int prot,u64 dma_mask) {
@@ -525,6 +552,55 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys,return iova + iova_off; } +static dma_addr_t __iommu_dma_map_swiotlb (struct device *dev,phys_addr_t phys, +size_t org_size,dma_addr_t dma_mask,bool coherent, +enum dma_data_direction dir,unsigned long attrs) +{ +int prot =dma_info_to_prot (dir, coherent, attrs); +struct iommu_domain *domain =iommu_get_dma_domain (dev); +struct iommu_dma_cookie *cookie = domain->iova_cookie; +struct iova_domain *iovad = &cookie->iovad; +size_t aligned_size = org_size; +void *padding_start; +size_t padding_size; +dma_addr_t iova; + +/* +* If both the physical buffer start address and size are +* page aligned, we don't need to use a bounce page. +*/ +if (IS_ENABLED (CONFIG_SWIOTLB ) &&dev_is_untrusted (dev) && +iova_offset (iovad, phys | org_size)) { + aligned_size =iova_align (iovad, org_size); + phys =swiotlb_tbl_map_single (dev, +__phys_to_dma (dev, io_tlb_start), + phys, org_size, aligned_size, dir, attrs); + +if (phys ==DMA_MAPPING_ERROR ) +return DMA_MAPPING_ERROR ; + +/* Cleanup the padding area. */ + padding_start =phys_to_virt (phys); + padding_size = aligned_size; + +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC ) && + (dir ==DMA_TO_DEVICE || + dir ==DMA_BIDIRECTIONAL )) { + padding_start += org_size; + padding_size -= org_size; + } + +memset (padding_start,0 , padding_size); + } + + iova =__iommu_dma_map (dev, phys, aligned_size, prot, dma_mask); +if ((iova ==DMA_MAPPING_ERROR ) &&is_swiotlb_buffer (phys)) +swiotlb_tbl_unmap_single (dev, phys, org_size, + aligned_size, dir, attrs); + +return iova; +} +static void __iommu_dma_free_pages (struct page **pages,int count) {while (count--)
@@ -697,11 +773,15 @@ static void iommu_dma_sync_single_for_cpu(struct device *dev, {phys_addr_t phys; -if (dev_is_dma_coherent (dev)) +if (dev_is_dma_coherent (dev) && !dev_is_untrusted (dev))return ; phys =iommu_iova_to_phys (iommu_get_dma_domain (dev), dma_handle); -arch_sync_dma_for_cpu (phys, size, dir); +if (!dev_is_dma_coherent (dev)) +arch_sync_dma_for_cpu (phys, size, dir); + +if (is_swiotlb_buffer (phys)) +swiotlb_tbl_sync_single (dev, phys, size, dir,SYNC_FOR_CPU ); } static void iommu_dma_sync_single_for_device(struct device *dev,
@@ -709,11 +789,15 @@ static void iommu_dma_sync_single_for_device(struct device *dev, {phys_addr_t phys; -if (dev_is_dma_coherent (dev)) +if (dev_is_dma_coherent (dev) && !dev_is_untrusted (dev))return ; phys =iommu_iova_to_phys (iommu_get_dma_domain (dev), dma_handle); -arch_sync_dma_for_device (phys, size, dir); +if (is_swiotlb_buffer (phys)) +swiotlb_tbl_sync_single (dev, phys, size, dir,SYNC_FOR_DEVICE ); + +if (!dev_is_dma_coherent (dev)) +arch_sync_dma_for_device (phys, size, dir); } static void iommu_dma_sync_sg_for_cpu(struct device *dev,
@@ -723,11 +807,17 @@ static void iommu_dma_sync_sg_for_cpu(struct device *dev,struct scatterlist *sg;int i; -if (dev_is_dma_coherent (dev)) +if (dev_is_dma_coherent (dev) && !dev_is_untrusted (dev))return ; -for_each_sg (sgl, sg, nelems, i) -arch_sync_dma_for_cpu (sg_phys (sg), sg->length, dir); +for_each_sg (sgl, sg, nelems, i) { +if (!dev_is_dma_coherent (dev)) +arch_sync_dma_for_cpu (sg_phys (sg), sg->length, dir); + +if (is_swiotlb_buffer (sg_phys (sg))) +swiotlb_tbl_sync_single (dev,sg_phys (sg), sg->length, + dir,SYNC_FOR_CPU ); + } } static void iommu_dma_sync_sg_for_device(struct device *dev,
@@ -737,11 +827,17 @@ static void iommu_dma_sync_sg_for_device(struct device *dev,struct scatterlist *sg;int i; -if (dev_is_dma_coherent (dev)) +if (dev_is_dma_coherent (dev) && !dev_is_untrusted (dev))return ; -for_each_sg (sgl, sg, nelems, i) -arch_sync_dma_for_device (sg_phys (sg), sg->length, dir); +for_each_sg (sgl, sg, nelems, i) { +if (is_swiotlb_buffer (sg_phys (sg))) +swiotlb_tbl_sync_single (dev,sg_phys (sg), sg->length, + dir,SYNC_FOR_DEVICE ); + +if (!dev_is_dma_coherent (dev)) +arch_sync_dma_for_device (sg_phys (sg), sg->length, dir); + } } static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
@@ -750,10 +846,10 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, {phys_addr_t phys =page_to_phys (page) + offset;bool coherent =dev_is_dma_coherent (dev); -int prot =dma_info_to_prot (dir, coherent, attrs);dma_addr_t dma_handle; - dma_handle =__iommu_dma_map (dev, phys, size, prot,dma_get_mask (dev)); + dma_handle =__iommu_dma_map_swiotlb (dev, phys, size,dma_get_mask (dev), + coherent, dir, attrs);if (!coherent && !(attrs &DMA_ATTR_SKIP_CPU_SYNC ) && dma_handle !=DMA_MAPPING_ERROR )arch_sync_dma_for_device (phys, size, dir);
@@ -765,7 +861,7 @@ static void iommu_dma_unmap_page(struct device *dev, dma_addr_t dma_handle, {if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC ))iommu_dma_sync_single_for_cpu (dev, dma_handle, size, dir); -__iommu_dma_unmap (dev, dma_handle, size); +__iommu_dma_unmap_swiotlb (dev, dma_handle, size, dir, attrs); }/*
@@ -843,6 +939,39 @@ static void __invalidate_sg(struct scatterlist *sg, int nents) } } +static void iommu_dma_unmap_sg_swiotlb (struct device *dev,struct scatterlist *sg, +int nents,enum dma_data_direction dir,unsigned long attrs) +{ +struct scatterlist *s; +int i; + +for_each_sg (sg, s, nents, i) +__iommu_dma_unmap_swiotlb (dev,sg_dma_address (s), +sg_dma_len (s), dir, attrs); +} + +static int iommu_dma_map_sg_swiotlb (struct device *dev,struct scatterlist *sg, +int nents,enum dma_data_direction dir,unsigned long attrs) +{ +struct scatterlist *s; +int i; + +for_each_sg (sg, s, nents, i) { +sg_dma_address (s) =__iommu_dma_map_swiotlb (dev,sg_phys (s), + s->length,dma_get_mask (dev), +dev_is_dma_coherent (dev), dir, attrs); +if (sg_dma_address (s) ==DMA_MAPPING_ERROR ) + goto out_unmap; +sg_dma_len (s) = s->length; + } + +return nents; + +out_unmap: +iommu_dma_unmap_sg_swiotlb (dev, sg, i, dir, attrs |DMA_ATTR_SKIP_CPU_SYNC ); +return 0 ; +} +/* * The DMA API client is passing in a scatterlist which could describe * any old buffer layout, but the IOMMU API requires everything to be
@@ -869,6 +998,9 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC ))iommu_dma_sync_sg_for_device (dev, sg, nents, dir); +if (dev_is_untrusted (dev)) +return iommu_dma_map_sg_swiotlb (dev, sg, nents, dir, attrs); +/* * Work out how much IOVA space we need, and align the segments to * IOVA granules for the IOMMU driver to handle. With some clever
@@ -938,6 +1070,11 @@ static void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg,if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC ))iommu_dma_sync_sg_for_cpu (dev, sg, nents, dir); +if (dev_is_untrusted (dev)) { +iommu_dma_unmap_sg_swiotlb (dev, sg, nents, dir, attrs); +return ; + } +/* * The scatterlist segments are mapped into a single * contiguous IOVA allocation, so this is incredibly easy.
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Lu Baolu
maintainerPATCH v4 4/7 iommu: Add quirk for Intel graphic devices in map_sg
In reply to Lu BaoluCombining the sg segments exposes a bug in the Intel i915 driver which causes visual artifacts and the screen to freeze. This is most likely because of how the i915 handles the returned list. It probably doesn't respect the returned value specifying the number of elements in the list and instead depends on the previous behaviour of the Intel iommu driver which would return the same number of elements in the output list as in the input list.
--- drivers/iommu/dma-iommu.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/iommu/dma-iommu.c +27 -0
@@ -879,6 +879,33 @@ static int __finalise_sg(struct device *dev, struct scatterlist *sg, int nents,unsigned int cur_len =0 , max_len =dma_get_max_seg_size (dev);int i, count =0 ; +/* +* The Intel graphic driver is used to assume that the returned +* sg list is not combound. This blocks the efforts of converting +* Intel IOMMU driver to dma-iommu api's. Add this quirk to make the +* device driver work and should be removed once it's fixed in i915 +* driver. +*/ +if (IS_ENABLED (CONFIG_DRM_I915 ) &&dev_is_pci (dev) && +to_pci_dev (dev)->vendor ==PCI_VENDOR_ID_INTEL && + (to_pci_dev (dev)->class >>16 ) ==PCI_BASE_CLASS_DISPLAY ) { +for_each_sg (sg, s, nents, i) { +unsigned int s_iova_off =sg_dma_address (s); +unsigned int s_length =sg_dma_len (s); +unsigned int s_iova_len = s->length; + + s->offset += s_iova_off; + s->length = s_length; +sg_dma_address (s) = dma_addr + s_iova_off; +sg_dma_len (s) = s_length; + dma_addr += s_iova_len; + +pr_info_once ("sg combining disabled due to i915 driver\n" ); + } + +return nents; + } +for_each_sg (sg, s, nents, i) {/* Restore this segment's original unaligned fields first */ unsigned int s_iova_off =sg_dma_address (s);
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Robin Murphy
maintainerRe: [PATCH v4 4/7] iommu: Add quirk for Intel graphic devices in map_sg
Quoted 38 lines · Lu Baolu
Combining the sg segments exposes a bug in the Intel i915 driver which causes visual artifacts and the screen to freeze. This is most likely because of how the i915 handles the returned list. It probably doesn't respect the returned value specifying the number of elements in the list and instead depends on the previous behaviour of the Intel iommu driver which would return the same number of elements in the output list as in the input list.
Signed-off-by Tom Murphy <[email protected]>Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/dma-iommu.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)drivers/iommu/dma-iommu.c +16
-0@@ -879,6 +879,33 @@ static int __finalise_sg(struct device *dev, struct scatterlist *sg, int nents,unsigned int cur_len =0 , max_len =dma_get_max_seg_size (dev);int i, count =0 ; +/* +* The Intel graphic driver is used to assume that the returned +* sg list is not combound. This blocks the efforts of converting +* Intel IOMMU driver to dma-iommu api's. Add this quirk to make the +* device driver work and should be removed once it's fixed in i915 +* driver. +*/ +if (IS_ENABLED (CONFIG_DRM_I915 ) &&dev_is_pci (dev) && +to_pci_dev (dev)->vendor ==PCI_VENDOR_ID_INTEL && + (to_pci_dev (dev)->class >>16 ) ==PCI_BASE_CLASS_DISPLAY ) { +for_each_sg (sg, s, nents, i) { +unsigned int s_iova_off =sg_dma_address (s); +unsigned int s_length =sg_dma_len (s); +unsigned int s_iova_len = s->length; + + s->offset += s_iova_off;
drivers/iommu/dma-iommu.c static int __finalise_sg(struct device *dev, struct scatterlist *sg, int nents, · line 907
Quoted 10 lines
drivers/iommu/dma-iommu.c +10
-0+ s->length = s_length; +sg_dma_address (s) = dma_addr + s_iova_off; +sg_dma_len (s) = s_length; + dma_addr += s_iova_len; + +pr_info_once ("sg combining disabled due to i915 driver\n" ); + } + +return nents; + }
BTW, a much less invasive workaround would be to simply override seg_mask to 0. That's enough to make sure that no segment looks eligible for merging.
Robin.
Quoted 5 lines
drivers/iommu/dma-iommu.c +1
-0+for_each_sg (sg, s, nents, i) {/* Restore this segment's original unaligned fields first */ unsigned int s_iova_off =sg_dma_address (s);
Lu Baolu
maintainerPATCH v4 5/7 iommu/vt-d: Update domain geometry in iommu_ops.at(de)tach_dev
In reply to Lu BaoluThe iommu-dma constrains IOVA allocation based on the domain geometry that the driver reports. Update domain geometry everytime a domain is attached to or detached from a device.
--- drivers/iommu/intel/iommu.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +14 -2
@@ -67,8 +67,8 @@#define MAX_AGAW_WIDTH 64#define MAX_AGAW_PFN_WIDTH (MAX_AGAW_WIDTH - VTD_PAGE_SHIFT) -#define __DOMAIN_MAX_PFN (gaw) ((((uint64_t)1) << (gaw-VTD_PAGE_SHIFT)) - 1) -#define __DOMAIN_MAX_ADDR (gaw) ((((uint64_t)1) << gaw) - 1) +#define __DOMAIN_MAX_PFN (gaw) ((((uint64_t)1) << ((gaw) - VTD_PAGE_SHIFT)) - 1) +#define __DOMAIN_MAX_ADDR (gaw) ((((uint64_t)1) << (gaw)) - 1)/* We limit DOMAIN_MAX_PFN to fit in an unsigned long, and DOMAIN_MAX_ADDR to match. That way, we can use 'unsigned long' for PFNs with impunity. */
@@ -739,6 +739,18 @@ static void domain_update_iommu_cap(struct dmar_domain *domain)*/ if (domain->nid ==NUMA_NO_NODE ) domain->nid =domain_update_device_node (domain); + +/* +* First-level translation restricts the input-address to a +* canonical address (i.e., address bits 63:N have the same +* value as address bit [N-1], where N is 48-bits with 4-level +* paging and 57-bits with 5-level paging). Hence, skip bit +* [N-1]. +*/ +if (domain_use_first_level (domain)) + domain->domain.geometry.aperture_end =__DOMAIN_MAX_ADDR (domain->gaw -1 ); +else + domain->domain.geometry.aperture_end =__DOMAIN_MAX_ADDR (domain->gaw); } struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus,
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Lu Baolu
maintainerPATCH v4 6/7 iommu/vt-d: Convert intel iommu driver to the iommu ops
In reply to Lu BaoluFrom: Tom Murphy <[email protected]>
Convert the intel iommu driver to the dma-iommu api. Remove the iova handling and reserve region code from the intel iommu driver.
--- drivers/iommu/intel/Kconfig | 1 + drivers/iommu/intel/iommu.c | 742 ++---------------------------------- 2 files changed, 43 insertions(+), 700 deletions(-)
drivers/iommu/intel/Kconfig +1 -0
@@ -13,6 +13,7 @@ config INTEL_IOMMU select DMAR_TABLE select SWIOTLB select IOASID + select IOMMU_DMA help DMA remapping (DMAR) devices support enables independent address translations for Direct Memory Access (DMA) from devices.
drivers/iommu/intel/iommu.c +42 -700
874 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Lu Baolu
maintainerPATCH v4 7/7 iommu/vt-d: Cleanup after converting to dma-iommu ops
In reply to Lu BaoluSome cleanups after converting the driver to use dma-iommu ops.
- Remove nobounce option;
- Cleanup and simplify the path in domain mapping.
--- .../admin-guide/kernel-parameters.txt | 5 -- drivers/iommu/intel/iommu.c | 90 ++++++------------- 2 files changed, 28 insertions(+), 67 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -5
@@ -1866,11 +1866,6 @@ Note that using this option lowers the security provided by tboot because it makes the system vulnerable to DMA attacks. - nobounce [Default off] - Disable bounce buffer for untrusted devices such as - the Thunderbolt devices. This will treat the untrusted - devices as the trusted ones, hence might expose security - risks of DMA attacks. intel_idle.max_cstate= [KNL,HW,ACPI,X86] 0 disables intel_idle and fall back on acpi_idle.
drivers/iommu/intel/iommu.c +28 -62
175 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BUILD: failure for Convert the intel iommu driver to the dma-iommu api (rev3)
In reply to Lu Baolu== Series Details ==
== Series Details ==
Series: Convert the intel iommu driver to the dma-iommu api (rev3)
URL : https://patchwork.freedesktop.org/series/71260/
State : failure
== Summary ==
Applying: iommu: Handle freelists when using deferred flushing in iommu drivers
error: sha1 information is lacking or useless (drivers/iommu/dma-iommu.c).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 iommu: Handle freelists when using deferred flushing in iommu drivers When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 12 lines · Lu Baolu
Hi,
The previous post of this series could be found here.
https://lore.kernel.org/linux-iommu/[email protected]/
This version introduce a new patch [4/7] to fix an issue reported here.
https://lore.kernel.org/linux-iommu/[email protected]/
There aren't any other changes.
Quoted 7 lines
Please help to test and review.
Best regards,
baoluLu Baolu (3):
iommu: Add quirk for Intel graphic devices inmap_sg
Since I do have patches to fix i915 to handle this, do we want to co-ordinate the two and avoid having to add this quirk and then later remove it? Or you want to go the staged approach?
Regards,
Tvrtko
Quoted 17 lines
iommu/vt-d: Update domain geometry in iommu_ops.at(de)tach_dev iommu/vt-d: Cleanup after converting to dma-iommu ops
Tom Murphy (4):
iommu: Handle freelists when using deferred flushing in iommu drivers
iommu: Addiommu_dma_free_cpu_cached_iovas()
iommu: Allow the dma-iommu api to use bounce buffers iommu/vt-d: Convert intel iommu driver to the iommu ops.../admin-guide/kernel-parameters.txt | 5 - drivers/iommu/dma-iommu.c | 228 ++++- drivers/iommu/intel/Kconfig | 1 + drivers/iommu/intel/iommu.c | 901 +++--------------- include/linux/dma-iommu.h | 8 + include/linux/iommu.h | 1 + 6 files changed, 336 insertions(+), 808 deletions(-)
Lu Baolu
maintainerHi Tvrtko,
Quoted 18 lines · Tvrtko Ursulin
Quoted 16 lines · Lu Baolu
Hi,
The previous post of this series could be found here.
https://lore.kernel.org/linux-iommu/[email protected]/
This version introduce a new patch [4/7] to fix an issue reported here.
https://lore.kernel.org/linux-iommu/[email protected]/
There aren't any other changes.
Please help to test and review.
Quoted 7 lines
Quoted 5 lines
Best regards,
baoluLu Baolu (3):
iommu: Add quirk for Intel graphic devices inmap_sgSince I do have patches to fix i915 to handle this, do we want to co-ordinate the two and avoid having to add this quirk and then later remove it? Or you want to go the staged approach?
I have no preference. It depends on which patch goes first. Let the maintainers help here.
Best regards,
baolu
Quoted 22 lines
Regards,
Tvrtko
Quoted 17 lines
iommu/vt-d: Update domain geometry in iommu_ops.at(de)tach_dev iommu/vt-d: Cleanup after converting to dma-iommu ops
Tom Murphy (4):
iommu: Handle freelists when using deferred flushing in iommu drivers
iommu: Addiommu_dma_free_cpu_cached_iovas()
iommu: Allow the dma-iommu api to use bounce buffers iommu/vt-d: Convert intel iommu driver to the iommu ops.../admin-guide/kernel-parameters.txt | 5 - drivers/iommu/dma-iommu.c | 228 ++++- drivers/iommu/intel/Kconfig | 1 + drivers/iommu/intel/iommu.c | 901 +++--------------- include/linux/dma-iommu.h | 8 + include/linux/iommu.h | 1 +
6 files changed, 336 insertions(+), 808 deletions(-)
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Joerg Roedel
maintainerHi Baolu,
Quoted 2 lines · Lu Baolu
I have no preference. It depends on which patch goes first. Let the maintainers help here.
No preference on my side, except that it is too late for this now to make it into v5.10. Besides that I let the decission up to you when this is ready. Just send me a pull-request when it should get into the iommu-tree.
Regards,
Joerg
Lu Baolu
maintainerHi Joerg,
Quoted 10 lines · Joerg Roedel
Hi Baolu,
Quoted 2 lines · Lu Baolu
I have no preference. It depends on which patch goes first. Let the maintainers help here.
No preference on my side, except that it is too late for this now to make it into v5.10. Besides that I let the decission up to you when this is ready. Just send me a pull-request when it should get into the iommu-tree.
Sure.
Best regards,
baolu
Quoted 5 lines
Regards,
Joerg
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 24 lines · Lu Baolu
Hi Tvrtko,
Quoted 21 lines · Tvrtko Ursulin
Quoted 19 lines · Lu Baolu
Hi,
The previous post of this series could be found here.
https://lore.kernel.org/linux-iommu/[email protected]/
This version introduce a new patch [4/7] to fix an issue reported here.
https://lore.kernel.org/linux-iommu/[email protected]/
There aren't any other changes.
Please help to test and review.
Best regards,
baolu
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Lu Baolu (3):
iommu: Add quirk for Intel graphic devices inmap_sgSince I do have patches to fix i915 to handle this, do we want to co-ordinate the two and avoid having to add this quirk and then later remove it? Or you want to go the staged approach?
I have no preference. It depends on which patch goes first. Let the maintainers help here.
FYI we have merged the required i915 patches to out tree last week or so. I *think* this means they will go into 5.11. So the i915 specific workaround patch will not be needed in Intel IOMMU.
Regards,
Tvrtko
Lu Baolu
maintainerHi Tvrtko,
Quoted 29 lines · Tvrtko Ursulin
Quoted 27 lines · Lu Baolu
Hi Tvrtko,
Quoted 24 lines · Tvrtko Ursulin
Quoted 21 lines · Lu Baolu
Hi,
The previous post of this series could be found here.
https://lore.kernel.org/linux-iommu/[email protected]/
This version introduce a new patch [4/7] to fix an issue reported here.
https://lore.kernel.org/linux-iommu/[email protected]/
There aren't any other changes.
Please help to test and review.
Best regards,
baoluLu Baolu (3):
iommu: Add quirk for Intel graphic devices inmap_sg
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Since I do have patches to fix i915 to handle this, do we want to co-ordinate the two and avoid having to add this quirk and then later remove it? Or you want to go the staged approach?
I have no preference. It depends on which patch goes first. Let the maintainers help here.
FYI we have merged the required i915 patches to out tree last week or so. I *think* this means they will go into 5.11. So the i915 specific workaround patch will not be needed in Intel IOMMU.
Thanks for letting us know this. I will drop the workaround patch and test the whole series after the next rc1.
Best regards,
baolu
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Lu Baolu
maintainerHi Tvrtko,
Quoted 29 lines · Tvrtko Ursulin
Quoted 27 lines · Lu Baolu
Hi Tvrtko,
Quoted 24 lines · Tvrtko Ursulin
Quoted 21 lines · Lu Baolu
Hi,
The previous post of this series could be found here.
https://lore.kernel.org/linux-iommu/[email protected]/
This version introduce a new patch [4/7] to fix an issue reported here.
https://lore.kernel.org/linux-iommu/[email protected]/
There aren't any other changes.
Please help to test and review.
Best regards,
baoluLu Baolu (3):
iommu: Add quirk for Intel graphic devices inmap_sg
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Since I do have patches to fix i915 to handle this, do we want to co-ordinate the two and avoid having to add this quirk and then later remove it? Or you want to go the staged approach?
I have no preference. It depends on which patch goes first. Let the maintainers help here.
FYI we have merged the required i915 patches to out tree last week or so. I *think* this means they will go into 5.11. So the i915 specific workaround patch will not be needed in Intel IOMMU.
Do you mind telling me what's the status of this fix patch? I tried this series on v5.10-rc1 with the graphic quirk patch dropped. I am still seeing dma faults from graphic device.
Best regards,
baolu
Quoted 4 lines
Regards,
Tvrtko
Quoted 33 lines · Lu Baolu
Hi Tvrtko,
Quoted 31 lines · Tvrtko Ursulin
Quoted 29 lines · Lu Baolu
Hi Tvrtko,
Quoted 25 lines · Tvrtko Ursulin
Quoted 14 lines · Lu Baolu
Hi,
The previous post of this series could be found here.
https://lore.kernel.org/linux-iommu/[email protected]/
This version introduce a new patch [4/7] to fix an issue reported here.
https://lore.kernel.org/linux-iommu/[email protected]/
There aren't any other changes.
Quoted 7 lines
Please help to test and review.
Best regards,
baoluLu Baolu (3):
iommu: Add quirk for Intel graphic devices inmap_sgSince I do have patches to fix i915 to handle this, do we want to co-ordinate the two and avoid having to add this quirk and then later remove it? Or you want to go the staged approach?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I have no preference. It depends on which patch goes first. Let the maintainers help here.
FYI we have merged the required i915 patches to out tree last week or so. I *think* this means they will go into 5.11. So the i915 specific workaround patch will not be needed in Intel IOMMU.
Do you mind telling me what's the status of this fix patch? I tried this series on v5.10-rc1 with the graphic quirk patch dropped. I am still seeing dma faults from graphic device.
Hmm back then I thought i915 fixes for this would land in 5.11 so I will stick with that. :) (See my quoted text a paragraph above yours.)
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Lu Baolu
maintainerQuoted 38 lines · Tvrtko Ursulin
Quoted 36 lines · Lu Baolu
Hi Tvrtko,
Quoted 34 lines · Tvrtko Ursulin
Quoted 31 lines · Lu Baolu
Hi Tvrtko,
Quoted 18 lines · Tvrtko Ursulin
Quoted 16 lines · Lu Baolu
Hi,
The previous post of this series could be found here.
https://lore.kernel.org/linux-iommu/[email protected]/
This version introduce a new patch [4/7] to fix an issue reported here.
https://lore.kernel.org/linux-iommu/[email protected]/
There aren't any other changes.
Please help to test and review.
Quoted 7 lines
Quoted 5 lines
Best regards,
baoluLu Baolu (3):
iommu: Add quirk for Intel graphic devices inmap_sgSince I do have patches to fix i915 to handle this, do we want to co-ordinate the two and avoid having to add this quirk and then later remove it? Or you want to go the staged approach?
I have no preference. It depends on which patch goes first. Let the maintainers help here.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
FYI we have merged the required i915 patches to out tree last week or so. I *think* this means they will go into 5.11. So the i915 specific workaround patch will not be needed in Intel IOMMU.
Do you mind telling me what's the status of this fix patch? I tried this series on v5.10-rc1 with the graphic quirk patch dropped. I am still seeing dma faults from graphic device.
Hmm back then I thought i915 fixes for this would land in 5.11 so I will stick with that. :) (See my quoted text a paragraph above yours.)
What size are those fixes? I am considering pushing this series for v5.11. Is it possible to get some acks for those patches and let them go to Linus through iommu tree?
Best regards,
baolu
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 45 lines · Lu Baolu
Quoted 44 lines · Tvrtko Ursulin
Quoted 41 lines · Lu Baolu
Hi Tvrtko,
Quoted 29 lines · Tvrtko Ursulin
Quoted 27 lines · Lu Baolu
Hi Tvrtko,
Quoted 24 lines · Tvrtko Ursulin
Quoted 21 lines · Lu Baolu
Hi,
The previous post of this series could be found here.
https://lore.kernel.org/linux-iommu/[email protected]/
This version introduce a new patch [4/7] to fix an issue reported here.
https://lore.kernel.org/linux-iommu/[email protected]/
There aren't any other changes.
Please help to test and review.
Best regards,
baoluLu Baolu (3):
iommu: Add quirk for Intel graphic devices inmap_sgQuoted 6 lines
Quoted 4 lines
Quoted 1 line
Since I do have patches to fix i915 to handle this, do we want to co-ordinate the two and avoid having to add this quirk and then later remove it? Or you want to go the staged approach?
I have no preference. It depends on which patch goes first. Let the maintainers help here.
FYI we have merged the required i915 patches to out tree last week or so. I *think* this means they will go into 5.11. So the i915 specific workaround patch will not be needed in Intel IOMMU.
Do you mind telling me what's the status of this fix patch? I tried this series on v5.10-rc1 with the graphic quirk patch dropped. I am still seeing dma faults from graphic device.
Quoted 5 lines
Quoted 1 line
Hmm back then I thought i915 fixes for this would land in 5.11 so I will stick with that. :) (See my quoted text a paragraph above yours.)
What size are those fixes? I am considering pushing this series for v5.11. Is it possible to get some acks for those patches and let them go to Linus through iommu tree?
For 5.10 you mean? They feel a bit too large for comfort to go via a non-i915/drm tree. These are the two patches required:
https://cgit.freedesktop.org/drm-intel/commit/?h=drm-intel-gt-next&id=8a473dbadccfc6206150de3db3223c40785da348
https://cgit.freedesktop.org/drm-intel/commit/?h=drm-intel-gt-next&id=934941ed5a3070a7833c688c9b1d71484fc01a68
I'll copy Joonas as our maintainer - how does the idea of taking the above two patches through the iommu tree sound to you?
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoting Tvrtko Ursulin (2020-11-03 11:14:32)
Quoted 10 lines · Lu Baolu
Quoted 7 lines · Tvrtko Ursulin
Quoted 6 lines · Lu Baolu
Quoted 4 lines
Hi Tvrtko,
Quoted 2 lines · Tvrtko Ursulin
On 29/09/2020 01:11, Lu Baolu wrote:
<SNIP>
Quoted 15 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
FYI we have merged the required i915 patches to out tree last week or so. I *think* this means they will go into 5.11. So the i915 specific workaround patch will not be needed in Intel IOMMU.
Do you mind telling me what's the status of this fix patch? I tried this series on v5.10-rc1 with the graphic quirk patch dropped. I am still seeing dma faults from graphic device.
Quoted 6 lines
Quoted 2 lines
Hmm back then I thought i915 fixes for this would land in 5.11 so I will stick with that. :) (See my quoted text a paragraph above yours.)
What size are those fixes? I am considering pushing this series for v5.11. Is it possible to get some acks for those patches and let them go to Linus through iommu tree?
Quoted 8 lines
For 5.10 you mean? They feel a bit too large for comfort to go via a non-i915/drm tree. These are the two patches required:
https://cgit.freedesktop.org/drm-intel/commit/?h=drm-intel-gt-next&id=8a473dbadccfc6206150de3db3223c40785da348
https://cgit.freedesktop.org/drm-intel/commit/?h=drm-intel-gt-next&id=934941ed5a3070a7833c688c9b1d71484fc01a68I'll copy Joonas as our maintainer - how does the idea of taking the above two patches through the iommu tree sound to you?
Hi Lu,
The patches have already been merged into our tree and are heading towards 5.11, so I don't think we should merge them elsewhere. DRM subsystem had the feature freeze for 5.10 at the time of 5.9-rc5 and only drm-intel-fixes pull requests are sent after that.
The patches seem to target to eliminate need for a previously used workaround. To me it seems more appropriate for the patches to follow the regular process as new feature for 5.11 to make sure the changes get validated as part of linux-next.
Would that work for you? We intend to send the feature pull requests to DRM for 5.11 in the upcoming weeks.
Regards, Joonas
Joerg Roedel
maintainerHi,
Quoted 2 lines · Joonas Lahtinen
Would that work for you? We intend to send the feature pull requests to DRM for 5.11 in the upcoming weeks.
For the IOMMU side it is best to include the workaround for now. When the DRM fixes are merged into v5.11-rc1 together with this conversion, it can be reverted and will not be in 5.11-final.
Regards,
Joerg
Lu Baolu
maintainerQuoted 9 lines · Joerg Roedel
Hi,
Quoted 2 lines · Joonas Lahtinen
Would that work for you? We intend to send the feature pull requests to DRM for 5.11 in the upcoming weeks.
For the IOMMU side it is best to include the workaround for now. When the DRM fixes are merged into v5.11-rc1 together with this conversion, it can be reverted and will not be in 5.11-final.
Okay! So I will keep the workaround and send a new version (mostly rebase) to Will.
Best regards,
baolu
Hi Lu,
Quoted 6 lines · Lu Baolu
Hi,
The previous post of this series could be found here.
Quoted 7 lines
This version introduce a new patch [4/7] to fix an issue reported here.
https://lore.kernel.org/linux-iommu/[email protected]/
There aren't any other changes.
Please help to test and review.
I've tested this patchset on my Sandy Bridge machine and found no issues (while including a patch to ioat I've sent to that maintainer).
Thanks,
Logan