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

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


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Date: Thu, 10 Sep 2026 21:31:10 +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=ZRMOrcUBuKZGWJ4fSy5SoqfBgF/O6euKv4pLdi6oABw=; b=Ql0IQeIclGCrEsV2RPNJbYTjXT1g43iFNLssc3QqGGzjilwqaTyJlm0JfY2A3D7lnYKtQz42ISa6l5jbGaeeHY+1U3DJ6clDW8AxqhFUfUppWUNvuZ/YrNabZGLM8qKefLvHawzOIPWCqLCVtDFo3cYeIwoLLMtfTCpj2f7fkU1QZKheSUmin783t2swSR7U5imftFEsFVyWUXdMTdi4l/RNhVUSKYpGE5gUsrS+mDKk+DRbRoATrppl/xPrXgxlRIaIOIKSENYNtj+RiTl5FcOxLQ3TMdNu0LWQn62Nf0DmQivBN7iEinZ2J20Uz64TWluYWU9kf0nzBHwLJVMkMQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ceBxpU+qmzyTFxqWrmw0ZDlcv2YfwyKl9jAtshhLOf7UJfrDd1WF72FJ04tbpoO8Ld9sXC9YVwOv/c/swmyrjAMwlqmhbg9F+J/d6Wg3lz8khxvgl/Wd0+X1JWAB5vTfaRI9VCs9Mp902Q4xFS0u78zJv/B7sbS8s8EnRAmX6t7On3KEicF77uR1JheFDu9JTS8A4GubSM7Ekqc+JP0ercgZEjCK/2SSpRikvdrVDF6RNuPTuoPQTKnUSMOJj1DNJfj+IZhJ/o4AEBdY4af+ljuNI3ZDu1H0bPNyWLRrWL1uvnl1vbsDgLfdYfN0N0+pgZczxDZ/wq5zLt1jvYc58Q==
  • 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, teddy.astie@xxxxxxxxxx, Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Delivery-date: Thu, 10 Sep 2026 20:29:45 +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>
---
Changes in v2:
- UPDATE_ENTRY now returns the old pte value instead of using an out
  pointer
---
 xen/arch/x86/mm.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index dcbc44f57c54..59ad5ce16486 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -2150,7 +2150,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 update_flags,
-                        struct vcpu *pt_vcpu, struct domain *pg_dom)
+                        struct vcpu *pt_vcpu, struct domain *pg_dom,
+                        l1_pgentry_t *ol1e_out)
 {
     l1_pgentry_t ol1e = l1e_read(pl1e);
     struct domain *pt_dom = pt_vcpu->domain;
@@ -2211,9 +2212,12 @@ 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) )
         {
-            UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu, update_flags);
+            ol1e.l1 = UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,
+                                   update_flags);
             if ( page )
                 put_page(page);
+            if ( ol1e_out )
+                *ol1e_out = ol1e;
             return 0;
         }
 
@@ -2234,14 +2238,20 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, 
l1_pgentry_t nl1e,
         if ( page )
             put_page(page);
 
-        UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu, update_flags);
+        ol1e.l1 = UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,
+                               update_flags);
     }
     else if ( pv_l1tf_check_l1e(pt_dom, nl1e) )
         return -ERESTART;
     else
-        UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu, update_flags);
+        ol1e.l1 = UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,
+                               update_flags);
 
     put_page_from_l1e(ol1e, pt_dom);
+
+    if ( !rc && ol1e_out )
+        *ol1e_out = ol1e;
+
     return rc;
 }
 
@@ -4109,7 +4119,7 @@ long do_mmu_update(
                 {
                 case PGT_l1_page_table:
                     rc = mod_l1_entry(va, l1e_from_intpte(req.val), mfn,
-                                      update_flags, v, pg_owner);
+                                      update_flags, v, pg_owner, NULL);
                     break;
 
                 case PGT_l2_page_table:
@@ -4474,7 +4484,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®.