* [PATCH] x86/boot/sev: Move SEV decompressor variables into the .data section
@ 2026-02-04 15:01 Tom Lendacky
2026-02-04 15:54 ` Ard Biesheuvel
2026-02-26 19:16 ` Changyuan Lyu
0 siblings, 2 replies; 7+ messages in thread
From: Tom Lendacky @ 2026-02-04 15:01 UTC (permalink / raw)
To: linux-kernel, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
stable, Ard Biesheuvel, Kevin Hui
As part of the work to remove the dependency on calling into the
decompressor code (startup_64()) for a UEFI boot, a call to rmpadjust()
was removed from sev_enable() in favor of checking the value of the
snp_vmpl variable. When booting through a non-UEFI path and calling
startup_64(), the call to sev_enable() is performed before the BSS section
is zeroed. With the removal of the rmpadjust() call and the corresponding
check of the return code, the snp_vmpl variable is checked. Since the
kernel is running at VMPL0, the snp_vmpl variable will not have been set
and should be the default value of 0. However, since the call occurs
before the BSS is zeroed, the snp_vmpl variable may not actually be zero,
which will cause the guest boot to fail.
Since the decompressor relocates itself, the BSS would need to be cleared
both before and after the relocation, but this would, in effect, cause all
of the changes to BSS variables before relocation to be lost after
relocation.
Instead, move the snp_vmpl variable into the .data section so that it is
initialized and the value made safe during relocation. As a pre-caution
against future changes, move other SEV-related decompressor variables into
the .data section, too.
Fixes: 68a501d7fd82 ("x86/boot: Drop redundant RMPADJUST in SEV SVSM presence check")
Cc: stable@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>
Tested-by: Kevin Hui <kevinhui@meta.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
arch/x86/boot/compressed/sev.c | 8 ++++----
arch/x86/boot/startup/sev-shared.c | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c
index c8c1464b3a56..46b54720d91d 100644
--- a/arch/x86/boot/compressed/sev.c
+++ b/arch/x86/boot/compressed/sev.c
@@ -28,17 +28,17 @@
#include "sev.h"
static struct ghcb boot_ghcb_page __aligned(PAGE_SIZE);
-struct ghcb *boot_ghcb;
+struct ghcb *boot_ghcb __section(".data");
#undef __init
#define __init
#define __BOOT_COMPRESSED
-u8 snp_vmpl;
-u16 ghcb_version;
+u8 snp_vmpl __section(".data");
+u16 ghcb_version __section(".data");
-u64 boot_svsm_caa_pa;
+u64 boot_svsm_caa_pa __section(".data");
/* Include code for early handlers */
#include "../../boot/startup/sev-shared.c"
diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev-shared.c
index a0fa8bb2b945..d9ac3a929d33 100644
--- a/arch/x86/boot/startup/sev-shared.c
+++ b/arch/x86/boot/startup/sev-shared.c
@@ -31,7 +31,7 @@ static u32 cpuid_std_range_max __ro_after_init;
static u32 cpuid_hyp_range_max __ro_after_init;
static u32 cpuid_ext_range_max __ro_after_init;
-bool sev_snp_needs_sfw;
+bool sev_snp_needs_sfw __section(".data");
void __noreturn
sev_es_terminate(unsigned int set, unsigned int reason)
base-commit: 659e9d68ebea99eb9010d4f5756a3853c04dd6ce
--
2.51.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/boot/sev: Move SEV decompressor variables into the .data section
2026-02-04 15:01 [PATCH] x86/boot/sev: Move SEV decompressor variables into the .data section Tom Lendacky
@ 2026-02-04 15:54 ` Ard Biesheuvel
2026-02-26 19:16 ` Changyuan Lyu
1 sibling, 0 replies; 7+ messages in thread
From: Ard Biesheuvel @ 2026-02-04 15:54 UTC (permalink / raw)
To: Tom Lendacky, linux-kernel, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
stable, Kevin Hui
On Wed, 4 Feb 2026, at 16:01, Tom Lendacky wrote:
> As part of the work to remove the dependency on calling into the
> decompressor code (startup_64()) for a UEFI boot, a call to rmpadjust()
> was removed from sev_enable() in favor of checking the value of the
> snp_vmpl variable. When booting through a non-UEFI path and calling
> startup_64(), the call to sev_enable() is performed before the BSS section
> is zeroed. With the removal of the rmpadjust() call and the corresponding
> check of the return code, the snp_vmpl variable is checked. Since the
> kernel is running at VMPL0, the snp_vmpl variable will not have been set
> and should be the default value of 0. However, since the call occurs
> before the BSS is zeroed, the snp_vmpl variable may not actually be zero,
> which will cause the guest boot to fail.
>
> Since the decompressor relocates itself, the BSS would need to be cleared
> both before and after the relocation, but this would, in effect, cause all
> of the changes to BSS variables before relocation to be lost after
> relocation.
>
> Instead, move the snp_vmpl variable into the .data section so that it is
> initialized and the value made safe during relocation. As a pre-caution
> against future changes, move other SEV-related decompressor variables into
> the .data section, too.
>
> Fixes: 68a501d7fd82 ("x86/boot: Drop redundant RMPADJUST in SEV SVSM
> presence check")
> Cc: stable@vger.kernel.org
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Tested-by: Kevin Hui <kevinhui@meta.com>
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/boot/sev: Move SEV decompressor variables into the .data section
2026-02-04 15:01 [PATCH] x86/boot/sev: Move SEV decompressor variables into the .data section Tom Lendacky
2026-02-04 15:54 ` Ard Biesheuvel
@ 2026-02-26 19:16 ` Changyuan Lyu
2026-02-26 19:22 ` Borislav Petkov
1 sibling, 1 reply; 7+ messages in thread
From: Changyuan Lyu @ 2026-02-26 19:16 UTC (permalink / raw)
To: thomas.lendacky
Cc: ardb, bp, dave.hansen, kevinhui, linux-kernel, mingo, stable,
tglx, x86, Changyuan Lyu
On Wed, 4 Feb 2026 09:01:00 -0600, Tom Lendacky <thomas.lendacky@amd.com> wrote
> As part of the work to remove the dependency on calling into the
> decompressor code (startup_64()) for a UEFI boot, a call to rmpadjust()
> was removed from sev_enable() in favor of checking the value of the
> snp_vmpl variable. When booting through a non-UEFI path and calling
> startup_64(), the call to sev_enable() is performed before the BSS section
> is zeroed. With the removal of the rmpadjust() call and the corresponding
> check of the return code, the snp_vmpl variable is checked. Since the
> kernel is running at VMPL0, the snp_vmpl variable will not have been set
> and should be the default value of 0. However, since the call occurs
> before the BSS is zeroed, the snp_vmpl variable may not actually be zero,
> which will cause the guest boot to fail.
>
> Since the decompressor relocates itself, the BSS would need to be cleared
> both before and after the relocation, but this would, in effect, cause all
> of the changes to BSS variables before relocation to be lost after
> relocation.
>
> Instead, move the snp_vmpl variable into the .data section so that it is
> initialized and the value made safe during relocation. As a pre-caution
> against future changes, move other SEV-related decompressor variables into
> the .data section, too.
>
> Fixes: 68a501d7fd82 ("x86/boot: Drop redundant RMPADJUST in SEV SVSM presence check")
> Cc: stable@vger.kernel.org
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Tested-by: Kevin Hui <kevinhui@meta.com>
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Changyuan Lyu <changyuanl@google.com>
> [...]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/boot/sev: Move SEV decompressor variables into the .data section
2026-02-26 19:16 ` Changyuan Lyu
@ 2026-02-26 19:22 ` Borislav Petkov
2026-02-26 19:29 ` Changyuan Lyu
0 siblings, 1 reply; 7+ messages in thread
From: Borislav Petkov @ 2026-02-26 19:22 UTC (permalink / raw)
To: Changyuan Lyu, thomas.lendacky
Cc: ardb, dave.hansen, kevinhui, linux-kernel, mingo, stable, tglx, x86
On February 26, 2026 7:16:11 PM UTC, Changyuan Lyu <changyuanl@google.com> wrote:
>On Wed, 4 Feb 2026 09:01:00 -0600, Tom Lendacky <thomas.lendacky@amd.com> wrote
>> As part of the work to remove the dependency on calling into the
>> decompressor code (startup_64()) for a UEFI boot, a call to rmpadjust()
>> was removed from sev_enable() in favor of checking the value of the
>> snp_vmpl variable. When booting through a non-UEFI path and calling
>> startup_64(), the call to sev_enable() is performed before the BSS section
>> is zeroed. With the removal of the rmpadjust() call and the corresponding
>> check of the return code, the snp_vmpl variable is checked. Since the
>> kernel is running at VMPL0, the snp_vmpl variable will not have been set
>> and should be the default value of 0. However, since the call occurs
>> before the BSS is zeroed, the snp_vmpl variable may not actually be zero,
>> which will cause the guest boot to fail.
>>
>> Since the decompressor relocates itself, the BSS would need to be cleared
>> both before and after the relocation, but this would, in effect, cause all
>> of the changes to BSS variables before relocation to be lost after
>> relocation.
>>
>> Instead, move the snp_vmpl variable into the .data section so that it is
>> initialized and the value made safe during relocation. As a pre-caution
>> against future changes, move other SEV-related decompressor variables into
>> the .data section, too.
>>
>> Fixes: 68a501d7fd82 ("x86/boot: Drop redundant RMPADJUST in SEV SVSM presence check")
>> Cc: stable@vger.kernel.org
>> Cc: Ard Biesheuvel <ardb@kernel.org>
>> Tested-by: Kevin Hui <kevinhui@meta.com>
>> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
>
>Reviewed-by: Changyuan Lyu <changyuanl@google.com>
>
>> [...]
Did you test it too to make sure it fixes your issue?
--
Small device. Typos and formatting crap
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/boot/sev: Move SEV decompressor variables into the .data section
2026-02-26 19:22 ` Borislav Petkov
@ 2026-02-26 19:29 ` Changyuan Lyu
2026-02-26 19:38 ` Borislav Petkov
0 siblings, 1 reply; 7+ messages in thread
From: Changyuan Lyu @ 2026-02-26 19:29 UTC (permalink / raw)
To: Borislav Petkov
Cc: thomas.lendacky, ardb, dave.hansen, kevinhui, linux-kernel,
mingo, stable, tglx, x86
On Thu, Feb 26, 2026 at 11:22 AM Borislav Petkov <bp@alien8.de> wrote:
>
> On February 26, 2026 7:16:11 PM UTC, Changyuan Lyu <changyuanl@google.com> wrote:
> >On Wed, 4 Feb 2026 09:01:00 -0600, Tom Lendacky <thomas.lendacky@amd.com> wrote
> >> As part of the work to remove the dependency on calling into the
> >> decompressor code (startup_64()) for a UEFI boot, a call to rmpadjust()
> >> was removed from sev_enable() in favor of checking the value of the
> >> snp_vmpl variable. When booting through a non-UEFI path and calling
> >> startup_64(), the call to sev_enable() is performed before the BSS section
> >> is zeroed. With the removal of the rmpadjust() call and the corresponding
> >> check of the return code, the snp_vmpl variable is checked. Since the
> >> kernel is running at VMPL0, the snp_vmpl variable will not have been set
> >> and should be the default value of 0. However, since the call occurs
> >> before the BSS is zeroed, the snp_vmpl variable may not actually be zero,
> >> which will cause the guest boot to fail.
> >>
> >> Since the decompressor relocates itself, the BSS would need to be cleared
> >> both before and after the relocation, but this would, in effect, cause all
> >> of the changes to BSS variables before relocation to be lost after
> >> relocation.
> >>
> >> Instead, move the snp_vmpl variable into the .data section so that it is
> >> initialized and the value made safe during relocation. As a pre-caution
> >> against future changes, move other SEV-related decompressor variables into
> >> the .data section, too.
> >>
> >> Fixes: 68a501d7fd82 ("x86/boot: Drop redundant RMPADJUST in SEV SVSM presence check")
> >> Cc: stable@vger.kernel.org
> >> Cc: Ard Biesheuvel <ardb@kernel.org>
> >> Tested-by: Kevin Hui <kevinhui@meta.com>
> >> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> >
> >Reviewed-by: Changyuan Lyu <changyuanl@google.com>
> >
> >> [...]
>
> Did you test it too to make sure it fixes your issue?
Hi Borislav,
I rebased this patch to e3c81bae4f282a6be56bc22e05e2ce3dd92ae301
and tested with the steps in
https://lore.kernel.org/all/20260226060714.1636773-1-changyuanl@google.com/.
This fix works for my use case (direct kernel boot without UEFI).
Tested-by: Changyuan Lyu <changyuanl@google.com>
Best
Changyuan
> Small device. Typos and formatting crap
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/boot/sev: Move SEV decompressor variables into the .data section
2026-02-26 19:29 ` Changyuan Lyu
@ 2026-02-26 19:38 ` Borislav Petkov
2026-02-27 20:55 ` Borislav Petkov
0 siblings, 1 reply; 7+ messages in thread
From: Borislav Petkov @ 2026-02-26 19:38 UTC (permalink / raw)
To: Changyuan Lyu
Cc: thomas.lendacky, ardb, dave.hansen, kevinhui, linux-kernel,
mingo, stable, tglx, x86
On February 26, 2026 7:29:56 PM UTC, Changyuan Lyu <changyuanl@google.com> wrote:
>
>I rebased this patch to e3c81bae4f282a6be56bc22e05e2ce3dd92ae301
>and tested with the steps in
>https://lore.kernel.org/all/20260226060714.1636773-1-changyuanl@google.com/.
>This fix works for my use case (direct kernel boot without UEFI).
>
>Tested-by: Changyuan Lyu <changyuanl@google.com>
Thanks.
--
Small device. Typos and formatting crap
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/boot/sev: Move SEV decompressor variables into the .data section
2026-02-26 19:38 ` Borislav Petkov
@ 2026-02-27 20:55 ` Borislav Petkov
0 siblings, 0 replies; 7+ messages in thread
From: Borislav Petkov @ 2026-02-27 20:55 UTC (permalink / raw)
To: Changyuan Lyu
Cc: thomas.lendacky, ardb, dave.hansen, kevinhui, linux-kernel,
mingo, stable, tglx, x86
On Thu, Feb 26, 2026 at 07:38:44PM +0000, Borislav Petkov wrote:
> On February 26, 2026 7:29:56 PM UTC, Changyuan Lyu <changyuanl@google.com> wrote:
> >
> >I rebased this patch to e3c81bae4f282a6be56bc22e05e2ce3dd92ae301
> >and tested with the steps in
> >https://lore.kernel.org/all/20260226060714.1636773-1-changyuanl@google.com/.
> >This fix works for my use case (direct kernel boot without UEFI).
> >
> >Tested-by: Changyuan Lyu <changyuanl@google.com>
>
> Thanks.
Seems to work here too. Will queue next week.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-02-27 20:55 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-04 15:01 [PATCH] x86/boot/sev: Move SEV decompressor variables into the .data section Tom Lendacky
2026-02-04 15:54 ` Ard Biesheuvel
2026-02-26 19:16 ` Changyuan Lyu
2026-02-26 19:22 ` Borislav Petkov
2026-02-26 19:29 ` Changyuan Lyu
2026-02-26 19:38 ` Borislav Petkov
2026-02-27 20:55 ` Borislav Petkov
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®