Skip to contentSkip to conversation

Cleaning up altp2m code

PATCH Superseded Paul Lai 2 participants 6 messages Sep 13, 2016 – Sep 26, 2016

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Paul Lai

author
#0 lore raw

v5 cover Cleaning up altp2m code

Altp2m cleanup work

The altp2m clean work is motivated by the following URLs:
https://lists.xenproject.org/archives/html/xen-devel/2015-07/msg04323.html
https://lists.xenproject.org/archives/html/xen-devel/2015-07/msg04454.html
https://lists.xenproject.org/archives/html/xen-devel/2015-07/msg04530.html

Most of the work has been:
Lots of white space, indentation, and other coding style preference corrections.
Lots of moving altp2m functions to the altp2m file.
Lots of moving ept functions to the ept file.
Lots of function return type corrections (and checking). Better sanity checking of values before processing in do_altp2m_op(). Just using 'return' after a if() clause instead of using a goto if the block is can be a one liner.

Most importantly here, we help submit Ravi Sahita's dynamically allocated altp2m domain for struct p2m. Also, Ravi introduces set_altp2m_active() and altp2m_active() APIs for better readability and maintainability.

Along the way, some dependencies have broken and we've waited for them to be fixed. Most recently the gfn() which caused a hang of the whole system. The gfn fixes are currently in staging. We've have verified against the staging branch that this series of patches functions as expected.

Paul Lai (3):
altp2m cleanup work.
Move altp2m specific functions to altp2m files.
Making altp2m domain dynamically allocated.

 xen/arch/x86/hvm/hvm.c            |  54 +++++++++----------
 xen/arch/x86/hvm/vmx/vmx.c        |   2 +-
 xen/arch/x86/mm/altp2m.c          |  57 ++++++++++++++++++++
 xen/arch/x86/mm/hap/hap.c         |  38 ++++----------
 xen/arch/x86/mm/mem_sharing.c     |   2 +-
 xen/arch/x86/mm/mm-locks.h        |   4 +-
 xen/arch/x86/mm/p2m-ept.c         |  39 ++++++++++++++
 xen/arch/x86/mm/p2m.c             | 106 +++++++++++++-------------------------
 xen/common/monitor.c              |   1 +
 xen/include/asm-x86/altp2m.h      |  11 +++-
 xen/include/asm-x86/domain.h      |   6 +--
 xen/include/asm-x86/hvm/hvm.h     |  22 ++++++--
 xen/include/asm-x86/hvm/vmx/vmx.h |   3 ++
 xen/include/asm-x86/p2m.h         |  18 ++++---
 14 files changed, 216 insertions(+), 147 deletions(-)
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#1 lore raw

PATCH v5 1/3 altp2m cleanup work.

Indent goto labels by one space.
Inline (header) altp2m functions.
In do_altp2m_op(), during the sanity check of the passed command, return -ENONSYS if not a valid command.
In do_altp2m_op(), when evaluating a command, ASSERT_UNREACHABLE() if the command is not recognizable. The sanity check above should have triggered the return of -ENOSYS.
Make altp2m_vcpu_emulate_ve() return actual bool_t (rather than return void()).

---
 xen/arch/x86/hvm/hvm.c        | 46 ++++++++++++++++++++-----------------------
 xen/include/asm-x86/hvm/hvm.h | 22 ++++++++++++++++++---
 2 files changed, 40 insertions(+), 28 deletions(-)
xen/arch/x86/hvm/hvm.c +21 -25
index 2c89984..1bf2d01 100644
@@ -1932,11 +1932,11 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,
      * Otherwise, this is an error condition. */
     rc = fall_through;
 
-out_put_gfn:
+ out_put_gfn:
     __put_gfn(p2m, gfn);
     if ( ap2m_active )
         __put_gfn(hostp2m, gfn);
-out:
+ out:
     /* All of these are delayed until we exit, since we might 
      * sleep on event ring wait queues, and we must not hold
      * locks in such circumstance */
