diff mbox series

[06/48] iov_iter: Add copy_folio_to_iter()

Message ID 20211208042256.1923824-7-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Folios for 5.17 | expand

Commit Message

Matthew Wilcox Dec. 8, 2021, 4:22 a.m. UTC
This wrapper around copy_page_to_iter() works because copy_page_to_iter()
handles compound pages correctly.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/uio.h | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Christoph Hellwig Dec. 23, 2021, 6:55 a.m. UTC | #1
On Wed, Dec 08, 2021 at 04:22:14AM +0000, Matthew Wilcox (Oracle) wrote:
> +static inline size_t copy_folio_to_iter(struct folio *folio, size_t offset,
> +		size_t bytes, struct iov_iter *i)
> +{
> +	return copy_page_to_iter((struct page *)folio, offset, bytes, i);
> +}

I think we had this 2 or three series ago, but these open coded casts
are a bad idea.  I think we need a proper and well documented helper for
them.
Matthew Wilcox Dec. 23, 2021, 2:22 p.m. UTC | #2
On Wed, Dec 22, 2021 at 10:55:20PM -0800, Christoph Hellwig wrote:
> On Wed, Dec 08, 2021 at 04:22:14AM +0000, Matthew Wilcox (Oracle) wrote:
> > +static inline size_t copy_folio_to_iter(struct folio *folio, size_t offset,
> > +		size_t bytes, struct iov_iter *i)
> > +{
> > +	return copy_page_to_iter((struct page *)folio, offset, bytes, i);
> > +}
> 
> I think we had this 2 or three series ago, but these open coded casts
> are a bad idea.  I think we need a proper and well documented helper for
> them.

I don't want to see casts between folio & page in most code, but I think
having it in this kind of helper is fine.  It literally exists in order
to document that the callee handles folios correctly.
diff mbox series

Patch

diff --git a/include/linux/uio.h b/include/linux/uio.h
index 6350354f97e9..8479cf46b5b1 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -10,6 +10,7 @@ 
 #include <uapi/linux/uio.h>
 
 struct page;
+struct folio;
 struct pipe_inode_info;
 
 struct kvec {
@@ -146,6 +147,12 @@  size_t _copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i);
 size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i);
 size_t _copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i);
 
+static inline size_t copy_folio_to_iter(struct folio *folio, size_t offset,
+		size_t bytes, struct iov_iter *i)
+{
+	return copy_page_to_iter((struct page *)folio, offset, bytes, i);
+}
+
 static __always_inline __must_check
 size_t copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i)
 {