Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1336109pxf; Fri, 12 Mar 2021 07:23:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLrZPXGwpgtdV6bP1jKRO52x+gCcX2ATjzumA9IvX3oa6x0e8hj85Gpi39BhFA1veBvBnU X-Received: by 2002:aa7:d347:: with SMTP id m7mr14460698edr.260.1615562596450; Fri, 12 Mar 2021 07:23:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615562596; cv=none; d=google.com; s=arc-20160816; b=QJBGuOq5dONtwiGBKkPfPIRoX3NpxlR6z+94CAN24PbYePQbrcnuvdKedUY0l+gJq1 6rtMrkaiMBGPpz88tTZGaBLAFzTp30+UzcPbt+ImLkUmJiv911BYmj/veaA8Ct0CkMvg cLVzvFBOfjZElk6KzZ+S69iUBy1I1mWQMs5stFNKbXtUukktAIHcZo3gwk0QCIKjOokm paYSb33M+TVyLEJy++TCIC1QhLJUo8PLqjZGQpMRLHsUP1H7w8UJsTSTCGCG4VveKWGa UhLl3zipHutO0rFtAE5gC0F1jej/3ukHHHrDOVvHjbrK5XNNL5Fu9aZjPBlZ+xsx+VhM RUWQ== 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=XNhlw58yD5yXI9Wev/02PZnuhLLW5yA/Trw5RjUWlz8=; b=w1pWDeLPv8L2fdBVGPy8ugyHgi/HGxRcHabWOP+FzdAk76Mv6ALuwHLFRmZl/eyf7D AITxW1PLAyeNnASyEuDByMrfcPIXgPBV07CeeSRSXB+aUSDw9DuacEOa8iM5X/lHorrP b1kqNf9FQg+rErkXC51128iT7HFh6ife+cMQ6R0p8hjyEPL0lQekX2ls+FVYePnPrYAq exq8W95auvpbtC8vck1uvd6O23PVQZIk+uQN/8Y1iXAyOHx1CwedMsj8zNZHR+gFd1Es S0xFiiuMk+Itdhd3j4hpnxelzXA7qb52DwQUxwW6YL2l+OjumL3oMKg7u8ltSc3q7cPI tlJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YsGwYCKn; 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 m19si4220687edc.561.2021.03.12.07.22.46; Fri, 12 Mar 2021 07:23:16 -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=YsGwYCKn; 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 S232283AbhCLPVN (ORCPT + 99 others); Fri, 12 Mar 2021 10:21:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24131 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231378AbhCLPU4 (ORCPT ); Fri, 12 Mar 2021 10:20:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615562455; 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=XNhlw58yD5yXI9Wev/02PZnuhLLW5yA/Trw5RjUWlz8=; b=YsGwYCKnU1cvfhechO5ZIWBUZi6RVanAX/JQReoAhqwQc37+my+l/7YNakJtSkC1Da7bnb MbvNVzMbN22pdt3MWtohMQQrLZnRfE0ozqu2Mha5ezcV+VHOxXR/E17cujAy2EzYr0aYU9 AW9m0ctO/TBWQX2fNUW93A7hAnVNORw= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-284-8SjYIFf6O1evmpsIrnBoaQ-1; Fri, 12 Mar 2021 10:20:54 -0500 X-MC-Unique: 8SjYIFf6O1evmpsIrnBoaQ-1 Received: by mail-wr1-f72.google.com with SMTP id s10so11293171wre.0 for ; Fri, 12 Mar 2021 07:20:53 -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=XNhlw58yD5yXI9Wev/02PZnuhLLW5yA/Trw5RjUWlz8=; b=ndc1mIazXPSaSGSv7hbBYC16VzHm9/n1YVp7zIVjMJaOL8qSIKxKBfdJToIMQ4fF6Q EFGhlvPK9lGfk7jAzdOxeD91IvwX2FuW7pMvcZIsNbgw/YPP/0KQPa3X5LxHZVyAkhYw upVRu3c/Xo1aTxs3JfdpCX3aIeeDKVffQ82ZzPrfU2jNgMMKCPnCVmcLOeqBuBhCh8Rw Z5KnKc5642eBAKf4GkqN0F9m8mGzzSfo89HkYg+s/0HdT4LnX23EpNn0t6VFv5U0VD5Z SgqDrFddj7jLUyuZ+v2s4GcHB08vClm7z7utKFWjrURuDUmen9riMP6Ktq5rb0MJ03UO pYeQ== X-Gm-Message-State: AOAM532shaILP8KLAn2uFAQnRIWJ+s2vDfQeNutzP0hQ+S+DwWBiCLCD lfZl5HKS+2ykCdZYW+PEIjMVW5FTCVWJyJQ7D8U2K0SRO4sRv4nUu6yBiY60MbFPDDogKcFNjgF jXFcyAHOSFC6c25c5ofUoLzs2 X-Received: by 2002:adf:8562:: with SMTP id 89mr14637736wrh.101.1615562452730; Fri, 12 Mar 2021 07:20:52 -0800 (PST) X-Received: by 2002:adf:8562:: with SMTP id 89mr14637714wrh.101.1615562452552; Fri, 12 Mar 2021 07:20:52 -0800 (PST) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id s84sm2463651wme.11.2021.03.12.07.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 07:20:52 -0800 (PST) Date: Fri, 12 Mar 2021 16:20:49 +0100 From: Stefano Garzarella To: Arseny Krasnov Cc: Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Jorgen Hansen , Andra Paraschiv , Norbert Slusarek , Colin Ian King , 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 v6 12/22] virtio/vsock: fetch length for SEQPACKET record Message-ID: <20210312152049.iiarapjotp6eqho2@steredhat> References: <20210307175722.3464068-1-arseny.krasnov@kaspersky.com> <20210307180235.3465973-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210307180235.3465973-1-arseny.krasnov@kaspersky.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 07, 2021 at 09:02:31PM +0300, Arseny Krasnov wrote: >This adds transport callback which tries to fetch record begin marker >from socket's rx queue. It is called from af_vsock.c before reading data >packets of record. > >Signed-off-by: Arseny Krasnov >--- > include/linux/virtio_vsock.h | 1 + > net/vmw_vsock/virtio_transport_common.c | 53 +++++++++++++++++++++++++ > 2 files changed, 54 insertions(+) > >diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h >index 466a5832d2f5..d7edcfeb4cd2 100644 >--- a/include/linux/virtio_vsock.h >+++ b/include/linux/virtio_vsock.h >@@ -88,6 +88,7 @@ virtio_transport_dgram_dequeue(struct vsock_sock *vsk, > struct msghdr *msg, > size_t len, int flags); > >+size_t virtio_transport_seqpacket_seq_get_len(struct vsock_sock *vsk); > int > virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk, > struct msghdr *msg, >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c >index 5f1e283e43f3..6fc78fec41c0 100644 >--- a/net/vmw_vsock/virtio_transport_common.c >+++ b/net/vmw_vsock/virtio_transport_common.c >@@ -399,6 +399,59 @@ static inline void virtio_transport_remove_pkt(struct virtio_vsock_pkt *pkt) > virtio_transport_free_pkt(pkt); > } > >+static size_t virtio_transport_drop_until_seq_begin(struct virtio_vsock_sock *vvs) >+{ >+ struct virtio_vsock_pkt *pkt, *n; >+ size_t bytes_dropped = 0; >+ >+ list_for_each_entry_safe(pkt, n, &vvs->rx_queue, list) { >+ if (le16_to_cpu(pkt->hdr.op) == VIRTIO_VSOCK_OP_SEQ_BEGIN) >+ break; >+ >+ bytes_dropped += le32_to_cpu(pkt->hdr.len); >+ virtio_transport_dec_rx_pkt(vvs, pkt); >+ virtio_transport_remove_pkt(pkt); >+ } >+ >+ return bytes_dropped; >+} >+ >+size_t virtio_transport_seqpacket_seq_get_len(struct vsock_sock *vsk) >+{ >+ struct virtio_vsock_seq_hdr *seq_hdr; >+ struct virtio_vsock_sock *vvs; >+ struct virtio_vsock_pkt *pkt; >+ size_t bytes_dropped; >+ >+ vvs = vsk->trans; >+ >+ spin_lock_bh(&vvs->rx_lock); >+ >+ /* Fetch all orphaned 'RW' packets and send credit update. */ >+ bytes_dropped = virtio_transport_drop_until_seq_begin(vvs); >+ >+ if (list_empty(&vvs->rx_queue)) >+ goto out; What do we return to in this case? IIUC we return the len of the previous packet, should we set vvs->seqpacket_state.user_read_seq_len to 0? >+ >+ pkt = list_first_entry(&vvs->rx_queue, struct virtio_vsock_pkt, list); >+ >+ vvs->seqpacket_state.user_read_copied = 0; >+ >+ seq_hdr = (struct virtio_vsock_seq_hdr *)pkt->buf; >+ vvs->seqpacket_state.user_read_seq_len = >le32_to_cpu(seq_hdr->msg_len); >+ vvs->seqpacket_state.curr_rx_msg_id = le32_to_cpu(seq_hdr->msg_id); >+ virtio_transport_dec_rx_pkt(vvs, pkt); >+ virtio_transport_remove_pkt(pkt); >+out: >+ spin_unlock_bh(&vvs->rx_lock); >+ >+ if (bytes_dropped) >+ virtio_transport_send_credit_update(vsk); >+ >+ return vvs->seqpacket_state.user_read_seq_len; >+} >+EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_seq_get_len); >+ > static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, > struct msghdr *msg, > bool *msg_ready) >-- >2.25.1 >