Skip to content

Commit 8234177

Browse files
nikunjadbp3tk0v
authored andcommitted
virt: sev-guest: Remove is_vmpck_empty() helper
Remove is_vmpck_empty() which uses a local array allocation to check if the VMPCK is empty and replace it with memchr_inv() to directly determine if the VMPCK is empty without additional memory allocation. [ bp: Massage commit message. ] Suggested-by: Borislav Petkov <[email protected]> Signed-off-by: Nikunj A Dadhania <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 21fc617 commit 8234177

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

drivers/virt/coco/sev-guest/sev-guest.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with the PSP.
6363
/* Mutex to serialize the shared buffer access and command handling. */
6464
static DEFINE_MUTEX(snp_cmd_mutex);
6565

66-
static bool is_vmpck_empty(struct snp_msg_desc *mdesc)
67-
{
68-
char zero_key[VMPCK_KEY_LEN] = {0};
69-
70-
if (mdesc->vmpck)
71-
return !memcmp(mdesc->vmpck, zero_key, VMPCK_KEY_LEN);
72-
73-
return true;
74-
}
75-
7666
/*
7767
* If an error is received from the host or AMD Secure Processor (ASP) there
7868
* are two options. Either retry the exact same encrypted request or discontinue
@@ -335,7 +325,7 @@ static int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
335325
guard(mutex)(&snp_cmd_mutex);
336326

337327
/* Check if the VMPCK is not empty */
338-
if (is_vmpck_empty(mdesc)) {
328+
if (!mdesc->vmpck || !memchr_inv(mdesc->vmpck, 0, VMPCK_KEY_LEN)) {
339329
pr_err_ratelimited("VMPCK is disabled\n");
340330
return -ENOTTY;
341331
}
@@ -1024,7 +1014,7 @@ static int __init sev_guest_probe(struct platform_device *pdev)
10241014
}
10251015

10261016
/* Verify that VMPCK is not zero. */
1027-
if (is_vmpck_empty(mdesc)) {
1017+
if (!memchr_inv(mdesc->vmpck, 0, VMPCK_KEY_LEN)) {
10281018
dev_err(dev, "Empty VMPCK%d communication key\n", vmpck_id);
10291019
goto e_unmap;
10301020
}

0 commit comments

Comments
 (0)