Skip to contentSkip to conversation

x86/altp2m: propagate ept.ad changes to all active altp2ms

PATCH Superseded Razvan Cojocaru 3 participants 7 messages Sep 28, 2018 – Oct 1, 2018

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/altp2m: propagate ept.ad changes to all active altp2ms

This patch is a pre-requisite for fixing the logdirty VGA issue (display freezes when switching to a new altp2m view early in a domain's lifetime), but sent separately for easier review. The new ept_set_ad_sync() function has been added to update all active altp2ms' ept.ad. New altp2ms will inherit the hostp2m's ept.ad value. ept_set_ad_sync() is now also the code responsible for locking updated p2ms.

---
 xen/arch/x86/mm/p2m-ept.c | 55 ++++++++++++++++++++++++++++++++++++++++-------
 xen/arch/x86/mm/p2m.c     |  8 -------
 2 files changed, 47 insertions(+), 16 deletions(-)
xen/arch/x86/mm/p2m-ept.c +47 -8
index d376966..432ff5c 100644
@@ -17,6 +17,7 @@
 
 #include <xen/domain_page.h>
 #include <xen/sched.h>
+#include <asm/altp2m.h>
 #include <asm/current.h>
 #include <asm/paging.h>
 #include <asm/types.h>
@@ -1218,34 +1219,67 @@ static void ept_tlb_flush(struct p2m_domain *p2m)
     ept_sync_domain_mask(p2m, p2m->domain->dirty_cpumask);
 }
 
+static void ept_set_ad_sync(struct p2m_domain *p2m, int value)
+{
+    struct domain *d = p2m->domain;
+    unsigned int i;
+
+    if ( likely(!altp2m_active(d)) )
+    {
+        p2m_lock(p2m);
+        p2m->ept.ad = value;
+        p2m_unlock(p2m);
+
+        return;
+    }
+
+    for ( i = 0; i < MAX_ALTP2M; i++ )
+    {
+        if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
+            continue;
+
+        p2m = d->arch.altp2m_p2m[i];
+
+        p2m_lock(p2m);
+        p2m->ept.ad = value;
+        p2m_unlock(p2m);
+    }
+}
+
 static void ept_enable_pml(struct p2m_domain *p2m)
 {
+    struct domain *d = p2m->domain;
+
     /* Domain must have been paused */
-    ASSERT(atomic_read(&p2m->domain->pause_count));
+    ASSERT(atomic_read(&d->pause_count));
 
     /*
      * No need to return whether vmx_domain_enable_pml has succeeded, as
      * ept_p2m_type_to_flags will do the check, and write protection will be
      * used if PML is not enabled.
      */
-    if ( vmx_domain_enable_pml(p2m->domain) )
+    if ( vmx_domain_enable_pml(d) )
         return;
 
     /* Enable EPT A/D bit for PML */
-    p2m->ept.ad = 1;
-    vmx_domain_update_eptp(p2m->domain);
+    ept_set_ad_sync(p2m, 1);
+
+    vmx_domain_update_eptp(d);
 }
 
 static void ept_disable_pml(struct p2m_domain *p2m)
 {
+    struct domain *d = p2m->domain;
+
     /* Domain must have been paused */
-    ASSERT(atomic_read(&p2m->domain->pause_count));
+    ASSERT(atomic_read(&d->pause_count));
 
-    vmx_domain_disable_pml(p2m->domain);
+    vmx_domain_disable_pml(d);
 
     /* Disable EPT A/D bit */
-    p2m->ept.ad = 0;
-    vmx_domain_update_eptp(p2m->domain);
+    ept_set_ad_sync(p2m, 0);
+
+    vmx_domain_update_eptp(d);
 }
 
 static void ept_flush_pml_buffers(struct p2m_domain *p2m)
