ipv4/udp: support externally provided ubufs
Teach ipv4/udp how to use external ubuf_info provided in msghdr and also prepare it for managed frags by sprinkling skb_zcopy_downgrade_managed() when it could mix managed and not managed frags. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
84ce071e38
commit
c445f31b3c
|
@ -1017,18 +1017,35 @@ static int __ip_append_data(struct sock *sk,
|
||||||
(!exthdrlen || (rt->dst.dev->features & NETIF_F_HW_ESP_TX_CSUM)))
|
(!exthdrlen || (rt->dst.dev->features & NETIF_F_HW_ESP_TX_CSUM)))
|
||||||
csummode = CHECKSUM_PARTIAL;
|
csummode = CHECKSUM_PARTIAL;
|
||||||
|
|
||||||
if (flags & MSG_ZEROCOPY && length && sock_flag(sk, SOCK_ZEROCOPY)) {
|
if ((flags & MSG_ZEROCOPY) && length) {
|
||||||
uarg = msg_zerocopy_realloc(sk, length, skb_zcopy(skb));
|
struct msghdr *msg = from;
|
||||||
if (!uarg)
|
|
||||||
return -ENOBUFS;
|
if (getfrag == ip_generic_getfrag && msg->msg_ubuf) {
|
||||||
extra_uref = !skb_zcopy(skb); /* only ref on new uarg */
|
if (skb_zcopy(skb) && msg->msg_ubuf != skb_zcopy(skb))
|
||||||
if (rt->dst.dev->features & NETIF_F_SG &&
|
return -EINVAL;
|
||||||
csummode == CHECKSUM_PARTIAL) {
|
|
||||||
paged = true;
|
/* Leave uarg NULL if can't zerocopy, callers should
|
||||||
zc = true;
|
* be able to handle it.
|
||||||
} else {
|
*/
|
||||||
uarg->zerocopy = 0;
|
if ((rt->dst.dev->features & NETIF_F_SG) &&
|
||||||
skb_zcopy_set(skb, uarg, &extra_uref);
|
csummode == CHECKSUM_PARTIAL) {
|
||||||
|
paged = true;
|
||||||
|
zc = true;
|
||||||
|
uarg = msg->msg_ubuf;
|
||||||
|
}
|
||||||
|
} else if (sock_flag(sk, SOCK_ZEROCOPY)) {
|
||||||
|
uarg = msg_zerocopy_realloc(sk, length, skb_zcopy(skb));
|
||||||
|
if (!uarg)
|
||||||
|
return -ENOBUFS;
|
||||||
|
extra_uref = !skb_zcopy(skb); /* only ref on new uarg */
|
||||||
|
if (rt->dst.dev->features & NETIF_F_SG &&
|
||||||
|
csummode == CHECKSUM_PARTIAL) {
|
||||||
|
paged = true;
|
||||||
|
zc = true;
|
||||||
|
} else {
|
||||||
|
uarg->zerocopy = 0;
|
||||||
|
skb_zcopy_set(skb, uarg, &extra_uref);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1192,13 +1209,14 @@ alloc_new_skb:
|
||||||
err = -EFAULT;
|
err = -EFAULT;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else if (!uarg || !uarg->zerocopy) {
|
} else if (!zc) {
|
||||||
int i = skb_shinfo(skb)->nr_frags;
|
int i = skb_shinfo(skb)->nr_frags;
|
||||||
|
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
if (!sk_page_frag_refill(sk, pfrag))
|
if (!sk_page_frag_refill(sk, pfrag))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
skb_zcopy_downgrade_managed(skb);
|
||||||
if (!skb_can_coalesce(skb, i, pfrag->page,
|
if (!skb_can_coalesce(skb, i, pfrag->page,
|
||||||
pfrag->offset)) {
|
pfrag->offset)) {
|
||||||
err = -EMSGSIZE;
|
err = -EMSGSIZE;
|
||||||
|
|
Loading…
Reference in New Issue