@@ -5227,12 +5227,25 @@ static int do_altp2m_op(
         return -EFAULT;
 
     if ( a.pad1 || a.pad2 ||
-         (a.version != HVMOP_ALTP2M_INTERFACE_VERSION) ||
-         (a.cmd < HVMOP_altp2m_get_domain_state) ||
-         (a.cmd > HVMOP_altp2m_change_gfn) )
+        (a.version != HVMOP_ALTP2M_INTERFACE_VERSION) )
         return -EINVAL;
 
-    d = (a.cmd != HVMOP_altp2m_vcpu_enable_notify) ?
+    switch ( a.cmd )
+    {
+    case HVMOP_altp2m_get_domain_state:
+    case HVMOP_altp2m_set_domain_state:
+    case HVMOP_altp2m_vcpu_enable_notify:
+    case HVMOP_altp2m_create_p2m:
+    case HVMOP_altp2m_destroy_p2m:
+    case HVMOP_altp2m_switch_p2m:
+    case HVMOP_altp2m_set_mem_access:
+    case HVMOP_altp2m_change_gfn:
+        break;
+    default:
+        return -ENOSYS;
+    }
+
+    d = ( a.cmd != HVMOP_altp2m_vcpu_enable_notify ) ?
         rcu_lock_domain_by_any_id(a.domain) : rcu_lock_current_domain();
 
     if ( d == NULL )
@@ -5349,6 +5362,8 @@ static int do_altp2m_op(
             rc = p2m_change_altp2m_gfn(d, a.u.change_gfn.view,
                     _gfn(a.u.change_gfn.old_gfn),
                     _gfn(a.u.change_gfn.new_gfn));
+    default:
+        ASSERT_UNREACHABLE();
     }
 
  out:
@@ -5873,25 +5888,6 @@ void hvm_toggle_singlestep(struct vcpu *v)
     v->arch.hvm_vcpu.single_step = !v->arch.hvm_vcpu.single_step;
 }
 
-void altp2m_vcpu_update_p2m(struct vcpu *v)
-{
-    if ( hvm_funcs.altp2m_vcpu_update_p2m )
-        hvm_funcs.altp2m_vcpu_update_p2m(v);
-}
-
-void altp2m_vcpu_update_vmfunc_ve(struct vcpu *v)
-{
-    if ( hvm_funcs.altp2m_vcpu_update_vmfunc_ve )
-        hvm_funcs.altp2m_vcpu_update_vmfunc_ve(v);
-}
-
-bool_t altp2m_vcpu_emulate_ve(struct vcpu *v)
-{
-    if ( hvm_funcs.altp2m_vcpu_emulate_ve )
-        return hvm_funcs.altp2m_vcpu_emulate_ve(v);
-    return 0;
-}
-
 int hvm_set_mode(struct vcpu *v, int mode)
 {
 
xen/include/asm-x86/hvm/hvm.h +19 -3
index 5d463e0..f3c996d 100644
@@ -589,13 +589,29 @@ static inline bool_t hvm_altp2m_supported(void)
 }
 
 /* updates the current hardware p2m */
-void altp2m_vcpu_update_p2m(struct vcpu *v);
+static inline void altp2m_vcpu_update_p2m(struct vcpu *v)
+{
+    if ( hvm_funcs.altp2m_vcpu_update_p2m )
+        hvm_funcs.altp2m_vcpu_update_p2m(v);
+}
 
 /* updates VMCS fields related to VMFUNC and #VE */
-void altp2m_vcpu_update_vmfunc_ve(struct vcpu *v);
+static inline void altp2m_vcpu_update_vmfunc_ve(struct vcpu *v)
+{
+    if ( hvm_funcs.altp2m_vcpu_update_vmfunc_ve )
+        hvm_funcs.altp2m_vcpu_update_vmfunc_ve(v);
+}
 
 /* emulates #VE */
