From: Jinjiang Tu <tujinjiang@huawei.com>
To: <akpm@linux-foundation.org>, <david@kernel.org>, <ljs@kernel.org>,
<catalin.marinas@arm.com>, <will@kernel.org>,
<mark.rutland@arm.com>, <ryan.roberts@arm.com>,
<peterx@redhat.com>, <dave.jiang@intel.com>,
<linux-arm-kernel@lists.infradead.org>, <linux-mm@kvack.org>
Cc: <wangkefeng.wang@huawei.com>, <sunnanyong@huawei.com>,
<tujinjiang@huawei.com>
Subject: [PATCH v2 3/4] mm: add spurious fault fixing support for huge pud
Date: Tue, 17 Nov 2026 10:02:36 +0800 [thread overview]
Message-ID: <20261117020237.4037980-4-tujinjiang@huawei.com> (raw)
In-Reply-To: <20261117020237.4037980-1-tujinjiang@huawei.com>
Spurious fault fixing is supported for PTE and huge PMD mappings, but not
for huge PUD mappings.
The next patch in the series adds PUD THP support for DAX and pfnmap on
arm64. arm64 write protection faults only flush the local TLB and leave
stale read-only entries to be flushed by the faulting CPU, so these
mappings need the huge PUD variant of the same fix.
Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
---
arch/arm64/include/asm/pgtable.h | 4 ++++
include/linux/huge_mm.h | 5 +++--
include/linux/pgtable.h | 4 ++++
mm/huge_memory.c | 17 +++++++++--------
mm/internal.h | 2 +-
mm/memory.c | 14 ++++++++++----
6 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index a06b0f5c3411..3c1c000cc5dd 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -107,6 +107,10 @@ static inline void arch_leave_lazy_mmu_mode(void)
__flush_tlb_range(vma, address, address + PMD_SIZE, PMD_SIZE, 2, \
TLBF_NOBROADCAST | TLBF_NONOTIFY | TLBF_NOWALKCACHE)
+#define flush_tlb_fix_spurious_fault_pud(vma, address, pudp) \
+ __flush_tlb_range(vma, address, address + PUD_SIZE, PUD_SIZE, 1, \
+ TLBF_NOBROADCAST | TLBF_NONOTIFY | TLBF_NOWALKCACHE)
+
#ifdef CONFIG_ARM64_PA_BITS_52
static inline phys_addr_t __pte_to_phys(pte_t pte)
{
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index fac05120ab77..1d8ab7c864f2 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -16,10 +16,11 @@ int copy_huge_pud(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma
pud_t *dst_pud, pud_t *src_pud, unsigned long addr);
#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
-void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud);
+bool huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud);
#else
-static inline void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud)
+static inline bool huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud)
{
+ return true;
}
#endif
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 0021eaf88e1d..795bbc313bcb 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -1493,6 +1493,10 @@ static inline void arch_swap_restore(swp_entry_t entry, struct folio *folio)
#define flush_tlb_fix_spurious_fault_pmd(vma, address, pmdp) do { } while (0)
#endif
+#ifndef flush_tlb_fix_spurious_fault_pud
+#define flush_tlb_fix_spurious_fault_pud(vma, address, pudp) do { } while (0)
+#endif
+
/*
* When walking page tables, get the address of the next boundary,
* or the end address of the range if that comes earlier. Although no
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index eb913acb03b7..09bf622b14ea 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2059,7 +2059,7 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
}
#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
-void touch_pud(struct vm_area_struct *vma, unsigned long addr,
+bool touch_pud(struct vm_area_struct *vma, unsigned long addr,
pud_t *pud, bool write)
{
pud_t _pud;
@@ -2068,8 +2068,12 @@ void touch_pud(struct vm_area_struct *vma, unsigned long addr,
if (write)
_pud = pud_mkdirty(_pud);
if (pudp_set_access_flags(vma, addr & HPAGE_PUD_MASK,
- pud, _pud, write))
+ pud, _pud, write)) {
update_mmu_cache_pud(vma, addr, pud);
+ return true;
+ }
+
+ return false;
}
int copy_huge_pud(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma,
@@ -2118,17 +2122,14 @@ int copy_huge_pud(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma
return ret;
}
-void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud)
+bool huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud)
{
bool write = vmf->flags & FAULT_FLAG_WRITE;
- vmf->ptl = pud_lock(vmf->vma->vm_mm, vmf->pud);
if (unlikely(!pud_same(*vmf->pud, orig_pud)))
- goto unlock;
+ return false;
- touch_pud(vmf->vma, vmf->address, vmf->pud, write);
-unlock:
- spin_unlock(vmf->ptl);
+ return touch_pud(vmf->vma, vmf->address, vmf->pud, write);
}
#endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */
diff --git a/mm/internal.h b/mm/internal.h
index e3f92883bf23..0a0a71fa110d 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1311,7 +1311,7 @@ int __must_check try_grab_folio(struct folio *folio, int refs,
/*
* mm/huge_memory.c
*/
-void touch_pud(struct vm_area_struct *vma, unsigned long addr,
+bool touch_pud(struct vm_area_struct *vma, unsigned long addr,
pud_t *pud, bool write);
bool touch_pmd(struct vm_area_struct *vma, unsigned long addr,
pmd_t *pmd, bool write);
diff --git a/mm/memory.c b/mm/memory.c
index ec3d9d99ccee..94a6d106e801 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -6578,8 +6578,8 @@ static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud)
*
* Note: flush_tlb_fix_spurious_fault() is defined as flush_tlb_page()
* by default and used as such on most architectures, while
- * flush_tlb_fix_spurious_fault_pmd() is defined as NOP by default and
- * used as such on most architectures.
+ * flush_tlb_fix_spurious_fault_pmd() and flush_tlb_fix_spurious_fault_pud()
+ * are defined as NOP by default and used as such on most architectures.
*/
static void fix_spurious_fault(struct vm_fault *vmf,
enum pgtable_level ptlevel)
@@ -6597,9 +6597,12 @@ static void fix_spurious_fault(struct vm_fault *vmf,
if (ptlevel == PGTABLE_LEVEL_PTE)
flush_tlb_fix_spurious_fault(vmf->vma, vmf->address,
vmf->pte);
- else
+ else if (ptlevel == PGTABLE_LEVEL_PMD)
flush_tlb_fix_spurious_fault_pmd(vmf->vma, vmf->address,
vmf->pmd);
+ else
+ flush_tlb_fix_spurious_fault_pud(vmf->vma, vmf->address,
+ vmf->pud);
}
}
/*
@@ -6757,7 +6760,10 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma,
if (!(ret & VM_FAULT_FALLBACK))
return ret;
} else {
- huge_pud_set_accessed(&vmf, orig_pud);
+ vmf.ptl = pud_lock(vmf.vma->vm_mm, vmf.pud);
+ if (!huge_pud_set_accessed(&vmf, orig_pud))
+ fix_spurious_fault(&vmf, PGTABLE_LEVEL_PUD);
+ spin_unlock(vmf.ptl);
return 0;
}
}
--
2.54.0
next prev parent reply other threads:[~2026-11-17 2:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 2:02 [PATCH v2 0/4] arm64: Add PUD THP support for DAX and pfnmap Jinjiang Tu
2026-11-17 2:02 ` [PATCH v2 1/4] mm: define generic pudp_invalidate() implementation Jinjiang Tu
2026-11-17 21:32 ` David Hildenbrand (Arm)
2026-11-17 2:02 ` [PATCH v2 2/4] arm64: simplify pmd_special and pmd_mkspecial Jinjiang Tu
2026-11-17 2:02 ` Jinjiang Tu [this message]
2026-11-17 2:02 ` [PATCH v2 4/4] arm64: Add PUD THP support for DAX and pfnmap Jinjiang Tu
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=20261117020237.4037980-4-tujinjiang@huawei.com \
--to=tujinjiang@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=dave.jiang@intel.com \
--cc=david@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mark.rutland@arm.com \
--cc=peterx@redhat.com \
--cc=ryan.roberts@arm.com \
--cc=sunnanyong@huawei.com \
--cc=wangkefeng.wang@huawei.com \
--cc=will@kernel.org \
/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