Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4233964pxf; Tue, 23 Mar 2021 06:13:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkNOiZGcABaRFIrLoAfXgGKsSJ+p7fCcKaGffQld0qIPiVeFYy+LVTbhfPYuO27z+aTjpz X-Received: by 2002:aa7:c403:: with SMTP id j3mr4543686edq.137.1616505230993; Tue, 23 Mar 2021 06:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616505230; cv=none; d=google.com; s=arc-20160816; b=Ui40K8/hFYwnSW0NL5ZfUADsf7S9MyJ5Iw7XOUnQv+STL+NmYvaR9Du24M2cHmBTu7 15QQBfmuWy30vtN6yqzyVNH3T97U3lkdJKN1C+0hcDQNEfeJ7UYcgvL7EqwWF+Sorzhj mBR00uHW83AluUPopqaYNkRwdyk1itWaEe7ztCrDsC4hEsdXrb+IjI93u+b/CteIHHfC K0eegS+4MIGmVIa7QY0BAIy3AXrfnVmkajsMGcMMHOosBLqTqiv7LWr14gGatu/z/3lS n5U5jl6fjhALKQcdmkKLqr7/4W6UeD4wFIlGfAoY3zo609n1FFnj6TPjaImCdh1liECY dJPA== 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=G/SQfMTYxcXZHgmRt90aeYj0Ecb+uFfrAcgJZrHNEZk=; b=YcPgEvrj9LgIe40dWIWrPRj5+q71CWEXWKKeiu9wXPYGtfpKhDOtxheQHfiYS1Njzq 2wLL3M/+ePnFLXkvvXQ5mxPoBcaFIF+9fipNrXzz9DA3ryefjQTk+tjKizI/YtrHE+25 Qpze1hvWQ74cokBIjndKdcqmhnCAqz9MAKgqq8s/aBsUINCPTNv2Wgfaz+zsqlZxlByL lahPING4I8wAyvp2QwScKZ/2hRhoBVB50Mef57Xr7N0Ew4m4p8ZaEUp3H147iy1azfjA vijCxCkkzfHtKPl2q6Azrw8BiG1sdr2l9Swn7lIuPlhZeaq8n+enRowdWa/R/16oConI bK2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kaspersky.com header.s=mail202102 header.b=tZILYMYB; 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 k23si4057285ejv.188.2021.03.23.06.13.28; Tue, 23 Mar 2021 06:13:50 -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=tZILYMYB; 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 S231548AbhCWNKv (ORCPT + 99 others); Tue, 23 Mar 2021 09:10:51 -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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: linux-kernel@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 --- 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 -- 2.25.1