-bool_t altp2m_vcpu_emulate_ve(struct vcpu *v);
+static inline bool_t altp2m_vcpu_emulate_ve(struct vcpu *v)
+{
+    if ( hvm_funcs.altp2m_vcpu_emulate_ve )
+    {
+        hvm_funcs.altp2m_vcpu_emulate_ve(v);
+        return true;
+    }
+    return false;
+}
 
 /* Check CR4/EFER values */
 const char *hvm_efer_valid(const struct vcpu *v, uint64_t value,
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH Altp2m cleanup v5 1/3] altp2m cleanup work.

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 13.09.16 at 18:46, <[email protected]> wrote:

Indent goto labels by one space.
Inline (header) altp2m functions.
In do_altp2m_op(), during the sanity check of the passed command, return -ENONSYS if not a valid command.
In do_altp2m_op(), when evaluating a command, ASSERT_UNREACHABLE() if the command is not recognizable. The sanity check above should have triggered the return of -ENOSYS.
Make altp2m_vcpu_emulate_ve() return actual bool_t (rather than return void()).

Quoted 2 lines

---

It is very disappointing to find that there is still no information here on what changed from the previous version.

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 5367

Quoted 7 lines
xen/arch/x86/hvm/hvm.c +2 -0
@@ -5349,6 +5362,8 @@ static int do_altp2m_op(
             rc = p2m_change_altp2m_gfn(d, a.u.change_gfn.view,
                     _gfn(a.u.change_gfn.old_gfn),
                     _gfn(a.u.change_gfn.new_gfn));
+    default:
+        ASSERT_UNREACHABLE();
     }

And it is even worse that the bug pointed out here is still present.

xen/include/asm-x86/hvm/hvm.h static inline bool_t hvm_altp2m_supported(void) · line 606

Quoted 3 lines
xen/include/asm-x86/hvm/hvm.h +1 -1
 /* emulates #VE */
-bool_t altp2m_vcpu_emulate_ve(struct vcpu *v);
+static inline bool_t altp2m_vcpu_emulate_ve(struct vcpu *v)

Nor did you switch to plain bool here, as was requested during both v3 and v4 review.

Please do not resubmit this series until you have taken care of _all_ review comments you've received so far. As with the previous version I'm not going to spend time looking at the other two patches due to this fundamental requirement, despite having been pointed out before, not being met.

Jan

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

author
#3 lore raw

Re: [PATCH Altp2m cleanup v5 1/3] altp2m cleanup work.

Quoted 17 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 13.09.16 at 18:46, <[email protected]> wrote:

Indent goto labels by one space.
Inline (header) altp2m functions.
In do_altp2m_op(), during the sanity check of the passed command, return -ENONSYS if not a valid command.
In do_altp2m_op(), when evaluating a command, ASSERT_UNREACHABLE() if the command is not recognizable. The sanity check above should have triggered the return of -ENOSYS.
Make altp2m_vcpu_emulate_ve() return actual bool_t (rather than return void()).

Quoted 2 lines

---

It is very disappointing to find that there is still no information here on what changed from the previous version.

Quoted 9 lines

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 5367

Quoted 7 lines
xen/arch/x86/hvm/hvm.c +2 -0
@@ -5349,6 +5362,8 @@ static int do_altp2m_op(
             rc = p2m_change_altp2m_gfn(d, a.u.change_gfn.view,
                     _gfn(a.u.change_gfn.old_gfn),
                     _gfn(a.u.change_gfn.new_gfn));
+    default:
+        ASSERT_UNREACHABLE();
     }

And it is even worse that the bug pointed out here is still present.

I reread the comment in
https://lists.xenproject.org/archives/html/xen-devel/2016-09/msg00937.html
and missed the "unintended fallthrough".
Will correct.

Quoted 7 lines

xen/include/asm-x86/hvm/hvm.h static inline bool_t hvm_altp2m_supported(void) · line 606

Quoted 4 lines
xen/include/asm-x86/hvm/hvm.h +1 -1
 /* emulates #VE */
-bool_t altp2m_vcpu_emulate_ve(struct vcpu *v);
+static inline bool_t altp2m_vcpu_emulate_ve(struct vcpu *v)

Nor did you switch to plain bool here, as was requested during both v3 and v4 review.

