From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6AEC38F232 for ; Wed, 8 Jul 2026 10:29:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783506567; cv=none; b=kyxYo6xqqmX/i2KT2FICl72UUBJQVlgeZ4YKsIshQCxk2rRa9Oqvvp/R3y/R/wX2dUaAsAdNRHPqD1weCTB7/bg3zbJpiJx7V3xmqPTtazvLTUjJxwQVjsoYdSdbI2NuBBACE/R2EMlgIxdLN8n1h/SfeIzcv6Mu884kJ9bCClk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783506567; c=relaxed/simple; bh=qNZiJSTEfc7fTVZbT1Hdz+TpSbOWakYcGAe5W8RAZ0U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S8eNq9LcT+Xomy/Z40oNuANUoyLnajnrKFxZzdft/lSikpFJnrOn96v0vrBT66hUH5sAllIJjS00eSxfWeu65podeg5PNVmrKgIbYJfz/FJ5MLCm+suTyF0a1nxIXUw51alB3QE24pMa54ld/vQ20cd+kDjmZPp3jKB4fosLHn8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q2spR+fO; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZJ+eCHMK; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q2spR+fO"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZJ+eCHMK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783506560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s31Zp5IE8kvOUi9c30CVIvqfz2iKzORtScqC5v+Omgg=; b=Q2spR+fOfLu0Yua9vZr1N9oDGS4sKdckEsu0FVoWJErat8SRaeUYmWb8pws44ilhJFlgF6 gDsQv+5QMBWZfTgxpgwVwMcoL9b33jiLI+eHHVGi4MIuVRIduiozN0w+uP6LEVX32/gmBY mV/Hw1f0UYKnOBU443C6zoe2lVWvIFk= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-282-I7AMqw1tPcmcK3vfNDlT9w-1; Wed, 08 Jul 2026 06:29:18 -0400 X-MC-Unique: I7AMqw1tPcmcK3vfNDlT9w-1 X-Mimecast-MFC-AGG-ID: I7AMqw1tPcmcK3vfNDlT9w_1783506557 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-473f4a48e9aso388892f8f.2 for ; Wed, 08 Jul 2026 03:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1783506557; x=1784111357; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s31Zp5IE8kvOUi9c30CVIvqfz2iKzORtScqC5v+Omgg=; b=ZJ+eCHMK3R7j+L+r/kYfzRJdAwh3wE9G80wMTBjO0LrNgrErx1NBt0A+00cDJcr7HU XE8Sc/pfwxfbji9rroVv1ISaHmlGKMHZy6O//shgkDc6gkcz+QgvFqS3TX4H/vXQ31qO 7ccy38zOdqJgdkFaqpOFlRGWBitfU8iER9FpysmarUj4AszOvkVqd2VT/dvDlMYvWPw6 nCR+dbpxiKJVf1cRQOGEOx0VdeNh3Cq5vvtUU2NSfORPm7m3DT/MnXXY82Qw3FZ3ZZUa Fw5rJSNejtpbN2zTU71W122vJik+SLkZrzVEBjAGULGiNrMXBrLrMN9vrX3nOVQUlf6E Y2Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783506557; x=1784111357; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=s31Zp5IE8kvOUi9c30CVIvqfz2iKzORtScqC5v+Omgg=; b=eza1C7ere4NL9h/nJ0hSQzXfdb7Y7dGuK7dPbRyfr3NdVqH1uDmitUBOuur871UVgi cRKPfVsOWaSFApHJNTbXl7fLoMWPKxDOnkAPE+HqNMXFv8V5osZ40LhFyVlJ0FyCxObp OMAXxv8J4Q+Ahserig29PekEiTIdJsZdRVzj/q1T2yclrS++OX2/zgqlgJ5uyXh7d2Um uD0TAwnf9f2mFFt+VO56T4mCrvqVmMK8rVmDLw5vjpDr2Om757JIA6PbaVqOqMYJibML xIBB9avCzAPXCnjk1wAjdLcEgkqoCO2bsmgRNSGKv2kJf9KAE1ZNcAVxMcY/+ezEjMWI /Z5w== X-Forwarded-Encrypted: i=1; AHgh+Rqy0TCa1FoPZpViO28+VxldP5wmxg3iakh2WuPP3sNSrIXiJMOSWgqbquIw1IUxW4QwF+eBcNpxmQZmscs=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4aaGvTTgQPLn0AWiBsIQQ4kWWI4lod78HP6iju9YpgcZ6jGTV P9rOuV5JEpDENJjCCSwEuR7pQdkofKhp4KimkN5/VI/0cg6Td+bnCo13Wuy/VAnYnK60N4qYoNX iLwXNPfn114X+CfEM1kReSP8zyOPvy2zgo8Hd7iNnAAXW+N98uTSUWmaY9NJXhxSQqg== X-Gm-Gg: AfdE7cmVLkXh4dCz7P5dvtWT+GvYht2p6s928V1LxcukneEVFx3enEzh8jaCZPo1hGf zTPkV2DKjbXTHmQ6XUAWJEYNztIoDwM6nbBGB3CwsVobG7K1AD2mbP/jth5eOZsF5gXUXg3ocDZ GbxtUBXsKsYZY6xYUhjh+5VYXgyqqMgHu8LilVLBu4wpkWVMWJzLjOGcwY4aBnB/o3MhjQkrGcB GFfYvFKKjEx627gQufcnkmQGxr2wuVutNA17/OJpGASg5MLgEV8cvLdeWirQOmqkYodSp0LnSCX 2PQ2w5PXCaggTVCtUMizv9MFZKyBpyoNzeD3TaTgq6YspzRCdztOp9WIeQMJ6wrxIJGAnbJC+ol zJGZBT19ZqrmEOT8Mvrsdgyq2cveIwTd3lsNc+P8qo9SBJgo= X-Received: by 2002:a05:6000:24ca:b0:462:e086:35f with SMTP id ffacd0b85a97d-47df0725e5cmr2146632f8f.21.1783506556909; Wed, 08 Jul 2026 03:29:16 -0700 (PDT) X-Received: by 2002:a05:6000:24ca:b0:462:e086:35f with SMTP id ffacd0b85a97d-47df0725e5cmr2146583f8f.21.1783506556408; Wed, 08 Jul 2026 03:29:16 -0700 (PDT) Received: from stex1 (host-79-34-22-35.business.telecomitalia.it. [79.34.22.35]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0f214d2sm40461480f8f.33.2026.07.08.03.29.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 03:29:15 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Jason Wang , Stefano Garzarella , Xuan Zhuo , Eric Dumazet , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Simon Horman , Stefan Hajnoczi , "David S. Miller" , linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , kvm@vger.kernel.org, Paolo Abeni , virtualization@lists.linux.dev, Jakub Kicinski , Jason Wang Subject: [PATCH net v2 2/2] vsock/test: add test for small packets under pressure Date: Wed, 8 Jul 2026 12:29:04 +0200 Message-ID: <20260708102904.50732-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260708102904.50732-1-sgarzare@redhat.com> References: <20260708102904.50732-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Stefano Garzarella Add a test that sends 2 MB of data using randomly sized small packets (129-512 bytes) over a SOCK_STREAM connection. Packets above GOOD_COPY_LEN (128) bypass the in-place coalescing in recv_enqueue(), forcing each one into its own skb. Without receive queue collapsing, the per-skb overhead eventually exceeds buf_alloc and the connection is reset. The test verifies that all data arrives and that content integrity is preserved. Signed-off-by: Stefano Garzarella --- tools/testing/vsock/vsock_test.c | 87 ++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 76be0e4a7f0e..b4ff9f946565 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -2347,6 +2347,88 @@ static void test_stream_tx_credit_bounds_server(const struct test_opts *opts) close(fd); } +/* Test that many small packets don't cause a connection reset under pressure + * and that data integrity is preserved. Packet sizes vary randomly between + * 129 and 512 bytes, above GOOD_COPY_LEN (128) to bypass in-place coalescing + * in recv_enqueue, forcing each one into its own skb. Without receive queue + * collapsing, the per-skb overhead eventually exceeds buf_alloc and the + * connection is reset. + */ +#define COLLAPSE_PKT_MIN 129 +#define COLLAPSE_PKT_MAX 512 +#define COLLAPSE_TOTAL (2 * 1024 * 1024) + +static void test_stream_collapse_client(const struct test_opts *opts) +{ + unsigned char *data; + unsigned long hash; + size_t offset = 0; + int i, fd; + + data = malloc(COLLAPSE_TOTAL); + if (!data) { + perror("malloc"); + exit(EXIT_FAILURE); + } + + for (i = 0; i < COLLAPSE_TOTAL; i++) + data[i] = rand() & 0xff; + + fd = vsock_stream_connect(opts->peer_cid, opts->peer_port); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + while (offset < COLLAPSE_TOTAL) { + size_t pkt_size = COLLAPSE_PKT_MIN + + rand() % (COLLAPSE_PKT_MAX - COLLAPSE_PKT_MIN + 1); + + pkt_size = min(pkt_size, COLLAPSE_TOTAL - offset); + + send_buf(fd, data + offset, pkt_size, 0, pkt_size); + offset += pkt_size; + } + + hash = hash_djb2(data, COLLAPSE_TOTAL); + control_writeulong(hash); + + free(data); + close(fd); +} + +static void test_stream_collapse_server(const struct test_opts *opts) +{ + unsigned long hash, remote_hash; + unsigned char *data; + int fd; + + data = malloc(COLLAPSE_TOTAL); + if (!data) { + perror("malloc"); + exit(EXIT_FAILURE); + } + + fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL); + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + recv_buf(fd, data, COLLAPSE_TOTAL, 0, COLLAPSE_TOTAL); + + hash = hash_djb2(data, COLLAPSE_TOTAL); + remote_hash = control_readulong(); + if (hash != remote_hash) { + fprintf(stderr, "hash mismatch: local %lu remote %lu\n", + hash, remote_hash); + exit(EXIT_FAILURE); + } + + free(data); + close(fd); +} + static struct test_case test_cases[] = { { .name = "SOCK_STREAM connection reset", @@ -2546,6 +2628,11 @@ static struct test_case test_cases[] = { .run_client = test_stream_msg_peek_client, .run_server = test_stream_peek_after_recv_server, }, + { + .name = "SOCK_STREAM small packets backpressure", + .run_client = test_stream_collapse_client, + .run_server = test_stream_collapse_server, + }, {}, }; -- 2.55.0