[drivers][virtio] Fix RX buffer leak on pbuf allocation failure - #11726
[drivers][virtio] Fix RX buffer leak on pbuf allocation failure#11726Zepp-Hanzj wants to merge 1 commit into
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-08-20 22:50 CST)
📝 Review Instructions
|
Description / 描述
Fix a receive buffer leak in
virtio_net_rx(): whenpbuf_alloc()fails, the buffer already read from the virtqueue used ring is not returned to the available ring, permanently losing that RX slot.修复
virtio_net_rx()中的接收缓冲泄漏:当pbuf_alloc()失败时,已从 virtqueue used ring 读出的 buffer 未归还到 available ring,导致该接收槽位永久丢失。Why / 为什么需要
In
virtio_net_rx(), afterrt_virtqueue_read_buf()consumes a buffer (vq->num_free++but the buffer is not yet re-queued), the code unlocks and callspbuf_alloc(). On failure the original code simplyreturn RT_NULLwithout callingrt_virtqueue_add_inbuf()to return the buffer. Repeated OOM eventually exhausts the RX queue.The success path re-acquires the lock and returns the buffer via
rt_virtqueue_add_inbuf() + rt_virtqueue_kick(); the failure path was missing this symmetric cleanup.在
virtio_net_rx()中,rt_virtqueue_read_buf()消费 buffer 后(vq->num_free++但 buffer 尚未重新入队),代码解锁并调用pbuf_alloc()。失败时原代码直接return RT_NULL,未调用rt_virtqueue_add_inbuf()归还 buffer。反复 OOM 会逐步耗尽接收队列。成功路径会重新加锁并通过rt_virtqueue_add_inbuf() + rt_virtqueue_kick()归还 buffer,失败路径缺失了这个对称清理。How / 修改了哪些文件
components/drivers/virtio/virtio-net.c: in thepbuf_alloc()failure branch, re-acquirerx_lock, mirror the success path'srt_virtqueue_poll/rt_list_remove/rt_virtqueue_add_inbuf/rt_virtqueue_kicksequence before returningRT_NULL.