virtio-devices: Respect PCI CFG cap.length for BAR access - #8272
Conversation
The VIRTIO_PCI_CAP_PCI_CFG indirect access mechanism was ignoring the cap.length field written by the guest driver. PCI config register reads always produce a 4 byte buffer, so when a driver set cap.length to 1 for a byte wide access to device_status at common config offset 0x14, the VMM passed all 4 bytes to read_bar, dispatching to the dword handler which does not cover that offset. Use cap.length to determine the actual BAR access width per virtio spec 4.1.4.9.1. Also replace the unsafe transmute with the safe Le32::to_native() conversion. Signed-off-by: Anatol Belski <[email protected]>
Verify that bar_access_params clamps the access length to cap.length when the PCI config read buffer is larger. Signed-off-by: Anatol Belski <[email protected]>
Verify that bar_access_params uses data_len when it is smaller than cap.length. Signed-off-by: Anatol Belski <[email protected]>
aa6b0ec to
7048e9e
Compare
|
I think this might be causing failures on the vfio test suite - can you take a look? |
|
Looks like it is working this time - might just have been a flake but please investigate to see if it's possibly related. |
Sure, I'm gonna run |
It turns out the vfio test image is private, thus instead I went looking at the CI logs. From there, on the VMM side device activation and BAR reprogramming take place with no anomaly, like I'd therefore lean towards flake for now. Thanks |
The VIRTIO_PCI_CAP_PCI_CFG indirect access mechanism was ignoring the cap.length field written by the guest driver. PCI config register reads always produce a 4 byte buffer, so when a driver set cap.length to 1 for a byte wide access to device_status at common config offset 0x14, the VMM passed all 4 bytes to read_bar, dispatching to the dword handler which does not cover that offset.
Use cap.length to determine the actual BAR access width per virtio spec 4.1.4.9.1. Also replace the unsafe transmute with the safe Le32::to_native() conversion.