All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>, Jan Beulich <jbeulich@suse.com>
Subject: [PATCH for-next v3 08/12] x86/domain: factor out pv_domain_initialise
Date: Wed, 26 Apr 2017 16:54:53 +0100	[thread overview]
Message-ID: <20170426155457.10799-9-wei.liu2@citrix.com> (raw)
In-Reply-To: <20170426155457.10799-1-wei.liu2@citrix.com>

Lump everything PV related in arch_domain_create into
pv_domain_initialise.

Though domcr_flags and config are not necessary, the new function is
given those to match hvm counterpart.

Since it cleans up after itself there is no need to clean up in
arch_domain_create in case of failure. Remove the initialiser of rc in
arch_domain_create.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/domain.c | 88 +++++++++++++++++++++++++++++----------------------
 1 file changed, 51 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index a904e4ecb6..cb104c6730 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -550,11 +550,54 @@ static void pv_domain_destroy(struct domain *d)
     d->arch.pv_domain.gdt_ldt_l1tab = NULL;
 }
 
+static int pv_domain_initialise(struct domain *d, unsigned int domcr_flags,
+                                struct xen_arch_domainconfig *config)
+{
+    static const struct arch_csw pv_csw = {
+        .from = paravirt_ctxt_switch_from,
+        .to   = paravirt_ctxt_switch_to,
+        .tail = continue_nonidle_domain,
+    };
+    int rc = -ENOMEM;
+
+    d->arch.pv_domain.gdt_ldt_l1tab =
+        alloc_xenheap_pages(0, MEMF_node(domain_to_node(d)));
+    if ( !d->arch.pv_domain.gdt_ldt_l1tab )
+        goto fail;
+    clear_page(d->arch.pv_domain.gdt_ldt_l1tab);
+
+    if ( levelling_caps & ~LCAP_faulting )
+    {
+        d->arch.pv_domain.cpuidmasks = xmalloc(struct cpuidmasks);
+        if ( !d->arch.pv_domain.cpuidmasks )
+            goto fail;
+        *d->arch.pv_domain.cpuidmasks = cpuidmask_defaults;
+    }
+
+    rc = create_perdomain_mapping(d, GDT_LDT_VIRT_START,
+                                  GDT_LDT_MBYTES << (20 - PAGE_SHIFT),
+                                  NULL, NULL);
+    if ( rc )
+        goto fail;
+
+    d->arch.ctxt_switch = &pv_csw;
+
+    /* 64-bit PV guest by default. */
+    d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 0;
+
+    return 0;
+
+ fail:
+    pv_domain_destroy(d);
+
+    return rc;
+}
+
 int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                        struct xen_arch_domainconfig *config)
 {
     bool paging_initialised = false;
-    int rc = -ENOMEM;
+    int rc;
 
     if ( config == NULL && !is_idle_domain(d) )
         return -EINVAL;
@@ -610,30 +653,6 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
         d->arch.emulation_flags = emflags;
     }
 
-    rc = 0; /* HVM and idle domain */
-    if ( is_pv_domain(d) )
-    {
-        d->arch.pv_domain.gdt_ldt_l1tab =
-            alloc_xenheap_pages(0, MEMF_node(domain_to_node(d)));
-        if ( !d->arch.pv_domain.gdt_ldt_l1tab )
-            goto fail;
-        clear_page(d->arch.pv_domain.gdt_ldt_l1tab);
-
-        if ( levelling_caps & ~LCAP_faulting )
-        {
-            d->arch.pv_domain.cpuidmasks = xmalloc(struct cpuidmasks);
-            if ( !d->arch.pv_domain.cpuidmasks )
-                goto fail;
-            *d->arch.pv_domain.cpuidmasks = cpuidmask_defaults;
-        }
-
-        rc = create_perdomain_mapping(d, GDT_LDT_VIRT_START,
-                                      GDT_LDT_MBYTES << (20 - PAGE_SHIFT),
-                                      NULL, NULL);
-    }
-    if ( rc )
-        goto fail;
-
     mapcache_domain_init(d);
 
     HYPERVISOR_COMPAT_VIRT_START(d) =
@@ -681,23 +700,20 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
         if ( (rc = hvm_domain_initialise(d, domcr_flags, config)) != 0 )
             goto fail;
     }
-    else
+    else if ( is_idle_domain(d) )
     {
-        static const struct arch_csw pv_csw = {
-            .from = paravirt_ctxt_switch_from,
-            .to   = paravirt_ctxt_switch_to,
-            .tail = continue_nonidle_domain,
-        };
         static const struct arch_csw idle_csw = {
             .from = paravirt_ctxt_switch_from,
             .to   = paravirt_ctxt_switch_to,
             .tail = continue_idle_domain,
         };
 
-        d->arch.ctxt_switch = is_idle_domain(d) ? &idle_csw : &pv_csw;
-
-        /* 64-bit PV guest by default. */
-        d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 0;
+        d->arch.ctxt_switch = &idle_csw;
+    }
+    else
+    {
+        if ( (rc = pv_domain_initialise(d, domcr_flags, config)) != 0 )
+            goto fail;
     }
 
     /* initialize default tsc behavior in case tools don't */
@@ -724,8 +740,6 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     xfree(d->arch.cpuid);
     if ( paging_initialised )
         paging_final_teardown(d);
-    if ( is_pv_domain(d) )
-        pv_domain_destroy(d);
     free_perdomain_mappings(d);
 
     return rc;
-- 
2.11.0


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

  parent reply	other threads:[~2017-04-26 15:59 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-26 15:54 [PATCH for-next v3 00/12] x86: refactor x86/domain.c Wei Liu
2017-04-26 15:54 ` [PATCH for-next v3 01/12] x86/mm: make free_perdomain_mappings idempotent Wei Liu
2017-04-27 10:40   ` George Dunlap
2017-04-26 15:54 ` [PATCH for-next v3 02/12] x86/domain: provide pv_{create, destroy}_gdt_ldt_l1tab and use them Wei Liu
2017-04-28  8:39   ` Jan Beulich
2017-04-26 15:54 ` [PATCH for-next v3 03/12] x86/domain: make release_compact_l4 NULL tolerant Wei Liu
2017-04-26 15:54 ` [PATCH for-next v3 04/12] x86/domain: factor out pv_vcpu_destroy Wei Liu
2017-04-26 15:54 ` [PATCH for-next v3 05/12] x86/domain: factor out pv_vcpu_initialise Wei Liu
2017-04-28  8:41   ` Jan Beulich
2017-04-26 15:54 ` [PATCH for-next v3 06/12] x86/domain: push some code down to hvm_domain_initialise Wei Liu
2017-05-31 18:06   ` Wei Liu
2017-06-01 11:10     ` Wei Liu
2017-06-01 11:19       ` Jan Beulich
2017-06-01 11:42         ` Wei Liu
2017-04-26 15:54 ` [PATCH for-next v3 07/12] x86/domain: factor out pv_domain_destroy Wei Liu
2017-04-28  8:41   ` Jan Beulich
2017-04-26 15:54 ` Wei Liu [this message]
2017-04-26 15:54 ` [PATCH for-next v3 09/12] x86/domain: move PV specific code to pv/domain.c Wei Liu
2017-04-28  8:47   ` Jan Beulich
2017-04-28 10:54     ` Wei Liu
2017-04-28 12:24       ` Jan Beulich
2017-04-28 12:54         ` Wei Liu
2017-04-26 15:54 ` [PATCH for-next v3 10/12] x86/domain: move HVM specific code to hvm/domain.c Wei Liu
2017-04-26 15:54 ` [PATCH for-next v3 11/12] x86/pv/domain: clean up setup_compat_l4 Wei Liu
2017-04-28  8:49   ` Jan Beulich
2017-04-26 15:54 ` [PATCH for-next v3 12/12] x86/pv/domain: clean up switch_compat Wei Liu
2017-04-28  8:51   ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170426155457.10799-9-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.