x86/mm changes for v4.1
Subsystems (4)
Linus,
Please pull the latest x86-mm-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86-mm-for-linus
# HEAD: 4e26d11f52684dc8b1632a8cfe450cb5197a8464 x86/mm: Improve AMD Bulldozer ASLR workaround
The main changes in this cycle were:
- reduce the x86/32 PAE per task PGD allocation overhead from 4K to 0.032k. (Fenghua Yu)
- early_ioremap/memunmap() usage cleanups (Juergen Gross)
- gbpages support cleanups (Luis R. Rodriguez)
- improve AMD Bulldozer (family 0x15) ASLR I$ aliasing workaround to increase randomization by 3 bits (per bootup). (Hector Marco-Gisbert)
- misc fixlets
out-of-topic modifications in x86-mm-for-linus:
-------------------------------------------------
include/linux/init.h # c281b94570ab: init.h: Clean up the __setup
# bfb33bad83f6: init.h: Add early_param_on_o
Thanks,
Ingo
------------------>
Daniel Borkmann (1):
x86/mm: Unexport set_memory_ro() and set_memory_rw()
Fenghua Yu (1):
x86/mm: Reduce PAE-mode per task pgd allocation overhead from 4K to 32 bytes
Hector Marco-Gisbert (1):
x86/mm: Improve AMD Bulldozer ASLR workaround
Ingo Molnar (4):
x86/mm: Further simplify 1 GB kernel linear mappings handling
x86/mm: Simplify probe_page_size_mask()
init.h: Clean up the __setup()/early_param() macros
x86/mm/pat: Initialize __cachemode2pte_tbl[] and __pte2cachemode_tbl[] in a bit more readable fashion
Juergen Gross (2):
x86/mm: Use early_memunmap() instead of early_iounmap() x86/mm, efi: Use early_ioremap() in arch/x86/platform/efi/efi-bgrt.c
Luis R. Rodriguez (4):
x86/mm: Use IS_ENABLED() for direct_gbpages x86/mm: Simplify enabling direct_gbpages init.h: Add early_param_on_off()
x86/mm: Use early_param_on_off() for direct_gbpages
Pavel Machek (1):
x86/mm/pat: Ensure different messages in STRICT_DEVMEM and PAT cases
arch/x86/Kconfig | 14 +++---- arch/x86/include/asm/elf.h | 1 + arch/x86/kernel/cpu/amd.c | 4 ++ arch/x86/kernel/devicetree.c | 4 +- arch/x86/kernel/e820.c | 2 +- arch/x86/kernel/setup.c | 8 ++-- arch/x86/kernel/sys_x86_64.c | 30 +++++++++++++-- arch/x86/mm/init.c | 68 +++++++++++++++------------------ arch/x86/mm/init_64.c | 14 ------- arch/x86/mm/pageattr.c | 4 -- arch/x86/mm/pat.c | 6 +-- arch/x86/mm/pgtable.c | 81 ++++++++++++++++++++++++++++++++++++++-- arch/x86/platform/efi/efi-bgrt.c | 4 +- include/linux/init.h | 38 ++++++++++++++----- 14 files changed, 189 insertions(+), 89 deletions(-)
arch/x86/Kconfig +7 -7
@@ -1299,14 +1299,14 @@ config ARCH_DMA_ADDR_T_64BIT def_bool y depends on X86_64 || HIGHMEM64G -config DIRECT_GBPAGES - bool "Enable 1GB pages for kernel pagetables" if EXPERT - default y - depends on X86_64 +config X86_DIRECT_GBPAGES + def_bool y + depends on X86_64 && !DEBUG_PAGEALLOC && !KMEMCHECK ---help--- - Allow the kernel linear mapping to use 1GB pages on CPUs that - support it. This can improve the kernel's performance a tiny bit by - reducing TLB pressure. If in doubt, say "Y". + Certain kernel features effectively disable kernel + linear 1 GB mappings (even if the CPU otherwise + supports them), so don't confuse the user by printing + that we have them enabled. # Common NUMA Features config NUMA
arch/x86/include/asm/elf.h +1 -0
@@ -365,6 +365,7 @@ enum align_flags {struct va_alignment {int flags;unsigned long mask; +unsigned long bits; }____cacheline_aligned ;extern struct va_alignment va_align;
arch/x86/kernel/cpu/amd.c +4 -0
@@ -5,6 +5,7 @@#include <linux/io.h> #include <linux/sched.h> +#include <linux/random.h> #include <asm/processor.h> #include <asm/apic.h> #include <asm/cpu.h>
@@ -488,6 +489,9 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) va_align.mask = (upperbit -1 ) &PAGE_MASK ; va_align.flags =ALIGN_VA_32 |ALIGN_VA_64 ; + +/* A random value per boot for bit slice [12:upper_bit) */ + va_align.bits =get_random_int () & va_align.mask; } }
arch/x86/kernel/devicetree.c +2 -2
@@ -286,13 +286,13 @@ static void __init x86_flattree_get_config(void) initial_boot_params = dt =early_memremap (initial_dtb, map_len); size =of_get_flat_dt_size ();if (map_len < size) { -early_iounmap (dt, map_len); +early_memunmap (dt, map_len); initial_boot_params = dt =early_memremap (initial_dtb, size); map_len = size; }unflatten_and_copy_device_tree (); - early_iounmap(dt, map_len); + early_memunmap(dt, map_len); }#else static inline void x86_flattree_get_config (void ) { }
arch/x86/kernel/e820.c +1 -1
@@ -661,7 +661,7 @@ void __init parse_e820_ext(u64 phys_addr, u32 data_len) extmap = (struct e820entry *)(sdata->data);__append_e820_map (extmap, entries);sanitize_e820_map (e820.map,ARRAY_SIZE (e820.map), &e820.nr_map); -early_iounmap (sdata, data_len); +early_memunmap (sdata, data_len);printk (KERN_INFO "e820: extended physical RAM map:\n" );e820_print_map ("extended" ); }
arch/x86/kernel/setup.c +4 -4
@@ -356,7 +356,7 @@ static void __init relocate_initrd(void) mapaddr = ramdisk_image &PAGE_MASK ; p =early_memremap (mapaddr, clen+slop);memcpy (q, p+slop, clen); -early_iounmap (p, clen+slop); +early_memunmap (p, clen+slop); q += clen; ramdisk_image += clen; ramdisk_size -= clen;
@@ -445,7 +445,7 @@ static void __init parse_setup_data(void) data_len = data->len +sizeof (struct setup_data ); data_type = data->type; pa_next = data->next; -early_iounmap (data,sizeof (*data)); +early_memunmap (data,sizeof (*data));switch (data_type) {case SETUP_E820_EXT :
@@ -480,7 +480,7 @@ static void __init e820_reserve_setup_data(void) E820_RAM, E820_RESERVED_KERN); found =1 ; pa_data = data->next; -early_iounmap (data,sizeof (*data)); +early_memunmap (data,sizeof (*data)); }if (!found)return ;
@@ -501,7 +501,7 @@ static void __init memblock_x86_reserve_range_setup_data(void) data =early_memremap (pa_data,sizeof (*data));memblock_reserve (pa_data,sizeof (*data) + data->len); pa_data = data->next; -early_iounmap (data,sizeof (*data)); +early_memunmap (data,sizeof (*data)); } }
arch/x86/kernel/sys_x86_64.c +27 -3
@@ -34,10 +34,26 @@ static unsigned long get_align_mask(void)return va_align.mask; } +/* +* To avoid aliasing in the I$ on AMD F15h, the bits defined by the +* va_align.bits, [12:upper_bit), are set to a random value instead of +* zeroing them. This random value is computed once per boot. This form +* of ASLR is known as "per-boot ASLR". +* +* To achieve this, the random value is added to the info.align_offset +* value before calling vm_unmapped_area() or ORed directly to the +* address. +*/ +static unsigned long get_align_bits (void ) +{ +return va_align.bits &get_align_mask (); +} +unsigned long align_vdso_addr (unsigned long addr) {unsigned long align_mask =get_align_mask (); -return (addr + align_mask) & ~align_mask; + addr = (addr + align_mask) & ~align_mask; +return addr |get_align_bits (); }static int __init control_va_addr_alignment (char *str)
@@ -135,8 +151,12 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, info.length = len; info.low_limit = begin; info.high_limit = end; - info.align_mask = filp ?get_align_mask () :0 ; + info.align_mask =0 ; info.align_offset = pgoff <<PAGE_SHIFT ; +if (filp) { + info.align_mask =get_align_mask (); + info.align_offset +=get_align_bits (); + }return vm_unmapped_area (&info); }
@@ -174,8 +194,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len; info.low_limit =PAGE_SIZE ; info.high_limit = mm->mmap_base; - info.align_mask = filp ?get_align_mask () :0 ; + info.align_mask =0 ; info.align_offset = pgoff <<PAGE_SHIFT ; +if (filp) { + info.align_mask =get_align_mask (); + info.align_offset +=get_align_bits (); + } addr =vm_unmapped_area (&info);if (!(addr & ~PAGE_MASK ))return addr;
arch/x86/mm/init.c +31 -37
103 lines not on this page · raw message
arch/x86/mm/init_64.c +0 -14
@@ -130,20 +130,6 @@ int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page,return 0 ; } -static int __init parse_direct_gbpages_off (char *arg) -{ - direct_gbpages =0 ; -return 0 ; -} -early_param ("nogbpages" , parse_direct_gbpages_off); - -static int __init parse_direct_gbpages_on (char *arg) -{ - direct_gbpages =1 ; -return 0 ; -} -early_param ("gbpages" , parse_direct_gbpages_on); -/* * NOTE: pagetable_init alloc all the fixmap pagetables contiguous on the * physical space so we can cache the place of the first one and move
arch/x86/mm/pageattr.c +0 -4
@@ -81,11 +81,9 @@ void arch_report_meminfo(struct seq_file *m)seq_printf (m,"DirectMap4M: %8lu kB\n" , direct_pages_count[PG_LEVEL_2M ] <<12 );#endif -#ifdef CONFIG_X86_64 if (direct_gbpages)seq_printf (m,"DirectMap1G: %8lu kB\n" , direct_pages_count[PG_LEVEL_1G ] <<20 ); -#endif }#else static inline void split_page_count (int level) { }
@@ -1654,13 +1652,11 @@ int set_memory_ro(unsigned long addr, int numpages) {return change_page_attr_clear (&addr, numpages,__pgprot (_PAGE_RW),0 ); } -EXPORT_SYMBOL_GPL (set_memory_ro);int set_memory_rw (unsigned long addr,int numpages) {return change_page_attr_set (&addr, numpages,__pgprot (_PAGE_RW),0 ); } -EXPORT_SYMBOL_GPL (set_memory_rw);int set_memory_np (unsigned long addr,int numpages) {
arch/x86/mm/pat.c +3 -3
@@ -610,7 +610,7 @@ pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, }#ifdef CONFIG_STRICT_DEVMEM -/* This check is done in drivers/char/mem.c in case of STRICT_DEVMEM*/ +/* This check is done in drivers/char/mem.c in case of STRICT_DEVMEM */ static inline int range_is_allowed (unsigned long pfn,unsigned long size) {return 1 ;
@@ -628,8 +628,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)while (cursor < to) {if (!devmem_is_allowed (pfn)) { -printk (KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n" , - current->comm, from, to -1 ); +printk (KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx], PAT prevents it\n" , + current->comm, from, to -1 );return 0 ; } cursor +=PAGE_SIZE ;
arch/x86/mm/pgtable.c +78 -3
104 lines not on this page · raw message
arch/x86/platform/efi/efi-bgrt.c +2 -2
@@ -67,7 +67,7 @@ void __init efi_bgrt_init(void) image =efi_lookup_mapped_addr (bgrt_tab->image_address);if (!image) { - image =early_memremap (bgrt_tab->image_address, + image =early_ioremap (bgrt_tab->image_address,sizeof (bmp_header)); ioremapped = true;if (!image) {
@@ -89,7 +89,7 @@ void __init efi_bgrt_init(void) }if (ioremapped) { - image =early_memremap (bgrt_tab->image_address, + image =early_ioremap (bgrt_tab->image_address, bmp_header.size);if (!image) {pr_err ("Ignoring BGRT: failed to map image memory\n" );
include/linux/init.h +29 -9
@@ -253,21 +253,41 @@ struct obs_kernel_param {* obs_kernel_param "array" too far apart in .init.setup. */ #define __setup_param (str, unique_id, fn, early) \ - static const char __setup_str_##unique_id[] __initconst \ - __aligned(1) = str; \ - static struct obs_kernel_param __setup_##unique_id \ - __used __section(.init.setup) \ - __attribute__((aligned((sizeof(long))))) \ + static const char __setup_str_##unique_id[] __initconst \ + __aligned(1) = str; \ + static struct obs_kernel_param __setup_##unique_id \ + __used __section(.init.setup) \ + __attribute__((aligned((sizeof(long))))) \ = { __setup_str_##unique_id, fn, early } -#define __setup (str, fn) \ +#define __setup (str, fn) \ __setup_param(str, fn, fn, 0) -/* NOTE: fn is as per module_param, not __setup! Emits warning if fn -* returns non-zero. */ -#define early_param (str, fn) \ +/* +* NOTE: fn is as per module_param, not __setup! +* Emits warning if fn returns non-zero. +*/ +#define early_param (str, fn) \ __setup_param(str, fn, fn, 1) +#define early_param_on_off (str_on, str_off, var, config) \ + \ + int var = IS_ENABLED(config); \ + \ + static int __init parse_##var##_on(char *arg) \ + { \ + var = 1; \ + return 0; \ + } \ + __setup_param(str_on, parse_##var##_on, parse_##var##_on, 1); \ + \ + static int __init parse_##var##_off(char *arg) \ + { \ + var = 0; \ + return 0; \ + } \ + __setup_param(str_off, parse_##var##_off, parse_##var##_off, 1) +/* Relies on boot_command_line being set */ void __init parse_early_param (void );void __init parse_early_options (char *cmdline);