From: Dev Jain <dev.jain@arm.com>
To: "David Hildenbrand (Arm)" <david@kernel.org>,
Hugh Dickins <hughd@google.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Rapoport <rppt@kernel.org>, Peter Xu <peterx@redhat.com>,
Michal Hocko <mhocko@suse.com>, Kiryl Shutsemau <kas@kernel.org>,
Manfred Spraul <manfred@colorfullife.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Cyrill Gorcunov <gorcunov@gmail.com>, Zi Yan <ziy@nvidia.com>,
"Liam R. Howlett" <liam@infradead.org>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Lorenzo Stoakes <ljs@kernel.org>, Rik van Riel <riel@surriel.com>,
Vlastimil Babka <vbabka@kernel.org>, Harry Yoo <harry@kernel.org>,
Jann Horn <jannh@google.com>, Yang Shi <shy828301@gmail.com>,
Zach O'Keefe <zokeefe@google.com>, Song Liu <song@kernel.org>,
David Stevens <stevensd@chromium.org>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
Alex Williamson <alex@shazbot.org>,
Suren Baghdasaryan <surenb@google.com>,
Dave Jiang <dave.jiang@intel.com>,
Matthew Wilcox <willy@infradead.org>,
Miaohe Lin <linmiaohe@huawei.com>,
David Rientjes <rientjes@google.com>,
Shakeel Butt <shakeel.butt@linux.dev>, Jan Kara <jack@suse.cz>,
Mel Gorman <mgorman@suse.de>, Jason Gunthorpe <jgg@ziepe.ca>,
John Hubbard <jhubbard@nvidia.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Vivek Kasireddy <vivek.kasireddy@intel.com>,
Dave Airlie <airlied@redhat.com>,
Matthew Brost <matthew.brost@intel.com>,
Joshua Hahn <joshua.hahnjy@gmail.com>,
Byungchul Park <byungchul@sk.com>,
Gregory Price <gourry@gourry.net>,
Ying Huang <ying.huang@linux.alibaba.com>,
Alistair Popple <apopple@nvidia.com>,
Hagen Paul Pfeifer <hagen@jauu.net>,
James Bottomley <James.Bottomley@HansenPartnership.com>,
Felix Kuehling <Felix.Kuehling@amd.com>,
Alex Sierra <alex.sierra@amd.com>,
Balbir Singh <balbirs@nvidia.com>,
Kairui Song <kasong@tencent.com>, Qi Zheng <qi.zheng@linux.dev>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Baoquan He <baoquan.he@linux.dev>,
Oscar Salvador <osalvador@suse.de>,
Muchun Song <muchun.song@linux.dev>,
Dan Williams <djbw@kernel.org>, Rakie Kim <rakie.kim@sk.com>,
Hao Li <hao.li@linux.dev>, Christoph Lameter <cl@gentwo.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Alexei Starovoitov <ast@kernel.org>, Xu Xin <xu.xin@linux.dev>,
Chengming Zhou <chengming.zhou@linux.dev>,
Shivank Garg <shivankg@amd.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org,
linux-rt-devel@lists.linux.dev, SJ Park <sj@kernel.org>,
stable@vger.kernel.org, Chris Mason <mason@kernel.org>
Subject: Re: [PATCH 07/32] mm/khugepaged: check the VMA before walking page tables when collapsing
Date: Wed, 2 Dec 2026 10:48:34 +0530 [thread overview]
Message-ID: <adf6227a-cd3b-4e08-9aab-a321b4de215b@arm.com> (raw)
In-Reply-To: <20261129-fixes_core_3-v1-7-f66094116801@kernel.org>
On 29/11/26 3:36 pm, David Hildenbrand (Arm) wrote:
> MADV_COLLAPSE and khugepaged can end up traversing page tables of a VMA
> through find_pmd_or_thp_or_none() before verifying that the VMA is still
> as expected.
>
> Calling find_pmd_or_thp_or_none() on a mapping with PUDs
> (hugetlb/dax/PFNMAP) is invalid, as it treats every present PUD entry as
> a pointer to a PMD table.
>
> Consequently, we can end up interpreting the memory mapped by a PUD leaf
> as a PMD table.
>
> Let's fix it by performing the thp_vma_allowable_order() check before
> the page table walk.
>
> Further, let's also make find_pmd_or_thp_or_none() harder to get wrong
> by rejecting any pgd/p4d/pud leaves.
>
> This has high urgency, as unprivileged users can trigger it, although
> getting relevant PUD mappings (e.g., hugetlb) should be rather uncommon
> in most setups.
>
> Fixes: 58ac9a8993a1 ("mm/khugepaged: attempt to map file/shmem-backed pte-mapped THPs by pmds")
> Cc: stable@vger.kernel.org
> Reported-by: Chris Mason <mason@kernel.org>
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> ---
So for retract_page_tables(), when we use the struct address_space to traverse
the VMAs, we cannot get a hugetlb or DAX VMA.
But for the case described here, vma_lookup() can perhaps get a completely new
VMA.
Reviewed-by: Dev Jain <dev.jain@arm.com>
> mm/khugepaged.c | 10 +++++-----
> mm/rmap.c | 6 +++---
> 2 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 93d4a6f159e81..b133c378dac72 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -1894,11 +1894,6 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign
> !range_in_vma(vma, haddr, haddr + HPAGE_PMD_SIZE))
> return SCAN_VMA_CHECK;
>
> - /* Fast check before locking page if already PMD-mapped */
> - result = find_pmd_or_thp_or_none(mm, haddr, &pmd);
> - if (result == SCAN_PMD_MAPPED)
> - return result;
> -
> /*
> * If we are here, we've succeeded in replacing all the native pages
> * in the page cache with a single hugepage. If a mm were to fault-in
> @@ -1909,6 +1904,11 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign
> if (!thp_vma_allowable_order(vma, vma->vm_flags, TVA_FORCED_COLLAPSE, PMD_ORDER))
> return SCAN_VMA_CHECK;
>
> + /* Quick check if already PMD-mapped before locking the folio. */
> + result = find_pmd_or_thp_or_none(mm, haddr, &pmd);
> + if (result == SCAN_PMD_MAPPED)
> + return result;
> +
> /*
> * Keep pmd pgtable while the uffd bit is in use; see comment in
> * retract_page_tables().
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 81a97b94ca4b9..e7e2a0df1780b 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -883,15 +883,15 @@ pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address)
> pmd_t *pmd = NULL;
>
> pgd = pgd_offset(mm, address);
> - if (!pgd_present(*pgd))
> + if (!pgd_present(*pgd) || pgd_leaf(*pgd))
> goto out;
>
> p4d = p4d_offset(pgd, address);
> - if (!p4d_present(*p4d))
> + if (!p4d_present(*p4d) || p4d_leaf(*p4d))
> goto out;
>
> pud = pud_offset(p4d, address);
> - if (!pud_present(*pud))
> + if (!pud_present(*pud) || pud_leaf(*pud))
> goto out;
>
> pmd = pmd_offset(pud, address);
>
next prev parent reply other threads:[~2026-12-02 5:19 UTC|newest]
Thread overview: 93+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 10:06 [PATCH 00/32] mm: various (urgent?) fixes, part 3 David Hildenbrand (Arm)
2026-11-29 10:06 ` [PATCH 01/32] mm/shmem: count only the swapped pages in the requested range David Hildenbrand (Arm)
2026-11-30 3:41 ` Zi Yan
2026-12-01 9:42 ` David Hildenbrand (Arm)
2026-12-01 13:47 ` Gregory Price (Meta)
2026-12-02 7:29 ` Baolin Wang
2026-11-29 10:06 ` [PATCH 02/32] mm/shmem: don't skip parts of a split swap entry when punching holes David Hildenbrand (Arm)
2026-11-29 10:06 ` [PATCH 03/32] mm/shmem: reject userfaultfd fills during hole punch David Hildenbrand (Arm)
2026-11-29 19:47 ` Jose A. Perez de Azpillaga
2026-12-01 9:45 ` David Hildenbrand (Arm)
2026-12-01 13:49 ` Gregory Price (Meta)
2026-11-29 10:06 ` [PATCH 04/32] mm/shmem: fix commit limit bypass with very large shmem sizes David Hildenbrand (Arm)
2026-11-30 22:39 ` Gregory Price (Meta)
2026-12-02 8:31 ` Baolin Wang
2026-11-29 10:06 ` [PATCH 05/32] mm/shmem: don't pin inodes with eviction held off in the huge shrinker David Hildenbrand (Arm)
2026-11-29 10:06 ` [PATCH 06/32] mm/shmem: seal the size of SysV and shared anon files David Hildenbrand (Arm)
2026-11-30 22:41 ` Gregory Price (Meta)
2026-11-29 10:06 ` [PATCH 07/32] mm/khugepaged: check the VMA before walking page tables when collapsing David Hildenbrand (Arm)
2026-11-29 19:55 ` Jose A. Perez de Azpillaga
2026-11-30 16:31 ` Zi Yan
2026-12-02 5:18 ` Dev Jain [this message]
2026-12-02 5:29 ` Gregory Price (Meta)
2026-11-29 10:06 ` [PATCH 08/32] mm/khugepaged: flush file after unlocking folios in collapse_file() David Hildenbrand (Arm)
2026-11-29 19:58 ` Jose A. Perez de Azpillaga
2026-11-30 17:02 ` Zi Yan
2026-11-29 10:06 ` [PATCH 09/32] mm/khugepaged: check for uffd outside the i_pages lock David Hildenbrand (Arm)
2026-11-29 20:07 ` Jose A. Perez de Azpillaga
2026-12-02 5:36 ` Gregory Price (Meta)
2026-11-29 10:06 ` [PATCH 10/32] mm/khugepaged: don't wait for userfaultfd David Hildenbrand (Arm)
2026-11-29 20:16 ` Jose A. Perez de Azpillaga
2026-12-01 9:51 ` David Hildenbrand (Arm)
2026-11-29 10:06 ` [PATCH 11/32] mm/khugepaged: store new folio before adding it to LRU David Hildenbrand (Arm)
2026-11-29 20:22 ` Jose A. Perez de Azpillaga
2026-11-30 17:12 ` Zi Yan
2026-11-29 10:06 ` [PATCH 12/32] mm/khugepaged: check PMD support with the folios locked David Hildenbrand (Arm)
2026-11-29 20:27 ` Jose A. Perez de Azpillaga
2026-11-30 17:13 ` Zi Yan
2026-11-29 10:06 ` [PATCH 13/32] mm/khugepaged: stop MADV_COLLAPSE on a fatal signal David Hildenbrand (Arm)
2026-11-29 20:29 ` Jose A. Perez de Azpillaga
2026-11-30 17:13 ` Zi Yan
2026-12-02 5:37 ` Gregory Price (Meta)
2026-11-29 10:06 ` [PATCH 14/32] mm/huge_memory: split huge zero PMDs on unshare faults David Hildenbrand (Arm)
2026-11-29 20:33 ` Jose A. Perez de Azpillaga
2026-12-01 13:51 ` Gregory Price (Meta)
2026-12-02 1:16 ` Zi Yan
2026-11-29 10:06 ` [PATCH 15/32] mm/huge_memory: don't map huge PFN entries if the arch restricts PFNs David Hildenbrand (Arm)
2026-11-29 20:41 ` Jose A. Perez de Azpillaga
2026-12-01 9:54 ` David Hildenbrand (Arm)
2026-12-01 12:02 ` Jose A. Perez de Azpillaga
2026-11-29 10:06 ` [PATCH 16/32] mm/memory: don't clear a PUD leaf as bad in a zap David Hildenbrand (Arm)
2026-11-29 20:47 ` Jose A. Perez de Azpillaga
2026-11-29 10:06 ` [PATCH 17/32] mm/memory: drop the swap device ref before do_wp_page() David Hildenbrand (Arm)
2026-11-29 20:50 ` Jose A. Perez de Azpillaga
2026-12-01 13:52 ` Gregory Price (Meta)
2026-11-29 10:06 ` [PATCH 18/32] mm: consistently check MMF_UNSTABLE when populating in CoW mappings David Hildenbrand (Arm)
2026-11-29 20:58 ` Jose A. Perez de Azpillaga
2026-11-29 10:06 ` [PATCH 19/32] mm/gup: check for fatal signals in memfd_pin_folios() David Hildenbrand (Arm)
2026-12-02 5:52 ` Gregory Price (Meta)
2026-11-29 10:06 ` [PATCH 20/32] mm/migrate_device: don't collect secretmem pages David Hildenbrand (Arm)
2026-12-01 13:54 ` Gregory Price (Meta)
2026-12-02 4:03 ` Alistair Popple
2026-11-29 10:06 ` [PATCH 21/32] mm/migrate_device: mark folios leaving device memory dirty David Hildenbrand (Arm)
2026-12-01 13:55 ` Gregory Price (Meta)
2026-12-02 4:15 ` Alistair Popple
2026-11-29 10:06 ` [PATCH 22/32] mm: taint device sections before setting subsections valid David Hildenbrand (Arm)
2026-11-29 10:06 ` [PATCH 23/32] mm/mempolicy: check access under exec_update_lock David Hildenbrand (Arm)
2026-11-30 18:14 ` Gregory Price (Meta)
2026-11-29 10:06 ` [PATCH 24/32] mm/mempolicy: reject an empty set of allowed nodes David Hildenbrand (Arm)
2026-11-30 15:46 ` Joshua Hahn
2026-11-30 18:05 ` Gregory Price (Meta)
2026-12-02 5:55 ` Gregory Price (Meta)
2026-11-29 10:06 ` [PATCH 25/32] mm/mempolicy: don't wait for mems_allowed_seq in kmalloc_nolock() David Hildenbrand (Arm)
2026-11-29 21:27 ` Jose A. Perez de Azpillaga
2026-11-30 15:55 ` Joshua Hahn
2026-12-01 9:40 ` David Hildenbrand (Arm)
2026-11-30 18:12 ` Gregory Price (Meta)
2026-12-01 9:39 ` David Hildenbrand (Arm)
2026-12-01 11:44 ` Vlastimil Babka (SUSE)
2026-12-01 11:58 ` David Hildenbrand (Arm)
2026-12-01 14:00 ` Gregory Price (Meta)
2026-12-01 15:02 ` David Hildenbrand (Arm)
2026-12-02 8:10 ` Vlastimil Babka (SUSE)
2026-12-01 13:13 ` Harry Yoo
2026-12-01 13:59 ` Gregory Price (Meta)
2026-11-29 10:06 ` [PATCH 26/32] mm/ksm: look up the folio again in cmp_and_merge_page() David Hildenbrand (Arm)
2026-11-29 10:06 ` [PATCH 27/32] mm/ksm: copy KSM folios at swap-in without VM_MERGEABLE David Hildenbrand (Arm)
2026-12-01 14:56 ` Gregory Price (Meta)
2026-12-01 15:01 ` David Hildenbrand (Arm)
2026-11-29 10:06 ` [PATCH 28/32] mm/ksm: don't convert a shared anon folio into a KSM folio David Hildenbrand (Arm)
2026-11-29 10:07 ` [PATCH 29/32] mm/ksm: use a migration counter to detect KSM folio migration David Hildenbrand (Arm)
2026-11-29 10:07 ` [PATCH 30/32] mm/migrate: fix KSM oddity by checking expected refcount without mappings David Hildenbrand (Arm)
2026-11-29 10:07 ` [PATCH 31/32] mm/migrate_device: don't collect KSM folios David Hildenbrand (Arm)
2026-11-29 10:07 ` [PATCH 32/32] mm/migrate: use consistent folio locking logic David Hildenbrand (Arm)
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=adf6227a-cd3b-4e08-9aab-a321b4de215b@arm.com \
--to=dev.jain@arm.com \
--cc=Felix.Kuehling@amd.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=airlied@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alex.sierra@amd.com \
--cc=alex@shazbot.org \
--cc=apopple@nvidia.com \
--cc=ast@kernel.org \
--cc=axelrasmussen@google.com \
--cc=balbirs@nvidia.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=bigeasy@linutronix.de \
--cc=byungchul@sk.com \
--cc=chengming.zhou@linux.dev \
--cc=cl@gentwo.org \
--cc=clrkwllms@kernel.org \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=david@kernel.org \
--cc=djbw@kernel.org \
--cc=gorcunov@gmail.com \
--cc=gourry@gourry.net \
--cc=hagen@jauu.net \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=hughd@google.com \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=joshua.hahnjy@gmail.com \
--cc=kas@kernel.org \
--cc=kasong@tencent.com \
--cc=kraxel@redhat.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linmiaohe@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=ljs@kernel.org \
--cc=manfred@colorfullife.com \
--cc=mason@kernel.org \
--cc=matthew.brost@intel.com \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=muchun.song@linux.dev \
--cc=nico.pache@linux.dev \
--cc=osalvador@suse.de \
--cc=peterx@redhat.com \
--cc=qi.zheng@linux.dev \
--cc=rakie.kim@sk.com \
--cc=riel@surriel.com \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=shakeel.butt@linux.dev \
--cc=shivankg@amd.com \
--cc=shy828301@gmail.com \
--cc=sj@kernel.org \
--cc=song@kernel.org \
--cc=stable@vger.kernel.org \
--cc=stevensd@chromium.org \
--cc=surenb@google.com \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=vivek.kasireddy@intel.com \
--cc=wangkefeng.wang@huawei.com \
--cc=weixugc@google.com \
--cc=willy@infradead.org \
--cc=xu.xin@linux.dev \
--cc=ying.huang@linux.alibaba.com \
--cc=yuanchu@google.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.