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

Re: [PATCH v4 2/5] x86: extend mod_l*_entry() to optionally return the old PTE value


  • To: kevin.lampis@xxxxxxxxxx
  • From: chunjie.zhu@xxxxxxxxxx
  • Date: Tue, 20 Oct 2026 10:34:00 +0800
  • 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=bSyAJ+7mF0iFg6+8/U9QEEA0hLWt2Jce+tVfic3iu3A=; b=jDhUza1YTYqhEniKTQkxiAHyu3quiytiDb0py/KAJy3EGHQhX476wCw1tOODfvSJShV8RY6sgK22YNP6F9ecyLCSTmEEm8F76ydcBqeNbKQ6D+UGZS3U+1V0MstC3F1MrrbX/9uY3P1ArtKNu2wTF7T8TmA6faFnLXYdkFn4R+0F+AxZ8mydERdslPlts/FBYOtSmVBqfrqgIdy/c/6400r9oLJGWl6KIMMy2wEMr4EECXcTuH5oUAYNZhS5P+KJHjQnLFyYA+8TmyH+kLc+9YzSGa1WwF3G2KNH77inh6KVSude6I80kE4hni9n4S1fxgzj4RNHmwJA0Ot+NKi4lA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KHGT/xCP/lHKmmMUSuq0hdGfRGkSljSqmHjs3i78F5y7cjkFelkpLJyMwBILwV0AmSEO4B/SFchpkWdeW5HAXNl1pr+K72F9QShZy/UKt0KmbhJcVTwH1ftCRQmqUxBv2pAsfrF9GWkRzh0Wyb2dDscS0wNxR5TfUTsj94LdYEmgaZTHJ0ZzIZZHPmli0zN08PNPMIktX4QTHEE257WL5+bJx0VVGdcEhohv7Pd68wpdNfr20M3ZwbaOuwdVOIJ0S94DZR8bWMTuaHATokNxJQun0MqB7ijIVyKMhZMPWN4OZ9oFHHeoB9RKxh83f83RINdY/VAXnWf8jaoXAJ3rcg==
  • 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: andrew.cooper3@xxxxxxxxxx, jbeulich@xxxxxxxx, roger@xxxxxxxxxxxxxx, teddy.astie@xxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 20 Oct 2026 02:34:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, Oct 16, 2026 at 05:48:12 PM, Kevin Lampis <kevin.lampis@xxxxxxxxxx> 
wrote:

> Calling mod_l*_entry() with a valid ol*e_out pointer will do atomic
> CMPXCHG to set the new pte value and return the old pte value through
> the ol*e_out pointer. If the ol*e_out pointer is NULL then old behavior
> is preserved.
>
> Signed-off-by: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
> ---
> Changes in v4:
> - Refactor how UPDATE_ENTRY is used
> - Update commit message to specify CMPXCHG instead of xchg
>
> Changes in v3:
> - Add swap to mod_l{2,3,4}_entry()
>
> Changes in v2:
> - UPDATE_ENTRY now returns the old pte value instead of using an out
>   pointer
> ---
>  xen/arch/x86/mm.c | 106 ++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 84 insertions(+), 22 deletions(-)
>
> diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
> index e42cd33c0d09..609c8595a487 100644
> --- a/xen/arch/x86/mm.c
> +++ b/xen/arch/x86/mm.c
> @@ -2193,7 +2193,8 @@ static void l3t_unlock(struct page_info *page)
>  /* Update the L1 entry at pl1e to new value nl1e. */
>  static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e,
>                          mfn_t gl1mfn, unsigned int update_flags,
> -                        struct vcpu *pt_vcpu, struct domain *pg_dom)
> +                        struct vcpu *pt_vcpu, struct domain *pg_dom,
> +                        l1_pgentry_t *ol1e_out)
>  {
>      l1_pgentry_t ol1e = l1e_read(pl1e);
>      struct domain *pt_dom = pt_vcpu->domain;
> @@ -2254,7 +2255,11 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, 
> l1_pgentry_t nl1e,
>          /* Fast path for sufficiently-similar mappings. */
>          if ( !l1e_has_changed(ol1e, nl1e, ~FASTPATH_FLAG_WHITELIST) )
>          {
> -            UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu, 
> update_flags);
> +            intpte_t old = UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, 
> pt_vcpu,
> +                                        update_flags);
> +            if ( ol1e_out )
> +                *ol1e_out = l1e_from_intpte(old);
> +

Same "intpte_t old = UPDATE_ENTRY(); if ( olNe_out ) ..." code block is now
repeated three times in each of mod_l{1,2,3,4}_entry().

Alternatively, a single local variable per function, assigned at each call
site and copied out once at the end. Does this avoid the duplication?



 


Rackspace

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