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

[PATCH v2 8/9] x86/shadow: call sh_detach_old_tables() directly


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 11 Jan 2023 14:57:08 +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=4uJicMk7KMO3J5OufWXUur+3R2HmbLQ7mvJAVkX8lh8=; b=oMaoI6rCBCF4h4BIMNx5AZVZaysitmIpl4TslSq3cA9CRJuaJGk2K1hpEbet1TY6Ww2SYu4QXKUkA8994sbkVYCBbCQFi0rK1ye6W9Mzk77h9zpO3zWFx97KSDdl1Pl5KDOz4JTuc0REUnlkhA9ir0NGxThmGwGYIGPW2Mdjz8qA6bhXKvM3OPj9IojyY2iCHBbrSj9LxCxVPeHBCfPeJjczUozxgUjNHSPAzEESz61nk7sKAXviTYM9xjOv0HabjZV5+okcXg7pouU6IBDkY+SD9tkhq5jtvCs/KeRhxqyeQy1PHp27dsfzb2j8EE457wduSTwBHauezRNEYUPGgg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WkxdgB88KE20zyOORVTy4RosbNtgrxGjpkEM4pysQbT6Xyuok9jeYshiM5nlk1quYhhnR/AfPYh+iLgpZESwSSe0eTOtGfz+cEimMVJEnSRjIy8t4wAMp+z0OgQDDLOAk2vDr7NRSa/MfljoqUB/7I8Wj8LPHO9PPvFd3N35vkppXmRQPNURGKz7m4SbjKz4CTvW0RlHD58+Ye1QaR2uSdszSG3RpNUpWF6P8/BKJanme3WMkc171FwXK90CDfktz08xJj30uslkkx1cedVju1E082c5NVM8hPnvwj5Ea5y1OXOQbhfeEVP3gIryZ1YINutue9mRIb54p6mkPL5Oaw==
  • 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>, Tim Deegan <tim@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>
  • Delivery-date: Wed, 11 Jan 2023 13:57:17 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

There's nothing really mode specific in this function anymore (the
varying number of valid entries in v->arch.paging.shadow.shadow_table[]
is dealt with fine by the zero check, and we have other similar cases of
iterating through the full array in common.c), and hence there's neither
a need to have multiple instances of it, nor does it need calling
through a function pointer.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
I've retained the C++-style comment in the function as this style is
used elsewhere as well in shadow code. I wouldn't mind changing the
comment to conform to ./CODING_STYLE.
---
v2: New.

