[dm][ivshmem] Add Inter-VM shared memory for virtualization#11645
[dm][ivshmem] Add Inter-VM shared memory for virtualization#11645GuEe-GUI 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-07-23 09:57 CST)
📝 Review Instructions
|
There was a problem hiding this comment.
Pull request overview
This PR introduces an Inter-VM shared memory (ivshmem) device driver under the RT-Thread Device Model (DM) / PCI stack to support virtualization scenarios (including a QEMU-specific implementation).
Changes:
- Add
ivshmemdriver Kconfig and build integration undercomponents/drivers/. - Introduce a common PCI probe/remove implementation (
ivshmem.c/.h) for ivshmem devices. - Add a QEMU ivshmem PCI driver with RT-Thread device ops and an MSH helper command (
ivshmem-qemu.c).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| components/drivers/Kconfig | Adds Kconfig sourcing for ivshmem (and also adds an ethernet Kconfig include). |
| components/drivers/ivshmem/SConscript | Adds SCons build rules for ivshmem and optional QEMU backend. |
| components/drivers/ivshmem/Kconfig | Adds configuration options for enabling ivshmem and QEMU support. |
| components/drivers/ivshmem/ivshmem.h | Defines ivshmem registers/BARs and core ivshmem device structure/API. |
| components/drivers/ivshmem/ivshmem.c | Implements common PCI probe/remove and IRQ setup helpers. |
| components/drivers/ivshmem/ivshmem-qemu.c | Implements QEMU ivshmem PCI driver, device ops, and MSH command helpers. |
Comments suppressed due to low confidence (4)
components/drivers/ivshmem/ivshmem.c:182
- [bug/缺陷]: Reading 64-bit shared-memory address/size by casting
&ivdev->shmem/&ivdev->shmem_sizetort_uint32_t*and using+ 1is non-portable and can break on different architectures/ABIs.
English: This relies on object layout/endianness and may violate strict-aliasing/alignment rules. Prefer reading into temporary u32 low/high parts and composing a 64-bit value explicitly.
中文:通过把 &ivdev->shmem / &ivdev->shmem_size 强转为 rt_uint32_t* 再 +1 读取高 32bit 的方式不具备可移植性,且可能触发严格别名/对齐问题。建议用临时的 low/high 变量读取后显式拼成 64bit 值。
rt_pci_read_config_u32(pdev, PCI_CFG_SHARE_MEM_ADDR_LO, (rt_uint32_t *)&ivdev->shmem);
rt_pci_read_config_u32(pdev, PCI_CFG_SHARE_MEM_ADDR_HI, (rt_uint32_t *)&ivdev->shmem + 1);
rt_pci_read_config_u32(pdev, PCI_CFG_SHARE_MEM_SIZE_LO, (rt_uint32_t *)&ivdev->shmem_size);
rt_pci_read_config_u32(pdev, PCI_CFG_SHARE_MEM_SIZE_HI, (rt_uint32_t *)&ivdev->shmem_size + 1);
components/drivers/ivshmem/ivshmem-qemu.c:234
- [bug/缺陷]:
qemu_ivshmem_remove()does not handleivshmem_pci_remove()returningRT_NULL, which can lead to a NULL dereference.
English: If pdev is invalid or sysdata is not set, ivshmem_pci_remove() returns RT_NULL, but the code immediately calls raw_to_qemu_ivshmem(ivdev). Add a NULL check and return an error.
中文:当 pdev 非法或 sysdata 未设置时,ivshmem_pci_remove() 会返回 RT_NULL,当前代码随后直接 raw_to_qemu_ivshmem(ivdev) 可能空指针解引用。请增加空指针检查并返回错误。
static rt_err_t qemu_ivshmem_remove(struct rt_pci_device *pdev)
{
struct ivshmem_device *ivdev = ivshmem_pci_remove(pdev);
struct qemu_ivshmem *qivdev = raw_to_qemu_ivshmem(ivdev);
rt_device_unregister(&qivdev->parent.parent);
rt_free(qivdev);
return RT_EOK;
components/drivers/ivshmem/ivshmem-qemu.c:366
- [bug/缺陷]: Format string mismatch:
posislongbut printed with%d.
English: This is undefined behavior on some targets. Use %ld (or cast to int if you really want %d).
中文:pos 类型为 long,但用 %d 打印在部分平台上会产生未定义行为。请改用 %ld(或显式转换为 int)。
rt_kprintf("[%2d] = %02x (%c)\n", pos, value, value);
components/drivers/ivshmem/ivshmem.c:216
- [bug/缺陷]:
ivshmem_pci_remove()enables interrupts during teardown and also detaches the legacy INTx IRQ even when MSI-X was used.
English: In the MSI-X loop it calls rt_hw_interrupt_umask(irq) (enable) right before detaching, which can allow IRQs to fire while resources are being freed. Also rt_hw_interrupt_umask(ivdev->irq) / rt_pic_detach_irq(ivdev->irq, ...) runs unconditionally even though INTx handler was never installed in the MSI-X path. Finally, the INTx teardown path calls rt_pci_irq_unmask() (enable) during remove; it should mask.
中文:ivshmem_pci_remove() 在卸载过程中错误地“使能”中断,并且在 MSI-X 模式下仍无条件卸载 legacy INTx IRQ。MSI-X 循环里在 detach 前调用 rt_hw_interrupt_umask() 可能导致释放资源时仍触发中断;同时 INTx 的 umask/detach 在 MSI-X 路径下并未安装过 handler;另外 INTx teardown 里还调用了 rt_pci_irq_unmask()(使能),卸载时应改为 mask。
if (ivdev->msix_entries)
{
for (int i = 0; i < ivdev->nvectors; ++i)
{
int irq = ivdev->msix_entries[i].irq;
Signed-off-by: GuEe-GUI <2991707448@qq.com>
|
@Rbb666 审核建议已修改完成 |
[
Add Inter-VM shared memory for virtualization
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up