powerpc/64s: Use dec_mm_active_cpus helper
authorNicholas Piggin <npiggin@gmail.com>
Wed, 24 May 2023 06:08:19 +0000 (16:08 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 2 Aug 2023 12:22:18 +0000 (22:22 +1000)
Avoid open-coded atomic_dec on mm->context.active_cpus and use the
function made for it. Add CONFIG_DEBUG_VM underflow checking on the
counter.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230524060821.148015-3-npiggin@gmail.com
arch/powerpc/include/asm/book3s/64/mmu.h
arch/powerpc/include/asm/mmu_context.h
arch/powerpc/mm/book3s64/radix_tlb.c

index 570a4960cf1790e00e1465979cd74bdf143b9955..5cf0e9c953b32737c18e72c6075095da479122c6 100644 (file)
@@ -261,7 +261,7 @@ static inline void radix_init_pseries(void) { }
 #define arch_clear_mm_cpumask_cpu(cpu, mm)                             \
        do {                                                            \
                if (cpumask_test_cpu(cpu, mm_cpumask(mm))) {            \
-                       atomic_dec(&(mm)->context.active_cpus);         \
+                       dec_mm_active_cpus(mm);                         \
                        cpumask_clear_cpu(cpu, mm_cpumask(mm));         \
                }                                                       \
        } while (0)
index 57f5017111f476d3a43de48f40ed2fb92cc1dde4..37bffa0f79183bdf49c7998303b88bd5bf7a5008 100644 (file)
@@ -127,6 +127,7 @@ static inline void inc_mm_active_cpus(struct mm_struct *mm)
 
 static inline void dec_mm_active_cpus(struct mm_struct *mm)
 {
+       VM_WARN_ON_ONCE(atomic_read(&mm->context.active_cpus) <= 0);
        atomic_dec(&mm->context.active_cpus);
 }
 
index 0bd4866d98241d68546ec7669fc265b93866badb..4e72d8007f885d56b9776d5428c0c288636d2d09 100644 (file)
@@ -820,7 +820,7 @@ void exit_lazy_flush_tlb(struct mm_struct *mm, bool always_flush)
         * that's what the caller expects.
         */
        if (cpumask_test_cpu(cpu, mm_cpumask(mm))) {
-               atomic_dec(&mm->context.active_cpus);
+               dec_mm_active_cpus(mm);
                cpumask_clear_cpu(cpu, mm_cpumask(mm));
                always_flush = true;
        }