iommu/vt-d: Try info->iommu in device_to_iommu()
Subsystems (2)
PATCH 1/1 iommu/vt-d: Try info->iommu in device_to_iommu()
Local boot test and VFIO sanity test show that info->iommu can be used in device_to_iommu() as a fast path. So this patch adds it.
--- drivers/iommu/intel/iommu.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/iommu/intel/iommu.c +5 -0
@@ -777,6 +777,7 @@ static bool iommu_is_dummy(struct intel_iommu *iommu, struct device *dev)struct intel_iommu *device_to_iommu (struct device *dev,u8 *bus,u8 *devfn) {struct dmar_drhd_unit *drhd =NULL ; +struct device_domain_info *info;struct pci_dev *pdev =NULL ;struct intel_iommu *iommu;struct device *tmp;
@@ -786,6 +787,10 @@ struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn)if (!dev)return NULL ; + info =dev_iommu_priv_get (dev); +if (info) +return info->iommu; +if (dev_is_pci (dev)) {struct pci_dev *pf_pdev;
Signature · 6 lines
2.17.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Baolu Lu
maintainerQuoted 21 lines · Nicolin Chen
Local boot test and VFIO sanity test show that
info->iommucan be used indevice_to_iommu()as a fast path. So this patch adds it.Signed-off-by Nicolin Chen <[email protected]>--- drivers/iommu/intel/iommu.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/iommu/intel/iommu.c +1
-0@@ -777,6 +777,7 @@ static bool iommu_is_dummy(struct intel_iommu *iommu, struct device *dev)struct intel_iommu *device_to_iommu (struct device *dev,u8 *bus,u8 *devfn) {struct dmar_drhd_unit *drhd =NULL ; +struct device_domain_info *info;struct pci_dev *pdev =NULL ;struct intel_iommu *iommu;struct device *tmp;
drivers/iommu/intel/iommu.c struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn) · line 792
Quoted 6 lines
drivers/iommu/intel/iommu.c +3
-0@@ -786,6 +787,10 @@ struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn)if (!dev)return NULL ; + info =dev_iommu_priv_get (dev); +if (info) +return info->iommu;
device_to_iommu() also returns device source id (@bus, @devfn).
Perhaps, we can make device_to_iommu() only for probe_device() where the per-device info data is not initialized yet. After probe_device(), iommu and sid are retrieved through other helpers by looking up the device info directly?
Best regards,
baolu
drivers/iommu/intel/iommu.c struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn) · line 796
Quoted 4 lines
drivers/iommu/intel/iommu.c +1
-0+if (dev_is_pci (dev)) {struct pci_dev *pf_pdev;
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 34 lines · Baolu Lu
External email: Use caution opening links or attachments
Quoted 21 lines · Nicolin Chen
Local boot test and VFIO sanity test show that
info->iommucan be used indevice_to_iommu()as a fast path. So this patch adds it.Signed-off-by Nicolin Chen <[email protected]>--- drivers/iommu/intel/iommu.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/iommu/intel/iommu.c +1
-0@@ -777,6 +777,7 @@ static bool iommu_is_dummy(struct intel_iommu *iommu, struct device *dev)struct intel_iommu *device_to_iommu (struct device *dev,u8 *bus,u8 *devfn) {struct dmar_drhd_unit *drhd =NULL ; +struct device_domain_info *info;struct pci_dev *pdev =NULL ;struct intel_iommu *iommu;struct device *tmp;drivers/iommu/intel/iommu.c struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn) · line 792
Quoted 6 lines
drivers/iommu/intel/iommu.c +3
-0@@ -786,6 +787,10 @@ struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn)if (!dev)return NULL ; + info =dev_iommu_priv_get (dev); +if (info) +return info->iommu;
device_to_iommu()also returns device source id (@bus, @devfn).
Quoted 4 lines
Perhaps, we can make
device_to_iommu()only forprobe_device()where the per-device info data is not initialized yet. Afterprobe_device(), iommu and sid are retrieved through other helpers by looking up the device info directly?
That should work I think. I was just not sure when the priv could be unset. But it seems that you have cleaned up those places other than probe/release_device() in recent version :)
Nic
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 19 lines · Baolu Lu
Quoted 18 lines · Nicolin Chen
Local boot test and VFIO sanity test show that
info->iommucan be used indevice_to_iommu()as a fast path. So this patch adds it.Signed-off-by Nicolin Chen <[email protected]>drivers/iommu/intel/iommu.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/iommu/intel/iommu.c +2
-0+++ b/drivers/iommu/intel/iommu.c@@ -777,6 +777,7 @@ static bool iommu_is_dummy(struct intel_iommu *iommu, struct device *dev)struct intel_iommu *device_to_iommu (struct device *dev,u8 *bus,u8 *devfn) {struct dmar_drhd_unit *drhd =NULL ; +struct device_domain_info *info;struct pci_dev *pdev =NULL ;struct intel_iommu *iommu;struct device *tmp;
Quoted 8 lines
drivers/iommu/intel/iommu.c struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn) · line 791
Quoted 6 lines
drivers/iommu/intel/iommu.c +3
-0@@ -786,6 +787,10 @@ struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn)if (!dev)return NULL ; + info =dev_iommu_priv_get (dev); +if (info) +return info->iommu;
device_to_iommu()also returns device source id (@bus, @devfn).
Those are in the info too..
Quoted 4 lines
Perhaps, we can make
device_to_iommu()only forprobe_device()where the per-device info data is not initialized yet. Afterprobe_device(), iommu and sid are retrieved through other helpers by looking up the device info directly?
This design makes the most sense to me... Nicolin you said there was a case where attach was happening before probe though??
Jasno
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 7 lines · Jason Gunthorpe
Quoted 4 lines
Perhaps, we can make
device_to_iommu()only forprobe_device()where the per-device info data is not initialized yet. Afterprobe_device(), iommu and sid are retrieved through other helpers by looking up the device info directly?This design makes the most sense to me... Nicolin you said there was a case where attach was happening before probe though??
I was testing on top of our IOMMUFD dev branch actually, which is still on 5.17 where priv/info seems to be set at the end of first ->attach_dev() call. In 5.18, Baolu has already cleaned away some code. So now, just eyeballing here, it should be set at driver's ->probe_device() call, so it'd be safe to get info in attach_dev (and in the new op that we are adding).
I am also rebasing our dev branch to more recent version btw.
Thanks
Nic
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu