Linux 4.4.110
Greg KH
maintainerI'm announcing the release of the 4.4.110 kernel.
All users of the 4.4 kernel series must upgrade.
But be careful, there have been some reports of problems with this release during the -rc review cycle. Hopefully all of those issues are now resolved.
So please test, as of right now, it should be "bug compatible" with the "enterprise" kernel releases with regards to the Meltdown bug and proper support on all virtual platforms (meaning there is still a vdso issue that might trip up some old binaries, again, please test!)
If anyone has any problems, please let me know.
The updated 4.4.y git tree can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git linux-4.4.y
and can be browsed at the normal kernel.org git web browser:
http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=summary
thanks,
greg k-h
------------
Documentation/kernel-parameters.txt | 8 Makefile | 2 arch/x86/boot/compressed/misc.h | 1 arch/x86/entry/entry_64.S | 164 ++++++++-- arch/x86/entry/entry_64_compat.S | 7 arch/x86/entry/vdso/vclock_gettime.c | 99 +++--- arch/x86/entry/vdso/vdso-layout.lds.S | 3 arch/x86/entry/vdso/vdso2c.c | 3 arch/x86/entry/vdso/vma.c | 13 arch/x86/include/asm/cmdline.h | 2 arch/x86/include/asm/cpufeature.h | 4 arch/x86/include/asm/desc.h | 2 arch/x86/include/asm/hw_irq.h | 2 arch/x86/include/asm/kaiser.h | 141 ++++++++ arch/x86/include/asm/pgtable.h | 28 + arch/x86/include/asm/pgtable_64.h | 25 + arch/x86/include/asm/pgtable_types.h | 29 + arch/x86/include/asm/processor.h | 2 arch/x86/include/asm/pvclock.h | 9 arch/x86/include/asm/tlbflush.h | 74 +++- arch/x86/include/asm/vdso.h | 1 arch/x86/include/uapi/asm/processor-flags.h | 3 arch/x86/kernel/cpu/common.c | 28 + arch/x86/kernel/cpu/perf_event_intel_ds.c | 57 ++- arch/x86/kernel/espfix_64.c | 10 arch/x86/kernel/head_64.S | 35 +- arch/x86/kernel/irqinit.c | 2 arch/x86/kernel/kvmclock.c | 5 arch/x86/kernel/ldt.c | 25 + arch/x86/kernel/paravirt_patch_64.c | 2 arch/x86/kernel/process.c | 2 arch/x86/kernel/setup.c | 7 arch/x86/kernel/tracepoint.c | 2 arch/x86/kvm/x86.c | 3 arch/x86/lib/cmdline.c | 105 ++++++ arch/x86/mm/Makefile | 1 arch/x86/mm/init.c | 2 arch/x86/mm/init_64.c | 10 arch/x86/mm/kaiser.c | 456 ++++++++++++++++++++++++++++ arch/x86/mm/kasan_init_64.c | 11 arch/x86/mm/pageattr.c | 63 ++- arch/x86/mm/pgtable.c | 16 arch/x86/mm/tlb.c | 39 ++ include/asm-generic/vmlinux.lds.h | 7 include/linux/kaiser.h | 52 +++ include/linux/mmzone.h | 3 include/linux/percpu-defs.h | 32 + init/main.c | 2 kernel/fork.c | 6 mm/vmstat.c | 1 security/Kconfig | 10 51 files changed, 1469 insertions(+), 147 deletions(-)
Andrey Ryabinin (1):
x86/kasan: Clear kasan_zero_page after TLB flush
Andy Lutomirski (2):
x86, vdso, pvclock: Simplify and speed up the vdso pvclock reader x86/vdso: Get pvclock data from the vvar VMA instead of the fixmap
Borislav Petkov (4):
x86/kaiser: Rename and simplify X86_FEATURE_KAISER handling x86/kaiser: Check boottime cmdline params x86/kaiser: Reenable PARAVIRT
x86/kaiser: Move feature detection up
Dave Hansen (2):
kaiser: merged update
kaiser: enhanced by kernel and user PCIDs
Greg Kroah-Hartman (1):
Linux 4.4.110
Guenter Roeck (1):
kaiser: Set _PAGE_NX only if supported
Hugh Dickins (25):
kaiser: do not set _PAGE_NX on pgd_none
kaiser: stack map PAGE_SIZE at THREAD_SIZE-PAGE_SIZE
kaiser: fix build and FIXME in alloc_ldt_struct()
kaiser: KAISER depends on SMP
kaiser: fix regs to do_nmi() ifndef CONFIG_KAISER
kaiser: fix perf crashes
kaiser: ENOMEM if kaiser_pagetable_walk() NULL
kaiser: tidied up asm/kaiser.h somewhat
kaiser: tidied up kaiser_add/remove_mapping slightly
kaiser: kaiser_remove_mapping() move along the pgd
kaiser: cleanups while trying for gold link
kaiser: name that 0x1000 KAISER_SHADOW_PGD_OFFSET
kaiser: delete KAISER_REAL_SWITCH option
kaiser: vmstat show NR_KAISERTABLE as nr_overhead
kaiser: load_new_mm_cr3() let SWITCH_USER_CR3 flush user
kaiser: PCID 0 for kernel and 128 for user
kaiser: x86_cr3_pcid_noflush and x86_cr3_pcid_user
kaiser: paranoid_entry pass cr3 need to paranoid_exit
kaiser: _pgd_alloc() without __GFP_REPEAT to avoid stalls
kaiser: fix unlikely error in alloc_ldt_struct()
kaiser: add "nokaiser" boot option, using ALTERNATIVE
kaiser: use ALTERNATIVE instead of x86_cr3_pcid_noflush
kaiser: drop is_atomic arg to kaiser_pagetable_walk()
kaiser: asm/tlbflush.h handle noPGE at lower level
kaiser: kaiser_flush_tlb_on_return_to_user() check PCID
Jiri Kosina (1):
kaiser: disabled on Xen PV
Kees Cook (2):
KPTI: Rename to PAGE_TABLE_ISOLATION
KPTI: Report when enabled
Richard Fellner (1):
KAISER: Kernel Address Isolation
Thomas Gleixner (1):
x86/paravirt: Dont patch flush_tlb_single
Tom Lendacky (1):
x86/boot: Add early cmdline parsing for options with arguments
Greg KH
maintainerDocumentation/kernel-parameters.txt +8 -0
@@ -2523,6 +2523,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted. nojitter [IA-64] Disables jitter checking for ITC timers. + nopti [X86-64] Disable KAISER isolation of kernel from user. + no-kvmclock [X86,KVM] Disable paravirtualized KVM clock driver no-kvmapf [X86,KVM] Disable paravirtualized asynchronous page
@@ -3054,6 +3056,12 @@ bytes respectively. Such letter suffixes can also be entirely omitted. pt. [PARIDE] See Documentation/blockdev/paride.txt. + pti= [X86_64] + Control KAISER user/kernel address space isolation: + on - enable + off - disable + auto - default setting + pty.legacy_count= [KNL] Number of legacy pty's. Overwrites compiled-in default number.
Makefile +1 -1
@@ -1,6 +1,6 @@ VERSION = 4 PATCHLEVEL = 4 -SUBLEVEL = 109 +SUBLEVEL = 110 EXTRAVERSION = NAME = Blurry Fish Butt
arch/x86/boot/compressed/misc.h +1 -0
@@ -9,6 +9,7 @@*/ #undef CONFIG_PARAVIRT#undef CONFIG_PARAVIRT_SPINLOCKS +#undef CONFIG_PAGE_TABLE_ISOLATION#undef CONFIG_KASAN#include <linux/linkage.h>
arch/x86/entry/entry_64.S +145 -19
279 lines not on this page · raw message
arch/x86/entry/entry_64_compat.S +7 -0
@@ -13,6 +13,8 @@ #include <asm/irqflags.h> #include <asm/asm.h> #include <asm/smap.h> +#include <asm/pgtable_types.h> +#include <asm/kaiser.h> #include <linux/linkage.h> #include <linux/err.h>
@@ -50,6 +52,7 @@ ENDPROC(native_usergs_sysret32) ENTRY(entry_SYSENTER_compat) /* Interrupts are off on entry. */ SWAPGS_UNSAFE_STACK + SWITCH_KERNEL_CR3_NO_STACK movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp /*
@@ -161,6 +164,7 @@ ENDPROC(entry_SYSENTER_compat) ENTRY(entry_SYSCALL_compat) /* Interrupts are off on entry. */ SWAPGS_UNSAFE_STACK + SWITCH_KERNEL_CR3_NO_STACK /* Stash user ESP and switch to the kernel stack. */ movl %esp, %r8d
@@ -208,6 +212,7 @@ ENTRY(entry_SYSCALL_compat) /* Opportunistic SYSRET */ sysret32_from_system_call: TRACE_IRQS_ON /* User mode traces as IRQs on. */ + SWITCH_USER_CR3 movq RBX(%rsp), %rbx /* pt_regs->rbx */ movq RBP(%rsp), %rbp /* pt_regs->rbp */ movq EFLAGS(%rsp), %r11 /* pt_regs->flags (in r11) */
@@ -269,6 +274,7 @@ ENTRY(entry_INT80_compat) PARAVIRT_ADJUST_EXCEPTION_FRAME ASM_CLAC /* Do this early to minimize exposure */ SWAPGS + SWITCH_KERNEL_CR3_NO_STACK /* * User tracing code (ptrace or signal handlers) might assume that
@@ -311,6 +317,7 @@ ENTRY(entry_INT80_compat) /* Go back to user mode. */ TRACE_IRQS_ON + SWITCH_USER_CR3 SWAPGS jmp restore_regs_and_iret END(entry_INT80_compat)
arch/x86/entry/vdso/vclock_gettime.c +53 -46
122 lines not on this page · raw message
arch/x86/entry/vdso/vdso-layout.lds.S +2 -1
@@ -25,7 +25,7 @@ SECTIONS * segment. */ - vvar_start = . - 2 * PAGE_SIZE; + vvar_start = . - 3 * PAGE_SIZE; vvar_page = vvar_start; /* Place all vvars at the offsets in asm/vvar.h. */
@@ -36,6 +36,7 @@ SECTIONS #undef EMIT_VVAR hpet_page = vvar_start + PAGE_SIZE; + pvclock_page = vvar_start + 2 * PAGE_SIZE; . = SIZEOF_HEADERS;
arch/x86/entry/vdso/vdso2c.c +3 -0
@@ -73,6 +73,7 @@ enum { sym_vvar_start, sym_vvar_page, sym_hpet_page, + sym_pvclock_page, sym_VDSO_FAKE_SECTION_TABLE_START, sym_VDSO_FAKE_SECTION_TABLE_END, };
@@ -80,6 +81,7 @@ enum {const int special_pages[] = { sym_vvar_page, sym_hpet_page, + sym_pvclock_page, };struct vdso_sym {
@@ -91,6 +93,7 @@ struct vdso_sym required_syms[] = { [sym_vvar_start] = {"vvar_start", true}, [sym_vvar_page] = {"vvar_page", true}, [sym_hpet_page] = {"hpet_page", true}, + [sym_pvclock_page] = {"pvclock_page", true}, [sym_VDSO_FAKE_SECTION_TABLE_START] = {"VDSO_FAKE_SECTION_TABLE_START" , false },
arch/x86/entry/vdso/vma.c +13 -0
@@ -100,6 +100,7 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr) .name = "[vvar]", .pages = no_pages, }; +struct pvclock_vsyscall_time_info *pvti;if (calculate_addr) { addr = vdso_addr(current->mm->start_stack,
@@ -169,6 +170,18 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr) }#endif + pvti =pvclock_pvti_cpu0_va (); +if (pvti && image->sym_pvclock_page) { + ret =remap_pfn_range (vma, + text_start + image->sym_pvclock_page, +__pa (pvti) >>PAGE_SHIFT , +PAGE_SIZE , +PAGE_READONLY ); + +if (ret) + goto up_fail; + } + up_fail:if (ret) current->mm->context.vdso =NULL ;
arch/x86/include/asm/cmdline.h +2 -0
@@ -2,5 +2,7 @@#define _ASM_X86_CMDLINE_Hint cmdline_find_option_bool (const char *cmdline_ptr,const char *option); +int cmdline_find_option (const char *cmdline_ptr,const char *option, +char *buffer,int bufsize);#endif /* _ASM_X86_CMDLINE_H */
arch/x86/include/asm/cpufeature.h +4 -0
@@ -187,6 +187,7 @@#define X86_FEATURE_ARAT ( 7*32+ 1)/* Always Running APIC Timer */ #define X86_FEATURE_CPB ( 7*32+ 2)/* AMD Core Performance Boost */ #define X86_FEATURE_EPB ( 7*32+ 3)/* IA32_ENERGY_PERF_BIAS support */ +#define X86_FEATURE_INVPCID_SINGLE ( 7*32+ 4)/* Effectively INVPCID && CR4.PCIDE=1 */ #define X86_FEATURE_PLN ( 7*32+ 5)/* Intel Power Limit Notification */ #define X86_FEATURE_PTS ( 7*32+ 6)/* Intel Package Thermal Status */ #define X86_FEATURE_DTHERM ( 7*32+ 7)/* Digital Thermal Sensor */
@@ -199,6 +200,9 @@#define X86_FEATURE_HWP_PKG_REQ ( 7*32+14)/* Intel HWP_PKG_REQ */ #define X86_FEATURE_INTEL_PT ( 7*32+15)/* Intel Processor Trace */ +/* Because the ALTERNATIVE scheme is for members of the X86_FEATURE club... */ +#define X86_FEATURE_KAISER ( 7*32+31)/* CONFIG_PAGE_TABLE_ISOLATION w/o nokaiser */ +/* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW ( 8*32+ 0)/* Intel TPR Shadow */ #define X86_FEATURE_VNMI ( 8*32+ 1)/* Intel Virtual NMI */
arch/x86/include/asm/desc.h +1 -1
@@ -43,7 +43,7 @@ struct gdt_page {struct desc_struct gdt[GDT_ENTRIES ]; } __attribute__((aligned(PAGE_SIZE))); -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page); +DECLARE_PER_CPU_PAGE_ALIGNED_USER_MAPPED(struct gdt_page, gdt_page);static inline struct desc_struct *get_cpu_gdt_table (unsigned int cpu) {
arch/x86/include/asm/hw_irq.h +1 -1
@@ -187,7 +187,7 @@ extern char irq_entries_start[];#define VECTOR_RETRIGGERED ((void *)~0UL)typedef struct irq_desc *vector_irq_t [NR_VECTORS ]; -DECLARE_PER_CPU (vector_irq_t, vector_irq); +DECLARE_PER_CPU_USER_MAPPED (vector_irq_t, vector_irq);#endif /* !ASSEMBLY_ */
arch/x86/include/asm/kaiser.h new file +141 -0
141 lines not on this page · raw message
arch/x86/include/asm/pgtable.h +26 -2
@@ -18,6 +18,12 @@#ifndef __ASSEMBLY__#include <asm/x86_init.h> +#ifdef CONFIG_PAGE_TABLE_ISOLATION +extern int kaiser_enabled; +#else +#define kaiser_enabled 0 +#endif +void ptdump_walk_pgd_level (struct seq_file *m,pgd_t *pgd);void ptdump_walk_pgd_level_checkwx (void );
@@ -653,7 +659,17 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)static inline int pgd_bad (pgd_t pgd) { -return (pgd_flags (pgd) & ~_PAGE_USER) != _KERNPG_TABLE; +pgdval_t ignore_flags = _PAGE_USER; +/* +* We set NX on KAISER pgds that map userspace memory so +* that userspace can not meaningfully use the kernel +* page table by accident; it will fault on the first +* instruction it tries to run. See native_set_pgd(). +*/ +if (kaiser_enabled) + ignore_flags |= _PAGE_NX; + +return (pgd_flags (pgd) & ~ignore_flags) != _KERNPG_TABLE; }static inline int pgd_none (pgd_t pgd)
@@ -855,7 +871,15 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,*/ static inline void clone_pgd_range (pgd_t *dst,pgd_t *src,int count) { -memcpy (dst, src, count *sizeof (pgd_t)); +memcpy (dst, src, count *sizeof (pgd_t)); +#ifdef CONFIG_PAGE_TABLE_ISOLATION +if (kaiser_enabled) { +/* Clone the shadow pgd part as well */ +memcpy (native_get_shadow_pgd (dst), +native_get_shadow_pgd (src), + count *sizeof (pgd_t)); + } +#endif }#define PTE_SHIFT ilog2(PTRS_PER_PTE)
arch/x86/include/asm/pgtable_64.h +24 -1
@@ -106,9 +106,32 @@ static inline void native_pud_clear(pud_t *pud)native_set_pud (pud,native_make_pud (0 )); } +#ifdef CONFIG_PAGE_TABLE_ISOLATION +extern pgd_t kaiser_set_shadow_pgd (pgd_t *pgdp,pgd_t pgd); + +static inline pgd_t *native_get_shadow_pgd (pgd_t *pgdp) +{ +#ifdef CONFIG_DEBUG_VM +/* linux/mmdebug.h may not have been included at this point */ +BUG_ON (!kaiser_enabled); +#endif +return (pgd_t *)((unsigned long )pgdp | (unsigned long )PAGE_SIZE ); +} +#else +static inline pgd_t kaiser_set_shadow_pgd (pgd_t *pgdp,pgd_t pgd) +{ +return pgd; +} +static inline pgd_t *native_get_shadow_pgd (pgd_t *pgdp) +{ +BUILD_BUG_ON (1 ); +return NULL ; +} +#endif /* CONFIG_PAGE_TABLE_ISOLATION */ +static inline void native_set_pgd (pgd_t *pgdp,pgd_t pgd) { - *pgdp = pgd; + *pgdp =kaiser_set_shadow_pgd (pgdp, pgd); }static inline void native_pgd_clear (pgd_t *pgd)
arch/x86/include/asm/pgtable_types.h +28 -1
@@ -89,7 +89,7 @@#define _PAGE_NX (_AT(pteval_t, 0))#endif -#define _PAGE_PROTNONE (_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE) +#define _PAGE_PROTNONE (_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE)#define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \ _PAGE_ACCESSED | _PAGE_DIRTY)
@@ -102,6 +102,33 @@ _PAGE_SOFT_DIRTY)#define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE) +/* The ASID is the lower 12 bits of CR3 */ +#define X86_CR3_PCID_ASID_MASK (_AC((1<<12)-1,UL)) + +/* Mask for all the PCID-related bits in CR3: */ +#define X86_CR3_PCID_MASK (X86_CR3_PCID_NOFLUSH | X86_CR3_PCID_ASID_MASK) +#define X86_CR3_PCID_ASID_KERN (_AC(0x0,UL)) + +#if defined(CONFIG_PAGE_TABLE_ISOLATION ) && defined(CONFIG_X86_64 ) +/* Let X86_CR3_PCID_ASID_USER be usable for the X86_CR3_PCID_NOFLUSH bit */ +#define X86_CR3_PCID_ASID_USER (_AC(0x80,UL)) + +#define X86_CR3_PCID_KERN_FLUSH (X86_CR3_PCID_ASID_KERN) +#define X86_CR3_PCID_USER_FLUSH (X86_CR3_PCID_ASID_USER) +#define X86_CR3_PCID_KERN_NOFLUSH (X86_CR3_PCID_NOFLUSH | X86_CR3_PCID_ASID_KERN) +#define X86_CR3_PCID_USER_NOFLUSH (X86_CR3_PCID_NOFLUSH | X86_CR3_PCID_ASID_USER) +#else +#define X86_CR3_PCID_ASID_USER (_AC(0x0,UL)) +/* +* PCIDs are unsupported on 32-bit and none of these bits can be +* set in CR3: +*/ +#define X86_CR3_PCID_KERN_FLUSH (0) +#define X86_CR3_PCID_USER_FLUSH (0) +#define X86_CR3_PCID_KERN_NOFLUSH (0) +#define X86_CR3_PCID_USER_NOFLUSH (0) +#endif +/* * The cache modes defined here are used to translate between pure SW usage * and the HW defined cache mode bits and/or PAT entries.
arch/x86/include/asm/processor.h +1 -1
@@ -305,7 +305,7 @@ struct tss_struct { }____cacheline_aligned ; -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, cpu_tss); +DECLARE_PER_CPU_SHARED_ALIGNED_USER_MAPPED(struct tss_struct, cpu_tss);#ifdef CONFIG_X86_32 DECLARE_PER_CPU(unsigned long, cpu_current_top_of_stack);
arch/x86/include/asm/pvclock.h +9 -0
@@ -4,6 +4,15 @@#include <linux/clocksource.h> #include <asm/pvclock-abi.h> +#ifdef CONFIG_PARAVIRT_CLOCK +extern struct pvclock_vsyscall_time_info *pvclock_pvti_cpu0_va (void ); +#else +static inline struct pvclock_vsyscall_time_info *pvclock_pvti_cpu0_va (void ) +{ +return NULL ; +} +#endif +/* some helper functions for xen and kvm pv clock sources */ cycle_t pvclock_clocksource_read (struct pvclock_vcpu_time_info *src);u8 pvclock_read_flags (struct pvclock_vcpu_time_info *src);
arch/x86/include/asm/tlbflush.h +61 -13
117 lines not on this page · raw message
arch/x86/include/asm/vdso.h +1 -0
@@ -22,6 +22,7 @@ struct vdso_image {long sym_vvar_page;long sym_hpet_page; +long sym_pvclock_page;long sym_VDSO32_NOTE_MASK;long sym___kernel_sigreturn;long sym___kernel_rt_sigreturn;
arch/x86/include/uapi/asm/processor-flags.h +2 -1
@@ -77,7 +77,8 @@#define X86_CR3_PWT _BITUL(X86_CR3_PWT_BIT)#define X86_CR3_PCD_BIT 4/* Page Cache Disable */ #define X86_CR3_PCD _BITUL(X86_CR3_PCD_BIT) -#define X86_CR3_PCID_MASK _AC(0x00000fff,UL)/* PCID Mask */ +#define X86_CR3_PCID_NOFLUSH_BIT 63/* Preserve old PCID */ +#define X86_CR3_PCID_NOFLUSH _BITULL(X86_CR3_PCID_NOFLUSH_BIT)/* * Intel CPU features in CR4
arch/x86/kernel/cpu/common.c +25 -3
@@ -92,7 +92,7 @@ static const struct cpu_dev default_cpu = {static const struct cpu_dev *this_cpu = &default_cpu; -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = { +DEFINE_PER_CPU_PAGE_ALIGNED_USER_MAPPED(struct gdt_page, gdt_page) = { .gdt = { #ifdef CONFIG_X86_64/* * We need valid kernel segments for data and code in long mode too
@@ -324,8 +324,21 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)static void setup_pcid (struct cpuinfo_x86 *c) {if (cpu_has (c,X86_FEATURE_PCID )) { -if (cpu_has (c,X86_FEATURE_PGE )) { +if (cpu_has (c,X86_FEATURE_PGE ) || kaiser_enabled) {cr4_set_bits (X86_CR4_PCIDE ); +/* +* INVPCID has two "groups" of types: +* 1/2: Invalidate an individual address +* 3/4: Invalidate all contexts +* +* 1/2 take a PCID, but 3/4 do not. So, 3/4 +* ignore the PCID argument in the descriptor. +* But, we have to be careful not to call 1/2 +* with an actual non-zero PCID in them before +* we do the above cr4_set_bits(). +*/ +if (cpu_has (c,X86_FEATURE_INVPCID )) +set_cpu_cap (c,X86_FEATURE_INVPCID_SINGLE ); }else {/* * flush_tlb_all(), as currently implemented, won't
@@ -338,6 +351,7 @@ static void setup_pcid(struct cpuinfo_x86 *c)clear_cpu_cap (c,X86_FEATURE_PCID ); } } +kaiser_setup_pcid (); }/*
@@ -1229,7 +1243,7 @@ static const unsigned int exception_stack_sizes[N_EXCEPTION_STACKS] = { [DEBUG_STACK - 1] = DEBUG_STKSZ }; -static DEFINE_PER_CPU_PAGE_ALIGNED(char, exception_stacks +DEFINE_PER_CPU_PAGE_ALIGNED_USER_MAPPED (char, exception_stacks [(N_EXCEPTION_STACKS -1 ) *EXCEPTION_STKSZ +DEBUG_STKSZ ]);/* May not be marked __init: used by software suspend */
@@ -1392,6 +1406,14 @@ void cpu_init(void)* try to read it. */ cr4_init_shadow (); +if (!kaiser_enabled) { +/* +* secondary_startup_64() deferred setting PGE in cr4: +* probe_page_size_mask() sets it on the boot cpu, +* but it needs to be set on each secondary cpu. +*/ +cr4_set_bits (X86_CR4_PGE ); + }/* * Load microcode on this cpu if a valid microcode is available.
arch/x86/kernel/cpu/perf_event_intel_ds.c +45 -12
116 lines not on this page · raw message
arch/x86/kernel/espfix_64.c +10 -0
@@ -41,6 +41,7 @@#include <asm/pgalloc.h> #include <asm/setup.h> #include <asm/espfix.h> +#include <asm/kaiser.h> /* * Note: we only need 6*8 = 48 bytes for the espfix stack, but round
@@ -126,6 +127,15 @@ void __init init_espfix_bsp(void)/* Install the espfix pud into the kernel page directory */ pgd_p = &init_level4_pgt[pgd_index (ESPFIX_BASE_ADDR )];pgd_populate (&init_mm, pgd_p, (pud_t *)espfix_pud_page); +/* +* Just copy the top-level PGD that is mapping the espfix +* area to ensure it is mapped into the shadow user page +* tables. +*/ +if (kaiser_enabled) { +set_pgd (native_get_shadow_pgd (pgd_p), +__pgd (_KERNPG_TABLE |__pa ((pud_t *)espfix_pud_page))); + }/* Randomize the locations */ init_espfix_random ();
arch/x86/kernel/head_64.S +30 -5
@@ -183,8 +183,8 @@ ENTRY(secondary_startup_64) movq $(init_level4_pgt - __START_KERNEL_map), %rax 1: - /* Enable PAE mode and PGE */ - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx + /* Enable PAE and PSE, but defer PGE until kaiser_enabled is decided */ + movl $(X86_CR4_PAE | X86_CR4_PSE), %ecx movq %rcx, %cr4 /* Setup early boot stage 4 level pagetables. */
@@ -441,6 +441,27 @@ early_idt_ripmsg: .balign PAGE_SIZE; \ GLOBAL(name) +#ifdef CONFIG_PAGE_TABLE_ISOLATION +/* + * Each PGD needs to be 8k long and 8k aligned. We do not + * ever go out to userspace with these, so we do not + * strictly *need* the second page, but this allows us to + * have a single set_pgd() implementation that does not + * need to worry about whether it has 4k or 8k to work + * with. + * + * This ensures PGDs are 8k long: + */ +#define KAISER_USER_PGD_FILL 512 +/* This ensures they are 8k-aligned: */ +#define NEXT_PGD_PAGE(name) \ + .balign 2 * PAGE_SIZE; \ +GLOBAL(name) +#else +#define NEXT_PGD_PAGE(name) NEXT_PAGE(name) +#define KAISER_USER_PGD_FILL 0 +#endif + /* Automate the creation of 1 to 1 mapping pmd entries */ #define PMDS(START, PERM, COUNT) \ i = 0 ; \
@@ -450,9 +471,10 @@ GLOBAL(name) .endr __INITDATA -NEXT_PAGE(early_level4_pgt) +NEXT_PGD_PAGE(early_level4_pgt) .fill 511,8,0 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE + .fill KAISER_USER_PGD_FILL,8,0 NEXT_PAGE(early_dynamic_pgts) .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
@@ -460,16 +482,18 @@ NEXT_PAGE(early_dynamic_pgts) .data #ifndef CONFIG_XEN -NEXT_PAGE(init_level4_pgt) +NEXT_PGD_PAGE(init_level4_pgt) .fill 512,8,0 + .fill KAISER_USER_PGD_FILL,8,0 #else -NEXT_PAGE(init_level4_pgt) +NEXT_PGD_PAGE(init_level4_pgt) .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE .org init_level4_pgt + L4_PAGE_OFFSET*8, 0 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE .org init_level4_pgt + L4_START_KERNEL*8, 0 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */ .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE + .fill KAISER_USER_PGD_FILL,8,0 NEXT_PAGE(level3_ident_pgt) .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
@@ -480,6 +504,7 @@ NEXT_PAGE(level2_ident_pgt) */ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) #endif + .fill KAISER_USER_PGD_FILL,8,0 NEXT_PAGE(level3_kernel_pgt) .fill L3_START_KERNEL,8,0
arch/x86/kernel/irqinit.c +1 -1
@@ -51,7 +51,7 @@ static struct irqaction irq2 = { .flags = IRQF_NO_THREAD, }; -DEFINE_PER_CPU(vector_irq_t, vector_irq) = { +DEFINE_PER_CPU_USER_MAPPED(vector_irq_t, vector_irq) = { [0 ... NR_VECTORS - 1] = VECTOR_UNUSED, };
arch/x86/kernel/kvmclock.c +5 -0
@@ -45,6 +45,11 @@ early_param("no-kvmclock", parse_no_kvmclock);static struct pvclock_vsyscall_time_info *hv_clock;static struct pvclock_wall_clock wall_clock; +struct pvclock_vsyscall_time_info *pvclock_pvti_cpu0_va (void ) +{ +return hv_clock; +} +/* * The wallclock is the time of day when we booted. Since then, some time may * have elapsed since the hypervisor wrote the data. So we try to account for
arch/x86/kernel/ldt.c +20 -5
@@ -16,6 +16,7 @@#include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/uaccess.h> +#include <linux/kaiser.h> #include <asm/ldt.h> #include <asm/desc.h>
@@ -34,11 +35,21 @@ static void flush_ldt(void *current_mm)set_ldt (pc->ldt->entries, pc->ldt->size); } +static void __free_ldt_struct (struct ldt_struct *ldt) +{ +if (ldt->size *LDT_ENTRY_SIZE >PAGE_SIZE ) +vfree (ldt->entries); +else +free_page ((unsigned long )ldt->entries); +kfree (ldt); +} +/* The caller must call finalize_ldt_struct on the result. LDT starts zeroed. */ static struct ldt_struct *alloc_ldt_struct (int size) {struct ldt_struct *new_ldt;int alloc_size; +int ret;if (size >LDT_ENTRIES )return NULL ;
@@ -66,7 +77,13 @@ static struct ldt_struct *alloc_ldt_struct(int size)return NULL ; } + ret =kaiser_add_mapping ((unsigned long )new_ldt->entries, alloc_size, + __PAGE_KERNEL); new_ldt->size = size; +if (ret) { +__free_ldt_struct (new_ldt); +return NULL ; + }return new_ldt; }
@@ -92,12 +109,10 @@ static void free_ldt_struct(struct ldt_struct *ldt)if (likely (!ldt))return ; +kaiser_remove_mapping ((unsigned long )ldt->entries, + ldt->size *LDT_ENTRY_SIZE );paravirt_free_ldt (ldt->entries, ldt->size); -if (ldt->size *LDT_ENTRY_SIZE >PAGE_SIZE ) -vfree (ldt->entries); -else -free_page ((unsigned long )ldt->entries); -kfree (ldt); +__free_ldt_struct (ldt); }/*
arch/x86/kernel/paravirt_patch_64.c +0 -2
@@ -9,7 +9,6 @@ DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");DEF_NATIVE (pv_mmu_ops, read_cr2,"movq %cr2, %rax" );DEF_NATIVE (pv_mmu_ops, read_cr3,"movq %cr3, %rax" );DEF_NATIVE (pv_mmu_ops, write_cr3,"movq %rdi, %cr3" ); -DEF_NATIVE (pv_mmu_ops, flush_tlb_single,"invlpg (%rdi)" );DEF_NATIVE (pv_cpu_ops, clts,"clts" );DEF_NATIVE (pv_cpu_ops, wbinvd,"wbinvd" );
@@ -62,7 +61,6 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,PATCH_SITE (pv_mmu_ops, read_cr3);PATCH_SITE (pv_mmu_ops, write_cr3);PATCH_SITE (pv_cpu_ops, clts); -PATCH_SITE (pv_mmu_ops, flush_tlb_single);PATCH_SITE (pv_cpu_ops, wbinvd);#if defined(CONFIG_PARAVIRT_SPINLOCKS ) && defined(CONFIG_QUEUED_SPINLOCKS )case PARAVIRT_PATCH (pv_lock_ops.queued_spin_unlock):
arch/x86/kernel/process.c +1 -1
@@ -39,7 +39,7 @@* section. Since TSS's are completely CPU-local, we want them * on exact cacheline boundaries, to eliminate cacheline ping-pong. */ -__visible DEFINE_PER_CPU_SHARED_ALIGNED (struct tss_struct ,cpu_tss ) = { +__visible DEFINE_PER_CPU_SHARED_ALIGNED_USER_MAPPED (struct tss_struct ,cpu_tss ) = { .x86_tss = { .sp0 =TOP_OF_INIT_STACK , #ifdef CONFIG_X86_32
arch/x86/kernel/setup.c +7 -0
@@ -112,6 +112,7 @@#include <asm/alternative.h> #include <asm/prom.h> #include <asm/microcode.h> +#include <asm/kaiser.h> /* * max_low_pfn_mapped: highest direct mapped pfn under 4GB
@@ -1016,6 +1017,12 @@ void __init setup_arch(char **cmdline_p)*/ init_hypervisor_platform (); +/* +* This needs to happen right after XENPV is set on xen and +* kaiser_enabled is checked below in cleanup_highmap(). +*/ +kaiser_check_boottime_disable (); + x86_init.resources.probe_roms ();/* after parse_early_param, so could debug it */
arch/x86/kernel/tracepoint.c +2 -0
@@ -9,10 +9,12 @@#include <linux/atomic.h> atomic_t trace_idt_ctr =ATOMIC_INIT (0 ); +__aligned(PAGE_SIZE) struct desc_ptr trace_idt_descr = {NR_VECTORS *16 -1 , (unsigned long ) trace_idt_table };/* No need to be aligned, but done to keep all IDTs defined the same way. */ +__aligned(PAGE_SIZE) gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;static int trace_irq_vector_refcount;
arch/x86/kvm/x86.c +2 -1
@@ -759,7 +759,8 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)return 1 ;/* PCID can not be enabled when cr3[11:0]!=000H or EFER.LMA=0 */ -if ((kvm_read_cr3 (vcpu) &X86_CR3_PCID_MASK ) || !is_long_mode (vcpu)) +if ((kvm_read_cr3 (vcpu) &X86_CR3_PCID_ASID_MASK ) || + !is_long_mode (vcpu))return 1 ; }
arch/x86/lib/cmdline.c +105 -0
108 lines not on this page · raw message
arch/x86/mm/Makefile +1 -0
@@ -32,3 +32,4 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o obj-$(CONFIG_NUMA_EMU) += numa_emulation.o obj-$(CONFIG_X86_INTEL_MPX) += mpx.o +obj-$(CONFIG_PAGE_TABLE_ISOLATION) += kaiser.o
arch/x86/mm/init.c +1 -1
@@ -165,7 +165,7 @@ static void __init probe_page_size_mask(void)cr4_set_bits_and_update_boot (X86_CR4_PSE );/* Enable PGE if available */ -if (cpu_has_pge) { +if (cpu_has_pge && !kaiser_enabled) {cr4_set_bits_and_update_boot (X86_CR4_PGE ); __supported_pte_mask |= _PAGE_GLOBAL; }else
arch/x86/mm/init_64.c +10 -0
@@ -395,6 +395,16 @@ void __init cleanup_highmap(void)continue ;if (vaddr < (unsigned long ) _text || vaddr > end)set_pmd (pmd,__pmd (0 )); +else if (kaiser_enabled) { +/* +* level2_kernel_pgt is initialized with _PAGE_GLOBAL: +* clear that now. This is not important, so long as +* CR4.PGE remains clear, but it removes an anomaly. +* Physical mapping setup below avoids _PAGE_GLOBAL +* by use of massage_pgprot() inside pfn_pte() etc. +*/ +set_pmd (pmd,pmd_clear_flags (*pmd, _PAGE_GLOBAL)); + } } }
arch/x86/mm/kaiser.c new file +456 -0
456 lines not on this page · raw message
arch/x86/mm/kasan_init_64.c +8 -3
@@ -121,11 +121,16 @@ void __init kasan_init(void)kasan_populate_zero_shadow (kasan_mem_to_shadow ((void *)MODULES_END ), (void *)KASAN_SHADOW_END ); -memset (kasan_zero_page,0 ,PAGE_SIZE ); -load_cr3 (init_level4_pgt);__flush_tlb_all (); - init_task.kasan_depth =0 ; +/* +* kasan_zero_page has been used as early shadow memory, thus it may +* contain some garbage. Now we can clear it, since after the TLB flush +* no one should write to it. +*/ +memset (kasan_zero_page,0 ,PAGE_SIZE ); + + init_task.kasan_depth =0 ;pr_info ("KernelAddressSanitizer initialized\n" ); }
arch/x86/mm/pageattr.c +47 -16
160 lines not on this page · raw message
arch/x86/mm/pgtable.c +13 -3
@@ -6,7 +6,7 @@#include <asm/fixmap.h> #include <asm/mtrr.h> -#define PGALLOC_GFP GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO +#define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO)#ifdef CONFIG_HIGHPTE #define PGALLOC_USER_GFP __GFP_HIGHMEM
@@ -340,14 +340,24 @@ static inline void _pgd_free(pgd_t *pgd) kmem_cache_free(pgd_cache, pgd); }#else + +/* +* Instead of one pgd, Kaiser acquires two pgds. Being order-1, it is +* both 8k in size and 8k-aligned. That lets us just flip bit 12 +* in a pointer to swap between the two 4k halves. +*/ +#define PGD_ALLOCATION_ORDER kaiser_enabled +static inline pgd_t *_pgd_alloc (void ) { -return (pgd_t *)__get_free_page (PGALLOC_GFP ); +/* No __GFP_REPEAT: to avoid page allocation stalls in order-1 case */ +return (pgd_t *)__get_free_pages (PGALLOC_GFP & ~__GFP_REPEAT, +PGD_ALLOCATION_ORDER ); }static inline void _pgd_free (pgd_t *pgd) { -free_page ((unsigned long )pgd); +free_pages ((unsigned long )pgd,PGD_ALLOCATION_ORDER ); }#endif /* CONFIG_X86_PAE */
arch/x86/mm/tlb.c +35 -4
@@ -6,13 +6,14 @@#include <linux/interrupt.h> #include <linux/module.h> #include <linux/cpu.h> +#include <linux/debugfs.h> #include <asm/tlbflush.h> #include <asm/mmu_context.h> #include <asm/cache.h> #include <asm/apic.h> #include <asm/uv/uv.h> -#include <linux/debugfs.h> +#include <asm/kaiser.h> /* * TLB flushing, formerly SMP-only
@@ -34,6 +35,36 @@ struct flush_tlb_info {unsigned long flush_end; }; +static void load_new_mm_cr3 (pgd_t *pgdir) +{ +unsigned long new_mm_cr3 =__pa (pgdir); + +if (kaiser_enabled) { +/* +* We reuse the same PCID for different tasks, so we must +* flush all the entries for the PCID out when we change tasks. +* Flush KERN below, flush USER when returning to userspace in +* kaiser's SWITCH_USER_CR3 (_SWITCH_TO_USER_CR3) macro. +* +* invpcid_flush_single_context(X86_CR3_PCID_ASID_USER) could +* do it here, but can only be used if X86_FEATURE_INVPCID is +* available - and many machines support pcid without invpcid. +* +* If X86_CR3_PCID_KERN_FLUSH actually added something, then it +* would be needed in the write_cr3() below - if PCIDs enabled. +*/ +BUILD_BUG_ON (X86_CR3_PCID_KERN_FLUSH ); +kaiser_flush_tlb_on_return_to_user (); + } + +/* +* Caution: many callers of this function expect +* that load_cr3() is serializing and orders TLB +* fills with respect to the mm_cpumask writes. +*/ +write_cr3 (new_mm_cr3); +} +/* * We cannot call mmdrop() because we are in interrupt context, * instead update mm->cpu_vm_mask.
@@ -45,7 +76,7 @@ void leave_mm(int cpu)BUG ();if (cpumask_test_cpu (cpu,mm_cpumask (active_mm))) {cpumask_clear_cpu (cpu,mm_cpumask (active_mm)); -load_cr3 (swapper_pg_dir); +load_new_mm_cr3 (swapper_pg_dir);/* * This gets called in the idle path where RCU * functions differently. Tracing normally
@@ -105,7 +136,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,* ordering guarantee we need. * */ -load_cr3 (next->pgd); +load_new_mm_cr3 (next->pgd);trace_tlb_flush (TLB_FLUSH_ON_TASK_SWITCH ,TLB_FLUSH_ALL );
@@ -152,7 +183,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,* As above, load_cr3() is serializing and orders TLB * fills with respect to the mm_cpumask write. */ -load_cr3 (next->pgd); +load_new_mm_cr3 (next->pgd);trace_tlb_flush (TLB_FLUSH_ON_TASK_SWITCH ,TLB_FLUSH_ALL );load_mm_cr4 (next);load_mm_ldt (next);
include/asm-generic/vmlinux.lds.h +7 -0
@@ -725,7 +725,14 @@*/ #define PERCPU_INPUT (cacheline) \ VMLINUX_SYMBOL(__per_cpu_start) = .; \ + VMLINUX_SYMBOL(__per_cpu_user_mapped_start) = .; \ *(.data..percpu..first) \ + . = ALIGN(cacheline); \ + *(.data..percpu..user_mapped) \ + *(.data..percpu..user_mapped..shared_aligned) \ + . = ALIGN(PAGE_SIZE); \ + *(.data..percpu..user_mapped..page_aligned) \ + VMLINUX_SYMBOL(__per_cpu_user_mapped_end) = .; \ . = ALIGN(PAGE_SIZE); \ *(.data..percpu..page_aligned) \ . = ALIGN(cacheline); \
include/linux/kaiser.h new file +52 -0
52 lines not on this page · raw message
include/linux/mmzone.h +2 -1
@@ -131,8 +131,9 @@ enum zone_stat_item {NR_SLAB_RECLAIMABLE ,NR_SLAB_UNRECLAIMABLE ,NR_PAGETABLE ,/* used for pagetables */ -NR_KERNEL_STACK ,/* Second 128 byte cacheline */ +NR_KERNEL_STACK , +NR_KAISERTABLE ,NR_UNSTABLE_NFS ,/* NFS unstable pages */ NR_BOUNCE , NR_VMSCAN_WRITE,
include/linux/percpu-defs.h +31 -1
@@ -35,6 +35,12 @@#endif +#ifdef CONFIG_PAGE_TABLE_ISOLATION +#define USER_MAPPED_SECTION "..user_mapped" +#else +#define USER_MAPPED_SECTION "" +#endif +/* * Base implementations of per-CPU variable declarations and definitions, where * the section in which the variable is to be placed is provided by the
@@ -115,6 +121,12 @@#define DEFINE_PER_CPU (type, name) \ DEFINE_PER_CPU_SECTION(type, name, "") +#define DECLARE_PER_CPU_USER_MAPPED (type, name) \ + DECLARE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION) + +#define DEFINE_PER_CPU_USER_MAPPED (type, name) \ + DEFINE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION) +/* * Declaration/definition used for per-CPU variables that must come first in * the set of variables.
@@ -144,6 +156,14 @@ DEFINE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \ ____cacheline_aligned_in_smp +#define DECLARE_PER_CPU_SHARED_ALIGNED_USER_MAPPED (type, name) \ + DECLARE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION PER_CPU_SHARED_ALIGNED_SECTION) \ + ____cacheline_aligned_in_smp + +#define DEFINE_PER_CPU_SHARED_ALIGNED_USER_MAPPED (type, name) \ + DEFINE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION PER_CPU_SHARED_ALIGNED_SECTION) \ + ____cacheline_aligned_in_smp +#define DECLARE_PER_CPU_ALIGNED (type, name) \ DECLARE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION) \ ____cacheline_aligned
@@ -162,11 +182,21 @@#define DEFINE_PER_CPU_PAGE_ALIGNED (type, name) \ DEFINE_PER_CPU_SECTION(type, name, "..page_aligned") \ __aligned(PAGE_SIZE) +/* +* Declaration/definition used for per-CPU variables that must be page aligned and need to be mapped in user mode. +*/ +#define DECLARE_PER_CPU_PAGE_ALIGNED_USER_MAPPED (type, name) \ + DECLARE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION"..page_aligned") \ + __aligned(PAGE_SIZE) + +#define DEFINE_PER_CPU_PAGE_ALIGNED_USER_MAPPED (type, name) \ + DEFINE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION"..page_aligned") \ + __aligned(PAGE_SIZE)/* * Declaration/definition used for per-CPU variables that must be read mostly. */ -#define DECLARE_PER_CPU_READ_MOSTLY (type, name) \ +#define DECLARE_PER_CPU_READ_MOSTLY (type, name) \ DECLARE_PER_CPU_SECTION(type, name, "..read_mostly")#define DEFINE_PER_CPU_READ_MOSTLY (type, name) \
init/main.c +2 -0
@@ -81,6 +81,7 @@#include <linux/integrity.h> #include <linux/proc_ns.h> #include <linux/io.h> +#include <linux/kaiser.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -492,6 +493,7 @@ static void __init mm_init(void)pgtable_init ();vmalloc_init ();ioremap_huge_init (); +kaiser_init (); } asmlinkage __visible void __init start_kernel(void)
kernel/fork.c +6 -0
@@ -58,6 +58,7 @@#include <linux/tsacct_kern.h> #include <linux/cn_proc.h> #include <linux/freezer.h> +#include <linux/kaiser.h> #include <linux/delayacct.h> #include <linux/taskstats_kern.h> #include <linux/random.h>
@@ -169,6 +170,7 @@ static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,static inline void free_thread_info (struct thread_info *ti) { +kaiser_unmap_thread_stack (ti);free_kmem_pages ((unsigned long )ti,THREAD_SIZE_ORDER ); }# else
@@ -352,6 +354,10 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) goto free_ti; tsk->stack = ti; + + err =kaiser_map_thread_stack (tsk->stack); +if (err) + goto free_ti;#ifdef CONFIG_SECCOMP /* * We must handle setting up seccomp filters once we're under
mm/vmstat.c +1 -0
@@ -736,6 +736,7 @@ const char * const vmstat_text[] = {"nr_slab_unreclaimable" ,"nr_page_table_pages" ,"nr_kernel_stack" , +"nr_overhead" ,"nr_unstable" ,"nr_bounce" , "nr_vmscan_write",
security/Kconfig +10 -0
@@ -31,6 +31,16 @@ config SECURITY If you are unsure how to answer this question, answer N. +config PAGE_TABLE_ISOLATION + bool "Remove the kernel mapping in user mode" + default y + depends on X86_64 && SMP + help + This enforces a strict kernel and user space isolation, in order + to close hardware side channels on kernel address information. + + If you are unsure how to answer this question, answer Y. + config SECURITYFS bool "Enable the securityfs filesystem" help
Quoted 8 lines · Greg KH
I'm announcing the release of the 4.4.110 kernel.
All users of the 4.4 kernel series must upgrade.
But be careful, there have been some reports of problems with this release during the -rc review cycle. Hopefully all of those issues are now resolved.
Quoted 6 lines
So please test, as of right now, it should be "bug compatible" with the "enterprise" kernel releases with regards to the Meltdown bug and proper support on all virtual platforms (meaning there is still a vdso issue that might trip up some old binaries, again, please test!)
If anyone has any problems, please let me know.
FWIW I've just booted one of our LBs on it and am hammering it at full load with pti enabled and will let it run for the week-end. It takes 860k irq/s and about 1.7M syscalls/s. For now it works well (but slowly). Hopefully if there are any rare race conditions left it has a chance to trigger them.
Willy
Greg KH
maintainerQuoted 14 lines · Willy Tarreau
Quoted 13 lines · Greg KH
I'm announcing the release of the 4.4.110 kernel.
All users of the 4.4 kernel series must upgrade.
But be careful, there have been some reports of problems with this release during the -rc review cycle. Hopefully all of those issues are now resolved.
So please test, as of right now, it should be "bug compatible" with the "enterprise" kernel releases with regards to the Meltdown bug and proper support on all virtual platforms (meaning there is still a vdso issue that might trip up some old binaries, again, please test!)
Quoted 7 lines
Quoted 1 line
If anyone has any problems, please let me know.
FWIW I've just booted one of our LBs on it and am hammering it at full load with pti enabled and will let it run for the week-end. It takes 860k irq/s and about 1.7M syscalls/s. For now it works well (but slowly). Hopefully if there are any rare race conditions left it has a chance to trigger them.
Thanks for the testing, let me know if you see anything. And "slowly", does that mean it is noticable? I have some querys from the virtual networking people that are getting worried about all of this. I told them to go test, but they were having a hard time finding a kernel to test with. Hopefully we hear back from them now that these are out...
thanks,
greg k-h
Quoted 17 lines · Greg KH
Quoted 16 lines · Willy Tarreau
Quoted 14 lines · Greg KH
I'm announcing the release of the 4.4.110 kernel.
All users of the 4.4 kernel series must upgrade.
But be careful, there have been some reports of problems with this release during the -rc review cycle. Hopefully all of those issues are now resolved.
So please test, as of right now, it should be "bug compatible" with the "enterprise" kernel releases with regards to the Meltdown bug and proper support on all virtual platforms (meaning there is still a vdso issue that might trip up some old binaries, again, please test!)
If anyone has any problems, please let me know.
Quoted 7 lines
Quoted 5 lines
FWIW I've just booted one of our LBs on it and am hammering it at full load with pti enabled and will let it run for the week-end. It takes 860k irq/s and about 1.7M syscalls/s. For now it works well (but slowly). Hopefully if there are any rare race conditions left it has a chance to trigger them.
Thanks for the testing, let me know if you see anything.
Definitely! For now zero error after almost one billion connections and around 15 billion syscalls and 7B irqs.
Quoted 1 line
And "slowly", does that mean it is noticable?
It depends by whom :-) We benchmarked this machine a while ago at 93k connections per second on 4.9 on a single process and now I'm seeing about 60k for a single process. I don't want to digress too much about numbers now as the test conditions certainly differ a bit, I'll have to rerun more detailed ones later. For 99.9% of the users it will not be noticeable. Those having to fight DDoS will certainly notice it. I'm pretty sure we'll run with pti=off at least at the beginning.
Quoted 4 lines
I have some querys from the virtual
networking people that are getting worried about all of this. I told them to go test, but they were having a hard time finding a kernel to test with. Hopefully we hear back from them now that these are out...
I've tested and found a 40% perf drop on networking under KVM between pti=off and pti=on :-(
Fortunately in our case, people running in VMs are not those interested in performance (that's commonly the case) but I expect it willy impact some high-performance users who tune their VMs very precisely.
I'm currently testing a completely different approach for systems like these running basically a single task. The idea is to limit rdtsc to privileged processes only. I just discovered that my libc happily uses it in the ld.so so that limits my capabilities for now :-) But implementing an emulator could solve this for non-privileged processes, masking the lower bits and losing precision. It would not be a fix but an acceptable mitigation solution for some environments where pti=off is too expensive and where untrusted users are extremely rare (ie: just the remote cron job check disk space and collecting network stats). I already tested the variant of the spectre poc without rdtsc (using a thread and a counter) and it definitely is not something reasonably usable to steal reliable information anymore, I managed to get around 1/10 byte OK, but you never know which one.
For this reason, people considering pti=off as the only solution might sometimes prefer this one as a small improvement (and it could also stop other classes of future attacks, maybe something for KSPP later).
I'll continue to investigate and share my observations.
Have a nice week-end!
Willy
Quoted 7 lines
It depends by whom :-) We benchmarked this machine a while ago at 93k connections per second on 4.9 on a single process and now I'm seeing about 60k for a single process. I don't want to digress too much about numbers now as the test conditions certainly differ a bit, I'll have to rerun more detailed ones later. For 99.9% of the users it will not be noticeable. Those having to fight DDoS will certainly notice it. I'm pretty sure we'll run with pti=off at least at the beginning.
Are you running pti on the vm kernels or the host kernel or both ?
Quoted 3 lines
I'm currently testing a completely different approach for systems like these running basically a single task. The idea is to limit rdtsc to privileged processes only. I just discovered that my libc happily uses
The javascript attack in the paper does not use rdtsc, and the techniques to deal with rdtsc disabling are well known and used in other existing attacks.
Quoted 3 lines
For this reason, people considering pti=off as the only solution might sometimes prefer this one as a small improvement (and it could also stop other classes of future attacks, maybe something for KSPP later).
For a large class of environments where you are only running code that you trust (or at least if anyone evil changes you've got much bigger problems) that is probably a rational approach anyway.
Alan
Quoted 9 lines · Alan Cox
Quoted 7 lines
It depends by whom :-) We benchmarked this machine a while ago at 93k connections per second on 4.9 on a single process and now I'm seeing about 60k for a single process. I don't want to digress too much about numbers now as the test conditions certainly differ a bit, I'll have to rerun more detailed ones later. For 99.9% of the users it will not be noticeable. Those having to fight DDoS will certainly notice it. I'm pretty sure we'll run with pti=off at least at the beginning.
Are you running pti on the vm kernels or the host kernel or both ?
First, just to avoid confusion, numbers above were on bare metal (i7-4790K, having PCID). But as I said, I didn't necessarily apply the exact same test protocol as my goal was to quickly fire a long test to run for the week-end. In previous tests (pti vs non-pti) I only measured 17% difference.
For the tests I ran in KVM, PTI was only in the VM, the host was my laptop that has not yet been rebooted, hence is not protected yet. And here I used the same test protocol with/without PTI. The numbers I have in mind were respectively 30.3k conn/s and 18.3k (with pti).
Quoted 5 lines
Quoted 3 lines
I'm currently testing a completely different approach for systems like these running basically a single task. The idea is to limit rdtsc to privileged processes only. I just discovered that my libc happily uses
The javascript attack in the paper does not use rdtsc,
from what I've seen it uses the precise time reported by the browser which itself uses clock_gettime() (which we can thus control as well). But I might have missed certain points, there has been a lot to read this week...
Quoted 3 lines
and the techniques
to deal with rdtsc disabling are well known and used in other existing attacks.
Yes i've tested one of them for the spectre poc, but it really did not work well, leading to about 1 among 10 bytes only to be valid. In fact either you run the counter thread on the other sibling of the same core and it significantly perturbates the local activity, or you run it on another core, and the time it takes to retrieve the time requires some L1+L2 traversal. I'm not saying it doesn't work at all, I'm saying that the accuracy is highly degraded and that can turn something 100% reproducible into something requiring a long time to run, making the attack more noticeable (and possibly letting observed data degrade during the period).
Quoted 7 lines
Quoted 3 lines
For this reason, people considering pti=off as the only solution might sometimes prefer this one as a small improvement (and it could also stop other classes of future attacks, maybe something for KSPP later).
For a large class of environments where you are only running code that you trust (or at least if anyone evil changes you've got much bigger problems) that is probably a rational approach anyway.
For now yes unfortunately :-/
Willy
Quoted 5 lines · Willy Tarreau
Quoted 3 lines · Alan Cox
and the techniques
to deal with rdtsc disabling are well known and used in other existing attacks.
Quoted 10 lines
Yes i've tested one of them for the spectre poc, but it really did not work well, leading to about 1 among 10 bytes only to be valid. In fact either you run the counter thread on the other sibling of the same core and it significantly perturbates the local activity, or you run it on another core, and the time it takes to retrieve the time requires some L1+L2 traversal. I'm not saying it doesn't work at all, I'm saying that the accuracy is highly degraded and that can turn something 100% reproducible into something requiring a long time to run, making the attack more noticeable (and possibly letting observed data degrade during the period).
So I worked on an improved RDTSC emulation (attached) and it works reasonably well on the spectre poc found online. Its accuracy is almost as good as rdtsc on my i7-6700k on two threads running on the same core, and 8-10 times worse on two distinct cores, but still leads to ~50% success rate on the PoC. So my conclusion now is that it's indeed pointless to invest time trying to make RDTSC less accessible/accurate.
Willy
/*
* Evaluation of alternatives to rdtsc - 2018-01-06 - Willy Tarreau <[email protected]> *
* Observation on core-i7 6700k @4.4 GHz :
* - 2 threads, same core:
* hard resolution (local) ~= 28-30 cycles
* soft resolution (remote) ~= 29 cycles
*
* - 2 distinct cores:
* hard resolution (local) ~= 27-28 cycles
* soft resolution (remote) ~= 180-260 cycles
*/
#include <pthread.h>
#include <signal.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define MAXLOG 10000000
static volatile uint64_t softtsc;
static uint64_t t0, t1, harddur, softdur, hardamp, softamp; static uint64_t hardlog[MAXLOG];
static uint64_t softlog[MAXLOG];
static pthread_t thr;
static int hardcnt, softcnt;
static inline uint64_t rdtsc()
{
uint32_t a, d;
__asm__ volatile("rdtsc" : "=a" (a), "=d" (d));
return a + ((uint64_t)d << 32);
}void *run_softtsc(void *arg)
{
register __attribute__((unused)) uint64_t c = 0;
/* best resolution so far : 29 cycles */
__asm__ volatile(".align 16\n"
"1:\n"
"mov %0, %1\n"
"inc %0\n"
"sfence\n"
"jmp 1b\n"
: "+r"(c) : "m"(softtsc));
/* 36-37 cycles */
while (1) {
//__asm__ volatile("incq %0\nsfence" :: "m"(softtsc));
//__asm__ volatile("addq $1,%0\nsfence" :: "m"(softtsc));
//softtsc = c++;
//__asm__ volatile("sfence"/* ::: "memory"*/);
softtsc++;
}
}/* display the message and exit with the code */ __attribute__((noreturn)) void die(int code, const char *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
exit(code);
}int main(int argc, char **argv)
{
int err;
int log;
err = pthread_create(&thr, NULL, &run_softtsc, NULL);
if (err != 0)
die(1, "cannot create thread");
pthread_detach(thr);
t0 = rdtsc();
for (log = 0; log < MAXLOG; log++)
hardlog[log] = rdtsc();
t1 = rdtsc();
harddur = t1 - t0;
hardamp = hardlog[MAXLOG-1] - hardlog[0];
hardcnt = t0 = 0;
for (log = 0; log < MAXLOG; log++) {
if (t0 != hardlog[log]) {
hardcnt++;
t0 = hardlog[log];
}
}
t0 = rdtsc();
for (log = 0; log < MAXLOG; log++)
softlog[log] = softtsc;
t1 = rdtsc();
softdur = t1 - t0;
softamp = softlog[MAXLOG-1] - softlog[0];
//pthread_kill(thr, SIGKILL);
//pthread_join(thr, NULL);
softcnt = t0 = 0;
for (log = 0; log < MAXLOG; log++) {
if (t0 != softlog[log]) {
softcnt++;
t0 = softlog[log];
}
}
printf("hard: duration=%Lu cycles amplitude=%Lu values=%Lu resolution=%Lu\n",
(unsigned long long)harddur, (unsigned long long)hardamp,
(unsigned long long)hardcnt, (unsigned long long)harddur/hardcnt);
printf("soft: duration=%Lu cycles amplitude=%Lu values=%Lu resolution=%Lu\n",
(unsigned long long)softdur, (unsigned long long)softamp,
(unsigned long long)softcnt, (unsigned long long)softdur/softcnt);
//for (log = 0; log < MAXLOG; log++)
// printf("%d %Lu %Lu\n", log, (unsigned long long)hardlog[log], (unsigned long long)softlog[log]);
exit (0);
}Quoted 23 lines · Greg KH
Quoted 14 lines · Willy Tarreau
Quoted 13 lines · Greg KH
I'm announcing the release of the 4.4.110 kernel.
All users of the 4.4 kernel series must upgrade.
But be careful, there have been some reports of problems with this release during the -rc review cycle. Hopefully all of those issues are now resolved.
So please test, as of right now, it should be "bug compatible" with the "enterprise" kernel releases with regards to the Meltdown bug and proper support on all virtual platforms (meaning there is still a vdso issue that might trip up some old binaries, again, please test!)
Quoted 7 lines
Quoted 1 line
If anyone has any problems, please let me know.
FWIW I've just booted one of our LBs on it and am hammering it at full load with pti enabled and will let it run for the week-end. It takes 860k irq/s and about 1.7M syscalls/s. For now it works well (but slowly). Hopefully if there are any rare race conditions left it has a chance to trigger them.
Quoted 5 lines
Thanks for the testing, let me know if you see anything. And "slowly", does that mean it is noticable? I have some querys from the virtual networking people that are getting worried about all of this. I told them to go test, but they were having a hard time finding a kernel to test with. Hopefully we hear back from them now that these are out...
So at least the good news is that after 2.5 days, it has flawlessly forwarded 21 billion connections, 3 TB of TCP payload and processed ~180 billion interrupts. No single error in dmesg nor in the test. Thus I'm now quite confident with this kernel's stability.
Regards
Willy
Greg KH
maintainerQuoted 30 lines · Willy Tarreau
Quoted 23 lines · Greg KH
Quoted 14 lines · Willy Tarreau
Quoted 13 lines · Greg KH
I'm announcing the release of the 4.4.110 kernel.
All users of the 4.4 kernel series must upgrade.
But be careful, there have been some reports of problems with this release during the -rc review cycle. Hopefully all of those issues are now resolved.
So please test, as of right now, it should be "bug compatible" with the "enterprise" kernel releases with regards to the Meltdown bug and proper support on all virtual platforms (meaning there is still a vdso issue that might trip up some old binaries, again, please test!)
Quoted 7 lines
Quoted 1 line
If anyone has any problems, please let me know.
FWIW I've just booted one of our LBs on it and am hammering it at full load with pti enabled and will let it run for the week-end. It takes 860k irq/s and about 1.7M syscalls/s. For now it works well (but slowly). Hopefully if there are any rare race conditions left it has a chance to trigger them.
Quoted 5 lines
Thanks for the testing, let me know if you see anything. And "slowly", does that mean it is noticable? I have some querys from the virtual networking people that are getting worried about all of this. I told them to go test, but they were having a hard time finding a kernel to test with. Hopefully we hear back from them now that these are out...
Quoted 4 lines
So at least the good news is that after 2.5 days, it has flawlessly forwarded 21 billion connections, 3 TB of TCP payload and processed ~180 billion interrupts. No single error in dmesg nor in the test. Thus I'm now quite confident with this kernel's stability.
Wow, impressive. Thanks for the testing and letting me know.
greg k-h