From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A2751BCA0E; Wed, 23 Oct 2024 15:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698247; cv=none; b=U74/T/4140zSAWbVCP8Iw2BJd2E5PEmznVt552DTY6OfW2bVLN5PaYOwPIRHU8wtqBBC5vqhMHNZwdWJDP4SMSnhv4HOUVi6dzrXSjHG2BCNAUZaQHLbY0x4M7vWry09RKsVhc7MIuk14L2zty3JIXNAN8iTc5meAsKzsz3x8u0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698247; c=relaxed/simple; bh=DbSfoMlzpZVhU+8FFsUY3AHTX/zbUMYdVXfjpyEzHfU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qvOPstFwH2YjzQtTjGbvNcrg9AQwIOkXjDamarZV3TE6RMkrSxlnBUXT1Z6ZqC8K0ApaxskxEy/5KQKkmQV9hrFGjZf3yzHTCMOww7SJuQz9sZ3OdkULJ6sOpJsUwLxvzKxN8LnzMCeA+0qMnPbkWWmBBOLm2tgnQbzpXaSiXu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2e30fb8cb07so5081642a91.3; Wed, 23 Oct 2024 08:44:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698244; x=1730303044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fYIgIfdOM+KXAHby1i+hfUVdj9h7/069nIsE/U1uz/s=; b=DV4Je8jkPRInVeY6TSnrNW5knKtgcbWAMgRiSyZuO3ANDBBzEo9prQkeaznx5XlCy1 Z2NTNRyFcBJPBII6VO4Pe8DfxATlxWYUNLE/ETrexuRo7WidmInWI3XC7/7i/fyfpQHa L5LTQMOz2/o5g3F4BQ3jxSDCMlyNLnEYgBRuJ2bPIsdNzv9CSTjsPla7/8G41vqbowJY RY3G6agTOksg0sRm2YQdx2P0lYzzf5fggbFpiolHYX0UtZ6dmzG7h7WyNhXKHhv4H7xt NWmXrtqJ/ohzoQ2KYWTGSxvVhUyqga647KLzaGABOAN/4+WN9teo0wMLWPhU0E45O2gE KC6g== X-Forwarded-Encrypted: i=1; AJvYcCUO8uzZPsqh7yRB5LjnUNOTEj2iG1XiqPlyWh5PPAEgq8iB00F6P3vmKz/4pTR7vrFx0ICLrsn8B0Es+no=@vger.kernel.org, AJvYcCWsHY9/rgLBLV2sHEbShPryOZcT0nkyqSW3yXMfcXeTZ3Ro8DZyMboqjXfMu1kN5/73lIC+l7YiIsg9hW1kSgie@vger.kernel.org X-Gm-Message-State: AOJu0YwrM7Zyt/6StR6hznmSWwIQhtJ6yEcCeQcZe4Atd+W8R3L6TVsv dn4lIlatXu2qj0x2sQiVi4bC8MnGLqTe6jTXVmSeuZzYM0BEFbBPsonMtyQ= X-Google-Smtp-Source: AGHT+IFu7lBM+EJGVygAzV3cmO05QBJgIGHPmTtsC8bJS4QRheXrgrJV9V7tD6x9y7raW+zdNhczfA== X-Received: by 2002:a17:90b:3512:b0:2da:8730:5683 with SMTP id 98e67ed59e1d1-2e76b727a81mr3093880a91.39.1729698244253; Wed, 23 Oct 2024 08:44:04 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e76df50ee7sm1584007a91.23.2024.10.23.08.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:03 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 01/12] selftests: ncdevmem: Redirect all non-payload output to stderr Date: Wed, 23 Oct 2024 08:43:51 -0700 Message-ID: <20241023154402.441510-2-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" That should make it possible to do expected payload validation on the caller side. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 61 +++++++++++++------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index 64d6805381c5..9245d3f158dd 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -88,7 +88,6 @@ void print_nonzero_bytes(void *ptr, size_t size) =20 for (i =3D 0; i < size; i++) putchar(p[i]); - printf("\n"); } =20 void validate_buffer(void *line, size_t size) @@ -120,7 +119,7 @@ void validate_buffer(void *line, size_t size) char command[256]; \ memset(command, 0, sizeof(command)); \ snprintf(command, sizeof(command), cmd, ##__VA_ARGS__); \ - printf("Running: %s\n", command); \ + fprintf(stderr, "Running: %s\n", command); \ system(command); \ }) =20 @@ -128,22 +127,22 @@ static int reset_flow_steering(void) { int ret =3D 0; =20 - ret =3D run_command("sudo ethtool -K %s ntuple off", ifname); + ret =3D run_command("sudo ethtool -K %s ntuple off >&2", ifname); if (ret) return ret; =20 - return run_command("sudo ethtool -K %s ntuple on", ifname); + return run_command("sudo ethtool -K %s ntuple on >&2", ifname); } =20 static int configure_headersplit(bool on) { - return run_command("sudo ethtool -G %s tcp-data-split %s", ifname, + return run_command("sudo ethtool -G %s tcp-data-split %s >&2", ifname, on ? "on" : "off"); } =20 static int configure_rss(void) { - return run_command("sudo ethtool -X %s equal %d", ifname, start_queue); + return run_command("sudo ethtool -X %s equal %d >&2", ifname, start_queue= ); } =20 static int configure_channels(unsigned int rx, unsigned int tx) @@ -153,7 +152,7 @@ static int configure_channels(unsigned int rx, unsigned= int tx) =20 static int configure_flow_steering(void) { - return run_command("sudo ethtool -N %s flow-type tcp4 src-ip %s dst-ip %s= src-port %s dst-port %s queue %d", + return run_command("sudo ethtool -N %s flow-type tcp4 src-ip %s dst-ip %s= src-port %s dst-port %s queue %d >&2", ifname, client_ip, server_ip, port, port, start_queue); } =20 @@ -187,7 +186,7 @@ static int bind_rx_queue(unsigned int ifindex, unsigned= int dmabuf_fd, goto err_close; } =20 - printf("got dmabuf id=3D%d\n", rsp->id); + fprintf(stderr, "got dmabuf id=3D%d\n", rsp->id); dmabuf_id =3D rsp->id; =20 netdev_bind_rx_req_free(req); @@ -314,8 +313,8 @@ int do_server(void) if (ret) error(errno, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); =20 - printf("binding to address %s:%d\n", server_ip, - ntohs(server_sin.sin_port)); + fprintf(stderr, "binding to address %s:%d\n", server_ip, + ntohs(server_sin.sin_port)); =20 ret =3D bind(socket_fd, &server_sin, sizeof(server_sin)); if (ret) @@ -329,14 +328,14 @@ int do_server(void) =20 inet_ntop(server_sin.sin_family, &server_sin.sin_addr, buffer, sizeof(buffer)); - printf("Waiting or connection on %s:%d\n", buffer, - ntohs(server_sin.sin_port)); + fprintf(stderr, "Waiting or connection on %s:%d\n", buffer, + ntohs(server_sin.sin_port)); client_fd =3D accept(socket_fd, &client_addr, &client_addr_len); =20 inet_ntop(client_addr.sin_family, &client_addr.sin_addr, buffer, sizeof(buffer)); - printf("Got connection from %s:%d\n", buffer, - ntohs(client_addr.sin_port)); + fprintf(stderr, "Got connection from %s:%d\n", buffer, + ntohs(client_addr.sin_port)); =20 while (1) { struct iovec iov =3D { .iov_base =3D iobuf, @@ -349,14 +348,13 @@ int do_server(void) ssize_t ret; =20 is_devmem =3D false; - printf("\n\n"); =20 msg.msg_iov =3D &iov; msg.msg_iovlen =3D 1; msg.msg_control =3D ctrl_data; msg.msg_controllen =3D sizeof(ctrl_data); ret =3D recvmsg(client_fd, &msg, MSG_SOCK_DEVMEM); - printf("recvmsg ret=3D%ld\n", ret); + fprintf(stderr, "recvmsg ret=3D%ld\n", ret); if (ret < 0 && (errno =3D=3D EAGAIN || errno =3D=3D EWOULDBLOCK)) continue; if (ret < 0) { @@ -364,7 +362,7 @@ int do_server(void) continue; } if (ret =3D=3D 0) { - printf("client exited\n"); + fprintf(stderr, "client exited\n"); goto cleanup; } =20 @@ -373,7 +371,7 @@ int do_server(void) if (cm->cmsg_level !=3D SOL_SOCKET || (cm->cmsg_type !=3D SCM_DEVMEM_DMABUF && cm->cmsg_type !=3D SCM_DEVMEM_LINEAR)) { - fprintf(stdout, "skipping non-devmem cmsg\n"); + fprintf(stderr, "skipping non-devmem cmsg\n"); continue; } =20 @@ -384,7 +382,7 @@ int do_server(void) /* TODO: process data copied from skb's linear * buffer. */ - fprintf(stdout, + fprintf(stderr, "SCM_DEVMEM_LINEAR. dmabuf_cmsg->frag_size=3D%u\n", dmabuf_cmsg->frag_size); =20 @@ -395,12 +393,13 @@ int do_server(void) token.token_count =3D 1; =20 total_received +=3D dmabuf_cmsg->frag_size; - printf("received frag_page=3D%llu, in_page_offset=3D%llu, frag_offset= =3D%llu, frag_size=3D%u, token=3D%u, total_received=3D%lu, dmabuf_id=3D%u\n= ", - dmabuf_cmsg->frag_offset >> PAGE_SHIFT, - dmabuf_cmsg->frag_offset % getpagesize(), - dmabuf_cmsg->frag_offset, dmabuf_cmsg->frag_size, - dmabuf_cmsg->frag_token, total_received, - dmabuf_cmsg->dmabuf_id); + fprintf(stderr, + "received frag_page=3D%llu, in_page_offset=3D%llu, frag_offset=3D%llu,= frag_size=3D%u, token=3D%u, total_received=3D%lu, dmabuf_id=3D%u\n", + dmabuf_cmsg->frag_offset >> PAGE_SHIFT, + dmabuf_cmsg->frag_offset % getpagesize(), + dmabuf_cmsg->frag_offset, + dmabuf_cmsg->frag_size, dmabuf_cmsg->frag_token, + total_received, dmabuf_cmsg->dmabuf_id); =20 if (dmabuf_cmsg->dmabuf_id !=3D dmabuf_id) error(1, 0, @@ -438,15 +437,15 @@ int do_server(void) if (!is_devmem) error(1, 0, "flow steering error\n"); =20 - printf("total_received=3D%lu\n", total_received); + fprintf(stderr, "total_received=3D%lu\n", total_received); } =20 - fprintf(stdout, "%s: ok\n", TEST_PREFIX); + fprintf(stderr, "%s: ok\n", TEST_PREFIX); =20 - fprintf(stdout, "page_aligned_frags=3D%lu, non_page_aligned_frags=3D%lu\n= ", + fprintf(stderr, "page_aligned_frags=3D%lu, non_page_aligned_frags=3D%lu\n= ", page_aligned_frags, non_page_aligned_frags); =20 - fprintf(stdout, "page_aligned_frags=3D%lu, non_page_aligned_frags=3D%lu\n= ", + fprintf(stderr, "page_aligned_frags=3D%lu, non_page_aligned_frags=3D%lu\n= ", page_aligned_frags, non_page_aligned_frags); =20 cleanup: @@ -551,7 +550,7 @@ int main(int argc, char *argv[]) ifname =3D optarg; break; case '?': - printf("unknown option: %c\n", optopt); + fprintf(stderr, "unknown option: %c\n", optopt); break; } } @@ -559,7 +558,7 @@ int main(int argc, char *argv[]) ifindex =3D if_nametoindex(ifname); =20 for (; optind < argc; optind++) - printf("extra arguments: %s\n", argv[optind]); + fprintf(stderr, "extra arguments: %s\n", argv[optind]); =20 run_devmem_tests(); =20 --=20 2.47.0 From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B50533A1DA; Wed, 23 Oct 2024 15:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698248; cv=none; b=oM6dj21ZcxkrzuZgalvHJNEa8r9ULG7DuS1UruOp1RYVr0rhRXqTQjCsJTmgY4dMRNjCbGfHN3zacb9bJ9jbg+tx1glFTQAclM1vc0xxfhunmnHv5s9ghUGVdX948TBtyAf3zSQzj7oaBtNHwIexVkhIRS9TCaqBXeUsK4BJUqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698248; c=relaxed/simple; bh=uDxOm844VsAsi9UnMdkeV0AtSZv36ezRQCbCtTNGPfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UdgqzqHPCe0CmB7SzcqVbm6BPu7vBjqybJI66zf0OU6L2Be7SHUZAkGQ0sImdWxqTu1tjSQ1v5KRU3g3VNmpSOXvTa/lG6R74aYQtqvqNUsukK+HAU3LREdEOECUrxgLmX3M96SHeJUFP1Xl94qoGyKmlQWDb4e8nWogpqF+mvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-20ce65c8e13so59717705ad.1; Wed, 23 Oct 2024 08:44:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698246; x=1730303046; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jJEggviDo9R4Ek8kHMFcfr5AkXM+HxfAn8Vpwc2O0pc=; b=Up7wEZuQRvRxP8eFQSGQ8VmAM9Ar1vyGm1Y+6k4RWg/Pe/VDIysbDM1WAljP9E6H7n YbtSSJbv4l+voa8HejCpHHjg6kGsVqySrSWrmGxsdz74kUAEYk3byYECi40pKNegNjYR FH9TsUub6likgXLEWe9je8CtqnZMFSEquwrOXYexKImEMTmYVqgFwA3VtDRXH1JBhy3E 0jXL4UvO1Cv+OZgwbeGxzoSi+D8B0ohhXUt/3yvYdTkUdgeXmY59SlbXHGbdKNxIEFm3 MvnkJG5SlbCAmX+jCzFVO+evmFJpUrWc2dXVKSXprBE+pYp76382D+9sXLUkru3nlt8L 64hA== X-Forwarded-Encrypted: i=1; AJvYcCUgQKUer5XhN5o6UAxPC7B9zMDUDeO0ksMvnhSFDp6b1Y7FCDsK4gAUOFsrhrFX8yWGE7EH7PeTuRj2UmQ=@vger.kernel.org, AJvYcCV5JHKZ9S/q9Cns3YB0oMQU6CxGN5a8yfyqQQBR18tCNd0evDF8EYfPkW6oIoL0EW//0ympbPLa8QZpeIHWMULu@vger.kernel.org X-Gm-Message-State: AOJu0Yz9vfGBDaRWuJ1kzKzT4F3OkVefTLAzP7S4aPcE+wUnHhoS13DY BfcmiecVIlpMKAgOtuzfiLU1JD4dHCa7pMxQcbD+DJYeYaU1gXWP+kiZhfI= X-Google-Smtp-Source: AGHT+IHBEPCfsM6TR7ZLRV2HrZ2my5lDqweT6eEKqO/wIiPTXc8fSxq62SssnyytEe/QxlJVRel9GQ== X-Received: by 2002:a17:902:e74d:b0:20c:e005:2c27 with SMTP id d9443c01a7336-20fa9e9fd45mr44150325ad.42.1729698245625; Wed, 23 Oct 2024 08:44:05 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e76df52ff1sm1592404a91.6.2024.10.23.08.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:05 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 02/12] selftests: ncdevmem: Separate out dmabuf provider Date: Wed, 23 Oct 2024 08:43:52 -0700 Message-ID: <20241023154402.441510-3-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" So we can plug the other ones in the future if needed. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 198 +++++++++++++++---------- 1 file changed, 117 insertions(+), 81 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index 9245d3f158dd..9b3ca6398a9d 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -71,17 +71,101 @@ static char *ifname =3D "eth1"; static unsigned int ifindex; static unsigned int dmabuf_id; =20 -void print_bytes(void *ptr, size_t size) +struct memory_buffer { + int fd; + size_t size; + + int devfd; + int memfd; + char *buf_mem; +}; + +struct memory_provider { + struct memory_buffer *(*alloc)(size_t size); + void (*free)(struct memory_buffer *ctx); + void (*memcpy_from_device)(void *dst, struct memory_buffer *src, + size_t off, int n); +}; + +static struct memory_buffer *udmabuf_alloc(size_t size) { - unsigned char *p =3D ptr; - int i; + struct udmabuf_create create; + struct memory_buffer *ctx; + int ret; =20 - for (i =3D 0; i < size; i++) - printf("%02hhX ", p[i]); - printf("\n"); + ctx =3D malloc(sizeof(*ctx)); + if (!ctx) + error(1, ENOMEM, "malloc failed"); + + ctx->size =3D size; + + ctx->devfd =3D open("/dev/udmabuf", O_RDWR); + if (ctx->devfd < 0) + error(1, errno, + "%s: [skip,no-udmabuf: Unable to access DMA buffer device file]\n", + TEST_PREFIX); + + ctx->memfd =3D memfd_create("udmabuf-test", MFD_ALLOW_SEALING); + if (ctx->memfd < 0) + error(1, errno, "%s: [skip,no-memfd]\n", TEST_PREFIX); + + ret =3D fcntl(ctx->memfd, F_ADD_SEALS, F_SEAL_SHRINK); + if (ret < 0) + error(1, errno, "%s: [skip,fcntl-add-seals]\n", TEST_PREFIX); + + ret =3D ftruncate(ctx->memfd, size); + if (ret =3D=3D -1) + error(1, errno, "%s: [FAIL,memfd-truncate]\n", TEST_PREFIX); + + memset(&create, 0, sizeof(create)); + + create.memfd =3D ctx->memfd; + create.offset =3D 0; + create.size =3D size; + ctx->fd =3D ioctl(ctx->devfd, UDMABUF_CREATE, &create); + if (ctx->fd < 0) + error(1, errno, "%s: [FAIL, create udmabuf]\n", TEST_PREFIX); + + ctx->buf_mem =3D mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, + ctx->fd, 0); + if (ctx->buf_mem =3D=3D MAP_FAILED) + error(1, errno, "%s: [FAIL, map udmabuf]\n", TEST_PREFIX); + + return ctx; +} + +static void udmabuf_free(struct memory_buffer *ctx) +{ + munmap(ctx->buf_mem, ctx->size); + close(ctx->fd); + close(ctx->memfd); + close(ctx->devfd); + free(ctx); } =20 -void print_nonzero_bytes(void *ptr, size_t size) +static void udmabuf_memcpy_from_device(void *dst, struct memory_buffer *sr= c, + size_t off, int n) +{ + struct dma_buf_sync sync =3D {}; + + sync.flags =3D DMA_BUF_SYNC_START; + ioctl(src->fd, DMA_BUF_IOCTL_SYNC, &sync); + + memcpy(dst, src->buf_mem + off, n); + + sync.flags =3D DMA_BUF_SYNC_END; + ioctl(src->fd, DMA_BUF_IOCTL_SYNC, &sync); +} + +static struct memory_provider udmabuf_memory_provider =3D { + .alloc =3D udmabuf_alloc, + .free =3D udmabuf_free, + .memcpy_from_device =3D udmabuf_memcpy_from_device, +}; + +static struct memory_provider *provider =3D &udmabuf_memory_provider; + +static void print_nonzero_bytes(void *ptr, size_t size) { unsigned char *p =3D ptr; unsigned int i; @@ -201,42 +285,7 @@ static int bind_rx_queue(unsigned int ifindex, unsigne= d int dmabuf_fd, return -1; } =20 -static void create_udmabuf(int *devfd, int *memfd, int *buf, size_t dmabuf= _size) -{ - struct udmabuf_create create; - int ret; - - *devfd =3D open("/dev/udmabuf", O_RDWR); - if (*devfd < 0) { - error(70, 0, - "%s: [skip,no-udmabuf: Unable to access DMA buffer device file]\n", - TEST_PREFIX); - } - - *memfd =3D memfd_create("udmabuf-test", MFD_ALLOW_SEALING); - if (*memfd < 0) - error(70, 0, "%s: [skip,no-memfd]\n", TEST_PREFIX); - - /* Required for udmabuf */ - ret =3D fcntl(*memfd, F_ADD_SEALS, F_SEAL_SHRINK); - if (ret < 0) - error(73, 0, "%s: [skip,fcntl-add-seals]\n", TEST_PREFIX); - - ret =3D ftruncate(*memfd, dmabuf_size); - if (ret =3D=3D -1) - error(74, 0, "%s: [FAIL,memfd-truncate]\n", TEST_PREFIX); - - memset(&create, 0, sizeof(create)); - - create.memfd =3D *memfd; - create.offset =3D 0; - create.size =3D dmabuf_size; - *buf =3D ioctl(*devfd, UDMABUF_CREATE, &create); - if (*buf < 0) - error(75, 0, "%s: [FAIL, create udmabuf]\n", TEST_PREFIX); -} - -int do_server(void) +int do_server(struct memory_buffer *mem) { char ctrl_data[sizeof(int) * 20000]; struct netdev_queue_id *queues; @@ -244,23 +293,18 @@ int do_server(void) struct sockaddr_in client_addr; struct sockaddr_in server_sin; size_t page_aligned_frags =3D 0; - int devfd, memfd, buf, ret; size_t total_received =3D 0; socklen_t client_addr_len; bool is_devmem =3D false; - char *buf_mem =3D NULL; + char *tmp_mem =3D NULL; struct ynl_sock *ys; - size_t dmabuf_size; char iobuf[819200]; char buffer[256]; int socket_fd; int client_fd; size_t i =3D 0; int opt =3D 1; - - dmabuf_size =3D getpagesize() * NUM_PAGES; - - create_udmabuf(&devfd, &memfd, &buf, dmabuf_size); + int ret; =20 if (reset_flow_steering()) error(1, 0, "Failed to reset flow steering\n"); @@ -284,13 +328,12 @@ int do_server(void) queues[i].id =3D start_queue + i; } =20 - if (bind_rx_queue(ifindex, buf, queues, num_queues, &ys)) + if (bind_rx_queue(ifindex, mem->fd, queues, num_queues, &ys)) error(1, 0, "Failed to bind\n"); =20 - buf_mem =3D mmap(NULL, dmabuf_size, PROT_READ | PROT_WRITE, MAP_SHARED, - buf, 0); - if (buf_mem =3D=3D MAP_FAILED) - error(1, 0, "mmap()"); + tmp_mem =3D malloc(mem->size); + if (!tmp_mem) + error(1, ENOMEM, "malloc failed"); =20 server_sin.sin_family =3D AF_INET; server_sin.sin_port =3D htons(atoi(port)); @@ -341,7 +384,6 @@ int do_server(void) struct iovec iov =3D { .iov_base =3D iobuf, .iov_len =3D sizeof(iobuf) }; struct dmabuf_cmsg *dmabuf_cmsg =3D NULL; - struct dma_buf_sync sync =3D { 0 }; struct cmsghdr *cm =3D NULL; struct msghdr msg =3D { 0 }; struct dmabuf_token token; @@ -410,22 +452,17 @@ int do_server(void) else page_aligned_frags++; =20 - sync.flags =3D DMA_BUF_SYNC_READ | DMA_BUF_SYNC_START; - ioctl(buf, DMA_BUF_IOCTL_SYNC, &sync); + provider->memcpy_from_device(tmp_mem, mem, + dmabuf_cmsg->frag_offset, + dmabuf_cmsg->frag_size); =20 if (do_validation) validate_buffer( - ((unsigned char *)buf_mem) + + ((unsigned char *)tmp_mem) + dmabuf_cmsg->frag_offset, dmabuf_cmsg->frag_size); else - print_nonzero_bytes( - ((unsigned char *)buf_mem) + - dmabuf_cmsg->frag_offset, - dmabuf_cmsg->frag_size); - - sync.flags =3D DMA_BUF_SYNC_READ | DMA_BUF_SYNC_END; - ioctl(buf, DMA_BUF_IOCTL_SYNC, &sync); + print_nonzero_bytes(tmp_mem, dmabuf_cmsg->frag_size); =20 ret =3D setsockopt(client_fd, SOL_SOCKET, SO_DEVMEM_DONTNEED, &token, @@ -450,12 +487,9 @@ int do_server(void) =20 cleanup: =20 - munmap(buf_mem, dmabuf_size); + free(tmp_mem); close(client_fd); close(socket_fd); - close(buf); - close(memfd); - close(devfd); ynl_sock_destroy(ys); =20 return 0; @@ -464,14 +498,11 @@ int do_server(void) void run_devmem_tests(void) { struct netdev_queue_id *queues; - int devfd, memfd, buf; + struct memory_buffer *mem; struct ynl_sock *ys; - size_t dmabuf_size; size_t i =3D 0; =20 - dmabuf_size =3D getpagesize() * NUM_PAGES; - - create_udmabuf(&devfd, &memfd, &buf, dmabuf_size); + mem =3D provider->alloc(getpagesize() * NUM_PAGES); =20 /* Configure RSS to divert all traffic from our devmem queues */ if (configure_rss()) @@ -482,7 +513,7 @@ void run_devmem_tests(void) if (configure_headersplit(1)) error(1, 0, "Failed to configure header split\n"); =20 - if (!bind_rx_queue(ifindex, buf, queues, num_queues, &ys)) + if (!bind_rx_queue(ifindex, mem->fd, queues, num_queues, &ys)) error(1, 0, "Binding empty queues array should have failed\n"); =20 for (i =3D 0; i < num_queues; i++) { @@ -495,7 +526,7 @@ void run_devmem_tests(void) if (configure_headersplit(0)) error(1, 0, "Failed to configure header split\n"); =20 - if (!bind_rx_queue(ifindex, buf, queues, num_queues, &ys)) + if (!bind_rx_queue(ifindex, mem->fd, queues, num_queues, &ys)) error(1, 0, "Configure dmabuf with header split off should have failed\n= "); =20 if (configure_headersplit(1)) @@ -508,7 +539,7 @@ void run_devmem_tests(void) queues[i].id =3D start_queue + i; } =20 - if (bind_rx_queue(ifindex, buf, queues, num_queues, &ys)) + if (bind_rx_queue(ifindex, mem->fd, queues, num_queues, &ys)) error(1, 0, "Failed to bind\n"); =20 /* Deactivating a bound queue should not be legal */ @@ -517,11 +548,15 @@ void run_devmem_tests(void) =20 /* Closing the netlink socket does an implicit unbind */ ynl_sock_destroy(ys); + + provider->free(mem); } =20 int main(int argc, char *argv[]) { + struct memory_buffer *mem; int is_server =3D 0, opt; + int ret; =20 while ((opt =3D getopt(argc, argv, "ls:c:p:v:q:t:f:")) !=3D -1) { switch (opt) { @@ -562,8 +597,9 @@ int main(int argc, char *argv[]) =20 run_devmem_tests(); =20 - if (is_server) - return do_server(); + mem =3D provider->alloc(getpagesize() * NUM_PAGES); + ret =3D is_server ? do_server(mem) : 1; + provider->free(mem); =20 - return 0; + return ret; } --=20 2.47.0 From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3C951C830B; Wed, 23 Oct 2024 15:44:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698249; cv=none; b=lUDLqDIDI0IdP/ZRQiKYg1V/MV1eYGEf00bJXESupLA/yppvmrFq8IMvij0zyZlXvCQI/yCQiyHk952H+SbU/UNVWL/9E4LIz9wZFnFMZxUc5KInp8ySNyARd0f8rgD5QB3fb0G/bcaMTJ+9vd5a3zJv6IHO5877L0WFCw/dqPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698249; c=relaxed/simple; bh=OaE7XwAEFbIu+s9p7ZnqgQDlY0jv4o3kXb+oqYrd/d8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ahac9Q8ByF3wJ0RJaUBYresVKbSznVfyUd59YBYTJW8ekbe5setgHyu2CXjGFrrbvAzFQs7S9U/6N3BGtKSCqiVXOa1H5vAisRB1tcOXFAOnFmbxJPhZ7zkFbnZYPt7Ry0wLgbHeeD3aUSoj2e4DigMx8wHDXUiy40yVlo+FVg4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-20ca388d242so50731785ad.2; Wed, 23 Oct 2024 08:44:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698247; x=1730303047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DJuaEXoxJxSHRZGvGUlWEOD0V27rFOSWO6abbhkkw/I=; b=lQKXJ4r9Ub4Rq+lKRNczOpWKetr36XrFDUwuyVIhMEb9Mi3DTbWe47qKqiqK1wa0Fk 11f0uggHS5iJO4tE3kPspo6yaz7m5NQyIKYiZf8AOz2UldeldtIVDPRSYW/wORzlQ1pT CYWLRSnq4nYIGlqsE2F5B5c2gpFvzSsIdNpgylm1UhSjIEPQKWvEKbecUibEulEy+ItH X8demYg8J5amxViIBaqTW+zWkj2wBtYqvxW2xkRvjTz++YbhO6k96eoa5YMM2XDfVnhM qd4cssBuz6+U9tqmTG0mQLgAEjOvB2ohooB5ZAI0tn4GE4t6KCkUebuaAOna1rhsJXvm gQiQ== X-Forwarded-Encrypted: i=1; AJvYcCUy5lm7z49rMvme8VS/ypQx1eFpcRg8XKTmlylGBSMv/8v5f+lwjrjdLC5xl76zt+wBXuYdZ+1rGK+jFO64cTxP@vger.kernel.org, AJvYcCWWJiY17kgA49MNePuYajL4GqUcwWYm6tx10YuRntreEcRgqstThEHleKIhYnO+pO30nYYxB+6w7fbLjU4=@vger.kernel.org X-Gm-Message-State: AOJu0YwwqLJRVcsqE6Z2i0rKlDV1MwhqzkcBJTIHwrB8vVUT9own2u4J KjV0PiqdqL2CVJ1T/GCQezdOK5FQUEq073+YUwXMgOx8ENncBK3zb0JHFxI= X-Google-Smtp-Source: AGHT+IH2m0+GzmebnxYriEdM12PtEjZTpEDLdoCN3QSsSee+zEiHZfi3qJPnlduMMlvWCHdwLQKSoQ== X-Received: by 2002:a17:902:ec82:b0:20c:8c0f:f986 with SMTP id d9443c01a7336-20fa9e5b449mr40058585ad.24.1729698246840; Wed, 23 Oct 2024 08:44:06 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0d9a7esm58947855ad.182.2024.10.23.08.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:06 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 03/12] selftests: ncdevmem: Unify error handling Date: Wed, 23 Oct 2024 08:43:53 -0700 Message-ID: <20241023154402.441510-4-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is a bunch of places where error() calls look out of place. Use the same error(1, errno, ...) pattern everywhere. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index 9b3ca6398a9d..07222bfcdb07 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -339,33 +339,33 @@ int do_server(struct memory_buffer *mem) server_sin.sin_port =3D htons(atoi(port)); =20 ret =3D inet_pton(server_sin.sin_family, server_ip, &server_sin.sin_addr); - if (socket < 0) - error(79, 0, "%s: [FAIL, create socket]\n", TEST_PREFIX); + if (ret < 0) + error(1, pton, "%s: [FAIL, create socket]\n", TEST_PREFIX); =20 socket_fd =3D socket(server_sin.sin_family, SOCK_STREAM, 0); - if (socket < 0) - error(errno, errno, "%s: [FAIL, create socket]\n", TEST_PREFIX); + if (socket_fd < 0) + error(1, errno, "%s: [FAIL, create socket]\n", TEST_PREFIX); =20 ret =3D setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)); if (ret) - error(errno, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); + error(1, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); =20 ret =3D setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); if (ret) - error(errno, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); + error(1, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); =20 fprintf(stderr, "binding to address %s:%d\n", server_ip, ntohs(server_sin.sin_port)); =20 ret =3D bind(socket_fd, &server_sin, sizeof(server_sin)); if (ret) - error(errno, errno, "%s: [FAIL, bind]\n", TEST_PREFIX); + error(1, errno, "%s: [FAIL, bind]\n", TEST_PREFIX); =20 ret =3D listen(socket_fd, 1); if (ret) - error(errno, errno, "%s: [FAIL, listen]\n", TEST_PREFIX); + error(1, errno, "%s: [FAIL, listen]\n", TEST_PREFIX); =20 client_addr_len =3D sizeof(client_addr); =20 --=20 2.47.0 From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7B401CBEA9; Wed, 23 Oct 2024 15:44:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698250; cv=none; b=Uema5djTKxQPZtgQN0oLKGGt6UVQITBdKZZVLWEi7bEIIus+DTkUOxeuuj23gSVkhCO515IZZOPHLQ3waeHg5/9TGu/VWhfSvtQhFDP3QXVP4TDYXeBgNlk9U95dYqQpiNeuNQhVMFrv4nwGFUJPM9gYH3X7N1WdtY+0/y0eKXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698250; c=relaxed/simple; bh=cLZ/HloOGC0PMG4sMhRkkQxtcn8WnnLKy6YyEv7N6mU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HTSiHpcRhpf//IKtsBCyXDAOjDOskjREzkYRNSZjrAIqTRExfKe77J5JzEhmSShd3M1qovT5rS5bFYjlzwSH9I/yONhXXP8C5/jjM048Ejl3ieQAzEnGOs+EPM+cEZd+Jh6OF+sbFRvqNhPXFoTFbr0lS0TrJxfWLwKijfh1mI4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-7ea6a4f287bso4534876a12.3; Wed, 23 Oct 2024 08:44:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698248; x=1730303048; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JG/ONzrCW+sST5tBBAYNuLx/AbByhvZTDB5rCiNmSS4=; b=N91utPYTvY/UYDivzbA1g2DaNxBVzHtd36ZOdo03CemrtylTSxHyJ3NgbWLY3PgivS ALbD9g0zjW8ZIabPM34ginM/1Fcgc2pbSQhgVJynh7QJZh7x2Nlrhs9LjzGhQH2JUv9J dVwf1kf/PN7hRDi1eVlwosUOvEKNmK7Ynx03HXaZi2l+Cf5iwiFBmhzWRekD2w0a3xoB 6f4ttzY78gxg2qwb8lC/D5EzMOw84bFMf699QbolJpM0sDRJOiSWE0x77l5Xq6FClyam UcylVFP6ocGGMRtcrIIz5GA3yWE/yfPZtyR5a4TDH7SOBnQuQuBVlmfkiXfl6J/nm5rE kYPw== X-Forwarded-Encrypted: i=1; AJvYcCWqRmDHjmoWXWyGFR8b0PtCWMSqAIJPghhXV5OxYIWMFhHQJF7s1gH6e8A+MCccqXtw91o0merybrBIThQ=@vger.kernel.org, AJvYcCX+mnTC5TUlosCbMb5hn00hmBa4qEzNoMGc94yX0O57N0dk65Ih0b2DZX1Qn6XKsKG5b8j9s8r3V911OSwsY323@vger.kernel.org X-Gm-Message-State: AOJu0YyhGCfsBAefA5k9MjYllrqF8Cu1YFp7rCy2mLdhfJBTo8Q3US7+ c62OvpWNFtBWJ75DnCM3s1Xn3/9isq48EDXwK35hDEDWatG7/O/hN0ROcAc= X-Google-Smtp-Source: AGHT+IEDepy9ucFyZHPrSHloe/rBoO+atm93Zb5yszpwpBIjPGbZKilEeYzqRxKM7Id1rrBOKW/I4w== X-Received: by 2002:a05:6a20:d528:b0:1d9:28ae:5e72 with SMTP id adf61e73a8af0-1d978b97cabmr3185775637.36.1729698248008; Wed, 23 Oct 2024 08:44:08 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13eb0c8sm6493605b3a.182.2024.10.23.08.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:07 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 04/12] selftests: ncdevmem: Make client_ip optional Date: Wed, 23 Oct 2024 08:43:54 -0700 Message-ID: <20241023154402.441510-5-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support 3-tuple filtering by making client_ip optional. When -c is not passed, don't specify src-ip/src-port in the filter. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index 07222bfcdb07..051dd8bb0d3c 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -62,7 +62,7 @@ */ =20 static char *server_ip =3D "192.168.1.4"; -static char *client_ip =3D "192.168.1.2"; +static char *client_ip; static char *port =3D "5201"; static size_t do_validation; static int start_queue =3D 8; @@ -236,8 +236,14 @@ static int configure_channels(unsigned int rx, unsigne= d int tx) =20 static int configure_flow_steering(void) { - return run_command("sudo ethtool -N %s flow-type tcp4 src-ip %s dst-ip %s= src-port %s dst-port %s queue %d >&2", - ifname, client_ip, server_ip, port, port, start_queue); + return run_command("sudo ethtool -N %s flow-type tcp4 %s %s dst-ip %s %s = %s dst-port %s queue %d >&2", + ifname, + client_ip ? "src-ip" : "", + client_ip ?: "", + server_ip, + client_ip ? "src-port" : "", + client_ip ? port : "", + port, start_queue); } =20 static int bind_rx_queue(unsigned int ifindex, unsigned int dmabuf_fd, --=20 2.47.0 From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F4F51CCEE9; Wed, 23 Oct 2024 15:44:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698251; cv=none; b=V270G0Q+oEoSRI9QtpwtxGbLc3AZIYWbcYq1xmP7dgL2OV9kHxlSjK3T1M8qslWmmDE0z85N/49KR+kAfX0srzwpTb6Ed4T5oBJApCh5DnEQGt7eYZR3ou9VqLT6reEFHAGDkrlQOkL0HLPpSaJ/cW2fhmSNg2h3/1pEebKjvV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698251; c=relaxed/simple; bh=3Q3dlvLAs/sXPMb1qDNuGq5SMufPn93IIeoDTDQN6hs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rvzBDisIJfuUbVXneGiQqoIAqe5DTCnwvyG6sOPDPDcIf9AqJ0rV9lj8BWaG79UcJ01MK2rKgl7XQY7QuiI5VGS7zQpPRNB4ZWSjKLY1NCP/1PIwynYCrx/gVT4u/xjvTDMBZ8QWjzZT87IPM6vzqWCmDNJ947R4uBqA/NmqBIs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-20cb7139d9dso64384935ad.1; Wed, 23 Oct 2024 08:44:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698249; x=1730303049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fiS+4uLi7KwWxf2hS/+lqiCxxDWyZoQdVn1wNhIX8dw=; b=sHBIJ+oeeLgfLaEazDvJKJOQ7mfgpWRC2uTmF8RReju47QdaAsP8m7jOpK87yGryxZ XB/mDorPfLJ/l9hZi4qfYo6GtKBYR1lRWFvMeh8PYMmBOcMYempZrjhqhu5sFw+9AAwx wBY+Uv/AaMUqMV2tC6Pfh70PQyRXmAmlxB3sK5V8p5lsrjxqEoFJoeSFklvggi/NjNvt 1O0uXZNfQxc5FAZCNHgufS0f4TQ8sV7VkDTmib1/muY35VrUQNdXsi5bhsq7E691TuF/ 6F9CUG8IiQJhTzRF3meZEx6zL2eQ7OFAXhFNojTMr9YvAu71Cx5vS5EPYmG8KrwZbmqU DpmA== X-Forwarded-Encrypted: i=1; AJvYcCU05BKKcA6z6C5lkJMSgtV0ds4LFYDBZ1dpSQS11i/6fParJQH+VhBIm/PwJ++LFyl1lexYdsyJQ8dcXWs=@vger.kernel.org, AJvYcCUjEjqz3Om70iv6u98ioMf6OJRrx0j3QQ3C0OceMXT2tJBoxjnP7gvFMXFD//G7UnHGBQIIR/NPTRLB2ZHHiWhv@vger.kernel.org X-Gm-Message-State: AOJu0YyRj2s0SPWCN9ZSOmgxa39z/MuGCIVk0g2Kp6AG9NF8FELLVJFP sKl2uCjhrUjHxJIO8OsdMr6MhmioPEcMxLbpa6uZ/gKtgYAYT881ZMPkf0c= X-Google-Smtp-Source: AGHT+IHKVYwFII+FgdeA/Ug+ahHx5vB6W9ty+r7noIXKmcnI19zzBwv1oQyVPIf460mqnXTILZGFuQ== X-Received: by 2002:a17:902:e851:b0:20c:b3d9:f5bd with SMTP id d9443c01a7336-20fa9e41304mr33951145ad.18.1729698249163; Wed, 23 Oct 2024 08:44:09 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7ef0cbf1sm59149395ad.103.2024.10.23.08.44.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:08 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 05/12] selftests: ncdevmem: Remove default arguments Date: Wed, 23 Oct 2024 08:43:55 -0700 Message-ID: <20241023154402.441510-6-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To make it clear what's required and what's not. Also, some of the values don't seem like a good defaults; for example eth1. Move the invocation comment to the top, add missing -s to the client and cleanup the client invocation a bit to make more readable. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 61 ++++++++++++++++---------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index 051dd8bb0d3c..b81b8de165f0 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -1,4 +1,31 @@ // SPDX-License-Identifier: GPL-2.0 +/* + * tcpdevmem netcat. Works similarly to netcat but does device memory TCP + * instead of regular TCP. Uses udmabuf to mock a dmabuf provider. + * + * Usage: + * + * On server: + * ncdevmem -s [-c ] -f eth1 -l -p 5201 + * + * On client: + * echo -n "hello\nworld" | nc -s 5201 -p 5201 + * + * Test data validation: + * + * On server: + * ncdevmem -s [-c ] -f eth1 -l -p 5201 -v 7 + * + * On client: + * yes $(echo -e \\x01\\x02\\x03\\x04\\x05\\x06) | \ + * tr \\n \\0 | \ + * head -c 5G | \ + * nc 5201 -p 5201 + * + * + * Note this is compatible with regular netcat. i.e. the sender or receive= r can + * be replaced with regular netcat to test the RX or TX path in isolation. + */ #define _GNU_SOURCE #define __EXPORTED_HEADERS__ =20 @@ -42,32 +69,13 @@ #define MSG_SOCK_DEVMEM 0x2000000 #endif =20 -/* - * tcpdevmem netcat. Works similarly to netcat but does device memory TCP - * instead of regular TCP. Uses udmabuf to mock a dmabuf provider. - * - * Usage: - * - * On server: - * ncdevmem -s -c -f eth1 -l -p 5201 -v 7 - * - * On client: - * yes $(echo -e \\x01\\x02\\x03\\x04\\x05\\x06) | \ - * tr \\n \\0 | \ - * head -c 5G | \ - * nc 5201 -p 5201 - * - * Note this is compatible with regular netcat. i.e. the sender or receive= r can - * be replaced with regular netcat to test the RX or TX path in isolation. - */ - -static char *server_ip =3D "192.168.1.4"; +static char *server_ip; static char *client_ip; -static char *port =3D "5201"; +static char *port; static size_t do_validation; static int start_queue =3D 8; static int num_queues =3D 8; -static char *ifname =3D "eth1"; +static char *ifname; static unsigned int ifindex; static unsigned int dmabuf_id; =20 @@ -596,6 +604,15 @@ int main(int argc, char *argv[]) } } =20 + if (!server_ip) + error(1, 0, "Missing -s argument\n"); + + if (!port) + error(1, 0, "Missing -p argument\n"); + + if (!ifname) + error(1, 0, "Missing -f argument\n"); + ifindex =3D if_nametoindex(ifname); =20 for (; optind < argc; optind++) --=20 2.47.0 From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4441D1CEAA2; Wed, 23 Oct 2024 15:44:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698252; cv=none; b=tWNjSNG+Cqb2/sTD1q/qq7Tmv1GfuK2rXqtBAMPr1YY9vZg3lcoJKNoTpYbHxUrH8OWp1ykiS7bWS5g6Uv2W2HZ6/Dn90C5A+eSDTdnsEpz2rkyJ8kVvRBjKVkoMhTrvAAYynLg1yahJe7CV+Pb19yB+6e9d14dIoYN2UHjFFqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698252; c=relaxed/simple; bh=S2Bt7IDkIp3RcUwSnvhgbtsbgEJQf9urUQoYVHH0eBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gxrxD64Z543E82A/tX6uh/foUsBkpy4yUs53mdmnRs0gtXi580+93aB4haFfLNC/nUdFWCMEoBxnybkGCLxdROPTQY9vPkGHwrzb1ZXnXuxwsxHDC9XeMeBP6l6DV+c696xUZGjk6FRlRfNWwx+w3qEiwy6FicyIXMHQEH+naxA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2e2ad9825a7so12732a91.0; Wed, 23 Oct 2024 08:44:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698250; x=1730303050; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X01t2SGg+C1pUVxt40lNj32d2wiORw41g4O6n04tiDE=; b=H0OxvvyK/j5pr+mOG/vfBeQWb3ybATdESTZ10cZtHAMmtFXZk49TLvpXqAqwixVLW4 YEE3FNir5xESUhYa5ZRDlLXrmubgrm0+xim3YQVD2mZW5II3GiEGbLVJQPjVwD2CTj+y A8bAEbxhhncHl3bhuEeBV0Jhgq4NEy4zcsk1nVA7vCLlzF94k5Ux6crEv86PFsURDEBj TiYllX2FBLDgkuiOueHnssbLphikpf1INHvWSDzAR8uWnFV9JBhKgIrH5Xa4dWWbV8aB gFF9JVMRRjL2rH/sELIJ/jcl06fXTgJP/qV3T072er7BxcaRxitC0nf0hdLJggdAzQIu Hfwg== X-Forwarded-Encrypted: i=1; AJvYcCWlczOMm6IX1X0Ot+dMECb+Qb8GUqUWe19mLVO8XgnoamSfRfSshKiSkU+4YGK7k8isyDWGJQ5nDyuRf1qS03T5@vger.kernel.org, AJvYcCXE6jbt4czXbjS2NziiQmzHIrM7b8kJKoEIUD6jczDhMino75jYwME2YzV9RmHWAnQrxctl4ZHtoBRz7zQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwuMyPy0hV666IaxBgA8D2E9W5t7M2Cjek1c8DiHPD7fzlpli6G 7EuSyB5MnBCWjYbTuJyH0hguqk/8AEgv55BilbySf/TRJFY6uauoXsUbBJw= X-Google-Smtp-Source: AGHT+IETgqiaxg2PanUbC5M6bRDY5UaOMe2COqt7Zk9wnHAfTJe4hyWmVcl73+FJQliSnfs41Lq2mw== X-Received: by 2002:a17:90b:234e:b0:2e2:b64e:f4f7 with SMTP id 98e67ed59e1d1-2e76b6f4c5emr2966473a91.29.1729698250373; Wed, 23 Oct 2024 08:44:10 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e76dfba01csm1585769a91.30.2024.10.23.08.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:10 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 06/12] selftests: ncdevmem: Switch to AF_INET6 Date: Wed, 23 Oct 2024 08:43:56 -0700 Message-ID: <20241023154402.441510-7-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use dualstack socket to support both v4 and v6. v4-mapped-v6 address can be used to do v4. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 85 +++++++++++++++++--------- 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index b81b8de165f0..8e4a0fe74bb1 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -242,13 +242,22 @@ static int configure_channels(unsigned int rx, unsign= ed int tx) return run_command("sudo ethtool -L %s rx %u tx %u", ifname, rx, tx); } =20 -static int configure_flow_steering(void) +static int configure_flow_steering(struct sockaddr_in6 *server_sin) { - return run_command("sudo ethtool -N %s flow-type tcp4 %s %s dst-ip %s %s = %s dst-port %s queue %d >&2", + const char *server_addr =3D server_ip; + const char *type =3D "tcp6"; + + if (IN6_IS_ADDR_V4MAPPED(&server_sin->sin6_addr)) { + type =3D "tcp4"; + server_addr =3D strrchr(server_ip, ':') + 1; + } + + return run_command("sudo ethtool -N %s flow-type %s %s %s dst-ip %s %s %s= dst-port %s queue %d >&2", ifname, + type, client_ip ? "src-ip" : "", client_ip ?: "", - server_ip, + server_addr, client_ip ? "src-port" : "", client_ip ? port : "", port, start_queue); @@ -299,13 +308,43 @@ static int bind_rx_queue(unsigned int ifindex, unsign= ed int dmabuf_fd, return -1; } =20 +static int enable_reuseaddr(int fd) +{ + int opt =3D 1; + int ret; + + ret =3D setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)); + if (ret) + return -errno; + + ret =3D setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + if (ret) + return -errno; + + return 0; +} + +static int parse_address(const char *str, int port, struct sockaddr_in6 *s= in6) +{ + int ret; + + sin6->sin6_family =3D AF_INET6; + sin6->sin6_port =3D htons(port); + + ret =3D inet_pton(sin6->sin6_family, str, &sin6->sin6_addr); + if (ret < 0) + return -1; + + return 0; +} + int do_server(struct memory_buffer *mem) { char ctrl_data[sizeof(int) * 20000]; struct netdev_queue_id *queues; size_t non_page_aligned_frags =3D 0; - struct sockaddr_in client_addr; - struct sockaddr_in server_sin; + struct sockaddr_in6 client_addr; + struct sockaddr_in6 server_sin; size_t page_aligned_frags =3D 0; size_t total_received =3D 0; socklen_t client_addr_len; @@ -317,9 +356,12 @@ int do_server(struct memory_buffer *mem) int socket_fd; int client_fd; size_t i =3D 0; - int opt =3D 1; int ret; =20 + ret =3D parse_address(server_ip, atoi(port), &server_sin); + if (ret < 0) + error(1, 0, "parse server address"); + if (reset_flow_steering()) error(1, 0, "Failed to reset flow steering\n"); =20 @@ -328,7 +370,7 @@ int do_server(struct memory_buffer *mem) error(1, 0, "Failed to configure rss\n"); =20 /* Flow steer our devmem flows to start_queue */ - if (configure_flow_steering()) + if (configure_flow_steering(&server_sin)) error(1, 0, "Failed to configure flow steering\n"); =20 sleep(1); @@ -349,29 +391,16 @@ int do_server(struct memory_buffer *mem) if (!tmp_mem) error(1, ENOMEM, "malloc failed"); =20 - server_sin.sin_family =3D AF_INET; - server_sin.sin_port =3D htons(atoi(port)); - - ret =3D inet_pton(server_sin.sin_family, server_ip, &server_sin.sin_addr); - if (ret < 0) - error(1, pton, "%s: [FAIL, create socket]\n", TEST_PREFIX); - - socket_fd =3D socket(server_sin.sin_family, SOCK_STREAM, 0); + socket_fd =3D socket(AF_INET6, SOCK_STREAM, 0); if (socket_fd < 0) error(1, errno, "%s: [FAIL, create socket]\n", TEST_PREFIX); =20 - ret =3D setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &opt, - sizeof(opt)); - if (ret) - error(1, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); - - ret =3D setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &opt, - sizeof(opt)); + ret =3D enable_reuseaddr(socket_fd); if (ret) - error(1, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); + error(1, errno, "%s: [FAIL, reuseaddr]\n", TEST_PREFIX); =20 fprintf(stderr, "binding to address %s:%d\n", server_ip, - ntohs(server_sin.sin_port)); + ntohs(server_sin.sin6_port)); =20 ret =3D bind(socket_fd, &server_sin, sizeof(server_sin)); if (ret) @@ -383,16 +412,16 @@ int do_server(struct memory_buffer *mem) =20 client_addr_len =3D sizeof(client_addr); =20 - inet_ntop(server_sin.sin_family, &server_sin.sin_addr, buffer, + inet_ntop(AF_INET6, &server_sin.sin6_addr, buffer, sizeof(buffer)); fprintf(stderr, "Waiting or connection on %s:%d\n", buffer, - ntohs(server_sin.sin_port)); + ntohs(server_sin.sin6_port)); client_fd =3D accept(socket_fd, &client_addr, &client_addr_len); =20 - inet_ntop(client_addr.sin_family, &client_addr.sin_addr, buffer, + inet_ntop(AF_INET6, &client_addr.sin6_addr, buffer, sizeof(buffer)); fprintf(stderr, "Got connection from %s:%d\n", buffer, - ntohs(client_addr.sin_port)); + ntohs(client_addr.sin6_port)); =20 while (1) { struct iovec iov =3D { .iov_base =3D iobuf, --=20 2.47.0 From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72D551CEEB5; Wed, 23 Oct 2024 15:44:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698253; cv=none; b=lNllSQ5K8nvmUu/A1W8N2pLQsiBtwAH9YlcYiuomBQYcI8wzjhb4s+SEq9cEYTP13tGZvPZPuHNTdXUw4cvhni0SsvBE8D6sq6UVwtrJ9XZ5x2NxfbE8ZCkx6wjFHKV73Ci3QAArbjfeha4cpXvvW06jg+e8jM7Ku1V/m7dh5vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698253; c=relaxed/simple; bh=Ie/Ptsq9qO1ESENyDMOnFQ6N1E2e+FpWUSYWB06bdOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TVr0ouWVRx00FHjuRt2NvZa1goUDUtxjTMZUAi7qoVOcV4IqSb+4KZ4mWGkbv3NK/L03TQJH0aZJaoJmSCqwQFbFoCr2laiNQ/RWVL1rLw/7u1GZzg4DBo1do6RCabShcsdsYxTD7uZAYcxY8p54efkBgg88Xux1xxnElbNnFj4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2e2b9480617so703a91.1; Wed, 23 Oct 2024 08:44:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698251; x=1730303051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/RMY5HztPWF4NWuW1QBTHPrJP1v43bJinxEr3M4sUnA=; b=AsWmB2bai8D7Bgl7NXtvCehMecWwe5nX+GB0+JaZWuf4L9hniZb7eBWybfo8LiomWC wMtI3SvkJK+89B/WUfHbz12CKuBKqXBroJd2iaClX2ep3977XYVZ1brb0B+gSf1TyU3V cTMYpPWKSDm0IUIULsgZDYFZHvX6RFClMbSIBmj6OrXnOG8PdvTU36BIU+R7plvFWYm5 z+ttKiNJFlhOAvtdYUOeeJNQ7bgE1jhlkL/8SUMe0mOBxl8AWh91c6r7+1DWvsj/nwbc pt7galRitvto5CwJ0ai9BulMoZOxfUQfQ2A/axywYUtpu+OGPYFvFAxgDrZqJM1HexmP zwTA== X-Forwarded-Encrypted: i=1; AJvYcCWatheJT2duY5ew1krqPTMaHwcNcv9Rsi70W/cIa9V4KxOi4HwiujMOQ7yMw6IIjULeAOzfGXlPjBshWo8=@vger.kernel.org, AJvYcCWrXE5UTNYLoPvgFwie5bsPHGolbUWJxFTeiM5Vdoik//RWUv2EirJSok3PFDtsRPnZOyng8rzBYpiVf+GJ7PkC@vger.kernel.org X-Gm-Message-State: AOJu0YyYacp687dumcCi+RUEdBowPRm6a94odjT6drwSSj791cxxOxkh mXUc5JLPZr2TtICPhX1dGjt6V7G1p6VHj7ZZqOXx6iLyNLnlB5vlP8CKxts= X-Google-Smtp-Source: AGHT+IH0UN+JvitaWu3wC6MXLlA89MMB40sRPCiJu+ypghT9t0AYB7k5P7v7OsnfPV5RUjhJKk1niQ== X-Received: by 2002:a17:90b:4a44:b0:2e2:de72:2b76 with SMTP id 98e67ed59e1d1-2e76b5e0390mr3012412a91.16.1729698251476; Wed, 23 Oct 2024 08:44:11 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e76df6fdd0sm1589133a91.28.2024.10.23.08.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:11 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 07/12] selftests: ncdevmem: Properly reset flow steering Date: Wed, 23 Oct 2024 08:43:57 -0700 Message-ID: <20241023154402.441510-8-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ntuple off/on might be not enough to do it on all NICs. Add a bunch of shell crap to explicitly remove the rules. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index 8e4a0fe74bb1..697771c1f9fa 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -217,13 +217,18 @@ void validate_buffer(void *line, size_t size) =20 static int reset_flow_steering(void) { - int ret =3D 0; - - ret =3D run_command("sudo ethtool -K %s ntuple off >&2", ifname); - if (ret) - return ret; - - return run_command("sudo ethtool -K %s ntuple on >&2", ifname); + /* Depending on the NIC, toggling ntuple off and on might not + * be allowed. Additionally, attempting to delete existing filters + * will fail if no filters are present. Therefore, do not enforce + * the exit status. + */ + + run_command("sudo ethtool -K %s ntuple off >&2", ifname); + run_command("sudo ethtool -K %s ntuple on >&2", ifname); + run_command( + "sudo ethtool -n %s | grep 'Filter:' | awk '{print $2}' | xargs -n1 etht= ool -N %s delete >&2", + ifname, ifname); + return 0; } =20 static int configure_headersplit(bool on) --=20 2.47.0 From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83F8B1CF5E8; Wed, 23 Oct 2024 15:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698255; cv=none; b=bD/MHbFlWHINpt4/RACrOJNE+G+f+CnHElfyw9ioKX1JO2F2KuwKvHpD+FEdk6jzPCNReAp2tZHO/b+zqZcAQmXqMnsRxqweqEnsnXEIW9Kwi9pdli49wDG5rEHobOlJUkC0/DRXjvGIlwqffNA9oLbWTE/3Xx8aGR7mA7JKV2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698255; c=relaxed/simple; bh=HQzDey7GgEVa3rTI5jthiLJDrmkMe+R6419M0Ug8+yg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tLZf1XxqaPK1RSUY++IBtuWIeSsi52FnS9uw5S36SQW0Afr3J9UERsl+PqA+3qua5Zb9WGva+b2eHJnbuHDsM2wfOx58UuV3mojvjvejXh/hhSWjpMPKlbpXQ6qXCfdUGTDWhB8sfApkcAzPTfeFLtYbO/sV5nhRYs5y3A7Hgww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-71ea2643545so4755188b3a.3; Wed, 23 Oct 2024 08:44:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698253; x=1730303053; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/lZRzUOJGf0+vqtRPw1M1zfctMTkla5AJBP9vN6QXRw=; b=feOGsypmZC8Hhzo1Q4gUWzfEcVdlgqeuK8wCTAlfuwKlHSgNUj1xw239OzNnCbe+Xy RZOGx7YrF9ef88HBsW1hX7yGHfsaWTdlx/cdP575V8VTW7F0Ym4KZR/kMgWAHDgGg4jx 5NIOnOpnp6kYvAMKYwFZW4gPDuxLWykEVQKPR0izoiPasH3ahnxIiQtj/cvwnQiTjeeO sHL7SzOrIiNpWBnTOemclq35ON4LyLSl+RZ5g+Vra7kFn+sdux0SeEu+AgdAun4RFtWD XlqulyYb5GZi9+mgO2k4IsjeKysR8VAPEnI9dYMyVf1myg8uSHBDL/045XpCDgAV7tc5 LtzQ== X-Forwarded-Encrypted: i=1; AJvYcCVDmarlj4ItqIu21fUK8JanYAu83Gmvxo/fafIOJZSVH9tRPaQG+VTk5GEzIpFIdQ8lskylBUnYq1t0woA=@vger.kernel.org, AJvYcCX1lIl50kQJb2KHfhnr4cXRNF9OZWxXJmGa/QBBb7tSSkgdJg/xmrfd5Dk684ZaIVhYJXwQNkBSBjxQvXinOIuY@vger.kernel.org X-Gm-Message-State: AOJu0Yxw+fyJu/nOPBOCWFq/IdSfdiRGGsPLCSJlfFGEny86l9g1DhuO rf17mLYxyx11LALxendQOmq7JDuJ6V2wB5dYl2GEABwO9+1po/5o37rglMs= X-Google-Smtp-Source: AGHT+IHj64z2ZiDnLpjI261VFNR6D2A2Ch7MZv5ivbzzHXDu8Jfy3MHaGsuBTRTGHRJawP2UL73New== X-Received: by 2002:a05:6a00:27a1:b0:71e:b4ee:960d with SMTP id d2e1a72fcca58-72030aa4330mr4928096b3a.10.1729698252581; Wed, 23 Oct 2024 08:44:12 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13ea284sm6693072b3a.146.2024.10.23.08.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:12 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 08/12] selftests: ncdevmem: Use YNL to enable TCP header split Date: Wed, 23 Oct 2024 08:43:58 -0700 Message-ID: <20241023154402.441510-9-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the next patch the hard-coded queue numbers are gonna be removed. So introduce some initial support for ethtool YNL and use it to enable header split. Also, tcp-data-split requires latest ethtool which is unlikely to be present in the distros right now. (ideally, we should not shell out to ethtool at all). Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/Makefile | 2 +- tools/testing/selftests/net/ncdevmem.c | 57 +++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests= /net/Makefile index 26a4883a65c9..759b1d2dc8b4 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -111,7 +111,7 @@ TEST_INCLUDES :=3D forwarding/lib.sh include ../lib.mk =20 # YNL build -YNL_GENS :=3D netdev +YNL_GENS :=3D ethtool netdev include ynl.mk =20 $(OUTPUT)/epoll_busy_poll: LDLIBS +=3D -lcap diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index 697771c1f9fa..e1faad46548b 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -55,10 +55,12 @@ #include #include #include +#include #include #include =20 #include "netdev-user.h" +#include "ethtool-user.h" #include =20 #define PAGE_SHIFT 12 @@ -231,10 +233,58 @@ static int reset_flow_steering(void) return 0; } =20 +static const char *tcp_data_split_str(int val) +{ + switch (val) { + case 0: + return "off"; + case 1: + return "auto"; + case 2: + return "on"; + default: + return "?"; + } +} + static int configure_headersplit(bool on) { - return run_command("sudo ethtool -G %s tcp-data-split %s >&2", ifname, - on ? "on" : "off"); + struct ethtool_rings_get_req *get_req; + struct ethtool_rings_get_rsp *get_rsp; + struct ethtool_rings_set_req *req; + struct ynl_error yerr; + struct ynl_sock *ys; + int ret; + + ys =3D ynl_sock_create(&ynl_ethtool_family, &yerr); + if (!ys) { + fprintf(stderr, "YNL: %s\n", yerr.msg); + return -1; + } + + req =3D ethtool_rings_set_req_alloc(); + ethtool_rings_set_req_set_header_dev_index(req, ifindex); + /* 0 - off, 1 - auto, 2 - on */ + ethtool_rings_set_req_set_tcp_data_split(req, on ? 2 : 0); + ret =3D ethtool_rings_set(ys, req); + if (ret < 0) + fprintf(stderr, "YNL failed: %s\n", ys->err.msg); + ethtool_rings_set_req_free(req); + + if (ret =3D=3D 0) { + get_req =3D ethtool_rings_get_req_alloc(); + ethtool_rings_get_req_set_header_dev_index(get_req, ifindex); + get_rsp =3D ethtool_rings_get(ys, get_req); + ethtool_rings_get_req_free(get_req); + if (get_rsp) + fprintf(stderr, "TCP header split: %s\n", + tcp_data_split_str(get_rsp->tcp_data_split)); + ethtool_rings_get_rsp_free(get_rsp); + } + + ynl_sock_destroy(ys); + + return ret; } =20 static int configure_rss(void) @@ -370,6 +420,9 @@ int do_server(struct memory_buffer *mem) if (reset_flow_steering()) error(1, 0, "Failed to reset flow steering\n"); =20 + if (configure_headersplit(1)) + error(1, 0, "Failed to enable TCP header split\n"); + /* Configure RSS to divert all traffic from our devmem queues */ if (configure_rss()) error(1, 0, "Failed to configure rss\n"); --=20 2.47.0 From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9AB21CF29B; Wed, 23 Oct 2024 15:44:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698256; cv=none; b=ZYHw70UHZtsWp8cESAzq4TQ8FS79+5KglPB9g9mZMLQ6M9Dj5Dqtxdgpo9QDZpR6DneLdsAs1EzjtF3Y+4ZTkb/JpnRim40QvMLuEvCSAQzEoXvXiBulOQ5J4TBHy2uvU8WKGlBlN6RViw35izpNChPfg4KOuDpZDVD7+Z+hOHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698256; c=relaxed/simple; bh=og3zr3saPqbWT0VxgUJgzCO724Ye3nF8hiqLbYRm8GU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kljNl++jV20AYlBxbW1qXisLNUJUuD+8ISpDVL/wVW85t1JRoW8qNknQ/Cawa4L6AKWcWiAbCRl1sW16V12g+lYikkL18XzptV9zPeccE26OwkvEI43tdOwklQQow+5vt8v6WJRZ/eI0hHb4UUXbHJT03w66eV7/h8y3rJve+WQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-20c9978a221so79248605ad.1; Wed, 23 Oct 2024 08:44:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698254; x=1730303054; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0+bp/FLvuQ/H/YT5HFz5uDgTntUpplmekx3z9WyNTng=; b=PotNYE0iIrpsv9bjxex0Ld9tmnaM3qEVPCQXoQEs9nzVc+TO+YlTQUh+nX3K6Menut uLvi6x5JPPoX/7OsO09MOaf8vTDRh6Jai5TG3p9cpa3z7kXE05pSB4penHI9+KpZMP7F hB/Gwi4wbGZyv53GbIlKJ6TmTTgUkluj2zlJG9v+3uyLVvheOGBfp3kgUB8jP4USnQDC qoz4JroHxDAr+VS/Q59LgarWmfsBfhcGl0ys7AkaWPkoqpjFCPlcHB52k3Jfint7ahXR QFxS8EVWEzk06tHnrpjIlgJv5oJz+GW24A8qOcBVo58dDQWbx/bXGDM5p8vfkBbu1XK8 cW7w== X-Forwarded-Encrypted: i=1; AJvYcCWRTSTfG5ic7jnZKUXCH7TPMFQk41RU1xowIvtIn0fwZ1me2ia71wyEXYOdO7xoDPE6sSzcl1eQNOv7a59sizZZ@vger.kernel.org, AJvYcCWp8W6zF84k6wxlOoUGfCXfTNzvD5EQPhelp7d/Qqfq/RULpw6vN2AceNb1V/Ati1pmOzgOIdokbm7nFoQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxG0z1NsTPLymMM4BVM4uAqa7TR4p3Nx5KmYtwg+K2GbvPiUBQQ cSOTUNOLGC1ZI8v5azMCGUMMPeNmKOmt7lrQ0eNQtWr0gumylGIjk7OSz40= X-Google-Smtp-Source: AGHT+IEZZfTmueaaco1d83ZsWoO2wNzZMdh/1WHP5mfohgQTgpDmlHwPVGqu0yQE6IyB3z0LUC0M/A== X-Received: by 2002:a17:902:ecc6:b0:20b:ab74:f567 with SMTP id d9443c01a7336-20fa9e7850amr42005405ad.27.1729698253715; Wed, 23 Oct 2024 08:44:13 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f104ac1sm59113725ad.299.2024.10.23.08.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:13 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 09/12] selftests: ncdevmem: Remove hard-coded queue numbers Date: Wed, 23 Oct 2024 08:43:59 -0700 Message-ID: <20241023154402.441510-10-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use single last queue of the device and probe it dynamically. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 40 ++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index e1faad46548b..fe4d81ef1ca5 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -75,8 +75,8 @@ static char *server_ip; static char *client_ip; static char *port; static size_t do_validation; -static int start_queue =3D 8; -static int num_queues =3D 8; +static int start_queue =3D -1; +static int num_queues =3D 1; static char *ifname; static unsigned int ifindex; static unsigned int dmabuf_id; @@ -208,6 +208,33 @@ void validate_buffer(void *line, size_t size) fprintf(stdout, "Validated buffer\n"); } =20 +static int rxq_num(int ifindex) +{ + struct ethtool_channels_get_req *req; + struct ethtool_channels_get_rsp *rsp; + struct ynl_error yerr; + struct ynl_sock *ys; + int num =3D -1; + + ys =3D ynl_sock_create(&ynl_ethtool_family, &yerr); + if (!ys) { + fprintf(stderr, "YNL: %s\n", yerr.msg); + return -1; + } + + req =3D ethtool_channels_get_req_alloc(); + ethtool_channels_get_req_set_header_dev_index(req, ifindex); + rsp =3D ethtool_channels_get(ys, req); + if (rsp) + num =3D rsp->rx_count + rsp->combined_count; + ethtool_channels_get_req_free(req); + ethtool_channels_get_rsp_free(rsp); + + ynl_sock_destroy(ys); + + return num; +} + #define run_command(cmd, ...) \ ({ \ char command[256]; \ @@ -702,6 +729,15 @@ int main(int argc, char *argv[]) =20 ifindex =3D if_nametoindex(ifname); =20 + if (start_queue < 0) { + start_queue =3D rxq_num(ifindex) - 1; + + if (start_queue < 0) + error(1, 0, "couldn't detect number of queues\n"); + + fprintf(stderr, "using queues %d..%d\n", start_queue, start_queue + num_= queues); + } + for (; optind < argc; optind++) fprintf(stderr, "extra arguments: %s\n", argv[optind]); =20 --=20 2.47.0 From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADBD41D0402; Wed, 23 Oct 2024 15:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698257; cv=none; b=n3VxMA8LiOSZQllOEqLANWEMuck/rVo0bCxyJ0az6AS1qQ02V03v/vqhU2fGNXJzvqF1yN6KQvZ7nFRP5+K3y9Ncqmsu2Dh68/RgtJCxBCxOGFTfb6aQcRPmibB6QJfeGgYeu1uSc+9c7McmzQWwUJCQdTFZLO7BWqM8LHgEQtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698257; c=relaxed/simple; bh=oFNEdZLPtcjUpbqtcRQsl/ELJcA51ONRPBDy5kQu3qk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rxn7BKgiHF4MwVfd+iepyz6R7s0omCn9Mfjh7iUR1GBZmpZwW7tILl3q/M5BJwaZQduwmqU0ulJG6HbcQWtuhJntHL3QIt8mSP1zhQsJjiJ1TRbH6IrczGAb7aGuquQ5CWpg41hPDs6Z0BcneDIz4mpdaxyDvgp0w9fqVgy9KEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20ca1b6a80aso67933725ad.2; Wed, 23 Oct 2024 08:44:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698255; x=1730303055; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MebxHJqXK6owyg4bREmStt7nVbsj68A52KHrJWNeIO4=; b=JyCzG2JVAIquTora9Oyg26q3YphwXlUCP2LzvpMiWAxRV4HzC4Fgs/bQCaPnwFn6F7 OXsRmD4rPgSMbRvpfeLDTqrklmox6kG/SFckzCROTnZNcrwkxFNHsLP3MLHZWL5kowJw 0yh0L/UxwCGyJ7GSXKSiTFoxM3DD2BFXfX9AI1mMFjzruOYYoMgpcsiwuGYUM9IX1bsq bNAKew/3oxaAWcWADlrid3in+704GaPf2QChOLjZDdwOyPcPJBG7po1EOvfYqIkBfyKa fp8+DOX4T3gguVK4wRTE7D+z8galjSCskxd06M5cTdkduXlgVAO7Zc4v3eoA0Zq3GY9Z jjMw== X-Forwarded-Encrypted: i=1; AJvYcCUs7sfP+CwDOCNl1udQ5ESCvwF8NgFFtE+uJapEiZkVgWbAS07tnUf4V61NVT6yLewMF0enCtoG5cd7HIU=@vger.kernel.org, AJvYcCVdYkAVSrruSRB8r/fRB78SA6pg8Fco0C5gjQla6m22k5kOtdURogUE4onCo1129Q8J/I9HbZqz55oFSMdLfqyB@vger.kernel.org X-Gm-Message-State: AOJu0YxdBIxsPmmhrcuE5+ohFoBjVs3icOY6qufgUfcLiUSEJLOn4UfE Tj1qIrCk9cX1tSQwpKEAbJx4/xuwvZmErPhr3XWJDE1RvyabzRFX+zHB2B4= X-Google-Smtp-Source: AGHT+IHCJjMRK8HlnNgTrAY8AO6pvtBwrS1bB+mfsFkekaUHQGKiPoBbTlLHknehrC536pJQ7kh26A== X-Received: by 2002:a17:902:d2cf:b0:20b:61ec:7d3c with SMTP id d9443c01a7336-20fab303739mr33614225ad.49.1729698254814; Wed, 23 Oct 2024 08:44:14 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0db968sm58648025ad.200.2024.10.23.08.44.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:14 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 10/12] selftests: ncdevmem: Run selftest when none of the -s or -c has been provided Date: Wed, 23 Oct 2024 08:44:00 -0700 Message-ID: <20241023154402.441510-11-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This will be used as a 'probe' mode in the selftest to check whether the device supports the devmem or not. Use hard-coded queue layout (two last queues) and prevent user from passing custom -q and/or -t. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 42 ++++++++++++++++++++------ 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index fe4d81ef1ca5..07a91516103a 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -76,7 +76,7 @@ static char *client_ip; static char *port; static size_t do_validation; static int start_queue =3D -1; -static int num_queues =3D 1; +static int num_queues =3D -1; static char *ifname; static unsigned int ifindex; static unsigned int dmabuf_id; @@ -718,19 +718,31 @@ int main(int argc, char *argv[]) } } =20 - if (!server_ip) - error(1, 0, "Missing -s argument\n"); - - if (!port) - error(1, 0, "Missing -p argument\n"); - if (!ifname) error(1, 0, "Missing -f argument\n"); =20 ifindex =3D if_nametoindex(ifname); =20 - if (start_queue < 0) { - start_queue =3D rxq_num(ifindex) - 1; + if (!server_ip && !client_ip) { + if (start_queue < 0 && num_queues < 0) { + num_queues =3D rxq_num(ifindex); + if (num_queues < 0) + error(1, 0, "couldn't detect number of queues\n"); + /* make sure can bind to multiple queues */ + start_queue =3D num_queues / 2; + num_queues /=3D 2; + } + + if (start_queue < 0 || num_queues < 0) + error(1, 0, "Both -t and -q are required\n"); + + run_devmem_tests(); + return 0; + } + + if (start_queue < 0 && num_queues < 0) { + num_queues =3D 1; + start_queue =3D rxq_num(ifindex) - num_queues; =20 if (start_queue < 0) error(1, 0, "couldn't detect number of queues\n"); @@ -741,7 +753,17 @@ int main(int argc, char *argv[]) for (; optind < argc; optind++) fprintf(stderr, "extra arguments: %s\n", argv[optind]); =20 - run_devmem_tests(); + if (start_queue < 0) + error(1, 0, "Missing -t argument\n"); + + if (num_queues < 0) + error(1, 0, "Missing -q argument\n"); + + if (!server_ip) + error(1, 0, "Missing -s argument\n"); + + if (!port) + error(1, 0, "Missing -p argument\n"); =20 mem =3D provider->alloc(getpagesize() * NUM_PAGES); ret =3D is_server ? do_server(mem) : 1; --=20 2.47.0 From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 047991D0799; Wed, 23 Oct 2024 15:44:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698258; cv=none; b=N7xrxsobiU6u0upsV5ZUhsA5p0kVwN4Uu/nMiaFG1uykhDji5qbZj4Tor7cdeV9zVp3UxUtIM37RRPDr0OEKc5e7M71hTgR0nVgKbVJkIKQo99wMCte4V9IxFjPKUyWeosyNL3AkdWjzB5QsmeQ2CHenvKJWWao83BfVltYhdJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698258; c=relaxed/simple; bh=QNIVoaUG6HoJ02+8aCHTzhZtbDvKJFEGC7k27W7G0/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q9pAOQqij2Bl6lbBAm13jEziLwj7i6zWBi/20JLexuMZUuDTSPHeHAr1xi8KCvSYQXs11nQIlu6gjqvMZOeztYMC1qUnccO4OMAfqzEP7WZTAIzbWwlITOfVCtLnsV5wRX50niPtsQR34GG8prFeW59yBAKPisRuG7yANOdFJJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-718e9c8bd83so779477b3a.1; Wed, 23 Oct 2024 08:44:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698256; x=1730303056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WLuAo808h43hPUqDZon7CMUoTgxLTq7GJOn3Y6RziyQ=; b=jgMTHa5gbSUl9OxBuAc62Q4nBsyk4AGrvjF8pK5EcE4pppmYyf03xybhhxtG3FoSHM KmSUW9rLrh3/lHjk3Xg6kzboCq3CJxQWu3mVIroTOhH1/7HF088bgX2LwpcBoa01W9mT XpKU6tuycOrzJFWgj7sVjXU6Y6Yu8A69EVKVD9dT5m9emP4yEb+csvEsXdxodiNLS0za aWX4c+CdgXOX0sJe/XnBPzEdA2nBcWA841tPyk7cAWSQtL61eIooQhi6G6TzDJYYcYU0 Tajs71AQGGM2stfb6UAuPTbwoECcHjhExflStRMvLv7LHtjfclxUNPWD0Xfx1aO9MP7w sr0w== X-Forwarded-Encrypted: i=1; AJvYcCWL3cW5cwSZfKYxAuCSm+jtjHwmakVPDOVFuMFNvPH7tyRmJNFT5Cp45TrlS73iA+NaUNhehceW8yo1kXXYnyHN@vger.kernel.org, AJvYcCXxj/iKuiQeT2sISzZx8E0tx22+su71jEULu1zWb0XB43Vnr/PIKFge2bgGemGY8vQWof4wkl86fcoZotw=@vger.kernel.org X-Gm-Message-State: AOJu0YyP2cm2R4Dpm34QWmzooapfz0Y1kiNeYfjD7GiWiDjtVYusGvdv U0WfB4rsPs6ahRWZftWMe4vOtqtfejHhEgfvklq/v/CC+8OkWlee9xlrnjA= X-Google-Smtp-Source: AGHT+IEOaI887BOI704vql0OLz3gq+9dRFk/uA2lyriK37cKHhq3KVNlDCQI2vpUYt6hR7vam91DcA== X-Received: by 2002:a05:6a00:1142:b0:71e:76dc:10f7 with SMTP id d2e1a72fcca58-72030f79cd7mr5038113b3a.4.1729698255965; Wed, 23 Oct 2024 08:44:15 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec1312d14sm6713485b3a.16.2024.10.23.08.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:15 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 11/12] selftests: ncdevmem: Move ncdevmem under drivers/net/hw Date: Wed, 23 Oct 2024 08:44:01 -0700 Message-ID: <20241023154402.441510-12-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is where all the tests that depend on the HW functionality live in and this is where the automated test is gonna be added in the next patch. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/drivers/net/hw/.gitignore | 1 + tools/testing/selftests/drivers/net/hw/Makefile | 8 ++++++++ .../testing/selftests/{net =3D> drivers/net/hw}/ncdevmem.c | 0 tools/testing/selftests/net/.gitignore | 1 - tools/testing/selftests/net/Makefile | 8 -------- 5 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 tools/testing/selftests/drivers/net/hw/.gitignore rename tools/testing/selftests/{net =3D> drivers/net/hw}/ncdevmem.c (100%) diff --git a/tools/testing/selftests/drivers/net/hw/.gitignore b/tools/test= ing/selftests/drivers/net/hw/.gitignore new file mode 100644 index 000000000000..e9fe6ede681a --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/.gitignore @@ -0,0 +1 @@ +ncdevmem diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testin= g/selftests/drivers/net/hw/Makefile index c9f2f48fc30f..182348f4bd40 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -26,4 +26,12 @@ TEST_INCLUDES :=3D \ ../../../net/forwarding/tc_common.sh \ # =20 +# YNL files, must be before "include ..lib.mk" +YNL_GEN_FILES :=3D ncdevmem +TEST_GEN_FILES +=3D $(YNL_GEN_FILES) + include ../../../lib.mk + +# YNL build +YNL_GENS :=3D ethtool netdev +include ../../../net/ynl.mk diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/drivers/net/hw/ncdevmem.c similarity index 100% rename from tools/testing/selftests/net/ncdevmem.c rename to tools/testing/selftests/drivers/net/hw/ncdevmem.c diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftes= ts/net/.gitignore index 217d8b7a7365..a78debbd1fe7 100644 --- a/tools/testing/selftests/net/.gitignore +++ b/tools/testing/selftests/net/.gitignore @@ -18,7 +18,6 @@ ipv6_flowlabel_mgr log.txt msg_oob msg_zerocopy -ncdevmem nettest psock_fanout psock_snd diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests= /net/Makefile index 759b1d2dc8b4..22a5d6a7c3f3 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -97,10 +97,6 @@ TEST_PROGS +=3D fq_band_pktlimit.sh TEST_PROGS +=3D vlan_hw_filter.sh TEST_PROGS +=3D bpf_offload.py =20 -# YNL files, must be before "include ..lib.mk" -YNL_GEN_FILES :=3D ncdevmem -TEST_GEN_FILES +=3D $(YNL_GEN_FILES) - TEST_FILES :=3D settings TEST_FILES +=3D in_netns.sh lib.sh net_helper.sh setup_loopback.sh setup_v= eth.sh =20 @@ -110,10 +106,6 @@ TEST_INCLUDES :=3D forwarding/lib.sh =20 include ../lib.mk =20 -# YNL build -YNL_GENS :=3D ethtool netdev -include ynl.mk - $(OUTPUT)/epoll_busy_poll: LDLIBS +=3D -lcap $(OUTPUT)/reuseport_bpf_numa: LDLIBS +=3D -lnuma $(OUTPUT)/tcp_mmap: LDLIBS +=3D -lpthread -lcrypto --=20 2.47.0 From nobody Mon Nov 25 22:22:16 2024 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4599F1CF29B; Wed, 23 Oct 2024 15:44:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698259; cv=none; b=m2XQldZQcbgUR89mMX6CuBh1/82OczMMqJjCANgP0n+6m3GMZQrhZjhFn3EFNVopJfBW2Xce8KjGkTICojurndMfrd5Th9739PSpRXAh3ntBz6imlP3vGaMSTtvnxIgpQSm5cRgcdJByeOXqr5bs6ND1RQ/vx1v7MA0RqKM3P9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729698259; c=relaxed/simple; bh=k3NksgKMGGwSiQjqqQDiIoWxu2o4MtjaGnPwO3kHGQE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R3r2u7aeQf61NhFf3dRv537Uj4Cq0oCcN7OgMswKvpIu4DfoXqVb0FjTX1ehPIv7MmJzgZsQTcrCg/LPiJONNuHlBm5JCBPBC4rcsBe5vxKqryalZtiZ0vshneaNACPN3MeVWDgRQCQFnidXYkiLaZdvjuuRT56nkfO1igZai9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-20c6f492d2dso81004595ad.0; Wed, 23 Oct 2024 08:44:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729698257; x=1730303057; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X3YqyV0YwGuilWF+8lpqEcTlB/FpyMoTdw0SNw6nZVo=; b=NDX9XE9CFSH16J/AwLJa6RmvNVaM3WuWVNaOYcO4t6n1rCioKBQin5NZwkNRmq3QUp 5Uhtns9r9HZJc+6l+Vte9dNjEgxn9tYqfQrGOKwgFZ5tePvL1Ff2l9Pe1VAdbJncvIIg XmcNjmMaH2ElqjIWM1Ma8iK8175xAtB93D/Xd2AJgaUASldymPLNyQhOcxR+Oe0J6jN8 YsY8B8RRpXhjvaxQDqrUc0ks+usdmhEpi6HRpmYrZjT4x4ZOZmEzAG8gVZEu0XAhSXdb EkIFdnDsi5dZiGOImRLHAQpIsEGeisp1P+56j0d6kfVPFbzgD0YRWBbgZ3/39JnS6NHH 1GbA== X-Forwarded-Encrypted: i=1; AJvYcCUm4S9CGv4fzPM/yCUF4FxO2xItvuaWOXNoQ+qUUcYOiKtDGUgCroIiL2LgSAh3nWOyG2mhs+Mmqq4JgELGHOGW@vger.kernel.org, AJvYcCVbOe21gStxYkEXzezx/NsCRRiN5oSJMZGB8nWscKJZmsy+vB6Gt/rPu0NPDsw2hIQ3xbrDhpfcGA014hs=@vger.kernel.org X-Gm-Message-State: AOJu0YyWXzXex5UBDx6b75IUHhwJhY5vyNPGMEOXgNmEMN8C/tlyZNKv nzgSoe3MvfkrE7wQ6MvHmgX7QUL0F1Ct/3j6N4Z8gseKoSPHPVIhP1KVsT0= X-Google-Smtp-Source: AGHT+IG5tIKpYeuEz6ZLsiWpOGSrUCthd3VQ2flnhUoELbeYmk26pijtnqS/JXJt/3edd7064c+NAA== X-Received: by 2002:a17:902:ce86:b0:20b:58f2:e1a0 with SMTP id d9443c01a7336-20fa9e246e0mr30293045ad.18.1729698257223; Wed, 23 Oct 2024 08:44:17 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0bcb75sm59576405ad.176.2024.10.23.08.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:44:16 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v5 12/12] selftests: ncdevmem: Add automated test Date: Wed, 23 Oct 2024 08:44:02 -0700 Message-ID: <20241023154402.441510-13-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023154402.441510-1-sdf@fomichev.me> References: <20241023154402.441510-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Only RX side for now and small message to test the setup. In the future, we can extend it to TX side and to testing both sides with a couple of megs of data. make \ -C tools/testing/selftests \ TARGETS=3D"drivers/hw/net" \ install INSTALL_PATH=3D~/tmp/ksft scp ~/tmp/ksft ${HOST}: scp ~/tmp/ksft ${PEER}: cfg+=3D"NETIF=3D${DEV}\n" cfg+=3D"LOCAL_V6=3D${HOST_IP}\n" cfg+=3D"REMOTE_V6=3D${PEER_IP}\n" cfg+=3D"REMOTE_TYPE=3Dssh\n" cfg+=3D"REMOTE_ARGS=3Droot@${PEER}\n" echo -e "$cfg" | ssh root@${HOST} "cat > ksft/drivers/net/net.config" ssh root@${HOST} "cd ksft && ./run_kselftest.sh -t drivers/net:devmem.py" Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- .../testing/selftests/drivers/net/hw/Makefile | 1 + .../selftests/drivers/net/hw/devmem.py | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/hw/devmem.py diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testin= g/selftests/drivers/net/hw/Makefile index 182348f4bd40..1c6a77480923 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -3,6 +3,7 @@ TEST_PROGS =3D \ csum.py \ devlink_port_split.py \ + devmem.py \ ethtool.sh \ ethtool_extended_state.sh \ ethtool_mm.sh \ diff --git a/tools/testing/selftests/drivers/net/hw/devmem.py b/tools/testi= ng/selftests/drivers/net/hw/devmem.py new file mode 100755 index 000000000000..1416c31ff81e --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/devmem.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +from lib.py import ksft_run, ksft_exit +from lib.py import ksft_eq, KsftSkipEx +from lib.py import NetDrvEpEnv +from lib.py import bkg, cmd, rand_port, wait_port_listen +from lib.py import ksft_disruptive + + +def require_devmem(cfg): + if not hasattr(cfg, "_devmem_probed"): + port =3D rand_port() + probe_command =3D f"./ncdevmem -f {cfg.ifname}" + cfg._devmem_supported =3D cmd(probe_command, fail=3DFalse, shell= =3DTrue).ret =3D=3D 0 + cfg._devmem_probed =3D True + + if not cfg._devmem_supported: + raise KsftSkipEx("Test requires devmem support") + + +@ksft_disruptive +def check_rx(cfg) -> None: + cfg.require_v6() + require_devmem(cfg) + + port =3D rand_port() + listen_cmd =3D f"./ncdevmem -l -f {cfg.ifname} -s {cfg.v6} -p {port}" + + with bkg(listen_cmd) as nc: + wait_port_listen(port) + cmd(f"echo -e \"hello\\nworld\"| nc {cfg.v6} {port}", host=3Dcfg.r= emote, shell=3DTrue) + + ksft_eq(nc.stdout.strip(), "hello\nworld") + + +def main() -> None: + with NetDrvEpEnv(__file__) as cfg: + ksft_run([check_rx], + args=3D(cfg, )) + ksft_exit() + + +if __name__ =3D=3D "__main__": + main() --=20 2.47.0