Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2082745pxb; Thu, 11 Feb 2021 04:02:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1PXmrRI30dQxTA0+Xgk8iG6CJ5l9Kf7jQUL6dXSblb+3nTZAKVkUQ0TH7Qe9Aiwdc1eiJ X-Received: by 2002:a17:906:1355:: with SMTP id x21mr8272143ejb.53.1613044976961; Thu, 11 Feb 2021 04:02:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613044976; cv=none; d=google.com; s=arc-20160816; b=NULIogJQYWf9dWY/CNZwyWURZaednk3Jco2GlRQqToqZW4YDNlXZAhnbuqEVF0lLgE VfwsIR7flR3BGWxy7ofBwgsmIJK/Cnkz1LydvKC1h/tavdPPMImMa3F4oVakIjjh+/Dl wG/bEK3LYsT+X84ZjKfAnA32LdkcuaevLGmN7Tq8HBZvOipXfs7KKCI3rLShQp5cdNDx mTnBTOc1CaD7kYz1TmJ3xES2YLqKuUTcUAPjPxGkPzF6T1YWsAnBv3+iOLWBg7LMbUe8 y3XSTj5JaQ44myzyk9U5Hy2Dz9z2vuNWI92KJhjR+SHxg1yDstAOQ1+4zULnzH8CNshs 85Hg== 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=622PK+GXq9S1qrkes0QjDaGHdMGIQhnkDb8cr2jJCIE=; b=UFbCLqczuNSr0cClLX6ghO4YQSI4uQJl7s9O18tQlNCHcl4/6VYvAM1I3EZrZTtNNw 9CP+nJQyk+uo2nOrXWFvNtnEc1wKJwjPP2T8Nw1zl1M/8EGCCpmvHoBirKHrbqLCMVek BgyGDJycI3HNUy13QJgBbGquNDM3X1bBfqtQiPIynpEoq3fPrCewRItYGgWn8NQoRgxg RQFEB28R7teAlRdBk7kXQAegQjQTbakSUQh52kpL7mvW6oSbZtDOZKKsypLkG358WeFy VTl0DbXsqzY4dm1jpsrYeg/C1D+K2cQEQqIRpV2Z5Sj8x7Bx8mH9oW2J89E2xEuHauOh xqDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b15nW0YP; 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 z9si3938646edb.204.2021.02.11.04.02.25; Thu, 11 Feb 2021 04:02:56 -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=b15nW0YP; 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 S231727AbhBKMA7 (ORCPT + 99 others); Thu, 11 Feb 2021 07:00:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43506 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231178AbhBKLtW (ORCPT ); Thu, 11 Feb 2021 06:49:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613044075; 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=622PK+GXq9S1qrkes0QjDaGHdMGIQhnkDb8cr2jJCIE=; b=b15nW0YPkZq4X1/AZ2v8FBI1TVF7uZJZeVT6ZqvfcakqE1w2ekT9dganCpOSFXi5en5JX4 PQeKg+jKiqsrW0RAgaoXD8XRsYJznhb9XrlMAgGunzQJFoTPD3QfgwP3qnHxUEyaDDI50+ FCrN+pUGPjI8BTg/mhZeysK6LvNp+qQ= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-545-PkXjXCgzP16X2Qg1rcmGAg-1; Thu, 11 Feb 2021 06:47:53 -0500 X-MC-Unique: PkXjXCgzP16X2Qg1rcmGAg-1 Received: by mail-ed1-f69.google.com with SMTP id bo11so4549509edb.0 for ; Thu, 11 Feb 2021 03:47:52 -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=622PK+GXq9S1qrkes0QjDaGHdMGIQhnkDb8cr2jJCIE=; b=UO3B4y4oQELTFDhl2REwxnt7toip0ypXdedK+uEHNVJyPh+WeqWgqWN+95FZ/ummSL tCjZ64l8/RsO/YPbKU6TSBkCUexpvDckLcJVoVuT+Feq4zoNIZoSIR1XkLBMN/jMquk+ epOL2Di2w6q+ZiSj3Hj+p346T+XPWxMLLnA4qiRd9ehauqg7lZvGd5DWetU5eJN+OfQ9 H5GDBebH+55LoFRhN19xe32NPMa28BTHlUiFpcbpiINLCqxXR//RqGkLUq6QT4xi9o2X 1h35XAb8NKJbzGFKQIQy32dmmVITyfz9l4b4UCDmkQ14YRYndKFb5VZ2M3m8XnJszDuS bB4A== X-Gm-Message-State: AOAM532sZvbtriTxH1eSR5OT9JmxyzmgeNapWjU+7V88UrZfAWTnH59d cy9sN28oLT/h8aLMBTQWdl1G2wsIu/321XpOjWt53wpNXkIRqx7jqpLsXfIMNU2OU4gtowxiXt5 /jHFZPZGVqBPJf47LUdIjLXBz X-Received: by 2002:a17:906:6087:: with SMTP id t7mr8301140ejj.90.1613044071889; Thu, 11 Feb 2021 03:47:51 -0800 (PST) X-Received: by 2002:a17:906:6087:: with SMTP id t7mr8301133ejj.90.1613044071704; Thu, 11 Feb 2021 03:47:51 -0800 (PST) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id x17sm1593873edq.42.2021.02.11.03.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 03:47:51 -0800 (PST) Date: Thu, 11 Feb 2021 12:47:48 +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 , Alexander Popov , 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 04/17] af_vsock: implement SEQPACKET receive loop Message-ID: <20210211114748.jshxyiecqmbwzmv3@steredhat> References: <20210207151259.803917-1-arseny.krasnov@kaspersky.com> <20210207151526.804741-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210207151526.804741-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:22PM +0300, Arseny Krasnov wrote: >This adds receive loop for SEQPACKET. It looks like receive loop for >STREAM, but there is a little bit difference: >1) It doesn't call notify callbacks. >2) It doesn't care about 'SO_SNDLOWAT' and 'SO_RCVLOWAT' values, because > there is no sense for these values in SEQPACKET case. >3) It waits until whole record is received or error is found during > receiving. >4) It processes and sets 'MSG_TRUNC' flag. > >So to avoid extra conditions for two types of socket inside one loop, two >independent functions were created. > >Signed-off-by: Arseny Krasnov >--- > include/net/af_vsock.h | 5 +++ > net/vmw_vsock/af_vsock.c | 96 +++++++++++++++++++++++++++++++++++++++- > 2 files changed, 100 insertions(+), 1 deletion(-) > >diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h >index b1c717286993..bb6a0e52be86 100644 >--- a/include/net/af_vsock.h >+++ b/include/net/af_vsock.h >@@ -135,6 +135,11 @@ struct vsock_transport { > bool (*stream_is_active)(struct vsock_sock *); > bool (*stream_allow)(u32 cid, u32 port); > >+ /* SEQ_PACKET. */ >+ size_t (*seqpacket_seq_get_len)(struct vsock_sock *); >+ int (*seqpacket_dequeue)(struct vsock_sock *, struct msghdr *, >+ int flags, bool *msg_ready); CHECK: Alignment should match open parenthesis #35: FILE: include/net/af_vsock.h:141: + int (*seqpacket_dequeue)(struct vsock_sock *, struct msghdr *, + int flags, bool *msg_ready); And to make checkpatch.pl happy please use the identifier name also for the others parameter. I know we haven't done this before, but for new code I think we can do it. >+ > /* Notification. */ > int (*notify_poll_in)(struct vsock_sock *, size_t, bool *); > int (*notify_poll_out)(struct vsock_sock *, size_t, bool *); >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c >index 66c8a932f49b..3d8af987216a 100644 >--- a/net/vmw_vsock/af_vsock.c >+++ b/net/vmw_vsock/af_vsock.c >@@ -1977,6 +1977,97 @@ static int __vsock_stream_recvmsg(struct sock *sk, struct msghdr *msg, > return err; > } > >+static int __vsock_seqpacket_recvmsg(struct sock *sk, struct msghdr *msg, >+ size_t len, int flags) >+{ >+ const struct vsock_transport *transport; >+ const struct iovec *orig_iov; >+ unsigned long orig_nr_segs; >+ bool msg_ready; >+ struct vsock_sock *vsk; >+ size_t record_len; >+ long timeout; >+ int err = 0; >+ DEFINE_WAIT(wait); >+ >+ vsk = vsock_sk(sk); >+ transport = vsk->transport; >+ >+ timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); >+ orig_nr_segs = msg->msg_iter.nr_segs; >+ orig_iov = msg->msg_iter.iov; >+ msg_ready = false; >+ record_len = 0; >+ >+ while (1) { >+ err = vsock_wait_data(sk, &wait, timeout, NULL, 0); >+ >+ if (err <= 0) { >+ /* In case of any loop break(timeout, signal >+ * interrupt or shutdown), we report user that >+ * nothing was copied. >+ */ >+ err = 0; >+ break; >+ } >+ >+ if (record_len == 0) { >+ record_len = >+ transport->seqpacket_seq_get_len(vsk); >+ >+ if (record_len == 0) >+ continue; >+ } >+ >+ err = transport->seqpacket_dequeue(vsk, msg, >+ flags, &msg_ready); A single line here should be okay. >+ if (err < 0) { >+ if (err == -EAGAIN) { >+ iov_iter_init(&msg->msg_iter, READ, >+ orig_iov, orig_nr_segs, >+ len); >+ /* Clear 'MSG_EOR' here, because dequeue >+ * callback above set it again if it was >+ * set by sender. This 'MSG_EOR' is from >+ * dropped record. >+ */ >+ msg->msg_flags &= ~MSG_EOR; >+ record_len = 0; >+ continue; >+ } >+ >+ err = -ENOMEM; >+ break; >+ } >+ >+ if (msg_ready) >+ break; >+ } >+ >+ if (sk->sk_err) >+ err = -sk->sk_err; >+ else if (sk->sk_shutdown & RCV_SHUTDOWN) >+ err = 0; >+ >+ if (msg_ready) { >+ /* User sets MSG_TRUNC, so return real length of >+ * packet. >+ */ >+ if (flags & MSG_TRUNC) >+ err = record_len; >+ else >+ err = len - msg->msg_iter.count; >+ >+ /* Always set MSG_TRUNC if real length of packet is >+ * bigger than user's buffer. >+ */ >+ if (record_len > len) >+ msg->msg_flags |= MSG_TRUNC; >+ } >+ >+ return err; >+} >+ > static int > vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, > int flags) >@@ -2032,7 +2123,10 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, > goto out; > } > >- err = __vsock_stream_recvmsg(sk, msg, len, flags); >+ if (sk->sk_type == SOCK_STREAM) >+ err = __vsock_stream_recvmsg(sk, msg, len, flags); >+ else >+ err = __vsock_seqpacket_recvmsg(sk, msg, len, flags); > > out: > release_sock(sk); The rest seems ok to me, but I need to get more familiar with SEQPACKET before giving my R-b. Thanks, Stefano