Subject: 64-bit little endian semaphore bug

From: "Kip Walker" <[email-masked]>
Date: Fri, 08 Nov 2002 15:37:38 -0800

In the 64-bit kernel, the semaphore structure (like the 32-bit kernel)
has waking and count fields swizzled so they line up the same in a
64-bit double word for either endian.  However, the semaphore-helper.h
function waking_non_zero_interruptible still has specialized code for
little-endian manipulation of the fields as though they are swapped.

Patch is attached, and fixes a pipe deadlock I was seeing (both the
reader and writer were down'ing the semaphore).

patch is against 2.5, but should be clean against 2.4 also.

Kip

Index: include/asm-mips64/semaphore-helper.h
===================================================================
RCS file: /home/cvs/linux/include/asm-mips64/semaphore-helper.h,v
retrieving revision 1.10
diff -u -r1.10 semaphore-helper.h
--- include/asm-mips64/semaphore-helper.h	19 Aug 2002 23:25:28 -0000	1.10
+++ include/asm-mips64/semaphore-helper.h	8 Nov 2002 22:32:46 -0000
@@ -66,8 +66,6 @@
 {
 	long ret, tmp;
 
-#ifdef __MIPSEB__
-
         __asm__ __volatile__(
 	".set\tpush\t\t\t# waking_non_zero_interruptible\n\t"
 	".set\tnoat\n\t"
@@ -87,38 +85,6 @@
 	".set\tpop"
 	: "=&r" (ret), "=&r" (tmp), "=m" (*sem)
 	: "r" (signal_pending(tsk)), "i" (-EINTR));
-
-#elif defined(__MIPSEL__)
-
-	__asm__ __volatile__(
-	".set\tpush\t\t\t# waking_non_zero_interruptible\n\t"
-	".set\t	noat\n"
-	"0:\tlld\t%1, %2\n\t"
-	"li\t%0, 0\n\t"
-	"blez\t%1, 1f\n\t"
-	"dli\t$1, 0x0000000100000000\n\t"
-	"dsubu\t%1, %1, $1\n\t"
-	"li\t%0, 1\n\t"
-	"b\t2f\n"
-	"1:\tbeqz\t%3, 2f\n\t"
-	"li\t%0, %4\n\t"
-	/*
-	 * It would be nice to assume that sem->count
-	 * is != -1, but we will guard against that case
-	 */
-	"daddiu\t$1, %1, 1\n\t"
-	"dsll32\t$1, $1, 0\n\t"
-	"dsrl32\t$1, $1, 0\n\t"
-	"dsrl32\t%1, %1, 0\n\t"
-	"dsll32\t%1, %1, 0\n\t"
-	"or\t%1, %1, $1\n"
-	"2:\tscd\t%1, %2\n\t"
-	"beqz\t	%1, 0b\n\t"
-	".set\tpop"
-	: "=&r" (ret), "=&r" (tmp), "=m" (*sem)
-	: "r" (signal_pending(tsk)), "i" (-EINTR));
-
-#endif
 
 	return ret;
 }

---

From: Ralf Baechle <[email-masked]>
Date: Sat, 9 Nov 2002 20:42:13 +0100

> patch is against 2.5, but should be clean against 2.4 also.

Patch is ok.  I tweaked it slightly to make the 2.4 and 2.5 versions
identical.

General request to everybody - cc me on all patches that you wish to
submit even if you're posting them to some list.

  Ralf