Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1496060pxb; Mon, 22 Feb 2021 03:34:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJznsEq4Ec4JXPSrrLwYN4qTZAKo2rdZPjOVNyfW2v0944Rz+M/in6lJYpmq9F3Tx2Qy5MQp X-Received: by 2002:a05:6402:430c:: with SMTP id m12mr22935416edc.299.1613993683240; Mon, 22 Feb 2021 03:34:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613993683; cv=none; d=google.com; s=arc-20160816; b=WUA+3B+ThikltdNt9s6kUAweqXjC35Q1NguMTArlb5uheoh82oJI9NktSp039vZGdX Hn2f9cdObIBw5shlPUf6mY/HH5GQ7fTHt3e0vuztpljYv+HtcL98eGO499e+KTiV3s7/ 4GtvQUsZFeMETlWEO2L6kaqyNB5gkTAJveD1yQg9FG5AvsjKLZzli5XwTfA55ORw1vze 9UW7FMTOgHgtdZheZK0Soli4XLEzfgu4QqYHySu8SmyP7XpzwV/QwVASNQfTMjbXFs44 V8mbvneOrPi7x5jXx2wJPMqkFjJ/ce3s1T0VhiDSh1mGuKDSHPYLaUhVmtqHxYAyNmh8 sDdg== 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=Y8uZhtxPnMc3VJgJ7/XsbDI2s/GkB4V6o+tAFFKwv/8=; b=LVxyu/ZNjSUmdBs4O1cUI3+aQs99kkIroA7qIM+e7CH9xLPUJUTk/iZ9bXNx3WPT3j SRbUZBznh+wG6ZtPV1zRScgvj1djGN5CXb/HLadysIyc6tYDS6uldCC7BHTwPNJBwHtF +HSFjoVCr1nhcUulkjuCtgn3t3Mg7w9ZK55jQuL0erWXRjFTwLgf7uA0kiKZk2x3dh2z 6qnA9lLHT2mWzUJbs/QD7DPPAkX7rlqIqVZx4lH/zQfIYd4AVA4Wzbk4rpMOLGzhvzpD UODCbqkbZjHxOPpJiMHWx54dyJJgnQDi8eVa5X6rJiYW0tNPXOCe5bDyj/6mpbhYVXnY 9G5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dLnhb5UD; 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 w21si11057885edd.421.2021.02.22.03.34.20; Mon, 22 Feb 2021 03:34: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=dLnhb5UD; 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 S230514AbhBVLb0 (ORCPT + 99 others); Mon, 22 Feb 2021 06:31:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46534 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbhBVLbH (ORCPT ); Mon, 22 Feb 2021 06:31:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613993370; 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=Y8uZhtxPnMc3VJgJ7/XsbDI2s/GkB4V6o+tAFFKwv/8=; b=dLnhb5UD+NpaCQn6v2pEF7GfZEbQ12O3I6Ief1E/7iLlUte0CrZPGBCt4uos+Cpy8o4Q3r IeFh/pbOvxb6LWW2w6h0kIcO4avB7V+w/ErLLlsyNZUyRyap7+3BRDERKYHlw4Umn2qyd+ ebdBrw7L+LarN8RMfSbSc+7Dmw9Zpj8= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-482-mHakWP2UPIG9dKLceVkvfg-1; Mon, 22 Feb 2021 06:29:29 -0500 X-MC-Unique: mHakWP2UPIG9dKLceVkvfg-1 Received: by mail-wr1-f71.google.com with SMTP id v1so5975441wru.2 for ; Mon, 22 Feb 2021 03:29:29 -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=Y8uZhtxPnMc3VJgJ7/XsbDI2s/GkB4V6o+tAFFKwv/8=; b=VXciTvWn0S8XMiVbBVcjx3ZSF14WxyC5dkkSUYciq2V+dPSx0Wc2vU3QXozKJfKXa2 n3TMXBhbiMHZKcs42yxEHdaZLCvgoG9TKUtycE9SjUxo6RJENnjW8KqfD2vZq6u5Lcfp bFSk5iwK43dnwkLz0uU8gXCUIvT48y7SjK1RRS6aF/1ja/5JTC3sl1Nc/vimKDOT1ObZ GzSUo42wKw7yrNW6llArdvSOBymXsfo3SqGTSUw4XoqNLxDy6yLCXzs9ldK77fX9BlJY MJq7vvuRQe2DBwflHrPgYtL15AVsmxc4ZieJaXtqzH7dH9u0S+tCLdRT4FkQOByxBlVu pvWA== X-Gm-Message-State: AOAM533gb5whEjB1KsWSh9n6kuRrQEpUCnQRkKsZGo7FRK1YAl8UTsaY woXDiKdm6wOwTZFNvodSWoe3zijEFd+s2LiBS8c9LhRu7NdTrtIIo54eb/AUY9mrsqW4rs4CXwF eo9kMJfTwbUfkZ1AnhxiXvFOD X-Received: by 2002:a5d:63ce:: with SMTP id c14mr7733618wrw.15.1613993368179; Mon, 22 Feb 2021 03:29:28 -0800 (PST) X-Received: by 2002:a5d:63ce:: with SMTP id c14mr7733598wrw.15.1613993367956; Mon, 22 Feb 2021 03:29:27 -0800 (PST) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id m24sm7861270wmc.18.2021.02.22.03.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Feb 2021 03:29:27 -0800 (PST) Date: Mon, 22 Feb 2021 12:29:24 +0100 From: Stefano Garzarella To: Arseny Krasnov Cc: Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Jorgen Hansen , Andra Paraschiv , Colin Ian King , Norbert Slusarek , 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 v5 02/19] af_vsock: separate wait data loop Message-ID: <20210222112924.hu2sfoiwni5kt5wm@steredhat> References: <20210218053347.1066159-1-arseny.krasnov@kaspersky.com> <20210218053637.1066959-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210218053637.1066959-1-arseny.krasnov@kaspersky.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 18, 2021 at 08:36:33AM +0300, Arseny Krasnov wrote: >This moves wait loop for data to dedicated function, because later >it will be used by SEQPACKET data receive loop. The patch LGTM, maybe just add a line in the commit message with something like this: While moving the code around, let's update an old comment. Whit that fixed: Reviewed-by: Stefano Garzarella > >Signed-off-by: Arseny Krasnov >--- > net/vmw_vsock/af_vsock.c | 155 +++++++++++++++++++++------------------ > 1 file changed, 83 insertions(+), 72 deletions(-) > >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c >index 656370e11707..6cf7bb977aa1 100644 >--- a/net/vmw_vsock/af_vsock.c >+++ b/net/vmw_vsock/af_vsock.c >@@ -1832,6 +1832,68 @@ static int vsock_connectible_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) >+{ >+ const struct vsock_transport *transport; >+ struct vsock_sock *vsk; >+ s64 data; >+ int err; >+ >+ vsk = vsock_sk(sk); >+ err = 0; >+ transport = vsk->transport; >+ prepare_to_wait(sk_sleep(sk), wait, TASK_INTERRUPTIBLE); >+ >+ while ((data = vsock_stream_has_data(vsk)) == 0) { >+ if (sk->sk_err != 0 || >+ (sk->sk_shutdown & RCV_SHUTDOWN) || >+ (vsk->peer_shutdown & SEND_SHUTDOWN)) { >+ break; >+ } >+ >+ /* Don't wait for non-blocking sockets. */ >+ if (timeout == 0) { >+ err = -EAGAIN; >+ break; >+ } >+ >+ if (recv_data) { >+ err = transport->notify_recv_pre_block(vsk, target, recv_data); >+ if (err < 0) >+ break; >+ } >+ >+ release_sock(sk); >+ timeout = schedule_timeout(timeout); >+ lock_sock(sk); >+ >+ if (signal_pending(current)) { >+ err = sock_intr_errno(timeout); >+ break; >+ } else if (timeout == 0) { >+ err = -EAGAIN; >+ break; >+ } >+ } >+ >+ finish_wait(sk_sleep(sk), wait); >+ >+ if (err) >+ return err; >+ >+ /* Internal transport error when checking for available >+ * data. XXX This should be changed to a connection >+ * reset in a later change. >+ */ >+ if (data < 0) >+ return -ENOMEM; >+ >+ return data; >+} >+ > static int > vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, > int flags) >@@ -1911,85 +1973,34 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, > > > while (1) { >- s64 ready; >- >- prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); >- ready = vsock_stream_has_data(vsk); >- >- if (ready == 0) { >- if (sk->sk_err != 0 || >- (sk->sk_shutdown & RCV_SHUTDOWN) || >- (vsk->peer_shutdown & SEND_SHUTDOWN)) { >- finish_wait(sk_sleep(sk), &wait); >- break; >- } >- /* Don't wait for non-blocking sockets. */ >- if (timeout == 0) { >- err = -EAGAIN; >- finish_wait(sk_sleep(sk), &wait); >- break; >- } >+ ssize_t read; > >- err = transport->notify_recv_pre_block( >- vsk, target, &recv_data); >- if (err < 0) { >- finish_wait(sk_sleep(sk), &wait); >- break; >- } >- release_sock(sk); >- timeout = schedule_timeout(timeout); >- lock_sock(sk); >+ err = vsock_wait_data(sk, &wait, timeout, &recv_data, target); >+ if (err <= 0) >+ break; > >- if (signal_pending(current)) { >- err = sock_intr_errno(timeout); >- finish_wait(sk_sleep(sk), &wait); >- break; >- } else if (timeout == 0) { >- err = -EAGAIN; >- finish_wait(sk_sleep(sk), &wait); >- break; >- } >- } else { >- ssize_t read; >- >- finish_wait(sk_sleep(sk), &wait); >- >- if (ready < 0) { >- /* Invalid queue pair content. XXX This should >- * be changed to a connection reset in a later >- * change. >- */ >- >- err = -ENOMEM; >- goto out; >- } >- >- err = transport->notify_recv_pre_dequeue( >- vsk, target, &recv_data); >- if (err < 0) >- break; >+ err = transport->notify_recv_pre_dequeue(vsk, target, >+ &recv_data); >+ if (err < 0) >+ break; > >- read = transport->stream_dequeue( >- vsk, msg, >- len - copied, flags); >- if (read < 0) { >- err = -ENOMEM; >- break; >- } >+ read = transport->stream_dequeue(vsk, msg, len - copied, flags); >+ if (read < 0) { >+ err = -ENOMEM; >+ break; >+ } > >- copied += read; >+ copied += read; > >- err = transport->notify_recv_post_dequeue( >- vsk, target, read, >- !(flags & MSG_PEEK), &recv_data); >- if (err < 0) >- goto out; >+ err = transport->notify_recv_post_dequeue(vsk, target, read, >+ !(flags & MSG_PEEK), &recv_data); >+ if (err < 0) >+ goto out; > >- if (read >= target || flags & MSG_PEEK) >- break; >+ if (read >= target || flags & MSG_PEEK) >+ break; > >- target -= read; >- } >+ target -= read; > } > > if (sk->sk_err) >-- >2.25.1 >