Skip to content

Commit 8ee3af1

Browse files
committed
fix(pci): fix handling of VirtIO PCI capabilities
The VirtioPciCap type had the wrong structure. This wasn't a problem, because the wrong field was actually operating as part of the padding of which it was taking away the space. Also, fix the initialization of the VirtioPciCfgCap so that it reports the correct length for the capability. Signed-off-by: Babis Chalios <[email protected]>
1 parent 6323d07 commit 8ee3af1

File tree

1 file changed

+10
-2
lines changed
  • src/vmm/src/devices/virtio/transport/pci

1 file changed

+10
-2
lines changed

src/vmm/src/devices/virtio/transport/pci/device.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct VirtioPciCap {
7979
cap_len: u8, // Generic PCI field: capability length
8080
cfg_type: u8, // Identifies the structure.
8181
pci_bar: u8, // Where to find it.
82-
id: u8, // Multiple capabilities of the same type
82+
id: u8, // Multiple capabilities of the same type.
8383
padding: [u8; 2], // Pad to full dword.
8484
offset: Le32, // Offset within bar.
8585
length: Le32, // Length of the structure, in bytes.
@@ -174,7 +174,15 @@ impl PciCapability for VirtioPciCfgCap {
174174
impl VirtioPciCfgCap {
175175
fn new() -> Self {
176176
VirtioPciCfgCap {
177-
cap: VirtioPciCap::new(PciCapabilityType::Pci, 0, 0),
177+
cap: VirtioPciCap {
178+
cap_len: u8::try_from(size_of::<Self>()).unwrap() + VIRTIO_PCI_CAP_LEN_OFFSET,
179+
cfg_type: PciCapabilityType::Pci as u8,
180+
pci_bar: VIRTIO_BAR_INDEX,
181+
id: 0,
182+
padding: [0; 2],
183+
offset: Le32::from(0),
184+
length: Le32::from(0),
185+
},
178186
..Default::default()
179187
}
180188
}

0 commit comments

Comments
 (0)