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

[PATCH 3/4] x86: extend do_mmu_update() to support returning the old PTE value


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Date: Mon, 27 Jul 2026 16:06:14 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=srJPZVfKyCLc9jNc72RgnPcAtxJpFYEiKTbfZigXhyU=; b=AWfwf0VC+jJcxruADW6rJU+LtyAW7vNYwXb+gsBs9DqU2Vkpstc2uQR8lwunCdERaJLZ9gNx3Gdo5E3aW0Nq5KAGW7poqi5x2iUahcK4LSiGwkttZo20oDCyC21VdCpBa+W4y3z8/eW+hobgQ3Emy7t54+V/iPTE61tvKWjNKnSHmCWVfZ1s+2MgER1BmMIDYPRG8S7LLvH7zhtdYe6BwbmoXCLmzTdGvsK40lUswlVBZX/rMSPXJ0UAvEeIWv6SyoJczd04VpvK1SKGC1INVn/hyt/ov7KBhAtb9qWXH5S8z8TnS+jXFwk5ebnAcnSmCtZ3ZLA6wWfOEcsx5Sm13Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JWcMQ3ykFM9xof0UWt7anfKXNQuKG9b7XTca5CaFjffp/OcKEkkDkA7nZIH3BMW7KqsBcqNI/GcFQInhLlLj02p4DuRUgajp2qdOe3Mip83+5quG4DGon28QEqItpwwCS7mOQk//wpRpDy5ebc1x+ztTLzbgF+xzSA39++DRmiDgzhyP4cW1G9dFm3FRdz9lcO+Y44i2BtZRekvuEILTHcz05CoiuSxBaQ4iLs4iDF5Wmsc80Fz4A/7F8k5rcCVPNwz5+ipY6oNbeMN+9m+1rEkDS3xHclDz4sN/0Zmr2le1ZyO2hJ50tT/VxIQiCAwbTIGptydA8h+i2C9WizOjVw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: jbeulich@xxxxxxxx, andrew.cooper3@xxxxxxxxxx, roger.pau@xxxxxxxxxx, Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Delivery-date: Mon, 27 Jul 2026 15:05:19 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

A new parameter write_back_old when set will return the old PTE value.

- The new PTE value in req.val must be 0, this is for clearing only.

- The PRESERVE_AD flag is rejected with -EINVAL because preserving
  Accessed/Dirty bits into a zero'ed PTE doesn't make sense.

- Only l1 PTEs are supported because they are the most frequent and have the
  biggest performance impact.

- The old PTE value is passed back to the guest through the req.val field

If the write_back_old flag is not set then the old behavior is preserved
  do_mmu_update -> mod_l1_entry -> UPDATE_ENTRY -> paging_write_guest_entry

The new get_and_clear call chain looks like this
  do_mmu_update -> mod_l1_entry -> update_intpte -> paging_cmpxchg_guest_entry

Signed-off-by: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
---
 xen/arch/x86/mm.c | 62 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 58 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 500549c8e036..278b992aca5c 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -3988,11 +3988,12 @@ long do_mmuext_op(
     return rc;
 }
 
-long do_mmu_update(
+static long __do_mmu_update(
     XEN_GUEST_HANDLE_PARAM(mmu_update_t) ureqs,
     unsigned int count,
     XEN_GUEST_HANDLE_PARAM(uint) pdone,
-    unsigned int foreigndom)
+    unsigned int foreigndom,
+    bool write_back_old)
 {
     struct mmu_update req;
     void *va = NULL;
@@ -4144,13 +4145,41 @@ long do_mmu_update(
                 switch ( page->u.inuse.type_info & PGT_type_mask )
                 {
                 case PGT_l1_page_table:
-                    rc = mod_l1_entry(va, l1e_from_intpte(req.val), mfn,
-                                      cmd, v, pg_owner, NULL);
+                {
+                    if ( !write_back_old )
+                        rc = mod_l1_entry(va, l1e_from_intpte(req.val), mfn,
+                                          cmd, v, pg_owner, NULL);
+                    else
+                    {
+                        l1_pgentry_t ol1e;
+                        if ( unlikely(req.val != 0 ||
+                                      cmd == MMU_PT_UPDATE_PRESERVE_AD) )
+                        {
+                            rc = -EINVAL;
+                            break;
+                        }
+
+                        rc = mod_l1_entry(va, l1e_from_intpte(req.val), mfn,
+                                          cmd, v, pg_owner, &ol1e);
+
+                        if ( !rc )
+                        {
+                            req.val = ol1e.l1;
+                            if ( unlikely(copy_to_guest(ureqs, &req, 1)) )
+                                rc = -EFAULT;
+                        }
+                    }
                     break;
+                }
 
                 case PGT_l2_page_table:
                     if ( unlikely(pg_owner != pt_owner) )
                         break;
+                    if ( unlikely(write_back_old) )
+                    {
+                        rc = -EINVAL;
+                        break;
+                    }
                     rc = mod_l2_entry(va, l2e_from_intpte(req.val), mfn,
                                       cmd == MMU_PT_UPDATE_PRESERVE_AD, v);
                     if ( !rc )
@@ -4160,6 +4189,11 @@ long do_mmu_update(
                 case PGT_l3_page_table:
                     if ( unlikely(pg_owner != pt_owner) )
                         break;
+                    if ( unlikely(write_back_old) )
+                    {
+                        rc = -EINVAL;
+                        break;
+                    }
                     rc = mod_l3_entry(va, l3e_from_intpte(req.val), mfn,
                                       cmd == MMU_PT_UPDATE_PRESERVE_AD, v);
                     if ( !rc )
@@ -4169,6 +4203,11 @@ long do_mmu_update(
                 case PGT_l4_page_table:
                     if ( unlikely(pg_owner != pt_owner) )
                         break;
+                    if ( unlikely(write_back_old) )
+                    {
+                        rc = -EINVAL;
+                        break;
+                    }
                     rc = mod_l4_entry(va, l4e_from_intpte(req.val), mfn,
                                       cmd == MMU_PT_UPDATE_PRESERVE_AD, v);
                     if ( !rc )
@@ -4198,6 +4237,11 @@ long do_mmu_update(
                     break;
 
                 case PGT_writable_page:
+                    if ( unlikely(write_back_old) )
+                    {
+                        rc = -EINVAL;
+                        break;
+                    }
                     perfc_incr(writable_mmu_updates);
                     paging_write_guest_entry(v, va, req.val, mfn);
                     rc = 0;
@@ -4366,6 +4410,16 @@ long do_mmu_update(
 
     return rc;
 }
+
+long do_mmu_update(
+    XEN_GUEST_HANDLE_PARAM(mmu_update_t) ureqs,
+    unsigned int count,
+    XEN_GUEST_HANDLE_PARAM(uint) pdone,
+    unsigned int foreigndom)
+{
+    return __do_mmu_update(ureqs, count, pdone, foreigndom, false);
+}
+
 #endif /* CONFIG_PV */
 
 /*
-- 
2.52.0




 


Rackspace

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