Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp299948pxj; Thu, 13 May 2021 05:21:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVrZMQnQ/4wFteWi/xbSVj6ojvz3w+jBIS3E4O2FQVSs2bDGf4zrgMCf2tgr0/Vzi4eGjq X-Received: by 2002:a05:6402:54e:: with SMTP id i14mr51680137edx.210.1620908500128; Thu, 13 May 2021 05:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620908500; cv=none; d=google.com; s=arc-20160816; b=J53p3HGD3CiUpdF2lQbEiVUBdoi8OW0Te6cikOhgbeyOyAlBM9uS2tqcDP1ssBnQNE jEyv5EuDwrFY7zihnknHi+4ovyaWQr3XZLBHAmckO9UcL1A6yR5T+BDDSU3Yt2JgMUS3 8WJTOXoliaDAT17z5t4xT8RMAY644A3YpV47zTYCp1S1PSr0yQDsDObpfpIeuzV4yBmM nTaNEd+dAwUgAGmOI+k9WUXEzg3qb/5VgjKlhwbNKD/wzMKLeaXA+kil9mVk9gEpuv8t rYVL1bOb1W1YuR9lRcKM+CSUM1Zh9oznOvjF0iTn9xhoZ5sUr2BcVRhmhW4c7/6HXAHK DiKA== 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=mHdwZTL+pvK8Zg99tTdQKEFKw4APO+UMqyfXLBZ12cw=; b=AbzuEs2wFenKThf1tlwsXU1Ve07udEM8IAKRWjUaXY14QVacEhuGtS+h83//Z99RT+ tae83U8t7XypUENnBjKho2pQbTxDvnVM/CsGy0/OPHn3bA4adWRJQZpPVigcC4ADPXhx oDXfTtZWFJZ57MS8sVWUno+y6XBOG81O1ElPVaayf9xpM8y+ctgPcZ/UOUW0BPyxyCjF umHa5Lq84ilKQkkqesVY2STPhZu0vTiqblnDY1oWta2LmQNDB08H3SZUCS6ZT+IpF0uG Qr39HAv6S1zfJutDtURyhZQ69ACo4V2nyisg8kep9MTH/GXrkLNyxUr/4XAcK9i0JO0/ XTZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="TPMz123/"; 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 jp4si3036582ejb.420.2021.05.13.05.21.15; Thu, 13 May 2021 05:21:40 -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=@redhat.com header.s=mimecast20190719 header.b="TPMz123/"; 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 S232985AbhEML7d (ORCPT + 99 others); Thu, 13 May 2021 07:59:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39005 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230097AbhEML7c (ORCPT ); Thu, 13 May 2021 07:59:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620907101; 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=mHdwZTL+pvK8Zg99tTdQKEFKw4APO+UMqyfXLBZ12cw=; b=TPMz123/QZJ05xlKbDrNfcIqcQSPuXup8htC57gdVMxtB+bJxTmnHIJH5qeLpUB7/AF8bX Eog3D78Ujqnoetz2REFl9u1Z9jOCtvlU9sn8u18sU6+UFBGUXOcNstIe5Gf36pRZHqEUxF jMpdfhnRaWgtU+drUa2LeIgDy0ztPIA= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-276-Z9DKk9Q1OfadcqV2DTSdfA-1; Thu, 13 May 2021 07:58:20 -0400 X-MC-Unique: Z9DKk9Q1OfadcqV2DTSdfA-1 Received: by mail-ej1-f69.google.com with SMTP id i23-20020a17090685d7b02903d089ab83fcso1518820ejy.19 for ; Thu, 13 May 2021 04:58:20 -0700 (PDT) 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=mHdwZTL+pvK8Zg99tTdQKEFKw4APO+UMqyfXLBZ12cw=; b=gv7n2q9VvIHADnFQHgYfZPK3oPBwZ8i388VHROh5VClsDj/9LLghUVpEwcV9vYAUh5 8BFwBgJGEqAYM/RnC+CRQl0VoMd2+SaJ+EIoKAsCwTAMYlPo2ohf/rexQ8R9T7vZUr9n h/qLiU615FHXGCHsqWqE74DrB1m0Qa53rgoXL2pdMR/lmQHCqH3sr7r7IfwBvfaYrmJT KWgI34JMghgbnJ3ccUKdNlrj8wrgCAJ9lQ26LKGDFxKqvlPK8whgn6Nvl8rdNZnz3kD/ OpKmbkd/KLdNw8JX+XRneW3xTBJOTMxcch7DDbI7+d1gOG+I4hmy17Hl/wupIxOhZ6K9 r+wQ== X-Gm-Message-State: AOAM531q1oxVSRoIf12yrVwFO6na5M2xWP8W/QFDYT+fI8+ULHlbga9f kxSTTvrLls0+hmCYhYnFCCC5tiUKbl0sbHIZmYhYi7ljT7oZLsuKGIaTLWPwkGjUF6GFeguKhV1 wvEjzpCGMzp9mcpCyX+wuHtgU X-Received: by 2002:a17:906:3952:: with SMTP id g18mr8710569eje.138.1620907099239; Thu, 13 May 2021 04:58:19 -0700 (PDT) X-Received: by 2002:a17:906:3952:: with SMTP id g18mr8710552eje.138.1620907099070; Thu, 13 May 2021 04:58:19 -0700 (PDT) Received: from steredhat (host-79-18-148-79.retail.telecomitalia.it. [79.18.148.79]) by smtp.gmail.com with ESMTPSA id b25sm2288552edv.9.2021.05.13.04.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 04:58:18 -0700 (PDT) Date: Thu, 13 May 2021 13:58:16 +0200 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 v9 11/19] virtio/vsock: dequeue callback for SOCK_SEQPACKET Message-ID: <20210513115816.332nfej4jyra7vrh@steredhat> References: <20210508163027.3430238-1-arseny.krasnov@kaspersky.com> <20210508163523.3431999-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210508163523.3431999-1-arseny.krasnov@kaspersky.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 08, 2021 at 07:35:20PM +0300, Arseny Krasnov wrote: >This adds transport callback and it's logic for SEQPACKET dequeue. >Callback fetches RW packets from rx queue of socket until whole record >is copied(if user's buffer is full, user is not woken up). This is done >to not stall sender, because if we wake up user and it leaves syscall, >nobody will send credit update for rest of record, and sender will wait >for next enter of read syscall at receiver's side. So if user buffer is >full, we just send credit update and drop data. > >Signed-off-by: Arseny Krasnov >--- > v8 -> v9: > 1) Check for RW packet type is removed from loop(all packet now > considered RW). > 2) Locking in loop is fixed. > 3) cpu_to_le32()/le32_to_cpu() now used. > 4) MSG_TRUNC handling removed from transport. > > include/linux/virtio_vsock.h | 5 ++ > net/vmw_vsock/virtio_transport_common.c | 64 +++++++++++++++++++++++++ > 2 files changed, 69 insertions(+) > >diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h >index dc636b727179..02acf6e9ae04 100644 >--- a/include/linux/virtio_vsock.h >+++ b/include/linux/virtio_vsock.h >@@ -80,6 +80,11 @@ virtio_transport_dgram_dequeue(struct vsock_sock *vsk, > struct msghdr *msg, > size_t len, int flags); > >+ssize_t >+virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk, >+ struct msghdr *msg, >+ int flags, >+ bool *msg_ready); > s64 virtio_transport_stream_has_data(struct vsock_sock *vsk); > s64 virtio_transport_stream_has_space(struct vsock_sock *vsk); > >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c >index ad0d34d41444..f649a21dd23b 100644 >--- a/net/vmw_vsock/virtio_transport_common.c >+++ b/net/vmw_vsock/virtio_transport_common.c >@@ -393,6 +393,58 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, > return err; > } > >+static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, >+ struct msghdr *msg, >+ int flags, >+ bool *msg_ready) >+{ >+ struct virtio_vsock_sock *vvs = vsk->trans; >+ struct virtio_vsock_pkt *pkt; >+ int err = 0; >+ size_t user_buf_len = msg->msg_iter.count; >+ >+ *msg_ready = false; >+ spin_lock_bh(&vvs->rx_lock); >+ >+ while (!*msg_ready && !list_empty(&vvs->rx_queue) && err >= 0) { >+ size_t bytes_to_copy; >+ size_t pkt_len; >+ >+ pkt = list_first_entry(&vvs->rx_queue, struct virtio_vsock_pkt, list); >+ pkt_len = (size_t)le32_to_cpu(pkt->hdr.len); >+ bytes_to_copy = min(user_buf_len, pkt_len); >+ >+ if (bytes_to_copy) { >+ /* sk_lock is held by caller so no one else can dequeue. >+ * Unlock rx_lock since memcpy_to_msg() may sleep. >+ */ >+ spin_unlock_bh(&vvs->rx_lock); >+ >+ if (memcpy_to_msg(msg, pkt->buf, bytes_to_copy)) >{ >+ err = -EINVAL; >+ } else { >+ err += pkt_len; If `bytes_to_copy == 0` we are not increasing the real length. Anyway is a bit confusing increase a variable called `err`, I think is better to have another variable to store this information that we return if there aren't errors.