-
Notifications
You must be signed in to change notification settings - Fork 2.1k
increase the number of IRQs on x86_64 #2286
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,13 @@ use crate::mem_size_mib; | |
| use crate::vmm_config::snapshot::{CreateSnapshotParams, LoadSnapshotParams, SnapshotType}; | ||
| use crate::vstate::{self, vcpu::VcpuState, vm::VmState}; | ||
|
|
||
| use crate::device_manager::mmio::MMIODeviceManager; | ||
| use crate::device_manager::persist::DeviceStates; | ||
| use crate::memory_snapshot; | ||
| use crate::memory_snapshot::{GuestMemoryState, SnapshotMemory}; | ||
| use crate::version_map::FC_VERSION_TO_SNAP_VERSION; | ||
| use crate::Vmm; | ||
| use arch::IRQ_BASE; | ||
| use cpuid::common::{get_vendor_id_from_cpuid, get_vendor_id_from_host}; | ||
| use logger::{error, info}; | ||
| use polly::event_manager::EventManager; | ||
|
|
@@ -32,6 +34,10 @@ use versionize::{VersionMap, Versionize, VersionizeResult}; | |
| use versionize_derive::Versionize; | ||
| use vm_memory::GuestMemoryMmap; | ||
|
|
||
| const FC_V0_23_SNAP_VERSION: u16 = 1; | ||
| const FC_V0_23_IRQ_NUMBER: u32 = 16; | ||
| const FC_V0_23_MAX_DEVICES: u32 = FC_V0_23_IRQ_NUMBER - IRQ_BASE; | ||
|
|
||
| /// Holds information related to the VM that is not part of VmState. | ||
| #[derive(Debug, PartialEq, Versionize)] | ||
| // NOTICE: Any changes to this structure require a snapshot version bump. | ||
|
|
@@ -115,6 +121,8 @@ pub enum CreateSnapshotError { | |
| SerializeMicrovmState(snapshot::Error), | ||
| /// Failed to open the snapshot backing file. | ||
| SnapshotBackingFile(io::Error), | ||
| /// Number of devices exceeds the maximum supported devices for the snapshot data version. | ||
| TooManyDevices(usize), | ||
| } | ||
|
|
||
| impl Display for CreateSnapshotError { | ||
|
|
@@ -132,6 +140,12 @@ impl Display for CreateSnapshotError { | |
| MicrovmState(err) => write!(f, "Cannot save microvm state: {}", err), | ||
| SerializeMicrovmState(err) => write!(f, "Cannot serialize MicrovmState: {:?}", err), | ||
| SnapshotBackingFile(err) => write!(f, "Cannot open snapshot file: {:?}", err), | ||
| TooManyDevices(val) => write!( | ||
| f, | ||
| "Too many devices attached: {}. The maximum number allowed \ | ||
| for the snapshot data version requested is {}.", | ||
| val, FC_V0_23_MAX_DEVICES | ||
| ), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -187,6 +201,7 @@ pub fn create_snapshot( | |
| ¶ms.snapshot_path, | ||
| ¶ms.version, | ||
| version_map, | ||
| &vmm.mmio_device_manager, | ||
| )?; | ||
|
|
||
| Ok(()) | ||
|
|
@@ -197,6 +212,7 @@ fn snapshot_state_to_file( | |
| snapshot_path: &PathBuf, | ||
| version: &Option<String>, | ||
| version_map: VersionMap, | ||
| device_manager: &MMIODeviceManager, | ||
| ) -> std::result::Result<(), CreateSnapshotError> { | ||
| use self::CreateSnapshotError::*; | ||
| let mut snapshot_file = OpenOptions::new() | ||
|
|
@@ -208,6 +224,10 @@ fn snapshot_state_to_file( | |
| // Translate the microVM version to its corresponding snapshot data format. | ||
| let snapshot_data_version = match version { | ||
| Some(version) => match FC_VERSION_TO_SNAP_VERSION.get(version) { | ||
| Some(&FC_V0_23_SNAP_VERSION) => { | ||
| validate_devices_number(device_manager.used_irqs_count())?; | ||
luminitavoicu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Ok(FC_V0_23_SNAP_VERSION) | ||
| } | ||
| Some(data_version) => Ok(*data_version), | ||
| _ => Err(InvalidVersion), | ||
| }, | ||
|
|
@@ -330,6 +350,14 @@ fn guest_memory_from_file( | |
| GuestMemoryMmap::restore(&mem_file, mem_state, track_dirty_pages).map_err(DeserializeMemory) | ||
| } | ||
|
|
||
| fn validate_devices_number(device_number: usize) -> std::result::Result<(), CreateSnapshotError> { | ||
| use self::CreateSnapshotError::TooManyDevices; | ||
| if device_number > FC_V0_23_MAX_DEVICES as usize { | ||
| return Err(TooManyDevices(device_number)); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
Comment on lines
+353
to
+359
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this is function is specific to v0.23-only, it've better been hardcoded in the version |
||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
@@ -462,6 +490,9 @@ mod tests { | |
|
|
||
| let err = SnapshotBackingFile(io::Error::from_raw_os_error(0)); | ||
| let _ = format!("{}{:?}", err, err); | ||
|
|
||
| let err = TooManyDevices(0); | ||
| let _ = format!("{}{:?}", err, err); | ||
| } | ||
|
|
||
| #[test] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Tests scenario for adding the maximum number of devices to a microVM.""" | ||
|
|
||
| import platform | ||
| import pytest | ||
| import host_tools.network as net_tools | ||
|
|
||
| # IRQs are available from 5 to 23, so the maximum number of devices | ||
| # supported at the same time is 19. | ||
| MAX_DEVICES_ATTACHED = 19 | ||
sandreim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| platform.machine() != "x86_64", | ||
| reason="Firecracker supports 24 IRQs on x86_64." | ||
| ) | ||
| def test_attach_maximum_devices(test_microvm_with_ssh, network_config): | ||
| """Test attaching maximum number of devices to the microVM.""" | ||
| test_microvm = test_microvm_with_ssh | ||
| test_microvm.spawn() | ||
|
|
||
| # Set up a basic microVM. | ||
| test_microvm.basic_config() | ||
|
|
||
| # Add (`MAX_DEVICES_ATTACHED` - 1) devices because the rootfs | ||
| # has already been configured in the `basic_config()`function. | ||
| guest_ips = [] | ||
| for i in range(MAX_DEVICES_ATTACHED - 1): | ||
| # Create tap before configuring interface. | ||
| _tap, _host_ip, guest_ip = test_microvm.ssh_network_config( | ||
| network_config, | ||
| str(i) | ||
| ) | ||
| guest_ips.append(guest_ip) | ||
|
|
||
| test_microvm.start() | ||
|
|
||
| # Test that network devices attached are operational. | ||
| for i in range(MAX_DEVICES_ATTACHED - 1): | ||
| test_microvm.ssh_config['hostname'] = guest_ips[i] | ||
| ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config) | ||
| # Verify if guest can run commands. | ||
| exit_code, _, _ = ssh_connection.execute_command("sync") | ||
| assert exit_code == 0 | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| platform.machine() != "x86_64", | ||
| reason="Firecracker supports 24 IRQs on x86_64." | ||
| ) | ||
| def test_attach_too_many_devices(test_microvm_with_ssh, network_config): | ||
| """Test attaching to a microVM more devices than available IRQs.""" | ||
| test_microvm = test_microvm_with_ssh | ||
| test_microvm.spawn() | ||
|
|
||
| # Set up a basic microVM. | ||
| test_microvm.basic_config() | ||
|
|
||
| # Add `MAX_DEVICES_ATTACHED` network devices on top of the | ||
| # already configured rootfs. | ||
| for i in range(MAX_DEVICES_ATTACHED): | ||
| # Create tap before configuring interface. | ||
| _tap, _host_ip, _guest_ip = test_microvm.ssh_network_config( | ||
| network_config, | ||
| str(i) | ||
| ) | ||
|
|
||
| # Attempting to start a microVM with more than | ||
| # `MAX_DEVICES_ATTACHED` devices should fail. | ||
| response = test_microvm.actions.put(action_type='InstanceStart') | ||
| assert test_microvm.api_session.is_status_bad_request(response.status_code) | ||
| assert "no more IRQs are available" in response.text | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.