iommu/pages: Formalize the freelist API
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 8 Apr 2025 16:53:56 +0000 (13:53 -0300)
committerJoerg Roedel <jroedel@suse.de>
Thu, 17 Apr 2025 14:22:40 +0000 (16:22 +0200)
commit13f43d7cf3e0570004a0d960bc1be23db827c2ff
treef363566d8bd10eb941836f8a9fb4c0ea96663248
parentf5af4a4f7ccb58c0022175b3457c840a77463e7a
iommu/pages: Formalize the freelist API

We want to get rid of struct page references outside the internal
allocator implementation. The free list has the driver open code something
like:

   list_add_tail(&virt_to_page(ptr)->lru, freelist);

Move the above into a small inline and make the freelist into a wrapper
type 'struct iommu_pages_list' so that the compiler can help check all the
conversion.

This struct has also proven helpful in some future ideas to convert to a
singly linked list to get an extra pointer in the struct page, and to
signal that the pages should be freed with RCU.

Use a temporary _Generic so we don't need to rename the free function as
the patches progress.

Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Tested-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/8-v4-c8663abbb606+3f7-iommu_pages_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommu-pages.c
drivers/iommu/iommu-pages.h
include/linux/iommu.h