Development issues regarding the cerowrt test router project
 help / color / mirror / Atom feed
From: Dave Taht <dave.taht@gmail.com>
To: cerowrt-devel <cerowrt-devel@lists.bufferbloat.net>
Subject: [Cerowrt-devel] Fwd: [RFC v2 07/19] ipv6/udp: add support msgdr::msg_ubuf
Date: Tue, 21 Dec 2021 23:17:13 -0800	[thread overview]
Message-ID: <CAA93jw6biEdx-p2L5y-QTcPhhOdTbYYPneFeaT2eGY=8w2W=bA@mail.gmail.com> (raw)
In-Reply-To: <70428063e99a4418d2e519a496ebd1096d45ac59.1640029579.git.asml.silence@gmail.com>

zerocopy udp

---------- Forwarded message ---------
From: Pavel Begunkov <asml.silence@gmail.com>
Date: Tue, Dec 21, 2021 at 11:16 PM
Subject: [RFC v2 07/19] ipv6/udp: add support msgdr::msg_ubuf
To: <io-uring@vger.kernel.org>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: Jakub Kicinski <kuba@kernel.org>, Jonathan Lemon
<jonathan.lemon@gmail.com>, David S . Miller <davem@davemloft.net>,
Willem de Bruijn <willemb@google.com>, Eric Dumazet
<edumazet@google.com>, David Ahern <dsahern@kernel.org>, Jens Axboe
<axboe@kernel.dk>, Pavel Begunkov <asml.silence@gmail.com>


Make ipv6/udp to use ubuf_info passed in struct msghdr if it was
specified.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 net/ipv6/ip6_output.c | 49 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 37 insertions(+), 12 deletions(-)

diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 2f044a49afa8..822e3894dd3b 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1452,6 +1452,7 @@ static int __ip6_append_data(struct sock *sk,
        unsigned int maxnonfragsize, headersize;
        unsigned int wmem_alloc_delta = 0;
        bool paged, extra_uref = false;
+       bool zc = false;

        skb = skb_peek_tail(queue);
        if (!skb) {
@@ -1516,17 +1517,37 @@ static int __ip6_append_data(struct sock *sk,
            rt->dst.dev->features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
                csummode = CHECKSUM_PARTIAL;

-       if (flags & MSG_ZEROCOPY && length && 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;
-               } else {
-                       uarg->zerocopy = 0;
-                       skb_zcopy_set(skb, uarg, &extra_uref);
+       if ((flags & MSG_ZEROCOPY) && length) {
+               struct msghdr *msg = from;
+
+               if (getfrag == ip_generic_getfrag && msg->msg_ubuf) {
+                       uarg = msg->msg_ubuf;
+                       if (skb_zcopy(skb) && uarg != skb_zcopy(skb))
+                               return -EINVAL;
+
+                       if (rt->dst.dev->features & NETIF_F_SG &&
+                               csummode == CHECKSUM_PARTIAL) {
+                               paged = true;
+                               zc = true;
+                       } else {
+                               /* Drop uarg if can't zerocopy, callers should
+                                * be able to handle it.
+                                */
+                               uarg = NULL;
+                       }
+               } 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);
+                       }
                }
        }

@@ -1717,9 +1738,13 @@ static int __ip6_append_data(struct sock *sk,
                                err = -EFAULT;
                                goto error;
                        }
-               } else if (!uarg || !uarg->zerocopy) {
+               } else if (!zc) {
                        int i = skb_shinfo(skb)->nr_frags;

+                       if (skb_shinfo(skb)->flags & SKBFL_MANAGED_FRAGS) {
+                               err = -EFAULT;
+                               goto error;
+                       }
                        err = -ENOMEM;
                        if (!sk_page_frag_refill(sk, pfrag))
                                goto error;
--
2.34.1



-- 
I tried to build a better future, a few times:
https://wayforward.archive.org/?site=https%3A%2F%2Fwww.icei.org

Dave Täht CEO, TekLibre, LLC

           reply	other threads:[~2021-12-22  7:17 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <70428063e99a4418d2e519a496ebd1096d45ac59.1640029579.git.asml.silence@gmail.com>]

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

  List information: https://lists.bufferbloat.net/postorius/lists/cerowrt-devel.lists.bufferbloat.net/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAA93jw6biEdx-p2L5y-QTcPhhOdTbYYPneFeaT2eGY=8w2W=bA@mail.gmail.com' \
    --to=dave.taht@gmail.com \
    --cc=cerowrt-devel@lists.bufferbloat.net \
    /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