Skip to content

Commit c2f10a0

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 1915947 commit c2f10a0

2 files changed

Lines changed: 12 additions & 418 deletions

File tree

src/vmm/src/pci/bus.rs

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,6 @@ mod tests {
492492
reloc_cnt: AtomicUsize,
493493
}
494494

495-
impl RelocationMock {
496-
fn cnt(&self) -> usize {
497-
self.reloc_cnt.load(std::sync::atomic::Ordering::SeqCst)
498-
}
499-
}
500-
501495
impl DeviceRelocation for RelocationMock {
502496
fn move_bar(
503497
&self,
@@ -516,7 +510,7 @@ mod tests {
516510

517511
impl PciDevMock {
518512
fn new() -> Self {
519-
let mut config = PciConfiguration::new_type0(
513+
let config = PciConfiguration::new_type0(
520514
0x42,
521515
0x0,
522516
0x0,
@@ -526,9 +520,6 @@ mod tests {
526520
0x12,
527521
None,
528522
);
529-
530-
config.add_pci_bar(0, 0x1000, 0x1000);
531-
532523
PciDevMock(config)
533524
}
534525
}
@@ -550,10 +541,10 @@ mod tests {
550541

551542
fn detect_bar_reprogramming(
552543
&mut self,
553-
reg_idx: u16,
554-
data: &[u8],
544+
_reg_idx: u16,
545+
_data: &[u8],
555546
) -> Option<BarReprogrammingParams> {
556-
self.0.detect_bar_reprogramming(reg_idx, data)
547+
None
557548
}
558549
}
559550

@@ -936,56 +927,4 @@ mod tests {
936927
read_mmio_config(&mut mmio_config, 0, 0, 0, 15, 0, &mut buffer);
937928
assert_eq!(buffer[0], 0x42);
938929
}
939-
940-
#[test]
941-
fn test_bar_reprogramming() {
942-
let (mut mmio_config, _, mock) = initialize_bus();
943-
let mut buffer = [0u8; 4];
944-
assert_eq!(mock.cnt(), 0);
945-
946-
read_mmio_config(&mut mmio_config, 0, 1, 0, 0x4, 0, &mut buffer);
947-
let old_addr = u32::from_le_bytes(buffer) & 0xffff_fff0;
948-
assert_eq!(old_addr, 0x1000);
949-
950-
// Writing the lower 32bits first should not trigger any reprogramming
951-
write_mmio_config(
952-
&mut mmio_config,
953-
0,
954-
1,
955-
0,
956-
0x4,
957-
0,
958-
&u32::to_le_bytes(0x1312_0000),
959-
);
960-
961-
read_mmio_config(&mut mmio_config, 0, 1, 0, 0x4, 0, &mut buffer);
962-
let new_addr = u32::from_le_bytes(buffer) & 0xffff_fff0;
963-
assert_eq!(new_addr, 0x1312_0000);
964-
assert_eq!(mock.cnt(), 0);
965-
966-
// Writing the upper 32bits first should now trigger the reprogramming logic
967-
write_mmio_config(&mut mmio_config, 0, 1, 0, 0x5, 0, &u32::to_le_bytes(0x1110));
968-
read_mmio_config(&mut mmio_config, 0, 1, 0, 0x5, 0, &mut buffer);
969-
let new_addr = u32::from_le_bytes(buffer);
970-
assert_eq!(new_addr, 0x1110);
971-
assert_eq!(mock.cnt(), 1);
972-
973-
// BAR2 should not be used, so reading its address should return all 0s
974-
read_mmio_config(&mut mmio_config, 0, 1, 0, 0x6, 0, &mut buffer);
975-
assert_eq!(buffer, [0x0, 0x0, 0x0, 0x0]);
976-
977-
// and reprogramming shouldn't have any effect
978-
write_mmio_config(
979-
&mut mmio_config,
980-
0,
981-
1,
982-
0,
983-
0x5,
984-
0,
985-
&u32::to_le_bytes(0x1312_1110),
986-
);
987-
988-
read_mmio_config(&mut mmio_config, 0, 1, 0, 0x6, 0, &mut buffer);
989-
assert_eq!(buffer, [0x0, 0x0, 0x0, 0x0]);
990-
}
991930
}

0 commit comments

Comments
 (0)