Re: [PATCH] mm: userfaultfd: add UFFDIO_CONTINUE_MODE_WP to install WP PTEs

From: Peter Xu
Date: Tue Feb 14 2023 - 19:33:36 EST


On Tue, Feb 14, 2023 at 02:37:51PM -0800, Axel Rasmussen wrote:
> Agreed, it would likely be a nice cleanup. Peter, any objections? I
> wouldn't mind writing a commit to do this sort of refactor, and rebase
> my change on top of that.

No objection here. Personally I actually prefer keeping the parameters
around if possible because it's straightforward and no thinking of any
possible indirect accesses all over the place. But maybe growing as long as
8 is still a moot point.. It's just that I don't really know whether it'll
look that good if we put everything into a struct*.

Things like src_start/dst_start/.. do not look good to be there: each layer
could loop over its own range of start/end/... so even if not in the
function parameter we'll need a variable to hold them anyway.

But I do see a few low hanging fruits:

- I don't see why we need to pass over mmap_changing over all of the
__mcopy_atomic() callers. One chance is we simply pass in the ctx* to
replace "dst_mm + mmap_changing".

- Merge mcopy_atomic_mode and mode, having last 2 bits for the existing
three modes, then bit 3 for WP, good enough to set it for the new case.

- Optionally, we can avoid passing over dst_mm/src_mm all around, when
dst_vma/src_vma is there?

How about we start from simple?

--
Peter Xu