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

[PATCH 1/4] x86: extend update_intpte() to support atomic get-and-update


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Date: Mon, 27 Jul 2026 16:06:12 +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=fNm1nuNO+XAb5R8ex77Fpi902ddh3pTIX6BDJO1AGYQ=; b=x+qgBUvGiKrpjtKDtImvr7f6hccMBj8Es45OtKhIS5cUbCPAcAyz4L0ZqlH+FmxZmGfzoqIUi1jTW3vFSKfOnXs9w/gRNhuk/j0GO1ryBhegB/HcYbn2HYgrZYS0hRXp1Uq3UjRDssxBXGHGNOOVFEJKVwC8FoA6grE/wH6HVnx0awVhOzHYi2ymsT04iJdYaSs0/E73CSnk+RklVa9wSJP8YdYAYrzvq1iyxq07YpZUo1Z7s41NkhmR1qoReNNMa8d6lZerynGZ/H1Vc9b30kLMMm4FRVp8h0g5Z2QlQkhIxuY9RPVRYQyl0ly+UPkJu66TcTxJQ1geaK5d/P4G4w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=s4tjOl0fuwL4QXfG77SGdFqTyJvcudTtQb6zd+gTLM+fCUBRx+Y83oMeQXundQkVFkBu/CUUO5LKCE9/IHj2h/1CPEklRVmK4eqjmEbSqkceUp3yXY8tYMzv8hpe3EvEu0QMiKSp/Xr3c0LwNMcXGxApuhoBMFEd+2eoF8W5VfV4KIMf591LQ10EI39qC5IjPdPik+nq3VT4+oV274YFOrl8ihTJG9TUrGNEsP7Sc3cjIh9W3u4Jl+ESiBgHDWoCQ58MHta/n9qIU72oIgNdqizByhkKLzDOaSmF9rR/nZn8gWsxCYRBZm7C4dzLFkbOEHMs/grNg1bwQH2oXZ09pA==
  • 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:09 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The update_intpte() function now accepts a new use_cmpxchg flag and if set
returns the old pte value through the new *old pointer.

No functional change for existing callers.

Signed-off-by: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
---
 xen/arch/x86/pv/mm.h | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/xen/arch/x86/pv/mm.h b/xen/arch/x86/pv/mm.h
index 4564cab9fc0f..8c42cf3b3f4d 100644
--- a/xen/arch/x86/pv/mm.h
+++ b/xen/arch/x86/pv/mm.h
@@ -66,13 +66,14 @@ static inline intpte_t paging_cmpxchg_guest_entry(
  * How to write an entry to the guest pagetables.
  * Returns false for failure (pointer not valid), true for success.
  */
-static inline bool update_intpte(intpte_t *p, intpte_t old, intpte_t new,
-                                 mfn_t mfn, struct vcpu *v, bool preserve_ad)
+static inline bool update_intpte(intpte_t *p, intpte_t *old, intpte_t new,
+                                 mfn_t mfn, struct vcpu *v, bool preserve_ad,
+                                 bool use_cmpxchg)
 {
     bool rv = true;
 
 #ifndef PTE_UPDATE_WITH_CMPXCHG
-    if ( !preserve_ad )
+    if ( !preserve_ad && !use_cmpxchg )
         paging_write_guest_entry(v, p, new, mfn);
     else
 #endif
@@ -82,30 +83,36 @@ static inline bool update_intpte(intpte_t *p, intpte_t old, 
intpte_t new,
             intpte_t _new = new, t;
 
             if ( preserve_ad )
-                _new |= old & (_PAGE_ACCESSED | _PAGE_DIRTY);
+                _new |= *old & (_PAGE_ACCESSED | _PAGE_DIRTY);
 
-            t = paging_cmpxchg_guest_entry(v, p, old, _new, mfn);
+            t = paging_cmpxchg_guest_entry(v, p, *old, _new, mfn);
 
-            if ( t == old )
+            if ( t == *old )
                 break;
 
             /* Allowed to change in Accessed/Dirty flags only. */
-            BUG_ON((t ^ old) & ~(intpte_t)(_PAGE_ACCESSED|_PAGE_DIRTY));
+            BUG_ON((t ^ *old) & ~(intpte_t)(_PAGE_ACCESSED|_PAGE_DIRTY));
 
-            old = t;
+            *old = t;
         }
     }
     return rv;
 }
 
+static inline bool _update_intpte(intpte_t *p, intpte_t old, intpte_t new,
+                                  mfn_t mfn, struct vcpu *v, bool preserve_ad)
+{
+    return update_intpte(p, &old, new, mfn, v, preserve_ad, false);
+}
+
 /*
  * Macro that wraps the appropriate type-changes around update_intpte().
  * Arguments are: type, ptr, old, new, mfn, vcpu
  */
 #define UPDATE_ENTRY(_t,_p,_o,_n,_m,_v,_ad)                         \
-    update_intpte(&_t ## e_get_intpte(*(_p)),                       \
-                  _t ## e_get_intpte(_o), _t ## e_get_intpte(_n),   \
-                  (_m), (_v), (_ad))
+    _update_intpte(&_t ## e_get_intpte(*(_p)),                      \
+                   _t ## e_get_intpte(_o), _t ## e_get_intpte(_n),  \
+                   (_m), (_v), (_ad))
 
 static always_inline l1_pgentry_t adjust_guest_l1e(l1_pgentry_t l1e,
                                                    const struct domain *d)
-- 
2.52.0




 


Rackspace

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