linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Liam R. Howlett" <Liam.Howlett@oracle.com>
To: "David Hildenbrand (Red Hat)" <david@kernel.org>
Cc: Peter Xu <peterx@redhat.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Mike Rapoport <rppt@kernel.org>,
	Muchun Song <muchun.song@linux.dev>,
	Nikita Kalyazin <kalyazin@amazon.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Axel Rasmussen <axelrasmussen@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	James Houghton <jthoughton@google.com>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Hugh Dickins <hughd@google.com>, Michal Hocko <mhocko@suse.com>,
	Ujwal Kundur <ujwal.kundur@gmail.com>,
	Oscar Salvador <osalvador@suse.de>,
	Suren Baghdasaryan <surenb@google.com>,
	Andrea Arcangeli <aarcange@redhat.com>
Subject: Re: [PATCH v4 0/4] mm/userfaultfd: modulize memory types
Date: Fri, 7 Nov 2025 11:55:01 -0500	[thread overview]
Message-ID: <bqbpshgjulakvpgykagfuez6ljnzwyzzv6sgepc4akewfh5q6y@bh6ritosdmmq> (raw)
In-Reply-To: <29da6069-1d41-4b15-be95-5c1889a37aa0@kernel.org>

* David Hildenbrand (Red Hat) <david@kernel.org> [251107 05:16]:
> [wondering how my mail client decides to use random mail aliases at this
> point. The kernel.org change seems to confuse something :) ]
> 
> > > 
> > > > 
> > > > uffd_flag_t has been removed.  This was turning into a middleware and
> > > > it is not necessary.  Neither is supported_ioctls.
> > > 
> > > I assume you mean the entries that were proposed in Peters series, not
> > > something that is upstream.
> > 
> > No.  This is upstream today.
> 
> Ah, you mean *uffd_flags_t*. I was confused there for a second when grepping
> the codebase.
> 
> Yeah, not sad to see that go ;)

Ah, my bad.  I even continued to make that mistake later in my reply
here.


...

> > > 
> > > After calling err = info->op(info);
> > > 
> > > Couldn't that callback just deal with the -ENOENT case?
> > > 
> > > So in case of increment/failed_do_unlock, maybe we could find a way to just
> > > let the ->copy etc communicate/perform that directly.
> > 
> > The failure case is only detected after getting a folio, but will need
> > to 'retry' (copy is the only one that does a retry).  Retry gets the
> > destination vma, where the vm_ops comes from.  This is why you need to
> > return to the loop.  So it's not that simple to moving it into the
> > function.
> 
> 
> In mfill_copy_loop() we have
> 
> 		err = info->op(info);
> 		cond_resched();
> 		if (unlikely(err == -ENOENT)) {
> 			err = info->uffd_ops->failed_do_unlock(info);
> 			if (unlikely(err))
> 				return err; /* Unlocked already */
> 
> 			return -ENOENT;
> 		} else {
> 			VM_WARN_ON_ONCE(info->foliop);
> 		}
> 
> 		if (!err) {
> 			uffd_info_inc(info);
> 			if (fatal_signal_pending(current))
> 				err = -EINTR;
> 		}
> 
> 
> Just to be clear, I was thinking about moving the failed_do_unlock()
> handling on -ENOENT into the info->op(). And the inc as well. (different)
> Return values could indicate what we have or don't have to do.

I'm not sure on the structure that people want to have in the end.  I
moved the unlock here because the normal unlocking remains at the same
level and was easier to see in bisect-able chunks.  The annoying name
was to indicate ti was returned unlocked, and the comment above as well.

I honestly wonder if the complication of this bug fix is worth leaving a
folio sitting around.  It's to do with low-memory and avoiding
re-acquiring a folio, AFAICT.  It's a lot of complication if it's just
for a corner case, but maybe it happens a lot or I'm missing something -
I don't know.

...

> > > >           .page_shift             =       uffd_page_shift,
> > > 
> > > Fortunately, this is not required. The only user in move_present_ptes()
> > > moves *real* PTEs, and nothing else (no hugetlb PTEs that are PMDs etc. in
> > > disguise).
> > 
> > The hugetlb code had a different value, so I did extract it when I
> > Iunited mfill_atomic() and mfill_atomic_hugetlb().  I am sure there are
> > other changes that could be removed as well, but to logically follow the
> > changes through each step it seemed easier to extract everything that
> > was different into its own function pointer.
> 
> 
> Let me elaborate to see if I am missing something.
> 
> page_shift() is only invoked from move_present_ptes().
> 
> move_present_ptes() works on individual PAGE_SIZE PTEs.
> 
> hugetlb does not support UFFDIO_MOVE, see how validate_move_areas() rejects
> VM_HUGETLB.
> 
> Also, move_present_ptes() wouldn't ever do anything on large folios, see
> move_present_ptes() where we have a
> 
> if (folio_test_large(src_folio) ||
>     ...
> 	err = -EBUSY;
> 	goto out;
> }
> 
> So I think the page_shift() callback can simply be dropped?

Yes, looks like it.

