]> git.baikalelectronics.ru Git - kernel.git/commitdiff
tap/tun: add skb_zcopy_init() helper for initialization.
authorJonathan Lemon <jonathan.lemon@gmail.com>
Wed, 6 Jan 2021 22:18:40 +0000 (14:18 -0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 8 Jan 2021 00:08:37 +0000 (16:08 -0800)
Replace direct assignments with skb_zcopy_init() for zerocopy
cases where a new skb is initialized, without changing the
reference counts.

Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/tap.c
drivers/net/tun.c
drivers/vhost/net.c
include/linux/skbuff.h

index f7a19d9b7c2714fa09dc46ecfc7e247efb6f3e9d..3c652c8ac5ba7e30303eb265ac74a4ae9d954e82 100644 (file)
@@ -722,8 +722,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
        tap = rcu_dereference(q->tap);
        /* copy skb_ubuf_info for callback when skb has no error */
        if (zerocopy) {
-               skb_shinfo(skb)->destructor_arg = msg_control;
-               skb_shinfo(skb)->flags |= SKBFL_ZEROCOPY_FRAG;
+               skb_zcopy_init(skb, msg_control);
        } else if (msg_control) {
                struct ubuf_info *uarg = msg_control;
                uarg->callback(NULL, uarg, false);
index d8f1c3d346123ea21838e34b4129d2b2d51fc2a6..02a93cfdb6b1a94d2e61916eb4e2b69f01edee45 100644 (file)
@@ -1814,8 +1814,7 @@ drop:
 
        /* copy skb_ubuf_info for callback when skb has no error */
        if (zerocopy) {
-               skb_shinfo(skb)->destructor_arg = msg_control;
-               skb_shinfo(skb)->flags |= SKBFL_ZEROCOPY_FRAG;
+               skb_zcopy_init(skb, msg_control);
        } else if (msg_control) {
                struct ubuf_info *uarg = msg_control;
                uarg->callback(NULL, uarg, false);
index f834a097895e3ef185490106429831edf840f80c..3b744031ec8f2daa2518b1a1e79d86d2ad5a6879 100644 (file)
@@ -903,6 +903,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)
                        ubuf->callback = vhost_zerocopy_callback;
                        ubuf->ctx = nvq->ubufs;
                        ubuf->desc = nvq->upend_idx;
+                       ubuf->flags = SKBFL_ZEROCOPY_FRAG;
                        refcount_set(&ubuf->refcnt, 1);
                        msg.msg_control = &ctl;
                        ctl.type = TUN_MSG_UBUF;
index a7bc71d2debbbeca5bbfe67216e7c37cb9502271..68ad45a98810e1ffc9cd908c29c4b0242a0f8525 100644 (file)
@@ -1448,6 +1448,12 @@ static inline void skb_zcopy_get(struct ubuf_info *uarg)
        refcount_inc(&uarg->refcnt);
 }
 
+static inline void skb_zcopy_init(struct sk_buff *skb, struct ubuf_info *uarg)
+{
+       skb_shinfo(skb)->destructor_arg = uarg;
+       skb_shinfo(skb)->flags |= uarg->flags;
+}
+
 static inline void skb_zcopy_set(struct sk_buff *skb, struct ubuf_info *uarg,
                                 bool *have_ref)
 {
@@ -1456,8 +1462,7 @@ static inline void skb_zcopy_set(struct sk_buff *skb, struct ubuf_info *uarg,
                        *have_ref = false;
                else
                        skb_zcopy_get(uarg);
-               skb_shinfo(skb)->destructor_arg = uarg;
-               skb_shinfo(skb)->flags |= uarg->flags;
+               skb_zcopy_init(skb, uarg);
        }
 }