From: prashantbhole.linux@gmail•com
To: "Michael S . Tsirkin" <mst@redhat•com>,
Jason Wang <jasowang@redhat•com>,
"David S . Miller" <davem@davemloft•net>
Cc: Prashant Bhole <prashantbhole.linux@gmail•com>,
David Ahern <dsahern@gmail•com>,
kvm@vger•kernel.org, netdev@vger•kernel.org
Subject: [PATCH net-next 1/3] tuntap: reorganize tun_msg_ctl usage
Date: Sat, 12 Oct 2019 10:53:55 +0900 [thread overview]
Message-ID: <20191012015357.1775-2-prashantbhole.linux@gmail.com> (raw)
In-Reply-To: <20191012015357.1775-1-prashantbhole.linux@gmail.com>
From: Prashant Bhole <prashantbhole.linux@gmail•com>
In order to extend the usage of tun_msg_ctl structure, this patch
changes the member name from type to cmd. Also following definitions
are changed:
TUN_MSG_PTR : TUN_CMD_BATCH
TUN_MSG_UBUF: TUN_CMD_PACKET
Signed-off-by: Prashant Bhole <prashantbhole.linux@gmail•com>
---
drivers/net/tap.c | 9 ++++++---
drivers/net/tun.c | 8 ++++++--
drivers/vhost/net.c | 4 ++--
include/linux/if_tun.h | 6 +++---
4 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 3ae70c7e6860..01bd260ce60c 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -1213,9 +1213,10 @@ static int tap_sendmsg(struct socket *sock, struct msghdr *m,
struct tap_queue *q = container_of(sock, struct tap_queue, sock);
struct tun_msg_ctl *ctl = m->msg_control;
struct xdp_buff *xdp;
+ void *ptr = NULL;
int i;
- if (ctl && (ctl->type == TUN_MSG_PTR)) {
+ if (ctl && ctl->cmd == TUN_CMD_BATCH) {
for (i = 0; i < ctl->num; i++) {
xdp = &((struct xdp_buff *)ctl->ptr)[i];
tap_get_user_xdp(q, xdp);
@@ -1223,8 +1224,10 @@ static int tap_sendmsg(struct socket *sock, struct msghdr *m,
return 0;
}
- return tap_get_user(q, ctl ? ctl->ptr : NULL, &m->msg_iter,
- m->msg_flags & MSG_DONTWAIT);
+ if (ctl && ctl->cmd == TUN_CMD_PACKET)
+ ptr = ctl->ptr;
+
+ return tap_get_user(q, ptr, &m->msg_iter, m->msg_flags & MSG_DONTWAIT);
}
static int tap_recvmsg(struct socket *sock, struct msghdr *m,
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 0413d182d782..29711671959b 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2529,11 +2529,12 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
struct tun_struct *tun = tun_get(tfile);
struct tun_msg_ctl *ctl = m->msg_control;
struct xdp_buff *xdp;
+ void *ptr = NULL;
if (!tun)
return -EBADFD;
- if (ctl && (ctl->type == TUN_MSG_PTR)) {
+ if (ctl && ctl->cmd == TUN_CMD_BATCH) {
struct tun_page tpage;
int n = ctl->num;
int flush = 0;
@@ -2560,7 +2561,10 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
goto out;
}
- ret = tun_get_user(tun, tfile, ctl ? ctl->ptr : NULL, &m->msg_iter,
+ if (ctl && ctl->cmd == TUN_CMD_PACKET)
+ ptr = ctl->ptr;
+
+ ret = tun_get_user(tun, tfile, ptr, &m->msg_iter,
m->msg_flags & MSG_DONTWAIT,
m->msg_flags & MSG_MORE);
out:
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 1a2dd53caade..5946d2775bd0 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -462,7 +462,7 @@ static void vhost_tx_batch(struct vhost_net *net,
struct msghdr *msghdr)
{
struct tun_msg_ctl ctl = {
- .type = TUN_MSG_PTR,
+ .cmd = TUN_CMD_BATCH,
.num = nvq->batched_xdp,
.ptr = nvq->xdp,
};
@@ -902,7 +902,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)
ubuf->desc = nvq->upend_idx;
refcount_set(&ubuf->refcnt, 1);
msg.msg_control = &ctl;
- ctl.type = TUN_MSG_UBUF;
+ ctl.cmd = TUN_CMD_PACKET;
ctl.ptr = ubuf;
msg.msg_controllen = sizeof(ctl);
ubufs = nvq->ubufs;
diff --git a/include/linux/if_tun.h b/include/linux/if_tun.h
index 5bda8cf457b6..bdfa671612db 100644
--- a/include/linux/if_tun.h
+++ b/include/linux/if_tun.h
@@ -11,10 +11,10 @@
#define TUN_XDP_FLAG 0x1UL
-#define TUN_MSG_UBUF 1
-#define TUN_MSG_PTR 2
+#define TUN_CMD_PACKET 1
+#define TUN_CMD_BATCH 2
struct tun_msg_ctl {
- unsigned short type;
+ unsigned short cmd;
unsigned short num;
void *ptr;
};
--
2.21.0
next prev parent reply other threads:[~2019-10-12 1:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-12 1:53 [PATCH net-next 0/3] vhost_net: access ptr ring using tap recvmsg prashantbhole.linux
2019-10-12 1:53 ` prashantbhole.linux [this message]
2019-10-12 7:44 ` [PATCH net-next 1/3] tuntap: reorganize tun_msg_ctl usage Jason Wang
2019-10-15 0:33 ` Prashant Bhole
2019-10-12 1:53 ` [PATCH net-next 2/3] vhost_net: user tap recvmsg api to access ptr ring prashantbhole.linux
2019-10-12 7:54 ` Jason Wang
2019-10-12 20:41 ` Michael S. Tsirkin
2019-10-15 0:57 ` Prashant Bhole
2019-10-12 1:53 ` [PATCH net-next 3/3] tuntap: remove usage of ptr ring in vhost_net prashantbhole.linux
2019-10-12 7:57 ` [PATCH net-next 0/3] vhost_net: access ptr ring using tap recvmsg Jason Wang
2019-10-12 20:38 ` Michael S. Tsirkin
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191012015357.1775-2-prashantbhole.linux@gmail.com \
--to=prashantbhole.linux@gmail$(echo .)com \
--cc=davem@davemloft$(echo .)net \
--cc=dsahern@gmail$(echo .)com \
--cc=jasowang@redhat$(echo .)com \
--cc=kvm@vger$(echo .)kernel.org \
--cc=mst@redhat$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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