x86/mm: put nested p2m code under CONFIG_HVM
authorWei Liu <wei.liu2@citrix.com>
Fri, 21 Sep 2018 15:54:50 +0000 (16:54 +0100)
committerWei Liu <wei.liu2@citrix.com>
Mon, 24 Sep 2018 16:45:36 +0000 (17:45 +0100)
These functions are only useful for nested hvm, which isn't enabled
when CONFIG_HVM is false.

Enclose relevant code and fields in CONFIG_HVM.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
xen/arch/x86/mm/p2m.c
xen/include/asm-x86/domain.h
xen/include/asm-x86/p2m.h

index 10ff54352ad79c26be8cd86bf3d71faabd0da6a4..3e680a84424ef63dbb78151adcf951f2f6159ae1 100644 (file)
@@ -49,23 +49,30 @@ boolean_param("hap_2mb", opt_hap_2mb);
 
 DEFINE_PERCPU_RWLOCK_GLOBAL(p2m_percpu_rwlock);
 
+static void p2m_nestedp2m_init(struct p2m_domain *p2m)
+{
+#ifdef CONFIG_HVM
+    INIT_LIST_HEAD(&p2m->np2m_list);
+
+    p2m->np2m_base = P2M_BASE_EADDR;
+    p2m->np2m_generation = 0;
+#endif
+}
+
 /* Init the datastructures for later use by the p2m code */
 static int p2m_initialise(struct domain *d, struct p2m_domain *p2m)
 {
     int ret = 0;
 
     mm_rwlock_init(&p2m->lock);
-    INIT_LIST_HEAD(&p2m->np2m_list);
     INIT_PAGE_LIST_HEAD(&p2m->pages);
 
     p2m->domain = d;
     p2m->default_access = p2m_access_rwx;
     p2m->p2m_class = p2m_host;
 
-    p2m->np2m_base = P2M_BASE_EADDR;
-    p2m->np2m_generation = 0;
-
     p2m_pod_init(p2m);
+    p2m_nestedp2m_init(p2m);
 
     if ( hap_enabled(d) && cpu_has_vmx )
         ret = ept_p2m_init(p2m);
@@ -137,6 +144,7 @@ static void p2m_teardown_hostp2m(struct domain *d)
     }
 }
 
+#ifdef CONFIG_HVM
 static void p2m_teardown_nestedp2m(struct domain *d)
 {
     unsigned int i;
@@ -174,6 +182,7 @@ static int p2m_init_nestedp2m(struct domain *d)
 
     return 0;
 }
+#endif
 
 static void p2m_teardown_altp2m(struct domain *d)
 {
@@ -221,6 +230,7 @@ int p2m_init(struct domain *d)
     if ( rc )
         return rc;
 
+#ifdef CONFIG_HVM
     /* Must initialise nestedp2m unconditionally
      * since nestedhvm_enabled(d) returns false here.
      * (p2m_init runs too early for HVM_PARAM_* options) */
@@ -230,12 +240,15 @@ int p2m_init(struct domain *d)
         p2m_teardown_hostp2m(d);
         return rc;
     }
+#endif
 
     rc = p2m_init_altp2m(d);
     if ( rc )
     {
         p2m_teardown_hostp2m(d);
+#ifdef CONFIG_HVM
         p2m_teardown_nestedp2m(d);
+#endif
     }
 
     return rc;
@@ -687,7 +700,9 @@ void p2m_final_teardown(struct domain *d)
      * we initialise them unconditionally.
      */
     p2m_teardown_altp2m(d);
+#ifdef CONFIG_HVM
     p2m_teardown_nestedp2m(d);
+#endif
 
     /* Iterate over all p2m tables per domain */
     p2m_teardown_hostp2m(d);
@@ -1713,6 +1728,7 @@ void p2m_altp2m_check(struct vcpu *v, uint16_t idx)
         p2m_switch_vcpu_altp2m_by_id(v, idx);
 }
 
+#ifdef CONFIG_HVM
 static struct p2m_domain *
 p2m_getlru_nestedp2m(struct domain *d, struct p2m_domain *p2m)
 {
@@ -1970,6 +1986,7 @@ void np2m_schedule(int dir)
         p2m_unlock(p2m);
     }
 }
+#endif
 
 unsigned long paging_gva_to_gfn(struct vcpu *v,
                                 unsigned long va,
index 4da4353de7865f5fb7c669435d4163a4c3c88f0c..b46cfb0ce4bf2e00122076eb94ba9490aec92e6b 100644 (file)
@@ -333,9 +333,11 @@ struct arch_domain
         void (*tail)(struct vcpu *);
     } *ctxt_switch;
 
+#ifdef CONFIG_HVM
     /* nestedhvm: translate l2 guest physical to host physical */
     struct p2m_domain *nested_p2m[MAX_NESTEDP2M];
     mm_lock_t nested_p2m_lock;
+#endif
 
     /* altp2m: allow multiple copies of host p2m */
     bool_t altp2m_active;
index fb4227532ea0c2ed271ca30f679b450572ac8f99..6def498b8e360b32865d212440430e7d89857725 100644 (file)
@@ -204,6 +204,7 @@ struct p2m_domain {
 
     p2m_class_t       p2m_class; /* host/nested/alternate */
 
+#ifdef CONFIG_HVM
     /* Nested p2ms only: nested p2m base value that this p2m shadows.
      * This can be cleared to P2M_BASE_EADDR under the per-p2m lock but
      * needs both the per-p2m lock and the per-domain nestedp2m lock
@@ -216,6 +217,7 @@ struct p2m_domain {
      * The host p2m hasolds the head of the list and the np2ms are 
      * threaded on in LRU order. */
     struct list_head   np2m_list;
+#endif
 
     /* Host p2m: Log-dirty ranges registered for the domain. */
     struct rangeset   *logdirty_ranges;
@@ -379,7 +381,11 @@ struct p2m_domain *p2m_get_p2m(struct vcpu *v);
 #define NP2M_SCHEDLE_IN  0
 #define NP2M_SCHEDLE_OUT 1
 
+#ifdef CONFIG_HVM
 void np2m_schedule(int dir);
+#else
+static inline void np2m_schedule(int dir) {}
+#endif
 
 static inline bool_t p2m_is_hostp2m(const struct p2m_domain *p2m)
 {