Skip to content

Commit 6b5816b

Browse files
committed
Adding the ControllerManagementFaultConfiguration to the mix
1 parent 3d713a3 commit 6b5816b

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use inspect::InspectMut;
1111
use mesh::CellUpdater;
1212
use nvme::NvmeControllerCaps;
1313
use nvme_resources::fault::AdminQueueFaultConfig;
14-
use nvme_resources::fault::FaultConfiguration;
14+
use nvme_resources::fault::ControllerManagementFaultConfig;
1515
use nvme_resources::fault::FaultBehaviour;
16+
use nvme_resources::fault::FaultConfiguration;
1617
use nvme_spec::AdminOpcode;
1718
use nvme_spec::Cap;
1819
use nvme_spec::Command;
@@ -50,6 +51,7 @@ async fn test_nvme_command_fault(driver: DefaultDriver) {
5051
AdminOpcode::CREATE_IO_COMPLETION_QUEUE.0,
5152
FaultBehaviour::Update(output_cmd),
5253
),
54+
controller_management_fault: ControllerManagementFaultConfig::new(),
5355
},
5456
)
5557
.await;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct ControllerManagementFaultConfig {
3030
pub controller_management_fault_enable: FaultBehaviour<bool>,
3131
}
3232

33-
#[derive(MeshPayload)]
33+
#[derive(MeshPayload, Clone)]
3434
/// A buildable fault configuration for the controller management interface (cc.en(), csts.rdy(), ... )
3535
pub struct ControllerManagementFaultConfig {
3636
/// Fault to apply to cc.en() bit during enablement

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use guestmem::GuestMemory;
3030
use guid::Guid;
3131
use inspect::Inspect;
3232
use inspect::InspectMut;
33+
use nvme_resources::fault::FaultBehaviour;
3334
use nvme_resources::fault::FaultConfiguration;
3435
use parking_lot::Mutex;
3536
use pci_core::capabilities::msix::MsixEmulator;
@@ -157,7 +158,7 @@ impl NvmeFaultController {
157158
max_cqs: caps.max_io_queues,
158159
qe_sizes: Arc::clone(&qe_sizes),
159160
subsystem_id: caps.subsystem_id,
160-
fault_configuration,
161+
fault_configuration: fault_configuration.clone(),
161162
});
162163

163164
Self {
@@ -166,6 +167,7 @@ impl NvmeFaultController {
166167
registers: RegState::new(),
167168
workers: admin,
168169
qe_sizes,
170+
fault_configuration,
169171
}
170172
}
171173

@@ -343,8 +345,23 @@ impl NvmeFaultController {
343345

344346
if cc.en() != self.registers.cc.en() {
345347
if cc.en() {
346-
// If any, perform the fault at the beginning of the enable sequence.
347-
if
348+
// If any fault was configured for cc.en() process it here
349+
match self
350+
.fault_configuration
351+
.controller_management_fault
352+
.controller_management_fault_enable
353+
{
354+
FaultBehaviour::Delay(duration) => {
355+
std::thread::sleep(duration);
356+
}
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
364+
}
348365

349366
// Some drivers will write zeros to IOSQES and IOCQES, assuming that the defaults will work.
350367
if cc.iocqes() == 0 {
@@ -389,8 +406,6 @@ impl NvmeFaultController {
389406
}
390407
}
391408

392-
393-
394409
self.registers.cc = cc;
395410
*self.qe_sizes.lock() = IoQueueEntrySizes {
396411
sqe_bits: cc.iosqes(),
@@ -437,6 +452,7 @@ impl ChangeDeviceState for NvmeFaultController {
437452
registers,
438453
qe_sizes,
439454
workers,
455+
fault_configuration: _,
440456
} = self;
441457
workers.reset().await;
442458
cfg_space.reset();

0 commit comments

Comments
 (0)