Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8622102rwp; Wed, 19 Jul 2023 12:38:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlFmxbVYwBwCGZIP6Wes+wJLsilObezjMEWSTioaAKA+wKEsPv6Dd535XuCwe+gZWTzoDFLP X-Received: by 2002:a17:907:ea9:b0:973:d06d:545f with SMTP id ho41-20020a1709070ea900b00973d06d545fmr3605026ejc.24.1689795517172; Wed, 19 Jul 2023 12:38:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689795517; cv=none; d=google.com; s=arc-20160816; b=0iR+HUWxKHzkUeQpYAGZWFQ96X4QYkSIexXcAY9shfjMpEFCQTDk8pdRk57k5gp2af FqoKlt5vacieDssqyxZ5Erv8jh8pL6FFP4KU/W+b0w2MmSPky13sC3pQ6/s7W4L45dc5 erfLCUPMPtJk11W0pQ4xLjOUJoyllZFlLra6nvE9EdTTWQIkyTPr26YM7X/VDnvoLm2k BSNKxbe4EHxBiNBx6/MP4//8zTyL9mdHTzIQfCIirzSVN9tArGbC2of5HjTXDte5+moH cPeDuozQYFhfriDaWKAKytt+7syYtKor8SSTF1+OYVrOhLB2EQwp4/CpkcoKuKWUBow3 CtsQ== 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:dkim-filter; bh=9KIwX5m0AsbY8eFETkFbK8y/WZQO82su8tgmIiM0rvk=; fh=IiLlUAYZQ4hWuQbi3V9KE00VdjFsw4tg4Y6JCUFRLn0=; b=lJdg4mchipzh8xKw+ljP4Yp4rpatyl3i7I5q+OMPwVlK2gtXOA3XyxDfSotqZ7PDBN DuI6f8b08Vo98fUiqvli/x+TZkNjEIb00wQjoFwuhTspf2kN8DxTN/4+rMCy+J19uhfP ksXb3b2Nxgd8V9BBdY42SSFogqDBee/6Ds6cpi5IsS2T7qykTGHY7HcCUuwHkzifQ3Tm yKSs1jITlVovob69Zbrs6EjpDnl7vrw2sQs6/7RPiutbHTHHN4Q2dUKU0gUJbhnBRbQ0 GGofsHKcPAIcMNH1ZqHunDf45n1ScVGzJAau/G6fW868PcXS1oTEvUPMUZ3Fc0bJoPc0 YLyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b="jX4mEsn/"; 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 j7-20020a170906430700b0098d5b21121dsi3296940ejm.804.2023.07.19.12.38.11; Wed, 19 Jul 2023 12: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=@sberdevices.ru header.s=mail header.b="jX4mEsn/"; 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 S231235AbjGSTdL (ORCPT + 99 others); Wed, 19 Jul 2023 15:33:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231313AbjGSTc7 (ORCPT ); Wed, 19 Jul 2023 15:32:59 -0400 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23F1B2130; Wed, 19 Jul 2023 12:32:49 -0700 (PDT) Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 3644512007C; Wed, 19 Jul 2023 22:32:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 3644512007C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1689795168; bh=9KIwX5m0AsbY8eFETkFbK8y/WZQO82su8tgmIiM0rvk=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=jX4mEsn/0ZyN2kghUm/BaXynu7Dkmveb/upEub7xblvz6Cb5qbf+JFmJwbKXz+mOx I5Ni/pCZx0CMKZSXXqKdumXIGAYm4zPLrwMybrgBCy6/fvDWJvNDklpEku1FRuZ+/A ICC4SyUt8ryr8S8Zo9gE5St81TtakaNT+PHwUz+2/fSjpMWkStBFTw/+DRgjpIA5Uk oa1SyvmN2WGkQQ13xeN6uYnoqHIDX3X09xtbpDc2jDgNUcK0c19OyPIEDsSfoBr24A ngRM/l6ObNNX6aqAfRrpyes/8VHWm1eDdzRMhGQUq0UHVtejrckDICtG5pw4LRfMxC NyvyzDMJP0juw== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Wed, 19 Jul 2023 22:32:48 +0300 (MSK) Received: from localhost.localdomain (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 19 Jul 2023 22:32:47 +0300 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 v2 2/4] virtio/vsock: support MSG_PEEK for SOCK_SEQPACKET Date: Wed, 19 Jul 2023 22:27:06 +0300 Message-ID: <20230719192708.1775162-3-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230719192708.1775162-1-AVKrasnov@sberdevices.ru> References: <20230719192708.1775162-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 178730 [Jul 19 2023] X-KSMG-AntiSpam-Version: 5.9.59.0 X-KSMG-AntiSpam-Envelope-From: AVKrasnov@sberdevices.ru X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 524 524 9753033d6953787301affc41bead8ed49c47b39d, {Tracking_from_domain_doesnt_match_to}, p-i-exch-sc-m01.sberdevices.ru:5.0.1,7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;100.64.160.123:7.1.2;127.0.0.199:7.1.2;sberdevices.ru:5.0.1,7.1.1, FromAlignment: s, {Tracking_white_helo}, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2023/07/19 15:29:00 #21641898 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,RCVD_IN_DNSWL_BLOCKED, 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 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); -- 2.25.1