Message ID | 174448976513.31282.4012948519562214371.tip-bot2@tip-bot2 |
---|---|
State | New |
Headers | show |
Series | [tip:,x86/boot] x86/boot/sev: Avoid shared GHCB page for early memory acceptance | expand |
On Sat, 12 Apr 2025 at 22:29, tip-bot2 for Ard Biesheuvel <tip-bot2@linutronix.de> wrote: > > The following commit has been merged into the x86/boot branch of tip: > This may be slightly premature. I took some of Tom's code, hence the co-developed-by, but the should really confirm that what I did is correct before we queue this up.
* Ard Biesheuvel <ardb@kernel.org> wrote: > On Sat, 12 Apr 2025 at 22:29, tip-bot2 for Ard Biesheuvel > <tip-bot2@linutronix.de> wrote: > > > > The following commit has been merged into the x86/boot branch of tip: > > > > This may be slightly premature. I took some of Tom's code, hence the > co-developed-by, but the should really confirm that what I did is > correct before we queue this up. OK, I've zapped it again, especially as the rest of the series wasn't ready either, please include the latest version of this patch as part of the boot/setup/ series, which hard-relies upon it. Thanks, Ingo
On Sat, 12 Apr 2025 at 22:45, Ingo Molnar <mingo@kernel.org> wrote: > > > * Ard Biesheuvel <ardb@kernel.org> wrote: > > > On Sat, 12 Apr 2025 at 22:29, tip-bot2 for Ard Biesheuvel > > <tip-bot2@linutronix.de> wrote: > > > > > > The following commit has been merged into the x86/boot branch of tip: > > > > > > > This may be slightly premature. I took some of Tom's code, hence the > > co-developed-by, but the should really confirm that what I did is > > correct before we queue this up. > > OK, I've zapped it again, especially as the rest of the series wasn't > ready either, please include the latest version of this patch as part > of the boot/setup/ series, which hard-relies upon it. > OK
* Ard Biesheuvel <ardb@kernel.org> wrote: > On Sat, 12 Apr 2025 at 22:45, Ingo Molnar <mingo@kernel.org> wrote: > > > > > > * Ard Biesheuvel <ardb@kernel.org> wrote: > > > > > On Sat, 12 Apr 2025 at 22:29, tip-bot2 for Ard Biesheuvel > > > <tip-bot2@linutronix.de> wrote: > > > > > > > > The following commit has been merged into the x86/boot branch of tip: > > > > > > > > > > This may be slightly premature. I took some of Tom's code, hence the > > > co-developed-by, but the should really confirm that what I did is > > > correct before we queue this up. > > > > OK, I've zapped it again, especially as the rest of the series wasn't > > ready either, please include the latest version of this patch as part > > of the boot/setup/ series, which hard-relies upon it. > > > > I have sent out a v4 here [0]. > > I am not including it in the next rev of the startup/ refactor series, > given that this change is a fix that also needs to go to stable. > Please apply it as a fix and merge back the branch into tip/x86/boot - > I will rebase the startup/ refactor series on top of that. > > Thanks, > > [0] https://lore.kernel.org/linux-efi/20250417202120.1002102-2-ardb+git@google.com/T/#u Noted, thanks for the heads up! Ingo
* Ingo Molnar <mingo@kernel.org> wrote: > > * Ard Biesheuvel <ardb@kernel.org> wrote: > > > On Sat, 12 Apr 2025 at 22:45, Ingo Molnar <mingo@kernel.org> wrote: > > > > > > > > > * Ard Biesheuvel <ardb@kernel.org> wrote: > > > > > > > On Sat, 12 Apr 2025 at 22:29, tip-bot2 for Ard Biesheuvel > > > > <tip-bot2@linutronix.de> wrote: > > > > > > > > > > The following commit has been merged into the x86/boot branch of tip: > > > > > > > > > > > > > This may be slightly premature. I took some of Tom's code, hence the > > > > co-developed-by, but the should really confirm that what I did is > > > > correct before we queue this up. > > > > > > OK, I've zapped it again, especially as the rest of the series wasn't > > > ready either, please include the latest version of this patch as part > > > of the boot/setup/ series, which hard-relies upon it. > > > > > > > I have sent out a v4 here [0]. > > > > I am not including it in the next rev of the startup/ refactor series, > > given that this change is a fix that also needs to go to stable. > > Please apply it as a fix and merge back the branch into tip/x86/boot - > > I will rebase the startup/ refactor series on top of that. > > > > Thanks, > > > > [0] https://lore.kernel.org/linux-efi/20250417202120.1002102-2-ardb+git@google.com/T/#u > > Noted, thanks for the heads up! So there's this new merge commit in tip:x86/boot: 54f71aa90c84 Merge branch 'x86/urgent' into x86/boot, to merge dependent commit and fixes which brings this fix into x86/boot: a718833cb456 ("x86/boot/sev: Avoid shared GHCB page for early memory acceptance") thus 54f71aa90c84 should be a proper base the rest of the startup/ series, right? Thanks, Ingo
On Fri, 18 Apr 2025 at 10:14, Ingo Molnar <mingo@kernel.org> wrote: > > > * Ingo Molnar <mingo@kernel.org> wrote: > ... > > So there's this new merge commit in tip:x86/boot: > > 54f71aa90c84 Merge branch 'x86/urgent' into x86/boot, to merge dependent commit and fixes > > which brings this fix into x86/boot: > > a718833cb456 ("x86/boot/sev: Avoid shared GHCB page for early memory acceptance") > > thus 54f71aa90c84 should be a proper base the rest of the startup/ > series, right? > Yes, perfect. Thanks.
diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 6eadd79..478eca4 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -169,10 +169,7 @@ bool sev_snp_enabled(void) static void __page_state_change(unsigned long paddr, enum psc_op op) { - u64 val; - - if (!sev_snp_enabled()) - return; + u64 val, msr; /* * If private -> shared then invalidate the page before requesting the @@ -181,6 +178,9 @@ 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(); @@ -190,6 +190,9 @@ 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. @@ -200,11 +203,17 @@ static void __page_state_change(unsigned long paddr, enum psc_op op) void snp_set_page_private(unsigned long paddr) { + if (!sev_snp_enabled()) + return; + __page_state_change(paddr, SNP_PAGE_STATE_PRIVATE); } void snp_set_page_shared(unsigned long paddr) { + if (!sev_snp_enabled()) + return; + __page_state_change(paddr, SNP_PAGE_STATE_SHARED); } @@ -228,56 +237,10 @@ static bool early_setup_ghcb(void) return true; } -static phys_addr_t __snp_accept_memory(struct snp_psc_desc *desc, - phys_addr_t pa, phys_addr_t pa_end) -{ - struct psc_hdr *hdr; - struct psc_entry *e; - unsigned int i; - - hdr = &desc->hdr; - memset(hdr, 0, sizeof(*hdr)); - - e = desc->entries; - - i = 0; - while (pa < pa_end && i < VMGEXIT_PSC_MAX_ENTRY) { - hdr->end_entry = i; - - e->gfn = pa >> PAGE_SHIFT; - e->operation = SNP_PAGE_STATE_PRIVATE; - if (IS_ALIGNED(pa, PMD_SIZE) && (pa_end - pa) >= PMD_SIZE) { - e->pagesize = RMP_PG_SIZE_2M; - pa += PMD_SIZE; - } else { - e->pagesize = RMP_PG_SIZE_4K; - pa += PAGE_SIZE; - } - - e++; - i++; - } - - if (vmgexit_psc(boot_ghcb, desc)) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC); - - pvalidate_pages(desc); - - return pa; -} - void snp_accept_memory(phys_addr_t start, phys_addr_t end) { - struct snp_psc_desc desc = {}; - unsigned int i; - phys_addr_t pa; - - if (!boot_ghcb && !early_setup_ghcb()) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC); - - pa = start; - while (pa < end) - pa = __snp_accept_memory(&desc, pa, end); + for (phys_addr_t pa = start; pa < end; pa += PAGE_SIZE) + __page_state_change(pa, SNP_PAGE_STATE_PRIVATE); } void sev_es_shutdown_ghcb(void)