I did not know "bool" existed, and thought "plain bool" was "bool_t". I have looked around and see that "bool" is better defined ({0,1} instead of {0, !0}) and hopefully understand your motivation for using/requiring it.

Quoted 9 lines

Please do not resubmit this series until you have taken care of _all_ review comments you've received so far. As with the previous version I'm not going to spend time looking at the other two patches due to this fundamental requirement, despite having been pointed out before, not being met.

Jan

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

author
#4 lore raw

PATCH v5 2/3 Move altp2m specific functions to altp2m files.

In reply to Paul Lai

This makes the code a little easier to read.
Moving hvm_altp2m_supported() check into functions that use it for better readability.
Moving ept code to ept specific files as requested in:
https://lists.xenproject.org/archives/html/xen-devel/2015-07/msg04323.html
Renamed p2m_init_altp2m_helper() to p2m_init_altp2m_ept(). Got rid of stray blanks after open paren after function names. Defining _XEN_ASM_X86_P2M_H instead of _XEN_P2M_H for xen/include/asm-x86/p2m.h.

---
 xen/arch/x86/mm/altp2m.c          | 57 +++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/mm/hap/hap.c         | 38 +++++++-------------------
 xen/arch/x86/mm/p2m-ept.c         | 39 +++++++++++++++++++++++++++
 xen/arch/x86/mm/p2m.c             | 45 +++----------------------------
 xen/include/asm-x86/altp2m.h      |  4 ++-
 xen/include/asm-x86/hvm/vmx/vmx.h |  3 +++
 xen/include/asm-x86/p2m.h         |  9 +++----
 7 files changed, 117 insertions(+), 78 deletions(-)
xen/arch/x86/mm/altp2m.c +57 -0
index 930bdc2..62801ae 100644
@@ -17,6 +17,7 @@
 
 #include <asm/hvm/support.h>
 #include <asm/hvm/hvm.h>
+#include <asm/domain.h>
 #include <asm/p2m.h>
 #include <asm/altp2m.h>
 
@@ -66,6 +67,62 @@ altp2m_vcpu_destroy(struct vcpu *v)
 }
 
 /*
+ * altp2m_domain_init(struct domain *d))
+ *  allocate and initialize memory for altp2m portion of domain
+ *
+ *  returns < 0 on error
+ *  returns 0 on no operation (success)
+ *  returns > 0 on success
+ */
+int
+altp2m_domain_init(struct domain *d)
+{
+    int rc;
+    unsigned int i;
+
+    if ( d == NULL)
+        return 0;
+
+    if ( !hvm_altp2m_supported() )
+        return 0;
+
+    /* Init alternate p2m data. */
+    if ( (d->arch.altp2m_eptp = alloc_xenheap_page()) == NULL )
+        return -ENOMEM;
+
+    for ( i = 0; i < MAX_EPTP; i++ )
+        d->arch.altp2m_eptp[i] = mfn_x(INVALID_MFN);
+
+    for ( i = 0; i < MAX_ALTP2M; i++ )
+    {
+        rc = p2m_alloc_table(d->arch.altp2m_p2m[i]);
+        if ( rc != 0 )
+           return rc;
+    }
+
+    d->arch.altp2m_active = 0;
+
+    return rc;
+}
+
+void
+altp2m_domain_teardown(struct domain *d)
+{
+    unsigned int i;
+
+    if ( !hvm_altp2m_supported() )
+        return;
+
+    d->arch.altp2m_active = 0;
+
+    free_xenheap_page(d->arch.altp2m_eptp);
+    d->arch.altp2m_eptp = NULL;
+
+    for ( i = 0; i < MAX_ALTP2M; i++ )
+        p2m_teardown(d->arch.altp2m_p2m[i]);
+}
+
+/*
  * Local variables:
  * mode: C
  * c-file-style: "BSD"
xen/arch/x86/mm/hap/hap.c +9 -29
index 3218fa2..61c0c42 100644
@@ -37,6 +37,7 @@
 #include <asm/hap.h>
 #include <asm/paging.h>
 #include <asm/p2m.h>
+#include <asm/altp2m.h>
 #include <asm/domain.h>
 #include <xen/numa.h>
 #include <asm/hvm/nestedhvm.h>
@@ -499,26 +500,17 @@ int hap_enable(struct domain *d, u32 mode)
            goto out;
     }
 
-    if ( hvm_altp2m_supported() )
+    if ( (rv = altp2m_domain_init(d)) < 0 )
     {
-        /* Init alternate p2m data */
-        if ( (d->arch.altp2m_eptp = alloc_xenheap_page()) == NULL )
-        {
-            rv = -ENOMEM;
-            goto out;
+        for (i = 0; i < MAX_NESTEDP2M; i++) {
+            p2m_teardown(d->arch.nested_p2m[i]);
         }
 
-        for ( i = 0; i < MAX_EPTP; i++ )
-            d->arch.altp2m_eptp[i] = mfn_x(INVALID_MFN);
-
-        for ( i = 0; i < MAX_ALTP2M; i++ )
-        {
-            rv = p2m_alloc_table(d->arch.altp2m_p2m[i]);
-            if ( rv != 0 )
-               goto out;
-        }
+        if ( d->arch.paging.hap.total_pages != 0 )
+            hap_teardown(d, NULL);
 
-        d->arch.altp2m_active = 0;
+        p2m_teardown(p2m_get_hostp2m(d));
+        goto out;
     }
 
     /* Now let other users see the new mode */
