Skip to content

Commit a754963

Browse files
kraxelbp3tk0v
authored andcommitted
x86/sev: Let sev_es_efi_map_ghcbs() map the CA pages too
OVMF EFI firmware needs access to the CA 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 <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/[email protected]
1 parent 7b22e04 commit a754963

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

arch/x86/coco/sev/core.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,18 +1045,21 @@ int __init sev_es_setup_ap_jump_table(struct real_mode_header *rmh)
10451045
* This is needed by the OVMF UEFI firmware which will use whatever it finds in
10461046
* the GHCB MSR as its GHCB to talk to the hypervisor. So make sure the per-cpu
10471047
* runtime GHCBs used by the kernel are also mapped in the EFI page-table.
1048+
*
1049+
* When running under SVSM the CA page is needed too, so map it as well.
10481050
*/
1049-
int __init sev_es_efi_map_ghcbs(pgd_t *pgd)
1051+
int __init sev_es_efi_map_ghcbs_cas(pgd_t *pgd)
10501052
{
1053+
unsigned long address, pflags, pflags_enc;
10511054
struct sev_es_runtime_data *data;
1052-
unsigned long address, pflags;
10531055
int cpu;
10541056
u64 pfn;
10551057

10561058
if (!cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT))
10571059
return 0;
10581060

10591061
pflags = _PAGE_NX | _PAGE_RW;
1062+
pflags_enc = cc_mkenc(pflags);
10601063

10611064
for_each_possible_cpu(cpu) {
10621065
data = per_cpu(runtime_data, cpu);
@@ -1066,6 +1069,16 @@ int __init sev_es_efi_map_ghcbs(pgd_t *pgd)
10661069

10671070
if (kernel_map_pages_in_pgd(pgd, pfn, address, 1, pflags))
10681071
return 1;
1072+
1073+
if (snp_vmpl) {
1074+
address = per_cpu(svsm_caa_pa, cpu);
1075+
if (!address)
1076+
return 1;
1077+
1078+
pfn = address >> PAGE_SHIFT;
1079+
if (kernel_map_pages_in_pgd(pgd, pfn, address, 1, pflags_enc))
1080+
return 1;
1081+
}
10691082
}
10701083

10711084
return 0;

arch/x86/include/asm/sev.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static __always_inline void sev_es_nmi_complete(void)
446446
cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT))
447447
__sev_es_nmi_complete();
448448
}
449-
extern int __init sev_es_efi_map_ghcbs(pgd_t *pgd);
449+
extern int __init sev_es_efi_map_ghcbs_cas(pgd_t *pgd);
450450
extern void sev_enable(struct boot_params *bp);
451451

452452
/*
@@ -554,7 +554,7 @@ static inline void sev_es_ist_enter(struct pt_regs *regs) { }
554554
static inline void sev_es_ist_exit(void) { }
555555
static inline int sev_es_setup_ap_jump_table(struct real_mode_header *rmh) { return 0; }
556556
static inline void sev_es_nmi_complete(void) { }
557-
static inline int sev_es_efi_map_ghcbs(pgd_t *pgd) { return 0; }
557+
static inline int sev_es_efi_map_ghcbs_cas(pgd_t *pgd) { return 0; }
558558
static inline void sev_enable(struct boot_params *bp) { }
559559
static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate) { return 0; }
560560
static inline int rmpadjust(unsigned long vaddr, bool rmp_psize, unsigned long attrs) { return 0; }

arch/x86/platform/efi/efi_64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
216216
* When SEV-ES is active, the GHCB as set by the kernel will be used
217217
* by firmware. Create a 1:1 unencrypted mapping for each GHCB.
218218
*/
219-
if (sev_es_efi_map_ghcbs(pgd)) {
220-
pr_err("Failed to create 1:1 mapping for the GHCBs!\n");
219+
if (sev_es_efi_map_ghcbs_cas(pgd)) {
220+
pr_err("Failed to create 1:1 mapping for the GHCBs and CAs!\n");
221221
return 1;
222222
}
223223

0 commit comments

Comments
 (0)