From patchwork Mon Jul 18 08:15:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 12920979 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 1338CC43334 for ; Mon, 18 Jul 2022 08:16:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231937AbiGRIQh (ORCPT ); Mon, 18 Jul 2022 04:16:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229801AbiGRIQg (ORCPT ); Mon, 18 Jul 2022 04:16:36 -0400 Received: from mail.sberdevices.ru (mail.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDBFA18B34; Mon, 18 Jul 2022 01:16:34 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mail.sberdevices.ru (Postfix) with ESMTP id 379A85FD02; Mon, 18 Jul 2022 11:16:33 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1658132193; bh=P1nJrkr4Sn5U/iYTmAgG12ArGGHsfWi2OJp13EVm0cA=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=JatiyhM0hARi6p2do309wBi/iTOndctex3kl1O5m7NBQyoRn+R0yaoRyBjEQL+Uo9 zA5k+SGXqldQLx6CZMhyGZdcgFB0YFUiokKzC7cfu/8n/udA1saE3fa1FX5fQeH6Ux tTbU8vT4pX0rQQaJU1HOLyGXDD++5/qbxQmir1l2BitHYtJ4vAG6yD94GV9AVQiDBh MMKpjjV3k6BxIXQ+NzqNonD3sTOquqxNtxNkuaGJ89jI7Jm4QZJVBJUcJt4Re9RqNo qsWWWFLlGYmJwtOXe0Vw3NPeMI7FbDJ6tZHrGI7Wz9IW6EESVXMlcNVcmlIS6/IlKM lmm2eNSqOZNmg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mail.sberdevices.ru (Postfix) with ESMTP; Mon, 18 Jul 2022 11:16:32 +0300 (MSK) From: Arseniy Krasnov To: Stefano Garzarella , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Stefan Hajnoczi , "Michael S. Tsirkin" , Arseniy Krasnov , Krasnov Arseniy , "edumazet@google.com" CC: "linux-kernel@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , "kvm@vger.kernel.org" , kernel Subject: [RFC PATCH v1 1/3] vsock: use sk_skrcvlowat to set POLLIN,POLLRDNORM, bits. Thread-Topic: [RFC PATCH v1 1/3] vsock: use sk_skrcvlowat to set POLLIN,POLLRDNORM, bits. Thread-Index: AQHYmn6SAU6pAMObZUmsS+bpsPqTqA== Date: Mon, 18 Jul 2022 08:15:42 +0000 Message-ID: <637e945f-f28a-86d9-a242-1f4be85d9840@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: 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/07/18 02:31:00 #19923013 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC Both bits indicate, that next data read call won't be blocked, but when sk_rcvlowat is not 1,these bits will be set by poll anyway,thus when user tries to dequeue data, it will wait until sk_rcvlowat bytes of data will be available. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/af_vsock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index f04abf662ec6..0225f3558e30 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1067,7 +1067,7 @@ static __poll_t vsock_poll(struct file *file, struct socket *sock, !(sk->sk_shutdown & RCV_SHUTDOWN)) { bool data_ready_now = false; int ret = transport->notify_poll_in( - vsk, 1, &data_ready_now); + vsk, sk->sk_rcvlowat, &data_ready_now); if (ret < 0) { mask |= EPOLLERR; } else { From patchwork Mon Jul 18 08:17:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 12920982 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 3AD2EC43334 for ; Mon, 18 Jul 2022 08:18:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233567AbiGRISZ (ORCPT ); Mon, 18 Jul 2022 04:18:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232796AbiGRISX (ORCPT ); Mon, 18 Jul 2022 04:18:23 -0400 Received: from mail.sberdevices.ru (mail.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C51518E0D; Mon, 18 Jul 2022 01:18:22 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mail.sberdevices.ru (Postfix) with ESMTP id E4C595FD02; Mon, 18 Jul 2022 11:18:20 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1658132300; bh=qE3oICe7EFjo8tBFXaB+54QUv+zuKwoUREtOQS9uPkI=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=UWMKMHr/QTzKS6bP877LWnR1qzAfuH4KhypdiAI33Emzzn//E84vDckRKMy4tprK1 9qhrDYFqmageiypiPv6G716fe1I1e2Wfpt3pp9hn5W4LyPmXzrKymp9DxhGrJrLj6V iFCMfZj2Lv7Q+gllGsjn96pix0wybVQdBBdgYbLPRSeLSh/aZlYp49PW/x946Nqz7X g9PAkctNKp+IHqvVFXfJ5UNuf+pfrmAbWIkhp/K7NFRn6jYvZEK2ePvb99Wz5Lk0Do /tLBuHkx7tz4r93gNcJb0Fu6+pt2XNmwYXkh2C4cjsVRx+xwB+cWzKDApB/DdGCr/X 2gD3Xyaes4yIQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mail.sberdevices.ru (Postfix) with ESMTP; Mon, 18 Jul 2022 11:18:20 +0300 (MSK) From: Arseniy Krasnov To: Stefano Garzarella , "David S. Miller" , "edumazet@google.com" , "Jakub Kicinski" , Paolo Abeni , Stefan Hajnoczi , "Michael S. Tsirkin" , Arseniy Krasnov , Krasnov Arseniy CC: "linux-kernel@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , "kvm@vger.kernel.org" , kernel Subject: [RFC PATCH v1 2/3] virtio/vsock: use 'target' in notify_poll_in, callback. Thread-Topic: [RFC PATCH v1 2/3] virtio/vsock: use 'target' in notify_poll_in, callback. Thread-Index: AQHYmn7T+PqKYxwQ8USiiecixCHJYQ== Date: Mon, 18 Jul 2022 08:17:31 +0000 Message-ID: <358f8d52-fd88-ad2e-87e2-c64bfa516a58@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: <6A2B7E3D9075EA4E817DC70C89877970@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/07/18 02:31:00 #19923013 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC This callback controls setting of POLLIN,POLLRDNORM output bits of poll() syscall,but in some cases,it is incorrectly to set it, when socket has at least 1 bytes of available data. Use 'target' which is already exists and equal to sk_rcvlowat in this case. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index ec2c2afbf0d0..591908740992 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -634,7 +634,7 @@ virtio_transport_notify_poll_in(struct vsock_sock *vsk, size_t target, bool *data_ready_now) { - if (vsock_stream_has_data(vsk)) + if (vsock_stream_has_data(vsk) >= target) *data_ready_now = true; else *data_ready_now = false; From patchwork Mon Jul 18 08:19:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 12920983 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 6FDD4C433EF for ; Mon, 18 Jul 2022 08:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233755AbiGRIUA (ORCPT ); Mon, 18 Jul 2022 04:20:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233511AbiGRIT7 (ORCPT ); Mon, 18 Jul 2022 04:19:59 -0400 Received: from mail.sberdevices.ru (mail.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8C9417056; Mon, 18 Jul 2022 01:19:57 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mail.sberdevices.ru (Postfix) with ESMTP id 1A3DF5FD02; Mon, 18 Jul 2022 11:19:56 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1658132396; bh=3T6O41NlBXfvtTgteoGhbCjYTT3urPlJ/Ul1XBHbcwI=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=meEgdfCrGtogIlee0jzKtl7NK3aKaY+Yxds0yzc7qbhWtM3dY36yJQat6q5Bw1f6U uGxJ/FXDLklqRLlzLka6HPc9dhAuDUxMuBbpv8KQArv3g5Iv6iHUdnTWnU+iOggZbr +imj63QLGWA3mnjtVHq5ih7SoTqMN+BsUnmlwAJPcmmjiuHInfXaNkK+/s+w0l4zM6 OVMRdC/VE/dykBX4jDXMPWaZWtGY58L1DE1Xhhahwr4THc9d7AqsEcvZ5bN5GZdShL 6rh8L//wc1F1fxI33OPGKHOT/b9giqtYg0uhNbHQqd+GjOoXna1QTG5broXLhWqv08 61J/nrDNFiPzw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mail.sberdevices.ru (Postfix) with ESMTP; Mon, 18 Jul 2022 11:19:55 +0300 (MSK) From: Arseniy Krasnov To: Stefano Garzarella , "David S. Miller" , "edumazet@google.com" , "Jakub Kicinski" , Paolo Abeni , Stefan Hajnoczi , "Michael S. Tsirkin" , Arseniy Krasnov , Krasnov Arseniy CC: "linux-kernel@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , "kvm@vger.kernel.org" , kernel Subject: [RFC PATCH v1 3/3] vsock_test: POLLIN + SO_RCVLOWAT test. Thread-Topic: [RFC PATCH v1 3/3] vsock_test: POLLIN + SO_RCVLOWAT test. Thread-Index: AQHYmn8L0QxAqOPQQUWV5xnNPUkeXw== Date: Mon, 18 Jul 2022 08:19:06 +0000 Message-ID: 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: <530D1D0E04DDF84FACFB4AB9CB69387E@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/07/18 02:31:00 #19923013 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC This adds test to check, that when poll() returns POLLIN and POLLRDNORM bits, next read call won't block. Signed-off-by: Arseniy Krasnov --- tools/testing/vsock/vsock_test.c | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index dc577461afc2..8e394443eaf6 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "timeout.h" #include "control.h" @@ -596,6 +597,90 @@ static void test_seqpacket_invalid_rec_buffer_server(const struct test_opts *opt close(fd); } +static void test_stream_poll_rcvlowat_server(const struct test_opts *opts) +{ +#define RCVLOWAT_BUF_SIZE 128 + int fd; + int i; + + fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + /* Send 1 byte. */ + send_byte(fd, 1, 0); + + control_writeln("SRVSENT"); + + /* Just empirically delay value. */ + sleep(4); + + for (i = 0; i < RCVLOWAT_BUF_SIZE - 1; i++) + send_byte(fd, 1, 0); + + /* Keep socket in active state. */ + control_expectln("POLLDONE"); + + close(fd); +} + +static void test_stream_poll_rcvlowat_client(const struct test_opts *opts) +{ + unsigned long lowat_val = RCVLOWAT_BUF_SIZE; + char buf[RCVLOWAT_BUF_SIZE]; + struct pollfd fds; + ssize_t read_res; + short poll_flags; + int fd; + + fd = vsock_stream_connect(opts->peer_cid, 1234); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + if (setsockopt(fd, SOL_SOCKET, SO_RCVLOWAT, + &lowat_val, sizeof(lowat_val))) { + perror("setsockopt"); + exit(EXIT_FAILURE); + } + + control_expectln("SRVSENT"); + + /* At this point, server sent 1 byte. */ + fds.fd = fd; + poll_flags = POLLIN | POLLRDNORM; + fds.events = poll_flags; + + if (poll(&fds, 1, -1) < 0) { + perror("poll"); + exit(EXIT_FAILURE); + } + + /* Only these two bits are expected. */ + if (fds.revents != poll_flags) { + fprintf(stderr, "Unexpected poll result %hx\n", + fds.revents); + exit(EXIT_FAILURE); + } + + /* Use MSG_DONTWAIT, if call is going to wait, EAGAIN + * will be returned. + */ + read_res = recv(fd, buf, sizeof(buf), MSG_DONTWAIT); + if (read_res != RCVLOWAT_BUF_SIZE) { + fprintf(stderr, "Unexpected recv result %zi\n", + read_res); + exit(EXIT_FAILURE); + } + + control_writeln("POLLDONE"); + + close(fd); +} + static struct test_case test_cases[] = { { .name = "SOCK_STREAM connection reset", @@ -646,6 +731,11 @@ static struct test_case test_cases[] = { .run_client = test_seqpacket_invalid_rec_buffer_client, .run_server = test_seqpacket_invalid_rec_buffer_server, }, + { + .name = "SOCK_STREAM poll() + SO_RCVLOWAT", + .run_client = test_stream_poll_rcvlowat_client, + .run_server = test_stream_poll_rcvlowat_server, + }, {}, };