Skip to contentSkip to conversation

net: devmem: support single IOV with sendmsg

PATCH In review Stanislav Fomichev 4 participants 13 messages May 20, 2025 – May 28, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 net: devmem: support single IOV with sendmsg

sendmsg() with a single iov becomes ITER_UBUF, sendmsg() with multiple iovs becomes ITER_IOVEC. iter_iov_len does not return correct value for UBUF, so teach to treat UBUF differently.

Cc Al Viro <[email protected]>
Cc Pavel Begunkov <[email protected]>
Cc Mina Almasry <[email protected]>
Fixes bd61848900bf ("net: devmem: Implement TX path")
---
 include/linux/uio.h | 8 +++++++-
 net/core/datagram.c | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)
include/linux/uio.h +7 -1
index 49ece9e1888f..393d0622cc28 100644
@@ -99,7 +99,13 @@ static inline const struct iovec *iter_iov(const struct iov_iter *iter)
 }
 
 #define iter_iov_addr(iter)	(iter_iov(iter)->iov_base + (iter)->iov_offset)
-#define iter_iov_len(iter)	(iter_iov(iter)->iov_len - (iter)->iov_offset)
+
+static inline size_t iter_iov_len(const struct iov_iter *i)
+{
+	if (i->iter_type == ITER_UBUF)
+		return i->count;
+	return iter_iov(i)->iov_len - i->iov_offset;
+}
 
 static inline enum iter_type iov_iter_type(const struct iov_iter *i)
 {
net/core/datagram.c +2 -1
index 9ef5442536f5..c44f1d2b70a4 100644
@@ -706,7 +706,8 @@ zerocopy_fill_skb_from_devmem(struct sk_buff *skb, struct iov_iter *from,
 	 * iov_addrs are interpreted as an offset in bytes into the dma-buf to
 	 * send from. We do not support other iter types.
 	 */
-	if (iov_iter_type(from) != ITER_IOVEC)
+	if (iov_iter_type(from) != ITER_IOVEC &&
+	    iov_iter_type(from) != ITER_UBUF)
 		return -EFAULT;
 
 	while (length && iov_iter_count(from)) {
Signature · 1 line
2.49.0
#1 lore raw

PATCH 2/3 selftests: ncdevmem: make chunking optional

Add new -z argument to specify max IOV size. By default, use single large IOV.

---
 .../selftests/drivers/net/hw/ncdevmem.c       | 49 +++++++++++--------
 1 file changed, 29 insertions(+), 20 deletions(-)
tools/testing/selftests/drivers/net/hw/ncdevmem.c +29 -20
index ca723722a810..fc7ba7d71502 100644
@@ -82,6 +82,9 @@
 #define MSG_SOCK_DEVMEM 0x2000000
 #endif
 
+#define MAX_IOV 1024
+
+static size_t max_chunk;
 static char *server_ip;
 static char *client_ip;
 static char *port;
@@ -834,10 +837,10 @@ static int do_client(struct memory_buffer *mem)
 	struct sockaddr_in6 server_sin;
 	struct sockaddr_in6 client_sin;
 	struct ynl_sock *ys = NULL;
+	struct iovec iov[MAX_IOV];
 	struct msghdr msg = {};
 	ssize_t line_size = 0;
 	struct cmsghdr *cmsg;
-	struct iovec iov[2];
 	char *line = NULL;
 	unsigned long mid;
 	size_t len = 0;
@@ -893,27 +896,29 @@ static int do_client(struct memory_buffer *mem)
 		if (line_size < 0)
 			break;
 
-		mid = (line_size / 2) + 1;
-
-		iov[0].iov_base = (void *)1;
-		iov[0].iov_len = mid;
-		iov[1].iov_base = (void *)(mid + 2);
-		iov[1].iov_len = line_size - mid;
+		if (max_chunk) {
+			msg.msg_iovlen =
+				(line_size + max_chunk - 1) / max_chunk;
+			if (msg.msg_iovlen > MAX_IOV)
+				error(1, 0,
+				      "can't partition %zd bytes into maximum of %d chunks",
+				      line_size, MAX_IOV);
 
-		provider->memcpy_to_device(mem, (size_t)iov[0].iov_base, line,
-					   iov[0].iov_len);
-		provider->memcpy_to_device(mem, (size_t)iov[1].iov_base,
-					   line + iov[0].iov_len,
-					   iov[1].iov_len);
+			for (int i = 0; i < msg.msg_iovlen; i++) {
+				iov[i].iov_base = (void *)(i * max_chunk);
+				iov[i].iov_len = max_chunk;
+			}
 
-		fprintf(stderr,
-			"read line_size=%ld iov[0].iov_base=%lu, iov[0].iov_len=%lu, iov[1].iov_base=%lu, iov[1].iov_len=%lu\n",
-			line_size, (unsigned long)iov[0].iov_base,
-			iov[0].iov_len, (unsigned long)iov[1].iov_base,
-			iov[1].iov_len);
+			iov[msg.msg_iovlen - 1].iov_len =
+				line_size - (msg.msg_iovlen - 1) * max_chunk;
+		} else {
+			iov[0].iov_base = 0;
+			iov[0].iov_len = line_size;
+			msg.msg_iovlen = 1;
+		}
 
 		msg.msg_iov = iov;
-		msg.msg_iovlen = 2;
+		provider->memcpy_to_device(mem, 0, line, line_size);
 
 		msg.msg_control = ctrl_data;
 		msg.msg_controllen = sizeof(ctrl_data);
@@ -934,7 +939,8 @@ static int do_client(struct memory_buffer *mem)
 		fprintf(stderr, "sendmsg_ret=%d\n", ret);
 
 		if (ret != line_size)
-			error(1, errno, "Did not send all bytes");
+			error(1, errno, "Did not send all bytes %d vs %zd", ret,
+			      line_size);
 
 		wait_compl(socket_fd);
 	}
@@ -956,7 +962,7 @@ int main(int argc, char *argv[])
 	int is_server = 0, opt;
 	int ret;
 
-	while ((opt = getopt(argc, argv, "ls:c:p:v:q:t:f:")) != -1) {
+	while ((opt = getopt(argc, argv, "ls:c:p:v:q:t:f:z:")) != -1) {
 		switch (opt) {
 		case 'l':
 			is_server = 1;
@@ -982,6 +988,9 @@ int main(int argc, char *argv[])
 		case 'f':
 			ifname = optarg;
 			break;
+		case 'z':
+			max_chunk = atoi(optarg);
+			break;
 		case '?':
 			fprintf(stderr, "unknown option: %c\n", optopt);
 			break;
Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH net-next 2/3] selftests: ncdevmem: make chunking optional

Quoted 51 lines · Stanislav Fomichev

Add new -z argument to specify max IOV size. By default, use single large IOV.

---
 .../selftests/drivers/net/hw/ncdevmem.c       | 49 +++++++++++--------
 1 file changed, 29 insertions(+), 20 deletions(-)
tools/testing/selftests/drivers/net/hw/ncdevmem.c +10 -7
index ca723722a810..fc7ba7d71502 100644
@@ -82,6 +82,9 @@
 #define MSG_SOCK_DEVMEM 0x2000000
 #endif
 
+#define MAX_IOV 1024
+
+static size_t max_chunk;
 static char *server_ip;
 static char *client_ip;
 static char *port;
@@ -834,10 +837,10 @@ static int do_client(struct memory_buffer *mem)
        struct sockaddr_in6 server_sin;
        struct sockaddr_in6 client_sin;
        struct ynl_sock *ys = NULL;
+       struct iovec iov[MAX_IOV];
        struct msghdr msg = {};
        ssize_t line_size = 0;
        struct cmsghdr *cmsg;
-       struct iovec iov[2];
        char *line = NULL;
        unsigned long mid;
        size_t len = 0;
@@ -893,27 +896,29 @@ static int do_client(struct memory_buffer *mem)
                if (line_size < 0)
                        break;
 
-               mid = (line_size / 2) + 1;
-
-               iov[0].iov_base = (void *)1;
-               iov[0].iov_len = mid;
-               iov[1].iov_base = (void *)(mid + 2);
-               iov[1].iov_len = line_size - mid;
+               if (max_chunk) {
+                       msg.msg_iovlen =
+                               (line_size + max_chunk - 1) / max_chunk;
+                       if (msg.msg_iovlen > MAX_IOV)
+                               error(1, 0,
+                                     "can't partition %zd bytes into maximum of %d chunks",

tools/testing/selftests/drivers/net/hw/ncdevmem.c static int do_client(struct memory_buffer *mem) · line 909

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/ncdevmem.c +4 -5
+                                     line_size, MAX_IOV);
 
-               provider->memcpy_to_device(mem, (size_t)iov[0].iov_base, line,
-                                          iov[0].iov_len);
-               provider->memcpy_to_device(mem, (size_t)iov[1].iov_base,
-                                          line + iov[0].iov_len,
-                                          iov[1].iov_len);
+                       for (int i = 0; i < msg.msg_iovlen; i++) {
+                               iov[i].iov_base = (void *)(i * max_chunk);
+                               iov[i].iov_len = max_chunk;

Isn't the last iov going to be truncated in the case where line_size is not exactly divisible with max_chunk?

Quoted 4 lines
tools/testing/selftests/drivers/net/hw/ncdevmem.c +1 -2
+                       }
 
-               fprintf(stderr,
-                       "read line_size=%ld iov[0].iov_base=%lu, iov[0].iov_len=%lu, iov[1].iov_base=%lu, iov[1].iov_len=%lu\n",

tools/testing/selftests/drivers/net/hw/ncdevmem.c static int do_client(struct memory_buffer *mem) · line 918

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/ncdevmem.c +7 -3
-                       line_size, (unsigned long)iov[0].iov_base,
-                       iov[0].iov_len, (unsigned long)iov[1].iov_base,
-                       iov[1].iov_len);
+                       iov[msg.msg_iovlen - 1].iov_len =
+                               line_size - (msg.msg_iovlen - 1) * max_chunk;
+               } else {
+                       iov[0].iov_base = 0;
+                       iov[0].iov_len = line_size;
+                       msg.msg_iovlen = 1;
+               }

Do you need to special case this? Shouldn't this be the same as max_chunk==1?

Quoted 39 lines
tools/testing/selftests/drivers/net/hw/ncdevmem.c +7 -4
                msg.msg_iov = iov;
-               msg.msg_iovlen = 2;
+               provider->memcpy_to_device(mem, 0, line, line_size);
 
                msg.msg_control = ctrl_data;
                msg.msg_controllen = sizeof(ctrl_data);
@@ -934,7 +939,8 @@ static int do_client(struct memory_buffer *mem)
                fprintf(stderr, "sendmsg_ret=%d\n", ret);
 
                if (ret != line_size)
-                       error(1, errno, "Did not send all bytes");
+                       error(1, errno, "Did not send all bytes %d vs %zd", ret,
+                             line_size);
 
                wait_compl(socket_fd);
        }
@@ -956,7 +962,7 @@ int main(int argc, char *argv[])
        int is_server = 0, opt;
        int ret;
 
-       while ((opt = getopt(argc, argv, "ls:c:p:v:q:t:f:")) != -1) {
+       while ((opt = getopt(argc, argv, "ls:c:p:v:q:t:f:z:")) != -1) {
                switch (opt) {
                case 'l':
                        is_server = 1;
@@ -982,6 +988,9 @@ int main(int argc, char *argv[])
                case 'f':
                        ifname = optarg;
                        break;
+               case 'z':
+                       max_chunk = atoi(optarg);
+                       break;
                case '?':
                        fprintf(stderr, "unknown option: %c\n", optopt);
                        break;
--

2.49.0

Signature · 2 lines
Thanks,
Mina
#3 lore raw

Re: [PATCH net-next 2/3] selftests: ncdevmem: make chunking optional

Quoted 54 lines · Mina Almasry
Quoted 53 lines · Stanislav Fomichev

Add new -z argument to specify max IOV size. By default, use single large IOV.

---
 .../selftests/drivers/net/hw/ncdevmem.c       | 49 +++++++++++--------
 1 file changed, 29 insertions(+), 20 deletions(-)
tools/testing/selftests/drivers/net/hw/ncdevmem.c +11 -7
index ca723722a810..fc7ba7d71502 100644
@@ -82,6 +82,9 @@
 #define MSG_SOCK_DEVMEM 0x2000000
 #endif
 
+#define MAX_IOV 1024
+
+static size_t max_chunk;
 static char *server_ip;
 static char *client_ip;
 static char *port;
@@ -834,10 +837,10 @@ static int do_client(struct memory_buffer *mem)
        struct sockaddr_in6 server_sin;
        struct sockaddr_in6 client_sin;
        struct ynl_sock *ys = NULL;
+       struct iovec iov[MAX_IOV];
        struct msghdr msg = {};
        ssize_t line_size = 0;
        struct cmsghdr *cmsg;
-       struct iovec iov[2];
        char *line = NULL;
        unsigned long mid;
        size_t len = 0;
@@ -893,27 +896,29 @@ static int do_client(struct memory_buffer *mem)
                if (line_size < 0)
                        break;
 
-               mid = (line_size / 2) + 1;
-
-               iov[0].iov_base = (void *)1;
-               iov[0].iov_len = mid;
-               iov[1].iov_base = (void *)(mid + 2);
-               iov[1].iov_len = line_size - mid;
+               if (max_chunk) {
+                       msg.msg_iovlen =
+                               (line_size + max_chunk - 1) / max_chunk;
+                       if (msg.msg_iovlen > MAX_IOV)
+                               error(1, 0,
+                                     "can't partition %zd bytes into maximum of %d chunks",
+                                     line_size, MAX_IOV);
 
Quoted 11 lines

tools/testing/selftests/drivers/net/hw/ncdevmem.c static int do_client(struct memory_buffer *mem) · line 909

Quoted 8 lines
tools/testing/selftests/drivers/net/hw/ncdevmem.c +3 -5
-               provider->memcpy_to_device(mem, (size_t)iov[0].iov_base, line,
-                                          iov[0].iov_len);
-               provider->memcpy_to_device(mem, (size_t)iov[1].iov_base,
-                                          line + iov[0].iov_len,
-                                          iov[1].iov_len);
+                       for (int i = 0; i < msg.msg_iovlen; i++) {
+                               iov[i].iov_base = (void *)(i * max_chunk);
+                               iov[i].iov_len = max_chunk;

Isn't the last iov going to be truncated in the case where line_size is not exactly divisible with max_chunk?

I have this for the last iov entry:

   iov[msg.msg_iovlen - 1].iov_len =
           line_size - (msg.msg_iovlen - 1) * max_chunk;

I think that should correctly adjust it to the remaining 1..max_chunk len?

Quoted 15 lines
Quoted 4 lines
tools/testing/selftests/drivers/net/hw/ncdevmem.c +1 -2
+                       }
 
-               fprintf(stderr,
-                       "read line_size=%ld iov[0].iov_base=%lu, iov[0].iov_len=%lu, iov[1].iov_base=%lu, iov[1].iov_len=%lu\n",

tools/testing/selftests/drivers/net/hw/ncdevmem.c static int do_client(struct memory_buffer *mem) · line 918

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/ncdevmem.c +7 -3
-                       line_size, (unsigned long)iov[0].iov_base,
-                       iov[0].iov_len, (unsigned long)iov[1].iov_base,
-                       iov[1].iov_len);
+                       iov[msg.msg_iovlen - 1].iov_len =
+                               line_size - (msg.msg_iovlen - 1) * max_chunk;
+               } else {
+                       iov[0].iov_base = 0;
+                       iov[0].iov_len = line_size;
+                       msg.msg_iovlen = 1;
+               }
Quoted 1 line

Do you need to special case this? Shouldn't this be the same as max_chunk==1?

I might need a better name. max_chunk is the max size of the iov entry (max iov_len), not the max number of IOVs. And I use max_chunk==0 as "max size of the iov is not provided -> use line_size", so not sure I can't make it work without a special case?

Reviewed-by
#4 lore raw

Re: [PATCH net-next 2/3] selftests: ncdevmem: make chunking optional

Quoted 68 lines · Stanislav Fomichev
Quoted 54 lines · Mina Almasry
Quoted 53 lines · Stanislav Fomichev

Add new -z argument to specify max IOV size. By default, use single large IOV.

---
 .../selftests/drivers/net/hw/ncdevmem.c       | 49 +++++++++++--------
 1 file changed, 29 insertions(+), 20 deletions(-)
tools/testing/selftests/drivers/net/hw/ncdevmem.c +11 -7
index ca723722a810..fc7ba7d71502 100644
@@ -82,6 +82,9 @@
 #define MSG_SOCK_DEVMEM 0x2000000
 #endif
 
+#define MAX_IOV 1024
+
+static size_t max_chunk;
 static char *server_ip;
 static char *client_ip;
 static char *port;
@@ -834,10 +837,10 @@ static int do_client(struct memory_buffer *mem)
        struct sockaddr_in6 server_sin;
        struct sockaddr_in6 client_sin;
        struct ynl_sock *ys = NULL;
+       struct iovec iov[MAX_IOV];
        struct msghdr msg = {};
        ssize_t line_size = 0;
        struct cmsghdr *cmsg;
-       struct iovec iov[2];
        char *line = NULL;
        unsigned long mid;
        size_t len = 0;
@@ -893,27 +896,29 @@ static int do_client(struct memory_buffer *mem)
                if (line_size < 0)
                        break;
 
-               mid = (line_size / 2) + 1;
-
-               iov[0].iov_base = (void *)1;
-               iov[0].iov_len = mid;
-               iov[1].iov_base = (void *)(mid + 2);
-               iov[1].iov_len = line_size - mid;
+               if (max_chunk) {
+                       msg.msg_iovlen =
+                               (line_size + max_chunk - 1) / max_chunk;
+                       if (msg.msg_iovlen > MAX_IOV)
+                               error(1, 0,
+                                     "can't partition %zd bytes into maximum of %d chunks",
+                                     line_size, MAX_IOV);
 
Quoted 11 lines

tools/testing/selftests/drivers/net/hw/ncdevmem.c static int do_client(struct memory_buffer *mem) · line 909

Quoted 8 lines
tools/testing/selftests/drivers/net/hw/ncdevmem.c +3 -5
-               provider->memcpy_to_device(mem, (size_t)iov[0].iov_base, line,
-                                          iov[0].iov_len);
-               provider->memcpy_to_device(mem, (size_t)iov[1].iov_base,
-                                          line + iov[0].iov_len,
-                                          iov[1].iov_len);
+                       for (int i = 0; i < msg.msg_iovlen; i++) {
+                               iov[i].iov_base = (void *)(i * max_chunk);
+                               iov[i].iov_len = max_chunk;

Isn't the last iov going to be truncated in the case where line_size is not exactly divisible with max_chunk?

Quoted 8 lines

I have this for the last iov entry:

   iov[msg.msg_iovlen - 1].iov_len =
           line_size - (msg.msg_iovlen - 1) * max_chunk;

I think that should correctly adjust it to the remaining 1..max_chunk len?

Thanks, I missed that line.

Signature · 2 lines
Thanks,
Mina
#5 lore raw

PATCH 3/3 selftests: ncdevmem: add tx test with multiple IOVs

In reply to Stanislav Fomichev

Use prime 3 for length to make offset slowly drift away.

---
 .../testing/selftests/drivers/net/hw/devmem.py  | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/hw/devmem.py +16 -1
index 7fc686cf47a2..d7f6a76eb2b7 100755
@@ -49,12 +49,27 @@ from lib.py import ksft_disruptive
     ksft_eq(socat.stdout.strip(), "hello\nworld")
 
 
+@ksft_disruptive
+def check_tx_chunks(cfg) -> None:
+    cfg.require_ipver("6")
+    require_devmem(cfg)
+
+    port = rand_port()
+    listen_cmd = f"socat -U - TCP6-LISTEN:{port}"
+
+    with bkg(listen_cmd, exit_wait=True) as socat:
+        wait_port_listen(port)
+        cmd(f"echo -e \"hello\\nworld\"| {cfg.bin_remote} -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port} -z 3", host=cfg.remote, shell=True)
+
+    ksft_eq(socat.stdout.strip(), "hello\nworld")
+
+
 def main() -> None:
     with NetDrvEpEnv(__file__) as cfg:
         cfg.bin_local = path.abspath(path.dirname(__file__) + "/ncdevmem")
         cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
 
-        ksft_run([check_rx, check_tx],
+        ksft_run([check_rx, check_tx, check_tx_chunks],
                  args=(cfg, ))
     ksft_exit()
 
Signature · 1 line
2.49.0
Acked-by on v1 3/3
#6 lore raw

Re: [PATCH net-next 3/3] selftests: ncdevmem: add tx test with multiple IOVs

Quoted 42 lines · Stanislav Fomichev

Use prime 3 for length to make offset slowly drift away.

---
 .../testing/selftests/drivers/net/hw/devmem.py  | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/hw/devmem.py +16 -2
index 7fc686cf47a2..d7f6a76eb2b7 100755
@@ -49,12 +49,27 @@ from lib.py import ksft_disruptive
     ksft_eq(socat.stdout.strip(), "hello\nworld")
 
 
+@ksft_disruptive
+def check_tx_chunks(cfg) -> None:
+    cfg.require_ipver("6")
+    require_devmem(cfg)
+
+    port = rand_port()
+    listen_cmd = f"socat -U - TCP6-LISTEN:{port}"
+
+    with bkg(listen_cmd, exit_wait=True) as socat:
+        wait_port_listen(port)
+        cmd(f"echo -e \"hello\\nworld\"| {cfg.bin_remote} -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port} -z 3", host=cfg.remote, shell=True)
+
+    ksft_eq(socat.stdout.strip(), "hello\nworld")
+
+
 def main() -> None:
     with NetDrvEpEnv(__file__) as cfg:
         cfg.bin_local = path.abspath(path.dirname(__file__) + "/ncdevmem")
         cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
 
-        ksft_run([check_rx, check_tx],
+        ksft_run([check_rx, check_tx, check_tx_chunks],
                  args=(cfg, ))
     ksft_exit()
 
--
Quoted 2 lines

2.49.0

I was hoping we'd add the test coverage without the need to add test cases to the ksft. I was thinking maybe ncdevmem can do rand() each sendmsg loop and send a different set of chunks, so that we don't need a flag.

But it may be too hacky to have the test be non-deterministic, so up to you

Signature · 2 lines
Thanks,
Mina
#7 lore raw

Re: [PATCH net-next 3/3] selftests: ncdevmem: add tx test with multiple IOVs

Quoted 51 lines · Mina Almasry
Quoted 42 lines · Stanislav Fomichev

Use prime 3 for length to make offset slowly drift away.

---
 .../testing/selftests/drivers/net/hw/devmem.py  | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/hw/devmem.py +16 -2
index 7fc686cf47a2..d7f6a76eb2b7 100755
@@ -49,12 +49,27 @@ from lib.py import ksft_disruptive
     ksft_eq(socat.stdout.strip(), "hello\nworld")
 
 
+@ksft_disruptive
+def check_tx_chunks(cfg) -> None:
+    cfg.require_ipver("6")
+    require_devmem(cfg)
+
+    port = rand_port()
+    listen_cmd = f"socat -U - TCP6-LISTEN:{port}"
+
+    with bkg(listen_cmd, exit_wait=True) as socat:
+        wait_port_listen(port)
+        cmd(f"echo -e \"hello\\nworld\"| {cfg.bin_remote} -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port} -z 3", host=cfg.remote, shell=True)
+
+    ksft_eq(socat.stdout.strip(), "hello\nworld")
+
+
 def main() -> None:
     with NetDrvEpEnv(__file__) as cfg:
         cfg.bin_local = path.abspath(path.dirname(__file__) + "/ncdevmem")
         cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
 
-        ksft_run([check_rx, check_tx],
+        ksft_run([check_rx, check_tx, check_tx_chunks],
                  args=(cfg, ))
     ksft_exit()
 
--
Quoted 2 lines

2.49.0

I was hoping we'd add the test coverage without the need to add test cases to the ksft. I was thinking maybe ncdevmem can do rand() each sendmsg loop and send a different set of chunks, so that we don't need a flag.

Quoted 3 lines

But it may be too hacky to have the test be non-deterministic, so up to you

Thanks! Let's spell it out explicitly for now. Doing it at random seems like an option when we start sending more data (after your series that converts the tests to -v).

#8 lore raw
In reply to Stanislav Fomichev
Quoted 22 lines · Stanislav Fomichev

sendmsg() with a single iov becomes ITER_UBUF, sendmsg() with multiple iovs becomes ITER_IOVEC. iter_iov_len does not return correct value for UBUF, so teach to treat UBUF differently.

Cc Al Viro <[email protected]>
Cc Pavel Begunkov <[email protected]>
Cc Mina Almasry <[email protected]>
Fixes bd61848900bf ("net: devmem: Implement TX path")
---
 include/linux/uio.h | 8 +++++++-
 net/core/datagram.c | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)
include/linux/uio.h +0 -0
index 49ece9e1888f..393d0622cc28 100644
@@ -99,7 +99,13 @@ static inline const struct iovec *iter_iov(const struct iov_iter *iter)
 }
 

include/linux/uio.h static inline const struct iovec *iter_iov(const struct iov_iter *iter) · line 109

Quoted 10 lines
include/linux/uio.h +7 -1
 #define iter_iov_addr(iter)    (iter_iov(iter)->iov_base + (iter)->iov_offset)
-#define iter_iov_len(iter)     (iter_iov(iter)->iov_len - (iter)->iov_offset)
+
+static inline size_t iter_iov_len(const struct iov_iter *i)
+{
+       if (i->iter_type == ITER_UBUF)
+               return i->count;
+       return iter_iov(i)->iov_len - i->iov_offset;
+}
 

This change looks good to me from devmem perspective, but aren't you potentially breaking all these existing callers to iter_iov_len?

ackc -i iter_iov_len
fs/read_write.c
846: iter_iov_len(iter), ppos);
849: iter_iov_len(iter), ppos);
858: if (nr != iter_iov_len(iter))

mm/madvise.c
1808: size_t len_in = iter_iov_len(iter);
1838: iov_iter_advance(iter, iter_iov_len(iter));

io_uring/rw.c
710: len = iter_iov_len(iter);

Or are you confident this change is compatible with these callers for some reason?

Maybe better to handle this locally in zerocopy_fill_skb_from_devmem, and then follow up with a more ambitious change that streamlines how all the iters behave.

Signature · 2 lines
Thanks,
Mina
#9 lore raw
Quoted 47 lines · Mina Almasry
Quoted 22 lines · Stanislav Fomichev

sendmsg() with a single iov becomes ITER_UBUF, sendmsg() with multiple iovs becomes ITER_IOVEC. iter_iov_len does not return correct value for UBUF, so teach to treat UBUF differently.

Cc Al Viro <[email protected]>
Cc Pavel Begunkov <[email protected]>
Cc Mina Almasry <[email protected]>
Fixes bd61848900bf ("net: devmem: Implement TX path")
---
 include/linux/uio.h | 8 +++++++-
 net/core/datagram.c | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)
include/linux/uio.h +0 -0
index 49ece9e1888f..393d0622cc28 100644
@@ -99,7 +99,13 @@ static inline const struct iovec *iter_iov(const struct iov_iter *iter)
 }
 

include/linux/uio.h static inline const struct iovec *iter_iov(const struct iov_iter *iter) · line 109

Quoted 10 lines
include/linux/uio.h +7 -1
 #define iter_iov_addr(iter)    (iter_iov(iter)->iov_base + (iter)->iov_offset)
-#define iter_iov_len(iter)     (iter_iov(iter)->iov_len - (iter)->iov_offset)
+
+static inline size_t iter_iov_len(const struct iov_iter *i)
+{
+       if (i->iter_type == ITER_UBUF)
+               return i->count;
+       return iter_iov(i)->iov_len - i->iov_offset;
+}
 

This change looks good to me from devmem perspective, but aren't you potentially breaking all these existing callers to iter_iov_len?

ackc -i iter_iov_len
fs/read_write.c
846: iter_iov_len(iter), ppos);
849: iter_iov_len(iter), ppos);
858: if (nr != iter_iov_len(iter))

mm/madvise.c
1808: size_t len_in = iter_iov_len(iter);
1838: iov_iter_advance(iter, iter_iov_len(iter));

Quoted 5 lines

io_uring/rw.c
710: len = iter_iov_len(iter);

Or are you confident this change is compatible with these callers for some reason?

Pavel did go over all callers, see:
https://lore.kernel.org/netdev/[email protected]/

Quoted 3 lines

Maybe better to handle this locally in zerocopy_fill_skb_from_devmem, and then follow up with a more ambitious change that streamlines how all the iters behave.

Yes, I can definitely do that, but it seems a bit strange that the callers need to distinguish between IOVEC and UBUF (which is a 1-entry IOVEC), so having working iter_iov_len seems a bit cleaner.

Acked-by
#10 lore raw
Quoted 49 lines · Stanislav Fomichev
Quoted 47 lines · Mina Almasry
Quoted 22 lines · Stanislav Fomichev

sendmsg() with a single iov becomes ITER_UBUF, sendmsg() with multiple iovs becomes ITER_IOVEC. iter_iov_len does not return correct value for UBUF, so teach to treat UBUF differently.

Cc Al Viro <[email protected]>
Cc Pavel Begunkov <[email protected]>
Cc Mina Almasry <[email protected]>
Fixes bd61848900bf ("net: devmem: Implement TX path")
---
 include/linux/uio.h | 8 +++++++-
 net/core/datagram.c | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)
include/linux/uio.h +0 -0
index 49ece9e1888f..393d0622cc28 100644
@@ -99,7 +99,13 @@ static inline const struct iovec *iter_iov(const struct iov_iter *iter)
 }
 

include/linux/uio.h static inline const struct iovec *iter_iov(const struct iov_iter *iter) · line 109

Quoted 10 lines
include/linux/uio.h +7 -1
 #define iter_iov_addr(iter)    (iter_iov(iter)->iov_base + (iter)->iov_offset)
-#define iter_iov_len(iter)     (iter_iov(iter)->iov_len - (iter)->iov_offset)
+
+static inline size_t iter_iov_len(const struct iov_iter *i)
+{
+       if (i->iter_type == ITER_UBUF)
+               return i->count;
+       return iter_iov(i)->iov_len - i->iov_offset;
+}
 

This change looks good to me from devmem perspective, but aren't you potentially breaking all these existing callers to iter_iov_len?

ackc -i iter_iov_len
fs/read_write.c
846: iter_iov_len(iter), ppos);
849: iter_iov_len(iter), ppos);
858: if (nr != iter_iov_len(iter))

