Unverified Commit b92a3a9b authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!1093 vfio-pci: Match specific devices with vendor id and device id

Merge Pull Request from: @did-you-collect-the-wool-today 
 
In probe_vendor_drivers, all registered vendor drivers are traversed.
This is not a good idea. If a vendor driver is not implemented well
enough, it may cause the system to panic. Use the vendor id and
device id to select a proper driver.
The acc live migration driver needs to be adapted. 
 
Link:https://gitee.com/openeuler/kernel/pulls/1093

 

Reviewed-by: default avatarZenghui Yu <yuzenghui@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parents 55026287 75fbddc8
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1739,6 +1739,8 @@ static void acc_vf_remove(void *vendor_data)
static struct vfio_pci_vendor_driver_ops  sec_vf_mig_ops = {
	.owner		= THIS_MODULE,
	.name		= "hisi_sec2",
	.vendor		= PCI_VENDOR_ID_HUAWEI,
	.device		= PCI_DEVICE_ID_HUAWEI_SEC_VF,
	.probe		= acc_vf_probe,
	.remove		= acc_vf_remove,
	.device_ops	= &acc_vf_device_ops_node,
@@ -1747,6 +1749,8 @@ static struct vfio_pci_vendor_driver_ops sec_vf_mig_ops = {
static struct vfio_pci_vendor_driver_ops  hpre_vf_mig_ops = {
	.owner		= THIS_MODULE,
	.name		= "hisi_hpre",
	.vendor		= PCI_VENDOR_ID_HUAWEI,
	.device		= PCI_DEVICE_ID_HUAWEI_HPRE_VF,
	.probe		= acc_vf_probe,
	.remove		= acc_vf_remove,
	.device_ops	= &acc_vf_device_ops_node,
@@ -1755,6 +1759,8 @@ static struct vfio_pci_vendor_driver_ops hpre_vf_mig_ops = {
static struct vfio_pci_vendor_driver_ops  zip_vf_mig_ops = {
	.owner		= THIS_MODULE,
	.name		= "hisi_zip",
	.vendor		= PCI_VENDOR_ID_HUAWEI,
	.device		= PCI_DEVICE_ID_HUAWEI_ZIP_VF,
	.probe		= acc_vf_probe,
	.remove		= acc_vf_remove,
	.device_ops	= &acc_vf_device_ops_node,
+4 −0
Original line number Diff line number Diff line
@@ -2077,6 +2077,10 @@ static int probe_vendor_drivers(struct vfio_pci_device *vdev)
	list_for_each_entry(driver, &vfio_pci.vendor_drivers_list, next) {
		void *data;

		if (vdev->pdev->vendor != driver->ops->vendor ||
		    vdev->pdev->device != driver->ops->device)
			continue;

		if (!try_module_get(driver->ops->owner))
			continue;

+3 −0
Original line number Diff line number Diff line
@@ -253,6 +253,9 @@ extern int vfio_pci_set_vendor_regions(void *device_data,
struct vfio_pci_vendor_driver_ops {
	char			*name;
	struct module		*owner;
	/* Used to match device */
	unsigned short		vendor;
	unsigned short		device;
	void			*(*probe)(struct pci_dev *pdev);
	void			(*remove)(void *vendor_data);
	struct vfio_device_ops *device_ops;