All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i386: convert mm_context_t semaphore to a mutex
@ 2007-08-03 13:55 Luiz Fernando N. Capitulino
  2007-08-06  7:46 ` Ingo Molnar
  0 siblings, 1 reply; 12+ messages in thread
From: Luiz Fernando N. Capitulino @ 2007-08-03 13:55 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, mingo



Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
---
 arch/i386/kernel/i386_ksyms.c |    1 +
 arch/i386/kernel/ldt.c        |   14 +++++++-------
 arch/i386/kernel/ptrace.c     |    4 ++--
 include/asm-i386/mmu.h        |    4 ++--
 4 files changed, 12 insertions(+), 11 deletions(-)

--- linux-2.6-lcpt.orig/arch/i386/kernel/ldt.c
+++ linux-2.6-lcpt/arch/i386/kernel/ldt.c
@@ -94,13 +94,13 @@ int init_new_context(struct task_struct 
 	struct mm_struct * old_mm;
 	int retval = 0;
 
-	init_MUTEX(&mm->context.sem);
+	mutex_init(&mm->context.lock);
 	mm->context.size = 0;
 	old_mm = current->mm;
 	if (old_mm && old_mm->context.size > 0) {
-		down(&old_mm->context.sem);
+		mutex_lock(&old_mm->context.lock);
 		retval = copy_ldt(&mm->context, &old_mm->context);
-		up(&old_mm->context.sem);
+		mutex_unlock(&old_mm->context.lock);
 	}
 	return retval;
 }
@@ -132,7 +132,7 @@ static int read_ldt(void __user * ptr, u
 	if (bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES)
 		bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES;
 
-	down(&mm->context.sem);
+	mutex_lock(&mm->context.lock);
 	size = mm->context.size*LDT_ENTRY_SIZE;
 	if (size > bytecount)
 		size = bytecount;
@@ -140,7 +140,7 @@ static int read_ldt(void __user * ptr, u
 	err = 0;
 	if (copy_to_user(ptr, mm->context.ldt, size))
 		err = -EFAULT;
-	up(&mm->context.sem);
+	mutex_unlock(&mm->context.lock);
 	if (err < 0)
 		goto error_return;
 	if (size != bytecount) {
@@ -196,7 +196,7 @@ static int write_ldt(void __user * ptr, 
 			goto out;
 	}
 
-	down(&mm->context.sem);
+	mutex_lock(&mm->context.lock);
 	if (ldt_info.entry_number >= mm->context.size) {
 		error = alloc_ldt(&current->mm->context, ldt_info.entry_number+1, 1);
 		if (error < 0)
@@ -223,7 +223,7 @@ install:
 	error = 0;
 
 out_unlock:
-	up(&mm->context.sem);
+	mutex_unlock(&mm->context.lock);
 out:
 	return error;
 }
--- linux-2.6-lcpt.orig/arch/i386/kernel/ptrace.c
+++ linux-2.6-lcpt/arch/i386/kernel/ptrace.c
@@ -166,7 +166,7 @@ static unsigned long convert_eip_to_line
 
 		seg &= ~7UL;
 
-		down(&child->mm->context.sem);
+		mutex_lock(&child->mm->context.lock);
 		if (unlikely((seg >> 3) >= child->mm->context.size))
 			addr = -1L; /* bogus selector, access would fault */
 		else {
@@ -180,7 +180,7 @@ static unsigned long convert_eip_to_line
 				addr &= 0xffff;
 			addr += base;
 		}
-		up(&child->mm->context.sem);
+		mutex_unlock(&child->mm->context.lock);
 	}
 	return addr;
 }
--- linux-2.6-lcpt.orig/include/asm-i386/mmu.h
+++ linux-2.6-lcpt/include/asm-i386/mmu.h
@@ -1,7 +1,7 @@
 #ifndef __i386_MMU_H
 #define __i386_MMU_H
 
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 /*
  * The i386 doesn't have a mmu context, but
  * we put the segment information here.
@@ -10,7 +10,7 @@
  */
 typedef struct { 
 	int size;
-	struct semaphore sem;
+	struct mutex lock;
 	void *ldt;
 	void *vdso;
 } mm_context_t;
--- linux-2.6-lcpt.orig/arch/i386/kernel/i386_ksyms.c
+++ linux-2.6-lcpt/arch/i386/kernel/i386_ksyms.c
@@ -1,4 +1,5 @@
 #include <linux/module.h>
+#include <asm/semaphore.h>
 #include <asm/checksum.h>
 #include <asm/desc.h>
 


-- 
Luiz Fernando N. Capitulino

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] i386: convert mm_context_t semaphore to a mutex
  2007-08-03 13:55 [PATCH] i386: convert mm_context_t semaphore to a mutex Luiz Fernando N. Capitulino
@ 2007-08-06  7:46 ` Ingo Molnar
  2007-08-06 13:34   ` Luiz Fernando N. Capitulino
                     ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Ingo Molnar @ 2007-08-06  7:46 UTC (permalink / raw)
  To: Luiz Fernando N. Capitulino; +Cc: Andrew Morton, linux-kernel


>  typedef struct { 
>  	int size;
> -	struct semaphore sem;
> +	struct mutex lock;

hm, looks good to me but i'm wondering why this was a holdout for such a 
long time :-) Did you manage to test actual LDT functionality with this 
patch applied?

	Ingo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] i386: convert mm_context_t semaphore to a mutex
  2007-08-06  7:46 ` Ingo Molnar
@ 2007-08-06 13:34   ` Luiz Fernando N. Capitulino
  2007-08-06 13:36   ` Luiz Fernando N. Capitulino
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: Luiz Fernando N. Capitulino @ 2007-08-06 13:34 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, linux-kernel

Em Mon, 6 Aug 2007 09:46:08 +0200
Ingo Molnar <mingo@elte.hu> escreveu:

| 
| >  typedef struct { 
| >  	int size;
| > -	struct semaphore sem;
| > +	struct mutex lock;
| 
| hm, looks good to me but i'm wondering why this was a holdout for such a 
| long time :-) Did you manage to test actual LDT functionality with this 
| patch applied?

 No, I didn't. The only test I did was to run the kernel with this
patch applied.

 I'll manage to test it then. Do you have a test-case or has any
suggestion?

 Oh, btw, I forgot to 'quilt add arch/i386/mm/fault.c' so the
patch I sent was incomplete. Fixed version below. Shame on me.

[PATCH] i386: convert mm_context_t semaphore to a mutex

---
 arch/i386/kernel/i386_ksyms.c |    1 +
 arch/i386/kernel/ldt.c        |   14 +++++++-------
 arch/i386/kernel/ptrace.c     |    4 ++--
 arch/i386/mm/fault.c          |    4 ++--
 include/asm-i386/mmu.h        |    4 ++--
 5 files changed, 14 insertions(+), 13 deletions(-)

--- linux-2.6-lcpt.orig/arch/i386/kernel/ldt.c
+++ linux-2.6-lcpt/arch/i386/kernel/ldt.c
@@ -94,13 +94,13 @@ int init_new_context(struct task_struct 
 	struct mm_struct * old_mm;
 	int retval = 0;
 
-	init_MUTEX(&mm->context.sem);
+	mutex_init(&mm->context.lock);
 	mm->context.size = 0;
 	old_mm = current->mm;
 	if (old_mm && old_mm->context.size > 0) {
-		down(&old_mm->context.sem);
+		mutex_lock(&old_mm->context.lock);
 		retval = copy_ldt(&mm->context, &old_mm->context);
-		up(&old_mm->context.sem);
+		mutex_unlock(&old_mm->context.lock);
 	}
 	return retval;
 }
@@ -132,7 +132,7 @@ static int read_ldt(void __user * ptr, u
 	if (bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES)
 		bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES;
 
-	down(&mm->context.sem);
+	mutex_lock(&mm->context.lock);
 	size = mm->context.size*LDT_ENTRY_SIZE;
 	if (size > bytecount)
 		size = bytecount;
@@ -140,7 +140,7 @@ static int read_ldt(void __user * ptr, u
 	err = 0;
 	if (copy_to_user(ptr, mm->context.ldt, size))
 		err = -EFAULT;
-	up(&mm->context.sem);
+	mutex_unlock(&mm->context.lock);
 	if (err < 0)
 		goto error_return;
 	if (size != bytecount) {
@@ -196,7 +196,7 @@ static int write_ldt(void __user * ptr, 
 			goto out;
 	}
 
-	down(&mm->context.sem);
+	mutex_lock(&mm->context.lock);
 	if (ldt_info.entry_number >= mm->context.size) {
 		error = alloc_ldt(&current->mm->context, ldt_info.entry_number+1, 1);
 		if (error < 0)
@@ -223,7 +223,7 @@ install:
 	error = 0;
 
 out_unlock:
-	up(&mm->context.sem);
+	mutex_unlock(&mm->context.lock);
 out:
 	return error;
 }
--- linux-2.6-lcpt.orig/arch/i386/kernel/ptrace.c
+++ linux-2.6-lcpt/arch/i386/kernel/ptrace.c
@@ -166,7 +166,7 @@ static unsigned long convert_eip_to_line
 
 		seg &= ~7UL;
 
-		down(&child->mm->context.sem);
+		mutex_lock(&child->mm->context.lock);
 		if (unlikely((seg >> 3) >= child->mm->context.size))
 			addr = -1L; /* bogus selector, access would fault */
 		else {
@@ -180,7 +180,7 @@ static unsigned long convert_eip_to_line
 				addr &= 0xffff;
 			addr += base;
 		}
-		up(&child->mm->context.sem);
+		mutex_unlock(&child->mm->context.lock);
 	}
 	return addr;
 }
--- linux-2.6-lcpt.orig/include/asm-i386/mmu.h
+++ linux-2.6-lcpt/include/asm-i386/mmu.h
@@ -1,7 +1,7 @@
 #ifndef __i386_MMU_H
 #define __i386_MMU_H
 
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 /*
  * The i386 doesn't have a mmu context, but
  * we put the segment information here.
@@ -10,7 +10,7 @@
  */
 typedef struct { 
 	int size;
-	struct semaphore sem;
+	struct mutex lock;
 	void *ldt;
 	void *vdso;
 } mm_context_t;
--- linux-2.6-lcpt.orig/arch/i386/kernel/i386_ksyms.c
+++ linux-2.6-lcpt/arch/i386/kernel/i386_ksyms.c
@@ -1,4 +1,5 @@
 #include <linux/module.h>
+#include <asm/semaphore.h>
 #include <asm/checksum.h>
 #include <asm/desc.h>
 
--- linux-2.6-lcpt.orig/arch/i386/mm/fault.c
+++ linux-2.6-lcpt/arch/i386/mm/fault.c
@@ -110,7 +110,7 @@ static inline unsigned long get_segment_
 	   LDT and other horrors are only used in user space. */
 	if (seg & (1<<2)) {
 		/* Must lock the LDT while reading it. */
-		down(&current->mm->context.sem);
+		mutex_lock(&current->mm->context.lock);
 		desc = current->mm->context.ldt;
 		desc = (void *)desc + (seg & ~7);
 	} else {
@@ -123,7 +123,7 @@ static inline unsigned long get_segment_
 	base = get_desc_base((unsigned long *)desc);
 
 	if (seg & (1<<2)) { 
-		up(&current->mm->context.sem);
+		mutex_unlock(&current->mm->context.lock);
 	} else
 		put_cpu();
 


-- 
Luiz Fernando N. Capitulino

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] i386: convert mm_context_t semaphore to a mutex
  2007-08-06  7:46 ` Ingo Molnar
  2007-08-06 13:34   ` Luiz Fernando N. Capitulino
@ 2007-08-06 13:36   ` Luiz Fernando N. Capitulino
  2007-08-06 15:25     ` Ingo Molnar
  2007-08-06 19:32     ` Andi Kleen
  2007-08-06 13:36   ` Luiz Fernando N. Capitulino
  2007-08-06 13:39   ` Luiz Fernando N. Capitulino
  3 siblings, 2 replies; 12+ messages in thread
From: Luiz Fernando N. Capitulino @ 2007-08-06 13:36 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, linux-kernel

Em Mon, 6 Aug 2007 09:46:08 +0200
Ingo Molnar <mingo@elte.hu> escreveu:

| 
| >  typedef struct { 
| >  	int size;
| > -	struct semaphore sem;
| > +	struct mutex lock;
| 
| hm, looks good to me but i'm wondering why this was a holdout for such a 
| long time :-) Did you manage to test actual LDT functionality with this 
| patch applied?

 No, I didn't. The only test I did was to run the kernel with this
patch applied.

 I'll manage to test it then. Do you have a test-case or has any
suggestion?

 Oh, btw, I forgot to 'quilt add arch/i386/mm/fault.c' so the
patch I sent was incomplete. Fixed version below. Shame on me.

[PATCH] i386: convert mm_context_t semaphore to a mutex

---
 arch/i386/kernel/i386_ksyms.c |    1 +
 arch/i386/kernel/ldt.c        |   14 +++++++-------
 arch/i386/kernel/ptrace.c     |    4 ++--
 arch/i386/mm/fault.c          |    4 ++--
 include/asm-i386/mmu.h        |    4 ++--
 5 files changed, 14 insertions(+), 13 deletions(-)

--- linux-2.6-lcpt.orig/arch/i386/kernel/ldt.c
+++ linux-2.6-lcpt/arch/i386/kernel/ldt.c
@@ -94,13 +94,13 @@ int init_new_context(struct task_struct 
 	struct mm_struct * old_mm;
 	int retval = 0;
 
-	init_MUTEX(&mm->context.sem);
+	mutex_init(&mm->context.lock);
 	mm->context.size = 0;
 	old_mm = current->mm;
 	if (old_mm && old_mm->context.size > 0) {
-		down(&old_mm->context.sem);
+		mutex_lock(&old_mm->context.lock);
 		retval = copy_ldt(&mm->context, &old_mm->context);
-		up(&old_mm->context.sem);
+		mutex_unlock(&old_mm->context.lock);
 	}
 	return retval;
 }
@@ -132,7 +132,7 @@ static int read_ldt(void __user * ptr, u
 	if (bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES)
 		bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES;
 
-	down(&mm->context.sem);
+	mutex_lock(&mm->context.lock);
 	size = mm->context.size*LDT_ENTRY_SIZE;
 	if (size > bytecount)
 		size = bytecount;
@@ -140,7 +140,7 @@ static int read_ldt(void __user * ptr, u
 	err = 0;
 	if (copy_to_user(ptr, mm->context.ldt, size))
 		err = -EFAULT;
-	up(&mm->context.sem);
+	mutex_unlock(&mm->context.lock);
 	if (err < 0)
 		goto error_return;
 	if (size != bytecount) {
@@ -196,7 +196,7 @@ static int write_ldt(void __user * ptr, 
 			goto out;
 	}
 
-	down(&mm->context.sem);
+	mutex_lock(&mm->context.lock);
 	if (ldt_info.entry_number >= mm->context.size) {
 		error = alloc_ldt(&current->mm->context, ldt_info.entry_number+1, 1);
 		if (error < 0)
@@ -223,7 +223,7 @@ install:
 	error = 0;
 
 out_unlock:
-	up(&mm->context.sem);
+	mutex_unlock(&mm->context.lock);
 out:
 	return error;
 }
--- linux-2.6-lcpt.orig/arch/i386/kernel/ptrace.c
+++ linux-2.6-lcpt/arch/i386/kernel/ptrace.c
@@ -166,7 +166,7 @@ static unsigned long convert_eip_to_line
 
 		seg &= ~7UL;
 
-		down(&child->mm->context.sem);
+		mutex_lock(&child->mm->context.lock);
 		if (unlikely((seg >> 3) >= child->mm->context.size))
 			addr = -1L; /* bogus selector, access would fault */
 		else {
@@ -180,7 +180,7 @@ static unsigned long convert_eip_to_line
 				addr &= 0xffff;
 			addr += base;
 		}
-		up(&child->mm->context.sem);
+		mutex_unlock(&child->mm->context.lock);
 	}
 	return addr;
 }
--- linux-2.6-lcpt.orig/include/asm-i386/mmu.h
+++ linux-2.6-lcpt/include/asm-i386/mmu.h
@@ -1,7 +1,7 @@
 #ifndef __i386_MMU_H
 #define __i386_MMU_H
 
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 /*
  * The i386 doesn't have a mmu context, but
  * we put the segment information here.
@@ -10,7 +10,7 @@
  */
 typedef struct { 
 	int size;
-	struct semaphore sem;
+	struct mutex lock;
 	void *ldt;
 	void *vdso;
 } mm_context_t;
--- linux-2.6-lcpt.orig/arch/i386/kernel/i386_ksyms.c
+++ linux-2.6-lcpt/arch/i386/kernel/i386_ksyms.c
@@ -1,4 +1,5 @@
 #include <linux/module.h>
+#include <asm/semaphore.h>
 #include <asm/checksum.h>
 #include <asm/desc.h>
 
--- linux-2.6-lcpt.orig/arch/i386/mm/fault.c
+++ linux-2.6-lcpt/arch/i386/mm/fault.c
@@ -110,7 +110,7 @@ static inline unsigned long get_segment_
 	   LDT and other horrors are only used in user space. */
 	if (seg & (1<<2)) {
 		/* Must lock the LDT while reading it. */
-		down(&current->mm->context.sem);
+		mutex_lock(&current->mm->context.lock);
 		desc = current->mm->context.ldt;
 		desc = (void *)desc + (seg & ~7);
 	} else {
@@ -123,7 +123,7 @@ static inline unsigned long get_segment_
 	base = get_desc_base((unsigned long *)desc);
 
 	if (seg & (1<<2)) { 
-		up(&current->mm->context.sem);
+		mutex_unlock(&current->mm->context.lock);
 	} else
 		put_cpu();
 


-- 
Luiz Fernando N. Capitulino

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] i386: convert mm_context_t semaphore to a mutex
  2007-08-06  7:46 ` Ingo Molnar
  2007-08-06 13:34   ` Luiz Fernando N. Capitulino
  2007-08-06 13:36   ` Luiz Fernando N. Capitulino
@ 2007-08-06 13:36   ` Luiz Fernando N. Capitulino
  2007-08-06 21:10     ` Luiz Fernando N. Capitulino
  2007-08-06 13:39   ` Luiz Fernando N. Capitulino
  3 siblings, 1 reply; 12+ messages in thread
From: Luiz Fernando N. Capitulino @ 2007-08-06 13:36 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, linux-kernel

Em Mon, 6 Aug 2007 09:46:08 +0200
Ingo Molnar <mingo@elte.hu> escreveu:

| 
| >  typedef struct { 
| >  	int size;
| > -	struct semaphore sem;
| > +	struct mutex lock;
| 
| hm, looks good to me but i'm wondering why this was a holdout for such a 
| long time :-) Did you manage to test actual LDT functionality with this 
| patch applied?

 No, I didn't. The only test I did was to run the kernel with this
patch applied.

 I'll manage to test it then. Do you have a test-case or has any
suggestion?

 Oh, btw, I forgot to 'quilt add arch/i386/mm/fault.c' so the
patch I sent was incomplete. Fixed version below. Shame on me.

[PATCH] i386: convert mm_context_t semaphore to a mutex

---
 arch/i386/kernel/i386_ksyms.c |    1 +
 arch/i386/kernel/ldt.c        |   14 +++++++-------
 arch/i386/kernel/ptrace.c     |    4 ++--
 arch/i386/mm/fault.c          |    4 ++--
 include/asm-i386/mmu.h        |    4 ++--
 5 files changed, 14 insertions(+), 13 deletions(-)

--- linux-2.6-lcpt.orig/arch/i386/kernel/ldt.c
+++ linux-2.6-lcpt/arch/i386/kernel/ldt.c
@@ -94,13 +94,13 @@ int init_new_context(struct task_struct 
 	struct mm_struct * old_mm;
 	int retval = 0;
 
-	init_MUTEX(&mm->context.sem);
+	mutex_init(&mm->context.lock);
 	mm->context.size = 0;
 	old_mm = current->mm;
 	if (old_mm && old_mm->context.size > 0) {
-		down(&old_mm->context.sem);
+		mutex_lock(&old_mm->context.lock);
 		retval = copy_ldt(&mm->context, &old_mm->context);
-		up(&old_mm->context.sem);
+		mutex_unlock(&old_mm->context.lock);
 	}
 	return retval;
 }
@@ -132,7 +132,7 @@ static int read_ldt(void __user * ptr, u
 	if (bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES)
 		bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES;
 
-	down(&mm->context.sem);
+	mutex_lock(&mm->context.lock);
 	size = mm->context.size*LDT_ENTRY_SIZE;
 	if (size > bytecount)
 		size = bytecount;
@@ -140,7 +140,7 @@ static int read_ldt(void __user * ptr, u
 	err = 0;
 	if (copy_to_user(ptr, mm->context.ldt, size))
 		err = -EFAULT;
-	up(&mm->context.sem);
+	mutex_unlock(&mm->context.lock);
 	if (err < 0)
 		goto error_return;
 	if (size != bytecount) {
@@ -196,7 +196,7 @@ static int write_ldt(void __user * ptr, 
 			goto out;
 	}
 
-	down(&mm->context.sem);
+	mutex_lock(&mm->context.lock);
 	if (ldt_info.entry_number >= mm->context.size) {
 		error = alloc_ldt(&current->mm->context, ldt_info.entry_number+1, 1);
 		if (error < 0)
@@ -223,7 +223,7 @@ install:
 	error = 0;
 
 out_unlock:
-	up(&mm->context.sem);
+	mutex_unlock(&mm->context.lock);
 out:
 	return error;
 }
--- linux-2.6-lcpt.orig/arch/i386/kernel/ptrace.c
+++ linux-2.6-lcpt/arch/i386/kernel/ptrace.c
@@ -166,7 +166,7 @@ static unsigned long convert_eip_to_line
 
 		seg &= ~7UL;
 
-		down(&child->mm->context.sem);
+		mutex_lock(&child->mm->context.lock);
 		if (unlikely((seg >> 3) >= child->mm->context.size))
 			addr = -1L; /* bogus selector, access would fault */
 		else {
@@ -180,7 +180,7 @@ static unsigned long convert_eip_to_line
 				addr &= 0xffff;
 			addr += base;
 		}
-		up(&child->mm->context.sem);
+		mutex_unlock(&child->mm->context.lock);
 	}
 	return addr;
 }
--- linux-2.6-lcpt.orig/include/asm-i386/mmu.h
+++ linux-2.6-lcpt/include/asm-i386/mmu.h
@@ -1,7 +1,7 @@
 #ifndef __i386_MMU_H
 #define __i386_MMU_H
 
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 /*
  * The i386 doesn't have a mmu context, but
  * we put the segment information here.
@@ -10,7 +10,7 @@
  */
 typedef struct { 
 	int size;
-	struct semaphore sem;
+	struct mutex lock;
 	void *ldt;
 	void *vdso;
 } mm_context_t;
--- linux-2.6-lcpt.orig/arch/i386/kernel/i386_ksyms.c
+++ linux-2.6-lcpt/arch/i386/kernel/i386_ksyms.c
@@ -1,4 +1,5 @@
 #include <linux/module.h>
+#include <asm/semaphore.h>
 #include <asm/checksum.h>
 #include <asm/desc.h>
 
--- linux-2.6-lcpt.orig/arch/i386/mm/fault.c
+++ linux-2.6-lcpt/arch/i386/mm/fault.c
@@ -110,7 +110,7 @@ static inline unsigned long get_segment_
 	   LDT and other horrors are only used in user space. */
 	if (seg & (1<<2)) {
 		/* Must lock the LDT while reading it. */
-		down(&current->mm->context.sem);
+		mutex_lock(&current->mm->context.lock);
 		desc = current->mm->context.ldt;
 		desc = (void *)desc + (seg & ~7);
 	} else {
@@ -123,7 +123,7 @@ static inline unsigned long get_segment_
 	base = get_desc_base((unsigned long *)desc);
 
 	if (seg & (1<<2)) { 
-		up(&current->mm->context.sem);
+		mutex_unlock(&current->mm->context.lock);
 	} else
 		put_cpu();
 


-- 
Luiz Fernando N. Capitulino

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] i386: convert mm_context_t semaphore to a mutex
  2007-08-06  7:46 ` Ingo Molnar
                     ` (2 preceding siblings ...)
  2007-08-06 13:36   ` Luiz Fernando N. Capitulino
@ 2007-08-06 13:39   ` Luiz Fernando N. Capitulino
  3 siblings, 0 replies; 12+ messages in thread
From: Luiz Fernando N. Capitulino @ 2007-08-06 13:39 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, linux-kernel

Em Mon, 6 Aug 2007 09:46:08 +0200
Ingo Molnar <mingo@elte.hu> escreveu:

| 
| >  typedef struct { 
| >  	int size;
| > -	struct semaphore sem;
| > +	struct mutex lock;
| 
| hm, looks good to me but i'm wondering why this was a holdout for such a 
| long time :-) Did you manage to test actual LDT functionality with this 
| patch applied?

 No, I didn't. The only test I did was to run the kernel with this
patch applied.

 I'll manage to test it then. Do you have a test-case or has any
suggestion?

 Oh, btw, I forgot to 'quilt add arch/i386/mm/fault.c' so the
patch I sent was incomplete. Fixed version below. Shame on me.

[PATCH] i386: convert mm_context_t semaphore to a mutex

---
 arch/i386/kernel/i386_ksyms.c |    1 +
 arch/i386/kernel/ldt.c        |   14 +++++++-------
 arch/i386/kernel/ptrace.c     |    4 ++--
 arch/i386/mm/fault.c          |    4 ++--
 include/asm-i386/mmu.h        |    4 ++--
 5 files changed, 14 insertions(+), 13 deletions(-)

--- linux-2.6-lcpt.orig/arch/i386/kernel/ldt.c
+++ linux-2.6-lcpt/arch/i386/kernel/ldt.c
@@ -94,13 +94,13 @@ int init_new_context(struct task_struct 
 	struct mm_struct * old_mm;
 	int retval = 0;
 
-	init_MUTEX(&mm->context.sem);
+	mutex_init(&mm->context.lock);
 	mm->context.size = 0;
 	old_mm = current->mm;
 	if (old_mm && old_mm->context.size > 0) {
-		down(&old_mm->context.sem);
+		mutex_lock(&old_mm->context.lock);
 		retval = copy_ldt(&mm->context, &old_mm->context);
-		up(&old_mm->context.sem);
+		mutex_unlock(&old_mm->context.lock);
 	}
 	return retval;
 }
@@ -132,7 +132,7 @@ static int read_ldt(void __user * ptr, u
 	if (bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES)
 		bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES;
 
-	down(&mm->context.sem);
+	mutex_lock(&mm->context.lock);
 	size = mm->context.size*LDT_ENTRY_SIZE;
 	if (size > bytecount)
 		size = bytecount;
@@ -140,7 +140,7 @@ static int read_ldt(void __user * ptr, u
 	err = 0;
 	if (copy_to_user(ptr, mm->context.ldt, size))
 		err = -EFAULT;
-	up(&mm->context.sem);
+	mutex_unlock(&mm->context.lock);
 	if (err < 0)
 		goto error_return;
 	if (size != bytecount) {
@@ -196,7 +196,7 @@ static int write_ldt(void __user * ptr, 
 			goto out;
 	}
 
-	down(&mm->context.sem);
+	mutex_lock(&mm->context.lock);
 	if (ldt_info.entry_number >= mm->context.size) {
 		error = alloc_ldt(&current->mm->context, ldt_info.entry_number+1, 1);
 		if (error < 0)
@@ -223,7 +223,7 @@ install:
 	error = 0;
 
 out_unlock:
-	up(&mm->context.sem);
+	mutex_unlock(&mm->context.lock);
 out:
 	return error;
 }
--- linux-2.6-lcpt.orig/arch/i386/kernel/ptrace.c
+++ linux-2.6-lcpt/arch/i386/kernel/ptrace.c
@@ -166,7 +166,7 @@ static unsigned long convert_eip_to_line
 
 		seg &= ~7UL;
 
-		down(&child->mm->context.sem);
+		mutex_lock(&child->mm->context.lock);
 		if (unlikely((seg >> 3) >= child->mm->context.size))
 			addr = -1L; /* bogus selector, access would fault */
 		else {
@@ -180,7 +180,7 @@ static unsigned long convert_eip_to_line
 				addr &= 0xffff;
 			addr += base;
 		}
-		up(&child->mm->context.sem);
+		mutex_unlock(&child->mm->context.lock);
 	}
 	return addr;
 }
--- linux-2.6-lcpt.orig/include/asm-i386/mmu.h
+++ linux-2.6-lcpt/include/asm-i386/mmu.h
@@ -1,7 +1,7 @@
 #ifndef __i386_MMU_H
 #define __i386_MMU_H
 
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 /*
  * The i386 doesn't have a mmu context, but
  * we put the segment information here.
@@ -10,7 +10,7 @@
  */
 typedef struct { 
 	int size;
-	struct semaphore sem;
+	struct mutex lock;
 	void *ldt;
 	void *vdso;
 } mm_context_t;
--- linux-2.6-lcpt.orig/arch/i386/kernel/i386_ksyms.c
+++ linux-2.6-lcpt/arch/i386/kernel/i386_ksyms.c
@@ -1,4 +1,5 @@
 #include <linux/module.h>
+#include <asm/semaphore.h>
 #include <asm/checksum.h>
 #include <asm/desc.h>
 
--- linux-2.6-lcpt.orig/arch/i386/mm/fault.c
+++ linux-2.6-lcpt/arch/i386/mm/fault.c
@@ -110,7 +110,7 @@ static inline unsigned long get_segment_
 	   LDT and other horrors are only used in user space. */
 	if (seg & (1<<2)) {
 		/* Must lock the LDT while reading it. */
-		down(&current->mm->context.sem);
+		mutex_lock(&current->mm->context.lock);
 		desc = current->mm->context.ldt;
 		desc = (void *)desc + (seg & ~7);
 	} else {
@@ -123,7 +123,7 @@ static inline unsigned long get_segment_
 	base = get_desc_base((unsigned long *)desc);
 
 	if (seg & (1<<2)) { 
-		up(&current->mm->context.sem);
+		mutex_unlock(&current->mm->context.lock);
 	} else
 		put_cpu();
 


-- 
Luiz Fernando N. Capitulino

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] i386: convert mm_context_t semaphore to a mutex
  2007-08-06 13:36   ` Luiz Fernando N. Capitulino
@ 2007-08-06 15:25     ` Ingo Molnar
  2007-08-06 17:15       ` Luiz Fernando N. Capitulino
  2007-08-06 19:32     ` Andi Kleen
  1 sibling, 1 reply; 12+ messages in thread
From: Ingo Molnar @ 2007-08-06 15:25 UTC (permalink / raw)
  To: Luiz Fernando N. Capitulino; +Cc: Andrew Morton, linux-kernel


* Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br> wrote:

> | hm, looks good to me but i'm wondering why this was a holdout for 
> | such a long time :-) Did you manage to test actual LDT functionality 
> | with this patch applied?
> 
>  No, I didn't. The only test I did was to run the kernel with this 
> patch applied.
> 
>  I'll manage to test it then. Do you have a test-case or has any 
> suggestion?

i think try any pthread program with:

   export LD_ASSUME_KERNEL=2.4.0

should trigger the LDT code. Try stracing the code and modify_ldt calls 
should show up.

>  Oh, btw, I forgot to 'quilt add arch/i386/mm/fault.c' [...]

heh. After a dozen of such incidents i scripted my editor command to 
automatically do the quilt add :)

	Ingo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] i386: convert mm_context_t semaphore to a mutex
  2007-08-06 15:25     ` Ingo Molnar
@ 2007-08-06 17:15       ` Luiz Fernando N. Capitulino
  2007-08-06 17:43         ` Ingo Molnar
  0 siblings, 1 reply; 12+ messages in thread
From: Luiz Fernando N. Capitulino @ 2007-08-06 17:15 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, linux-kernel

Em Mon, 6 Aug 2007 17:25:02 +0200
Ingo Molnar <mingo@elte.hu> escreveu:

| 
| * Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br> wrote:
| 
| > | hm, looks good to me but i'm wondering why this was a holdout for 
| > | such a long time :-) Did you manage to test actual LDT functionality 
| > | with this patch applied?
| > 
| >  No, I didn't. The only test I did was to run the kernel with this 
| > patch applied.
| > 
| >  I'll manage to test it then. Do you have a test-case or has any 
| > suggestion?
| 
| i think try any pthread program with:
| 
|    export LD_ASSUME_KERNEL=2.4.0
| 
| should trigger the LDT code. Try stracing the code and modify_ldt calls 
| should show up.

 I couldn't run this because my libc requires 2.6 kernels.

 But I've managed to run wine with a game called 'Align-it!', and
I have the following result:

"""
~/tmp/ egrep -c 'modify_ldt' wine-strace.txt 
46
~/tmp/ 
"""

 I've checked the calls and none has failed. Not sure how good
this test is though.

 Maybe it could be more tested in -mm?

| >  Oh, btw, I forgot to 'quilt add arch/i386/mm/fault.c' [...]
| 
| heh. After a dozen of such incidents i scripted my editor command to 
| automatically do the quilt add :)

 Oh, that's a good tip.

 Thanks a lot,

-- 
Luiz Fernando N. Capitulino

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] i386: convert mm_context_t semaphore to a mutex
  2007-08-06 17:15       ` Luiz Fernando N. Capitulino
@ 2007-08-06 17:43         ` Ingo Molnar
  0 siblings, 0 replies; 12+ messages in thread
From: Ingo Molnar @ 2007-08-06 17:43 UTC (permalink / raw)
  To: Luiz Fernando N. Capitulino; +Cc: Andrew Morton, linux-kernel


* Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br> wrote:

>  But I've managed to run wine with a game called 'Align-it!', and
> I have the following result:
> 
> """
> ~/tmp/ egrep -c 'modify_ldt' wine-strace.txt 
> 46
> ~/tmp/ 
> """
> 
>  I've checked the calls and none has failed. Not sure how good
> this test is though.

ok, this is certainly good enough.

Acked-by: Ingo Molnar <mingo@elte.hu>

	Ingo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] i386: convert mm_context_t semaphore to a mutex
  2007-08-06 13:36   ` Luiz Fernando N. Capitulino
  2007-08-06 15:25     ` Ingo Molnar
@ 2007-08-06 19:32     ` Andi Kleen
  2007-08-06 20:36       ` Luiz Fernando N. Capitulino
  1 sibling, 1 reply; 12+ messages in thread
From: Andi Kleen @ 2007-08-06 19:32 UTC (permalink / raw)
  To: Luiz Fernando N. Capitulino; +Cc: Ingo Molnar, Andrew Morton, linux-kernel

"Luiz Fernando N. Capitulino" <lcapitulino@mandriva.com.br> writes:
> 
>  I'll manage to test it then. Do you have a test-case or has any
> suggestion?

LTP has some simple test cases for modify_ldt

-Andi

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] i386: convert mm_context_t semaphore to a mutex
  2007-08-06 19:32     ` Andi Kleen
@ 2007-08-06 20:36       ` Luiz Fernando N. Capitulino
  0 siblings, 0 replies; 12+ messages in thread
From: Luiz Fernando N. Capitulino @ 2007-08-06 20:36 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Ingo Molnar, Andrew Morton, linux-kernel

