aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Hansen <dave.hansen@linux.intel.com>2015-06-07 14:37:02 -0400
committerIngo Molnar <mingo@kernel.org>2015-06-09 06:24:30 -0400
commit46a6e0cf1c6665a8e867d8f7798d7a3538633f03 (patch)
tree85b142ed094594330ee5e170fc92463d432e9097
parenta84eeaa96b36a03188e1423349669c108d3a4bd7 (diff)
x86/mpx: Clean up the code by not passing a task pointer around when unnecessary
The MPX code can only work on the current task. You can not, for instance, enable MPX management in another process or thread. You can also not handle a fault for another process or thread. Despite this, we pass a task_struct around prolifically. This patch removes all of the task struct passing for code paths where the code can not deal with another task (which turns out to be all of them). This has no functional changes. It's just a cleanup. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Dave Hansen <dave@sr71.net> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: bp@alien8.de Link: http://lkml.kernel.org/r/20150607183702.6A81DA2C@viggo.jf.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/include/asm/mpx.h10
-rw-r--r--arch/x86/include/asm/processor.h12
-rw-r--r--arch/x86/kernel/traps.c5
-rw-r--r--arch/x86/mm/mpx.c19
-rw-r--r--kernel/sys.c8
5 files changed, 25 insertions, 29 deletions
diff --git a/arch/x86/include/asm/mpx.h b/arch/x86/include/asm/mpx.h
index 39f2d0ffe1e2..0cdd16af71ad 100644
--- a/arch/x86/include/asm/mpx.h
+++ b/arch/x86/include/asm/mpx.h
@@ -59,9 +59,8 @@
59 MPX_BT_ENTRY_MASK) << MPX_BT_ENTRY_SHIFT) 59 MPX_BT_ENTRY_MASK) << MPX_BT_ENTRY_SHIFT)
60 60
61#ifdef CONFIG_X86_INTEL_MPX 61#ifdef CONFIG_X86_INTEL_MPX
62siginfo_t *mpx_generate_siginfo(struct pt_regs *regs, 62siginfo_t *mpx_generate_siginfo(struct pt_regs *regs);
63 struct task_struct *tsk); 63int mpx_handle_bd_fault(void);
64int mpx_handle_bd_fault(struct task_struct *tsk);
65static inline int kernel_managing_mpx_tables(struct mm_struct *mm) 64static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
66{ 65{
67 return (mm->bd_addr != MPX_INVALID_BOUNDS_DIR); 66 return (mm->bd_addr != MPX_INVALID_BOUNDS_DIR);
@@ -77,12 +76,11 @@ static inline void mpx_mm_init(struct mm_struct *mm)
77void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma, 76void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
78 unsigned long start, unsigned long end); 77 unsigned long start, unsigned long end);
79#else 78#else
80static inline siginfo_t *mpx_generate_siginfo(struct pt_regs *regs, 79static inline siginfo_t *mpx_generate_siginfo(struct pt_regs *regs)
81 struct task_struct *tsk)
82{ 80{
83 return NULL; 81 return NULL;
84} 82}
85static inline int mpx_handle_bd_fault(struct task_struct *tsk) 83static inline int mpx_handle_bd_fault(void)
86{ 84{
87 return -EINVAL; 85 return -EINVAL;
88} 86}
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 8e04f51d6bea..53dbd2b4f1d8 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -802,18 +802,18 @@ extern int get_tsc_mode(unsigned long adr);
802extern int set_tsc_mode(unsigned int val); 802extern int set_tsc_mode(unsigned int val);
803 803
804/* Register/unregister a process' MPX related resource */ 804/* Register/unregister a process' MPX related resource */
805#define MPX_ENABLE_MANAGEMENT(tsk) mpx_enable_management((tsk)) 805#define MPX_ENABLE_MANAGEMENT() mpx_enable_management()
806#define MPX_DISABLE_MANAGEMENT(tsk) mpx_disable_management((tsk)) 806#define MPX_DISABLE_MANAGEMENT() mpx_disable_management()
807 807
808#ifdef CONFIG_X86_INTEL_MPX 808#ifdef CONFIG_X86_INTEL_MPX
809extern int mpx_enable_management(struct task_struct *tsk); 809extern int mpx_enable_management(void);
810extern int mpx_disable_management(struct task_struct *tsk); 810extern int mpx_disable_management(void);
811#else 811#else
812static inline int mpx_enable_management(struct task_struct *tsk) 812static inline int mpx_enable_management(void)
813{ 813{
814 return -EINVAL; 814 return -EINVAL;
815} 815}
816static inline int mpx_disable_management(struct task_struct *tsk) 816static inline int mpx_disable_management(void)
817{ 817{
818 return -EINVAL; 818 return -EINVAL;
819} 819}
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 42f15314b361..cffff669be3f 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -371,7 +371,6 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
371 371
372dotraplinkage void do_bounds(struct pt_regs *regs, long error_code) 372dotraplinkage void do_bounds(struct pt_regs *regs, long error_code)
373{ 373{
374 struct task_struct *tsk = current;
375 enum ctx_state prev_state; 374 enum ctx_state prev_state;
376 const struct bndcsr *bndcsr; 375 const struct bndcsr *bndcsr;
377 siginfo_t *info; 376 siginfo_t *info;
@@ -407,11 +406,11 @@ dotraplinkage void do_bounds(struct pt_regs *regs, long error_code)
407 */ 406 */
408 switch (bndcsr->bndstatus & MPX_BNDSTA_ERROR_CODE) { 407 switch (bndcsr->bndstatus & MPX_BNDSTA_ERROR_CODE) {
409 case 2: /* Bound directory has invalid entry. */ 408 case 2: /* Bound directory has invalid entry. */
410 if (mpx_handle_bd_fault(tsk)) 409 if (mpx_handle_bd_fault())
411 goto exit_trap; 410 goto exit_trap;
412 break; /* Success, it was handled */ 411 break; /* Success, it was handled */
413 case 1: /* Bound violation. */ 412 case 1: /* Bound violation. */
414 info = mpx_generate_siginfo(regs, tsk); 413 info = mpx_generate_siginfo(regs);
415 if (IS_ERR(info)) { 414 if (IS_ERR(info)) {
416 /* 415 /*
417 * We failed to decode the MPX instruction. Act as if 416 * We failed to decode the MPX instruction. Act as if
diff --git a/arch/x86/mm/mpx.c b/arch/x86/mm/mpx.c
index 9d67e230b4fb..47e4a8564012 100644
--- a/arch/x86/mm/mpx.c
+++ b/arch/x86/mm/mpx.c
@@ -271,8 +271,7 @@ bad_opcode:
271 * 271 *
272 * The caller is expected to kfree() the returned siginfo_t. 272 * The caller is expected to kfree() the returned siginfo_t.
273 */ 273 */
274siginfo_t *mpx_generate_siginfo(struct pt_regs *regs, 274siginfo_t *mpx_generate_siginfo(struct pt_regs *regs)
275 struct task_struct *tsk)
276{ 275{
277 const struct bndreg *bndregs, *bndreg; 276 const struct bndreg *bndregs, *bndreg;
278 siginfo_t *info = NULL; 277 siginfo_t *info = NULL;
@@ -340,7 +339,7 @@ err_out:
340 return ERR_PTR(err); 339 return ERR_PTR(err);
341} 340}
342 341
343static __user void *task_get_bounds_dir(struct task_struct *tsk) 342static __user void *mpx_get_bounds_dir(void)
344{ 343{
345 const struct bndcsr *bndcsr; 344 const struct bndcsr *bndcsr;
346 345
@@ -376,10 +375,10 @@ static __user void *task_get_bounds_dir(struct task_struct *tsk)
376 (bndcsr->bndcfgu & MPX_BNDCFG_ADDR_MASK); 375 (bndcsr->bndcfgu & MPX_BNDCFG_ADDR_MASK);
377} 376}
378 377
379int mpx_enable_management(struct task_struct *tsk) 378int mpx_enable_management(void)
380{ 379{
381 void __user *bd_base = MPX_INVALID_BOUNDS_DIR; 380 void __user *bd_base = MPX_INVALID_BOUNDS_DIR;
382 struct mm_struct *mm = tsk->mm; 381 struct mm_struct *mm = current->mm;
383 int ret = 0; 382 int ret = 0;
384 383
385 /* 384 /*
@@ -393,7 +392,7 @@ int mpx_enable_management(struct task_struct *tsk)
393 * directory here means that we do not have to do xsave in the 392 * directory here means that we do not have to do xsave in the
394 * unmap path; we can just use mm->bd_addr instead. 393 * unmap path; we can just use mm->bd_addr instead.
395 */ 394 */
396 bd_base = task_get_bounds_dir(tsk); 395 bd_base = mpx_get_bounds_dir();
397 down_write(&mm->mmap_sem); 396 down_write(&mm->mmap_sem);
398 mm->bd_addr = bd_base; 397 mm->bd_addr = bd_base;
399 if (mm->bd_addr == MPX_INVALID_BOUNDS_DIR) 398 if (mm->bd_addr == MPX_INVALID_BOUNDS_DIR)
@@ -403,7 +402,7 @@ int mpx_enable_management(struct task_struct *tsk)
403 return ret; 402 return ret;
404} 403}
405 404
406int mpx_disable_management(struct task_struct *tsk) 405int mpx_disable_management(void)
407{ 406{
408 struct mm_struct *mm = current->mm; 407 struct mm_struct *mm = current->mm;
409 408
@@ -497,7 +496,7 @@ out_unmap:
497 * bound table is 16KB. With 64-bit mode, the size of BD is 2GB, 496 * bound table is 16KB. With 64-bit mode, the size of BD is 2GB,
498 * and the size of each bound table is 4MB. 497 * and the size of each bound table is 4MB.
499 */ 498 */
500static int do_mpx_bt_fault(struct task_struct *tsk) 499static int do_mpx_bt_fault(void)
501{ 500{
502 unsigned long bd_entry, bd_base; 501 unsigned long bd_entry, bd_base;
503 const struct bndcsr *bndcsr; 502 const struct bndcsr *bndcsr;
@@ -525,7 +524,7 @@ static int do_mpx_bt_fault(struct task_struct *tsk)
525 return allocate_bt((long __user *)bd_entry); 524 return allocate_bt((long __user *)bd_entry);
526} 525}
527 526
528int mpx_handle_bd_fault(struct task_struct *tsk) 527int mpx_handle_bd_fault(void)
529{ 528{
530 /* 529 /*
531 * Userspace never asked us to manage the bounds tables, 530 * Userspace never asked us to manage the bounds tables,
@@ -534,7 +533,7 @@ int mpx_handle_bd_fault(struct task_struct *tsk)
534 if (!kernel_managing_mpx_tables(current->mm)) 533 if (!kernel_managing_mpx_tables(current->mm))
535 return -EINVAL; 534 return -EINVAL;
536 535
537 if (do_mpx_bt_fault(tsk)) { 536 if (do_mpx_bt_fault()) {
538 force_sig(SIGSEGV, current); 537 force_sig(SIGSEGV, current);
539 /* 538 /*
540 * The force_sig() is essentially "handling" this 539 * The force_sig() is essentially "handling" this
diff --git a/kernel/sys.c b/kernel/sys.c
index a4e372b798a5..8571296b7ddb 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -92,10 +92,10 @@
92# define SET_TSC_CTL(a) (-EINVAL) 92# define SET_TSC_CTL(a) (-EINVAL)
93#endif 93#endif
94#ifndef MPX_ENABLE_MANAGEMENT 94#ifndef MPX_ENABLE_MANAGEMENT
95# define MPX_ENABLE_MANAGEMENT(a) (-EINVAL) 95# define MPX_ENABLE_MANAGEMENT() (-EINVAL)
96#endif 96#endif
97#ifndef MPX_DISABLE_MANAGEMENT 97#ifndef MPX_DISABLE_MANAGEMENT
98# define MPX_DISABLE_MANAGEMENT(a) (-EINVAL) 98# define MPX_DISABLE_MANAGEMENT() (-EINVAL)
99#endif 99#endif
100#ifndef GET_FP_MODE 100#ifndef GET_FP_MODE
101# define GET_FP_MODE(a) (-EINVAL) 101# define GET_FP_MODE(a) (-EINVAL)
@@ -2230,12 +2230,12 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
2230 case PR_MPX_ENABLE_MANAGEMENT: 2230 case PR_MPX_ENABLE_MANAGEMENT:
2231 if (arg2 || arg3 || arg4 || arg5) 2231 if (arg2 || arg3 || arg4 || arg5)
2232 return -EINVAL; 2232 return -EINVAL;
2233 error = MPX_ENABLE_MANAGEMENT(me); 2233 error = MPX_ENABLE_MANAGEMENT();
2234 break; 2234 break;
2235 case PR_MPX_DISABLE_MANAGEMENT: 2235 case PR_MPX_DISABLE_MANAGEMENT:
2236 if (arg2 || arg3 || arg4 || arg5) 2236 if (arg2 || arg3 || arg4 || arg5)
2237 return -EINVAL; 2237 return -EINVAL;
2238 error = MPX_DISABLE_MANAGEMENT(me); 2238 error = MPX_DISABLE_MANAGEMENT();
2239 break; 2239 break;
2240 case PR_SET_FP_MODE: 2240 case PR_SET_FP_MODE:
2241 error = SET_FP_MODE(me, arg2); 2241 error = SET_FP_MODE(me, arg2);