Skip to content

Commit 6c0f74d

Browse files
codomaniasuryasaimadhu
authored andcommitted
x86/sev: Define the Linux-specific guest termination reasons
The GHCB specification defines the reason code for reason set 0. The reason codes defined in the set 0 do not cover all possible causes for a guest to request termination. The reason sets 1 to 255 are reserved for the vendor-specific codes. Reserve the reason set 1 for the Linux guest. Define the error codes for reason set 1 so that one can have meaningful termination reasons and thus better guest failure diagnosis. While at it, change sev_es_terminate() to accept a reason set parameter. [ bp: Massage commit message. ] Signed-off-by: Brijesh Singh <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Venu Busireddy <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f742b90 commit 6c0f74d

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

arch/x86/boot/compressed/sev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,
119119
static bool early_setup_sev_es(void)
120120
{
121121
if (!sev_es_negotiate_protocol())
122-
sev_es_terminate(GHCB_SEV_ES_PROT_UNSUPPORTED);
122+
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_PROT_UNSUPPORTED);
123123

124124
if (set_page_decrypted((unsigned long)&boot_ghcb_page))
125125
return false;
@@ -172,7 +172,7 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)
172172
enum es_result result;
173173

174174
if (!boot_ghcb && !early_setup_sev_es())
175-
sev_es_terminate(GHCB_SEV_ES_GEN_REQ);
175+
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);
176176

177177
vc_ghcb_invalidate(boot_ghcb);
178178
result = vc_init_em_ctxt(&ctxt, regs, exit_code);
@@ -199,7 +199,7 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)
199199
if (result == ES_OK)
200200
vc_finish_insn(&ctxt);
201201
else if (result != ES_RETRY)
202-
sev_es_terminate(GHCB_SEV_ES_GEN_REQ);
202+
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);
203203
}
204204

205205
void sev_enable(struct boot_params *bp)

arch/x86/include/asm/sev-common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,17 @@
7373
/* GHCBData[23:16] */ \
7474
((((u64)reason_val) & 0xff) << 16))
7575

76+
/* Error codes from reason set 0 */
77+
#define SEV_TERM_SET_GEN 0
7678
#define GHCB_SEV_ES_GEN_REQ 0
7779
#define GHCB_SEV_ES_PROT_UNSUPPORTED 1
7880

81+
/* Linux-specific reason codes (used with reason set 1) */
82+
#define SEV_TERM_SET_LINUX 1
83+
#define GHCB_TERM_REGISTER 0 /* GHCB GPA registration failure */
84+
#define GHCB_TERM_PSC 1 /* Page State Change failure */
85+
#define GHCB_TERM_PVALIDATE 2 /* Pvalidate failure */
86+
7987
#define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK)
8088

8189
/*

arch/x86/kernel/sev-shared.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@ static bool __init sev_es_check_cpu_features(void)
2424
return true;
2525
}
2626

27-
static void __noreturn sev_es_terminate(unsigned int reason)
27+
static void __noreturn sev_es_terminate(unsigned int set, unsigned int reason)
2828
{
2929
u64 val = GHCB_MSR_TERM_REQ;
3030

31-
/*
32-
* Tell the hypervisor what went wrong - only reason-set 0 is
33-
* currently supported.
34-
*/
35-
val |= GHCB_SEV_TERM_REASON(0, reason);
31+
/* Tell the hypervisor what went wrong. */
32+
val |= GHCB_SEV_TERM_REASON(set, reason);
3633

3734
/* Request Guest Termination from Hypvervisor */
3835
sev_es_wr_ghcb_msr(val);
@@ -221,7 +218,7 @@ void __init do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code)
221218

222219
fail:
223220
/* Terminate the guest */
224-
sev_es_terminate(GHCB_SEV_ES_GEN_REQ);
221+
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);
225222
}
226223

227224
static enum es_result vc_insn_string_read(struct es_em_ctxt *ctxt,

arch/x86/kernel/sev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ DEFINE_IDTENTRY_VC_KERNEL(exc_vmm_communication)
13371337
show_regs(regs);
13381338

13391339
/* Ask hypervisor to sev_es_terminate */
1340-
sev_es_terminate(GHCB_SEV_ES_GEN_REQ);
1340+
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);
13411341

13421342
/* If that fails and we get here - just panic */
13431343
panic("Returned from Terminate-Request to Hypervisor\n");
@@ -1385,7 +1385,7 @@ bool __init handle_vc_boot_ghcb(struct pt_regs *regs)
13851385

13861386
/* Do initial setup or terminate the guest */
13871387
if (unlikely(boot_ghcb == NULL && !sev_es_setup_ghcb()))
1388-
sev_es_terminate(GHCB_SEV_ES_GEN_REQ);
1388+
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);
13891389

13901390
vc_ghcb_invalidate(boot_ghcb);
13911391

0 commit comments

Comments
 (0)