[PATCH 17/19] iommu/riscv: Update to use iommu_alloc_pages_node_lg2()
Tomasz Jeznach
tjeznach at rivosinc.com
Wed Feb 5 21:30:05 PST 2025
On Tue, Feb 04, 2025 at 02:34:58PM -0400, Jason Gunthorpe wrote:
> One part of RISCV already has a computed size, the other part seems to use
> PAGE_SIZE (which is probably SZ_4K?). Convert the call.
>
> 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 549bd8d0615d75..b7cee3d651b179 100644
> --- a/drivers/iommu/riscv/iommu.c
> +++ b/drivers/iommu/riscv/iommu.c
> @@ -65,13 +65,15 @@ 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_lg2(dev_to_node(iommu->dev),
> + GFP_KERNEL_ACCOUNT,
> + order_base_2(size));
> if (unlikely(!addr))
> return NULL;
>
> @@ -161,9 +163,8 @@ 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, queue_size);
> queue->phys = __pa(queue->base);
All allocations must be 4k aligned, including sub-page allocs.
Note from IOMMU/RISC-V spec:
"If the command-queue has 256 or fewer entries then the base address of the
queue is always aligned to 4-KiB."
I can't find this to be guaranteed with new allocation API.
> } 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, PAGE_SIZE);
> 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, PAGE_SIZE);
> iommu->ddt_phys = __pa(iommu->ddt_root);
> }
>
> --
> 2.43.0
>
best,
- Tomasz
More information about the Linux-rockchip
mailing list