Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp19033imw; Wed, 13 Jul 2022 18:09:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vbKgHY6lFJ32rkqO/Z8mJmHjrnhaS7T8gvgpphpKIDPhvDvVC89jl5E8cDKKiXxla9O6fV X-Received: by 2002:a17:902:d50e:b0:16c:1664:81e5 with SMTP id b14-20020a170902d50e00b0016c166481e5mr5865880plg.149.1657760954643; Wed, 13 Jul 2022 18:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657760954; cv=none; d=google.com; s=arc-20160816; b=hj0ab4D9HCKGdzAjDgVfIQwFx19ierwZVA9XWiEZSC+qOX/UGV+hNoFAFZMnIkjIGE wOJdR1ODXySI8ZgoSbS1FLNnwWa5rWy1bp8kLreic0xMC3n3Lqgxrs2z2vLGSVXAN4ww W1p1rcSNvRW5eoAMHQt3CmUvg7Q3PIWqu6KFKosezETrGcFbtVTkp2W8VgLMj8Tq12Pa D/j3Myp9ibxtAP2O6vW6hWaOyXYefqScbf97qB0k6Z7BpLQoYLVNboZ7Mobq1/YU9t69 tP2YoT7r1rpTTW+IAr/Jfb9lFOd8bTs94lBdNevhSVUsSqqsn9zZ1nQWWV5CNW45rKUC YpoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iYjvT9/K+PJOYO+PKYqApFIeqrzKMwdmFTyx44M/bUw=; b=OAFGZHkiUgO79Z2pv9u1ee3OW78dtzgTSS7mB4ZfeQESeuoKkPuAIVq4wSfhGA0eqE lthJlwqr5YAQrXqn3Vu7LOEPZzCwrV0vA7sHYla30kHPWy42WoprVEGaNK1KELeC4F31 7BeMRyUDHb7JR/yPsc0Ik7ZFxBguw0h7KSDrr2ijp6F54Vlh+gKHiAouUGkgGppT+xoi jBsdYddTiEFJHT4b/61YKGsGD1566imToP8O8cElslj8bKijiCgGaL+Slj4wtSwDU30Q uNi4MsuiB313CasXFirrQaVw1BjvxfUQUVKU/SexzO1E2UwtPO2ANPNckX8L0x0V/A/y +1cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=s9pNVCwJ; 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 p23-20020a170902a41700b00163e31eb390si193640plq.280.2022.07.13.18.09.02; Wed, 13 Jul 2022 18:09:14 -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=20210112 header.b=s9pNVCwJ; 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 S231206AbiGNBDy (ORCPT + 99 others); Wed, 13 Jul 2022 21:03:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbiGNBDw (ORCPT ); Wed, 13 Jul 2022 21:03:52 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61A9D11C2F for ; Wed, 13 Jul 2022 18:03:51 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id a15so467059pfv.13 for ; Wed, 13 Jul 2022 18:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=iYjvT9/K+PJOYO+PKYqApFIeqrzKMwdmFTyx44M/bUw=; b=s9pNVCwJpiRtqZOHmC9JoqSbIHVFh0WcP6GlOiQEvWpNg9ctAYIL9TC74ZHJwDmQbr ujX1YfT+IVTqR8HVG+hTZliHN024gh9S9Pg203g/w/Bao0+j+IoHioLNgvk11I+ChPBk HBHnskhUnzqC/Gn8ign5LtntTGXrnDE107IPN5/vDkLHTKg5XJ/pfYVAF5ISWRKbRMkD b4xbcglZ2QBxniVLRlcKW864QEwH+3hXRWfFtaWOj9jOLSfGgLSTEhToYfsI6cPh/sfk HO7/3PgNobJRxm1haK+WNfLJm+yjw8/yi9baTclGMlllGg2hKHJB+0zk4WjqcoAqIKYT UlOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=iYjvT9/K+PJOYO+PKYqApFIeqrzKMwdmFTyx44M/bUw=; b=xUb7ec2ImRoZ8/9NuYjdu/0Ui4HKSpaxYC2VnaZXB1lCRa3Qm+a0AnRm8m9V76lfYS /ct6fDWfMGvZ192sYAwE5dGmPrqgfZZKehht0pktkJCgU/kHHqRezy0Et+B1PQc7FMAT abIYsE+SMOO2PGVNA1U9YT8GdmYW2q9poGsWDyyUT6QKTJW4Up3p/gzK1nAjUTls0xAo UD8IewCN8rBuTwLT8ymqr0cL24NVpMYwxtU6ktQyu+Oo/w40Hfr2mOioH7TZ5kpvRIb/ hfbjQEJschZ/gFe3DvfN7/EAMzm6z8v9Cuy0g6SprGWJphh9uFLez4fbSgjvSpPdvvtZ tgNg== X-Gm-Message-State: AJIora/62Yv05ArA688cNb664n2Usjza4Odkiy4OkHDK6AhCKkerKAkE cfXV+OnUKpV8XdlOiXGvzQWBsA== X-Received: by 2002:a62:e10d:0:b0:52a:b77e:8bd3 with SMTP id q13-20020a62e10d000000b0052ab77e8bd3mr5810419pfh.66.1657760630794; Wed, 13 Jul 2022 18:03:50 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id g21-20020aa796b5000000b005289cade5b0sm170538pfk.124.2022.07.13.18.03.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 18:03:49 -0700 (PDT) Date: Thu, 14 Jul 2022 01:03:46 +0000 From: Sean Christopherson To: isaku.yamahata@intel.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini Subject: Re: [PATCH v7 000/102] KVM TDX basic feature support Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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=ham 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 Mon, Jun 27, 2022, isaku.yamahata@intel.com wrote: > From: Isaku Yamahata > > KVM TDX basic feature support > > Hello. This is v7 the patch series vof KVM TDX support. > This is based on v5.19-rc1 + kvm/queue branch + TDX HOST patch series. > The tree can be found at https://github.com/intel/tdx/tree/kvm-upstream > How to run/test: It's describe at https://github.com/intel/tdx/wiki/TDX-KVM > > Major changes from v6: > - rebased to v5.19 base > > TODO: > - integrate fd-based guest memory. As the discussion is still on-going, I > intentionally dropped fd-based guest memory support yet. The integration can > be found at https://github.com/intel/tdx/tree/kvm-upstream-workaround. > - 2M large page support. It's work-in-progress. > For large page support, there are several design choices. Here is the design options. > Any thoughts/feedback? Apologies, I didn't read beyond the intro paragraph. In case something like this comes up again, it's probably best to send a standalone email tagged RFC, I doubt I'm the only one that missed this embedded RFC. > KVM MMU Large page support for TDX ... > * options to track private or shared > At each page size (4KB, 2MB, and 1GB), track private, shared, or mixed (2MB and > 1GB case). For 4KB each page, 1 bit per page is needed. private or shared. For > large pages (2MB and 1GB), 2 bits per large page is needed. (private, shared, or > mixed). When resolving KVM page fault, we don't want to check the lower-size > pages to check if the given GPA can be a large for performance. On MapGPA check > it instead. > > Option A). enhance kvm_arch_memory_slot > enum kvm_page_type { > KVM_PAGE_TYPE_INVALID, > KVM_PAGE_TYPE_SHARED, > KVM_PAGE_TYPE_PRIVATE, > KVM_PAGE_TYPE_MIXED, > }; > > struct kvm_page_attr { > enum kvm_page_type type; > }; > > struct kvm_arch_memory_slot { > + struct kvm_page_attr *page_attr[KVM_NR_PAGE_SIZES]; > > Option B). steal one more bit SPTE_MIXED_MASK in addition to SPTE_SHARED_MASK > If !SPTE_MIXED_MASK, it can be large page. > > Option C). use SPTE_SHARED_MASK and kvm_mmu_page::mixed bitmap > kvm_mmu_page::mixed bitmap of 1GB, root indicates mixed for 2MB, 1GB. > > > * comparison > A). > + straightforward to implement > + SPTE_SHARED_MASK isn't needed > - memory overhead compared to B). or C). > - more memory reference on KVM page fault > > B). > + simpler than C) (complex than A)?) > + efficient on KVM page fault. (only SPTE reference) > + low memory overhead > - Waste precious SPTE bits. > > C). > + efficient on KVM page fault. (only SPTE reference) > + low memory overhead > - complicates MapGPA > - scattered data structure Option D). track shared regions in an Xarray, update kvm_arch_memory_slot.lpage_info on insertion/removal to (dis)allow hugepages as needed. + efficient on KVM page fault (no new lookups) + zero memory overhead (assuming KVM has to eat the cost of the Xarray anyways) + straightforward to implement + can (and should) be merged as part of the UPM series I believe xa_for_each_range() can be used to see if a given 2mb/1gb range is completely covered (fully shared) or not covered at all (fully private), but I'm not 100% certain that xa_for_each_range() works the way I think it does.