Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/mpx: Add temporary variable to reduce masking

When we allocate a bounds table, we call mmap(), then add a
"valid" bit to the value before storing it in to the bounds
directory.

If we fail along the way, we go and mask that valid bit
_back_ out. That seems a little silly, and this makes it
much more clear when we have a plain address versus an
actual table _entry_.

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: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20150607183704.3D69D5F4@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Dave Hansen and committed by
Ingo Molnar
a1149fc8 b0e9b09b

+4 -3
+4 -3
arch/x86/mm/mpx.c
··· 429 429 unsigned long expected_old_val = 0; 430 430 unsigned long actual_old_val = 0; 431 431 unsigned long bt_addr; 432 + unsigned long bd_new_entry; 432 433 int ret = 0; 433 434 434 435 /* ··· 442 441 /* 443 442 * Set the valid flag (kinda like _PAGE_PRESENT in a pte) 444 443 */ 445 - bt_addr = bt_addr | MPX_BD_ENTRY_VALID_FLAG; 444 + bd_new_entry = bt_addr | MPX_BD_ENTRY_VALID_FLAG; 446 445 447 446 /* 448 447 * Go poke the address of the new bounds table in to the ··· 456 455 * of the MPX code that have to pagefault_disable(). 457 456 */ 458 457 ret = user_atomic_cmpxchg_inatomic(&actual_old_val, bd_entry, 459 - expected_old_val, bt_addr); 458 + expected_old_val, bd_new_entry); 460 459 if (ret) 461 460 goto out_unmap; 462 461 ··· 487 486 trace_mpx_new_bounds_table(bt_addr); 488 487 return 0; 489 488 out_unmap: 490 - vm_munmap(bt_addr & MPX_BT_ADDR_MASK, MPX_BT_SIZE_BYTES); 489 + vm_munmap(bt_addr, MPX_BT_SIZE_BYTES); 491 490 return ret; 492 491 } 493 492