From patchwork Thu Nov 7 18:12:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841853 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 6CED5216A32; Thu, 7 Nov 2024 18:12:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003137; cv=none; b=pzHSlJMMzLmjQGOUoRfnRZwqov6UdYgH6PWBFiL7z/ymg+CJv5yR/wz4tRqA0Z5Sm/BGa3tk1c+NwaJ/B1j2tP3y+p1G8JAnhvia/Ou5wdx9bhYbh/ZqVhvk4mUlQ+Fkij+rAIyiM0GrkVLaY1MtbDmH8uiPV3DapkxQ+5dtOfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003137; c=relaxed/simple; bh=dpRMcCluWvSuwyCrQOQuaW7bCjf75tmXApIEtfIMCeY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bhteaE06RabNV7cBRo5O1bx+PJDwNqWM1nLY7O/jGTaWbG1yvDC27DAxfD+tN69QSktVb0ExNPaVuozR+wC/SAi+tZNQp+JOOpDcFKO2qvKgNx+/ezLJGYfCgYLC3ggYbLLlYYo30SUgN5b8RRAksbMRzlQGF0HPMSiKnuDqxck= 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.51 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-f51.google.com with SMTP id 98e67ed59e1d1-2e59746062fso1029926a91.2; Thu, 07 Nov 2024 10:12:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003134; x=1731607934; 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=PhAREs1aRYj4toqDy2GP71NzwoQ/NE/KsGfvfZjEouc=; b=YCoLt4c/+d7KtynaDE86Kl11fUbFMk794IxEeSAgDtIH383e/pZkieqXG52sF49rVm 2i1Tiuonh9ppkS/No9Xxr743YmPXeZSm5iJGnpbGRnijso6hMSsjeP0sfz6wp6OgM8hi B8rXeVanlM55UoYs6X2mSX4G7p2qp76BvNBMxJ0wZQE6t9B7IcWUh933pBP2E0qMQMc8 QmHe2d1c2U1TvHkf2YWRcnCbbjISnMn1W5t+11+pKLeubbWQYJDGN9zLg5c6mK/r+udA W6cKl0CetBv1wKZuxln7tkoGRNr2Bw6/g0cjAo476H82P6qee0q7Z9X/WWH2uM7I/UOm h2xQ== X-Forwarded-Encrypted: i=1; AJvYcCWC/ES4rObNA/jNUk2p8Uu2vGRXrR+XP3akZCDG+xjpe+DqRmvwhuO4y9VVpFc6o6iKu+aXG3u7bhGDzH1VsRyU@vger.kernel.org, AJvYcCWzES0TRvc67SxEW0ZMaF1qTQBMgnMGMCO96/Nacrdt6kKDjlC/vhy4YnVdP/b4g8/j+7xJV4Ip+O4SydQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yznq7n0hpVKyaDcBxX/IriK9/TDfjff5/ogJ6ubuZx0g4sGUBSZ 2qZUR8FfAxWTRJOjve2B8ZJrFa3QdEGjL3Wjr0WgJkqhTCqbTOmH028X X-Google-Smtp-Source: AGHT+IEAQoJdUoOaXfagn/7uxF7O5PQ0bPEYgt4XRWFhyu1DnrccaYk1y6z2+BhD5c7IASp7Rl8j2Q== X-Received: by 2002:a17:90b:1807:b0:2e2:cd79:ec06 with SMTP id 98e67ed59e1d1-2e9b16955c6mr175950a91.10.1731003134223; Thu, 07 Nov 2024 10:12:14 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e99a62bd09sm3813779a91.46.2024.11.07.10.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:13 -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, jdamato@fastly.com Subject: [PATCH net-next v8 01/12] selftests: ncdevmem: Redirect all non-payload output to stderr Date: Thu, 7 Nov 2024 10:12:00 -0800 Message-ID: <20241107181211.3934153-2-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 That should make it possible to do expected payload validation on the caller side. Reviewed-by: Mina Almasry Reviewed-by: Joe Damato 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/selftests/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) for (i = 0; i < size; i++) putchar(p[i]); - printf("\n"); } 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); \ }) @@ -128,22 +127,22 @@ static int reset_flow_steering(void) { int ret = 0; - ret = run_command("sudo ethtool -K %s ntuple off", ifname); + ret = run_command("sudo ethtool -K %s ntuple off >&2", ifname); if (ret) return ret; - return run_command("sudo ethtool -K %s ntuple on", ifname); + return run_command("sudo ethtool -K %s ntuple on >&2", ifname); } 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"); } 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); } static int configure_channels(unsigned int rx, unsigned int tx) @@ -153,7 +152,7 @@ static int configure_channels(unsigned int rx, unsigned int tx) 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); } @@ -187,7 +186,7 @@ static int bind_rx_queue(unsigned int ifindex, unsigned int dmabuf_fd, goto err_close; } - printf("got dmabuf id=%d\n", rsp->id); + fprintf(stderr, "got dmabuf id=%d\n", rsp->id); dmabuf_id = rsp->id; 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); - 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)); ret = bind(socket_fd, &server_sin, sizeof(server_sin)); if (ret) @@ -329,14 +328,14 @@ int do_server(void) 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 = accept(socket_fd, &client_addr, &client_addr_len); 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)); while (1) { struct iovec iov = { .iov_base = iobuf, @@ -349,14 +348,13 @@ int do_server(void) ssize_t ret; is_devmem = false; - printf("\n\n"); msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = ctrl_data; msg.msg_controllen = sizeof(ctrl_data); ret = recvmsg(client_fd, &msg, MSG_SOCK_DEVMEM); - printf("recvmsg ret=%ld\n", ret); + fprintf(stderr, "recvmsg ret=%ld\n", ret); if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) continue; if (ret < 0) { @@ -364,7 +362,7 @@ int do_server(void) continue; } if (ret == 0) { - printf("client exited\n"); + fprintf(stderr, "client exited\n"); goto cleanup; } @@ -373,7 +371,7 @@ int do_server(void) if (cm->cmsg_level != SOL_SOCKET || (cm->cmsg_type != SCM_DEVMEM_DMABUF && cm->cmsg_type != SCM_DEVMEM_LINEAR)) { - fprintf(stdout, "skipping non-devmem cmsg\n"); + fprintf(stderr, "skipping non-devmem cmsg\n"); continue; } @@ -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=%u\n", dmabuf_cmsg->frag_size); @@ -395,12 +393,13 @@ int do_server(void) token.token_count = 1; total_received += dmabuf_cmsg->frag_size; - printf("received frag_page=%llu, in_page_offset=%llu, frag_offset=%llu, frag_size=%u, token=%u, total_received=%lu, dmabuf_id=%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=%llu, in_page_offset=%llu, frag_offset=%llu, frag_size=%u, token=%u, total_received=%lu, dmabuf_id=%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); if (dmabuf_cmsg->dmabuf_id != dmabuf_id) error(1, 0, @@ -438,15 +437,15 @@ int do_server(void) if (!is_devmem) error(1, 0, "flow steering error\n"); - printf("total_received=%lu\n", total_received); + fprintf(stderr, "total_received=%lu\n", total_received); } - fprintf(stdout, "%s: ok\n", TEST_PREFIX); + fprintf(stderr, "%s: ok\n", TEST_PREFIX); - fprintf(stdout, "page_aligned_frags=%lu, non_page_aligned_frags=%lu\n", + fprintf(stderr, "page_aligned_frags=%lu, non_page_aligned_frags=%lu\n", page_aligned_frags, non_page_aligned_frags); - fprintf(stdout, "page_aligned_frags=%lu, non_page_aligned_frags=%lu\n", + fprintf(stderr, "page_aligned_frags=%lu, non_page_aligned_frags=%lu\n", page_aligned_frags, non_page_aligned_frags); cleanup: @@ -551,7 +550,7 @@ int main(int argc, char *argv[]) ifname = 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 = if_nametoindex(ifname); for (; optind < argc; optind++) - printf("extra arguments: %s\n", argv[optind]); + fprintf(stderr, "extra arguments: %s\n", argv[optind]); run_devmem_tests(); From patchwork Thu Nov 7 18:12:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841570 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 8D3B0216A38; Thu, 7 Nov 2024 18:12:16 +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=1731003138; cv=none; b=BF3ZBFp79hZehWwgpOSb5J2mrvPkFFsoDNcYBfBvV/RNOK3Wo8sPiwXSH/7ALq56KoWQQTC9Zc9/imrzubBSZOf+pBQ0wA4MgeMpliAGhkbsflIz+txcIyrLx28Uy8QKwAntl5209WffdETpiohtH3TRkk4wqfiYo3hvcTbLuko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003138; c=relaxed/simple; bh=FBpO1dsdYOB6WYOdbq//gyXGFxJKiCGP5Tb3Vv4T4co=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ir8T12kBFnYMdjvdVWG9Ts1Tn76DTn10RCXvoHs+QgfOh/hWIxYBhDgY+lt6RjUKRE63MXgtRt1/LstjdOuMbwka9oyGyrSEbA1/+fqS54oJYrvxh95sBme1VU+RShKtXYO7Xft7v0cxG5/iERj4/ec2MzU1poMo0+DwPEuEYgo= 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-71e79f73aaeso968994b3a.3; Thu, 07 Nov 2024 10:12:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003136; x=1731607936; 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=MToGSWGRNwhdqbbNBFCpFCusQtsGd9R5bipRLaud6aU=; b=KXKrUxmmV+M/7hCyHbMckLf25w5gmy7Zl9CDyC/23lfkomCmIy8DuxX9klouWu7mNx IpjDK+7w12PFjB1ZuBtGufnZ8VXsu8+5nLjW1x40zE58J24QFCeG8TicEyJY2AAbTEua VGsQUg4YdR2dCxRy821hz1XGXDzuNv3QnRpzV6dzVMNCpJzDG9gW6Ruj6T5bx3iECCpk RvRNdV44epvPmAW4BvFFn9SutRDECCFdnzgH2qcVNPRYrcvlA2mkcxtiyR0BfDllo6jy Dh63eNRKVaAHua15zleVQM+jrRTzqInDRBvNyg3hUBCMMq0UTYkOoBKzc2SQLV/Luyic KVJg== X-Forwarded-Encrypted: i=1; AJvYcCWJUdp+X9JmqF0cuYlj5jSlX3VXY7ZGkEhCEMpPv9uKWHlmEIkiaGAlUY9bCNgNbwqWU/qSRfYzxmb6spA=@vger.kernel.org, AJvYcCXfVeFEKj1ei8RBcoiXGxLP/m48FA16zPXFuOaqdGsru5GU9UHE4r8I+R8kAsOIP/TicpOR93l9Vw15ZXa8P/0l@vger.kernel.org X-Gm-Message-State: AOJu0YzD+kcYAcxzKRMd6PQaEADfATSU2a7v5eFqolamXcmAUueh6BOE urYK2hWXSmvq3Yokv5I9v+Wd1sGCjbpBDLJScDhfAhGpYTbMqLFcoI0+ X-Google-Smtp-Source: AGHT+IE3WV9Au0mI2tSF0JDsUb5jtqGjJwfENeCwgaoZO99pr1xX+kDogmcfaZEa7K+XAUGCoCcg1w== X-Received: by 2002:a05:6a00:140f:b0:71e:7c92:a192 with SMTP id d2e1a72fcca58-724129c5463mr343244b3a.24.1731003135513; Thu, 07 Nov 2024 10:12:15 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72407a1a800sm1883976b3a.164.2024.11.07.10.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:15 -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, jdamato@fastly.com Subject: [PATCH net-next v8 02/12] selftests: ncdevmem: Separate out dmabuf provider Date: Thu, 7 Nov 2024 10:12:01 -0800 Message-ID: <20241107181211.3934153-3-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 So we can plug the other ones in the future if needed. Reviewed-by: Mina Almasry Reviewed-by: Joe Damato Signed-off-by: Stanislav Fomichev --- 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/selftests/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 = "eth1"; static unsigned int ifindex; static unsigned int dmabuf_id; -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 = ptr; - int i; + struct udmabuf_create create; + struct memory_buffer *ctx; + int ret; - for (i = 0; i < size; i++) - printf("%02hhX ", p[i]); - printf("\n"); + ctx = malloc(sizeof(*ctx)); + if (!ctx) + error(1, ENOMEM, "malloc failed"); + + ctx->size = size; + + ctx->devfd = 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 = memfd_create("udmabuf-test", MFD_ALLOW_SEALING); + if (ctx->memfd < 0) + error(1, errno, "%s: [skip,no-memfd]\n", TEST_PREFIX); + + ret = fcntl(ctx->memfd, F_ADD_SEALS, F_SEAL_SHRINK); + if (ret < 0) + error(1, errno, "%s: [skip,fcntl-add-seals]\n", TEST_PREFIX); + + ret = ftruncate(ctx->memfd, size); + if (ret == -1) + error(1, errno, "%s: [FAIL,memfd-truncate]\n", TEST_PREFIX); + + memset(&create, 0, sizeof(create)); + + create.memfd = ctx->memfd; + create.offset = 0; + create.size = size; + ctx->fd = ioctl(ctx->devfd, UDMABUF_CREATE, &create); + if (ctx->fd < 0) + error(1, errno, "%s: [FAIL, create udmabuf]\n", TEST_PREFIX); + + ctx->buf_mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, + ctx->fd, 0); + if (ctx->buf_mem == 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); } -void print_nonzero_bytes(void *ptr, size_t size) +static void udmabuf_memcpy_from_device(void *dst, struct memory_buffer *src, + size_t off, int n) +{ + struct dma_buf_sync sync = {}; + + sync.flags = DMA_BUF_SYNC_START; + ioctl(src->fd, DMA_BUF_IOCTL_SYNC, &sync); + + memcpy(dst, src->buf_mem + off, n); + + sync.flags = DMA_BUF_SYNC_END; + ioctl(src->fd, DMA_BUF_IOCTL_SYNC, &sync); +} + +static struct memory_provider udmabuf_memory_provider = { + .alloc = udmabuf_alloc, + .free = udmabuf_free, + .memcpy_from_device = udmabuf_memcpy_from_device, +}; + +static struct memory_provider *provider = &udmabuf_memory_provider; + +static void print_nonzero_bytes(void *ptr, size_t size) { unsigned char *p = ptr; unsigned int i; @@ -201,42 +285,7 @@ static int bind_rx_queue(unsigned int ifindex, unsigned int dmabuf_fd, return -1; } -static void create_udmabuf(int *devfd, int *memfd, int *buf, size_t dmabuf_size) -{ - struct udmabuf_create create; - int ret; - - *devfd = 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 = memfd_create("udmabuf-test", MFD_ALLOW_SEALING); - if (*memfd < 0) - error(70, 0, "%s: [skip,no-memfd]\n", TEST_PREFIX); - - /* Required for udmabuf */ - ret = fcntl(*memfd, F_ADD_SEALS, F_SEAL_SHRINK); - if (ret < 0) - error(73, 0, "%s: [skip,fcntl-add-seals]\n", TEST_PREFIX); - - ret = ftruncate(*memfd, dmabuf_size); - if (ret == -1) - error(74, 0, "%s: [FAIL,memfd-truncate]\n", TEST_PREFIX); - - memset(&create, 0, sizeof(create)); - - create.memfd = *memfd; - create.offset = 0; - create.size = dmabuf_size; - *buf = 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 = 0; - int devfd, memfd, buf, ret; size_t total_received = 0; socklen_t client_addr_len; bool is_devmem = false; - char *buf_mem = NULL; + char *tmp_mem = NULL; struct ynl_sock *ys; - size_t dmabuf_size; char iobuf[819200]; char buffer[256]; int socket_fd; int client_fd; size_t i = 0; int opt = 1; - - dmabuf_size = getpagesize() * NUM_PAGES; - - create_udmabuf(&devfd, &memfd, &buf, dmabuf_size); + int ret; if (reset_flow_steering()) error(1, 0, "Failed to reset flow steering\n"); @@ -284,13 +328,12 @@ int do_server(void) queues[i].id = start_queue + i; } - 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"); - buf_mem = mmap(NULL, dmabuf_size, PROT_READ | PROT_WRITE, MAP_SHARED, - buf, 0); - if (buf_mem == MAP_FAILED) - error(1, 0, "mmap()"); + tmp_mem = malloc(mem->size); + if (!tmp_mem) + error(1, ENOMEM, "malloc failed"); server_sin.sin_family = AF_INET; server_sin.sin_port = htons(atoi(port)); @@ -341,7 +384,6 @@ int do_server(void) struct iovec iov = { .iov_base = iobuf, .iov_len = sizeof(iobuf) }; struct dmabuf_cmsg *dmabuf_cmsg = NULL; - struct dma_buf_sync sync = { 0 }; struct cmsghdr *cm = NULL; struct msghdr msg = { 0 }; struct dmabuf_token token; @@ -410,22 +452,16 @@ int do_server(void) else page_aligned_frags++; - sync.flags = 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); 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 = DMA_BUF_SYNC_READ | DMA_BUF_SYNC_END; - ioctl(buf, DMA_BUF_IOCTL_SYNC, &sync); + print_nonzero_bytes(tmp_mem, + dmabuf_cmsg->frag_size); ret = setsockopt(client_fd, SOL_SOCKET, SO_DEVMEM_DONTNEED, &token, @@ -450,12 +486,9 @@ int do_server(void) cleanup: - munmap(buf_mem, dmabuf_size); + free(tmp_mem); close(client_fd); close(socket_fd); - close(buf); - close(memfd); - close(devfd); ynl_sock_destroy(ys); 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 = 0; - dmabuf_size = getpagesize() * NUM_PAGES; - - create_udmabuf(&devfd, &memfd, &buf, dmabuf_size); + mem = provider->alloc(getpagesize() * NUM_PAGES); /* 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"); - 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"); for (i = 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"); - 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"); if (configure_headersplit(1)) @@ -508,7 +538,7 @@ void run_devmem_tests(void) queues[i].id = start_queue + i; } - 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"); /* Deactivating a bound queue should not be legal */ @@ -517,11 +547,15 @@ void run_devmem_tests(void) /* Closing the netlink socket does an implicit unbind */ ynl_sock_destroy(ys); + + provider->free(mem); } int main(int argc, char *argv[]) { + struct memory_buffer *mem; int is_server = 0, opt; + int ret; while ((opt = getopt(argc, argv, "ls:c:p:v:q:t:f:")) != -1) { switch (opt) { @@ -562,8 +596,9 @@ int main(int argc, char *argv[]) run_devmem_tests(); - if (is_server) - return do_server(); + mem = provider->alloc(getpagesize() * NUM_PAGES); + ret = is_server ? do_server(mem) : 1; + provider->free(mem); - return 0; + return ret; } From patchwork Thu Nov 7 18:12:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841852 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.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 D841E21733D; Thu, 7 Nov 2024 18:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003139; cv=none; b=F00/5kTY4vAr/Vv+dEGqioLXWcSE6xtXbP03yvdViOSDsfvHQGjdVrEXw4A0c0q3LBaY3TcMEwvvnR1gZdVMwvFqaGaFzvTojMC1R9/44poxkxAK+hUl43jD91sW6wvIbiJDzRrLdPAd1LaHifga6TcB/gmqP7BfupazioiO7v4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003139; c=relaxed/simple; bh=BJNDPj2EW/7eBR3P0ASg3cYQs56qXa3RvksZiRR0saU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=amVrBAGdsZbPnExPPwEJjMoLWpiFdz2F4vmP3sVAudfr2bQzJobKTXgsK6AWmuQ5vlMZTV1p5PJZL0cAbf8E9LL/SIh73vS2WLRFKsBgzB/000f4o7WdYzU6LbDfiCvezMC3PUgMp2rjP/T6xdHEWr/fUMSDbPStjO02JjLdSqY= 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.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-pf1-f177.google.com with SMTP id d2e1a72fcca58-71e4244fdc6so1075721b3a.0; Thu, 07 Nov 2024 10:12:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003137; x=1731607937; 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=f4w+ZoIX01KDuregY361pXi0ktHoI4FAq2xqZjxJlJE=; b=rSnyjMYlJJKRO3irco72Ue9OPbfLeKW5aRYv3eRreDUBX0oQsTfzalyoVNY+IylBc1 27aAuoG/FUpZrbGNvT+dhLZmUd3fGnVtAsxGSO+3B+yNewbulsALL+PrLTG/ZjbiBBBD tsWG4DWM72tZYljStYfyS45gwMKLVvGjOhHUoCxsBv39eHc4pzwnZeYNHkeGX8Z+zDZb gtAsy5m7VXGIEUNMrQBaOn6A9QWH2ZCaxkDiGVEgqC58UaYoQjsZpxKgtCz+us7+98qV TXf8K4KlUhIvM7i8ZFsvAIyNrgGhlNkE1OgGk7u0m88ypqSMSmIEPMfv4E5HFg/16863 WYdw== X-Forwarded-Encrypted: i=1; AJvYcCXAkLoqUVYHGCNjgEvCX0iYiqd7U1gsj7eTusbg1mSiNHfXZEV6NeWCo+Qd9x874ywPCzS/6xAzk5ecYcUQ+6RN@vger.kernel.org, AJvYcCXjvtyLHnBhJQUeBQfrv74B9jpA+IPRplZ20pySBCSU06HXq+sz80VMZicIJ6+liULl0cPZwZBBxsj3Frk=@vger.kernel.org X-Gm-Message-State: AOJu0YxQ0vIViYjsm7QIXd+uweYUsDr6R45NiqWlifr9y9Lfgy2OHINv WhFiW91syY02tcZE4oofxRfJ6WQxbzsvezRmJgF+V0dFy5GDdw9A2aAq X-Google-Smtp-Source: AGHT+IEXKuPN883Ey5CWPn15bOCKfr9AQJUwyirHXPJOPvwOkA97gvv47fpVfdg5IftUYabkaEOG/Q== X-Received: by 2002:a05:6a00:889:b0:71e:cb:e7bf with SMTP id d2e1a72fcca58-724129a97e7mr388982b3a.18.1731003136834; Thu, 07 Nov 2024 10:12:16 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724078a467bsm1901368b3a.43.2024.11.07.10.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:16 -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, jdamato@fastly.com Subject: [PATCH net-next v8 03/12] selftests: ncdevmem: Unify error handling Date: Thu, 7 Nov 2024 10:12:02 -0800 Message-ID: <20241107181211.3934153-4-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Joe Damato 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/selftests/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 = htons(atoi(port)); ret = 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); socket_fd = 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); ret = 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); ret = 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); fprintf(stderr, "binding to address %s:%d\n", server_ip, ntohs(server_sin.sin_port)); ret = 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); ret = listen(socket_fd, 1); if (ret) - error(errno, errno, "%s: [FAIL, listen]\n", TEST_PREFIX); + error(1, errno, "%s: [FAIL, listen]\n", TEST_PREFIX); client_addr_len = sizeof(client_addr); From patchwork Thu Nov 7 18:12:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841569 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 42FDD217F2B; Thu, 7 Nov 2024 18:12:18 +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=1731003141; cv=none; b=EB3ycb1977sw/afm/YE0OEsg0Rk4AtJpGBAbYJ/XKRnOV+SZmcg8m86INQyfaVzLGLs31J6SjB2W9nen6XcTwabme3BqOlUiblJF/EPKWCbWgw5Ra5LSswP1OTz6xMH536IgQnfp0IUP8GhXGSxCmziga8L0bLV2DEGQNZXuUAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003141; c=relaxed/simple; bh=9X6FLUGAqn3qmzaE6xbIR1acTxKaykWu0We8X1AhD2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s83V2F9oc40GUxJT2pOB8QSg2LZMZ6X0jlXRXaOLzG3T0VGTV7Jbz48TLkUtmKcDoqzycaVb6xJLmS8TegIbmiXuXv53BkDMiXowdXLdgGoPMjSGSEWYq4Bd3K9Fnsn8UtSI4e0UAb8v1AMyxVhs6edq2QYmK/KmmeSUy9WbDoo= 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-210e5369b7dso13692505ad.3; Thu, 07 Nov 2024 10:12:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003138; x=1731607938; 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=CNjL6vCUogToxpfHoTXEsRohnjfAJy/fV2Z2nSZAqtk=; b=nNL19S9RQatu0kpRMIF/5JI1c72dYcbQdjEpQxpo67xB7r2XNx/hFo6nky6f/o1cg/ VX6gD1uUDYLws8p44zdHWC3lZlpmKWBPxZhBTYBD4zunw/Zvk1aCGpPt7pg32ZMUztUe vdZq/edNCJPB5gA4vfi1MQXFTjprHUJr31CJ+GnWUPAhWKK6Oa4a3nFdCT5P6SFbQzM3 O91RUvgPtLMlfCKscSsnx7s/eW8WzrbNsAmaA2soi8O8XZRD41ol7CYrLXJ7fv3X72my fwvd/25VYAu2kSEOt0SWPLBMs5Ro6dueZztxdxf2qHprsYeqX88pirJ0iOrhDBZK2Ggw 6lWQ== X-Forwarded-Encrypted: i=1; AJvYcCU6o/xffTbcsmNcErAPlLFvafmacFAN66SRyRwigSUbskcCo2LpQsa0R/CIlxUs4vD0bh7ExhYrVVG+GqoW3zJe@vger.kernel.org, AJvYcCXl07QhSIN1jS6rBUwliNZF6SjJnCCXTbGAD8LmzOnvEfofUXgb/UtTv1VC0jf9I6NVPDHTKVFwV7RLek0=@vger.kernel.org X-Gm-Message-State: AOJu0YzwJwK9b2lDor0DaIJY/3CpJ7z4Wdtpyti1FlSGw0/FXGgjqECY k51kGcmLvRL0+VS2PN0sjA6QYGaJl3vZEXnD0Gt3DKrMgVQAlAyrN77Q X-Google-Smtp-Source: AGHT+IGoEzfdRe0g7TDcmu0xvjVnA8zNCF40GERGBOa9bD1bBZPEPCGvD0KdlEsex+4nh0MOk4bDUQ== X-Received: by 2002:a17:90b:1c08:b0:2d8:3fe8:a195 with SMTP id 98e67ed59e1d1-2e9b16ea69bmr145835a91.4.1731003138062; Thu, 07 Nov 2024 10:12:18 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177ddd616sm15146285ad.63.2024.11.07.10.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:17 -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, jdamato@fastly.com Subject: [PATCH net-next v8 04/12] selftests: ncdevmem: Make client_ip optional Date: Thu, 7 Nov 2024 10:12:03 -0800 Message-ID: <20241107181211.3934153-5-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Joe Damato 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/selftests/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 @@ */ static char *server_ip = "192.168.1.4"; -static char *client_ip = "192.168.1.2"; +static char *client_ip; static char *port = "5201"; static size_t do_validation; static int start_queue = 8; @@ -236,8 +236,14 @@ static int configure_channels(unsigned int rx, unsigned int tx) 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); } static int bind_rx_queue(unsigned int ifindex, unsigned int dmabuf_fd, From patchwork Thu Nov 7 18:12:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841851 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 2C624217F29; Thu, 7 Nov 2024 18:12:20 +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=1731003141; cv=none; b=sADi5mOWZsbpmyNNvhfxrNHOtXHfq8aKuQENYf09O9b4aHDhlUslrPERJ4crt2ezRUfng3/LSPqQifielg4tr1gaOS0Yh41Z99lI8L3EUdo2DsSkmmh+ZFzps3glSstY05ZmFn69zkC8Y/o1pSjHYEbo5FTk3cg08Iun9QvzPrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003141; c=relaxed/simple; bh=l/t2OEt/S6sMEb2VgG10+aYBp6AnZFYQDPVVgeT5QaM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rMO2G9rfMe2gFJ3mA59nOxLaCNB5J59vh6/TzOih6YygmIP6K9wX3gkWtCGMgENKZW61k9UGwh+QGw2MGPWezXKUlAir4eT1U798lg9ejyLu8D9FOE46uGnA01hOkcpY5YgnFOgsgwQ4lw1HuG4sv5rp8kgWneuVTzbF0KKl5kE= 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-7f3da2c2cb5so1062420a12.2; Thu, 07 Nov 2024 10:12:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003139; x=1731607939; 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=ycZNb+MV+lt/bFEqz5a3XvWO/EIFkiP256xD9EmYPa8=; b=IMYJ3kG4AOh1yh78bSSA/YgqZbdk2Xc1KNn7Wbq1UUQCguS8BqsLpjvhOZJrbBplIq FdUFuWlu+0ERtP7sCC3jPn/Xek7sG1I85tC0htsOT5L3Xe9k8sO5HmbX3a8u0voMlYiQ aeF94ZqXHq3CL5lXQzqXKdttVKZA4gWf6LPrnclF0bndDQ8tZL0vQT4r+jAk40jYjSIV QvspOt5tzaFWqK9j9pI6W3P+mAfruB0inyp1LWnkbDxUm1sBAeIFo5GpGfKGeO1/yHKm UyO/PIoLOCyL83i4zszNY2dXRoNTKPWYY+NHuq15Ctc0soiRSZmqeiymWvEVl8ZaXjnh oVTw== X-Forwarded-Encrypted: i=1; AJvYcCU/Ac7c18zAUUmjF+WH7OLrQKlHC0kaL1RXMK6/KOMz2qWtwLHY8V3o+3q8bMac9kvcKekYHbCnHyb1QlaiuYYX@vger.kernel.org, AJvYcCW+PKF6s543Jue7gmJ/DdseM4poFrDWXoH5Mve6zvWctH/yS8atiE9BpxYS5iV1zstHxn47vIAFBl5r16o=@vger.kernel.org X-Gm-Message-State: AOJu0YwjuXqXHDE7xL16CAIKIVNacfs7Ayf8PEEJXG6qsYM/EIOu0kVk 4RB5zl3myY6omY0co/jPbxpXkBrRcHHfeikJN1yCmBGVeZCWScI0oWNT X-Google-Smtp-Source: AGHT+IHm9H1tgRkUbltQueJe7Zk8MP32jmY1Y7IUr6IRDZ3hmf/qvFhRGiZlv0FJHcAhu7KgvBKcrw== X-Received: by 2002:a05:6a20:72a2:b0:1d9:2b51:3ccd with SMTP id adf61e73a8af0-1dc204ad1cbmr672198637.7.1731003139208; Thu, 07 Nov 2024 10:12:19 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f41f4890d2sm1733076a12.14.2024.11.07.10.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:18 -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, jdamato@fastly.com Subject: [PATCH net-next v8 05/12] selftests: ncdevmem: Remove default arguments Date: Thu, 7 Nov 2024 10:12:04 -0800 Message-ID: <20241107181211.3934153-6-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Joe Damato 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/selftests/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 receiver can + * be replaced with regular netcat to test the RX or TX path in isolation. + */ #define _GNU_SOURCE #define __EXPORTED_HEADERS__ @@ -42,32 +69,13 @@ #define MSG_SOCK_DEVMEM 0x2000000 #endif -/* - * 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 receiver can - * be replaced with regular netcat to test the RX or TX path in isolation. - */ - -static char *server_ip = "192.168.1.4"; +static char *server_ip; static char *client_ip; -static char *port = "5201"; +static char *port; static size_t do_validation; static int start_queue = 8; static int num_queues = 8; -static char *ifname = "eth1"; +static char *ifname; static unsigned int ifindex; static unsigned int dmabuf_id; @@ -595,6 +603,15 @@ int main(int argc, char *argv[]) } } + 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 = if_nametoindex(ifname); for (; optind < argc; optind++) From patchwork Thu Nov 7 18:12:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841568 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.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 55AE4217F4B; Thu, 7 Nov 2024 18:12:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003143; cv=none; b=B4clmk6iIJv7GMpS2A7ZLJWbAc/LxG3TkUYXfJ7nN1qMGiw3gATsTjp5t1o31szJYVrJg0LtXEGR8PINT+sNxgcrv50RIS3Tt6utYmQLXGDIMC+Lcl+52iDYnVYCOtk40RwH1jKMsqufjyU0DqmwEPU5vmpTbP24qAYsSc46CCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003143; c=relaxed/simple; bh=iPzT6eQpRnHtKqTPuVl6lvCdUooVuLUt7jI+2VuHlrc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q+6NOiQoAid7zZsnvhE6OM2Q365di/uzsdLOsP1z3QDhD/BlsMB62KxJa/m0Vixud4FgaAwk0GYxTjiiew7Ut6tkkBs3121nWU3jXSS7LVVXGuyl2rhVQO6aT9igGzp9lNbHdwY14QbBXr0Uth0rrVTh17btYY4G8FXVNJRF/bA= 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.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-pl1-f174.google.com with SMTP id d9443c01a7336-20cf3e36a76so13841815ad.0; Thu, 07 Nov 2024 10:12:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003140; x=1731607940; 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=qkoD+bxqtCPC7R806MtQ5rvDQ1QYwwjiPHDFKfL1vC8=; b=OpePH3ARmo6prGV6n1PaJrXLiJujXrE5xn/Jtue5bR9knfzVzjFJwVUHHYFrUzODdb o/jjaqUuqTM6IZtqlpMgGPHxxDGa4fog/ASxkjgy9sbh8zj8MbUUTVaRfP2bD2pe7TpL VO4PcGoNyNES+1fZLS9QOLE2C7RMgkEFZo29zo0LmVVpffstw617B8BXl/v0Q7JULihf NqTQm9Sf4n7k/unasqBc4JS8dQT9PKqyzLIX9df71jLVcqSMfZjx7ULRRoyoPnhPT1Oh EEwOGqumL4CT2BRAD66bwQc3rtszySowq/kLq7IhCY9Zr7xVfWlqqwTJO+NxuR6+uJb8 eTuw== X-Forwarded-Encrypted: i=1; AJvYcCU2VYZBo3sWRk5xL2cpLuqk3uWDDUpe4QBqFQg9ZFYSO5e7hdzYb2wSxoBf3eA2QxdX4AssqQJLpN0n6zDQax89@vger.kernel.org, AJvYcCWIqLf5zmItYSsgf5YqzgTs1Rx/GEeR56m1SwT64hTJmTzvUb3NVn1b71uA/YSZ6UgYP4i98atEqErB8Eg=@vger.kernel.org X-Gm-Message-State: AOJu0Yzf8I0XEyyPBjiHpt11ptsOWIXHh2RO4URVOEUS1GTtHaZQlfH4 ikG3K0YomYndFREms+l7g7IUxqwZoSozoy3pbl2r+qwzH5RNEE+inojO X-Google-Smtp-Source: AGHT+IFfWMHmWKQt25HlMZkBuNTrZHct4RqK/6pujgP5Z9sdOvonYfOxwvO8UhuTSZsqhrZ1fdBgIw== X-Received: by 2002:a17:903:41c9:b0:20b:b5d5:8072 with SMTP id d9443c01a7336-2118116ceb2mr11136765ad.2.1731003140395; Thu, 07 Nov 2024 10:12:20 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e49489sm15014015ad.136.2024.11.07.10.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:20 -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, jdamato@fastly.com Subject: [PATCH net-next v8 06/12] selftests: ncdevmem: Switch to AF_INET6 Date: Thu, 7 Nov 2024 10:12:05 -0800 Message-ID: <20241107181211.3934153-7-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use dualstack socket to support both v4 and v6. v4-mapped-v6 address can be used to do v4. Reviewed-by: Mina Almasry Reviewed-by: Joe Damato Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 97 ++++++++++++++++++-------- 1 file changed, 68 insertions(+), 29 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 0feeca56c049..645ef0bb63ec 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, unsigned int tx) return run_command("sudo ethtool -L %s rx %u tx %u", ifname, rx, tx); } -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 = "tcp6"; + const char *server_addr; + char buf[40]; + + inet_ntop(AF_INET6, &server_sin->sin6_addr, buf, sizeof(buf)); + server_addr = buf; + + if (IN6_IS_ADDR_V4MAPPED(&server_sin->sin6_addr)) { + type = "tcp4"; + server_addr = 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,51 @@ static int bind_rx_queue(unsigned int ifindex, unsigned int dmabuf_fd, return -1; } +static void enable_reuseaddr(int fd) +{ + int opt = 1; + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)); + if (ret) + error(1, errno, "%s: [FAIL, SO_REUSEPORT]\n", TEST_PREFIX); + + ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + if (ret) + error(1, errno, "%s: [FAIL, SO_REUSEADDR]\n", TEST_PREFIX); +} + +static int parse_address(const char *str, int port, struct sockaddr_in6 *sin6) +{ + int ret; + + sin6->sin6_family = AF_INET6; + sin6->sin6_port = htons(port); + + ret = inet_pton(sin6->sin6_family, str, &sin6->sin6_addr); + if (ret != 1) { + /* fallback to plain IPv4 */ + ret = inet_pton(AF_INET, str, &sin6->sin6_addr.s6_addr32[3]); + if (ret != 1) + return -1; + + /* add ::ffff prefix */ + sin6->sin6_addr.s6_addr32[0] = 0; + sin6->sin6_addr.s6_addr32[1] = 0; + sin6->sin6_addr.s6_addr16[4] = 0; + sin6->sin6_addr.s6_addr16[5] = 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 = 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 = 0; size_t total_received = 0; socklen_t client_addr_len; @@ -317,9 +368,12 @@ int do_server(struct memory_buffer *mem) int socket_fd; int client_fd; size_t i = 0; - int opt = 1; int ret; + ret = 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"); @@ -328,7 +382,7 @@ int do_server(struct memory_buffer *mem) error(1, 0, "Failed to configure rss\n"); /* 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"); sleep(1); @@ -349,29 +403,14 @@ int do_server(struct memory_buffer *mem) if (!tmp_mem) error(1, ENOMEM, "malloc failed"); - server_sin.sin_family = AF_INET; - server_sin.sin_port = htons(atoi(port)); - - ret = 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 = socket(server_sin.sin_family, SOCK_STREAM, 0); + socket_fd = socket(AF_INET6, SOCK_STREAM, 0); if (socket_fd < 0) error(1, errno, "%s: [FAIL, create socket]\n", TEST_PREFIX); - ret = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &opt, - sizeof(opt)); - if (ret) - error(1, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); - - ret = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &opt, - sizeof(opt)); - if (ret) - error(1, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); + enable_reuseaddr(socket_fd); fprintf(stderr, "binding to address %s:%d\n", server_ip, - ntohs(server_sin.sin_port)); + ntohs(server_sin.sin6_port)); ret = bind(socket_fd, &server_sin, sizeof(server_sin)); if (ret) @@ -383,16 +422,16 @@ int do_server(struct memory_buffer *mem) client_addr_len = sizeof(client_addr); - 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 = accept(socket_fd, &client_addr, &client_addr_len); - 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)); while (1) { struct iovec iov = { .iov_base = iobuf, From patchwork Thu Nov 7 18:12:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841850 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.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 A4D6B218338; Thu, 7 Nov 2024 18:12:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003144; cv=none; b=UjUlhEy+oqEtv/xSvZ8TjvFY8VMibsOajKoeh7wwXrykqyNQ73aNBjmr3/k4XEKF8km+rcvuegyJD9tbbCD1zdltJV8J5e+qROGoKHtVUddvtj3Up91mCBwh+ndvlWQJOAssFmKaDDrovuBLoLhdbuxHZD8Y51RarH+T/xaJPlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003144; c=relaxed/simple; bh=9qqAnoRvNDzm2DIP6UmeNvVQpyt/Q98tePSZZ6r1O4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hp/ZKLHzoOmpynLXMbACjf35FpN6USIDHhHRs2gXL9gl9bw51eRMSJj+da4tUmY7eJ7qdR1Uo99ride1bRIne9G4Nt3Vh3lun02x4MQqD6vCRQnL5JKaUpdik8HysIoH7zJ64EsasW0czUdwlf00/6L4l2WlLUuRABgZgQdMDFk= 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.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-pg1-f175.google.com with SMTP id 41be03b00d2f7-7ee386ce3dfso1880333a12.1; Thu, 07 Nov 2024 10:12:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003142; x=1731607942; 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=xDZD8Z6wjohcMulNg2Bu3w2bLGAhxse6AUuUhWisEno=; b=TDkXXPtoP2Ny6ZCuqxsCI/NH/ksA1NtiTHnLvwIL/MvsTZ7A4YbeSSezEqrmOrwah0 N+gljXK3H6TzpkLmC1rIrwVXiMSAkP3+RDAmS5kgVdGw/UM2FQnSCFeKS0qYzplLCh6y 1UZ9nZ9kkDPg/T61MtFwFhpEeO04MJdx98WRgnXOSzeASWkS+FkSneSh5oPsDDm5PZxF URymZCVuazQkaSvErBqLng+uCvnM/D310ari/qMXc/cMLvitDwVLpnKfvnJWGOoQ3W2Q YEhE9NKFcZap4S6HkksU7J1Ul/O4YK6xZbOH/iKoddjTo6efIff4licTihTeWHHHXQpQ fmvg== X-Forwarded-Encrypted: i=1; AJvYcCWP5JbFczRYTKBClGbIDBXdbc9o4fMpmxihztUhHX+w7os0lPCsSXulULnIIisI+GcO3J0t12pFYKb7O5lwjAvM@vger.kernel.org, AJvYcCX09l0kaweDeq7uqaO4QCM5JkfXoOtqGLpPqqNMxt1B2R3hhAmYaAb4kWY6iy/sEiEGqg5jv1KuIzuAW7g=@vger.kernel.org X-Gm-Message-State: AOJu0YwbCUC+kuSdDHl3vC5btvgjsr0oOcqFZ7wk2q2liynbMXx0J19U aR6tVqruuBMrmpx2NiuXV1ajQSOhmGAFXoIBN7q5y5jdDPGZbjx0ksN+ X-Google-Smtp-Source: AGHT+IH/ZB7QYbw7ZT12XZgjggR2xsVIUCn1idVt2hn4syh/aOYp/QYhzWesS9VEj2B0MiQx7tIp9A== X-Received: by 2002:a17:902:c411:b0:20b:c043:3873 with SMTP id d9443c01a7336-211821ca239mr6906005ad.21.1731003141593; Thu, 07 Nov 2024 10:12:21 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e418d6sm15274015ad.142.2024.11.07.10.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:21 -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, jdamato@fastly.com Subject: [PATCH net-next v8 07/12] selftests: ncdevmem: Properly reset flow steering Date: Thu, 7 Nov 2024 10:12:06 -0800 Message-ID: <20241107181211.3934153-8-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Joe Damato 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/selftests/net/ncdevmem.c index 645ef0bb63ec..ad6de8e0e97b 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) static int reset_flow_steering(void) { - int ret = 0; - - ret = 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 ethtool -N %s delete >&2", + ifname, ifname); + return 0; } static int configure_headersplit(bool on) From patchwork Thu Nov 7 18:12:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841567 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 A15C4218300; Thu, 7 Nov 2024 18:12:23 +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=1731003145; cv=none; b=J0dM0FIQpZDwvcnFy+3ChjuTPQVSQw4vJiXiIToK8SFGL6OI4ICtdUGp1tKzvmSWHeBYMM43fJ9Usly6ZvSgx6WBfEWwe0CNSS3+1g/RshL2UxxUci/kaGfa6UlV2KaeQ+g0Rknx2fMDdwsO5pw6EBrghHEYxj9BPDdJzxf91k0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003145; c=relaxed/simple; bh=IpP00aCuowF9QGCHU0HXnhDTJIAjGcRrPT96a5RuCBc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZX5B2ndoxCi9QRBKqo0YutFbaIG1cNbFDwUZxeQzFabMBpqcgTc77Zr3eaU2xH2yIAgVh3oVmB3BHDEw2WLGUpxzrwX+JnwrdCIv0q7UgSGkALxRKFIAKYcrDHicuf92sbn7P/DXGaGhX4ZQI4LPxbu2O6K1gfZJhX4qPNaOKuM= 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-2110a622d76so10770165ad.3; Thu, 07 Nov 2024 10:12:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003143; x=1731607943; 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=Em1uH7WWwP9uLKDu0J9tx3ubhx+AkkX/SgdwOrqLhXk=; b=f6ZpIvFsw4XnlhLLS4sipr3xoYTy7nJxIIiXFLGWYUD7FeDtaSO8iFIbwYOiyBjFUo VtGb2AIZ0iAB/uGCC9yTAXFjorr27mbraXa9BrcNUFCHDjAFyo1LA8MicXtpasmVqsMX lhcyF2cbK8kxnjYGhZo41tYXUGeTsKKIR1EaJTCQHJ0udvSE2V0KN4Cep09h3u15xMnH exqSWZSOzwT6/4mzmYuskR9QoVaeD5YB4H8mW7HRwYz176HH7wq9vPVWvDbw+YwvsPZ2 3An00RFky/MHbBO4FO/+zs/GF6qUwyWcthMDRLwFXDyRx9O7ktGPkfy6o9gicYe4U607 3y6g== X-Forwarded-Encrypted: i=1; AJvYcCUjNzV1bAyFyEKXXSpuUYVMJC58CqoEvTD6j7TvYsYHWz/PTKA/xCJuMPhzIG8OnySmdbEtnbW9PRLsodie0Ak+@vger.kernel.org, AJvYcCVAKeVFkNOtHdQN44p/KqfDiJ2b9GQKlPQ9Yp1rqEAw0KowUXa+OE1S48p2lcvkv1H1jZHV+1P9vmYwUoU=@vger.kernel.org X-Gm-Message-State: AOJu0YzvFkWWUxpTykccagacbObWA7jWsznAJg2yxyc0GaoOWDNuI+2L wNdZNxiVzLQC+dAdestarSCuafn4uOQBuHpphlp1AG449atJxglDth75 X-Google-Smtp-Source: AGHT+IGRTlUxM7UsRogy1kztiQGDP7ZnWrUD40jI8gSq4yJP0icpO11xsRiE+cpHtLs7Y1xAml21Jw== X-Received: by 2002:a17:902:ec83:b0:20c:8abc:733a with SMTP id d9443c01a7336-211823dab1emr3832125ad.53.1731003142793; Thu, 07 Nov 2024 10:12:22 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177dc8354sm15192615ad.4.2024.11.07.10.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:22 -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, jdamato@fastly.com Subject: [PATCH net-next v8 08/12] selftests: ncdevmem: Use YNL to enable TCP header split Date: Thu, 7 Nov 2024 10:12:07 -0800 Message-ID: <20241107181211.3934153-9-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Joe Damato 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 := forwarding/lib.sh include ../lib.mk # YNL build -YNL_GENS := netdev +YNL_GENS := ethtool netdev include ynl.mk $(OUTPUT)/epoll_busy_poll: LDLIBS += -lcap diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index ad6de8e0e97b..9ca2da3a2f63 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 #include "netdev-user.h" +#include "ethtool-user.h" #include #define PAGE_SHIFT 12 @@ -231,10 +233,58 @@ static int reset_flow_steering(void) return 0; } +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 = ynl_sock_create(&ynl_ethtool_family, &yerr); + if (!ys) { + fprintf(stderr, "YNL: %s\n", yerr.msg); + return -1; + } + + req = 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 = 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 == 0) { + get_req = ethtool_rings_get_req_alloc(); + ethtool_rings_get_req_set_header_dev_index(get_req, ifindex); + get_rsp = 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; } static int configure_rss(void) @@ -382,6 +432,9 @@ int do_server(struct memory_buffer *mem) if (reset_flow_steering()) error(1, 0, "Failed to reset flow steering\n"); + 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"); From patchwork Thu Nov 7 18:12:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841849 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.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 2E574218957; Thu, 7 Nov 2024 18:12:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003146; cv=none; b=odmb3AO2rcP8WnsCIhiFoppQd/a7iRX8QY2BTw1AkWbtUFc3uTDBqjGiEdmw8tLu5qUWORh9o1+QYL4TDlaXHvRtF2rl1gNdtOq+h2Tg9TduDlVsw+YtJ3rl6JnO7t9TT2guiozRKLrfLye6T6ofvHGUHWW4fw0KjfYce5oL9KM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003146; c=relaxed/simple; bh=GhC9tGqKarQ2Bdbc3qqWnBXRxTTtgWuongQth71ldwY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e1aQOMHwGB8bZD1wEVDzkWZtpmn+VKaMt+Ket0+Z/Ev/uWmQO2O/tnLshpRIsdB6o7xDOFI/XPybWaCMYkxIqZndxrCMoa/h0nYCRIJQ75OBiNy9WiajCzRZz1W5p2nsp0+2qilyPeYppmWQTWLtY8Sts7sVQuq1PR5ppaRfL2E= 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.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-pg1-f175.google.com with SMTP id 41be03b00d2f7-7f3e30a43f1so956800a12.1; Thu, 07 Nov 2024 10:12:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003144; x=1731607944; 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=ZvCVvFo9Qc8rModALEQHZE29SD8rgkDPTG1TevSkcA8=; b=beS4yPGczFwYxMzKugAcE63LKLMwJliOJyz0YNLeusU55JESsdOXUCG0CRXtDS9EgT OPmVRQukulWShAx7GVHmVV8AcqyP1UvJ4aAxrc6BlFNwMCk2th+6sRF/HwnlwkB+90W9 4XYmJSTlh4jVZ5Dv2GgBmX6lNpjBI3Vrl4jgMeVdiMcSu1ExHhqbvOMbEn9COckGlaQI KQUhBRoAXVfyNqk3lb6TloMGJrT3a0zyF5RdsTXeQ65qOyc+NRi5ddZxoy7VKc4pZxJH uo0636+tbX27LZICCrk/3iwIDOcQInXCs76KLWTqSS9zpIfe9hLiZWi8FPagkCMyILY3 LcyQ== X-Forwarded-Encrypted: i=1; AJvYcCUv1L6lpPSxur1DoYNln6iBOh1eHKWFu/OBlyFfFAXlXc8j2RbJOjSP5ozOfYbQnyAvHUjd98/zlK6WdOGwt+zI@vger.kernel.org, AJvYcCWLAch2uNCeGqiD+mVs+8MmBk/ZJNhgduqAX4SWjtOdkV+oOG9d7GnwxzSUplPojJFzHuMxWH3FYf6yIV4=@vger.kernel.org X-Gm-Message-State: AOJu0Yxgm1kURpM0omSXGQTe+5SqtQRG+zm3mvF5OXFfFOwOb30kDPyq E+RgdpdQ/xWfHS1cDVQmbatIWBh6Uawu3zhNIBvZAoOer9gRWd93pXVF X-Google-Smtp-Source: AGHT+IFV0VHiaT6gLpvKpGa/i997fI0xVeW+AcxPD4YDHOECBfRtRsxObNP4T8pzvqrW+PeSBJKZtg== X-Received: by 2002:a05:6a20:748f:b0:1dc:30b:cfe with SMTP id adf61e73a8af0-1dc20637470mr621193637.37.1731003143922; Thu, 07 Nov 2024 10:12:23 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72407860906sm1886811b3a.9.2024.11.07.10.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:23 -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, jdamato@fastly.com Subject: [PATCH net-next v8 09/12] selftests: ncdevmem: Remove hard-coded queue numbers Date: Thu, 7 Nov 2024 10:12:08 -0800 Message-ID: <20241107181211.3934153-10-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use single last queue of the device and probe it dynamically. Reviewed-by: Mina Almasry Reviewed-by: Joe Damato 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/selftests/net/ncdevmem.c index 9ca2da3a2f63..1ea62c129ddc 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 = 8; -static int num_queues = 8; +static int start_queue = -1; +static int num_queues = 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"); } +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 = -1; + + ys = ynl_sock_create(&ynl_ethtool_family, &yerr); + if (!ys) { + fprintf(stderr, "YNL: %s\n", yerr.msg); + return -1; + } + + req = ethtool_channels_get_req_alloc(); + ethtool_channels_get_req_set_header_dev_index(req, ifindex); + rsp = ethtool_channels_get(ys, req); + if (rsp) + num = 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]; \ @@ -711,6 +738,15 @@ int main(int argc, char *argv[]) ifindex = if_nametoindex(ifname); + if (start_queue < 0) { + start_queue = 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]); From patchwork Thu Nov 7 18:12:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841566 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.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 2FAAE2194A6; Thu, 7 Nov 2024 18:12:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003148; cv=none; b=d4Q2g2GkSAFkUD7SDLtfOx48QKGAyNF1EZha9UEpngueDzUaMVoFUAWkE/ZmqPSqlKO7Xfl31xOnVLL/LfXyWGLC/0gmpnaDkjOvOl1zDOojIVnL6dKAPkcNKjBBZ3uVa+oRPtiSnnnqeBlh1rFz0qz3yE+LvXcE/hvWDbgJ7S8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003148; c=relaxed/simple; bh=WCIDt+21qODKvmHLEUAs2MLPOshG5oyBZZXSw4k38Oo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tSlFSRX+OoE79V9Emq5XZC+njtT0jMNv6T7ONKEG+axYQytiuG/7QHVtBk04RWSOJySeDpvSsYGzqB3rzh5bYnPcmxZO7dUqT2sHoP150sh3hMo3bMpOGKJztMiK5wRox41xvBN1jD2EEE9S3YLnWn4jQscRVPlGYJ3LaizR2lQ= 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.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-pl1-f174.google.com with SMTP id d9443c01a7336-20c803787abso11507175ad.0; Thu, 07 Nov 2024 10:12:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003145; x=1731607945; 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=X6TbHrRXODFPr6hzD7HJyGTadmIdNPZf+yRqUs/51D8=; b=foQfRdOrT6d4PLCjkdpbZZCL5EwICKpQa92CAeA9fPv/wrqmvsvgX0JtE0TnjrCjqv 4QzNCkKslWrSW4S9HFezmBDdRrCM1yDjpxPUCBHXX37lcsAVKFYDv59IX0kwlOuB5uCe WP88uEsObVeBGwrYaZKBkh5ka0pSPOZIJLAwxtrH2Aw0Q1YdGV9xpgpIpUovMXkYaWAq NEm/NxaKZiiGbv3SSa+d9jRfF8shrVQO7FRpT2i9T471a7yBqklmJ6x/pJqojZgZuNSl WwvlbmXo9hcexeJ8RX4ttcBmHiQPSjKVe99ymLlvNj3hhPpuiB5RAcSAZOps8d5pgIk+ 13vw== X-Forwarded-Encrypted: i=1; AJvYcCVFDOvRfsZn3Sypmq0uyiy+kSklQzpaNx4qfhW/eZricTFvcrBWmIkJesfuNoSin0/wgTreVeE+7Q78nj+CaiGN@vger.kernel.org, AJvYcCXSGt7yY2KbZV0CKZPTIfApdpEtY2YMOdNZWTk41fc/+VO2BHR2dC9VjidpPzuD6ztMXGHAXts6OvacRYo=@vger.kernel.org X-Gm-Message-State: AOJu0YwuePj1Y1Rjipa84TZ5q6KN82ivaJqTb+yX/Pow4IJfLjj9+CeW yGgkf1oNQefJSZmyGqY7IyWFwOvF/QCXYyVuMzqUWqpt+g7lY4aTjg8g X-Google-Smtp-Source: AGHT+IFdAzIPzvHOecE6NEoUJONwTO5AcHu5+0SNVy/eNc9HbuclSzPNd0qvUpW/gLAstfj1awcbWg== X-Received: by 2002:a17:902:f651:b0:211:3363:8c8d with SMTP id d9443c01a7336-21182202b3dmr8010925ad.20.1731003145293; Thu, 07 Nov 2024 10:12:25 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e99a5f935dsm4177603a91.35.2024.11.07.10.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:24 -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, jdamato@fastly.com Subject: [PATCH net-next v8 10/12] selftests: ncdevmem: Run selftest when none of the -s or -c has been provided Date: Thu, 7 Nov 2024 10:12:09 -0800 Message-ID: <20241107181211.3934153-11-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Joe Damato Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 49 ++++++++++++++++++++------ 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 1ea62c129ddc..8e502a1f8f9b 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 = -1; -static int num_queues = 1; +static int num_queues = -1; static char *ifname; static unsigned int ifindex; static unsigned int dmabuf_id; @@ -727,19 +727,38 @@ int main(int argc, char *argv[]) } } - 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 = if_nametoindex(ifname); - if (start_queue < 0) { - start_queue = rxq_num(ifindex) - 1; + if (!server_ip && !client_ip) { + if (start_queue < 0 && num_queues < 0) { + num_queues = rxq_num(ifindex); + if (num_queues < 0) + error(1, 0, "couldn't detect number of queues\n"); + if (num_queues < 2) + error(1, 0, + "number of device queues is too low\n"); + /* make sure can bind to multiple queues */ + start_queue = num_queues / 2; + num_queues /= 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 = rxq_num(ifindex); + if (num_queues < 2) + error(1, 0, "number of device queues is too low\n"); + + num_queues = 1; + start_queue = rxq_num(ifindex) - num_queues; if (start_queue < 0) error(1, 0, "couldn't detect number of queues\n"); @@ -750,7 +769,17 @@ int main(int argc, char *argv[]) for (; optind < argc; optind++) fprintf(stderr, "extra arguments: %s\n", argv[optind]); - 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"); mem = provider->alloc(getpagesize() * NUM_PAGES); ret = is_server ? do_server(mem) : 1; From patchwork Thu Nov 7 18:12:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841565 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 15241219C9A; Thu, 7 Nov 2024 18:12:28 +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=1731003150; cv=none; b=Iqp1jvkQ0ayRmopIx5EKxeE5IKcpq9WVne8Dfaajlo8uU64sk/TtClaWJq4LBKlWfLmx4kfslHXIdCOhyGLlYIntU94aZDNnR2zK0tTuu9fdiRTnO/OLLUNktiVzojmDw3qLywA8U2H1pxDpY/CAnmn2UJmcDZFWfG+a9CXSFjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003150; c=relaxed/simple; bh=QNIVoaUG6HoJ02+8aCHTzhZtbDvKJFEGC7k27W7G0/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qqdaVlJNdiWvkKbpq2CD/tCtAwfNOKsFd3NAFYbNZhug/xnl5UJAnZs8PPStyjRnsQcyO1hoXdGLKYtGCgEG6zmX7jm7EpoTFF/SUZv44aNt64sKz6tn0pRfm66pefxqIyut8wc1bBsNLn0Fyu33iKMexdq3WyCM4UeUfMcXmrE= 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-71ec997ad06so1007038b3a.3; Thu, 07 Nov 2024 10:12:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003148; x=1731607948; 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=qNhE4YRfShJkdt2GI/0tkrKLcEcEwniPhDcX9YpyZao5z7jpq5++XE+Pfymxr9X+a2 jpuDUhJH2Wjhe7OXw5fGWFUZjIGRtFXIOmZLrRnSyetTk+sQIN6k2sK+OSfNHV9M+KNa DpUKlbO2Z8ldpNREdAR9E1/fjajEfM1HlJcVEZVeF2ImYjRPZbvhUn+dhNTpBJjUR4Vn CHeZlOMyfX8LCV1y64pjkYYWBhh7pQ9Lpg4iG9SLDZntX7Y+gYfd1MrOJofFjScF+g3B z5Cil8GsnfGXiISD9+SHKCV9roDV6r50WYNdoihsk+S1FW1+PNG+s2/yh0xMWYQgSzgn xBlg== X-Forwarded-Encrypted: i=1; AJvYcCW5+UjBUVPbxxn3f/9XuQU6dKw1C5oEpyj6QNAXbjhlK1N7ZkRfERrg4IcYqzpVtK4nHZGq4E6Vtw9NMhw=@vger.kernel.org, AJvYcCXZJ8WHvh9YiGe8NcMSper6mD8gYBlyJWEnyG07nW84amCxcvt476RvgbkAN1EwmhUF5jCt1JzRNSyZeRT5oLLg@vger.kernel.org X-Gm-Message-State: AOJu0Yw0Qwtf1+1PsQL3To8D12eSYEyPVH8LdU6RkmEKhDYM591xq7xG Z7MEc8XjN3RDTOf55DWR5kM8g0pYoGu8bP94GF/59tbPpEaLdJjBhnr9 X-Google-Smtp-Source: AGHT+IESI5ADNbsaRUr7r3ros762SVgz2pZbG8VO9M6J7g7TP8uIBZYhDBr0hDVOk+2GV2slkwIgQA== X-Received: by 2002:a05:6a20:a913:b0:1d9:29ab:9b49 with SMTP id adf61e73a8af0-1dc1e4d388amr898810637.32.1731003146542; Thu, 07 Nov 2024 10:12:26 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72407860a4dsm1940874b3a.29.2024.11.07.10.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:26 -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, jdamato@fastly.com Subject: [PATCH net-next v8 11/12] selftests: ncdevmem: Move ncdevmem under drivers/net/hw Date: Thu, 7 Nov 2024 10:12:10 -0800 Message-ID: <20241107181211.3934153-12-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 => 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 => drivers/net/hw}/ncdevmem.c (100%) diff --git a/tools/testing/selftests/drivers/net/hw/.gitignore b/tools/testing/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/testing/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 := \ ../../../net/forwarding/tc_common.sh \ # +# YNL files, must be before "include ..lib.mk" +YNL_GEN_FILES := ncdevmem +TEST_GEN_FILES += $(YNL_GEN_FILES) + include ../../../lib.mk + +# YNL build +YNL_GENS := ethtool netdev +include ../../../net/ynl.mk diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/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/selftests/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 += fq_band_pktlimit.sh TEST_PROGS += vlan_hw_filter.sh TEST_PROGS += bpf_offload.py -# YNL files, must be before "include ..lib.mk" -YNL_GEN_FILES := ncdevmem -TEST_GEN_FILES += $(YNL_GEN_FILES) - TEST_FILES := settings TEST_FILES += in_netns.sh lib.sh net_helper.sh setup_loopback.sh setup_veth.sh @@ -110,10 +106,6 @@ TEST_INCLUDES := forwarding/lib.sh include ../lib.mk -# YNL build -YNL_GENS := ethtool netdev -include ynl.mk - $(OUTPUT)/epoll_busy_poll: LDLIBS += -lcap $(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma $(OUTPUT)/tcp_mmap: LDLIBS += -lpthread -lcrypto From patchwork Thu Nov 7 18:12:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 841848 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.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 D1E6D219C8E; Thu, 7 Nov 2024 18:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003150; cv=none; b=pP7AVT+2QkgFj4GnJxtxFx1U/TeUlVujLgvd1UOw1dOBi8wmNbrR8oW7LiGSwATHP3IvJKM2kxejq48KkEClkFpml2go/I18gkHieW4dXzFYtsHYnugsmItA2ObgTANneuJM3UL55nnc4s4MxPIX+mp5UxuxwD5OLSuLCFA6y+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731003150; c=relaxed/simple; bh=WEVapGRSibcZWnAdVZddqFwRKnfxfw/1NS5vjEqInk4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eZpaa2LoqRdJyhZNq0LgfP+UjvprmgIQlDB91N9yZDHRLU7o3vlPw4PUlWue8hQXDjj2HirwKCHwGvCcw5sRPw3GGkJ9J8gQxfUNc1Q8iJNb/z7TWh0NG1XM59eD9wbDEII1Eupoyq9a/ZW/+MiX+LKsNhoAVXTh777eSZlM0pY= 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.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-pf1-f171.google.com with SMTP id d2e1a72fcca58-7205b6f51f3so998772b3a.1; Thu, 07 Nov 2024 10:12:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731003148; x=1731607948; 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=Hx/2wnbdQkN8QIuIPvLKCg6kXWPOICXSJLx031omQYg=; b=Tj0i9yj6pePhg9vzsQGcUN+3wdeGYuz2yj6O9O2X+YzW59xocecyD0XRz3iubD7XyU CXtPAuMZEoJTIt6V5CqYxiopqmAxVfEFHttH1Q8uqXnMa4IL2/K7zGaG6vNQaAV3yk7T P1Y2X2UikAUVj5bEpZX+xpNj1JDRBUwbUr7szUq6JC4RtNpyDuJiJOnTR54mZejp83YR 81pXaDy1PB1l8YcFtO10I9xz4SyDAySf2MatOKGvzoGmZqoL3LcVJFy1uY6X2toBz+jV ApYMsKTfW3mcyxlNbP+NUdz4I4rH2UmsYJ5dLG7RCOoxr7YogcphkqCFA3NBgFxgEHGo qh6Q== X-Forwarded-Encrypted: i=1; AJvYcCV8zgzKoYTsd1riwuyf77qQQ4acZbHXOky+btR7JKb5SoBa1J/K8aNZNEVUySWfxUrZKYdkOqnKwxWKBZ+SxHpu@vger.kernel.org, AJvYcCWAolXk9pJ1F/bUEzDw2uzLGr2V2fF9S5CiXAG3KZljpq5vZWwvqo2lC/R6Wvf/y+jT9c6twuosSet702A=@vger.kernel.org X-Gm-Message-State: AOJu0Yz85khEF+VLsAsFoY9eu09RVH63nnK5KCjKzy0lGAIfvU5M0qVE hHHLYy3907U0EiFqZBoCdoEW0pESH5xAO8CgyGHDL7JqvKruM7mHvE4+ X-Google-Smtp-Source: AGHT+IGaWDZqmfbW85mkzCyEVanG3EM2BoxuAf/uYsm7sCeaTKZTZkIR3DakFqzP8SMfT4gbBpyovQ== X-Received: by 2002:a05:6a00:84d:b0:720:9a03:b6dc with SMTP id d2e1a72fcca58-72412986e46mr408154b3a.18.1731003147709; Thu, 07 Nov 2024 10:12:27 -0800 (PST) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72407a18f24sm1866818b3a.152.2024.11.07.10.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 10:12:27 -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, jdamato@fastly.com Subject: [PATCH net-next v8 12/12] selftests: ncdevmem: Add automated test Date: Thu, 7 Nov 2024 10:12:11 -0800 Message-ID: <20241107181211.3934153-13-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107181211.3934153-1-sdf@fomichev.me> References: <20241107181211.3934153-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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="drivers/hw/net" \ install INSTALL_PATH=~/tmp/ksft scp ~/tmp/ksft ${HOST}: scp ~/tmp/ksft ${PEER}: cfg+="NETIF=${DEV}\n" cfg+="LOCAL_V6=${HOST_IP}\n" cfg+="REMOTE_V6=${PEER_IP}\n" cfg+="REMOTE_TYPE=ssh\n" cfg+="REMOTE_ARGS=root@${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/testing/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 = \ 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/testing/selftests/drivers/net/hw/devmem.py new file mode 100755 index 000000000000..1223f0f5c10c --- /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 = rand_port() + probe_command = f"./ncdevmem -f {cfg.ifname}" + cfg._devmem_supported = cmd(probe_command, fail=False, shell=True).ret == 0 + cfg._devmem_probed = 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 = rand_port() + listen_cmd = f"./ncdevmem -l -f {cfg.ifname} -s {cfg.v6} -p {port}" + + with bkg(listen_cmd) as socat: + wait_port_listen(port) + cmd(f"echo -e \"hello\\nworld\"| socat -u - TCP6:[{cfg.v6}]:{port}", host=cfg.remote, shell=True) + + ksft_eq(socat.stdout.strip(), "hello\nworld") + + +def main() -> None: + with NetDrvEpEnv(__file__) as cfg: + ksft_run([check_rx], + args=(cfg, )) + ksft_exit() + + +if __name__ == "__main__": + main()