From patchwork Fri Aug 19 05:25:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 12948318 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D405BC32771 for ; Fri, 19 Aug 2022 05:25:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346216AbiHSFZw (ORCPT ); Fri, 19 Aug 2022 01:25:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346175AbiHSFZs (ORCPT ); Fri, 19 Aug 2022 01:25:48 -0400 Received: from mail.sberdevices.ru (mail.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71B1ED8B30; Thu, 18 Aug 2022 22:25:47 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mail.sberdevices.ru (Postfix) with ESMTP id BD1845FD07; Fri, 19 Aug 2022 08:25:45 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1660886745; bh=b45BV2ZXGjDFGbqD7Zc7LoRug2dgFwYM1iZaE+GqaIA=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=QPZYdBOUvRAqMbDWuqeHx/lrMrjg2z4INcZAeWFCIbIXE/qYu8mgVX31NEFrDBTvJ bQNuD0/3YHikbUAsFLNpBthnsaahPsnHKOU2h2Ts61jKbTXZyrRUzgebQmCGbVi/jr t6cic8pffPOmH025W5cKevRmPwWR6k1g2Z0VouXO6FdjAbjShWNo7VHan1fnttEH3a qa6fhP6obfo6ZV76Z56Ch3B5G+0y8gezcDiPADH0f3cWWe+jGvIaa855UdD+u754Jp XAjMMkrMIIDX3vNxY5bKpKwO/fG3e0ZlNy2l+abCgdHguT3n4Md+f+2SaMhlDQqm2M Ht5FmvFs+qM6w== Received: from S-MS-EXCH02.sberdevices.ru (S-MS-EXCH02.sberdevices.ru [172.16.1.5]) by mail.sberdevices.ru (Postfix) with ESMTP; Fri, 19 Aug 2022 08:25:44 +0300 (MSK) From: Arseniy Krasnov To: Stefano Garzarella , "David S. Miller" , "edumazet@google.com" , "Jakub Kicinski" , Paolo Abeni , "kys@microsoft.com" , "haiyangz@microsoft.com" , "sthemmin@microsoft.com" , "wei.liu@kernel.org" , Dexuan Cui , Stefan Hajnoczi , Bryan Tan , Vishnu Dasa , Krasnov Arseniy , "Michael S. Tsirkin" CC: "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "kvm@vger.kernel.org" , kernel , VMware PV-Drivers Reviewers Subject: [PATCH net-next v4 1/9] vsock: SO_RCVLOWAT transport set callback Thread-Topic: [PATCH net-next v4 1/9] vsock: SO_RCVLOWAT transport set callback Thread-Index: AQHYs4wSVKV9ssq90kaiB/V349f4rA== Date: Fri, 19 Aug 2022 05:25:19 +0000 Message-ID: <09389925-8a2f-24c8-6975-f84822b12fe8@sberdevices.ru> In-Reply-To: Accept-Language: en-US, ru-RU Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.1.12] Content-ID: <6E558B7D73F28949B271809B785A889A@sberdevices.ru> MIME-Version: 1.0 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: 2022/08/19 00:26:00 #20118704 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This adds transport specific callback for SO_RCVLOWAT, because in some transports it may be difficult to know current available number of bytes ready to read. Thus, when SO_RCVLOWAT is set, transport may reject it. Signed-off-by: Arseniy Krasnov --- include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index 1c53c4c4d88f..d609a088cb27 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h @@ -135,6 +135,7 @@ struct vsock_transport { u64 (*stream_rcvhiwat)(struct vsock_sock *); bool (*stream_is_active)(struct vsock_sock *); bool (*stream_allow)(u32 cid, u32 port); + int (*set_rcvlowat)(struct vsock_sock *vsk, int val); /* SEQ_PACKET. */ ssize_t (*seqpacket_dequeue)(struct vsock_sock *vsk, struct msghdr *msg, diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index f04abf662ec6..0a6777526c73 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -2129,6 +2129,25 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, return err; } +static int vsock_set_rcvlowat(struct sock *sk, int val) +{ + const struct vsock_transport *transport; + struct vsock_sock *vsk; + + vsk = vsock_sk(sk); + + if (val > vsk->buffer_size) + return -EINVAL; + + transport = vsk->transport; + + if (transport && transport->set_rcvlowat) + return transport->set_rcvlowat(vsk, val); + + WRITE_ONCE(sk->sk_rcvlowat, val ? : 1); + return 0; +} + static const struct proto_ops vsock_stream_ops = { .family = PF_VSOCK, .owner = THIS_MODULE, @@ -2148,6 +2167,7 @@ static const struct proto_ops vsock_stream_ops = { .recvmsg = vsock_connectible_recvmsg, .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, + .set_rcvlowat = vsock_set_rcvlowat, }; static const struct proto_ops vsock_seqpacket_ops = {