2010-11-26 08:27:00

by Dongdong Deng

[permalink] [raw]
Subject: [PATCH 1/2] debug_core: add a memory barrier before atomic_inc(&slaves_in_kgdb)

The atomic_inc operation of slaves_in_kgdb could be executed on
multi-cpus at the same time when kgdb have more than one slave
cpu.

Due to the atomic_inc() function do not imply memory barrier,
a missing memory barrier here maybe could casue an incorrect
value of slaves_in_kgdb, then let kgdb confused.

Add a memory barrier before atomic_inc(&slaves_in_kgdb) to
avoid that potential problem.

Signed-off-by: Dongdong Deng <[email protected]>
---
kernel/debug/debug_core.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index cefd4a1..bec8af0 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -468,10 +468,13 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
kgdb_info[ks->cpu].enter_kgdb++;
kgdb_info[ks->cpu].exception_state |= exception_state;

- if (exception_state == DCPU_WANT_MASTER)
+ if (exception_state == DCPU_WANT_MASTER) {
+ smp_mb__before_atomic_inc();
atomic_inc(&masters_in_kgdb);
- else
+ } else {
+ smp_mb__before_atomic_inc();
atomic_inc(&slaves_in_kgdb);
+ }

if (arch_kgdb_ops.disable_hw_break)
arch_kgdb_ops.disable_hw_break(regs);
--
1.6.0.4


2010-11-26 08:27:00

by Dongdong Deng

[permalink] [raw]
Subject: [PATCH 2/2] debug_core: replace atomic_set() with atomic_xchg() for atomic kgdb_active

The atomic_set() don't imply memory barriers, therefor the single
stepping processor could not observe the changing of kgdb_active
value which was done at other cpu immediately.

Using atomic_xchg() to replace atomic_set() to change kgdb_active,
as it implys the memory barrier semantics around the atomic_xchg().

Signed-off-by: Dongdong Deng <[email protected]>
---
kernel/debug/debug_core.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index bec8af0..722968f 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -548,7 +548,7 @@ return_normal:
if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
(kgdb_info[cpu].task &&
kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
- atomic_set(&kgdb_active, -1);
+ atomic_xchg(&kgdb_active, -1);
raw_spin_unlock(&dbg_master_lock);
dbg_touch_watchdogs();
local_irq_restore(flags);
@@ -657,7 +657,7 @@ kgdb_restore:
smp_mb__before_atomic_dec();
atomic_dec(&masters_in_kgdb);
/* Free kgdb_active */
- atomic_set(&kgdb_active, -1);
+ atomic_xchg(&kgdb_active, -1);
raw_spin_unlock(&dbg_master_lock);
dbg_touch_watchdogs();
local_irq_restore(flags);
--
1.6.0.4