Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7012376pxb; Wed, 17 Feb 2021 21:47:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGFp95lzK51V+YLL298lqy418vYEM1aG7HJnnAGfKcus+FPdeLd7RRAJdRoNq3Blem3rxL X-Received: by 2002:a05:6402:1ac2:: with SMTP id ba2mr2271676edb.81.1613627251073; Wed, 17 Feb 2021 21:47:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613627251; cv=none; d=google.com; s=arc-20160816; b=KMJ1gLZiSq4ymOE4qUb75d2DnwpdX6ZAoeKTzlxqEUiqJGjAUVVQX7Sed8fMxpeJlb +AyDXPud8CCgv+SQYqgiVg3vhMaVx4zs8FgGZpQ8WDAC9HN8wjPtIxShqzu/+w+f5MV8 EsCQeb3Unl58jqDK92dY2ajmLMEC5YsDMJcDi6EThdJLsGThEwjn6uPUhZwavFUIJK2U LmQHkPBuM5rgLw0Q3Jtny8zB4P3YXPRe3p+R6KRXthD4gU2kkDlpRJp6VwA7gJFBrv/E za8g6ZW7Mnu0nfZEnYrLE8vYfO2FZd2TWyWa/00ZU6hdG6uhHqcgCRMK6/LRsWKK00Or 0/cA== 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=y2FXGfgqiRxkhzAUueFYQ0jRDtLlP6btDCtHMcDJ/os=; b=frVeHQ1xSWkFoXZGrGkTPRQtQjRTIp25PylHdr7QjETeRK9ECCiRh3bpwsdfvv2jj2 HTp2Bq3xtm6emfa66XsaWhYY4xQv4XHY7WGBxMtEnqsHiSCjb5YVhg2yw3alJiEZItRY 3fpTtnwzg2sxlUcOKGe1FmsoJGnxpNcKwW3+7oZZYYZOM/J3BEkyInckdxP6g2NcJzLJ a4Od7eohTRuOzr5tx9OziFTQZLLXE3y6DNkXfxrE1csppMhDsy5uvtehKIfG9A4CYs2j ywWtRagqZbChG6Gzk9P8Ds9JiZTObudPex0/zUu7cZ4I9/ykJjI4PTMr5OnI2lPB5qTe J0OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kaspersky.com header.s=mail202102 header.b=bxh4HdSz; 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 kj22si3013312ejc.691.2021.02.17.21.47.07; Wed, 17 Feb 2021 21:47:31 -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=mail202102 header.b=bxh4HdSz; 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 S230042AbhBRFoj (ORCPT + 99 others); Thu, 18 Feb 2021 00:44:39 -0500 Received: from mx13.kaspersky-labs.com ([91.103.66.164]:44383 "EHLO mx13.kaspersky-labs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231311AbhBRFiV (ORCPT ); Thu, 18 Feb 2021 00:38:21 -0500 Received: from relay13.kaspersky-labs.com (unknown [127.0.0.10]) by relay13.kaspersky-labs.com (Postfix) with ESMTP id 30579520D28; Thu, 18 Feb 2021 08:37:34 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kaspersky.com; s=mail202102; t=1613626654; bh=y2FXGfgqiRxkhzAUueFYQ0jRDtLlP6btDCtHMcDJ/os=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=bxh4HdSzjbqqDpg/vCDi3hKAy3xrmOwYPXsf8tEYcdxOaiqgiHSILZq9sTn3iizOi UU+ZrmYJhQ4PwMjKD0X9FIus2k711ug8uuvha5eygGUuECpL3Rd+GJTt1EFVwxhSQw wK+M/mmlFqUda2HlTEIBQVxaOvFrNv8xQdJz4x4aQzrwj7uk2PbTrGdU47807P84mo 5SxJNqF9KbOf3m8zlFE649uRWOFSxC6A7NoBfvVn2ulGcWY4MjvIlaUPyKnrVZWiBg JSCArIyhcb4emPRZw9+ZrwrEIEj+5Kl27vx8mWz59wAhmgFZphXy61S29fBW4iT45x G769RSXNiTM1Q== 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 44E50520CE1; Thu, 18 Feb 2021 08:37:33 +0300 (MSK) Received: from arseniy-pc.avp.ru (10.64.64.121) 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; Thu, 18 Feb 2021 08:36:59 +0300 From: Arseny Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Arseny Krasnov , Jorgen Hansen , Colin Ian King , Andra Paraschiv , Norbert Slusarek CC: , , , , , Subject: [RFC PATCH v5 03/19] af_vsock: separate receive data loop Date: Thu, 18 Feb 2021 08:36:50 +0300 Message-ID: <20210218053653.1067086-1-arseny.krasnov@kaspersky.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218053347.1066159-1-arseny.krasnov@kaspersky.com> References: <20210218053347.1066159-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.64.64.121] 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.16, Database issued on: 02/06/2021 23:52:08 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 10 X-KSE-AntiSpam-Info: Lua profiles 161679 [Feb 06 2021] X-KSE-AntiSpam-Info: LuaCore: 422 422 763e61bea9fcfcd94e075081cb96e065bc0509b4 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: 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: 02/06/2021 23:55: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: 06.02.2021 21:17: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/02/18 04:51:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2021/02/18 04:31:00 #16269527 X-KLMS-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This moves STREAM specific data receive logic to dedicated function: '__vsock_stream_recvmsg()', while checks that will be same for both types of socket are in shared function: 'vsock_connectible_recvmsg()'. Signed-off-by: Arseny Krasnov --- 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 6cf7bb977aa1..d277dc1cdbdf 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1894,65 +1894,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 occured 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 @@ -2011,6 +1968,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