From: Kevin Lampis <kevin.lampis@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: jbeulich@suse.com, andrew.cooper3@citrix.com,
roger.pau@citrix.com, Kevin Lampis <kevin.lampis@citrix.com>
Subject: [PATCH 1/4] x86: extend update_intpte() to support atomic get-and-update
Date: Mon, 27 Jul 2026 16:06:12 +0100 [thread overview]
Message-ID: <20260727150615.1373200-2-kevin.lampis@citrix.com> (raw)
In-Reply-To: <20260727150615.1373200-1-kevin.lampis@citrix.com>
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@citrix.com>
---
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
next prev parent reply other threads:[~2026-07-27 15:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 15:06 [PATCH 0/4] unmap_page_range optimisation Kevin Lampis
2026-07-27 15:06 ` Kevin Lampis [this message]
2026-08-13 12:01 ` [PATCH 1/4] x86: extend update_intpte() to support atomic get-and-update Jan Beulich
2026-08-13 12:22 ` Andrew Cooper
2026-07-27 15:06 ` [PATCH 2/4] x86: extend mod_l1_entry() to optionally return the old PTE value Kevin Lampis
2026-07-27 15:06 ` [PATCH 3/4] x86: extend do_mmu_update() to support returning " Kevin Lampis
2026-08-13 12:51 ` Jan Beulich
2026-07-27 15:06 ` [PATCH 4/4] x86: add new pte_get_and_clear hypercall Kevin Lampis
2026-08-04 10:30 ` Teddy Astie
2026-08-13 12:55 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260727150615.1373200-2-kevin.lampis@citrix.com \
--to=kevin.lampis@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.