Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1241679c authored by Steve Capper's avatar Steve Capper Committed by Greg Kroah-Hartman
Browse files

arm64: hugetlb: Fix handling of young ptes



[ Upstream commit 469ed9d823b7d240d6b9574f061ded7c3834c167 ]

In the contiguous bit hugetlb break-before-make code we assume that all
hugetlb pages are young.

In fact, remove_migration_pte is able to place an old hugetlb pte so
this assumption is not valid.

This patch fixes the contiguous hugetlb scanning code to preserve young
ptes.

Fixes: d8bdcff2 ("arm64: hugetlb: Add break-before-make logic for contiguous entries")
Signed-off-by: default avatarSteve Capper <steve.capper@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 11577134
Loading
Loading
Loading
Loading
+9 −3
Original line number Original line Diff line number Diff line
@@ -118,11 +118,14 @@ static pte_t get_clear_flush(struct mm_struct *mm,


		/*
		/*
		 * If HW_AFDBM is enabled, then the HW could turn on
		 * If HW_AFDBM is enabled, then the HW could turn on
		 * the dirty bit for any page in the set, so check
		 * the dirty or accessed bit for any page in the set,
		 * them all.  All hugetlb entries are already young.
		 * so check them all.
		 */
		 */
		if (pte_dirty(pte))
		if (pte_dirty(pte))
			orig_pte = pte_mkdirty(orig_pte);
			orig_pte = pte_mkdirty(orig_pte);

		if (pte_young(pte))
			orig_pte = pte_mkyoung(orig_pte);
	}
	}


	if (valid)
	if (valid)
@@ -347,10 +350,13 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma,
	if (!pte_same(orig_pte, pte))
	if (!pte_same(orig_pte, pte))
		changed = 1;
		changed = 1;


	/* Make sure we don't lose the dirty state */
	/* Make sure we don't lose the dirty or young state */
	if (pte_dirty(orig_pte))
	if (pte_dirty(orig_pte))
		pte = pte_mkdirty(pte);
		pte = pte_mkdirty(pte);


	if (pte_young(orig_pte))
		pte = pte_mkyoung(pte);

	hugeprot = pte_pgprot(pte);
	hugeprot = pte_pgprot(pte);
	for (i = 0; i < ncontig; i++, ptep++, addr += pgsize, pfn += dpfn)
	for (i = 0; i < ncontig; i++, ptep++, addr += pgsize, pfn += dpfn)
		set_pte_at(vma->vm_mm, addr, ptep, pfn_pte(pfn, hugeprot));
		set_pte_at(vma->vm_mm, addr, ptep, pfn_pte(pfn, hugeprot));