From patchwork Wed Oct 30 14:27:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856612 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96C5D1F131B; Wed, 30 Oct 2024 14:27:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298448; cv=none; b=XK22m2UHzpp3dBG+ZJ0I90T4EATHK7DG/ZqGFmWBl991RNQK2bPH+pvm0IVkzxzly1bxPIL2StaXcR8hWtRxkA2Pn/j9Jjp3iN9ExvbIVf+T8TAMpb++sOUMWrFEANuGAWVCJjSeX64tJioVCCcBbzug0d5bX/p1FrJLZ0ft0+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298448; c=relaxed/simple; bh=DbSfoMlzpZVhU+8FFsUY3AHTX/zbUMYdVXfjpyEzHfU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UXA6//GBnKpXGb/365rxAIGHX5HULWIoAEOgUzaGOio6prL/nZ9OTd+p64t3N0MBs1r3v1kTVpYLVs5/OAp0IHpYfLttpIXHYUmEJwmZwYrIw1/8pZ38XP6dI+kR5RQH1q5EG6Qnlx0v3AOG8igDji9deDoBvx2nl2FrDkSqXtE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-71e4c2e36daso698242b3a.0; Wed, 30 Oct 2024 07:27:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298445; x=1730903245; 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=Om2sagzOHp9WBoevq12Ew8sjQoqoRBjB9Q5U637geAfK8rXgpKugYdRSf7hg5hktLZ 7xHzRImewq50f+ZHTsyJqcs7w6PcmJuMYffE4CYvMkz/pk3mW0Bmzb4cCXKhWBxzkQE+ JuftrXNtyix4AI7OVfL1pRi5QpooWhY201ENi21nO6V6WwM1BmT1wiQu8MyRhA8em9jy xfg+TKQOXy5bcRQH4QfFwFugvJQXcmmDKmmOzLJS2jPnzDTX9bqJf2MPZ66l2VcIOUJd zU8FBvJ82x93F9GKWJO9GWJXzrsZ+itugIJN7fsBRd6ZBW6RMMO9bAKWBfvslcsFM2Qr MYAw== X-Forwarded-Encrypted: i=1; AJvYcCVeS2JGsmz4dNHG5EDlTnZqIcrxgXP4FyaE2SvzNo6+0G6xqb6Lo1kuLvKaidaPyJY4JZughStnGWu64KI=@vger.kernel.org, AJvYcCWPm8cJMu/dAaB24Yt8an66Ii7O7oYDjbd+iqj8MfaOVqJgNR6VU6dW8pAo7kVeX2KvTw3SAEVOQ3dM6dOyndIp@vger.kernel.org X-Gm-Message-State: AOJu0YwD2BhVHnvbmAwmOfH3Ij0cY182sTx6UMP0ll+0qnTmK9SmvwzY GPEgZqeWtEmXUd1/YWb4QUAh9K/Ihj2vuKMJLy2TIw/KDWmar+9fybAg9to= X-Google-Smtp-Source: AGHT+IHcYyMNajAcXQtfx/pUj0w6uio/6atCMOpg1MpwRBQ8XcxjbYioDvvhHFlOdlm557Klqq7YcA== X-Received: by 2002:a05:6a00:10d2:b0:71e:5573:8dcd with SMTP id d2e1a72fcca58-72096b9a529mr9261354b3a.2.1730298445186; Wed, 30 Oct 2024 07:27:25 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc8685729sm9352812a12.37.2024.10.30.07.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:24 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 01/12] selftests: ncdevmem: Redirect all non-payload output to stderr Date: Wed, 30 Oct 2024 07:27:11 -0700 Message-ID: <20241030142722.2901744-2-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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 30 14:27:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856613 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 C954E1F4284; Wed, 30 Oct 2024 14:27:27 +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=1730298450; cv=none; b=iwEBnWnM9d6Z0OdLZaLDLVy0SZkuKCq8yM8xtVFhb2rEmu97LouCAlndKM5fta8R/ZaNOXP5pWoXQc3R5lFUZRYK6PppaoCdpIKzKijFbCfOCuYdXjW+B0gJOSL3Bn50VFpddwdljejlF07BAzTNng4JjhQ3y3tinH1LgTkhCUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298450; c=relaxed/simple; bh=uDxOm844VsAsi9UnMdkeV0AtSZv36ezRQCbCtTNGPfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fvoopnw3n7GdKXF8vkelrNUHGKQ4U7suu55igGPPpEWOKsQKCcWetSFelmWU3HbHRuA2D5341ffybtsRnPBYo6x13aAjGVfdKQfyg60Lyk9FA1JtLeg2OwQ8JTE4uLl6wiUCmfR3Ebj0oXa3aE0JLTeCNEvV4d0+TJKbYbhvssE= 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-20c9978a221so72946555ad.1; Wed, 30 Oct 2024 07:27:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298447; x=1730903247; 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=rwe5a9GiyNJwkxtBHFJbPBBU4q6iMiPSSkZewE5aGWta88m5O4P2fCHDd3e8Js/F6N 7a6jZ6j++R8LWJ9RtjXugO56PYyYd63WU0o5e0MElpJCN0Y45OIk8BZV/aJjFg4pRL2C Jy0fvTohS9YDGqZcvrnPP9dIUQWfGycJvUmLt11UPGNfx0EHMjViZ9/i0HbYnrKtYPeO UA23yQfE2/oE4boI5kCnRedhizvPNInvrjgptoIdN7hb5mIw40Y+mzHeIXQCofrlUXYW JzVRMVooQRvcigIk+iWjIXeyoH4w8KxbloudEGakiv8Zkd9vM710e4tJGgppk/KNw2mj c9WQ== X-Forwarded-Encrypted: i=1; AJvYcCV+KJ873H3xSykFwFIM5CL1GvW4dIvZiEuVOhk8luuBNTGEDx1Ie+LUlZtxBYszJ5t0GTe/uU7hsl0OBA1WZkV1@vger.kernel.org, AJvYcCX4Er3qQ+cExisULsaBWHTHmAzrzpNXK7VqHcSvhCW+7YmEr3RFsu+qvWX9UoeU9eFuoWxbhDbPEsQTfEk=@vger.kernel.org X-Gm-Message-State: AOJu0YyhehUiyVbvQieIpPwA6s0boV0aFYS13SgHz0UyClrvDtKTf2Xh Zr73PlJOVAk2tkuJT47OaLBy4BTwlRq3CUJeu3TQZl5GLr+uwKrrLBzZxAc= X-Google-Smtp-Source: AGHT+IH+aBTpxou2cWtxON0T1GS9tyqrhYHHsSwrYDeYk2RB3Pt6s6NRmwCpoWrtj8BzIS1XG44lWw== X-Received: by 2002:a17:902:e890:b0:20c:8abc:733a with SMTP id d9443c01a7336-210c6ca8b77mr203336935ad.53.1730298446612; Wed, 30 Oct 2024 07:27:26 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc01791bsm81834775ad.145.2024.10.30.07.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:26 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 02/12] selftests: ncdevmem: Separate out dmabuf provider Date: Wed, 30 Oct 2024 07:27:12 -0700 Message-ID: <20241030142722.2901744-3-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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 30 14:27:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856614 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4CD91F4701; Wed, 30 Oct 2024 14:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298450; cv=none; b=UtjG7fh2pcp8scqq94bmDfWzSmUNAfOuUayoIqorftcqpIt9dbr3XIgJwkjmYGeBBlWGDHcr65RxxejMPUtn4vdJHfPJJLiOGC5qt1BrGxfJVRXUc7GL+zMc+FAzZZd3TnHF7LVaq6gkxbXwyYkmKPKQi1c+Dwm0LfS7VaR5emo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298450; c=relaxed/simple; bh=OIDSuCZ7YG+e+v0WLdyGHp25gpwYSalsNS50axL7TJ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OtMoOX+N+Rdt6adsX2hwd8YdX1x+TFCvE9aRdeKR8+YMJZgCoq/Y2E5pwx0xRcOsJ//21f30bWVsf4SO33rE8kUbFpZvWYFWfbRRb6r/ZUJGYQKAQp3RqpixuBtTn2Qk0EYRYgECBRAFh3tD43ElWFwF5VDAzwEt20Mci0E19Ak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-20c8b557f91so63786005ad.2; Wed, 30 Oct 2024 07:27:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298448; x=1730903248; 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=c+29L4jHAr9oczA6UEMXmjLx3Osf7cPlK2lZ59Hz8FA=; b=NhSU/DB+iRyHiLYvTouIWn25MlgFo5lEcn1bviKtjfamZyMAZu26C1pungF7Rszqe1 L9X87EvGVXrrCla2syKRB03HlWb4j5xKnbEIMAtOKuMS7ZK2KDqBxUNudXNYehHIATQW QVYFJ2jDBErM7gI4ZduWq1H6j9llz/sK6IMGJ8SCM6lFrJTe/raPYQTAGH0eEnKYCVAs d38x18WNjtvhTzS1xngGE0n2JQuItYq4YAWrjpxch6xNnfhK+vrARZzaGQu9rcf5JmRP ERbQmtlCW/XvOhiseRBHvqG8pyDR8h7z1zs9WduHyJtwv1xt3fry3Hq4bp3Buij/R3iK wqgg== X-Forwarded-Encrypted: i=1; AJvYcCWYEq1HQC82ixBvjL+vc9fVDhhB71TfhvNEz2rxs+0TotEm3SQIL02UEAS15F4kJgHriW9ZvZ7ILbT2nXU=@vger.kernel.org, AJvYcCWv+6vuvs82RPSvx1oO3J0QJFPPICMnQvSOmimQayS5nUdUCvP30qwDM5bRteACdq/+JD6PmDQZBhdde6kHqzfo@vger.kernel.org X-Gm-Message-State: AOJu0YwdlAlgPcBmpByE86kMODqK+KLSwtJx4GtG5A9nPvuajFF0XawD QO4kT4b9cJNwdIQNhzY/Q4wGlC9blHZAhsSt2vQinf7d+OYLV3l2HxJtf2A= X-Google-Smtp-Source: AGHT+IHpEKJrNK+QUexvQiW8T/gG0xZvnnPgaacp4Xcgs+8s7aGvnWKM5fcaMFxbtl0o170WOj/Law== X-Received: by 2002:a17:902:c94e:b0:20c:af07:a816 with SMTP id d9443c01a7336-210c6c0dcfcmr176301445ad.31.1730298447813; Wed, 30 Oct 2024 07:27:27 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc0492f8sm81429065ad.256.2024.10.30.07.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:27 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 03/12] selftests: ncdevmem: Unify error handling Date: Wed, 30 Oct 2024 07:27:13 -0700 Message-ID: <20241030142722.2901744-4-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 9b3ca6398a9d..b89b62445158 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -339,33 +339,33 @@ int do_server(struct memory_buffer *mem) server_sin.sin_port = htons(atoi(port)); ret = inet_pton(server_sin.sin_family, server_ip, &server_sin.sin_addr); - if (socket < 0) - error(79, 0, "%s: [FAIL, create socket]\n", TEST_PREFIX); + if (ret < 0) + error(1, errno, "%s: [FAIL, create socket]\n", TEST_PREFIX); socket_fd = socket(server_sin.sin_family, SOCK_STREAM, 0); - if (socket < 0) - error(errno, errno, "%s: [FAIL, create socket]\n", TEST_PREFIX); + if (socket_fd < 0) + error(1, errno, "%s: [FAIL, create socket]\n", TEST_PREFIX); ret = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)); if (ret) - error(errno, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); + error(1, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); ret = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); if (ret) - error(errno, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); + error(1, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); fprintf(stderr, "binding to address %s:%d\n", server_ip, ntohs(server_sin.sin_port)); ret = bind(socket_fd, &server_sin, sizeof(server_sin)); if (ret) - error(errno, errno, "%s: [FAIL, bind]\n", TEST_PREFIX); + error(1, errno, "%s: [FAIL, bind]\n", TEST_PREFIX); ret = listen(socket_fd, 1); if (ret) - error(errno, errno, "%s: [FAIL, listen]\n", TEST_PREFIX); + error(1, errno, "%s: [FAIL, listen]\n", TEST_PREFIX); client_addr_len = sizeof(client_addr); From patchwork Wed Oct 30 14:27:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856616 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C462F1F7064; Wed, 30 Oct 2024 14:27:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298453; cv=none; b=EswdcP6ILHrnKizUEj3U710QFPhYi3HbUY3Q7bR8l61+nm56HLN473xFRCMSX0KYLN4d3YBj03apyOgWE6IRJ0ZszPbFRwvjNt8PkyTB1DhfFZ4P3eYraaLN/MCkyHm/nKIG0c6pfPbsx4PftCUs6wev9l13xKS1Y9+Pul/ZtYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298453; c=relaxed/simple; bh=V/snhxZi+0I3HXsSt+QlACbncN3kHgsS3nE3sHv68wc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I4IYnCF9oCDN1XTBS/juS0NCwox/bP5Y+NMj7NjSLw9gFzv8WDFoVfS1+xMUUlCTEzLoxwiiEAD/PyoXAmUWdVHVirK+YO30z7dhMRLEOUa1db76CcGI2gXTyH7W5qrETFAxfUpuUT34jgAl7K8i7fAIkwyHKdzDW1gMwK9cH98= 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.160.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-288b392b8daso2980989fac.2; Wed, 30 Oct 2024 07:27:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298450; x=1730903250; 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=NajTBikUup8pa87QS9/1kmZjqVP13oIq9vk9Hq0DWdg=; b=at89AXpJs6c1n3gKuZND8X3bW7Hqj5FPl0QGCVZ76/i36xZa22KbLjKLM4OJQOf6QG BW0jwjM8GUGZ/6VQgLgZlD8mAyKzRr/gFpZuuEjGqCJmpM/z7M20S2Ultz2ADfdFWYhT kyCzaCaOZaZkrZImcPPU6KPK7NLJY3yQmtj7XafcRBwZ34Sj1/7BhKTCdy0VebiC94Xe nOLISuEdataUkA+ETeGDunAPZWg245HQIFTcxMEDHDAHt3dS2xhNh+XoHWInUBt3r9Tr 2nuE7RDcq59nZPotTa2VR9axoxhmKEMnxXrGrTLxrVqM6db6BqcfAhRh0NgYJvYHZvHE aAFg== X-Forwarded-Encrypted: i=1; AJvYcCUwsWkFyxjdwbZc8JADpF7Go3KavezKybOnrekA/Jkc/uOhUPo1mrFdm9K5E429xpuND9LV8A7Wi+IRBnEuJzZJ@vger.kernel.org, AJvYcCV8Ie2QxSzxKYFdHC7M03lVqIGoYY6SwiSfpErEeCI1ozstu7w5sUAfaTnryTLoy/G2OVh7bTzjoDKrgqA=@vger.kernel.org X-Gm-Message-State: AOJu0YymdiDrDoqQ+eTFaJff+5Twuyc19+zPAU1cQ1wOonOJRcXljH5h srnoIz97NFxcA1f1NtfuoPzs6PgjMbyCIJXLYv95EWa9Xyh9vCBe/h0i+JI= X-Google-Smtp-Source: AGHT+IEB54j61/HMXCP7CKcR0j3pOBfdeG2E0C8G9eLI3FTeK9A3M6cnzDY172xgmx/rFRC+AfNkgw== X-Received: by 2002:a05:6870:a11b:b0:278:65c:3c14 with SMTP id 586e51a60fabf-29051ae9defmr14531581fac.5.1730298449031; Wed, 30 Oct 2024 07:27:29 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc8a3d1c6sm9382378a12.81.2024.10.30.07.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:28 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 04/12] selftests: ncdevmem: Make client_ip optional Date: Wed, 30 Oct 2024 07:27:14 -0700 Message-ID: <20241030142722.2901744-5-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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 b89b62445158..b94f7c4a53ed 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 30 14:27:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856615 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 452B11F5834; Wed, 30 Oct 2024 14:27:31 +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=1730298453; cv=none; b=o7owTkAajulY3Tvpq+I1XHALMRanehmBSbVBc/1hrJ1WJVS7zwwgqM477ZS+DNMDZV+lUkU9+npx5PQ+LjxjEI1AaMqME2UuwLLiCmUSm4LOkaculdbizYnpSZaubdNULwC7Qqyu5phykILOH7K0U80yGuhoGY+Y5ODoYfZmufI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298453; c=relaxed/simple; bh=cZM8NLCE5I1kpIKc1v+Fo5zXbiCk1fh2kkSluf5P1Kk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bDDKYV3R9iB3kBNscPM2j4nT6pOhYjorp+nMnshPQVUARaGg/QrDdBThXjKubfqQTnn//dElJR7wbGSJxvop2bWUOW1Krdl+bID4k0YS8yaj4w1FRdEnIacZyOVW8GkbYEz0hFF0Tfo3wsi/wHq1nV+9KoO1W0i1jE+d9REMtVc= 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-20cbcd71012so72606835ad.3; Wed, 30 Oct 2024 07:27:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298450; x=1730903250; 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=uFRG3akeouWA/XW0R5O9u9ae+dag70KWFU2wlOjYpuY=; b=W6bP70s6Bw/oe4pkTk+VHhB6Qp0vuBa+zH+WmuVQSuz2X05xcO0hzDFrsidoFKgm0n 4Dh7DqXMk16NU/jRpqrDW7YXRYNbVZLbmS11DBSzF57sxj6OiH8ONJfhJirpvy3PmBxm 9gAfc97wfK04HFyRJhCzilIChwUlkjac1jv829n0C7AT6uFjFN6lrWgcrluI7ck3jTlG xvE31w4VXIyPGDFottls4FjiLHPxOjKXKGlv9PH+PegZ2UW1aV7Fqv5lqjIuWEgD+o9n PqB+vpyAHN66sMP0SP3GLHTsQc7lbqWihyO96nK3FbgPgYKAwiAAUSusjByJl6PtrQIc agSw== X-Forwarded-Encrypted: i=1; AJvYcCWVp44bpV7hgVvs+7hdcSpXZQzuv4Hi4mSKpFEE4RK8Zsuosmx7x8XMzMs9vvTXTCuXjywQ2jdHOq3J6+v+0lKY@vger.kernel.org, AJvYcCXXNGk2Ti2MYEHlAK5ZGz+ZD6wsWZ7ri96d51mn1ET4IvwmzGPuSF2E3bGt9qsS0IqS216RMh6uy1DG4jw=@vger.kernel.org X-Gm-Message-State: AOJu0YzFdDA0TtknEJIHgtePZseFP7mmIvsKMEKK5k/otAT93Nlb4Lj0 A8KEeKD4q+4NdSLHVANRvdKXPRbLalfJvnydKQexehf1lVWh0UrX7/0frE4= X-Google-Smtp-Source: AGHT+IHvi+b4Ud2DkRezJIKBc+Yh572At2DSidGhkmiYh+PniSjY+SwMvBTo2m333/Q5LjDypq/O6Q== X-Received: by 2002:a17:903:2312:b0:205:8407:6321 with SMTP id d9443c01a7336-210c6879f49mr199352505ad.9.1730298450223; Wed, 30 Oct 2024 07:27:30 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bbf6d3e7sm81009385ad.89.2024.10.30.07.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:29 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 05/12] selftests: ncdevmem: Remove default arguments Date: Wed, 30 Oct 2024 07:27:15 -0700 Message-ID: <20241030142722.2901744-6-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 61 ++++++++++++++++---------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index b94f7c4a53ed..037fb6e97d29 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -1,4 +1,31 @@ // SPDX-License-Identifier: GPL-2.0 +/* + * tcpdevmem netcat. Works similarly to netcat but does device memory TCP + * instead of regular TCP. Uses udmabuf to mock a dmabuf provider. + * + * Usage: + * + * On server: + * ncdevmem -s [-c ] -f eth1 -l -p 5201 + * + * On client: + * echo -n "hello\nworld" | nc -s 5201 -p 5201 + * + * Test data validation: + * + * On server: + * ncdevmem -s [-c ] -f eth1 -l -p 5201 -v 7 + * + * On client: + * yes $(echo -e \\x01\\x02\\x03\\x04\\x05\\x06) | \ + * tr \\n \\0 | \ + * head -c 5G | \ + * nc 5201 -p 5201 + * + * + * Note this is compatible with regular netcat. i.e. the sender or receiver can + * be replaced with regular netcat to test the RX or TX path in isolation. + */ #define _GNU_SOURCE #define __EXPORTED_HEADERS__ @@ -42,32 +69,13 @@ #define MSG_SOCK_DEVMEM 0x2000000 #endif -/* - * tcpdevmem netcat. Works similarly to netcat but does device memory TCP - * instead of regular TCP. Uses udmabuf to mock a dmabuf provider. - * - * Usage: - * - * On server: - * ncdevmem -s -c -f eth1 -l -p 5201 -v 7 - * - * On client: - * yes $(echo -e \\x01\\x02\\x03\\x04\\x05\\x06) | \ - * tr \\n \\0 | \ - * head -c 5G | \ - * nc 5201 -p 5201 - * - * Note this is compatible with regular netcat. i.e. the sender or receiver can - * be replaced with regular netcat to test the RX or TX path in isolation. - */ - -static char *server_ip = "192.168.1.4"; +static char *server_ip; static char *client_ip; -static char *port = "5201"; +static char *port; static size_t do_validation; static int start_queue = 8; static int num_queues = 8; -static char *ifname = "eth1"; +static char *ifname; static unsigned int ifindex; static unsigned int dmabuf_id; @@ -596,6 +604,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 30 14:27:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856617 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD3951F7082; Wed, 30 Oct 2024 14:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298454; cv=none; b=Rk39XR/hKYwWRBeo6ys4yd+hqDQB5OoG/2XmNcfn4yKRZac4mtWOYAUOIJBtKvx8J9T5rl6o4XPPBfT6gOVU5mbNn48ZNdhnBJWyNTLK7UIjd9oQj7WmyPt9PxXtskOlg5af6SS5kUKmHX59KTtTFTmWmFBTVIBwCV1PnJbk0f0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298454; c=relaxed/simple; bh=/9Aeg71P+WeuP/lJ/VnhMNWlAqelLsVbXCewlIWWuVs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AVL+qGPKOos23L4N71QW2IrMSewcQjpxLFzNlTAta3L9BMOWBfNkxMAytpM8SB3ep7IerFvULf7yky96nsI527RLi4b/KgEaSmio/F8s5Woz9qyx4pxHxpu0JtTqCdteyD/D27Qzjx8khUnW+oqn8opFcy78+35ICnqaBzJMZtk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-20cb7139d9dso65164865ad.1; Wed, 30 Oct 2024 07:27:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298451; x=1730903251; 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=SGFZk/edoAU0ji551OMPbJzhccOrkILDSWMyBZaA81E=; b=J/hXwXb7zzIpBAhdB4OrbOdEK6sNOn+faLplawf0DGvRuztjeiz0wwMD6ItKL5sYv+ eciARKL/jqANjuIQf1etGkRQ4602VwdCtj0fUI4NI5BZr71IDTls0J4TF908kzFB0BZh /7JPFvzHfW/WhN6qKpTXHBuXtBWVhxhDJ8qxo2unlV1ZyIX5E5IbznJp3kaoNghF2IXW ZRWX8bXvGUtyot0r5H1/f6s0IxFU1VLUzz73zzSonvhVbFCYIwQyqfNfAroweYaR/pSb 3E7WXUdlTW3fJk1BZ+K8InpLPTgh8mQ0weRzm1W97qILeQRcY8pGwy3flrvgovzzDhfp wLPg== X-Forwarded-Encrypted: i=1; AJvYcCX6EN9dqPQEM/PigaI/fSrdUNLTOTpar0ktuQijebOrfAkCfQmyDBLXcAOjopo+3PUwS27FroDedqOehQ2zPsDu@vger.kernel.org, AJvYcCX7/OtZ/EBmlUzqYFyN6s1/1MEVCOZF9ST6pbfuCUS12SQgGMD7zM4TW32GeZ/hhFUNcRDf4+9kHxXb77s=@vger.kernel.org X-Gm-Message-State: AOJu0Yyz1ZjkRPEGX7CXkwwlH+F7pTI3Yr+VE6qn3q1G9HVW6RAlkKbV imBIa78JREJ2SbO3ILHaEmOVvT9x5Q6BzpTu/n7txHehShIXaw/Xxtz6UsE= X-Google-Smtp-Source: AGHT+IFTtAIbKvQ4WSBihFqCuysx6SerVOR0yHxJZyGQPpm1cBM+uEjEKheafjWJB3/8SGTrhMFuXg== X-Received: by 2002:a17:902:e548:b0:20b:951f:6dff with SMTP id d9443c01a7336-210c673ae39mr188774055ad.0.1730298451479; Wed, 30 Oct 2024 07:27:31 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc03d50esm81347085ad.231.2024.10.30.07.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:31 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 06/12] selftests: ncdevmem: Switch to AF_INET6 Date: Wed, 30 Oct 2024 07:27:16 -0700 Message-ID: <20241030142722.2901744-7-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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 037fb6e97d29..8e4a0fe74bb1 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -242,13 +242,22 @@ static int configure_channels(unsigned int rx, 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); @@ -299,13 +308,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; @@ -317,9 +356,12 @@ int do_server(struct memory_buffer *mem) int socket_fd; int client_fd; size_t i = 0; - int opt = 1; int ret; + ret = parse_address(server_ip, atoi(port), &server_sin); + if (ret < 0) + error(1, 0, "parse server address"); + if (reset_flow_steering()) error(1, 0, "Failed to reset flow steering\n"); @@ -328,7 +370,7 @@ int do_server(struct memory_buffer *mem) error(1, 0, "Failed to configure rss\n"); /* Flow steer our devmem flows to start_queue */ - if (configure_flow_steering()) + if (configure_flow_steering(&server_sin)) error(1, 0, "Failed to configure flow steering\n"); sleep(1); @@ -349,29 +391,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 (ret < 0) - error(1, errno, "%s: [FAIL, create socket]\n", TEST_PREFIX); - - socket_fd = socket(server_sin.sin_family, SOCK_STREAM, 0); + socket_fd = socket(AF_INET6, SOCK_STREAM, 0); if (socket_fd < 0) error(1, errno, "%s: [FAIL, create socket]\n", TEST_PREFIX); - ret = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &opt, - sizeof(opt)); - if (ret) - error(1, errno, "%s: [FAIL, set sock opt]\n", TEST_PREFIX); - - ret = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &opt, - sizeof(opt)); + 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) @@ -383,16 +412,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 30 14:27:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856618 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2DDD1F76B1; Wed, 30 Oct 2024 14:27:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298455; cv=none; b=F5FISFIj8ZiFJl22SFLbwYuDGlM8thYkAG8n8mASt6mO18fGAZcTdpWuiY2OFAhwbAWcnZxAAuzRxYR7Ni7A8MYVZddSbZKv3OwX2+xe4KW081JJqjtMVgPQLI9V2kq8gRU+6yEAdZJ8ZNLBDKL+kmSZ25vA5B2SkAGn5PWiAAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298455; c=relaxed/simple; bh=Ie/Ptsq9qO1ESENyDMOnFQ6N1E2e+FpWUSYWB06bdOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tu9o5aPuCU19ednPfSQ1n5nYIZVl5zpzqySbfMQ6T88ZYwQ42BiZUFj/MTHQ7m20cvX0n68qoYuzgldQAVjGaE9eBBlZQxTXBaO3HS1CC1CVJn6dt/TEdAl7W+543/YbsmclD0xYUdFuRDTG4Kj1qjj/wtZ29epPIEwHMDkUwBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-20ca1b6a80aso65967425ad.2; Wed, 30 Oct 2024 07:27:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298453; x=1730903253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/RMY5HztPWF4NWuW1QBTHPrJP1v43bJinxEr3M4sUnA=; b=uuplHFaW2wtdYWLEdTOF8RTkI3s/QZ0nesVvBFPx54M+r1O9uEOB+9cFTpyic0ET/6 mtltgKUEsJEzRF/nsnduhm3Ti4Jye7agoHJmLnLK+2l65WRl71OeUIU4PoRojbh9+sSC D+dXZGV3m7cY+JRQWaP5/mb7My08JDIijAqHo18ADJ5aKEnIr1r/E7P8jDj1ghRZqq96 b0+M+dmEVqtp83vBD+R8VPnlLLlo5JRYXzpRxJS2aXS6x7nxMTNO6g5b/zPZnG1kf/RR wb7wCUaBQISQ8MYFvFzYpdh4/g5xpKcDKx4zMM5bRzqr32boJUQ0w1rX9qA+Xk7QAwDE S74A== X-Forwarded-Encrypted: i=1; AJvYcCUjeqtAiTSnsNioj7WiEeqjFuZWqUQMW/WoeSWZuP40cysyDdcLl2ExepbDbulueWv/Zf4oOOH//muwhyk=@vger.kernel.org, AJvYcCXHncnTVpxhx3uO01xCzRdSqDmMq9/gMigpyR0/OG6EifxEoRjCH8H73XyN7+3XRX644ts3SykX0Hw4cbuvrIt9@vger.kernel.org X-Gm-Message-State: AOJu0YwgIXBy3vYZmAwy0CeUakv3gCRMUAyUOjSYlPPY/G8aZ/7ozpap E0q7ndNNf5muCtsSVm+5vBQu8MmDBGXj+y4jIYYaWMtM/A/34pJPQvYA4Sg= X-Google-Smtp-Source: AGHT+IF7WpuTgTe7n9pEyhkelv8MdxKn5f3fAEgcGmK2Nv+2M/7Z0RGaPxjCPQJeKEcz4PgKrcWXcg== X-Received: by 2002:a17:902:e883:b0:20b:7210:5859 with SMTP id d9443c01a7336-210c6c75ad9mr227321995ad.38.1730298452831; Wed, 30 Oct 2024 07:27:32 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc02edf3sm81512725ad.205.2024.10.30.07.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:32 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 07/12] selftests: ncdevmem: Properly reset flow steering Date: Wed, 30 Oct 2024 07:27:17 -0700 Message-ID: <20241030142722.2901744-8-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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 8e4a0fe74bb1..697771c1f9fa 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -217,13 +217,18 @@ void validate_buffer(void *line, size_t size) 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 30 14:27:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856619 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 23F7D1F892D; Wed, 30 Oct 2024 14:27:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298457; cv=none; b=iRfphjuaLSTxJ3E9DISz2eYNZ/DpreyaGwkiroqSlRtmUQRoIJApeJnGgwxDp57zzxNPPvzhSRnMF2UDe+FjuMmOdZks8qu9OdS2n5wmBAyiRBxjIyoIU14Fcwmi2XkUF0IzE/Kyh8BnfgXyFnmTE/rNpE19gNArG9Q/GqjZ5eM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298457; c=relaxed/simple; bh=HQzDey7GgEVa3rTI5jthiLJDrmkMe+R6419M0Ug8+yg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=urcN6hOZ7i6VFyrvjXnhEBLDIaux1/SvuAPtHhbXwMhGBt+DvSP2BAumTZtVw7Dbwy6X+gMC3kqqJAZJ///K8FX38mX9fgAHGICo4oNB0TDfdNHCfRQz6gnSv26ghi7N25OX9Jvwo1sibZ8DcVhLjWnhivokD0E7yFo3cNdVNsA= 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.54 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-f54.google.com with SMTP id 98e67ed59e1d1-2e2a97c2681so5008454a91.2; Wed, 30 Oct 2024 07:27:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298454; x=1730903254; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/lZRzUOJGf0+vqtRPw1M1zfctMTkla5AJBP9vN6QXRw=; b=bUdE3OQmcrutewdmsJiGfGo/Dyv/AxSyS/m/ltxwdYFUpgcrsdRDodhCUgqmTpc2m4 xeq8QH6nIUTVH4di3G+B9MY0Fdagf820SF/P+SM6GsU6X82EcBzNfb3VKvW7V9NZQQpD xO5uU8pGR1y17hpa4Rw17VN3jPGOixOE2K2bJIxVVj+zejtQEWQYQdAhJSGorgFwugZE TZ/BHFmqh+1qp7aodSfGwT3UwiUNG3BzqEEZ4orbXUhpG+c7+KLWfXg1VGWU/t56rxlW KsQe6fVcVKZtjhH8u8dl/1tz/euBn+TCA2vWaFCNpnfiG+h0QTYsharYH1DsSfmXHzfM v/Mw== X-Forwarded-Encrypted: i=1; AJvYcCUP2cA1N/9F44KL4U4R6bhvImbHRMaBNgdBellq39XM93WJfnN/tXvojWPQoknFqd1UvPjQtOCGH+yUvlU=@vger.kernel.org, AJvYcCVJmX7RBxeL41IhG/qwYxT0Fy9ZbKVOC0fFXoJbfS3okrPphh4ignT0F6iLUWo6khApQYnsq5FyzwRuxjTbTPEo@vger.kernel.org X-Gm-Message-State: AOJu0Yw9xFyqvkLLNoNB7Sdqt3/1xGIRap2YyufSBoPQzwH1BKxkyQLB HeS8gNk1WOkYcWMpi9CYQCUFcT0Sq/ESunWruBfUr5Pjv5SJpD4sXzZYjbQ= X-Google-Smtp-Source: AGHT+IFsH/EwXVMLCxRW/raeS6EBiQwsIMQYcxG/dXnvDNoTZFiN7pBi8KR5sP8ApAZo7L9SVZGheA== X-Received: by 2002:a17:90a:53a2:b0:2e0:f896:b806 with SMTP id 98e67ed59e1d1-2e92cf2d020mr3697105a91.27.1730298454077; Wed, 30 Oct 2024 07:27:34 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e92fbfb05asm1756851a91.48.2024.10.30.07.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:33 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 08/12] selftests: ncdevmem: Use YNL to enable TCP header split Date: Wed, 30 Oct 2024 07:27:18 -0700 Message-ID: <20241030142722.2901744-9-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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 26a4883a65c9..759b1d2dc8b4 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -111,7 +111,7 @@ TEST_INCLUDES := forwarding/lib.sh include ../lib.mk # YNL build -YNL_GENS := netdev +YNL_GENS := ethtool netdev include ynl.mk $(OUTPUT)/epoll_busy_poll: LDLIBS += -lcap diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index 697771c1f9fa..e1faad46548b 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -55,10 +55,12 @@ #include #include #include +#include #include #include #include "netdev-user.h" +#include "ethtool-user.h" #include #define PAGE_SHIFT 12 @@ -231,10 +233,58 @@ static int reset_flow_steering(void) return 0; } +static const char *tcp_data_split_str(int val) +{ + switch (val) { + case 0: + return "off"; + case 1: + return "auto"; + case 2: + return "on"; + default: + return "?"; + } +} + static int configure_headersplit(bool on) { - return run_command("sudo ethtool -G %s tcp-data-split %s >&2", ifname, - on ? "on" : "off"); + struct ethtool_rings_get_req *get_req; + struct ethtool_rings_get_rsp *get_rsp; + struct ethtool_rings_set_req *req; + struct ynl_error yerr; + struct ynl_sock *ys; + int ret; + + ys = ynl_sock_create(&ynl_ethtool_family, &yerr); + if (!ys) { + fprintf(stderr, "YNL: %s\n", yerr.msg); + return -1; + } + + req = ethtool_rings_set_req_alloc(); + ethtool_rings_set_req_set_header_dev_index(req, ifindex); + /* 0 - off, 1 - auto, 2 - on */ + ethtool_rings_set_req_set_tcp_data_split(req, on ? 2 : 0); + ret = ethtool_rings_set(ys, req); + if (ret < 0) + fprintf(stderr, "YNL failed: %s\n", ys->err.msg); + ethtool_rings_set_req_free(req); + + if (ret == 0) { + get_req = ethtool_rings_get_req_alloc(); + ethtool_rings_get_req_set_header_dev_index(get_req, ifindex); + get_rsp = ethtool_rings_get(ys, get_req); + ethtool_rings_get_req_free(get_req); + if (get_rsp) + fprintf(stderr, "TCP header split: %s\n", + tcp_data_split_str(get_rsp->tcp_data_split)); + ethtool_rings_get_rsp_free(get_rsp); + } + + ynl_sock_destroy(ys); + + return ret; } static int configure_rss(void) @@ -370,6 +420,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 30 14:27:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856620 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.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 CF0961F1304; Wed, 30 Oct 2024 14:27:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298458; cv=none; b=QCfNBn8yTlv+wQGEZ3ehAkTWVbLeJiBBQ/UKiK80+7nb94FUK6saLzskW5LAB7+W4hefWloQEzwQKUNZE9pwwPLUObYBC1tMb3EarUlqG/6GHuEyxL4NIooSigghjexoDvsRgY0pJGhTkpAuu2s8mncVpEFD0Tk/5EHkmlo7riQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298458; c=relaxed/simple; bh=og3zr3saPqbWT0VxgUJgzCO724Ye3nF8hiqLbYRm8GU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lniayxi+Bo6pqZU7NVsU1eZug2aobSNS1xFXh/Ryg/5UVPyX7aAYsY1mjdq/Ae8nRErD79xKoZCqJwiUdcn+m6qCAaiYC0J8KoWmD9x142Q4ZT4cIF1gqi7xR2N3XU+LY5VGA9IAsGnp9EZWc23L9TuF4YeluWqwQ2IJF9HlnBY= 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.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-pg1-f180.google.com with SMTP id 41be03b00d2f7-656d8b346d2so4592062a12.2; Wed, 30 Oct 2024 07:27:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298456; x=1730903256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0+bp/FLvuQ/H/YT5HFz5uDgTntUpplmekx3z9WyNTng=; b=jxTgJKwJr3HptIs52XB4ZJeMVg8hr/eZYKqGumNUFwVmgEnye9uxDxjkDCAywNTO3h BFLDONf/bKvxwyjEOtMUWPfpi/j88ck0RFWNzQHXnGld81GJJOKL/ug9iVI6iwo7cvix AsesDIinHlPRVE/pDx9KYTVNCtQA6scD39ThIbfLS8V02GyC73OwwE9O5u7VXp3yblp8 dL1y0/MlnCEv8fbnfZdxRz6Ni8Xh/EQ01Jn4bp0yRyBJgHGzP97hBRWYcYt+J+hsYfS0 2P4eI+NeVWQbba221c9p8UrODW61Q56C8SN0lt3BRChTGbzHRXZE95OJFnD5VcXwBRNb 0lyg== X-Forwarded-Encrypted: i=1; AJvYcCWTS55AbobvXORzllcnRDpiRAwlChVgf5N3EemDXl9uWx9zZ81SSLJJy326nLn03sWVL7f8q33pqYY2w1GoXuJy@vger.kernel.org, AJvYcCX3/Sr5yebJpnYkXhvBC1GLiZEL8LReQzDPIlHopusYTZjzkiSivRiidaHRL5vvKy2Rj8Yrrrzfh5N7H7w=@vger.kernel.org X-Gm-Message-State: AOJu0YxXwN0vcevku5oufBtpjWlk16sJBvsvb6TCVhUxgN8/aUP8S1xH hROW8692PlB4qcG7l+I/YcM7ryTtSx7MHg6N0Jv7eCix911NzpsyVf2eh1c= X-Google-Smtp-Source: AGHT+IFNbGrqHHMfY+G+fciJmPrc6K3Oy5dPTfwsk3FBfXZZKnnOnxcIuLShI6o9je+d/FignN4u8A== X-Received: by 2002:a05:6a21:3a4a:b0:1d9:3957:8c24 with SMTP id adf61e73a8af0-1d9a83ffdb5mr21634630637.21.1730298455740; Wed, 30 Oct 2024 07:27:35 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057931e2csm9268012b3a.63.2024.10.30.07.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:35 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 09/12] selftests: ncdevmem: Remove hard-coded queue numbers Date: Wed, 30 Oct 2024 07:27:19 -0700 Message-ID: <20241030142722.2901744-10-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 40 ++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index e1faad46548b..fe4d81ef1ca5 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -75,8 +75,8 @@ static char *server_ip; static char *client_ip; static char *port; static size_t do_validation; -static int start_queue = 8; -static int num_queues = 8; +static int start_queue = -1; +static int num_queues = 1; static char *ifname; static unsigned int ifindex; static unsigned int dmabuf_id; @@ -208,6 +208,33 @@ void validate_buffer(void *line, size_t size) fprintf(stdout, "Validated buffer\n"); } +static int rxq_num(int ifindex) +{ + struct ethtool_channels_get_req *req; + struct ethtool_channels_get_rsp *rsp; + struct ynl_error yerr; + struct ynl_sock *ys; + int num = -1; + + ys = ynl_sock_create(&ynl_ethtool_family, &yerr); + if (!ys) { + fprintf(stderr, "YNL: %s\n", yerr.msg); + return -1; + } + + req = ethtool_channels_get_req_alloc(); + ethtool_channels_get_req_set_header_dev_index(req, ifindex); + rsp = ethtool_channels_get(ys, req); + if (rsp) + num = rsp->rx_count + rsp->combined_count; + ethtool_channels_get_req_free(req); + ethtool_channels_get_rsp_free(rsp); + + ynl_sock_destroy(ys); + + return num; +} + #define run_command(cmd, ...) \ ({ \ char command[256]; \ @@ -702,6 +729,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 30 14:27:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856621 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.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 DA8811F9423; Wed, 30 Oct 2024 14:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298459; cv=none; b=L4pf68z3Dr4zjTURNpj7Tqvqx9YtC2sfsV6VOCgiNGXbALHGR51HM9Y3LCFJ9EVDE3LEB+4x5McUzU5Oa5Hyho9gXtjp0GGKDX0pgirh/cOUw3M/TLpi22bJPvIFhFIfoImyBS/7AK/EPZwq6ZbGWf1A3pNx0ACMuZ2T9l8LU0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298459; c=relaxed/simple; bh=oFNEdZLPtcjUpbqtcRQsl/ELJcA51ONRPBDy5kQu3qk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L+9DT9P9TU7ycRiOznPJ3S5zl+uYwjqpewZ0Tk7Opc+OWiwSHsxWkdpIbLX72fhBIAHALpEaCHwfkEBdLdEeS+TzjnQ1/RGxtxuQs4mG4RT9VCkt+NUF0w7lrHkuy0B7R7RTU6GSXLqMREKX+UquNoJkRZhQ4PznjbiftUGU76g= 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.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-pf1-f180.google.com with SMTP id d2e1a72fcca58-71e4244fdc6so4848951b3a.0; Wed, 30 Oct 2024 07:27:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298457; x=1730903257; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MebxHJqXK6owyg4bREmStt7nVbsj68A52KHrJWNeIO4=; b=YxK3naE6kS/LlqtnIZXvVzxZKl/mbm8H216TbgHZYtYAt0DODRiY4wvtFtqYRkNM3q Q7C/lLVOZwdROcSncacyVPmdr7ohRR1rNUx7G/D9d6rfXxItc76N+UjsrUvQH1PeKR7j 0f1qvCwtQLSwiMwedIKB0E/ipmAsyG2QExK5v3iKO+MoswNkX+3g/dMzTAOPM5p6Wrc3 mJSmsmZCvNXGnxiN2ZQqGQ9tZeRlQeV7Obcg8NjX4aIleM64jlDTBRGHjZwTuZyl28k6 C3SKLnWO5ui3ChL/jtN5xlkMlZcEgAXhAULRUdTglQXV/0v0twMlWcumwuf19eYufL9a ow/A== X-Forwarded-Encrypted: i=1; AJvYcCWPH8dycwaZXqCYdBHgeTiKvjNcXDfYaTFpsH7scK6AzpBklYUYyefwh34BLRwwM5cl34Wdo+kk+qqnqBcjCPnW@vger.kernel.org, AJvYcCWrjdRS4Pb5uLwVhCs2o9Q0RGwoppVf+f/qDGs9PzmnBfBNZw1TaNZZ65YEpdXPbDXqPfdwO6Mv0VKdihA=@vger.kernel.org X-Gm-Message-State: AOJu0YyN2+Z8jx1xl+jU9JrKPPUZ/uElY1ARF1XWlY76XlgAdD47d1aN 8UDHh3TUJVEIyXeYX+QLhb6NFgWYY7pwSpU6MBxS4GSPs5xwFb6PaKyZlmk= X-Google-Smtp-Source: AGHT+IFf+tmAlRwEcCyViWcW+IoTTFcT2WOQzOSIcRvMn1akHgYmQJnJrFGtwNsZgIcV9kgtZKzF6g== X-Received: by 2002:a05:6a00:3c87:b0:71e:21c:bf1b with SMTP id d2e1a72fcca58-72062fb2df2mr23094235b3a.14.1730298456897; Wed, 30 Oct 2024 07:27:36 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057a3c2c9sm9252837b3a.196.2024.10.30.07.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:36 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 10/12] selftests: ncdevmem: Run selftest when none of the -s or -c has been provided Date: Wed, 30 Oct 2024 07:27:20 -0700 Message-ID: <20241030142722.2901744-11-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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. Reviewed-by: Mina Almasry Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/ncdevmem.c | 42 ++++++++++++++++++++------ 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c index fe4d81ef1ca5..07a91516103a 100644 --- a/tools/testing/selftests/net/ncdevmem.c +++ b/tools/testing/selftests/net/ncdevmem.c @@ -76,7 +76,7 @@ static char *client_ip; static char *port; static size_t do_validation; static int start_queue = -1; -static int num_queues = 1; +static int num_queues = -1; static char *ifname; static unsigned int ifindex; static unsigned int dmabuf_id; @@ -718,19 +718,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_queue = num_queues / 2; + num_queues /= 2; + } + + if (start_queue < 0 || num_queues < 0) + error(1, 0, "Both -t and -q are required\n"); + + run_devmem_tests(); + return 0; + } + + if (start_queue < 0 && num_queues < 0) { + num_queues = 1; + start_queue = rxq_num(ifindex) - num_queues; if (start_queue < 0) error(1, 0, "couldn't detect number of queues\n"); @@ -741,7 +753,17 @@ int main(int argc, char *argv[]) for (; optind < argc; optind++) fprintf(stderr, "extra arguments: %s\n", argv[optind]); - 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 30 14:27:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856622 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95C431F9A9D; Wed, 30 Oct 2024 14:27:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298461; cv=none; b=MplyaZUdUUQe+m6Djl4GKlVTcvln9HqHtAWTRI/8PFuRy6cM7GAFSUROnbSInkxSSRZa1bhjq9DMsgpkd/ytkmvEVr017i7D1p2G2AWt4/3cZhpCctx27JJIPA2jLfXXdEGz9pflM0Kv4PVlSsWsFAVPpLLL++edmuI0pfa6bs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298461; c=relaxed/simple; bh=QNIVoaUG6HoJ02+8aCHTzhZtbDvKJFEGC7k27W7G0/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LMUJH52Pfk3wavjmY7FYaqgFdLYRE7/qEAMBtmTMTbQ9j3tEN33PRhfp8DAUGP/E7AjnIA/Vz919KTdsYKBns67F/A9FWku29fkJrFpbiSUnvuMkOdSnWcrxLXt+a38lQ2vSreoXqXbfo1U1cx99bD9Kq5NEfIZsF0yKhhx+uPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-72097a5ca74so1469947b3a.3; Wed, 30 Oct 2024 07:27:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298458; x=1730903258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WLuAo808h43hPUqDZon7CMUoTgxLTq7GJOn3Y6RziyQ=; b=WUBl51PIWHVHrmbGViOSBnJ9z0IujCuJ9Z1aWio0q0UuNzKDfXc00grDf1UJe489LD 1814p3zqrgzNRjp2u+41JtM8/rPnjkrjOY/QREjwDbtKX+laYZu1XRzqxvPRDHEic24L SqPpRXyrKE5jlND+65hXUkKKkdaPSCA60cQut0DSvuB9mwwutV98bbLPM3qAgLEBhXla W2qU4fE7uZuHrr5zkOuvWMFnBs7w3GcI3qrCsgn5CNHK2/KUYUZPBeDHyFWkTos1gTWy D6DlH+WeYbTXX3QnSvJ0nSAeaVbUpQJ3Zrk2TuUlmd1fBlC8Efrari3jH4gDz+xTZTx6 MOGQ== X-Forwarded-Encrypted: i=1; AJvYcCUNg7WRUd0la24Ikte/RXOD86+k1y/P7E9vWlCtCUo2a3tNtxdd1qhhiwLTlB/UqxZgEurHdY8GpjA3344=@vger.kernel.org, AJvYcCVlZPIEtRQG7nfpNgbJLIl8piBriAyU2iJDDW/J4fE2QKoGevdfR7JG8HqzNnF7x+iYpcXMofcBFPLkToebWRmu@vger.kernel.org X-Gm-Message-State: AOJu0YzGaFA3nvpmNtcFJonnbwiO89dqrhAJxaW6tq86tzo3f7Pn7Ni/ +2cm/HMfbVyv4arGfIbotsJ7JQcgok9etkw1/HsFGavmdG0him+DGa/nc1Y= X-Google-Smtp-Source: AGHT+IGESpx2DY1HGdcUopbjIVIaRxqP0Rfsk2Qrsm0ApMsyz45s7oVrRnqsp+St8+IrdHSqrYtw1w== X-Received: by 2002:a05:6a00:1884:b0:71d:fe19:83ee with SMTP id d2e1a72fcca58-72062f8f29bmr21410627b3a.10.1730298458200; Wed, 30 Oct 2024 07:27:38 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057a1eec0sm9596351b3a.143.2024.10.30.07.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:37 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 11/12] selftests: ncdevmem: Move ncdevmem under drivers/net/hw Date: Wed, 30 Oct 2024 07:27:21 -0700 Message-ID: <20241030142722.2901744-12-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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 | 8 ++++++++ .../testing/selftests/{net => drivers/net/hw}/ncdevmem.c | 0 tools/testing/selftests/net/.gitignore | 1 - tools/testing/selftests/net/Makefile | 8 -------- 5 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 tools/testing/selftests/drivers/net/hw/.gitignore rename tools/testing/selftests/{net => drivers/net/hw}/ncdevmem.c (100%) diff --git a/tools/testing/selftests/drivers/net/hw/.gitignore b/tools/testing/selftests/drivers/net/hw/.gitignore new file mode 100644 index 000000000000..e9fe6ede681a --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/.gitignore @@ -0,0 +1 @@ +ncdevmem diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index c9f2f48fc30f..182348f4bd40 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -26,4 +26,12 @@ TEST_INCLUDES := \ ../../../net/forwarding/tc_common.sh \ # +# YNL files, must be before "include ..lib.mk" +YNL_GEN_FILES := ncdevmem +TEST_GEN_FILES += $(YNL_GEN_FILES) + include ../../../lib.mk + +# YNL build +YNL_GENS := ethtool netdev +include ../../../net/ynl.mk diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/drivers/net/hw/ncdevmem.c similarity index 100% rename from tools/testing/selftests/net/ncdevmem.c rename to tools/testing/selftests/drivers/net/hw/ncdevmem.c diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore index 217d8b7a7365..a78debbd1fe7 100644 --- a/tools/testing/selftests/net/.gitignore +++ b/tools/testing/selftests/net/.gitignore @@ -18,7 +18,6 @@ ipv6_flowlabel_mgr log.txt msg_oob msg_zerocopy -ncdevmem nettest psock_fanout psock_snd diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 759b1d2dc8b4..22a5d6a7c3f3 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -97,10 +97,6 @@ TEST_PROGS += fq_band_pktlimit.sh TEST_PROGS += vlan_hw_filter.sh TEST_PROGS += bpf_offload.py -# YNL files, must be before "include ..lib.mk" -YNL_GEN_FILES := ncdevmem -TEST_GEN_FILES += $(YNL_GEN_FILES) - TEST_FILES := settings TEST_FILES += in_netns.sh lib.sh net_helper.sh setup_loopback.sh setup_veth.sh @@ -110,10 +106,6 @@ TEST_INCLUDES := forwarding/lib.sh include ../lib.mk -# YNL build -YNL_GENS := ethtool netdev -include ynl.mk - $(OUTPUT)/epoll_busy_poll: LDLIBS += -lcap $(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma $(OUTPUT)/tcp_mmap: LDLIBS += -lpthread -lcrypto From patchwork Wed Oct 30 14:27:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13856623 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.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 91C641F9EBB; Wed, 30 Oct 2024 14:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298462; cv=none; b=mytIsM66lT+8MwoTw3CxY6pvwI6M+0DjA3itQTiZQ+ZetIrhHlHMvHtObvGyBVARII4n1uYmyrwH6pfqzh8kbsTC+aPUGRIEt+u477VI0zILPWx/w19heb9Im96wZCvVtf3nDcSDovbZF9cdxOu3tl1Mv/4ivAE3lnC+5EOuxJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730298462; c=relaxed/simple; bh=k3NksgKMGGwSiQjqqQDiIoWxu2o4MtjaGnPwO3kHGQE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kFtt4t+Q4WPxNHpNJw1/wK+1xPlY6hFhzTZaGE3R3dCKh2qgH17TwxMMeV08+EcJaOtpzX+l+BMu6VcavXg4da7/zlm8JrdyXNpkqF3uEuI6Czex2zOeXH9J4ML9GtcfinUyqFAY217wiRN3uNjNeHL8THuKvsFHEDVC3EKmA04= 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.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-pg1-f182.google.com with SMTP id 41be03b00d2f7-7ea76a12c32so5144035a12.1; Wed, 30 Oct 2024 07:27:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730298459; x=1730903259; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X3YqyV0YwGuilWF+8lpqEcTlB/FpyMoTdw0SNw6nZVo=; b=hBWfQHUe7ygOTl1jFrJirurdos6WzAOSd/MKc/YiyZKZ2ffCNcSfAm2dZuzOFPvyCu P5tctNe6eqBpn0i/Ve4X/RyII3Bu8ICBiX144M4Jf+Jw+t7C3RwaiWicdD7yPq4uS+Bv oD/A1bNXkf42wT3M56fQm3V9R8ifBb2LtPQkNgjYouKBudPcB0fKqAUGTCh/QnXGpvxd 3tFaJhllDYUuuwclRbYw5WmBQvrDNeJ2jHOGEpRJX6AxNF8VrSDES9xDb/rFwczsB5sH beLSzgwEOfnebQecLQeu3WztYRJ0NjxGzlO3OCU9Qbz5gu1+Sh6eIjM3NnUf8KDtggRA DhWQ== X-Forwarded-Encrypted: i=1; AJvYcCVB8bx/Zax0THTk5tQFirphC46sRUjY0de91fjjhYgIeGMBFQif8bxTjbrpOg8X7c0xwASl/2oqqY1pMF9Y8Wel@vger.kernel.org, AJvYcCWDbiv8eSNXEK3zxE4Q1xTqYz5lpGWhP+tWCZw1CPugducTNEJZ620tvcic3Zz/o6QRudX+xmpSD3jJy1c=@vger.kernel.org X-Gm-Message-State: AOJu0YyqUdSIf3ttiAdSEbPwlnFHxU0s/geonF8ZMTGzaG7VGUCn41Y9 qhAm8VARWliLwC+BTLfEDR/PiDIRkI4djCV9zMT1rUnPoqASQNt9zVQRerc= X-Google-Smtp-Source: AGHT+IFa0T3NhLLZTVYB47aMtxMkeD80BrpeKBP22/0bqgcXxhS+vEBtm3n6X1TYaNAhdmXADKD2sQ== X-Received: by 2002:a05:6a21:1707:b0:1d9:d8d:d0a4 with SMTP id adf61e73a8af0-1d9a83a913emr19237362637.9.1730298459536; Wed, 30 Oct 2024 07:27:39 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720579397d8sm9346440b3a.86.2024.10.30.07.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:27:39 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, horms@kernel.org, sdf@fomichev.me, almasrymina@google.com, willemb@google.com, petrm@nvidia.com Subject: [PATCH net-next v6 12/12] selftests: ncdevmem: Add automated test Date: Wed, 30 Oct 2024 07:27:22 -0700 Message-ID: <20241030142722.2901744-13-sdf@fomichev.me> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030142722.2901744-1-sdf@fomichev.me> References: <20241030142722.2901744-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 | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/hw/devmem.py diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 182348f4bd40..1c6a77480923 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -3,6 +3,7 @@ TEST_PROGS = \ csum.py \ devlink_port_split.py \ + devmem.py \ ethtool.sh \ ethtool_extended_state.sh \ ethtool_mm.sh \ diff --git a/tools/testing/selftests/drivers/net/hw/devmem.py b/tools/testing/selftests/drivers/net/hw/devmem.py new file mode 100755 index 000000000000..1416c31ff81e --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/devmem.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +from lib.py import ksft_run, ksft_exit +from lib.py import ksft_eq, KsftSkipEx +from lib.py import NetDrvEpEnv +from lib.py import bkg, cmd, rand_port, wait_port_listen +from lib.py import ksft_disruptive + + +def require_devmem(cfg): + if not hasattr(cfg, "_devmem_probed"): + port = 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()