x86/AMD-Vi: Fold exit paths of {enable, disable}_iommu()
PATCH 1/1 x86/AMD-Vi: Fold exit paths of {enable, disable}_iommu()
... to avoid having multiple spin_unlock_irqrestore() calls.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>
Interestingly GCC 6.3 managed to fold disable_iommu() automatically. There is some partial folding for enable_iommu() (insofar as there is only a single call to _spin_unlock_irqrestore emitted), but this delta yeilds
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-20 (-20)
Function old new delta
enable_iommu 1844 1824 -20
Total: Before=3340299, After=3340279, chg -0.00%
which means that something wasn't done automatically.
Noticed while investigating the S3 regression.
--- xen/drivers/passthrough/amd/iommu_init.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
xen/drivers/passthrough/amd/iommu_init.c +7 -10
@@ -899,11 +899,8 @@ static void enable_iommu(struct amd_iommu *iommu)spin_lock_irqsave (&iommu->lock, flags); -if ( iommu->enabled ) - { -spin_unlock_irqrestore (&iommu->lock, flags); -return ; - } +if (unlikely (iommu->enabled) ) + goto out;amd_iommu_erratum_746_workaround (iommu);
@@ -957,6 +954,8 @@ static void enable_iommu(struct amd_iommu *iommu)amd_iommu_flush_all_caches (iommu); iommu->enabled =1 ; + + out:spin_unlock_irqrestore (&iommu->lock, flags); }
@@ -966,11 +965,8 @@ static void disable_iommu(struct amd_iommu *iommu)spin_lock_irqsave (&iommu->lock, flags); -if ( !iommu->enabled ) - { -spin_unlock_irqrestore (&iommu->lock, flags); -return ; - } +if (unlikely (!iommu->enabled) ) + goto out;if ( !iommu->ctrl.int_cap_xt_en )amd_iommu_msi_enable (iommu,IOMMU_CONTROL_DISABLED );
@@ -988,6 +984,7 @@ static void disable_iommu(struct amd_iommu *iommu) iommu->enabled =0 ; + out:spin_unlock_irqrestore (&iommu->lock, flags); }
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 3 lines · Andy Cooper
... to avoid having multiple
spin_unlock_irqrestore()calls.Signed-off-by Andrew Cooper <[email protected]>
Quoted 76 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>Interestingly GCC 6.3 managed to fold
disable_iommu()automatically. There is some partial folding forenable_iommu()(insofar as there is only a single call to_spin_unlock_irqrestoreemitted), but this delta yeildsadd/remove: 0/0 grow/shrink: 0/1 up/down: 0/-20 (-20)
Function old new delta
enable_iommu1844 1824 -20
Total: Before=3340299, After=3340279, chg -0.00%which means that something wasn't done automatically.
Noticed while investigating the S3 regression.
--- xen/drivers/passthrough/amd/iommu_init.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)xen/drivers/passthrough/amd/iommu_init.c +7
-10@@ -899,11 +899,8 @@ static void enable_iommu(struct amd_iommu *iommu)spin_lock_irqsave (&iommu->lock, flags); -if ( iommu->enabled ) - { -spin_unlock_irqrestore (&iommu->lock, flags); -return ; - } +if (unlikely (iommu->enabled) ) + goto out;amd_iommu_erratum_746_workaround (iommu);@@ -957,6 +954,8 @@ static void enable_iommu(struct amd_iommu *iommu)amd_iommu_flush_all_caches (iommu); iommu->enabled =1 ; + + out:spin_unlock_irqrestore (&iommu->lock, flags); }@@ -966,11 +965,8 @@ static void disable_iommu(struct amd_iommu *iommu)spin_lock_irqsave (&iommu->lock, flags); -if ( !iommu->enabled ) - { -spin_unlock_irqrestore (&iommu->lock, flags); -return ; - } +if (unlikely (!iommu->enabled) ) + goto out;if ( !iommu->ctrl.int_cap_xt_en )amd_iommu_msi_enable (iommu,IOMMU_CONTROL_DISABLED );@@ -988,6 +984,7 @@ static void disable_iommu(struct amd_iommu *iommu) iommu->enabled =0 ; + out:spin_unlock_irqrestore (&iommu->lock, flags); }Signature · 1 line
2.11.0
Signature · 6 lines
Brian Woods _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel