Re: [PATCH RFC v3 03/88] mm: shmem: Implement guest_memfd provider operations for tmpfs
From: Christian Brauner
Date: Fri Nov 20 2026 - 03:52:23 EST
On Fri, Nov 06, 2026 at 04:36:37PM -0800, Ackerley Tng via B4 Relay wrote:
> I put guest_memfd_provider_operations as a pointer in struct
> file_operations. Being in file_operations generalizes well to other kinds
> of providers, like devices, which don't have their own super_operations.
> @@ -1960,6 +1961,9 @@ struct file_operations {
> int (*uring_cmd_iopoll)(struct io_uring_cmd *, struct io_comp_batch *,
> unsigned int poll_flags);
> int (*mmap_prepare)(struct vm_area_desc *);
> +#ifdef CONFIG_KVM_GUEST_MEMFD
> + const struct guest_memfd_provider_operations *gmem_provider_ops;
> +#endif
> } __randomize_layout;
Sorry, no! struct file_operations is not the place to hang KVM specific
callbacks off of. We didn't let KHO/LUO hang an ops table off of struct
file either and nobody else is getting one in file_operations.
LUO registers handlers that recognize their files by f_op instead,
memfd_luo just uses shmem_file(). And KVM already does the same for
VFIO: kvm_vfio_file_is_valid() -> vfio_file_is_valid(). Do the same for
providers and leave struct file_operations alone.
> Setting it in shmem_dir_operations allows directory file descriptors
> opened on a tmpfs mount to provide memory to guest_memfd.
That is weird. A directory fd is not an allocator handle. The folios
aren't backed by any inode in that tmpfs instance but they're charged
against its max_blocks. Which means statfs() shows space as used that no
file in the filesystem accounts for and that you can't get back by
removing files.
And also with CONFIG_KVM_GUEST_MEMFD every tmpfs directory on the system
gets its own file_operations just for this?
> +#ifdef CONFIG_KVM_GUEST_MEMFD
> + inode->i_fop = &shmem_dir_operations;
> +#else
> inode->i_fop = &simple_offset_dir_operations;
> +#endif
Afaict what you actually want from tmpfs is a mempolicyj a size limit
and noswap? guest_memfd already has a mempolicy. Teach guest_memfd the
rest instead of turning tmpfs mounts into a memory pool?