Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/memory: move adjusting of address range to unmap_vmas()

__zap_vma_range() has two callers, whereby zap_page_range_single_batched()
documents that the range must fit into the VMA range.

So move adjusting the range to unmap_vmas() where it is actually required
and add a safety check in __zap_vma_range() instead. In unmap_vmas(),
we'd never expect to have empty ranges (otherwise, why have the vma in
there in the first place).

__zap_vma_range() will no longer be called with start == end, so cleanup
the function a bit. While at it, simplify the overly long comment to its
core message.

We will no longer call uprobe_munmap() for start == end, which actually
seems to be the right thing to do.

Note that hugetlb_zap_begin()->...->adjust_range_if_pmd_sharing_possible()
cannot result in the range exceeding the vma range.

Link: https://lkml.kernel.org/r/20260227200848.114019-9-david@kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Arve <arve@android.com>
Cc: "Borislav Petkov (AMD)" <bp@alien8.de>
Cc: Carlos Llamas <cmllamas@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Daniel Borkman <daniel@iogearbox.net>
Cc: Dave Airlie <airlied@gmail.com>
Cc: David Ahern <dsahern@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Dimitri Sivanich <dimitri.sivanich@hpe.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jakub Kacinski <kuba@kernel.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Janosch Frank <frankja@linux.ibm.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Namhyung kim <namhyung@kernel.org>
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Todd Kjos <tkjos@android.com>
Cc: Tvrtko Ursulin <tursulin@ursulin.net>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand (Arm) and committed by
Andrew Morton
b6c0384a 19e48cb9

+23 -35
+23 -35
mm/memory.c
··· 2073 2073 tlb_end_vma(tlb, vma); 2074 2074 } 2075 2075 2076 - 2077 - static void __zap_vma_range(struct mmu_gather *tlb, 2078 - struct vm_area_struct *vma, unsigned long start_addr, 2079 - unsigned long end_addr, struct zap_details *details) 2076 + static void __zap_vma_range(struct mmu_gather *tlb, struct vm_area_struct *vma, 2077 + unsigned long start, unsigned long end, 2078 + struct zap_details *details) 2080 2079 { 2081 - unsigned long start = max(vma->vm_start, start_addr); 2082 - unsigned long end; 2083 - 2084 - if (start >= vma->vm_end) 2085 - return; 2086 - end = min(vma->vm_end, end_addr); 2087 - if (end <= vma->vm_start) 2088 - return; 2080 + VM_WARN_ON_ONCE(start >= end || !range_in_vma(vma, start, end)); 2089 2081 2090 2082 if (vma->vm_file) 2091 2083 uprobe_munmap(vma, start, end); 2092 2084 2093 - if (start != end) { 2094 - if (unlikely(is_vm_hugetlb_page(vma))) { 2095 - /* 2096 - * It is undesirable to test vma->vm_file as it 2097 - * should be non-null for valid hugetlb area. 2098 - * However, vm_file will be NULL in the error 2099 - * cleanup path of mmap_region. When 2100 - * hugetlbfs ->mmap method fails, 2101 - * mmap_region() nullifies vma->vm_file 2102 - * before calling this function to clean up. 2103 - * Since no pte has actually been setup, it is 2104 - * safe to do nothing in this case. 2105 - */ 2106 - if (vma->vm_file) { 2107 - zap_flags_t zap_flags = details ? 2108 - details->zap_flags : 0; 2109 - __unmap_hugepage_range(tlb, vma, start, end, 2110 - NULL, zap_flags); 2111 - } 2112 - } else 2113 - unmap_page_range(tlb, vma, start, end, details); 2085 + if (unlikely(is_vm_hugetlb_page(vma))) { 2086 + zap_flags_t zap_flags = details ? details->zap_flags : 0; 2087 + 2088 + /* 2089 + * vm_file will be NULL when we fail early while instantiating 2090 + * a new mapping. In this case, no pages were mapped yet and 2091 + * there is nothing to do. 2092 + */ 2093 + if (!vma->vm_file) 2094 + return; 2095 + __unmap_hugepage_range(tlb, vma, start, end, NULL, zap_flags); 2096 + } else { 2097 + unmap_page_range(tlb, vma, start, end, details); 2114 2098 } 2115 2099 } 2116 2100 ··· 2158 2174 unmap->vma_start, unmap->vma_end); 2159 2175 mmu_notifier_invalidate_range_start(&range); 2160 2176 do { 2161 - unsigned long start = unmap->vma_start; 2162 - unsigned long end = unmap->vma_end; 2177 + unsigned long start = max(vma->vm_start, unmap->vma_start); 2178 + unsigned long end = min(vma->vm_end, unmap->vma_end); 2179 + 2163 2180 hugetlb_zap_begin(vma, &start, &end); 2164 2181 __zap_vma_range(tlb, vma, start, end, &details); 2165 2182 hugetlb_zap_end(vma, &details); ··· 2188 2203 struct mmu_notifier_range range; 2189 2204 2190 2205 VM_WARN_ON_ONCE(!tlb || tlb->mm != vma->vm_mm); 2206 + 2207 + if (unlikely(!size)) 2208 + return; 2191 2209 2192 2210 mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma->vm_mm, 2193 2211 address, end);