Skip to content

Commit 59cc84c

Browse files
fbarratmpe
authored andcommitted
Revert "powerpc/kernel/iommu: Align size for IOMMU_PAGE_SIZE() to save TCEs"
This reverts commit 3c0468d. That commit was breaking alignment guarantees for the DMA address when allocating coherent mappings, as described in Documentation/core-api/dma-api-howto.rst It was also noticed by Mellanox' driver: [ 1515.763621] mlx5_core c002:01:00.0: mlx5_frag_buf_alloc_node:146:(pid 13402): unexpected map alignment: 0x0800000000c61000, page_shift=16 [ 1515.763635] mlx5_core c002:01:00.0: mlx5_cqwq_create:181:(pid 13402): mlx5_frag_buf_alloc_node() failed, -12 Fixes: 3c0468d ("powerpc/kernel/iommu: Align size for IOMMU_PAGE_SIZE() to save TCEs") Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com> Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20210526144540.117795-1-fbarrat@linux.ibm.com
1 parent 1438709 commit 59cc84c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

arch/powerpc/kernel/iommu.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,6 @@ void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl,
898898
unsigned int order;
899899
unsigned int nio_pages, io_order;
900900
struct page *page;
901-
size_t size_io = size;
902901

903902
size = PAGE_ALIGN(size);
904903
order = get_order(size);
@@ -925,9 +924,8 @@ void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl,
925924
memset(ret, 0, size);
926925

927926
/* Set up tces to cover the allocated range */
928-
size_io = IOMMU_PAGE_ALIGN(size_io, tbl);
929-
nio_pages = size_io >> tbl->it_page_shift;
930-
io_order = get_iommu_order(size_io, tbl);
927+
nio_pages = size >> tbl->it_page_shift;
928+
io_order = get_iommu_order(size, tbl);
931929
mapping = iommu_alloc(dev, tbl, ret, nio_pages, DMA_BIDIRECTIONAL,
932930
mask >> tbl->it_page_shift, io_order, 0);
933931
if (mapping == DMA_MAPPING_ERROR) {
@@ -942,9 +940,10 @@ void iommu_free_coherent(struct iommu_table *tbl, size_t size,
942940
void *vaddr, dma_addr_t dma_handle)
943941
{
944942
if (tbl) {
945-
size_t size_io = IOMMU_PAGE_ALIGN(size, tbl);
946-
unsigned int nio_pages = size_io >> tbl->it_page_shift;
943+
unsigned int nio_pages;
947944

945+
size = PAGE_ALIGN(size);
946+
nio_pages = size >> tbl->it_page_shift;
948947
iommu_free(tbl, dma_handle, nio_pages);
949948
size = PAGE_ALIGN(size);
950949
free_pages((unsigned long)vaddr, get_order(size));

0 commit comments

Comments
 (0)