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

[PATCH 1/2] x86/shadow: defer/avoid paging_mfn_is_dirty() invocation


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 1 Dec 2021 11:35:15 +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=zWiZkdcG1+Y6rmdkCu8SSuxZST9U/BC4xB8A111L5Vc=; b=fkvmoIiV3DBA58hC7d5JhsHTdKbZHySRUoiTgo5jWI5IH02sTZd8CiEki0tYmPj2Zmy0qiOAIrr700viOPn+odqm5ewWnlJRk4ehvzz/BDhTNh/faPyZ5Inj694c4FkPGL9CGm5YC2m6SYCAoFBJt4mNod86VEkKRHjHCNuBQva51E2Lr2hmYybAYJ3JIqhlNoD5WTWIjZnRh4wXu13f2H9jrUN916UL6jbMOR/t5NBDNs+ZFXomtsIjQM1qwtjL8m2WagoxHHTKRgw6IvLy9WG0LJJtZKLWD1696nEL5yJO8/gK/uFLwEvXz7RaW+3+HE1Y0iU1s5pngGffMhcVpg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aWZejNfdecTejKrdOEXvfRj58P9ULZiuBi/nqZMBPnh4owj8UK9juPdcca5crKQbb0OlmCPex7aQZA8MJnNEd+g6GmjVBGcAl8DZhobj4EUxmTSsWkoKQBJysA/VCMIJLzn120wwnst85WhNtljBTS+EQDJxMjfLPUMp5J7vC91XJ/Niu42MwNQLDToYzLoVfzPM/8TOwtVVSH1Y2OPsdU6UBZQMG5XEoZu1x1BLHzeaSRuI9kGFVT8YrtMtjF8mgQx90B8FsPDzXZej/zNvqtPHXRAYIb3R8TRubexQSLGsq9+2EBDNUby5GII8QX+xs3dMpzAyTpfQho6gipER2Q==
  • 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, 01 Dec 2021 10:35:24 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

paging_mfn_is_dirty() is moderately expensive, so avoid its use unless
its result might actually change anything. This means moving the
surrounding if() down below all other checks that can result in clearing
_PAGE_RW from sflags, in order to then check whether _PAGE_RW is
actually still set there before calling the function.

While moving the block of code, fold two if()s and make a few style
adjustments.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
TBD: Perhaps the dirty-VRAM piece also wants moving down a little, such
     that all three "level == 1" conditionals can be folded?

--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -604,23 +604,6 @@ _sh_propagate(struct vcpu *v,
                   && !(gflags & _PAGE_DIRTY)) )
         sflags &= ~_PAGE_RW;
 
-    // shadow_mode_log_dirty support
-    //
-    // Only allow the guest write access to a page a) on a demand fault,
-    // or b) if the page is already marked as dirty.
-    //
-    // (We handle log-dirty entirely inside the shadow code, without using the
-    // p2m_ram_logdirty p2m type: only HAP uses that.)
-    if ( unlikely((level == 1) && shadow_mode_log_dirty(d)) )
-    {
-        if ( mfn_valid(target_mfn) ) {
-            if ( ft & FETCH_TYPE_WRITE )
-                paging_mark_dirty(d, target_mfn);
-            else if ( !paging_mfn_is_dirty(d, target_mfn) )
-                sflags &= ~_PAGE_RW;
-        }
-    }
-
 #ifdef CONFIG_HVM
     if ( unlikely(level == 1) && is_hvm_domain(d) )
     {
@@ -661,6 +644,25 @@ _sh_propagate(struct vcpu *v,
                   ) )
         sflags &= ~_PAGE_RW;
 
+    /*
+     * shadow_mode_log_dirty support
+     *
+     * Only allow the guest write access to a page a) on a demand fault,
+     * or b) if the page is already marked as dirty.
+     *
+     * (We handle log-dirty entirely inside the shadow code, without using the
+     * p2m_ram_logdirty p2m type: only HAP uses that.)
+     */
+    if ( level == 1 && unlikely(shadow_mode_log_dirty(d)) &&
+         mfn_valid(target_mfn) )
+    {
+        if ( ft & FETCH_TYPE_WRITE )
+            paging_mark_dirty(d, target_mfn);
+        else if ( (sflags & _PAGE_RW) &&
+                  !paging_mfn_is_dirty(d, target_mfn) )
+            sflags &= ~_PAGE_RW;
+    }
+
     // PV guests in 64-bit mode use two different page tables for user vs
     // supervisor permissions, making the guest's _PAGE_USER bit irrelevant.
     // It is always shadowed as present...




 


Rackspace

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