Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1023552pxb; Thu, 9 Sep 2021 18:17:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoNJRqO1AvaCn9JrixtSpQjhRocwYqBiq+zRufbeT2LczqsuHOoohdPCMPMN53OCVM5YD0 X-Received: by 2002:a92:de44:: with SMTP id e4mr4350355ilr.205.1631236620779; Thu, 09 Sep 2021 18:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631236620; cv=none; d=google.com; s=arc-20160816; b=zN1uXUDyIQAQB/+PEK6UZBrBKReh13f9G4rDynpNTVnLWckdc+Mnx2pUQWS9FyhxUx 7n24CLG+MxwY6oLUhKc7RPhSA2Eac2Tn3BqR5H9HQyGdgZFYBRL4044fI/1Bb5vW162u 5mHpd5uaxJonS/JMvYe5T+Jok5PFPtXNDriQljvttdLyTbzJXjfNZSCSTpYG2ODKIHkv JbMflVBcyhQKeWWLr4PXjtBn2IwE/bM29aaeaFBSnOLiwiw30vxWYbjlwFa8Y/ReESA3 2zGCbYyyTRQeLYZy9p5VDTS2BTeIyNGfiOfbI5ZjoHuiFpHeLCbSjR/g6a3XMWUPiPen vDqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6EzzDQr8yG5LGu5YaQcJ8I2pgkIJnUB9NbZo6MY9NXc=; b=rzJFaR9wdhQPJZTzREkgaRqXuatIgxAcT4Sy68QNJfVCYLAOl1gmS/ZFY5NeYDpK15 iV99Lqj+MLXTVpmmj+ClCD2aGWZAmi+0+WDPmGE9MI7JtRjer/5aByzL8jmI/uqzBO77 Pc5HIW0DbbAla/TiQ+lgWwr0bR5vChQCeUlcdSwRPVEm1h3ddiX02CK/h+2qsKbMsFSW EbE663Ue+9q46wJcby7lV3U2wpSAqTDlG2qEfh9FBrs4a4TOqpQ3UBc4+YskR0EBjQP/ 2BtRL1K4evl91XPegW2MgV6boNaecKjlcVP4OiloNHx+L13110bZ0SJ2M7leKRoWclXG 1MhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=c5HRKGzh; 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 l8si3135292ioj.7.2021.09.09.18.16.48; Thu, 09 Sep 2021 18:17:00 -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=20210112 header.b=c5HRKGzh; 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 S237241AbhIJBQi (ORCPT + 99 others); Thu, 9 Sep 2021 21:16:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237181AbhIJBQY (ORCPT ); Thu, 9 Sep 2021 21:16:24 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 410D7C02C3E2 for ; Thu, 9 Sep 2021 17:50:47 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id q22so392075pfu.0 for ; Thu, 09 Sep 2021 17:50:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6EzzDQr8yG5LGu5YaQcJ8I2pgkIJnUB9NbZo6MY9NXc=; b=c5HRKGzhLdFkDdqEaIAkzI2TMXEXey1oW4MYk1KKgGtbVRwNCS50yLwVApx2ET8oZE a08EtNL8Nr9TakKWLixpnMOtjt6TND+WWSSwZtAzso/DATK5EyfEi0bFk3rcAxNtADr/ X473cN9R3YlbUVxapedTDrJw17TrwvHZXdi4mu5cXsF2bxWh/fkhDVhm3TvgXaYOjWDl 1y2NmOWQrUik0qHnTeQOABPGH75WGlung4k6tvXcTfROJhET3yUQY66nXwdfDxw81SQ5 hOvMtNLBJZjhSYGgC6uifXXwVWf2hJKkHq4+Q9Luyf4cyAQCNYvcdTN/qF/6J8y4NNoD Ze4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6EzzDQr8yG5LGu5YaQcJ8I2pgkIJnUB9NbZo6MY9NXc=; b=NvQi5xP5p4IZ7yNZW5dB7ll/qYdmkovcnFhy/v5na5XO+swxv5yvUCF8HdqGRC+zb2 9rsH+vCwKpPSrOilPYcEmBYHMOyqKmleJW9xgZh/R+KGeuPtlaKgyjywZE2VPIs4Kqr1 +8Ud8PCY628mAV/vM0TosMBYu3e4pabxOoiK1w7KuWSublz9LBF6DdBOTlXN6wEGHMxO Qe/AlxXpAh8QgHcLNXDJV47KnKD23mtJxMBnLZRY8BW30/QBvaQgrcm13xBIYsXfxR+M Ms1xDqeK/AMVGX0AeH+u2OKe1ybGXxgowcOm01N+yoPqp22vccyQHNCMvWYRinOCgz1a uLyg== X-Gm-Message-State: AOAM533Esd0543d7BiH/JoSavAOF+L4VaXkZ352JU03PAIpYgnqWbxp9 6qTDjLstgQkneG4nMZOK+/aVuw== X-Received: by 2002:a63:1e16:: with SMTP id e22mr5012704pge.153.1631235046553; Thu, 09 Sep 2021 17:50:46 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id a78sm3407284pfa.95.2021.09.09.17.50.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 17:50:46 -0700 (PDT) Date: Fri, 10 Sep 2021 00:50:42 +0000 From: Sean Christopherson To: Peter Gonda Cc: kvm@vger.kernel.org, Marc Orr , Paolo Bonzini , David Rientjes , "Dr . David Alan Gilbert" , Brijesh Singh , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3 V7] KVM, SEV: Add support for SEV-ES intra host migration Message-ID: References: <20210902181751.252227-1-pgonda@google.com> <20210902181751.252227-3-pgonda@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210902181751.252227-3-pgonda@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 02, 2021, Peter Gonda wrote: > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > index 8db666a362d4..fac21a82e4de 100644 > --- a/arch/x86/kvm/svm/sev.c > +++ b/arch/x86/kvm/svm/sev.c > @@ -1545,6 +1545,59 @@ static void migrate_info_from(struct kvm_sev_info *dst, > list_replace_init(&src->regions_list, &dst->regions_list); > } > > +static int migrate_vmsa_from(struct kvm *dst, struct kvm *src) > +{ > + int i, num_vcpus; > + struct kvm_vcpu *dst_vcpu, *src_vcpu; > + struct vcpu_svm *dst_svm, *src_svm; > + > + num_vcpus = atomic_read(&dst->online_vcpus); > + if (num_vcpus != atomic_read(&src->online_vcpus)) { > + pr_warn_ratelimited( > + "Source and target VMs must have same number of vCPUs.\n"); Same comments about not logging the why. > + return -EINVAL; > + } > + > + for (i = 0; i < num_vcpus; ++i) > + src_vcpu = src->vcpus[i]; This can be: kvm_for_each_vcpu(i, src_vcpu, src) { if (!src_vcpu->arch.guest_state_protected) return -EINVAL; } > + if (!src_vcpu->arch.guest_state_protected) { > + pr_warn_ratelimited( > + "Source ES VM vCPUs must have protected state.\n"); > + return -EINVAL; > + } > + } > + > + for (i = 0; i < num_vcpus; ++i) { And again here, kvm_for_each_vcpu(i, src_vcpu, src) { src_svm = to_svm(src_vcpu); > + src_vcpu = src->vcpus[i]; > + src_svm = to_svm(src_vcpu); > + dst_vcpu = dst->vcpus[i]; Probably a good idea to use kvm_get_vcpu(), even though dst->lock is held. If nothing else, using kvm_get_vcpu() may save some merge pain as there's a proposal to switch vcpus to an xarray. > + dst_svm = to_svm(dst_vcpu); > + > + /* > + * Copy VMSA and GHCB fields from the source to the destination. > + * Clear them on the source to prevent the VM running and As brought up in the prior patch, clearing the fields might ensure future KVM_RUNs fail, but it doesn't prevent the VM from running _now_. And with vcpu->mutext held, I think a more appropriate comment would be: /* * Transfer VMSA and GHCB state to the destination. Nullify and * clear source fields as appropriate, the state now belongs to * the destination. */ > + * changing the state of the VMSA/GHCB unexpectedly. > + */ > + dst_vcpu->vcpu_id = src_vcpu->vcpu_id; > + dst_svm->vmsa = src_svm->vmsa; > + src_svm->vmsa = NULL; > + dst_svm->ghcb = src_svm->ghcb; > + src_svm->ghcb = NULL; > + dst_svm->vmcb->control.ghcb_gpa = > + src_svm->vmcb->control.ghcb_gpa; Let this poke out, an 83 char line isn't the end of the world, and not having the interrupt makes the code more readable overall. > + src_svm->vmcb->control.ghcb_gpa = 0; Nit, '0' isn't an invalid GPA. The reset value would be more appropriate, though I would just leave this alone. > + dst_svm->ghcb_sa = src_svm->ghcb_sa; > + src_svm->ghcb_sa = NULL; > + dst_svm->ghcb_sa_len = src_svm->ghcb_sa_len; > + src_svm->ghcb_sa_len = 0; > + dst_svm->ghcb_sa_sync = src_svm->ghcb_sa_sync; > + src_svm->ghcb_sa_sync = false; > + dst_svm->ghcb_sa_free = src_svm->ghcb_sa_free; > + src_svm->ghcb_sa_free = false; > + } > + return 0; > +}