Re: [PATCH v14 03/13] x86/sev: Add Secure TSC support for SNP guests
From: Borislav Petkov
Date: Mon Nov 11 2024 - 05:52:27 EST
On Mon, Nov 11, 2024 at 02:16:00PM +0530, Nikunj A. Dadhania wrote:
> That was the reason I had not implemented "free" counterpart.
Then let's simplify this too because it is kinda silly right now:
---
diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index a72400704421..efddccf4b2c6 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -96,7 +96,7 @@ static u64 sev_hv_features __ro_after_init;
/* Secrets page physical address from the CC blob */
static u64 secrets_pa __ro_after_init;
-static struct snp_msg_desc *snp_mdesc;
+static struct snp_msg_desc snp_mdesc;
/* Secure TSC values read using TSC_INFO SNP Guest request */
static u64 snp_tsc_scale __ro_after_init;
@@ -2749,19 +2749,13 @@ EXPORT_SYMBOL_GPL(snp_msg_init);
struct snp_msg_desc *snp_msg_alloc(void)
{
- struct snp_msg_desc *mdesc;
+ struct snp_msg_desc *mdesc = &snp_mdesc;
BUILD_BUG_ON(sizeof(struct snp_guest_msg) > PAGE_SIZE);
- if (snp_mdesc)
- return snp_mdesc;
-
- mdesc = kzalloc(sizeof(struct snp_msg_desc), GFP_KERNEL);
- if (!mdesc)
- return ERR_PTR(-ENOMEM);
+ memset(mdesc, 0, sizeof(struct snp_msg_desc));
- mdesc->secrets = (__force struct snp_secrets_page *)ioremap_encrypted(secrets_pa,
- PAGE_SIZE);
+ mdesc->secrets = (__force struct snp_secrets_page *)ioremap_encrypted(secrets_pa, PAGE_SIZE);
if (!mdesc->secrets)
return ERR_PTR(-ENODEV);
@@ -2783,8 +2777,6 @@ struct snp_msg_desc *snp_msg_alloc(void)
mdesc->input.resp_gpa = __pa(mdesc->response);
mdesc->input.data_gpa = __pa(mdesc->certs_data);
- snp_mdesc = mdesc;
-
return mdesc;
e_free_response:
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette