Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2094776pxb; Thu, 11 Feb 2021 04:20:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwV30GavBQIFGs90rNNKmFeuRjr9LpdN7M3IbxiwFfAoVmZcNgwMUffUsj1DLiGqaO8QEN4 X-Received: by 2002:aa7:d7d3:: with SMTP id e19mr7886148eds.288.1613046054673; Thu, 11 Feb 2021 04:20:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613046054; cv=none; d=google.com; s=arc-20160816; b=Ke3UgiKgfyA1Wm4lN8tB2qgCSIRZ5CIJsykt58X5ufrCgt472V57JmUl2bSn5P8kTU enadr2uvHnNj2jubrhdRn+WcqxXypXPK2C3I8t+cJJGV63BbL8dbD1oizsIR6i+zYC+y eS5J5ckfgTMAaxHgYxTDPT8tl9GvFYbpuMtyKeCnVHWMrb3zUj28tqntcpts0tjm3Fx5 zLuZzWHI0wsaE3GoQH2cmZmKJLVhsOgdFPETp/k2IJpsdKH6SgjF1eIAxAd21qb9KhT7 RGfhippplBSAFdB2fGmkjtZqdQ+yf4bH9slXdM1IxsHS7rPvtjwqSxgTxzu7+QNPErqp RdBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BEPfHOoOC9PkCRSqxehgaNL1z0I7JWFoen0MxY6aOAg=; b=DAVbLonpg+uyujgoODll4/bDU6+UM2t4K8jTUXvNMkMBRGQ9+TG2zZjvETQd89XQ41 KYhtgmDtEW69TcP7wacAmmkJhIj/Yj3vFUxDkdmgS40LAu1MCi7jVKHcOw/tnLbpaidZ vH7ix2vE6OWIr/w+ZBckbzYE3BXoOlxsUMt02eXoSGT6HiBiYN3eZMWaBg9j/Cz+Oqha tTcGbjcptF2pH1VDkUM9MI3m4GW6TraHO4krZ3wiMkpys1b+Bf3530d6bB0O6OXiZ7FY a9NI0qySUC21WWEVWqILrorggsMutGGm60sDva5BNo7kzK6gY7jverviJYK0yGb4YHNl JuSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AuYYYtM4; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v14si3681015ejx.593.2021.02.11.04.20.27; Thu, 11 Feb 2021 04:20:54 -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=@redhat.com header.s=mimecast20190719 header.b=AuYYYtM4; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231142AbhBKMS7 (ORCPT + 99 others); Thu, 11 Feb 2021 07:18:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60919 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbhBKMPr (ORCPT ); Thu, 11 Feb 2021 07:15:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613045656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BEPfHOoOC9PkCRSqxehgaNL1z0I7JWFoen0MxY6aOAg=; b=AuYYYtM4YPQiXLrU+mmQDhDY7HlqLkNfUD6bMoXXW7qWNzGV38AdvNuITmhoZ2I63gNnum ApMfYF32II/0xDxHM5wOzX6fwPJ3pM9pmEtJoBQcby3LaRXMHXxw4zlW9MgDDAwFHCJWdA 7tJCThEGMhi8lggDbNdziwMfMZznvkM= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-316-puFAcDOQPNOdGZgpg3D0_g-1; Thu, 11 Feb 2021 07:14:14 -0500 X-MC-Unique: puFAcDOQPNOdGZgpg3D0_g-1 Received: by mail-ed1-f70.google.com with SMTP id i4so4561459edt.11 for ; Thu, 11 Feb 2021 04:14:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BEPfHOoOC9PkCRSqxehgaNL1z0I7JWFoen0MxY6aOAg=; b=HhDeYRv+JQmtlX39ULMtCwRmOVZoaGpP9/kgqfcZly1qv5eZpXRZkC9wZ23bR1aG+x XWyKavKvHbPhUmFabFJMa7U4BgDSWMDmsruBm9RrC0ejQVTUNB6/n1eIfKfsZro5dDWn /c3L5D7x+o4JI1Z7F8o6Y4k2Qxj+1ZKqtim++biT5vwnE0KdzaP6RGaFWsNYB6p6eD4h azKGtaZRTYeUuWI83GGK596+wd/mNug1FF7A5kOWq8S1LhZ/Mv2BljYV3SMsPKY5nFzs rvjb4odyeRDbs23/xjRrxvBRkNsVGbjBDnlYzhFC4kVUue+5DjwALsmvUVhSSVoRlUII HJGw== X-Gm-Message-State: AOAM530XW4zv4jdQE5EAyPUo9B8O9Lzq572SjE0Hv0SwbNrTMOLOdcq6 IGBGDEcALffajN4WKUNlyrMaKPMecrF0BQn8iHJLPztJEpsFLuPP3xPj0zZeyZhREabtbEdIYTz KhHkvcSV6VA0P78TLVRgPTvbp X-Received: by 2002:a17:906:f8d1:: with SMTP id lh17mr2835204ejb.137.1613045652829; Thu, 11 Feb 2021 04:14:12 -0800 (PST) X-Received: by 2002:a17:906:f8d1:: with SMTP id lh17mr2835178ejb.137.1613045652627; Thu, 11 Feb 2021 04:14:12 -0800 (PST) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id t23sm4115198ejs.4.2021.02.11.04.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 04:14:12 -0800 (PST) Date: Thu, 11 Feb 2021 13:14:09 +0100 From: Stefano Garzarella To: Arseny Krasnov Cc: Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Jorgen Hansen , Colin Ian King , Andra Paraschiv , Jeff Vander Stoep , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stsp2@yandex.ru, oxffffaa@gmail.com Subject: Re: [RFC PATCH v4 05/17] af_vsock: separate wait space loop Message-ID: <20210211121409.y3yo3zzvm24rhmry@steredhat> References: <20210207151259.803917-1-arseny.krasnov@kaspersky.com> <20210207151545.804889-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210207151545.804889-1-arseny.krasnov@kaspersky.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 07, 2021 at 06:15:41PM +0300, Arseny Krasnov wrote: >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 | 93 ++++++++++++++++++++++++++-------------- > 2 files changed, 62 insertions(+), 33 deletions(-) > >diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h >index bb6a0e52be86..19f6f22821ec 100644 >--- a/include/net/af_vsock.h >+++ b/include/net/af_vsock.h >@@ -205,6 +205,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 3d8af987216a..ea99261e88ac 100644 >--- a/net/vmw_vsock/af_vsock.c >+++ b/net/vmw_vsock/af_vsock.c >@@ -1693,6 +1693,64 @@ 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)) { Maybe a new line here, like in the original code, would help the readability. >+ /* 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) > { After removing the wait loop in vsock_connectible_sendmsg(), we should remove the 'timeout' variable because it is no longer used. >@@ -1751,39 +1809,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 >