xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] AMD IOMMU: don't free page table prematurely
@ 2014-05-26 10:16 Jan Beulich
  2014-05-26 15:55 ` Andrew Cooper
  2014-05-28  5:20 ` Suravee Suthikulpanit
  0 siblings, 2 replies; 3+ messages in thread
From: Jan Beulich @ 2014-05-26 10:16 UTC (permalink / raw)
  To: xen-devel; +Cc: Aravind Gopalakrishnan, suravee.suthikulpanit

[-- Attachment #1: Type: text/plain, Size: 1177 bytes --]

iommu_merge_pages() still wants to look at the next level page table,
the TLB flush necessary before freeing too happens in that function,
and if it fails no free should happen at all. Hence the freeing must
be done after that function returned successfully, not before it's
being called.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/drivers/passthrough/amd/iommu_map.c
+++ b/xen/drivers/passthrough/amd/iommu_map.c
@@ -691,8 +691,6 @@ int amd_iommu_map_page(struct domain *d,
         if ( !iommu_update_pde_count(d, pt_mfn[merge_level],
                                      gfn, mfn, merge_level) )
             break;
-        /* Deallocate lower level page table */
-        free_amd_iommu_pgtable(mfn_to_page(pt_mfn[merge_level - 1]));
 
         if ( iommu_merge_pages(d, pt_mfn[merge_level], gfn, 
                                flags, merge_level) )
@@ -703,6 +701,9 @@ int amd_iommu_map_page(struct domain *d,
             domain_crash(d);
             return -EFAULT;
         }
+
+        /* Deallocate lower level page table */
+        free_amd_iommu_pgtable(mfn_to_page(pt_mfn[merge_level - 1]));
     }
 
 out:




[-- Attachment #2: AMD-IOMMU-defer-merge-free.patch --]
[-- Type: text/plain, Size: 1219 bytes --]

AMD IOMMU: don't free page table prematurely

iommu_merge_pages() still wants to look at the next level page table,
the TLB flush necessary before freeing too happens in that function,
and if it fails no free should happen at all. Hence the freeing must
be done after that function returned successfully, not before it's
being called.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/drivers/passthrough/amd/iommu_map.c
+++ b/xen/drivers/passthrough/amd/iommu_map.c
@@ -691,8 +691,6 @@ int amd_iommu_map_page(struct domain *d,
         if ( !iommu_update_pde_count(d, pt_mfn[merge_level],
                                      gfn, mfn, merge_level) )
             break;
-        /* Deallocate lower level page table */
-        free_amd_iommu_pgtable(mfn_to_page(pt_mfn[merge_level - 1]));
 
         if ( iommu_merge_pages(d, pt_mfn[merge_level], gfn, 
                                flags, merge_level) )
@@ -703,6 +701,9 @@ int amd_iommu_map_page(struct domain *d,
             domain_crash(d);
             return -EFAULT;
         }
+
+        /* Deallocate lower level page table */
+        free_amd_iommu_pgtable(mfn_to_page(pt_mfn[merge_level - 1]));
     }
 
 out:

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [PATCH] AMD IOMMU: don't free page table prematurely
  2014-05-26 10:16 [PATCH] AMD IOMMU: don't free page table prematurely Jan Beulich
@ 2014-05-26 15:55 ` Andrew Cooper
  2014-05-28  5:20 ` Suravee Suthikulpanit
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Cooper @ 2014-05-26 15:55 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Aravind Gopalakrishnan, suravee.suthikulpanit


[-- Attachment #1.1: Type: text/plain, Size: 1440 bytes --]

On 26/05/2014 11:16, Jan Beulich wrote:
> iommu_merge_pages() still wants to look at the next level page table,
> the TLB flush necessary before freeing too happens in that function,
> and if it fails no free should happen at all. Hence the freeing must
> be done after that function returned successfully, not before it's
> being called.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

>
> --- a/xen/drivers/passthrough/amd/iommu_map.c
> +++ b/xen/drivers/passthrough/amd/iommu_map.c
> @@ -691,8 +691,6 @@ int amd_iommu_map_page(struct domain *d,
>          if ( !iommu_update_pde_count(d, pt_mfn[merge_level],
>                                       gfn, mfn, merge_level) )
>              break;
> -        /* Deallocate lower level page table */
> -        free_amd_iommu_pgtable(mfn_to_page(pt_mfn[merge_level - 1]));
>  
>          if ( iommu_merge_pages(d, pt_mfn[merge_level], gfn, 
>                                 flags, merge_level) )
> @@ -703,6 +701,9 @@ int amd_iommu_map_page(struct domain *d,
>              domain_crash(d);
>              return -EFAULT;
>          }
> +
> +        /* Deallocate lower level page table */
> +        free_amd_iommu_pgtable(mfn_to_page(pt_mfn[merge_level - 1]));
>      }
>  
>  out:
>
>
>
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel


[-- Attachment #1.2: Type: text/html, Size: 2306 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [PATCH] AMD IOMMU: don't free page table prematurely
  2014-05-26 10:16 [PATCH] AMD IOMMU: don't free page table prematurely Jan Beulich
  2014-05-26 15:55 ` Andrew Cooper
@ 2014-05-28  5:20 ` Suravee Suthikulpanit
  1 sibling, 0 replies; 3+ messages in thread
From: Suravee Suthikulpanit @ 2014-05-28  5:20 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Aravind Gopalakrishnan

On 05/26/2014 05:16 AM, Jan Beulich wrote:
> iommu_merge_pages() still wants to look at the next level page table,
> the TLB flush necessary before freeing too happens in that function,
> and if it fails no free should happen at all. Hence the freeing must
> be done after that function returned successfully, not before it's
> being called.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- a/xen/drivers/passthrough/amd/iommu_map.c
> +++ b/xen/drivers/passthrough/amd/iommu_map.c
> @@ -691,8 +691,6 @@ int amd_iommu_map_page(struct domain *d,
>           if ( !iommu_update_pde_count(d, pt_mfn[merge_level],
>                                        gfn, mfn, merge_level) )
>               break;
> -        /* Deallocate lower level page table */
> -        free_amd_iommu_pgtable(mfn_to_page(pt_mfn[merge_level - 1]));
>
>           if ( iommu_merge_pages(d, pt_mfn[merge_level], gfn,
>                                  flags, merge_level) )
> @@ -703,6 +701,9 @@ int amd_iommu_map_page(struct domain *d,
>               domain_crash(d);
>               return -EFAULT;
>           }
> +
> +        /* Deallocate lower level page table */
> +        free_amd_iommu_pgtable(mfn_to_page(pt_mfn[merge_level - 1]));
>       }
>
>   out:
>
>
>

Reviewed and tested. By the way, is this patch fix any existing known 
issues?

Suravee

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

end of thread, other threads:[~2014-05-28  5:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-26 10:16 [PATCH] AMD IOMMU: don't free page table prematurely Jan Beulich
2014-05-26 15:55 ` Andrew Cooper
2014-05-28  5:20 ` Suravee Suthikulpanit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).