Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp132208pxb; Thu, 14 Jan 2021 21:57:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNeUL6tROWJ2gOCZaiEaP7wCV+DTXYbl/CLNNu/94CQNvOS+jfVach/vwct4Vri+tY45ty X-Received: by 2002:a05:6402:100c:: with SMTP id c12mr8685103edu.356.1610690271520; Thu, 14 Jan 2021 21:57:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610690271; cv=none; d=google.com; s=arc-20160816; b=jICXNzzVhfje5iFtYttS8vgIp2eLgcWzUodv8bx6ko/QfJtwCf/pbSvZY39Q2P34lY BCGNVjTho7Bcwiw19YJZwMCiuDcztosFFtQsHICpusm9FNwTILPLph8x8HnLOenwO3z4 3FLuQ3FA6cGRcFwOjQI0hjINaJB7Ft4ccVVjYpRkNzJiPO87HkhOo/Fsg9Jr1qQ6cBeJ Awk1/2K4oAfYe4C6+id6ZlGmncfxCzisvGSu9WcgAukPoKFlm9z78WyIorrR5rAnGtU6 wJPMUkJWDpT9kUCr6yxklda6meu9rWBOB9RxAgu0SgP6wetLgPcIF9AFWjPikNS2yqAP QoCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0/Rd09doNafb1GzsBb/ZiK/cvnJ0V4qaIqeOwSe6J1U=; b=O5VnaLyIDoQ9vfnvBDNIFEA3WWMcxJpUqaJrFqZ/o7TB5I9/a3A/OBwJz3P60rhCu9 e0YGMbqOpFvrk8bZ1RMDnOCAL/YXRblYJAqgMFUI5ftOtdmFt4zhVa6kXzObHhXgEYIx HJ8d4RlNLSALBWKh/mrqiU/6QEWWeOLzEpyucp2d7Ykq5XR5/Fr0DBfCh0nwuAmBfKGi /HPxQstB+i3O1htrpj8KkBH39NnkrDeExmP8OslLAesDpweiZrL5rx66W0pkRI7Glj1E VCwVhxz8Gpd4fy5UP/F7N3owzCsA0cdxZpgiVTcJ3t8jBasZ24EMsX//zbmkvki4/F6j pyAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kaspersky.com header.s=mail header.b="UrAAF/Zf"; 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 o9si2574639ejr.672.2021.01.14.21.57.28; Thu, 14 Jan 2021 21:57:51 -0800 (PST) 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=mail header.b="UrAAF/Zf"; 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 S1733283AbhAOFn0 (ORCPT + 99 others); Fri, 15 Jan 2021 00:43:26 -0500 Received: from mx12.kaspersky-labs.com ([91.103.66.155]:61427 "EHLO mx12.kaspersky-labs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732093AbhAOFnX (ORCPT ); Fri, 15 Jan 2021 00:43:23 -0500 Received: from relay12.kaspersky-labs.com (unknown [127.0.0.10]) by relay12.kaspersky-labs.com (Postfix) with ESMTP id 2BC3875F1E; Fri, 15 Jan 2021 08:42:38 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kaspersky.com; s=mail; t=1610689358; bh=0/Rd09doNafb1GzsBb/ZiK/cvnJ0V4qaIqeOwSe6J1U=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=UrAAF/ZffApCuHAUyivhX2MuchbmfyWHOOdL4ad0ei5MQBZE48HjbsYnJZRtcx+Uw MGXEeAhlMLprxjPMAnhYBiPL7TvNFHAiEnrBeTq/dnFtreFO1a6lzRcF75+fkm/ZhB lnaiSJMNXZyA1bdwZpWhl+HQt5yHR908wrJN7LEI= 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 D3FB475F1C; Fri, 15 Jan 2021 08:42:37 +0300 (MSK) Received: from arseniy-pc.avp.ru (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.2044.4; Fri, 15 Jan 2021 08:42:37 +0300 From: Arseny Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Arseny Krasnov , Colin Ian King , Andra Paraschiv , Jeff Vander Stoep CC: , , , , , Subject: [RFC PATCH v2 05/13] af_vsock: implement send logic for SOCK_SEQPACKET Date: Fri, 15 Jan 2021 08:42:27 +0300 Message-ID: <20210115054230.1456257-1-arseny.krasnov@kaspersky.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210115053553.1454517-1-arseny.krasnov@kaspersky.com> References: <20210115053553.1454517-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.64.68.129] X-ClientProxiedBy: hqmailmbx3.avp.ru (10.64.67.243) 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.16, Database issued on: 01/15/2021 05:18:27 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 10 X-KSE-AntiSpam-Info: Lua profiles 161159 [Jan 15 2021] X-KSE-AntiSpam-Info: LuaCore: 420 420 0b339e70b2b1bb108f53ec9b40aa316bba18ceea X-KSE-AntiSpam-Info: Version: 5.9.16.0 X-KSE-AntiSpam-Info: Envelope from: arseny.krasnov@kaspersky.com X-KSE-AntiSpam-Info: {Prob_from_in_msgid} X-KSE-AntiSpam-Info: {Tracking_date, moscow} X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: arseniy-pc.avp.ru:7.1.1;kaspersky.com:7.1.1;127.0.0.199:7.1.2;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1 X-KSE-AntiSpam-Info: Rate: 10 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: 01/15/2021 05:21: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: 15.01.2021 2:12: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/01/15 05:03:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2021/01/15 02:12:00 #16041563 X-KLMS-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds some logic to current stream enqueue function for SEQPACKET support: 1) Send record begin marker with length of record. 2) Return value from enqueue function is wholevrecord length or error for SOCK_SEQPACKET. Signed-off-by: Arseny Krasnov --- include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index 46073842d489..ec6bf4600ef8 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h @@ -136,6 +136,7 @@ struct vsock_transport { bool (*stream_allow)(u32 cid, u32 port); /* SEQ_PACKET. */ + bool (*seqpacket_seq_send_len)(struct vsock_sock *, size_t len); size_t (*seqpacket_seq_get_len)(struct vsock_sock *); ssize_t (*seqpacket_dequeue)(struct vsock_sock *, struct msghdr *, size_t len, int flags); diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 5bf887190881..4a7cdf7756c0 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1683,8 +1683,8 @@ static int vsock_stream_getsockopt(struct socket *sock, return 0; } -static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, - size_t len) +static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg, + size_t len) { struct sock *sk; struct vsock_sock *vsk; @@ -1737,6 +1737,12 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, if (err < 0) goto out; + if (sk->sk_type == SOCK_SEQPACKET) { + err = transport->seqpacket_seq_send_len(vsk, len); + if (err < 0) + goto out; + } + while (total_written < len) { ssize_t written; @@ -1815,13 +1821,31 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, } out_err: - if (total_written > 0) - err = total_written; + if (total_written > 0) { + /* Return number of written bytes only if: + * 1) SOCK_STREAM socket. + * 2) SOCK_SEQPACKET socket when whole buffer is sent. + */ + if (sk->sk_type == SOCK_STREAM || total_written == len) + err = total_written; + } out: release_sock(sk); return err; } +static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, + size_t len) +{ + return vsock_connectible_sendmsg(sock, msg, len); +} + +static int vsock_seqpacket_sendmsg(struct socket *sock, struct msghdr *msg, + size_t len) +{ + return vsock_connectible_sendmsg(sock, msg, len); +} + static int vsock_wait_data(struct sock *sk, struct wait_queue_entry *wait, long timeout, struct vsock_transport_recv_notify_data *recv_data, -- 2.25.1