Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2800340pxb; Tue, 12 Oct 2021 13:50:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2DEl8aXEg7Ldtf7ySSme55B21NzehgeS5TGq5kXQRKOEjcgYAt1wEbSNrMSQiwENpfMjr X-Received: by 2002:a17:90a:7148:: with SMTP id g8mr8366463pjs.221.1634071828393; Tue, 12 Oct 2021 13:50:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634071828; cv=none; d=google.com; s=arc-20160816; b=lv6VBEGzw3cMxXvrbilA9/aHurOY9/kuiuvKW00GJxgVEcaawDQJlpT2q4iXTx0kTM miN9mvxYbPGmKjikeA857kR0thRjaJ17ytqpWO7nXw1iP81GVZ1N6+QmyxFT8xUcB0fO fe/d6g1WO4V5AN+c1EbZf1w+F2AdzNnbnhzw3LVRezeORcAUhAzFRmHqSW/NVy4Y5B8b E+1PL0XaK/f20Cr87rU3NvpxRIt05hNEJF/JNv8dC8Fc1A/RmOzdX/F7nBUTR3T1ePED j4weJx1HQhwH7hSQaDtJ/JRX48vDXkyG8vTl/hWSjq5j7WtzkdzuIjAnKaO3qqN3H5Uh C3bA== 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=teEEhVWJN+Qa6H6Qk1wKq131PVGwnj7NNqky10GsyoI=; b=WQOgRUy+NFKPv5j6G/NRrPDsuOaR9Ar3qJ7Kx4fasIN3yEBPdbSvdRL15R/XTYyimW QsQLdhGkHxJRW3s4WsSsQGiNzvU9n+nIgYkaMC9QLaiwdtsrhuNg13XWogET03QYwNji aG/ClZ2fwijkRogOf3p266Oy2+tM/7V18dHgz3QNySkgwz+ayQzVaG7PITEIMy2iiqds 21gF05Izm5ADoBDYuJRKZHA3KgEymX4jJ1bWoaOvynwtOoL7nJfVCOivpMnQfgVQmITY SOAduMTBSkA/tV12yqT0EbHVGUZRKRzB8t7ppj0q4owjsdNGCiSFv05hReY8aGhFBRJ7 E0hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OiGTRrza; 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 v15si4605987pjt.92.2021.10.12.13.50.15; Tue, 12 Oct 2021 13:50:28 -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=OiGTRrza; 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 S235137AbhJLUvN (ORCPT + 99 others); Tue, 12 Oct 2021 16:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234757AbhJLUvF (ORCPT ); Tue, 12 Oct 2021 16:51:05 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85D1AC061570 for ; Tue, 12 Oct 2021 13:49:03 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id n1-20020a05622a11c100b002a749aace38so498514qtk.4 for ; Tue, 12 Oct 2021 13:49:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=teEEhVWJN+Qa6H6Qk1wKq131PVGwnj7NNqky10GsyoI=; b=OiGTRrzaxSz0x5HSUuTg4hDTD/OeCBAaD/mWV8UZ8XyjJG/gdgfKyZcn0SQPwisM+h fXqoflM2sv0pCaZUKFh6qXeNq3Vd+aNA3I0J0Q2TL1yC4iw4fc25ZGn1XbPKhRO9rKLV eLlEt/S+g02f1ZSqsow1cq5Ce6FY2ZhJzliLWojrXbuSpDTC7Y/AAlvthgYohIzgl7X3 KR4tLcEk8wR1f+i93CD2P3zvLCZhqQGopG9tAh/QCC78f2zvgC0nWq3+WTQZ5OpxY5LS cctPwwBnkZ+h0SJW5XJWeYRFEcD1IPUnuuToF19ElOm8dOhe/7me0v5RLB267vWGMCf6 pJpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=teEEhVWJN+Qa6H6Qk1wKq131PVGwnj7NNqky10GsyoI=; b=W8uBRJ5dX0QDH/LuZmjXmwTbJLuQ2tJ10iSW9CFn8abu+nAGZBlCnXbElzI+Qn/k0c l+jjfTTics124VLYnHPQRDmvwPaLqwpmKfd5EdLpgJZ8k3ilJ4s96G4o4XBCqUfpzuoz ZKLxrGShgjmNvq4nwjE/ca86j+VAVFdmzOOExzfA1Z2jmnw2FBpI1l8p5uDGEWslTdP2 XdcGEZfde1zye1vUAgypHPx7Yf2LBjsL1pW/d2PgyNfcrA64Acbczm4+K3GgOkv1KO87 AfxwnrDghNs0/Vch5MQXvMD+4FzsCTOdkZCitREwbvyPkO9oK4J7016OvMC47uTFOYyp Ilww== X-Gm-Message-State: AOAM532hhkn64J6VgFhadKsCEJCX7EzylvC2BRnqXqT9foJo77/bb8L4 SuWcOGJtFQWNf/EBGQ/Mxq0tKoNPSmo= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:204:bab5:e2c:2623:d2f8]) (user=pgonda job=sendgmr) by 2002:ac8:5e14:: with SMTP id h20mr24196018qtx.364.1634071742702; Tue, 12 Oct 2021 13:49:02 -0700 (PDT) Date: Tue, 12 Oct 2021 13:48:53 -0700 Message-Id: <20211012204858.3614961-1-pgonda@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH 0/5 V10] Add AMD SEV and SEV-ES intra host migration support From: Peter Gonda To: kvm@vger.kernel.org Cc: Peter Gonda , Marc Orr , Paolo Bonzini , Sean Christopherson , David Rientjes , "Dr . David Alan Gilbert" , Brijesh Singh , Tom Lendacky , 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). V10 * Add new starting patch to refactor all SEV-ES related vCPU data into for easier copying. V9 * Fix sev_lock_vcpus_for_migration from unlocking the vCPU mutex it failed to unlock. V8 * Update to require that @dst is not SEV or SEV-ES enabled. * Address selftest feedback. V7 * Address selftest feedback. 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/ base-commit: 2acbc5c9a0ec Cc: Marc Orr Cc: Paolo Bonzini Cc: Sean Christopherson Cc: David Rientjes Cc: Dr. David Alan Gilbert Cc: Brijesh Singh Cc: Tom Lendacky 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 Peter Gonda (5): Refactor out sev_es_state struct KVM: SEV: Add support for SEV intra host migration KVM: SEV: Add support for SEV-ES intra host migration selftest: KVM: Add open sev dev helper selftest: KVM: Add intra host migration tests Documentation/virt/kvm/api.rst | 15 + arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm/sev.c | 264 +++++++++++++++--- arch/x86/kvm/svm/svm.c | 9 +- arch/x86/kvm/svm/svm.h | 28 +- arch/x86/kvm/x86.c | 6 + include/uapi/linux/kvm.h | 1 + tools/testing/selftests/kvm/Makefile | 3 +- .../testing/selftests/kvm/include/kvm_util.h | 1 + .../selftests/kvm/include/x86_64/svm_util.h | 2 + tools/testing/selftests/kvm/lib/kvm_util.c | 24 +- tools/testing/selftests/kvm/lib/x86_64/svm.c | 13 + .../selftests/kvm/x86_64/sev_vm_tests.c | 203 ++++++++++++++ 13 files changed, 504 insertions(+), 66 deletions(-) create mode 100644 tools/testing/selftests/kvm/x86_64/sev_vm_tests.c -- 2.33.0.882.g93a45727a2-goog