History

KVM: SVM: Add support for KVM_SEV_SEND_CANCEL command

After completion of SEND_START, but before SEND_FINISH, the source VMM can issue the SEND_CANCEL command to stop a migration. This is necessary so that a cancelled migration can restart with a new target later.

Steve Rutherford committed 5 years ago

Commit 5569e2e1 parent fddecf65 files · +45 −0Browse files

Unified · Split

5 files
  1. Documentation/virt/kvm/amd-memory-encryption.rst +9 −0
  2. arch/x86/kvm/svm/sev.c +23 −0
  3. drivers/crypto/ccp/sev-dev.c +1 −0
  4. include/linux/psp-sev.h +10 −0
  5. include/uapi/linux/kvm.h +2 −0
Documentation/virt/kvm/amd-memory-encryption.rst+9−0
@@ -356,6 +356,15 @@ issued by the hypervisor to delete the encryption context. · 355 unmodified lines
356356
357357 Returns: 0 on success, -negative on error
358358
359+14. KVM_SEV_SEND_CANCEL
360+------------------------
361+
362+After completion of SEND_START, but before SEND_FINISH, the source VMM can issue the
363+SEND_CANCEL command to stop a migration. This is necessary so that a cancelled
364+migration can restart with a new target later.
365+
366+Returns: 0 on success, -negative on error
367+
359368 References
360369 ==========
361370
arch/x86/kvm/svm/sev.c+23−0
@@ -1377,6 +1377,26 @@ static int sev_send_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) · 1376 unmodified lines
13771377 return ret;
13781378 }
13791379
1380+static int sev_send_cancel(struct kvm *kvm, struct kvm_sev_cmd *argp)
1381+{
1382+ struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
1383+ struct sev_data_send_cancel *data;
1384+ int ret;
1385+
1386+ if (!sev_guest(kvm))
1387+ return -ENOTTY;
1388+
1389+ data = kzalloc(sizeof(*data), GFP_KERNEL);
1390+ if (!data)
1391+ return -ENOMEM;
1392+
1393+ data->handle = sev->handle;
1394+ ret = sev_issue_cmd(kvm, SEV_CMD_SEND_CANCEL, data, &argp->error);
1395+
1396+ kfree(data);
1397+ return ret;
1398+}
1399+
13801400 int svm_mem_enc_op(struct kvm *kvm, void __user *argp)
13811401 {
13821402 struct kvm_sev_cmd sev_cmd;
@@ -1448,6 +1468,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) · 65 unmodified lines
14481468 case KVM_SEV_SEND_FINISH:
14491469 r = sev_send_finish(kvm, &sev_cmd);
14501470 break;
1471+ case KVM_SEV_SEND_CANCEL:
1472+ r = sev_send_cancel(kvm, &sev_cmd);
1473+ break;
14511474 default:
14521475 r = -EINVAL;
14531476 goto out;
drivers/crypto/ccp/sev-dev.c+1−0
@@ -129,6 +129,7 @@ static int sev_cmd_buffer_len(int cmd) · 128 unmodified lines
129129 case SEV_CMD_DOWNLOAD_FIRMWARE: return sizeof(struct sev_data_download_firmware);
130130 case SEV_CMD_GET_ID: return sizeof(struct sev_data_get_id);
131131 case SEV_CMD_ATTESTATION_REPORT: return sizeof(struct sev_data_attestation_report);
132+ case SEV_CMD_SEND_CANCEL: return sizeof(struct sev_data_send_cancel);
132133 default: return 0;
133134 }
134135
include/linux/psp-sev.h+10−0
@@ -73,6 +73,7 @@ enum sev_cmd { · 72 unmodified lines
7373 SEV_CMD_SEND_UPDATE_DATA = 0x041,
7474 SEV_CMD_SEND_UPDATE_VMSA = 0x042,
7575 SEV_CMD_SEND_FINISH = 0x043,
76+ SEV_CMD_SEND_CANCEL = 0x044,
7677
7778 /* Guest migration commands (incoming) */
7879 SEV_CMD_RECEIVE_START = 0x050,
@@ -392,6 +393,15 @@ struct sev_data_send_finish { · 313 unmodified lines
392393 u32 handle; /* In */
393394 } __packed;
394395
396+/**
397+ * struct sev_data_send_cancel - SEND_CANCEL command parameters
398+ *
399+ * @handle: handle of the VM to process
400+ */
401+struct sev_data_send_cancel {
402+ u32 handle; /* In */
403+} __packed;
404+
395405 /**
396406 * struct sev_data_receive_start - RECEIVE_START command parameters
397407 *
include/uapi/linux/kvm.h+2−0
@@ -1674,6 +1674,8 @@ enum sev_cmd_id { · 1673 unmodified lines
16741674 KVM_SEV_CERT_EXPORT,
16751675 /* Attestation report */
16761676 KVM_SEV_GET_ATTESTATION_REPORT,
1677+ /* Guest Migration Extension */
1678+ KVM_SEV_SEND_CANCEL,
16771679
16781680 KVM_SEV_NR_MAX,
16791681 };