]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/sev: Remove redundant ghcbs_initialized checks around __sev_{get,put}_ghcb()
authorNikunj A Dadhania <nikunj@amd.com>
Mon, 18 May 2026 10:22:30 +0000 (10:22 +0000)
committerBorislav Petkov (AMD) <bp@alien8.de>
Tue, 19 May 2026 20:31:29 +0000 (13:31 -0700)
After

  3645eb7e3915 ("x86/fred: Fix early boot failures on SEV-ES/SNP guests"),

__sev_{get,put}_ghcb() handle the early-boot GHCB fallback internally, making
the ghcbs_initialized guards in __set_pages_state() and
svsm_perform_call_protocol() redundant.

Remove them.

Also initialize state->ghcb to NULL in the early-boot path of
__sev_get_ghcb() so that the ghcb_state is well-defined for all callers,
even though __sev_put_ghcb() currently returns early before reading it.

No functional change intended.

Suggested-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Link: https://patch.msgid.link/20260518102230.3394603-1-nikunj@amd.com
arch/x86/coco/sev/core.c
arch/x86/coco/sev/noinstr.c
arch/x86/coco/sev/svsm.c

index 7ed3da998489d9e08afb84f540aecd1ef7300008..ecd77d3217f3c3a08e3731a6cfdba472c97fed60 100644 (file)
@@ -367,17 +367,13 @@ static unsigned long __set_pages_state(struct snp_psc_desc *data, unsigned long
 
        local_irq_save(flags);
 
-       if (sev_cfg.ghcbs_initialized)
-               ghcb = __sev_get_ghcb(&state);
-       else
-               ghcb = boot_ghcb;
+       ghcb = __sev_get_ghcb(&state);
 
        /* Invoke the hypervisor to perform the page state changes */
        if (!ghcb || vmgexit_psc(ghcb, data))
                sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC);
 
-       if (sev_cfg.ghcbs_initialized)
-               __sev_put_ghcb(&state);
+       __sev_put_ghcb(&state);
 
        local_irq_restore(flags);
 
index 5afd663a1c217aca9d15c168f5a049fff55c49ca..e1e03f12fc7bb0ed38dc53f86f958a1a1655f179 100644 (file)
@@ -121,8 +121,10 @@ noinstr struct ghcb *__sev_get_ghcb(struct ghcb_state *state)
 
        WARN_ON(!irqs_disabled());
 
-       if (!sev_cfg.ghcbs_initialized)
+       if (!sev_cfg.ghcbs_initialized) {
+               state->ghcb = NULL;
                return boot_ghcb;
+       }
 
        data = this_cpu_read(runtime_data);
        ghcb = &data->ghcb_page;
index 2acf4a76afe7a99bf20d8e83f9d573da8f115f59..916d62cd17dc70ba2cb6b3475d69d4494bb03804 100644 (file)
@@ -74,20 +74,14 @@ int svsm_perform_call_protocol(struct svsm_call *call)
 
        flags = native_local_irq_save();
 
-       if (sev_cfg.ghcbs_initialized)
-               ghcb = __sev_get_ghcb(&state);
-       else if (boot_ghcb)
-               ghcb = boot_ghcb;
-       else
-               ghcb = NULL;
+       ghcb = __sev_get_ghcb(&state);
 
        do {
                ret = ghcb ? svsm_perform_ghcb_protocol(ghcb, call)
                           : __pi_svsm_perform_msr_protocol(call);
        } while (ret == -EAGAIN);
 
-       if (sev_cfg.ghcbs_initialized)
-               __sev_put_ghcb(&state);
+       __sev_put_ghcb(&state);
 
        native_local_irq_restore(flags);