Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3208884pxf; Mon, 15 Mar 2021 04:29:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnzReJf82DbmSl9vMLj/avE9aDwk1FAhpOZBOXICaGIF4lG2Svij+HkJ3T4EUTmPezRM/C X-Received: by 2002:a17:906:1706:: with SMTP id c6mr1745355eje.223.1615807740526; Mon, 15 Mar 2021 04:29:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615807740; cv=none; d=google.com; s=arc-20160816; b=rhz8ioM7+bKtChZ61BiJ5wRhtf0he+s1YYOVCPCNjK4qGub1jAdcaQ45ov7OaPq2VF fx60uFAw1u6YJI4j01rkggjx2sQaGfdNS5SuHZbNAzthLv+jAgCROjerzd3G3AYcG3Df ex1WfLem/UJv5xdeDaSInLXUOFbC4Lh3fD42D2Vy0mIwbKyZZQPHDeR3flsDc+XvEy7J 6Bg1+UejHpjPvj6+P5OA1nBd3fSQtGTFgFzfecvAW1ENKnAs0dGV1iE1n5/vkMGETHg5 kMksRYrSiuyip+FcliVPyPOKbAuoD4XsFDTUhe+7ihZuAh2807GH0mkAE/mHkUilRO/2 wAWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EDcN82trASDnIA4Psf1sFMT849eJlpI4rz5LIx/ZPbc=; b=dBrTbFE2ER2aBRLEW3sCwoTzBdupNCFQBSmnxkWK7EgiXk/PjEattgcosK46/xRydo JGvKbaGXQG7oXHjQ6IpP7OcVLT4PH5ZLNvrSFa8XU5ZhE3es4F2NOQy1wAHYSWV4CYpn JDElR2vigh6f5ebKilV8S6xc+ZJZ3U9ZjJRwp2nQZFWrkH80wLS3Tal07Xq8Ou9azmy+ qaEP5vkKUmazhyOopLrH27Qgo5rD6x4C6tcFUrSFBv7Hci2AnnkwgdheFzpFmeIXgkQC WhhzcoDkyHM4l0yjKITPsJmqy15Z91DtXsz5BwNqZGfJn7ST1yI/85NptLP2SPnG9p7K dnGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DnGpBcOb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rs13si10825963ejb.31.2021.03.15.04.28.36; Mon, 15 Mar 2021 04:29:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DnGpBcOb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229756AbhCOLZd (ORCPT + 99 others); Mon, 15 Mar 2021 07:25:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53314 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229686AbhCOLZW (ORCPT ); Mon, 15 Mar 2021 07:25:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615807522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EDcN82trASDnIA4Psf1sFMT849eJlpI4rz5LIx/ZPbc=; b=DnGpBcObSosUbNV/O9qh6cJyrnMxnrKDKZk7GbyKmLPrWJ5QfpwrddoZsdQ8MoFvidyrxI fXLzA7qf2F9KVkWIqlXoC69LE/8+Uiwu/X/2HN6Q5aCl0h8/fOVwcpMlZt56mViQ94/I0B kZUxL+y9Y6583xxvqRy1+TOLlGkAONs= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-437-LeRstUttMrSFUw3LZ0sJPw-1; Mon, 15 Mar 2021 07:25:20 -0400 X-MC-Unique: LeRstUttMrSFUw3LZ0sJPw-1 Received: by mail-wm1-f69.google.com with SMTP id a65so2785730wmh.1 for ; Mon, 15 Mar 2021 04:25:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EDcN82trASDnIA4Psf1sFMT849eJlpI4rz5LIx/ZPbc=; b=NhLZwZ0Ew/ozOiZQd41/B5my6c3z9B7YWcWcZ4Nz/cxKftRr+r1TeeQ18jkdkWz+mB 5081wkGjpFcerBXwS6RgjAL8njaIaTgeSadC5LIC/HqUBF6TQClIeQMct9UmLIFhWAKA sIXpz7dnlDVX622H9lYsBbCtpbg7kP48Uz8606sf2koFpGIu3VErH6t0CCRoc5M8gfsB ZV6paL+aGd3Lpnp8siQnG1C1yWMVSEaDUWOA7fF6UGbt810Qsja6BY3M5g7rI5aArZRP 66NHbHz7YDHKKviDDOVAfnN9N3NlpTUaiCj9ROfhmgkaB1pnI4l7sFY1ZUPRZRXJUcQg DcTg== X-Gm-Message-State: AOAM533g2jk2zpbxWnf1/D4PF6BtOK3iaKAt0RdkQuReUqVNmzeMKeIs tPP7IV1dkw/2mcddJRbPe9ShgJSBWDPRRZOTptvMu4jVttxoSTwKXgrTHMsEg4WqNvTnE6tZ5r5 K3VtbEj97Rn+mBGKfftoLeLwc X-Received: by 2002:a5d:4c85:: with SMTP id z5mr26147138wrs.208.1615807519056; Mon, 15 Mar 2021 04:25:19 -0700 (PDT) X-Received: by 2002:a5d:4c85:: with SMTP id z5mr26147121wrs.208.1615807518885; Mon, 15 Mar 2021 04:25:18 -0700 (PDT) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id f22sm11933706wmb.31.2021.03.15.04.25.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 04:25:18 -0700 (PDT) Date: Mon, 15 Mar 2021 12:25:16 +0100 From: Stefano Garzarella To: Arseny Krasnov Cc: Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Jorgen Hansen , Norbert Slusarek , Colin Ian King , Andra Paraschiv , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stsp2@yandex.ru, oxffffaa@gmail.com Subject: Re: [RFC PATCH v6 14/22] virtio/vsock: rest of SOCK_SEQPACKET support Message-ID: <20210315112516.wa5yos6cbukcv3ww@steredhat> References: <20210307175722.3464068-1-arseny.krasnov@kaspersky.com> <20210307180312.3466235-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210307180312.3466235-1-arseny.krasnov@kaspersky.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 07, 2021 at 09:03:09PM +0300, Arseny Krasnov wrote: >This adds rest of logic for SEQPACKET: >1) SEQPACKET specific functions which send SEQ_BEGIN/SEQ_END. > Note that both functions may sleep to wait enough space for > SEQPACKET header. >2) SEQ_BEGIN/SEQ_END in TAP packet capture. >3) Send SHUTDOWN on socket close for SEQPACKET type. >4) Set SEQPACKET packet type during send. >5) Set MSG_EOR in flags for SEQPACKET during send. >6) 'seqpacket_allow' flag to virtio transport. > >Signed-off-by: Arseny Krasnov >--- > include/linux/virtio_vsock.h | 8 +++ > net/vmw_vsock/virtio_transport_common.c | 87 ++++++++++++++++++++++++- > 2 files changed, 93 insertions(+), 2 deletions(-) > >diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h >index d7edcfeb4cd2..6b45a8b98226 100644 >--- a/include/linux/virtio_vsock.h >+++ b/include/linux/virtio_vsock.h >@@ -22,6 +22,7 @@ struct virtio_vsock_seqpack_state { > u32 user_read_seq_len; > u32 user_read_copied; > u32 curr_rx_msg_id; >+ u32 next_tx_msg_id; > }; > > /* Per-socket state (accessed via vsk->trans) */ >@@ -76,6 +77,8 @@ struct virtio_transport { > > /* Takes ownership of the packet */ > int (*send_pkt)(struct virtio_vsock_pkt *pkt); >+ >+ bool seqpacket_allow; > }; > > ssize_t >@@ -90,6 +93,11 @@ virtio_transport_dgram_dequeue(struct vsock_sock *vsk, > > size_t virtio_transport_seqpacket_seq_get_len(struct vsock_sock *vsk); > int >+virtio_transport_seqpacket_enqueue(struct vsock_sock *vsk, >+ struct msghdr *msg, >+ int flags, >+ size_t len); >+int > virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk, > struct msghdr *msg, > int flags, >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c >index 9d86375935ce..8e9fdd8aba5d 100644 >--- a/net/vmw_vsock/virtio_transport_common.c >+++ b/net/vmw_vsock/virtio_transport_common.c >@@ -139,6 +139,8 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque) > break; > case VIRTIO_VSOCK_OP_CREDIT_UPDATE: > case VIRTIO_VSOCK_OP_CREDIT_REQUEST: >+ case VIRTIO_VSOCK_OP_SEQ_BEGIN: >+ case VIRTIO_VSOCK_OP_SEQ_END: > hdr->op = cpu_to_le16(AF_VSOCK_OP_CONTROL); > break; > default: >@@ -187,7 +189,12 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk, > struct virtio_vsock_pkt *pkt; > u32 pkt_len = info->pkt_len; > >- info->type = VIRTIO_VSOCK_TYPE_STREAM; >+ info->type = virtio_transport_get_type(sk_vsock(vsk)); >+ >+ if (info->type == VIRTIO_VSOCK_TYPE_SEQPACKET && >+ info->msg && >+ info->msg->msg_flags & MSG_EOR) >+ info->flags |= VIRTIO_VSOCK_RW_EOR; > > t_ops = virtio_transport_get_ops(vsk); > if (unlikely(!t_ops)) >@@ -401,6 +408,43 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, > return err; > } > >+static int virtio_transport_seqpacket_send_ctrl(struct vsock_sock *vsk, >+ int type, >+ size_t len, >+ int flags) >+{ >+ struct virtio_vsock_sock *vvs = vsk->trans; >+ struct virtio_vsock_pkt_info info = { >+ .op = type, >+ .vsk = vsk, >+ .pkt_len = sizeof(struct virtio_vsock_seq_hdr) >+ }; >+ >+ struct virtio_vsock_seq_hdr seq_hdr = { >+ .msg_id = cpu_to_le32(vvs->seqpacket_state.next_tx_msg_id), >+ .msg_len = cpu_to_le32(len) >+ }; >+ >+ struct kvec seq_hdr_kiov = { >+ .iov_base = (void *)&seq_hdr, >+ .iov_len = sizeof(struct virtio_vsock_seq_hdr) >+ }; >+ >+ struct msghdr msg = {0}; >+ >+ //XXX: do we need 'vsock_transport_send_notify_data' pointer? >+ if (vsock_wait_space(sk_vsock(vsk), >+ sizeof(struct virtio_vsock_seq_hdr), >+ flags, NULL)) >+ return -1; >+ >+ iov_iter_kvec(&msg.msg_iter, WRITE, &seq_hdr_kiov, 1, sizeof(seq_hdr)); >+ >+ info.msg = &msg; >+ >+ return virtio_transport_send_pkt_info(vsk, &info); >+} >+ > static inline void virtio_transport_remove_pkt(struct virtio_vsock_pkt *pkt) > { > list_del(&pkt->list); >@@ -582,6 +626,45 @@ virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk, > } > EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_dequeue); > >+int >+virtio_transport_seqpacket_enqueue(struct vsock_sock *vsk, >+ struct msghdr *msg, >+ int flags, >+ size_t len) >+{ >+ int written; >+ >+ if (msg->msg_iter.iov_offset == 0) { >+ /* Send SEQBEGIN. */ >+ if (virtio_transport_seqpacket_send_ctrl(vsk, >+ VIRTIO_VSOCK_OP_SEQ_BEGIN, >+ len, >+ flags) < 0) >+ return -1; >+ } >+ >+ written = virtio_transport_stream_enqueue(vsk, msg, len); >+ >+ if (written < 0) >+ return -1; >+ >+ if (msg->msg_iter.count == 0) { >+ struct virtio_vsock_sock *vvs = vsk->trans; >+ >+ /* Send SEQEND. */ >+ if (virtio_transport_seqpacket_send_ctrl(vsk, >+ VIRTIO_VSOCK_OP_SEQ_END, >+ 0, >+ flags) < 0) >+ return -1; >+ >+ vvs->seqpacket_state.next_tx_msg_id++; >+ } I suspect we should increment next_tx_msg_id even in case of an error to avoid issues with packets with same IDs, so in case of error I would do: if (/* error */) { written = -1; goto out; } Then we can add the 'out' label and the id increment: out: vvs->seqpacket_state.next_tx_msg_id++; >+ >+ return written; >+} >+EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_enqueue); >+ > int > virtio_transport_dgram_dequeue(struct vsock_sock *vsk, > struct msghdr *msg, >@@ -1001,7 +1084,7 @@ void virtio_transport_release(struct vsock_sock *vsk) > struct sock *sk = &vsk->sk; > bool remove_sock = true; > >- if (sk->sk_type == SOCK_STREAM) >+ if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) > remove_sock = virtio_transport_close(vsk); > > list_for_each_entry_safe(pkt, tmp, &vvs->rx_queue, list) { >-- >2.25.1 >