zhhyu7 opened a new pull request, #22204:
URL: https://github.com/apache/nuttx/pull/22204

   *Note: Please adhere to [Contributing 
Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).*
   
   ## Summary
   
   Queues of IOB chains were built from a separate iob_qentry_s pool sized by 
CONFIG_IOB_NCHAINS. Two pools serving one purpose can be exhausted 
independently: a module using plain IOBs could starve one pool
   while the other still had room, and every enqueue had to allocate, which 
meant it could fail or block on a semaphore even when IOBs were plentiful.
                                                                                
                                                                                
                                               
   This series removes that pool. A queue now links iob_s structures directly, 
and the end of each chain within a queue is marked by an IOB_CHAIN_END bit 
stored in the low bits of io_flink. IOBs are at least
   4-byte aligned, so those bits are always zero and the marker costs no 
memory. CONFIG_IOB_NCHAINS and all the #if CONFIG_IOB_NCHAINS > 0 conditionals 
disappear, so queue support is unconditional.          
                                                                                
                                                                                
                                               
   The trade-off is that finding a chain end is now an O(m) walk over the chain 
rather than a pointer in a queue entry. Chains are typically 1-3 IOBs, and the 
walk replaces an allocation plus lock and       
   semaphore traffic.                                                           
                                                                                
                                               
                                                                                
                                                                                
                                               
   Storing a flag inside a pointer creates one new obligation: every site that 
reads io_flink must mask the flag bits, and every site that extends a chain 
must carry IOB_CHAIN_END over to the new tail. The 
   first commit does not cover all of them, so the seven follow-up commits that 
fix the remaining sites are included here rather than left for later:
                                                                                
                                                                                
                                               
   - read io_flink through IOB_LINK_GET() instead of directly                   
                                                                                
                                               
   - preserve the flag when a chain grows in iob_copyin(), iob_update_pktlen() 
and iob_clone_partial()                                                         
                                                
   - advance from qh_tail to the real chain end before linking, since a chain 
may have been extended after it was enqueued
   - a null check for iob2 in iob_clone_partial()                               
                                                                                
                                               
   - memmove() in iob_copyin_internal(), because a source inside the 
destination IOB can overlap the copied range
                                                                                
                                                                                
                                               
   Without them the result builds and passes ordinary TCP and ICMP traffic, 
then dereferences a flagged pointer as if it were a plain one. IP fragmentation 
hits this immediately, because 
   ip_fragout_allocfragbuf() enqueues an IOB and then keeps writing into it:    
                                                                                
                                               
                                                                                
                         
   #0  iob_copyin_internal ()                                                   
                                                                                
                                               
   #1  ip_fragout_slice ()                                                      
                                                                                
                                               
   #2  ipv4_fragout ()                                                          
                         
   #3  ipv4_in ()                                                               
                                                                                
                                               
   #7  netdev_upper_input ()                                                    
                                                                                
                                               
                                                                                
                                                                                
                                               
   
   The last commit fixes two pre-existing checkpatch errors in files this 
series touches.
   
   ## Impact
   
   CONFIG_IOB_NCHAINS is removed. Any out-of-tree configuration that sets it 
will see the option silently dropped by olddefconfig; no action is needed, 
since queues are now always available. The 102 in-tree 
   defconfigs that set it are updated.                                          
                         
                                                                                
                                                                                
                                               
   NET_IPFRAG loses its depends on IOB_NCHAINS > 0, so IP fragmentation can now 
be enabled on any configuration with NET_IPv4 or NET_IPv6. NET_ARP_SEND gains 
the same freedom.                                
                                                                                
                                                                                
                                               
   Code shrinks by roughly 440 lines net in C sources, and the per-queue-entry 
allocations are gone. There is no change to the public IOB API beyond the new 
IOB_CHAIN_END, IOB_LINK_GET(), IOB_FLAG_GET(),    
   IOB_FLAG_SET() and IOB_FLAG_TEST() definitions in include/nuttx/mm/iob.h.    
                                                                                
                                               
                                                                                
                                                                                
                                               
   Code outside mm/iob that walks io_flink by hand must use IOB_LINK_GET(). All 
in-tree users are converted here. 
   
   ## Testing
   
   sim:dynconns (in tools/ci/testlist/sim-02.dat) with CONFIG_SIM_NET_BRIDGE=y, 
CONFIG_DEBUG_ASSERTIONS=y, CONFIG_NET_IPFRAG=y, tcpecho on port 80 and 
apps/examples/udp with EXAMPLES_UDP_SERVER1=y on port  
   5471. Host bridge nuttx0 10.0.1.1/24, target 10.0.1.2/24.                    
                                                                                
                                               
                                                                                
                                                                                
                                               
   TCP, 4 concurrent connections echoing 256 KiB each, byte counts compared in 
both directions:                                                                
                                                
                                                                                
                                                                                
                                               
   === TCP echo: 4 conn x 256 KiB ===                                           
                                                                                
                                               
   conn0: sent=262144 recv=262144 err=None                                      
                                                                                
                                               
   conn1: sent=262144 recv=262144 err=None                                      
                                                                                
                                               
   conn2: sent=262144 recv=262144 err=None                                      
                                                                                
                                               
   conn3: sent=262144 recv=262144 err=None                                      
                                                                                
                                               
                                                                                
                                                                                
                                               
                                                                                
                         
   UDP, 256 datagrams. The target's udpserver checks the sequence byte and the 
payload pattern of every datagram and exits on the first mismatch, so a silent 
corruption would be reported rather than counted 
   as received:                                                                 
                                                                                
                                               
                                                                                
                         
   === UDP: 256 x 96B datagrams, target validates payload ===                   
                                                                                
                                               
   udp client: sent 256 datagrams of 96 bytes (24576 bytes payload)             
                                                                                
                                               
   server: 255. Received 96 bytes from 10.0.1.1:5472                            
                                                                                
                                               
   --- server error lines (should be none) ---
   (none)
   
   
   ICMP, and the fragmentation path that the flagged-pointer bug broke:
   
   4 packets transmitted, 4 received, 0% packet loss
   500 packets transmitted, 500 received, 0% packet loss    (flood)
   20 packets transmitted, 20 received, 0% packet loss      (-s 4000)
   10 packets transmitted, 10 received, 0% packet loss      (-s 8000)
   200 packets transmitted, 200 received, 0% packet loss    (flood, -s 4000)
   
   No assertions, no segmentation fault, node alive after every run.
   
   With only the first commit applied, the same fragmentation test fails and 
produces the backtrace shown above:
   
   5 packets transmitted, 0 received, +2 errors, 100% packet loss
   Segmentation fault
   
   
   Builds: sim:dynconns and sim:ipforward, both clean. sim:ipforward is 
included because it enables CONFIG_NET_IPFRAG and CONFIG_NET_IPFORWARD.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to