On Wed, Mar 24, 2021 at 11:09:27AM +0300, Andrey Gruzdev wrote: > > I'm also looking into introducing UFFD_FEATURE_WP_UNALLOCATED so as to > > wr-protect page holes too for a uffd-wp region when the feature bit is set. > > With that feature we should be able to avoid pre-fault as what we do in the > > last patch of this series. However even if that can work out, we'll still > > need > > this for old kernel anyways. > > I'm curious this new feature is based on adding wr-protection at the level of > VMAs, > so we won't miss write faults for missing pages?
I think we can do it with multiple ways. The most efficient one would be wr-protect the range during uffd-wp registration, so as you said it'll be per-vma attribute. However that'll change the general semantics of uffd-wp as normally we need registration and explicit wr-protect. Then it'll still be pte-based for faulted in pages (the ones we wr-protected during registration will still be), however for the rest it'll become vma-based. It's indeed a bit confusing. The other way is we can fault in zero page during UFFDIO_WRITEPROTECT. However that's less efficient, since it's close to pre-fault on read but it's just slightly more cleaner than doing it in userspace. When I rethink about this it may not worth it to do in kernel if userspace can achieve things similar. So let's stick with current solution; that idea may need more thoughts.. Thanks, -- Peter Xu