@@ -1386,8 +1420,13 @@ void setup_ept_dump(void)
 void p2m_init_altp2m_ept(struct domain *d, unsigned int i)
 {
     struct p2m_domain *p2m = d->arch.altp2m_p2m[i];
+    struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
     struct ept_data *ept;
 
+    p2m_lock(hostp2m);
+    p2m->ept.ad = hostp2m->ept.ad;
+    p2m_unlock(hostp2m);
+
     p2m->min_remapped_gfn = gfn_x(INVALID_GFN);
     p2m->max_remapped_gfn = 0;
     ept = &p2m->ept;
xen/arch/x86/mm/p2m.c +0 -8
index d6a8810..d90c624 100644
@@ -360,11 +360,7 @@ void p2m_enable_hardware_log_dirty(struct domain *d)
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
 
     if ( p2m->enable_hardware_log_dirty )
-    {
-        p2m_lock(p2m);
         p2m->enable_hardware_log_dirty(p2m);
-        p2m_unlock(p2m);
-    }
 }
 
 void p2m_disable_hardware_log_dirty(struct domain *d)
@@ -372,11 +368,7 @@ void p2m_disable_hardware_log_dirty(struct domain *d)
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
 
     if ( p2m->disable_hardware_log_dirty )
-    {
-        p2m_lock(p2m);
         p2m->disable_hardware_log_dirty(p2m);
-        p2m_unlock(p2m);
-    }
 }
 
 void p2m_flush_hardware_cached_dirty(struct domain *d)
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 104 lines · Razvan Cojocaru

This patch is a pre-requisite for fixing the logdirty VGA issue (display freezes when switching to a new altp2m view early in a domain's lifetime), but sent separately for easier review. The new ept_set_ad_sync() function has been added to update all active altp2ms' ept.ad. New altp2ms will inherit the hostp2m's ept.ad value. ept_set_ad_sync() is now also the code responsible for locking updated p2ms.

---
 xen/arch/x86/mm/p2m-ept.c | 55 ++++++++++++++++++++++++++++++++++++++++-------
 xen/arch/x86/mm/p2m.c     |  8 -------
 2 files changed, 47 insertions(+), 16 deletions(-)
xen/arch/x86/mm/p2m-ept.c +42 -8
index d376966..432ff5c 100644
@@ -17,6 +17,7 @@
 
 #include <xen/domain_page.h>
 #include <xen/sched.h>
+#include <asm/altp2m.h>
 #include <asm/current.h>
 #include <asm/paging.h>
 #include <asm/types.h>
@@ -1218,34 +1219,67 @@ static void ept_tlb_flush(struct p2m_domain *p2m)
     ept_sync_domain_mask(p2m, p2m->domain->dirty_cpumask);
 }
 
+static void ept_set_ad_sync(struct p2m_domain *p2m, int value)
+{
+    struct domain *d = p2m->domain;
+    unsigned int i;
+
+    if ( likely(!altp2m_active(d)) )
+    {
+        p2m_lock(p2m);
+        p2m->ept.ad = value;
+        p2m_unlock(p2m);
+
+        return;
+    }
+
+    for ( i = 0; i < MAX_ALTP2M; i++ )
+    {
+        if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
+            continue;
+
+        p2m = d->arch.altp2m_p2m[i];
+
+        p2m_lock(p2m);
+        p2m->ept.ad = value;
+        p2m_unlock(p2m);
+    }
+}
+
 static void ept_enable_pml(struct p2m_domain *p2m)
 {
+    struct domain *d = p2m->domain;
+
     /* Domain must have been paused */
-    ASSERT(atomic_read(&p2m->domain->pause_count));
+    ASSERT(atomic_read(&d->pause_count));
 
     /*
      * No need to return whether vmx_domain_enable_pml has succeeded, as
      * ept_p2m_type_to_flags will do the check, and write protection will be
      * used if PML is not enabled.
      */
-    if ( vmx_domain_enable_pml(p2m->domain) )
+    if ( vmx_domain_enable_pml(d) )
         return;
 
     /* Enable EPT A/D bit for PML */
-    p2m->ept.ad = 1;
-    vmx_domain_update_eptp(p2m->domain);
+    ept_set_ad_sync(p2m, 1);
+
+    vmx_domain_update_eptp(d);
 }
 
 static void ept_disable_pml(struct p2m_domain *p2m)
 {
+    struct domain *d = p2m->domain;
+
     /* Domain must have been paused */
-    ASSERT(atomic_read(&p2m->domain->pause_count));
+    ASSERT(atomic_read(&d->pause_count));
 
-    vmx_domain_disable_pml(p2m->domain);
+    vmx_domain_disable_pml(d);
 
     /* Disable EPT A/D bit */
-    p2m->ept.ad = 0;
-    vmx_domain_update_eptp(p2m->domain);
+    ept_set_ad_sync(p2m, 0);
+
+    vmx_domain_update_eptp(d);
 }
 
 static void ept_flush_pml_buffers(struct p2m_domain *p2m)

