Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp548726pxf; Thu, 25 Mar 2021 09:05:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyM5fBpE36TJopRt8phJ9TJxgdZAZZ0Ig60o2W2ps4rMgkGN9m7a35lOdBawAKkpRjfHYVv X-Received: by 2002:a17:906:948d:: with SMTP id t13mr9986619ejx.402.1616688342098; Thu, 25 Mar 2021 09:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616688342; cv=none; d=google.com; s=arc-20160816; b=uR5wnLe4VcDj2GjPEzwYbh65K24D3JmKJA0598Ym1PKspewgca5EyG7qfjNMUUTrAt dUtOqKAcdGshGk1wWxVn/MOYJOcNd4kFBNSyHv8XQxlPPlg0ZEI4E6CxpXbZX39QJp0u KbYw+Ka/rx+CmOr+OYxDd4EAVOiT2qyXvOL13P9295VpU/le1HVTJOrVBDXPGxUdLRWO htVF0lohHwwFU8A2TNtqbHlvuYpFye0lS4dQ7n8AJghalYOO5EMQARjL92IPiOZlDalg uwJQ/tnACktniQrD2A304DopkJjQaF+nauloMVcyM0icE+S1gibBcPIQyyXIX8Xuj1+1 Nt/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=9Bg7HBw1vWT7Y4BrQr21D0+4waQYxf0ZTdVSLqOpzBU=; b=btfSAxRgrGLa+Fl40gm66czcdE4BYz8IcQTHmRqpye4rtk81MtqxY9mjQWFf5cBuja fo9O7BCdLV0hgqn6Rn6csb6xfPWWr9N8ydwqpUJv9JR8VSjJEYimjb0bxCkeORNX6fkF 7xlQeVmiUIuMLMdJH60UMSvm9Agu7u1a+OQA9hM1zbZAAeE8DIxJQ9Jyy1zYgbhyqpvf zEn8bGtYSTvsQqU4qVHW5ktOtfwEIRDtzPyPTIO3GCywhYATBbNJu+g9ZoKFmgb4ssXS rECn+qnqii9Am1PMdwQTM3qov49m9MdUJSFkUaXVnalWC0U3032ANC//0gf7ivoXYUu4 K+Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kaspersky.com header.s=mail202102 header.b=vpLEIjXf; 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=REJECT sp=REJECT dis=NONE) header.from=kaspersky.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr14si4470834ejb.627.2021.03.25.09.05.18; Thu, 25 Mar 2021 09:05:42 -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=@kaspersky.com header.s=mail202102 header.b=vpLEIjXf; 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=REJECT sp=REJECT dis=NONE) header.from=kaspersky.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230022AbhCYQDl (ORCPT + 99 others); Thu, 25 Mar 2021 12:03:41 -0400 Received: from mx12.kaspersky-labs.com ([91.103.66.155]:36425 "EHLO mx12.kaspersky-labs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229651AbhCYQD2 (ORCPT ); Thu, 25 Mar 2021 12:03:28 -0400 Received: from relay12.kaspersky-labs.com (unknown [127.0.0.10]) by relay12.kaspersky-labs.com (Postfix) with ESMTP id 03DCB774AB; Thu, 25 Mar 2021 19:03:26 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kaspersky.com; s=mail202102; t=1616688206; bh=9Bg7HBw1vWT7Y4BrQr21D0+4waQYxf0ZTdVSLqOpzBU=; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type; b=vpLEIjXf6TF/XnednffQcF2d+ObBaxgdOjJdHNPSSETyY2Po34GvFv77kHZqpJilv +CwtErTyyBRcu+0Mf272TN0zzfyeun65LpYXqcNeyynz+XsrwgXJC528qYKJ0E7BGM K1pF/Gl/tH4nyHgbDLB2s5rZh+B0+vxVF6YAqNYgNNP3UFBymBQ4RBiECdGschsL6u FkH9sHCIhLCCTKcCmDd73+ehpP0GAX2dEo/jfMBARSKyW18AFB7EpOXclhRewzp68f 4VcJGVpckFTEnJ/pHfWuVeiG+Qy643jJNsnKPUqjM4YbMXcXlZiSFylFaJD5vEsRPk lli8bIMlIgW/Q== Received: from mail-hq2.kaspersky.com (unknown [91.103.66.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client CN "mail-hq2.kaspersky.com", Issuer "Kaspersky MailRelays CA G3" (verified OK)) by mailhub12.kaspersky-labs.com (Postfix) with ESMTPS id AA907774B5; Thu, 25 Mar 2021 19:03:25 +0300 (MSK) Received: from [10.16.171.77] (10.64.68.129) by hqmailmbx3.avp.ru (10.64.67.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 25 Mar 2021 19:03:24 +0300 Subject: Re: [RFC PATCH v7 14/22] virtio/vsock: rest of SOCK_SEQPACKET support To: Stefano Garzarella CC: Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Jorgen Hansen , Norbert Slusarek , Andra Paraschiv , Colin Ian King , Jeff Vander Stoep , Alexander Popov , "kvm@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "stsp2@yandex.ru" , "oxffffaa@gmail.com" References: <20210323130716.2459195-1-arseny.krasnov@kaspersky.com> <20210323131332.2461409-1-arseny.krasnov@kaspersky.com> <20210325101841.o7gs7peafxwb7rfd@steredhat> From: Arseny Krasnov Message-ID: <14dacfcf-1385-93d0-b413-611e6b7fca4a@kaspersky.com> Date: Thu, 25 Mar 2021 19:03:24 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210325101841.o7gs7peafxwb7rfd@steredhat> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.64.68.129] X-ClientProxiedBy: hqmailmbx2.avp.ru (10.64.67.242) To hqmailmbx3.avp.ru (10.64.67.243) X-KSE-ServerInfo: hqmailmbx3.avp.ru, 9 X-KSE-AntiSpam-Interceptor-Info: scan successful X-KSE-AntiSpam-Version: 5.9.20, Database issued on: 03/25/2021 15:37:01 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 0 X-KSE-AntiSpam-Info: Lua profiles 162675 [Mar 25 2021] X-KSE-AntiSpam-Info: LuaCore: 438 438 e169a60cee0e977a975a890ed8ef829a2851344a X-KSE-AntiSpam-Info: Version: 5.9.20.0 X-KSE-AntiSpam-Info: Envelope from: arseny.krasnov@kaspersky.com X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: 127.0.0.199:7.1.2;kaspersky.com:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1 X-KSE-AntiSpam-Info: Rate: 0 X-KSE-AntiSpam-Info: Status: not_detected X-KSE-AntiSpam-Info: Method: none X-KSE-Antiphishing-Info: Clean X-KSE-Antiphishing-ScanningType: Deterministic X-KSE-Antiphishing-Method: None X-KSE-Antiphishing-Bases: 03/25/2021 15:40:00 X-KSE-AttachmentFiltering-Interceptor-Info: no applicable attachment filtering rules found X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 25.03.2021 15:18:00 X-KSE-BulkMessagesFiltering-Scan-Result: InTheLimit X-KSE-AttachmentFiltering-Interceptor-Info: no applicable attachment filtering rules found X-KSE-BulkMessagesFiltering-Scan-Result: InTheLimit X-KLMS-Rule-ID: 52 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Status: not scanned, disabled by settings X-KLMS-AntiSpam-Interceptor-Info: not scanned X-KLMS-AntiPhishing: Clean, bases: 2021/03/25 14:47:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2021/03/25 13:43:00 #16496755 X-KLMS-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25.03.2021 13:18, Stefano Garzarella wrote: > On Tue, Mar 23, 2021 at 04:13:29PM +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 >> --- >> v6 -> v7: >> In 'virtio_transport_seqpacket_enqueue()', 'next_tx_msg_id' is updated >> in both cases when message send successfully or error occured. >> >> include/linux/virtio_vsock.h | 7 ++ >> net/vmw_vsock/virtio_transport_common.c | 88 ++++++++++++++++++++++++- >> 2 files changed, 93 insertions(+), 2 deletions(-) >> >> diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h >> index 0e3aa395c07c..ab5f56fd7251 100644 >> --- a/include/linux/virtio_vsock.h >> +++ b/include/linux/virtio_vsock.h >> @@ -22,6 +22,7 @@ struct virtio_vsock_seq_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 >> @@ -89,6 +92,10 @@ virtio_transport_dgram_dequeue(struct vsock_sock *vsk, >> size_t len, int flags); >> >> int >> +virtio_transport_seqpacket_enqueue(struct vsock_sock *vsk, >> + struct msghdr *msg, >> + 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 bfe0d7026bf8..01a56c7da8bd 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->seq_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); >> @@ -595,6 +639,46 @@ 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, >> + size_t len) >> +{ >> + int written = -1; >> + >> + if (msg->msg_iter.iov_offset == 0) { >> + /* Send SEQBEGIN. */ >> + if (virtio_transport_seqpacket_send_ctrl(vsk, >> + VIRTIO_VSOCK_OP_SEQ_BEGIN, >> + len, >> + msg->msg_flags) < 0) >> + goto out; >> + } >> + >> + written = virtio_transport_stream_enqueue(vsk, msg, len); >> + >> + if (written < 0) >> + goto out; >> + >> + if (msg->msg_iter.count == 0) { >> + /* Send SEQEND. */ >> + virtio_transport_seqpacket_send_ctrl(vsk, >> + VIRTIO_VSOCK_OP_SEQ_END, >> + 0, >> + msg->msg_flags); > What happen if this fail? > > In the previous version we returned -1, now we return the bytes > transmitted, is that right? Ack, i'll fix it > > The rest LGTM. > >> + } >> +out: >> + /* Update next id on error or message transmission done. */ >> + if (written < 0 || msg->msg_iter.count == 0) { >> + struct virtio_vsock_sock *vvs = vsk->trans; >> + >> + vvs->seq_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, >> @@ -1014,7 +1098,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 >> >