From patchwork Sun Jun 18 06:24:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 109574 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2321894vqr; Sat, 17 Jun 2023 23:44:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4DF/V1TWR+PkD+6pgFM8icmenxQd3SZY3+vfnE2775EXVy+JGPJXhfKDERgmU2CprrQFET X-Received: by 2002:a05:6871:4417:b0:19e:c953:d854 with SMTP id nd23-20020a056871441700b0019ec953d854mr4815923oab.52.1687070657849; Sat, 17 Jun 2023 23:44:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687070657; cv=none; d=google.com; s=arc-20160816; b=ZRLJG3J2tjyQY7gMgDTf7X9kddW9pjovVeW1O/XCblgCellWjMIvABREBOZfXIA2B+ GTWhwbuHFd1FkxCcQiFVgena/XQ10sd+1XMsYyx9kR9LZOlK4rd1ifV/RZaoJki7rvkO 0KdDmtOcg+sT0GLMkhrwQ9JrohMpTsygitB75Ob6VPjUJsKMIhe7H9zkOY3hg2clasLM Xp9mMDny7gpK8KXQknFRilvMHD1RD4hz/0OFBfyE6V8S3qCVYiLUMrIBJcgCc4ED5UJt Wfjml/BqZH35VM96yaH4JT51HDrbHlUh29xF2x8TZQoMWj4ktucujsVqGwBLpZwBvLsQ jRVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9KIwX5m0AsbY8eFETkFbK8y/WZQO82su8tgmIiM0rvk=; b=VxoQtM4mXdYdFg7Ik6cs0aEgwXU6s6Y4Ur313kua6Y7QBfFrHvD3XPEL7yAXWHI4y6 EFU6IEwkEot9dLnkNv9grzshfA4NI1MbHHTXr1i4FY2H6cyHvuGI4kc3KqtJA2eaOuHq 74zhcY41/2oPC/IHRZGE7Ud2/EXDAZjRhuHO/TEF0REdB3iAOharw59vyWEhfAIwzmmU 7ILG8G6Irqep8BrB98wuUOsYZqzsSlNC9eOl/elaAdrcDdqSttRcPT+w8qGK8kJ5wtpn njnze/PvoGGxcfM0l65ER8Ud2N2apL9CvpAiDG0xNxSkmEr40SK4ds6SVaRenOgiriiR rihQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=oe5y8pf7; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a6552cb000000b00543fd615d2fsi14971545pgp.879.2023.06.17.23.44.01; Sat, 17 Jun 2023 23:44:17 -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=oe5y8pf7; 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 S229628AbjFRGaa (ORCPT + 99 others); Sun, 18 Jun 2023 02:30:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjFRGaM (ORCPT ); Sun, 18 Jun 2023 02:30:12 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6059B1710; Sat, 17 Jun 2023 23:30:06 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 7FA155FD25; Sun, 18 Jun 2023 09:30:02 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1687069802; bh=9KIwX5m0AsbY8eFETkFbK8y/WZQO82su8tgmIiM0rvk=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=oe5y8pf7qlvBMoNHAU3fzfQu1oOY315uLH+FTCBI1GZndpJn2SgvhR5uFxYqtsqFp 4OwWflv5kft8X4teM5xw8iUKlAOpm6SB2uUh2YF/G5/1a+1KiuI/ELi3Zz0nDnbyxi gnAmRZFV0JVVQb++XqBN/SePB4Yc2vDROIfRNKGHdb23Gf811ltG6TQSwu9soiIZgq ep7xvBWO9dhoF/CMfD1/oS9QKDQ4qR9MqxoOAxcBKOFaOihy+/iOPFNQ6TtxVDRhJC rxX1PjY7wgmgnb5w3UCibzbYHDPBx2UJXF0tjm/zr3WMuN+MNdLSuCeUDEWlVU+Wl+ 4CShUG/hIdP/A== 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; Sun, 18 Jun 2023 09:30:02 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v1 2/4] virtio/vsock: support MSG_PEEK for SOCK_SEQPACKET Date: Sun, 18 Jun 2023 09:24:49 +0300 Message-ID: <20230618062451.79980-3-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230618062451.79980-1-AVKrasnov@sberdevices.ru> References: <20230618062451.79980-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) 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/18 01:53:00 #21507494 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769021802130343498?= X-GMAIL-MSGID: =?utf-8?q?1769021802130343498?= 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; +} + 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);