x86/sev-es: Invalidate the GHCB after completing VMGEXIT
authorTom Lendacky <thomas.lendacky@amd.com>
Mon, 17 May 2021 17:42:33 +0000 (12:42 -0500)
committerBorislav Petkov <bp@suse.de>
Tue, 18 May 2021 05:06:29 +0000 (07:06 +0200)
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: 0786138c78e79 ("x86/sev-es: Add a Runtime #VC Exception Handler")
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/5a8130462e4f0057ee1184509cd056eedd78742b.1621273353.git.thomas.lendacky@amd.com
arch/x86/kernel/sev-shared.c
arch/x86/kernel/sev.c

index 6ec8b3bfd76ebec3692aa6a37c06fbb395eb9417..9f90f460a28cc0f49b161188933dba804249acdf 100644 (file)
@@ -63,6 +63,7 @@ static bool sev_es_negotiate_protocol(void)
 
 static __always_inline void vc_ghcb_invalidate(struct ghcb *ghcb)
 {
+       ghcb->save.sw_exit_code = 0;
        memset(ghcb->save.valid_bitmap, 0, sizeof(ghcb->save.valid_bitmap));
 }
 
index 45e212675811c958ac5add742fd274cd242a6497..4fa111becc93bc437c1da7cc08f11a026ae7ce9c 100644 (file)
@@ -457,6 +457,11 @@ static __always_inline void sev_es_put_ghcb(struct ghcb_state *state)
                data->backup_ghcb_active = false;
                state->ghcb = NULL;
        } else {
+               /*
+                * Invalidate the GHCB so a VMGEXIT instruction issued
+                * from userspace won't appear to be valid.
+                */
+               vc_ghcb_invalidate(ghcb);
                data->ghcb_active = false;
        }
 }