Skip to content

Commit e004a93

Browse files
committed
Created a whole new struct for Pci related faults
1 parent 6b5816b commit e004a93

File tree

7 files changed

+42
-47
lines changed

7 files changed

+42
-47
lines changed

vm/devices/storage/disk_nvme/nvme_driver/src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use inspect::InspectMut;
1111
use mesh::CellUpdater;
1212
use nvme::NvmeControllerCaps;
1313
use nvme_resources::fault::AdminQueueFaultConfig;
14-
use nvme_resources::fault::ControllerManagementFaultConfig;
15-
use nvme_resources::fault::FaultBehaviour;
1614
use nvme_resources::fault::FaultConfiguration;
15+
use nvme_resources::fault::PciFaultConfig;
16+
use nvme_resources::fault::QueueFaultBehavior;
1717
use nvme_spec::AdminOpcode;
1818
use nvme_spec::Cap;
1919
use nvme_spec::Command;
@@ -49,9 +49,9 @@ async fn test_nvme_command_fault(driver: DefaultDriver) {
4949
fault_active: CellUpdater::new(true).cell(),
5050
admin_fault: AdminQueueFaultConfig::new().with_submission_queue_fault(
5151
AdminOpcode::CREATE_IO_COMPLETION_QUEUE.0,
52-
FaultBehaviour::Update(output_cmd),
52+
QueueFaultBehavior::Update(output_cmd),
5353
),
54-
controller_management_fault: ControllerManagementFaultConfig::new(),
54+
pci_fault: PciFaultConfig::new(),
5555
},
5656
)
5757
.await;

vm/devices/storage/nvme_resources/src/fault.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,27 @@ pub enum QueueFaultBehavior<T> {
2323
Panic(String),
2424
}
2525

