Skip to content
Permalink
Browse files
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.

Reviewed-by: Nathan Tempelman <natet@google.com>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Steve Rutherford <srutherford@google.com>
  • Loading branch information
stevenrutherford authored and intel-lab-lkp committed Apr 9, 2021
1 parent f96be2d commit 16f9122ec5c3ee772f1edb80c2c2526650b60868
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
@@ -284,6 +284,15 @@ Returns: 0 on success, -negative on error
__u32 len;
};

16. KVM_SEV_SEND_CANCEL
------------------------

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.

Returns: 0 on success, -negative on error

References
==========

@@ -1111,6 +1111,26 @@ static int sev_get_attestation_report(struct kvm *kvm, struct kvm_sev_cmd *argp)
return ret;
}

static int sev_send_cancel(struct kvm *kvm, struct kvm_sev_cmd *argp)
{
struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
struct sev_data_send_cancel *data;
int ret;

if (!sev_guest(kvm))
return -ENOTTY;

data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;

data->handle = sev->handle;
ret = sev_issue_cmd(kvm, SEV_CMD_SEND_CANCEL, data, &argp->error);

kfree(data);
return ret;
}

int svm_mem_enc_op(struct kvm *kvm, void __user *argp)
{
struct kvm_sev_cmd sev_cmd;
@@ -1171,6 +1191,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp)
case KVM_SEV_GET_ATTESTATION_REPORT:
r = sev_get_attestation_report(kvm, &sev_cmd);
break;
case KVM_SEV_SEND_CANCEL:
r = sev_send_cancel(kvm, &sev_cmd);
break;
default:
r = -EINVAL;
goto out;
@@ -129,6 +129,7 @@ static int sev_cmd_buffer_len(int cmd)
case SEV_CMD_DOWNLOAD_FIRMWARE: return sizeof(struct sev_data_download_firmware);
case SEV_CMD_GET_ID: return sizeof(struct sev_data_get_id);
case SEV_CMD_ATTESTATION_REPORT: return sizeof(struct sev_data_attestation_report);
case SEV_SEND_CANCEL: return sizeof(struct sev_data_send_cancel);
default: return 0;
}

@@ -73,6 +73,7 @@ enum sev_cmd {
SEV_CMD_SEND_UPDATE_DATA = 0x041,
SEV_CMD_SEND_UPDATE_VMSA = 0x042,
SEV_CMD_SEND_FINISH = 0x043,
SEV_CMD_SEND_CANCEL = 0x044,

/* Guest migration commands (incoming) */
SEV_CMD_RECEIVE_START = 0x050,
@@ -392,6 +393,15 @@ struct sev_data_send_finish {
u32 handle; /* In */
} __packed;

/**
* struct sev_data_send_cancel - SEND_CANCEL command parameters
*
* @handle: handle of the VM to process
*/
struct sev_data_send_cancel {
u32 handle; /* In */
} __packed;

/**
* struct sev_data_receive_start - RECEIVE_START command parameters
*
@@ -1672,6 +1672,8 @@ enum sev_cmd_id {
KVM_SEV_CERT_EXPORT,
/* Attestation report */
KVM_SEV_GET_ATTESTATION_REPORT,
/* Guest Migration Extension */
KVM_SEV_SEND_CANCEL,

KVM_SEV_NR_MAX,
};

0 comments on commit 16f9122

Please sign in to comment.