From patchwork Sat Dec 17 19:45:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13075921 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 41000C3DA6E for ; Sat, 17 Dec 2022 19:46:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229635AbiLQTqB (ORCPT ); Sat, 17 Dec 2022 14:46:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbiLQTp7 (ORCPT ); Sat, 17 Dec 2022 14:45:59 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADE916478; Sat, 17 Dec 2022 11:45:57 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 0A95B5FD03; Sat, 17 Dec 2022 22:45:56 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1671306356; bh=fRQaScZUwNSlmdqZ+Io2YTz+G50P34agK3PANG8xcpg=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=SYrU7wwJjd48bsmEyayCo3z+n3YukZqN12mu5SGqHo5v6byneL+q+3U7GIzPE7BMP hmLUetTPQpw+Xq4pT08RTy7t/sxOwMLs4tCjrK1TSwypxP6GoRAqcxmR6LglHr+wD7 CMpEOtvMSWP4l2zk7yrry12hitXe50XR/Uwwk7a+r/IhTV/qCpMQ3c4gnKKP+txJfh MyAx8n9c8v4GaquwxhFAqnxjuYDiePj0cSKs54jCxtM5uBo8p6MrT8g/0KbsUCkv9v qJnONB7m5fISmnFOsCWgv8/itgjGEX9GLyFY/IGrGmp3yMeEMY4wgcreYpN8cSd6t/ a91p7St8NxhrA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 17 Dec 2022 22:45:55 +0300 (MSK) From: Arseniy Krasnov To: Stefano Garzarella , Stefan Hajnoczi , "edumazet@google.com" , "David S. Miller" , Jakub Kicinski , Paolo Abeni CC: "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "kvm@vger.kernel.org" , kernel , Krasnov Arseniy , Arseniy Krasnov Subject: [RFC PATCH v1 1/2] virtio/vsock: send credit update depending on SO_RCVLOWAT Thread-Topic: [RFC PATCH v1 1/2] virtio/vsock: send credit update depending on SO_RCVLOWAT Thread-Index: AQHZElAtpIjfFhXnAkiL/v8iyYioYA== Date: Sat, 17 Dec 2022 19:45:55 +0000 Message-ID: In-Reply-To: <39b2e9fd-601b-189d-39a9-914e5574524c@sberdevices.ru> 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: <34A3F028C08A3C47A856A1176E2EEEFC@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/12/17 15:49:00 #20678428 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC This adds extra condition to send credit update message during data read to userspace. Problem arises, when sender waits for the free space on the receiver while receiver waits in 'poll()' until 'rx_bytes' reaches SO_RCVLOWAT value of the socket. With this patch, receiver sends credit update message when number of bytes in it's rx queue is too small to avoid sleeping in 'poll()'. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index a1581c77cf84..4cf26cf8a754 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -362,6 +362,7 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, struct virtio_vsock_sock *vvs = vsk->trans; size_t bytes, total = 0; struct sk_buff *skb; + bool low_rx_bytes; int err = -EFAULT; u32 free_space; @@ -396,6 +397,8 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, } free_space = vvs->buf_alloc - (vvs->fwd_cnt - vvs->last_fwd_cnt); + low_rx_bytes = (vvs->rx_bytes < + sock_rcvlowat(sk_vsock(vsk), 0, INT_MAX)); spin_unlock_bh(&vvs->rx_lock); @@ -405,9 +408,11 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, * too high causes extra messages. Too low causes transmitter * stalls. As stalls are in theory more expensive than extra * messages, we set the limit to a high value. TODO: experiment - * with different values. + * with different values. Also send credit update message when + * number of bytes in rx queue is not enough to wake up reader. */ - if (free_space < VIRTIO_VSOCK_MAX_PKT_BUF_SIZE) + if (free_space < VIRTIO_VSOCK_MAX_PKT_BUF_SIZE || + low_rx_bytes) virtio_transport_send_credit_update(vsk); return total; From patchwork Sat Dec 17 19:47:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13075922 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 D8D82C4332F for ; Sat, 17 Dec 2022 19:47:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229866AbiLQTrz (ORCPT ); Sat, 17 Dec 2022 14:47:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbiLQTry (ORCPT ); Sat, 17 Dec 2022 14:47:54 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EDE264C3; Sat, 17 Dec 2022 11:47:53 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 9B5225FD03; Sat, 17 Dec 2022 22:47:51 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1671306471; bh=OSv0Ba0Sxi0FhQJ1RPOToNqj3ToGYcwsxV98SeyHUao=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=A15Ne/c0w29kIO6PGVPSjlJG9Nxj8ZcBi+V872RDC0a2AReTHvkA+vl4lS3sHyyXa B2OK1WZc7+SZZr7zQA6mUL4ggv+2ElEbBWH26BUafTDN7csTkz8Vw97j4ACmTMLorw /N0jtc6WFH7akGMO3LCBIdJU7UjqrOlcTf8jUXndgYtl17MqvRIYcqAjq42wUjD1Ln PxU0sxYw4KZdWUPzt+UjEkvfIbfYu8QGSWHMeo9TT95zWcBuOsFdFFb+PvBsqcmTh1 iLGPypmHsyat+3nQdvpCz2SSuggAX86PktggizoxImDTLCfx92pM8FRyqP8Bwhhv0i 69/liYj/llDvg== Received: from S-MS-EXCH02.sberdevices.ru (S-MS-EXCH02.sberdevices.ru [172.16.1.5]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 17 Dec 2022 22:47:50 +0300 (MSK) From: Arseniy Krasnov To: Stefano Garzarella , Stefan Hajnoczi , "edumazet@google.com" , "David S. Miller" , Jakub Kicinski , Paolo Abeni CC: "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "kvm@vger.kernel.org" , kernel , Krasnov Arseniy , Arseniy Krasnov Subject: [RFC PATCH v1 2/2] vsock_test: mutual hungup reproducer Thread-Topic: [RFC PATCH v1 2/2] vsock_test: mutual hungup reproducer Thread-Index: AQHZElBxEL3j6aqlHkKaLR49F0BTQw== Date: Sat, 17 Dec 2022 19:47:50 +0000 Message-ID: <26d57ed5-f2f5-5e1d-b557-67a41c1c573c@sberdevices.ru> In-Reply-To: <39b2e9fd-601b-189d-39a9-914e5574524c@sberdevices.ru> 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: <36B3A5240833DB4FAF5244237C8F6E41@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/12/17 15:49:00 #20678428 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC This is not for merge, just demo. Signed-off-by: Arseniy Krasnov --- tools/testing/vsock/vsock_test.c | 78 ++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index bb6d691cb30d..320ecf4db74b 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -699,7 +699,85 @@ static void test_stream_poll_rcvlowat_client(const struct test_opts *opts) close(fd); } +static void test_stall_client(const struct test_opts *opts) +{ + int fd; + unsigned long lowat_val = 128*1024; + size_t data_size = 64 * 1024; + void *data; + + + fd = vsock_stream_connect(opts->peer_cid, 1234); + assert(fd != -1); + + assert(!setsockopt(fd, SOL_SOCKET, SO_RCVLOWAT, + &lowat_val, sizeof(lowat_val))); + + data = malloc(data_size); + assert(data); + + /* Wait for tx to send data. */ + sleep(3); + + while (1) { + struct pollfd fds = {0}; + + fds.fd = fd; + fds.events = POLLIN | POLLRDNORM | POLLERR | POLLRDHUP | POLLHUP; + + /* Try to wait for 1 sec. */ + printf("[RX] ENTER POLL\n"); + assert(poll(&fds, 1, -1) >= 0); + printf("[RX] LEAVE POLL\n"); + + if (fds.revents & (POLLIN | POLLRDNORM)) { + read(fd, data, data_size); + } + + if (fds.revents & POLLERR) { + printf("[RX] POLL ERR\n"); + break; + } + + if (fds.revents & (POLLRDHUP | POLLHUP)) { + printf("[RX] POLL DONE\n"); + break; + } + } + + close(fd); + exit(0); +} + +static void test_stall_server(const struct test_opts *opts) +{ + size_t data_size = (256 * 1024) + 1; + void *data; + int fd; + + fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + assert(fd != -1); + + data = malloc(data_size); + assert(data); + + printf("[TX] ENTER WRITE\n"); + assert(write(fd, data, data_size) == data_size); + + /* Never get here without kernel patch. */ + printf("[TX] LEAVE WRITE\n"); + + close(fd); + exit(0); +} + + static struct test_case test_cases[] = { + { + .name = "Test stall", + .run_client = test_stall_client, + .run_server = test_stall_server, + }, { .name = "SOCK_STREAM connection reset", .run_client = test_stream_connection_reset,