From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B271EC433FE for ; Fri, 8 Oct 2021 17:26:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98C0360C4B for ; Fri, 8 Oct 2021 17:26:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235278AbhJHR2l (ORCPT ); Fri, 8 Oct 2021 13:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231164AbhJHR2j (ORCPT ); Fri, 8 Oct 2021 13:28:39 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B45D1C061570 for ; Fri, 8 Oct 2021 10:26:43 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id x27so42027993lfa.9 for ; Fri, 08 Oct 2021 10:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=B3qeR7tBKVxf2LGhI0YPmlW51b6P4/1lbrG+pCI+eQ4=; b=kdm78ZXnSxyTXIBZ2EJpULCfPYA/DtBVz2wySJ3jGAYfavL1IikRd8VrZrncaWHgN3 c7bQGt8rlZhOFLh5ShBwbAtK5haMah27Cg3ChsPvEBRvtJJXrUsB0b172wB/zHl53WXC JEpofiXx6k8FnGlT8Xi7vyaw9Oy/ciEFPvEutPg9h0uv6l1iDMt7/6ACDXwOcIPGP+yM 2wkjqL+VNZ6B2XOHeVIz72nqfAhbHxQw7jvU829pOpsry1+7eM4YMtSR5OMtztjWEPOA FqnCbMTXupfPmWCXEsIeBwA6saTIRUpuFZfhIZ4x1AGaE6vr9DSyKqKBpE6ENRYZmLsX Cyhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=B3qeR7tBKVxf2LGhI0YPmlW51b6P4/1lbrG+pCI+eQ4=; b=plelAK4bpHivkS7DZ76wvIw3Y1txrabxD1/ukJimQVf8Zj4ELS5bF82UPDAKToBbzR r5ptH5nRKHWefYzyf7cVnbH99SKbv+hzvNDOAw0yuxgwuh2Aw31ZwWDHQX7XhYs0D18Q LZ5bgS9OLBubAWuIKu3A+jW0lhuJLmcQDx7ZqzUDcsYzOTSmeT8lY0asybfxqog35eiG SFQaSgGrMWy/3KIRm1feKBamAHDQ9fqNM3ag6lUWNbXAtvHBazJclY8A4wN68aq7WSus r7RF6vRw6mdOjXtckQ7Jjg7c9LsSL1cz/l22fUZkTdBnW/BUu/pMrSS+Yke5L7baYpFA ET4g== X-Gm-Message-State: AOAM533MVe5MduIKqs50WGQfPUUnTntvnXrjDxr6cU2K/9PYzDO81XcF SKSztF5VJK+jTQMdkmiqX0DjE3oFiTLJ/mIM7RZ0ZQ== X-Google-Smtp-Source: ABdhPJwlscVCQ4hK24IV6RgfA6KVeV48ZBgyD/EJCRnyKIr6FE62evaK5bG1B0gtY7iET1k0rNiGz1MpxV+bAbRFe8o= X-Received: by 2002:a05:6512:c18:: with SMTP id z24mr10423419lfu.193.1633714001796; Fri, 08 Oct 2021 10:26:41 -0700 (PDT) MIME-Version: 1.0 References: <20211005141357.2393627-1-pgonda@google.com> <20211005141357.2393627-3-pgonda@google.com> <5f6e6f61-0d34-e640-caea-ff71ac1563d8@amd.com> In-Reply-To: <5f6e6f61-0d34-e640-caea-ff71ac1563d8@amd.com> From: Peter Gonda Date: Fri, 8 Oct 2021 11:26:30 -0600 Message-ID: Subject: Re: [PATCH 2/4 V9] KVM: SEV: Add support for SEV-ES intra host migration To: Tom Lendacky Cc: kvm list , Marc Orr , Paolo Bonzini , Sean Christopherson , 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" , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 8, 2021 at 9:38 AM Tom Lendacky wrote: > > On 10/5/21 9:13 AM, Peter Gonda wrote: > > For SEV-ES to work with intra host migration the VMSAs, GHCB metadata, > > and other SEV-ES info needs to be preserved along with the guest's > > memory. > > > > Signed-off-by: Peter Gonda > > Reviewed-by: Marc Orr > > Cc: Marc Orr > > Cc: Paolo Bonzini > > Cc: Sean Christopherson > > Cc: David Rientjes > > Cc: Dr. David Alan Gilbert > > Cc: Brijesh Singh > > Cc: Vitaly Kuznetsov > > Cc: Wanpeng Li > > Cc: Jim Mattson > > Cc: Joerg Roedel > > Cc: Thomas Gleixner > > Cc: Ingo Molnar > > Cc: Borislav Petkov > > Cc: "H. Peter Anvin" > > Cc: kvm@vger.kernel.org > > Cc: linux-kernel@vger.kernel.org > > --- > > arch/x86/kvm/svm/sev.c | 53 +++++++++++++++++++++++++++++++++++++++++- > > 1 file changed, 52 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > > index 6fc1935b52ea..321b55654f36 100644 > > --- a/arch/x86/kvm/svm/sev.c > > +++ b/arch/x86/kvm/svm/sev.c > > @@ -1576,6 +1576,51 @@ static void sev_migrate_from(struct kvm_sev_info *dst, > > list_replace_init(&src->regions_list, &dst->regions_list); > > } > > > > +static int sev_es_migrate_from(struct kvm *dst, struct kvm *src) > > +{ > > + int i; > > + struct kvm_vcpu *dst_vcpu, *src_vcpu; > > + struct vcpu_svm *dst_svm, *src_svm; > > + > > + if (atomic_read(&src->online_vcpus) != atomic_read(&dst->online_vcpus)) > > + return -EINVAL; > > + > > + kvm_for_each_vcpu(i, src_vcpu, src) { > > + if (!src_vcpu->arch.guest_state_protected) > > + return -EINVAL; > > + } > > + > > + kvm_for_each_vcpu(i, src_vcpu, src) { > > + src_svm = to_svm(src_vcpu); > > + dst_vcpu = dst->vcpus[i]; > > + dst_vcpu = kvm_get_vcpu(dst, i); > > One of these assignments of dst_vcpu can be deleted. Good catch I'll remove the `dst_vcpu = dst->vcpus[i];` line. > > > + dst_svm = to_svm(dst_vcpu); > > + > > + /* > > + * Transfer VMSA and GHCB state to the destination. Nullify and > > + * clear source fields as appropriate, the state now belongs to > > + * the destination. > > + */ > > + 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; > > + 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; > > Would it make sense to have a pre-patch that puts these fields into a > struct? Then you can just copy the struct and zero it after. If anything > is ever added for any reason, then it could/should be added to the struct > and this code wouldn't have to change. It might be more churn than it's > worth, just a thought. > That sounds like a good idea to me. I'll add a new patch to the start of the series which adds in something like: struct vcpu_sev_es_state { /* SEV-ES support */ struct vmcb_save_area *vmsa; struct ghcb *ghcb; struct kvm_host_map ghcb_map; bool received_first_sipi; /* SEV-ES scratch area support */ void *ghcb_sa; u64 ghcb_sa_len; bool ghcb_sa_sync; bool ghcb_sa_free; }; struct vcpu_svm { ... struct vcpu_sev_es_state sev_es_state; ... }; I think that will make this less tedious / error prone code. Names sound OK or better suggestion?