Re: [PATCH v2] iommufd: only hold references to files memfd_pin_folios() can pin
From: Jason Gunthorpe
Date: Wed Nov 18 2026 - 14:03:44 EST
> [ ... 61 lines skipped ... ]
> @@ -515,6 +517,18 @@ int iopt_map_file_pages(struct iommufd_ctx *ictx, struct io_pagetable *iopt,
> if (!file)
> return -EBADF;
>
> + /*
> + * iopt_pages keeps a reference to the file until the mapping is
> + * destroyed, so only accept the files memfd_pin_folios() is able
> + * to pin. Any other fd, in particular one that itself owns an
> + * iommufd_ctx (iommufd, vfio, ...), would put the file into a
> + * reference cycle with this iommufd and never be released.
> + */
> + if (!shmem_file(file) && !is_file_hugepages(file)) {
> + fput(file);
> + return -EINVAL;
> + }
[Severity: High]
Does calling shmem_file() here break the build when CONFIG_IOMMUFD=m and
CONFIG_SHMEM=y?
shmem_file() is only an inline stub when CONFIG_SHMEM is disabled; when
CONFIG_SHMEM=y it is defined out-of-line in mm/shmem.c without an
EXPORT_SYMBOL_GPL(), so linking iommufd.ko fails at modpost with an undefined
symbol error.
Please send another version fixing this.. I guess we need to export
it, but maybe that says the mm should instead provide a helper along
side the pin helper that is "is file compatible with
memfd_pin_folios()" ?
Two patches and CC the mm list too.
--
Jason