dma-mapping: fix vmap and mmap of noncontiougs allocations
Commitb5c58b2fdc("dma-mapping: direct calls for dma-iommu") switched to use direct calls to dma-iommu, but missed the dma_vmap_noncontiguous, dma_vunmap_noncontiguous and dma_mmap_noncontiguous behavior keyed off the presence of the alloc_noncontiguous method. Fix this by removing the now unused alloc_noncontiguous and free_noncontiguous methods and moving the vmapping and mmaping of the noncontiguous allocations into the iommu code, as it is the only provider of actually noncontiguous allocations. Fixes:b5c58b2fdc("dma-mapping: direct calls for dma-iommu") Reported-by: Xi Ruoyao <xry111@xry111.site> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Leon Romanovsky <leon@kernel.org> Tested-by: Xi Ruoyao <xry111@xry111.site>
This commit is contained in:
+10
-27
@@ -750,7 +750,6 @@ out_free_sgt:
|
||||
struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size,
|
||||
enum dma_data_direction dir, gfp_t gfp, unsigned long attrs)
|
||||
{
|
||||
const struct dma_map_ops *ops = get_dma_ops(dev);
|
||||
struct sg_table *sgt;
|
||||
|
||||
if (WARN_ON_ONCE(attrs & ~DMA_ATTR_ALLOC_SINGLE_PAGES))
|
||||
@@ -758,9 +757,7 @@ struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size,
|
||||
if (WARN_ON_ONCE(gfp & __GFP_COMP))
|
||||
return NULL;
|
||||
|
||||
if (ops && ops->alloc_noncontiguous)
|
||||
sgt = ops->alloc_noncontiguous(dev, size, dir, gfp, attrs);
|
||||
else if (use_dma_iommu(dev))
|
||||
if (use_dma_iommu(dev))
|
||||
sgt = iommu_dma_alloc_noncontiguous(dev, size, dir, gfp, attrs);
|
||||
else
|
||||
sgt = alloc_single_sgt(dev, size, dir, gfp);
|
||||
@@ -786,13 +783,10 @@ static void free_single_sgt(struct device *dev, size_t size,
|
||||
void dma_free_noncontiguous(struct device *dev, size_t size,
|
||||
struct sg_table *sgt, enum dma_data_direction dir)
|
||||
{
|
||||
const struct dma_map_ops *ops = get_dma_ops(dev);
|
||||
|
||||
trace_dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir, 0);
|
||||
debug_dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir);
|
||||
if (ops && ops->free_noncontiguous)
|
||||
ops->free_noncontiguous(dev, size, sgt, dir);
|
||||
else if (use_dma_iommu(dev))
|
||||
|
||||
if (use_dma_iommu(dev))
|
||||
iommu_dma_free_noncontiguous(dev, size, sgt, dir);
|
||||
else
|
||||
free_single_sgt(dev, size, sgt, dir);
|
||||
@@ -802,37 +796,26 @@ EXPORT_SYMBOL_GPL(dma_free_noncontiguous);
|
||||
void *dma_vmap_noncontiguous(struct device *dev, size_t size,
|
||||
struct sg_table *sgt)
|
||||
{
|
||||
const struct dma_map_ops *ops = get_dma_ops(dev);
|
||||
unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
|
||||
|
||||
if (ops && ops->alloc_noncontiguous)
|
||||
return vmap(sgt_handle(sgt)->pages, count, VM_MAP, PAGE_KERNEL);
|
||||
if (use_dma_iommu(dev))
|
||||
return iommu_dma_vmap_noncontiguous(dev, size, sgt);
|
||||
|
||||
return page_address(sg_page(sgt->sgl));
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dma_vmap_noncontiguous);
|
||||
|
||||
void dma_vunmap_noncontiguous(struct device *dev, void *vaddr)
|
||||
{
|
||||
const struct dma_map_ops *ops = get_dma_ops(dev);
|
||||
|
||||
if (ops && ops->alloc_noncontiguous)
|
||||
vunmap(vaddr);
|
||||
if (use_dma_iommu(dev))
|
||||
iommu_dma_vunmap_noncontiguous(dev, vaddr);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dma_vunmap_noncontiguous);
|
||||
|
||||
int dma_mmap_noncontiguous(struct device *dev, struct vm_area_struct *vma,
|
||||
size_t size, struct sg_table *sgt)
|
||||
{
|
||||
const struct dma_map_ops *ops = get_dma_ops(dev);
|
||||
|
||||
if (ops && ops->alloc_noncontiguous) {
|
||||
unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
|
||||
|
||||
if (vma->vm_pgoff >= count ||
|
||||
vma_pages(vma) > count - vma->vm_pgoff)
|
||||
return -ENXIO;
|
||||
return vm_map_pages(vma, sgt_handle(sgt)->pages, count);
|
||||
}
|
||||
if (use_dma_iommu(dev))
|
||||
return iommu_dma_mmap_noncontiguous(dev, vma, size, sgt);
|
||||
return dma_mmap_pages(dev, vma, size, sg_page(sgt->sgl));
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dma_mmap_noncontiguous);
|
||||
|
||||
Reference in New Issue
Block a user