Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp685726pxb; Thu, 19 Aug 2021 08:51:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7CBd5wNlGf622mdf4tuGWcfwrkPMBfZvnXfIMjIt/502vL8GgNkcroS93UzM0/4uXmczg X-Received: by 2002:a5e:d70a:: with SMTP id v10mr12389779iom.10.1629388274783; Thu, 19 Aug 2021 08:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629388274; cv=none; d=google.com; s=arc-20160816; b=Upgv8kdqhX4Bxa7OWZ/hBZDnWClGT7DGN/HpgQj7R3fAovD9NxCb6q8MDEtpYVPPXy rhzgAVYHZmCygxs2Ps94+nBfEl2CP1C0dCgPypW+/czjDPc7unrLXBFfkqrrH4bOtkDB TWOuCGLCZmus3SLFDmwJiZDUogbYthNp+mE6h1TV8tAbXDW9lqb9dMKuOCIMfCB9hSOc U/5Ponz7UrmmbTusXMI+9gg653l1wX5hqKC1o7lSC2KbTtq39xwc7wgMg92Y27SLI1UA g/+agHxUCi7HxxbsjKi8Sv75fG3YOdGsQs2w7MS2ARFczxjhWOoBXf2EU1TS2swCnsF4 gamw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=06xCCfeaDxwheq8VhlMKBbnaHCeiAJzMnFNIfyATnu0=; b=ovPONP2DCNII+mbxzptIhG4lpXfbOwc+XpwKKoy8mCejlAL8YO0f+2vuT5ZZByOPZX TyVGiNbqoEZEHFyDDuw9KiFyhpB/1JpUdkS9fflQXsCIuHCHcz6X5qO4cbD3X2D8EpWJ X0CxKBw0a5O+xI0btTyvrM9GbRz7MlShHkl39kv82wlHf2YkKBNQDERmeKCSKSCraVVR +2wZV1bd5xqlAzqmuMqK0+fubeUnK6hy/C8uhFrhqG2R5SxKpyv/BONb9HMc0PK49J3w rBlDClOy8hMbJiaJmo37LlVP+/OjyNhDae7MSMXKybKZhSjeMuomEPUU0gLMvU7PIsvH 9UqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=s7az7JI8; 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 f16si4015519ilc.93.2021.08.19.08.51.02; Thu, 19 Aug 2021 08:51:14 -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=s7az7JI8; 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 S240617AbhHSPtw (ORCPT + 99 others); Thu, 19 Aug 2021 11:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235645AbhHSPtv (ORCPT ); Thu, 19 Aug 2021 11:49:51 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8221C061575 for ; Thu, 19 Aug 2021 08:49:14 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id fs12-20020a17090af28c00b001797c5272b7so2717078pjb.9 for ; Thu, 19 Aug 2021 08:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=06xCCfeaDxwheq8VhlMKBbnaHCeiAJzMnFNIfyATnu0=; b=s7az7JI8GVaX8Owd7nc9lURKMIYeL6ZASEWKYW5SpoNi8JEXhQKu9qiI5q/1BFyfmK DxMjXJcry+Of8Wy3fwTkTHQIYeBNNLPW1dr/0TJqtbE9rkPp3iofwYeEh1jiwCOdgl7p GVv7a+QtavFRbqLE1qz+vpAClBDsLKMHe71+bBQoQlMEm9/QCHYRS8wT23sizWziYIhu uIJFdkSKhWm5pS0a8v2MlRMxezBK3ZKTDGASvkUMGbGm6Ms0PZOYMrqVBcLiSUJlUdlS kjWLD9b4tN1BzH+RPHeBEkxeRKsrlTEvfncRhKHPqB4zVczSk5s/cI4ZaW1Gn4aOOFqv LcGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=06xCCfeaDxwheq8VhlMKBbnaHCeiAJzMnFNIfyATnu0=; b=X2UZyGM3W0joCfa1ggBurIT6xqWAuCV+/zolGOqzSd5lXgK8RIKj8oclSuXuNM+Emy ikcpPClR6LJE+7+Rf3djDeVhhZ91pcye1g835huL9bVaUewkz2GcZjhafMFfU7xTfToq lCgNBiXADWsI5pqVyDpLn7pnjj6t+qg1SwyYlzUlKTuuJVmPDdn4pcuZfCTsTRgalwYJ GRzMAv9UHm0CQPgeo7hpZLlW3Kuv42zMMNsNy0/pbeqsxm9YHlnIYqq7qO+6V6B0yU0v hydbzKA25OtvJP3Rc4VczU5FMwPIRMUkY2X/scUgZUgHfTVOQx7zz7S0s0hM0MiGOEz2 64iA== X-Gm-Message-State: AOAM53226OTrtxAV4hoVxY+ncFiabcNEJNS++7mREIiKGc7auEjsPWRl wAwTEsbIBqXRIGYfTqo8YvJo6yHPKqo= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:204:6cf4:9d41:7258:8536]) (user=pgonda job=sendgmr) by 2002:a17:90a:db96:: with SMTP id h22mr16031244pjv.212.1629388154249; Thu, 19 Aug 2021 08:49:14 -0700 (PDT) Date: Thu, 19 Aug 2021 08:49:08 -0700 Message-Id: <20210819154910.1064090-1-pgonda@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH 0/2 V4] Add AMD SEV and SEV-ES intra host migration support From: Peter Gonda To: kvm@vger.kernel.org Cc: Peter Gonda , 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" , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Intra host migration provides a low-cost mechanism for userspace VMM upgrades. It is an alternative to traditional (i.e., remote) live migration. Whereas remote migration handles moving a guest to a new host, intra host migration only handles moving a guest to a new userspace VMM within a host. This can be used to update, rollback, change flags of the VMM, etc. The lower cost compared to live migration comes from the fact that the guest's memory does not need to be copied between processes. A handle to the guest memory simply gets passed to the new VMM, this could be done via /dev/shm with share=on or similar feature. The guest state can be transferred from an old VMM to a new VMM as follows: 1. Export guest state from KVM to the old user-space VMM via a getter user-space/kernel API 2. Transfer guest state from old VMM to new VMM via IPC communication 3. Import guest state into KVM from the new user-space VMM via a setter user-space/kernel API VMMs by exporting from KVM using getters, sending that data to the new VMM, then setting it again in KVM. In the common case for intra host migration, we can rely on the normal ioctls for passing data from one VMM to the next. SEV, SEV-ES, and other confidential compute environments make most of this information opaque, and render KVM ioctls such as "KVM_GET_REGS" irrelevant. As a result, we need the ability to pass this opaque metadata from one VMM to the next. The easiest way to do this is to leave this data in the kernel, and transfer ownership of the metadata from one KVM VM (or vCPU) to the next. For example, we need to move the SEV enabled ASID, VMSAs, and GHCB metadata from one VMM to the next. In general, we need to be able to hand off any data that would be unsafe/impossible for the kernel to hand directly to userspace (and cannot be reproduced using data that can be handed safely to userspace). For the intra host operation the SEV required metadata, the source VM FD is sent to the target VMM. The target VMM calls the new cap ioctl with the source VM FD, KVM then moves all the SEV state to the target VM from the source VM. V4: * Move to seanjc@'s suggestion of source VM FD based single ioctl design. v3: * Fix memory leak found by dan.carpenter@ v2: * Added marcorr@ reviewed by tag * Renamed function introduced in 1/3 * Edited with seanjc@'s review comments ** Cleaned up WARN usage ** Userspace makes random token now * Edited with brijesh.singh@'s review comments ** Checks for different LAUNCH_* states in send function v1: https://lore.kernel.org/kvm/20210621163118.1040170-1-pgonda@google.com/ Peter Gonda (2): KVM, SEV: Add support for SEV intra host migration KVM, SEV: Add support for SEV-ES intra host migration Documentation/virt/kvm/api.rst | 15 +++ arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm/sev.c | 160 ++++++++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/svm/svm.h | 3 + arch/x86/kvm/x86.c | 5 + include/uapi/linux/kvm.h | 1 + 7 files changed, 186 insertions(+) base-commit: a3e0b8bd99ab 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 -- 2.33.0.rc1.237.g0d66db33f3-goog