zhhyu7 opened a new pull request, #21931:
URL: https://github.com/apache/nuttx/pull/21931
## Summary
A set of VLAN / upper-half driver improvements, with the main change
being that VLAN receive no longer holds the real device lock, improving
real-time behavior. The patches build on each other, so they are kept
as a series.
VLAN feature / behavior:
- vlan: inherit the operating mode (rxtype) from the real device
- vlan: support setting the VLAN rxtype from ioctl, and copy the MTU
from the real device on creation
- vlan: add txpoll support for netpoll passthrough (delegate txpoll to
the real device so netpoll features work when bound to a VLAN)
- vlan: undo VLAN encapsulation on transmit failure, so a re-queued
packet is not double-tagged on retry
Upper-half / locking:
- netdev: fix use-after-free in netdev_lower_register on the register
failure path
- netdev: replace net_lock with netdev_lock for netdev_upper_vlan_foreach
- netdev_upperhalf: trigger txpoll only when the TX quota has ever
dropped to 0 (adds a per-device txdone flag)
- drivers/net/vlan: strip VLAN devices from their reliance on the real
device lock — a received VLAN-tagged frame is dispatched into the VLAN
device's own RX queue (iob queue + spinlock) and processed by the VLAN
device's own RX poll, instead of being handled recursively under the
real device's netdev_lock
A companion apps-side change is required (see "Depends"):
- netutils/netlib: initialize rx_type/rx_priority in netlib_add_vlan,
because this series adds an rx_type field to the VLAN add ioctl.
## Impact
- VLAN RX path no longer takes the real device's netdev_lock. Tagged
frames go through a new per-VLAN RX queue (spinlock-protected) and the
VLAN device's own RX poll, so VLAN receive no longer serializes on the
real device lock. This is the intended real-time improvement; the old
recursive-under-lock eth_input path for VLAN frames is removed.
- New field `txdone` added to `struct netdev_lowerhalf_s`; txpoll is now
gated on it (only fired after the TX quota has dropped to 0). Out-of-tree
lower-half drivers that read that struct by offset are affected.
- The VLAN add ioctl (`struct vlan_ioctl_args`) gains `rx_type` /
`rx_priority` fields, and `vlan_register()` gains two parameters and
rejects an out-of-range `rx_type` with -EINVAL. Any in-kernel caller of
`vlan_register()` and any user-space constructor of the ADD_VLAN ioctl
must initialize `rx_type` (use NETDEV_RX_DEFAULT to inherit the real
device's rxtype). The in-tree constructor `netlib_add_vlan()` is updated
accordingly in the companion apps patch; without it, an uninitialized
rx_type is passed to the kernel and VLAN creation fails intermittently
with -EINVAL.
- VLAN devices now copy the MTU from the real device at creation.
- No change to non-VLAN RX, and no change for connections/devices that
do not use VLAN.
## Testing
Built and run on the simulator (flat build). The sim network tap
requires running the simulator as root (SIM_NETDEV_TAP opens
/dev/net/tun); without root the sim has no network.
Build / style:
- `./tools/configure.sh sim:dynconns` + CONFIG_NET_VLAN — make and link
succeed.
- `./tools/checkpatch.sh -c -m -g <range>` — passes; nxstyle clean on all
touched files.
Runtime (sim:dynconns + CONFIG_NET_VLAN, sim tap bridged to the host):
1. VLAN create / MTU inherit / delete (throwaway self-test):
vlanrx: real eth0 mtu=1280
vlanrx: vlan eth0.100 created mtu=1280 (MTU inherited from eth0)
vlanrx: eth0.100 deleted and reclaimed
2. VLAN RX dispatch off the real device lock (the main change). Host
creates an 802.1Q sub-interface on the sim's tap and sends tagged
traffic to the VLAN device IP:
host $ ping 10.0.100.2 (tagged, via host vlan sub-if)
3 packets transmitted, 3 received, 0% packet loss
With temporary instrumentation in netdev_upper_vlan_dispatch (removed
before commit), the sim showed the tagged frames taking the new path:
rx eth type=8100 (802.1Q tagged frame received)
tagged vid=100 vlan=0x... (matched the VLAN device)
dispatched to vlan, rxready (queued to VLAN rxq, RX poll kicked)
This confirms tagged RX reaches the VLAN device through vlan_dispatch
without taking the real device lock, and bidirectional tagged ARP/ICMP
works end to end.
--
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]