Skip to content

Commit 6068754

Browse files
nikunjadbp3tk0v
authored andcommitted
x86/sev: Cache the secrets page address
Instead of calling get_secrets_page(), which parses the CC blob every time to get the secrets page physical address (secrets_pa), save the secrets page physical address during snp_init() from the CC blob. Since get_secrets_page() is no longer used, remove the function. Signed-off-by: Nikunj A Dadhania <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Tom Lendacky <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f75ff17 commit 6068754

File tree

1 file changed

+11
-40
lines changed

1 file changed

+11
-40
lines changed

arch/x86/coco/sev/core.c

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ static struct ghcb *boot_ghcb __section(".data");
9292
/* Bitmap of SEV features supported by the hypervisor */
9393
static u64 sev_hv_features __ro_after_init;
9494

95+
/* Secrets page physical address from the CC blob */
96+
static u64 secrets_pa __ro_after_init;
97+
9598
/* #VC handler runtime per-CPU data */
9699
struct sev_es_runtime_data {
97100
struct ghcb ghcb_page;
@@ -695,45 +698,13 @@ void noinstr __sev_es_nmi_complete(void)
695698
__sev_put_ghcb(&state);
696699
}
697700

698-
static u64 __init get_secrets_page(void)
699-
{
700-
u64 pa_data = boot_params.cc_blob_address;
701-
struct cc_blob_sev_info info;
702-
void *map;
703-
704-
/*
705-
* The CC blob contains the address of the secrets page, check if the
706-
* blob is present.
707-
*/
708-
if (!pa_data)
709-
return 0;
710-
711-
map = early_memremap(pa_data, sizeof(info));
712-
if (!map) {
713-
pr_err("Unable to locate SNP secrets page: failed to map the Confidential Computing blob.\n");
714-
return 0;
715-
}
716-
memcpy(&info, map, sizeof(info));
717-
early_memunmap(map, sizeof(info));
718-
719-
/* smoke-test the secrets page passed */
720-
if (!info.secrets_phys || info.secrets_len != PAGE_SIZE)
721-
return 0;
722-
723-
return info.secrets_phys;
724-
}
725-
726701
static u64 __init get_snp_jump_table_addr(void)
727702
{
728703
struct snp_secrets_page *secrets;
729704
void __iomem *mem;
730-
u64 pa, addr;
731-
732-
pa = get_secrets_page();
733-
if (!pa)
734-
return 0;
705+
u64 addr;
735706

736-
mem = ioremap_encrypted(pa, PAGE_SIZE);
707+
mem = ioremap_encrypted(secrets_pa, PAGE_SIZE);
737708
if (!mem) {
738709
pr_err("Unable to locate AP jump table address: failed to map the SNP secrets page.\n");
739710
return 0;
@@ -2273,6 +2244,11 @@ bool __head snp_init(struct boot_params *bp)
22732244
if (!cc_info)
22742245
return false;
22752246

2247+
if (cc_info->secrets_phys && cc_info->secrets_len == PAGE_SIZE)
2248+
secrets_pa = cc_info->secrets_phys;
2249+
else
2250+
return false;
2251+
22762252
setup_cpuid_table(cc_info);
22772253

22782254
svsm_setup(cc_info);
@@ -2469,16 +2445,11 @@ static struct platform_device sev_guest_device = {
24692445
static int __init snp_init_platform_device(void)
24702446
{
24712447
struct sev_guest_platform_data data;
2472-
u64 gpa;
24732448

24742449
if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
24752450
return -ENODEV;
24762451

2477-
gpa = get_secrets_page();
2478-
if (!gpa)
2479-
return -ENODEV;
2480-
2481-
data.secrets_gpa = gpa;
2452+
data.secrets_gpa = secrets_pa;
24822453
if (platform_device_add_data(&sev_guest_device, &data, sizeof(data)))
24832454
return -ENODEV;
24842455

0 commit comments

Comments
 (0)