Skip to content

Commit 23a55f4

Browse files
ofirgallaxboe
authored andcommitted
net: introduce helper sendpages_ok()
Network drivers are using sendpage_ok() to check the first page of an iterator in order to disable MSG_SPLICE_PAGES. The iterator can represent list of contiguous pages. When MSG_SPLICE_PAGES is enabled skb_splice_from_iter() is being used, it requires all pages in the iterator to be sendable. Therefore it needs to check that each page is sendable. The patch introduces a helper sendpages_ok(), it returns true if all the contiguous pages are sendable. Drivers who want to send contiguous pages with MSG_SPLICE_PAGES may use this helper to check whether the page list is OK. If the helper does not return true, the driver should remove MSG_SPLICE_PAGES flag. Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Ofir Gal <ofir.gal@volumez.com> Acked-by: Jakub Kicinski <kuba@kernel.org> Link: https://lore.kernel.org/r/20240718084515.3833733-2-ofir.gal@volumez.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 79c6c60 commit 23a55f4

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

include/linux/net.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,25 @@ static inline bool sendpage_ok(struct page *page)
322322
return !PageSlab(page) && page_count(page) >= 1;
323323
}
324324

325+
/*
326+
* Check sendpage_ok on contiguous pages.
327+
*/
328+
static inline bool sendpages_ok(struct page *page, size_t len, size_t offset)
329+
{
330+
struct page *p = page + (offset >> PAGE_SHIFT);
331+
size_t count = 0;
332+
333+
while (count < len) {
334+
if (!sendpage_ok(p))
335+
return false;
336+
337+
p++;
338+
count += PAGE_SIZE;
339+
}
340+
341+
return true;
342+
}
343+
325344
int kernel_sendmsg(struct socket *sock, struct msghdr *msg, struct kvec *vec,
326345
size_t num, size_t len);
327346
int kernel_sendmsg_locked(struct sock *sk, struct msghdr *msg,

0 commit comments

Comments
 (0)