powerpc/mm: handle VDSO unmapping via close() rather than arch_unmap()
authorMichael Ellerman <mpe@ellerman.id.au>
Mon, 12 Aug 2024 08:26:03 +0000 (18:26 +1000)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 2 Sep 2024 03:26:12 +0000 (20:26 -0700)
Add a close() callback to the VDSO special mapping to handle unmapping of
the VDSO.  That will make it possible to remove the arch_unmap() hook
entirely in a subsequent patch.

Link: https://lkml.kernel.org/r/20240812082605.743814-2-mpe@ellerman.id.au
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Jeff Xu <jeffxu@google.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/powerpc/include/asm/mmu_context.h
arch/powerpc/kernel/vdso.c

index 37bffa0f79183bdf49c7998303b88bd5bf7a5008..9b8c1555744e66ae37652270a842637b0df6ac7f 100644 (file)
@@ -263,10 +263,6 @@ extern void arch_exit_mmap(struct mm_struct *mm);
 static inline void arch_unmap(struct mm_struct *mm,
                              unsigned long start, unsigned long end)
 {
-       unsigned long vdso_base = (unsigned long)mm->context.vdso;
-
-       if (start <= vdso_base && vdso_base < end)
-               mm->context.vdso = NULL;
 }
 
 #ifdef CONFIG_PPC_MEM_KEYS
index 7a2ff9010f1727e653b149b006b675d2b4ed20b4..220a76cae7c180c5f0290d6d3f70e2fd5032bef3 100644 (file)
@@ -81,6 +81,21 @@ static int vdso64_mremap(const struct vm_special_mapping *sm, struct vm_area_str
        return vdso_mremap(sm, new_vma, &vdso64_end - &vdso64_start);
 }
 
+static void vdso_close(const struct vm_special_mapping *sm, struct vm_area_struct *vma)
+{
+       struct mm_struct *mm = vma->vm_mm;
+
+       /*
+        * close() is called for munmap() but also for mremap(). In the mremap()
+        * case the vdso pointer has already been updated by the mremap() hook
+        * above, so it must not be set to NULL here.
+        */
+       if (vma->vm_start != (unsigned long)mm->context.vdso)
+               return;
+
+       mm->context.vdso = NULL;
+}
+
 static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
                             struct vm_area_struct *vma, struct vm_fault *vmf);
 
@@ -92,11 +107,13 @@ static struct vm_special_mapping vvar_spec __ro_after_init = {
 static struct vm_special_mapping vdso32_spec __ro_after_init = {
        .name = "[vdso]",
        .mremap = vdso32_mremap,
+       .close = vdso_close,
 };
 
 static struct vm_special_mapping vdso64_spec __ro_after_init = {
        .name = "[vdso]",
        .mremap = vdso64_mremap,
+       .close = vdso_close,
 };
 
 #ifdef CONFIG_TIME_NS