Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3917181pxb; Mon, 30 Aug 2021 13:58:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7Vw2DVnJ2gsgl6avIJW4GTixF+kGIOPIvraUM2jMHigCOKZ9FYjIq97/FjD9rZGd+mteP X-Received: by 2002:a5d:9653:: with SMTP id d19mr19609734ios.74.1630357102114; Mon, 30 Aug 2021 13:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630357102; cv=none; d=google.com; s=arc-20160816; b=u4ikfKGdekdqKAR97rC7MJ5kUKz5Vdq/VQj64W3brOBfusK2v03y6tqeFCINO1p49q LWMkeMfGjP7jvb9ImIRtChTYSPkXXutlPl8UW4pS9xTgsh4gv5HJ6bSnbHZU3mnQLUxJ EGg8j+fJ1Ajr0KtQ7E+Vm0inZ17Tut5D5nEUcmkM517D2g9ed2dlfoSlRJ9riAqRTNfr 6U2LOs0SaSYjT33Ar1emt3xAwsWADP/JUEsHrO9mhrljyQGBqXiiiI9T9SYxQcajICbF /+OT5+xCJQGDYKNoco/UCH2TuRmkpIZCioLoVtVMNTz8Z3Ea/8bxXPD10oLnoEzovzi7 muAw== 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=qQlkZxCZKnPJMcE0Oq5p1b0zS1PuedDR0ng2hng3Vck=; b=rIqrk9PInvMYDO7rw1qLjdVUdnIu9kzgzrQRlTkYwNkcb37LzmXW8E3SpKkBTJDYNm jcAeqh5n9mfzJwpy5ltLNwi1zBDxC3oBnxPV6kt94BKepVi1f/axUoluHdS6iX7AA3gH L7I5fgEaz8ipkLdoe7A3cY0su+/Peni+YDDxXGwNGc3ZaycGe1/E6dEm9bK5evTDzWU2 sExUxKlEDJMityl49Oono0eK7qSxqJxBpVmTndMvRgvevMkR6UZqir4JFbpfEjVUpW7o myJMmOlIHgMTEQ7WTXs9zrP2YVaXA0uFa/fU8363PHuyOtWaVVv9k4y6DbgNlehUchuN IHdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=URLkGxYv; 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 i9si6596734ilc.6.2021.08.30.13.58.07; Mon, 30 Aug 2021 13:58:22 -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=URLkGxYv; 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 S235663AbhH3U6Q (ORCPT + 99 others); Mon, 30 Aug 2021 16:58:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233969AbhH3U6P (ORCPT ); Mon, 30 Aug 2021 16:58:15 -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 5BE8BC061575 for ; Mon, 30 Aug 2021 13:57:21 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id ml19-20020a17090b361300b00196588f5090so263067pjb.0 for ; Mon, 30 Aug 2021 13:57:21 -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=qQlkZxCZKnPJMcE0Oq5p1b0zS1PuedDR0ng2hng3Vck=; b=URLkGxYvi4dBsZzh96zP2kS+YcEDsz3DGH6wz7BYGUfXshLjwU1mhGJWiWu2oHYcf4 WhwdD1CHVOh/yBtaJ7Bx+gDMZyEnqFttVGrHccs8WkSGbmS+QkbCk7FGHP2mwpCoANSW Btbg+akgj3u6dioHCLAPaMQhMEQZfY+ambjPjtN6imFnVsDb5hSRPv8513n1YALFO2Q3 c3xzxgG0It4Wlq4WVkIQssCbhrsnkHiJcdoPlKXaDp4Uyod+7alcbfJ5yyEZXmFcG616 GhkEQBvh9zmRLVqUXPWGtx9P5/voI2XIZiYlNJby7IqS/HFrRO91Ru3avPdaIqCxgWH3 ShRw== 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=qQlkZxCZKnPJMcE0Oq5p1b0zS1PuedDR0ng2hng3Vck=; b=lhwpxv7AY1owItkvaITRJ3H8qrdJuUdTcwTIC7Al1GRvJ6RB7hGY/5tExyx9StJmBx zs0eP/rL34p/PajkvOjR85n1H1pDuIYIfDW19uB8yX8+8yCQsXxhkAN2TzX8VNcRjdS3 ApccmyIQNLJ0e86qfjYyEW0hNwJ7/tIRoBi4hwkfAFzzICL+4V5LUXFzgNp7QuBeS36B NkOyXpCMRGZ7inb2Fld0s2mJQheQcUrJ/aWdMMNVw3D66n8WI7TXr6rEVh/XnUS+QnHU ByUr5ajTF6gACzDGGRG+uKjCn+xaeA+EqO0p92IWW8nYCY4fCLpUTqeDrOGeaNpeQ/vb IqBw== X-Gm-Message-State: AOAM531fE3GRRv5UbjrkcE5Ax6ieUa3tF2wRycBTIPNLz8QTsKCHSRlg xjrBFwKk0C3zwYQx249YrwKMVh9qrLg= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:204:e552:6d5e:b69d:968c]) (user=pgonda job=sendgmr) by 2002:a05:6a00:b4e:b0:3eb:1c8d:d5d8 with SMTP id p14-20020a056a000b4e00b003eb1c8dd5d8mr24459675pfo.67.1630357040822; Mon, 30 Aug 2021 13:57:20 -0700 (PDT) Date: Mon, 30 Aug 2021 13:57:14 -0700 Message-Id: <20210830205717.3530483-1-pgonda@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog Subject: [PATCH 0/2 V6] 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. V6 * Add selftest. V5: * Fix up locking scheme * Address marcorr@ comments. 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 | 157 ++++++++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/svm/svm.h | 2 + arch/x86/kvm/x86.c | 5 + include/uapi/linux/kvm.h | 1 + 7 files changed, 182 insertions(+) base-commit: a3e0b8bd99ab Peter Gonda (3): KVM, SEV: Add support for SEV intra host migration KVM, SEV: Add support for SEV-ES intra host migration selftesting Documentation/virt/kvm/api.rst | 15 ++ arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm/sev.c | 157 ++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/svm/svm.h | 2 + arch/x86/kvm/x86.c | 5 + include/uapi/linux/kvm.h | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/x86_64/sev_vm_tests.c | 152 +++++++++++++++++ 9 files changed, 335 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/sev_vm_tests.c 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.259.gc128427fd7-goog