]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu/io-pgtable-arm: Use consistent sizes for page allocation and freeing
authorMostafa Saleh <smostafa@google.com>
Wed, 13 May 2026 21:52:01 +0000 (21:52 +0000)
committerJoerg Roedel <joerg.roedel@amd.com>
Tue, 19 May 2026 09:03:45 +0000 (11:03 +0200)
At the moment we use alloc_size to allocate memory but then there
is a logical error where we just size in the error and free path,
which might be smaller.
Also we size to do DMA-API operations, which is OK, but confusing.

Instead of this error-prone handling, just set size to alloc_size
and use it everywhere.

Signed-off-by: Mostafa Saleh <smostafa@google.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
drivers/iommu/io-pgtable-arm.c

index 0208e5897c299a1829e4d4e9c6fc5ed191207a6c..0cbe545c491df2414d241771575be35fafa363c5 100644 (file)
@@ -253,7 +253,6 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp,
                                    void *cookie)
 {
        struct device *dev = cfg->iommu_dev;
-       size_t alloc_size;
        dma_addr_t dma;
        void *pages;
 
@@ -261,12 +260,11 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp,
         * For very small starting-level translation tables the HW requires a
         * minimum alignment of at least 64 to cover all cases.
         */
-       alloc_size = max(size, 64);
+       size = max(size, 64);
        if (cfg->alloc)
-               pages = cfg->alloc(cookie, alloc_size, gfp);
+               pages = cfg->alloc(cookie, size, gfp);
        else
-               pages = iommu_alloc_pages_node_sz(dev_to_node(dev), gfp,
-                                                 alloc_size);
+               pages = iommu_alloc_pages_node_sz(dev_to_node(dev), gfp, size);
 
        if (!pages)
                return NULL;
@@ -303,6 +301,9 @@ static void __arm_lpae_free_pages(void *pages, size_t size,
                                  struct io_pgtable_cfg *cfg,
                                  void *cookie)
 {
+       /* See __arm_lpae_alloc_pages(). */
+       size = max(size, 64);
+
        if (!cfg->coherent_walk)
                dma_unmap_single(cfg->iommu_dev, __arm_lpae_dma_addr(pages),
                                 size, DMA_TO_DEVICE);