[PATCH v2 19/23] iommu/riscv: Update to use iommu_alloc_pages_node_lg2()
Tomasz Jeznach
tjeznach at rivosinc.com
Thu Feb 20 11:35:49 PST 2025
On Fri, Feb 14, 2025 at 01:07:52PM -0400, Jason Gunthorpe wrote:
> One part of RISCV already has a computed size, however the queue
> allocation must be aligned to 4k. The other objects are 4k by spec.
>
> Signed-off-by: Jason Gunthorpe <jgg at nvidia.com>
> ---
> drivers/iommu/riscv/iommu.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c
> index 2750f2e6e01a2b..8835c82f118db4 100644
> --- a/drivers/iommu/riscv/iommu.c
> +++ b/drivers/iommu/riscv/iommu.c
> @@ -65,13 +65,14 @@ static int riscv_iommu_devres_pages_match(struct device *dev, void *res, void *p
> return devres->addr == target->addr;
> }
>
> -static void *riscv_iommu_get_pages(struct riscv_iommu_device *iommu, int order)
> +static void *riscv_iommu_get_pages(struct riscv_iommu_device *iommu,
> + unsigned int size)
> {
> struct riscv_iommu_devres *devres;
> void *addr;
>
> - addr = iommu_alloc_pages_node(dev_to_node(iommu->dev),
> - GFP_KERNEL_ACCOUNT, order);
> + addr = iommu_alloc_pages_node_sz(dev_to_node(iommu->dev),
> + GFP_KERNEL_ACCOUNT, size);
> if (unlikely(!addr))
> return NULL;
>
> @@ -161,9 +162,9 @@ static int riscv_iommu_queue_alloc(struct riscv_iommu_device *iommu,
> } else {
> do {
> const size_t queue_size = entry_size << (logsz + 1);
> - const int order = get_order(queue_size);
>
> - queue->base = riscv_iommu_get_pages(iommu, order);
> + queue->base = riscv_iommu_get_pages(
> + iommu, max(queue_size, SZ_4K));
> queue->phys = __pa(queue->base);
> } while (!queue->base && logsz-- > 0);
> }
> @@ -618,7 +619,7 @@ static struct riscv_iommu_dc *riscv_iommu_get_dc(struct riscv_iommu_device *iomm
> break;
> }
>
> - ptr = riscv_iommu_get_pages(iommu, 0);
> + ptr = riscv_iommu_get_pages(iommu, SZ_4K);
> if (!ptr)
> return NULL;
>
> @@ -698,7 +699,7 @@ static int riscv_iommu_iodir_alloc(struct riscv_iommu_device *iommu)
> }
>
> if (!iommu->ddt_root) {
> - iommu->ddt_root = riscv_iommu_get_pages(iommu, 0);
> + iommu->ddt_root = riscv_iommu_get_pages(iommu, SZ_4K);
> iommu->ddt_phys = __pa(iommu->ddt_root);
> }
>
> --
> 2.43.0
>
Reviewed-by: Tomasz Jeznach <tjeznach at rivosinc.com>
Thanks,
- Tomasz
More information about the linux-riscv
mailing list