mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-15 00:34:10 +08:00
VFIO updates for v4.7-rc1
- Hide INTx on certain known broken devices (Alex Williamson) - Additional backdoor reset detection (Alex Williamson) - Remove unused iommudata reference (Alexey Kardashevskiy) - Use cfg_size to avoid probing extended config space (Alexey Kardashevskiy) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) iQIcBAABAgAGBQJXRc8hAAoJECObm247sIsigWAP/R+q+UnOHXd7cvSKpI33p2IP ur09xwV9GktQViWz4tclFdfk8cScq86UX8I5e/jkeFVCXT7e5FU7FhKqJi7dPbp1 Yh3g5fGUkk6a0B3gebIq3qY02aLwJF17WZg0R/KHkQT0B/yQuTQqdF37Xh9rGv0S c7sgQn1X5nmO7jVDYYKO3SwEgmZWAcBz4Ht2XpqCdSrmhsse9OxlnmOkieM5BNUz rQhnziaeJE/Ya+y/A74XicbGforyThvNyJs/anJnPEE89773SGVQy/Jdlz4Lwji7 XImPuj4AT9duTgX9HaD38xIpFOsAKDfZ6sClsICkIvhbs232UXuiMxcPszDA97c0 7MxSJcLVr9fKB6zatq2JWhGDp7C6ylUxapEI9PFCV6gE5OYZRM7KD+hm32oVnuPv rSzPoqnm0Sudu8SO6n46QUZAifp+mX9MNhqzkXGR/YlBHhB1L3/QcczyekY0eBbj vJ2htebrg0qNQn4G9n4ygMm19r53ew/Q+pO2y7y4TdOr+gZNW1Wj7uOezMpvDOOB hiy+HkJ24MCTfAGNgjpjjCot/o608+QT5H+y8SR7vT1IK4shOSE4rYfvo6jlzRQp 9FRTolGhYqrtih+zB5R7eLghtvlDp4lN0gDCSgWGHM7e2rMLxaomzoF1VNQ8eKJZ iUJZ8jE2QrdGDpKssRuF =fGnT -----END PGP SIGNATURE----- Merge tag 'vfio-v4.7-rc1' of git://github.com/awilliam/linux-vfio Pull VFIO updates from Alex Williamson: - Hide INTx on certain known broken devices (Alex Williamson) - Additional backdoor reset detection (Alex Williamson) - Remove unused iommudata reference (Alexey Kardashevskiy) - Use cfg_size to avoid probing extended config space (Alexey Kardashevskiy) * tag 'vfio-v4.7-rc1' of git://github.com/awilliam/linux-vfio: vfio_pci: Test for extended capabilities if config space > 256 bytes vfio_iommu_spapr_tce: Remove unneeded iommu_group_get_iommudata vfio/pci: Add test for BAR restore vfio/pci: Hide broken INTx support from user
This commit is contained in:
commit
48dd7cefa0
@ -113,6 +113,35 @@ static inline bool vfio_pci_is_vga(struct pci_dev *pdev)
|
||||
static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev);
|
||||
static void vfio_pci_disable(struct vfio_pci_device *vdev);
|
||||
|
||||
/*
|
||||
* INTx masking requires the ability to disable INTx signaling via PCI_COMMAND
|
||||
* _and_ the ability detect when the device is asserting INTx via PCI_STATUS.
|
||||
* If a device implements the former but not the latter we would typically
|
||||
* expect broken_intx_masking be set and require an exclusive interrupt.
|
||||
* However since we do have control of the device's ability to assert INTx,
|
||||
* we can instead pretend that the device does not implement INTx, virtualizing
|
||||
* the pin register to report zero and maintaining DisINTx set on the host.
|
||||
*/
|
||||
static bool vfio_pci_nointx(struct pci_dev *pdev)
|
||||
{
|
||||
switch (pdev->vendor) {
|
||||
case PCI_VENDOR_ID_INTEL:
|
||||
switch (pdev->device) {
|
||||
/* All i40e (XL710/X710) 10/20/40GbE NICs */
|
||||
case 0x1572:
|
||||
case 0x1574:
|
||||
case 0x1580 ... 0x1581:
|
||||
case 0x1583 ... 0x1589:
|
||||
case 0x37d0 ... 0x37d2:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int vfio_pci_enable(struct vfio_pci_device *vdev)
|
||||
{
|
||||
struct pci_dev *pdev = vdev->pdev;
|
||||
@ -136,6 +165,21 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev)
|
||||
pr_debug("%s: Couldn't store %s saved state\n",
|
||||
__func__, dev_name(&pdev->dev));
|
||||
|
||||
if (likely(!nointxmask)) {
|
||||
if (vfio_pci_nointx(pdev)) {
|
||||
dev_info(&pdev->dev, "Masking broken INTx support\n");
|
||||
vdev->nointx = true;
|
||||
pci_intx(pdev, 0);
|
||||
} else
|
||||
vdev->pci_2_3 = pci_intx_mask_supported(pdev);
|
||||
}
|
||||
|
||||
pci_read_config_word(pdev, PCI_COMMAND, &cmd);
|
||||
if (vdev->pci_2_3 && (cmd & PCI_COMMAND_INTX_DISABLE)) {
|
||||
cmd &= ~PCI_COMMAND_INTX_DISABLE;
|
||||
pci_write_config_word(pdev, PCI_COMMAND, cmd);
|
||||
}
|
||||
|
||||
ret = vfio_config_init(vdev);
|
||||
if (ret) {
|
||||
kfree(vdev->pci_saved_state);
|
||||
@ -144,15 +188,6 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (likely(!nointxmask))
|
||||
vdev->pci_2_3 = pci_intx_mask_supported(pdev);
|
||||
|
||||
pci_read_config_word(pdev, PCI_COMMAND, &cmd);
|
||||
if (vdev->pci_2_3 && (cmd & PCI_COMMAND_INTX_DISABLE)) {
|
||||
cmd &= ~PCI_COMMAND_INTX_DISABLE;
|
||||
pci_write_config_word(pdev, PCI_COMMAND, cmd);
|
||||
}
|
||||
|
||||
msix_pos = pdev->msix_cap;
|
||||
if (msix_pos) {
|
||||
u16 flags;
|
||||
@ -304,7 +339,7 @@ static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type)
|
||||
if (irq_type == VFIO_PCI_INTX_IRQ_INDEX) {
|
||||
u8 pin;
|
||||
pci_read_config_byte(vdev->pdev, PCI_INTERRUPT_PIN, &pin);
|
||||
if (IS_ENABLED(CONFIG_VFIO_PCI_INTX) && pin)
|
||||
if (IS_ENABLED(CONFIG_VFIO_PCI_INTX) && !vdev->nointx && pin)
|
||||
return 1;
|
||||
|
||||
} else if (irq_type == VFIO_PCI_MSI_IRQ_INDEX) {
|
||||
|
@ -408,6 +408,7 @@ static void vfio_bar_restore(struct vfio_pci_device *vdev)
|
||||
{
|
||||
struct pci_dev *pdev = vdev->pdev;
|
||||
u32 *rbar = vdev->rbar;
|
||||
u16 cmd;
|
||||
int i;
|
||||
|
||||
if (pdev->is_virtfn)
|
||||
@ -420,6 +421,12 @@ static void vfio_bar_restore(struct vfio_pci_device *vdev)
|
||||
pci_user_write_config_dword(pdev, i, *rbar);
|
||||
|
||||
pci_user_write_config_dword(pdev, PCI_ROM_ADDRESS, *rbar);
|
||||
|
||||
if (vdev->nointx) {
|
||||
pci_user_read_config_word(pdev, PCI_COMMAND, &cmd);
|
||||
cmd |= PCI_COMMAND_INTX_DISABLE;
|
||||
pci_user_write_config_word(pdev, PCI_COMMAND, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
static __le32 vfio_generate_bar_flags(struct pci_dev *pdev, int bar)
|
||||
@ -515,6 +522,23 @@ static int vfio_basic_config_read(struct vfio_pci_device *vdev, int pos,
|
||||
return count;
|
||||
}
|
||||
|
||||
/* Test whether BARs match the value we think they should contain */
|
||||
static bool vfio_need_bar_restore(struct vfio_pci_device *vdev)
|
||||
{
|
||||
int i = 0, pos = PCI_BASE_ADDRESS_0, ret;
|
||||
u32 bar;
|
||||
|
||||
for (; pos <= PCI_BASE_ADDRESS_5; i++, pos += 4) {
|
||||
if (vdev->rbar[i]) {
|
||||
ret = pci_user_read_config_dword(vdev->pdev, pos, &bar);
|
||||
if (ret || vdev->rbar[i] != bar)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int vfio_basic_config_write(struct vfio_pci_device *vdev, int pos,
|
||||
int count, struct perm_bits *perm,
|
||||
int offset, __le32 val)
|
||||
@ -553,7 +577,8 @@ static int vfio_basic_config_write(struct vfio_pci_device *vdev, int pos,
|
||||
* SR-IOV devices will trigger this, but we catch them later
|
||||
*/
|
||||
if ((new_mem && virt_mem && !phys_mem) ||
|
||||
(new_io && virt_io && !phys_io))
|
||||
(new_io && virt_io && !phys_io) ||
|
||||
vfio_need_bar_restore(vdev))
|
||||
vfio_bar_restore(vdev);
|
||||
}
|
||||
|
||||
@ -1124,9 +1149,12 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
|
||||
return pcibios_err_to_errno(ret);
|
||||
|
||||
if (PCI_X_CMD_VERSION(word)) {
|
||||
/* Test for extended capabilities */
|
||||
pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
|
||||
vdev->extended_caps = (dword != 0);
|
||||
if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
|
||||
/* Test for extended capabilities */
|
||||
pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE,
|
||||
&dword);
|
||||
vdev->extended_caps = (dword != 0);
|
||||
}
|
||||
return PCI_CAP_PCIX_SIZEOF_V2;
|
||||
} else
|
||||
return PCI_CAP_PCIX_SIZEOF_V0;
|
||||
@ -1138,9 +1166,11 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
|
||||
|
||||
return byte;
|
||||
case PCI_CAP_ID_EXP:
|
||||
/* Test for extended capabilities */
|
||||
pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
|
||||
vdev->extended_caps = (dword != 0);
|
||||
if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
|
||||
/* Test for extended capabilities */
|
||||
pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
|
||||
vdev->extended_caps = (dword != 0);
|
||||
}
|
||||
|
||||
/* length based on version */
|
||||
if ((pcie_caps_reg(pdev) & PCI_EXP_FLAGS_VERS) == 1)
|
||||
@ -1545,7 +1575,7 @@ int vfio_config_init(struct vfio_pci_device *vdev)
|
||||
*(__le16 *)&vconfig[PCI_DEVICE_ID] = cpu_to_le16(pdev->device);
|
||||
}
|
||||
|
||||
if (!IS_ENABLED(CONFIG_VFIO_PCI_INTX))
|
||||
if (!IS_ENABLED(CONFIG_VFIO_PCI_INTX) || vdev->nointx)
|
||||
vconfig[PCI_INTERRUPT_PIN] = 0;
|
||||
|
||||
ret = vfio_cap_init(vdev);
|
||||
|
@ -83,6 +83,7 @@ struct vfio_pci_device {
|
||||
bool bardirty;
|
||||
bool has_vga;
|
||||
bool needs_reset;
|
||||
bool nointx;
|
||||
struct pci_saved_state *pci_saved_state;
|
||||
int refcnt;
|
||||
struct eventfd_ctx *err_trigger;
|
||||
|
@ -331,14 +331,12 @@ static void tce_iommu_free_table(struct iommu_table *tbl);
|
||||
static void tce_iommu_release(void *iommu_data)
|
||||
{
|
||||
struct tce_container *container = iommu_data;
|
||||
struct iommu_table_group *table_group;
|
||||
struct tce_iommu_group *tcegrp;
|
||||
long i;
|
||||
|
||||
while (tce_groups_attached(container)) {
|
||||
tcegrp = list_first_entry(&container->group_list,
|
||||
struct tce_iommu_group, next);
|
||||
table_group = iommu_group_get_iommudata(tcegrp->grp);
|
||||
tce_iommu_detach_group(iommu_data, tcegrp->grp);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user