diff options
Diffstat (limited to 'arch/x86/kernel/ds.c')
-rw-r--r-- | arch/x86/kernel/ds.c | 81 |
1 files changed, 53 insertions, 28 deletions
diff --git a/arch/x86/kernel/ds.c b/arch/x86/kernel/ds.c index 2b69994fd3a8..a2d1176c38ee 100644 --- a/arch/x86/kernel/ds.c +++ b/arch/x86/kernel/ds.c | |||
@@ -21,8 +21,6 @@ | |||
21 | */ | 21 | */ |
22 | 22 | ||
23 | 23 | ||
24 | #ifdef CONFIG_X86_DS | ||
25 | |||
26 | #include <asm/ds.h> | 24 | #include <asm/ds.h> |
27 | 25 | ||
28 | #include <linux/errno.h> | 26 | #include <linux/errno.h> |
@@ -211,14 +209,15 @@ static DEFINE_PER_CPU(struct ds_context *, system_context); | |||
211 | static inline struct ds_context *ds_get_context(struct task_struct *task) | 209 | static inline struct ds_context *ds_get_context(struct task_struct *task) |
212 | { | 210 | { |
213 | struct ds_context *context; | 211 | struct ds_context *context; |
212 | unsigned long irq; | ||
214 | 213 | ||
215 | spin_lock(&ds_lock); | 214 | spin_lock_irqsave(&ds_lock, irq); |
216 | 215 | ||
217 | context = (task ? task->thread.ds_ctx : this_system_context); | 216 | context = (task ? task->thread.ds_ctx : this_system_context); |
218 | if (context) | 217 | if (context) |
219 | context->count++; | 218 | context->count++; |
220 | 219 | ||
221 | spin_unlock(&ds_lock); | 220 | spin_unlock_irqrestore(&ds_lock, irq); |
222 | 221 | ||
223 | return context; | 222 | return context; |
224 | } | 223 | } |
@@ -226,18 +225,16 @@ static inline struct ds_context *ds_get_context(struct task_struct *task) | |||
226 | /* | 225 | /* |
227 | * Same as ds_get_context, but allocates the context and it's DS | 226 | * Same as ds_get_context, but allocates the context and it's DS |
228 | * structure, if necessary; returns NULL; if out of memory. | 227 | * structure, if necessary; returns NULL; if out of memory. |
229 | * | ||
230 | * pre: requires ds_lock to be held | ||
231 | */ | 228 | */ |
232 | static inline struct ds_context *ds_alloc_context(struct task_struct *task) | 229 | static inline struct ds_context *ds_alloc_context(struct task_struct *task) |
233 | { | 230 | { |
234 | struct ds_context **p_context = | 231 | struct ds_context **p_context = |
235 | (task ? &task->thread.ds_ctx : &this_system_context); | 232 | (task ? &task->thread.ds_ctx : &this_system_context); |
236 | struct ds_context *context = *p_context; | 233 | struct ds_context *context = *p_context; |
234 | unsigned long irq; | ||
237 | 235 | ||
238 | if (!context) { | 236 | if (!context) { |
239 | context = kzalloc(sizeof(*context), GFP_KERNEL); | 237 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
240 | |||
241 | if (!context) | 238 | if (!context) |
242 | return NULL; | 239 | return NULL; |
243 | 240 | ||
@@ -247,18 +244,27 @@ static inline struct ds_context *ds_alloc_context(struct task_struct *task) | |||
247 | return NULL; | 244 | return NULL; |
248 | } | 245 | } |
249 | 246 | ||
250 | *p_context = context; | 247 | spin_lock_irqsave(&ds_lock, irq); |
251 | 248 | ||
252 | context->this = p_context; | 249 | if (*p_context) { |
253 | context->task = task; | 250 | kfree(context->ds); |
251 | kfree(context); | ||
252 | |||
253 | context = *p_context; | ||
254 | } else { | ||
255 | *p_context = context; | ||
254 | 256 | ||
255 | if (task) | 257 | context->this = p_context; |
256 | set_tsk_thread_flag(task, TIF_DS_AREA_MSR); | 258 | context->task = task; |
257 | 259 | ||
258 | if (!task || (task == current)) | 260 | if (task) |
259 | wrmsr(MSR_IA32_DS_AREA, (unsigned long)context->ds, 0); | 261 | set_tsk_thread_flag(task, TIF_DS_AREA_MSR); |
260 | 262 | ||
261 | get_tracer(task); | 263 | if (!task || (task == current)) |
264 | wrmsrl(MSR_IA32_DS_AREA, | ||
265 | (unsigned long)context->ds); | ||
266 | } | ||
267 | spin_unlock_irqrestore(&ds_lock, irq); | ||
262 | } | 268 | } |
263 | 269 | ||
264 | context->count++; | 270 | context->count++; |
@@ -272,10 +278,12 @@ static inline struct ds_context *ds_alloc_context(struct task_struct *task) | |||
272 | */ | 278 | */ |
273 | static inline void ds_put_context(struct ds_context *context) | 279 | static inline void ds_put_context(struct ds_context *context) |
274 | { | 280 | { |
281 | unsigned long irq; | ||
282 | |||
275 | if (!context) | 283 | if (!context) |
276 | return; | 284 | return; |
277 | 285 | ||
278 | spin_lock(&ds_lock); | 286 | spin_lock_irqsave(&ds_lock, irq); |
279 | 287 | ||
280 | if (--context->count) | 288 | if (--context->count) |
281 | goto out; | 289 | goto out; |
@@ -297,7 +305,7 @@ static inline void ds_put_context(struct ds_context *context) | |||
297 | kfree(context->ds); | 305 | kfree(context->ds); |
298 | kfree(context); | 306 | kfree(context); |
299 | out: | 307 | out: |
300 | spin_unlock(&ds_lock); | 308 | spin_unlock_irqrestore(&ds_lock, irq); |
301 | } | 309 | } |
302 | 310 | ||
303 | 311 | ||
@@ -368,6 +376,7 @@ static int ds_request(struct task_struct *task, void *base, size_t size, | |||
368 | struct ds_context *context; | 376 | struct ds_context *context; |
369 | unsigned long buffer, adj; | 377 | unsigned long buffer, adj; |
370 | const unsigned long alignment = (1 << 3); | 378 | const unsigned long alignment = (1 << 3); |
379 | unsigned long irq; | ||
371 | int error = 0; | 380 | int error = 0; |
372 | 381 | ||
373 | if (!ds_cfg.sizeof_ds) | 382 | if (!ds_cfg.sizeof_ds) |
@@ -382,25 +391,27 @@ static int ds_request(struct task_struct *task, void *base, size_t size, | |||
382 | return -EOPNOTSUPP; | 391 | return -EOPNOTSUPP; |
383 | 392 | ||
384 | 393 | ||
385 | spin_lock(&ds_lock); | ||
386 | |||
387 | if (!check_tracer(task)) | ||
388 | return -EPERM; | ||
389 | |||
390 | error = -ENOMEM; | ||
391 | context = ds_alloc_context(task); | 394 | context = ds_alloc_context(task); |
392 | if (!context) | 395 | if (!context) |
396 | return -ENOMEM; | ||
397 | |||
398 | spin_lock_irqsave(&ds_lock, irq); | ||
399 | |||
400 | error = -EPERM; | ||
401 | if (!check_tracer(task)) | ||
393 | goto out_unlock; | 402 | goto out_unlock; |
394 | 403 | ||
404 | get_tracer(task); | ||
405 | |||
395 | error = -EALREADY; | 406 | error = -EALREADY; |
396 | if (context->owner[qual] == current) | 407 | if (context->owner[qual] == current) |
397 | goto out_unlock; | 408 | goto out_put_tracer; |
398 | error = -EPERM; | 409 | error = -EPERM; |
399 | if (context->owner[qual] != NULL) | 410 | if (context->owner[qual] != NULL) |
400 | goto out_unlock; | 411 | goto out_put_tracer; |
401 | context->owner[qual] = current; | 412 | context->owner[qual] = current; |
402 | 413 | ||
403 | spin_unlock(&ds_lock); | 414 | spin_unlock_irqrestore(&ds_lock, irq); |
404 | 415 | ||
405 | 416 | ||
406 | error = -ENOMEM; | 417 | error = -ENOMEM; |
@@ -448,10 +459,17 @@ static int ds_request(struct task_struct *task, void *base, size_t size, | |||
448 | out_release: | 459 | out_release: |
449 | context->owner[qual] = NULL; | 460 | context->owner[qual] = NULL; |
450 | ds_put_context(context); | 461 | ds_put_context(context); |
462 | put_tracer(task); | ||
463 | return error; | ||
464 | |||
465 | out_put_tracer: | ||
466 | spin_unlock_irqrestore(&ds_lock, irq); | ||
467 | ds_put_context(context); | ||
468 | put_tracer(task); | ||
451 | return error; | 469 | return error; |
452 | 470 | ||
453 | out_unlock: | 471 | out_unlock: |
454 | spin_unlock(&ds_lock); | 472 | spin_unlock_irqrestore(&ds_lock, irq); |
455 | ds_put_context(context); | 473 | ds_put_context(context); |
456 | return error; | 474 | return error; |
457 | } | 475 | } |
@@ -801,13 +819,21 @@ static const struct ds_configuration ds_cfg_var = { | |||
801 | .sizeof_ds = sizeof(long) * 12, | 819 | .sizeof_ds = sizeof(long) * 12, |
802 | .sizeof_field = sizeof(long), | 820 | .sizeof_field = sizeof(long), |
803 | .sizeof_rec[ds_bts] = sizeof(long) * 3, | 821 | .sizeof_rec[ds_bts] = sizeof(long) * 3, |
822 | #ifdef __i386__ | ||
804 | .sizeof_rec[ds_pebs] = sizeof(long) * 10 | 823 | .sizeof_rec[ds_pebs] = sizeof(long) * 10 |
824 | #else | ||
825 | .sizeof_rec[ds_pebs] = sizeof(long) * 18 | ||
826 | #endif | ||
805 | }; | 827 | }; |
806 | static const struct ds_configuration ds_cfg_64 = { | 828 | static const struct ds_configuration ds_cfg_64 = { |
807 | .sizeof_ds = 8 * 12, | 829 | .sizeof_ds = 8 * 12, |
808 | .sizeof_field = 8, | 830 | .sizeof_field = 8, |
809 | .sizeof_rec[ds_bts] = 8 * 3, | 831 | .sizeof_rec[ds_bts] = 8 * 3, |
832 | #ifdef __i386__ | ||
810 | .sizeof_rec[ds_pebs] = 8 * 10 | 833 | .sizeof_rec[ds_pebs] = 8 * 10 |
834 | #else | ||
835 | .sizeof_rec[ds_pebs] = 8 * 18 | ||
836 | #endif | ||
811 | }; | 837 | }; |
812 | 838 | ||
813 | static inline void | 839 | static inline void |
@@ -861,4 +887,3 @@ void ds_free(struct ds_context *context) | |||
861 | while (leftovers--) | 887 | while (leftovers--) |
862 | ds_put_context(context); | 888 | ds_put_context(context); |
863 | } | 889 | } |
864 | #endif /* CONFIG_X86_DS */ | ||