Skip to content

Commit ce47d0c

Browse files
joergroedelsuryasaimadhu
authored andcommitted
x86/sev: Allow #VC exceptions on the VC2 stack
When code running on the VC2 stack causes a nested VC exception, the handler will not handle it as expected but goes again into the error path. The result is that the panic() call happening when the VC exception was raised in an invalid context is called recursively. Fix this by checking the interrupted stack too and only call panic if it is not the VC2 stack. [ bp: Fixup comment. ] Fixes: 0786138 ("x86/sev-es: Add a Runtime #VC Exception Handler") Reported-by: Xinyang Ge <[email protected]> Signed-off-by: Joerg Roedel <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 5681981 commit ce47d0c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

arch/x86/kernel/sev.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,13 +1319,26 @@ static __always_inline void vc_forward_exception(struct es_em_ctxt *ctxt)
13191319
}
13201320
}
13211321

1322-
static __always_inline bool on_vc_fallback_stack(struct pt_regs *regs)
1322+
static __always_inline bool is_vc2_stack(unsigned long sp)
13231323
{
1324-
unsigned long sp = (unsigned long)regs;
1325-
13261324
return (sp >= __this_cpu_ist_bottom_va(VC2) && sp < __this_cpu_ist_top_va(VC2));
13271325
}
13281326

1327+
static __always_inline bool vc_from_invalid_context(struct pt_regs *regs)
1328+
{
1329+
unsigned long sp, prev_sp;
1330+
1331+
sp = (unsigned long)regs;
1332+
prev_sp = regs->sp;
1333+
1334+
/*
1335+
* If the code was already executing on the VC2 stack when the #VC
1336+
* happened, let it proceed to the normal handling routine. This way the
1337+
* code executing on the VC2 stack can cause #VC exceptions to get handled.
1338+
*/
1339+
return is_vc2_stack(sp) && !is_vc2_stack(prev_sp);
1340+
}
1341+
13291342
static bool vc_raw_handle_exception(struct pt_regs *regs, unsigned long error_code)
13301343
{
13311344
struct ghcb_state state;
@@ -1406,7 +1419,7 @@ DEFINE_IDTENTRY_VC_KERNEL(exc_vmm_communication)
14061419
* But keep this here in case the noinstr annotations are violated due
14071420
* to bug elsewhere.
14081421
*/
1409-
if (unlikely(on_vc_fallback_stack(regs))) {
1422+
if (unlikely(vc_from_invalid_context(regs))) {
14101423
instrumentation_begin();
14111424
panic("Can't handle #VC exception from unsupported context\n");
14121425
instrumentation_end();

0 commit comments

Comments
 (0)