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

[PATCH 2/4] x86: extend mod_l1_entry() to optionally return the old PTE value


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Date: Mon, 27 Jul 2026 16:06:13 +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=PaSZ+4Bh6/Qv4PdxxpQxW+d/eMMp06pD/qD0eGNft/o=; b=ucJuljTARHb9Oz5Ea7A+u5G+wXOR7epVSRJB9ZhoHMtibelq9CDJstoVHomSnpu78pkjgPvCgkW2GGId1mUlhlIrJWTVZPW2ZYvflixFVRGb+4Oio/omfVbJWCQUA5sWjLfu6saQ/bGhLcdtQHD8eC/oHLGz3nufuxRvo8yk9c5FkY4aVkXOFmP8fcPLuFEvkNYtZO2YpnmUGXGTurbT2X4mPhY+kA0I0PWGzxhOismK4PSqc4rKHQrZRiG71pEQHcKUyUMFiYPlPJXrxmLvCTFkapdvNJ1pRhRuMQaLdjg1SMaka1vCtUX8LwmleWQNOyi7xkmBaPp3e7ugPkSSrA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OIBat6jkRD+tnlX2AS6BP6Ij/dSAGdwfzQFa8MkKu3mFPx0lQ/nfHKEFL24tMQIQfYNvhTOMVIhUHisWTxOHNOnAefmR2m5gMsBJIfUe+2p1F1xrPHrB1lESnReexeH7s8W5cTn+GnawJ39P5KSFp7E3H98dayE2Ui/Pt4HYygblbYsqFwYU+hUgIn8xF/2fsSBMmQrWYNCxqq5/I99Yl2XoaFwXKIZwPoLaHM/oEzEZPkgMNi4Fy/1ge8Kxd7gdwp048rqXEHwoysOVAwlVRydFcF9aDpc0oymI+TFD4Ed+hmvpVBWuAR1vXjkWVn9wh4TdvjFEZRce0kprprRNpA==
  • 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:11 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Calling mod_l1_entry() with a valid ol1e_out pointer will do an atomic xchg to
set the new pte value and return the old pte value through the ol1e_out
pointer. If the ol1e_out pointer is NULL then old behavior is preserved.

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

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index bb4ba0afe2d4..500549c8e036 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -2151,7 +2151,8 @@ static void l3t_unlock(struct page_info *page)
 /* Update the L1 entry at pl1e to new value nl1e. */
 static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e,
                         mfn_t gl1mfn, unsigned int cmd,
-                        struct vcpu *pt_vcpu, struct domain *pg_dom)
+                        struct vcpu *pt_vcpu, struct domain *pg_dom,
+                        l1_pgentry_t *ol1e_out)
 {
     bool preserve_ad = (cmd == MMU_PT_UPDATE_PRESERVE_AD);
     l1_pgentry_t ol1e = l1e_read(pl1e);
@@ -2213,8 +2214,8 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t 
nl1e,
         /* Fast path for sufficiently-similar mappings. */
         if ( !l1e_has_changed(ol1e, nl1e, ~FASTPATH_FLAG_WHITELIST) )
         {
-            rc = UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,
-                              preserve_ad);
+            rc = update_intpte(&pl1e->l1, &ol1e.l1, nl1e.l1, gl1mfn, pt_vcpu,
+                               preserve_ad, !!ol1e_out);
             if ( page )
                 put_page(page);
             return rc ? 0 : -EBUSY;
@@ -2237,8 +2238,8 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t 
nl1e,
         if ( page )
             put_page(page);
 
-        if ( unlikely(!UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,
-                                    preserve_ad)) )
+        if ( unlikely(!update_intpte(&pl1e->l1, &ol1e.l1, nl1e.l1, gl1mfn,
+                                     pt_vcpu, preserve_ad, !!ol1e_out)) )
         {
             ol1e = nl1e;
             rc = -EBUSY;
@@ -2246,13 +2247,17 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, 
l1_pgentry_t nl1e,
     }
     else if ( pv_l1tf_check_l1e(pt_dom, nl1e) )
         return -ERESTART;
-    else if ( unlikely(!UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,
-                                     preserve_ad)) )
+    else if ( unlikely(!update_intpte(&pl1e->l1, &ol1e.l1, nl1e.l1, gl1mfn,
+                                      pt_vcpu, preserve_ad, !!ol1e_out)) )
     {
         return -EBUSY;
     }
 
     put_page_from_l1e(ol1e, pt_dom);
+
+    if ( !rc && ol1e_out )
+        *ol1e_out = ol1e;
+
     return rc;
 }
 
@@ -4140,7 +4145,7 @@ long do_mmu_update(
                 {
                 case PGT_l1_page_table:
                     rc = mod_l1_entry(va, l1e_from_intpte(req.val), mfn,
-                                      cmd, v, pg_owner);
+                                      cmd, v, pg_owner, NULL);
                     break;
 
                 case PGT_l2_page_table:
@@ -4505,7 +4510,8 @@ static int __do_update_va_mapping(
         goto out;
     }
 
-    rc = mod_l1_entry(pl1e, val, gl1mfn, MMU_NORMAL_PT_UPDATE, v, pg_owner);
+    rc = mod_l1_entry(pl1e, val, gl1mfn, MMU_NORMAL_PT_UPDATE, v, pg_owner,
+                      NULL);
 
     page_unlock(gl1pg);
     put_page(gl1pg);
-- 
2.52.0




 


Rackspace

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