Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp873744pxf; Thu, 8 Apr 2021 15:05:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEXmKIuHlcRBAFuyF3E6+LCTMpHZjb5LWlJ+H7o3HbLzXMg9ZDNia82Lkjgn8Lj7wx3rfr X-Received: by 2002:a17:907:3a98:: with SMTP id fh24mr3264806ejc.371.1617919507088; Thu, 08 Apr 2021 15:05:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617919507; cv=none; d=google.com; s=arc-20160816; b=whK1QZXNUvF162aTLiAgAKVeCHotu1NCdMtUzxeMK9rXl2wR5R0jDWEXwH1CXR2lmj uxREP2SBjbZlJe9a2XEERBF9rM3KbA22CRLckWzHOybUwnzyzEzteBHFEKmoXO3OkBFn LWsz9N0V7WCF8FpEHD4lr7YyqSLcluxxdAELNmw+0wQ76+COba2QncNVgkya/QGMOykm jW75Pyut/SNyTjBlS2mV7W40cOtps2e/r2riP4zp5vwaN2gWrPmpj5EvWEC+Al4R6fwT NeM75kEDoaXsFn9MXFXF0rVtPN+9cAUX/S1uao57rP+sy6FLsVfXKD6x9d0Dd7zsdERQ Ga+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=z78DXVE9WBm7/7q42/7ISkvRmbVqJnFckYhnNs8iZ0k=; b=UgVJmF5abp3ultT2irnACnQYnl52IFXqoqYzV310j5cCN6NcB62U+z1jxqHn2/ki6F 7YqLN6Fo7aV/JPW04G5tf1XxR1qTrOm/gIgD7vhxYvYFVfs6hLl9WxKRhEDTf6Wi9Ckt qzSTgxmtaxQSZCkwSIdYr9qmZf0J69X8Be9zUu7t31n1ErVxJ7sM2pNxMXjdWu49yuZ/ 4h6QY/2ZZ01sOybq2X0xNMr+55U1y/Tsc4wVyBUaCs+eCDR0rgtOZcN67Bwdf9XG6rIm 8Cz6Gmst1lwjP3TsTK0f2Z9/nrPzLBdVM9GWNf0Qbq7eSP3nXGkl2qcOaNWN9WkfVXsE j+eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hfODF5w2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si512438eju.132.2021.04.08.15.04.43; Thu, 08 Apr 2021 15:05:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hfODF5w2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232744AbhDHWDG (ORCPT + 99 others); Thu, 8 Apr 2021 18:03:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232158AbhDHWDF (ORCPT ); Thu, 8 Apr 2021 18:03:05 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 924FAC061760 for ; Thu, 8 Apr 2021 15:02:53 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id g35so2351531pgg.9 for ; Thu, 08 Apr 2021 15:02:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=z78DXVE9WBm7/7q42/7ISkvRmbVqJnFckYhnNs8iZ0k=; b=hfODF5w2VKgIycyUnbATTLWtyJ6DfcsoXmU1GfHp77ZKjL/Di/Dccm9fqQhLM7NLjG EgvT5d4OBVGlbCLGYHcqh5YLg0FMgmwCcnXm4+KMOvIs00ZpKHhBr/CpvXib1yO8bJ2N PBce4FC3AF5R5Mr+TPuTSen7T5EpfgviaUWHgz01LpE2ou99PskAgQjfhhWwd49X2Vv8 kBCOhMXtSe6or2qeWzjFnsEPZD24PRVoEVcKmQ3nzcPQMKdNOsoQ7fJoBVkkkH32ZvYi pJtCiRE0aEAwmEJpLVfzfkgsIAB8ksI+Idzr8eXj+gFt7Rwi7Swlqik4XnxiHOSXeRE8 latQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=z78DXVE9WBm7/7q42/7ISkvRmbVqJnFckYhnNs8iZ0k=; b=bF8eU8XjktYK7iLBnTxf7Oq+HQe/keiwnmXsPn6AbvMFH0daC/6b7BSHcAERQl1PPm XW657KoDqb62KO7VrX0jTMs5g4vRmZE4Ps8TwILovO38jtiEe3MsOX8jEj3N/17Q4WCe kmPg/AyY/qlP0QzFZhbqbZeZz+OGqsiBrPBPx2EDaZagGPWAGmAqAeStZ1zoGc7k9uT4 p3MX4Ns1VQeGdtGZYmH8kwysyKU2iaWcqM26OyKDuqhUUmyhd+iUTeHjl6OOSKRr6j0G c7x8BcR8LRxSoeAtT9OK1MtUrSYWpVGiO5qa9tHGMDh9tSJ112W3cVkCdhHpypfNtaNR 2leA== X-Gm-Message-State: AOAM532+XRipqUPMRErMNKqTJMlmKL19yck3FFz+1/NaFYzKgTQQ/6AV N7QHlOosQllhq86xG7t0I5CC6EKh+PpIfOBXoQD+BQ== X-Received: by 2002:a63:dc56:: with SMTP id f22mr9986289pgj.287.1617919372905; Thu, 08 Apr 2021 15:02:52 -0700 (PDT) MIME-Version: 1.0 References: <20210402014438.1721086-1-srutherford@google.com> In-Reply-To: <20210402014438.1721086-1-srutherford@google.com> From: Nathan Tempelman Date: Thu, 8 Apr 2021 15:02:41 -0700 Message-ID: Subject: Re: [PATCH] KVM: SVM: Add support for KVM_SEV_SEND_CANCEL command To: Steve Rutherford Cc: kvm , linux-kernel@vger.kernel.org, Ashish Kalra , Brijesh Singh , Paolo Bonzini Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 1, 2021 at 6:45 PM Steve Rutherford wrote: > > 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. > > Signed-off-by: Steve Rutherford > --- > .../virt/kvm/amd-memory-encryption.rst | 9 +++++++ > arch/x86/kvm/svm/sev.c | 24 +++++++++++++++++++ > include/linux/psp-sev.h | 10 ++++++++ > include/uapi/linux/kvm.h | 2 ++ > 4 files changed, 45 insertions(+) > > diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst > index 469a6308765b1..9e018a3eec03b 100644 > --- a/Documentation/virt/kvm/amd-memory-encryption.rst > +++ b/Documentation/virt/kvm/amd-memory-encryption.rst > @@ -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 > ========== > > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > index 83e00e5245136..88e72102cb900 100644 > --- a/arch/x86/kvm/svm/sev.c > +++ b/arch/x86/kvm/svm/sev.c > @@ -1110,6 +1110,27 @@ 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; > @@ -1163,6 +1184,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; > diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h > index b801ead1e2bb5..74f2babffc574 100644 > --- a/include/linux/psp-sev.h > +++ b/include/linux/psp-sev.h > @@ -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 > * > diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h > index f6afee209620d..707469b6b7072 100644 > --- a/include/uapi/linux/kvm.h > +++ b/include/uapi/linux/kvm.h > @@ -1671,6 +1671,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, > }; > -- > 2.31.0.208.g409f899ff0-goog > Reviewed-by: Nathan Tempelman