26-
#[derive(MeshPayload)]
27-
/// A buildable fault configuration for the controller management interface (cc.en(), csts.rdy(), ... )
28-
pub struct ControllerManagementFaultConfig {
29-
/// Fault to apply to cc.en() bit during enablement
30-
pub controller_management_fault_enable: FaultBehaviour<bool>,
26+
#[derive(Clone, MeshPayload)]
27+
/// Supported fault behaviour for PCI faults
28+
pub enum PciFaultBehavior {
29+
/// Introduce a delay to the PCI operation
30+
Delay(Duration),
31+
/// Do nothing
32+
Default,
3133
}
3234

3335
#[derive(MeshPayload, Clone)]
3436
/// A buildable fault configuration for the controller management interface (cc.en(), csts.rdy(), ... )
35-
pub struct ControllerManagementFaultConfig {
37+
pub struct PciFaultConfig {
3638
/// Fault to apply to cc.en() bit during enablement
37-
pub controller_management_fault_enable: FaultBehaviour<bool>,
39+
pub controller_management_fault_enable: PciFaultBehavior,
3840
}
3941

4042
#[derive(MeshPayload, Clone)]
4143
/// A buildable fault configuration
4244
pub struct AdminQueueFaultConfig {
4345
/// A map of NVME opcodes to the fault behavior for each. (This would ideally be a `HashMap`, but `mesh` doesn't support that type. Given that this is not performance sensitive, the lookup is okay)
44-
pub admin_submission_queue_faults: Vec<(u8, FaultBehaviour<Command>)>,
46+
pub admin_submission_queue_faults: Vec<(u8, QueueFaultBehavior<Command>)>,
4547
}
4648

4749
#[derive(MeshPayload, Clone)]
@@ -52,22 +54,19 @@ pub struct FaultConfiguration {
5254
/// Fault to apply to the admin queues
5355
pub admin_fault: AdminQueueFaultConfig,
5456
/// Fault to apply to management layer of the controller
55-
pub controller_management_fault: ControllerManagementFaultConfig,
57+
pub pci_fault: PciFaultConfig,
5658
}
5759

58-
impl ControllerManagementFaultConfig {
60+
impl PciFaultConfig {
5961
/// Create a new no-op fault configuration
6062
pub fn new() -> Self {
6163
Self {
62-
controller_management_fault_enable: FaultBehaviour::Default,
64+
controller_management_fault_enable: PciFaultBehavior::Default,
6365
}
6466
}
6567

6668
/// Create a new fault configuration
67-
pub fn with_controller_management_enable_fault(
68-
mut self,
69-
behaviour: FaultBehaviour<bool>,
70-
) -> Self {
69+
pub fn with_cc_enable_fault(mut self, behaviour: PciFaultBehavior) -> Self {
7170
self.controller_management_fault_enable = behaviour;
7271
self
7372
}
@@ -85,7 +84,7 @@ impl AdminQueueFaultConfig {
8584
pub fn with_submission_queue_fault(
8685
mut self,
8786
opcode: u8,
88-
behaviour: FaultBehaviour<Command>,
87+
behaviour: QueueFaultBehavior<Command>,
8988
) -> Self {
9089
if self
9190
.admin_submission_queue_faults

vm/devices/storage/nvme_test/src/pci.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use guestmem::GuestMemory;
3030
use guid::Guid;
3131
use inspect::Inspect;
3232
use inspect::InspectMut;
33-
use nvme_resources::fault::FaultBehaviour;
3433
use nvme_resources::fault::FaultConfiguration;
34+
use nvme_resources::fault::PciFaultBehavior;
3535
use parking_lot::Mutex;
3636
use pci_core::capabilities::msix::MsixEmulator;
3737
use pci_core::cfg_space_emu::BarMemoryKind;
@@ -348,19 +348,13 @@ impl NvmeFaultController {
348348
// If any fault was configured for cc.en() process it here
349349
match self
350350
.fault_configuration
351-
.controller_management_fault
351+
.pci_fault
352352
.controller_management_fault_enable
353353
{
354-
FaultBehaviour::Delay(duration) => {
354+
PciFaultBehavior::Delay(duration) => {
355355
std::thread::sleep(duration);
356356
}
357-
FaultBehaviour::Drop => {
358-
tracelimit::warn_ratelimited!(
359-
"Dropping enable command due to fault injection"
360-
);
361-
return;
362-
}
363-
_ => {} // Update is not yet configured for this fault. Treat that as a default action for now
357+
PciFaultBehavior::Default => {}
364358
}
365359

366360
// Some drivers will write zeros to IOSQES and IOCQES, assuming that the defaults will work.

vm/devices/storage/nvme_test/src/tests/controller_tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use guestmem::GuestMemory;
1717
use guid::Guid;
1818
use mesh::CellUpdater;
1919
use nvme_resources::fault::AdminQueueFaultConfig;
20-
use nvme_resources::fault::ControllerManagementFaultConfig;
21-
use nvme_resources::fault::FaultBehaviour;
2220
use nvme_resources::fault::FaultConfiguration;
21+
use nvme_resources::fault::PciFaultConfig;
22+
use nvme_resources::fault::QueueFaultBehavior;
2323
use nvme_spec::Command;
2424
use nvme_spec::Completion;
2525
use pal_async::DefaultDriver;
@@ -209,7 +209,7 @@ async fn test_basic_registers(driver: DefaultDriver) {
209209
let fault_configuration = FaultConfiguration {
210210
fault_active: CellUpdater::new(false).cell(),
211211
admin_fault: AdminQueueFaultConfig::new(),
212-
controller_management_fault: ControllerManagementFaultConfig::new(),
212+
pci_fault: PciFaultConfig::new(),
213213
};
214214
let mut nvmec = instantiate_controller(driver, &gm, None, fault_configuration);
215215
let mut dword = 0u32;
@@ -238,7 +238,7 @@ async fn test_invalid_configuration(driver: DefaultDriver) {
238238
let fault_configuration = FaultConfiguration {
239239
fault_active: CellUpdater::new(false).cell(),
240240
admin_fault: AdminQueueFaultConfig::new(),
241-
controller_management_fault: ControllerManagementFaultConfig::new(),
241+
pci_fault: PciFaultConfig::new(),
242242
};
243243
let mut nvmec = instantiate_controller(driver, &gm, None, fault_configuration);
244244
let mut dword = 0u32;
@@ -257,7 +257,7 @@ async fn test_enable_controller(driver: DefaultDriver) {
257257
let fault_configuration = FaultConfiguration {
258258
fault_active: CellUpdater::new(false).cell(),
259259
admin_fault: AdminQueueFaultConfig::new(),
260-
controller_management_fault: ControllerManagementFaultConfig::new(),
260+
pci_fault: PciFaultConfig::new(),
261261
};
262262
let mut nvmec = instantiate_controller(driver, &gm, None, fault_configuration);
263263

@@ -289,7 +289,7 @@ async fn test_multi_page_admin_queues(driver: DefaultDriver) {
289289
let fault_configuration = FaultConfiguration {
290290
fault_active: CellUpdater::new(false).cell(),
291291
admin_fault: AdminQueueFaultConfig::new(),
292-
controller_management_fault: ControllerManagementFaultConfig::new(),
292+
pci_fault: PciFaultConfig::new(),
293293
};
294294
let mut nvmec = instantiate_controller(driver, &gm, None, fault_configuration);
295295

@@ -364,7 +364,7 @@ async fn test_send_identify_no_fault(driver: DefaultDriver) {
364364
let fault_configuration = FaultConfiguration {
365365
fault_active: CellUpdater::new(false).cell(),
366366
admin_fault: AdminQueueFaultConfig::new(),
367-
controller_management_fault: ControllerManagementFaultConfig::new(),
367+
pci_fault: PciFaultConfig::new(),
368368
};
369369
let cqe = send_identify(driver, fault_configuration).await;
370370

@@ -380,9 +380,9 @@ async fn test_send_identify_with_sq_fault(driver: DefaultDriver) {
380380
fault_active: CellUpdater::new(true).cell(),
381381
admin_fault: AdminQueueFaultConfig::new().with_submission_queue_fault(
382382
nvme_spec::AdminOpcode::IDENTIFY.0,
383-
FaultBehaviour::Update(faulty_identify),
383+
QueueFaultBehavior::Update(faulty_identify),
384384
),
385-
controller_management_fault: ControllerManagementFaultConfig::new(),
385+
pci_fault: PciFaultConfig::new(),
386386
};
387387
let cqe = send_identify(driver, fault_configuration).await;
388388

vm/devices/storage/nvme_test/src/tests/shadow_doorbell_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use crate::tests::test_helpers::write_command_to_queue;
1414
use guestmem::GuestMemory;
1515
use mesh::CellUpdater;
1616
use nvme_resources::fault::AdminQueueFaultConfig;
17-
use nvme_resources::fault::ControllerManagementFaultConfig;
1817
use nvme_resources::fault::FaultConfiguration;
18+
use nvme_resources::fault::PciFaultConfig;
1919
use pal_async::DefaultDriver;
2020
use pal_async::async_test;
2121
use pci_core::test_helpers::TestPciInterruptController;
@@ -43,7 +43,7 @@ async fn setup_shadow_doorbells(
4343
let fault_configuration = FaultConfiguration {
4444
fault_active: CellUpdater::new(false).cell(),
4545
admin_fault: AdminQueueFaultConfig::new(),
46-
controller_management_fault: ControllerManagementFaultConfig::new(),
46+
pci_fault: PciFaultConfig::new(),
4747
}; // Build a controller with 64 entries in the admin queue (just so that the ASQ fits in one page).
4848
let mut nvmec = instantiate_and_build_admin_queue(
4949
cq_buf,

vm/devices/storage/nvme_test/src/workers/admin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ use futures_concurrency::future::Race;
3131
use guestmem::GuestMemory;
3232
use guid::Guid;
3333
use inspect::Inspect;
34-
use nvme_resources::fault::FaultBehaviour;
3534
use nvme_resources::fault::FaultConfiguration;
35+
use nvme_resources::fault::QueueFaultBehavior;
3636
use pal_async::task::Spawn;
3737
use pal_async::task::Task;
3838
use pal_async::timer::PolledTimer;
@@ -481,22 +481,22 @@ impl AdminHandler {
481481
.unwrap_or_else(|| QueueFaultBehavior::Default);
482482

483483
match fault {
484-
FaultBehaviour::Update(command_updated) => {
484+
QueueFaultBehavior::Update(command_updated) => {
485485
tracing::warn!(
486486
"configured fault: admin command updated in sq. original: {:?},\n new: {:?}",
487487
&command,
488488
&command_updated
489489
);
490490
command = command_updated;
491491
}
492-
FaultBehaviour::Drop => {
492+
QueueFaultBehavior::Drop => {
493493
tracing::warn!(
494494
"configured fault: admin command dropped from sq {:?}",
495495
&command
496496
);
497497
return Ok(());
498498
}
499-
FaultBehaviour::Delay(duration) => {
499+
QueueFaultBehavior::Delay(duration) => {
500500
self.timer.sleep(duration).await;
501501
}
502502
QueueFaultBehavior::Panic(message) => {

vmm_tests/vmm_tests/tests/tests/multiarch/openhcl_servicing.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ use mesh::CellUpdater;
1515
use nvme_resources::NamespaceDefinition;
1616
use nvme_resources::NvmeFaultControllerHandle;
1717
use nvme_resources::fault::AdminQueueFaultConfig;
18-
use nvme_resources::fault::FaultBehaviour;
1918
use nvme_resources::fault::FaultConfiguration;
19+
use nvme_resources::fault::PciFaultConfig;
20+
use nvme_resources::fault::QueueFaultBehavior;
2021
use petri::OpenHclServicingFlags;
2122
use petri::PetriVmBuilder;
2223
use petri::PetriVmmBackend;
@@ -256,8 +257,9 @@ async fn keepalive_with_nvme_fault(
256257
fault_active: fault_start_updater.cell(),
257258
admin_fault: AdminQueueFaultConfig::new().with_submission_queue_fault(
258259
nvme_spec::AdminOpcode::CREATE_IO_COMPLETION_QUEUE.0,
259-
QueueFaultBehavior::Panic("Received a CREATE_IO_COMPLETION_QUEUE command during servicing with keepalive enabled. This should never happen.".to_string()),
260+
QueueFaultBehavior::Panic("Received a CREATE_IO_COMPLETION_QUEUE command during servicing with keepalive enabled. THERE IS A BUG SOMEWHERE.".to_string()),
260261
),
262+
pci_fault: PciFaultConfig::new(),
261263
};
262264

263265
let (mut vm, agent) = config

0 commit comments

Comments
 (0)