Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4699469rwo; Tue, 25 Jul 2023 09:38:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlG8Mb+GPFHD/yIuZrdyIeU7QLinH+20aKyTAWE86mynjUIvT5BwlOpUYKhKyCzzayiehLM4 X-Received: by 2002:a17:907:1c1b:b0:992:103c:43fa with SMTP id nc27-20020a1709071c1b00b00992103c43famr3051004ejc.30.1690303117551; Tue, 25 Jul 2023 09:38:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690303117; cv=none; d=google.com; s=arc-20160816; b=kMe4XGMOvn3s/6FGLQdfuId/30ffkuztCfVImRK6o9x8ctNWhC9dboEQUGWf9WS3y7 sN2FWAxzSdE1QWXjxLU5E2N1VqTt9XHqApb9UUJf05WRDeTZeQwaOV8ZqlH972CpY1yO 7PYco4XcZTl2uLfu+E+hnKsfvikk3y+H8/hBgRSC9qCUE9eypyxx/n34C4WUGfG/gy6g eUwwuKCp/T37/aPs0CXb6dTMoAtrVNtUVecnNcunG1Zsb7Jys+/NPEZhoHzYX8jKbr2P lP3zPVAUWdZEPXZQ/oJ++DFzNSx1mG4vyPteZlntD4Urc+FBE9/tkMXTEHyiTkEXM867 5CCA== 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=hl7TlGBY8KC9fCz4U38u+w32QQOwR9hjmIKn/+TtjDc=; fh=LmSvGF8mKyhe+4SfmYOr3uCnhF0XAFkKvuoevTchCp0=; b=kPWlk3CyvxNx3wR/WrhnEuI4cUKRw5lIQ2GiDp6x6gobhZmai73HNSvw0c0fZV2ip9 b52PoKgzXWZ8L1H2b7b2JUEpY9pQjtVgMsL7rBfEZiamy6tCF/lYw41oqvc68jqB8HoE jSSw+tDmgdTtc0aAc/C22BkBS2A6WqcaqUz9y1QucsL3SFASkETL8JwYLNyGT7ecPr85 dH+LrkQA9M+aKJELskTFvnlFP518kxmt8OxGCcz4+4T0uGsa7KfAGKi/cda3we+U1DAK PQs8uQEAuovzKtVLg+PKFTAnO+3ffaiNgAvmEOXC3NnWLeytsi5V5syV7aPwKSX9qBuL fjsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Eqfenazn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m4-20020a170906848400b00992ae4dfc04si8072040ejx.990.2023.07.25.09.38.12; Tue, 25 Jul 2023 09:38:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Eqfenazn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231477AbjGYPk1 (ORCPT + 99 others); Tue, 25 Jul 2023 11:40:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231276AbjGYPkZ (ORCPT ); Tue, 25 Jul 2023 11:40:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 975CA1FD0 for ; Tue, 25 Jul 2023 08:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690299577; 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=hl7TlGBY8KC9fCz4U38u+w32QQOwR9hjmIKn/+TtjDc=; b=Eqfenaznp7EdkrxatwpStZue6/oR7OfchzFM+38/JhlfXJWqoB37aqlmSSqpONUwwtso3U ikPZ6nzjWwnV+JzhgDj9kg5dm+Dg5I3An1M9l2QKOSWN4kvJccGHvkyAcm1HH2ATFmxuQ/ 4Tfi2/j1D8X8Bl3iD8HaNj6cY9JlykA= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-436-IDLONoxKN9KgsCQefNg4zQ-1; Tue, 25 Jul 2023 11:39:36 -0400 X-MC-Unique: IDLONoxKN9KgsCQefNg4zQ-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-403ae7d56baso71164011cf.3 for ; Tue, 25 Jul 2023 08:39:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690299576; x=1690904376; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hl7TlGBY8KC9fCz4U38u+w32QQOwR9hjmIKn/+TtjDc=; b=HG7Mx7Alx7+4VXYLJBdLpAeLx3dysGloL9aY10ZnjDRzNXpwlo1ZZryTsGBp6o3idi YdImivsh0RiPjOWfQrEgi6cUVw1ErtbViKqQyi9ifevxIgYtyYJhwbSGIhMwZkHu/SfS Dt2qqaqVuKOMfVTBWqSJOcE9V83c/4FQAmqvhV3r5hTlBXVwxDyvj+NbRqXiOi8mGxn2 QEht5V6sEQ/Gu1PN+gvOFsXYC7Fp/3C8XcydDyM0Faqo2hTvNjIo5mLcMcX7JcHPaQmo 9mqwxpIqRhNu/CLC+mzIm+tPuPbVjpYDBn9ZNotzOx4cB8WABTOoh3UdAwBEUy1SwOjO 2j6w== X-Gm-Message-State: ABy/qLYPan2Hrbi3zpNQjnNISJDvYilTIll/ym1LsRTUrK4Ou9qSIltX CqxS5H08yP6yDVXwmK/Uwko7Ys9YOeS477UXf29drD4Dbob+Az4F4/ogc7V3rqoy0fG3aJjxicT acAxgMTWPglHO9ZFtkpGySuFc X-Received: by 2002:a05:622a:1013:b0:402:76e3:59f6 with SMTP id d19-20020a05622a101300b0040276e359f6mr3746331qte.9.1690299576273; Tue, 25 Jul 2023 08:39:36 -0700 (PDT) X-Received: by 2002:a05:622a:1013:b0:402:76e3:59f6 with SMTP id d19-20020a05622a101300b0040276e359f6mr3746308qte.9.1690299576067; Tue, 25 Jul 2023 08:39:36 -0700 (PDT) Received: from sgarzare-redhat ([193.207.153.113]) by smtp.gmail.com with ESMTPSA id s21-20020ac85ed5000000b00403b44bc230sm4085933qtx.95.2023.07.25.08.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 08:39:35 -0700 (PDT) Date: Tue, 25 Jul 2023 17:39:30 +0200 From: Stefano Garzarella To: Arseniy Krasnov Cc: Stefan Hajnoczi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@sberdevices.ru, oxffffaa@gmail.com Subject: Re: [RFC PATCH v2 2/4] virtio/vsock: support MSG_PEEK for SOCK_SEQPACKET Message-ID: References: <20230719192708.1775162-1-AVKrasnov@sberdevices.ru> <20230719192708.1775162-3-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20230719192708.1775162-3-AVKrasnov@sberdevices.ru> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 19, 2023 at 10:27:06PM +0300, Arseniy Krasnov wrote: >This adds support of MSG_PEEK flag for SOCK_SEQPACKET type of socket. >Difference with SOCK_STREAM is that this callback returns either length >of the message or error. > >Signed-off-by: Arseniy Krasnov >--- > net/vmw_vsock/virtio_transport_common.c | 63 +++++++++++++++++++++++-- > 1 file changed, 60 insertions(+), 3 deletions(-) Reviewed-by: Stefano Garzarella > >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c >index 2ee40574c339..352d042b130b 100644 >--- a/net/vmw_vsock/virtio_transport_common.c >+++ b/net/vmw_vsock/virtio_transport_common.c >@@ -460,6 +460,63 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, > return err; > } > >+static ssize_t >+virtio_transport_seqpacket_do_peek(struct vsock_sock *vsk, >+ struct msghdr *msg) >+{ >+ struct virtio_vsock_sock *vvs = vsk->trans; >+ struct sk_buff *skb; >+ size_t total, len; >+ >+ spin_lock_bh(&vvs->rx_lock); >+ >+ if (!vvs->msg_count) { >+ spin_unlock_bh(&vvs->rx_lock); >+ return 0; >+ } >+ >+ total = 0; >+ len = msg_data_left(msg); >+ >+ skb_queue_walk(&vvs->rx_queue, skb) { >+ struct virtio_vsock_hdr *hdr; >+ >+ if (total < len) { >+ size_t bytes; >+ int err; >+ >+ bytes = len - total; >+ if (bytes > skb->len) >+ bytes = skb->len; >+ >+ spin_unlock_bh(&vvs->rx_lock); >+ >+ /* sk_lock is held by caller so no one else can dequeue. >+ * Unlock rx_lock since memcpy_to_msg() may sleep. >+ */ >+ err = memcpy_to_msg(msg, skb->data, bytes); >+ if (err) >+ return err; >+ >+ spin_lock_bh(&vvs->rx_lock); >+ } >+ >+ total += skb->len; >+ hdr = virtio_vsock_hdr(skb); >+ >+ if (le32_to_cpu(hdr->flags) & VIRTIO_VSOCK_SEQ_EOM) { >+ if (le32_to_cpu(hdr->flags) & VIRTIO_VSOCK_SEQ_EOR) >+ msg->msg_flags |= MSG_EOR; >+ >+ break; >+ } >+ } >+ >+ spin_unlock_bh(&vvs->rx_lock); >+ >+ return total; >+} >+ > static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, > struct msghdr *msg, > int flags) >@@ -554,9 +611,9 @@ virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk, > int flags) > { > if (flags & MSG_PEEK) >- return -EOPNOTSUPP; >- >- return virtio_transport_seqpacket_do_dequeue(vsk, msg, flags); >+ return virtio_transport_seqpacket_do_peek(vsk, msg); >+ else >+ return virtio_transport_seqpacket_do_dequeue(vsk, msg, flags); > } > EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_dequeue); > >-- >2.25.1 >