Re: [PATCH v1 15/26] x86/virt/tdx: Extend tdx_page_array to support IOMMU_MT

Dave Hansen
2025-11-17T19:19:52Z

On 11/16/25 18:22, Xu Yilun wrote:
> +struct tdx_page_array *
> +tdx_page_array_create_iommu_mt(unsigned int iq_order, unsigned int nr_mt_pages)
> +{
> + unsigned int nr_entries = 2 + nr_mt_pages;
> + int ret;
> +
> + if (nr_entries > TDX_PAGE_ARRAY_MAX_NENTS)
> + return NULL;
> +
> + struct tdx_page_array *array __free(kfree) = kzalloc(sizeof(*array),
> + GFP_KERNEL);
> + if (!array)
> + return NULL;
> +
> + struct page *root __free(__free_page) = alloc_page(GFP_KERNEL |
> + __GFP_ZERO);
> + if (!root)
> + return NULL;
> +
> + struct page **pages __free(kfree) = kcalloc(nr_entries, sizeof(*pages),
> + GFP_KERNEL);
> + if (!pages)
> + return NULL;
> +
> + /* TODO: folio_alloc_node() is preferred, but need numa info */
> + struct folio *t_iq __free(folio_put) = folio_alloc(GFP_KERNEL |
> + __GFP_ZERO,
> + iq_order);
> + if (!t_iq)
> + return NULL;
> +
> + struct folio *t_ctxiq __free(folio_put) = folio_alloc(GFP_KERNEL |
> + __GFP_ZERO,
> + iq_order);
> + if (!t_ctxiq)
> + return NULL;
> +
> + ret = tdx_alloc_pages_bulk(nr_mt_pages, pages + 2);
> + if (ret)
> + return NULL;
> +
> + pages[0] = folio_page(no_free_ptr(t_iq), 0);
> + pages[1] = folio_page(no_free_ptr(t_ctxiq), 0);
> +
> + array->nr_pages = nr_entries;
> + array->pages = no_free_ptr(pages);
> + array->root = no_free_ptr(root);
> +
> + tdx_page_array_fill_root(array, 0);
> +
> + return no_free_ptr(array);
> +}
> +EXPORT_SYMBOL_GPL(tdx_page_array_create_iommu_mt);

Please endeavor to find another way to do this. This is virtually a
copy-and-paste of the earlier code. Please refactor it in way that you
don't need the copy-and-paste.