Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17153334rwd; Mon, 26 Jun 2023 22:02:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/fwe00P4BQPndcVEsRVjyvUbTbFolE6fyiiGvRh0ZtI1+RU44hrG+IJmo+9mR64K/bp/K X-Received: by 2002:a05:6a20:431d:b0:12a:9e2e:e455 with SMTP id h29-20020a056a20431d00b0012a9e2ee455mr1096857pzk.26.1687842124264; Mon, 26 Jun 2023 22:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687842124; cv=none; d=google.com; s=arc-20160816; b=uaOivKS+XZ7yL4LR7xyiTRNdAckWC83llyDn4F5Eh7rdp6K2C5MtLxu2x0Q3ZPSbQr exfB/Auy0Gw01YcKyx+1+1wAzeIegF7LFU8nq418Vhs2JGTG+6WM6E+g9C6b7aSZODSN s6N8iHlPegvjpUM2Mz2xPYC0b1q05Ex+/j75rzcAeEnmKJzUvCLyIYY055iyPofnB1F6 u+09z0/RWYeu0ZCu+PUin88Fv8xrkLWEzGjRvKhdOTcqdyqH6INKXuRJ9hN9/R2lRMMw tMsEElwPC28dOMZsXg4q5IcBe5Gb11YK9pP8KMBakI9WTiQjKuXD7OgHAxOgKiBGA6Di NyhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=95OGPHRDGayh8A0YYyqNyKQ1yAf3hId+4mS4asKi6iA=; fh=l7xBQVGdpXDK+Z71lZkrtPT+DrTVUNscI0qNZEzUJW4=; b=LghLblj7lOwPOvA+x5Z2xGVuOSdi8jgqRLaPinTJEv/KdQbUyVHjMMYFQRbDpgcTvE MztKmIy/2Oxy8fesNwvrP74EVd1ob/9Tq+ETNV0749C+awcDB8TiraFGyuYdRkkrWMX6 yecAze14hPP0DR09EHy0rSeTtKJ39kZiRL24DBK0WBPbbWYJmp53+dUdd3Wha+PuHxwV htprAWlY/QmsMgipwmYLvBs5zWnfXbv+Wr96PKBa8AYQpd6RPsXX+WGjOkxzND+jMgJ5 Bt4ZUREET2hXafrRwI2WljRA9JKQVDSsDlOKgC7gF7NhFDh4xQN/XtozBCLxscfmnDPD bIKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=ghf1LqwV; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c17-20020a170902b69100b001a5089fe47fsi6097331pls.326.2023.06.26.22.01.52; Mon, 26 Jun 2023 22:02:04 -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=@sberdevices.ru header.s=mail header.b=ghf1LqwV; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231314AbjF0EnY (ORCPT + 99 others); Tue, 27 Jun 2023 00:43:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbjF0EmZ (ORCPT ); Tue, 27 Jun 2023 00:42:25 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84C0826A8; Mon, 26 Jun 2023 21:39:35 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id A5B095FD20; Tue, 27 Jun 2023 07:39:30 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1687840770; bh=95OGPHRDGayh8A0YYyqNyKQ1yAf3hId+4mS4asKi6iA=; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; b=ghf1LqwVimoV5AgcawNO04eGGiCBCjyEdL8auyfrIPdU5L4J5OmaTHhzqK6bE5+8J 2OyZwfTTaLjv9aumSOdQjIwGYx7fSGnN1LFjwiWPvS1CDmNJT92MDYyYCvKwe9TCLD viZ3divoTp1VLsHQgqhzPuQtTAEcOmvAKXl3PCEwLpo2gIxP0OHNvY/YCXdxsCE9fn 4nZ4S++FAsSQomKRUmENtb77xbwNyKoNNoP3rXSzidVOPFGrkoJCy/D7R7sHLYFt/M ZSb+IR+eCAafKKZu8be4GVLybrjHYt/uQegVLyEfQbCGZIyyYSplr9Mwaccz4TZx15 NFf1IVlarzDcg== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) by mx.sberdevices.ru (Postfix) with ESMTP; Tue, 27 Jun 2023 07:39:26 +0300 (MSK) Message-ID: <9553a82f-ce31-e2e0-ff62-8abd2a6b639b@sberdevices.ru> Date: Tue, 27 Jun 2023 07:34:29 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [RFC PATCH v1 2/4] virtio/vsock: support MSG_PEEK for SOCK_SEQPACKET Content-Language: en-US To: Stefano Garzarella CC: Stefan Hajnoczi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman , , , , , , References: <20230618062451.79980-1-AVKrasnov@sberdevices.ru> <20230618062451.79980-3-AVKrasnov@sberdevices.ru> From: Arseniy Krasnov In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/27 02:11:00 #21585463 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 26.06.2023 19:28, Stefano Garzarella wrote: > On Sun, Jun 18, 2023 at 09:24:49AM +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(-) >> >> 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; > > Should we return the minimum between total and len? I guess no, because seqpacket dequeue callback always returns length of message, then, in af_vsock.c we return either number of bytes read or length of message depending on MSG_TRUNC flags. Thanks, Arseniy > > Thanks, > Stefano > >> +} >> + >> 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 >> >