Skip to content

Commit b250f2f

Browse files
joergroedelsuryasaimadhu
authored andcommitted
x86/sev-es: Don't return NULL from sev_es_get_ghcb()
sev_es_get_ghcb() is called from several places but only one of them checks the return value. The reaction to returning NULL is always the same: calling panic() and kill the machine. Instead of adding checks to all call sites, move the panic() into the function itself so that it will no longer return NULL. Fixes: 0786138 ("x86/sev-es: Add a Runtime #VC Exception Handler") Signed-off-by: Joerg Roedel <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: [email protected] # v5.10+ Link: https://lkml.kernel.org/r/[email protected]
1 parent 0024430 commit b250f2f

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

arch/x86/kernel/sev.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,18 @@ static __always_inline struct ghcb *sev_es_get_ghcb(struct ghcb_state *state)
203203
if (unlikely(data->ghcb_active)) {
204204
/* GHCB is already in use - save its contents */
205205

206-
if (unlikely(data->backup_ghcb_active))
207-
return NULL;
206+
if (unlikely(data->backup_ghcb_active)) {
207+
/*
208+
* Backup-GHCB is also already in use. There is no way
209+
* to continue here so just kill the machine. To make
210+
* panic() work, mark GHCBs inactive so that messages
211+
* can be printed out.
212+
*/
213+
data->ghcb_active = false;
214+
data->backup_ghcb_active = false;
215+
216+
panic("Unable to handle #VC exception! GHCB and Backup GHCB are already in use");
217+
}
208218

209219
/* Mark backup_ghcb active before writing to it */
210220
data->backup_ghcb_active = true;
@@ -1289,7 +1299,6 @@ static __always_inline bool on_vc_fallback_stack(struct pt_regs *regs)
12891299
*/
12901300
DEFINE_IDTENTRY_VC_SAFE_STACK(exc_vmm_communication)
12911301
{
1292-
struct sev_es_runtime_data *data = this_cpu_read(runtime_data);
12931302
irqentry_state_t irq_state;
12941303
struct ghcb_state state;
12951304
struct es_em_ctxt ctxt;
@@ -1315,16 +1324,6 @@ DEFINE_IDTENTRY_VC_SAFE_STACK(exc_vmm_communication)
13151324
*/
13161325

13171326
ghcb = sev_es_get_ghcb(&state);
1318-
if (!ghcb) {
1319-
/*
1320-
* Mark GHCBs inactive so that panic() is able to print the
1321-
* message.
1322-
*/
1323-
data->ghcb_active = false;
1324-
data->backup_ghcb_active = false;
1325-
1326-
panic("Unable to handle #VC exception! GHCB and Backup GHCB are already in use");
1327-
}
13281327

13291328
vc_ghcb_invalidate(ghcb);
13301329
result = vc_init_em_ctxt(&ctxt, regs, error_code);

0 commit comments

Comments
 (0)