Skip to content

Commit ae59661

Browse files
nikunjadbp3tk0v
authored andcommitted
virt: sev-guest: Reduce the scope of SNP command mutex
The SNP command mutex is used to serialize access to the shared buffer, command handling, and message sequence number. All shared buffer, command handling, and message sequence updates are done within snp_send_guest_request(), so moving the mutex to this function is appropriate and maintains the critical section. Since the mutex is now taken at a later point in time, remove the lockdep checks that occur before taking the mutex. 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 999d736 commit ae59661

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

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

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,14 @@ static int snp_send_guest_request(struct snp_guest_dev *snp_dev, struct snp_gues
345345
u64 seqno;
346346
int rc;
347347

348+
guard(mutex)(&snp_cmd_mutex);
349+
350+
/* Check if the VMPCK is not empty */
351+
if (is_vmpck_empty(snp_dev)) {
352+
dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n");
353+
return -ENOTTY;
354+
}
355+
348356
/* Get message sequence and verify that its a non-zero */
349357
seqno = snp_get_msg_seqno(snp_dev);
350358
if (!seqno)
@@ -401,8 +409,6 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io
401409
struct snp_guest_req req = {};
402410
int rc, resp_len;
403411

404-
lockdep_assert_held(&snp_cmd_mutex);
405-
406412
if (!arg->req_data || !arg->resp_data)
407413
return -EINVAL;
408414

@@ -449,8 +455,6 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque
449455
/* Response data is 64 bytes and max authsize for GCM is 16 bytes. */
450456
u8 buf[64 + 16];
451457

452-
lockdep_assert_held(&snp_cmd_mutex);
453-
454458
if (!arg->req_data || !arg->resp_data)
455459
return -EINVAL;
456460

@@ -501,8 +505,6 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques
501505
int ret, npages = 0, resp_len;
502506
sockptr_t certs_address;
503507

504-
lockdep_assert_held(&snp_cmd_mutex);
505-
506508
if (sockptr_is_null(io->req_data) || sockptr_is_null(io->resp_data))
507509
return -EINVAL;
508510

@@ -598,15 +600,6 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long
598600
if (!input.msg_version)
599601
return -EINVAL;
600602

601-
mutex_lock(&snp_cmd_mutex);
602-
603-
/* Check if the VMPCK is not empty */
604-
if (is_vmpck_empty(snp_dev)) {
605-
dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n");
606-
mutex_unlock(&snp_cmd_mutex);
607-
return -ENOTTY;
608-
}
609-
610603
switch (ioctl) {
611604
case SNP_GET_REPORT:
612605
ret = get_report(snp_dev, &input);
@@ -628,8 +621,6 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long
628621
break;
629622
}
630623

631-
mutex_unlock(&snp_cmd_mutex);
632-
633624
if (input.exitinfo2 && copy_to_user(argp, &input, sizeof(input)))
634625
return -EFAULT;
635626

@@ -744,8 +735,6 @@ static int sev_svsm_report_new(struct tsm_report *report, void *data)
744735
man_len = SZ_4K;
745736
certs_len = SEV_FW_BLOB_MAX_SIZE;
746737

747-
guard(mutex)(&snp_cmd_mutex);
748-
749738
if (guid_is_null(&desc->service_guid)) {
750739
call_id = SVSM_ATTEST_CALL(SVSM_ATTEST_SERVICES);
751740
} else {
@@ -880,14 +869,6 @@ static int sev_report_new(struct tsm_report *report, void *data)
880869
if (!buf)
881870
return -ENOMEM;
882871

883-
guard(mutex)(&snp_cmd_mutex);
884-
885-
/* Check if the VMPCK is not empty */
886-
if (is_vmpck_empty(snp_dev)) {
887-
dev_err_ratelimited(snp_dev->dev, "VMPCK is disabled\n");
888-
return -ENOTTY;
889-
}
890-
891872
cert_table = buf + report_size;
892873
struct snp_ext_report_req ext_req = {
893874
.data = { .vmpl = desc->privlevel },

0 commit comments

Comments
 (0)