* [PATCH v4 0/4] mm: fix races between huge and non-huge faults in PFN mappings
@ 2026-11-26 14:36 Lorenzo Stoakes (ARM)
2026-11-26 14:36 ` [PATCH v4 1/4] mm: update walk_to_pmd() to explicitly return an error Lorenzo Stoakes (ARM)
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-26 14:36 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Alex Williamson, Peter Xu, Zi Yan, Baolin Wang, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
Kiryl Shutsemau, Wei Liu, Roman Kisel, Saurabh Sengar,
Naman Jain, Michael Kelley
Cc: ljs, linux-mm, linux-kernel, stable, Jose A. Perez de Azpillaga,
T.J. Mercier, Eliav Farber, Gregory Price (Meta)
A driver that implements both ->fault and ->huge_fault must anticipate
concurrent use of both.
This can happen, for example, if a user calls prctl(PR_SET_THP_DISABLE)
concurrent with faulting, as that only holds the mmap write lock and thus
does not exclude faulting threads stabilised by VMA lock.
A number of places in the code that implements huge PFN support fail to
take this into account correctly, which this series aims to address.
Generally the shape of the issue is that faulting the same empty page table
entry can result in the ->fault and ->huge_fault handlers racing and the
loser finding something they didn't expect.
The fault code must tolerate this, but fails to in 3 places:
1. walk_to_pmd() asserts, without the PMD lock, that the PMD entry is not
huge, so a VM_BUG_ON() triggers. [ vfio-pci, nvgrace-gpu ]
2. insert_pfn() treats a failure to map the PTE table as an allocation
failure and reports OOM, causing kernel accesses to the range to
spuriously fail with -EFAULT. [ vfio-pci, nvgrace-gpu ]
3. insert_pmd() and insert_pud() assume a populated entry is huge and
compare its PFN on write fault, warning when that of a page table does
not match. [ mshv_vtl, drm_gem_shmem, panthor ]
This was originally reported and fixed by Eliav Farber in [0], this series
reworks patches 1-3 of that one.
Patch 4 of that series (x86 PAT encoding of huge PFN mappings) is dropped -
it is unrelated to the above, no in-tree driver is affected by it, and it
needs a different approach which is better pursued separately with the x86
maintainers.
All three issues were reproduced on x86-64 under QEMU using vfio-pci in
no-IOMMU mode on an ivshmem BAR, with 6 threads faulting the same address
in each PMD or PUD aligned range of the mapping while another toggles
PR_SET_THP_DISABLE (note that vfio-pci had to be modified to pass the write
flag to reproduce the third issue).
Without this series the BUG is hit immediately, with only patches 1 and 2
applied tens of thousands of -EFAULTs are observed within seconds, and with
patches 1-3 (and the vfio-pci modification) both warnings fire immediately.
With the series applied 30 second runs at each of PMD and PUD size complete
with none of the above, with or without the vfio-pci modification.
[0]: https://lore.kernel.org/all/20261112051440.16140-1-farbere@amazon.com/
---
v4:
* Rebased on mm-core/for-next.
v3:
* Propagated tags, thanks everybody!
* Fix issue with 3/4 returning -EFAULT, which resulted in a SIGBUS. Fix
this by returning -EBUSY so the fault is retried. As reported by the
kernel test robot.
* Updated 3/4 comments and commit message to reflect this + also that
MADV_DONTNEED can result in a missing page table.
* Updated 3/4 to also have insert_pages() return -EBUSY under the same
circumstances as insert_page() for consistency.
* Fixed 'Reivewed-by' tag in 3/4.
https://lore.kernel.org/r/20261125-huge-pfnmap-fault-races-v3-0-bbc44489341b@kernel.org
v2:
* Added 1/4 to have walk_to_pmd() return an error code. This is marked for
stable as it is a prerequisite of 3/4.
* Updated 3/4 (was 2/3) to add __get_locked_pte(), which differentiates a
failed page table allocation from racing a huge entry, and to use it in
both insert_pfn() and insert_page(), as per David.
* Updated 3/4 (was 2/3) to have walk_to_pmd() return -EFAULT if it
encounters a huge PUD entry, as per David.
* Updated 3/4 (was 2/3) to be authored by me as it is substantially
reworked, retaining Eliav as reporter.
* Updated 4/4 (was 3/3) to use [pmd, pud]_leaf() rather than
[pmd, pud]_trans_huge(), as per David.
* Propagated tags, other than to 3/4 (was 2/3) as changed significantly.
https://lore.kernel.org/r/20261117-huge-pfnmap-fault-races-v2-0-276007e73bcb@kernel.org
v1:
https://patch.msgid.link/20261115-huge-pfnmap-fault-races-v1-0-537605643f6f@kernel.org
---
Eliav Farber (1):
mm/memory: remove racy huge PMD assertion from walk_to_pmd()
Lorenzo Stoakes (ARM) (3):
mm: update walk_to_pmd() to explicitly return an error
mm/memory: do not report OOM if insert_pfn() races a huge fault
mm/huge_memory: only compare PFNs of huge entries on huge fault insert
mm/huge_memory.c | 8 +++++++
mm/memory.c | 70 ++++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 58 insertions(+), 20 deletions(-)
---
base-commit: ded26aaeec76470592fb8e5eae1ec7bcbfa14b24
change-id: 20261115-huge-pfnmap-fault-races-534e626de5cc
Cheers,
--
Lorenzo Stoakes (ARM) <ljs@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v4 1/4] mm: update walk_to_pmd() to explicitly return an error
2026-11-26 14:36 [PATCH v4 0/4] mm: fix races between huge and non-huge faults in PFN mappings Lorenzo Stoakes (ARM)
@ 2026-11-26 14:36 ` Lorenzo Stoakes (ARM)
2026-11-26 14:36 ` [PATCH v4 2/4] mm/memory: remove racy huge PMD assertion from walk_to_pmd() Lorenzo Stoakes (ARM)
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-26 14:36 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Alex Williamson, Peter Xu, Zi Yan, Baolin Wang, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
Kiryl Shutsemau, Wei Liu, Roman Kisel, Saurabh Sengar,
Naman Jain, Michael Kelley
Cc: ljs, linux-mm, linux-kernel, stable, Jose A. Perez de Azpillaga,
T.J. Mercier
Rather than callers inferring an error from a NULL pmd return, explicitly
return error codes.
This allows different error codes to be returned for different failure
conditions.
No functional change intended.
This is a prerequisite for the fix to insert_pfn() which follows, as that
needs to be able to tell a failure to allocate a page table apart from a
race with a huge fault, so mark it for stable alongside that fix.
Fixes: f9e54c3a2f5b ("vfio/pci: implement huge_fault support")
Cc: stable@vger.kernel.org
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: T.J. Mercier <tjmercier@google.com>
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
---
mm/memory.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index d238985dbf01..0e994f076bf7 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2383,7 +2383,7 @@ void zap_special_vma_range(struct vm_area_struct *vma, unsigned long address,
}
EXPORT_SYMBOL_GPL(zap_special_vma_range);
-static pmd_t *walk_to_pmd(struct mm_struct *mm, unsigned long addr)
+static int walk_to_pmd(struct mm_struct *mm, unsigned long addr, pmd_t **pmdp)
{
pgd_t *pgd;
p4d_t *p4d;
@@ -2393,24 +2393,25 @@ static pmd_t *walk_to_pmd(struct mm_struct *mm, unsigned long addr)
pgd = pgd_offset(mm, addr);
p4d = p4d_alloc(mm, pgd, addr);
if (!p4d)
- return NULL;
+ return -ENOMEM;
pud = pud_alloc(mm, p4d, addr);
if (!pud)
- return NULL;
+ return -ENOMEM;
pmd = pmd_alloc(mm, pud, addr);
if (!pmd)
- return NULL;
+ return -ENOMEM;
VM_BUG_ON(pmd_trans_huge(*pmd));
- return pmd;
+ *pmdp = pmd;
+ return 0;
}
pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr,
spinlock_t **ptl)
{
- pmd_t *pmd = walk_to_pmd(mm, addr);
+ pmd_t *pmd;
- if (!pmd)
+ if (walk_to_pmd(mm, addr, &pmd))
return NULL;
return pte_alloc_map_lock(mm, pmd, addr, ptl);
}
@@ -2558,13 +2559,11 @@ static int insert_pages(struct vm_area_struct *vma, unsigned long addr,
unsigned long curr_page_idx = 0;
unsigned long remaining_pages_total = *num;
unsigned long pages_to_write_in_pmd;
- int err = 0;
+ int err;
more:
- pmd = walk_to_pmd(mm, addr);
- if (!pmd) {
- err = -ENOMEM;
+ err = walk_to_pmd(mm, addr, &pmd);
+ if (err)
goto out;
- }
pages_to_write_in_pmd = min_t(unsigned long,
remaining_pages_total, PTRS_PER_PTE - pte_index(addr));
--
2.56.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v4 2/4] mm/memory: remove racy huge PMD assertion from walk_to_pmd()
2026-11-26 14:36 [PATCH v4 0/4] mm: fix races between huge and non-huge faults in PFN mappings Lorenzo Stoakes (ARM)
2026-11-26 14:36 ` [PATCH v4 1/4] mm: update walk_to_pmd() to explicitly return an error Lorenzo Stoakes (ARM)
@ 2026-11-26 14:36 ` Lorenzo Stoakes (ARM)
2026-11-26 14:36 ` [PATCH v4 3/4] mm/memory: do not report OOM if insert_pfn() races a huge fault Lorenzo Stoakes (ARM)
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-26 14:36 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Alex Williamson, Peter Xu, Zi Yan, Baolin Wang, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
Kiryl Shutsemau, Wei Liu, Roman Kisel, Saurabh Sengar,
Naman Jain, Michael Kelley
Cc: ljs, linux-mm, linux-kernel, Eliav Farber, stable,
Jose A. Perez de Azpillaga, Gregory Price (Meta),
T.J. Mercier
From: Eliav Farber <farbere@amazon.com>
walk_to_pmd() asserts that the PMD entry it returns is not huge, but does
so without holding the PMD lock, so the assertion is only valid if nothing
can concurrently install a huge PMD entry in the range.
This is not the case for a VMA whose driver implements both ->fault and
->huge_fault and which invokes vmf_insert_pfn() from the former.
The existence of prctl(PR_SET_THP_DISABLE) is problematic here, as it only
takes the mmap write lock and faults taken under the VMA lock are
unaffected by this.
This can result in two concurrent threads faulting the same thing
disagreeing as to whether to attempt a huge fault and thus ->fault and
->huge_fault running at the same time and triggering this assertion.
So just remove the assert.
Target the commit which introduced the first driver able to do this for the
fix - vfio-pci. DAX also mixes fault orders within a VMA, but serialises
them using its own mapping entry lock.
Link: https://lore.kernel.org/all/20261112051440.16140-2-farbere@amazon.com/
Fixes: f9e54c3a2f5b ("vfio/pci: implement huge_fault support")
Cc: stable@vger.kernel.org
Signed-off-by: Eliav Farber <farbere@amazon.com>
[ ljs: rewrote commit message ]
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
Tested-by: Gregory Price (Meta) <gourry@gourry.net>
Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: T.J. Mercier <tjmercier@google.com>
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
---
mm/memory.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/mm/memory.c b/mm/memory.c
index 0e994f076bf7..c07e1de63043 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2401,7 +2401,6 @@ static int walk_to_pmd(struct mm_struct *mm, unsigned long addr, pmd_t **pmdp)
if (!pmd)
return -ENOMEM;
- VM_BUG_ON(pmd_trans_huge(*pmd));
*pmdp = pmd;
return 0;
}
--
2.56.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v4 3/4] mm/memory: do not report OOM if insert_pfn() races a huge fault
2026-11-26 14:36 [PATCH v4 0/4] mm: fix races between huge and non-huge faults in PFN mappings Lorenzo Stoakes (ARM)
2026-11-26 14:36 ` [PATCH v4 1/4] mm: update walk_to_pmd() to explicitly return an error Lorenzo Stoakes (ARM)
2026-11-26 14:36 ` [PATCH v4 2/4] mm/memory: remove racy huge PMD assertion from walk_to_pmd() Lorenzo Stoakes (ARM)
@ 2026-11-26 14:36 ` Lorenzo Stoakes (ARM)
2026-11-26 14:36 ` [PATCH v4 4/4] mm/huge_memory: only compare PFNs of huge entries on huge fault insert Lorenzo Stoakes (ARM)
2026-11-26 14:42 ` [PATCH v4 0/4] mm: fix races between huge and non-huge faults in PFN mappings David Hildenbrand
4 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-26 14:36 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Alex Williamson, Peter Xu, Zi Yan, Baolin Wang, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
Kiryl Shutsemau, Wei Liu, Roman Kisel, Saurabh Sengar,
Naman Jain, Michael Kelley
Cc: ljs, linux-mm, linux-kernel, Eliav Farber, stable,
Jose A. Perez de Azpillaga, Gregory Price (Meta),
T.J. Mercier
A driver that implements both ->fault and ->huge_fault must anticipate
concurrent use of both.
This can happen, for example, if a user calls prctl(PR_SET_THP_DISABLE)
concurrent with faulting, as that only holds the mmap write lock and thus
does not exclude faulting threads stabilised by VMA lock.
This is not currently safely handled by insert_pfn(), however, which
obtains its PTE entry via get_locked_pte(), and treats a NULL return value
as an allocation failure, returning VM_FAULT_OOM.
The issue is that get_locked_pte() also returns NULL if the PMD entry is
not a page table which can happen if a concurrent huge fault installs a
huge PMD entry between __handle_mm_fault() observing the PMD entry to be
empty and insert_pfn() being invoked.
This can result in VM_FAULT_OOM being reported incorrectly.
Fix this by introducing and using __get_locked_pte() which returns -ENOMEM
if a page table allocation fails or -EBUSY if raced.
This allows insert_pfn() to return VM_FAULT_OOM only when an allocation
fails and VM_FAULT_NOPAGE otherwise so the fault is retried.
The same change is applied to insert_page(), which only impacts DAX (which
has its own locking), however even in this case DAX can be impacted the
page table can be freed by madvise(..., MADV_DONTNEED) if CONFIG_PT_RECLAIM
is set.
This means that insert_page() now propagates the returned error, so -EBUSY
in the case of a race, resulting in the fault being retried.
Similarly, update walk_to_pmd() to return -EBUSY if it encounters a huge
PUD leaf.
And finally, update insert_pages() to return -EBUSY under the same
circumstances for consistency.
Target the commit introducing the first driver able to do this.
Reported-by: Eliav Farber <farbere@amazon.com>
Closes: https://lore.kernel.org/all/20261112051440.16140-3-farbere@amazon.com/
Fixes: f9e54c3a2f5b ("vfio/pci: implement huge_fault support")
Cc: stable@vger.kernel.org
Suggested-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
Tested-by: Gregory Price (Meta) <gourry@gourry.net>
Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: T.J. Mercier <tjmercier@google.com>
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
---
mm/memory.c | 50 +++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 41 insertions(+), 9 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index c07e1de63043..dfa307a9228c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2400,19 +2400,48 @@ static int walk_to_pmd(struct mm_struct *mm, unsigned long addr, pmd_t **pmdp)
pmd = pmd_alloc(mm, pud, addr);
if (!pmd)
return -ENOMEM;
+ /* We may have raced a huge PUD fault. */
+ if (pud_trans_unstable(pud))
+ return -EBUSY;
*pmdp = pmd;
return 0;
}
+/*
+ * Map and lock the PTE entry for addr, allocating page tables as necessary.
+ *
+ * Returns 0 on success, -ENOMEM if a page table could not be allocated, or
+ * -EBUSY if we raced and didn't find a page table.
+ */
+static int __get_locked_pte(struct mm_struct *mm, unsigned long addr,
+ pte_t **ptep, spinlock_t **ptl)
+{
+ pmd_t *pmd;
+ pte_t *pte;
+ int err;
+
+ err = walk_to_pmd(mm, addr, &pmd);
+ if (err)
+ return err;
+ if (pte_alloc(mm, pmd))
+ return -ENOMEM;
+ pte = pte_offset_map_lock(mm, pmd, addr, ptl);
+ if (!pte)
+ return -EBUSY;
+
+ *ptep = pte;
+ return 0;
+}
+
pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr,
spinlock_t **ptl)
{
- pmd_t *pmd;
+ pte_t *pte;
- if (walk_to_pmd(mm, addr, &pmd))
+ if (__get_locked_pte(mm, addr, &pte, ptl))
return NULL;
- return pte_alloc_map_lock(mm, pmd, addr, ptl);
+ return pte;
}
static bool vm_mixed_zeropage_allowed(struct vm_area_struct *vma)
@@ -2523,9 +2552,8 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
retval = validate_page_before_insert(vma, page);
if (retval)
goto out;
- retval = -ENOMEM;
- pte = get_locked_pte(vma->vm_mm, addr, &ptl);
- if (!pte)
+ retval = __get_locked_pte(vma->vm_mm, addr, &pte, &ptl);
+ if (retval)
goto out;
retval = insert_page_into_pte_locked(vma, pte, addr, page, prot,
mkwrite);
@@ -2579,7 +2607,7 @@ static int insert_pages(struct vm_area_struct *vma, unsigned long addr,
start_pte = pte_offset_map_lock(mm, pmd, addr, &pte_lock);
if (!start_pte) {
- err = -EFAULT;
+ err = -EBUSY;
goto out;
}
for (pte = start_pte; pte_idx < batch_size; ++pte, ++pte_idx) {
@@ -2891,10 +2919,14 @@ static vm_fault_t insert_pfn(struct vm_area_struct *vma, unsigned long addr,
struct mm_struct *mm = vma->vm_mm;
pte_t *pte, entry;
spinlock_t *ptl;
+ int err;
- pte = get_locked_pte(mm, addr, &ptl);
- if (!pte)
+ err = __get_locked_pte(mm, addr, &pte, &ptl);
+ if (err == -ENOMEM)
return VM_FAULT_OOM;
+ /* We may have raced a huge fault, if so, retry the fault. */
+ if (err)
+ return VM_FAULT_NOPAGE;
entry = ptep_get(pte);
if (!pte_none(entry))
goto out_unlock;
--
2.56.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v4 4/4] mm/huge_memory: only compare PFNs of huge entries on huge fault insert
2026-11-26 14:36 [PATCH v4 0/4] mm: fix races between huge and non-huge faults in PFN mappings Lorenzo Stoakes (ARM)
` (2 preceding siblings ...)
2026-11-26 14:36 ` [PATCH v4 3/4] mm/memory: do not report OOM if insert_pfn() races a huge fault Lorenzo Stoakes (ARM)
@ 2026-11-26 14:36 ` Lorenzo Stoakes (ARM)
2026-11-26 14:42 ` [PATCH v4 0/4] mm: fix races between huge and non-huge faults in PFN mappings David Hildenbrand
4 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-26 14:36 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Alex Williamson, Peter Xu, Zi Yan, Baolin Wang, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
Kiryl Shutsemau, Wei Liu, Roman Kisel, Saurabh Sengar,
Naman Jain, Michael Kelley
Cc: ljs, linux-mm, linux-kernel, Eliav Farber, stable,
Jose A. Perez de Azpillaga, Gregory Price (Meta),
T.J. Mercier
A driver that implements both ->fault and ->huge_fault must anticipate
concurrent use of both.
This can happen, for example, if a user calls prctl(PR_SET_THP_DISABLE)
concurrent with faulting, as that only holds the mmap write lock and thus
does not exclude faulting threads stabilised by VMA lock.
insert_pmd() and insert_pud() have issues with this as they both assume
that, if the page table entry being populated is not empty, it must be a
present huge entry.
This is problematic as if it is a write fault, it compares its PFN against
the one being inserted, warning if they differ, on the assumption that the
entry is a huge leaf.
Since the entry may be a page table, this is invalid and can result in
spurious warnings.
Equally, the entry might be non-present. Nothing can install such an entry
in the VMAs that reach this code today, but there is no reason to rely upon
that.
Therefore only examine the PFN if the entry is both present and huge, and
otherwise simply return VM_FAULT_NOPAGE so the fault is retried and handled
at the appropriate level.
This is what already happens for a read fault, for which the existing entry
is not examined at all.
Target the commit which introduced the first driver which both mixes fault
orders and passes the write flag for the fix (since this commit, both
drm_gem_shmem and panthor are prey to this issue).
Reported-by: Eliav Farber <farbere@amazon.com>
Closes: https://lore.kernel.org/all/20261112051440.16140-4-farbere@amazon.com/
Fixes: 7bfe3b8ea6e3 ("Drivers: hv: Introduce mshv_vtl driver")
Cc: stable@vger.kernel.org
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Tested-by: Gregory Price (Meta) <gourry@gourry.net>
Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
Acked-by: Naman Jain <namjain@linux.microsoft.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: T.J. Mercier <tjmercier@google.com>
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
---
mm/huge_memory.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index ca9ca39d2768..b15e5b22b180 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1644,6 +1644,10 @@ static vm_fault_t insert_pmd(struct vm_area_struct *vma, unsigned long addr,
const unsigned long pfn = fop.is_folio ? folio_pfn(fop.folio) :
fop.pfn;
+ /* We may have raced a fault which installed a page table. */
+ if (!pmd_present(*pmd) || !pmd_leaf(*pmd))
+ goto out_unlock;
+
if (write) {
if (pmd_pfn(*pmd) != pfn) {
WARN_ON_ONCE(!is_huge_zero_pmd(*pmd));
@@ -1775,6 +1779,10 @@ static vm_fault_t insert_pud(struct vm_area_struct *vma, unsigned long addr,
const unsigned long pfn = fop.is_folio ? folio_pfn(fop.folio) :
fop.pfn;
+ /* We may have raced a fault which installed a page table. */
+ if (!pud_present(*pud) || !pud_leaf(*pud))
+ goto out_unlock;
+
if (write) {
if (WARN_ON_ONCE(pud_pfn(*pud) != pfn))
goto out_unlock;
--
2.56.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4 0/4] mm: fix races between huge and non-huge faults in PFN mappings
2026-11-26 14:36 [PATCH v4 0/4] mm: fix races between huge and non-huge faults in PFN mappings Lorenzo Stoakes (ARM)
` (3 preceding siblings ...)
2026-11-26 14:36 ` [PATCH v4 4/4] mm/huge_memory: only compare PFNs of huge entries on huge fault insert Lorenzo Stoakes (ARM)
@ 2026-11-26 14:42 ` David Hildenbrand
4 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand @ 2026-11-26 14:42 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Alex Williamson, Peter Xu, Zi Yan, Baolin Wang, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
Kiryl Shutsemau, Wei Liu, Roman Kisel, Saurabh Sengar,
Naman Jain, Michael Kelley, Lorenzo Stoakes (ARM)
Cc: linux-mm, linux-kernel, stable, Jose A. Perez de Azpillaga,
T.J. Mercier, Eliav Farber, Gregory Price (Meta)
On Thu, 26 Nov 2026 14:36:18 +0000, Lorenzo Stoakes (ARM) wrote:
> A driver that implements both ->fault and ->huge_fault must anticipate
> concurrent use of both.
>
> This can happen, for example, if a user calls prctl(PR_SET_THP_DISABLE)
> concurrent with faulting, as that only holds the mmap write lock and thus
> does not exclude faulting threads stabilised by VMA lock.
>
> [...]
Applied, thanks!
tree: mm/core.git
branch: core-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we
can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even
though the patches have already been applied. If possible, patch trailers
will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. Further, this is not a guarantee that the
patches will go upstream. If in doubt, please check the listed branch.
[1/4] mm: update walk_to_pmd() to explicitly return an error
https://git.kernel.org/mm/core/c/0ad3f82c
[2/4] mm/memory: remove racy huge PMD assertion from walk_to_pmd()
https://git.kernel.org/mm/core/c/71a45211
[3/4] mm/memory: do not report OOM if insert_pfn() races a huge fault
https://git.kernel.org/mm/core/c/125a4415
[4/4] mm/huge_memory: only compare PFNs of huge entries on huge fault insert
https://git.kernel.org/mm/core/c/36363864
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-26 14:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 14:36 [PATCH v4 0/4] mm: fix races between huge and non-huge faults in PFN mappings Lorenzo Stoakes (ARM)
2026-11-26 14:36 ` [PATCH v4 1/4] mm: update walk_to_pmd() to explicitly return an error Lorenzo Stoakes (ARM)
2026-11-26 14:36 ` [PATCH v4 2/4] mm/memory: remove racy huge PMD assertion from walk_to_pmd() Lorenzo Stoakes (ARM)
2026-11-26 14:36 ` [PATCH v4 3/4] mm/memory: do not report OOM if insert_pfn() races a huge fault Lorenzo Stoakes (ARM)
2026-11-26 14:36 ` [PATCH v4 4/4] mm/huge_memory: only compare PFNs of huge entries on huge fault insert Lorenzo Stoakes (ARM)
2026-11-26 14:42 ` [PATCH v4 0/4] mm: fix races between huge and non-huge faults in PFN mappings David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®