iommu/arm-smmu-v3: Enable PCI ATS in passthrough mode as well
Subsystems (3)
PATCH 1/1 iommu/arm-smmu-v3: Enable PCI ATS in passthrough mode as well
The current smmu-v3 driver does not enable PCI ATS for physical functions of ATS capable End Points when booted in smmu bypass mode (iommu.passthrough=1). This will not allow virtual functions to enable ATS(even though EP supports it) while they are attached to a VM using VFIO driver.
This patch adds changes to enable ATS support for physical functions in passthrough/bypass mode as well.
Also, adding check to avoid disabling of ATS if it is not enabled, to avoid unnecessary call-traces.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +7 -3
@@ -2313,11 +2313,16 @@ static void arm_smmu_enable_ats(struct arm_smmu_master *master)static void arm_smmu_disable_ats (struct arm_smmu_master *master) {struct arm_smmu_domain *smmu_domain = master->domain; +struct pci_dev *pdev;if (!master->ats_enabled)return ; -pci_disable_ats (to_pci_dev (master->dev)); + pdev =to_pci_dev (master->dev); + +if (pdev->ats_enabled) +pci_disable_ats (pdev); +/* * Ensure ATS is disabled at the endpoint before we issue the * ATC invalidation via the SMMU.
@@ -2453,8 +2458,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = smmu_domain; -if (smmu_domain->stage !=ARM_SMMU_DOMAIN_BYPASS ) - master->ats_enabled =arm_smmu_ats_supported (master); + master->ats_enabled =arm_smmu_ats_supported (master);arm_smmu_install_ste_for_dev (master);
Signature · 1 line
2.37.3
Robin Murphy
reviewerQuoted 24 lines · Ganapatrao Kulkarni
The current smmu-v3 driver does not enable PCI ATS for physical functions of ATS capable End Points when booted in smmu bypass mode (iommu.passthrough=1). This will not allow virtual functions to enable ATS(even though EP supports it) while they are attached to a VM using VFIO driver.
This patch adds changes to enable ATS support for physical functions in passthrough/bypass mode as well.
Also, adding check to avoid disabling of ATS if it is not enabled, to avoid unnecessary call-traces.
Signed-off-by Ganapatrao Kulkarni <[email protected]>--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +0
-0@@ -2313,11 +2313,16 @@ static void arm_smmu_enable_ats(struct arm_smmu_master *master)static void arm_smmu_disable_ats (struct arm_smmu_master *master) {
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static void arm_smmu_enable_ats(struct arm_smmu_master *master) · line 2323
Quoted 10 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +4
-1struct arm_smmu_domain *smmu_domain = master->domain; +struct pci_dev *pdev;if (!master->ats_enabled)return ; -pci_disable_ats (to_pci_dev (master->dev)); + pdev =to_pci_dev (master->dev); + +if (pdev->ats_enabled)
If the master->ats_enabled check above passes when ATS isn't actually enabled, surely that's a bug?
Robin.
Quoted 15 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +3
-2+pci_disable_ats (pdev); +/* * Ensure ATS is disabled at the endpoint before we issue the * ATC invalidation via the SMMU. @@ -2453,8 +2458,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = smmu_domain; -if (smmu_domain->stage !=ARM_SMMU_DOMAIN_BYPASS ) - master->ats_enabled =arm_smmu_ats_supported (master); + master->ats_enabled =arm_smmu_ats_supported (master);arm_smmu_install_ste_for_dev (master);
Quoted 28 lines · Robin Murphy
Quoted 27 lines · Ganapatrao Kulkarni
The current smmu-v3 driver does not enable PCI ATS for physical functions of ATS capable End Points when booted in smmu bypass mode (iommu.passthrough=1). This will not allow virtual functions to enable ATS(even though EP supports it) while they are attached to a VM using VFIO driver.
This patch adds changes to enable ATS support for physical functions in passthrough/bypass mode as well.
Also, adding check to avoid disabling of ATS if it is not enabled, to avoid unnecessary call-traces.
Signed-off-by Ganapatrao Kulkarni <[email protected]>---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c| 10 +++++++---1 file changed, 7 insertions(+), 3 deletions(-)drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1
-0@@ -2313,11 +2313,16 @@ static void arm_smmu_enable_ats(struct arm_smmu_master *master) static void arm_smmu_disable_ats(struct arm_smmu_master *master) { struct arm_smmu_domain *smmu_domain = master->domain; + struct pci_dev *pdev;
Quoted 8 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static void arm_smmu_enable_ats(struct arm_smmu_master *master) · line 2323
Quoted 6 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +3
-1if (!master->ats_enabled) return; - pci_disable_ats(to_pci_dev(master->dev)); + pdev = to_pci_dev(master->dev); + + if (pdev->ats_enabled)If the
master->ats_enabledcheck above passes when ATS isn't actually enabled, surely that's a bug?
IIUC, It means ATS feature is supported (just check for existence of ATS extended capability and smmu capability) and not necessarily enabled. Function pci_enable_ats(called by arm_smmu_enable_ats) enables the ATS by setting bit 15 of ATS Control Register (Offset 06h).
If pci_enable_ats is not successful, it will not set dev->ats_enabled flag. So calling pci_disable_ats later results in call-trace, if dev->ats_enabled is not set.
Function arm_smmu_enable_ats already prints error message if ATS enable is failed.
Quoted 15 lines
Robin.
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static int arm_smmu_attach_dev(struct · line 2461
Quoted 12 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +3
-2+ pci_disable_ats(pdev); + /** Ensure ATS is disabled at the endpoint before we issue the * ATC invalidation via the SMMU. @@ -2453,8 +2458,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = smmu_domain; - if (smmu_domain->stage != ARM_SMMU_DOMAIN_BYPASS) - master->ats_enabled = arm_smmu_ats_supported(master); + master->ats_enabled = arm_smmu_ats_supported(master); arm_smmu_install_ste_for_dev(master);
Thanks,
Ganapat
Robin Murphy
reviewerQuoted 40 lines · Ganapatrao Kulkarni
Quoted 28 lines · Robin Murphy
Quoted 27 lines · Ganapatrao Kulkarni
The current smmu-v3 driver does not enable PCI ATS for physical functions of ATS capable End Points when booted in smmu bypass mode (iommu.passthrough=1). This will not allow virtual functions to enable ATS(even though EP supports it) while they are attached to a VM using VFIO driver.
This patch adds changes to enable ATS support for physical functions in passthrough/bypass mode as well.
Also, adding check to avoid disabling of ATS if it is not enabled, to avoid unnecessary call-traces.
Signed-off-by Ganapatrao Kulkarni <[email protected]>---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c| 10 +++++++---1 file changed, 7 insertions(+), 3 deletions(-)drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1
-0@@ -2313,11 +2313,16 @@ static void arm_smmu_enable_ats(struct arm_smmu_master *master) static void arm_smmu_disable_ats(struct arm_smmu_master *master) { struct arm_smmu_domain *smmu_domain = master->domain; + struct pci_dev *pdev;Quoted 8 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static void arm_smmu_enable_ats(struct arm_smmu_master *master) · line 2323
Quoted 6 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +3
-1if (!master->ats_enabled) return; - pci_disable_ats(to_pci_dev(master->dev)); + pdev = to_pci_dev(master->dev); + + if (pdev->ats_enabled)If the
master->ats_enabledcheck above passes when ATS isn't actually enabled, surely that's a bug?
Quoted 3 lines
IIUC, It means ATS feature is supported (just check for existence of ATS extended capability and smmu capability) and not necessarily enabled. Function
pci_enable_ats(called by arm_smmu_enable_ats)enables the ATS by setting bit 15 of ATS Control Register (Offset 06h).
Ifpci_enable_atsis not successful, it will not setdev->ats_enabledflag. So callingpci_disable_atslater results in call-trace, ifdev->ats_enabledis not set.
And like I say, that appears to be a bug, or at least something deserving of improvement. If we *know* that enabling ATS failed, leaving it hanging in some half-enabled state seems wrong. I know the PCI spec says that functions must accept ATS invalidate requests even when ATS is disabled, but that still doesn't make it a great idea for the driver to spend time and effort sending them when it should know they are unnecessarily (especially given the infamous 90-second maximum timeout).
Quoted 1 line
Function
arm_smmu_enable_atsalready prints error message if ATS enable is failed.
Printing a message hardly constitutes robust error handling...
Thanks,
Robin.
Quoted 8 lines · Ganapatrao Kulkarni
The current smmu-v3 driver does not enable PCI ATS for physical functions of ATS capable End Points when booted in smmu bypass mode (iommu.passthrough=1). This will not allow virtual functions to enable ATS(even though EP supports it) while they are attached to a VM using VFIO driver.
This patch adds changes to enable ATS support for physical functions in passthrough/bypass mode as well.
[...]
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) · line 2461
Quoted 7 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1
-2@@ -2453,8 +2458,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = smmu_domain; -if (smmu_domain->stage !=ARM_SMMU_DOMAIN_BYPASS ) - master->ats_enabled =arm_smmu_ats_supported (master); + master->ats_enabled =arm_smmu_ats_supported (master);
I should have added a comment for this. Only found the reason in an old cover letter [1]:
"When no translation stages are enabled (0b100), ATS Translation Requests (and Translated traffic, if SMMU_CR0.ATSCHK == 1) are denied as though EATS == 0b00; the actual value of the EATS field is IGNORED. Such a Translation Request causes F_BAD_ATS_TREQ and Translated traffic causes F_TRANSL_FORBIDDEN."
(See 3.9.1.1 "Responses to ATS Translation Requests and Translated transactions" and 5.2 "Stream Table Entry")
So I don't think we can enable ATS for bypass domains :/ The PF needs to be in translated mode in that case.
I can send a patch adding the comment next cycle.
Thanks,
Jean
Will Deacon
maintainerQuoted 27 lines · Jean-Philippe Brucker
Quoted 8 lines · Ganapatrao Kulkarni
The current smmu-v3 driver does not enable PCI ATS for physical functions of ATS capable End Points when booted in smmu bypass mode (iommu.passthrough=1). This will not allow virtual functions to enable ATS(even though EP supports it) while they are attached to a VM using VFIO driver.
This patch adds changes to enable ATS support for physical functions in passthrough/bypass mode as well.
[...]
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) · line 2461
Quoted 7 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1
-2@@ -2453,8 +2458,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = smmu_domain; -if (smmu_domain->stage !=ARM_SMMU_DOMAIN_BYPASS ) - master->ats_enabled =arm_smmu_ats_supported (master); + master->ats_enabled =arm_smmu_ats_supported (master);I should have added a comment for this. Only found the reason in an old cover letter [1]:
"When no translation stages are enabled (0b100), ATS Translation Requests (and Translated traffic, if SMMU_CR0.ATSCHK == 1) are denied as though EATS == 0b00; the actual value of the EATS field is IGNORED. Such a Translation Request causes
F_BAD_ATS_TREQand Translated traffic causesF_TRANSL_FORBIDDEN."
Quoted 7 lines
(See 3.9.1.1 "Responses to ATS Translation Requests and Translated transactions" and 5.2 "Stream Table Entry")
So I don't think we can enable ATS for bypass domains :/ The PF needs to be in translated mode in that case.
I can send a patch adding the comment next cycle.
Yes, please!
Will
Quoted 27 lines · Jean-Philippe Brucker
Quoted 8 lines · Ganapatrao Kulkarni
The current smmu-v3 driver does not enable PCI ATS for physical functions of ATS capable End Points when booted in smmu bypass mode (iommu.passthrough=1). This will not allow virtual functions to enable ATS(even though EP supports it) while they are attached to a VM using VFIO driver.
This patch adds changes to enable ATS support for physical functions in passthrough/bypass mode as well.
[...]
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) · line 2461
Quoted 7 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1
-2@@ -2453,8 +2458,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = smmu_domain; -if (smmu_domain->stage !=ARM_SMMU_DOMAIN_BYPASS ) - master->ats_enabled =arm_smmu_ats_supported (master); + master->ats_enabled =arm_smmu_ats_supported (master);I should have added a comment for this. Only found the reason in an old cover letter [1]:
"When no translation stages are enabled (0b100), ATS Translation Requests (and Translated traffic, if SMMU_CR0.ATSCHK == 1) are denied as though EATS == 0b00; the actual value of the EATS field is IGNORED. Such a Translation Request causes
F_BAD_ATS_TREQand Translated traffic causesF_TRANSL_FORBIDDEN."
Quoted 5 lines
(See 3.9.1.1 "Responses to ATS Translation Requests and Translated transactions" and 5.2 "Stream Table Entry")
So I don't think we can enable ATS for bypass domains :/ The PF needs to be in translated mode in that case.
Are you intending to say smmu-v3 driver/spec will not support ATS to a VF, if it's PF is in bypass?
Quoted 2 lines
I can send a patch adding the comment next cycle.
I am more keen to know, how we enable ATS to a VF of ATS capable EP when it's PF is in bypass? or it is mandatory to have a PF also translated? then that should be captured somewhere in documentation.
Quoted 6 lines
Thanks,
Jean
Thanks,
Ganapat
Quoted 28 lines · Ganapatrao Kulkarni
Quoted 25 lines · Jean-Philippe Brucker
Quoted 8 lines · Ganapatrao Kulkarni
The current smmu-v3 driver does not enable PCI ATS for physical functions of ATS capable End Points when booted in smmu bypass mode (iommu.passthrough=1). This will not allow virtual functions to enable ATS(even though EP supports it) while they are attached to a VM using VFIO driver.
This patch adds changes to enable ATS support for physical functions in passthrough/bypass mode as well.
[...]
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) · line 2459
Quoted 5 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1
-2@@ -2453,8 +2458,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = smmu_domain; -if (smmu_domain->stage !=ARM_SMMU_DOMAIN_BYPASS ) - master->ats_enabled =arm_smmu_ats_supported (master); + master->ats_enabled =arm_smmu_ats_supported (master);I should have added a comment for this. Only found the reason in an old cover letter [1]:
"When no translation stages are enabled (0b100), ATS Translation Requests (and Translated traffic, if SMMU_CR0.ATSCHK == 1) are denied as though EATS == 0b00; the actual value of the EATS field is IGNORED. Such a Translation Request causes
F_BAD_ATS_TREQand Translated traffic causesF_TRANSL_FORBIDDEN."
Quoted 8 lines
Quoted 5 lines
(See 3.9.1.1 "Responses to ATS Translation Requests and Translated transactions" and 5.2 "Stream Table Entry")
So I don't think we can enable ATS for bypass domains :/ The PF needs to be in translated mode in that case.
Are you intending to say smmu-v3 driver/spec will not support ATS to a VF, if it's PF is in bypass?
What I meant was that if, in order to enable the VF ATS capability, the PCIe device requires to first enable the PF ATS capability, then given that the SMMU does not allow enabling ATS for streams in bypass, we need to enable translation on both PF and VF SMMU configurations.
But reading the PCIe spec, it looks like the capabilities are not necessarily tied together:
"The ATS Capabilities in VFs and their associated PFs are permitted to be enabled independently." 10.5.1 ATS Extended Capability
That wording doesn't indicate that all implementations must allow enabling the caps independently, only that they are allowed to do so. If a device provides independent capabilities, then I don't think you need to enable ATS in the PF.
Then the ATS Control Register seems to contradict this with the STU field:
"For VFs, this field must be hardwired to Zero. The associated PF's value applies." 10.5.1.3 ATS Control Register (Offset 06h)
So pci_enable_ats() requires that pdev->ats_stu is set in order to enable ATS on the VF:
/*
* Note that enabling ATS on a VF fails unless it's already enabled
* with the same STU on the PF.
*/
...
if (dev->is_virtfn) {
pdev = pci_physfn(dev);
if (pdev->ats_stu != ps)
return -EINVAL;But I suspect it's done this way only because it's easier to implement. The spec doesn't require the PF ATS capability to be enabled, it just says that the PF's STU value counts as the VF's one. It looks like we're allowed to enable ATS on the VF without enabling it on the PF, right? If you rework the PCI driver to only write the PF's STU without enabling the capability, then you could enable it in the VF.
Thanks,
Jean
Quoted 19 lines
Quoted 3 lines
I can send a patch adding the comment next cycle.
I am more keen to know, how we enable ATS to a VF of ATS capable EP when it's PF is in bypass?
or it is mandatory to have a PF also translated? then that should be captured somewhere in documentation.Quoted 6 lines
Thanks,
JeanThanks,
Ganapat
Quoted 46 lines · Jean-Philippe Brucker
Quoted 28 lines · Ganapatrao Kulkarni
Quoted 25 lines · Jean-Philippe Brucker
Quoted 8 lines · Ganapatrao Kulkarni
The current smmu-v3 driver does not enable PCI ATS for physical functions of ATS capable End Points when booted in smmu bypass mode (iommu.passthrough=1). This will not allow virtual functions to enable ATS(even though EP supports it) while they are attached to a VM using VFIO driver.
This patch adds changes to enable ATS support for physical functions in passthrough/bypass mode as well.
[...]
Review static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) · line 2459
Quoted 5 lines
(quoted diff) +1
-2@@ -2453,8 +2458,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = smmu_domain; - if (smmu_domain->stage != ARM_SMMU_DOMAIN_BYPASS) - master->ats_enabled = arm_smmu_ats_supported(master); + master->ats_enabled = arm_smmu_ats_supported(master);I should have added a comment for this. Only found the reason in an old cover letter [1]:
"When no translation stages are enabled (0b100), ATS Translation Requests (and Translated traffic, if SMMU_CR0.ATSCHK == 1) are denied as though EATS == 0b00; the actual value of the EATS field is IGNORED. Such a Translation Request causes
F_BAD_ATS_TREQand Translated traffic causesF_TRANSL_FORBIDDEN."Quoted 8 lines
Quoted 5 lines
(See 3.9.1.1 "Responses to ATS Translation Requests and Translated transactions" and 5.2 "Stream Table Entry")
So I don't think we can enable ATS for bypass domains :/ The PF needs to be in translated mode in that case.
Are you intending to say smmu-v3 driver/spec will not support ATS to a VF, if it's PF is in bypass?
What I meant was that if, in order to enable the VF ATS capability, the PCIe device requires to first enable the PF ATS capability, then given that the SMMU does not allow enabling ATS for streams in bypass, we need to enable translation on both PF and VF SMMU configurations.
But reading the PCIe spec, it looks like the capabilities are not necessarily tied together:
Quoted 7 lines
"The ATS Capabilities in VFs and their associated PFs are permitted to be enabled independently." 10.5.1 ATS Extended Capability
That wording doesn't indicate that all implementations must allow enabling the caps independently, only that they are allowed to do so. If a device provides independent capabilities, then I don't think you need to enable ATS in the PF.
Yes makes sense, thanks.
Quoted 6 lines
Then the ATS Control Register seems to contradict this with the STU field:
"For VFs, this field must be hardwired to Zero. The associated PF's value applies." 10.5.1.3 ATS Control Register (Offset 06h)
Quoted 7 lines
So
pci_enable_ats()requires thatpdev->ats_stuis set in order to enable ATS on the VF:/*
* Note that enabling ATS on a VF fails unless it's already enabled
* with the same STU on the PF.
*/
This comment was misleading!
Quoted 10 lines
... if (dev->is_virtfn) { pdev = pci_physfn(dev); if (pdev->ats_stu != ps) return -EINVAL;But I suspect it's done this way only because it's easier to implement. The spec doesn't require the PF ATS capability to be enabled, it just says that the PF's STU value counts as the VF's one. It looks like we're allowed to enable ATS on the VF without enabling it on the PF, right?
OK thanks, as per spec ATS enable on VF and PF are independent. only STU and Capability are hardwired to be same.
Quoted 2 lines
If you rework the PCI driver to only write the PF's STU without enabling the capability, then you could enable it in the VF.
Makes sense, It should be feasible to write to STU of a PF without enabling it.
Below diff is more appropriate fix for this case.
drivers/pci/ats.c +9 -0
@@ -74,6 +74,15 @@ int pci_enable_ats(struct pci_dev *dev, int ps) ctrl =PCI_ATS_CTRL_ENABLE ;if (dev->is_virtfn) { pdev =pci_physfn (dev); + +if (!pdev->ats_enabled) { +u16 ctrl2; + + pdev->ats_stu = ps; + ctrl2 =PCI_ATS_CTRL_STU (pdev->ats_stu -PCI_ATS_MIN_STU ); +pci_write_config_word (pdev, pdev->ats_cap +PCI_ATS_CTRL , ctrl2); + } +if (pdev->ats_stu != ps)return -EINVAL ; }else {
Thanks,
Ganapat
Quoted 23 lines
Thanks,
JeanQuoted 19 lines
Quoted 3 lines
I can send a patch adding the comment next cycle.
I am more keen to know, how we enable ATS to a VF of ATS capable EP when it's PF is in bypass?
or it is mandatory to have a PF also translated? then that should be captured somewhere in documentation.Quoted 6 lines
Thanks,
JeanThanks,
Ganapat