archive mirror
 help / color / mirror / Atom feed
From: "Zach O'Keefe" <>
To: Andrew Morton <>
Cc:, Yang Shi <>,
	 "Zach O'Keefe" <>
Subject: [PATCH v2] mm/khugepaged: check compound_order() in collapse_pte_mapped_thp()
Date: Thu, 22 Sep 2022 15:27:31 -0700	[thread overview]
Message-ID: <> (raw)

By the time we lock a page in collapse_pte_mapped_thp(), the page
mapped by the address pushed onto the slot's .pte_mapped_thp[] array
might have changed arbitrarily since we last looked at it.  We
revalidate that the page is still the head of a compound page, but we
don't revalidate if the compound page is of order HPAGE_PMD_ORDER before
applying rmap and page table updates.

Since the kernel now supports large folios of arbitrary order, and since
replacing page's pte mappings by a pmd mapping only makes sense for
compound pages of order HPAGE_PMD_ORDER, revalidate that the compound
order is indeed of order HPAGE_PMD_ORDER before proceeding.

Suggested-by: Yang Shi <>
Signed-off-by: Zach O'Keefe <>
 mm/khugepaged.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 57af2c841b41..40fd9f7b3ed3 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1399,6 +1399,9 @@ void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr)
 	if (!PageHead(hpage))
 		goto drop_hpage;
+	if (compound_order(hpage) != HPAGE_PMD_ORDER)
+		goto drop_hpage;
 	if (find_pmd_or_thp_or_none(mm, haddr, &pmd) != SCAN_SUCCEED)
 		goto drop_hpage;

             reply	other threads:[~2022-09-22 22:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-22 22:27 Zach O'Keefe [this message]
2022-09-26 18:13 ` [PATCH v2] mm/khugepaged: check compound_order() in collapse_pte_mapped_thp() Yang Shi
2022-09-26 18:15   ` Zach O'Keefe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).