Commit 2b03bcae authored by David Howells's avatar David Howells Committed by Jakub Kicinski

kcm: Support MSG_SPLICE_PAGES

Make AF_KCM sendmsg() support MSG_SPLICE_PAGES.  This causes pages to be
spliced from the source iterator if possible.

This allows ->sendpage() to be replaced by something that can handle
multiple multipage folios in a single transaction.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
cc: Tom Herbert <tom@herbertland.com>
cc: Tom Herbert <tom@quantonium.net>
cc: Cong Wang <cong.wang@bytedance.com>
cc: Jens Axboe <axboe@kernel.dk>
cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 28cfea98
......@@ -989,9 +989,29 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
merge = false;
}
if (msg->msg_flags & MSG_SPLICE_PAGES) {
copy = msg_data_left(msg);
if (!sk_wmem_schedule(sk, copy))
goto wait_for_memory;
err = skb_splice_from_iter(skb, &msg->msg_iter, copy,
sk->sk_allocation);
if (err < 0) {
if (err == -EMSGSIZE)
goto wait_for_memory;
goto out_error;
}
copy = err;
skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG;
sk_wmem_queued_add(sk, copy);
sk_mem_charge(sk, copy);
if (head != skb)
head->truesize += copy;
} else {
copy = min_t(int, msg_data_left(msg),
pfrag->size - pfrag->offset);
if (!sk_wmem_schedule(sk, copy))
goto wait_for_memory;
......@@ -1004,7 +1024,8 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
/* Update the skb. */
if (merge) {
skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy);
skb_frag_size_add(
&skb_shinfo(skb)->frags[i - 1], copy);
} else {
skb_fill_page_desc(skb, i, pfrag->page,
pfrag->offset, copy);
......@@ -1012,6 +1033,8 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
}
pfrag->offset += copy;
}
copied += copy;
if (head != skb) {
head->len += copy;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment