Enable SR-IOV instantiation through /sys file
Subsystems (3)
PATCH v2 1/1 Enable SR-IOV instantiation through /sys file
From: Liang-Min Wang <[email protected]>
When a SR-IOV capable device is bound with vfio-pci, the device loses capability of creating SR-IOV instances through /sy/bus/ pci/devices/.../sriov_numvfs. This patch re-activates this capability for a PCIe device that is SR-IOV capable and is bound with vfio-pci.ko. This patch also disables drivers_autoprobe attribute of SR-IOV devices created from vfio-pci bound device by default, so user-space PF device can coordinate the bring-up of SR-IOV devices
--- drivers/pci/pci-driver.c | 12 ++++++++++++ drivers/vfio/pci/vfio_pci.c | 22 ++++++++++++++++++++++ include/linux/pci.h | 1 + 3 files changed, 35 insertions(+)
drivers/pci/pci-driver.c +12 -0
@@ -1467,6 +1467,18 @@ void pci_dev_put(struct pci_dev *dev) }EXPORT_SYMBOL (pci_dev_put); +/** +* pci_dev_sriov_autoprobe_set - set device sriov driver autoprobe +* @dev: device with which sriov autoprobe will be set +* +*/ +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool autoprobe) +{ +if (dev && dev->sriov) + dev->sriov->drivers_autoprobe = autoprobe; +} +EXPORT_SYMBOL (pci_dev_sriov_autoprobe_set); +static int pci_uevent (struct device *dev,struct kobj_uevent_env *env) {struct pci_dev *pdev;
drivers/vfio/pci/vfio_pci.c +22 -0
@@ -1213,6 +1213,8 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)return -ENOMEM ; } +/* disable sriov automatic driver attachment */ +pci_dev_sriov_autoprobe_set (pdev, false); vdev->pdev = pdev; vdev->irq_type =VFIO_PCI_NUM_IRQS ;mutex_init (&vdev->igate);
@@ -1256,6 +1258,7 @@ static void vfio_pci_remove(struct pci_dev *pdev)if (!vdev)return ; +pci_disable_sriov (pdev);vfio_iommu_group_put (pdev->dev.iommu_group, &pdev->dev);kfree (vdev->region);kfree (vdev);
@@ -1303,12 +1306,31 @@ static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, .error_detected = vfio_pci_aer_err_detected, }; +static int vfio_sriov_configure (struct pci_dev *pdev,int num_vfs) +{ +int status; + +if (!num_vfs) { +pci_disable_sriov (pdev); +return 0 ; + } + + status =pci_enable_sriov (pdev, num_vfs); +if (!status) { +pr_crit ("Created %d SR-IOV from a user-space driver based upon vfio-pci\n" , num_vfs); +add_taint (TAINT_USER ,LOCKDEP_STILL_OK ); + } + +return status; +} +static struct pci_driver vfio_pci_driver = { .name ="vfio-pci" , .id_table =NULL ,/* only dynamic ids */ .probe = vfio_pci_probe, .remove = vfio_pci_remove, .err_handler = &vfio_err_handlers, + .sriov_configure = vfio_sriov_configure, };struct vfio_devices {
include/linux/pci.h +1 -0
@@ -921,6 +921,7 @@ struct resource *pci_find_parent_resource(const struct pci_dev *dev,struct pci_dev *pci_dev_get (struct pci_dev *dev);void pci_dev_put (struct pci_dev *dev);void pci_remove_bus (struct pci_bus *b); +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool autoprobe);void pci_stop_and_remove_bus_device (struct pci_dev *dev);void pci_stop_and_remove_bus_device_locked (struct pci_dev *dev);void pci_stop_root_bus (struct pci_bus *bus);
Signature · 1 line
1.9.1
Quoted 26 lines · On Fri, 8 Dec 2017 13:47:58 -0800 Jeff Kirsher <[email protected]>…
From: Liang-Min Wang <[email protected]>
When a SR-IOV capable device is bound with vfio-pci, the device loses capability of creating SR-IOV instances through /sy/bus/ pci/devices/.../sriov_numvfs. This patch re-activates this capability for a PCIe device that is SR-IOV capable and is bound with vfio-pci.ko. This patch also disables
drivers_autoprobeattribute of SR-IOV devices created from vfio-pci bound device by default, so user-space PF device can coordinate the bring-up of SR-IOV devicesSigned-off-by Liang-Min Wang <[email protected]>--- drivers/pci/pci-driver.c | 12 ++++++++++++ drivers/vfio/pci/vfio_pci.c | 22 ++++++++++++++++++++++ include/linux/pci.h | 1 + 3 files changed, 35 insertions(+)drivers/pci/pci-driver.c +1
-0@@ -1467,6 +1467,18 @@ void pci_dev_put(struct pci_dev *dev) }EXPORT_SYMBOL (pci_dev_put); +/**
drivers/pci/pci-driver.c void pci_dev_put(struct pci_dev *dev) · line 1480
Quoted 10 lines
drivers/pci/pci-driver.c +10
-0+* pci_dev_sriov_autoprobe_set - set device sriov driver autoprobe +* @dev: device with which sriov autoprobe will be set +* +*/ +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool autoprobe) +{ +if (dev && dev->sriov) + dev->sriov->drivers_autoprobe = autoprobe; +} +EXPORT_SYMBOL (pci_dev_sriov_autoprobe_set);
_GPL?
It'd also be best to separate the pci and vfio changes into different patches. Bjorn would need to at least ack this PCI interface.
Quoted 9 lines
drivers/pci/pci-driver.c +1
-0+static int pci_uevent (struct device *dev,struct kobj_uevent_env *env) {struct pci_dev *pdev;drivers/vfio/pci/vfio_pci.c +0
-0
drivers/vfio/pci/vfio_pci.c static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 1217
Quoted 5 lines
drivers/vfio/pci/vfio_pci.c +2
-0@@ -1213,6 +1213,8 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)return -ENOMEM ; } +/* disable sriov automatic driver attachment */ +pci_dev_sriov_autoprobe_set (pdev, false);
This looks stateful, VF autoprobe is not restored on release. Also, how would we know the initial state to restore it to?
Quoted 19 lines
drivers/vfio/pci/vfio_pci.c +5
-0vdev->pdev = pdev; vdev->irq_type =VFIO_PCI_NUM_IRQS ;mutex_init (&vdev->igate);@@ -1256,6 +1258,7 @@ static void vfio_pci_remove(struct pci_dev *pdev)if (!vdev)return ; +pci_disable_sriov (pdev);vfio_iommu_group_put (pdev->dev.iommu_group, &pdev->dev);kfree (vdev->region);kfree (vdev);@@ -1303,12 +1306,31 @@ static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, .error_detected = vfio_pci_aer_err_detected, }; +static int vfio_sriov_configure (struct pci_dev *pdev,int num_vfs) +{ +int status; +
drivers/vfio/pci/vfio_pci.c static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, · line 1322
Quoted 10 lines
drivers/vfio/pci/vfio_pci.c +10
-0+if (!num_vfs) { +pci_disable_sriov (pdev); +return 0 ; + } + + status =pci_enable_sriov (pdev, num_vfs); +if (!status) { +pr_crit ("Created %d SR-IOV from a user-space driver based upon vfio-pci\n" , num_vfs); +add_taint (TAINT_USER ,LOCKDEP_STILL_OK ); + }
This probably deserves more explanation, in comment and commit log. Probably a dev_crit() is also justified, knowing the PF would be useful. Thanks,
Alex
Quoted 26 lines
drivers/vfio/pci/vfio_pci.c +5
-0+ +return status; +} +static struct pci_driver vfio_pci_driver = { .name ="vfio-pci" , .id_table =NULL ,/* only dynamic ids */ .probe = vfio_pci_probe, .remove = vfio_pci_remove, .err_handler = &vfio_err_handlers, + .sriov_configure = vfio_sriov_configure, };struct vfio_devices {include/linux/pci.h +1
-0@@ -921,6 +921,7 @@ struct resource *pci_find_parent_resource(const struct pci_dev *dev,struct pci_dev *pci_dev_get (struct pci_dev *dev);void pci_dev_put (struct pci_dev *dev);void pci_remove_bus (struct pci_bus *b); +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool autoprobe);void pci_stop_and_remove_bus_device (struct pci_dev *dev);void pci_stop_and_remove_bus_device_locked (struct pci_dev *dev);void pci_stop_root_bus (struct pci_bus *bus);
Quoted 57 lines · Alex Williamson
Quoted 26 lines · On Fri, 8 Dec 2017 13:47:58 -0800 Jeff Kirsher <[email protected]>…
From: Liang-Min Wang <[email protected]>
When a SR-IOV capable device is bound with vfio-pci, the device loses capability of creating SR-IOV instances through /sy/bus/ pci/devices/.../sriov_numvfs. This patch re-activates this capability for a PCIe device that is SR-IOV capable and is bound with vfio-pci.ko. This patch also disables
drivers_autoprobeattribute of SR-IOV devices created from vfio-pci bound device by default, so user-space PF device can coordinate the bring-up of SR-IOV devicesSigned-off-by Liang-Min Wang <[email protected]>--- drivers/pci/pci-driver.c | 12 ++++++++++++ drivers/vfio/pci/vfio_pci.c | 22 ++++++++++++++++++++++ include/linux/pci.h | 1 + 3 files changed, 35 insertions(+)drivers/pci/pci-driver.c +1
-0@@ -1467,6 +1467,18 @@ void pci_dev_put(struct pci_dev *dev) }EXPORT_SYMBOL (pci_dev_put); +/** drivers/pci/pci-driver.c void pci_dev_put(struct pci_dev *dev) · line 1480
Quoted 10 lines
drivers/pci/pci-driver.c +10
-0+* pci_dev_sriov_autoprobe_set - set device sriov driver autoprobe +* @dev: device with which sriov autoprobe will be set +* +*/ +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool autoprobe) +{ +if (dev && dev->sriov) + dev->sriov->drivers_autoprobe = autoprobe; +} +EXPORT_SYMBOL (pci_dev_sriov_autoprobe_set);
_GPL?It'd also be best to separate the pci and vfio changes into different patches. Bjorn would need to at least ack this PCI interface.
Quoted 12 lines
drivers/pci/pci-driver.c +1
-0+static int pci_uevent (struct device *dev,struct kobj_uevent_env *env) {struct pci_dev *pdev;drivers/vfio/pci/vfio_pci.c +0
-0@@ -1213,6 +1213,8 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)return -ENOMEM ; }
Quoted 5 lines
drivers/vfio/pci/vfio_pci.c static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 1217
Quoted 2 lines
drivers/vfio/pci/vfio_pci.c +2
-0+/* disable sriov automatic driver attachment */ +pci_dev_sriov_autoprobe_set (pdev, false);This looks stateful, VF autoprobe is not restored on release. Also, how would we know the initial state to restore it to?
The initial state is whatever the user set it to. It is something that can be toggled on and off via sysfs, and it defaults to true at initialization. In this case we are opting to toggle it off when VFIO is attached to the device. Restoring it after unloading the driver might be even more confusing since it is something the user could toggle at any time so a restore would end up overwriting that.
Quoted 63 lines
Quoted 19 lines
drivers/vfio/pci/vfio_pci.c +5
-0vdev->pdev = pdev; vdev->irq_type =VFIO_PCI_NUM_IRQS ;mutex_init (&vdev->igate);@@ -1256,6 +1258,7 @@ static void vfio_pci_remove(struct pci_dev *pdev)if (!vdev)return ; +pci_disable_sriov (pdev);vfio_iommu_group_put (pdev->dev.iommu_group, &pdev->dev);kfree (vdev->region);kfree (vdev);@@ -1303,12 +1306,31 @@ static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, .error_detected = vfio_pci_aer_err_detected, }; +static int vfio_sriov_configure (struct pci_dev *pdev,int num_vfs) +{ +int status; +drivers/vfio/pci/vfio_pci.c static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, · line 1322
Quoted 10 lines
drivers/vfio/pci/vfio_pci.c +10
-0+if (!num_vfs) { +pci_disable_sriov (pdev); +return 0 ; + } + + status =pci_enable_sriov (pdev, num_vfs); +if (!status) { +pr_crit ("Created %d SR-IOV from a user-space driver based upon vfio-pci\n" , num_vfs); +add_taint (TAINT_USER ,LOCKDEP_STILL_OK ); + }This probably deserves more explanation, in comment and commit log. Probably a
dev_crit()is also justified, knowing the PF would be useful. Thanks,Alex
Quoted 26 lines
drivers/vfio/pci/vfio_pci.c +5
-0+ +return status; +} +static struct pci_driver vfio_pci_driver = { .name ="vfio-pci" , .id_table =NULL ,/* only dynamic ids */ .probe = vfio_pci_probe, .remove = vfio_pci_remove, .err_handler = &vfio_err_handlers, + .sriov_configure = vfio_sriov_configure, };struct vfio_devices {include/linux/pci.h +1
-0@@ -921,6 +921,7 @@ struct resource *pci_find_parent_resource(const struct pci_dev *dev,struct pci_dev *pci_dev_get (struct pci_dev *dev);void pci_dev_put (struct pci_dev *dev);void pci_remove_bus (struct pci_bus *b); +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool autoprobe);void pci_stop_and_remove_bus_device (struct pci_dev *dev);void pci_stop_and_remove_bus_device_locked (struct pci_dev *dev);void pci_stop_root_bus (struct pci_bus *bus);
Quoted 65 lines · On Fri, 8 Dec 2017 15:19:18 -0800 Alexander Duyck <[email protected]>…
Quoted 57 lines · Alex Williamson
Quoted 26 lines · On Fri, 8 Dec 2017 13:47:58 -0800 Jeff Kirsher <[email protected]>…
From: Liang-Min Wang <[email protected]>
When a SR-IOV capable device is bound with vfio-pci, the device loses capability of creating SR-IOV instances through /sy/bus/ pci/devices/.../sriov_numvfs. This patch re-activates this capability for a PCIe device that is SR-IOV capable and is bound with vfio-pci.ko. This patch also disables
drivers_autoprobeattribute of SR-IOV devices created from vfio-pci bound device by default, so user-space PF device can coordinate the bring-up of SR-IOV devicesSigned-off-by Liang-Min Wang <[email protected]>--- drivers/pci/pci-driver.c | 12 ++++++++++++ drivers/vfio/pci/vfio_pci.c | 22 ++++++++++++++++++++++ include/linux/pci.h | 1 + 3 files changed, 35 insertions(+)drivers/pci/pci-driver.c +1
-0@@ -1467,6 +1467,18 @@ void pci_dev_put(struct pci_dev *dev) }EXPORT_SYMBOL (pci_dev_put); +/** drivers/pci/pci-driver.c void pci_dev_put(struct pci_dev *dev) · line 1480
Quoted 10 lines
drivers/pci/pci-driver.c +10
-0+* pci_dev_sriov_autoprobe_set - set device sriov driver autoprobe +* @dev: device with which sriov autoprobe will be set +* +*/ +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool autoprobe) +{ +if (dev && dev->sriov) + dev->sriov->drivers_autoprobe = autoprobe; +} +EXPORT_SYMBOL (pci_dev_sriov_autoprobe_set);
_GPL?It'd also be best to separate the pci and vfio changes into different patches. Bjorn would need to at least ack this PCI interface.
Quoted 12 lines
drivers/pci/pci-driver.c +1
-0+static int pci_uevent (struct device *dev,struct kobj_uevent_env *env) {struct pci_dev *pdev;drivers/vfio/pci/vfio_pci.c +0
-0@@ -1213,6 +1213,8 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)return -ENOMEM ; }Quoted 5 lines
drivers/vfio/pci/vfio_pci.c static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 1217
Quoted 2 lines
drivers/vfio/pci/vfio_pci.c +2
-0+/* disable sriov automatic driver attachment */ +pci_dev_sriov_autoprobe_set (pdev, false);This looks stateful, VF autoprobe is not restored on release. Also, how would we know the initial state to restore it to?
Quoted 6 lines
The initial state is whatever the user set it to. It is something that can be toggled on and off via sysfs, and it defaults to true at initialization. In this case we are opting to toggle it off when VFIO is attached to the device. Restoring it after unloading the driver might be even more confusing since it is something the user could toggle at any time so a restore would end up overwriting that.
I'm not really willing to sign up for the inevitable bug reports when users can't figure out how to make their VFs work again in the host after they've used the PF for userspace drivers with vfio-pci. I agree, both options are confusing, how do we make it not confusing? Can PCI core reset the autoprobe attribute to the default at some obvious point? Thanks,
Alex
Quoted 88 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Friday, December 08, 2017 6:35 PM
To: Alexander Duyck <[email protected]>
Cc: Kirsher, Jeffrey T <[email protected]>; Wang, Liang-min <liang- [email protected]>; [email protected]; [email protected]; linux- [email protected]; Bjorn Helgaas <[email protected]>; Duyck, Alexander H <[email protected]>
Subject: Re: [PATCH v2] Enable SR-IOV instantiation through /sys fileQuoted 47 lines · On Fri, 8 Dec 2017 15:19:18 -0800 Alexander Duyck <[email protected]>…
Quoted 45 lines · Alex Williamson
Quoted 26 lines · On Fri, 8 Dec 2017 13:47:58 -0800 Jeff Kirsher <[email protected]>…
From: Liang-Min Wang <[email protected]>
When a SR-IOV capable device is bound with vfio-pci, the device loses capability of creating SR-IOV instances through /sy/bus/ pci/devices/.../sriov_numvfs. This patch re-activates this capability for a PCIe device that is SR-IOV capable and is bound with vfio-pci.ko. This patch also disables
drivers_autoprobeattribute of SR-IOV devices created from vfio-pci bound device by default, so user-space PF device can coordinate the bring-up of SR-IOV devicesSigned-off-by Liang-Min Wang <[email protected]>--- drivers/pci/pci-driver.c | 12 ++++++++++++ drivers/vfio/pci/vfio_pci.c | 22 ++++++++++++++++++++++ include/linux/pci.h | 1 + 3 files changed, 35 insertions(+)drivers/pci/pci-driver.c +1
-0@@ -1467,6 +1467,18 @@ void pci_dev_put(struct pci_dev *dev) }EXPORT_SYMBOL (pci_dev_put); +/** drivers/pci/pci-driver.c void pci_dev_put(struct pci_dev *dev) · line 1480
Quoted 10 lines
drivers/pci/pci-driver.c +10
-0+* pci_dev_sriov_autoprobe_set - set device sriov driver autoprobe +* @dev: device with which sriov autoprobe will be set +* +*/ +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool autoprobe) +{ +if (dev && dev->sriov) + dev->sriov->drivers_autoprobe = autoprobe; +} +EXPORT_SYMBOL (pci_dev_sriov_autoprobe_set);
_GPL?It'd also be best to separate the pci and vfio changes into different patches. Bjorn would need to at least ack this PCI interface.
Quoted 9 lines
Quoted 9 lines
drivers/vfio/pci/vfio_pci.c static int vfio_pci_probe(struct pci_dev *pdev,
Quoted 9 lines
drivers/pci/pci-driver.c +1
-0+static int pci_uevent (struct device *dev,struct kobj_uevent_env *env) {struct pci_dev *pdev;drivers/vfio/pci/vfio_pci.c +0
-0@@ -1213,6 +1213,8 @@ static int vfio_pci_probe(struct pci_dev *pdev,const struct
pci_device_id*id)Quoted 9 lines
Quoted 8 lines
drivers/vfio/pci/vfio_pci.c static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 1217
Quoted 5 lines
drivers/vfio/pci/vfio_pci.c +2
-0return -ENOMEM ; } +/* disable sriov automatic driver attachment */ +pci_dev_sriov_autoprobe_set (pdev, false);This looks stateful, VF autoprobe is not restored on release. Also, how would we know the initial state to restore it to?
Quoted 6 lines
The initial state is whatever the user set it to. It is something that can be toggled on and off via sysfs, and it defaults to true at initialization. In this case we are opting to toggle it off when VFIO is attached to the device. Restoring it after unloading the driver might be even more confusing since it is something the user could toggle at any time so a restore would end up overwriting that.
Quoted 7 lines
I'm not really willing to sign up for the inevitable bug reports when users can't figure out how to make their VFs work again in the host after they've used the PF for userspace drivers with vfio-pci. I agree, both options are confusing, how do we make it not confusing? Can PCI core reset the autoprobe attribute to the default at some obvious point? Thanks,
I would like to confirm the scenario discussed here is to unload PF driver, right? Since users need to release all SR-IOV from PF driver first before PF driver is released, does it make sense to restore autoprobe when VFs are released?
Quoted 1 line
Alex
We could do that. It shouldn't be an issue as long as we disable SR-IOV first.
It would just be a matter of recording the state of kernel_pf_autoprobe vs user_pf_autoprobe. It might be useful to make that distinction in the comments somewhere in the code and in the patch description.
- Alex
Quoted 114 lines
-----Original Message-----
From: Wang, Liang-min
Sent: Monday, December 11, 2017 6:23 AM
To: Alex Williamson <[email protected]>; Alexander Duyck <[email protected]>
Cc: Kirsher, Jeffrey T <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Bjorn Helgaas <[email protected]>; Duyck, Alexander H <[email protected]>
Subject: RE: [PATCH v2] Enable SR-IOV instantiation through /sys fileQuoted 11 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Friday, December 08, 2017 6:35 PM
To: Alexander Duyck <[email protected]>
Cc: Kirsher, Jeffrey T <[email protected]>; Wang, Liang-min <liang- [email protected]>; [email protected]; [email protected]; linux- [email protected]; Bjorn Helgaas <[email protected]>; Duyck, Alexander H <[email protected]>
Subject: Re: [PATCH v2] Enable SR-IOV instantiation through /sys fileQuoted 14 lines
Quoted 11 lines · On Fri, 8 Dec 2017 15:19:18 -0800 Alexander Duyck <[email protected]>…
Quoted 9 lines · Alex Williamson
Quoted 6 lines · On Fri, 8 Dec 2017 13:47:58 -0800 Jeff Kirsher <[email protected]>…
From: Liang-Min Wang <[email protected]>
When a SR-IOV capable device is bound with vfio-pci, the device loses capability of creating SR-IOV instances through /sy/bus/ pci/devices/.../sriov_numvfs. This patch re-activates this capability for a PCIe device that is SR-IOV capable and is bound with vfio-
pci.ko.
Quoted 63 lines
Quoted 36 lines
Quoted 36 lines
Quoted 20 lines
This patch also disables
drivers_autoprobeattribute of SR-IOV devices created from vfio-pci bound device by default, so user-space PF device can coordinate the bring-up of SR-IOV devicesSigned-off-by Liang-Min Wang <[email protected]>--- drivers/pci/pci-driver.c | 12 ++++++++++++ drivers/vfio/pci/vfio_pci.c | 22 ++++++++++++++++++++++ include/linux/pci.h | 1 + 3 files changed, 35 insertions(+)drivers/pci/pci-driver.c +1
-0@@ -1467,6 +1467,18 @@ void pci_dev_put(struct pci_dev *dev) }EXPORT_SYMBOL (pci_dev_put); +/** drivers/pci/pci-driver.c void pci_dev_put(struct pci_dev *dev) } · line 1479
Quoted 10 lines
drivers/pci/pci-driver.c +10
-0+* pci_dev_sriov_autoprobe_set - set device sriov driver +autoprobe +* @dev: device with which sriov autoprobe will be set +* +*/ +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool +autoprobe) { +if (dev && dev->sriov) + dev->sriov->drivers_autoprobe = autoprobe; } +EXPORT_SYMBOL (pci_dev_sriov_autoprobe_set);
_GPL?It'd also be best to separate the pci and vfio changes into different patches. Bjorn would need to at least ack this PCI interface.
Quoted 10 lines
Quoted 10 lines
drivers/vfio/pci/vfio_pci.c static int vfio_pci_probe(struct pci_dev · line 1213
Quoted 10 lines
drivers/pci/pci-driver.c +1
-0+static int pci_uevent (struct device *dev,struct kobj_uevent_env *env) {struct pci_dev *pdev;(quoted diff) +0
-0
b/drivers/vfio/pci/vfio_pci.cindex f041b1a..004836c 100644drivers/vfio/pci/vfio_pci.c +0
-0@@ -1213,6 +1213,8 @@ static int vfio_pci_probe(struct pci_dev *pdev,const struct
pci_device_id*id)Quoted 9 lines
Quoted 8 lines
drivers/vfio/pci/vfio_pci.c static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 1217
Quoted 5 lines
drivers/vfio/pci/vfio_pci.c +2
-0return -ENOMEM ; } +/* disable sriov automatic driver attachment */ +pci_dev_sriov_autoprobe_set (pdev, false);This looks stateful, VF autoprobe is not restored on release. Also, how would we know the initial state to restore it to?
Quoted 6 lines
The initial state is whatever the user set it to. It is something that can be toggled on and off via sysfs, and it defaults to true at initialization. In this case we are opting to toggle it off when VFIO is attached to the device. Restoring it after unloading the driver might be even more confusing since it is something the user could toggle at any time so a restore would end up overwriting that.
Quoted 7 lines
I'm not really willing to sign up for the inevitable bug reports when users can't figure out how to make their VFs work again in the host after they've used the PF for userspace drivers with vfio-pci. I agree, both options are confusing, how do we make it not confusing? Can PCI core reset the autoprobe attribute to the default at some obvious point? Thanks,
I would like to confirm the scenario discussed here is to unload PF driver, right? Since users need to release all SR-IOV from PF driver first before PF driver is released, does it make sense to restore autoprobe when VFs are released?
Quoted 1 line
Alex
Quoted 94 lines · Liang-min
Quoted 86 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Friday, December 08, 2017 6:35 PM
To: Alexander Duyck <[email protected]>
Cc: Kirsher, Jeffrey T <[email protected]>; Wang, Liang-min <liang- [email protected]>; [email protected]; [email protected]; linux- [email protected]; Bjorn Helgaas <[email protected]>; Duyck, Alexander H <[email protected]>
Subject: Re: [PATCH v2] Enable SR-IOV instantiation through /sys fileQuoted 47 lines · On Fri, 8 Dec 2017 15:19:18 -0800 Alexander Duyck <[email protected]>…
Quoted 45 lines · Alex Williamson
Quoted 26 lines · On Fri, 8 Dec 2017 13:47:58 -0800 Jeff Kirsher <[email protected]>…
From: Liang-Min Wang <[email protected]>
When a SR-IOV capable device is bound with vfio-pci, the device loses capability of creating SR-IOV instances through /sy/bus/ pci/devices/.../sriov_numvfs. This patch re-activates this capability for a PCIe device that is SR-IOV capable and is bound with vfio-pci.ko. This patch also disables
drivers_autoprobeattribute of SR-IOV devices created from vfio-pci bound device by default, so user-space PF device can coordinate the bring-up of SR-IOV devicesSigned-off-by Liang-Min Wang <[email protected]>--- drivers/pci/pci-driver.c | 12 ++++++++++++ drivers/vfio/pci/vfio_pci.c | 22 ++++++++++++++++++++++ include/linux/pci.h | 1 + 3 files changed, 35 insertions(+)drivers/pci/pci-driver.c +1
-0@@ -1467,6 +1467,18 @@ void pci_dev_put(struct pci_dev *dev) }EXPORT_SYMBOL (pci_dev_put); +/** drivers/pci/pci-driver.c void pci_dev_put(struct pci_dev *dev) · line 1480
Quoted 10 lines
drivers/pci/pci-driver.c +10
-0+* pci_dev_sriov_autoprobe_set - set device sriov driver autoprobe +* @dev: device with which sriov autoprobe will be set +* +*/ +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool autoprobe) +{ +if (dev && dev->sriov) + dev->sriov->drivers_autoprobe = autoprobe; +} +EXPORT_SYMBOL (pci_dev_sriov_autoprobe_set);
_GPL?It'd also be best to separate the pci and vfio changes into different patches. Bjorn would need to at least ack this PCI interface.
Quoted 9 lines
Quoted 9 lines
drivers/vfio/pci/vfio_pci.c static int vfio_pci_probe(struct pci_dev *pdev,
Quoted 9 lines
drivers/pci/pci-driver.c +1
-0+static int pci_uevent (struct device *dev,struct kobj_uevent_env *env) {struct pci_dev *pdev;drivers/vfio/pci/vfio_pci.c +0
-0@@ -1213,6 +1213,8 @@ static int vfio_pci_probe(struct pci_dev *pdev,const struct
pci_device_id*id)Quoted 9 lines
Quoted 8 lines
drivers/vfio/pci/vfio_pci.c static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 1217
Quoted 5 lines
drivers/vfio/pci/vfio_pci.c +2
-0return -ENOMEM ; } +/* disable sriov automatic driver attachment */ +pci_dev_sriov_autoprobe_set (pdev, false);This looks stateful, VF autoprobe is not restored on release. Also, how would we know the initial state to restore it to?
Quoted 6 lines
The initial state is whatever the user set it to. It is something that can be toggled on and off via sysfs, and it defaults to true at initialization. In this case we are opting to toggle it off when VFIO is attached to the device. Restoring it after unloading the driver might be even more confusing since it is something the user could toggle at any time so a restore would end up overwriting that.
Quoted 7 lines
I'm not really willing to sign up for the inevitable bug reports when users can't figure out how to make their VFs work again in the host after they've used the PF for userspace drivers with vfio-pci. I agree, both options are confusing, how do we make it not confusing? Can PCI core reset the autoprobe attribute to the default at some obvious point? Thanks,
Quoted 3 lines
I would like to confirm the scenario discussed here is to unload PF driver, right? Since users need to release all SR-IOV from PF driver first before PF driver is released, does it make sense to restore autoprobe when VFs are released?
We don't know that VFs will be created, but perhaps you mean the point at which SR-IOV would be disabled in the PF unbind process. Still, I think you're left with userspace and kernel-space both trying to use the same control bit and they're going to step on each other and create corner cases that are inconsistent. It's not necessarily even clear how using separate trackers solves it since the kernel isn't necessarily behaving in the way the user directed. Maybe the user interface to autoprobe needs to be locked out if the PF driver disables it.
Didn't we also discuss whether or not it's safe for vfio to enable SR-IOV while the PF is in use by a user? Does that all fall into the "Dr. it hurts when I do this..." category and contributes to tainting the kernel when enabled? Definitely worth some comment words to describe the various considerations contributing to kernel tainting. Thanks,
Alex
Quoted 118 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Monday, December 11, 2017 1:13 PM
To: Wang, Liang-min <[email protected]>
Cc: Alexander Duyck <[email protected]>; Kirsher, Jeffrey T <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Bjorn Helgaas <[email protected]>; Duyck, Alexander H <[email protected]>
Subject: Re: [PATCH v2] Enable SR-IOV instantiation through /sys fileQuoted 5 lines · Liang-min
Quoted 5 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Friday, December 08, 2017 6:35 PM
To: Alexander Duyck <[email protected]>
Cc: Kirsher, Jeffrey T <[email protected]>; Wang, Liang-min<liang-
Quoted 1 line
Quoted 1 line
linux-
Quoted 37 lines
Quoted 37 lines
[email protected]; Bjorn Helgaas <[email protected]>; Duyck, Alexander H <[email protected]>
Subject: Re: [PATCH v2] Enable SR-IOV instantiation through /sys fileQuoted 30 lines · On Fri, 8 Dec 2017 15:19:18 -0800 Alexander Duyck <[email protected]>…
Quoted 28 lines · Alex Williamson
Quoted 25 lines · On Fri, 8 Dec 2017 13:47:58 -0800 Jeff Kirsher <[email protected]>…
From: Liang-Min Wang <[email protected]>
When a SR-IOV capable device is bound with vfio-pci, the device loses capability of creating SR-IOV instances through /sy/bus/ pci/devices/.../sriov_numvfs. This patch re-activates this capability for a PCIe device that is SR-IOV capable and is bound with vfio-pci.ko. This patch also disables
drivers_autoprobeattribute of SR-IOV devices created from vfio-pci bound device by default, so user-space PF device can coordinate the bring-up of SR-IOV devicesSigned-off-by Liang-Min Wang <[email protected]>--- drivers/pci/pci-driver.c | 12 ++++++++++++ drivers/vfio/pci/vfio_pci.c | 22 ++++++++++++++++++++++ include/linux/pci.h | 1 + 3 files changed, 35 insertions(+)drivers/pci/pci-driver.c +0
-0@@ -1467,6 +1467,18 @@ void pci_dev_put(struct pci_dev *dev) }EXPORT_SYMBOL (pci_dev_put);Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/pci/pci-driver.c void pci_dev_put(struct pci_dev *dev)
Quoted 6 lines
drivers/pci/pci-driver.c +6
-0+/** +* pci_dev_sriov_autoprobe_set - set device sriov driver autoprobe +* @dev: device with which sriov autoprobe will be set +* +*/ +void pci_dev_sriov_autoprobe_set(struct pci_dev *dev, boolautoprobe)
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/pci/pci-driver.c void pci_dev_put(struct pci_dev *dev) · line 1480
Quoted 5 lines
drivers/pci/pci-driver.c +5
-0+{ +if (dev && dev->sriov) + dev->sriov->drivers_autoprobe = autoprobe; +} +EXPORT_SYMBOL (pci_dev_sriov_autoprobe_set);
_GPL?It'd also be best to separate the pci and vfio changes into different patches. Bjorn would need to at least ack this PCI interface.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/vfio/pci/vfio_pci.c static int vfio_pci_probe(struct pci_dev
Quoted 9 lines
drivers/pci/pci-driver.c +1
-0+static int pci_uevent (struct device *dev,struct kobj_uevent_env *env) {struct pci_dev *pdev;drivers/vfio/pci/vfio_pci.c +0
-0@@ -1213,6 +1213,8 @@ static int vfio_pci_probe(struct pci_dev*pdev,
Quoted 25 lines
Quoted 17 lines
const struct
pci_device_id*id)Quoted 9 lines
Quoted 8 lines
drivers/vfio/pci/vfio_pci.c static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 1217
Quoted 5 lines
drivers/vfio/pci/vfio_pci.c +2
-0return -ENOMEM ; } +/* disable sriov automatic driver attachment */ +pci_dev_sriov_autoprobe_set (pdev, false);This looks stateful, VF autoprobe is not restored on release. Also, how would we know the initial state to restore it to?
Quoted 6 lines
The initial state is whatever the user set it to. It is something that can be toggled on and off via sysfs, and it defaults to true at initialization. In this case we are opting to toggle it off when VFIO is attached to the device. Restoring it after unloading the driver might be even more confusing since it is something the user could toggle at any time so a restore would end up overwriting that.
Quoted 7 lines
I'm not really willing to sign up for the inevitable bug reports when users can't figure out how to make their VFs work again in the host after they've used the PF for userspace drivers with vfio-pci. I agree, both options are confusing, how do we make it not confusing? Can PCI core reset the autoprobe attribute to the default at some obvious point? Thanks,
Quoted 1 line
I would like to confirm the scenario discussed here is to unload PF driver,
right?
Quoted 2 lines
Since users need to release all SR-IOV from PF driver first before PF driver is released, does it make sense to restore autoprobe when VFs are released?
Quoted 9 lines
We don't know that VFs will be created, but perhaps you mean the point at which SR-IOV would be disabled in the PF unbind process. Still, I think you're left with userspace and kernel-space both trying to use the same control bit and they're going to step on each other and create corner cases that are inconsistent. It's not necessarily even clear how using separate trackers solves it since the kernel isn't necessarily behaving in the way the user directed. Maybe the user interface to autoprobe needs to be locked out if the PF driver disables it.
To ensure there is no overlap between user-space applications to modify autoprobe bit while kernel is changing its value. One approach is to move the overwrite and restore into vfio_sriov_configure like below:
static int vfio_sriov_configure(struct pci_dev *pdev, int num_vfs)
{
int status;
bool old_autoprobe;
if (!num_vfs) {
pci_disable_sriov(pdev);
return 0;
}
/*
To avoid newly created VF to be bound with driver when
user-space PF may not be ready, disable the SR-IOV
instance driver automatic attachment, and save the original
setting and restore the setting after SR-IOV are created.
*/
old_autoprobe = pci_dev_sriov_autoprobe_set(pdev, vdev->sriov_driver_autoprobe);
status = pci_enable_sriov(pdev, num_vfs);
if (!status) {
dev_crit("Created %d SR-IOV from a user-space driver based upon vfio-pci\n"
"These VFs are not bound with driver when they are created.\n"
"User needs to bring up user-space PF driver first,"
" then bind new VFs with respective driver to"
" ensure there is a PF driver to respond any VF request\n", num_vfs);
add_taint(TAINT_USER, LOCKDEP_STILL_OK);
}
pci_dev_sriov_autoprobe_set(pdev, old_autoprobe);Would that resolve the issue as described? If not, could there be an example to illustrate the scenario that was described.
Larry
Quoted 9 lines
Didn't we also discuss whether or not it's safe for vfio to enable SR-IOV while the PF is in use by a user? Does that all fall into the "Dr. it hurts when I do this..." category and contributes to tainting the kernel when enabled? Definitely worth some comment words to describe the various considerations contributing to kernel tainting. Thanks,
Alex
Quoted 9 lines · Jeff Kirsher
From: Liang-Min Wang <[email protected]>
When a SR-IOV capable device is bound with vfio-pci, the device loses capability of creating SR-IOV instances through /sy/bus/ pci/devices/.../sriov_numvfs. This patch re-activates this capability for a PCIe device that is SR-IOV capable and is bound with vfio-pci.ko. This patch also disables
drivers_autoprobeattribute of SR-IOV devices created from vfio-pci bound device by default, so user-space PF device can coordinate the bring-up of SR-IOV devices
Seems like the discussion here petered out without a real conclusion, so I'm going to drop this one for now and wait for another try.
Quoted 98 lines
Signed-off-by Liang-Min Wang <[email protected]>--- drivers/pci/pci-driver.c | 12 ++++++++++++ drivers/vfio/pci/vfio_pci.c | 22 ++++++++++++++++++++++ include/linux/pci.h | 1 + 3 files changed, 35 insertions(+)drivers/pci/pci-driver.c +12
-0@@ -1467,6 +1467,18 @@ void pci_dev_put(struct pci_dev *dev) }EXPORT_SYMBOL (pci_dev_put); +/** +* pci_dev_sriov_autoprobe_set - set device sriov driver autoprobe +* @dev: device with which sriov autoprobe will be set +* +*/ +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool autoprobe) +{ +if (dev && dev->sriov) + dev->sriov->drivers_autoprobe = autoprobe; +} +EXPORT_SYMBOL (pci_dev_sriov_autoprobe_set); +static int pci_uevent (struct device *dev,struct kobj_uevent_env *env) {struct pci_dev *pdev;drivers/vfio/pci/vfio_pci.c +22
-0@@ -1213,6 +1213,8 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)return -ENOMEM ; } +/* disable sriov automatic driver attachment */ +pci_dev_sriov_autoprobe_set (pdev, false); vdev->pdev = pdev; vdev->irq_type =VFIO_PCI_NUM_IRQS ;mutex_init (&vdev->igate);@@ -1256,6 +1258,7 @@ static void vfio_pci_remove(struct pci_dev *pdev)if (!vdev)return ; +pci_disable_sriov (pdev);vfio_iommu_group_put (pdev->dev.iommu_group, &pdev->dev);kfree (vdev->region);kfree (vdev);@@ -1303,12 +1306,31 @@ static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, .error_detected = vfio_pci_aer_err_detected, }; +static int vfio_sriov_configure (struct pci_dev *pdev,int num_vfs) +{ +int status; + +if (!num_vfs) { +pci_disable_sriov (pdev); +return 0 ; + } + + status =pci_enable_sriov (pdev, num_vfs); +if (!status) { +pr_crit ("Created %d SR-IOV from a user-space driver based upon vfio-pci\n" , num_vfs); +add_taint (TAINT_USER ,LOCKDEP_STILL_OK ); + } + +return status; +} +static struct pci_driver vfio_pci_driver = { .name ="vfio-pci" , .id_table =NULL ,/* only dynamic ids */ .probe = vfio_pci_probe, .remove = vfio_pci_remove, .err_handler = &vfio_err_handlers, + .sriov_configure = vfio_sriov_configure, };struct vfio_devices {include/linux/pci.h +1
-0@@ -921,6 +921,7 @@ struct resource *pci_find_parent_resource(const struct pci_dev *dev,struct pci_dev *pci_dev_get (struct pci_dev *dev);void pci_dev_put (struct pci_dev *dev);void pci_remove_bus (struct pci_bus *b); +void pci_dev_sriov_autoprobe_set (struct pci_dev *dev,bool autoprobe);void pci_stop_and_remove_bus_device (struct pci_dev *dev);void pci_stop_and_remove_bus_device_locked (struct pci_dev *dev);void pci_stop_root_bus (struct pci_bus *bus);Signature · 1 line
1.9.1