linux-brain/arch/x86/mm
Tim Chen 2585e4b41c x86/speculation: Use Indirect Branch Prediction Barrier in context switch
commit 18bf3c3ea8 upstream.

Flush indirect branches when switching into a process that marked itself
non dumpable. This protects high value processes like gpg better,
without having too high performance overhead.

If done naïvely, we could switch to a kernel idle thread and then back
to the original process, such as:

    process A -> idle -> process A

In such scenario, we do not have to do IBPB here even though the process
is non-dumpable, as we are switching back to the same process after a
hiatus.

To avoid the redundant IBPB, which is expensive, we track the last mm
user context ID. The cost is to have an extra u64 mm context id to track
the last mm we were using before switching to the init_mm used by idle.
Avoiding the extra IBPB is probably worth the extra memory for this
common scenario.

For those cases where tlb_defer_switch_to_init_mm() returns true (non
PCID), lazy tlb will defer switch to init_mm, so we will not be changing
the mm for the process A -> idle -> process A switch. So IBPB will be
skipped for this case.

Thanks to the reviewers and Andy Lutomirski for the suggestion of
using ctx_id which got rid of the problem of mm pointer recycling.

Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: ak@linux.intel.com
Cc: karahmed@amazon.de
Cc: arjan@linux.intel.com
Cc: torvalds@linux-foundation.org
Cc: linux@dominikbrodowski.net
Cc: peterz@infradead.org
Cc: bp@alien8.de
Cc: luto@kernel.org
Cc: pbonzini@redhat.com
Link: https://lkml.kernel.org/r/1517263487-3708-1-git-send-email-dwmw@amazon.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-11 16:21:30 +01:00
..
kmemcheck x86/mm: Audit and remove any unnecessary uses of module.h 2016-07-14 13:04:20 +02:00
amdtopology.c x86/mm/numa: Open code function early_get_boot_cpu_id() 2016-08-15 08:51:54 +02:00
debug_pagetables.c x86/mm/ptdump: Make (debugfs)/kernel_page_tables read-only 2015-12-04 12:55:01 +01:00
dump_pagetables.c x86/mm/ptdump: Fix soft lockup in page table walker 2017-02-14 15:25:41 -08:00
extable.c x86/traps: Ignore high word of regs->cs in early_fixup_exception() 2016-11-21 08:06:54 +01:00
fault.c x86/mm/pkeys: Fix fill_sig_info_pkey 2018-01-23 19:57:06 +01:00
gup.c x86, mm: fix gup_pte_range() vs DAX mappings 2017-03-15 10:02:51 +08:00
highmem_32.c x86/mm: Audit and remove any unnecessary uses of module.h 2016-07-14 13:04:20 +02:00
hugetlbpage.c mm: larger stack guard gap, between vmas 2017-06-24 07:11:18 +02:00
ident_map.c x86/power/64: Always create temporary identity mapping correctly 2016-08-08 22:04:30 +02:00
init_32.c x86/mm: Audit and remove any unnecessary uses of module.h 2016-07-14 13:04:20 +02:00
init_64.c kaiser: add "nokaiser" boot option, using ALTERNATIVE 2018-01-05 15:46:34 +01:00
init.c x86/tlb: Drop the _GPL from the cpu_tlbstate export 2018-01-10 09:29:54 +01:00
iomap_32.c x86/mm: Audit and remove any unnecessary uses of module.h 2016-07-14 13:04:20 +02:00
ioremap.c x86/mm/kmmio: Fix mmiotrace for page unaligned addresses 2018-02-25 11:05:49 +01:00
kaiser.c vsyscall: Fix permissions for emulate mode with KAISER/PTI 2018-01-31 12:55:53 +01:00
kasan_init_64.c x86/kasan: Fix boot with KASAN=y and PROFILE_ANNOTATED_BRANCHES=y 2017-03-22 12:43:40 +01:00
kaslr.c KPTI: Rename to PAGE_TABLE_ISOLATION 2018-01-05 15:46:35 +01:00
kmmio.c x86/mm/kmmio: Fix mmiotrace for page unaligned addresses 2018-02-25 11:05:49 +01:00
Makefile KPTI: Rename to PAGE_TABLE_ISOLATION 2018-01-05 15:46:35 +01:00
mm_internal.h x86: Enable PAT to use cache mode translation tables 2014-11-16 11:04:26 +01:00
mmap.c Merge branch 'x86-mm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2016-03-15 10:45:39 -07:00
mmio-mod.c x86/mm: Audit and remove any unnecessary uses of module.h 2016-07-14 13:04:20 +02:00
mpx.c x86/mpx: Correctly report do_mpx_bt_fault() failures to user-space 2017-07-05 14:40:29 +02:00
numa_32.c x86/mm/32: Set the '__vmalloc_start_set' flag in initmem_init() 2017-06-24 07:11:14 +02:00
numa_64.c x86, mm: kill numa_free_all_bootmem() 2012-11-17 11:59:47 -08:00
numa_emulation.c x86: delete __cpuinit usage from all x86 files 2013-07-14 19:36:56 -04:00
numa_internal.h x86-32, mm: Rip out x86_32 NUMA remapping code 2013-01-31 14:12:30 -08:00
numa.c x86/numa: Online memory-less nodes at boot time 2016-09-21 21:18:38 +02:00
pageattr-test.c x86/mm/pat: Make mm/pageattr[-test].c explicitly non-modular 2015-08-25 09:48:38 +02:00
pageattr.c kaiser: merged update 2018-01-05 15:46:32 +01:00
pat_internal.h x86/mm/pat: Convert to pr_*() usage 2015-05-27 14:40:59 +02:00
pat_rbtree.c x86: Clean up various simple wrapper functions 2016-09-13 20:42:58 +02:00
pat.c x86/mm/pat: Don't report PAT on CPUs that don't support it 2017-07-15 12:16:17 +02:00
pf_in.c x86/mm: Audit and remove any unnecessary uses of module.h 2016-07-14 13:04:20 +02:00
pf_in.h
pgtable_32.c Merge branch 'x86-headers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2016-08-01 14:23:42 -04:00
pgtable.c x86/pti/efi: broken conversion from efi to kernel page table 2018-01-17 09:39:00 +01:00
physaddr.c x86/mm: Audit and remove any unnecessary uses of module.h 2016-07-14 13:04:20 +02:00
physaddr.h x86: split __phys_addr out into separate file 2009-09-10 11:48:55 -07:00
pkeys.c x86/pkeys: Allow configuration of init_pkru 2016-09-09 13:02:28 +02:00
setup_nx.c Revert "x86/mm/32: Set NX in __supported_pte_mask before enabling paging" 2016-04-26 19:52:57 +02:00
srat.c Merge branch 'x86-headers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2016-08-01 14:23:42 -04:00
testmmiotrace.c x86, kmmio/mmiotrace: Fix double free of kmmio_fault_pages 2010-06-18 11:30:09 +02:00
tlb.c x86/speculation: Use Indirect Branch Prediction Barrier in context switch 2018-03-11 16:21:30 +01:00