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

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


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Date: Thu, 12 Nov 2026 10:00:00 +0000
  • 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=63CXyESIaJK9T27H0ZieUap05rsG9VJ02OpYFtvONGw=; b=rqoT9COVX6X6fPRCJHy1rU81XmBtwvsNuikwKJ71NOvhN0vlCqmZt9AvTewabnVb8gCfLjl23vj47y9XUfds7dzuTocuXaoCZMosrNz276Q1KkFHDTnrm4mh4uKDNoGQb/UJ+Y8zDTRQc30dswSNdWqxAKUFppe1JtnjXsvaBNfDDpWMTZJB5HWR7kxB+lgBikG95fMlasRJmgsqG3OEXP+PH1VHZGPQYe/gFpkQ7kjX9LyCSMJZIB3E3QZZIIbsylV/frxbQlLqP8mzh12T6kZE+5yqtL7iRTTYku8Q6dbsJ/wB7ZpSEJ3BBBnz4fCKWy5gLQ2oC/GdphPE/L5L5g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yP0qMlk9Bj2wVt2DOIpo2gZLoobQZVg/ST8Wkkv8RZI7pnXfTQ4R5Oc5tdb0UXq9KVGjw1hNRy0Ggt0XTD+LRReKyHhFYNrn+ONM6MgwIgbFelqcUTI9LKzT5obP950t3tSLrIckeO+WPmCzY7eCovBoOM60WMIc+HytYqfNHudwI5l4PorlOlz12ni617ut5aeR0Ul+QhDpWUVwQVuXapubWaNb42I2zwGiFhuV1ZtAH9VXLwh4WyOwa2/N7/vAtJJ6q9nkMICLXuCqxB9aLaN1W8juH1OJsaimg6yfZJ2iAvbX4traiODFh9Dn0q5/b/JuVPDHxpwwNsWD+Gd7MQ==
  • 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: Thu, 12 Nov 2026 10:00:56 +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 v5:
- Update the comment above update_intpte()

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..4016dd1087ba 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.
  */
-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®.