From: Tom Lendacky <thomas.lendacky@amd.com>
To: Borislav Petkov <bp@alien8.de>, Ard Biesheuvel <ardb@kernel.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>,
oe-kbuild@lists.linux.dev, lkp@intel.com,
oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org,
x86@kernel.org, Ingo Molnar <mingo@kernel.org>
Subject: Re: [tip:x86/boot 10/10] arch/x86/boot/compressed/sev-handle-vc.c:104 do_boot_stage2_vc() error: we previously assumed 'boot_ghcb' could be null (see line 101)
Date: Fri, 12 Sep 2025 13:34:09 -0500 [thread overview]
Message-ID: <77049b07-9e13-4c6a-a7bb-70e9e74a662f@amd.com> (raw)
In-Reply-To: <20250912182642.GCaMRl4nu7R9C8uP6R@fat_crate.local>
On 9/12/25 13:26, Borislav Petkov wrote:
> On Sat, May 10, 2025 at 09:57:23AM +0200, Ard Biesheuvel wrote:
>> The logic is a bit clunky here: for clarity, it could be rewritten as
>>
>> if (!boot_ghcb) {
>> early_setup_ghcb();
>> if (!boot_ghcb)
>> sev_es_terminate(...);
>> }
>
> I like that. Untested patch below:
>
> ---
>
> From: "Borislav Petkov (AMD)" <bp@alien8.de>
> Date: Fri, 12 Sep 2025 20:21:39 +0200
> Subject: [PATCH] x86/sev: Clean up boot_ghcb assignment
>
> Make it more obvious that early_setup_ghcb() assigns the boot_ghcb
> pointer by simply returning it. This way the code becomes a bit
> more readable and comprehensible.
>
> No functional changes intended.
>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Suggested-by: Ard Biesheuvel <ardb@kernel.org>
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
> Link: https://lore.kernel.org/r/202505100719.9pE7wDfB-lkp@intel.com
> ---
> arch/x86/boot/compressed/misc.h | 2 +-
> arch/x86/boot/compressed/sev-handle-vc.c | 5 ++++-
> arch/x86/boot/compressed/sev.c | 11 +++++++----
> 3 files changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
> index db1048621ea2..648f751538de 100644
> --- a/arch/x86/boot/compressed/misc.h
> +++ b/arch/x86/boot/compressed/misc.h
> @@ -150,7 +150,7 @@ void sev_prep_identity_maps(unsigned long top_level_pgt);
> enum es_result vc_decode_insn(struct es_em_ctxt *ctxt);
> bool insn_has_rep_prefix(struct insn *insn);
> void sev_insn_decode_init(void);
> -bool early_setup_ghcb(void);
> +struct ghcb *early_setup_ghcb(void);
> #else
> static inline void sev_enable(struct boot_params *bp)
> {
> diff --git a/arch/x86/boot/compressed/sev-handle-vc.c b/arch/x86/boot/compressed/sev-handle-vc.c
> index 7530ad8b768b..66b29fbb9f57 100644
> --- a/arch/x86/boot/compressed/sev-handle-vc.c
> +++ b/arch/x86/boot/compressed/sev-handle-vc.c
> @@ -101,7 +101,10 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)
> struct es_em_ctxt ctxt;
> enum es_result result;
>
> - if (!boot_ghcb && !early_setup_ghcb())
> + if (!boot_ghcb)
> + boot_ghcb = early_setup_ghcb();
> +
> + if (!boot_ghcb)
> sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);
>
> vc_ghcb_invalidate(boot_ghcb);
> diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c
> index 6e5c32a53d03..f9dcd1b795d7 100644
> --- a/arch/x86/boot/compressed/sev.c
> +++ b/arch/x86/boot/compressed/sev.c
> @@ -75,10 +75,10 @@ void snp_set_page_shared(unsigned long paddr)
> __page_state_change(paddr, paddr, &d);
> }
>
> -bool early_setup_ghcb(void)
> +struct ghcb *early_setup_ghcb(void)
> {
> if (set_page_decrypted((unsigned long)&boot_ghcb_page))
> - return false;
> + return NULL;
>
> /* Page is now mapped decrypted, clear it */
> memset(&boot_ghcb_page, 0, sizeof(boot_ghcb_page));
> @@ -92,7 +92,7 @@ bool early_setup_ghcb(void)
> if (sev_snp_enabled())
> snp_register_ghcb_early(__pa(&boot_ghcb_page));
>
> - return true;
> + return boot_ghcb;
Shouldn't this routine then delete the line that assigns boot_ghcb and
instead return &boot_ghcb_page?
Thanks,
Tom
> }
>
> void snp_accept_memory(phys_addr_t start, phys_addr_t end)
> @@ -216,6 +216,9 @@ void snp_check_features(void)
> {
> u64 unsupported;
>
> + if (!boot_ghcb)
> + boot_ghcb = early_setup_ghcb();
> +
> /*
> * Terminate the boot if hypervisor has enabled any feature lacking
> * guest side implementation. Pass on the unsupported features mask through
> @@ -224,7 +227,7 @@ void snp_check_features(void)
> */
> unsupported = snp_get_unsupported_features(sev_status);
> if (unsupported) {
> - if (ghcb_version < 2 || (!boot_ghcb && !early_setup_ghcb()))
> + if (ghcb_version < 2 || !boot_ghcb)
> sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED);
>
> sev_es_ghcb_terminate(boot_ghcb, SEV_TERM_SET_GEN,
next prev parent reply other threads:[~2025-09-12 18:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-10 7:43 Dan Carpenter
2025-05-10 7:57 ` Ard Biesheuvel
2025-05-10 10:11 ` Dan Carpenter
2025-09-12 18:26 ` Borislav Petkov
2025-09-12 18:34 ` Tom Lendacky [this message]
2025-09-12 18:44 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=77049b07-9e13-4c6a-a7bb-70e9e74a662f@amd.com \
--to=thomas.lendacky@amd.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dan.carpenter@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=mingo@kernel.org \
--cc=oe-kbuild-all@lists.linux.dev \
--cc=oe-kbuild@lists.linux.dev \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®