@@ -533,19 +525,7 @@ void hap_final_teardown(struct domain *d)
 {
     unsigned int i;
 
-    if ( hvm_altp2m_supported() )
-    {
-        d->arch.altp2m_active = 0;
-
-        if ( d->arch.altp2m_eptp )
-        {
-            free_xenheap_page(d->arch.altp2m_eptp);
-            d->arch.altp2m_eptp = NULL;
-        }
-
-        for ( i = 0; i < MAX_ALTP2M; i++ )
-            p2m_teardown(d->arch.altp2m_p2m[i]);
-    }
+    altp2m_domain_teardown(d);
 
     /* Destroy nestedp2m's first */
     for (i = 0; i < MAX_NESTEDP2M; i++) {
xen/arch/x86/mm/p2m-ept.c +39 -0
index 13cab24..04878f5 100644
@@ -1329,6 +1329,45 @@ void setup_ept_dump(void)
     register_keyhandler('D', ept_dump_p2m_table, "dump VT-x EPT tables", 0);
 }
 
+void p2m_init_altp2m_ept(struct domain *d, unsigned int i)
+{
+    struct p2m_domain *p2m = d->arch.altp2m_p2m[i];
+    struct ept_data *ept;
+
+    p2m->min_remapped_gfn = gfn_x(INVALID_GFN);
+    p2m->max_remapped_gfn = 0;
+    ept = &p2m->ept;
+    ept->asr = pagetable_get_pfn(p2m_get_pagetable(p2m));
+    d->arch.altp2m_eptp[i] = ept_get_eptp(ept);
+}
+
+unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp)
+{
+    struct p2m_domain *p2m;
+    struct ept_data *ept;
+    unsigned int i;
+
+    altp2m_list_lock(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];
+        ept = &p2m->ept;
+
+        if ( eptp == ept_get_eptp(ept) )
+            goto out;
+    }
+
+    i = INVALID_ALTP2M;
+
+ out:
+    altp2m_list_unlock(d);
+    return i;
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/mm/p2m.c +3 -42

76 lines not on this page · raw message

xen/include/asm-x86/altp2m.h +3 -1
index 64c7618..0090c89 100644
@@ -18,7 +18,6 @@
 #ifndef __ASM_X86_ALTP2M_H
 #define __ASM_X86_ALTP2M_H
 
-#include <xen/types.h>
 #include <xen/sched.h>         /* for struct vcpu, struct domain */
 #include <asm/hvm/vcpu.h>      /* for vcpu_altp2m */
 
