Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35730200rwd; Mon, 10 Jul 2023 11:39:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlEVKUU4AR6nhiDUjj6I97xuc3Gaowm1NnH9r/SSRwxVLTjx57W1T9cNmxzNWEr0zdH4tsgm X-Received: by 2002:a17:906:51d1:b0:973:daa0:2f6 with SMTP id v17-20020a17090651d100b00973daa002f6mr14560805ejk.3.1689014354550; Mon, 10 Jul 2023 11:39:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689014354; cv=none; d=google.com; s=arc-20160816; b=ilEG6qxXbvIl4yNulI7ysBDcW3jGI/Uh8qXpUvjZazRrtdUg91nxMq/eiqo0oPuajE TBX5hRKNawhsklAW4d0p2sHWg6346W7kCnnIC/Lvc6Grii51XNMt6jU8w8LTm0LGYKcr jMvzIy9JoJhoIUdR0Dx9QLVipvo7jK1v+YJP9bQg+rFWsI2I0Lvul7ivez67SSxExWYt TnyXlTFTvP4EMihcTeysT4LY0c8aaWFFNggSddpQZLraZJLHnwOcn55S4j4nZ48epiN3 IXDEydhzZkYUrIu6ia+4X1JdCtk58tOUVy3DomEDddAlJWMsWxRnblcfWCOhmkCiwmmd U94A== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=y3Kh6x6stmaNirlbTTjGLpQMo7AQpwDDe4+8wKlDwRI=; fh=1Hr1Ol8BKhMvSSmzlF9qxFBwVXeQ6d9cSuj7fFEfXzU=; b=fq/bB6iPpi1etwQlHYyQyrsB3jGBYgTLhyjdNydO2hpz+fNiqw29GCXR9JUwniBI9+ pHZpQVsQk6dqGd+aB/8VmP/YApdKlaXmopetq3FUfHsvtDK8r4mKV+k1r63JBhBmCfZl pFjDk4bYYDJaYPs9qmmhXsqKjfTZcKeYRiOo1C095tNog++7lV8di8CS5qMZ/0O+lO9z jARied6dYEja7BoTBglBPSHjYLdagCQJRz2+Y7j762rwuZaImoTp+Wg1zGXNYIYy9R2X Nrrcz8fHP0kY8vlgKUGR5kPl/gQhicdyuQrB34otf4HxidW6JXF7Fp/aFRCFegsrQNeH Llbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=gny4Y0B5; 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 i7-20020a1709064ec700b0098282dca7dcsi135218ejv.519.2023.07.10.11.38.50; Mon, 10 Jul 2023 11:39: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=20221208 header.b=gny4Y0B5; 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 S233084AbjGJR60 (ORCPT + 99 others); Mon, 10 Jul 2023 13:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229786AbjGJR6R (ORCPT ); Mon, 10 Jul 2023 13:58:17 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACCD811B for ; Mon, 10 Jul 2023 10:58:16 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-666edb1f24aso8398725b3a.2 for ; Mon, 10 Jul 2023 10:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689011896; x=1691603896; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=y3Kh6x6stmaNirlbTTjGLpQMo7AQpwDDe4+8wKlDwRI=; b=gny4Y0B5iRsAfscYzrlANXGnpPraf2ilAIKd3sBAIh7ljOzLacn90WAyUN5AvepX85 bIE3BREZHLXXu1fbO1DnDO7/Txd4D4Phqr5bv2xfc57JMqgiJJ60C7BoY78DdMgvLs3a KYwEX5FcX7Xft89IBFx/v6pb9jfduOWZpbakgiHxCgiXA4OHE1oxPucHk89myUYss1iY PgY91LPFn2VqguNAxgLSPqVNpqLRpC5llIc3264JmY+vcQUUKxR21R4GvzyLcnyDOhJZ XZjdho6cyjinpS04GxwPizzBgqrPEmndPWvsjxiTDPz86ua7yPbNWQ46I3Rh93i/g7/9 UyHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689011896; x=1691603896; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y3Kh6x6stmaNirlbTTjGLpQMo7AQpwDDe4+8wKlDwRI=; b=SctSZ6bGkyk8hM1YiA7VpwWFISClDoesoEUtsVd7LruQulm82Gp8T6VpZoOv3OTTMk mWvpsOOkJxnake1hcoi57H9mp59i2Fz/phWLUN/+zn9/WdA/fl927Xgs/JhF9AA1OMe6 Cl4TmbOx+/C/0NV8S997WZXN8L77rPMdK/QeGA3YUAgK2F6TQTYqqc88li79iHpbacVk 5raFyfKHi1oYK+f+Os7d+yGwhLKiHrl0pk0ZhImON5mppmu8uEiHTS2yKUMutdXhARx2 CWJNJ6AaGr75U4rhK7/hCKHtruUlz+uFeFC1Rs4QTivcQbX6nG/fKoC4T6lk1l0P8Vcw WPPg== X-Gm-Message-State: ABy/qLawzYghC8wmPfAFs6Gql1Q3gw0MBfmYj9Gqfvqf5udxnuzdDBaL Y4GX+JgfsWvhZ5Y+jVsedKCHWAwjtKI= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:3998:b0:668:7143:50ea with SMTP id fi24-20020a056a00399800b00668714350eamr18119150pfb.4.1689011896073; Mon, 10 Jul 2023 10:58:16 -0700 (PDT) Date: Mon, 10 Jul 2023 10:58:14 -0700 In-Reply-To: <0c32f845-aad0-3059-2efa-9f6e3bb3affb@intel.com> Mime-Version: 1.0 References: <0c9639db604a0670eeae5343d456e43d06b35d39.camel@intel.com> <20230630092615.GD2533791@hirez.programming.kicks-ass.net> <2659d6eef84f008635ba300f4712501ac88cef2c.camel@intel.com> <20230630183020.GA4253@hirez.programming.kicks-ass.net> <20230630190514.GH3436214@ls.amr.corp.intel.com> <20230704165836.GB462772@hirez.programming.kicks-ass.net> <1a8099e2-da28-6b2a-7b5a-1d6346b7f95d@intel.com> <20230705145750.GD4253@hirez.programming.kicks-ass.net> <0c32f845-aad0-3059-2efa-9f6e3bb3affb@intel.com> Message-ID: Subject: Re: [PATCH v12 07/22] x86/virt/tdx: Add skeleton to enable TDX on demand From: Sean Christopherson To: Dave Hansen Cc: Peter Zijlstra , Isaku Yamahata , Kai Huang , "kvm@vger.kernel.org" , Ashok Raj , Tony Luck , "david@redhat.com" , "bagasdotme@gmail.com" , "ak@linux.intel.com" , Rafael J Wysocki , "kirill.shutemov@linux.intel.com" , Reinette Chatre , "pbonzini@redhat.com" , "mingo@redhat.com" , "tglx@linutronix.de" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , Isaku Yamahata , "nik.borisov@suse.com" , "hpa@zytor.com" , Sagi Shahar , "imammedo@redhat.com" , "bp@alien8.de" , Chao Gao , Len Brown , "sathyanarayanan.kuppuswamy@linux.intel.com" , Ying Huang , Dan J Williams , "x86@kernel.org" Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_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 Thu, Jul 06, 2023, Dave Hansen wrote: > On 7/5/23 07:57, Peter Zijlstra wrote: > > On Wed, Jul 05, 2023 at 07:34:06AM -0700, Dave Hansen wrote: > >> On 7/4/23 09:58, Peter Zijlstra wrote: > >>> If we have concerns about allocating the PAMT array, can't we use CMA > >>> for this? Allocate the whole thing at boot as CMA such that when not > >>> used for TDX it can be used for regular things like userspace and > >>> filecache pages? > >> I never thought of CMA as being super reliable. Maybe it's improved > >> over the years. > >> > >> KVM also has a rather nasty habit of pinning pages, like for device > >> passthrough. I suspect that means that we'll have one of two scenarios: > >> > >> 1. CMA works great, but the TDX/CMA area is unusable for KVM because > >> it's pinning all its pages and they just get moved out of the CMA > >> area immediately. The CMA area is effectively wasted. > >> 2. CMA sucks, and users get sporadic TDX failures when they wait a long > >> time to run a TDX guest after boot. Users just work around the CMA > >> support by starting up TDX guests at boot or demanding a module > >> parameter be set. Hacking in CMA support was a waste. > >> > >> Am I just too much of a pessimist? > > Well, if CMA still sucks, then that needs fixing. If CMA works, but we > > have a circular fail in that KVM needs to long-term pin the PAMT pages > > but long-term pin is evicted from CMA (the whole point of long-term pin, > > after all), then surely we can break that cycle somehow, since in this > > case the purpose of the CMA is being able to grab that memory chunk when > > we needs it. > > > > That is, either way around is just a matter of a little code, no? > > It's not a circular dependency, it's conflicting requirements. > > CMA makes memory more available, but only in the face of unpinned pages. > > KVM can pin lots of pages, even outside of TDX-based VMs. > > So we either need to change how CMA works fundamentally or stop KVM from > pinning pages. Nit, I think you're conflating KVM with VFIO and/or IOMMU code. Device passhthrough does pin large chunks of memory, but KVM itself isn't involved or even aware of the pins. HugeTLB is another case where CMA will be effectively used to serve guest memory, but again KVM isn't the thing doing the pinning.