Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp22929951rwd; Fri, 30 Jun 2023 15:02:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlHf7O2xaAbViMLNaKJar2qJVHf7A5e+YQ9m47VEBPA3XBVl7dOZSbEZTmeqd/0+n2MCNhiz X-Received: by 2002:a17:90a:7487:b0:25e:c1ff:2cd with SMTP id p7-20020a17090a748700b0025ec1ff02cdmr3273596pjk.30.1688162579234; Fri, 30 Jun 2023 15:02:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688162579; cv=none; d=google.com; s=arc-20160816; b=KUAprFOqgMI5oBdrJ7RnHSmMWDRGTSrgennd6FLdSKpX4nfx3VgNr7d3rEcoeIF0iE 10mEvPYY88tdY5abpsd6aNy7MXus/K5iwaXPaucLQkyI7lHA2I/0Vfp930RvAeJ0PPAz VVBldmhnKv/jmFyqim7Ka71OSEztIKKnPL41F6sWCWITNt/h8GNwmTPd4mEWDo+WtJdG 0b9dvoz/QMHGrs9Y2r8vfSY4dG1Y5/EEYM5wWWN+tDc7iYSuSBOydq2dUsCN1OH/Hwsn fC4i1ivrZ1mKhqcTHr5gpaU6y9ngZxSB5RZX28PCDW8LWhVP/mV6CfeB4W5pBEGj0SZZ Sexg== 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=9OuqO+GprsYwzlZrAMxO302oe0WdyZWBaVRgt/0KOVc=; fh=Rg7FCIz7vhZyeffq+Kc02qbWwVfRGLYvPbg/IUYlNmA=; b=sJwzYWu0RXQx2VCsLFDIapX6oUK8JDfoku/IzhiiUhekyKnVWK0H72zwVDti3H97VV HByEVeoeSlizR8WHFmZNNX23CPZ5QDGsRyE2v2C8dtUsxCUgL+uJvgRQJdmeZntMgdbA 8SJGPiCJ6Q+rGsxTxMeXxEjNiTjcsc3wE/6tiQbRjl2cZBrYgH1HkXUK/ewNk5DzkAGR RujfHJplLHU+7j9YIz6p5aj8DBMoaWzoZy594RS4W1qnP7zjX2dMWUL/WBu3k9w1kZ6R vmVTUK6I9nRhDF+AfeLLh8g0w2Q7TE1Vo8zNgGUnMBlcahv+kae0MnFjnuqszFFNmTDu pa/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=C98VfhGL; 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 k7-20020a635607000000b005585b14499fsi11748814pgb.326.2023.06.30.15.02.44; Fri, 30 Jun 2023 15:02:59 -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=C98VfhGL; 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 S231937AbjF3VZB (ORCPT + 99 others); Fri, 30 Jun 2023 17:25:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229560AbjF3VY7 (ORCPT ); Fri, 30 Jun 2023 17:24:59 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B556F2686 for ; Fri, 30 Jun 2023 14:24:58 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bfebb1beeccso2197813276.2 for ; Fri, 30 Jun 2023 14:24:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688160298; x=1690752298; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9OuqO+GprsYwzlZrAMxO302oe0WdyZWBaVRgt/0KOVc=; b=C98VfhGLNA5xfbBYxeu79VpxIy9gRA6nupPJlAfe0FuPEfw/4GPR1LutGEmbPkU+D6 LCsyyk7D1OMMbPdZuqJ9pRQyj5bW6ckdCA5JJQ6l1LqK6+B3WHfFhFGW1zF4WhSDt95B 76niGAHa2KUaUlGFoU46LfHpWIdnS1uFr74lXzrCCEehASUT/Zkr0bpM7jQ7BSmVFXYz a2YxzWzm0vujdecLtLgB25IIGiMTe9YiFVK4SJ/eBhMlwZW3PKId1fdZAWpVYfILXO43 OkuMAJ9vMYtxDqrigZ3s9PiQR/RD0SJ2XoRA2Xh0FFvQ/TxS2T5r8RXuCsiv02v77dUv kuPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688160298; x=1690752298; 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=9OuqO+GprsYwzlZrAMxO302oe0WdyZWBaVRgt/0KOVc=; b=RQ09LRK46IEaZApWzcx6epoOoU0mD32LO50aDTi7HiwyiHOQoyK4RGbNTfeKF+KP/D kf5HqzFvYqxsqglC3R8Y9SVuhofE04/zA8P6kSorXbEvDhQf3eUAiyyUZ/isZMEBg7UC dX1B7ACOMx/nkruhh92qyTNy05XZRKKxrN3jv7cF0NpjuGNYILpDjVi7BzrM/3M5t6Qd Mgk4POmQGDXGjcRxwtSx7mVui3x24olhieN6dfTU+lERpmMs/tm2vTQzo34KfwNCkOzD tsJyy1B6XS9O9MCr0OKeB21JjBQcdt33w1eGEYPgw9Tn1q+4U8aeOy+ClXOz5rYoOYvm /rGQ== X-Gm-Message-State: ABy/qLbAQkAjWD/u2TdZ4jYVKuKcf9Tbf5fsFlkpM79r2EMp3l//nVUt rtNubb8noz/nDVcZ+ZeTN1hhHB00uP8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:4183:0:b0:c1e:f91c:2691 with SMTP id o125-20020a254183000000b00c1ef91c2691mr37547yba.10.1688160297945; Fri, 30 Jun 2023 14:24:57 -0700 (PDT) Date: Fri, 30 Jun 2023 14:24:56 -0700 In-Reply-To: <20230630190514.GH3436214@ls.amr.corp.intel.com> Mime-Version: 1.0 References: <104d324cd68b12e14722ee5d85a660cccccd8892.1687784645.git.kai.huang@intel.com> <20230628131717.GE2438817@hirez.programming.kicks-ass.net> <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> Message-ID: Subject: Re: [PATCH v12 07/22] x86/virt/tdx: Add skeleton to enable TDX on demand From: Sean Christopherson To: Isaku Yamahata Cc: Peter Zijlstra , Kai Huang , "kvm@vger.kernel.org" , Ashok Raj , Tony Luck , "david@redhat.com" , "bagasdotme@gmail.com" , Dave Hansen , "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_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_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 Fri, Jun 30, 2023, Isaku Yamahata wrote: > On Fri, Jun 30, 2023 at 08:30:20PM +0200, > Peter Zijlstra wrote: > > > On Fri, Jun 30, 2023 at 09:55:32AM +0000, Huang, Kai wrote: > > > On Fri, 2023-06-30 at 11:26 +0200, Peter Zijlstra wrote: > > > > On Thu, Jun 29, 2023 at 12:10:00AM +0000, Huang, Kai wrote: > > > > > On Wed, 2023-06-28 at 15:17 +0200, Peter Zijlstra wrote: > > > > > > On Tue, Jun 27, 2023 at 02:12:37AM +1200, Kai Huang wrote: > > > > > > > +EXPORT_SYMBOL_GPL(tdx_cpu_enable); > > > > > > > > > > > > I can't find a single caller of this.. why is this exported? > > > > > > > > > > It's for KVM TDX patch to use, which isn't in this series. > > > > > > > > > > I'll remove the export. KVM TDX series can export it. > > > > > > > > Fair enough; where will the KVM TDX series call this? Earlier there was > > > > talk about doing it at kvm module load time -- but I objected (and still > > > > do object) to that. > > > > > > > > What's the current plan? > > > > > > > > > > The direction is still doing it during module load (not my series anyway). But > > > this can be a separate discussion with KVM maintainers involved. > > > > They all on Cc afaict. > > > > > I understand you have concern that you don't want to have the memory & cpu time > > > wasted on enabling TDX by default. For that we can have a kernel command line > > > to disable TDX once for all (we can even make it default). > > > > That's insane, I don't want to totally disable it. I want it done at > > guard creation. Do the whole TDX setup the moment you actually create a > > TDX guast. > > > > Totally killing TDX is stupid, I dunno about that, *totally* killing TDX would make my life a lot simpler ;-) > > just about as stupid as doing it on module load (which equates to always > > doing it). > > > > > Also, KVM will have a module parameter 'enable_tdx'. I am hoping this could > > > reduce your concern too. > > > > I don't get this obsession with doing at module load time :/ Waiting until userspace attempts to create the first TDX guest adds complexity and limits what KVM can do to harden itself. Currently, all feature support in KVM is effectively frozen at module load. E.g. most of the setup code is contained in __init functions, many module-scoped variables are effectively RO after init (though they can't be marked as such until we smush kvm-intel.ko and kvm-amd.ko into kvm.ko, which is tentatively the long-term plan). All of those patterns would get tossed aside if KVM waits until userspace attempts to create the first guest. The userspace experience would also be poor, as KVM can't know whether or TDX is actually supported until the TDX module is fully loaded and configured. KVM waits until VM creation to enable VMX, but that's pure enabling and more or less guaranteed to succeed, e.g. will succeed barring hardware failures, software bugs, or *severe* memory pressure. There are also latency and noisy neighbor concerns, e.g. we *really* don't want to end up in a situation where creating a TDX guest for a customer can observe arbitrary latency *and* potentially be disruptive to VMs already running on the host. Userspace can workaround the second and third issues by spawning a dummy TDX guest as early as possible, but that adds complexity to userspace, especially if there's any desire for it to be race free, e.g. with respect to reporting system capabilities to the control plan. On the flip side, limited hardware availability (unless Intel has changed its tune) and the amount of enabling that's required in BIOS and whatnot makes it highly unlikely that random Linux users are going to unknowingly boot with TDX enabled. That said, if this is a sticking point, let's just make enable_tdx off by default, i.e. force userspace to opt-in. Deployments that *know* they may want to schedule TDX VMs on the host can simply force the module param. And for everyone else, since KVM is typically configured as a module by distros, KVM can be unloaded and reload if the user realizes they want TDX well after the system is up and running. > The KVM maintainers prefer the initialization on kvm_intel.ko loading time. [1] You can say "Sean", I'm not the bogeyman :-) > I can change enable_tdx parameter for kvm_intel.ko instead of boolean. > Something like > > enable_tdx > ondemand: on-demand initialization when creating the first TDX guest > onload: initialize TDX module when loading kvm_intel.ko No, that's the most complex path and makes no one happy. > disable: disable TDX support