All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: prashantbhole.linux@gmail.com,
	"Michael S . Tsirkin" <mst@redhat.com>,
	"David S . Miller" <davem@davemloft.net>
Cc: David Ahern <dsahern@gmail.com>,
	kvm@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next 1/3] tuntap: reorganize tun_msg_ctl usage
Date: Sat, 12 Oct 2019 15:44:31 +0800	[thread overview]
Message-ID: <739281a8-59fe-d898-0147-656d01fdfabc@redhat.com> (raw)
In-Reply-To: <20191012015357.1775-2-prashantbhole.linux@gmail.com>


On 2019/10/12 上午9:53, prashantbhole.linux@gmail.com wrote:
> 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


Not a native English speaker, but the conversion here looks not as 
straightforward as it did.

For TUN_MSG_PTR, it means recvmsg() can do receiving from a pointer to 
either XDP or skb instead of ptr_ring. TUN_CMD_BATCH sounds not related.

For TUN_MSG_UBUF, it means the packet is a zercopy (buffer pointers to 
userspace). TUN_CMD_PACKET may bring confusion in this case.

Thanks


>
> 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;
>   };

  reply	other threads:[~2019-10-12  7:44 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 ` [PATCH net-next 1/3] tuntap: reorganize tun_msg_ctl usage prashantbhole.linux
2019-10-12  7:44   ` Jason Wang [this message]
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=739281a8-59fe-d898-0147-656d01fdfabc@redhat.com \
    --to=jasowang@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=prashantbhole.linux@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.