drivers/virtio: use virtqueue_nused() to check pending buffers#18290
Merged
xiaoxiang781216 merged 1 commit intoapache:masterfrom Jan 31, 2026
Merged
drivers/virtio: use virtqueue_nused() to check pending buffers#18290xiaoxiang781216 merged 1 commit intoapache:masterfrom
xiaoxiang781216 merged 1 commit intoapache:masterfrom
Conversation
Replace direct virtqueue internal field access with virtqueue_nused() API to check for pending buffers in interrupt handlers. This improves code maintainability and handles cached memory scenarios correctly. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
xiaoxiang781216
approved these changes
Jan 30, 2026
acassis
approved these changes
Jan 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR optimizes the VirtIO MMIO and PCI interrupt handlers by replacing direct access to virtqueue internal fields with the proper
virtqueue_nused()API.Why this change is needed
The current implementation directly accesses virtqueue internal fields (
vq->vq_used_cons_idxandvq->vq_ring.used->idx) to determine if there are pending buffers to process. This approach has several issues:What this PR does
vq->vq_used_cons_idx != vq->vq_ring.used->idxwithvirtqueue_nused(vq) > 0vq->callback != NULLfirst (short-circuit optimization)virtio-mmio.candvirtio-pci.cImpact
Testing
Build Verification
# Build for qemu-armv8a with virtio support cmake -B cmake_out -DBOARD_CONFIG=qemu-armv8a:netnsh -GNinja cmake --build cmake_outRuntime Testing
Tested on QEMU ARM64 with virtio-net device:
VirtIO-MMIO Test
VirtIO-PCI Test