xen/arch/x86/mm/p2m-ept.c void setup_ept_dump(void) · line 1428

Quoted 9 lines
xen/arch/x86/mm/p2m-ept.c +4 -0
@@ -1386,8 +1420,13 @@ void setup_ept_dump(void)
 void p2m_init_altp2m_ept(struct domain *d, unsigned int i)
 {
     struct p2m_domain *p2m = d->arch.altp2m_p2m[i];
+    struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
     struct ept_data *ept;
 
+    p2m_lock(hostp2m);
+    p2m->ept.ad = hostp2m->ept.ad;
+    p2m_unlock(hostp2m);

Just realised I shouldn't lock the hostp2m here, sorry for the oversight.

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
In reply to Razvan Cojocaru

xen/arch/x86/mm/p2m-ept.c static void ept_tlb_flush(struct p2m_domain *p2m) · line 1222

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 13:55, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +1 -0
@@ -1218,34 +1219,67 @@ static void ept_tlb_flush(struct p2m_domain *p2m)
     ept_sync_domain_mask(p2m, p2m->domain->dirty_cpumask);
 }
 
+static void ept_set_ad_sync(struct p2m_domain *p2m, int value)

Can the second parameter be bool please (and the true/false arguments in the callers)?

xen/arch/x86/mm/p2m-ept.c static void ept_tlb_flush(struct p2m_domain *p2m) · line 1234

Quoted 12 lines
xen/arch/x86/mm/p2m-ept.c +12 -0
+{
+    struct domain *d = p2m->domain;
+    unsigned int i;
+
+    if ( likely(!altp2m_active(d)) )
+    {
+        p2m_lock(p2m);
+        p2m->ept.ad = value;
+        p2m_unlock(p2m);
+
+        return;
+    }

Why would you want to skip updating the host p2m's flag when altp2m is active?

Quoted 15 lines
xen/arch/x86/mm/p2m.c +0 -4
@@ -360,11 +360,7 @@ void p2m_enable_hardware_log_dirty(struct domain *d)
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
 
     if ( p2m->enable_hardware_log_dirty )
-    {
-        p2m_lock(p2m);
         p2m->enable_hardware_log_dirty(p2m);
-        p2m_unlock(p2m);
-    }
 }
 
 void p2m_disable_hardware_log_dirty(struct domain *d)

xen/arch/x86/mm/p2m.c void p2m_disable_hardware_log_dirty(struct domain *d) · line 372

Quoted 9 lines
xen/arch/x86/mm/p2m.c +0 -4
@@ -372,11 +368,7 @@ void p2m_disable_hardware_log_dirty(struct domain *d)
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
 
     if ( p2m->disable_hardware_log_dirty )
-    {
-        p2m_lock(p2m);
         p2m->disable_hardware_log_dirty(p2m);
-        p2m_unlock(p2m);
-    }
 }

I don't understand how this removal can be correct.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 9 lines · Jan Beulich

xen/arch/x86/mm/p2m-ept.c static void ept_tlb_flush(struct p2m_domain *p2m) · line 1222

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 13:55, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +1 -0
@@ -1218,34 +1219,67 @@ static void ept_tlb_flush(struct p2m_domain *p2m)
     ept_sync_domain_mask(p2m, p2m->domain->dirty_cpumask);
 }
 
