Re: [RFC PATCH kernel] iommufd: Allow mapping from KVM's guest_memfd
From: Sean Christopherson
Date: Thu Feb 26 2026 - 19:29:07 EST
On Thu, Feb 26, 2026, Jason Gunthorpe wrote:
> On Thu, Feb 26, 2026 at 02:40:50PM -0800, Sean Christopherson wrote:
>
> > > If guestmemfd is fully pinned and cannot free memory outside of
> > > truncate that may be good enough (though somehow I think that is not
> > > the case)
> >
> > With in-place conversion, PUNCH_HOLE and private=>shared conversions are the only
> > two ways to partial "remove" memory from guest_memfd, so it may really be that
> > simple.
>
> PUNCH_HOLE can be treated like truncate right?
Yep. Tomato, tomato. I called out PUNCH_HOLE because guest_memfd doesn't support
a pure truncate, the size is immutable (ignoring that destroying the inode is kinda
sorta a truncate).
> I'm confused though - I thought in-place conversion ment that
> private<->shared re-used the existing memory allocation? Why does it
> "remove" memory?
>
> Or perhaps more broadly, where is the shared memory kept/accessed in
> these guest memfd systems?
Oh, the physical memory doesn't change, but the IOMMU might care that memory is
being converted from private<=>shared. AMD IOMMU probably doesn't? But unless
Intel IOMMU reuses S-EPT from the VM itself, the IOMMU page tables will need to
be updated.
FWIW, conceptually, we're basically treating private=>shared in particular as
"free() + alloc()" that just so happens to guarantee the allocated page is the same.