On Fri, Dec 17, 2021 at 12:39 PM Linus Torvalds torvalds@linux-foundation.org wrote:
At the time of such a shared pin, you can do what we already do: re-use the page if it has a refcount of 1. Or do an early COW event (feel free to avoid the "mark it writable and dirty").
Note that this also depends on fork() doing the right thing, marking things for "a fork() can not share this page any more".
Which it does for regular pages, and is exactly what that page_needs_cow_for_dma() logic is all about (and the special write_protect_seq around gup/fork).
I do believe that huge-pages don't do it right. But I think that as you try to fix hugepages, you are now breaking the normal case.
If all your logic was only about hugepages, I wouldn't care so much. But you are playing questionable games with code that I think is correct.
Please explain why.
Linus