aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMohammed Hawari <mohammed@hawari.fr>2020-10-21 16:41:30 +0200
committerMohammed HAWARI <momohawari@gmail.com>2020-10-28 16:27:23 +0000
commit7ed6a731ad352d2cbd610481eed8f1ed5e2997c4 (patch)
treecee4f525cc93cfa780ba5bc026ac4cdcd58447d4 /src
parent11166453a54511b1396faed46abb946a0d2eb393 (diff)
pci: set PCI memory enable before mapping PCI BAR
This change mitigates software faults issued by some versions of the linux kernel vfio-pci driver when VF PCI BARs are used without setting the memory enable bit in the PCI configuration. This problem is mentionned in https://lkml.org/lkml/2020/6/25/628 Change-Id: Idc177be4a5adb6ee467b4dd8f055f133ff267fe1 Type: improvement Signed-off-by: Mohammed Hawari <mohammed@hawari.fr> (cherry picked from commit 70fc36f26855fb4c7a56c5d1563d541b395f8f5d)
Diffstat (limited to 'src')
-rw-r--r--src/vlib/linux/pci.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/vlib/linux/pci.c b/src/vlib/linux/pci.c
index 168acde7288..996c312b170 100644
--- a/src/vlib/linux/pci.c
+++ b/src/vlib/linux/pci.c
@@ -1123,9 +1123,21 @@ vlib_pci_map_region_int (vlib_main_t * vm, vlib_pci_dev_handle_t h,
clib_error_t *error;
int flags = MAP_SHARED;
u64 size = 0, offset = 0;
+ u16 command;
pci_log_debug (vm, p, "map region %u to va %p", bar, addr);
+ if ((error = vlib_pci_read_config_u16 (vm, h, 4, &command)))
+ return error;
+
+ if (!(command & PCI_COMMAND_MEMORY))
+ {
+ pci_log_debug (vm, p, "setting memory enable bit");
+ command |= PCI_COMMAND_MEMORY;
+ if ((error = vlib_pci_write_config_u16 (vm, h, 4, &command)))
+ return error;
+ }
+
if ((error = vlib_pci_region (vm, h, bar, &fd, &size, &offset)))
return error;