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

[PATCH v2 3/7] x86: extend update_intpte() to support atomic get-and-update


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Date: Thu, 10 Sep 2026 21:31:09 +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=+tOYekDsGmb2RFUH4obI70pViMHgOTrmNkYgsBIQIZY=; b=KJ+QfPpLEVE0KmIMJFBFngOOOYTicXoxGWyNcPxjf80imZBe9ahFacliJT5V3+Xz7y7psHWXKlIpHFm+JRwZYFKIxPyswdtPtznXZ+S2lKbzTNHN9b9msJwu1MdQT6wjofiO/RX3hLjkpU16jhnJ4asnpiMxlj1g/XCb4Bn5oL1cGCNOooZ+5WDb0Yd0gheler0gjsNIQeFcPsaGhwv+DF2TE2Y7/3ZEnuAzz5YsI8J+W79kxQvd3INRNzkOUd+VBrYCCkCncE2bxSrLer+pil6FmqKl/v6ICNlVeTgWs0RsB3bmYQ304+UTJysGDQb2FhNusKzdkN14V5kNIOb6Nw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aavSg4qCAsn/Ui1ldOXOnXYYDh71ZvX+iKZfqag7gmJZb2QacM5K9OC7+ztFUxAFLAbC1kmupmHRtND1X4zO86rVG6Z/w6GBjxwzFxRh6Xy65Fa4CRMfHjn6eYGB2hiLOYjB03PkLOUMKtJeCdBEfovJ3U5BPsHC8rD4QDab+uLrhJaXTz9gSxVuftkYypVd/CgqxQUGNsJJvPETn/OZaEL34hLbjVTAnbDByBf6cTuuRDYXbNUBbkRARYFytGz110VwsSNrd/Imte2+JtmmCNoP9z5u+KRZW3tkUneGGG8Q+gF3NuSB7Dao8ylL+2HzgxQyV1A2ricKoRjsziJAag==
  • 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>

The update_intpte() now accepts a new swap flag and if set
returns the old pte value.

No functional change for existing callers.

Signed-off-by: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
---
Changes in v2:
- Add new PTE_UPDATE_SWAP flag instead of a bool argument
- Return the old pte value instead of turning `old` into an out pointer
---
 xen/arch/x86/pv/mm.h | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/pv/mm.h b/xen/arch/x86/pv/mm.h
index bfee0feb7b21..f2bb26aef5b3 100644
--- a/xen/arch/x86/pv/mm.h
+++ b/xen/arch/x86/pv/mm.h
@@ -64,15 +64,18 @@ static inline intpte_t paging_cmpxchg_guest_entry(
 
 #define PTE_UPDATE_PRESERVE_AD  (1u << 0)
 #define PTE_UPDATE_NO_TRANSLATE (1u << 1)
+#define PTE_UPDATE_SWAP         (1u << 2)
 
 /*
  * How to write an entry to the guest pagetables.
+ * Returns the old PTE value.
  */
-static inline void update_intpte(intpte_t *p, intpte_t old, intpte_t new,
-                                 mfn_t mfn, struct vcpu *v, unsigned int flags)
+static inline intpte_t update_intpte(intpte_t *p, intpte_t old, intpte_t new,
+                                     mfn_t mfn, struct vcpu *v,
+                                     unsigned int flags)
 {
 #ifndef PTE_UPDATE_WITH_CMPXCHG
-    if ( !(flags & PTE_UPDATE_PRESERVE_AD) )
+    if ( !(flags & (PTE_UPDATE_PRESERVE_AD | PTE_UPDATE_SWAP)) )
         paging_write_guest_entry(v, p, new, mfn);
     else
 #endif
@@ -95,15 +98,16 @@ static inline void update_intpte(intpte_t *p, intpte_t old, 
intpte_t new,
             old = t;
         }
     }
+    return old;
 }
 
 /*
  * 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 , fl)                   \
-    update_intpte(&_t ## e_get_intpte(*(_p)),                       \
-                  _t ## e_get_intpte(_o), _t ## e_get_intpte(_n),   \
+#define UPDATE_ENTRY(_t ,_p ,_o ,_n ,_m ,_v , fl)                 \
+    update_intpte(&_t ## e_get_intpte(*(_p)),                     \
+                  _t ## e_get_intpte(_o), _t ## e_get_intpte(_n), \
                   _m, _v, fl)
 
 static always_inline l1_pgentry_t adjust_guest_l1e(l1_pgentry_t l1e,
-- 
2.52.0




 


Rackspace

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