Re: [PATCH v3 1/6] mm: userfaultfd: generic continue for non hugetlbfs
From: Peter Xu
Date: Fri Jun 20 2025 - 11:22:05 EST
Hi, Nikita,
On Fri, Jun 20, 2025 at 01:00:24PM +0100, Nikita Kalyazin wrote:
> Thanks for explaining that. I played a bit with it myself and it appears to
> be working for the MISSING mode for both shmem and guest_memfd. Attaching
[1]
> my sketch below. Please let me know if this is how you see it.
>
> I found that arguments and return values are significantly different between
> the two request types, which may be a bit confusing, although we do not
> expect many callers of those.
Indeed. Actually since I didn't yet get your reply, early this week I gave
it a shot, and then I found the same thing that it'll be nice to keep the
type checks all over the places. It'll also be awkward if we want to add
MISSING into the picture with the current req() interface (btw, IIUC you
meant MINOR above, not MISSING).
Please have a look at what I came up with. I didn't yet got a chance to
post it, but it did compile all fine and pass the smoke tests here. Feel
free to take it over if you think that makes sense to you, or I can also
post it officially after some more tests.
So, ultimately I introduced a vm_uffd_ops to keep all the type checks. I
don't think I like the uffd_copy() interfacing too much, but it should
still be the minimum changeset I can think of to generalize shmem as an
userfault user / module, and finally drop "linux/shmem_fs.h" inclusion in
the last patch.
It's also unfortunate that hugetlb won't be able to already use the API,
similar to why we have hugetlb's fault() to BUG() and hard-coded it in
handle_mm_fault(). However it'll at least start to use the rest API all
fine, so as to generalize some hugetlb checks.
The shmem definition looks like this:
static const vm_uffd_ops shmem_uffd_ops = {
.uffd_features = __VM_UFFD_FLAGS,
.uffd_ioctls = BIT(_UFFDIO_COPY) |
BIT(_UFFDIO_ZEROPAGE) |
BIT(_UFFDIO_WRITEPROTECT) |
BIT(_UFFDIO_CONTINUE) |
BIT(_UFFDIO_POISON),
.uffd_get_folio = shmem_uffd_get_folio,
.uffd_copy = shmem_mfill_atomic_pte,
};
Then guest-memfd can set (1) VM_UFFD_MINOR, (2) _UFFDIO_CONTINUE and
provide uffd_get_folio() for supporting MINOR.
Let me know what do you think.
Thanks,
===8<===