+static void ept_set_ad_sync(struct p2m_domain *p2m, int value)

Can the second parameter be bool please (and the true/false arguments in the callers)?

Of course.

Quoted 7 lines
Quoted 7 lines
xen/arch/x86/mm/p2m-ept.c +7 -0
+{
+    struct domain *d = p2m->domain;
+    unsigned int i;
+
+    if ( likely(!altp2m_active(d)) )
+    {
+        p2m_lock(p2m);
Quoted 8 lines

xen/arch/x86/mm/p2m-ept.c static void ept_tlb_flush(struct p2m_domain *p2m) · line 1234

Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +5 -0
+        p2m->ept.ad = value;
+        p2m_unlock(p2m);
+
+        return;
+    }

Why would you want to skip updating the host p2m's flag when altp2m is active?

It's not really skipped if I understand the altp2m code correctly: in that case the hostp2m is d->arch.altp2m_p2m[0], which is take care of in the loop below the code you've quoted.

Quoted 17 lines
Quoted 17 lines
xen/arch/x86/mm/p2m.c +0 -4
@@ -360,11 +360,7 @@ void p2m_enable_hardware_log_dirty(struct domain *d)
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
 
     if ( p2m->enable_hardware_log_dirty )
-    {
-        p2m_lock(p2m);
         p2m->enable_hardware_log_dirty(p2m);
-        p2m_unlock(p2m);
-    }
 }
 
 void p2m_disable_hardware_log_dirty(struct domain *d)
@@ -372,11 +368,7 @@ void p2m_disable_hardware_log_dirty(struct domain *d)
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
 
Quoted 9 lines

xen/arch/x86/mm/p2m.c void p2m_disable_hardware_log_dirty(struct domain *d) · line 372

Quoted 7 lines
xen/arch/x86/mm/p2m.c +0 -4
     if ( p2m->disable_hardware_log_dirty )
-    {
-        p2m_lock(p2m);
         p2m->disable_hardware_log_dirty(p2m);
-        p2m_unlock(p2m);
-    }
 }

I don't understand how this removal can be correct.

Do you mean because the lock is supposed to protect the vmx_domain_disable_pml(d); and vmx_domain_update_eptp(d); calls as well? Otherwise, I've removed them because the locking is now done in ept_set_ad_sync().

I had hoped that would address the following comments from George from a previous RFC patch:

"> static void ept_enable_pml(struct p2m_domain *p2m)

xen/arch/x86/mm/p2m-ept.c static void ept_tlb_flush(struct p2m_domain *p2m)

Quoted 11 lines

{

xen/arch/x86/mm/p2m-ept.c +4 -1
+    unsigned int i;
+    struct domain *d = p2m->domain;
+
     /* Domain must have been paused */
-    ASSERT(atomic_read(&p2m->domain->pause_count));
+    ASSERT(atomic_read(&d->pause_count));
 
     /*
      * No need to return whether vmx_domain_enable_pml has succeeded, as
      * ept_p2m_type_to_flags will do the check, and write protection

will be

Quoted 9 lines

* used if PML is not enabled.
*/

xen/arch/x86/mm/p2m-ept.c +1 -2
-    if ( vmx_domain_enable_pml(p2m->domain) )
+    if ( vmx_domain_enable_pml(d) )
         return;
 
     /* Enable EPT A/D bit for PML */
     p2m->ept.ad = 1;
-    vmx_domain_update_eptp(p2m->domain);

xen/arch/x86/mm/p2m-ept.c static void ept_tlb_flush(struct p2m_domain *p2m) · line 1246

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +10 -0
+
+    if ( altp2m_active(d) )
+        for ( i = 0; i < MAX_ALTP2M; i++ )
+        {
+            if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
+                continue;
+
+            p2m = d->arch.altp2m_p2m[i];
+            p2m->ept.ad = 1;
+        }

You're not grabbing the respective p2m locks here -- I'm pretty sure this will end up being three separate instructions (read, set ad bit, write).

But there would something a bit funny here about grabbing the main p2m lock in p2m.c, and then grabbing altp2m locks within the function. But on the other hand, you clearly only want to call this...

Quoted 1 line

+ vmx_domain_update_eptp(d);

...once. Some refactoring might be wanted."

Hence my refactoring attempt.

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 17:25, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 13:55, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +0 -0
@@ -1218,34 +1219,67 @@ static void ept_tlb_flush(struct p2m_domain *p2m)
     ept_sync_domain_mask(p2m, p2m->domain->dirty_cpumask);
 }
 
