|
@@ -2,7 +2,7 @@
|
|
* Copyright (C) 1992 Krishna Balasubramanian and Linus Torvalds
|
|
* Copyright (C) 1992 Krishna Balasubramanian and Linus Torvalds
|
|
* Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
|
|
* Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
|
|
* Copyright (C) 2002 Andi Kleen
|
|
* Copyright (C) 2002 Andi Kleen
|
|
- *
|
|
|
|
|
|
+ *
|
|
* This handles calls from both 32bit and 64bit mode.
|
|
* This handles calls from both 32bit and 64bit mode.
|
|
*/
|
|
*/
|
|
|
|
|
|
@@ -20,11 +20,11 @@
|
|
#include <asm/desc.h>
|
|
#include <asm/desc.h>
|
|
#include <asm/proto.h>
|
|
#include <asm/proto.h>
|
|
|
|
|
|
-#ifdef CONFIG_SMP /* avoids "defined but not used" warnig */
|
|
|
|
|
|
+#ifdef CONFIG_SMP
|
|
static void flush_ldt(void *null)
|
|
static void flush_ldt(void *null)
|
|
{
|
|
{
|
|
if (current->active_mm)
|
|
if (current->active_mm)
|
|
- load_LDT(¤t->active_mm->context);
|
|
|
|
|
|
+ load_LDT(¤t->active_mm->context);
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -37,19 +37,20 @@ static int alloc_ldt(mm_context_t *pc, unsigned mincount, int reload)
|
|
if (mincount <= (unsigned)pc->size)
|
|
if (mincount <= (unsigned)pc->size)
|
|
return 0;
|
|
return 0;
|
|
oldsize = pc->size;
|
|
oldsize = pc->size;
|
|
- mincount = (mincount+511)&(~511);
|
|
|
|
- if (mincount*LDT_ENTRY_SIZE > PAGE_SIZE)
|
|
|
|
- newldt = vmalloc(mincount*LDT_ENTRY_SIZE);
|
|
|
|
|
|
+ mincount = (mincount + 511) & (~511);
|
|
|
|
+ if (mincount * LDT_ENTRY_SIZE > PAGE_SIZE)
|
|
|
|
+ newldt = vmalloc(mincount * LDT_ENTRY_SIZE);
|
|
else
|
|
else
|
|
- newldt = kmalloc(mincount*LDT_ENTRY_SIZE, GFP_KERNEL);
|
|
|
|
|
|
+ newldt = kmalloc(mincount * LDT_ENTRY_SIZE, GFP_KERNEL);
|
|
|
|
|
|
if (!newldt)
|
|
if (!newldt)
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
|
|
|
|
if (oldsize)
|
|
if (oldsize)
|
|
- memcpy(newldt, pc->ldt, oldsize*LDT_ENTRY_SIZE);
|
|
|
|
|
|
+ memcpy(newldt, pc->ldt, oldsize * LDT_ENTRY_SIZE);
|
|
oldldt = pc->ldt;
|
|
oldldt = pc->ldt;
|
|
- memset(newldt+oldsize*LDT_ENTRY_SIZE, 0, (mincount-oldsize)*LDT_ENTRY_SIZE);
|
|
|
|
|
|
+ memset(newldt + oldsize * LDT_ENTRY_SIZE, 0,
|
|
|
|
+ (mincount - oldsize) * LDT_ENTRY_SIZE);
|
|
wmb();
|
|
wmb();
|
|
pc->ldt = newldt;
|
|
pc->ldt = newldt;
|
|
wmb();
|
|
wmb();
|
|
@@ -70,7 +71,7 @@ static int alloc_ldt(mm_context_t *pc, unsigned mincount, int reload)
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
if (oldsize) {
|
|
if (oldsize) {
|
|
- if (oldsize*LDT_ENTRY_SIZE > PAGE_SIZE)
|
|
|
|
|
|
+ if (oldsize * LDT_ENTRY_SIZE > PAGE_SIZE)
|
|
vfree(oldldt);
|
|
vfree(oldldt);
|
|
else
|
|
else
|
|
kfree(oldldt);
|
|
kfree(oldldt);
|
|
@@ -81,9 +82,10 @@ static int alloc_ldt(mm_context_t *pc, unsigned mincount, int reload)
|
|
static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
|
|
static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
|
|
{
|
|
{
|
|
int err = alloc_ldt(new, old->size, 0);
|
|
int err = alloc_ldt(new, old->size, 0);
|
|
|
|
+
|
|
if (err < 0)
|
|
if (err < 0)
|
|
return err;
|
|
return err;
|
|
- memcpy(new->ldt, old->ldt, old->size*LDT_ENTRY_SIZE);
|
|
|
|
|
|
+ memcpy(new->ldt, old->ldt, old->size * LDT_ENTRY_SIZE);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -93,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
|
|
*/
|
|
*/
|
|
int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
|
|
int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
|
|
{
|
|
{
|
|
- struct mm_struct * old_mm;
|
|
|
|
|
|
+ struct mm_struct *old_mm;
|
|
int retval = 0;
|
|
int retval = 0;
|
|
|
|
|
|
mutex_init(&mm->context.lock);
|
|
mutex_init(&mm->context.lock);
|
|
@@ -108,13 +110,12 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
- *
|
|
|
|
* Don't touch the LDT register - we're already in the next thread.
|
|
* Don't touch the LDT register - we're already in the next thread.
|
|
*/
|
|
*/
|
|
void destroy_context(struct mm_struct *mm)
|
|
void destroy_context(struct mm_struct *mm)
|
|
{
|
|
{
|
|
if (mm->context.size) {
|
|
if (mm->context.size) {
|
|
- if ((unsigned)mm->context.size*LDT_ENTRY_SIZE > PAGE_SIZE)
|
|
|
|
|
|
+ if ((unsigned)mm->context.size * LDT_ENTRY_SIZE > PAGE_SIZE)
|
|
vfree(mm->context.ldt);
|
|
vfree(mm->context.ldt);
|
|
else
|
|
else
|
|
kfree(mm->context.ldt);
|
|
kfree(mm->context.ldt);
|
|
@@ -122,19 +123,19 @@ void destroy_context(struct mm_struct *mm)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static int read_ldt(void __user * ptr, unsigned long bytecount)
|
|
|
|
|
|
+static int read_ldt(void __user *ptr, unsigned long bytecount)
|
|
{
|
|
{
|
|
int err;
|
|
int err;
|
|
unsigned long size;
|
|
unsigned long size;
|
|
- struct mm_struct * mm = current->mm;
|
|
|
|
|
|
+ struct mm_struct *mm = current->mm;
|
|
|
|
|
|
if (!mm->context.size)
|
|
if (!mm->context.size)
|
|
return 0;
|
|
return 0;
|
|
- if (bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES)
|
|
|
|
- bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES;
|
|
|
|
|
|
+ if (bytecount > LDT_ENTRY_SIZE * LDT_ENTRIES)
|
|
|
|
+ bytecount = LDT_ENTRY_SIZE * LDT_ENTRIES;
|
|
|
|
|
|
mutex_lock(&mm->context.lock);
|
|
mutex_lock(&mm->context.lock);
|
|
- size = mm->context.size*LDT_ENTRY_SIZE;
|
|
|
|
|
|
+ size = mm->context.size * LDT_ENTRY_SIZE;
|
|
if (size > bytecount)
|
|
if (size > bytecount)
|
|
size = bytecount;
|
|
size = bytecount;
|
|
|
|
|
|
@@ -146,7 +147,7 @@ static int read_ldt(void __user * ptr, unsigned long bytecount)
|
|
goto error_return;
|
|
goto error_return;
|
|
if (size != bytecount) {
|
|
if (size != bytecount) {
|
|
/* zero-fill the rest */
|
|
/* zero-fill the rest */
|
|
- if (clear_user(ptr+size, bytecount-size) != 0) {
|
|
|
|
|
|
+ if (clear_user(ptr + size, bytecount - size) != 0) {
|
|
err = -EFAULT;
|
|
err = -EFAULT;
|
|
goto error_return;
|
|
goto error_return;
|
|
}
|
|
}
|
|
@@ -156,21 +157,21 @@ error_return:
|
|
return err;
|
|
return err;
|
|
}
|
|
}
|
|
|
|
|
|
-static int read_default_ldt(void __user * ptr, unsigned long bytecount)
|
|
|
|
|
|
+static int read_default_ldt(void __user *ptr, unsigned long bytecount)
|
|
{
|
|
{
|
|
- /* Arbitrary number */
|
|
|
|
|
|
+ /* Arbitrary number */
|
|
/* x86-64 default LDT is all zeros */
|
|
/* x86-64 default LDT is all zeros */
|
|
- if (bytecount > 128)
|
|
|
|
- bytecount = 128;
|
|
|
|
|
|
+ if (bytecount > 128)
|
|
|
|
+ bytecount = 128;
|
|
if (clear_user(ptr, bytecount))
|
|
if (clear_user(ptr, bytecount))
|
|
return -EFAULT;
|
|
return -EFAULT;
|
|
- return bytecount;
|
|
|
|
|
|
+ return bytecount;
|
|
}
|
|
}
|
|
|
|
|
|
-static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
|
|
|
|
|
|
+static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
|
|
{
|
|
{
|
|
struct task_struct *me = current;
|
|
struct task_struct *me = current;
|
|
- struct mm_struct * mm = me->mm;
|
|
|
|
|
|
+ struct mm_struct *mm = me->mm;
|
|
__u32 entry_1, entry_2, *lp;
|
|
__u32 entry_1, entry_2, *lp;
|
|
int error;
|
|
int error;
|
|
struct user_desc ldt_info;
|
|
struct user_desc ldt_info;
|
|
@@ -179,7 +180,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
|
|
|
|
|
|
if (bytecount != sizeof(ldt_info))
|
|
if (bytecount != sizeof(ldt_info))
|
|
goto out;
|
|
goto out;
|
|
- error = -EFAULT;
|
|
|
|
|
|
+ error = -EFAULT;
|
|
if (copy_from_user(&ldt_info, ptr, bytecount))
|
|
if (copy_from_user(&ldt_info, ptr, bytecount))
|
|
goto out;
|
|
goto out;
|
|
|
|
|
|
@@ -195,15 +196,16 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
|
|
|
|
|
|
mutex_lock(&mm->context.lock);
|
|
mutex_lock(&mm->context.lock);
|
|
if (ldt_info.entry_number >= (unsigned)mm->context.size) {
|
|
if (ldt_info.entry_number >= (unsigned)mm->context.size) {
|
|
- error = alloc_ldt(¤t->mm->context, ldt_info.entry_number+1, 1);
|
|
|
|
|
|
+ error = alloc_ldt(¤t->mm->context,
|
|
|
|
+ ldt_info.entry_number + 1, 1);
|
|
if (error < 0)
|
|
if (error < 0)
|
|
goto out_unlock;
|
|
goto out_unlock;
|
|
}
|
|
}
|
|
|
|
|
|
- lp = (__u32 *) ((ldt_info.entry_number << 3) + (char *) mm->context.ldt);
|
|
|
|
|
|
+ lp = (__u32 *)((ldt_info.entry_number << 3) + (char *)mm->context.ldt);
|
|
|
|
|
|
- /* Allow LDTs to be cleared by the user. */
|
|
|
|
- if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
|
|
|
|
|
|
+ /* Allow LDTs to be cleared by the user. */
|
|
|
|
+ if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
|
|
if (oldmode || LDT_empty(&ldt_info)) {
|
|
if (oldmode || LDT_empty(&ldt_info)) {
|
|
entry_1 = 0;
|
|
entry_1 = 0;
|
|
entry_2 = 0;
|
|
entry_2 = 0;
|
|
@@ -228,7 +230,8 @@ out:
|
|
return error;
|
|
return error;
|
|
}
|
|
}
|
|
|
|
|
|
-asmlinkage int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
|
|
|
|
|
|
+asmlinkage int sys_modify_ldt(int func, void __user *ptr,
|
|
|
|
+ unsigned long bytecount)
|
|
{
|
|
{
|
|
int ret = -ENOSYS;
|
|
int ret = -ENOSYS;
|
|
|
|
|