From nobody Sun Nov 24 14:37:58 2024 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 723931CACDE; Mon, 4 Nov 2024 18:14:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744075; cv=none; b=aFUjxpELGhzgm1qz5IDR388wnpgfARHRunCZYWCveuuSJ9+qB3GRiI4hxhDW/XOphjGblwaRPI9X05YZTIoIW91R81B5xKSd78sFIxJkGYVl/Bm7T8slI20nAIqUkdtEM+T+ReKycsCpPvvlb+gJJe0KsIA9nHQ7zVTG3kkbwPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744075; c=relaxed/simple; bh=DbSfoMlzpZVhU+8FFsUY3AHTX/zbUMYdVXfjpyEzHfU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LTFcb05crRLy92cc4t49GeM1F+2i/5fddl86dI2TIxRagNgyPYPXt6vTRFRmlUM7RAX4WqVdnVMUXqjbeCvI1+7NX0GYBzwJmJstPuQJGzfzShk+ucOSxqwe3quWyn+TGmLAVofe9Zd8QqmgISsgMqLMViI2xYu5jxI+HO6nsOA= 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.177 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-f177.google.com with SMTP id d9443c01a7336-20c9978a221so46386495ad.1; Mon, 04 Nov 2024 10:14:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744072; x=1731348872; 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=oVgp0Y95/ShZ1Vt+t38PjMD6xGGvRHTRaS5Zo1sHbqCqCyfWlH2mJYNf2nz7QIM94t YH66XjAQTlvr5cW8HTClwTiBdtnnyoCfi3GpTQ+h3k6Kt1oJUPyp6jyhaP1h8iNewxfo i14gZRYFjRn3EScwG7b5FBBwOy7k6HDqILuxtN65kUmyjltgz6Q0uDn+4mUYvSf/8FlM aAoT9TDmaN0S1RFn7SA+iKMJQ/OWCyy4VSXRipX0z66FJQG7T7V8lrexdJWMC+5s0XS/ SQiteLH/R6U7oQLEODFl7TXiXK3TtvAXXn2gztknQixpjYzwVHSKJBuk8k5v/q0gOg3W OsLA== X-Forwarded-Encrypted: i=1; AJvYcCVr65QvozzzWmRIYinic6jKN2mJLP9t7SVb9gdYbkYWYFG7NaRxqCfIHoDZQxdHm86ASCMDj2tho9fYLrg=@vger.kernel.org, AJvYcCWVTySELstQzev7JN+Fj1AxUTyb2SOL1pW8KXMKP9WzhmyLOVYHIAfnXiz7QhsKzlJEa1CZ0Fu+hJRgWV4M6e/8@vger.kernel.org X-Gm-Message-State: AOJu0YzyXFsbtsUCfc9ojk4Gd5zLn9ingt3X2hAMLzcEa3G00CamSbXN UZhtG/hHi/Kcm5MotPfCDLMY/Ex9gegtR1XBYHLbNqKiX02rGD5wl/Yt X-Google-Smtp-Source: AGHT+IH5Hx5+8+j+5liP9xAPcP7HashQcWijPfR76kZPLAH59RNeYTmm2b1V3DjWdot+Rfx3zZjMIA== X-Received: by 2002:a17:902:dad1:b0:20c:ecc9:c50b with SMTP id d9443c01a7336-210c6c6e9bamr435809395ad.42.1730744072446; Mon, 04 Nov 2024 10:14:32 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057d8d4dsm63222975ad.270.2024.11.04.10.14.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:32 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 01/12] selftests: ncdevmem: Redirect all non-payload output to stderr Date: Mon, 4 Nov 2024 10:14:19 -0800 Message-ID: <20241104181430.228682-2-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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 Reviewed-by: Joe Damato --- 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 Sun Nov 24 14:37:58 2024 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.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 164491CBE85; Mon, 4 Nov 2024 18:14:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744076; cv=none; b=m7tXmZoOuMLJ9gnnXlVbe82pVGJ89NNb84rVH4H//zyncfda6pYi75qf0087P4CDi8F2sCnNJ4nV06xx7jervzCDxQKozZXG53j6KuZnwgKvz+j3uYXFHVS50h5Y2u5vLUNJsuXE5SKKPcV6oEdeHiZjJ7i+6YeG98LquRjH5CY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744076; c=relaxed/simple; bh=6SOqd5ang15aObvyf3Fy0XcXsj2Q7Cf1mPOUGeSoWSo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XWfIe+UXWFThxXFMaggjr6PEJFQiHiFwXx6LHbmjayy1lb2K7VHnjiZgqGAOaAbL2fL5WGp+LBNpBLLwdIpgS7giAJ9FlSuUdhAXF8LYYuay6KZsPdce/lsObING7npn4MztWukSTKluSbLDo7vzL93MyczEss0o5fZBL81Eno8= 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.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-pf1-f172.google.com with SMTP id d2e1a72fcca58-71e4c2e36daso3558785b3a.0; Mon, 04 Nov 2024 10:14:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744074; x=1731348874; 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=bEuQvf/RcvTcHpPd2XswcRl8oLleAdL4B8h7BSvpz40=; b=kQVKAzIJH61obXCr58F9OwL1KK3MVn38WZyFxKm2imS7PVCrks/eeA0QAQaIpudLjr vjuwr6qvhaSc4KJZIyfXn+ClG9WbHLl9GBy7B0G0pCt+pYhiFGd7lcuZBW4mpHP7Ifbz a78LgCmVTmlIC/8YfePf0mWK6p59ZN5xtO5riVcx1nrLTptIt4PtlUqCEMqN8iWjU8M4 s6NRj2swYLnTZ4pajkfeXfAa7KKd73qF2Rbayj5E+vNRtRK44XCpO0eDGbjlW92VriHP f0kgFJhXSzVUUnpA73mUwYMid+ryXxdbnGMcKyPCCwENB0u9Bdb3SV+yKEQRpMfDFwov R0Bg== X-Forwarded-Encrypted: i=1; AJvYcCVajtTQrEO7ojQZaItBJsInNVBYPMlzFtOPEedJW5FIr+fWw5sYxto/eDpThEeMchQfzt/yTpwhhXmuBTCxEikl@vger.kernel.org, AJvYcCWP3arIo7SMPt6UIppn7ru6ci8rQjVJb6wRUdL2OechHOu3m7i+9DmyETnIHn82jDQ0Lx1gGyRQf2HrPQU=@vger.kernel.org X-Gm-Message-State: AOJu0YxwaU6TnvePgTnwWXK5yUQZ4IzUzHSZeQid1k3H99ubfw0Eahgo tXiLbNV7tC17EZ+MDCMb4YOuPOeJcZFmI7W8hWwFs18p77y5y39f5O4K X-Google-Smtp-Source: AGHT+IHP6dvpRcTiJ1qceYF8Zp3nQjzSdcK2hZf1cCWt/rmdikgNkwIH2BHFMeCoFxDSiGwxvTeBnw== X-Received: by 2002:a05:6a00:2290:b0:71e:66e6:ca17 with SMTP id d2e1a72fcca58-720c97f35c3mr24918411b3a.9.1730744073957; Mon, 04 Nov 2024 10:14:33 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1b8cb9sm8127825b3a.11.2024.11.04.10.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:33 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 02/12] selftests: ncdevmem: Separate out dmabuf provider Date: Mon, 4 Nov 2024 10:14:20 -0800 Message-ID: <20241104181430.228682-3-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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 Reviewed-by: Joe Damato --- tools/testing/selftests/net/ncdevmem.c | 203 +++++++++++++++---------- 1 file changed, 119 insertions(+), 84 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index 9245d3f158dd..3e7ef2eedd60 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,16 @@ 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) + - dmabuf_cmsg->frag_offset, - dmabuf_cmsg->frag_size); + validate_buffer(tmp_mem, + 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 +486,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 +497,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 +512,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 +525,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 +538,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 +547,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 +596,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 Sun Nov 24 14:37:58 2024 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 545AF1CB9E5; Mon, 4 Nov 2024 18:14:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744077; cv=none; b=EtKPM12E3O6BXXY3afJb2wju0WEWIf9CwSwZtnclubNep9kzt+GfEpTu73769uM/WL6df+E6USJF/v1rPcQhve5DQuJd22QQifpzdVMgLPsJDTMTbKFwYzrE7uuulOYUrzq7G6bMYe31MbQUnQP2YLbih+v5mSj0uZMQcXvS7+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744077; c=relaxed/simple; bh=OUr7UbIXtV5F/r5JGVxieSj3s2Uf+l56sMqWfLXByW4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OxQPRnvIctyLqRsiOrY4PNUq1UTYgAJdqzZ1ABu+bIJrV+Yb1Vv458YKKotMJK8RB4HGAOiUotqaIZnSkvB0TSJ63Ki9bF9j1guzTuTvqr0xqoouQk50/iLeOCQMZX1eNmJhTlWF8pYtN+7tENrPJ6H/bVqa23C7jkzQrI1izQA= 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.174 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-f174.google.com with SMTP id 41be03b00d2f7-7ee4c57b037so2810708a12.0; Mon, 04 Nov 2024 10:14:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744075; x=1731348875; 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=/3/Gw3ir+FV9hqmx4cbabiMNpLz/qP2wnn0S+2scwDo=; b=Ol3yuFv8GSeN/J8BwDh4oVSktpFhbfr99VBrjUnCzhfaNaPmC46qHqvlkzD1fde9Yl VnsI8XfkymcZXSrdk9r4oT5vyMT4AIsYPqOXeerpKAOpfZF731kSrnlmrk3puzkbsBZ5 fL4lRkb6w9cA0qotDepYgdMmbIEmD/PhEdfAJnPPrIdB7/vMgdNIIPJqqhZi4SeXhzXo CDQSTOBBazl5zgvIMm/mjEjYmlPz47P/F0kSu+yof8tn6U4pV8eQUtb/CygoMgjZhh7E sX4KDaO5v+G2fkiJT/+NmxLQia29+pUeu1cbHCdjj5w01T4mExB9vakuWu8algat734g swpA== X-Forwarded-Encrypted: i=1; AJvYcCUOhLIsUBw8+9EhdwTn0946m5HJ+doe7DQRzGnVGO8HEDGqTSUusamKjbOm4NCg+6+LXcD5md2jXZ6wTik=@vger.kernel.org, AJvYcCXSPfxyXY9Yo6zu2UN0MrA4MW3U3FwwNxLyDJdFlr+IBS6MIAhyZaWz4x1AwjrDhms+keILX/PHMpZI7LuZx2yr@vger.kernel.org X-Gm-Message-State: AOJu0YypgwJWKOIbVArzeYrcTeIRtlC7WA/0rNkOQ+xGPwb7rKw1TbgT +3d/gtqcsIj1BYjMwhLYWy3AuGAO3/UPLxZZD6Wr4cwmVKb0gDzxeTuS X-Google-Smtp-Source: AGHT+IFKz78OOOgmoJsZEYNL1ytho71uwEre0CcD7w+r/UaD7HBnhbqlYYmFZapW71b1taVJc4Lp7g== X-Received: by 2002:a05:6a20:8403:b0:1db:eb76:578d with SMTP id adf61e73a8af0-1dbeb765792mr1955530637.36.1730744075395; Mon, 04 Nov 2024 10:14:35 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720c6a39a53sm7354819b3a.178.2024.11.04.10.14.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:34 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 03/12] selftests: ncdevmem: Unify error handling Date: Mon, 4 Nov 2024 10:14:21 -0800 Message-ID: <20241104181430.228682-4-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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 Reviewed-by: Joe Damato --- 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 3e7ef2eedd60..4733d1a0aab5 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, errno, "%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 Sun Nov 24 14:37:58 2024 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 AC11D1CEAA2; Mon, 4 Nov 2024 18:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744079; cv=none; b=Jfo7VjXUIOETEtbbLyVRpQax/RQb/M6QKnymAUCdQkDY/8UipXGOq0XEWPKNPUZBJ4Va3atJq8R/ql9oxVUCRHs9nRfTF5jdXw931/KelsMbic6PLYNusz8dAvbKkUBO2cc1KSFz3UmwWbijI4HYyUdhwozlJwiMGpgJnshVSdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744079; c=relaxed/simple; bh=y5Y1WWPur0r7GUqVUucgWo9PNwZ1yB0cWjEIlX6ocu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r53PWyQjLR1QjnJkkmW1PQWGEHIpGytN/RZMmoWx4QHuvu4YgYxTL/u4KlOAsf1mhZ0lFZJXB+3WSl8K8pIhd0CDN3YHfMqDA/+/Fy3ou/V2x9PJFMesqDobd80g/dgDrlc5dHAcKz0b9nGVpvYXub6XbiBekVSU3pnt5JVTFa4= 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.45 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-f45.google.com with SMTP id 98e67ed59e1d1-2e5a0177531so3462965a91.2; Mon, 04 Nov 2024 10:14:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744077; x=1731348877; 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=6mqBFKOzCX+vYAYq1/XbPV8gP7Inl10PB2v9tAVaqmw=; b=B9pDt48azVYL6Ti21vvH/wNeGAocA0ozYxRzPLm0D+AlXNDpiTCptVNHliOnIbTtPE yO/mgppYmTpiuctZ4mue+FVAUshI/O6i2SziQYO80zi9Zh6PP1d34r0fbpgFQgAOl6pf vK1SBjpNkGhm1gNAD+FxZb/fm6y3Lzu27qwVkf9TV2ioq+V5Vg56Rj/Hf9YnDUTSRo5d +cYtUM/g/Q1M+sZ3RoNCEi1L6SHy+C5aHoqSjnM9gjveV0UX9pg4rj/0X6bDyZcW9CYI zi2Zo+uaosBsx4C6Or6YHRlwkAoz0xTyojA2B1GFYk5S0kZq+ARwwMWQ0lKKimRBPoRe 8/DQ== X-Forwarded-Encrypted: i=1; AJvYcCUmeIc7mNSbVjVsh8EVBPYvfkGs6Dlg+TFI7b1HqJPfrTpDMbSh9VbEXFulnjB40b8uMBaaJBSKHJFpUafobw7p@vger.kernel.org, AJvYcCXxG3Hv/01OVvnr/qh95LGGlPyYkHeiLo2HA1daNl0NraTWQMoDbHmCZcPVHAuFom7RUW2PAGH9hQT1+EQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzlFvzC5K6NjHlpFHpBshITtIQzvf7UroAGAxx64G5cyX+kyv1w wpItXZFRsiw3qFN1wW0yki8nfsn/C/Tmlf1hmLCyezqhNwiCQc1sdfWA X-Google-Smtp-Source: AGHT+IEpk5nkugWF502idtRX5Eo3MlRaWyLuyVGEduIL7g2hVEE7g4EM874/N7+3WXOb+JkNBc3K5w== X-Received: by 2002:a17:90b:180d:b0:2e2:b204:90c5 with SMTP id 98e67ed59e1d1-2e8f11dced0mr38459320a91.33.1730744076703; Mon, 04 Nov 2024 10:14:36 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e93da98480sm7985357a91.7.2024.11.04.10.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:36 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 04/12] selftests: ncdevmem: Make client_ip optional Date: Mon, 4 Nov 2024 10:14:22 -0800 Message-ID: <20241104181430.228682-5-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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 Reviewed-by: Joe Damato --- 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 4733d1a0aab5..faa9dce121c7 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 Sun Nov 24 14:37:58 2024 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 48F471CB9EE; Mon, 4 Nov 2024 18:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744080; cv=none; b=dXWZz2lf5ZDSdoLROq9T0R6EM22PGvsAuTziBQZVrbVChaDzmyz90S3s3mSPruC7H/cxDvj7dsxZI2rN63jqDHzwYIv2LOlsRsWpZ1IBtJkoC7oc7xXZh4wV/dzJkW6Ez18H6FUu4Mlum1WdgGaEpq865hazqnvlUgSqbiGRpuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744080; c=relaxed/simple; bh=X1AHO5hh0Cz7YoXze/wBSjee7SVCwrbQ9TGTRkfLAkU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=neN0JG/iXd1PWUiMn/v3yf6feoS2vNjFB0RIojtmMV9gXnbgJ3R1DX/oEqi4TCx1wXaq+PM4TIXSajCdaEI7Xg19XjsigRxxMc/KoBvPxHCmar/rkUjyoSRiBSQU0F0qn5DOxzeX94naE7VyDjyRfYH2Q07Xa1F+adtExXJfoj4= 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.169 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-f169.google.com with SMTP id d9443c01a7336-20cf6eea3c0so35692365ad.0; Mon, 04 Nov 2024 10:14:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744078; x=1731348878; 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=a/Lvchejx+wbbnnPWqy0g/pNEGTgnXT8sEPSjXOpiZQ=; b=tJx+5EUKYodPoRpHnjjCE+5VjaVPxTa2sT61ihmdO3CyBFBJqGj3T8KiVivJTXAohT UyvK3J4GBLGwHyTKWdY82OyblDERGyIk5RDNPnQOze1Tv8pIyOhOCRBH6MjMaDsAGlAF 8x8TzKqbGHISOVqknzk4XM0HNPgJmJ5C1MXPMIrETYD4eSPq9mQxTHv26tfhjFoMKXeX YYMbTmq56wSnrmeXo8plef9OBwXTO5nsDU6m40/ygROdlpwX5UubILP0d4aXHjgtlw7G yfr5O3nTgyqEcbWiP9fvz3djN9LrCekG2SlGngtp+IRn1xhaWPMxAp+QwiHctKG7mP9E Lhwg== X-Forwarded-Encrypted: i=1; AJvYcCV+1bdHJ/2xvF1AhkcyfyQcKgj+Z7caXqEk9qsWDG68KIN4VIF2FhpjFVjDluDDl3g+bHcUDyzKb818N4c=@vger.kernel.org, AJvYcCX5uf8v6VamiP//aO+R6E8JzYXiCPOCy4aZ97fYR0HexKmiKAsht4/cu3kFz40vubs9N2X8qkueMzHVeGaKymwE@vger.kernel.org X-Gm-Message-State: AOJu0YzVPrGOoVhSic7FwDFcsr/x81MQuqEj2/irT3CcRsECT9U/JjC2 6nBWprsVove40mHL9NJ4y5ZBhHqX0/D3vrLSqCImvO7vSjstiYn1j1GQ X-Google-Smtp-Source: AGHT+IFQaG/M01w4kzS54ClH+YX+wiP0NG7/rEz4zqdriaevmeGp8BSqvEw9+wSQ/yN05763UJsFFg== X-Received: by 2002:a17:903:2a90:b0:20c:e8df:2516 with SMTP id d9443c01a7336-210c6c344admr411401635ad.42.1730744078012; Mon, 04 Nov 2024 10:14:38 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057bffffsm64244045ad.188.2024.11.04.10.14.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:37 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 05/12] selftests: ncdevmem: Remove default arguments Date: Mon, 4 Nov 2024 10:14:23 -0800 Message-ID: <20241104181430.228682-6-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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 Reviewed-by: Joe Damato --- 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 faa9dce121c7..0feeca56c049 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 @@ -595,6 +603,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 Sun Nov 24 14:37:58 2024 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 57EAA1D094B; Mon, 4 Nov 2024 18:14:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744081; cv=none; b=EdDhG5me7GFAe+Sj8iBawsFHiVcIn0BgM7Hd/JmAZHqF9XZDXuL0/VxbrlQfnYsftzq2Abg4SXLoUdBTIv5tFr53Q+eH5OAElzifJpTW78EX+yMxgbItmc8CFFJPITwoVLCnc0daSj1uvP7n50/F+IRUslXJlLRwzyeo08wyRo0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744081; c=relaxed/simple; bh=b0Dkv5Sy5ji+/9wdnjShe98xD6WGhX0x1ggGrQrv4Qs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MroVZiuzrGzQrIrvvSQs6L30TXGhErfUfgDmPTqdMTSJjUacgXV8asPRaS2jrhRADdHJqTBvbOXHtOQX3ORF6pMpei42sFIRbAchEe/sLhTH0kOZGu6MNgEEnOgAZJ5SZTNLN+IcysGmsQwxYhgGEhIF3fGcMNRj4G2pPSlgl8w= 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.178 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-f178.google.com with SMTP id d2e1a72fcca58-71e467c3996so3847363b3a.2; Mon, 04 Nov 2024 10:14:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744079; x=1731348879; 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=8X35Ea0gz6V3qdg4j5NOe8UKNtP5acIZlBezrrhgypI=; b=MqbLcwR00g96DXRceNAt6HLx+PdCGihW9i5fI63mn5RKBCXXTLPwZlVDtbjYlpYmzJ /q8f2ijJG9/xoPD+UuuOqLF1bjhupuuVnBH3+kFXpAc6N4q5pkeM3GZoC6juvi+/Dwsh nlq+uA/I47+2ukjMiY9UsS7GJ/0bPlKMzl0xhfguZ/ZJyxxcvvV/ha8/N8UfiPKIp/UZ ym4iWyZWc/kFaoc5Zq8x+QS4VuAb3wLk/kF5favRIamA5UKq7U78iw62jb5XhtgRhPvd NfCLUIRTlzDlCp2pF7t47joI6S4lRw+MXaeRUOpTYtd5x1rQqFFEgyfw+pXz4tUVqJ7i aEEw== X-Forwarded-Encrypted: i=1; AJvYcCX8QKOPZzcfbb0Pq/rup6jb59ijdO0qKUtEElq0qhjFEyesAGqvgqIXnKJQ6W7qi9EgaIeL4SCYxfy9iJPqZNBI@vger.kernel.org, AJvYcCXN+0pSPcIHSe7MQNFVKLCdQeA8Z/0hiSDxo4E7ul73SYAPiQu9cipz0Z42Qklzf8nNWQdLRAowmOdX4No=@vger.kernel.org X-Gm-Message-State: AOJu0YwIEL7mXtMhHw1Q9Hkb3zLs6EQS5hE0IH2gzLy5RXY7UT36ntNa 8YMg0eptWL/8RsB1sJqo2k2y2VwcIarLK34qLHFwG5y0nLVzE+kdCxsY X-Google-Smtp-Source: AGHT+IEWUiEq0a5bX1B33Rpzfhsz7vTOsBQVWJU64wJHkE+NBxwcLgeybNC9yB973pZ9nFMHpZWjxQ== X-Received: by 2002:a05:6a00:3d0d:b0:71d:ee1b:c851 with SMTP id d2e1a72fcca58-72062f13bd9mr47350527b3a.7.1730744079429; Mon, 04 Nov 2024 10:14:39 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1b8971sm8114424b3a.12.2024.11.04.10.14.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:38 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 06/12] selftests: ncdevmem: Switch to AF_INET6 Date: Mon, 4 Nov 2024 10:14:24 -0800 Message-ID: <20241104181430.228682-7-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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 Reviewed-by: Joe Damato --- tools/testing/selftests/net/ncdevmem.c | 99 ++++++++++++++++++-------- 1 file changed, 71 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftes= ts/net/ncdevmem.c index 0feeca56c049..c4897b2bdc7c 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -242,13 +242,26 @@ 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 *type =3D "tcp6"; + const char *server_addr; + char buf[256]; + + inet_ntop(AF_INET6, &server_sin->sin6_addr, buf, sizeof(buf)); + server_addr =3D buf; + + if (IN6_IS_ADDR_V4MAPPED(&server_sin->sin6_addr)) { + type =3D "tcp4"; + server_addr =3D strrchr(server_addr, ':') + 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 +312,53 @@ 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 !=3D 1) { + /* fallback to plain IPv4 */ + ret =3D inet_pton(AF_INET, str, &sin6->sin6_addr.s6_addr32[3]); + if (ret !=3D 1) + return -1; + + /* add ::ffff prefix */ + sin6->sin6_addr.s6_addr32[0] =3D 0; + sin6->sin6_addr.s6_addr32[1] =3D 0; + sin6->sin6_addr.s6_addr16[4] =3D 0; + sin6->sin6_addr.s6_addr16[5] =3D 0xffff; + } + + 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 +370,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 +384,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 +405,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, errno, "%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 +426,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 Sun Nov 24 14:37:58 2024 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 DC9931D12E6; Mon, 4 Nov 2024 18:14:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744083; cv=none; b=n0njrZrmKFHUeQSM9Q/y48r4Zws+hsPdh7MvRr80JOWPTnPNEYwREnyN+WQ4EqK89V44NGGmQha0g+Y9m4Zn4P2sq9uTCMrsoMWucnr7ZN9cTFzrKYdI6okQ8uL0ksUeNe6DdkqZptcgiZuxnK4RMqNxUZClEvtrr1WNXjjKUQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744083; c=relaxed/simple; bh=t4oQZFMur9cxBRlJZS0+COIzhW6jkWYV4QpeYt2kroU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AwvzS5O5NJ15RFXtmWKj04zEuVv2cadXHXB7izVl3d6snY7YiqarydjFfaGt7sZphOlekhMwlSzteSQz/vCB3XE2lZAAy26VuXGZzL/ICSO5fueQv6v6PFzY3tTnpbrDAIDP3akWDOpZOgJtbCpsoJcbl2g6ByV8hdBdbam3Xig= 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.174 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-f174.google.com with SMTP id d2e1a72fcca58-71e5a62031aso3675308b3a.1; Mon, 04 Nov 2024 10:14:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744081; x=1731348881; 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=cZ1Tvv0gMz3ty3u2/2A4hNdfs43uiaMnj09QJfrx3rc=; b=Xqp1rY7CxdZSOtbupRsuoeiIgvnNTMIwy5HDU//ByqSqx5vXKyEh8LYRtzS8EMjACp QSYFMr25e1FCG2FGDN+scq1voTG5eX/iKcHrtmR9G0dvAhNIlfVGtnbEq1BqDXp0tMuh dQgIvzMbbC2lfUiOjH8n2BeMMaIJB7fTfh+td4gnl/sLFBjIgCtnsd098k9xOeg/leXM KCaHaKgu2BFpLWVQIWx9W0ITbRF4qHguGeMgacs+041qz1m0Ba96uFaT95HNbJyaXKSa 6v/yWgI9kLVxYw+RMozNAGXGl4a0wZ8gA9iQV7vCKma7umwDO+l8SI7F/Qye09VgWv/W Rf9w== X-Forwarded-Encrypted: i=1; AJvYcCWSxg51pJZgGdXg8qsvsZui1yh2bv72OrKV+GwxyWOf0dIW7lILhmXYIfUfms8wDycAg/BwYbVkjrpskQk=@vger.kernel.org, AJvYcCXOvY+F5yN2S2advxvEupTKqhAHXlpgSFeQgiHXwTtiHXjl7+oAyfTScELX0iCmdMfxmXnehihTmrJUZSoYQN/O@vger.kernel.org X-Gm-Message-State: AOJu0Yxa+yRlm6ofmQhJ0Ar7dcr6JsNz0qh0aTlAVZYnQbiA+mGmQyPd 37Mk34o5sKZ+gXTz5+/6/iXuGFvUuwWYJQuNde+4UJ6dQ5SPD2/sxwjE X-Google-Smtp-Source: AGHT+IF/BD2lQwztMAI1ojDceoAS38rYjiPu8o9NbmTwOVFc4a3eYhaRCVDtH5kTKDANMtgJuJRNgQ== X-Received: by 2002:a05:6a21:6da0:b0:1db:eb2f:e281 with SMTP id adf61e73a8af0-1dbeb2fe2aamr2308494637.26.1730744080885; Mon, 04 Nov 2024 10:14:40 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72119bca1ccsm3616749b3a.128.2024.11.04.10.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:40 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 07/12] selftests: ncdevmem: Properly reset flow steering Date: Mon, 4 Nov 2024 10:14:25 -0800 Message-ID: <20241104181430.228682-8-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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 Reviewed-by: Joe Damato --- 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 c4897b2bdc7c..8062d26fbce0 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 Sun Nov 24 14:37:58 2024 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.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 2E6CE1D1E62; Mon, 4 Nov 2024 18:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744084; cv=none; b=Y8B7JVzLIeCUcWht4Wy0VjHoOqwfR9N0vdKOZvy6TXuycZvgpdbd+aupful6ZeLf+rC6vS/4pQGr1Fp1znXJAbHUCc5zwI/zA7hOtb8+SEty35CYHYCLSY9a7/AywcIb2pHt3wrhOlCW2sGMKk5bt5DMiYgC9H2D/YDNUMThFCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744084; c=relaxed/simple; bh=HEprPoq1IsIYeEgDwCpbe2AY4uFkB21Ly4ySJ8h1NCY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e+Wk2xslaIrvX6QyIE4AnJxTD8ZOh3GW7ODtQ5ZvncpTliCx7QDhlrQhzUMOL3SDGsK16R8Af3zIVxfQQZh3zVLuAMJOUEH0wb52Ln7NW3zi4HtA10X+sG/SHO2uhgVkK80eHVDGZMrfs+1/m/CE5uTiFYumzsn4ig75UKIbwFg= 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.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-pl1-f175.google.com with SMTP id d9443c01a7336-2110a622d76so34836685ad.3; Mon, 04 Nov 2024 10:14:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744082; x=1731348882; 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=chkH/KYtOTBy5j86yWDDP7t68zN26H3k4mJ3Ip1/oJs=; b=GdeDoAE1JgYWPZuQShNj1/hyfdv0ZZwSN80vkrLXXFPKu8n0TQEeRdEtj14SwOaB+D Rd5nyQ25cuXB6nWVXJxvGgjOgN/yNWLr/UTXrl3qqATwfNHzxV5kxwg/nGsQ4tzaJWy6 9NFrSWVzbtybzdtLYGH86SXf6CO38DYZatI3rAPhJeCSkNFIlMpyqZWRbV+sethv26+G pUVnH6g9z6eKcoj4QQdGKUznLg5eCAjjEOtF/jlJElu4qKtb1o3WSuFYd0rG0qHt8580 5c17JcYyvoCt8piof0/v4eSiSN/vZeclAg7+qWBn3J7tuhhjxCNlTxgExFehXrqmlelL fmZw== X-Forwarded-Encrypted: i=1; AJvYcCVQIecC4a04O3ii9X2ttNqodBcOw2Py04+ozxr78rw0Fnozp/KuNQ2ZQfmR4uUWdn3TYwRf81zgrySIXhZ88ZWn@vger.kernel.org, AJvYcCWAKPrpdfJdJqRTc4WzfDay88BNGlQgRVb6n1wpIlJRpsKRkwiBg5bxO5QXXc5we0BFq4aFKxTbN0jMnmM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4nmBAu9/oSanfSCv1RH/nGR+bATUqvLRF+plDrwAQJrW9HTAx GT5sQkbEYaGqstoZxuO6kYndl0ZyO7UPj/JMaPyqcctkAh2wDlKxtqcx X-Google-Smtp-Source: AGHT+IHdQdolv7+0xRZNxaMUgWAhLbTcH1r9wF6jgKwiSN9SY5f5W6UdX70Ee6I3trFcRz+lTvw0SA== X-Received: by 2002:a17:902:e5c3:b0:20c:95d9:25e6 with SMTP id d9443c01a7336-210c6c1b09fmr391058865ad.34.1730744082225; Mon, 04 Nov 2024 10:14:42 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2110570815bsm64278255ad.91.2024.11.04.10.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:41 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 08/12] selftests: ncdevmem: Use YNL to enable TCP header split Date: Mon, 4 Nov 2024 10:14:26 -0800 Message-ID: <20241104181430.228682-9-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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 Reviewed-by: Joe Damato --- 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 8062d26fbce0..be89735d6408 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) @@ -384,6 +434,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 Sun Nov 24 14:37:58 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 5C13A1D220A; Mon, 4 Nov 2024 18:14:44 +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=1730744085; cv=none; b=pw0+GXWwx58bm5iU34WrIXDlddD0eSu31opeUNRrgX+EA2jmbn11NsNzEkywjr2dy2rcZwJK/wmxNKnINNMv92KFhSnn4uAu/6Qc9aRgqPf5zUSKWwNf1IA6z1Z71jtNzOKmQQB+3XuiIOCBurdRaZ7SSu1HUpl+YSpwhQLrbBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744085; c=relaxed/simple; bh=FqwkzCj7Oo52GxQLIk8kMLxdTIgLdXiAl0FYGpgOpus=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lorYBFqSQcYQPkVyObN9V6g21E5OjvKfRUoMXvTNu5MUgn/6ESpHEQz/iAo4HbL+8rR+73Xzx/FnA0vBOS4JBUEFVdR+xpYdtnAOLKxyoLFtqlTNmSf898ecpW3SB6/EN41fQfB+EbfgrVY25LveZ06hl71EvJZhZISoQV4nyFY= 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-20c8b557f91so47074095ad.2; Mon, 04 Nov 2024 10:14:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744083; x=1731348883; 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=3RnouCHbo4rVx9xUzcrJNSVrtgq+CHRpQxygse3lkA4=; b=X3IyPKzz18Stgs/jvNlpqK3jiFFTdwDQ7IdAxxnx4PogTkRkj5XU90xbgKr5DX5keI 70QHH4Xlhg83xpCa812/1sTQh1rkaEJOXaDorHHhT9weIM9n7GAPugXgkfoREWW0fbwY PyNL37GMEoGyZyMDsByFQ/D29tC/jG7lHQQPNdJ5/H+w5hIXLRIDf0ogRvZENMTCpEeh RJ/D+UukFX5eNBStsgCWVXy7fvsF/bxRrJT3Di13n8ix7tG5aAwG3I0lfRUKt6v9sw6L G3gw78MLUPO4enhWK00MxEAE5ADZigAKNlPY8+8WD5a6Qbk7nhhmzxP5wp2R55fT/ZAR lYUw== X-Forwarded-Encrypted: i=1; AJvYcCVKqLX42cJFVO1ayz5F3oimRD+1SO8u/gteZhBg29rYStBdIZJoznEAqxVHg946CRnCYvSjqoWRe/kkThGcdsEl@vger.kernel.org, AJvYcCXSZMmqW/A8/+ebgHkw93gW2jqKPolbFw0saMx38riOT6HInnOwnPQjgLc2rTrYhGOknMXl1C7EcCbS5z0=@vger.kernel.org X-Gm-Message-State: AOJu0YyE4Hqf3YTCkfeQ9oimwKNAlrBRawwhE9h5fqKfaaaXmQWBsop6 IE38cyPXVmrB73olUQrMDPodQPnt50h3bcUqU90K3pHGJ8LlFCs+WvE7 X-Google-Smtp-Source: AGHT+IGMC893+Lvb6crgpz4p6LiMvJ7O/KeQMwbIVHwkPZcqfdXD+XpOSYq1oFrlenHMcofTVGqm+w== X-Received: by 2002:a17:902:f642:b0:210:e6d7:765 with SMTP id d9443c01a7336-210e6d70d99mr370068705ad.59.1730744083459; Mon, 04 Nov 2024 10:14:43 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211056edc1asm64371995ad.57.2024.11.04.10.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:42 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 09/12] selftests: ncdevmem: Remove hard-coded queue numbers Date: Mon, 4 Nov 2024 10:14:27 -0800 Message-ID: <20241104181430.228682-10-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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 Reviewed-by: Joe Damato --- 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 be89735d6408..044198ce02a7 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]; \ @@ -715,6 +742,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 Sun Nov 24 14:37:58 2024 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 B76BF1D2794; Mon, 4 Nov 2024 18:14:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744087; cv=none; b=s9y+3HCFCGGIj3DzzJXnCeffGSS1RAnct8j9ig9iUE1X+w4NIVls09kN9VmBqNO90T+0Y5tDrQ+wunNwvTx/x9eEfStgotIHlHKcuMs0QQGS5b22csb5+fb4NBLrl/rZKMyVUB562IeOdcZfca92JISb5ZUcSvB2UuaUAFuReHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744087; c=relaxed/simple; bh=72/R5PRQI9Otl/290uawNtrS6k8D/kufkgNBz6vJx4M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mFDNBu16wD9E1tB4yOSyOXmYmKxQS4xA7ANjRO8zK6cixmmpbzoFTIucpHG84bWA89tNFzJrvRfNJrTEUaFn3Kt4ztEyVfkHJqajU0vA3Cp13Nh/b71UOsUm0SwSIaTk46/Xn7h798nQYMTclmGIEfuF+11+3ybuJr5ojdeF4Wk= 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.41 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-f41.google.com with SMTP id 98e67ed59e1d1-2e2e6a1042dso3474127a91.2; Mon, 04 Nov 2024 10:14:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744085; x=1731348885; 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=DIs8ZvYHkw439c9Xv7PNSglUccQFPekABSAEtzHkHdY=; b=FABmU0sVVgTuNKj93LYQg5IrJgJPxpOorc+iUy2a5Q5f5To54/dTC/nvmmi7iDEJVF TKbzUYE/HgHC455LvNeuVZRCrVpxVX3aox6ocCZ3CN/e4LDWy/JfozVQ58Zx5vdEBR4c UMrW/CN1O5LmLiKr4EBaOwrS1vJAqueQfgfmuKaFYfIT1vknu0I0or2anX3WybSJB9+h H1sdI64ZETQPgJPb3I+dgk14ZEq6soT3C2TEQN/9zeqakR/KqurbYkeLsr+t1Yqjdmyl zhPpLkHavay3MkNhk3BmVMC1D7HSxccHEPOsr9irD85lWPNiH60B6pHKoOhY3aeyhQSQ jZDw== X-Forwarded-Encrypted: i=1; AJvYcCWurQQZ+6t5pU42EHlITfFtj/dQI12gXGa0KXRYOESm3QHdTCKAujhdjYM2N6jYavt3f9qLVVCoNJIFrZc=@vger.kernel.org, AJvYcCXBDcZjRostvy/3cL8VjKrOMExXDfjsHchVrGuc3nNm/a+LVxvyxvuf9b+r0dBLYWI0+zcxlaBQ7hYnZAN7H2Zp@vger.kernel.org X-Gm-Message-State: AOJu0YyL0IIqlhxM9LSZqe+j7vH7to1tNmkilvvtblj/llSaqttQh1Ft lztpUt6zKRXDukgMwSmUMSzwPDvKOmQIUaTIKy8atTv2qOpIJsQGZlRE X-Google-Smtp-Source: AGHT+IEkWoxmsVyVZ/bNCB9eIkdQQXPdol0Opi11VQOloRfjI7YmM5QjNMwMRiIYHYNGKRP2Q1KSgQ== X-Received: by 2002:a17:90b:2e4d:b0:2e5:e269:1b5a with SMTP id 98e67ed59e1d1-2e94c54a67emr16333096a91.41.1730744084894; Mon, 04 Nov 2024 10:14:44 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e92fbdfaeasm10107273a91.38.2024.11.04.10.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:44 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 10/12] selftests: ncdevmem: Run selftest when none of the -s or -c has been provided Date: Mon, 4 Nov 2024 10:14:28 -0800 Message-ID: <20241104181430.228682-11-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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 044198ce02a7..270a77206f65 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; @@ -731,19 +731,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"); @@ -754,7 +766,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 Sun Nov 24 14:37:58 2024 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.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 217DF1D2F46; Mon, 4 Nov 2024 18:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744088; cv=none; b=OwL5ag2aE1r6oH1iXICr2xgSW2mxKFvyuABuGTe7/f2u5mA+FiG+4DzqRZn23uSKnE0OUIoGr0yzBsGrKIdrgWq1u4heJR4/JzuxUojJTC7n0g+LlOxmeR+FSUj20dxM4ERbSgUZfW8y16xANcYVXtevTYpdd/RWiSe8bL5062A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744088; c=relaxed/simple; bh=QNIVoaUG6HoJ02+8aCHTzhZtbDvKJFEGC7k27W7G0/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NKwA8nWgpvps6gu7KChu1NduMB0mlhTUjWBTAPAZcGUhpP+bpXDw3IVPaPrZVgPN3XuIfGA5FizM020Ito/hFx7LuNQvxsbxy/HcPSviZQjPxxo7g09VlkqkCQEopJGUzwarksNSnxsR0HNw97if0QyUpcqdgpXONcWtXz/Bnhw= 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.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-pg1-f172.google.com with SMTP id 41be03b00d2f7-7f3da2c2cb5so906952a12.2; Mon, 04 Nov 2024 10:14:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744086; x=1731348886; 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=V7BUVwRCzrwoOUGuTr5iwj8TcOcBQuQ3hsS7eCzADNBxJ6bA0L7Lu2sAhquxhZo7dZ op8VE+ljfFunw/9DmqRBEail3/rR+8dbXhyk+4ExyG/Y00U5o2ZqHWtgyFHB1uxeo4no nd9ZmgmnnLJQdbaWcyr6SoRW5JLsrDrqFJnRYP7MFsY8potVbvcqEXuJLeV8ZhIcEC/y Tnsx2vXb4sNkWPgpE/bnvgh27ksazn6vav/IeZf13qObWLS2o/jvoWdoUhGBr1iLRZT1 aPN595EoSnTBpOethLgi4GHgHBDotQJBObsH8pxa8U4Q7z+s6x7eBE71qxOKq3UY3/7/ T1sg== X-Forwarded-Encrypted: i=1; AJvYcCU86a1WO4smjiqezl/1h6cA/dmMDThOjnsaHtSQAPC4LkjxTzKr1oN81+LwL1NGEfowqQXjEJTDwhQpMwn8Al60@vger.kernel.org, AJvYcCUoZ7JfBjb89XITL/qs/V6uIJtydVE6Drj2uE3veVsisMMleC6ZjMV5OREyuWpI5EP27VHeMCZOuCsGlCg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9U6aWhrl1Cr53DVpPvrXelXZPuo92PAe+hbZHBXC07UmAV+S9 TggFu5aj0CpI2xUrsqXOiGIGt9A8VRySPME4tOKPLE/UEFBCgVya3YUV X-Google-Smtp-Source: AGHT+IEoedDGOdcqJ0GvHtkAY26FM1JkHU82vYr/QOukdj6TBBejk+u81f/Qv1oikEz6Oh85UzH0zQ== X-Received: by 2002:a17:90b:4c8d:b0:2e2:af53:9326 with SMTP id 98e67ed59e1d1-2e8f11b895dmr39147007a91.30.1730744086189; Mon, 04 Nov 2024 10:14:46 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e92fbe114esm10116505a91.35.2024.11.04.10.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:45 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 11/12] selftests: ncdevmem: Move ncdevmem under drivers/net/hw Date: Mon, 4 Nov 2024 10:14:29 -0800 Message-ID: <20241104181430.228682-12-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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 Sun Nov 24 14:37:58 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 971E41D31BA; Mon, 4 Nov 2024 18:14:48 +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=1730744090; cv=none; b=R97wWpWzGuDULFj8aN6cEnROhhZN5YthxatQZe2TnxdDadUjHxI/NVhUoFUCWdQq4VPYGnK0FwUMDkDJR7YGJtg9XLK7RAQeZz8Vcrt5zkKnPWlqchcOGnNNWcMZQg5T4YZjlGCsEnpuSLlLzaXlZ+BQ4VBlLqrzfywOCzUxkqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730744090; c=relaxed/simple; bh=k3NksgKMGGwSiQjqqQDiIoWxu2o4MtjaGnPwO3kHGQE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bw3zLy/pvjABjkBQRbZc4wDH761VKXs8DaBFYV+Y2LiTkrcKpzq1NndtjM7ADd+0tkBLaI/X8MsH4Vev/kqaE1yYvmgm5mOpJ+p4iaTpMeoa3kKTyY2uAw55HjMm8JExW5yTUA9eoN5npw2Q2h+n8EgdygpOeEB/V61HYCwRg94= 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-20c6f492d2dso49026135ad.0; Mon, 04 Nov 2024 10:14:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730744087; x=1731348887; 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=Ei90Kslb4CMMLK3D8Lx50bHEMHWfOpXCLWRWtYSOO/B04GmGFDPusEf+UXDEiqWhSk KvYhhFImxVVln2munoB8hNWLlGvWvVrDLLn4YSYPozU8l/Hn5bVe6bu5kv8tW+gmtX/i ygxkB2kVgkUlo+Brc3I/1cH7BK8NzNET0QNgqFpPOli/H7UBqiSX9tHWhFrkQLH8qeVs wDjfppT7f1eikadchVlD68/5S+U2rNchV61STT5OttTGtR6PJVsmfYazX5qqzDmS0ICT 14NspBHl6mf4EZwC5HqTRzMTxiTkP30xhiHUmYG7241GsrAnDRSNF4Q1Ik2Y2gSxJ+1H QN5g== X-Forwarded-Encrypted: i=1; AJvYcCXIe/KJNT5UEkSZ1x8p1/iV32HrxV/bjQM7yRVOAuiRay0ZFnYi2Mjwi6AyIVj2WhZYxmuEj/keRc8fiV8=@vger.kernel.org, AJvYcCXKvQYW94GqmMObBvCtGWfgCEOWCbyYYc2Pl6FBFgq++d9oFzrtfI4CzDohFfBnbbBNk0k+RpfgZIT+PAK4tyuv@vger.kernel.org X-Gm-Message-State: AOJu0YxlOYO9HuihxpASZaEzYQgE2A+dAylFsnS0MpBOz2jTqbkQRVmd LYrZVC2HxEcyqzt02chm+vTwJJ6zxpjQ+Bwkthy1kjMQuw14qRDd4Wyu X-Google-Smtp-Source: AGHT+IHRCEF9Wme8C0aZgb892OYe/X4v+cIm86yN2WycRf+lICWUp822HUIdb27Af1bRxlCqJd5o1g== X-Received: by 2002:a17:903:2cd:b0:207:6fd:57d5 with SMTP id d9443c01a7336-2111af38936mr160079935ad.36.1730744087533; Mon, 04 Nov 2024 10:14:47 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057086e5sm63678585ad.75.2024.11.04.10.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 10:14:47 -0800 (PST) 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, horms@kernel.org, almasrymina@google.com, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v7 12/12] selftests: ncdevmem: Add automated test Date: Mon, 4 Nov 2024 10:14:30 -0800 Message-ID: <20241104181430.228682-13-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104181430.228682-1-sdf@fomichev.me> References: <20241104181430.228682-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