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,