Skip to content

Commit a50c5be

Browse files
tlendackysuryasaimadhu
authored andcommitted
x86/sev-es: Invalidate the GHCB after completing VMGEXIT
Since the VMGEXIT instruction can be issued from userspace, invalidate the GHCB after performing VMGEXIT processing in the kernel. Invalidation is only required after userspace is available, so call vc_ghcb_invalidate() from sev_es_put_ghcb(). Update vc_ghcb_invalidate() to additionally clear the GHCB exit code so that it is always presented as 0 when VMGEXIT has been issued by anything else besides the kernel. Fixes: 0786138 ("x86/sev-es: Add a Runtime #VC Exception Handler") Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/5a8130462e4f0057ee1184509cd056eedd78742b.1621273353.git.thomas.lendacky@amd.com
1 parent fea63d5 commit a50c5be

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

arch/x86/kernel/sev-shared.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static bool sev_es_negotiate_protocol(void)
6363

6464
static __always_inline void vc_ghcb_invalidate(struct ghcb *ghcb)
6565
{
66+
ghcb->save.sw_exit_code = 0;
6667
memset(ghcb->save.valid_bitmap, 0, sizeof(ghcb->save.valid_bitmap));
6768
}
6869

arch/x86/kernel/sev.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,11 @@ static __always_inline void sev_es_put_ghcb(struct ghcb_state *state)
457457
data->backup_ghcb_active = false;
458458
state->ghcb = NULL;
459459
} else {
460+
/*
461+
* Invalidate the GHCB so a VMGEXIT instruction issued
462+
* from userspace won't appear to be valid.
463+
*/
464+
vc_ghcb_invalidate(ghcb);
460465
data->ghcb_active = false;
461466
}
462467
}

0 commit comments

Comments
 (0)