Skip to content

Commit 407bc8d

Browse files
committed
Merge tag 'vfio-v5.9-rc1' of git://github.com/awilliam/linux-vfio
Pull VFIO updates from Alex Williamson: - Inclusive naming updates (Alex Williamson) - Intel X550 INTx quirk (Alex Williamson) - Error path resched between unmaps (Xiang Zheng) - SPAPR IOMMU pin_user_pages() conversion (John Hubbard) - Trivial mutex simplification (Alex Williamson) - QAT device denylist (Giovanni Cabiddu) - type1 IOMMU ioctl refactor (Liu Yi L) * tag 'vfio-v5.9-rc1' of git://github.com/awilliam/linux-vfio: vfio/type1: Refactor vfio_iommu_type1_ioctl() vfio/pci: Add QAT devices to denylist vfio/pci: Add device denylist PCI: Add Intel QuickAssist device IDs vfio/pci: Hold igate across releasing eventfd contexts vfio/spapr_tce: convert get_user_pages() --> pin_user_pages() vfio/type1: Add conditional rescheduling after iommu map failed vfio/pci: Add Intel X550 to hidden INTx devices vfio: Cleanup allowed driver naming
2 parents ea6ec77 + ccd59dc commit 407bc8d

File tree

5 files changed

+282
-193
lines changed

5 files changed

+282
-193
lines changed

drivers/vfio/pci/vfio_pci.c

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ module_param(enable_sriov, bool, 0644);
6060
MODULE_PARM_DESC(enable_sriov, "Enable support for SR-IOV configuration. Enabling SR-IOV on a PF typically requires support of the userspace PF driver, enabling VFs without such support may result in non-functional VFs or PF.");
6161
#endif
6262

63+
static bool disable_denylist;
64+
module_param(disable_denylist, bool, 0444);
65+
MODULE_PARM_DESC(disable_denylist, "Disable use of device denylist. Disabling the denylist allows binding to devices with known errata that may lead to exploitable stability or security issues when accessed by untrusted users.");
66+
6367
static inline bool vfio_vga_disabled(void)
6468
{
6569
#ifdef CONFIG_VFIO_PCI_VGA
@@ -69,6 +73,44 @@ static inline bool vfio_vga_disabled(void)
6973
#endif
7074
}
7175

76+
static bool vfio_pci_dev_in_denylist(struct pci_dev *pdev)
77+
{
78+
switch (pdev->vendor) {
79+
case PCI_VENDOR_ID_INTEL:
80+
switch (pdev->device) {
81+
case PCI_DEVICE_ID_INTEL_QAT_C3XXX:
82+
case PCI_DEVICE_ID_INTEL_QAT_C3XXX_VF:
83+
case PCI_DEVICE_ID_INTEL_QAT_C62X:
84+
case PCI_DEVICE_ID_INTEL_QAT_C62X_VF:
85+
case PCI_DEVICE_ID_INTEL_QAT_DH895XCC:
86+
case PCI_DEVICE_ID_INTEL_QAT_DH895XCC_VF:
87+
return true;
88+
default:
89+
return false;
90+
}
91+
}
92+
93+
return false;
94+
}
95+
96+
static bool vfio_pci_is_denylisted(struct pci_dev *pdev)
97+
{
98+
if (!vfio_pci_dev_in_denylist(pdev))
99+
return false;
100+
101+
if (disable_denylist) {
102+
pci_warn(pdev,
103+
"device denylist disabled - allowing device %04x:%04x.\n",
104+
pdev->vendor, pdev->device);
105+
return false;
106+
}
107+
108+
pci_warn(pdev, "%04x:%04x exists in vfio-pci device denylist, driver probing disallowed.\n",
109+
pdev->vendor, pdev->device);
110+
111+
return true;
112+
}
113+
72114
/*
73115
* Our VGA arbiter participation is limited since we don't know anything
74116
* about the device itself. However, if the device is the only VGA device
@@ -207,6 +249,8 @@ static bool vfio_pci_nointx(struct pci_dev *pdev)
207249
case 0x1580 ... 0x1581:
208250
case 0x1583 ... 0x158b:
209251
case 0x37d0 ... 0x37d2:
252+
/* X550 */
253+
case 0x1563:
210254
return true;
211255
default:
212256
return false;
@@ -521,14 +565,12 @@ static void vfio_pci_release(void *device_data)
521565
vfio_pci_vf_token_user_add(vdev, -1);
522566
vfio_spapr_pci_eeh_release(vdev->pdev);
523567
vfio_pci_disable(vdev);
568+
524569
mutex_lock(&vdev->igate);
525570
if (vdev->err_trigger) {
526571
eventfd_ctx_put(vdev->err_trigger);
527572
vdev->err_trigger = NULL;
528573
}
529-
mutex_unlock(&vdev->igate);
530-
531-
mutex_lock(&vdev->igate);
532574
if (vdev->req_trigger) {
533575
eventfd_ctx_put(vdev->req_trigger);
534576
vdev->req_trigger = NULL;
@@ -1856,6 +1898,9 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
18561898
struct iommu_group *group;
18571899
int ret;
18581900

1901+
if (vfio_pci_is_denylisted(pdev))
1902+
return -EINVAL;
1903+
18591904
if (pdev->hdr_type != PCI_HEADER_TYPE_NORMAL)
18601905
return -EINVAL;
18611906

@@ -2345,6 +2390,9 @@ static int __init vfio_pci_init(void)
23452390

23462391
vfio_pci_fill_ids();
23472392

2393+
if (disable_denylist)
2394+
pr_warn("device denylist disabled.\n");
2395+
23482396
return 0;
23492397

23502398
out_driver:

drivers/vfio/vfio.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,10 @@ static struct vfio_device *vfio_group_get_device(struct vfio_group *group,
627627
* that error notification via MSI can be affected for platforms that handle
628628
* MSI within the same IOVA space as DMA.
629629
*/
630-
static const char * const vfio_driver_whitelist[] = { "pci-stub" };
630+
static const char * const vfio_driver_allowed[] = { "pci-stub" };
631631

632-
static bool vfio_dev_whitelisted(struct device *dev, struct device_driver *drv)
632+
static bool vfio_dev_driver_allowed(struct device *dev,
633+
struct device_driver *drv)
633634
{
634635
if (dev_is_pci(dev)) {
635636
struct pci_dev *pdev = to_pci_dev(dev);
@@ -638,8 +639,8 @@ static bool vfio_dev_whitelisted(struct device *dev, struct device_driver *drv)
638639
return true;
639640
}
640641

641-
return match_string(vfio_driver_whitelist,
642-
ARRAY_SIZE(vfio_driver_whitelist),
642+
return match_string(vfio_driver_allowed,
643+
ARRAY_SIZE(vfio_driver_allowed),
643644
drv->name) >= 0;
644645
}
645646

@@ -648,7 +649,7 @@ static bool vfio_dev_whitelisted(struct device *dev, struct device_driver *drv)
648649
* one of the following states:
649650
* - driver-less
650651
* - bound to a vfio driver
651-
* - bound to a whitelisted driver
652+
* - bound to an otherwise allowed driver
652653
* - a PCI interconnect device
653654
*
654655
* We use two methods to determine whether a device is bound to a vfio
@@ -674,7 +675,7 @@ static int vfio_dev_viable(struct device *dev, void *data)
674675
}
675676
mutex_unlock(&group->unbound_lock);
676677

677-
if (!ret || !drv || vfio_dev_whitelisted(dev, drv))
678+
if (!ret || !drv || vfio_dev_driver_allowed(dev, drv))
678679
return 0;
679680

680681
device = vfio_group_get_device(group, dev);

drivers/vfio/vfio_iommu_spapr_tce.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static void tce_iommu_unuse_page(struct tce_container *container,
383383
struct page *page;
384384

385385
page = pfn_to_page(hpa >> PAGE_SHIFT);
386-
put_page(page);
386+
unpin_user_page(page);
387387
}
388388

389389
static int tce_iommu_prereg_ua_to_hpa(struct tce_container *container,
@@ -486,7 +486,7 @@ static int tce_iommu_use_page(unsigned long tce, unsigned long *hpa)
486486
struct page *page = NULL;
487487
enum dma_data_direction direction = iommu_tce_direction(tce);
488488

489-
if (get_user_pages_fast(tce & PAGE_MASK, 1,
489+
if (pin_user_pages_fast(tce & PAGE_MASK, 1,
490490
direction != DMA_TO_DEVICE ? FOLL_WRITE : 0,
491491
&page) != 1)
492492
return -EFAULT;

0 commit comments

Comments
 (0)