mm/madvise.c
1808: size_t len_in = iter_iov_len(iter);
1838: iov_iter_advance(iter, iter_iov_len(iter));

Quoted 9 lines
Quoted 5 lines

io_uring/rw.c
710: len = iter_iov_len(iter);

Or are you confident this change is compatible with these callers for some reason?

Pavel did go over all callers, see:
https://lore.kernel.org/netdev/[email protected]/

Thanks, I'm not confident enough in my understanding of the other call sites of iter_iov_len to provide a reviewed-by, but this looks fine to me for devmem TCP, so I think acked-by is appropriate.

Thanks!

Signature · 2 lines
Thanks,
Mina
Reviewed-by
#11 lore raw
In reply to Stanislav Fomichev
Quoted 48 lines · Stanislav Fomichev
Quoted 47 lines · Mina Almasry
Quoted 22 lines · Stanislav Fomichev

sendmsg() with a single iov becomes ITER_UBUF, sendmsg() with multiple iovs becomes ITER_IOVEC. iter_iov_len does not return correct value for UBUF, so teach to treat UBUF differently.

Cc Al Viro <[email protected]>
Cc Pavel Begunkov <[email protected]>
Cc Mina Almasry <[email protected]>
Fixes bd61848900bf ("net: devmem: Implement TX path")
---
  include/linux/uio.h | 8 +++++++-
  net/core/datagram.c | 3 ++-
  2 files changed, 9 insertions(+), 2 deletions(-)
