From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1DA6C433FE for ; Wed, 23 Nov 2022 19:03:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D8E26B0071; Wed, 23 Nov 2022 14:03:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 088626B0073; Wed, 23 Nov 2022 14:03:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB9F66B0074; Wed, 23 Nov 2022 14:03:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DB2956B0071 for ; Wed, 23 Nov 2022 14:03:17 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9CD6EC05B4 for ; Wed, 23 Nov 2022 19:03:17 +0000 (UTC) X-FDA: 80165630034.03.CD2EEF5 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf26.hostedemail.com (Postfix) with ESMTP id 1230814001E for ; Wed, 23 Nov 2022 19:03:16 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id k7so17459793pll.6 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=SbWg3IHD3cBUPkqftR9QUF9JGR+qZQV+wsc82bAGF7pHagaqRn6gGVsEy6XoNtWqNm uw9Rp1H9sOW98gUDFum0FRJdthcvhcaSptlc1699UI4lwi+o8tnK7XN8F2Sg6xLowbZs Q4MITvsnFrIiWXCGzwg8SR2FwIvQ9kkEAnrJIwywYZLc3xJZAX+HUmq8jNVdkqRpfWuw pMofmazWXAzMhwrR4AdhWDTjqEJ/qXuy9snyxUFjVJ3g/UDD6pETbRORWBSlPSNJUsUr 5Zdk5irsjJ2xkVDQ2H2ATjoAqFrkWznNb6tEtjdfblmifx/6+NsTwQjoHxQ3BtsuIowN 5S1Q== X-Gm-Message-State: ANoB5pmu2FmwhBnojvBqeCZW5np7moCfN35EHvrfbhSHFyxw9i1gwIP7 ipoG/18vlpGo2pZZiknjsrQP7A== X-Google-Smtp-Source: AA0mqf43KIjDGaGB0pVG3YdJhNXRRLbEvrskIfFRe6WjPffa9ZDsSSfHhzpMw/UYkiwwF3z8aHFfTg== 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> ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=kBJIv846; spf=pass (imf26.hostedemail.com: domain of seanjc@google.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669230197; a=rsa-sha256; cv=none; b=TT1shW1ou+PpFN1u9eXpZhVY5uLujr6fladz83xDXTmV/YggNoXoTz2/vFSi9HmHvVkzR2 2HL62jcLbA8XwUPFaBcFptJHHc4HzCxbRIczXkj42q7VCbiK9hcbAIDMRvqTk4bYXN0E4l VY4cqiOF0pOWzUa2qI8dVt7qTp0dTpo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669230197; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LYJ67wF71BcvO8uwmwy3ELqCWCBu6XNQ28q/rdgvWwE=; b=Y6hyANy+42swVwQhVA8OV2O/mRGMaE7w8y6M4v0+7qu762NqXsSt/kpowjjqB0VheIiYPg XSWi++7faqLQ9Hi99ckJXyQvcW5Phf/JnNrfeM0lz47F5RD4nIjxpVrlO6aa2ralriOyOx PHbu2QgA74JKTP9RBZLJ4g5OJ1TojHs= X-Stat-Signature: jhn1wkta5x7gjyawac415m7tdqdaxntr X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1230814001E Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=kBJIv846; spf=pass (imf26.hostedemail.com: domain of seanjc@google.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-HE-Tag: 1669230196-157292 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.