Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1996401pxb; Mon, 23 Aug 2021 09:30:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzp88wkhc55eYx8KAw+ywS7nNlAZd2ay7OgJxO8AfCrQq+ubQG/AdrwGbZ6it7+VtHkhIwt X-Received: by 2002:a17:907:3393:: with SMTP id zj19mr8922890ejb.535.1629736200974; Mon, 23 Aug 2021 09:30:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629736200; cv=none; d=google.com; s=arc-20160816; b=ycrmkFd7Nmg3Cr7n3Dw/1UjQCejejEoYKHj8sVh8I+rydd/KYlXj/w+kbI6bloYW/v /qUrS4PLmaq/Exz/p7QQmgXsWOxOpKgh011cP+la8HiPAQhTDG7C1YuvedoFKQQ2i4eE IHPUyy0m7YkqAub96bMA/3jMpTpDx/pDws1gBFJq1iE+z4RtHtt4tZn06M1v4AtHsAIZ x/U8/EP23XiQZq57xx7FLIg+qEU8Qj/d1wXd9y5ihY7UaFHCXg/M+ELgdS0fhVn++GFR 86KxOjcCH5qLj6Q8S2rwJBRQA0PP7Uz/JZrJoKOG9RbS82PhUzjMqzfqKkK7ZrsEvHTg AlHQ== 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=z+nmbEdHjJd9kCl6ax0Qt0CR58EnkRjNbiq5PgrCWGo=; b=KZiWAAdRhghS/ugAxESGjhqIzuJKk55QM6zdih6DqH5CS17euglb1cBB8okNHKnsk6 mt0nAKtWsL6phG+dFa/GCtVHjsE7qUMCMiwlCQ0+5uM+qR4nWWpjtk2NguABmG9T2Mum qz+chv6pxn2YfRnZdmh13giIwUy0hn7M1sWhZpEN1Ge0i8uITZ07FaqMm7NLIvNw0hr5 75dMfYGjvNbCSpPOdsUyJ+kqQ4QpPwbrFsdyud9tV2qDylr+yS/GSfzWWuz5iFm3BW9j sZa95wfU3MFrIEiJuq7TLccEcJjj+e4MTFK2pIbt/lI3HtZO+z1lt/wXiFS3dqTFspKm bIIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DamFGB1r; 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 b17si1371341ede.497.2021.08.23.09.29.37; Mon, 23 Aug 2021 09:30: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=20161025 header.b=DamFGB1r; 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 S229869AbhHWQ2r (ORCPT + 99 others); Mon, 23 Aug 2021 12:28:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229837AbhHWQ2r (ORCPT ); Mon, 23 Aug 2021 12:28:47 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DFCDC061575 for ; Mon, 23 Aug 2021 09:28:04 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id w200-20020a25c7d10000b02905585436b530so16905860ybe.21 for ; Mon, 23 Aug 2021 09:28:04 -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=z+nmbEdHjJd9kCl6ax0Qt0CR58EnkRjNbiq5PgrCWGo=; b=DamFGB1rYZZZIH5F92NKEYjruMrxbCl3hxTpuSGonrRna9NxtFkBeIPQ3tFA+GAFBi q91n+XJbWFdA+fWuBheP0zIm1xyHOYlKDBwkPYsPAs3ftWqcDX+MJPXYV9UkdzvN0Evg 710XbQ8U50pOF9bfZ7U4+5h8s++8gkj6KwUoMaDaqxt9NUKMuuo/ByL58nK1gWb/ZkH4 Pf2/WvCbjPYL+uZ47JtW9M/z6T+cmEnB/rrEPbyWj1E91UxM0GrMQzGMTzDS9EoXa17O QUxYucs3K+ZelvmRnXYMYpfZURekWMBMBXnObnPV7iz+6srs92Au2RS09SdgqJY4nMM3 dgpg== 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=z+nmbEdHjJd9kCl6ax0Qt0CR58EnkRjNbiq5PgrCWGo=; b=QQlLCp+AKhzgWqJTR20IpE1s0kx7y+vPg2YpqeZSTqdfX5NJS9WsdRbJj8c8oq0MFz yKOwpH2tpAwqXGFvYDckdxzEBhF+zBOXNV6RBBrOK4SsvCk8chZKmwYVWILuUZz9lYAS dJTmSkijPGK3z/zhDNt372I7k6pFVwLe5U0+iDeEy17/G3LDIKNhMT47jFLNI9xNonOa UJFpeLeXGOFl/+wDlO9jH+1eJbWado4UVBNMSOR/Ano2StSaRKBhkvVKTNarkSayfAEb MI5Lno7xVH1M1XoJyIDZl8qJBbSE+1xDTvd7dv5l+dLymXzX3SFAjkwWqKdE2e+5YR/b fhCg== X-Gm-Message-State: AOAM5308bDRHWMWUeqTEhgeFK9A2CxRMx6WdXbZGpzBLzZ3Cl6RXziYK LgFS713UnJX+UzkjqeK66iGvZ95ki3k= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:204:672c:389d:3532:4d07]) (user=pgonda job=sendgmr) by 2002:a25:8445:: with SMTP id r5mr46481398ybm.20.1629736083841; Mon, 23 Aug 2021 09:28:03 -0700 (PDT) Date: Mon, 23 Aug 2021 09:27:54 -0700 Message-Id: <20210823162756.2686856-1-pgonda@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog Subject: [PATCH 0/2 V5] 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. 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 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.rc2.250.ged5fa647cd-goog