Skip to content

Commit

Permalink
fix(virtio/pci): don't try to map VIRTIO_PCI_CAP_PCI_CFG
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
  • Loading branch information
mkroening committed Jun 4, 2024
1 parent 3db35b1 commit a09a5a9
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/drivers/virtio/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,12 +972,10 @@ fn read_caps(

let mut cap_list: Vec<PciCap> = Vec::new();
// Loop through capabilities list via next pointer
'cap_list: while next_ptr != 0u32 {
while next_ptr != 0u32 {
// read into raw capabilities structure
let cap_raw = read_cap_raw(device, next_ptr);

let mut iter = bars.iter();

let cfg_ptr = next_ptr;
// Set next pointer for next iteration of `caplist.
next_ptr = u32::from(cap_raw.cap_next);
Expand All @@ -986,27 +984,18 @@ fn read_caps(
// with virtio vendor id = 0x09
match cap_raw.cap_vndr {
0x09u8 => {
let cap_bar: PciBar = loop {
match iter.next() {
Some(bar) => {
// Drivers MUST ignore BAR values different then specified in Virtio spec v1.1. - 4.1.4
// See Virtio specification v1.1. - 4.1.4.1
if bar.index <= 5 && bar.index == cap_raw.bar_index {
break *bar;
}
}
None => {
error!("Found virtio capability whose BAR is not mapped or non existing. Capability of type {:x} and id {:x} for device {:x}, can not be used!",
cap_raw.cfg_type, cap_raw.id, device_id);

continue 'cap_list;
}
}
};
if cap_raw.cfg_type == virtio_spec::pci::Cap::PciCfg.into() {
continue;
}

let cap_bar = bars
.iter()
.find(|bar| bar.index == cap_raw.bar_index)
.unwrap();

cap_list.push(PciCap {
cfg_type: virtio_spec::pci::Cap::from(cap_raw.cfg_type),
bar: cap_bar,
bar: *cap_bar,
id: cap_raw.id,
offset: MemOff::from(cap_raw.offset),
length: MemLen::from(cap_raw.length),
Expand Down

0 comments on commit a09a5a9

Please sign in to comment.