Path: blob/master/arch/x86/include/asm/cpu_entry_area.h
26481 views
/* SPDX-License-Identifier: GPL-2.0 */12#ifndef _ASM_X86_CPU_ENTRY_AREA_H3#define _ASM_X86_CPU_ENTRY_AREA_H45#include <linux/percpu-defs.h>6#include <asm/processor.h>7#include <asm/intel_ds.h>8#include <asm/pgtable_areas.h>910#ifdef CONFIG_X86_641112#ifdef CONFIG_AMD_MEM_ENCRYPT13#define VC_EXCEPTION_STKSZ EXCEPTION_STKSZ14#else15#define VC_EXCEPTION_STKSZ 016#endif1718/* Macro to enforce the same ordering and stack sizes */19#define ESTACKS_MEMBERS(guardsize, optional_stack_size) \20char DF_stack_guard[guardsize]; \21char DF_stack[EXCEPTION_STKSZ]; \22char NMI_stack_guard[guardsize]; \23char NMI_stack[EXCEPTION_STKSZ]; \24char DB_stack_guard[guardsize]; \25char DB_stack[EXCEPTION_STKSZ]; \26char MCE_stack_guard[guardsize]; \27char MCE_stack[EXCEPTION_STKSZ]; \28char VC_stack_guard[guardsize]; \29char VC_stack[optional_stack_size]; \30char VC2_stack_guard[guardsize]; \31char VC2_stack[optional_stack_size]; \32char IST_top_guard[guardsize]; \3334/* The exception stacks' physical storage. No guard pages required */35struct exception_stacks {36ESTACKS_MEMBERS(0, VC_EXCEPTION_STKSZ)37};3839/* The effective cpu entry area mapping with guard pages. */40struct cea_exception_stacks {41ESTACKS_MEMBERS(PAGE_SIZE, EXCEPTION_STKSZ)42};4344/*45* The exception stack ordering in [cea_]exception_stacks46*/47enum exception_stack_ordering {48ESTACK_DF,49ESTACK_NMI,50ESTACK_DB,51ESTACK_MCE,52ESTACK_VC,53ESTACK_VC2,54N_EXCEPTION_STACKS55};5657#define CEA_ESTACK_SIZE(st) \58sizeof(((struct cea_exception_stacks *)0)->st## _stack)5960#define CEA_ESTACK_BOT(ceastp, st) \61((unsigned long)&(ceastp)->st## _stack)6263#define CEA_ESTACK_TOP(ceastp, st) \64(CEA_ESTACK_BOT(ceastp, st) + CEA_ESTACK_SIZE(st))6566#define CEA_ESTACK_OFFS(st) \67offsetof(struct cea_exception_stacks, st## _stack)6869#define CEA_ESTACK_PAGES \70(sizeof(struct cea_exception_stacks) / PAGE_SIZE)7172#endif7374#ifdef CONFIG_X86_3275struct doublefault_stack {76unsigned long stack[(PAGE_SIZE - sizeof(struct x86_hw_tss)) / sizeof(unsigned long)];77struct x86_hw_tss tss;78} __aligned(PAGE_SIZE);79#endif8081/*82* cpu_entry_area is a percpu region that contains things needed by the CPU83* and early entry/exit code. Real types aren't used for all fields here84* to avoid circular header dependencies.85*86* Every field is a virtual alias of some other allocated backing store.87* There is no direct allocation of a struct cpu_entry_area.88*/89struct cpu_entry_area {90char gdt[PAGE_SIZE];9192/*93* The GDT is just below entry_stack and thus serves (on x86_64) as94* a read-only guard page. On 32-bit the GDT must be writeable, so95* it needs an extra guard page.96*/97#ifdef CONFIG_X86_3298char guard_entry_stack[PAGE_SIZE];99#endif100struct entry_stack_page entry_stack_page;101102#ifdef CONFIG_X86_32103char guard_doublefault_stack[PAGE_SIZE];104struct doublefault_stack doublefault_stack;105#endif106107/*108* On x86_64, the TSS is mapped RO. On x86_32, it's mapped RW because109* we need task switches to work, and task switches write to the TSS.110*/111struct tss_struct tss;112113#ifdef CONFIG_X86_64114/*115* Exception stacks used for IST entries with guard pages.116*/117struct cea_exception_stacks estacks;118#endif119/*120* Per CPU debug store for Intel performance monitoring. Wastes a121* full page at the moment.122*/123struct debug_store cpu_debug_store;124/*125* The actual PEBS/BTS buffers must be mapped to user space126* Reserve enough fixmap PTEs.127*/128struct debug_store_buffers cpu_debug_buffers;129};130131#define CPU_ENTRY_AREA_SIZE (sizeof(struct cpu_entry_area))132133DECLARE_PER_CPU(struct cpu_entry_area *, cpu_entry_area);134DECLARE_PER_CPU(struct cea_exception_stacks *, cea_exception_stacks);135136extern void setup_cpu_entry_areas(void);137extern void cea_set_pte(void *cea_vaddr, phys_addr_t pa, pgprot_t flags);138139extern struct cpu_entry_area *get_cpu_entry_area(int cpu);140141static __always_inline struct entry_stack *cpu_entry_stack(int cpu)142{143return &get_cpu_entry_area(cpu)->entry_stack_page.stack;144}145146#define __this_cpu_ist_top_va(name) \147CEA_ESTACK_TOP(__this_cpu_read(cea_exception_stacks), name)148149#define __this_cpu_ist_bottom_va(name) \150CEA_ESTACK_BOT(__this_cpu_read(cea_exception_stacks), name)151152#endif153154155