Thread View: muc.lists.freebsd.bugs
4 messages
4 total messages
Started by bugzilla-noreply
Fri, 27 Nov 2026 22:38
[Bug 301205] mbuf(9): m_mbuftouio() loops until m is NULL without testing progress < total, so partial reads walk the rest of th...
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 22:38
Date: Fri, 27 Nov 2026 22:38
102 lines
6614 bytes
6614 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301205
Bug ID: 301205
Summary: mbuf(9): m_mbuftouio() loops until m is NULL without
testing progress < total, so partial reads walk the
rest of the chain calling zero-length uiomove()
Product: Base System
Version: 16.0-CURRENT
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: laamalif@proton.me
In sys/kern/uipc_mbuf.c (main 2534dcb233ad), m_mbuftouio() copies up to
total bytes into uio across an mbuf chain, but its loop condition only
tests m != NULL:
if (len > 0)
total = min(uio->uio_resid, len);
else
total = uio->uio_resid;
/* Fill the uio with data from the mbufs. */
for (; m != NULL; m = m->m_next) {
length = min(m->m_len, total - progress);
if ((m->m_flags & M_EXTPG) != 0)
error = m_unmapped_uiomove(m, 0, uio, length);
else
error = uiomove(mtod(m, void *), length, uio);
if (error)
return (error);
progress += length;
}
Once progress reaches total, length becomes 0, yet the loop walks every
remaining mbuf to the tail of the chain and calls uiomove() (or
m_unmapped_uiomove()) with length 0 on each one. soreceive_stream_locked()
(used by TCP when net.inet.tcp.soreceive_stream=1) and tunread() call
m_mbuftouio(); draining a 1 MiB receive buffer of 1024-byte segments in
64-byte reads turns 16384 reads into ~8.4 million mbuf steps and
zero-length uiomove() calls per MiB.
On FreeBSD 16.0-CURRENT amd64 GENERIC-NODEBUG (main 2534dcb233ad, Xeon
6975P-C) with net.inet.tcp.soreceive_stream=1, draining 1 MiB queued in
1024-byte TCP segments via 64-byte read(2) calls (ms per MiB, 10 runs):
cc -O2 -Wall -Wextra -Werror -o mbuftouio_partial_read mbuftouio_partial_read.c
for i in $(jot 10); do cpuset -l 2 ./mbuftouio_partial_read partial; done
x base_mbuftouio_partial.txt
+ patched_mbuftouio_partial.txt
+--------------------------------------------------------------------------+
|+ |
|+ |
|+ |
|+ |
|+ x |
|+ x |
|+ xx|
|+ xx|
|+ xx|
|+ xx|
|A A||
+--------------------------------------------------------------------------+
N Min Max Median Avg Stddev
x 10 42.359 42.949 42.6025 42.6237 0.19711083
+ 10 3.362 3.389 3.3795 3.3775 0.0086313383
Difference at 95.0% confidence
-39.2462 +/- 0.131085
-92.076% +/- 0.0278163%
(Student's t, pooled s = 0.139512)
DTrace fbt::uiomove:entry count across one run (warmup + timed MiB)
drops from 16795650 to 34818. On unmapped M_EXTPG mbufs queued via
sendfile(2) over an IFCAP_MEXTPG epair(4) VNET link (64-byte reads,
N=10), mean drain time drops from 31.933 ms to 3.515 ms (-88.99% +/-
0.39%) and fbt::m_unmapped_uiomove:entry drops from 11971565 to 32150.
With 65536-byte reads, mean drain time drops from 0.252 ms to 0.210 ms
(-16.62% +/- 1.35%); EFAULT recovery, 73-byte cross-page reads, and
debug GENERIC (INVARIANTS and WITNESS) all pass.
Adding progress < total to the for loop in m_mbuftouio() stops traversal
as soon as the requested byte count has been copied.
Tested on 16.0-CURRENT amd64 with mapped and sendfile(2) M_EXTPG mbufs;
I have not tested InfiniBand SDP.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301205] mbuf(9): m_mbuftouio() loops until m is NULL without testing progress < total, so partial reads walk the rest of th...
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 22:38
Date: Fri, 27 Nov 2026 22:38
16 lines
2576 bytes
2576 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301205 --- Comment #1 from laamalif@proton.me --- Created attachment 277834 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277834&action=edit stop the mbuf walk in m_mbuftouio() once progress reaches total -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301205] mbuf(9): m_mbuftouio() loops until m is NULL without testing progress < total, so partial reads walk the rest of th...
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 22:38
Date: Fri, 27 Nov 2026 22:38
18 lines
2637 bytes
2637 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301205 --- Comment #2 from laamalif@proton.me --- Created attachment 277835 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277835&action=edit benchmark: drain a 1 MiB TCP receive buffer of 1024-byte segments via 64-byte reads (partial) or 65536-byte reads (full) -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301205] mbuf(9): m_mbuftouio() loops until m is NULL without testing progress < total, so partial reads walk the rest of th...
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 22:38
Date: Fri, 27 Nov 2026 22:38
18 lines
2640 bytes
2640 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301205 --- Comment #3 from laamalif@proton.me --- Created attachment 277836 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277836&action=edit benchmark: sendfile(2) M_EXTPG unmapped mbufs across epair(4) VNET drained via 73-byte and 64-byte reads; build with -ljail -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads