Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 2, 2026

Per VirtIO spec, QueueSel must be written before reading queue-specific registers like QueueNumMax. The code was reading queue_num_max before setting queue_sel, causing failures on ARM FVP.

Changes

virtio_queue_init:

  • Set queue_sel before reading queue_num_max (moved from line 131 to 105)
  • Replace invalid assertion queue_num_max > queue_index with queue_index < queues_num
  • Add assertion ring_size <= queue_num_max to validate against hardware limits

virtio_queue_destroy:

  • Set queue_sel before reading queue_num_max (moved from line 170 to 163)
  • Replace invalid assertion queue_num_max > queue_index with queue_index < queues_num
// Before: reads queue_num_max without selecting queue first
RT_ASSERT(dev->mmio_config->queue_num_max > 0);
RT_ASSERT(dev->mmio_config->queue_num_max > queue_index);  // wrong comparison
// ... later:
dev->mmio_config->queue_sel = queue_index;

// After: select queue, then read its queue_num_max
dev->mmio_config->queue_sel = queue_index;
RT_ASSERT(dev->mmio_config->queue_num_max > 0);
RT_ASSERT(ring_size <= dev->mmio_config->queue_num_max);
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] virtio驱动中virtio_queue_init函数中开头的queue_num_max检测有问题</issue_title>
<issue_description>### RT-Thread Version

5.3.0

Hardware Type/Architectures

arm FVP

Develop Toolchain

GCC

Describe the bug

根据virtio规范,QueueSel作用于QueueNumMax, QueueNum, QueueReady, QueueDescLow,QueueDescHigh, QueueAvailLow, QueueAvailHigh, QueueUsedLow and QueueUsedHigh。
因此virtio_queue_init函数开头处应当是先选择queue, dev->mmio_config->queue_sel = queue_index;然后去检测queue_num_max。并且queue_num_max和queue_index无关,无需检测。

实际上这个驱动在arm FVP上就会触发这个问题。

Other additional context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix queue_num_max detection issue in virtio_queue_init function [virtio] Fix queue_sel ordering in virtio_queue_init and virtio_queue_destroy Jan 2, 2026
Copilot AI requested a review from BernardXiong January 2, 2026 14:53
@github-actions
Copy link

github-actions bot commented Jan 2, 2026

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • components/drivers/virtio/virtio.c

📊 Current Review Status (Last Updated: 2026-01-02 23:02 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] virtio驱动中virtio_queue_init函数中开头的queue_num_max检测有问题

3 participants