Commit 451ce7f0 authored by Ryan Roberts's avatar Ryan Roberts Committed by Liu Shixin
Browse files

arm64/mm: improve comment in contpte_ptep_get_lockless()

mainline inclusion
from mainline-v6.9-rc1
commit 94c18d5f7e0d612ce3fb9cb4aa8cfb1308d57a0a
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9OCYO
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=94c18d5f7e0d612ce3fb9cb4aa8cfb1308d57a0a

--------------------------------

Make clear the atmicity/consistency requirements of the API and how we
achieve them.

Link: https://lore.kernel.org/linux-mm/Zc-Tqqfksho3BHmU@arm.com/
Link: https://lkml.kernel.org/r/20240226120321.1055731-3-ryan.roberts@arm.com


Signed-off-by: default avatarRyan Roberts <ryan.roberts@arm.com>
Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
parent c2a12466
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -183,16 +183,20 @@ EXPORT_SYMBOL_GPL(contpte_ptep_get);
pte_t contpte_ptep_get_lockless(pte_t *orig_ptep)
{
	/*
	 * Gather access/dirty bits, which may be populated in any of the ptes
	 * of the contig range. We may not be holding the PTL, so any contiguous
	 * range may be unfolded/modified/refolded under our feet. Therefore we
	 * ensure we read a _consistent_ contpte range by checking that all ptes
	 * in the range are valid and have CONT_PTE set, that all pfns are
	 * contiguous and that all pgprots are the same (ignoring access/dirty).
	 * If we find a pte that is not consistent, then we must be racing with
	 * an update so start again. If the target pte does not have CONT_PTE
	 * set then that is considered consistent on its own because it is not
	 * part of a contpte range.
	 * The ptep_get_lockless() API requires us to read and return *orig_ptep
	 * so that it is self-consistent, without the PTL held, so we may be
	 * racing with other threads modifying the pte. Usually a READ_ONCE()
	 * would suffice, but for the contpte case, we also need to gather the
	 * access and dirty bits from across all ptes in the contiguous block,
	 * and we can't read all of those neighbouring ptes atomically, so any
	 * contiguous range may be unfolded/modified/refolded under our feet.
	 * Therefore we ensure we read a _consistent_ contpte range by checking
	 * that all ptes in the range are valid and have CONT_PTE set, that all
	 * pfns are contiguous and that all pgprots are the same (ignoring
	 * access/dirty). If we find a pte that is not consistent, then we must
	 * be racing with an update so start again. If the target pte does not
	 * have CONT_PTE set then that is considered consistent on its own
	 * because it is not part of a contpte range.
	 */

	pgprot_t orig_prot;