Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp971205rwe; Fri, 14 Apr 2023 12:13:04 -0700 (PDT) X-Google-Smtp-Source: AKy350bUFkeL3WTYlrFnU9Sei2EodcI1MTF5WzRo0x5T8b8uMdV8gFdR4XoGS8Rqg1DZZ+w8CpHH X-Received: by 2002:a05:6a20:c40a:b0:ec:4e19:fbff with SMTP id en10-20020a056a20c40a00b000ec4e19fbffmr6233622pzb.46.1681499583840; Fri, 14 Apr 2023 12:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681499583; cv=none; d=google.com; s=arc-20160816; b=WsSEmk4swKlZpj/jaqeMeTCvadhvUazv3Q4+QVoG5FD40FrKItmL1ZI5rDTyHJdK30 FfoXhVLBwBQEbbNSRkc+A/eVU/BNjT9EgkMOnZ6SygctACzl3KCZ+ufjlJTHTANNy/pn 4EJSnbR0Q800rVjzMrG7lEhfc3TASzHADWEKD5BhzdV8rwjkLAEx78JPVImlLgfjspTF bE4Db5SUODOOd1jw5IfOYg1smO2+lXyWKPR/mWBtoPnQ5NSQ5JQw+jyp04Y4Z1O9UoRJ yIH1UwNXMPoBWNx8WrMwnXsCuZQdmVq2Ruo3Rnvuxp5I2fK8TRCZKuwMDzl8t7pNUtwl scuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=jVnUlhBA6jdlz83dcJuvBqHrUvd0hrnnS1oyxuPo19o=; b=QyeAGengL4oaUKZeafci1ziLvX0Rm9lgHXWKgFfP3fWBc7xc0YRApx1Zm8PQeW6YmR 77saD++NNb5c4lkw/1sx0pEzx2I5+SlcVscPmRQbuEHg1ChCxC3spazVFgEqP9Co+wtC ex7ugeeU6NkCAKbAbuKzsMhP7HdEfJka6QAcXa7wF3YYI077VMdWI018eE+tN8WN3ZIa lRXy4JldQXEyNz6NW0UYzxz3pM6GRc50aIFPBkrf52mKi3gYRW6A7vhHTfkudgzgUIQe gR3oXsJ4SdsKOmAF6mabEL2bWkeO7WJbErg9J2SStP31Xf7YIHbKd+MRC6Iw3gH+fWou MtLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=n+f05nLe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y72-20020a638a4b000000b0051b7f3f862esi1162238pgd.824.2023.04.14.12.12.51; Fri, 14 Apr 2023 12:13:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=n+f05nLe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229941AbjDNTJe (ORCPT + 99 others); Fri, 14 Apr 2023 15:09:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjDNTJc (ORCPT ); Fri, 14 Apr 2023 15:09:32 -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 C7C4D1991 for ; Fri, 14 Apr 2023 12:09:28 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id u12so6950130lfu.5 for ; Fri, 14 Apr 2023 12:09:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681499367; x=1684091367; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=jVnUlhBA6jdlz83dcJuvBqHrUvd0hrnnS1oyxuPo19o=; b=n+f05nLeF9RRty+4PwYX2MJg35RU6XoRr+aQ19NimDsWDexyxXCssREQrw7SW0a+os Iiyatkx5HMRAITqlMSWlD250jp074ZpMQTZFA9Vky6cBe5M6L6C/uopa5mUK/zjuNVJb mClWHu6XEOn0ft7bPzsulddypbIq4+JXVkzb3TDdSYLGoxD0G7qLgrfaKJwrR+rC3UXG 7n5F9ieBZ4jJ+6Hm4PAmAL+JEDjSlXNfjMTDTg+bc390JlShIvanch/UD0BJlrQFiWrM ZzRil+jfJNwT5qx/fUzCxC2Ye7qfT8f+Z7Hq9HvjsbyRoiW4q+v5DRRf1TX7TOPQmfRL 69WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681499367; x=1684091367; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jVnUlhBA6jdlz83dcJuvBqHrUvd0hrnnS1oyxuPo19o=; b=Dwutmq2lg0W5EQe5BNnDFLEdoVpS5C8xUlWmVoeUat/2+WObSXmuGo767C2SvtBgeS rmin0NmoGQ0J5z/cNs/ho9S6IkeHEAuiAuZuQytCEkGsBAnAciwNgKoY/t5b20dRzh4j eR4XLzE0NvYNOrJjS/+I56daWr6k++2fPCkBrRpS1dbCrjjIkNNqgV3tbEO2biBKtMOO sMMBpspDh9povwN1C17+2tEIeFipwUTTW2jwfBQa6MNQhpZOjCzmZouMPhi27fqPpEIj 0AtiXX6KDzjtw+eqPN82cUHkYxcq813HGPbpXHlRB9JXNEikn6pDE+hDTFhLFTUH3j4H GwMg== X-Gm-Message-State: AAQBX9eNtI9WUhjn899MLUNmpP5Pqql5GzapGAisiif6dojf3IYxKpcy lzuLU+SdoME0KJTJcHnlge/nApMJxpvUfwcYsGOadA== X-Received: by 2002:ac2:454e:0:b0:4db:1c2a:a96e with SMTP id j14-20020ac2454e000000b004db1c2aa96emr39617lfm.9.1681499366734; Fri, 14 Apr 2023 12:09:26 -0700 (PDT) MIME-Version: 1.0 References: <20230407201921.2703758-1-sagis@google.com> <20230414100350.00000955.zhi.wang.linux@gmail.com> In-Reply-To: <20230414100350.00000955.zhi.wang.linux@gmail.com> From: Sagi Shahar Date: Fri, 14 Apr 2023 12:09:15 -0700 Message-ID: Subject: Re: [RFC PATCH 0/5] Add TDX intra host migration support To: Zhi Wang Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Sean Christopherson , Paolo Bonzini , Isaku Yamahata , Erdem Aktas , David Matlack , Kai Huang , Chao Peng , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 14, 2023 at 12:04=E2=80=AFAM Zhi Wang wrote: > > On Fri, 7 Apr 2023 20:19:16 +0000 > Sagi Shahar wrote: > > Hi: > > Is there any userspace using these APIs? I cant find them in AMD-QEMU rep= o > and upstream QEMU repo. It would nice to first take a look on how userspa= ce > is going to use it. > We are using a different userspace VMM internally so we didn't make changes to QEMU. I've uploaded our selftests which exercise these APIs to our public GitHub so you can take a look there: https://github.com/googleprodkernel/linux-cc/commit/62c8dba4c3cf06e37501807= 7a6d9f491c933dc6d Note that these are a slightly older version based on TDX V10 API. They also use the KVM_CAP_VM_COPY_ENC_CONTEXT_FROM instead of KVM_CAP_VM_MOVE_ENC_CONTEXT_FRO= M > > This patchset adds support for TDX intra host migration using the same > > API which was added for SEV intra host migration here: > > https://lore.kernel.org/all/20211021174303.385706-1-pgonda@google.com/ > > > > This patchset relies on the latest TDX patches from Intel: > > - fd-based approach for supporing KVM v10 and > > https://lore.kernel.org/lkml/20221202061347.1070246-1-chao.p.peng@lin= ux.intel.com/ > > - TDX host kernel support v10 > > https://lore.kernel.org/lkml/cover.1678111292.git.kai.huang@intel.com= / > > - KVM TDX basic feature support v13 > > https://lore.kernel.org/cover.1678643051.git.isaku.yamahata@intel.com > > > > The tree can be found at https://github.com/googleprodkernel/linux-cc/t= ree/copyless > > and is based on Intel's tdx tree at https://github.com/intel/tdx/tree/k= vm-upstream > > > > In the TDX case, we need to transfer the VM state from multiple sources= : > > > > * HKID and encrypted VM state is transfered between the kvm_tdx > > objects. > > * Encrypted and runtime state is transfered between the vcpu_tdx > > objects. > > * The EPT table backing TD's private memory is transfered at the > > kvm-mmu level. This is needed since the secure EPT table managed by > > the TD module remains the same after the migration so moving the > > current private EPT table eliminates the need to rebuild the private > > EPT table to match the secure EPT table on the destination. > > * Information regarding the current shared/private memory is trasfered > > using the mem_attr_array stored at the kvm object. > > * Additional information derived from shared/private memory state is > > trasfered at the memslot level. > > > > Tested with selftests locally. I will attach the self test in the next > > version after we send the new TDX selftest framework patches based on > > KVM TDX basic feature support v13. > > > > Sagi Shahar (5): > > KVM: Split tdp_mmu_pages to private and shared lists > > KVM: SEV: Refactor common code out of sev_vm_move_enc_context_from > > KVM: TDX: Add base implementation for tdx_vm_move_enc_context_from > > KVM: TDX: Implement moving private pages between 2 TDs > > KVM: TDX: Add core logic for TDX intra-host migration > > > > arch/x86/include/asm/kvm_host.h | 5 +- > > arch/x86/kvm/mmu.h | 2 + > > arch/x86/kvm/mmu/mmu.c | 60 ++++++++ > > arch/x86/kvm/mmu/tdp_mmu.c | 88 +++++++++++- > > arch/x86/kvm/mmu/tdp_mmu.h | 3 + > > arch/x86/kvm/svm/sev.c | 175 +++-------------------- > > arch/x86/kvm/vmx/main.c | 10 ++ > > arch/x86/kvm/vmx/tdx.c | 245 ++++++++++++++++++++++++++++++++ > > arch/x86/kvm/vmx/tdx.h | 2 + > > arch/x86/kvm/vmx/x86_ops.h | 5 + > > arch/x86/kvm/x86.c | 166 ++++++++++++++++++++++ > > arch/x86/kvm/x86.h | 16 +++ > > 12 files changed, 613 insertions(+), 164 deletions(-) > > >