From: David Hildenbrand <david@redhat.com>
To: David Howells <dhowells@redhat.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Christoph Hellwig <hch@infradead.org>
Cc: Matthew Wilcox <willy@infradead.org>,
Jens Axboe <axboe@kernel.dk>, Jan Kara <jack@suse.cz>,
Jeff Layton <jlayton@kernel.org>,
Logan Gunthorpe <logang@deltatee.com>,
linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
John Hubbard <jhubbard@nvidia.com>,
linux-mm@kvack.org
Subject: Re: [PATCH v8 02/10] iov_iter: Add a function to extract a page list from an iterator
Date: Tue, 24 Jan 2023 15:27:29 +0100 [thread overview]
Message-ID: <1b1eb3d8-c6b4-b264-1baa-1b3eb088173d@redhat.com> (raw)
In-Reply-To: <20230123173007.325544-3-dhowells@redhat.com>
On 23.01.23 18:29, David Howells wrote:
> Add a function, iov_iter_extract_pages(), to extract a list of pages from
> an iterator. The pages may be returned with a pin added or nothing,
> depending on the type of iterator.
>
> Add a second function, iov_iter_extract_mode(), to determine how the
> cleanup should be done.
>
> There are two cases:
>
> (1) ITER_IOVEC or ITER_UBUF iterator.
>
> Extracted pages will have pins (FOLL_PIN) obtained on them so that a
> concurrent fork() will forcibly copy the page so that DMA is done
> to/from the parent's buffer and is unavailable to/unaffected by the
> child process.
>
> iov_iter_extract_mode() will return FOLL_PIN for this case. The
> caller should use something like folio_put_unpin() to dispose of the
> page.
>
> (2) Any other sort of iterator.
>
> No refs or pins are obtained on the page, the assumption is made that
> the caller will manage page retention.
>
> iov_iter_extract_mode() will return 0. The pages don't need
> additional disposal.
>
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Al Viro <viro@zeniv.linux.org.uk>
> cc: Christoph Hellwig <hch@lst.de>
> cc: John Hubbard <jhubbard@nvidia.com>
> cc: David Hildenbrand <david@redhat.com>
> cc: Matthew Wilcox <willy@infradead.org>
> cc: linux-fsdevel@vger.kernel.org
> cc: linux-mm@kvack.org
> ---
>
> Notes:
> ver #8)
> - It seems that all DIO is supposed to be done under FOLL_PIN now, and not
> FOLL_GET, so switch to only using pin_user_pages() for user-backed
> iters.
> - Wrap an argument in brackets in the iov_iter_extract_mode() macro.
> - Drop the extract_flags argument to iov_iter_extract_mode() for now
> [hch].
>
> ver #7)
> - Switch to passing in iter-specific flags rather than FOLL_* flags.
> - Drop the direction flags for now.
> - Use ITER_ALLOW_P2PDMA to request FOLL_PCI_P2PDMA.
> - Disallow use of ITER_ALLOW_P2PDMA with non-user-backed iter.
> - Add support for extraction from KVEC-type iters.
> - Use iov_iter_advance() rather than open-coding it.
> - Make BVEC- and KVEC-type skip over initial empty vectors.
>
> ver #6)
> - Add back the function to indicate the cleanup mode.
> - Drop the cleanup_mode return arg to iov_iter_extract_pages().
> - Pass FOLL_SOURCE/DEST_BUF in gup_flags. Check this against the iter
> data_source.
>
> ver #4)
> - Use ITER_SOURCE/DEST instead of WRITE/READ.
> - Allow additional FOLL_* flags, such as FOLL_PCI_P2PDMA to be passed in.
>
> ver #3)
> - Switch to using EXPORT_SYMBOL_GPL to prevent indirect 3rd-party access
> to get/pin_user_pages_fast()[1].
>
> include/linux/uio.h | 22 +++
> lib/iov_iter.c | 320 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 342 insertions(+)
>
> diff --git a/include/linux/uio.h b/include/linux/uio.h
> index 46d5080314c6..a8165335f8da 100644
> --- a/include/linux/uio.h
> +++ b/include/linux/uio.h
> @@ -363,4 +363,26 @@ static inline void iov_iter_ubuf(struct iov_iter *i, unsigned int direction,
> /* Flags for iov_iter_get/extract_pages*() */
> #define ITER_ALLOW_P2PDMA 0x01 /* Allow P2PDMA on the extracted pages */
>
> +ssize_t iov_iter_extract_pages(struct iov_iter *i, struct page ***pages,
> + size_t maxsize, unsigned int maxpages,
> + unsigned int extract_flags, size_t *offset0);
> +
> +/**
> + * iov_iter_extract_mode - Indicate how pages from the iterator will be retained
> + * @iter: The iterator
> + *
> + * Examine the iterator and indicate by returning FOLL_PIN or 0 as to how, if
> + * at all, pages extracted from the iterator will be retained by the extraction
> + * function.
> + *
> + * FOLL_PIN indicates that the pages will have a pin placed in them that the
> + * caller must unpin. This is must be done for DMA/async DIO to force fork()
> + * to forcibly copy a page for the child (the parent must retain the original
> + * page).
> + *
> + * 0 indicates that no measures are taken and that it's up to the caller to
> + * retain the pages.
> + */
> +#define iov_iter_extract_mode(iter) (user_backed_iter(iter) ? FOLL_PIN : 0)
> +
Does it make sense to move that to the patch where it is needed? (do we
need it at all anymore?)
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2023-01-24 14:27 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230123173007.325544-1-dhowells@redhat.com>
2023-01-23 17:29 ` David Howells
2023-01-23 18:21 ` Christoph Hellwig
2023-01-24 14:27 ` David Hildenbrand [this message]
2023-01-24 14:35 ` David Howells
2023-01-24 14:37 ` David Hildenbrand
2023-01-24 14:45 ` David Howells
2023-01-24 14:52 ` David Hildenbrand
2023-01-23 17:30 ` [PATCH v8 03/10] mm: Provide a helper to drop a pin/ref on a page David Howells
2023-01-23 18:21 ` Christoph Hellwig
2023-01-24 3:03 ` John Hubbard
2023-01-24 14:28 ` David Hildenbrand
2023-01-24 14:41 ` David Howells
2023-01-24 14:52 ` Christoph Hellwig
2023-01-24 14:53 ` David Hildenbrand
2023-01-24 15:04 ` David Howells
2023-01-23 17:30 ` [PATCH v8 10/10] mm: Renumber FOLL_PIN and FOLL_GET down David Howells
2023-01-23 18:25 ` Christoph Hellwig
2023-01-24 3:08 ` John Hubbard
2023-01-24 3:11 ` John Hubbard
2023-01-24 13:13 ` Jason Gunthorpe
2023-01-24 13:18 ` Christoph Hellwig
2023-01-24 13:43 ` Jason Gunthorpe
2023-01-24 13:40 ` David Howells
2023-01-24 13:46 ` David Howells
2023-01-24 13:47 ` Jason Gunthorpe
2023-01-24 13:57 ` David Howells
2023-01-24 14:00 ` Jason Gunthorpe
2023-01-24 14:02 ` Christoph Hellwig
2023-01-24 14:11 ` David Howells
2023-01-24 14:14 ` Jason Gunthorpe
2023-01-24 14:27 ` David Howells
2023-01-24 14:31 ` Jason Gunthorpe
2023-01-24 14:59 ` David Howells
2023-01-24 15:06 ` Jason Gunthorpe
2023-01-24 15:12 ` David Howells
2023-01-24 14:12 ` David Howells
2023-01-24 14:13 ` Christoph Hellwig
2023-01-24 14:25 ` David Howells
2023-01-24 7:05 ` David Howells
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=1b1eb3d8-c6b4-b264-1baa-1b3eb088173d@redhat.com \
--to=david@redhat.com \
--cc=axboe@kernel.dk \
--cc=dhowells@redhat.com \
--cc=hch@infradead.org \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=jhubbard@nvidia.com \
--cc=jlayton@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=logang@deltatee.com \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/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