[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 06/14] x86/P2M: PoD, altp2m, and nested-p2m are HVM-only


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 23 Feb 2022 17:01:12 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2rZGfRwylNtAPsQ5UVyxgV9uPoIoLBQeDGzPZv56WOI=; b=lqWnLKiXzqTim2tsz0fMe/9N4JM1Atmz/3RZXaJF7EIv6Ov8q6bcWuaxX9f4uL/GixgdNHpa5sYmWPUPgcvJa5ITlcOvt3B09AXvbscJjN8ky91xR072Q8QdgvsXRGLPX03WRNIdVeKuM7hadoeC337xbKcf6FhvpkISzVJ7Bckorxc+zEeaqfS6YTT4qpJU6KnpXqJU4RH05KFilHXGo6mRpSIHFmhp8ZnOhfItHckCfVqmdys7G3B/mSXxgjyebiSNh3NtvZxnBbwU90Gq/0yWiI3AhoOh4I6ISYvlvm7yNtilCgtsco87EUCok2DjIk4dyfQCAvlPQukWQI8y6g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RcVBFhziv4YjjpxvCkhrDnq3RhXBZAk1bgPBcsRv8+8iZphoNkeSKfkB+owjdb8Pz3CAIVNUQIFlRRx1IiVTVK/aPgz4qMhFMjD/ZqcjmGe02CU0YYe4wwtNoBtQMA6So3Pf/vatwWageX/4q3I52a1nrGhvVhu/yJjwIVkMKSf2gHd10ftvKHZwsJ08yoFzWaSsl09ySwNbb2whk0Vz5g2GkTYBGw8aCeXvhFhqChgBa5CGaz8UUYAhMvpIv7327MP9QHpwactc6a/PtN7zz84yJALZoy8NqRcfUjZyUQ4f/OVDRGbObUY70GheAS3256/t/P060LqWEpVUASQrpg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>
  • Delivery-date: Wed, 23 Feb 2022 16:01:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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@xxxxxxxx>
---
v2: Also guard XENMEM_{get,set}_pod_target handling. Re-base over wider
    p2m_add_identity_entry() exposure in earlier patch. Add missing
    inclusion of "p2m.h". Mention the p2m_pod_demand_populate()
    adjustment separately in the description.
---
Perhaps p2m_pod_init() could be invoked from p2m_init_hostp2m(), leaving
all other p2m's PoD state uninitialized. Of course at that point the
question would be whether the PoD pieces of struct p2m_domain wouldn't
better move into a separate structure, present only for host P2Ms.
Together with the p2m_pod_demand_populate() adjustment this might then
better be a separate change ...

--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -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
     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
--- /dev/null
+++ b/xen/arch/x86/mm/p2m.h
@@ -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:
+ */
--- a/xen/arch/x86/mm/p2m-pod.c
+++ b/xen/arch/x86/mm/p2m-pod.c
@@ -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_domai
     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);
 
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -4810,7 +4810,9 @@ long arch_memory_op(unsigned long cmd, X
         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 )
--- a/xen/arch/x86/include/asm/p2m.h
+++ b/xen/arch/x86/include/asm/p2m.h
@@ -679,8 +679,6 @@ static inline long p2m_pod_entry_count(c
     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(c
     return 0;
 }
 
-static inline void p2m_pod_init(struct p2m_domain *p2m) {}
-
 #endif
 
 




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.