Skip to content

Refactor VirtIO devices, preparing for a PCI transport layer #5160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 30, 2025

Conversation

bchalios
Copy link
Contributor

Changes

This does a few changes around interrupts for VirtIO devices and code organization for being able to handle multiple transports for VirtIO devices:

  1. Creates a transport module within vmm::devices::virtio and moves mmio module inside it
  2. Adds a VirtioInterrupt trait that abstracts away the functionality of interrupts used by VirtIO devices. At the moment, only IrqTrigger implements VirtioInterrupt.
  3. Changes the moment in which an IrqTrigger object is assigned to a VirtIO device. Up until now we created this object when creating the device itself. This PR changes this logic so that it is the transport layer that creates this interrupt and passes it over to the device during activation time. This is how things are done with PCIe in the Cloud Hypervisor implementation. It also, doesn't change anything for us, semantically; devices only trigger interrupts after having been activated.

Reason

Preparing for adding PCIe support

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • I have read and understand CONTRIBUTING.md.
  • I have run tools/devtool checkstyle to verify that the PR passes the
    automated style checks.
  • I have described what is done in these changes, why they are needed, and
    how they are solving the problem in a clear and encompassing way.
  • I have updated any relevant documentation (both in code and in the docs)
    in the PR.
  • I have mentioned all user-facing changes in CHANGELOG.md.
  • If a specific issue led to this PR, this PR closes the issue.
  • When making API changes, I have followed the
    Runbook for Firecracker API changes.
  • I have tested all new and changed functionalities in unit tests and/or
    integration tests.
  • I have linked an issue to every new TODO.

  • This functionality cannot be added in rust-vmm.

Copy link

codecov bot commented Apr 17, 2025

Codecov Report

Attention: Patch coverage is 82.48408% with 55 lines in your changes missing coverage. Please review.

Project coverage is 83.07%. Comparing base (ae078ee) to head (7427a7d).
Report is 5 commits behind head on feature/pcie.

Files with missing lines Patch % Lines
src/vmm/src/devices/virtio/block/device.rs 0.00% 10 Missing ⚠️
src/vmm/src/devices/virtio/vsock/device.rs 66.66% 8 Missing ⚠️
src/vmm/src/devices/virtio/rng/device.rs 71.42% 6 Missing ⚠️
src/vmm/src/devices/virtio/transport/mmio.rs 90.00% 6 Missing ⚠️
src/vmm/src/devices/virtio/balloon/persist.rs 0.00% 4 Missing ⚠️
src/vmm/src/devices/virtio/block/virtio/persist.rs 0.00% 4 Missing ⚠️
src/vmm/src/devices/virtio/net/persist.rs 0.00% 4 Missing ⚠️
src/vmm/src/devices/virtio/vsock/persist.rs 0.00% 4 Missing ⚠️
src/vmm/src/devices/virtio/transport/mod.rs 0.00% 3 Missing ⚠️
src/vmm/src/devices/virtio/balloon/device.rs 93.10% 2 Missing ⚠️
... and 4 more
Additional details and impacted files
@@              Coverage Diff               @@
##           feature/pcie    #5160    +/-   ##
==============================================
  Coverage         83.06%   83.07%            
==============================================
  Files               250      251     +1     
  Lines             26897    27033   +136     
==============================================
+ Hits              22342    22457   +115     
- Misses             4555     4576    +21     
Flag Coverage Δ
5.10-c5n.metal 83.57% <82.48%> (+<0.01%) ⬆️
5.10-m5n.metal 83.56% <82.48%> (-0.01%) ⬇️
5.10-m6a.metal 82.80% <82.48%> (+0.01%) ⬆️
5.10-m6g.metal 79.37% <82.42%> (+0.03%) ⬆️
5.10-m6i.metal 83.56% <82.48%> (+<0.01%) ⬆️
5.10-m7a.metal-48xl 82.78% <82.48%> (+<0.01%) ⬆️
5.10-m7g.metal 79.37% <82.42%> (+0.03%) ⬆️
5.10-m7i.metal-24xl 83.52% <82.48%> (-0.01%) ⬇️
5.10-m7i.metal-48xl 83.52% <82.48%> (-0.01%) ⬇️
5.10-m8g.metal-24xl 79.37% <82.42%> (+0.03%) ⬆️
5.10-m8g.metal-48xl 79.37% <82.42%> (+0.03%) ⬆️
6.1-c5n.metal 83.61% <82.48%> (+<0.01%) ⬆️
6.1-m5n.metal 83.61% <82.48%> (+<0.01%) ⬆️
6.1-m6a.metal 82.84% <82.48%> (+0.01%) ⬆️
6.1-m6g.metal 79.37% <82.42%> (+0.03%) ⬆️
6.1-m6i.metal 83.60% <82.48%> (+<0.01%) ⬆️
6.1-m7a.metal-48xl 82.84% <82.48%> (+0.01%) ⬆️
6.1-m7g.metal 79.37% <82.42%> (+0.03%) ⬆️
6.1-m7i.metal-24xl 83.62% <82.48%> (+<0.01%) ⬆️
6.1-m7i.metal-48xl 83.63% <82.48%> (+<0.01%) ⬆️
6.1-m8g.metal-24xl 79.37% <82.42%> (+0.03%) ⬆️
6.1-m8g.metal-48xl 79.37% <82.42%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bchalios bchalios force-pushed the feature/pcie branch 7 times, most recently from 7ab92d6 to 5dd5953 Compare April 22, 2025 12:30
Copy link
Contributor

@Manciukic Manciukic left a comment

Choose a reason for hiding this comment

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

I had just a quick look but it looks good to me overall.

@bchalios bchalios force-pushed the feature/pcie branch 2 times, most recently from 040a2e2 to 9880eac Compare April 23, 2025 09:07
@bchalios bchalios force-pushed the feature/pcie branch 5 times, most recently from c59d619 to e21d2f7 Compare April 28, 2025 09:10
@bchalios bchalios marked this pull request as ready for review April 29, 2025 09:46
@bchalios bchalios added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Apr 29, 2025
@bchalios
Copy link
Contributor Author

I checked the codecov failures. All reported unchecked lines of code were already existing. It's not new code.

@bchalios bchalios changed the title RFC: refactor VirtIO devices, preparing for a PCI transport layer Refactor VirtIO devices, preparing for a PCI transport layer Apr 29, 2025
@bchalios bchalios force-pushed the feature/pcie branch 3 times, most recently from 023ad6e to dc41d9e Compare April 29, 2025 13:24
@bchalios bchalios force-pushed the feature/pcie branch 2 times, most recently from aa74281 to 7ff5c60 Compare April 30, 2025 07:37
This is just code organization changes. Create a new module under
`virtio`, called `transport`. For the time being the only transport
supported is `mmio`. Also, move `IrqInterrupt` type within the MMIO
transport code, as it is MMIO specific.

Signed-off-by: Babis Chalios <bchalios@amazon.es>
`IrqTrigger::new()` returns a `Result` because creating an `EventFd`
might fail with an `std::io::Error` error. All users of `IrqTrigger`
create the object and directly unwrap the error.

To avoid unwraps all over the place, change `IrqTrigger::new()` to
unwrap a potential error while creating the EventFd internally and just
return `Self`.

Signed-off-by: Babis Chalios <bchalios@amazon.es>
The MMIO transport for VirtIO devices uses an `IrqTrigger` object as the
object that models the logic for sending interrupts from the device to
the guest. We create one such object for every VirtIO device when
creating it. The MMIO device manager associates this object with an IRQ
number and registers it with KVM.

This commit changes the timing of association of an `IrqTrigger` with a
VirtIO-mmio device. It only assigns such an object to the device during
its activation. We do this to prepare for supporting a PCI transport for
VirtIO devices. The cloud hypervisor implementation for these passes the
interrupt objects used by the device during activation, so we make this
change to have a uniform way to handle interrupts for both transports.
Functionally, nothing changes for MMIO devices, as before activation we
don't trigger any interrupts.

Signed-off-by: Babis Chalios <bchalios@amazon.es>
Describing the APIs that need to implement types that are used as
interrupts for VirtIO devices. Currently, we only use `IrqInterrupt`
interrupts, but this will change once we have MSI-X with PCIe devices.

Signed-off-by: Babis Chalios <bchalios@amazon.es>
VirtIO devices assume they're operating under an MMIO transport and as a
consequence they use IrqTrigger as interrupts. Switch that to using
VirtioInterrupt for all VirtIO device objects. Only assume a
VirtioInterrupt is an IrqTrigger in MMIO specific code.

Signed-off-by: Babis Chalios <bchalios@amazon.es>
@bchalios bchalios enabled auto-merge (rebase) April 30, 2025 09:46
@bchalios bchalios merged commit 87a7164 into firecracker-microvm:feature/pcie Apr 30, 2025
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting review Indicates that a pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants