Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7862551rwb; Wed, 23 Nov 2022 11:47:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf6xPD5OLyFCcwxVy4WKRD1+Mxp7mk1gP8X9JFVEOsYYr5sligwMmmMHf7CvSFX/DH/P5pEx X-Received: by 2002:aa7:cc12:0:b0:462:79ec:55eb with SMTP id q18-20020aa7cc12000000b0046279ec55ebmr26670853edt.151.1669232863515; Wed, 23 Nov 2022 11:47:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669232863; cv=none; d=google.com; s=arc-20160816; b=nZNOke1FB5vr/QyGboDomS774zymDmA1DBxrrIK2HCG2vLPEr57RzDYuW27ForlQJ2 +SbF07Ny5VbLTU7AmQov7vyJLVcs8pBJy/z8PEDuKgNnu+QNfIZEjKcoMZFJojdaMPcH 65Y7ZmSAM3gfnOso1ehytgc832jj75fScuennvrSHDQd53Dw8VPesNl5PK5X4oEHFRmn Koxx+mrUDHLwKvcyldRApxLLhZPyMBgnYAodZvrGk7eLKGadEC1nM+hSN1PsHaHLWq+D rTP7IMAg7v259FSuATPZ1hjWelp71vaO5VIgbAaZ0N61l3q6bXHHxIwL9OOJZEJ9DORu veoA== 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=LYJ67wF71BcvO8uwmwy3ELqCWCBu6XNQ28q/rdgvWwE=; b=m22EP/T51AIynDfH0/oIEYBABAF3wi3B9d1mvNZic2RwGL18Hi3hDmrEegov4szVRz nevKd7RKx0HHEYBTDHgNDU8o8yZNS9dYxsfFWjOBb6zn6rIg77SMkc8dGC+gYCuXUeW4 tKEnG1YzfxQh7/gte2PYArRsU8B9lq3RZcWrz4M2fOmWOxIZxbuPq0GEd1nvfpWprJVs 6H9n+snhGP1Mbt3t4OME/Qyg8UCabwoQztjZuOE4giYbZgrRNxBKfvev2dLQa4Dn90Bo lcRcj83oYkE41T95aaEOO6K7VbnXupc9eivwt+3JYiSb6gfm+dH59aUcTqab1+CpUXcc xZ8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=kBJIv846; 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 m16-20020aa7c2d0000000b004691548cccasi11320798edp.523.2022.11.23.11.47.18; Wed, 23 Nov 2022 11:47:43 -0800 (PST) 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=kBJIv846; 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 S239389AbiKWTDU (ORCPT + 88 others); Wed, 23 Nov 2022 14:03:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236590AbiKWTDR (ORCPT ); Wed, 23 Nov 2022 14:03:17 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 564DF193C9 for ; Wed, 23 Nov 2022 11:03:16 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id j12so17464757plj.5 for ; Wed, 23 Nov 2022 11:03:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=LYJ67wF71BcvO8uwmwy3ELqCWCBu6XNQ28q/rdgvWwE=; b=kBJIv846/kULBsOC5L9jGrNLZS3fxfPXvIpSe6V8KKjwhAkFe3/VeU1d/ouT9MadTV VjDbPgjJLE6oqgcuzU5VUl64diSXtWgY8VdY93piOsVtuk1rSnZxxH7H8NWwoDkgLzFF pkHhI7NXHh6IYAIVPS+FJ0NB4D8yKJd0dRK+oRH4nI7jqkIOV4X1fDlGtTmvTD7ttqj0 HkqE+xFqgfA61AEAC7QYVGk1cTAMbaJ3FZLdpoN3GZ2M+nngfbQdyXYBGL5N3QP+XK0h jVdHv/9jIznrIxuOdqAFm5hX+F5Zsji+Vr3VVof4WbE/vCxH5TDqDsQdDXSvXoyLkfNh 3r8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LYJ67wF71BcvO8uwmwy3ELqCWCBu6XNQ28q/rdgvWwE=; b=0g8iGyOSDoZGdtD7GGsmWjVj5bm/c+HskZCOvN6JK+pdRKetglw8miaIZvgLAHSLIb sL1IiKiGtcn0+qForc5zR3lis8e8OiZfAa24C0CBTPik1iBNJS2YfFr7IIBEQLahpqJ9 BuuePUl80HmSIOewTRZ1LSmEPAPJNT9PZ9mms0pujW6E6lJeQ4mQKwk6rAz2fPDSaZ92 A20to/hPmkNDsSDh84Pnwcc1iwMkHFYyiMhDHMZXfbcp3L9wwo+BGziVVmDiRdPBwLrb F81wQcz6URNaic4FsR8aRE/fEP6BfrDk+lXpwEvd6VDdcfUN0p5h8owLBK5uzN7uhaWV ARgA== X-Gm-Message-State: ANoB5pmM4UIxC7Wwb1eLdktV7gNXihguQJuk8ArHbA/UBXDRd/b4Sy8d 9PzJ86J0dylclej/zsY6paPy6g== X-Received: by 2002:a17:90a:4892:b0:216:92a9:fd50 with SMTP id b18-20020a17090a489200b0021692a9fd50mr31657292pjh.126.1669230195636; Wed, 23 Nov 2022 11:03:15 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id e190-20020a621ec7000000b00561dcfa700asm13062762pfe.107.2022.11.23.11.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 11:03:15 -0800 (PST) Date: Wed, 23 Nov 2022 19:03:11 +0000 From: Sean Christopherson To: Dave Hansen Cc: "Huang, Kai" , "peterz@infradead.org" , "kvm@vger.kernel.org" , "Luck, Tony" , "bagasdotme@gmail.com" , "ak@linux.intel.com" , "Wysocki, Rafael J" , "linux-kernel@vger.kernel.org" , "Chatre, Reinette" , "pbonzini@redhat.com" , "linux-mm@kvack.org" , "Yamahata, Isaku" , "kirill.shutemov@linux.intel.com" , "Shahar, Sagi" , "imammedo@redhat.com" , "Gao, Chao" , "Brown, Len" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "Huang, Ying" , "Williams, Dan J" Subject: Re: [PATCH v7 06/20] x86/virt/tdx: Shut down TDX module in case of error Message-ID: References: <52b2be9b-defd-63ce-4cb2-96cd624a95a6@intel.com> <791bf9a2-a079-3cd6-90a3-42dbb332a38c@intel.com> <9f1ea2639839305dd8b82694b3d8c697803f43a1.camel@intel.com> <168ca2b3-ffac-31c4-0b83-2d0ee75f34a5@intel.com> <2d99f823-09bb-ff51-0e71-f254cc6ad28b@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2d99f823-09bb-ff51-0e71-f254cc6ad28b@intel.com> 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, 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 Wed, Nov 23, 2022, Dave Hansen wrote: > On 11/23/22 09:37, Sean Christopherson wrote: > > On Wed, Nov 23, 2022, Dave Hansen wrote: > >> There's no way we can guarantee _that_. For one, the PAMT* allocations > >> can always fail. I guess we could ask sysadmins to fire up a guest to > >> "prime" things, but that seems a little silly. Maybe that would work as > >> the initial implementation that we merge, but I suspect our users will > >> demand more determinism, maybe a boot or module parameter. > > Oh, you mean all of TDX initialization? I thought "initialization" here mean just > > doing tdx_enable(). > > Yes, but the first call to tdx_enable() does TDH_SYS_INIT and all the > subsequent work to get the module going. Ah, sorry, I misread the diff. Actually applied the patches this time... > > Yeah, that's not going to be a viable option. Aside from lacking determinisim, > > it would be all too easy to end up on a system with fragmented memory that can't > > allocate the PAMTs post-boot. > > For now, the post-boot runtime PAMT allocations are the one any only way > that TDX can be initialized. I pushed for it to be done this way. > Here's why: > > Doing tdx_enable() is relatively slow and it eats up a non-zero amount > of physically contiguous RAM for metadata (~1/256th or ~0.4% of RAM). > Systems that support TDX but will never run TDX guests should not pay > that cost. > > That means that we either make folks opt-in at boot-time or we try to > make a best effort at runtime to do the metadata allocations. > > From my perspective, the best-effort stuff is absolutely needed. Users > are going to forget the command-line opt in Eh, any sufficiently robust deployment should be able to ensure that its kernels boot with "required" command-line options. > and there's no harm in _trying_ the big allocations even if they fail. No, but there is "harm" if a host can't provide the functionality the control plane thinks it supports. > Second, in reality, the "real" systems that can run TDX guests are > probably not going to sit around fragmenting memory for a month before > they run their first guest. They're going to run one shortly after they > boot when memory isn't fragmented and the best-effort allocation will > work really well. I don't think this will hold true. Long term, we (Google) want to have a common pool for non-TDX and TDX VMs. Forcing TDX VMs to use a dedicated pool of hosts makes it much more difficult to react to demand, e.g. if we carve out N hosts for TDX, but only use 10% of those hosts, then that's a lot of wasted capacity/money. IIRC, people have discussed dynamically reconfiguring hosts so that systems could be moved in/out of a dedicated pool, but that's still suboptimal, e.g. would require emptying a host to reboot+reconfigure.. If/when we end up with a common pool, then it's very likely that we could have a TDX-capable host go weeks/months before launching its first TDX VM. > Third, if anyone *REALLY* cared to make it reliable *and* wanted to sit > around fragmenting memory for a month, they could just start a TDX guest > and kill it to get TDX initialized. This isn't ideal. But, to me, it > beats defining some new, separate ABI (or boot/module option) to do it. That's a hack. I have no objection to waiting until KVM is _loaded_ to initialize TDX, but waiting until KVM_CREATE_VM is not acceptable. Use cases aside, KVM's ABI would be a mess, e.g. KVM couldn't use KVM_CHECK_EXTENSION or any other /dev/kvm ioctl() to enumerate TDX support. > So, let's have those discussions. Long-term, what *is* the most > reliable way to get the TDX module loaded with 100% determinism? What > new ABI or interfaces are needed? Also, is that 100% determinism > required the moment this series is merged? Or, can we work up to it? I don't think we (Google again) strictly need 100% determinism with respect to enabling TDX, what's most important is that if a host says it's TDX-capable, then it really is TDX-capable. I'm sure we'll treat "failure to load" as an error, but it doesn't necessarily need to be a fatal error as the host can still run in a degraded state (no idea if we'll actually do that though). > I think it can wait until this particular series is farther along. For an opt-in kernel param, agreed. That can be added later, e.g. if it turns out that the PAMT allocation failure rate is too high.