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

[PATCH v3 2/4] x86/shadow: slightly consolidate sh_unshadow_for_p2m_change() (part II)


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 12 Aug 2022 09:44:31 +0200
  • 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=UgSRP2it2VqWEJo6oUkdTTXnRcYc9p6ImxEtjea60ng=; b=K85+MdPWaCC8DIrWspuFMWqoU/Usc1/Q7PHigTDJ3CSdIcK4ZmZj9hw9w6DMqX+cHgAv06/Blx3qtJw+degMXbBRe1o4nfu6d1miAIHkdMX7AJpuYEP4hFzP4Ys1UbQbvJLwfxUMLrpxu6i+lnvyCMHAIceYMNuo7c/cA/vZLh1OWqj2T0La/DeiHSGouZDhXpISu0P2LqaqCxvKxYikVPIP2n6X4+YoW9zeA2nJuUicCr0LDEMeQpkYXkrV2PV7j1CRWqEqfUfY7HATBlXT2ypTb3KkdidVRlOZmuDnG/0OgCf/ABXzW/lxXKauLk4HeZP4Grx0OTUnNe2Z1Pb1KQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jpmFUc3IEYUirhBmesxiieNu1VaXZAczi4+U+ymiv/5fUvGK3EahuU/Kzt3CCo4zBOL7xxOXJvgiba6gz81D/lamHTQa1dboBFSGIY88Z54tiVN5pVvZy1yRbe0ThH+g4P43B76QXCB7TypZz0Vu3L1HF0ynCasYdkXyZ6n8mROmdiWDDBV2gNa0ezztlaHJonKPQKwAdjpRUDhDd9skHwT8qYbsQ2sCJBXUUhACWOXg9NUKLGZ/vxJ11iAOelVBut1UJoEzh9nT2mtgYe1RZZdlF4YKNXzt7KRV3daDt/UqP1m1f0Xa0/Joe9rRIhzbjs2DffHeoEpbcQzJnVLtRQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Tim Deegan <tim@xxxxxxx>
  • Delivery-date: Fri, 12 Aug 2022 07:44:38 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Pull common checks out of the switch(). This includes extending a
_PAGE_PRESENT check to L1 as well, which presumably was deemed redundant
with p2m_is_valid() || p2m_is_grant(), but I think we are better off
being explicit in all cases. Note that for L2 (or higher) the grant
check isn't strictly necessary, as grants are only ever single pages.
Leave a respective assertion.

With _PAGE_PRESENT checked uniformly, the suspicious mfn_valid(omfn)
checks can be dropped rather than moved/folded - if anything we'd need
to compare against INVALID_MFN, but that won't come out of l1e_get_mfn().

For L1 replace the moved out condition with a PTE comparison: There's
no need for any update or flushing when the two match.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v3: Compare PTEs, not MFNs. Drop mfn_valid().
v2: Split from previous bigger patch. Add grant related assertion for
    L2.

--- a/xen/arch/x86/mm/shadow/hvm.c
+++ b/xen/arch/x86/mm/shadow/hvm.c
@@ -810,19 +810,27 @@ static void cf_check sh_unshadow_for_p2m
     if ( unlikely(!d->arch.paging.shadow.total_pages) )
         return;
 
+    /* Only previously present / valid entries need processing. */
+    if ( !(oflags & _PAGE_PRESENT) ||
+         (!p2m_is_valid(p2mt) && !p2m_is_grant(p2mt)) )
+        return;
+
     switch ( level )
     {
     default:
         /*
          * The following assertion is to make sure we don't step on 1GB host
-         * page support of HVM guest.
+         * page support of HVM guest. Plus we rely on ->set_entry() to never
+         * be called with orders above PAGE_ORDER_2M, not even to install
+         * non-present entries (which in principle ought to be fine even
+         * without respective large page support).
          */
-        ASSERT(!((oflags & _PAGE_PRESENT) && (oflags & _PAGE_PSE)));
+        ASSERT(!(oflags & _PAGE_PSE));
         break;
 
     /* If we're removing an MFN from the p2m, remove it from the shadows too */
     case 1:
-        if ( (p2m_is_valid(p2mt) || p2m_is_grant(p2mt)) && mfn_valid(omfn) )
+        if ( l1e_get_intpte(old) != l1e_get_intpte(new) )
         {
             sh_remove_all_shadows_and_parents(d, omfn);
             if ( sh_remove_all_mappings(d, omfn, _gfn(gfn)) )
@@ -836,10 +844,11 @@ static void cf_check sh_unshadow_for_p2m
      * scheme, that's OK, but otherwise they must be unshadowed.
      */
     case 2:
-        if ( !(oflags & _PAGE_PRESENT) || !(oflags & _PAGE_PSE) )
+        if ( !(oflags & _PAGE_PSE) )
             break;
 
-        if ( p2m_is_valid(p2mt) && mfn_valid(omfn) )
+        ASSERT(!p2m_is_grant(p2mt));
+
         {
             unsigned int i;
             mfn_t nmfn = l1e_get_mfn(new);




 


Rackspace

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