Quoted 16 lines

xen/arch/x86/mm/p2m-ept.c static void ept_tlb_flush(struct p2m_domain *p2m) · line 1234

Quoted 13 lines
xen/arch/x86/mm/p2m-ept.c +13 -0
+static void ept_set_ad_sync(struct p2m_domain *p2m, int value)
+{
+    struct domain *d = p2m->domain;
+    unsigned int i;
+
+    if ( likely(!altp2m_active(d)) )
+    {
+        p2m_lock(p2m);
+        p2m->ept.ad = value;
+        p2m_unlock(p2m);
+
+        return;
+    }

Why would you want to skip updating the host p2m's flag when altp2m is active?

Quoted 3 lines

It's not really skipped if I understand the altp2m code correctly: in that case the hostp2m is d->arch.altp2m_p2m[0], which is take care of in the loop below the code you've quoted.

p2m_init_altp2m() (and other code in p2m.c) suggests otherwise to me.

Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
xen/arch/x86/mm/p2m.c +0 -4
@@ -360,11 +360,7 @@ void p2m_enable_hardware_log_dirty(struct domain *d)
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
 
     if ( p2m->enable_hardware_log_dirty )
-    {
-        p2m_lock(p2m);
         p2m->enable_hardware_log_dirty(p2m);
-        p2m_unlock(p2m);
-    }
 }
 
 void p2m_disable_hardware_log_dirty(struct domain *d)
@@ -372,11 +368,7 @@ void p2m_disable_hardware_log_dirty(struct domain *d)
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
 
Quoted 9 lines

xen/arch/x86/mm/p2m.c void p2m_disable_hardware_log_dirty(struct domain *d) · line 372

Quoted 7 lines
xen/arch/x86/mm/p2m.c +0 -4
     if ( p2m->disable_hardware_log_dirty )
-    {
-        p2m_lock(p2m);
         p2m->disable_hardware_log_dirty(p2m);
-        p2m_unlock(p2m);
-    }
 }

I don't understand how this removal can be correct.

Quoted 2 lines

Do you mean because the lock is supposed to protect the vmx_domain_disable_pml(d); and vmx_domain_update_eptp(d); calls as well?

Not just there - I think you need to keep at least a read lock on the host p2m until you've managed to update all the altp2m-s.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 17:25, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 13:55, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +3 -0
@@ -1218,34 +1219,67 @@ static void ept_tlb_flush(struct p2m_domain *p2m)
     ept_sync_domain_mask(p2m, p2m->domain->dirty_cpumask);
 }
 
