[patch] xmon bitlock fix
Nick Piggin
npiggin at suse.de
Tue Nov 20 16:08:26 EST 2007
(sorry, untested for lack of hardware)
--
xmon uses a bit lock spinlock but doesn't close the critical section
when releasing it. It doesn't seem like a big deal because it will
eventually break out of the lock anyway, but presumably that's only
in exceptional cases where some error is tolerated, while the lack of a memory
barrier could allow incorrect results during normal functioning operation
as well.
Convert it to use a regular spinlock instead.
Signed-off-by: Nick Piggin <npiggin at suse.de>
Acked-by: Benjamin Herrenschmidt <benh at kernel.crashing.org>
---
Index: linux-2.6/arch/ppc/xmon/start.c
===================================================================
--- linux-2.6.orig/arch/ppc/xmon/start.c
+++ linux-2.6/arch/ppc/xmon/start.c
@@ -92,16 +92,14 @@ xmon_write(void *handle, void *ptr, int
{
char *p = ptr;
int i, c, ct;
-
-#ifdef CONFIG_SMP
- static unsigned long xmon_write_lock;
+ static DEFINE_SPINLOCK(xmon_write_lock);
int lock_wait = 1000000;
int locked;
- while ((locked = test_and_set_bit(0, &xmon_write_lock)) != 0)
+ while (!(locked = spin_trylock(&xmon_write_lock))) {
if (--lock_wait == 0)
break;
-#endif
+ }
if (!scc_initialized)
xmon_init_scc();
@@ -122,10 +120,9 @@ xmon_write(void *handle, void *ptr, int
eieio();
}
-#ifdef CONFIG_SMP
- if (!locked)
- clear_bit(0, &xmon_write_lock);
-#endif
+ if (locked)
+ spin_unlock(&xmon_write_lock);
+
return nb;
}
More information about the Linuxppc-dev
mailing list