> 
> > 
> > > 
> > > >           .complete_register      =       uffd_complete_register,
> > > > };
> > > > 
> > > 
> > > So, the design is to callback into the memory-type handler, which will then
> > > use exported uffd functionality to get the job done.
> > > 
> > > This nicely abstracts hugetlb handling, but could mean that any code
> > > implementing this interface has to built up on exported uffd functionality
> > > (not judging, just saying).
> > > 
> > > As we're using the callbacks as an indication whether features are
> > > supported, we cannot easily leave them unset to fallback to the default
> > > handling.
> > > 
> > > Of course, we could use some placeholder, magic UFFD_DEFAULT_HANDLER keyword
> > > to just use the uffd_* stuff without exporting them.
> > > 
> > > So NULL would mean "not supported" and "UFFD_DEFAULT_HANDLER" would mean "no
> > > special handling needed".
> > > 
> > > Not sure how often that would be the case, though. For shmem it would
> > > probably only be the poison callback, for others, I am not sure.
> > 
> > There are certainly a lot of this we would not want to export.  My
> > initial thought was to create two function pointers: one for operations
> > that can be replaced, and one for basic functions that always have a
> > default.  We could do this with two function pointers, either tiered or
> > at the same level.
> > 
> > Most of this is to do with hugetlb having its own code branch into its
> > own loop.  We could even create an op that is returned that only lives
> > in mm/userfaultfd.c and has two variants: hugetlb and not_hugetlb.  This
> > would indeed need the hugetlb.h again, but I'm pretty sure that removing
> > the header is 'too big of a change' anyways.
> 
> Yes, I think leaving hugetlb be the only special thing around would be a
> sensible thing to do. But I would expect shmem+anon etc. to be completely
> modularizable (is that a word?).
> 
> Having a high-level API draft of that could be very valuable.
> 
> > 
> > 
> > > 
> > > > Where guest-memfd needs to write the one function:
> > > > guest_memfd_pte_continue(), from what I understand.
> > > 
> > > It would be interesting to see how that one would look like.
> > > 
> > > I'd assume fairly similar to shmem_mfill_atomic_pte_continue()?
> > > 
> > > Interesting question would be, how to avoid the code duplication there.
> > 
> > Yes, this is where I was going here.  I was going to try and finish this
> > off by creating that one function.  That, and reducing the vm_ops to a
> > more sensible size (as mentioned above).
> > 
> > shmem_mfill_atomic_pte_continue() could be cut up into function segments
> > to avoid the duplication.  Or we could make a wrapper that accepts a
> > function pointer.. there are certainly ways we can mitigate duplication.
> > 
> 
> Seeing a prototype of that would be nice.
> 

I'm not up for investing more time into uffd.

...

> > 
> > I think there might be value uniting both hugetlb and the normal code
> > path, even if the operations call signatures are aligned and we just use
> > a pointer to a struct within the "while (src_addr < src_start + len)"
> > loop that exists today.
> > 
> 
> Right, what would be valuable is still leaving hugetlb be special, but
> minimizing the degree to which mm/userfaultfd.c would have to care / treat
> it specially.

The question is how special you want it to remain, I guess.

Thanks,
Liam


      reply	other threads:[~2025-11-07 16:55 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 23:14 Peter Xu
2025-10-14 23:14 ` [PATCH v4 1/4] mm: Introduce vm_uffd_ops API Peter Xu
2025-10-20 14:18   ` David Hildenbrand
2025-10-14 23:14 ` [PATCH v4 2/4] mm/shmem: Support " Peter Xu
2025-10-20 14:18   ` David Hildenbrand
2025-10-14 23:15 ` [PATCH v4 3/4] mm/hugetlb: " Peter Xu
2025-10-20 14:19   ` David Hildenbrand
2025-10-14 23:15 ` [PATCH v4 4/4] mm: Apply vm_uffd_ops API to core mm Peter Xu
2025-10-20 13:34 ` [PATCH v4 0/4] mm/userfaultfd: modulize memory types David Hildenbrand
2025-10-20 14:12   ` Peter Xu
2025-10-21 15:51     ` Liam R. Howlett
2025-10-21 16:28       ` Peter Xu
2025-10-30 17:13         ` Liam R. Howlett
2025-10-30 18:00           ` Nikita Kalyazin
2025-10-30 19:07           ` Peter Xu
2025-10-30 19:55             ` Peter Xu
2025-10-30 20:23               ` Lorenzo Stoakes
2025-10-30 21:13                 ` Peter Xu
2025-10-30 21:27                   ` Peter
2025-11-03 20:01                   ` David Hildenbrand (Red Hat)
2025-11-03 20:46                     ` Peter Xu
2025-11-03 21:27                       ` David Hildenbrand (Red Hat)
2025-11-03 22:49                         ` Peter Xu
2025-11-04  7:10                           ` Lorenzo Stoakes
2025-11-04 14:18                           ` David Hildenbrand (Red Hat)
2025-11-04  7:21                         ` Mike Rapoport
2025-11-04 12:23                           ` David Hildenbrand (Red Hat)
2025-11-06 16:32                           ` Liam R. Howlett
2025-11-09  7:11                             ` Mike Rapoport
2025-11-10 16:34                               ` Liam R. Howlett
2025-11-11 10:05                                 ` Mike Rapoport
2025-10-30 20:52               ` Liam R. Howlett
2025-10-30 21:33                 ` Peter Xu
2025-10-30 20:24             ` Liam R. Howlett
2025-10-30 21:26               ` Peter Xu
2025-11-03 16:11           ` Mike Rapoport
2025-11-03 18:43             ` Liam R. Howlett
2025-11-05 21:23           ` David Hildenbrand
2025-11-06 16:16             ` Liam R. Howlett
2025-11-07 10:16               ` David Hildenbrand (Red Hat)
2025-11-07 16:55                 ` Liam R. Howlett [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bqbpshgjulakvpgykagfuez6ljnzwyzzv6sgepc4akewfh5q6y@bh6ritosdmmq \
    --to=liam.howlett@oracle.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=david@kernel.org \
    --cc=hughd@google.com \
    --cc=jthoughton@google.com \
    --cc=kalyazin@amazon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=peterx@redhat.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=ujwal.kundur@gmail.com \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox