Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp483222pxj; Fri, 11 Jun 2021 04:13:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlrhY3iqN67IXXCm6erI4+9jXpPzznY9rqtUZtbSOW7cfXDJAUJIVObvHKniS9V2TVDd3T X-Received: by 2002:a17:906:bb0e:: with SMTP id jz14mr3129166ejb.285.1623410002703; Fri, 11 Jun 2021 04:13:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623410002; cv=none; d=google.com; s=arc-20160816; b=SmOiWpL6dE6IfhPy8DHAI1clWUR7MPHrAhddArvwKN8V4wKzG0GWP1Pk1KYJKW6xJ7 kwuHLxYLRPE6GdAi5ZmUkPqnteBLZlOQXKXA8daFvY4QgT9TnZUc94eYDgiApr7gcnyo cWJZDGuKQTqFSbCuI6V1XYaHqRoK/6kVXrCCelcUNVlM1eIjL0weIfiM4Hvv1eW/Ycdf ktnnV7S3kVLgFIoXZqzzeU/dxrLxyhr6qVqauKmotQazmMAol3O3rUEUMNF3cJv/PrIb 7FwopCmUXvFrsZLS4iiY5cSes25WPyKdq9Md9iGgqq/+6/r493vtsQHahP2p3cW4mPxt 9FgA== 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=UBsavzFZWcT0S3IYlrCNPPD8gQTQS24RNjbAotniV7I=; b=IEsgjl0xsU1tXB0FZ+snoEDU5Gglk0fMuTIZevxcKFyokUMSxWp3L2UOlvUDLoPlZS 26ykfbmKsHLGdITktQkfOxjge39QR90QlPKATWxDOc1HK9DsN86XxTYZORAgU0ai5IzG D4MGpXNeDqIbwqoHVRaaCwYRzd4qUwViJlg12OgYaP9C1BWO6wKxbvSm0/Uk7tItcPUG GKfgdYdbd/boO/YYfGv6JI8QmT7A3ktjLd/ErGWIYDDFd8hjhFBzLAYWw2/hAnwL+Che 2rYzn4jb6hCE8arA54o16RzQkKv9twkG2LNOXKC4Y/Yw8YkZwuSWHU7cIulghBfoDZqN GW5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kaspersky.com header.s=mail202102 header.b=BPFOurmh; 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 n8si4697988edq.61.2021.06.11.04.13.00; Fri, 11 Jun 2021 04:13:22 -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=BPFOurmh; 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 S231569AbhFKLMc (ORCPT + 99 others); Fri, 11 Jun 2021 07:12:32 -0400 Received: from mx13.kaspersky-labs.com ([91.103.66.164]:14236 "EHLO mx13.kaspersky-labs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231550AbhFKLMb (ORCPT ); Fri, 11 Jun 2021 07:12:31 -0400 Received: from relay13.kaspersky-labs.com (unknown [127.0.0.10]) by relay13.kaspersky-labs.com (Postfix) with ESMTP id 083E8520CC7; Fri, 11 Jun 2021 14:10:31 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kaspersky.com; s=mail202102; t=1623409831; bh=UBsavzFZWcT0S3IYlrCNPPD8gQTQS24RNjbAotniV7I=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=BPFOurmhhUDzU8TyONPr6clg71tv7trlVtQaYL3zsB7UMrBLnNfW8XdoGgDHiISuc 0qMiaFbEwD08iwQKlbbEPOojWsnTIs8QKiDZvBc/SPnnDKBCXsk8gWClxBbfFUbaSo 6N4JGCV26eX/jzero5IyomXckNmS8G0wDuz3WZpOi/FPF1LeZNaow3eesoArt1IrUv kOwcRArCt3kNu715o1jwAPygytyxoD4JdCKO+frDQaC9C+OSRj7MfHfeB1WOI+fyvh DBCVGldzsfmLspEZKvGjO3RzyTLlRarhHVSD3tSwfKkFKxwt4wscYtWciiMXjdvAPS 0+edr1Z+EOmYw== 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 mailhub13.kaspersky-labs.com (Postfix) with ESMTPS id A773C520CA6; Fri, 11 Jun 2021 14:10:30 +0300 (MSK) Received: from arseniy-pc.avp.ru (10.64.68.128) 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.14; Fri, 11 Jun 2021 14:10:30 +0300 From: Arseny Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Arseny Krasnov , Andra Paraschiv , Colin Ian King , Norbert Slusarek CC: , , , , Subject: [PATCH v11 03/18] af_vsock: separate receive data loop Date: Fri, 11 Jun 2021 14:10:21 +0300 Message-ID: <20210611111024.3651284-1-arseny.krasnov@kaspersky.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611110744.3650456-1-arseny.krasnov@kaspersky.com> References: <20210611110744.3650456-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.64.68.128] X-ClientProxiedBy: hqmailmbx1.avp.ru (10.64.67.241) 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: 06/11/2021 10:44:49 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 0 X-KSE-AntiSpam-Info: Lua profiles 164266 [Jun 11 2021] X-KSE-AntiSpam-Info: Version: 5.9.20.0 X-KSE-AntiSpam-Info: Envelope from: arseny.krasnov@kaspersky.com X-KSE-AntiSpam-Info: LuaCore: 448 448 71fb1b37213ce9a885768d4012c46ac449c77b17 X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: 127.0.0.199:7.1.2;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;arseniy-pc.avp.ru:7.1.1;kaspersky.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: 06/11/2021 10:48: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: 11.06.2021 5:31: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/06/11 09:09:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2021/06/10 21:54:00 #16707142 X-KLMS-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some code in receive data loop could be shared between SEQPACKET and STREAM sockets, while another part is type specific, so move STREAM specific data receive logic to '__vsock_stream_recvmsg()' dedicated function, while checks, that will be same for both STREAM and SEQPACKET sockets, stays in 'vsock_connectible_recvmsg()'. Signed-off-by: Arseny Krasnov Reviewed-by: Stefano Garzarella --- net/vmw_vsock/af_vsock.c | 116 ++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 4269e80b02cd..c4f6bfa1e381 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1896,65 +1896,22 @@ static int vsock_wait_data(struct sock *sk, struct wait_queue_entry *wait, return data; } -static int -vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, - int flags) +static int __vsock_stream_recvmsg(struct sock *sk, struct msghdr *msg, + size_t len, int flags) { - struct sock *sk; - struct vsock_sock *vsk; + struct vsock_transport_recv_notify_data recv_data; const struct vsock_transport *transport; - int err; - size_t target; + struct vsock_sock *vsk; ssize_t copied; + size_t target; long timeout; - struct vsock_transport_recv_notify_data recv_data; + int err; DEFINE_WAIT(wait); - sk = sock->sk; vsk = vsock_sk(sk); - err = 0; - - lock_sock(sk); - transport = vsk->transport; - if (!transport || sk->sk_state != TCP_ESTABLISHED) { - /* Recvmsg is supposed to return 0 if a peer performs an - * orderly shutdown. Differentiate between that case and when a - * peer has not connected or a local shutdown occurred with the - * SOCK_DONE flag. - */ - if (sock_flag(sk, SOCK_DONE)) - err = 0; - else - err = -ENOTCONN; - - goto out; - } - - if (flags & MSG_OOB) { - err = -EOPNOTSUPP; - goto out; - } - - /* We don't check peer_shutdown flag here since peer may actually shut - * down, but there can be data in the queue that a local socket can - * receive. - */ - if (sk->sk_shutdown & RCV_SHUTDOWN) { - err = 0; - goto out; - } - - /* It is valid on Linux to pass in a zero-length receive buffer. This - * is not an error. We may as well bail out now. - */ - if (!len) { - err = 0; - goto out; - } - /* We must not copy less than target bytes into the user's buffer * before returning successfully, so we wait for the consume queue to * have that much data to consume before dequeueing. Note that this @@ -2013,6 +1970,67 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, if (copied > 0) err = copied; +out: + return err; +} + +static int +vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, + int flags) +{ + struct sock *sk; + struct vsock_sock *vsk; + const struct vsock_transport *transport; + int err; + + DEFINE_WAIT(wait); + + sk = sock->sk; + vsk = vsock_sk(sk); + err = 0; + + lock_sock(sk); + + transport = vsk->transport; + + if (!transport || sk->sk_state != TCP_ESTABLISHED) { + /* Recvmsg is supposed to return 0 if a peer performs an + * orderly shutdown. Differentiate between that case and when a + * peer has not connected or a local shutdown occurred with the + * SOCK_DONE flag. + */ + if (sock_flag(sk, SOCK_DONE)) + err = 0; + else + err = -ENOTCONN; + + goto out; + } + + if (flags & MSG_OOB) { + err = -EOPNOTSUPP; + goto out; + } + + /* We don't check peer_shutdown flag here since peer may actually shut + * down, but there can be data in the queue that a local socket can + * receive. + */ + if (sk->sk_shutdown & RCV_SHUTDOWN) { + err = 0; + goto out; + } + + /* It is valid on Linux to pass in a zero-length receive buffer. This + * is not an error. We may as well bail out now. + */ + if (!len) { + err = 0; + goto out; + } + + err = __vsock_stream_recvmsg(sk, msg, len, flags); + out: release_sock(sk); return err; -- 2.25.1