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

[PATCH 12/16] x86/shadow: make monitor table create/destroy more consistent


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 22 Mar 2023 10:35:57 +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=UD+Cm4n1hMaiv0YQYjnlNZKs67pHNL/O4K2oCASMyfw=; b=JgdODgcEgga9wAiyeifR4A/bj9S59s2TDEeMznZ4v/G2YocYOrK8VOZdDrZ1vFFjpXWk3GAGBRGKPTH99a/gvGiOfK1yxZHq8c9W6gCuneb1pCPQPtEEHzjCWsCzr5OgPJg3hmuJpiNTbP6mjZyMDffmwO1kInJA47yw57+BO4OhmbSzMfuASs8DhQGBhSgkVGh4wRLAZS00JLHh/qVVcsRmX/lp20txTEzur632QFJYuWQ81UcT04KGmY8R2PCtLJAkdsPxb3OPOs5KSPoiagyOlH/n07NtNnRQm/R5kHgUjyjXb1DVKbizqoB6diK14T6tebd+IbuJKKjKwNMj8w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BrCAUnBywKtY8ZQ6FXXQzx5sfC4rqLyIjbjXkpYzJ1d0gFPx0eIiKUcUY7bhMPCEPFJWZqOH26kEDB0ygtUMEcisuDIuprohlDN0g1bT2snJ5w3dHmWin+HASgp/YccLDR3oRv9zoDJ8Mf3jZ2il/PuiSf+CE94THZXcCmgTsgF5RfU/qMk2DyOfukKwmO2Ta0weqQrWdbSu4YYnFhNsgf+oA7/Og0MxLMdZo0uPTgnJmDBIDwfG5h6pIrbJ8++mz4Gb22HFFVlhdPoBmC8niJkiEZKd9DyX23KDGxGUqjlvaPQc+eS1onSRpoPNyfjD+RhgRF23x81PLch+cACtDA==
  • 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>, Tim Deegan <tim@xxxxxxx>
  • Delivery-date: Wed, 22 Mar 2023 09:36:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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 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>

--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -129,8 +129,8 @@ void shadow_vcpu_init(struct vcpu *v)
     }
 #endif
 
-    v->arch.paging.mode = is_hvm_vcpu(v) ?
-                          &SHADOW_INTERNAL_NAME(sh_paging_mode, 3) :
+    v->arch.paging.mode = paging_mode_external(v->domain) ?
+                          &SHADOW_INTERNAL_NAME(sh_paging_mode, 2) :
                           &SHADOW_INTERNAL_NAME(sh_paging_mode, 4);
 }
 
@@ -1811,7 +1811,7 @@ static void sh_update_paging_modes(struc
         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;
 
@@ -1864,13 +1864,12 @@ static void sh_update_paging_modes(struc
             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,




 


Rackspace

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