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

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


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Date: Fri, 16 Oct 2026 17:48:11 +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=eis1qaNSuPfjas+GPjDLVyNpWEHsWLbEBEHoQsEMCHs=; b=xGUamh1TSo7wMfVeiwI/D5psjf4d1uQfWbGQwVO/voCPDquEfw6NMCJZq539iF4UFLAkxgqSVQKJe9QhFxCqDNxwIkelcUZeu1wkSqymMtCiVxy0DNZvkGBXK7lwKQubuQyUJzs7WwXKma0swebtrE5LLwlC010pJbss731nH3lF+/O3KIBPOVMyS6dq57rYWdVHOV8KHaVNEDUNK4GJkBGtq/gQjGsXKrrbT92BY2zbtvQmVP8TvW29lQ0VdTQspYz8mSxw581j2jKtpYlasbfmAzCeiyTCxwjdWAaqSlWBagVCIiXD8qfvkumKdI5QC8Wr/BcLkdpSgp7ghAWFdg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jOoZcEMm2jGMlA4U1zHTpaodLivu6WZgfgIXWP255IjbtO7P9/xNwXqdRRo1OALVnZKNMJngOSc8+E6qwDjoyC7K8utInVC8FTXQ2SPbnHrsJD2KNiAmBHrgJOgKrSQjK2pN1WIfPT1biXlaAijj6ehelevBLVU2c3A0OnmbWANPGwIhE5KsRkMko4A1cw7kpz1BFxKI/nYt5tJ4Ueenj3X3RBAlNayLkNn4THS6BImt5+W/7VbpYBZnoXSM6AYSUMuYSYvstvmnh3PNsaTHwjSqNsM4efCw+/W69u5hUI33O10cobGYGeyhhJ461Ma0I553mzLmbf/Exp8sC9kmKA==
  • 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: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: jbeulich@xxxxxxxx, andrew.cooper3@xxxxxxxxxx, roger@xxxxxxxxxxxxxx, teddy.astie@xxxxxxxxxx, Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Delivery-date: Fri, 16 Oct 2026 16:46:18 +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 v4:
- Remove UPDATE_ENTRY_SWAP
- Don't move the backslashes in UPDATE_ENTRY

Changes in v3:
- Return 0 in the paging_write_guest_entry() case (update_intpte)
- Add UPDATE_ENTRY_SWAP to convert return value to correct type

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 | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/pv/mm.h b/xen/arch/x86/pv/mm.h
index bfee0feb7b21..381a0e25b986 100644
--- a/xen/arch/x86/pv/mm.h
+++ b/xen/arch/x86/pv/mm.h
@@ -64,16 +64,22 @@ 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.
+ * If the SWAP flag is set then does an atomic swap and returns the old PTE
+ * value, otherwise returns 0.
  */
-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);
+        return 0;
+    }
     else
 #endif
     {
@@ -95,6 +101,8 @@ static inline void update_intpte(intpte_t *p, intpte_t old, 
intpte_t new,
             old = t;
         }
     }
+
+    return old;
 }
 
 /*
-- 
2.52.0




 


Rackspace

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