@@ -38,4 +37,7 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
     return vcpu_altp2m(v).p2midx;
 }
 
+int altp2m_domain_init(struct domain *d);
+void altp2m_domain_teardown(struct domain *d);
+
 #endif /* __ASM_X86_ALTP2M_H */
xen/include/asm-x86/hvm/vmx/vmx.h +3 -0
index 4cdd9b1..9f4c7de 100644
@@ -561,6 +561,9 @@ void ept_p2m_uninit(struct p2m_domain *p2m);
 void ept_walk_table(struct domain *d, unsigned long gfn);
 bool_t ept_handle_misconfig(uint64_t gpa);
 void setup_ept_dump(void);
+void p2m_init_altp2m_ept(struct domain *d, unsigned int i);
+/* Locate an alternate p2m by its EPTP */
+unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp);
 
 void update_guest_eip(void);
 
xen/include/asm-x86/p2m.h +3 -6
index d5fd546..0c5b391 100644
@@ -23,8 +23,8 @@
  * along with this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _XEN_P2M_H
-#define _XEN_P2M_H
+#ifndef _XEN_ASM_X86_P2M_H
+#define _XEN_ASM_X86_P2M_H
 
 #include <xen/config.h>
 #include <xen/paging.h>
@@ -781,9 +781,6 @@ static inline struct p2m_domain *p2m_get_altp2m(struct vcpu *v)
     return v->domain->arch.altp2m_p2m[index];
 }
 
-/* Locate an alternate p2m by its EPTP */
-unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp);
-
 /* Switch alternate p2m for a single vcpu */
 bool_t p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, unsigned int idx);
 
@@ -845,7 +842,7 @@ static inline unsigned int p2m_get_iommu_flags(p2m_type_t p2mt)
     return flags;
 }
 
-#endif /* _XEN_P2M_H */
+#endif /* _XEN_ASM_X86_P2M_H */
 
 /*
  * Local variables:
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#5 lore raw

PATCH v5 3/3 Making altp2m domain dynamically allocated.

In reply to Paul Lai

Ravi Sahita's dynamically allocated altp2m domain. Introduce set_altp2m_active() and altp2m_active() api()s.

---
 xen/arch/x86/hvm/hvm.c        |  8 +++---
 xen/arch/x86/hvm/vmx/vmx.c    |  2 +-
 xen/arch/x86/mm/altp2m.c      | 16 +++++------
 xen/arch/x86/mm/mem_sharing.c |  2 +-
 xen/arch/x86/mm/mm-locks.h    |  4 +--
 xen/arch/x86/mm/p2m-ept.c     | 10 +++----
 xen/arch/x86/mm/p2m.c         | 63 ++++++++++++++++++++++++-------------------
 xen/common/monitor.c          |  1 +
 xen/include/asm-x86/altp2m.h  |  7 ++++-
 xen/include/asm-x86/domain.h  |  6 ++---
 xen/include/asm-x86/p2m.h     |  9 ++++++-
 11 files changed, 73 insertions(+), 55 deletions(-)
xen/arch/x86/hvm/hvm.c +4 -4
index 1bf2d01..ac692ab 100644
@@ -5259,7 +5259,7 @@ static int do_altp2m_op(
 
     if ( (a.cmd != HVMOP_altp2m_get_domain_state) &&
          (a.cmd != HVMOP_altp2m_set_domain_state) &&
-         !d->arch.altp2m_active )
+         !altp2m_active(d) )
     {
         rc = -EOPNOTSUPP;
         goto out;
@@ -5293,11 +5293,11 @@ static int do_altp2m_op(
             break;
         }
 
-        ostate = d->arch.altp2m_active;
-        d->arch.altp2m_active = !!a.u.domain_state.state;
+        ostate = altp2m_active(d);
+        set_altp2m_active(d, a.u.domain_state.state);
 
         /* If the alternate p2m state has changed, handle appropriately */
