Re: [PATCH v2 4/7] iov_iter: new iov_iter_pin_pages*() routines

From: Al Viro
Date: Wed Sep 14 2022 - 12:43:13 EST


On Wed, Sep 14, 2022 at 04:52:33PM +0200, Jan Kara wrote:
> > =================================================================================
> > CASE 5: Pinning in order to write to the data within the page
> > -------------------------------------------------------------
> > Even though neither DMA nor Direct IO is involved, just a simple case of "pin,
> > write to a page's data, unpin" can cause a problem. Case 5 may be considered a
> > superset of Case 1, plus Case 2, plus anything that invokes that pattern. In
> > other words, if the code is neither Case 1 nor Case 2, it may still require
> > FOLL_PIN, for patterns like this:
> >
> > Correct (uses FOLL_PIN calls):
> > pin_user_pages()
> > write to the data within the pages
> > unpin_user_pages()
> >
> > INCORRECT (uses FOLL_GET calls):
> > get_user_pages()
> > write to the data within the pages
> > put_page()
> > =================================================================================
>
> Yes, that was my point.

The thing is, at which point do we pin those pages? pin_user_pages() works by
userland address; by the time we get to any of those we have struct page
references and no idea whether they are still mapped anywhere.

How would that work? What protects the area where you want to avoid running
into pinned pages from previously acceptable page getting pinned? If "they
must have been successfully unmapped" is a part of what you are planning, we
really do have a problem...