diff mbox

[v2,1/2] x86/altp2m: use __get_gfn_type_access to avoid lock conflicts

Message ID 1470841215-24450-1-git-send-email-tamas.lengyel@zentific.com (mailing list archive)
State New, archived
Headers show

Commit Message

Tamas Lengyel Aug. 10, 2016, 3 p.m. UTC
From: Tamas K Lengyel <tamas@tklengyel.com>

Use __get_gfn_type_access instead of get_gfn_type_access when checking
the hostp2m entries during altp2m mem_access setting and gfn remapping
to avoid a lock conflict which can make dom0 freeze. During mem_access
setting the hp2m is already locked. For gfn remapping we change the flow
to lock the hp2m before locking the ap2m.

Signed-off-by: Tamas K Lengyel <tamas.lengyel@zentific.com>
Reviewed-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
---
Cc: George Dunlap <george.dunlap@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>

v2: Lock the hp2m during gfn remapping
---
 xen/arch/x86/mm/p2m.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Jan Beulich Aug. 11, 2016, 11:57 a.m. UTC | #1
>>> On 10.08.16 at 17:00, <tamas.lengyel@zentific.com> wrote:
> From: Tamas K Lengyel <tamas@tklengyel.com>
> 
> Use __get_gfn_type_access instead of get_gfn_type_access when checking
> the hostp2m entries during altp2m mem_access setting and gfn remapping
> to avoid a lock conflict which can make dom0 freeze. During mem_access
> setting the hp2m is already locked. For gfn remapping we change the flow
> to lock the hp2m before locking the ap2m.
> 
> Signed-off-by: Tamas K Lengyel <tamas.lengyel@zentific.com>
> Reviewed-by: Razvan Cojocaru <rcojocaru@bitdefender.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>
Tamas Lengyel Aug. 31, 2016, 9:02 p.m. UTC | #2
On Thu, Aug 11, 2016 at 5:57 AM, Jan Beulich <JBeulich@suse.com> wrote:
>>>> On 10.08.16 at 17:00, <tamas.lengyel@zentific.com> wrote:
>> From: Tamas K Lengyel <tamas@tklengyel.com>
>>
>> Use __get_gfn_type_access instead of get_gfn_type_access when checking
>> the hostp2m entries during altp2m mem_access setting and gfn remapping
>> to avoid a lock conflict which can make dom0 freeze. During mem_access
>> setting the hp2m is already locked. For gfn remapping we change the flow
>> to lock the hp2m before locking the ap2m.
>>
>> Signed-off-by: Tamas K Lengyel <tamas.lengyel@zentific.com>
>> Reviewed-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>

Patch ping, I think this just needs George's ack.

Tamas
George Dunlap Sept. 6, 2016, 5:02 p.m. UTC | #3
On Wed, Aug 10, 2016 at 4:00 PM, Tamas K Lengyel
<tamas.lengyel@zentific.com> wrote:
> From: Tamas K Lengyel <tamas@tklengyel.com>
>
> Use __get_gfn_type_access instead of get_gfn_type_access when checking
> the hostp2m entries during altp2m mem_access setting and gfn remapping
> to avoid a lock conflict which can make dom0 freeze. During mem_access
> setting the hp2m is already locked. For gfn remapping we change the flow
> to lock the hp2m before locking the ap2m.
>
> Signed-off-by: Tamas K Lengyel <tamas.lengyel@zentific.com>
> Reviewed-by: Razvan Cojocaru <rcojocaru@bitdefender.com>

Acked-by: George Dunlap <george.dunlap@citrix.com>

> ---
> Cc: George Dunlap <george.dunlap@eu.citrix.com>
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
>
> v2: Lock the hp2m during gfn remapping
> ---
>  xen/arch/x86/mm/p2m.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
> index 812dbf6..1eeb934 100644
> --- a/xen/arch/x86/mm/p2m.c
> +++ b/xen/arch/x86/mm/p2m.c
> @@ -1787,8 +1787,8 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m,
>      if ( !mfn_valid(mfn) )
>      {
>
> -        mfn = get_gfn_type_access(hp2m, gfn_l, &t, &old_a,
> -                                  P2M_ALLOC | P2M_UNSHARE, &page_order);
> +        mfn = __get_gfn_type_access(hp2m, gfn_l, &t, &old_a,
> +                                    P2M_ALLOC | P2M_UNSHARE, &page_order, 0);
>
>          rc = -ESRCH;
>          if ( !mfn_valid(mfn) || t != p2m_ram_rw )
> @@ -2548,6 +2548,7 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
>      hp2m = p2m_get_hostp2m(d);
>      ap2m = d->arch.altp2m_p2m[idx];
>
> +    p2m_lock(hp2m);
>      p2m_lock(ap2m);
>
>      mfn = ap2m->get_entry(ap2m, gfn_x(old_gfn), &t, &a, 0, NULL, NULL);
> @@ -2563,8 +2564,8 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
>      /* Check host p2m if no valid entry in alternate */
>      if ( !mfn_valid(mfn) )
>      {
> -        mfn = get_gfn_type_access(hp2m, gfn_x(old_gfn), &t, &a,
> -                                  P2M_ALLOC | P2M_UNSHARE, &page_order);
> +        mfn = __get_gfn_type_access(hp2m, gfn_x(old_gfn), &t, &a,
> +                                    P2M_ALLOC | P2M_UNSHARE, &page_order, 0);
>
>          if ( !mfn_valid(mfn) || t != p2m_ram_rw )
>              goto out;
> @@ -2606,6 +2607,7 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
>
>   out:
>      p2m_unlock(ap2m);
> +    p2m_unlock(hp2m);
>      return rc;
>  }
>
> --
> 2.8.1
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> https://lists.xen.org/xen-devel
diff mbox

Patch

diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index 812dbf6..1eeb934 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -1787,8 +1787,8 @@  int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m,
     if ( !mfn_valid(mfn) )
     {
 
-        mfn = get_gfn_type_access(hp2m, gfn_l, &t, &old_a,
-                                  P2M_ALLOC | P2M_UNSHARE, &page_order);
+        mfn = __get_gfn_type_access(hp2m, gfn_l, &t, &old_a,
+                                    P2M_ALLOC | P2M_UNSHARE, &page_order, 0);
 
         rc = -ESRCH;
         if ( !mfn_valid(mfn) || t != p2m_ram_rw )
@@ -2548,6 +2548,7 @@  int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
     hp2m = p2m_get_hostp2m(d);
     ap2m = d->arch.altp2m_p2m[idx];
 
+    p2m_lock(hp2m);
     p2m_lock(ap2m);
 
     mfn = ap2m->get_entry(ap2m, gfn_x(old_gfn), &t, &a, 0, NULL, NULL);
@@ -2563,8 +2564,8 @@  int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
     /* Check host p2m if no valid entry in alternate */
     if ( !mfn_valid(mfn) )
     {
-        mfn = get_gfn_type_access(hp2m, gfn_x(old_gfn), &t, &a,
-                                  P2M_ALLOC | P2M_UNSHARE, &page_order);
+        mfn = __get_gfn_type_access(hp2m, gfn_x(old_gfn), &t, &a,
+                                    P2M_ALLOC | P2M_UNSHARE, &page_order, 0);
 
         if ( !mfn_valid(mfn) || t != p2m_ram_rw )
             goto out;
@@ -2606,6 +2607,7 @@  int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
 
  out:
     p2m_unlock(ap2m);
+    p2m_unlock(hp2m);
     return rc;
 }