include/linux/uio.h +0 -0
index 49ece9e1888f..393d0622cc28 100644
@@ -99,7 +99,13 @@ static inline const struct iovec *iter_iov(const struct iov_iter *iter)
  }
 

include/linux/uio.h static inline const struct iovec *iter_iov(const struct iov_iter *iter) · line 109

Quoted 10 lines
include/linux/uio.h +7 -1
  #define iter_iov_addr(iter)    (iter_iov(iter)->iov_base + (iter)->iov_offset)
-#define iter_iov_len(iter)     (iter_iov(iter)->iov_len - (iter)->iov_offset)
+
+static inline size_t iter_iov_len(const struct iov_iter *i)
+{
+       if (i->iter_type == ITER_UBUF)
+               return i->count;
+       return iter_iov(i)->iov_len - i->iov_offset;
+}
 

This change looks good to me from devmem perspective, but aren't you potentially breaking all these existing callers to iter_iov_len?

ackc -i iter_iov_len
fs/read_write.c
846: iter_iov_len(iter), ppos);
849: iter_iov_len(iter), ppos);
858: if (nr != iter_iov_len(iter))

mm/madvise.c
1808: size_t len_in = iter_iov_len(iter);
1838: iov_iter_advance(iter, iter_iov_len(iter));

Quoted 8 lines
Quoted 5 lines

io_uring/rw.c
710: len = iter_iov_len(iter);

Or are you confident this change is compatible with these callers for some reason?

Pavel did go over all callers, see:
https://lore.kernel.org/netdev/[email protected]/

Yes, the patch should work

Quoted 8 lines
Quoted 4 lines

Maybe better to handle this locally in zerocopy_fill_skb_from_devmem, and then follow up with a more ambitious change that streamlines how all the iters behave.

Yes, I can definitely do that, but it seems a bit strange that the callers need to distinguish between IOVEC and UBUF (which is a 1-entry IOVEC), so having working iter_iov_len seems a bit cleaner.

It might be a good idea to rename it at some point to highlight that it also works with ubufs (but not as a part of this fix).

Signature · 1 line
Pavel Begunkov
maintainer
#12 lore raw
In reply to Stanislav Fomichev
Quoted 3 lines · On Tue, 20 May 2025 13:30:42 -0700 Stanislav Fomichev wrote:

sendmsg() with a single iov becomes ITER_UBUF, sendmsg() with multiple iovs becomes ITER_IOVEC. iter_iov_len does not return correct value for UBUF, so teach to treat UBUF differently.

Looks like this has been merged (silently), thanks!