Skip to content

Commit 541ac97

Browse files
committed
x86/sev: Make the #VC exception stacks part of the default stacks storage
The size of the exception stacks was increased by the commit in Fixes, resulting in stack sizes greater than a page in size. The #VC exception handling was only mapping the first (bottom) page, resulting in an SEV-ES guest failing to boot. Make the #VC exception stacks part of the default exception stacks storage and allocate them with a CONFIG_AMD_MEM_ENCRYPT=y .config. Map them only when a SEV-ES guest has been detected. Rip out the custom VC stacks mapping and storage code. [ bp: Steal and adapt Tom's commit message. ] Fixes: 7fae4c2 ("x86: Increase exception stack sizes") Signed-off-by: Borislav Petkov <[email protected]> Tested-by: Tom Lendacky <[email protected]> Tested-by: Brijesh Singh <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent c7419a6 commit 541ac97

File tree

3 files changed

+14
-33
lines changed

3 files changed

+14
-33
lines changed

arch/x86/include/asm/cpu_entry_area.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
#ifdef CONFIG_X86_64
1212

13+
#ifdef CONFIG_AMD_MEM_ENCRYPT
14+
#define VC_EXCEPTION_STKSZ EXCEPTION_STKSZ
15+
#else
16+
#define VC_EXCEPTION_STKSZ 0
17+
#endif
18+
1319
/* Macro to enforce the same ordering and stack sizes */
1420
#define ESTACKS_MEMBERS(guardsize, optional_stack_size) \
1521
char DF_stack_guard[guardsize]; \
@@ -28,7 +34,7 @@
2834

2935
/* The exception stacks' physical storage. No guard pages required */
3036
struct exception_stacks {
31-
ESTACKS_MEMBERS(0, 0)
37+
ESTACKS_MEMBERS(0, VC_EXCEPTION_STKSZ)
3238
};
3339

3440
/* The effective cpu entry area mapping with guard pages. */

arch/x86/kernel/sev.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ static struct ghcb __initdata *boot_ghcb;
4646
struct sev_es_runtime_data {
4747
struct ghcb ghcb_page;
4848

49-
/* Physical storage for the per-CPU IST stack of the #VC handler */
50-
char ist_stack[EXCEPTION_STKSZ] __aligned(PAGE_SIZE);
51-
52-
/*
53-
* Physical storage for the per-CPU fall-back stack of the #VC handler.
54-
* The fall-back stack is used when it is not safe to switch back to the
55-
* interrupted stack in the #VC entry code.
56-
*/
57-
char fallback_stack[EXCEPTION_STKSZ] __aligned(PAGE_SIZE);
58-
5949
/*
6050
* Reserve one page per CPU as backup storage for the unencrypted GHCB.
6151
* It is needed when an NMI happens while the #VC handler uses the real
@@ -99,27 +89,6 @@ DEFINE_STATIC_KEY_FALSE(sev_es_enable_key);
9989
/* Needed in vc_early_forward_exception */
10090
void do_early_exception(struct pt_regs *regs, int trapnr);
10191

102-
static void __init setup_vc_stacks(int cpu)
103-
{
104-
struct sev_es_runtime_data *data;
105-
struct cpu_entry_area *cea;
106-
unsigned long vaddr;
107-
phys_addr_t pa;
108-
109-
data = per_cpu(runtime_data, cpu);
110-
cea = get_cpu_entry_area(cpu);
111-
112-
/* Map #VC IST stack */
113-
vaddr = CEA_ESTACK_BOT(&cea->estacks, VC);
114-
pa = __pa(data->ist_stack);
115-
cea_set_pte((void *)vaddr, pa, PAGE_KERNEL);
116-
117-
/* Map VC fall-back stack */
118-
vaddr = CEA_ESTACK_BOT(&cea->estacks, VC2);
119-
pa = __pa(data->fallback_stack);
120-
cea_set_pte((void *)vaddr, pa, PAGE_KERNEL);
121-
}
122-
12392
static __always_inline bool on_vc_stack(struct pt_regs *regs)
12493
{
12594
unsigned long sp = regs->sp;
@@ -787,7 +756,6 @@ void __init sev_es_init_vc_handling(void)
787756
for_each_possible_cpu(cpu) {
788757
alloc_runtime_data(cpu);
789758
init_ghcb(cpu);
790-
setup_vc_stacks(cpu);
791759
}
792760

793761
sev_es_setup_play_dead();

arch/x86/mm/cpu_entry_area.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ static void __init percpu_setup_exception_stacks(unsigned int cpu)
110110
cea_map_stack(NMI);
111111
cea_map_stack(DB);
112112
cea_map_stack(MCE);
113+
114+
if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
115+
if (cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) {
116+
cea_map_stack(VC);
117+
cea_map_stack(VC2);
118+
}
119+
}
113120
}
114121
#else
115122
static inline void percpu_setup_exception_stacks(unsigned int cpu)

0 commit comments

Comments
 (0)