From 49ef201cd186954b044c289f6cd175c566bfd673 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Thu, 1 Aug 2019 21:39:19 -0700 Subject: [PATCH] vfio: pci: Provide the right MSI-X table offset When reading from or writing to the MSI-X table, the function provided by the PCI crate expects the offset to start from the beginning of the table. That's why it is VFIO specific code to be responsible for providing the right offset, which means it needs to be the offset substracted by the beginning of the MSI-X table offset. This bug was not discovered until we tested VFIO with some device where the MSI-X table was placed on a BAR at an offset different from 0x0. Signed-off-by: Sebastien Boeuf --- vfio/src/vfio_pci.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vfio/src/vfio_pci.rs b/vfio/src/vfio_pci.rs index c9e50d551..a7610c783 100644 --- a/vfio/src/vfio_pci.rs +++ b/vfio/src/vfio_pci.rs @@ -207,12 +207,14 @@ impl Interrupt { fn msix_write_table(&mut self, offset: u64, data: &[u8]) { if let Some(ref mut msix) = &mut self.msix { + let offset = offset - u64::from(msix.cap.table_offset()); msix.bar.write_table(offset, data) } } fn msix_read_table(&self, offset: u64, data: &mut [u8]) { if let Some(msix) = &self.msix { + let offset = offset - u64::from(msix.cap.table_offset()); msix.bar.read_table(offset, data) } }