Xen-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [Xen-devel] [PATCH] x86/AMD-Vi: Fold exit paths of {enable, disable}_iommu()
@ 2019-08-12 17:52 Andrew Cooper
  2019-08-12 18:01 ` Woods, Brian
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Cooper @ 2019-08-12 17:52 UTC (permalink / raw)
  To: Xen-devel
  Cc: Jan Beulich, Wei Liu, Andrew Cooper, Suravee Suthikulpanit,
	Boris Ostrovsky, Brian Woods, Roger Pau Monné

... to avoid having multiple spin_unlock_irqrestore() calls.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wl@xen.org>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
CC: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
CC: Brian Woods <brian.woods@amd.com>

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(-)

diff --git a/xen/drivers/passthrough/amd/iommu_init.c b/xen/drivers/passthrough/amd/iommu_init.c
index bb9f33e264..bb5a3e57c9 100644
--- a/xen/drivers/passthrough/amd/iommu_init.c
+++ b/xen/drivers/passthrough/amd/iommu_init.c
@@ -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);
 }
 
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Xen-devel] [PATCH] x86/AMD-Vi: Fold exit paths of {enable, disable}_iommu()
  2019-08-12 17:52 [Xen-devel] [PATCH] x86/AMD-Vi: Fold exit paths of {enable, disable}_iommu() Andrew Cooper
@ 2019-08-12 18:01 ` Woods, Brian
  0 siblings, 0 replies; 2+ messages in thread
From: Woods, Brian @ 2019-08-12 18:01 UTC (permalink / raw)
  To: Andrew Cooper
  Cc: Jan Beulich, Wei Liu, Suthikulpanit, Suravee, Xen-devel,
	Boris Ostrovsky, Woods, Brian, Roger Pau Monné

On Mon, Aug 12, 2019 at 06:52:05PM +0100, Andy Cooper wrote:
> ... to avoid having multiple spin_unlock_irqrestore() calls.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Brian Woods <brian.woods@amd.com>

> ---
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Wei Liu <wl@xen.org>
> CC: Roger Pau Monné <roger.pau@citrix.com>
> CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> CC: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> CC: Brian Woods <brian.woods@amd.com>
> 
> 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(-)
> 
> diff --git a/xen/drivers/passthrough/amd/iommu_init.c b/xen/drivers/passthrough/amd/iommu_init.c
> index bb9f33e264..bb5a3e57c9 100644
> --- a/xen/drivers/passthrough/amd/iommu_init.c
> +++ b/xen/drivers/passthrough/amd/iommu_init.c
> @@ -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);
>  }
>  
> -- 
> 2.11.0
> 

-- 
Brian Woods

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 17:52 [Xen-devel] [PATCH] x86/AMD-Vi: Fold exit paths of {enable, disable}_iommu() Andrew Cooper
2019-08-12 18:01 ` Woods, Brian

Xen-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/xen-devel/0 xen-devel/git/0.git
	git clone --mirror https://lore.kernel.org/xen-devel/1 xen-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 xen-devel xen-devel/ https://lore.kernel.org/xen-devel \
		xen-devel@lists.xenproject.org xen-devel@archiver.kernel.org
	public-inbox-index xen-devel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.xenproject.lists.xen-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox