From patchwork Tue Mar 23 13:10:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseny Krasnov X-Patchwork-Id: 12157757 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D60AC433E2 for ; Tue, 23 Mar 2021 13:11:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52AD9619C0 for ; Tue, 23 Mar 2021 13:11:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231531AbhCWNKs (ORCPT ); Tue, 23 Mar 2021 09:10:48 -0400 Received: from mx13.kaspersky-labs.com ([91.103.66.164]:47085 "EHLO mx13.kaspersky-labs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231569AbhCWNKh (ORCPT ); Tue, 23 Mar 2021 09:10:37 -0400 Received: from relay13.kaspersky-labs.com (unknown [127.0.0.10]) by relay13.kaspersky-labs.com (Postfix) with ESMTP id 9E5A2521244; Tue, 23 Mar 2021 16:10:34 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kaspersky.com; s=mail202102; t=1616505034; bh=G/SQfMTYxcXZHgmRt90aeYj0Ecb+uFfrAcgJZrHNEZk=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=tZILYMYBnVMoslN4yeidP7cOlYDPUz2m/LsMgdZ3d5YZxtvgs/O3EOJuYRT4IrmQQ q/iT48IVCUGcIn5vsLW4gnTVMVSoWWvLAPrKL/yTX2l4jUWi7eNB8myDwuXsulZmDT pOrPDbUswFgyyjTcibk4HYdfCzoJBONdm+taJZloqjqZasNCWm7nK4rvKmTJ9iNH68 d9E+Mzyd0cKIBaO42lsXN4C60flE1cgOhROGPY3vwjBymb5Xgy3kqlXHkxiRpQfjEG +dA9HgLu95wwtmLhd837DGkG8RnngJt1Vy9///jRZjSWq0Y+FkT/Y2y/+vybFLluji XZklBtedpbiyg== 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 4E5B0521220; Tue, 23 Mar 2021 16:10:34 +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.2176.2; Tue, 23 Mar 2021 16:10:33 +0300 From: Arseny Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Jorgen Hansen , Colin Ian King , Andra Paraschiv , Norbert Slusarek , Alexander Popov CC: , , , , , , Subject: [RFC PATCH v7 05/22] af_vsock: separate wait space loop Date: Tue, 23 Mar 2021 16:10:23 +0300 Message-ID: <20210323131026.2460194-1-arseny.krasnov@kaspersky.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210323130716.2459195-1-arseny.krasnov@kaspersky.com> References: <20210323130716.2459195-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 X-Originating-IP: [10.64.64.121] 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.20, Database issued on: 03/23/2021 12:55:25 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 10 X-KSE-AntiSpam-Info: Lua profiles 162595 [Mar 23 2021] X-KSE-AntiSpam-Info: LuaCore: 437 437 85ecb8eec06a7bf2f475f889e784f42bce7b4445 X-KSE-AntiSpam-Info: Version: 5.9.20.0 X-KSE-AntiSpam-Info: Envelope from: arseny.krasnov@kaspersky.com X-KSE-AntiSpam-Info: {Prob_from_in_msgid} X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;arseniy-pc.avp.ru:7.1.1;127.0.0.199:7.1.2;kaspersky.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: 03/23/2021 12:58: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: 23.03.2021 11:46: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/23 11:43:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2021/03/23 11:40:00 #16480199 X-KLMS-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This moves loop that waits for space on send to separate function, because it will be used for SEQ_BEGIN/SEQ_END sending before and after data transmission. Waiting for SEQ_BEGIN/SEQ_END is needed because such packets carries SEQPACKET header that couldn't be fragmented by credit mechanism, so to avoid it, sender waits until enough space will be ready. Signed-off-by: Arseny Krasnov Reviewed-by: Stefano Garzarella --- include/net/af_vsock.h | 2 + net/vmw_vsock/af_vsock.c | 99 +++++++++++++++++++++++++--------------- 2 files changed, 63 insertions(+), 38 deletions(-) diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index 74ac8a4c4168..7232f6c42a36 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h @@ -204,6 +204,8 @@ void vsock_remove_sock(struct vsock_sock *vsk); void vsock_for_each_connected_socket(void (*fn)(struct sock *sk)); int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk); bool vsock_find_cid(unsigned int cid); +int vsock_wait_space(struct sock *sk, size_t space, int flags, + struct vsock_transport_send_notify_data *send_data); /**** TAP ****/ diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index fa0c37f97330..617ffe42693d 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1692,6 +1692,65 @@ static int vsock_connectible_getsockopt(struct socket *sock, return 0; } +int vsock_wait_space(struct sock *sk, size_t space, int flags, + struct vsock_transport_send_notify_data *send_data) +{ + const struct vsock_transport *transport; + struct vsock_sock *vsk; + long timeout; + int err; + + DEFINE_WAIT_FUNC(wait, woken_wake_function); + + vsk = vsock_sk(sk); + transport = vsk->transport; + timeout = sock_sndtimeo(sk, flags & MSG_DONTWAIT); + err = 0; + + add_wait_queue(sk_sleep(sk), &wait); + + while (vsock_stream_has_space(vsk) < space && + sk->sk_err == 0 && + !(sk->sk_shutdown & SEND_SHUTDOWN) && + !(vsk->peer_shutdown & RCV_SHUTDOWN)) { + + /* Don't wait for non-blocking sockets. */ + if (timeout == 0) { + err = -EAGAIN; + goto out_err; + } + + if (send_data) { + err = transport->notify_send_pre_block(vsk, send_data); + if (err < 0) + goto out_err; + } + + release_sock(sk); + timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, timeout); + lock_sock(sk); + if (signal_pending(current)) { + err = sock_intr_errno(timeout); + goto out_err; + } else if (timeout == 0) { + err = -EAGAIN; + goto out_err; + } + } + + if (sk->sk_err) { + err = -sk->sk_err; + } else if ((sk->sk_shutdown & SEND_SHUTDOWN) || + (vsk->peer_shutdown & RCV_SHUTDOWN)) { + err = -EPIPE; + } + +out_err: + remove_wait_queue(sk_sleep(sk), &wait); + return err; +} +EXPORT_SYMBOL_GPL(vsock_wait_space); + static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) { @@ -1699,10 +1758,8 @@ static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg, struct vsock_sock *vsk; const struct vsock_transport *transport; ssize_t total_written; - long timeout; int err; struct vsock_transport_send_notify_data send_data; - DEFINE_WAIT_FUNC(wait, woken_wake_function); sk = sock->sk; vsk = vsock_sk(sk); @@ -1740,9 +1797,6 @@ static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg, goto out; } - /* Wait for room in the produce queue to enqueue our user's data. */ - timeout = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); - err = transport->notify_send_init(vsk, &send_data); if (err < 0) goto out; @@ -1750,39 +1804,8 @@ static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg, while (total_written < len) { ssize_t written; - add_wait_queue(sk_sleep(sk), &wait); - while (vsock_stream_has_space(vsk) == 0 && - sk->sk_err == 0 && - !(sk->sk_shutdown & SEND_SHUTDOWN) && - !(vsk->peer_shutdown & RCV_SHUTDOWN)) { - - /* Don't wait for non-blocking sockets. */ - if (timeout == 0) { - err = -EAGAIN; - remove_wait_queue(sk_sleep(sk), &wait); - goto out_err; - } - - err = transport->notify_send_pre_block(vsk, &send_data); - if (err < 0) { - remove_wait_queue(sk_sleep(sk), &wait); - goto out_err; - } - - release_sock(sk); - timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, timeout); - lock_sock(sk); - if (signal_pending(current)) { - err = sock_intr_errno(timeout); - remove_wait_queue(sk_sleep(sk), &wait); - goto out_err; - } else if (timeout == 0) { - err = -EAGAIN; - remove_wait_queue(sk_sleep(sk), &wait); - goto out_err; - } - } - remove_wait_queue(sk_sleep(sk), &wait); + if (vsock_wait_space(sk, 1, msg->msg_flags, &send_data)) + goto out_err; /* These checks occur both as part of and after the loop * conditional since we need to check before and after