From: Tom Lendacky <thomas.lendacky@amd.com>
To: Ard Biesheuvel <ardb+git@google.com>, linux-kernel@vger.kernel.org
Cc: linux-efi@vger.kernel.org, x86@kernel.org,
Ard Biesheuvel <ardb@kernel.org>, Borislav Petkov <bp@alien8.de>,
Ingo Molnar <mingo@kernel.org>,
Dionna Amalie Glaze <dionnaglaze@google.com>,
Kevin Loughlin <kevinloughlin@google.com>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH v4 07/24] x86/sev: Move MSR save/restore out of early page state change helper
Date: Wed, 9 Jul 2025 13:16:18 -0500 [thread overview]
Message-ID: <80710331-7dd5-ac7c-5013-3f198e9fd72f@amd.com> (raw)
In-Reply-To: <20250709080840.2233208-33-ardb+git@google.com>
On 7/9/25 03:08, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <ardb@kernel.org>
>
> The function __page_state_change() in the decompressor is very similar
> to the loop in early_set_pages_state(), and they can share this code
> once the MSR save/restore is moved out.
>
> This also avoids doing the preserve/restore for each page in a longer
> sequence unnecessarily.
>
> This simplifies subsequent changes, where the APIs used by
> __page_state_change() are modified for better separation between startup
> code and ordinary code.
The reason for the calls being in __page_state_change() is because of
the call to pavalidate_4k_page(). If that code path is ever changed to
cause a #VC, then the GHCB MSR will be messed up when the UEFI #VC
handler gets control and will be an issue.
Thanks,
Tom
>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> arch/x86/boot/compressed/sev.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c
> index 6c0f91d38595..f00f68175f14 100644
> --- a/arch/x86/boot/compressed/sev.c
> +++ b/arch/x86/boot/compressed/sev.c
> @@ -71,9 +71,6 @@ static void __page_state_change(unsigned long paddr, enum psc_op op)
> if (op == SNP_PAGE_STATE_SHARED)
> pvalidate_4k_page(paddr, paddr, false);
>
> - /* Save the current GHCB MSR value */
> - msr = sev_es_rd_ghcb_msr();
> -
> /* Issue VMGEXIT to change the page state in RMP table. */
> sev_es_wr_ghcb_msr(GHCB_MSR_PSC_REQ_GFN(paddr >> PAGE_SHIFT, op));
> VMGEXIT();
> @@ -83,9 +80,6 @@ static void __page_state_change(unsigned long paddr, enum psc_op op)
> if ((GHCB_RESP_CODE(val) != GHCB_MSR_PSC_RESP) || GHCB_MSR_PSC_RESP_VAL(val))
> sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC);
>
> - /* Restore the GHCB MSR value */
> - sev_es_wr_ghcb_msr(msr);
> -
> /*
> * Now that page state is changed in the RMP table, validate it so that it is
> * consistent with the RMP entry.
> @@ -96,18 +90,26 @@ static void __page_state_change(unsigned long paddr, enum psc_op op)
>
> void snp_set_page_private(unsigned long paddr)
> {
> + u64 msr;
> +
> if (!sev_snp_enabled())
> return;
>
> + msr = sev_es_rd_ghcb_msr();
> __page_state_change(paddr, SNP_PAGE_STATE_PRIVATE);
> + sev_es_wr_ghcb_msr(msr);
> }
>
> void snp_set_page_shared(unsigned long paddr)
> {
> + u64 msr;
> +
> if (!sev_snp_enabled())
> return;
>
> + msr = sev_es_rd_ghcb_msr();
> __page_state_change(paddr, SNP_PAGE_STATE_SHARED);
> + sev_es_wr_ghcb_msr(msr);
> }
>
> bool early_setup_ghcb(void)
> @@ -132,8 +134,11 @@ bool early_setup_ghcb(void)
>
> void snp_accept_memory(phys_addr_t start, phys_addr_t end)
> {
> + u64 msr = sev_es_rd_ghcb_msr();
> +
> for (phys_addr_t pa = start; pa < end; pa += PAGE_SIZE)
> __page_state_change(pa, SNP_PAGE_STATE_PRIVATE);
> + sev_es_wr_ghcb_msr(msr);
> }
>
> void sev_es_shutdown_ghcb(void)
next prev parent reply other threads:[~2025-07-09 18:16 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-09 8:08 [PATCH v4 00/24] x86: strict separation of startup code Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 01/24] x86/sev: Separate MSR and GHCB based snp_cpuid() via a callback Ard Biesheuvel
2025-07-09 15:12 ` Tom Lendacky
2025-07-09 23:21 ` Ard Biesheuvel
2025-07-11 20:59 ` Borislav Petkov
2025-07-12 14:54 ` Tom Lendacky
2025-07-12 15:02 ` Borislav Petkov
2025-07-09 8:08 ` [PATCH v4 02/24] x86/sev: Use MSR protocol for remapping SVSM calling area Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 03/24] x86/sev: Use MSR protocol only for early SVSM PVALIDATE call Ard Biesheuvel
2025-07-09 15:50 ` Tom Lendacky
2025-07-09 8:08 ` [PATCH v4 04/24] x86/sev: Run RMPADJUST on SVSM calling area page to test VMPL Ard Biesheuvel
2025-07-09 16:13 ` Tom Lendacky
2025-07-09 8:08 ` [PATCH v4 05/24] x86/sev: Move GHCB page based HV communication out of startup code Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 06/24] x86/sev: Avoid global variable to store virtual address of SVSM area Ard Biesheuvel
2025-07-09 17:49 ` Tom Lendacky
2025-07-09 8:08 ` [PATCH v4 07/24] x86/sev: Move MSR save/restore out of early page state change helper Ard Biesheuvel
2025-07-09 18:16 ` Tom Lendacky [this message]
2025-07-09 8:08 ` [PATCH v4 08/24] x86/sev: Share implementation of MSR-based page state change Ard Biesheuvel
2025-07-09 18:24 ` Tom Lendacky
2025-07-15 5:09 ` Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 09/24] x86/sev: Pass SVSM calling area down to early page state change API Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 10/24] x86/sev: Use boot SVSM CA for all startup and init code Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 11/24] x86/boot: Drop redundant RMPADJUST in SEV SVSM presence check Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 12/24] x86/sev: Unify SEV-SNP hypervisor feature check Ard Biesheuvel
2025-07-10 4:21 ` Nikunj A Dadhania
2025-07-10 4:24 ` Ard Biesheuvel
[not found] ` <85o6tsv8m2.fsf@amd.com>
2025-07-10 7:36 ` Ard Biesheuvel
2025-07-10 8:02 ` Nikunj A Dadhania
2025-07-09 8:08 ` [PATCH v4 13/24] x86/boot: Provide PIC aliases for 5-level paging related constants Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 14/24] x86/sev: Provide PIC aliases for SEV related data objects Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 15/24] x86/sev: Move __sev_[get|put]_ghcb() into separate noinstr object Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 16/24] x86/sev: Export startup routines for later use Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 17/24] objtool: Add action to check for absence of absolute relocations Ard Biesheuvel
2025-07-09 8:08 ` [PATCH v4 18/24] x86/boot: Check startup code " Ard Biesheuvel
2025-07-09 8:09 ` [PATCH v4 19/24] x86/boot: Revert "Reject absolute references in .head.text" Ard Biesheuvel
2025-07-09 8:09 ` [PATCH v4 20/24] x86/kbuild: Incorporate boot/startup/ via Kbuild makefile Ard Biesheuvel
2025-07-09 8:09 ` [PATCH v4 21/24] x86/boot: Create a confined code area for startup code Ard Biesheuvel
2025-07-09 8:09 ` [PATCH v4 22/24] efistub/x86: Remap inittext read-execute when needed Ard Biesheuvel
2025-07-09 8:09 ` [PATCH v4 23/24] x86/boot: Move startup code out of __head section Ard Biesheuvel
2025-07-09 8:09 ` [PATCH v4 24/24] x86/boot: Get rid of the .head.text section Ard Biesheuvel
2025-07-09 10:23 ` [PATCH v4 00/24] x86: strict separation of startup code Kirill A. Shutemov
2025-07-09 10:32 ` Ard Biesheuvel
2025-07-09 14:01 ` Nikunj A Dadhania
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=80710331-7dd5-ac7c-5013-3f198e9fd72f@amd.com \
--to=thomas.lendacky@amd.com \
--cc=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dionnaglaze@google.com \
--cc=jpoimboe@kernel.org \
--cc=kevinloughlin@google.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--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;
as well as URLs for NNTP newsgroup(s).