[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] x86/AMD-Vi: Fold exit paths of {enable, disable}_iommu()


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: "Woods, Brian" <Brian.Woods@xxxxxxx>
  • Date: Mon, 12 Aug 2019 18:01:06 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wCVz3JhrZMIRX3KcKqpTC21dU7dut6AlirdSqBOSr9Q=; b=crR/C0p+W7Uad8bXlxtyU+On5HOE68CWZHDzFC7Oc15bT6GtMsCWHEYWOHJ25GrX3ZGvri3NdetT6HPuF20FVm8Nz6og5w7i+rBIBjFAbt7Bf73VOPYfXfYFuhTbJ8pHw+yPwPyXYnTCEZC0PcqmwhswlJNZe1CL87Zo0JxjZST63VM+W2Gq8hlh/NU38Sh+Pz+1wCQ2/F2AaiEFL7gOSB6/r3g9xRsurgJ++g3BogwqSgXdefu+wWqeqKT0innOdEWmHc0goRmBiPGUk9cGTrVvAMFSPKnJJYBlMj2VsXEeDIBPGk5X9mcvzMwcG1xWwjHKvnnGXphrwTPriU/uOQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bw0Imrxnn5OcYQEvnR+U3ckD7Tj4H0iTdKGgyovRX/f9Sff6kPHoFw1xayGPl6W0/vA/c/AEG763RoHZhlbb4xoszOpUDmLdaiE5ShOUhlQ0LJao2Da4wYuswBHO721QnCOta2Dm4f1w9k4Xv9R4tX7llkTGoYYeZre19k0F3tiSYdCYG6V7zprk+4DMv/7X7yTjWxy51XBHdbgnFPlH8LFnUDSffxakMz3hExusljTcp4XVaTmJUik3d8gBSUjekBAAUEq9Howmv+Hom1FDK1hGWatdmOzRVv4e0wegqAiBPBMwlSFmiYrR80We0YccQn2kTAvgHa00PiLaqkCd+A==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Brian.Woods@xxxxxxx;
  • Cc: Jan Beulich <JBeulich@xxxxxxxx>, Wei Liu <wl@xxxxxxx>, "Suthikulpanit, Suravee" <Suravee.Suthikulpanit@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, "Woods, Brian" <Brian.Woods@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 12 Aug 2019 18:01:22 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVUTaqOMIPPU6k90KWamZ+6e/EQqb3zWKA
  • Thread-topic: [PATCH] x86/AMD-Vi: Fold exit paths of {enable,disable}_iommu()

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@xxxxxxxxxx>

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

> ---
> CC: Jan Beulich <JBeulich@xxxxxxxx>
> CC: Wei Liu <wl@xxxxxxx>
> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> CC: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
> CC: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx>
> CC: Brian Woods <brian.woods@xxxxxxx>
> 
> 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@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.