x86/P2M: PoD, altp2m, and nested-p2m are HVM-only
authorJan Beulich <jbeulich@suse.com>
Fri, 8 Apr 2022 12:41:51 +0000 (14:41 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 8 Apr 2022 12:41:51 +0000 (14:41 +0200)
There's no need to initialize respective data for PV domains. Note that
p2m_teardown_{alt,nested}p2m() will handle the lack-of-initialization
case fine.

As a result, despite PV domains having a host P2M associated with them
and hence using XENMEM_get_pod_target on such may not be a real problem,
calling p2m_pod_set_mem_target() for a PV domain is surely wrong, even
if benign at present. Add a guard there as well.

In p2m_pod_demand_populate() the situation is a little different: This
function is reachable only for HVM domains anyway, but following from
other PoD functions only ever acting on the host P2M (and hence PoD
entries only ever existing in host P2Ms), assert and bail from there for
non-host-P2Ms.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
xen/arch/x86/include/asm/p2m.h
xen/arch/x86/mm.c
xen/arch/x86/mm/p2m-pod.c
xen/arch/x86/mm/p2m.c
xen/arch/x86/mm/p2m.h [new file with mode: 0644]

index 30236daba328fe13c6c215d13806f283641c1b00..44c953c83a48fd2e59e1a0bc2e36909357fcc90e 100644 (file)
@@ -679,8 +679,6 @@ static inline long p2m_pod_entry_count(const struct p2m_domain *p2m)
     return p2m->pod.entry_count;
 }
 
-void p2m_pod_init(struct p2m_domain *p2m);
-
 #else
 
 static inline bool
@@ -709,8 +707,6 @@ static inline long p2m_pod_entry_count(const struct p2m_domain *p2m)
     return 0;
 }
 
-static inline void p2m_pod_init(struct p2m_domain *p2m) {}
-
 #endif
 
 
index 6cc73187aca58ffe7b94f7a24ad5e2c390fc3e86..e90789085b33b40f581068c599918817fb2634e2 100644 (file)
@@ -4810,7 +4810,9 @@ long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( d == NULL )
             return -ESRCH;
 
-        if ( cmd == XENMEM_set_pod_target )
+        if ( !is_hvm_domain(d) )
+            rc = -EINVAL;
+        else if ( cmd == XENMEM_set_pod_target )
         {
             rc = xsm_set_pod_target(XSM_PRIV, d);
             if ( rc )
index afee09ab40acc0add8545fd8af2276f3094a38e9..fd12f8ca73366fb6ede6ab371ec909fdc874f876 100644 (file)
@@ -30,6 +30,7 @@
 #include <asm/p2m.h>
 
 #include "mm-locks.h"
+#include "p2m.h"
 
 #define superpage_aligned(_x)  (((_x)&(SUPERPAGE_PAGES-1))==0)
 
@@ -1162,6 +1163,12 @@ p2m_pod_demand_populate(struct p2m_domain *p2m, gfn_t gfn,
     mfn_t mfn;
     unsigned long i;
 
+    if ( !p2m_is_hostp2m(p2m) )
+    {
+        ASSERT_UNREACHABLE();
+        return false;
+    }
+
     ASSERT(gfn_locked_by_me(p2m, gfn));
     pod_lock(p2m);
 
index 48bff44a6ac3f1af0387c326677c11b055808a1d..1f1eddac4857d7ab6dbd9e8336a993be1ca933e7 100644 (file)
@@ -43,6 +43,7 @@
 #include <xsm/xsm.h>
 
 #include "mm-locks.h"
+#include "p2m.h"
 
 /* Override macro from asm/page.h to make work with mfn_t */
 #undef virt_to_mfn
@@ -101,6 +102,9 @@ static int p2m_initialise(struct domain *d, struct p2m_domain *p2m)
     p2m->default_access = p2m_access_rwx;
     p2m->p2m_class = p2m_host;
 
+    if ( !is_hvm_domain(d) )
+        return 0;
+
     p2m_pod_init(p2m);
     p2m_nestedp2m_init(p2m);
 
@@ -258,7 +262,7 @@ int p2m_init(struct domain *d)
     int rc;
 
     rc = p2m_init_hostp2m(d);
-    if ( rc )
+    if ( rc || !is_hvm_domain(d) )
         return rc;
 
 #ifdef CONFIG_HVM
diff --git a/xen/arch/x86/mm/p2m.h b/xen/arch/x86/mm/p2m.h
new file mode 100644 (file)
index 0000000..ec1d54f
--- /dev/null
@@ -0,0 +1,27 @@
+/******************************************************************************
+ * arch/x86/mm/p2m.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void p2m_pod_init(struct p2m_domain *p2m);
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */