From: Kefeng Wang Date: Thu, 23 Oct 2025 11:37:34 +0000 (+0800) Subject: mm: mprotect: always skip dma pinned folio in prot_numa_skip() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=03aa8e4f273284a6abf28c0d86529cf3947328b2;p=thirdparty%2Fkernel%2Flinux.git mm: mprotect: always skip dma pinned folio in prot_numa_skip() Patch series "mm: some optimizations for prot numa", v5. This patch (of 4): If the folio (even not CoW folio) is dma pinned, it can't be migrated due to the elevated reference count. So always skip a pinned folio to avoid wasting cycles when folios are migrated. Link: https://lkml.kernel.org/r/20251023113737.3572790-1-wangkefeng.wang@huawei.com Link: https://lkml.kernel.org/r/20251023113737.3572790-2-wangkefeng.wang@huawei.com Signed-off-by: Kefeng Wang Acked-by: Zi Yan Acked-by: David Hildenbrand Reviewed-by: Barry Song Reviewed-by: Dev Jain Reviewed-by: Lance Yang Reviewed-by: Sidhartha Kumar Reviewed-by: Lorenzo Stoakes Cc: Baolin Wang Cc: Liam Howlett Cc: Ryan Roberts Signed-off-by: Andrew Morton --- diff --git a/mm/mprotect.c b/mm/mprotect.c index 988c366137d50..056986d9076a8 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -136,9 +136,12 @@ static bool prot_numa_skip(struct vm_area_struct *vma, unsigned long addr, if (folio_is_zone_device(folio) || folio_test_ksm(folio)) goto skip; - /* Also skip shared copy-on-write pages */ - if (is_cow_mapping(vma->vm_flags) && - (folio_maybe_dma_pinned(folio) || folio_maybe_mapped_shared(folio))) + /* Also skip shared copy-on-write folios */ + if (is_cow_mapping(vma->vm_flags) && folio_maybe_mapped_shared(folio)) + goto skip; + + /* Folios are pinned and can't be migrated */ + if (folio_maybe_dma_pinned(folio)) goto skip; /*