Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2051512pxb; Mon, 18 Jan 2021 07:05:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtKIdTUB9ZoBgtshktAU6vUXWMms/CG9vLmDz6uUmphwduVS+MN1V03hEp0yDrEMSQfAw2 X-Received: by 2002:a05:6402:1383:: with SMTP id b3mr18900750edv.100.1610982343018; Mon, 18 Jan 2021 07:05:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610982343; cv=none; d=google.com; s=arc-20160816; b=Xu34ICpB3qCsnQ/nGbZq2ynbVD92Fbbl0tu9ccI5OYteAIzldoaTQyV3AMXX3zGA2+ +6seZ6+SxCjss+lEUtYQ+SRcZuaCw3Bt0/3pzUqbgsWAXK92sO3MQgcz38d+9NkMrfJP 6lDjBFJwCH8Zr/JcGAEgMlyYGNj4XKpZJ01M66NqZNn9GFoDCr3Pr7Bi2fiAJRUFUFXF p3/mGxc7pyO89BmYHluJcE1F5Nz4LenmBgBr4hpXwWCk9kfRWKUWqIGTwCSw9L76baR+ AWbvgD368sVS+Bk8kSeOfj+bqnhGAY7D/s4zLl40JDOtFAa0CPxzxdUIf1fvu/L3tzQg roug== 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=bvHYXveaY1fYHKCh/4G0s4Eb72E980+xC2zhbE72Tuc=; b=ZnhKx8TK2K7o31pcD4BbsbGjGvHJQgpaggTXTVIIDXmcMFvVkbpGM6uRD7pYDKBBl1 wZSju83QRyuaAejBfx/i5A3q3ruOGbR+WKtNJ8KbWBxF7/UfT+ZGonHeetFPxWbWeUJ7 lZRs73iudXILkh2hT9o/62D8loH4Ii7pZOtRWrWhK9IWpbihazR/tSkrKrbAZdhNkB2Y 5CdFeMmKH/n2h770orx3L4ScnKrltWeQFwYKL7y1FKHdD8St4jNrYP1qlIloFEvWtb0n BeqWwQpZ0vw7PpFcoJu0PUaFK8xizVh6weak+YiPn7FMkjB2sKRp7w4tSNKyIMTOu/O4 sATQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FyOH29Xz; 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 dc6si391880ejb.54.2021.01.18.07.05.17; Mon, 18 Jan 2021 07:05:43 -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=FyOH29Xz; 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 S2393229AbhARPBH (ORCPT + 99 others); Mon, 18 Jan 2021 10:01:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59102 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405292AbhAROxe (ORCPT ); Mon, 18 Jan 2021 09:53:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610981527; 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=bvHYXveaY1fYHKCh/4G0s4Eb72E980+xC2zhbE72Tuc=; b=FyOH29XzDEIYbttk4Mi0bU24VrkOgnqhwoY4qYvj8yO7YxApcqkbbA0QVlDxk7zNjzWvrU nqv6ifYuypBoMYgNR3ftGbVOrDyR7qdSiBberGXBjx4NaX/P+C43D1iCTTPm0F55t9J0Kv N1M2q2qZhMB9LMKBuM8uiCZboe78T/A= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-11-D-5vz38ZNSiuvY4IWpWGxg-1; Mon, 18 Jan 2021 09:52:03 -0500 X-MC-Unique: D-5vz38ZNSiuvY4IWpWGxg-1 Received: by mail-wr1-f69.google.com with SMTP id z8so8410965wrh.5 for ; Mon, 18 Jan 2021 06:52:03 -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=bvHYXveaY1fYHKCh/4G0s4Eb72E980+xC2zhbE72Tuc=; b=nTKEFzkBBwoNm5LlpVA92WpJuxYvTjwDfBk/dfVYzPBSxbeCVyZwPGEDFB6WAEI3rQ UzwFsDXZebUo/KkWkUF1zSr5E6MUXYO8vucS8LIek/9kZ/juf+g+emVilci1SIjOBuZU ZK0QNNm1Ur68PAsZ1gFXBW3YWLNE2DuA+t3VfRSbCJXMQbH3232zBX8/j34xngSIZxih ERpq2WqwZCHvQOzF2YrHbWIphpO9Tup/zkJ1cXMFphpNRIsXy5RiFn+JmqDmdZwo5e9R instpSXrLPAOEC0VBDiEuxnKfCrTN78bstGzcS8Z2dhrtn1D2nYatWCcfqgBKLXB28Hi 0jtA== X-Gm-Message-State: AOAM533cLajxmsWzEnlMjp1n9HgOol+jQyq64viwnisX94UxGebZ9Rlh mTCLIbyCc1IX+L7TkDfzYnBKmLmvebURProSWipj+g/0jfh9huwOHChIpw9DNIr1J89Cdty1rPg BBDJUMOddRVYE2rP3qpxbJbQg X-Received: by 2002:a5d:42d0:: with SMTP id t16mr26110645wrr.230.1610981522393; Mon, 18 Jan 2021 06:52:02 -0800 (PST) X-Received: by 2002:a5d:42d0:: with SMTP id t16mr26110629wrr.230.1610981522214; Mon, 18 Jan 2021 06:52:02 -0800 (PST) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id x25sm1728972wmk.20.2021.01.18.06.52.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 06:52:01 -0800 (PST) Date: Mon, 18 Jan 2021 15:51:58 +0100 From: Stefano Garzarella To: Arseny Krasnov Cc: Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , 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 v2 01/13] af_vsock: implement 'vsock_wait_data()'. Message-ID: <20210118145158.ufakay5mbezjex4v@steredhat> References: <20210115053553.1454517-1-arseny.krasnov@kaspersky.com> <20210115054028.1455574-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210115054028.1455574-1-arseny.krasnov@kaspersky.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 15, 2021 at 08:40:25AM +0300, Arseny Krasnov wrote: >This adds 'vsock_wait_data()' function which is called from user's read >syscall and waits until new socket data is arrived. It was based on code >from stream dequeue logic and moved to separate function because it will >be called both from SOCK_STREAM and SOCK_SEQPACKET receive loops. > >Signed-off-by: Arseny Krasnov >--- > net/vmw_vsock/af_vsock.c | 47 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 47 insertions(+) > >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c >index b12d3a322242..af716f5a93a4 100644 >--- a/net/vmw_vsock/af_vsock.c >+++ b/net/vmw_vsock/af_vsock.c >@@ -1822,6 +1822,53 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, > return err; > } > >+static int vsock_wait_data(struct sock *sk, struct wait_queue_entry *wait, >+ long timeout, >+ struct vsock_transport_recv_notify_data *recv_data, >+ size_t target) >+{ >+ int err = 0; >+ struct vsock_sock *vsk; >+ const struct vsock_transport *transport; Please be sure that here and in all of the next patches, you follow the "Reverse Christmas tree" rule followed in net/ for the local variable declarations (order variable declaration lines longest to shortest). >+ >+ vsk = vsock_sk(sk); >+ transport = vsk->transport; >+ >+ if (sk->sk_err != 0 || >+ (sk->sk_shutdown & RCV_SHUTDOWN) || >+ (vsk->peer_shutdown & SEND_SHUTDOWN)) { >+ finish_wait(sk_sleep(sk), wait); >+ return -1; >+ } >+ /* Don't wait for non-blocking sockets. */ >+ if (timeout == 0) { >+ err = -EAGAIN; >+ finish_wait(sk_sleep(sk), wait); >+ return err; >+ } >+ >+ if (recv_data) { >+ err = transport->notify_recv_pre_block(vsk, target, recv_data); >+ if (err < 0) { >+ finish_wait(sk_sleep(sk), wait); >+ return err; >+ } >+ } >+ >+ release_sock(sk); >+ timeout = schedule_timeout(timeout); >+ lock_sock(sk); >+ >+ if (signal_pending(current)) { >+ err = sock_intr_errno(timeout); >+ finish_wait(sk_sleep(sk), wait); >+ } else if (timeout == 0) { >+ err = -EAGAIN; >+ finish_wait(sk_sleep(sk), wait); >+ } >+ Since we are calling finish_wait() before return in all path, why not doing somethig like this: out: finish_wait(sk_sleep(sk), wait); >+ return err; >+} Then in the error paths you can do: err = XXX; goto out; Thanks, Stefano > > static int > vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, >-- >2.25.1 >