kgdb: use atomic_inc and atomic_dec instead of atomic_set
authorJason Wessel <jason.wessel@windriver.com>
Fri, 2 Apr 2010 19:58:18 +0000 (14:58 -0500)
committerJason Wessel <jason.wessel@windriver.com>
Fri, 2 Apr 2010 19:58:18 +0000 (14:58 -0500)
Memory barriers should be used for the kgdb cpu synchronization.  The
atomic_set() does not imply a memory barrier.

Reported-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
kernel/kgdb.c

index 6882c04..2f7f454 100644 (file)
@@ -1379,8 +1379,7 @@ acquirelock:
         * Make sure the above info reaches the primary CPU before
         * our cpu_in_kgdb[] flag setting does:
         */
         * Make sure the above info reaches the primary CPU before
         * our cpu_in_kgdb[] flag setting does:
         */
-       smp_wmb();
-       atomic_set(&cpu_in_kgdb[cpu], 1);
+       atomic_inc(&cpu_in_kgdb[cpu]);
 
        /*
         * CPU will loop if it is a slave or request to become a kgdb
 
        /*
         * CPU will loop if it is a slave or request to become a kgdb
@@ -1400,7 +1399,7 @@ return_normal:
                         */
                        if (arch_kgdb_ops.correct_hw_break)
                                arch_kgdb_ops.correct_hw_break();
                         */
                        if (arch_kgdb_ops.correct_hw_break)
                                arch_kgdb_ops.correct_hw_break();
-                       atomic_set(&cpu_in_kgdb[cpu], 0);
+                       atomic_dec(&cpu_in_kgdb[cpu]);
                        touch_softlockup_watchdog_sync();
                        clocksource_touch_watchdog();
                        local_irq_restore(flags);
                        touch_softlockup_watchdog_sync();
                        clocksource_touch_watchdog();
                        local_irq_restore(flags);
@@ -1449,7 +1448,7 @@ return_normal:
         */
        if (!kgdb_single_step) {
                for (i = 0; i < NR_CPUS; i++)
         */
        if (!kgdb_single_step) {
                for (i = 0; i < NR_CPUS; i++)
-                       atomic_set(&passive_cpu_wait[i], 1);
+                       atomic_inc(&passive_cpu_wait[i]);
        }
 
 #ifdef CONFIG_SMP
        }
 
 #ifdef CONFIG_SMP
@@ -1483,11 +1482,11 @@ return_normal:
        if (kgdb_io_ops->post_exception)
                kgdb_io_ops->post_exception();
 
        if (kgdb_io_ops->post_exception)
                kgdb_io_ops->post_exception();
 
-       atomic_set(&cpu_in_kgdb[ks->cpu], 0);
+       atomic_dec(&cpu_in_kgdb[ks->cpu]);
 
        if (!kgdb_single_step) {
                for (i = NR_CPUS-1; i >= 0; i--)
 
        if (!kgdb_single_step) {
                for (i = NR_CPUS-1; i >= 0; i--)
-                       atomic_set(&passive_cpu_wait[i], 0);
+                       atomic_dec(&passive_cpu_wait[i]);
                /*
                 * Wait till all the CPUs have quit
                 * from the debugger.
                /*
                 * Wait till all the CPUs have quit
                 * from the debugger.
@@ -1736,11 +1735,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);
  */
 void kgdb_breakpoint(void)
 {
  */
 void kgdb_breakpoint(void)
 {
-       atomic_set(&kgdb_setting_breakpoint, 1);
+       atomic_inc(&kgdb_setting_breakpoint);
        wmb(); /* Sync point before breakpoint */
        arch_kgdb_breakpoint();
        wmb(); /* Sync point after breakpoint */
        wmb(); /* Sync point before breakpoint */
        arch_kgdb_breakpoint();
        wmb(); /* Sync point after breakpoint */
-       atomic_set(&kgdb_setting_breakpoint, 0);
+       atomic_dec(&kgdb_setting_breakpoint);
 }
 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
 
 }
 EXPORT_SYMBOL_GPL(kgdb_breakpoint);