-        if ( d->arch.altp2m_active != ostate &&
+        if ( altp2m_active(d) != ostate &&
              (ostate || !(rc = p2m_init_altp2m_by_id(d, 0))) )
         {
             for_each_vcpu( d, v )
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index bb7a329..699e9b1 100644
@@ -2018,7 +2018,7 @@ static void vmx_vcpu_update_vmfunc_ve(struct vcpu *v)
     {
         v->arch.hvm_vmx.secondary_exec_control |= mask;
         __vmwrite(VM_FUNCTION_CONTROL, VMX_VMFUNC_EPTP_SWITCHING);
-        __vmwrite(EPTP_LIST_ADDR, virt_to_maddr(d->arch.altp2m_eptp));
+        __vmwrite(EPTP_LIST_ADDR, virt_to_maddr(d->arch.altp2m->eptp));
 
         if ( cpu_has_vmx_virt_exceptions )
         {
xen/arch/x86/mm/altp2m.c +8 -8
index 62801ae..7917a1e 100644
@@ -87,20 +87,20 @@ altp2m_domain_init(struct domain *d)
         return 0;
 
     /* Init alternate p2m data. */
-    if ( (d->arch.altp2m_eptp = alloc_xenheap_page()) == NULL )
+    if ( (d->arch.altp2m->eptp = alloc_xenheap_page()) == NULL )
         return -ENOMEM;
 
     for ( i = 0; i < MAX_EPTP; i++ )
-        d->arch.altp2m_eptp[i] = mfn_x(INVALID_MFN);
+        d->arch.altp2m->eptp[i] = mfn_x(INVALID_MFN);
 
     for ( i = 0; i < MAX_ALTP2M; i++ )
     {
-        rc = p2m_alloc_table(d->arch.altp2m_p2m[i]);
+        rc = p2m_alloc_table(d->arch.altp2m->p2m[i]);
         if ( rc != 0 )
            return rc;
     }
 
-    d->arch.altp2m_active = 0;
+    set_altp2m_active(d, false);
 
     return rc;
 }
@@ -113,13 +113,13 @@ altp2m_domain_teardown(struct domain *d)
     if ( !hvm_altp2m_supported() )
         return;
 
-    d->arch.altp2m_active = 0;
+    set_altp2m_active(d, false);
 
-    free_xenheap_page(d->arch.altp2m_eptp);
-    d->arch.altp2m_eptp = NULL;
+    free_xenheap_page(d->arch.altp2m->eptp);
+    d->arch.altp2m->eptp = NULL;
 
     for ( i = 0; i < MAX_ALTP2M; i++ )
-        p2m_teardown(d->arch.altp2m_p2m[i]);
+        p2m_teardown(d->arch.altp2m->p2m[i]);
 }
 
 /*
xen/arch/x86/mm/mem_sharing.c +1 -1
index e7c6b74..3fd8380 100644
@@ -877,7 +877,7 @@ int mem_sharing_nominate_page(struct domain *d,
 
         for ( i = 0; i < MAX_ALTP2M; i++ )
         {
-            ap2m = d->arch.altp2m_p2m[i];
+            ap2m = d->arch.altp2m->p2m[i];
             if ( !ap2m )
                 continue;
 
xen/arch/x86/mm/mm-locks.h +2 -2
index 74fdfc1..71d3891 100644
@@ -266,8 +266,8 @@ declare_mm_order_constraint(per_page_sharing)
  */
 
 declare_mm_lock(altp2mlist)
-#define altp2m_list_lock(d)   mm_lock(altp2mlist, &(d)->arch.altp2m_list_lock)
-#define altp2m_list_unlock(d) mm_unlock(&(d)->arch.altp2m_list_lock)
+#define altp2m_list_lock(d)   mm_lock(altp2mlist, &(d)->arch.altp2m->list_lock)
+#define altp2m_list_unlock(d) mm_unlock(&(d)->arch.altp2m->list_lock)
 
 /* P2M lock (per-altp2m-table)
  *
xen/arch/x86/mm/p2m-ept.c +5 -5
index 04878f5..9459d87 100644
@@ -1331,14 +1331,14 @@ 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 *p2m = d->arch.altp2m->p2m[i];
     struct ept_data *ept;
 
     p2m->min_remapped_gfn = gfn_x(INVALID_GFN);
-    p2m->max_remapped_gfn = 0;
+    p2m->max_remapped_gfn = gfn_x(_gfn(0UL));
     ept = &p2m->ept;
     ept->asr = pagetable_get_pfn(p2m_get_pagetable(p2m));
-    d->arch.altp2m_eptp[i] = ept_get_eptp(ept);
+    d->arch.altp2m->eptp[i] = ept_get_eptp(ept);
 }
 
 unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp)
@@ -1351,10 +1351,10 @@ unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp)
 
     for ( i = 0; i < MAX_ALTP2M; i++ )
     {
-        if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
+        if ( d->arch.altp2m->eptp[i] == mfn_x(INVALID_MFN) )
             continue;
 
-        p2m = d->arch.altp2m_p2m[i];
+        p2m = d->arch.altp2m->p2m[i];
         ept = &p2m->ept;
 
         if ( eptp == ept_get_eptp(ept) )
xen/arch/x86/mm/p2m.c +35 -28

156 lines not on this page · raw message

xen/common/monitor.c +1 -0
index c73d1d5..d6b3f90 100644
@@ -24,6 +24,7 @@
 #include <xen/sched.h>
 #include <xen/vm_event.h>
 #include <xsm/xsm.h>
+#include <asm/p2m.h>
 #include <asm/altp2m.h>
 #include <asm/monitor.h>
 #include <asm/vm_event.h>
xen/include/asm-x86/altp2m.h +6 -1
index 0090c89..65a7ead 100644
@@ -24,7 +24,12 @@
 /* Alternate p2m HVM on/off per domain */
 static inline bool_t altp2m_active(const struct domain *d)
 {
-    return d->arch.altp2m_active;
+    return d->arch.altp2m->active;
+}
+
+static inline void set_altp2m_active(const struct domain *d, bool_t v)
+{
+    d->arch.altp2m->active = v;
 }
 
 /* Alternate p2m VCPU */
xen/include/asm-x86/domain.h +2 -4
index 5807a1f..3b9fcc1 100644
@@ -242,6 +242,7 @@ typedef xen_domctl_cpuid_t cpuid_input_t;
 #define INVALID_ALTP2M  0xffff
 #define MAX_EPTP        (PAGE_SIZE / sizeof(uint64_t))
 struct p2m_domain;
+struct altp2m_domain;
 struct time_scale {
     int shift;
     u32 mul_frac;
@@ -320,10 +321,7 @@ struct arch_domain
     mm_lock_t nested_p2m_lock;
 
     /* altp2m: allow multiple copies of host p2m */
-    bool_t altp2m_active;
-    struct p2m_domain *altp2m_p2m[MAX_ALTP2M];
-    mm_lock_t altp2m_list_lock;
-    uint64_t *altp2m_eptp;
+    struct altp2m_domain *altp2m;
 
     /* NB. protected by d->event_lock and by irq_desc[irq].lock */
     struct radix_tree_root irq_pirq;
xen/include/asm-x86/p2m.h +8 -1
index 0c5b391..cf30924 100644
@@ -338,6 +338,13 @@ struct p2m_domain {
     };
 };
 
+struct altp2m_domain {
+    bool_t active;
+    struct p2m_domain *p2m[MAX_ALTP2M];
+    mm_lock_t list_lock;
+    uint64_t *eptp;
+};
+
 /* get host p2m table */
 #define p2m_get_hostp2m(d)      ((d)->arch.p2m)
 
@@ -778,7 +785,7 @@ static inline struct p2m_domain *p2m_get_altp2m(struct vcpu *v)
 
     BUG_ON(index >= MAX_ALTP2M);
 
-    return v->domain->arch.altp2m_p2m[index];
+    return v->domain->arch.altp2m->p2m[index];
 }
 
 /* Switch alternate p2m for a single vcpu */
Signature · 7 lines
2.7.4


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