Skip to content

Commit 131f796

Browse files
sumitsemwalgregkh
authored andcommitted
PCI: Don't update VF BARs while VF memory space is enabled
From: Bjorn Helgaas <bhelgaas@google.com> [ Upstream commit 546ba9f8f22f71b0202b6ba8967be5cc6dae4e21 ] If we update a VF BAR while it's enabled, there are two potential problems: 1) Any driver that's using the VF has a cached BAR value that is stale after the update, and 2) We can't update 64-bit BARs atomically, so the intermediate state (new lower dword with old upper dword) may conflict with another device, and an access by a driver unrelated to the VF may cause a bus error. Warn about attempts to update VF BARs while they are enabled. This is a programming error, so use dev_WARN() to get a backtrace. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 40a85d6 commit 131f796

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

drivers/pci/iov.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno)
567567
struct resource *res = dev->resource + resno;
568568
int vf_bar = resno - PCI_IOV_RESOURCES;
569569
struct pci_bus_region region;
570+
u16 cmd;
570571
u32 new;
571572
int reg;
572573

@@ -578,6 +579,13 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno)
578579
if (!iov)
579580
return;
580581

582+
pci_read_config_word(dev, iov->pos + PCI_SRIOV_CTRL, &cmd);
583+
if ((cmd & PCI_SRIOV_CTRL_VFE) && (cmd & PCI_SRIOV_CTRL_MSE)) {
584+
dev_WARN(&dev->dev, "can't update enabled VF BAR%d %pR\n",
585+
vf_bar, res);
586+
return;
587+
}
588+
581589
/*
582590
* Ignore unimplemented BARs, unused resource slots for 64-bit
583591
* BARs, and non-movable resources, e.g., those described via

0 commit comments

Comments
 (0)