summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJason Wang <jasowang@redhat.com>2018-09-11 23:17:06 -0400
committerDavid S. Miller <davem@davemloft.net>2018-09-13 12:25:40 -0400
commitfe8dd45bb7556246c6b76277b1ba4296c91c2505 (patch)
tree9e31911fda3e7b8ca55238498bf8becead0e3db4 /drivers
parent1a097910adda6b3328fc235575bba0e9ee408492 (diff)
tun: switch to new type of msg_control
This patch introduces to a new tun/tap specific msg_control: #define TUN_MSG_UBUF 1 #define TUN_MSG_PTR 2 struct tun_msg_ctl { int type; void *ptr; }; This allows us to pass different kinds of msg_control through sendmsg(). The first supported type is ubuf (TUN_MSG_UBUF) which will be used by the existed vhost_net zerocopy code. The second is XDP buff, which allows vhost_net to pass XDP buff to TUN. This could be used to implement accepting an array of XDP buffs from vhost_net in the following patches. Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/tap.c18
-rw-r--r--drivers/net/tun.c6
-rw-r--r--drivers/vhost/net.c7
3 files changed, 22 insertions, 9 deletions
diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index f0f7cd977667..7996ed7cbf18 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -619,7 +619,7 @@ static inline struct sk_buff *tap_alloc_skb(struct sock *sk, size_t prepad,
619#define TAP_RESERVE HH_DATA_OFF(ETH_HLEN) 619#define TAP_RESERVE HH_DATA_OFF(ETH_HLEN)
620 620
621/* Get packet from user space buffer */ 621/* Get packet from user space buffer */
622static ssize_t tap_get_user(struct tap_queue *q, struct msghdr *m, 622static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
623 struct iov_iter *from, int noblock) 623 struct iov_iter *from, int noblock)
624{ 624{
625 int good_linear = SKB_MAX_HEAD(TAP_RESERVE); 625 int good_linear = SKB_MAX_HEAD(TAP_RESERVE);
@@ -663,7 +663,7 @@ static ssize_t tap_get_user(struct tap_queue *q, struct msghdr *m,
663 if (unlikely(len < ETH_HLEN)) 663 if (unlikely(len < ETH_HLEN))
664 goto err; 664 goto err;
665 665
666 if (m && m->msg_control && sock_flag(&q->sk, SOCK_ZEROCOPY)) { 666 if (msg_control && sock_flag(&q->sk, SOCK_ZEROCOPY)) {
667 struct iov_iter i; 667 struct iov_iter i;
668 668
669 copylen = vnet_hdr.hdr_len ? 669 copylen = vnet_hdr.hdr_len ?
@@ -724,11 +724,11 @@ static ssize_t tap_get_user(struct tap_queue *q, struct msghdr *m,
724 tap = rcu_dereference(q->tap); 724 tap = rcu_dereference(q->tap);
725 /* copy skb_ubuf_info for callback when skb has no error */ 725 /* copy skb_ubuf_info for callback when skb has no error */
726 if (zerocopy) { 726 if (zerocopy) {
727 skb_shinfo(skb)->destructor_arg = m->msg_control; 727 skb_shinfo(skb)->destructor_arg = msg_control;
728 skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY; 728 skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
729 skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG; 729 skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
730 } else if (m && m->msg_control) { 730 } else if (msg_control) {
731 struct ubuf_info *uarg = m->msg_control; 731 struct ubuf_info *uarg = msg_control;
732 uarg->callback(uarg, false); 732 uarg->callback(uarg, false);
733 } 733 }
734 734
@@ -1150,7 +1150,13 @@ static int tap_sendmsg(struct socket *sock, struct msghdr *m,
1150 size_t total_len) 1150 size_t total_len)
1151{ 1151{
1152 struct tap_queue *q = container_of(sock, struct tap_queue, sock); 1152 struct tap_queue *q = container_of(sock, struct tap_queue, sock);
1153 return tap_get_user(q, m, &m->msg_iter, m->msg_flags & MSG_DONTWAIT); 1153 struct tun_msg_ctl *ctl = m->msg_control;
1154
1155 if (ctl && ctl->type != TUN_MSG_UBUF)
1156 return -EINVAL;
1157
1158 return tap_get_user(q, ctl ? ctl->ptr : NULL, &m->msg_iter,
1159 m->msg_flags & MSG_DONTWAIT);
1154} 1160}
1155 1161
1156static int tap_recvmsg(struct socket *sock, struct msghdr *m, 1162static int tap_recvmsg(struct socket *sock, struct msghdr *m,
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 3ae539374f6b..89779b58c7ca 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2431,11 +2431,15 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
2431 int ret; 2431 int ret;
2432 struct tun_file *tfile = container_of(sock, struct tun_file, socket); 2432 struct tun_file *tfile = container_of(sock, struct tun_file, socket);
2433 struct tun_struct *tun = tun_get(tfile); 2433 struct tun_struct *tun = tun_get(tfile);
2434 struct tun_msg_ctl *ctl = m->msg_control;
2434 2435
2435 if (!tun) 2436 if (!tun)
2436 return -EBADFD; 2437 return -EBADFD;
2437 2438
2438 ret = tun_get_user(tun, tfile, m->msg_control, &m->msg_iter, 2439 if (ctl && ctl->type != TUN_MSG_UBUF)
2440 return -EINVAL;
2441
2442 ret = tun_get_user(tun, tfile, ctl ? ctl->ptr : NULL, &m->msg_iter,
2439 m->msg_flags & MSG_DONTWAIT, 2443 m->msg_flags & MSG_DONTWAIT,
2440 m->msg_flags & MSG_MORE); 2444 m->msg_flags & MSG_MORE);
2441 tun_put(tun); 2445 tun_put(tun);
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 4e656f89cb22..fb01ce6d981c 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -620,6 +620,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)
620 .msg_controllen = 0, 620 .msg_controllen = 0,
621 .msg_flags = MSG_DONTWAIT, 621 .msg_flags = MSG_DONTWAIT,
622 }; 622 };
623 struct tun_msg_ctl ctl;
623 size_t len, total_len = 0; 624 size_t len, total_len = 0;
624 int err; 625 int err;
625 struct vhost_net_ubuf_ref *uninitialized_var(ubufs); 626 struct vhost_net_ubuf_ref *uninitialized_var(ubufs);
@@ -664,8 +665,10 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)
664 ubuf->ctx = nvq->ubufs; 665 ubuf->ctx = nvq->ubufs;
665 ubuf->desc = nvq->upend_idx; 666 ubuf->desc = nvq->upend_idx;
666 refcount_set(&ubuf->refcnt, 1); 667 refcount_set(&ubuf->refcnt, 1);
667 msg.msg_control = ubuf; 668 msg.msg_control = &ctl;
668 msg.msg_controllen = sizeof(ubuf); 669 ctl.type = TUN_MSG_UBUF;
670 ctl.ptr = ubuf;
671 msg.msg_controllen = sizeof(ctl);
669 ubufs = nvq->ubufs; 672 ubufs = nvq->ubufs;
670 atomic_inc(&ubufs->refcount); 673 atomic_inc(&ubufs->refcount);
671 nvq->upend_idx = (nvq->upend_idx + 1) % UIO_MAXIOV; 674 nvq->upend_idx = (nvq->upend_idx + 1) % UIO_MAXIOV;