aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/pci.c
diff options
context:
space:
mode:
authorAllen Kay <allen.m.kay@intel.com>2009-10-07 13:27:17 -0400
committerJesse Barnes <jbarnes@virtuousgeek.org>2009-11-04 11:47:25 -0500
commitae21ee65e8bc228416bbcc8a1da01c56a847a60c (patch)
treecbcd109c764a8fed06f18a0a4bd3d63208405552 /drivers/pci/pci.c
parent1ccbf5344c3daef046d2323190cc6807c44f1917 (diff)
PCI: acs p2p upsteram forwarding enabling
Note: dom0 checking in v4 has been separated out into 2/2. This patch enables P2P upstream forwarding in ACS capable PCIe switches. It solves two potential problems in virtualization environment where a PCIe device is assigned to a guest domain using a HW iommu such as VT-d: 1) Unintentional failure caused by guest physical address programmed into the device's DMA that happens to match the memory address range of other downstream ports in the same PCIe switch. This causes the PCI transaction to go to the matching downstream port instead of go to the root complex to get translated by VT-d as it should be. 2) Malicious guest software intentionally attacks another downstream PCIe device by programming the DMA address into the assigned device that matches memory address range of the downstream PCIe port. We are in process of implementing device filtering software in KVM/XEN management software to allow device assignment of PCIe devices behind a PCIe switch only if it has ACS capability and with the P2P upstream forwarding bits enabled. This patch is intended to work for both KVM and Xen environments. Signed-off-by: Allen Kay <allen.m.kay@intel.com> Reviewed-by: Mathew Wilcox <willy@linux.intel.com> Reviewed-by: Chris Wright <chris@sous-sol.org> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r--drivers/pci/pci.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 4859669f0ab5..557218222826 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1546,6 +1546,41 @@ void pci_enable_ari(struct pci_dev *dev)
1546} 1546}
1547 1547
1548/** 1548/**
1549 * pci_enable_acs - enable ACS if hardware support it
1550 * @dev: the PCI device
1551 */
1552void pci_enable_acs(struct pci_dev *dev)
1553{
1554 int pos;
1555 u16 cap;
1556 u16 ctrl;
1557
1558 if (!dev->is_pcie)
1559 return;
1560
1561 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
1562 if (!pos)
1563 return;
1564
1565 pci_read_config_word(dev, pos + PCI_ACS_CAP, &cap);
1566 pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl);
1567
1568 /* Source Validation */
1569 ctrl |= (cap & PCI_ACS_SV);
1570
1571 /* P2P Request Redirect */
1572 ctrl |= (cap & PCI_ACS_RR);
1573
1574 /* P2P Completion Redirect */
1575 ctrl |= (cap & PCI_ACS_CR);
1576
1577 /* Upstream Forwarding */
1578 ctrl |= (cap & PCI_ACS_UF);
1579
1580 pci_write_config_word(dev, pos + PCI_ACS_CTRL, ctrl);
1581}
1582
1583/**
1549 * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge 1584 * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge
1550 * @dev: the PCI device 1585 * @dev: the PCI device
1551 * @pin: the INTx pin (1=INTA, 2=INTB, 3=INTD, 4=INTD) 1586 * @pin: the INTx pin (1=INTA, 2=INTB, 3=INTD, 4=INTD)