Em 06 Aug 2007 21:32:29 +0200
Andi Kleen <andi@firstfloor.org> escreveu:

| "Luiz Fernando N. Capitulino" <lcapitulino@mandriva.com.br> writes:
| > 
| >  I'll manage to test it then. Do you have a test-case or has any
| > suggestion?
| 
| LTP has some simple test cases for modify_ldt

 I've just ran them from a LTP suite from 2007/04/30:

"""
/usr/lib/ltp/testcases/kernel/syscalls/modify_ldt/ ./modify_ldt01 
modify_ldt01    0  INFO  :  Enter block 1
modify_ldt01    0  INFO  :  block 1 PASSED
modify_ldt01    0  INFO  :  Exit block 1
modify_ldt01    0  INFO  :  Enter block 2
modify_ldt01    0  INFO  :  block 2 PASSED
modify_ldt01    0  INFO  :  Exit block 2
modify_ldt01    0  INFO  :  block 3 PASSED
modify_ldt01    0  INFO  :  Exit block 3
"""

"""
/usr/lib/ltp/testcases/kernel/syscalls/modify_ldt/ ./modify_ldt02
modify_ldt02    0  INFO  :  Enter block 1
modify_ldt02    0  INFO  :  block 1 PASSED
modify_ldt02    0  INFO  :  Exit block 1
modify_ldt02    0  INFO  :  Enter block 2
modify_ldt02    0  INFO  :  received signal: 11
modify_ldt02    0  INFO  :  block 2 PASSED
/usr/lib/ltp/testcases/kernel/syscalls/modify_ldt/ 
"""

 All passed it seems.

 Btw, I've send the same patch for x86_64 to you too.

