Skip to content

Commit 8a13897

Browse files
CmdrMoozyakpm00
authored andcommitted
mm: userfaultfd: support UFFDIO_POISON for hugetlbfs
The behavior here is the same as it is for anon/shmem. This is done separately because hugetlb pte marker handling is a bit different. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Axel Rasmussen <[email protected]> Acked-by: Peter Xu <[email protected]> Cc: Al Viro <[email protected]> Cc: Brian Geffon <[email protected]> Cc: Christian Brauner <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Gaosheng Cui <[email protected]> Cc: Huang, Ying <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: James Houghton <[email protected]> Cc: Jan Alexander Steffens (heftig) <[email protected]> Cc: Jiaqi Yan <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Kefeng Wang <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Miaohe Lin <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Mike Rapoport (IBM) <[email protected]> Cc: Muchun Song <[email protected]> Cc: Nadav Amit <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Suleiman Souhlal <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: T.J. Alumbaugh <[email protected]> Cc: Yu Zhao <[email protected]> Cc: ZhangPeng <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 597425d commit 8a13897

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

mm/hugetlb.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6262,6 +6262,25 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
62626262
int writable;
62636263
bool folio_in_pagecache = false;
62646264

6265+
if (uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON)) {
6266+
ptl = huge_pte_lock(h, dst_mm, dst_pte);
6267+
6268+
/* Don't overwrite any existing PTEs (even markers) */
6269+
if (!huge_pte_none(huge_ptep_get(dst_pte))) {
6270+
spin_unlock(ptl);
6271+
return -EEXIST;
6272+
}
6273+
6274+
_dst_pte = make_pte_marker(PTE_MARKER_POISONED);
6275+
set_huge_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte);
6276+
6277+
/* No need to invalidate - it was non-present before */
6278+
update_mmu_cache(dst_vma, dst_addr, dst_pte);
6279+
6280+
spin_unlock(ptl);
6281+
return 0;
6282+
}
6283+
62656284
if (is_continue) {
62666285
ret = -EFAULT;
62676286
folio = filemap_lock_folio(mapping, idx);

mm/userfaultfd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb(
377377
* by THP. Since we can not reliably insert a zero page, this
378378
* feature is not supported.
379379
*/
380-
if (uffd_flags_mode_is(flags, MFILL_ATOMIC_ZEROPAGE) ||
381-
uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON)) {
380+
if (uffd_flags_mode_is(flags, MFILL_ATOMIC_ZEROPAGE)) {
382381
mmap_read_unlock(dst_mm);
383382
return -EINVAL;
384383
}

0 commit comments

Comments
 (0)