Skip to content

Commit 94c18d5

Browse files
Ryan Robertsakpm00
authored andcommitted
arm64/mm: improve comment in contpte_ptep_get_lockless()
Make clear the atmicity/consistency requirements of the API and how we achieve them. Link: https://lore.kernel.org/linux-mm/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ryan Roberts <[email protected]> Acked-by: David Hildenbrand <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Cc: John Hubbard <[email protected]> Cc: Mark Rutland <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 912609e commit 94c18d5

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

arch/arm64/mm/contpte.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,20 @@ EXPORT_SYMBOL_GPL(contpte_ptep_get);
183183
pte_t contpte_ptep_get_lockless(pte_t *orig_ptep)
184184
{
185185
/*
186-
* Gather access/dirty bits, which may be populated in any of the ptes
187-
* of the contig range. We may not be holding the PTL, so any contiguous
188-
* range may be unfolded/modified/refolded under our feet. Therefore we
189-
* ensure we read a _consistent_ contpte range by checking that all ptes
190-
* in the range are valid and have CONT_PTE set, that all pfns are
191-
* contiguous and that all pgprots are the same (ignoring access/dirty).
192-
* If we find a pte that is not consistent, then we must be racing with
193-
* an update so start again. If the target pte does not have CONT_PTE
194-
* set then that is considered consistent on its own because it is not
195-
* part of a contpte range.
186+
* The ptep_get_lockless() API requires us to read and return *orig_ptep
187+
* so that it is self-consistent, without the PTL held, so we may be
188+
* racing with other threads modifying the pte. Usually a READ_ONCE()
189+
* would suffice, but for the contpte case, we also need to gather the
190+
* access and dirty bits from across all ptes in the contiguous block,
191+
* and we can't read all of those neighbouring ptes atomically, so any
192+
* contiguous range may be unfolded/modified/refolded under our feet.
193+
* Therefore we ensure we read a _consistent_ contpte range by checking
194+
* that all ptes in the range are valid and have CONT_PTE set, that all
195+
* pfns are contiguous and that all pgprots are the same (ignoring
196+
* access/dirty). If we find a pte that is not consistent, then we must
197+
* be racing with an update so start again. If the target pte does not
198+
* have CONT_PTE set then that is considered consistent on its own
199+
* because it is not part of a contpte range.
196200
*/
197201

198202
pgprot_t orig_prot;

0 commit comments

Comments
 (0)