[PATCH 1/8] mm: Add ptep_try_set() for lockless empty-slot installs

David Hildenbrand (Arm) david at kernel.org
Fri May 22 15:07:04 PDT 2026


>  
> +#ifndef ptep_try_set
> +/**
> + * ptep_try_set - atomically set an empty kernel PTE
> + * @ptep: page table entry
> + * @new_pte: value to install
> + *
> + * Atomically set *@ptep to @new_pte iff *@ptep is pte_none(). Return true on
> + * success, false if the slot was already populated or the arch has no
> + * implementation.
> + *
> + * For special kernel page tables only - never user page tables. The caller must
> + * prevent concurrent teardown of @ptep and must accept that other writers may
> + * race. Concurrent clearers must use ptep_get_and_clear() so racing accesses
> + * agree on the outcome.
> + *
> + * Architectures opt in by providing a cmpxchg-based override and defining
> + * ptep_try_set as an identity macro. The generic stub returns false, which is
> + * correct for callers that fall through to oops on failure.
> + */
> +static inline bool ptep_try_set(pte_t *ptep, pte_t new_pte)

There are only a handful of valid use cases for this (and the "fall through to
oops on failure") makes this very clear.

So I'm fine with this, assuming there won't really be a lot of other users
besides ebpf.

Acked-by: David Hildenbrand (arm) <david at kernel.org>

-- 
Cheers,

David



More information about the linux-arm-kernel mailing list