* [PATCH v2 2/2] x86/sev: let sev_es_efi_map_ghcbs map the caa pages too [not found] <20250602105050.1535272-1-kraxel@redhat.com> @ 2025-06-02 10:50 ` Gerd Hoffmann 2025-06-24 13:01 ` Borislav Petkov 0 siblings, 1 reply; 7+ messages in thread From: Gerd Hoffmann @ 2025-06-02 10:50 UTC (permalink / raw) To: linux-coco Cc: kvm, Gerd Hoffmann, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin, Ard Biesheuvel, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT), open list:EXTENSIBLE FIRMWARE INTERFACE (EFI) OVMF EFI firmware needs access to the CAA page to do SVSM protocol calls. So add that to sev_es_efi_map_ghcbs and also rename the function to reflect the additional job it is doing now. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- arch/x86/include/asm/sev.h | 4 ++-- arch/x86/coco/sev/core.c | 14 ++++++++++++-- arch/x86/platform/efi/efi_64.c | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 58e028d42e41..6e0ef192f23b 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -445,7 +445,7 @@ static __always_inline void sev_es_nmi_complete(void) cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) __sev_es_nmi_complete(); } -extern int __init sev_es_efi_map_ghcbs(pgd_t *pgd); +extern int __init sev_es_efi_map_ghcbs_caas(pgd_t *pgd); extern void sev_enable(struct boot_params *bp); /* @@ -556,7 +556,7 @@ static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } static inline int sev_es_setup_ap_jump_table(struct real_mode_header *rmh) { return 0; } static inline void sev_es_nmi_complete(void) { } -static inline int sev_es_efi_map_ghcbs(pgd_t *pgd) { return 0; } +static inline int sev_es_efi_map_ghcbs_caas(pgd_t *pgd) { return 0; } static inline void sev_enable(struct boot_params *bp) { } static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate) { return 0; } static inline int rmpadjust(unsigned long vaddr, bool rmp_psize, unsigned long attrs) { return 0; } diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index fbc1215d2746..7ab9fc0ea180 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -1054,11 +1054,13 @@ int __init sev_es_setup_ap_jump_table(struct real_mode_header *rmh) * This is needed by the OVMF UEFI firmware which will use whatever it finds in * the GHCB MSR as its GHCB to talk to the hypervisor. So make sure the per-cpu * runtime GHCBs used by the kernel are also mapped in the EFI page-table. + * + * When running under SVSM the CCA page is needed too, so map it as well. */ -int __init sev_es_efi_map_ghcbs(pgd_t *pgd) +int __init sev_es_efi_map_ghcbs_caas(pgd_t *pgd) { struct sev_es_runtime_data *data; - unsigned long address, pflags; + unsigned long address, pflags, pflags_enc; int cpu; u64 pfn; @@ -1066,6 +1068,7 @@ int __init sev_es_efi_map_ghcbs(pgd_t *pgd) return 0; pflags = _PAGE_NX | _PAGE_RW; + pflags_enc = cc_mkenc(pflags); for_each_possible_cpu(cpu) { data = per_cpu(runtime_data, cpu); @@ -1075,6 +1078,13 @@ int __init sev_es_efi_map_ghcbs(pgd_t *pgd) if (kernel_map_pages_in_pgd(pgd, pfn, address, 1, pflags)) return 1; + + address = per_cpu(svsm_caa_pa, cpu); + if (address) { + pfn = address >> PAGE_SHIFT; + if (kernel_map_pages_in_pgd(pgd, pfn, address, 1, pflags_enc)) + return 1; + } } return 0; diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index e7e8f77f77f8..97e8032db45d 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -216,8 +216,8 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) * When SEV-ES is active, the GHCB as set by the kernel will be used * by firmware. Create a 1:1 unencrypted mapping for each GHCB. */ - if (sev_es_efi_map_ghcbs(pgd)) { - pr_err("Failed to create 1:1 mapping for the GHCBs!\n"); + if (sev_es_efi_map_ghcbs_caas(pgd)) { + pr_err("Failed to create 1:1 mapping for the GHCBs and CAAs!\n"); return 1; } -- 2.49.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] x86/sev: let sev_es_efi_map_ghcbs map the caa pages too 2025-06-02 10:50 ` [PATCH v2 2/2] x86/sev: let sev_es_efi_map_ghcbs map the caa pages too Gerd Hoffmann @ 2025-06-24 13:01 ` Borislav Petkov 2025-06-25 11:52 ` Gerd Hoffmann 0 siblings, 1 reply; 7+ messages in thread From: Borislav Petkov @ 2025-06-24 13:01 UTC (permalink / raw) To: Gerd Hoffmann Cc: linux-coco, kvm, Thomas Gleixner, Ingo Molnar, Dave Hansen, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin, Ard Biesheuvel, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT), open list:EXTENSIBLE FIRMWARE INTERFACE (EFI) I got this now: --- From: Gerd Hoffmann <kraxel@redhat.com> Date: Mon, 2 Jun 2025 12:50:49 +0200 Subject: [PATCH] x86/sev: Let sev_es_efi_map_ghcbs() map the caa pages too OVMF EFI firmware needs access to the CAA page to do SVSM protocol calls. For example, when the SVSM implements an EFI variable store, such calls will be necessary. So add that to sev_es_efi_map_ghcbs() and also rename the function to reflect the additional job it is doing now. [ bp: Massage. ] Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/20250602105050.1535272-3-kraxel@redhat.com --- arch/x86/coco/sev/core.c | 15 +++++++++++++-- arch/x86/include/asm/sev.h | 4 ++-- arch/x86/platform/efi/efi_64.c | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 8375ca7fbd8a..6af3e94ba0ee 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -1045,11 +1045,13 @@ int __init sev_es_setup_ap_jump_table(struct real_mode_header *rmh) * This is needed by the OVMF UEFI firmware which will use whatever it finds in * the GHCB MSR as its GHCB to talk to the hypervisor. So make sure the per-cpu * runtime GHCBs used by the kernel are also mapped in the EFI page-table. + * + * When running under SVSM the CCA page is needed too, so map it as well. */ -int __init sev_es_efi_map_ghcbs(pgd_t *pgd) +int __init sev_es_efi_map_ghcbs_caas(pgd_t *pgd) { + unsigned long address, pflags, pflags_enc; struct sev_es_runtime_data *data; - unsigned long address, pflags; int cpu; u64 pfn; @@ -1057,6 +1059,7 @@ int __init sev_es_efi_map_ghcbs(pgd_t *pgd) return 0; pflags = _PAGE_NX | _PAGE_RW; + pflags_enc = cc_mkenc(pflags); for_each_possible_cpu(cpu) { data = per_cpu(runtime_data, cpu); @@ -1066,6 +1069,14 @@ int __init sev_es_efi_map_ghcbs(pgd_t *pgd) if (kernel_map_pages_in_pgd(pgd, pfn, address, 1, pflags)) return 1; + + address = per_cpu(svsm_caa_pa, cpu); + if (!address) + return 1; + + pfn = address >> PAGE_SHIFT; + if (kernel_map_pages_in_pgd(pgd, pfn, address, 1, pflags_enc)) + return 1; } return 0; diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index fbb616fcbfb8..5b809f0ef207 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -446,7 +446,7 @@ static __always_inline void sev_es_nmi_complete(void) cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) __sev_es_nmi_complete(); } -extern int __init sev_es_efi_map_ghcbs(pgd_t *pgd); +extern int __init sev_es_efi_map_ghcbs_caas(pgd_t *pgd); extern void sev_enable(struct boot_params *bp); /* @@ -554,7 +554,7 @@ static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } static inline int sev_es_setup_ap_jump_table(struct real_mode_header *rmh) { return 0; } static inline void sev_es_nmi_complete(void) { } -static inline int sev_es_efi_map_ghcbs(pgd_t *pgd) { return 0; } +static inline int sev_es_efi_map_ghcbs_caas(pgd_t *pgd) { return 0; } static inline void sev_enable(struct boot_params *bp) { } static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate) { return 0; } static inline int rmpadjust(unsigned long vaddr, bool rmp_psize, unsigned long attrs) { return 0; } diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index e7e8f77f77f8..97e8032db45d 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -216,8 +216,8 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) * When SEV-ES is active, the GHCB as set by the kernel will be used * by firmware. Create a 1:1 unencrypted mapping for each GHCB. */ - if (sev_es_efi_map_ghcbs(pgd)) { - pr_err("Failed to create 1:1 mapping for the GHCBs!\n"); + if (sev_es_efi_map_ghcbs_caas(pgd)) { + pr_err("Failed to create 1:1 mapping for the GHCBs and CAAs!\n"); return 1; } -- 2.43.0 -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] x86/sev: let sev_es_efi_map_ghcbs map the caa pages too 2025-06-24 13:01 ` Borislav Petkov @ 2025-06-25 11:52 ` Gerd Hoffmann 2025-06-25 12:40 ` Borislav Petkov 0 siblings, 1 reply; 7+ messages in thread From: Gerd Hoffmann @ 2025-06-25 11:52 UTC (permalink / raw) To: Borislav Petkov Cc: linux-coco, kvm, Thomas Gleixner, Ingo Molnar, Dave Hansen, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin, Ard Biesheuvel, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT), open list:EXTENSIBLE FIRMWARE INTERFACE (EFI) > for_each_possible_cpu(cpu) { > data = per_cpu(runtime_data, cpu); > @@ -1066,6 +1069,14 @@ int __init sev_es_efi_map_ghcbs(pgd_t *pgd) > > if (kernel_map_pages_in_pgd(pgd, pfn, address, 1, pflags)) > return 1; > + > + address = per_cpu(svsm_caa_pa, cpu); > + if (!address) > + return 1; > + > + pfn = address >> PAGE_SHIFT; > + if (kernel_map_pages_in_pgd(pgd, pfn, address, 1, pflags_enc)) > + return 1; > } The kernel allocates the caa page(s) only when running under svsm, see alloc_runtime_data(), so this is not correct. I think we either have to return to the original behavior of only doing something in case address is not NULL, or wrap the caa code block into a 'if (snp_vmpl) { ... }', following what alloc_runtime_data() is doing. take care, Gerd ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] x86/sev: let sev_es_efi_map_ghcbs map the caa pages too 2025-06-25 11:52 ` Gerd Hoffmann @ 2025-06-25 12:40 ` Borislav Petkov 2025-06-25 13:21 ` Gerd Hoffmann 0 siblings, 1 reply; 7+ messages in thread From: Borislav Petkov @ 2025-06-25 12:40 UTC (permalink / raw) To: Gerd Hoffmann Cc: linux-coco, kvm, Thomas Gleixner, Ingo Molnar, Dave Hansen, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin, Ard Biesheuvel, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT), open list:EXTENSIBLE FIRMWARE INTERFACE (EFI) On Wed, Jun 25, 2025 at 01:52:58PM +0200, Gerd Hoffmann wrote: > The kernel allocates the caa page(s) only when running under svsm, see > alloc_runtime_data(), so this is not correct. I think we either have to > return to the original behavior of only doing something in case address > is not NULL Yes, we're doing something only when the address is not NULL. Or maybe I'm missing what you're trying to tell me... -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] x86/sev: let sev_es_efi_map_ghcbs map the caa pages too 2025-06-25 12:40 ` Borislav Petkov @ 2025-06-25 13:21 ` Gerd Hoffmann 2025-06-25 14:29 ` Borislav Petkov 0 siblings, 1 reply; 7+ messages in thread From: Gerd Hoffmann @ 2025-06-25 13:21 UTC (permalink / raw) To: Borislav Petkov Cc: linux-coco, kvm, Thomas Gleixner, Ingo Molnar, Dave Hansen, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin, Ard Biesheuvel, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT), open list:EXTENSIBLE FIRMWARE INTERFACE (EFI) On Wed, Jun 25, 2025 at 02:40:16PM +0200, Borislav Petkov wrote: > On Wed, Jun 25, 2025 at 01:52:58PM +0200, Gerd Hoffmann wrote: > > The kernel allocates the caa page(s) only when running under svsm, see > > alloc_runtime_data(), so this is not correct. I think we either have to > > return to the original behavior of only doing something in case address > > is not NULL > > Yes, we're doing something only when the address is not NULL. This is inside a loop, so returning in case the caa address is NULL will skip ghcb setup for all but the first CPU. take care, Gerd ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] x86/sev: let sev_es_efi_map_ghcbs map the caa pages too 2025-06-25 13:21 ` Gerd Hoffmann @ 2025-06-25 14:29 ` Borislav Petkov 2025-06-26 7:43 ` Gerd Hoffmann 0 siblings, 1 reply; 7+ messages in thread From: Borislav Petkov @ 2025-06-25 14:29 UTC (permalink / raw) To: Gerd Hoffmann Cc: linux-coco, kvm, Thomas Gleixner, Ingo Molnar, Dave Hansen, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin, Ard Biesheuvel, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT), open list:EXTENSIBLE FIRMWARE INTERFACE (EFI) On Wed, Jun 25, 2025 at 03:21:47PM +0200, Gerd Hoffmann wrote: > This is inside a loop, so returning in case the caa address is NULL will > skip ghcb setup for all but the first CPU. Then you should not piggyback on this loop but map the CAs in a separate step, only when a SVSM is running. And even then we should think about allowing to continue if not all CAs map successfully. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] x86/sev: let sev_es_efi_map_ghcbs map the caa pages too 2025-06-25 14:29 ` Borislav Petkov @ 2025-06-26 7:43 ` Gerd Hoffmann 0 siblings, 0 replies; 7+ messages in thread From: Gerd Hoffmann @ 2025-06-26 7:43 UTC (permalink / raw) To: Borislav Petkov Cc: linux-coco, kvm, Thomas Gleixner, Ingo Molnar, Dave Hansen, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin, Ard Biesheuvel, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT), open list:EXTENSIBLE FIRMWARE INTERFACE (EFI) On Wed, Jun 25, 2025 at 04:29:36PM +0200, Borislav Petkov wrote: > On Wed, Jun 25, 2025 at 03:21:47PM +0200, Gerd Hoffmann wrote: > > This is inside a loop, so returning in case the caa address is NULL will > > skip ghcb setup for all but the first CPU. > > Then you should not piggyback on this loop but map the CAs in a separate step, > only when a SVSM is running. v3 sent. take care, Gerd ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-06-26 7:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20250602105050.1535272-1-kraxel@redhat.com>
2025-06-02 10:50 ` [PATCH v2 2/2] x86/sev: let sev_es_efi_map_ghcbs map the caa pages too Gerd Hoffmann
2025-06-24 13:01 ` Borislav Petkov
2025-06-25 11:52 ` Gerd Hoffmann
2025-06-25 12:40 ` Borislav Petkov
2025-06-25 13:21 ` Gerd Hoffmann
2025-06-25 14:29 ` Borislav Petkov
2025-06-26 7:43 ` Gerd Hoffmann
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox