From patchwork Mon Sep 30 17:17:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816754 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.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 DE81A198825 for ; Mon, 30 Sep 2024 17:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716680; cv=none; b=jtRIr/tden7NhLXZHY1OFDOqJNsfQTNkPdZWSMaGjcHzx1loONCBBudbKxLPIsHe/3aknHeg0NrLeTTB+xDFtAyOxmZltEW7+SlVYdZsj0Lp9niff80DU8UtzH2U65Qi5HIWPwQ9WO7fyT6O/nrh7VxAXh2QlyrEPtbEOdeT9vQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716680; c=relaxed/simple; bh=++7Sx5UWDA9G4DUzlO2wTO8BxxsWyhZOlHYiki14NZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wa1rLUUkC2V+gXPqIobm76aucFWC5K7jlV3CRl8zDbEl9FxC5szvlPg7sw/Q26PvqihlANUZqBHrcNIhI1I71vf/h7sf3dnTWdVXNWoUXv+AgHThiIw3A25vm7aMrx8Y4RmRhU8EzsKxBiCoBdXoNIeu3X3NFdjSJp0d+AqfH8E= 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.167.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-oi1-f169.google.com with SMTP id 5614622812f47-3e06853e579so2637154b6e.0 for ; Mon, 30 Sep 2024 10:17:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716677; x=1728321477; 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=VzhBHFvcV9hDwvSR/2bVW1w1QmYsKH0ftcaDPtzyOH4=; b=F+Mfq2gLMXIgwRa82KtJyrw7zpPfTyEGov3BlAtMACaZi29MNzgP1e4Yu/vh2j/pEi zKBNlae9VoU2FamNQqiI9+xQ4iF5InNGuAJg1SsBlOpkkdWDMSfoVaItP1h7vYhMHs7m YHbd4hsIqpBR1KYkD6cr8uSrt3HcADk0UG1CedIPKJGOzFQa5VZM+U6t3bUmemjjAFyM lGMz2opMddnk+XFiFt3+w/WpEXsSI1sa2cIQWwjIEc41XGrulhd1W2/Ybv0qkyJQQAfV MP8q2u3qUsXC9bSnmkoC86RcJbaUhHy4D7qlOx2VMU00y8nhlsMgeueMtE3ODfyopda3 HYCQ== X-Gm-Message-State: AOJu0YwE13ZUA8CQjcc+TRciJhl7iOWiHc2ZismcECGWJxWBUR5NflYR m+I3FRwa8TAwL7PV+eo/1lHg1ITina9fFAJjumkdm90z7ehdvu5w5/P9 X-Google-Smtp-Source: AGHT+IHWZa7OY6LoUPFeJfAisD/PoKexlAEtb72rNVeXnrt0TH9iG7ySzp9uVm3dCmOjBNxi8gKyJQ== X-Received: by 2002:a05:6808:152b:b0:3e0:3fcf:eed8 with SMTP id 5614622812f47-3e3939e4513mr7773168b6e.45.1727716676689; Mon, 30 Sep 2024 10:17:56 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e6db5f57f3sm6801924a12.77.2024.09.30.10.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:17:56 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 01/12] selftests: ncdevmem: Redirect all non-payload output to stderr Date: Mon, 30 Sep 2024 10:17:42 -0700 Message-ID: <20240930171753.2572922-2-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org That should make it possible to do expected payload validation on the caller side. Cc: Mina Almasry Signed-off-by: Stanislav Fomichev Reviewed-by: Mina Almasry --- 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 Mon Sep 30 17:17:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816755 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 88DD418E354 for ; Mon, 30 Sep 2024 17:17:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716681; cv=none; b=tmJKeZgwZraYQkkGaNEct3Liv3BhgTuI5NBxOdL+hLPk/emWAiwEMHIxbmNx38VN1hR1RzE3iBCWcPg0pdwH/B2PpD6hvfne7N5mjFBeURxCMc75hFCDGcehSNJiRsXJfbBrZFqp+q29srQekV1mpCBFI4TTWX+sSIw2f/Px1iI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716681; c=relaxed/simple; bh=9G6Zt3N0zb9smhrarp/q8rteUqcKdV3Z3Z9rNCBNVMs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lp/l17TPUZODwcmGb+KAQQjkadQDAveCzhZ1P3rR8w8ouN9uZA2AfJEEySB5H4LCPrjt4UUsuMHLxMaxUVMsxJPWlLlS7IBOVzLSrYLbkUD5/y0R2GZHCbGun7JiLNcV+AIVG4RKuzCt5nhS3E9ioOaZL3lZrVtguhPdWObalKU= 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.52 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-f52.google.com with SMTP id 98e67ed59e1d1-2d8abac30ddso3994616a91.0 for ; Mon, 30 Sep 2024 10:17:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716678; x=1728321478; 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=C0RPDPuJyfg+QyBf02JgJt7NjOIlGo2fb6qUMubteQs=; b=e8K//mEtY0PlIVZLiFUhrJ7Ce9yoN4NH8tnaQI+1yZ/NRz7KdrVEEXYSVZHzTwSd31 L88HIY6Pzj3t1+j12fuxBKjBENATP+AaKbYF7guv17rLYVdiOJZIwNvBfKkgXfgyhREe qmj0Bu5FP9/rReq+JhXkGN7E0wOmKI0tkbyJB4Q3EFrS4t3vcI0LVHe37Xj8RryVvLVW N3FHnxhxeSfL5E0le3OM33PBG1wYk3vu68BvDpd/ffMoxHEmEt46bnSEAHfawtCPhicW FqjIN6dG6H+ykpp3JOnuXzQV1Inc2AfpFySsnJUpfPLE2RfgTVrKd5l8a0PVOEFPhR6a DDaA== X-Gm-Message-State: AOJu0YzkzVPaSwGSiDp4hEwUkOE9ie1jRdrBVSJ3rkRobBKwG2Ep5yHj Tq7AtDsmbmhOKXVI9FdiM+ZI3p/HkP/Ir9ojZhSxUcBhMcQNaAdkNbtp X-Google-Smtp-Source: AGHT+IH1EyvvRePHhicm/03Vf3yhel/XIzwttgravrxGHBalOlh1Z1NJh2kC94m7Jn2IN0/Qh7sbXA== X-Received: by 2002:a17:90a:8a8e:b0:2d3:ca3f:7f2a with SMTP id 98e67ed59e1d1-2e0b8b1dbb9mr14672650a91.22.1727716678420; Mon, 30 Sep 2024 10:17:58 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e0b6c9d354sm8250256a91.25.2024.09.30.10.17.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:17:57 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 02/12] selftests: ncdevmem: Separate out dmabuf provider Date: Mon, 30 Sep 2024 10:17:43 -0700 Message-ID: <20240930171753.2572922-3-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org So we can plug the other ones in the future if needed. Cc: Mina Almasry Signed-off-by: Stanislav Fomichev Reviewed-by: Mina Almasry --- tools/testing/selftests/net/ncdevmem.c | 215 +++++++++++++++---------- 1 file changed, 134 insertions(+), 81 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 9245d3f158dd..557175c3bf02 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -71,17 +71,118 @@ 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_to_device)(struct memory_buffer *dst, size_t off, + void *src, int n); + 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); +} + +static void udmabuf_memcpy_to_device(struct memory_buffer *dst, size_t off, + void *src, int n) +{ + struct dma_buf_sync sync = {}; + + sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_WRITE; + ioctl(dst->fd, DMA_BUF_IOCTL_SYNC, &sync); + + memcpy(dst->buf_mem + off, src, n); + + sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE; + ioctl(dst->fd, DMA_BUF_IOCTL_SYNC, &sync); +} + +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); } -void print_nonzero_bytes(void *ptr, size_t size) +static struct memory_provider udmabuf_memory_provider = { + .alloc = udmabuf_alloc, + .free = udmabuf_free, + .memcpy_to_device = udmabuf_memcpy_to_device, + .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 +302,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 +310,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 +345,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 +401,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 +469,17 @@ 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) + + ((unsigned char *)tmp_mem) + dmabuf_cmsg->frag_offset, dmabuf_cmsg->frag_size); else - print_nonzero_bytes( - ((unsigned char *)buf_mem) + - dmabuf_cmsg->frag_offset, - dmabuf_cmsg->frag_size); - - sync.flags = 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 +504,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 +515,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 +530,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 +543,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 +556,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 +565,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 +614,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 Mon Sep 30 17:17:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816756 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.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 B0EF5198848 for ; Mon, 30 Sep 2024 17:18:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716682; cv=none; b=ntCldeacQ8nIa+FNDI29LqY8MQY3OS4jra7QNzwmdLsufiGGktU5kHtSKxpDQJPef9AA5Nu8Snxr4+k2QN28A2ZUHscFsoWXtWe6Z+NS6du3L/cRPvtAmU1u2Mqu6Ek2UOzJI+AJpYvnwIShFvjcYqHs02l791ePrpCcofXIZwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716682; c=relaxed/simple; bh=OEiQjsd77/J4AUaRRSihKZZbIILV9i6MyEIBV3CYweI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qcrdU6hpwj1l/HiIPIJBDk7sndp+CS+cVB+JxmZWmFtB+B5Z3umGegQRT1qqUkkBVGmfW54KMYFhoc3KAcb9Hw6Z6U/TZYu7TDWiqAhRq48Bb7jNGYSyCMkUml3sNIsw/wOXt7qqh4e1KpLzXHGmuMvSj8vPciGhv1PiG7fCpac= 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.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-pg1-f176.google.com with SMTP id 41be03b00d2f7-7d50e7a3652so3090560a12.3 for ; Mon, 30 Sep 2024 10:18:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716680; x=1728321480; 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=SOqtNZVQHyIAx4sh4ziq0pdIW94+VRMlBWI3BiRvwrw=; b=UKLIC4jCgD0RJjQIRiXphD40Mvlee7/IYXy4H0TQ3d7zKmQGLR4EADCGCqBYh+0Tju YjTDri3I0kFNmm9KkWk8rwYL4FJWdu7wXeMl3mLKHN3tDg03wWDt5K53mmBN0v4YX7Dc TGOApt1KdEmpzT/N3hFX8rfVeLpm6e8WjvDd2OIxpReAIJvbSFBDuFTm4HrH0rZmPSAp MUB0Wnenluh/P5yHLfbhdChVQdmRSj7JuFoxAc64FVTlBaYM7vgHjZTeeyYOrNvRguQE sBhjQQPauXt0ubolxkFlfSXZQdCC9qHJiAXWfv1PGe4FHz99Z7o9l46E27fRnASlu/tS LOTA== X-Gm-Message-State: AOJu0YxTmbCymQMfBkCmgNzsCDCR6wYAEj42tAyfc05Yxb1v80rE6zAN X4X3SB0AzYvPHEWSTRxOLyhuj/01QsaV7QVe3bhnVMZRAtly4r5BwLmT X-Google-Smtp-Source: AGHT+IFyLgssQn2gal5pMNvUGd1D/7MkfX5P5Rwm5FCOf142la99tCjDTddukMYhhgGzreU1tiCO2A== X-Received: by 2002:a05:6a20:6f90:b0:1d5:2b7f:d2f8 with SMTP id adf61e73a8af0-1d52b7fd476mr811669637.13.1727716679728; Mon, 30 Sep 2024 10:17:59 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b264d39e5sm6670783b3a.92.2024.09.30.10.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:17:59 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 03/12] selftests: ncdevmem: Unify error handling Date: Mon, 30 Sep 2024 10:17:44 -0700 Message-ID: <20240930171753.2572922-4-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org There is a bunch of places where error() calls look out of place. Use the same error(1, errno, ...) pattern everywhere. Cc: Mina Almasry Signed-off-by: Stanislav Fomichev Reviewed-by: Mina Almasry --- tools/testing/selftests/net/ncdevmem.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 557175c3bf02..7b56b13708d4 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -357,32 +357,32 @@ int do_server(struct memory_buffer *mem) 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); + error(1, 0, "%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); + 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 Mon Sep 30 17:17:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816757 X-Patchwork-Delegate: kuba@kernel.org 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 38A4B198E96 for ; Mon, 30 Sep 2024 17:18:01 +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=1727716683; cv=none; b=p/yi3adgyyYJFY9z7X7a7Sj02L41iBnXqd3hJpGPcUOdIzzhuAFGpg/LwdWQHxU1lelHtzG6k3Sy95Q0AGV+h0t1wJjgPYXdnQXvcS80rTO9doojnfxpOFlWQuk4ZlQtLfF14xUuhuSt1R7iyn+yecGfb7pp1ZFvCKcBxBSCzQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716683; c=relaxed/simple; bh=4sbRdjR7/fPoTU7/ByUzVIGdiIM8T5b0ZhCD8YLtBZw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aT+B51WFzR1VIMDWMJiAQtpyR6veisa5fAg+DEbFK9PMVm/pzzeoD6QqPUlBb2WWLE3h6IXatOXh/NrLOyNLRDqVXerjHC2oVGLwT3dacWLTMcIVupm46RaoHkDhGcCy6G/yS+mn3kfQsmRkmz3xOcOcNFS5gVN7N6aK5xsvzGo= 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-20ba733b6faso3080825ad.0 for ; Mon, 30 Sep 2024 10:18:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716681; x=1728321481; 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=OJEvaAS+5sv+Pr8rJakjDZsrflUEMuJ3AR1NhZU2/OI=; b=b4Fllt7h6604M9+YlnuY+lhwOU3UJEiqQl5qweG5dekjKTJZ6hvi9tXrgl3bcD4mKk htXZF3YDtmO7ogJ6adzXFcOcVUJHU9AZcq05CbumULOhzE8SdBgExLya3VPH179pHEF/ /JEZ7ukp7+h2sAQSAbtfwRtXLvDhJCtn6OZosST2Q303W0LUaG5Pw377bAs5dlex03QD 20RpKYGN3pzvkav3sG0sIb5eIv1puHvOXKEE2O5UQfG5xwwtZ9dkAVI297mB3CyK5IxR hkOxrwS2IZPlhwWwqwiA4WKOQ0kjh/vNkD9OPmjOYIXctL2/3lbp09Ra6SMAJ7qBacP9 dufA== X-Gm-Message-State: AOJu0YyK6q6qLzNsFw48+gdt4y9CUJYfg8IwbRiMa+8zNrkBZkX9hty2 q4YY9FCFWHhLwzG7ACo+Y/JSo67F4BQAikX1RMm+t0q5e4x8LVOOugw2 X-Google-Smtp-Source: AGHT+IHPad8KbIMqE4cxZVp/TchbvlzTBytiLlT3lH/3yGoiPFRX9wqxgwg1GqWhJGLyTDNpwROpow== X-Received: by 2002:a17:902:d488:b0:20b:6e74:b720 with SMTP id d9443c01a7336-20b6e74b8e3mr93801405ad.59.1727716681120; Mon, 30 Sep 2024 10:18:01 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37e516d3sm56588055ad.242.2024.09.30.10.18.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:18:00 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 04/12] selftests: ncdevmem: Make client_ip optional Date: Mon, 30 Sep 2024 10:17:45 -0700 Message-ID: <20240930171753.2572922-5-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Support 3-tuple filtering by making client_ip optional. When -c is not passed, don't specify src-ip/src-port in the filter. Cc: Mina Almasry Signed-off-by: Stanislav Fomichev Reviewed-by: Mina Almasry --- 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 7b56b13708d4..699692fdfd7d 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; @@ -253,8 +253,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 Mon Sep 30 17:17:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816758 X-Patchwork-Delegate: kuba@kernel.org 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 5DE46198A34 for ; Mon, 30 Sep 2024 17:18:03 +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=1727716684; cv=none; b=XxyHCotUBOy0oBYM24NA+P+GYUNIen4vcSXWDcXOrHmu/WwzJC7TZUwWbxip7kEfpmYEkUwAdFzl08T6IKQTa1ecsK6mmkSFnI+iJ6Au+neHEirTKpbvH0C2VsMWXgc5MzK+ZrIlP8EFsq595MAN3gBI/tV60jsuhieegk//JuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716684; c=relaxed/simple; bh=ZLy9o70mm8QxL0HkNd/A5JwdWyv7JQBFoH1edCFqIww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LY1TEw+Yst7UbUiFCdYMaVfdfyytbmdUB/i8v654OEBbPoMmrq0VgaS8p6LXpJ3VWUNDnxZDrYKfOp5i3piPZGA2V7cXJLaCKl1zaC3iF2P6+NrBEBvCc2n7aGKrncYOMm9ym9rJiZpNE6Beg6B1D9jT29yzMDRMJv/uCg3qN4g= 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-206b9455460so35176155ad.0 for ; Mon, 30 Sep 2024 10:18:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716682; x=1728321482; 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=1Am1750WxY5slKQ9JPH0IFp8T+o0hCjOvXnXFSzTaW0=; b=wPkOiNBZ18Zy1cw8iYfv5oyFNHfjnIkvQLXEIvW3QJTWbztxWXhCoP4D3VguUXkvYK Jt6VFyczFhqAnaixt0hfTFmucou5Ss25mSRcC+6HMm1cfMtHK3kbRmW0nye8Up740RKY MWjsgabiRAznrLc2JbjyHvy9607v8wY2lVzjzu5QB0DVAQ4T6k1569xti+WIOkFAt3cd rcvPL8aDSsKC5Wz2jbiVgM5dKrqJx1c16AIfdJxgEINKDl9QWqcMyXj8EtYRe41ciOKJ EDNTcueTeTSXwTqJVMolyjS1mZ/Yh6FF1qDwAmR7oTVo1zN24rs0sxGwTVFwNGoAn+jh 0TJg== X-Gm-Message-State: AOJu0YzWniLy6d9RdGOYHNAOX2lPrrSPO4EO8W/OChDkG+w83/g6GR5n GhIab+qjOVTUlahOcAW7D8UtUpCQ/wuEKqAuUOaQygQcT6mMzZe0VuLm X-Google-Smtp-Source: AGHT+IFGTyKRQydBrc2ct+YbqmUgTS4av8yaWaBXLuNa64BMObODPfZoc/Yv/GLC8W3DhPqNCvEBxA== X-Received: by 2002:a17:902:ec85:b0:205:4d27:616e with SMTP id d9443c01a7336-20ba9f059b9mr3960175ad.22.1727716682465; Mon, 30 Sep 2024 10:18:02 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37d8d522sm57057595ad.78.2024.09.30.10.18.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:18:01 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 05/12] selftests: ncdevmem: Remove default arguments Date: Mon, 30 Sep 2024 10:17:46 -0700 Message-ID: <20240930171753.2572922-6-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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. Cc: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 34 +++++++++----------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 699692fdfd7d..bf446d74a4f0 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -42,32 +42,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; @@ -613,6 +594,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 Mon Sep 30 17:17:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816759 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 244561991CB for ; Mon, 30 Sep 2024 17:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716686; cv=none; b=Q9BAZw6xaDy+v7SNUSFGBdnLOzty0pohxIdIsti2HRq3ageMTc5uSbgYZkbrj3QY/t+iXyev5rnbTpBeofRqhqi10J6l6zFu39ptcCtTr9zGXy5ndxf+Qb6LC4uwplFTEKed20w1mPzpBOcOTCJWfEzNQxq+FX5KmduSoWi8lic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716686; c=relaxed/simple; bh=ehq/ectSsxoqFc7/18XUmzKAFHtx4w8qrNK31G5AuGE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N7OJIbZ77FMzOTPfYav/XXjvS9/DQRYdY9DB86ce9bpBj32bkvFtkRHK7aXuq3jQc951EsU4EyshSmLeq2nPUrlKTt71vPjDbiD3E0G7lZDDUDwSzby6RUeUlx8d7OYe/DEiMFL97C4F0UsQev8WLAMjToCaOZ3Y0dQix4k5JTg= 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.180 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-f180.google.com with SMTP id d9443c01a7336-20b833f9b35so12022985ad.2 for ; Mon, 30 Sep 2024 10:18:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716684; x=1728321484; 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=hLKrJdKLbEdcAEPKkd7ffg4NcQaqGwWQ4w3NRbiabf8=; b=j29nDlQdkQr+kd6+ZAnUaoJee7hz6jDHyLaMnfjBV434XgahzczHfpznIpRpaAxkW2 q4KKR4kjXB/J1fqDe2lkN5+ZzPsR1Eu6JLmaP69+htcvO6zb3dCJhIXKl91VFkm/2tRS mX4Zuv2kHW/DSl/ijrx8PfekYRR2nrO99DgMDFZfOi6v3BjRM7MDLf0ChQD/OrOlBwz/ pEk81Njzbhhkj3llLAXs809UqBqB8fWgJfiJtAridqLCsHG3ihprfpjrJUHzK8TNxxx0 FcA1FdQYGbaaTU2dlN/KRgXk61ZX/W8tSksRR0c1AnRu9i9PNn6k/r+NZFWDgHUmf2iP mbhw== X-Gm-Message-State: AOJu0Yyrl6SxJy7Rvkyw5nQeFGQwld9wGL981lnfriFz2mKEJgkVrKlm U9T+j2OsmHlyrf7hdlsSfJIvtOxDbFy6Y996T4jvx/2iwsjyDp3iwlm5 X-Google-Smtp-Source: AGHT+IHjELcE2I7e2UQ8pYBRl7X2yTmQeLhVKmr+eSEr1G0Z0cYf+fXCo+w3ZriHGfdKJjuPvmGU1g== X-Received: by 2002:a17:902:d4d0:b0:201:f6e8:637f with SMTP id d9443c01a7336-20b367ca7e1mr224544765ad.11.1727716683990; Mon, 30 Sep 2024 10:18:03 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37d67757sm56538415ad.36.2024.09.30.10.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:18:03 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 06/12] selftests: ncdevmem: Switch to AF_INET6 Date: Mon, 30 Sep 2024 10:17:47 -0700 Message-ID: <20240930171753.2572922-7-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Use dualstack socket to support both v4 and v6. v4-mapped-v6 address can be used to do v4. Cc: Mina Almasry Signed-off-by: Stanislav Fomichev Reviewed-by: Mina Almasry --- tools/testing/selftests/net/ncdevmem.c | 85 +++++++++++++++++--------- 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index bf446d74a4f0..47458a13eff5 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -232,13 +232,22 @@ 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 *server_addr = server_ip; + const char *type = "tcp6"; + + if (IN6_IS_ADDR_V4MAPPED(&server_sin->sin6_addr)) { + type = "tcp4"; + server_addr = strrchr(server_ip, ':') + 1; + } + + return run_command("sudo ethtool -N %s flow-type %s %s %s dst-ip %s %s %s dst-port %s queue %d >&2", ifname, + type, client_ip ? "src-ip" : "", client_ip ?: "", - server_ip, + server_addr, client_ip ? "src-port" : "", client_ip ? port : "", port, start_queue); @@ -289,13 +298,43 @@ static int bind_rx_queue(unsigned int ifindex, unsigned int dmabuf_fd, return -1; } +static int enable_reuseaddr(int fd) +{ + int opt = 1; + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)); + if (ret) + return -errno; + + ret = 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 *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 < 0) + return -1; + + return 0; +} + int do_server(struct memory_buffer *mem) { char ctrl_data[sizeof(int) * 20000]; struct netdev_queue_id *queues; size_t non_page_aligned_frags = 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; @@ -307,9 +346,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"); @@ -318,7 +360,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); @@ -339,29 +381,16 @@ 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 (socket < 0) - error(1, 0, "%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 < 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)); + ret = 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); 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) @@ -373,16 +402,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 Mon Sep 30 17:17:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816760 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.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 C8DFF1957FC for ; Mon, 30 Sep 2024 17:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716688; cv=none; b=cDjYxsOzPpAbpPI+/T75n+Nlv51M/6mf10REPxUCGzdHSJDoMvWMoaKQtoSYr76W6vLBVHvHfNw6h8eHYD4CrkLOz57YBWhefvRrjl/kuY8u8StMfiAqjKcb87h7bEFWjvvmxYR//kS5EH4wxGClwJgdAuDusaN5ZEzHt+rTfV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716688; c=relaxed/simple; bh=mat5v89stmIyz1NOS6PrFFB6n20vGw2AVQ4ZCrezc30=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kMiY1NDoh+wOUsBeV5wS+9Vc8/QukEBQMAovWQVAqhdSLQi2LMdT0krA0WyeUdMNjFT+8zZQ/+zeqGepklQXBhrXnu+N621hyYvYEhFkk9RqJ+GMt1Sj+3VhUI5pCogiU2U+jGZunnirIA5JfJn1N/sWtnht1jsEOif/VbAxFsk= 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.167.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-oi1-f181.google.com with SMTP id 5614622812f47-3e399ca48f3so1375504b6e.3 for ; Mon, 30 Sep 2024 10:18:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716685; x=1728321485; 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=N5K9amt/Km0z6IjkBF+yG1dWFEwRkvs0nmjjUE5BXEw=; b=TMBjRYQ/KNacqCDJTtum1UMN+rPMgh13149NVDW23xEIynJKWaHTb5WTyBDQCPChcJ NQ0Nfhl09PA6GaQg6ewVdo1jJd0ULyqVnEa7T3vFlOHZLHiSOrk8bPma/p0uV7g/q0ZM otxia9yiW/LRnfxlUnkG5yKVW/U3cImMkVY9MNRnAiSXWixWdbY8Itc+yNOuy3kyaHgC iFKRpkdhe8x7NhMKXySLJFVlOH+tjDYFrfg9RDQiUskv8sy1wM3KcN0Bl9ySqe6+h3bd J4H+yPdiy2JgcHaeoumYy0SRLZV+e2AcIwU+/CW0LNNboAu2swVrUNRuD4R7T4R8cZwf Fstw== X-Gm-Message-State: AOJu0Yw7ps90k1zXfyNdqHo3EHo6zhrm9PFEZOufuUBK6E5V3SicMxO6 SQDXiheatNlv827RxHTiilgBYg9wPPE7rlHiy+1UT7V0UxtmFLp6w/qz X-Google-Smtp-Source: AGHT+IGS6eOfoUEDeWpBBJP7vuYC6XFegvNnzLp10Gnionp4cnjjo+K6iLWddYBGAYNjOAMUuAabPw== X-Received: by 2002:a05:6808:238b:b0:3e2:70fb:2216 with SMTP id 5614622812f47-3e3939e1b38mr7139749b6e.41.1727716685606; Mon, 30 Sep 2024 10:18:05 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e6db2c876dsm6811332a12.53.2024.09.30.10.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:18:05 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 07/12] selftests: ncdevmem: Properly reset flow steering Date: Mon, 30 Sep 2024 10:17:48 -0700 Message-ID: <20240930171753.2572922-8-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org ntuple off/on might be not enough to do it on all NICs. Add a bunch of shell crap to explicitly remove the rules. Cc: Mina Almasry Signed-off-by: Stanislav Fomichev Reviewed-by: Mina Almasry --- tools/testing/selftests/net/ncdevmem.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 47458a13eff5..48cbf057fde7 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -207,13 +207,12 @@ 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); + 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 Mon Sep 30 17:17:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816761 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 1A6A319922D for ; Mon, 30 Sep 2024 17:18:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716689; cv=none; b=KwkCRZcPC9PahoOAanMC2WDeTAhQadtYXhq4HhltKtIqne3fmRdrV+H0nObHbxei/UET4FguVxpRD7L+0y1/Khj5DSNl+E91Ggy5lO3tw/lF55l6fJ6VmqV5CtdlU7bNmdpfzB+34FTRvd4Vt7uWRUfpjSwYa6seGqVh90j00G0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716689; c=relaxed/simple; bh=DchTwohJsAm9ztDbrxiO7lBrit40qg4YFTMOJURrdl4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EEd+S3jg7njSbR9bPqwike0ExGrON4ZLBvVeAxbJYehSwUtf6c+4qbXYAi4Bs9Uy/Bgic44h7ofbpGdUBq/E52ISdV+jTrrUU9clilIADDivcjUkCnFdxms76kDivpbpqBpoAJi/othzh/uAYpaUWVouBeYXTKrqnwdw6NApGYg= 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.173 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-f173.google.com with SMTP id d9443c01a7336-20b0b2528d8so51020435ad.2 for ; Mon, 30 Sep 2024 10:18:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716687; x=1728321487; 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=Qm/BiP5G4zd1/28qh8JWsTl9oMWQWTePUlVBIOmJBLY=; b=lRoYPa9R4LMx9SObYEFdiWoLXJj5RdjRlqnS2x/FOm6IDtrCbj3y0/m4n3gs4QbctE wAho9hZ+8Uz2BT/XUdrs1CG+MXkebW40ikkIB8ZTox4t4mMQLfQ7ceSKs+IaTZeAMYos XieusnYuFVj7Go1bbm/bcrxnDD12zk5XMWK1Sf5RK1vLP2avYM8rN3FUzqsTaOK/NfK4 KiLeT3DFjRKwOZ25kAkZpK9YPq6FTBsD0QIwZeR7p7hIf2Wx4+0eAukPJDQqBiSQSGQG eCfCM5gFSr+Dtk+AgMJxC8UsYyHam3ld1wFN0xFtjxJuNgJQxKzsQKGHOJF/vX/zN65g WzTQ== X-Gm-Message-State: AOJu0YypHRJPEXIN++k0DiQxzJ50A4ohRE6AytuB/sjgAwAc3DV1o7uZ /nCfDJjLAsb7tcQNzI2oj0Uur8+09DeAWLwq+nb28eWIPwOfXSqynHN5 X-Google-Smtp-Source: AGHT+IHVPlJe9DUgw0z1GDKkliuMRleHui99SwTPn0rpxRJ97jU+y4XirIWkq2mocdAkfl46KnZtSQ== X-Received: by 2002:a17:902:dac2:b0:20b:85da:a6e5 with SMTP id d9443c01a7336-20b85daa92bmr74371315ad.8.1727716687260; Mon, 30 Sep 2024 10:18:07 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37e5169csm56842855ad.238.2024.09.30.10.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:18:06 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 08/12] selftests: ncdevmem: Use YNL to enable TCP header split Date: Mon, 30 Sep 2024 10:17:49 -0700 Message-ID: <20240930171753.2572922-9-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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). Cc: Mina Almasry Signed-off-by: Stanislav Fomichev Reviewed-by: Mina Almasry --- tools/testing/selftests/net/Makefile | 2 +- tools/testing/selftests/net/ncdevmem.c | 43 ++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 649f1fe0dc46..9c970e96ed33 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -112,7 +112,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 48cbf057fde7..a1fa818c8229 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -28,10 +28,12 @@ #include #include #include +#include #include #include #include "netdev-user.h" +#include "ethtool-user.h" #include #define PAGE_SHIFT 12 @@ -217,8 +219,42 @@ static int reset_flow_steering(void) 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_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); + 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); + + { + struct ethtool_rings_get_req *req; + struct ethtool_rings_get_rsp *rsp; + + req = ethtool_rings_get_req_alloc(); + ethtool_rings_get_req_set_header_dev_index(req, ifindex); + rsp = ethtool_rings_get(ys, req); + ethtool_rings_get_req_free(req); + if (rsp) + fprintf(stderr, "TCP header split: %d\n", + rsp->tcp_data_split); + ethtool_rings_get_rsp_free(rsp); + } + + ynl_sock_destroy(ys); + + return ret; } static int configure_rss(void) @@ -354,6 +390,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 Mon Sep 30 17:17:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816762 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (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 4DF44199259 for ; Mon, 30 Sep 2024 17:18:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716691; cv=none; b=rhM7HwOtWY0d3ePdRUIOP1n4HxzBkvSaEK/iPj9I9RORW4bKLdquLnRIoOCPycH41CIngy4egxmQ8goijsuMr6I4Oe3g5c6MQLk5STCjFKZasb9Pl1t8crH3rfy48MH12obzV8gS1/HOkuExvcMnwz4kuJJLd7PcNGiB3vtOeqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716691; c=relaxed/simple; bh=qYRlGVnaaqv8eSx7X6S4XG72C9yMTQv+zK2ngSN9Wr0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HK/WJEmh/oa81UaZhA9BNYX0sGG3u14MBom9+TYnr0aNzgNEoafjJzrro0EyfvK8m0tE1jRy0qsrCxVv7bfRgwORpfRWbk1vfh9YUk75SLSyPTT1+8t3YouyJCF91i5b+3bDTfY8WI6vq2dLDsEW6/UTkNNgbnPqtr6vckuOZ3I= 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.167.173 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-oi1-f173.google.com with SMTP id 5614622812f47-3e039666812so2422345b6e.1 for ; Mon, 30 Sep 2024 10:18:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716689; x=1728321489; 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=g+G4c17G8hd9HZGpYLt07D8EV4bOd7F7lOCgcyvo2vc=; b=C/TQAxclEhTbIhrOdAdqXqGEr0mHFo1E6BcK9tsiy0eea4oybIOvS+NAuAxEYiqnRB gppJnlWAZdM6OUrwPKLaNqQWYhVX5G9v2CANFwzQanpPvIwrSUo4IbCwrAWJPyU69sid ljVB8sic8lBy4Py0nThHMrzW5aOWnSN3l/MdbFUXwXmdnQqC54oAs3lE/anogAzB4rHd Q5fSnIWUZKAtQBgmDu4MCSAo7HkEUBX1USZam/ECmvClqzFg6k0IIi3A0SFuk0k0cDcG PCQ+V0g6BRE3eZZN64cE62R22RyaZ+wpGZ5NzVhGATwxjTYCMKZs/UuT3fAIfXSnmaaX E/EA== X-Gm-Message-State: AOJu0Yx5s6bOnNR8ONUJzzyvin8Y7OxzIg+Y/T1piy+S8SE31voxvOj9 le3TqL7J8YkB1ll5K9BneUjG2JrE/ZNwIAs+LLPoZR0tKsZw2PT6l085 X-Google-Smtp-Source: AGHT+IHZGXV46Ci4q5S5p6V+KJ8eBzgcbjCNFWNOwFDV7gi/D+gjb5d4cwHaZoAdHkQTJnqk/8uwag== X-Received: by 2002:a05:6808:338b:b0:3e0:83fb:ec24 with SMTP id 5614622812f47-3e393967c1emr7428840b6e.16.1727716689226; Mon, 30 Sep 2024 10:18:09 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e6db2942ecsm6809999a12.6.2024.09.30.10.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:18:08 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 09/12] selftests: ncdevmem: Remove hard-coded queue numbers Date: Mon, 30 Sep 2024 10:17:50 -0700 Message-ID: <20240930171753.2572922-10-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Use single last queue of the device and probe it dynamically. Cc: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 40 ++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index a1fa818c8229..900a661a61af 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -48,8 +48,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; @@ -198,6 +198,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]; \ @@ -672,6 +699,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 Mon Sep 30 17:17:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816763 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B65B197A98 for ; Mon, 30 Sep 2024 17:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716692; cv=none; b=fJvJTLHPLPKofKsc+qSmquwWmDtLkOcyWyDARM2Eg1zBIuA6RsKkX5OvdJJB7gnKkYzREG5R/6m5544zWVczzCHL11gJkaXp3GZZy5SzlhG24Lj9OqPRxFrCFZkAFAc18tVAi5g90mG8oz5wqtFkf+VHyTGlovy+lvjqjCWkKYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716692; c=relaxed/simple; bh=Wi7OcMjqw1UdGhUi1KtWoiJD1zmWDZd3H1A91Bd+TwU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CU0MmCBu9MzOfyFx440P+/YlIeWNBaGf9KmpQx0TxioELfWZ6vlx2tmMUq2Ow4C/TD/VxpJ9AAdgaAg/OlpyJErVn8Azp9riz12T3PxEgMCV+ovNflp1DJZf4PHall0DrNJYwCYKkUFvO+U7l2P7WjiKV+1KTFAaPXslTRVj8qM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-20b93887decso9139295ad.3 for ; Mon, 30 Sep 2024 10:18:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716690; x=1728321490; 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=TztfDobfhyf+myTs/dQ/tIdBGEBrp1wqtHoLxjzH6+M=; b=k0PuAHxZTty82JeG0/Clw4iXJV70Wa9938LYTVFhTEwlEGWS7CKEumwDwVC6vUaE/H m80EtVKWEAZGWqOztJyC0b0nphB8XwyQF61MUVoWgNFxHdcQyzrlA28xwINWsmYof3c3 aVOunMzX7Vk8/fAXlHqTTbMY8LgwPEqLb1KCzCT2nvxawoIGxueltL4KLPAiw1xH4QGC aO9gzzDE6Y0xOUnEdKJBh0MfwqLRhbSyFa89B6ejrydE51iXzBlctppKiX1/RKOVO3Rq ubBXaodCB+3+HtVsBY1mVeryndhV1UtPGRCueCf2UdAB4xq7UEpZh2EjdRnKfy92TY9k XVig== X-Gm-Message-State: AOJu0YzihNBoQ+Whtjkc23qqqr4MWqC1i+8++hXz5n087OyQkB7YPkIu 4RWc09ONp4s8Fm1X3UHy7psWzgikzP7kHgEsw7NaUfcpiZj82wugsIkb X-Google-Smtp-Source: AGHT+IGVGHG3YqfeFmm/NWzjeAeekPClNgfHoNy9x7TZNuTGpaSHa2inXKp3Vo3tawdW8BLFXtRxdA== X-Received: by 2002:a17:903:2452:b0:20b:7210:5859 with SMTP id d9443c01a7336-20b72105b5emr92229585ad.38.1727716690427; Mon, 30 Sep 2024 10:18:10 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37e4e627sm56807735ad.227.2024.09.30.10.18.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:18:10 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 10/12] selftests: ncdevmem: Run selftest when none of the -s or -c has been provided Date: Mon, 30 Sep 2024 10:17:51 -0700 Message-ID: <20240930171753.2572922-11-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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. Cc: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 27 +++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 900a661a61af..9b0a81b12eac 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -688,17 +688,26 @@ 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 (!server_ip && !client_ip) { + if (start_queue != -1) + error(1, 0, "don't support custom start queue for probing\n"); + if (num_queues != 1) + error(1, 0, "don't support custom number of queues for probing\n"); + + start_queue = rxq_num(ifindex) - 2; + if (start_queue < 0) + error(1, 0, "couldn't detect number of queues\n"); + num_queues = 2; /* make sure can bind to multiple queues */ + + run_devmem_tests(); + return 0; + } + if (start_queue < 0) { start_queue = rxq_num(ifindex) - 1; @@ -711,7 +720,11 @@ int main(int argc, char *argv[]) for (; optind < argc; optind++) fprintf(stderr, "extra arguments: %s\n", argv[optind]); - run_devmem_tests(); + 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 Mon Sep 30 17:17:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816764 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 1F7C61993B6 for ; Mon, 30 Sep 2024 17:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716694; cv=none; b=k+0qvOll8DdLX49KBkOFHXQnxk+TFgsCrHiNtaw9FDMJBV5ILZNv0f7DMQ0W59SkiyHWXWyFFZG+6NddANG1+63Oamc7A+w6Izb7/rMnzA94A9opupJecaje5HkaTP5SeIDJ6v8C8/JRXRnnrDxqJuQnog7jtw3UrGtjo/W+oIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716694; c=relaxed/simple; bh=vMNcy5rp/19kLtTFFRT5e69El7Ugk1upqapaGfCCX64=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HHZZaPyxdy4T0eXrNJtvMeTfHaykdn8jQ9u3Fs5yJexbN4F31ARb3U3LHgOmAezAj1U8mligE75C3tRBCe7DBkyagh1ef1H8vx6ow4RyYXHCW/WLYBHJxNK9QefRkHzneJybvgaHfffpRSbYuO6X3w86vS+Hnl63xn/pKILff9E= 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.52 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-f52.google.com with SMTP id 98e67ed59e1d1-2e0a060f6e8so3044037a91.1 for ; Mon, 30 Sep 2024 10:18:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716692; x=1728321492; 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=SSSLtD8diYjIU3ryK9k/GhGnK6d7d0bOVmQH4VUjHSQ=; b=JNAr8bZe6n7dohr+drx6AjSmzndBkmt4nrMVUZ1IGGhHTBftED2XAQSLiF0i9dXC8x yQCD7fRfiPJt6tbA03MHRoYSjv3b9V0lyts5BLmtWy/XarLfpdgdjk/7iVzsTkUjjYPk J0Lf4PNzzOowBvVp+WdRWvDzTqdcEpjbRIBlimg4ENwUi3XyDU5SC9ox/r+Bn1EoeVkR 5bxH6V0C6FrOCPHmsF0G+Wdu5kwQZbLsJBUj6NdakqODjn0XjmS4GkcGshNUczs6zKTQ 0PWqImrQp6HS80/I2QQUJRKRYLXeWjk60kYsHuhGMweoq+K//RRsF5Gj3DoudjQ4qtU0 2Gfg== X-Gm-Message-State: AOJu0YxdfZJFqgoGL8EYuaceEYCvsC0v6p/uqFP7JUtsiQmaZ3vfWQty Dyy2dWiIhbc4hCHK2Ca2RZZGRCA5uW91+/hY1dZrWtF86B3m8DX8IxLA X-Google-Smtp-Source: AGHT+IF6oCENfzoOcXeU15zolTEBlhvagDBqBm1R6ZeDDry2v7S+oqs0hXArDgDmZB8WtnbbB262lw== X-Received: by 2002:a17:90a:bd85:b0:2da:8c28:6561 with SMTP id 98e67ed59e1d1-2e0b8c4c097mr14004423a91.22.1727716692037; Mon, 30 Sep 2024 10:18:12 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e0d4af744bsm7168382a91.23.2024.09.30.10.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:18:11 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 11/12] selftests: ncdevmem: Move ncdevmem under drivers/net/hw Date: Mon, 30 Sep 2024 10:17:52 -0700 Message-ID: <20240930171753.2572922-12-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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. Cc: Mina Almasry Signed-off-by: Stanislav Fomichev Reviewed-by: Mina Almasry --- tools/testing/selftests/drivers/net/hw/.gitignore | 1 + tools/testing/selftests/drivers/net/hw/Makefile | 9 +++++++++ .../testing/selftests/{net => drivers/net/hw}/ncdevmem.c | 0 tools/testing/selftests/net/.gitignore | 1 - tools/testing/selftests/net/Makefile | 9 --------- 5 files changed, 10 insertions(+), 10 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..7bce46817953 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -26,4 +26,13 @@ TEST_INCLUDES := \ ../../../net/forwarding/tc_common.sh \ # +# YNL files, must be before "include ..lib.mk" +EXTRA_CLEAN += $(OUTPUT)/libynl.a $(OUTPUT)/ncdevmem +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 1c04c780db66..923bf098e2eb 100644 --- a/tools/testing/selftests/net/.gitignore +++ b/tools/testing/selftests/net/.gitignore @@ -17,7 +17,6 @@ ipv6_flowlabel ipv6_flowlabel_mgr log.txt msg_zerocopy -ncdevmem nettest psock_fanout psock_snd diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 9c970e96ed33..22a5d6a7c3f3 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -97,11 +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" -EXTRA_CLEAN += $(OUTPUT)/libynl.a -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 @@ -111,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 Mon Sep 30 17:17:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13816765 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 9584C198853 for ; Mon, 30 Sep 2024 17:18:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716696; cv=none; b=jmjqUf0XD+tSHGbk2GoV9G/7jhY80cf+PtmZVPwnRmNZdqBGws4+FdFWWQbqtneFhcQVC6r5AJQqK4kVWK2Sf/G68Vo76Iu3dy2wlmtoMywBHW6lNtSEeXAFxF/v3mitl5bygx4vUtzOjIWNjeV/4rx15qFnEd3RQWDCQ8VaExQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727716696; c=relaxed/simple; bh=sDP/mdVU0pmVlXrVoHaR9PIgvC/ZdssS9P6tKGZjrLg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CdemzFwYHrGIMz1Zv982qMV37pT0I0C/m5gPeHvjU2bRv0zttdfJqvSMthf3v48DGEveHIn/2L7aYrjtPN4ORGyztVqiBPwnJ2EGMIjQWHInj+kY0zUzX2mD08dr7lM3pAY6IyyllM+/j32GU/LMpzS+poH6g4psG/E3IrKeOWI= 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.173 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-f173.google.com with SMTP id d9443c01a7336-20ba6b39a78so3427805ad.3 for ; Mon, 30 Sep 2024 10:18:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727716693; x=1728321493; 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=nJyN3pBvoyo39KdM1J+u0iy78SMZF3WVQmI1dSkIgrw=; b=wIs/tpRXUTnwCu4G9wYiSYLWNEA/M/HbnYAVlEPmmocUenzWdlJekV2VVIE8ebgNXZ Ygy+p8+K7YiIlB7BAz+d6GjCD39mKqQot0FINsIgv7WTmgNa/Q+5cI0zd9cmlx13MaCm sE9ICIkLfOmHD1rqt3/mAQnqt/HF/XodiyY8zGByiqA7Kj1vj2jszHThsstX1zlVW8/D QH4rn+0ViG3JPG8etm9zKSLDbhLBgfdmFIy0balXjSIzsN+QRBMPDa7lM40EHp35CI1k zYd7X3qwBL/5rKwEfdAHWIFWhnTDw4fWmZQqN3i4ZwidLL86jUJHRObHxL+v6Cs3IBfE Bsxw== X-Gm-Message-State: AOJu0Yw5zof/5Qw9pQlIrrGD7+b9eICn097y1JoUBp9+Hp4hCb/fkKF/ zfDW1U3QMCM0p05rVPypuQlWNWsfzkkqn3Z5W1Z4L61GAFED+lAV9GQ/ X-Google-Smtp-Source: AGHT+IFvjy37vN5TVj7vBAB41A+9dNgkSGepzm1ZccHXJukK2ZH+VpLfDt43QFlCSMg8fPXqtr91HA== X-Received: by 2002:a17:902:dacf:b0:20b:8109:2c87 with SMTP id d9443c01a7336-20b81096217mr60926095ad.6.1727716693530; Mon, 30 Sep 2024 10:18:13 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37d60de3sm56853205ad.41.2024.09.30.10.18.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 10:18:12 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Mina Almasry Subject: [PATCH net-next v2 12/12] selftests: ncdevmem: Add automated test Date: Mon, 30 Sep 2024 10:17:53 -0700 Message-ID: <20240930171753.2572922-13-sdf@fomichev.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240930171753.2572922-1-sdf@fomichev.me> References: <20240930171753.2572922-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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" Cc: Mina Almasry Signed-off-by: Stanislav Fomichev Reviewed-by: Mina Almasry --- .../testing/selftests/drivers/net/hw/Makefile | 1 + .../selftests/drivers/net/hw/devmem.py | 46 +++++++++++++++++++ 2 files changed, 47 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 7bce46817953..a582b1bb3ae1 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..29085591616b --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/devmem.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import errno +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 nc: + wait_port_listen(port) + cmd(f"echo -e \"hello\\nworld\"| nc {cfg.v6} {port}", host=cfg.remote, shell=True) + + ksft_eq(nc.stdout.strip(), "hello\nworld") + + +def main() -> None: + with NetDrvEpEnv(__file__) as cfg: + ksft_run([check_rx], + args=(cfg, )) + ksft_exit() + + +if __name__ == "__main__": + main()