From patchwork Wed Oct 9 17:12:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13828837 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.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 CF901126C17 for ; Wed, 9 Oct 2024 17:12:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493977; cv=none; b=q3mYox5PSnai26Z7BWlxwe/WrW9KrtBeZqjqz/DOTpjltHBydv5uL13aqY8iv+48uav6dN/UF+VurVsyJ8OIrVtwsN407LXyqcPDlYCQmI4UMp1r6OJmIyOP25HQaTKdTwAUDdlHuUK8KE1YVLOU8asiflsQUgm7ob9DeqWK9KM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493977; c=relaxed/simple; bh=DbSfoMlzpZVhU+8FFsUY3AHTX/zbUMYdVXfjpyEzHfU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b7mprV44TaAp/oAro241SDSUzhu0SX2Yo+p69wA5B10/3/Ja+FhcjwvM/CF1j0dYFukJOq5wQ1Eg3k3/+DDi8Y41BqePIIUaCxFg4Y7Rc0AZIqlgmfOTCQZQr11whl5gkRNgckymb724BmKkHC9ntVt5zbpM+8mHMlwCITMTDvo= 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.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-pg1-f177.google.com with SMTP id 41be03b00d2f7-7db908c9c83so4519022a12.2 for ; Wed, 09 Oct 2024 10:12:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493975; x=1729098775; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fYIgIfdOM+KXAHby1i+hfUVdj9h7/069nIsE/U1uz/s=; b=f7+KCpIKfAw1JRfJ06PfJqLdP6jmm7H0f9iEjkTHzReGgBjtvzyd+gnLAyaJlm/4Tq ouI5WpRvc+U2ljouxctL/SCmYy1d6I8xQJhM43SJuLVzi4hUhybqsbz4T2DLNQgvGH57 +nIKvs6AWrLJ+LysI6kA6tye47/eliR6mdQI9ZhbXN+wSQkLeaKwf60jXgU9bjfClSc0 tH+wMHsZgun9R3n6MvzpUg76vEhU6Qud5m0wAWo1KKh543p6UhonfM86aeukPz7fdrEM 2GUTwAlmGj3CiRssi33oN61K1JxiOufHcXPLeQgOUK+LcwS0Af+xXrNY5oUQRVgEjrDw IN1Q== X-Gm-Message-State: AOJu0Yw2WM+N/3GKG9w49MzDGROFgO6aQ4VEYb+xDnuTUTwJ+aKLVzqL ++YeKmtx56/Tu/KtcPLg7gWpX6XSUaDv/iRUWO8HbiW1103DwkSaVz8g X-Google-Smtp-Source: AGHT+IGCzknJBKugY1sWVLPyTEpYvHRGAV/e3BhlUyD4G7uzZOoK2iVZ4ADVRLCrOb0pQFFXtm/Nrg== X-Received: by 2002:a05:6a21:1643:b0:1d8:aca7:912 with SMTP id adf61e73a8af0-1d8aca7102emr1642105637.28.1728493974706; Wed, 09 Oct 2024 10:12:54 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71df0ccc4b2sm7977845b3a.45.2024.10.09.10.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:12:54 -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 v3 01/12] selftests: ncdevmem: Redirect all non-payload output to stderr Date: Wed, 9 Oct 2024 10:12:41 -0700 Message-ID: <20241009171252.2328284-2-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 61 +++++++++++++------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/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 Wed Oct 9 17:12: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: 13828838 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.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 03DBE1D0E38 for ; Wed, 9 Oct 2024 17:12:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493978; cv=none; b=Kn8tz4Sw3k9qrFwJzdl5iJdKov70QOA8b/W1ifr1t7z0I90tvWHQGiWi/ErPR5YJjaz1M4NpYD+eFgaTaPCfb8a27nyN25zmOtiBYRpRUGEGAchlFHprNJ5Q37dybJKwWTe39xvlFlZwDm4qvbsgBPxKMMc/qwoOIICKtos2MEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493978; c=relaxed/simple; bh=uDxOm844VsAsi9UnMdkeV0AtSZv36ezRQCbCtTNGPfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DsfXpFdj080bJdtEYDq24DDeTX40oqgV3XjWJ/Ftq1YKeAacBv8JWSWbyDNYKD7UF69+x1SBT1vaU+vj2OkPlYrifNCqWuggcVbkQ3l3pewh6tBmZTG1V9yEicnLCxoCPnv9NgcN8pfPDaQCNAv9yIYtkRSX4AFgnOMzSOOduW0= 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.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-pf1-f182.google.com with SMTP id d2e1a72fcca58-71df0dbee46so39924b3a.0 for ; Wed, 09 Oct 2024 10:12:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493976; x=1729098776; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jJEggviDo9R4Ek8kHMFcfr5AkXM+HxfAn8Vpwc2O0pc=; b=B2ZdhCiLyuccu7PVZK20BmOfjSUS6tSARIf0SvSYYVuf5uuNn4z0FxGkAf1oTWLCOe BKCsnBZudJfKLnYflBmNPWBmlrWAk4YDiQn8V1eAC0Vu9mgdFs/19P3eMCJ/1Yt4dQfM 4LkihedOJAUgSxrGpooI2LH0E1W3xTJT96fFmmUiEv+X5ytbtbkv88AYayG/nWpTDYDz eYXDSarrEPHZa+BtgxL+NNjljERazbqlhkyWW/Gngsr+yrAvkOr20aRDtUlT9jFV1MFw clwcjrjP/bcsQmf937oaAwPU/juByKIK9BFXa8jAqXdg/g8n5B52ulXx9ZyvIKxZob14 WLZg== X-Gm-Message-State: AOJu0YyrqdXTvC95/GId8NedjqNXHCDF6S/VIj7LKrwqafMqP1l9QJcN TxkVQnppEBfKF+SYC6eCuUqoCW5GL8vezfvY0SfeK5P/fMKfvDE7BpRJ X-Google-Smtp-Source: AGHT+IGJKxn+lmdg3Jzb8qbdW22SoG2e2wM1m/yk2enHXdkv1h9kzUWcrMhxTOYZAOni7PCBfXrH3g== X-Received: by 2002:a05:6a00:8d0:b0:719:1f10:d1c9 with SMTP id d2e1a72fcca58-71e1db6490fmr4712822b3a.2.1728493975908; Wed, 09 Oct 2024 10:12:55 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71df0d6525esm8030215b3a.161.2024.10.09.10.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:12:55 -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 v3 02/12] selftests: ncdevmem: Separate out dmabuf provider Date: Wed, 9 Oct 2024 10:12:42 -0700 Message-ID: <20241009171252.2328284-3-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 198 +++++++++++++++---------- 1 file changed, 117 insertions(+), 81 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 9245d3f158dd..9b3ca6398a9d 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -71,17 +71,101 @@ static char *ifname = "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,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 +487,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 +498,11 @@ int do_server(void) void run_devmem_tests(void) { struct netdev_queue_id *queues; - int devfd, memfd, buf; + struct memory_buffer *mem; struct ynl_sock *ys; - size_t dmabuf_size; size_t i = 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 +513,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 +526,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 +539,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 +548,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 +597,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 Wed Oct 9 17:12: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: 13828839 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.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 EF2331DFD80 for ; Wed, 9 Oct 2024 17:12:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493979; cv=none; b=Dl7OTh50rl6Vej8n5W4IAGu0BdfgIZB4ACetabLyNt0Dk0r8vFXao/gQNtFsFLh1HOfUmKadACJYbCLWf6ONPDRvF2RRxx2O8lOeLRstvBLnWw9eXDJkL0Aat+wpXeD57iP0FD7JN1AlRhJF4+v9euRAtwyIZbtxLjreCeoVO5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493979; c=relaxed/simple; bh=IqvhzaUkJpjWKA7GF9EqRtKyUon0BB+Qggq6D7pfr0Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cwwFiXGvTo4MzWGGEGCY5NIirx/f+7ZZ90N8SPkt8uw8lWMy73b6Tru7EduBangfL55g3DxiLeL2fTXwbqEPQX98NdC30SdoZM962509YTxeddk1gjuerpNc6UzX/kX19w03H6ooIS+K/TqRJB45xTNc6yNL0aZs7gf2Tw+Kn2I= 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.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-pf1-f176.google.com with SMTP id d2e1a72fcca58-71def8abc2fso35244b3a.1 for ; Wed, 09 Oct 2024 10:12:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493977; x=1729098777; 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=oEB65DWGffO3kOcCBYySHyRKPvvEVxSFR9JywrzAoT8=; b=ZYo8gsxmooLw+PWY8AOZq5/qKlwxDFF5VzxKY3NpD5Odx8J8sPP/wulfKUDU4Nz/Mo 62qe3QZImLynbAvoxXrb0/OuTJ+9BiuKRQuguvc53FWv0Zgozo60lTBNHInX5RIqNSdU L/JkwMxEM972mHtR8ZfWdOnQ830vcq3VTyEM4nMYo9ulBFnlGmz3B3WjzybVXDL5ichM oqzbHmsuzr3xQy+Ayv6QIu+QvsyNXRxQ10qL1wxeHXKUQQehKZxEJAD+aGqYL4ABAAF/ vpI4KThfyKePYeeBgyFoLsYFnecQ9vA318yafqyEf/kHs8xBPZkWMZxkfSq2pqucC56F FbMA== X-Gm-Message-State: AOJu0YxT6Najtj7YR402rHZzCEtDsr3zvT0Vsbc0ryk0ZodITJWMNYK4 LPD0x0nTc8ZHbPzNzK+wOxtANq5jDA9OheQJq/KcPj0BI83ip4MAzb/l X-Google-Smtp-Source: AGHT+IGaaqFQBcMTGpCJGFCUQ23/bCaUMM1U7TXm0CDwu3JGCKMi031VWVXM4EjUyHdSYTZtwobdFg== X-Received: by 2002:a05:6a20:bca6:b0:1d8:a899:8896 with SMTP id adf61e73a8af0-1d8a8998977mr2180318637.29.1728493977065; Wed, 09 Oct 2024 10:12:57 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71df0d69246sm7982851b3a.182.2024.10.09.10.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:12: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 v3 03/12] selftests: ncdevmem: Unify error handling Date: Wed, 9 Oct 2024 10:12:43 -0700 Message-ID: <20241009171252.2328284-4-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- 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 9b3ca6398a9d..57437c34fdd2 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -340,32 +340,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 Wed Oct 9 17:12: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: 13828840 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E60A1DFE0E for ; Wed, 9 Oct 2024 17:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493981; cv=none; b=nKP5wllaQx4Yjxu/LcEVH9OS7j1yz58JDBsQ0AEWwMfVyiBCFsR1paYqHNBMo5ae/ceRUOMMTvuWRtLVg0ZbzdUxmVNgRrDAqfm/orxsc//BNYJ+7NLKLrZyiHd5Cx80CmNjLBqsjLt0V+8z6BIw3yR1SFuHpf2IVe0zzhGE9OU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493981; c=relaxed/simple; bh=FmldFMIB4EfRQpjNGb4dcSgm3bpFknowStTac1Zm0Cs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OMWvBot5jslrsk8NgYZOOLzOn1RxyhVzDydrgeavoSJKepqkm2GJ5Mz5Fhbj7NO/uFQnjoSFfpat6ruYDHm4TGWszvfulTa29+zsRqTfxhlRz4Ji/iZvv9/m0TEd8ERT7sOHNNVFRg2YFm95d6txZpk4LApkMKvb5ZVPe2bgQ3g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20b86298710so61344865ad.1 for ; Wed, 09 Oct 2024 10:12:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493978; x=1729098778; 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=UrCMEjPsFSH2LyCZdX13Hj4AEMiB0VKRqhFYl7onOmE=; b=O9jwYquLFKM7VY+j8NDdIBZcg3TrEC8RWFwrjzmPsqURTCRmMwasBDHhq3kzx0jEVD Y+M3z3lqjnbcDzw1vlGWidAz2L/8OYJRAoHi+A7J6KBmTaros2a7RvUKAplHvYl66uwd 9QrAGukIdvrYqoSFzBzUy19KaIKkjcdSw6X9o94hivc5vyOZGfu7uG1KPDcEpZeetjG0 lt3ZjxIyy85I5yGIMJ83Vzb0sDWS4u7abwfPFfMwWkrEWcv+CO0eEkQ6utqRJQfW5cid LqqVLTQprS5xaiNbd5CuvQGkSh1bycV8+vsKvgFFfuPel2r0DyptPHIsisGFoWq+l9MS jV/A== X-Gm-Message-State: AOJu0YwSmCQH5Qg+TXyPqOxXhGt1ojLyF6kEvT8O69B2GREFHeXFHfVn JFf/zantc2+Bf8iGRMOsAmd3HSdRHWq+VLO/nf5Wc9Z8KXDc0CgRhL2P X-Google-Smtp-Source: AGHT+IHLSCy5s7aqUl4Qa2GzV1FEUjzHkhQDQF8mTpvv2xWpId/SLHsxUkmZtJjDdb/7K0lCI8xK7Q== X-Received: by 2002:a17:903:244b:b0:20c:5909:cc48 with SMTP id d9443c01a7336-20c63780190mr36392235ad.40.1728493978087; Wed, 09 Oct 2024 10:12:58 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c60dc72c0sm16311165ad.100.2024.10.09.10.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:12: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 v3 04/12] selftests: ncdevmem: Make client_ip optional Date: Wed, 9 Oct 2024 10:12:44 -0700 Message-ID: <20241009171252.2328284-5-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 57437c34fdd2..2ee7b4eb9f71 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 Wed Oct 9 17:12: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: 13828841 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 38F831E04BF for ; Wed, 9 Oct 2024 17:13: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=1728493981; cv=none; b=BfRPY8L+G15iiAnAiHUoEvLVZyKTNTdpXoWUjJEYXeWuHkg4iun7OsQ71RJ6I3p2J63VZd92euw2NS+ctwiQRnQ+NWrcwl/v9CyUqSR2ra7I1xkieqYLTeM01eoZnqXEDc+klz7XcnidWthkO26dUm3ogvLNQM7vC5mJWXcfIfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493981; c=relaxed/simple; bh=Q9XouAJAMxZkDAHhshqh950WBwXQGagiWbRZjmNXB7Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uiqXQQndgqwshezWXmYZPMtm5wqaMlgLATSwvUhVUaZdcPSQ/UgEeSaCXvAN0QJJPI1ZRb9J148MM11HGXwAk2i+PriNSHnQXpSPp20tHY5jn1zP1jykX+CBTHD8FQ18AEly172cjy8ZrZtkGXt9F3FXUiBm7JcrQZknLvLvR2k= 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-7cd8803fe0aso6772a12.0 for ; Wed, 09 Oct 2024 10:13:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493979; x=1729098779; 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=xxn4VHXUc/ouDRHYAGg/9EidMYk+lmD6ujLsvzqZiYw=; b=R7euU4Q1TEluQ/Fi5FTAQ9Iuhg8spmhDsjdvpqqFiMahtgSQ+WY8Xb1yrhvcbpiUrc wx+HtygeDB5kLgkgXvAObYWqR7EQckVzx8MuiQETJg1wbMeLohiigExONfoCKxwjX4fR NxJhRiMzeTkOMrfsbTCMB6KXg4HkOAdQrKoYWyD/1sILVbC1luR63bzcV45hqnyXODDR hvRXB8MxmApNrZ8DBeLud6VwQmZUkXydVOw1G+yW4QQGiNGKj/if0iosnymFqJbgcoQX qTL5IjdLaRXpqlJKnrQeDZQ5b1jdLHFUVMuzPF0me9kwOyHD2QoCKLzdlmgyg/41WLy6 YR/w== X-Gm-Message-State: AOJu0YyJTeDUcwoxow/heYduat5sGLK8oTx253brOyo8z4Vwa3j57bgr fzAZrYpsI4Z4JqJhC+o+qA4nd59mrzNf/aVVAjZFM4FZwleEz3Bl17y3 X-Google-Smtp-Source: AGHT+IH9t7dAeaNOMoxaJJHsKidG/Q03HnCXI/vq2Wb6jRWu09CG2ojcN+QgkM6WUR25N8YKVdD3VQ== X-Received: by 2002:a05:6a21:107:b0:1d8:aa9c:d939 with SMTP id adf61e73a8af0-1d8ad8613e9mr904552637.47.1728493979240; Wed, 09 Oct 2024 10:12:59 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71df0d4a1ffsm8004838b3a.132.2024.10.09.10.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:12:58 -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 v3 05/12] selftests: ncdevmem: Remove default arguments Date: Wed, 9 Oct 2024 10:12:45 -0700 Message-ID: <20241009171252.2328284-6-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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. Move the invocation comment to the top, add missing -s to the client and cleanup the client invocation a bit to make more readable. Cc: Mina Almasry Signed-off-by: Stanislav Fomichev Reviewed-by: Mina Almasry --- tools/testing/selftests/net/ncdevmem.c | 49 ++++++++++++++------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 2ee7b4eb9f71..99ae3a595787 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -1,4 +1,19 @@ // 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 + * + * 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 +57,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; @@ -596,6 +592,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 Wed Oct 9 17:12: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: 13828842 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.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 533FB1E0DC9 for ; Wed, 9 Oct 2024 17:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493982; cv=none; b=XClhfc46/cdPSxpzP5CKVcBs5JEviwClji+ljHeMvjHvjGcSed1j7WT0SPp7+gtCPSpdtNii56Bw3YTa51pI7cbdHc/fBYuaE4tKOFohfWh0GU1LwgAvdhYBm5ZAnsiHZ9Fhwzh3qLM6Ri8UBBDnlpWwpPSrvsxsRinD5vE8fvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493982; c=relaxed/simple; bh=9WKK+wutHJgbmshPKKAc0dTWHTGvwOF1lyim5+H8wdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RCfadyBwOn+wu91mnVHrAcuwAjY3W6wI1W9mw1PpJiVnnKQyCgkChnaBJIsYnfrcKl1kcaHzy/DlE0NLYb6vj/5TsLHJUawBGqXYUF/meNtenDlZ3GA5niUIrdCvkvd98pDavH97of1WLwhqxrDBT63uLaLJ5HFbW14lXUCyK9k= 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.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-pg1-f173.google.com with SMTP id 41be03b00d2f7-7e9ff6fb4c6so5832970a12.3 for ; Wed, 09 Oct 2024 10:13:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493980; x=1729098780; 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=td+sIcXKneo/xE2z/OKG+5urxbxyBXW/X51jG9XxGbs=; b=UXY8lbulzNENvNySFECMfnhQfy/BFxtGosr74kxu1uEkl4qQahQ+k+HeZTZcTx+lkq qTTK0amY79pCX7ASr2ZDQ9LLqEmIZ81FccklzNt3pVNrUg3LdAVtz8Ld/ZswMPrxprHB ctlZRqy9q7MMPKDsLd0TUtZem47PPZJvOj2dJ5i/6e9VrxIenuiAe1lDbzpKdNH+jCAy NU1FACGxth7IqmFSXgtO0UzidNWctotfgOPP6tIHmWJSsu9wRbFd8nuJ555Qd/ckNC9G KHVWaVBGPKUIeS7lX/zNDxNdTZS4rZ57vqBQxIgFC0Ri3m7Yh7YiJGLX8qPrYCnbixEo TaDw== X-Gm-Message-State: AOJu0Yz4jMtds96NJndabA+2xltYnKhdUglEh/zkwvTiUwRamMC2EGvM 8GU+feM6Em742NaBl7joFnZy3lgknP+Wsb1QmnS/mMddaYHliTbe8DnJ X-Google-Smtp-Source: AGHT+IF0VadHn4OcpZhDeUadqXvLeJWF3amjj3Q0EGngl4gTvGaZsKtazZpADZe6AcYFGukBawF5UQ== X-Received: by 2002:a17:90a:fe8d:b0:2e2:b514:ca1 with SMTP id 98e67ed59e1d1-2e2b5140cf0mr2274309a91.6.1728493980379; Wed, 09 Oct 2024 10:13:00 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e2a56002d4sm1945802a91.18.2024.10.09.10.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:13: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 v3 06/12] selftests: ncdevmem: Switch to AF_INET6 Date: Wed, 9 Oct 2024 10:12:46 -0700 Message-ID: <20241009171252.2328284-7-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 85 +++++++++++++++++--------- 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 99ae3a595787..9415dbd2f577 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -230,13 +230,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); @@ -287,13 +296,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; @@ -305,9 +344,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"); @@ -316,7 +358,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); @@ -337,29 +379,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) @@ -371,16 +400,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 Wed Oct 9 17:12: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: 13828843 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 9198B1E1048 for ; Wed, 9 Oct 2024 17:13:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493983; cv=none; b=cfWiE/ixBBujbGFP2rrr9P+QIajKeFAPiDLibd9gEJW5OcPVOJdzyUDHDAqt63kJfVn7ZPol089AAkRmF/Q4NhakVG8vs/hiLBPkZUwPihldBdEhmD982VtYDDkBIR9LIINOvZ18ipm6C4PL+3LHS0bjjR7q756uhATelJE14aw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493983; c=relaxed/simple; bh=mV9UoZwzfuVfwKmqPyxPseIAACaJanldLJEFOK///Aw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lPzWwypiHcDCezaDqkMLRLxxfElscCMQuWEcbF5tdMQgs3zwXChE2FcI2LxSFsxABfPWS+Xy21u0o5mGJOjexfQPqiRz7JAS6F4T6SuWAqnqQdtC6KQoNG9TucQeTFn2tEQcK7cUprBhFv18ZhFE9VI0DhynN1PEA5tgxBnQ3oE= 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.43 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-f43.google.com with SMTP id 98e67ed59e1d1-2e0b93157caso887965a91.0 for ; Wed, 09 Oct 2024 10:13:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493981; x=1729098781; 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=MvyMY50m8Nk1mFDuJT9KU9oDV3vqLtu9+15otB+40qE=; b=LjNQfmjSvtSZxBIzTykp+RnL6YQ57Mh1V9DCcQmIJprw1giYzY+u++3IXRWUazqI+l 5mGlrLBaip5+aL7HqqIszyv/HDaP0Fh4GJCvbv4MQhWHNVdzet7QU8wQX0FLz92tyDP5 I9IUYAp5QMb0HeJKepZeaB2D7GMVbvQWNcv465RZhfF9rZPic6JFV0gQQi2DCBcWUUBX dxNTk0PqbwiCkcbjokMFJXxJiMfPdHoKYu57H8GAZStTn1wMKxpgaLJBnZ/Nbp0S71ET 22V8ZsMN0jaD/J1XNMy8OeLlw7Qn4LvJU94GjDjTYp5W0b//NlafrkBoIAeY1ZbmBj70 6aXg== X-Gm-Message-State: AOJu0YyD2ZmctX1BXChVmYyMzexoUg4azHJ6WKttiBoXK3brL4jHJeVs TKxjjcozdiqD5ewQUsf+Zgu8C1NTI2odL02asyeZKKvSZGGXP1Wu1kJh X-Google-Smtp-Source: AGHT+IGjRwTf8gO4ua+9tEu36aTSEZgpSVrkwsFxP88Jg2+gAPOEnStbpP5HOawmq3pD1MvoLBZLYA== X-Received: by 2002:a17:90a:9c6:b0:2e0:7e80:2011 with SMTP id 98e67ed59e1d1-2e2c81ba38fmr504722a91.16.1728493981539; Wed, 09 Oct 2024 10:13:01 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e9f681d7e2sm8749802a12.21.2024.10.09.10.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:13: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 v3 07/12] selftests: ncdevmem: Properly reset flow steering Date: Wed, 9 Oct 2024 10:12:47 -0700 Message-ID: <20241009171252.2328284-8-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 9415dbd2f577..e53207045728 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -205,13 +205,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 Wed Oct 9 17:12: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: 13828844 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 904CB1D61B5 for ; Wed, 9 Oct 2024 17:13:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493985; cv=none; b=hgpK++lYF9fz2RLtm6JysDjIcssYKWFRx/QXzfKPfNb5HkmoAHoV9FNHSbfFtOHm4i8GLaQtrt/x8RtrMApgCnaaJiPg+U5r9sW1Kp0C72dqwBbP2TZfc8YPzaWlHbmUE/WC84wNYTtboPx/p0zxTNJCMf/ms9Na63qFnySuh0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493985; c=relaxed/simple; bh=zjtCRSGrLR3Je2W0eOuap/k0ZilkmVO01LKyqGubEVU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YLItAsOPhi4uUPahHFuWOI0mhrHgpqHr7WzmCBRGFFveQaENCROhQAOfN9X1ZmAxh7OsEGYBU2c2yy+jMVTnpNvebHStOqVU94jT3X/hl8yjk3iSqr8VB6BRiWsfdT5C2jxhn5K7Vuk2g6Lp/dNPceHo+F6ClAyGEI7lP1Nnqe4= 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.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-20b9b35c7c7so51106245ad.1 for ; Wed, 09 Oct 2024 10:13:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493983; x=1729098783; 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=X/TS+Aq71vjUo51APt9hg7bhlQlYVdwazXqHzs4jF1E=; b=DJa+3CfOmtRKkGimVoVW0RjIXSGI26bsVSZ/Kp4Evd/Puy1y5Y8dT6jzUajIC9XSBO Vv6mIPSM5HpEePjUOBxec1KOTOYKubbMTNtX9eUPa5NVFbNBLFNAxOXECAr0Q+I3L64i Gy04+mZhjZZ1uVoyuETzMzETR6jZVVNZj1AEUTfM6MYWLqnAgKF44Fn0LmZTxTjp9YYV alrbesdZ26ZcdjfnN3ropT552snWJthSTHvnZzZL402/oYkP2kki86IL+zMgK4klP+r3 3XpNycRjBKI/49HCDf/eZZPw+XJ2gaoTZAImaWsnF+WnLz1VaBjnXK4WKdxiXjL8odkM AhQg== X-Gm-Message-State: AOJu0YywfNqOr05n08wyuWLQ5sHKRhm/rQYDwYKC4M1YkZ6RTPWVStrX dkNpHTkxJLpt6uU3kZdKFlIINVibtf50OIh2sI09xTrViiFfeq32rBxW X-Google-Smtp-Source: AGHT+IFQBcFt+PZO3NKYkWwsFsNmVQS/HDDRuFQNVNmfpWel+uX9VqU6TEvploxSFEIiyUl4P0Kh3Q== X-Received: by 2002:a17:902:da88:b0:20b:a728:d11e with SMTP id d9443c01a7336-20c63915481mr49255595ad.53.1728493982637; Wed, 09 Oct 2024 10:13:02 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c13930fecsm73506985ad.165.2024.10.09.10.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:13:02 -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 v3 08/12] selftests: ncdevmem: Use YNL to enable TCP header split Date: Wed, 9 Oct 2024 10:12:48 -0700 Message-ID: <20241009171252.2328284-9-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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). Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/Makefile | 2 +- tools/testing/selftests/net/ncdevmem.c | 57 +++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 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 e53207045728..02ba3f368888 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -43,10 +43,12 @@ #include #include #include +#include #include #include #include "netdev-user.h" +#include "ethtool-user.h" #include #define PAGE_SHIFT 12 @@ -219,10 +221,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) @@ -358,6 +408,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 Wed Oct 9 17:12: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: 13828845 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.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 B06271DE4CE for ; Wed, 9 Oct 2024 17:13:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493986; cv=none; b=sVEnBzLEaNxxhtfJdz0jvPFQr7TnXy8EUC46KI/DLsEWA8dM/HCgZyWZf36vAHzKb1kbNoSqN01zlZ8Lmtxa+dR43CicJ8bUc+GLk5GhU/WkuI7kmf9iibO40OrgynP2iG6H1dM9NvA2RhSsLankBGxcpuovdH74LQ4czpo/pSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493986; c=relaxed/simple; bh=vtF1aQjlg7zJIjdWfRXwwXxmJ53MtTbM82Io71VQxAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OE208Tv0suU97ciCO+WWsV25KQ7+ewskHIVUhv9z+8Quo0FyBQ+KkK/Zh/NkH8OeQpYDlinrN/s3W9tIYnWv+nLRwiiyX5RQW1X+7i9Ct+rFT5NcfiJrqdz/eXQJ+9KzbOBcgjXV7hryl8v1AC9xSuWgcx9uS/21LuXk9lRST1k= 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.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-pg1-f181.google.com with SMTP id 41be03b00d2f7-7db908c9c83so4519146a12.2 for ; Wed, 09 Oct 2024 10:13:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493984; x=1729098784; 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=6EPX6T6P41rWnZDYYT4pKZI/4MKdk+tIinSmqSIRYpI=; b=W7Of3ygVA0ee0lWYiu/0eyQ+ooicKi1u1NhK42HxzZkJA1Q1hIor3baWBGfTGkpaYP njy1953TwRS1whC59xhcQc0BqUDPVTPSeLos8N547wJ2+5vXcMSo9SIK1HGrknMyYL5I XSF9wxhO9Z6ZukU1kc0/ktJMLMqY1FRK67ybXizNTNisTr4iaeIUb4GXPvF46x6/Ues1 cttDdVAU3reZg9H/FohyHk5+f+J8isgQfWdbZ6Qv37brpi0uMeC9wvTrzXs0P4z5A4mS siDLZcUGGfQ1Ivsonzq5U5bOk/8t0SqOH05rTjcJ1tOqmTpoAi4Q4OoXLi5ZBgjP+Dxb 1MFA== X-Gm-Message-State: AOJu0YzWqbLIda9oTlaJaNUCMchT6iYeFqgtGtu8tJduO8CDd/EqGTJN BGhQI+Gq0UpOESTl0Is7Lc+A7ZzeI/8mJRbN7Ls3afaQN1IogmztO+R1 X-Google-Smtp-Source: AGHT+IFkyfSCzFHuGDd1KUm+goCGpDZlQ5fOKvLuk2D2v658tN28OqdRJXbSc8DOHJFnNP4NcW6RDA== X-Received: by 2002:a17:90a:bd83:b0:2d8:cd04:c8f0 with SMTP id 98e67ed59e1d1-2e2a25a1149mr3648204a91.39.1728493983770; Wed, 09 Oct 2024 10:13:03 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e2a55f9970sm1942852a91.8.2024.10.09.10.13.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:13: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 v3 09/12] selftests: ncdevmem: Remove hard-coded queue numbers Date: Wed, 9 Oct 2024 10:12:49 -0700 Message-ID: <20241009171252.2328284-10-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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 Reviewed-by: Mina Almasry --- 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 02ba3f368888..90aacfb3433f 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -63,8 +63,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; @@ -196,6 +196,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]; \ @@ -690,6 +717,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 Wed Oct 9 17:12: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: 13828846 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 A69C81E1A34 for ; Wed, 9 Oct 2024 17:13:06 +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=1728493988; cv=none; b=Ibz8/nsVqUtP6lKvN/SfUgdDy8yeuEWVNeM7ZsE3vd4UsamAsCBVXxnZD30WngKGwLkXw7z/6fXAlajwBeyYYZ1qYvrwtIf+KYcSj7e2FWlZquuEo0fnV5S2KCh++q95uG4yy30MxMzddp7URDBiuSxSocD0gSn9YqJ8gvppD6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493988; c=relaxed/simple; bh=GO41+IUnSK9rCr/c3Dp+p71R2jCokjC9vwfeN3r9L6s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D+aFODTxGIgE7kcg49tShM32tD6by8fH3Ty/jXLDQD0gRIeGpnSH2jV4dQWkGpm0996iGYVw0vWaj8owVmhTQckD5QxIARxvI0KFqR+62GORIvlgAdQ0H8X3f3yM4oyfeD2iRMyWjDw4MZdZmLsh6WBDLuTV5sbKNKoxjQmhluY= 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-2e221a7e7baso78599a91.0 for ; Wed, 09 Oct 2024 10:13:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493986; x=1729098786; 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=uGqk/HCE3+RRutk9vLeoLePiyZrKtIG6x7VUeS+mmoA=; b=JamnRe69LvK2LwwtFpalJPlwqawXpAf1wB/j4zUfQMdQ0qgwHgfBkZ//rh+HOp8xKl vMbtfwoPvnsqNKmwjJ8qd2gXYaWAAMFoAWFrwSuBxwnNwvS2wqDmY19UHQeVpojakLMM AkCjmLk5ygylBU/tm3AhcxWB6Idj7ldZZdvySHdk9uNvGZBKSQKQS+3lFyZVotoYOI6Q DomeoKj7u+47PFzDvksrxxskQlPt+yYcxCbe4XJ6w5cxhyFac9XGKPpVbkSzXA6TwNOq 2Z3BgppHP+25yXkcAvzJ486jTWB+AVFe0v4JrSpr6qRhYmu1/sbZ8DvO2+tHBFahonCd +IWw== X-Gm-Message-State: AOJu0YxGPd1ZKpeyGCxHFfNUA8hFhhmlMWNsN8OC+SvkVo33V5f2OAk1 ymNUxRCF/lEA7D8lz5rHQTdG/QqzyUw8fqLQVjD4xzSXaiz+rE5BrwWT X-Google-Smtp-Source: AGHT+IFf94W2RvDDIxyh5y9A1320vYbrVEv4ktJn/5p3NmVa7t+az1gF2MbnhBeBuriWuxYpCHbAxQ== X-Received: by 2002:a17:90a:bc92:b0:2e2:8d82:df13 with SMTP id 98e67ed59e1d1-2e2a21e6d03mr3544373a91.8.1728493985668; Wed, 09 Oct 2024 10:13:05 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e2a5ca9db5sm1942726a91.47.2024.10.09.10.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:13: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 v3 10/12] selftests: ncdevmem: Run selftest when none of the -s or -c has been provided Date: Wed, 9 Oct 2024 10:12:50 -0700 Message-ID: <20241009171252.2328284-11-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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 Reviewed-by: Mina Almasry --- tools/testing/selftests/net/ncdevmem.c | 42 ++++++++++++++++++++------ 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 90aacfb3433f..3a456c058241 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -64,7 +64,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; @@ -706,19 +706,31 @@ 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"); + /* make sure can bind to multiple queues */ + start_queues = num_queues / 2; + num_queues /= 2; + } + + if (start_queue < 0 || num_queues < 0) + error(1, 0, "Both -t and -q are requred\n"); + + run_devmem_tests(); + return 0; + } + + if (start_queue < 0 && num_queues < 0) { + num_queues = 1; + start_queue = rxq_num(ifindex) - num_queues; if (start_queue < 0) error(1, 0, "couldn't detect number of queues\n"); @@ -729,7 +741,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 Wed Oct 9 17:12: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: 13828847 X-Patchwork-Delegate: kuba@kernel.org 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 03AEC1E1A37 for ; Wed, 9 Oct 2024 17:13:07 +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=1728493989; cv=none; b=BWy60VPwQ1FDxcawBijjGka73oNwVfRflAyIv7y3ykS2bdXo8v0UOfE/DyyOTAejNMzH9zVWi/Zt3HS9gacPYUNAEPhyeE1wsjZxS0HN3v+nChgQP2dGniUCnknrpzgSvShLOxpdpFwT58q/CBdHSZA1rMCRcnHi2al2dQYRxgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493989; c=relaxed/simple; bh=/qVkdytMlaBiGOjGxXrXbqMZMovJTE1W72Hw9NA4+Ew=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iWCOk+6uABz+mG781mc2MYU+MGs/nkzGWZyFAYPiI+1GC6FQ1gmy7Swgxlu64xZVPeA88zA++zJe2Cb1DTRZM13EmJ73UJXARgOaJ0+nVNCsEhBUk4zNI4GKMB9fCtcTD0Y/5M45tuJ7xu1J7y+hTxJXu7h1P11xksCQZz+wVR4= 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-71de9e1f374so28363b3a.1 for ; Wed, 09 Oct 2024 10:13:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493987; x=1729098787; 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=8MXqeeh4LmcyRK43z6/VTXXaUX+Z/swMGPXe+IPj444=; b=NWYg2VY0+y2LRBRLlufQFRhrjvJ8tNs56KvJdLKGY04Klk2uBfbkpaeRgdX1lSLl8b 2K3kvMwhSdErk/JWUWWxkzUCA9PK7RjheX4Pg9L3sKELJQ0Axs2k/a6R1ANzipjLCmrq /47mIa5EN+OjiNnskM0MJol3oPMM0+8FJ0bAG2dVneBK30y9+3pVY39Qgh6Mc2II1piR c9/3Al+uq0uP1siqd4fy169mZaZaWlVMthS/hIgyBsvHiWKueTTUcQXhmUw7bAXSn4Xa f1cz67lfKrO5FzIkSFhHRcNYCzAPM4AlMmU/XnGg2sf49CwgwhbWWQ09pUvWsNHGs2k2 BL5g== X-Gm-Message-State: AOJu0YwHrIkAlyTmzLA4TeykaVmd05RpwfNNJJdYafAWPpwjWyF+ZWP1 om8t0wCIhFjfpbusEPTWfWRTMlj+TX1LDvO006Kv1zmtC7c4S0eyLaQd X-Google-Smtp-Source: AGHT+IEdtpm8FZT21bbfw2sFoASkEi115Pl9etjrAUDYGfnEFYA8gj71NLd8nVcoZmQD0qCyPFILHg== X-Received: by 2002:a05:6a00:2394:b0:717:9154:b5d6 with SMTP id d2e1a72fcca58-71e1dbb53a8mr5057794b3a.22.1728493986840; Wed, 09 Oct 2024 10:13:06 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71df0d6520dsm8267416b3a.171.2024.10.09.10.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:13: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 v3 11/12] selftests: ncdevmem: Move ncdevmem under drivers/net/hw Date: Wed, 9 Oct 2024 10:12:51 -0700 Message-ID: <20241009171252.2328284-12-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- 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 Wed Oct 9 17:12: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: 13828848 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.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 E5EFE1E1C06 for ; Wed, 9 Oct 2024 17:13:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493990; cv=none; b=cTAQzoWvyZ7r5+SNOw2fCHYdY9syxsELWhLj0iaQCqtrlX/+V/bHd94PtPk5ooflxkBeu921wGtwfj7iwHYEgFsWl/hKvMepFaqM5AEHVUb8uJKBYi8sAHtNKBNJ6HTkKddW9o9+KN+AJbOUSNmFrJj7SC3oskp8ChFYtsOVD4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728493990; c=relaxed/simple; bh=1zS+u1GiVC18xnG9Aw7f0ISl9pzrHe286vIjgalAdio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ay2jKt2pr7CKJVariXLzJ+ojV8EE1jxINGOQeFGmbsPB30RZMBVG8RIgkrilMeVYKpZzqKTHKs5id1jb03sYFKnS4XllvCl7akqaB9gcutyBB4Ix3gXJ4ZLUFCN5UllsmngGiAWapPPjVjnRgtx/k1VGyf8A2UE4Va6TjcTR9A0= 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.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-pg1-f169.google.com with SMTP id 41be03b00d2f7-7ea24595bccso948500a12.2 for ; Wed, 09 Oct 2024 10:13:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728493988; x=1729098788; 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=oFE5W/FSE3W/X2d1D2QPcYtHfiVNlbp2Z4vuTencDjs=; b=arVyqDR+EdzIAHAUu1UUtntpIfWgSKsXQ6fnQiZex60cqwHhDVB3eoAoumcAem22OV 2kWlZ94zSOJWmdyUth3XiTUYSgWT+8DZCHBcuQr5niqvicLMXv8bR1ozqWKIjF1oQ3Ng 49VGuUkcw3gL2scFw1epwL4KuJu9x5du2RQzYQ0gwozDcZujn5KTZVw1j3p/rZPqOCp7 VcMWnVs5tBRIgh9fqU9M7LD96fUmPLKYA6yaaTZjHB51isZxE7kHe/dW9x0Jp2Z9HFTd SkKRJF4Ak0HrmH0XxfNa3oZ5+w3vRgIpNOR594xMOZckmELZJIsozJL0/Yec/b0AI/Yk Ux0g== X-Gm-Message-State: AOJu0YwkZUJkwvEwMRx+MwCl5EobuzfCoYAuwP+vipSl6NaCG0XFxI+i bj4sRt8oZgMuhVUH5dMWcwxqN0t5zPqQbZrQQVTpkwgq8YJfc1en+JAB X-Google-Smtp-Source: AGHT+IGI5jTRyoA+8mdBCa+UcduYSkdpE6A0U6Gy1K4ltCG1nzRKzZKVTZ/XVjmQAyfli6KKrtDxwA== X-Received: by 2002:a17:90a:6fc6:b0:2d3:d95a:36dd with SMTP id 98e67ed59e1d1-2e2a21eec83mr3214970a91.8.1728493988084; Wed, 09 Oct 2024 10:13:08 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e2a57078dfsm1985503a91.16.2024.10.09.10.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:13:07 -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 v3 12/12] selftests: ncdevmem: Add automated test Date: Wed, 9 Oct 2024 10:12:52 -0700 Message-ID: <20241009171252.2328284-13-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241009171252.2328284-1-sdf@fomichev.me> References: <20241009171252.2328284-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" Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- .../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()