-- 
Luiz Fernando N. Capitulino

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] i386: convert mm_context_t semaphore to a mutex
  2007-08-06 13:36   ` Luiz Fernando N. Capitulino
@ 2007-08-06 21:10     ` Luiz Fernando N. Capitulino
  0 siblings, 0 replies; 12+ messages in thread
From: Luiz Fernando N. Capitulino @ 2007-08-06 21:10 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, linux-kernel

Em Mon, 6 Aug 2007 10:36:55 -0300
"Luiz Fernando N. Capitulino" <lcapitulino@mandriva.com.br> escreveu:

| Em Mon, 6 Aug 2007 09:46:08 +0200
| Ingo Molnar <mingo@elte.hu> escreveu:
| 
| | 
| | >  typedef struct { 
| | >  	int size;
| | > -	struct semaphore sem;
| | > +	struct mutex lock;
| | 
| | hm, looks good to me but i'm wondering why this was a holdout for such a 
| | long time :-) Did you manage to test actual LDT functionality with this 
| | patch applied?
| 
|  No, I didn't. The only test I did was to run the kernel with this
| patch applied.
| 
|  I'll manage to test it then. Do you have a test-case or has any
| suggestion?

 And again, SMTP problems makes me looks like a joker...

 Sorry for the spam, just realized the problem now.

-- 
Luiz Fernando N. Capitulino

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2007-08-06 21:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-03 13:55 [PATCH] i386: convert mm_context_t semaphore to a mutex Luiz Fernando N. Capitulino
2007-08-06  7:46 ` Ingo Molnar
2007-08-06 13:34   ` Luiz Fernando N. Capitulino
2007-08-06 13:36   ` Luiz Fernando N. Capitulino
2007-08-06 15:25     ` Ingo Molnar
2007-08-06 17:15       ` Luiz Fernando N. Capitulino
2007-08-06 17:43         ` Ingo Molnar
2007-08-06 19:32     ` Andi Kleen
2007-08-06 20:36       ` Luiz Fernando N. Capitulino
2007-08-06 13:36   ` Luiz Fernando N. Capitulino
2007-08-06 21:10     ` Luiz Fernando N. Capitulino
2007-08-06 13:39   ` Luiz Fernando N. Capitulino

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.