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

[xen staging] x86/shadow: make monitor table create/destroy more consistent



commit 06dfcb7f61c05ae184cb1e2d692a14a09551e704
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Tue Feb 24 09:16:07 2026 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Feb 24 10:29:55 2026 +0100

    x86/shadow: make monitor table create/destroy more consistent
    
    While benign at present, it is still a little fragile to operate on a
    wrong "old_mode" value in sh_update_paging_modes(). This can happen when
    no monitor table was present initially - we'd create one for the new
    mode without updating old_mode. Correct this in two ways, each of which
    would be sufficient on its own: Once by adding "else" to the second of
    the involved if()s in the function, and then by setting the correct
    initial mode for HVM domains in shadow_vcpu_init().
    
    Further use the same predicate (paging_mode_external()) consistently
    when dealing with shadow mode init/update/cleanup, rather than a mix of
    is_hvm_vcpu() (init), is_hvm_domain() (update), and
    paging_mode_external() (cleanup).
    
    Finally drop a redundant is_hvm_domain() from inside the bigger if()
    (which is being converted to paging_mode_external()) in
    sh_update_paging_modes().
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/arch/x86/mm/shadow/common.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/common.c
index c89ab8e063..126523b898 100644
--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -120,9 +120,9 @@ void shadow_vcpu_init(struct vcpu *v)
     }
 #endif
 
-    v->arch.paging.mode = is_hvm_vcpu(v) ?
-                          &SHADOW_INTERNAL_NAME(sh_paging_mode, 3) :
-                          &SHADOW_INTERNAL_NAME(sh_paging_mode, 4);
+    v->arch.paging.mode = paging_mode_external(v->domain)
+                          ? &SHADOW_INTERNAL_NAME(sh_paging_mode, 2)
+                          : &SHADOW_INTERNAL_NAME(sh_paging_mode, 4);
 }
 
 #if SHADOW_AUDIT
@@ -1802,7 +1802,7 @@ static void sh_update_paging_modes(struct vcpu *v)
         sh_detach_old_tables(v);
 
 #ifdef CONFIG_HVM
-    if ( is_hvm_domain(d) )
+    if ( paging_mode_external(d) )
     {
         const struct paging_mode *old_mode = v->arch.paging.mode;
 
@@ -1855,13 +1855,12 @@ static void sh_update_paging_modes(struct vcpu *v)
             make_cr3(v, mmfn);
             hvm_update_host_cr3(v);
         }
-
-        if ( v->arch.paging.mode != old_mode )
+        else if ( v->arch.paging.mode != old_mode )
         {
             SHADOW_PRINTK("new paging mode: %pv pe=%d gl=%u "
                           "sl=%u (was g=%u s=%u)\n",
                           v,
-                          is_hvm_domain(d) ? hvm_paging_enabled(v) : 1,
+                          hvm_paging_enabled(v),
                           v->arch.paging.mode->guest_levels,
                           v->arch.paging.mode->shadow.shadow_levels,
                           old_mode ? old_mode->guest_levels : 0,
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

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