Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 fixes from Ingo Molnar:
"Misc fixes: two vdso fixes, two kbuild fixes and a boot failure fix
with certain odd memory mappings"

* 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86, vdso: Use asm volatile in __getcpu
x86/build: Clean auto-generated processor feature files
x86: Fix mkcapflags.sh bash-ism
x86: Fix step size adjustment during initial memory mapping
x86_64, vdso: Fix the vdso address randomization algorithm

Changed files
+53 -39
arch
x86
boot
include
asm
kernel
mm
vdso
+1
arch/x86/boot/Makefile
··· 51 51 $(obj)/cpustr.h: $(obj)/mkcpustr FORCE 52 52 $(call if_changed,cpustr) 53 53 endif 54 + clean-files += cpustr.h 54 55 55 56 # --------------------------------------------------------------------------- 56 57
+4 -2
arch/x86/include/asm/vgtod.h
··· 80 80 81 81 /* 82 82 * Load per CPU data from GDT. LSL is faster than RDTSCP and 83 - * works on all CPUs. 83 + * works on all CPUs. This is volatile so that it orders 84 + * correctly wrt barrier() and to keep gcc from cleverly 85 + * hoisting it out of the calling function. 84 86 */ 85 - asm("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG)); 87 + asm volatile ("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG)); 86 88 87 89 return p; 88 90 }
+1
arch/x86/kernel/cpu/Makefile
··· 66 66 $(obj)/capflags.c: $(cpufeature) $(src)/mkcapflags.sh FORCE 67 67 $(call if_changed,mkcapflags) 68 68 endif 69 + clean-files += capflags.c
+1 -1
arch/x86/kernel/cpu/mkcapflags.sh
··· 28 28 # If the /* comment */ starts with a quote string, grab that. 29 29 VALUE="$(echo "$i" | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p')" 30 30 [ -z "$VALUE" ] && VALUE="\"$NAME\"" 31 - [ "$VALUE" == '""' ] && continue 31 + [ "$VALUE" = '""' ] && continue 32 32 33 33 # Name is uppercase, VALUE is all lowercase 34 34 VALUE="$(echo "$VALUE" | tr A-Z a-z)"
+17 -20
arch/x86/mm/init.c
··· 438 438 static unsigned long __init get_new_step_size(unsigned long step_size) 439 439 { 440 440 /* 441 - * Explain why we shift by 5 and why we don't have to worry about 442 - * 'step_size << 5' overflowing: 443 - * 444 - * initial mapped size is PMD_SIZE (2M). 441 + * Initial mapped size is PMD_SIZE (2M). 445 442 * We can not set step_size to be PUD_SIZE (1G) yet. 446 443 * In worse case, when we cross the 1G boundary, and 447 444 * PG_LEVEL_2M is not set, we will need 1+1+512 pages (2M + 8k) 448 - * to map 1G range with PTE. Use 5 as shift for now. 445 + * to map 1G range with PTE. Hence we use one less than the 446 + * difference of page table level shifts. 449 447 * 450 - * Don't need to worry about overflow, on 32bit, when step_size 451 - * is 0, round_down() returns 0 for start, and that turns it 452 - * into 0x100000000ULL. 448 + * Don't need to worry about overflow in the top-down case, on 32bit, 449 + * when step_size is 0, round_down() returns 0 for start, and that 450 + * turns it into 0x100000000ULL. 451 + * In the bottom-up case, round_up(x, 0) returns 0 though too, which 452 + * needs to be taken into consideration by the code below. 453 453 */ 454 - return step_size << 5; 454 + return step_size << (PMD_SHIFT - PAGE_SHIFT - 1); 455 455 } 456 456 457 457 /** ··· 471 471 unsigned long step_size; 472 472 unsigned long addr; 473 473 unsigned long mapped_ram_size = 0; 474 - unsigned long new_mapped_ram_size; 475 474 476 475 /* xen has big range in reserved near end of ram, skip it at first.*/ 477 476 addr = memblock_find_in_range(map_start, map_end, PMD_SIZE, PMD_SIZE); ··· 495 496 start = map_start; 496 497 } else 497 498 start = map_start; 498 - new_mapped_ram_size = init_range_memory_mapping(start, 499 + mapped_ram_size += init_range_memory_mapping(start, 499 500 last_start); 500 501 last_start = start; 501 502 min_pfn_mapped = last_start >> PAGE_SHIFT; 502 - /* only increase step_size after big range get mapped */ 503 - if (new_mapped_ram_size > mapped_ram_size) 503 + if (mapped_ram_size >= step_size) 504 504 step_size = get_new_step_size(step_size); 505 - mapped_ram_size += new_mapped_ram_size; 506 505 } 507 506 508 507 if (real_end < map_end) ··· 521 524 static void __init memory_map_bottom_up(unsigned long map_start, 522 525 unsigned long map_end) 523 526 { 524 - unsigned long next, new_mapped_ram_size, start; 527 + unsigned long next, start; 525 528 unsigned long mapped_ram_size = 0; 526 529 /* step_size need to be small so pgt_buf from BRK could cover it */ 527 530 unsigned long step_size = PMD_SIZE; ··· 536 539 * for page table. 537 540 */ 538 541 while (start < map_end) { 539 - if (map_end - start > step_size) { 542 + if (step_size && map_end - start > step_size) { 540 543 next = round_up(start + 1, step_size); 541 544 if (next > map_end) 542 545 next = map_end; 543 - } else 546 + } else { 544 547 next = map_end; 548 + } 545 549 546 - new_mapped_ram_size = init_range_memory_mapping(start, next); 550 + mapped_ram_size += init_range_memory_mapping(start, next); 547 551 start = next; 548 552 549 - if (new_mapped_ram_size > mapped_ram_size) 553 + if (mapped_ram_size >= step_size) 550 554 step_size = get_new_step_size(step_size); 551 - mapped_ram_size += new_mapped_ram_size; 552 555 } 553 556 } 554 557
+29 -16
arch/x86/vdso/vma.c
··· 41 41 42 42 struct linux_binprm; 43 43 44 - /* Put the vdso above the (randomized) stack with another randomized offset. 45 - This way there is no hole in the middle of address space. 46 - To save memory make sure it is still in the same PTE as the stack top. 47 - This doesn't give that many random bits. 48 - 49 - Only used for the 64-bit and x32 vdsos. */ 44 + /* 45 + * Put the vdso above the (randomized) stack with another randomized 46 + * offset. This way there is no hole in the middle of address space. 47 + * To save memory make sure it is still in the same PTE as the stack 48 + * top. This doesn't give that many random bits. 49 + * 50 + * Note that this algorithm is imperfect: the distribution of the vdso 51 + * start address within a PMD is biased toward the end. 52 + * 53 + * Only used for the 64-bit and x32 vdsos. 54 + */ 50 55 static unsigned long vdso_addr(unsigned long start, unsigned len) 51 56 { 52 57 #ifdef CONFIG_X86_32 ··· 59 54 #else 60 55 unsigned long addr, end; 61 56 unsigned offset; 62 - end = (start + PMD_SIZE - 1) & PMD_MASK; 57 + 58 + /* 59 + * Round up the start address. It can start out unaligned as a result 60 + * of stack start randomization. 61 + */ 62 + start = PAGE_ALIGN(start); 63 + 64 + /* Round the lowest possible end address up to a PMD boundary. */ 65 + end = (start + len + PMD_SIZE - 1) & PMD_MASK; 63 66 if (end >= TASK_SIZE_MAX) 64 67 end = TASK_SIZE_MAX; 65 68 end -= len; 66 - /* This loses some more bits than a modulo, but is cheaper */ 67 - offset = get_random_int() & (PTRS_PER_PTE - 1); 68 - addr = start + (offset << PAGE_SHIFT); 69 - if (addr >= end) 70 - addr = end; 69 + 70 + if (end > start) { 71 + offset = get_random_int() % (((end - start) >> PAGE_SHIFT) + 1); 72 + addr = start + (offset << PAGE_SHIFT); 73 + } else { 74 + addr = start; 75 + } 71 76 72 77 /* 73 - * page-align it here so that get_unmapped_area doesn't 74 - * align it wrongfully again to the next page. addr can come in 4K 75 - * unaligned here as a result of stack start randomization. 78 + * Forcibly align the final address in case we have a hardware 79 + * issue that requires alignment for performance reasons. 76 80 */ 77 - addr = PAGE_ALIGN(addr); 78 81 addr = align_vdso_addr(addr); 79 82 80 83 return addr;