Skip to content

Conversation

@shenw0000
Copy link
Contributor

Add save and restore for the PCIe Root Complex and PCIe Switch

@shenw0000 shenw0000 requested a review from a team as a code owner January 14, 2026 21:13
Copilot AI review requested due to automatic review settings January 14, 2026 21:13
@shenw0000 shenw0000 requested a review from a team as a code owner January 14, 2026 21:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds save and restore functionality for PCIe devices including the PCIe Root Complex and PCIe Switch. Previously, these devices returned SavedStateNotSupported, which prevented VMs with PCIe configurations from being saved and restored. This enhancement enables save/restore for VMs using PCIe emulation.

Changes:

  • Implemented SaveRestore trait for GenericPcieSwitch and GenericPcieRootComplex
  • Enhanced PciExpressCapability to save/restore all control and status registers
  • Updated petri test infrastructure to enable save/restore testing for PCIe configurations

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
vm/devices/pci/pcie/src/switch.rs Added save/restore implementation for GenericPcieSwitch with upstream and downstream port configuration space state, plus comprehensive tests
vm/devices/pci/pcie/src/root.rs Added save/restore implementation for GenericPcieRootComplex including bus number validation and root port configuration space state, plus tests
vm/devices/pci/pci_core/src/capabilities/pci_express.rs Expanded PciExpressCapability saved state to include all control/status registers (device, link, slot, root) and their _2 variants
vm/devices/pci/pcie/Cargo.toml Added mesh_protobuf dependency required for protobuf serialization
petri/src/vm/openvmm/start.rs Removed PCIe check from save/restore support detection to enable testing
Cargo.lock Updated with mesh_protobuf dependency for pcie crate

Copy link
Contributor

@mattkur mattkur left a comment

Choose a reason for hiding this comment

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

A few comments. Overall, thank you for adding tests here!

pub device_status: u16,
#[mesh(3)]
pub flr_handler: u16,
pub link_control: u16,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please confirm why it is safe to change this struct at this point. (Asking out of a due diligence)

Copy link
Contributor Author

@shenw0000 shenw0000 Jan 15, 2026

Choose a reason for hiding this comment

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

this was not used before (i.e. save returned error before, so I don't think there will be a migration issue) - and I don't think it is right to save the flr_handler to begin with. flr_handler is a pointer to the handler routine which does not make sense after restore

Err(SaveError::NotSupported)
let state = self.state.lock();
Ok(state::SavedState {
device_control: state.device_control.into_bits(),
Copy link
Contributor

Choose a reason for hiding this comment

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

A few comments:

  1. I thought the save operation was to be idempotent, whereas into_bits will take ownership of each of these fields. Paging @smalis-msft to correct me on the idempotency of save.
  2. You can destructure state to make sure that you get a compile error here if you add more state to device_control but forget to adjust the save state.
  3. Why did you choose to use u16 for the save state, rather than the type itself? I had thought mesh supported generic Into/From bytes, but I am almost certainly mistaken. Is that why you're using u16?

Copy link
Contributor

Choose a reason for hiding this comment

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

into_bits takes ownership but the types are Copy, so it's fine. save does need to be idempotent yes.

Copy link
Contributor

Choose a reason for hiding this comment

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

And yes please do destructure types in save/restore impls whenever possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattkur thanks for the comments! for u16 - I did that just because other examples were using that. Is it more recommended to use the actual type?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll leave that up to you. It looked a little weird to me to do this shuffle to/from bits explicitly. It also adds work here. But ... I put this squarely in "style" so I'll leave it up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattkur I researched around and it seems that this mesh::payload::encoding::ZeroCopyEncoding is what you are looking for? could you please help see if this update makes sense? I did add unit tests and that worked

@smalis-msft
Copy link
Contributor

Could we hold off on merging this until we have Gen 1 servicing tests onboarded, to make sure this change doesn't break that flow? Should be pretty soon.

@github-actions
Copy link

@shenw0000
Copy link
Contributor Author

Could we hold off on merging this until we have Gen 1 servicing tests onboarded, to make sure this change doesn't break that flow? Should be pretty soon.
@smalis-msft wondering are gen1 servicing tests onboarded yet? thank you!

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.

3 participants