Skip to content

Refine#87

Merged
junyu0312 merged 4 commits intomainfrom
refine
Mar 1, 2026
Merged

Refine#87
junyu0312 merged 4 commits intomainfrom
refine

Conversation

@junyu0312
Copy link
Owner

@junyu0312 junyu0312 commented Mar 1, 2026

Summary by CodeRabbit

  • Refactor

    • Streamlined VM startup: memory initialization sequencing simplified for more reliable startup and clearer initialization flow.
  • Bug Fixes / Error handling

    • More specific, typed error reporting for device and PCI failures, plus a distinct error when IRQ configuration is missing to improve diagnostics and recovery.

@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between 2c1dc52 and e410aec.

📒 Files selected for processing (7)
  • crates/vm-core/src/virt.rs
  • crates/vm-core/src/virt/hvp.rs
  • crates/vm-core/src/virt/kvm.rs
  • crates/vm-core/src/virt/kvm/arch.rs
  • crates/vm-core/src/virt/kvm/arch/aarch64.rs
  • crates/vm-core/src/virt/kvm/arch/x86_64.rs
  • crates/vm-machine/src/vm_builder.rs
 _____________________________________________
< Nose to the grindstone, eyes on the screen. >
 ---------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

✏️ Tip: You can disable in-progress messages and the fortune message in your review settings.

📝 Walkthrough

Walkthrough

The Virt::init_memory signature was changed to remove the ram_base parameter; implementations now obtain ram_base internally. VmBuilder reorders memory initialization (calls virt.init_memory earlier). Device initialization and error handling were refactored to use a concrete Error enum (vm-machine and vm-pci).

Changes

Cohort / File(s) Summary
Virt trait & impls
crates/vm-core/src/virt.rs, crates/vm-core/src/virt/hvp.rs, crates/vm-core/src/virt/kvm.rs
Removed ram_base: u64 from Virt::init_memory signature and updated implementations. hvp now derives ram_base from self.get_layout().get_ram_base() instead of receiving it.
VmBuilder memory init reorder
crates/vm-machine/src/vm_builder.rs
MemoryAddressSpace created and virt.init_memory(&mut memory_regions, self.memory_size) invoked before fetching the layout; eliminated prior reliance on layout-provided ram_base during initial memory mapping.
Device init & error refactor
crates/vm-machine/src/device.rs, crates/vm-machine/src/error.rs
Switched device init return types from anyhow::Result to crate Result<..., Error>; added Error::NoIrqChipSpecified, Error::Device(...), Error::PciDevice(...); updated device manager and error propagation accordingly.
PCI error variant
crates/vm-pci/src/error.rs
Added FailedRegisterPciDevice enum variant and mapped PCI registration failures to this variant.

Sequence Diagram(s)

sequenceDiagram
    participant Builder as VmBuilder
    participant Virt as Virt impl (Hvp/Kvm)
    participant Mem as MemoryAddressSpace
    participant Devices as DeviceManager

    Builder->>Mem: create MemoryAddressSpace
    Builder->>Virt: init_memory(&mut Mem, memory_size)
    Virt->>Virt: determine ram_base from layout
    Virt->>Mem: map RAM regions at ram_base
    Virt-->>Builder: return (post_init state)
    Builder->>Devices: init_devices(&mem_arc, ...) 
    Devices->>Mem: register device MMIO/regions
    Devices-->>Builder: devices initialized
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰
I hopped through structs and signatures light,
Pulled a param while keeping mappings tight.
Errors now named, devices line in queue,
Memory set early, ram_base found anew.
🥕 — CodeRabbit

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Refine' is too vague and generic; it does not convey meaningful information about the specific changes in the pull request. Consider using a more descriptive title that summarizes the main changes, such as 'Remove ram_base parameter from init_memory and update error handling' or 'Refactor memory initialization and consolidate error types'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refine

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/vm-machine/src/device.rs`:
- Around line 69-71: The call to pci_rc.register_device(virtio_pci_blk)
currently maps all errors to vm_pci::error::Error::FailedRegisterPciDevice,
losing the original error details; change the error handling to preserve the
underlying error by passing/ wrapping the original error into the returned error
(e.g., map_err(|e| vm_pci::error::Error::FailedRegisterPciDevice(e)) or use a
context-wrapping variant) so callers can inspect the cause; if
vm_pci::error::Error::FailedRegisterPciDevice does not accept an inner error,
modify that enum/variant to carry the source error and update
pci_rc.register_device(...) usage accordingly.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b05a4ab and d3743d8.

📒 Files selected for processing (3)
  • crates/vm-machine/src/device.rs
  • crates/vm-machine/src/error.rs
  • crates/vm-pci/src/error.rs

Comment on lines 69 to +71
pci_rc
.register_device(virtio_pci_blk)
.map_err(|_| anyhow!("failed to register pci device"))?;
.map_err(|_| vm_pci::error::Error::FailedRegisterPciDevice)?;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Preserve the underlying PCI registration error instead of collapsing it.

At Line 71, mapping every failure to FailedRegisterPciDevice drops actionable detail (e.g., capability-space errors), making diagnosis and handling weaker.

🔧 Proposed fix
                 pci_rc
                     .register_device(virtio_pci_blk)
-                    .map_err(|_| vm_pci::error::Error::FailedRegisterPciDevice)?;
+                    ?;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/vm-machine/src/device.rs` around lines 69 - 71, The call to
pci_rc.register_device(virtio_pci_blk) currently maps all errors to
vm_pci::error::Error::FailedRegisterPciDevice, losing the original error
details; change the error handling to preserve the underlying error by passing/
wrapping the original error into the returned error (e.g., map_err(|e|
vm_pci::error::Error::FailedRegisterPciDevice(e)) or use a context-wrapping
variant) so callers can inspect the cause; if
vm_pci::error::Error::FailedRegisterPciDevice does not accept an inner error,
modify that enum/variant to carry the source error and update
pci_rc.register_device(...) usage accordingly.

@junyu0312 junyu0312 merged commit 53bdb1f into main Mar 1, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant