FW: cmpxchg hard lockup on AMD64 - ASUS(A8V-MX)

From: chaitanya Huilgol
Date: Mon May 22 2006 - 04:06:09 EST

I am seeing a hard lockup when the lock-free lifo
implementation below is run on a AMD Athlon 64
and ASUS A8V-MX motherboard. GCC version is
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-47.fc4)

I have run this code on Pentiums without any issue
till now. Also the same code works fine in userland.
I fail to understand as to why the problem occurs
only in kernel mode.



#ifdef __SMP__
#define LOCK "lock ; "
#define LOCK ""

typedef struct cell {
struct cell* link; /* next cell in the lifo */
/*...*/ /* any data here */
} cell;

typedef struct lifo {
volatile cell* top; /* top of the stack */
volatile unsigned long cnt; /* used to avoid ABA problem */
} lifo;
void init(lifo* lf)
lf->top = 0;
lf->cnt = 0;

void push (lifo * lf, cell * cl)
__asm__ __volatile__ (
"# LFPUSH \n\t"
"movl %2, (%1) \n"
LOCK "cmpxchg %1, %0 \n\t"
"jnz 1b \n\t"
:"m" (*lf), "r" (cl), "a" (lf->top)

cell* pop (lifo * lf)
cell* v=0;
__asm__ __volatile__ (
"# LFPOP \n\t"
"testl %%eax, %%eax \n\t"
"jz 20f \n"
"movl (%%eax), %%ebx \n\t"
"movl %%edx, %%ecx \n\t"
"incl %%ecx \n\t"
LOCK "cmpxchg8b %1 \n\t"
"jz 20f \n\t"
"testl %%eax, %%eax \n\t"
"jnz 10b \n"
:"=a" (v)
:"m" (*lf), "a" (lf->top), "d" (lf->cnt)
:"ecx", "ebx" );
return v;

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/