+static void ept_set_ad_sync(struct p2m_domain *p2m, int value)
+{
+    struct domain *d = p2m->domain;

xen/arch/x86/mm/p2m-ept.c static void ept_tlb_flush(struct p2m_domain *p2m) · line 1234

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +10 -0
+    unsigned int i;
+
+    if ( likely(!altp2m_active(d)) )
+    {
+        p2m_lock(p2m);
+        p2m->ept.ad = value;
+        p2m_unlock(p2m);
+
+        return;
+    }

Why would you want to skip updating the host p2m's flag when altp2m is active?

Quoted 5 lines
Quoted 3 lines

It's not really skipped if I understand the altp2m code correctly: in that case the hostp2m is d->arch.altp2m_p2m[0], which is take care of in the loop below the code you've quoted.

p2m_init_altp2m() (and other code in p2m.c) suggests otherwise to me.

That's interesting, p2m_set_mem_access() is treating altp2m index 0 as the hostp2m:

360 /*

361  * Set access type for a region of gfns.
362  * If gfn == INVALID_GFN, sets the default access type.
363  */

364 long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
365 uint32_t start, uint32_t mask,
xenmem_access_t access,
366 unsigned int altp2m_idx)
367 {

368     struct p2m_domain *p2m = p2m_get_hostp2m(d), *ap2m = NULL;
369     p2m_access_t a;
370     unsigned long gfn_l;
371     long rc = 0;

372
373 /* altp2m view 0 is treated as the hostp2m */
374 #ifdef CONFIG_HVM
375 if ( altp2m_idx )
376 {
377 if ( altp2m_idx >= MAX_ALTP2M ||
378 d->arch.altp2m_eptp[altp2m_idx] == mfn_x(INVALID_MFN) )
379 return -EINVAL;
380
381 ap2m = d->arch.altp2m_p2m[altp2m_idx];
382 }
383 #else
384 ASSERT(!altp2m_idx);
385 #endif

which would seem to imply that either we should be able to treat d->arch.altp2m_p2m[0] and hostp2m interchangeably, or we are currently wasting an altp2m array slot.

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
Quoted 62 lines · Razvan Cojocaru
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 17:25, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 13:55, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +3 -0
@@ -1218,34 +1219,67 @@ static void ept_tlb_flush(struct p2m_domain *p2m)
     ept_sync_domain_mask(p2m, p2m->domain->dirty_cpumask);
 }
 
+static void ept_set_ad_sync(struct p2m_domain *p2m, int value)
+{
+    struct domain *d = p2m->domain;

xen/arch/x86/mm/p2m-ept.c static void ept_tlb_flush(struct p2m_domain *p2m) · line 1234

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +10 -0
+    unsigned int i;
+
+    if ( likely(!altp2m_active(d)) )
+    {
+        p2m_lock(p2m);
+        p2m->ept.ad = value;
+        p2m_unlock(p2m);
+
+        return;
+    }

Why would you want to skip updating the host p2m's flag when altp2m is active?

Quoted 5 lines
Quoted 3 lines

It's not really skipped if I understand the altp2m code correctly: in that case the hostp2m is d->arch.altp2m_p2m[0], which is take care of in the loop below the code you've quoted.

p2m_init_altp2m() (and other code in p2m.c) suggests otherwise to me.

That's interesting, p2m_set_mem_access() is treating altp2m index 0 as the hostp2m:

360 /*

361  * Set access type for a region of gfns.
362  * If gfn == INVALID_GFN, sets the default access type.
363  */

364 long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
365 uint32_t start, uint32_t mask,
xenmem_access_t access,
366 unsigned int altp2m_idx)
367 {

368     struct p2m_domain *p2m = p2m_get_hostp2m(d), *ap2m = NULL;
369     p2m_access_t a;
370     unsigned long gfn_l;
371     long rc = 0;

372
373 /* altp2m view 0 is treated as the hostp2m */
374 #ifdef CONFIG_HVM
375 if ( altp2m_idx )
376 {
377 if ( altp2m_idx >= MAX_ALTP2M ||
378 d->arch.altp2m_eptp[altp2m_idx] == mfn_x(INVALID_MFN) )
379 return -EINVAL;
380
381 ap2m = d->arch.altp2m_p2m[altp2m_idx];
382 }
383 #else
384 ASSERT(!altp2m_idx);
385 #endif

Quoted 3 lines

which would seem to imply that either we should be able to treat d->arch.altp2m_p2m[0] and hostp2m interchangeably, or we are currently wasting an altp2m array slot.

Yes, ISTR that altp2m_idx 0 was specifically meant to be the host p2m (unmodified). But there seems to be some confusion over that -- this seems to say it needs to be "manually" interpreted; some of the mem_access code seems to think that it can just grab d->arch.altp2m_p2m[0] and that will affect the hostp2m. And as you say, if we do the "manual interpretation", then we're allocating an extra p2m in slot 0 that we're not using.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel