# This changes the ldt semaphore to a global.  It's not a highly
# contended lock, so having one in each ldt struct doesn't make a lot
# of sense.  Also, having it in uml_ldt_t makes it hard to build
# userspace code which uses it.

Index: linux-2.6.16/arch/um/sys-i386/ldt.c
===================================================================
--- linux-2.6.16.orig/arch/um/sys-i386/ldt.c	2006-03-23 16:40:20.000000000 -0500
+++ linux-2.6.16/arch/um/sys-i386/ldt.c	2006-03-23 20:31:50.000000000 -0500
@@ -194,6 +194,8 @@ static long read_ldt_from_host(void __us
 	return res;
 }
 
+static DECLARE_MUTEX(ldt_sem);
+
 /*
  * In skas mode, we hold our own ldt data in UML.
  * Thus, the code implementing sys_modify_ldt_skas
@@ -222,7 +224,7 @@ static int read_ldt(void __user * ptr, u
 		return read_ldt_from_host(ptr, bytecount);
 	}
 
-	down(&ldt->semaphore);
+	down(&ldt_sem);
 	if(ldt->entry_count <= LDT_DIRECT_ENTRIES){
 		size = LDT_ENTRY_SIZE*LDT_DIRECT_ENTRIES;
 		if(size > bytecount)
@@ -246,7 +248,7 @@ static int read_ldt(void __user * ptr, u
 			ptr += size;
 		}
 	}
-	up(&ldt->semaphore);
+	up(&ldt_sem);
 
 	if(bytecount == 0 || err == -EFAULT)
 		goto out;
@@ -303,7 +305,7 @@ static int write_ldt(void __user * ptr, 
 	}
 
         if(!ptrace_ldt)
-                down(&ldt->semaphore);
+                down(&ldt_sem);
 
 	err = write_ldt_entry(mm_idp, func, &ldt_info, &addr, 1);
 	if(err)
@@ -363,7 +365,7 @@ static int write_ldt(void __user * ptr, 
 	err = 0;
 
 out_unlock:
-	up(&ldt->semaphore);
+	up(&ldt_sem);
 out:
 	return err;
 }
@@ -458,9 +460,6 @@ long init_new_ldt(struct mmu_context_ska
 	struct proc_mm_op copy;
 
 
-	if(!ptrace_ldt)
-		init_MUTEX(&new_mm->ldt.semaphore);
-
 	if(!from_mm){
 		memset(&desc, 0, sizeof(desc));
 		/*
@@ -519,7 +518,7 @@ long init_new_ldt(struct mmu_context_ska
 		 * i.e., we have to use the stub for modify_ldt, which
 		 * can't handle the big read buffer of up to 64kB.
 		 */
-		down(&from_mm->ldt.semaphore);
+		down(&ldt_sem);
 		if(from_mm->ldt.entry_count <= LDT_DIRECT_ENTRIES){
 			memcpy(new_mm->ldt.u.entries, from_mm->ldt.u.entries,
 			       sizeof(new_mm->ldt.u.entries));
@@ -539,7 +538,7 @@ long init_new_ldt(struct mmu_context_ska
 			}
 		}
 		new_mm->ldt.entry_count = from_mm->ldt.entry_count;
-		up(&from_mm->ldt.semaphore);
+		up(&ldt_sem);
 	}
 
     out:
Index: linux-2.6.16/include/asm-um/ldt-i386.h
===================================================================
--- linux-2.6.16.orig/include/asm-um/ldt-i386.h	2006-01-03 17:39:53.000000000 -0500
+++ linux-2.6.16/include/asm-um/ldt-i386.h	2006-03-23 20:31:50.000000000 -0500
@@ -8,7 +8,7 @@
 #ifndef __ASM_LDT_I386_H
 #define __ASM_LDT_I386_H
 
-#include "asm/semaphore.h"
+#include "asm/page.h"
 #include "asm/arch/ldt.h"
 
 struct mmu_context_skas;
@@ -31,7 +31,6 @@ struct ldt_entry {
 
 typedef struct uml_ldt {
 	int entry_count;
-	struct semaphore semaphore;
 	union {
 		struct ldt_entry * pages[LDT_PAGES_MAX];
 		struct ldt_entry entries[LDT_DIRECT_ENTRIES];
Index: linux-2.6.16/include/asm-um/ldt-x86_64.h
===================================================================
--- linux-2.6.16.orig/include/asm-um/ldt-x86_64.h	2006-03-23 16:40:24.000000000 -0500
+++ linux-2.6.16/include/asm-um/ldt-x86_64.h	2006-03-23 20:31:50.000000000 -0500
@@ -8,8 +8,9 @@
 #ifndef __ASM_LDT_X86_64_H
 #define __ASM_LDT_X86_64_H
 
-#include "asm/semaphore.h"
 #include "asm/arch/ldt.h"
+#include "asm/types.h"
+#include "asm/page.h"
 
 struct mmu_context_skas;
 extern void ldt_host_info(void);
@@ -31,7 +32,6 @@ struct ldt_entry {
 
 typedef struct uml_ldt {
 	int entry_count;
-	struct semaphore semaphore;
 	union {
 		struct ldt_entry * pages[LDT_PAGES_MAX];
 		struct ldt_entry entries[LDT_DIRECT_ENTRIES];
