diff mbox

[for-next,v3,02/12] x86/domain: provide pv_{create, destroy}_gdt_ldt_l1tab and use them

Message ID 20170426155457.10799-3-wei.liu2@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Liu April 26, 2017, 3:54 p.m. UTC
This patch encapsulates the perdomain creation and destruction into
helper functions and use them where appropriate.

Since destroy_perdomain_mapping is idempotent, it is safe to call the
destruction function multiple times.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2: new

v3: use 1U and eliminate d as parameter

Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/domain.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

Comments

Jan Beulich April 28, 2017, 8:39 a.m. UTC | #1
>>> On 26.04.17 at 17:54, <wei.liu2@citrix.com> wrote:
> This patch encapsulates the perdomain creation and destruction into
> helper functions and use them where appropriate.
> 
> Since destroy_perdomain_mapping is idempotent, it is safe to call the
> destruction function multiple times.
> 
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>
diff mbox

Patch

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 90e2b1f82a..31ef4c0293 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -387,6 +387,20 @@  int switch_compat(struct domain *d)
     return rc;
 }
 
+static int pv_create_gdt_ldt_l1tab(struct vcpu *v)
+{
+    return create_perdomain_mapping(v->domain, GDT_VIRT_START(v),
+                                    1U << GDT_LDT_VCPU_SHIFT,
+                                    v->domain->arch.pv_domain.gdt_ldt_l1tab,
+                                    NULL);
+}
+
+static void pv_destroy_gdt_ldt_l1tab(struct vcpu *v)
+{
+    destroy_perdomain_mapping(v->domain, GDT_VIRT_START(v),
+                              1U << GDT_LDT_VCPU_SHIFT);
+}
+
 int vcpu_initialise(struct vcpu *v)
 {
     struct domain *d = v->domain;
@@ -423,9 +437,7 @@  int vcpu_initialise(struct vcpu *v)
 
     if ( !is_idle_domain(d) )
     {
-        rc = create_perdomain_mapping(d, GDT_VIRT_START(v),
-                                      1 << GDT_LDT_VCPU_SHIFT,
-                                      d->arch.pv_domain.gdt_ldt_l1tab, NULL);
+        rc = pv_create_gdt_ldt_l1tab(v);
         if ( rc )
             goto done;
 
@@ -435,6 +447,7 @@  int vcpu_initialise(struct vcpu *v)
                                                   NR_VECTORS);
         if ( !v->arch.pv_vcpu.trap_ctxt )
         {
+            pv_destroy_gdt_ldt_l1tab(v);
             rc = -ENOMEM;
             goto done;
         }
@@ -464,7 +477,10 @@  int vcpu_initialise(struct vcpu *v)
         vcpu_destroy_fpu(v);
 
         if ( is_pv_domain(d) )
+        {
+            pv_destroy_gdt_ldt_l1tab(v);
             xfree(v->arch.pv_vcpu.trap_ctxt);
+        }
     }
     else if ( !is_idle_domain(v->domain) )
         vpmu_initialise(v);
@@ -491,7 +507,10 @@  void vcpu_destroy(struct vcpu *v)
     if ( is_hvm_vcpu(v) )
         hvm_vcpu_destroy(v);
     else
+    {
+        pv_destroy_gdt_ldt_l1tab(v);
         xfree(v->arch.pv_vcpu.trap_ctxt);
+    }
 }
 
 static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)