aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2008-01-30 07:30:13 -0500
committerIngo Molnar <mingo@elte.hu>2008-01-30 07:30:13 -0500
commit78aa1f66f77da078357bd263fcac95fbf6bca15b (patch)
treeca42e3ed0d6ed3359c3c3c88f539caaa7740f51f /arch/x86
parent2f36fa13ce49ffd000249feaedfcbefbcc83a72f (diff)
x86: clean up arch/x86/kernel/ldt_32/64.c
White space and coding style clenaup. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/kernel/ldt_32.c60
-rw-r--r--arch/x86/kernel/ldt_64.c69
2 files changed, 69 insertions, 60 deletions
diff --git a/arch/x86/kernel/ldt_32.c b/arch/x86/kernel/ldt_32.c
index 9ff90a27c45..e366c5fd0d1 100644
--- a/arch/x86/kernel/ldt_32.c
+++ b/arch/x86/kernel/ldt_32.c
@@ -17,7 +17,7 @@
17#include <asm/desc.h> 17#include <asm/desc.h>
18#include <asm/mmu_context.h> 18#include <asm/mmu_context.h>
19 19
20#ifdef CONFIG_SMP /* avoids "defined but not used" warnig */ 20#ifdef CONFIG_SMP
21static void flush_ldt(void *null) 21static void flush_ldt(void *null)
22{ 22{
23 if (current->active_mm) 23 if (current->active_mm)
@@ -34,19 +34,20 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
34 if (mincount <= pc->size) 34 if (mincount <= pc->size)
35 return 0; 35 return 0;
36 oldsize = pc->size; 36 oldsize = pc->size;
37 mincount = (mincount+511)&(~511); 37 mincount = (mincount + 511) & (~511);
38 if (mincount*LDT_ENTRY_SIZE > PAGE_SIZE) 38 if (mincount * LDT_ENTRY_SIZE > PAGE_SIZE)
39 newldt = vmalloc(mincount*LDT_ENTRY_SIZE); 39 newldt = vmalloc(mincount * LDT_ENTRY_SIZE);
40 else 40 else
41 newldt = kmalloc(mincount*LDT_ENTRY_SIZE, GFP_KERNEL); 41 newldt = kmalloc(mincount * LDT_ENTRY_SIZE, GFP_KERNEL);
42 42
43 if (!newldt) 43 if (!newldt)
44 return -ENOMEM; 44 return -ENOMEM;
45 45
46 if (oldsize) 46 if (oldsize)
47 memcpy(newldt, pc->ldt, oldsize*LDT_ENTRY_SIZE); 47 memcpy(newldt, pc->ldt, oldsize * LDT_ENTRY_SIZE);
48 oldldt = pc->ldt; 48 oldldt = pc->ldt;
49 memset(newldt+oldsize*LDT_ENTRY_SIZE, 0, (mincount-oldsize)*LDT_ENTRY_SIZE); 49 memset(newldt + oldsize * LDT_ENTRY_SIZE, 0,
50 (mincount - oldsize) * LDT_ENTRY_SIZE);
50 pc->ldt = newldt; 51 pc->ldt = newldt;
51 wmb(); 52 wmb();
52 pc->size = mincount; 53 pc->size = mincount;
@@ -55,6 +56,7 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
55 if (reload) { 56 if (reload) {
56#ifdef CONFIG_SMP 57#ifdef CONFIG_SMP
57 cpumask_t mask; 58 cpumask_t mask;
59
58 preempt_disable(); 60 preempt_disable();
59 load_LDT(pc); 61 load_LDT(pc);
60 mask = cpumask_of_cpu(smp_processor_id()); 62 mask = cpumask_of_cpu(smp_processor_id());
@@ -66,7 +68,7 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
66#endif 68#endif
67 } 69 }
68 if (oldsize) { 70 if (oldsize) {
69 if (oldsize*LDT_ENTRY_SIZE > PAGE_SIZE) 71 if (oldsize * LDT_ENTRY_SIZE > PAGE_SIZE)
70 vfree(oldldt); 72 vfree(oldldt);
71 else 73 else
72 kfree(oldldt); 74 kfree(oldldt);
@@ -77,9 +79,10 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
77static inline int copy_ldt(mm_context_t *new, mm_context_t *old) 79static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
78{ 80{
79 int err = alloc_ldt(new, old->size, 0); 81 int err = alloc_ldt(new, old->size, 0);
82
80 if (err < 0) 83 if (err < 0)
81 return err; 84 return err;
82 memcpy(new->ldt, old->ldt, old->size*LDT_ENTRY_SIZE); 85 memcpy(new->ldt, old->ldt, old->size * LDT_ENTRY_SIZE);
83 return 0; 86 return 0;
84} 87}
85 88
@@ -89,7 +92,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
89 */ 92 */
90int init_new_context(struct task_struct *tsk, struct mm_struct *mm) 93int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
91{ 94{
92 struct mm_struct * old_mm; 95 struct mm_struct *old_mm;
93 int retval = 0; 96 int retval = 0;
94 97
95 mutex_init(&mm->context.lock); 98 mutex_init(&mm->context.lock);
@@ -111,7 +114,7 @@ void destroy_context(struct mm_struct *mm)
111 if (mm->context.size) { 114 if (mm->context.size) {
112 if (mm == current->active_mm) 115 if (mm == current->active_mm)
113 clear_LDT(); 116 clear_LDT();
114 if (mm->context.size*LDT_ENTRY_SIZE > PAGE_SIZE) 117 if (mm->context.size * LDT_ENTRY_SIZE > PAGE_SIZE)
115 vfree(mm->context.ldt); 118 vfree(mm->context.ldt);
116 else 119 else
117 kfree(mm->context.ldt); 120 kfree(mm->context.ldt);
@@ -119,19 +122,19 @@ void destroy_context(struct mm_struct *mm)
119 } 122 }
120} 123}
121 124
122static int read_ldt(void __user * ptr, unsigned long bytecount) 125static int read_ldt(void __user *ptr, unsigned long bytecount)
123{ 126{
124 int err; 127 int err;
125 unsigned long size; 128 unsigned long size;
126 struct mm_struct * mm = current->mm; 129 struct mm_struct *mm = current->mm;
127 130
128 if (!mm->context.size) 131 if (!mm->context.size)
129 return 0; 132 return 0;
130 if (bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES) 133 if (bytecount > LDT_ENTRY_SIZE * LDT_ENTRIES)
131 bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES; 134 bytecount = LDT_ENTRY_SIZE * LDT_ENTRIES;
132 135
133 mutex_lock(&mm->context.lock); 136 mutex_lock(&mm->context.lock);
134 size = mm->context.size*LDT_ENTRY_SIZE; 137 size = mm->context.size * LDT_ENTRY_SIZE;
135 if (size > bytecount) 138 if (size > bytecount)
136 size = bytecount; 139 size = bytecount;
137 140
@@ -143,7 +146,7 @@ static int read_ldt(void __user * ptr, unsigned long bytecount)
143 goto error_return; 146 goto error_return;
144 if (size != bytecount) { 147 if (size != bytecount) {
145 /* zero-fill the rest */ 148 /* zero-fill the rest */
146 if (clear_user(ptr+size, bytecount-size) != 0) { 149 if (clear_user(ptr + size, bytecount - size) != 0) {
147 err = -EFAULT; 150 err = -EFAULT;
148 goto error_return; 151 goto error_return;
149 } 152 }
@@ -153,13 +156,13 @@ error_return:
153 return err; 156 return err;
154} 157}
155 158
156static int read_default_ldt(void __user * ptr, unsigned long bytecount) 159static int read_default_ldt(void __user *ptr, unsigned long bytecount)
157{ 160{
158 int err; 161 int err;
159 unsigned long size; 162 unsigned long size;
160 163
161 err = 0; 164 err = 0;
162 size = 5*sizeof(struct desc_struct); 165 size = 5 * sizeof(struct desc_struct);
163 if (size > bytecount) 166 if (size > bytecount)
164 size = bytecount; 167 size = bytecount;
165 168
@@ -170,9 +173,9 @@ static int read_default_ldt(void __user * ptr, unsigned long bytecount)
170 return err; 173 return err;
171} 174}
172 175
173static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode) 176static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
174{ 177{
175 struct mm_struct * mm = current->mm; 178 struct mm_struct *mm = current->mm;
176 __u32 entry_1, entry_2; 179 __u32 entry_1, entry_2;
177 int error; 180 int error;
178 struct user_desc ldt_info; 181 struct user_desc ldt_info;
@@ -180,7 +183,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
180 error = -EINVAL; 183 error = -EINVAL;
181 if (bytecount != sizeof(ldt_info)) 184 if (bytecount != sizeof(ldt_info))
182 goto out; 185 goto out;
183 error = -EFAULT; 186 error = -EFAULT;
184 if (copy_from_user(&ldt_info, ptr, sizeof(ldt_info))) 187 if (copy_from_user(&ldt_info, ptr, sizeof(ldt_info)))
185 goto out; 188 goto out;
186 189
@@ -196,13 +199,14 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
196 199
197 mutex_lock(&mm->context.lock); 200 mutex_lock(&mm->context.lock);
198 if (ldt_info.entry_number >= mm->context.size) { 201 if (ldt_info.entry_number >= mm->context.size) {
199 error = alloc_ldt(&current->mm->context, ldt_info.entry_number+1, 1); 202 error = alloc_ldt(&current->mm->context,
203 ldt_info.entry_number + 1, 1);
200 if (error < 0) 204 if (error < 0)
201 goto out_unlock; 205 goto out_unlock;
202 } 206 }
203 207
204 /* Allow LDTs to be cleared by the user. */ 208 /* Allow LDTs to be cleared by the user. */
205 if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { 209 if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
206 if (oldmode || LDT_empty(&ldt_info)) { 210 if (oldmode || LDT_empty(&ldt_info)) {
207 entry_1 = 0; 211 entry_1 = 0;
208 entry_2 = 0; 212 entry_2 = 0;
@@ -217,7 +221,8 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
217 221
218 /* Install the new entry ... */ 222 /* Install the new entry ... */
219install: 223install:
220 write_ldt_entry(mm->context.ldt, ldt_info.entry_number, entry_1, entry_2); 224 write_ldt_entry(mm->context.ldt, ldt_info.entry_number, entry_1,
225 entry_2);
221 error = 0; 226 error = 0;
222 227
223out_unlock: 228out_unlock:
@@ -226,7 +231,8 @@ out:
226 return error; 231 return error;
227} 232}
228 233
229asmlinkage int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount) 234asmlinkage int sys_modify_ldt(int func, void __user *ptr,
235 unsigned long bytecount)
230{ 236{
231 int ret = -ENOSYS; 237 int ret = -ENOSYS;
232 238
diff --git a/arch/x86/kernel/ldt_64.c b/arch/x86/kernel/ldt_64.c
index 60e57abb8e9..6c41db367de 100644
--- a/arch/x86/kernel/ldt_64.c
+++ b/arch/x86/kernel/ldt_64.c
@@ -2,7 +2,7 @@
2 * Copyright (C) 1992 Krishna Balasubramanian and Linus Torvalds 2 * Copyright (C) 1992 Krishna Balasubramanian and Linus Torvalds
3 * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com> 3 * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
4 * Copyright (C) 2002 Andi Kleen 4 * Copyright (C) 2002 Andi Kleen
5 * 5 *
6 * This handles calls from both 32bit and 64bit mode. 6 * This handles calls from both 32bit and 64bit mode.
7 */ 7 */
8 8
@@ -20,11 +20,11 @@
20#include <asm/desc.h> 20#include <asm/desc.h>
21#include <asm/proto.h> 21#include <asm/proto.h>
22 22
23#ifdef CONFIG_SMP /* avoids "defined but not used" warnig */ 23#ifdef CONFIG_SMP
24static void flush_ldt(void *null) 24static void flush_ldt(void *null)
25{ 25{
26 if (current->active_mm) 26 if (current->active_mm)
27 load_LDT(&current->active_mm->context); 27 load_LDT(&current->active_mm->context);
28} 28}
29#endif 29#endif
30 30
@@ -37,19 +37,20 @@ static int alloc_ldt(mm_context_t *pc, unsigned mincount, int reload)
37 if (mincount <= (unsigned)pc->size) 37 if (mincount <= (unsigned)pc->size)
38 return 0; 38 return 0;
39 oldsize = pc->size; 39 oldsize = pc->size;
40 mincount = (mincount+511)&(~511); 40 mincount = (mincount + 511) & (~511);
41 if (mincount*LDT_ENTRY_SIZE > PAGE_SIZE) 41 if (mincount * LDT_ENTRY_SIZE > PAGE_SIZE)
42 newldt = vmalloc(mincount*LDT_ENTRY_SIZE); 42 newldt = vmalloc(mincount * LDT_ENTRY_SIZE);
43 else 43 else
44 newldt = kmalloc(mincount*LDT_ENTRY_SIZE, GFP_KERNEL); 44 newldt = kmalloc(mincount * LDT_ENTRY_SIZE, GFP_KERNEL);
45 45
46 if (!newldt) 46 if (!newldt)
47 return -ENOMEM; 47 return -ENOMEM;
48 48
49 if (oldsize) 49 if (oldsize)
50 memcpy(newldt, pc->ldt, oldsize*LDT_ENTRY_SIZE); 50 memcpy(newldt, pc->ldt, oldsize * LDT_ENTRY_SIZE);
51 oldldt = pc->ldt; 51 oldldt = pc->ldt;
52 memset(newldt+oldsize*LDT_ENTRY_SIZE, 0, (mincount-oldsize)*LDT_ENTRY_SIZE); 52 memset(newldt + oldsize * LDT_ENTRY_SIZE, 0,
53 (mincount - oldsize) * LDT_ENTRY_SIZE);
53 wmb(); 54 wmb();
54 pc->ldt = newldt; 55 pc->ldt = newldt;
55 wmb(); 56 wmb();
@@ -70,7 +71,7 @@ static int alloc_ldt(mm_context_t *pc, unsigned mincount, int reload)
70#endif 71#endif
71 } 72 }
72 if (oldsize) { 73 if (oldsize) {
73 if (oldsize*LDT_ENTRY_SIZE > PAGE_SIZE) 74 if (oldsize * LDT_ENTRY_SIZE > PAGE_SIZE)
74 vfree(oldldt); 75 vfree(oldldt);
75 else 76 else
76 kfree(oldldt); 77 kfree(oldldt);
@@ -81,9 +82,10 @@ static int alloc_ldt(mm_context_t *pc, unsigned mincount, int reload)
81static inline int copy_ldt(mm_context_t *new, mm_context_t *old) 82static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
82{ 83{
83 int err = alloc_ldt(new, old->size, 0); 84 int err = alloc_ldt(new, old->size, 0);
85
84 if (err < 0) 86 if (err < 0)
85 return err; 87 return err;
86 memcpy(new->ldt, old->ldt, old->size*LDT_ENTRY_SIZE); 88 memcpy(new->ldt, old->ldt, old->size * LDT_ENTRY_SIZE);
87 return 0; 89 return 0;
88} 90}
89 91
@@ -93,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
93 */ 95 */
94int init_new_context(struct task_struct *tsk, struct mm_struct *mm) 96int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
95{ 97{
96 struct mm_struct * old_mm; 98 struct mm_struct *old_mm;
97 int retval = 0; 99 int retval = 0;
98 100
99 mutex_init(&mm->context.lock); 101 mutex_init(&mm->context.lock);
@@ -108,13 +110,12 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
108} 110}
109 111
110/* 112/*
111 *
112 * Don't touch the LDT register - we're already in the next thread. 113 * Don't touch the LDT register - we're already in the next thread.
113 */ 114 */
114void destroy_context(struct mm_struct *mm) 115void destroy_context(struct mm_struct *mm)
115{ 116{
116 if (mm->context.size) { 117 if (mm->context.size) {
117 if ((unsigned)mm->context.size*LDT_ENTRY_SIZE > PAGE_SIZE) 118 if ((unsigned)mm->context.size * LDT_ENTRY_SIZE > PAGE_SIZE)
118 vfree(mm->context.ldt); 119 vfree(mm->context.ldt);
119 else 120 else
120 kfree(mm->context.ldt); 121 kfree(mm->context.ldt);
@@ -122,19 +123,19 @@ void destroy_context(struct mm_struct *mm)
122 } 123 }
123} 124}
124 125
125static int read_ldt(void __user * ptr, unsigned long bytecount) 126static int read_ldt(void __user *ptr, unsigned long bytecount)
126{ 127{
127 int err; 128 int err;
128 unsigned long size; 129 unsigned long size;
129 struct mm_struct * mm = current->mm; 130 struct mm_struct *mm = current->mm;
130 131
131 if (!mm->context.size) 132 if (!mm->context.size)
132 return 0; 133 return 0;
133 if (bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES) 134 if (bytecount > LDT_ENTRY_SIZE * LDT_ENTRIES)
134 bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES; 135 bytecount = LDT_ENTRY_SIZE * LDT_ENTRIES;
135 136
136 mutex_lock(&mm->context.lock); 137 mutex_lock(&mm->context.lock);
137 size = mm->context.size*LDT_ENTRY_SIZE; 138 size = mm->context.size * LDT_ENTRY_SIZE;
138 if (size > bytecount) 139 if (size > bytecount)
139 size = bytecount; 140 size = bytecount;
140 141
@@ -146,7 +147,7 @@ static int read_ldt(void __user * ptr, unsigned long bytecount)
146 goto error_return; 147 goto error_return;
147 if (size != bytecount) { 148 if (size != bytecount) {
148 /* zero-fill the rest */ 149 /* zero-fill the rest */
149 if (clear_user(ptr+size, bytecount-size) != 0) { 150 if (clear_user(ptr + size, bytecount - size) != 0) {
150 err = -EFAULT; 151 err = -EFAULT;
151 goto error_return; 152 goto error_return;
152 } 153 }
@@ -156,21 +157,21 @@ error_return:
156 return err; 157 return err;
157} 158}
158 159
159static int read_default_ldt(void __user * ptr, unsigned long bytecount) 160static int read_default_ldt(void __user *ptr, unsigned long bytecount)
160{ 161{
161 /* Arbitrary number */ 162 /* Arbitrary number */
162 /* x86-64 default LDT is all zeros */ 163 /* x86-64 default LDT is all zeros */
163 if (bytecount > 128) 164 if (bytecount > 128)
164 bytecount = 128; 165 bytecount = 128;
165 if (clear_user(ptr, bytecount)) 166 if (clear_user(ptr, bytecount))
166 return -EFAULT; 167 return -EFAULT;
167 return bytecount; 168 return bytecount;
168} 169}
169 170
170static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode) 171static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
171{ 172{
172 struct task_struct *me = current; 173 struct task_struct *me = current;
173 struct mm_struct * mm = me->mm; 174 struct mm_struct *mm = me->mm;
174 __u32 entry_1, entry_2, *lp; 175 __u32 entry_1, entry_2, *lp;
175 int error; 176 int error;
176 struct user_desc ldt_info; 177 struct user_desc ldt_info;
@@ -179,7 +180,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
179 180
180 if (bytecount != sizeof(ldt_info)) 181 if (bytecount != sizeof(ldt_info))
181 goto out; 182 goto out;
182 error = -EFAULT; 183 error = -EFAULT;
183 if (copy_from_user(&ldt_info, ptr, bytecount)) 184 if (copy_from_user(&ldt_info, ptr, bytecount))
184 goto out; 185 goto out;
185 186
@@ -195,15 +196,16 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
195 196
196 mutex_lock(&mm->context.lock); 197 mutex_lock(&mm->context.lock);
197 if (ldt_info.entry_number >= (unsigned)mm->context.size) { 198 if (ldt_info.entry_number >= (unsigned)mm->context.size) {
198 error = alloc_ldt(&current->mm->context, ldt_info.entry_number+1, 1); 199 error = alloc_ldt(&current->mm->context,
200 ldt_info.entry_number + 1, 1);
199 if (error < 0) 201 if (error < 0)
200 goto out_unlock; 202 goto out_unlock;
201 } 203 }
202 204
203 lp = (__u32 *) ((ldt_info.entry_number << 3) + (char *) mm->context.ldt); 205 lp = (__u32 *)((ldt_info.entry_number << 3) + (char *)mm->context.ldt);
204 206
205 /* Allow LDTs to be cleared by the user. */ 207 /* Allow LDTs to be cleared by the user. */
206 if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { 208 if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
207 if (oldmode || LDT_empty(&ldt_info)) { 209 if (oldmode || LDT_empty(&ldt_info)) {
208 entry_1 = 0; 210 entry_1 = 0;
209 entry_2 = 0; 211 entry_2 = 0;
@@ -228,7 +230,8 @@ out:
228 return error; 230 return error;
229} 231}
230 232
231asmlinkage int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount) 233asmlinkage int sys_modify_ldt(int func, void __user *ptr,
234 unsigned long bytecount)
232{ 235{
233 int ret = -ENOSYS; 236 int ret = -ENOSYS;
234 237