--- a/xen/arch/x86/include/asm/paging.h
+++ b/xen/arch/x86/include/asm/paging.h
@@ -98,7 +98,6 @@
 
 struct shadow_paging_mode {
 #ifdef CONFIG_SHADOW_PAGING
-    void          (*detach_old_tables     )(struct vcpu *v);
 #ifdef CONFIG_PV
     void          (*write_guest_entry     )(struct vcpu *v, intpte_t *p,
                                             intpte_t new, mfn_t gmfn);
--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -2264,6 +2264,29 @@ void shadow_prepare_page_type_change(str
     shadow_remove_all_shadows(d, page_to_mfn(page));
 }
 
+/*
+ * Removes v->arch.paging.shadow.shadow_table[].
+ * Does all appropriate management/bookkeeping/refcounting/etc...
+ */
+static void sh_detach_old_tables(struct vcpu *v)
+{
+    struct domain *d = v->domain;
+    unsigned int i;
+
+    ////
+    //// vcpu->arch.paging.shadow.shadow_table[]
+    ////
+
+    for ( i = 0; i < ARRAY_SIZE(v->arch.paging.shadow.shadow_table); ++i )
+    {
+        mfn_t smfn = pagetable_get_mfn(v->arch.paging.shadow.shadow_table[i]);
+
+        if ( mfn_x(smfn) )
+            sh_put_ref(d, smfn, 0);
+        v->arch.paging.shadow.shadow_table[i] = pagetable_null();
+    }
+}
+
 /**************************************************************************/
 
 static void sh_update_paging_modes(struct vcpu *v)
@@ -2312,7 +2335,7 @@ static void sh_update_paging_modes(struc
     // First, tear down any old shadow tables held by this vcpu.
     //
     if ( v->arch.paging.mode )
-        v->arch.paging.mode->shadow.detach_old_tables(v);
+        sh_detach_old_tables(v);
 
 #ifdef CONFIG_HVM
     if ( is_hvm_domain(d) )
@@ -2700,7 +2723,7 @@ void shadow_vcpu_teardown(struct vcpu *v
     if ( !paging_mode_shadow(d) || !v->arch.paging.mode )
         goto out;
 
-    v->arch.paging.mode->shadow.detach_old_tables(v);
+    sh_detach_old_tables(v);
 #ifdef CONFIG_HVM
     if ( shadow_mode_external(d) )
     {
@@ -2935,7 +2958,7 @@ static int shadow_one_bit_disable(struct
         for_each_vcpu(d, v)
         {
             if ( v->arch.paging.mode )
-                v->arch.paging.mode->shadow.detach_old_tables(v);
+                sh_detach_old_tables(v);
             if ( !(v->arch.flags & TF_kernel_mode) )
                 make_cr3(v, pagetable_get_mfn(v->arch.guest_table_user));
             else
--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -3207,30 +3207,6 @@ sh_update_linear_entries(struct vcpu *v)
     sh_flush_local(d);
 }
 
-
-/*
- * Removes v->arch.paging.shadow.shadow_table[].
- * Does all appropriate management/bookkeeping/refcounting/etc...
- */
-static void cf_check sh_detach_old_tables(struct vcpu *v)
-{
-    struct domain *d = v->domain;
-    mfn_t smfn;
-    unsigned int i;
-
-    ////
-    //// vcpu->arch.paging.shadow.shadow_table[]
-    ////
-
-    for_each_shadow_table(v, i)
-    {
-        smfn = pagetable_get_mfn(v->arch.paging.shadow.shadow_table[i]);
-        if ( mfn_x(smfn) )
-            sh_put_ref(d, smfn, 0);
-        v->arch.paging.shadow.shadow_table[i] = pagetable_null();
-    }
-}
-
 static void cf_check sh_update_cr3(struct vcpu *v, int do_locking, bool 
noflush)
 /* Updates vcpu->arch.cr3 after the guest has changed CR3.
  * Paravirtual guests should set v->arch.guest_table (and guest_table_user,
@@ -4211,7 +4187,6 @@ const struct paging_mode sh_paging_mode
     .update_paging_modes           = shadow_update_paging_modes,
     .flush_tlb                     = shadow_flush_tlb,
     .guest_levels                  = GUEST_PAGING_LEVELS,
-    .shadow.detach_old_tables      = sh_detach_old_tables,
 #ifdef CONFIG_PV
     .shadow.write_guest_entry      = sh_write_guest_entry,
     .shadow.cmpxchg_guest_entry    = sh_cmpxchg_guest_entry,
--- a/xen/arch/x86/mm/shadow/types.h
+++ b/xen/arch/x86/mm/shadow/types.h
@@ -236,7 +236,6 @@ static inline shadow_l4e_t shadow_l4e_fr
 #define sh_unhook_pae_mappings     INTERNAL_NAME(sh_unhook_pae_mappings)
 #define sh_unhook_64b_mappings     INTERNAL_NAME(sh_unhook_64b_mappings)
 #define sh_paging_mode             INTERNAL_NAME(sh_paging_mode)
-#define sh_detach_old_tables       INTERNAL_NAME(sh_detach_old_tables)
 #define sh_audit_l1_table          INTERNAL_NAME(sh_audit_l1_table)
 #define sh_audit_fl1_table         INTERNAL_NAME(sh_audit_fl1_table)
 #define sh_audit_l2_table          INTERNAL_NAME(sh_audit_l2_table)




 


Rackspace

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