kgdb: fix signedness mixmatches, add statics, add declaration to header
[sfrench/cifs-2.6.git] / kernel / kgdb.c
index 017ee782bc088861129e60ef29587257883d9fc7..39e31a036f5b0e31bf6187df2751a589d409b328 100644 (file)
@@ -28,6 +28,7 @@
  * kind, whether express or implied.
  */
 #include <linux/pid_namespace.h>
+#include <linux/clocksource.h>
 #include <linux/interrupt.h>
 #include <linux/spinlock.h>
 #include <linux/console.h>
@@ -60,7 +61,7 @@ struct kgdb_state {
        int                     err_code;
        int                     cpu;
        int                     pass_exception;
-       long                    threadid;
+       unsigned long           threadid;
        long                    kgdb_usethreadid;
        struct pt_regs          *linux_regs;
 };
@@ -145,7 +146,7 @@ atomic_t                    kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
  * the other CPUs might interfere with your debugging context, so
  * use this with care:
  */
-int                            kgdb_do_roundup = 1;
+static int kgdb_do_roundup = 1;
 
 static int __init opt_nokgdbroundup(char *str)
 {
@@ -199,6 +200,17 @@ int __weak kgdb_arch_init(void)
        return 0;
 }
 
+int __weak kgdb_skipexception(int exception, struct pt_regs *regs)
+{
+       return 0;
+}
+
+void __weak
+kgdb_post_primary_code(struct pt_regs *regs, int e_vector, int err_code)
+{
+       return;
+}
+
 /**
  *     kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb.
  *     @regs: Current &struct pt_regs.
@@ -426,7 +438,7 @@ int kgdb_hex2mem(char *buf, char *mem, int count)
  * While we find nice hex chars, build a long_val.
  * Return number of chars processed.
  */
-int kgdb_hex2long(char **ptr, long *long_val)
+int kgdb_hex2long(char **ptr, unsigned long *long_val)
 {
        int hex_val;
        int num = 0;
@@ -549,18 +561,6 @@ static void kgdb_wait(struct pt_regs *regs)
        smp_wmb();
        atomic_set(&cpu_in_kgdb[cpu], 1);
 
-       /*
-        * The primary CPU must be active to enter here, but this is
-        * guard in case the primary CPU had not been selected if
-        * this was an entry via nmi.
-        */
-       while (atomic_read(&kgdb_active) == -1)
-               cpu_relax();
-
-       /* Wait till primary CPU goes completely into the debugger. */
-       while (!atomic_read(&cpu_in_kgdb[atomic_read(&kgdb_active)]))
-               cpu_relax();
-
        /* Wait till primary CPU is done with debugging */
        while (atomic_read(&passive_cpu_wait[cpu]))
                cpu_relax();
@@ -574,6 +574,7 @@ static void kgdb_wait(struct pt_regs *regs)
 
        /* Signal the primary CPU that we are done: */
        atomic_set(&cpu_in_kgdb[cpu], 0);
+       clocksource_touch_watchdog();
        local_irq_restore(flags);
 }
 #endif
@@ -587,12 +588,12 @@ static void kgdb_flush_swbreak_addr(unsigned long addr)
        if (!CACHE_FLUSH_IS_SAFE)
                return;
 
-       if (current->mm) {
+       if (current->mm && current->mm->mmap_cache) {
                flush_cache_range(current->mm->mmap_cache,
                                  addr, addr + BREAK_INSTR_SIZE);
-       } else {
-               flush_icache_range(addr, addr + BREAK_INSTR_SIZE);
        }
+       /* Force flush instruction cache if it was outside the mm */
+       flush_icache_range(addr, addr + BREAK_INSTR_SIZE);
 }
 
 /*
@@ -708,7 +709,7 @@ int kgdb_isremovedbreak(unsigned long addr)
        return 0;
 }
 
-int remove_all_break(void)
+static int remove_all_break(void)
 {
        unsigned long addr;
        int error;
@@ -716,14 +717,16 @@ int remove_all_break(void)
 
        /* Clear memory breakpoints. */
        for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
-               if (kgdb_break[i].state != BP_SET)
-                       continue;
+               if (kgdb_break[i].state != BP_ACTIVE)
+                       goto setundefined;
                addr = kgdb_break[i].bpt_addr;
                error = kgdb_arch_remove_breakpoint(addr,
                                kgdb_break[i].saved_instr);
                if (error)
-                       return error;
-               kgdb_break[i].state = BP_REMOVED;
+                       printk(KERN_ERR "KGDB: breakpoint remove failed: %lx\n",
+                          addr);
+setundefined:
+               kgdb_break[i].state = BP_UNDEFINED;
        }
 
        /* Clear hardware breakpoints. */
@@ -1137,10 +1140,10 @@ static void gdb_cmd_break(struct kgdb_state *ks)
                error = kgdb_remove_sw_break(addr);
        else if (remcom_in_buffer[0] == 'Z')
                error = arch_kgdb_ops.set_hw_breakpoint(addr,
-                       (int)length, *bpt_type);
+                       (int)length, *bpt_type - '0');
        else if (remcom_in_buffer[0] == 'z')
                error = arch_kgdb_ops.remove_hw_breakpoint(addr,
-                       (int) length, *bpt_type);
+                       (int) length, *bpt_type - '0');
 
        if (error == 0)
                strcpy(remcom_out_buffer, "OK");
@@ -1325,7 +1328,8 @@ static int kgdb_reenter_check(struct kgdb_state *ks)
                exception_level = 0;
                kgdb_skipexception(ks->ex_vector, ks->linux_regs);
                kgdb_activate_sw_breakpoints();
-               printk(KERN_CRIT "KGDB: re-enter error: breakpoint removed\n");
+               printk(KERN_CRIT "KGDB: re-enter error: breakpoint removed %lx\n",
+                       addr);
                WARN_ON_ONCE(1);
 
                return 1;
@@ -1396,6 +1400,7 @@ acquirelock:
            atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
 
                atomic_set(&kgdb_active, -1);
+               clocksource_touch_watchdog();
                local_irq_restore(flags);
 
                goto acquirelock;
@@ -1430,18 +1435,18 @@ acquirelock:
                        atomic_set(&passive_cpu_wait[i], 1);
        }
 
-#ifdef CONFIG_SMP
-       /* Signal the other CPUs to enter kgdb_wait() */
-       if ((!kgdb_single_step || !kgdb_contthread) && kgdb_do_roundup)
-               kgdb_roundup_cpus(flags);
-#endif
-
        /*
         * spin_lock code is good enough as a barrier so we don't
         * need one here:
         */
        atomic_set(&cpu_in_kgdb[ks->cpu], 1);
 
+#ifdef CONFIG_SMP
+       /* Signal the other CPUs to enter kgdb_wait() */
+       if ((!kgdb_single_step || !kgdb_contthread) && kgdb_do_roundup)
+               kgdb_roundup_cpus(flags);
+#endif
+
        /*
         * Wait for the other CPUs to be notified and be waiting for us:
         */
@@ -1487,6 +1492,7 @@ acquirelock:
 kgdb_restore:
        /* Free kgdb_active */
        atomic_set(&kgdb_active, -1);
+       clocksource_touch_watchdog();
        local_irq_restore(flags);
 
        return error;
@@ -1496,7 +1502,8 @@ int kgdb_nmicallback(int cpu, void *regs)
 {
 #ifdef CONFIG_SMP
        if (!atomic_read(&cpu_in_kgdb[cpu]) &&
-                       atomic_read(&kgdb_active) != cpu) {
+                       atomic_read(&kgdb_active) != cpu &&
+                       atomic_read(&cpu_in_kgdb[atomic_read(&kgdb_active)])) {
                kgdb_wait((struct pt_regs *)regs);
                return 0;
        }
@@ -1589,7 +1596,7 @@ static void kgdb_initial_breakpoint(void)
 }
 
 /**
- *     kkgdb_register_io_module - register KGDB IO module
+ *     kgdb_register_io_module - register KGDB IO module
  *     @new_kgdb_io_ops: the io ops vector
  *
  *     Register it with the KGDB core.