|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v6 2/4] x86: extend do_mmu_update() to support returning the old PTE value
On 25.11.2026 19:51, Kevin Lampis wrote:
> A new sub-op MMU_PT_UPDATE_SWAP when used will do an atomic swap to set
> the new value and return the old PTE value through the req.val field.
>
> - The old PTE value is passed back to the guest through the req.val field
>
> If MMU_PT_UPDATE_SWAP is not set then the old behavior is preserved
> do_mmu_update -> mod_l*_entry -> UPDATE_ENTRY -> paging_write_guest_entry
>
> The new MMU_PT_UPDATE_SWAP call chain looks like this
> do_mmu_update -> mod_l*_entry -> UPDATE_ENTRY -> paging_cmpxchg_guest_entry
>
> New feature flag XENFEAT_mmu_pt_update_swap.
>
> Signed-off-by: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
> ---
> Changes in v6:
> - Use l1e_get_intpte instead of accessing fields directly
> - copy_field_to_guest once at the end of the switch
> This removes duplication but keeps type safetly
> - I didn't go all the way with passing &req.val through as uint64_t
> I hope this is an acceptable compromise between type safety and
> de-duplication.
I think so, yes. Just two more or less cosmetic issues:
> @@ -4161,42 +4162,66 @@ long do_mmu_update(
> if ( page_lock(page) )
> {
> unsigned int update_flags = 0;
> + intpte_t old_pte = 0;
>
> if ( cmd == MMU_PT_UPDATE_PRESERVE_AD )
> update_flags = PTE_UPDATE_PRESERVE_AD;
> else if ( cmd == MMU_PT_UPDATE_NO_TRANSLATE )
> update_flags = PTE_UPDATE_NO_TRANSLATE;
> + else if ( cmd == MMU_PT_UPDATE_SWAP )
> + update_flags = PTE_UPDATE_SWAP;
>
> switch ( page->u.inuse.type_info & PGT_type_mask )
> {
> case PGT_l1_page_table:
> + {
> + l1_pgentry_t ol1e = {};
> +
> rc = mod_l1_entry(va, l1e_from_intpte(req.val), mfn,
> - update_flags, v, pg_owner, NULL);
> + update_flags, v, pg_owner, &ol1e);
> + old_pte = l1e_get_intpte(ol1e);
> break;
> -
> + }
Why is this blank line going away? (Same again further down.)
> @@ -4221,19 +4246,34 @@ long do_mmu_update(
> mfn) + local_in_use) )
> flush_root_pt_others = true;
> }
> + old_pte = l4e_get_intpte(ol4e);
> break;
> -
> + }
> case PGT_writable_page:
> + if ( unlikely(cmd == MMU_PT_UPDATE_SWAP) )
> + {
> + rc = -EINVAL;
> + break;
> + }
> perfc_incr(writable_mmu_updates);
> paging_write_guest_entry(v, va, req.val, mfn);
> rc = 0;
> break;
> }
> page_unlock(page);
> +
> + if ( !rc && cmd == MMU_PT_UPDATE_SWAP )
> + {
> + req.val = old_pte;
> + if ( unlikely(copy_field_to_guest(ureqs, &req, val)) )
Am I misremembering, or did we arrive at __copy_field_to_guest() already
in an earlier version?
Jan
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |