Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: "David Hildenbrand (Arm)" <david@kernel.org>,
	Chris Mason <mason@kernel.org>,
	"Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
	Hugh Dickins <hughd@google.com>, Zi Yan <ziy@nvidia.com>,
	Zach O'Keefe <zokeefe@google.com>, SJ Park <sj@kernel.org>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Lance Yang <lance.yang@linux.dev>,
	"Kiryl Shutsemau (Meta)" <kas@kernel.org>,
	Pedro Falcato <pfalcato@suse.de>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y 2/2] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
Date: Thu,  3 Dec 2026 22:59:07 -0500	[thread overview]
Message-ID: <20261204035900.2507447-2-sashal@kernel.org> (raw)
In-Reply-To: <20261204035900.2507447-1-sashal@kernel.org>

From: "David Hildenbrand (Arm)" <david@kernel.org>

[ Upstream commit 043a2260b96ffc13121a1dd65282e67eb2e1d8a8 ]

madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not
uptodate. For example, shmem fallocate() can put such folios into the
page cache.

collapse_file() already refuses to proceed with folios that are not
uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip
such folios, leaving handling to the page faults.

Note that collapse_file() effectively clears shmem folios through
shmem_get_folio(); let's keep this fix simple and simply let the page
fault path deal with that.

Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
Reported-by: Chris Mason <mason@kernel.org>
Cc: stable@vger.kernel.org
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Acked-by: Hugh Dickins <hughd@google.com>
Acked-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Zach O'Keefe <zokeefe@google.com>
Reviewed-by: SJ Park <sj@kernel.org>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: Lance Yang <lance.yang@linux.dev>
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Link: https://patch.msgid.link/20261105-set_huge_pmd_uptodate-v1-1-a78d8a1b7117@kernel.org
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 mm/khugepaged.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index a870ed3d6b98d..e2b7819ce36ed 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1518,6 +1518,12 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr,
 		goto drop_folio;
 	}
 
+	/* Leave any uninitialized folios to the page fault path. */
+	if (!folio_test_uptodate(folio)) {
+		result = SCAN_FAIL;
+		goto drop_folio;
+	}
+
 	result = find_pmd_or_thp_or_none(mm, haddr, &pmd);
 	switch (result) {
 	case SCAN_SUCCEED:
-- 
2.53.0


      reply	other threads:[~2026-12-04  3:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 16:10 FAILED: patch "[PATCH] mm/khugepaged: don't map folios that are not uptodate in" failed to apply to 6.6-stable tree gregkh
2026-12-04  3:59 ` [PATCH 6.6.y 1/2] mm/khugepaged: convert collapse_pte_mapped_thp() to use folios Sasha Levin
2026-12-04  3:59   ` Sasha Levin [this message]

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=20261204035900.2507447-2-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=hughd@google.com \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=ljs@kernel.org \
    --cc=mason@kernel.org \
    --cc=pfalcato@suse.de \
    --cc=sj@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=ziy@nvidia.com \
    --cc=zokeefe@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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