Skip to content

Commit 52e119c

Browse files
committed
pci: virtio: refactor: remove BAR handling from PciConfiguration
Previous commit created a separate `Bars` type to handle BARs region and made VirtioPciDevice type to use it instead of PciConfiguration to handle BARs region. This made BARs handling in PciConfiguration redundant, so this commit removes it. This also removes `detect_bar_reprogramming` support from PciConfiguration. But Firecracker does not support BAR relocation anyway, this does not affect functionality. The removal of `detect_bar_reprogramming` also required to remove the unit test for it in the pci/bus.rs. No functional change. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent f8e983a commit 52e119c

File tree

2 files changed

+12
-411
lines changed

2 files changed

+12
-411
lines changed

src/vmm/src/pci/bus.rs

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,6 @@ mod tests {
466466
reloc_cnt: AtomicUsize,
467467
}
468468

469-
impl RelocationMock {
470-
fn cnt(&self) -> usize {
471-
self.reloc_cnt.load(std::sync::atomic::Ordering::SeqCst)
472-
}
473-
}
474-
475469
impl DeviceRelocation for RelocationMock {
476470
fn move_bar(
477471
&self,
@@ -490,7 +484,7 @@ mod tests {
490484

491485
impl PciDevMock {
492486
fn new() -> Self {
493-
let mut config = PciConfiguration::new_type0(
487+
let config = PciConfiguration::new_type0(
494488
0x42,
495489
0x0,
496490
0x0,
@@ -500,9 +494,6 @@ mod tests {
500494
0x12,
501495
None,
502496
);
503-
504-
config.add_pci_bar(0, 0x1000, 0x1000);
505-
506497
PciDevMock(config)
507498
}
508499
}
@@ -524,10 +515,10 @@ mod tests {
524515

525516
fn detect_bar_reprogramming(
526517
&mut self,
527-
reg_idx: usize,
528-
data: &[u8],
518+
_reg_idx: usize,
519+
_data: &[u8],
529520
) -> Option<BarReprogrammingParams> {
530-
self.0.detect_bar_reprogramming(reg_idx, data)
521+
None
531522
}
532523
}
533524

@@ -910,56 +901,4 @@ mod tests {
910901
read_mmio_config(&mut mmio_config, 0, 0, 0, 15, 0, &mut buffer);
911902
assert_eq!(buffer[0], 0x42);
912903
}
913-
914-
#[test]
915-
fn test_bar_reprogramming() {
916-
let (mut mmio_config, _, mock) = initialize_bus();
917-
let mut buffer = [0u8; 4];
918-
assert_eq!(mock.cnt(), 0);
919-
920-
read_mmio_config(&mut mmio_config, 0, 1, 0, 0x4, 0, &mut buffer);
921-
let old_addr = u32::from_le_bytes(buffer) & 0xffff_fff0;
922-
assert_eq!(old_addr, 0x1000);
923-
924-
// Writing the lower 32bits first should not trigger any reprogramming
925-
write_mmio_config(
926-
&mut mmio_config,
927-
0,
928-
1,
929-
0,
930-
0x4,
931-
0,
932-
&u32::to_le_bytes(0x1312_0000),
933-
);
934-
935-
read_mmio_config(&mut mmio_config, 0, 1, 0, 0x4, 0, &mut buffer);
936-
let new_addr = u32::from_le_bytes(buffer) & 0xffff_fff0;
937-
assert_eq!(new_addr, 0x1312_0000);
938-
assert_eq!(mock.cnt(), 0);
939-
940-
// Writing the upper 32bits first should now trigger the reprogramming logic
941-
write_mmio_config(&mut mmio_config, 0, 1, 0, 0x5, 0, &u32::to_le_bytes(0x1110));
942-
read_mmio_config(&mut mmio_config, 0, 1, 0, 0x5, 0, &mut buffer);
943-
let new_addr = u32::from_le_bytes(buffer);
944-
assert_eq!(new_addr, 0x1110);
945-
assert_eq!(mock.cnt(), 1);
946-
947-
// BAR2 should not be used, so reading its address should return all 0s
948-
read_mmio_config(&mut mmio_config, 0, 1, 0, 0x6, 0, &mut buffer);
949-
assert_eq!(buffer, [0x0, 0x0, 0x0, 0x0]);
950-
951-
// and reprogramming shouldn't have any effect
952-
write_mmio_config(
953-
&mut mmio_config,
954-
0,
955-
1,
956-
0,
957-
0x5,
958-
0,
959-
&u32::to_le_bytes(0x1312_1110),
960-
);
961-
962-
read_mmio_config(&mut mmio_config, 0, 1, 0, 0x6, 0, &mut buffer);
963-
assert_eq!(buffer, [0x0, 0x0, 0x0, 0x0]);
964-
}
965904
}

0 commit comments

Comments
 (0)