From: Arseniy Krasnov <avkrasnov@salutedevices.com>
To: Amery Hung <ameryhung@gmail.com>
Cc: <stefanha@redhat.com>, <sgarzare@redhat.com>, <mst@redhat.com>,
<jasowang@redhat.com>, <xuanzhuo@linux.alibaba.com>,
<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<pabeni@redhat.com>, <kys@microsoft.com>,
<haiyangz@microsoft.com>, <wei.liu@kernel.org>,
<decui@microsoft.com>, <bryantan@vmware.com>, <vdasa@vmware.com>,
<pv-drivers@vmware.com>, <dan.carpenter@linaro.org>,
<simon.horman@corigine.com>, <oxffffaa@gmail.com>,
<kvm@vger.kernel.org>,
<virtualization@lists.linux-foundation.org>,
<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-hyperv@vger.kernel.org>, <bpf@vger.kernel.org>,
<bobby.eshleman@bytedance.com>, <jiang.wang@bytedance.com>,
<amery.hung@bytedance.com>, <xiyou.wangcong@gmail.com>,
<kernel@sberdevices.ru>
Subject: Re: [RFC PATCH net-next v6 07/14] virtio/vsock: add common datagram send path
Date: Tue, 30 Jul 2024 08:09:23 +0300 [thread overview]
Message-ID: <41421bd7-e6e1-db2d-6a43-06d6a44cfeb8@salutedevices.com> (raw)
In-Reply-To: <CAMB2axMXzcxrFr+zWV6CFJxDrKwH+U85F7dkeXfJjAO10EmSAg@mail.gmail.com>
On 30.07.2024 01:51, Amery Hung wrote:
> On Mon, Jul 29, 2024 at 1:12 PM Arseniy Krasnov
> <avkrasnov@salutedevices.com> wrote:
>>
>> Hi,
>>
>>> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>>> index a1c76836d798..46cd1807f8e3 100644
>>> --- a/net/vmw_vsock/virtio_transport_common.c
>>> +++ b/net/vmw_vsock/virtio_transport_common.c
>>> @@ -1040,13 +1040,98 @@ int virtio_transport_shutdown(struct vsock_sock *vsk, int mode)
>>> }
>>> EXPORT_SYMBOL_GPL(virtio_transport_shutdown);
>>>
>>> +static int virtio_transport_dgram_send_pkt_info(struct vsock_sock *vsk,
>>> + struct virtio_vsock_pkt_info *info)
>>> +{
>>> + u32 src_cid, src_port, dst_cid, dst_port;
>>> + const struct vsock_transport *transport;
>>> + const struct virtio_transport *t_ops;
>>> + struct sock *sk = sk_vsock(vsk);
>>> + struct virtio_vsock_hdr *hdr;
>>> + struct sk_buff *skb;
>>> + void *payload;
>>> + int noblock = 0;
>>> + int err;
>>> +
>>> + info->type = virtio_transport_get_type(sk_vsock(vsk));
>>> +
>>> + if (info->pkt_len > VIRTIO_VSOCK_MAX_PKT_BUF_SIZE)
>>> + return -EMSGSIZE;
>>
>> Small suggestion, i think we can check for packet length earlier ? Before
>> info->type = ...
>
> Certainly.
>
>>
>>> +
>>> + transport = vsock_dgram_lookup_transport(info->remote_cid, info->remote_flags);
>>> + t_ops = container_of(transport, struct virtio_transport, transport);
>>> + if (unlikely(!t_ops))
>>> + return -EFAULT;
>>> +
>>> + if (info->msg)
>>> + noblock = info->msg->msg_flags & MSG_DONTWAIT;
>>> +
>>> + /* Use sock_alloc_send_skb to throttle by sk_sndbuf. This helps avoid
>>> + * triggering the OOM.
>>> + */
>>> + skb = sock_alloc_send_skb(sk, info->pkt_len + VIRTIO_VSOCK_SKB_HEADROOM,
>>> + noblock, &err);
>>> + if (!skb)
>>> + return err;
>>> +
>>> + skb_reserve(skb, VIRTIO_VSOCK_SKB_HEADROOM);
>>> +
>>> + src_cid = t_ops->transport.get_local_cid();
>>> + src_port = vsk->local_addr.svm_port;
>>> + dst_cid = info->remote_cid;
>>> + dst_port = info->remote_port;
>>> +
>>> + hdr = virtio_vsock_hdr(skb);
>>> + hdr->type = cpu_to_le16(info->type);
>>> + hdr->op = cpu_to_le16(info->op);
>>> + hdr->src_cid = cpu_to_le64(src_cid);
>>> + hdr->dst_cid = cpu_to_le64(dst_cid);
>>> + hdr->src_port = cpu_to_le32(src_port);
>>> + hdr->dst_port = cpu_to_le32(dst_port);
>>> + hdr->flags = cpu_to_le32(info->flags);
>>> + hdr->len = cpu_to_le32(info->pkt_len);
>>
>> There is function 'virtio_transport_init_hdr()' in this file, may be reuse it ?
>
> Will do.
>
>>
>>> +
>>> + if (info->msg && info->pkt_len > 0) {
>>
>> If pkt_len is 0, do we really need to send such packets ? Because for connectible
>> sockets, we ignore empty OP_RW packets.
>
> Thanks for pointing this out. I think virtio dgram should also follow that.
>
>>
>>> + payload = skb_put(skb, info->pkt_len);
>>> + err = memcpy_from_msg(payload, info->msg, info->pkt_len);
>>> + if (err)
>>> + goto out;
>>> + }
>>> +
>>> + trace_virtio_transport_alloc_pkt(src_cid, src_port,
>>> + dst_cid, dst_port,
>>> + info->pkt_len,
>>> + info->type,
>>> + info->op,
>>> + info->flags,
>>> + false);
>>
>> ^^^ For SOCK_DGRAM, include/trace/events/vsock_virtio_transport_common.h also should
>> be updated?
>
> Can you elaborate what needs to be changed?
Sure, there are:
TRACE_DEFINE_ENUM(VIRTIO_VSOCK_TYPE_STREAM);
TRACE_DEFINE_ENUM(VIRTIO_VSOCK_TYPE_SEQPACKET);
#define show_type(val) \
__print_symbolic(val, \
{ VIRTIO_VSOCK_TYPE_STREAM, "STREAM" }, \
{ VIRTIO_VSOCK_TYPE_SEQPACKET, "SEQPACKET" })
I guess SOCK_DGRAM handling should be added to print type of socket.
Thanks, Arseniy
>
> Thank you,
> Amery
>
>>
>>> +
>>> + return t_ops->send_pkt(skb);
>>> +out:
>>> + kfree_skb(skb);
>>> + return err;
>>> +}
>>> +
>>> int
>>> virtio_transport_dgram_enqueue(struct vsock_sock *vsk,
>>> struct sockaddr_vm *remote_addr,
>>> struct msghdr *msg,
>>> size_t dgram_len)
>>> {
>>> - return -EOPNOTSUPP;
>>> + /* Here we are only using the info struct to retain style uniformity
>>> + * and to ease future refactoring and merging.
>>> + */
>>> + struct virtio_vsock_pkt_info info = {
>>> + .op = VIRTIO_VSOCK_OP_RW,
>>> + .remote_cid = remote_addr->svm_cid,
>>> + .remote_port = remote_addr->svm_port,
>>> + .remote_flags = remote_addr->svm_flags,
>>> + .msg = msg,
>>> + .vsk = vsk,
>>> + .pkt_len = dgram_len,
>>> + };
>>> +
>>> + return virtio_transport_dgram_send_pkt_info(vsk, &info);
>>> }
>>> EXPORT_SYMBOL_GPL(virtio_transport_dgram_enqueue);
>>>
>>> --
>>> 2.20.1
>>
>> Thanks, Arseniy
next prev parent reply other threads:[~2024-07-30 5:21 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-10 21:25 [RFC PATCH net-next v6 00/14] virtio/vsock: support datagrams Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 01/14] af_vsock: generalize vsock_dgram_recvmsg() to all transports Amery Hung
2024-07-15 8:02 ` Luigi Leonardi
2024-07-15 23:39 ` Amery Hung
2024-07-29 19:25 ` Arseniy Krasnov
2024-07-10 21:25 ` [RFC PATCH net-next v6 02/14] af_vsock: refactor transport lookup code Amery Hung
2024-07-25 6:29 ` Arseniy Krasnov
2024-07-28 22:10 ` Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 03/14] af_vsock: support multi-transport datagrams Amery Hung
2024-07-15 8:13 ` Arseniy Krasnov
2024-07-15 17:41 ` Amery Hung
2024-07-28 20:28 ` Arseniy Krasnov
2024-07-28 21:53 ` Amery Hung
2024-07-29 5:12 ` Arseniy Krasnov
2024-07-10 21:25 ` [RFC PATCH net-next v6 04/14] af_vsock: generalize bind table functions Amery Hung
2024-07-23 14:39 ` Stefano Garzarella
2024-07-28 18:52 ` Amery Hung
2024-07-30 8:00 ` Stefano Garzarella
2024-07-30 17:56 ` Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 05/14] af_vsock: use a separate dgram bind table Amery Hung
2024-07-23 14:41 ` Stefano Garzarella
2024-07-28 21:37 ` Amery Hung
2024-07-30 8:05 ` Stefano Garzarella
2024-07-10 21:25 ` [RFC PATCH net-next v6 06/14] virtio/vsock: add VIRTIO_VSOCK_TYPE_DGRAM Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 07/14] virtio/vsock: add common datagram send path Amery Hung
2024-07-23 14:42 ` Stefano Garzarella
2024-07-26 23:22 ` Amery Hung
2024-07-30 8:22 ` Stefano Garzarella
2024-07-29 20:00 ` Arseniy Krasnov
2024-07-29 22:51 ` Amery Hung
2024-07-30 5:09 ` Arseniy Krasnov [this message]
2024-07-10 21:25 ` [RFC PATCH net-next v6 08/14] af_vsock: add vsock_find_bound_dgram_socket() Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 09/14] virtio/vsock: add common datagram recv path Amery Hung
2024-07-23 14:42 ` Stefano Garzarella
2024-07-30 0:35 ` Amery Hung
2024-07-30 8:32 ` Stefano Garzarella
2024-07-10 21:25 ` [RFC PATCH net-next v6 10/14] virtio/vsock: add VIRTIO_VSOCK_F_DGRAM feature bit Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 11/14] vhost/vsock: implement datagram support Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 12/14] vsock/loopback: " Amery Hung
2024-08-01 12:18 ` Luigi Leonardi
2024-07-10 21:25 ` [RFC PATCH net-next v6 13/14] virtio/vsock: " Amery Hung
2024-07-11 23:02 ` Luigi Leonardi
2024-07-11 23:07 ` Amery Hung
2024-07-10 21:25 ` [RFC PATCH net-next v6 14/14] test/vsock: add vsock dgram tests Amery Hung
2024-07-20 19:58 ` Arseniy Krasnov
2024-07-23 14:43 ` Stefano Garzarella
2024-07-28 22:06 ` Amery Hung
2024-07-23 14:38 ` [RFC PATCH net-next v6 00/14] virtio/vsock: support datagrams Stefano Garzarella
2025-07-22 14:35 ` Stefano Garzarella
2025-07-26 5:53 ` Amery Hung
2025-07-29 12:40 ` Stefano Garzarella
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=41421bd7-e6e1-db2d-6a43-06d6a44cfeb8@salutedevices.com \
--to=avkrasnov@salutedevices.com \
--cc=amery.hung@bytedance.com \
--cc=ameryhung@gmail.com \
--cc=bobby.eshleman@bytedance.com \
--cc=bpf@vger.kernel.org \
--cc=bryantan@vmware.com \
--cc=dan.carpenter@linaro.org \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=edumazet@google.com \
--cc=haiyangz@microsoft.com \
--cc=jasowang@redhat.com \
--cc=jiang.wang@bytedance.com \
--cc=kernel@sberdevices.ru \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=oxffffaa@gmail.com \
--cc=pabeni@redhat.com \
--cc=pv-drivers@vmware.com \
--cc=sgarzare@redhat.com \
--cc=simon.horman@corigine.com \
--cc=stefanha@redhat.com \
--cc=vdasa@vmware.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=wei.liu@kernel.org \
--cc=xiyou.wangcong@gmail.com \
--cc=xuanzhuo@linux.alibaba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).