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 838CFEB64D9 for ; Tue, 4 Jul 2023 16:58:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F245028009B; Tue, 4 Jul 2023 12:58:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED4CC280096; Tue, 4 Jul 2023 12:58:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9C1A28009B; Tue, 4 Jul 2023 12:58:51 -0400 (EDT) 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 C8742280096 for ; Tue, 4 Jul 2023 12:58:51 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9E4FF1609F2 for ; Tue, 4 Jul 2023 16:58:51 +0000 (UTC) X-FDA: 80974538862.18.0F3C585 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 7A302120005 for ; Tue, 4 Jul 2023 16:58:49 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=uAHjvH5a; spf=none (imf29.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688489930; 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=DabEsTadhQxjy5l0iivtu039CZEIVIYM+Tg+eA1/T04=; b=uPSptYlGbVzH79PwBKC/dtQ3v/j13u4J3jOtb0QzmB4zBz37Rjvv4eGqLsTbyp6bL9ceLa +lVG99podHd6lOYstfkMcx7PFvjXHvvX4vn88MXg/tw328nunzIe+E1OdThkyg4Ohwzv0E 3jbAibRA+hOCkQZrUIxXKbvSJSsMVIs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688489930; a=rsa-sha256; cv=none; b=OMtKS00VFi9GC6+vdvDremJepodT2qT9ZKC+C44C8JApwuQIiosTrEImf8s4J7px9dtkVG 0K/1LY0aUPpNUEX0N0z6exRdD40RFLV2QC+yj0lWlHa98YqVJL/Sdal8DrL8ALw7s7cw83 +e+Xm+erAZf3E5XJYKzt/E+RL8+o66c= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=uAHjvH5a; spf=none (imf29.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=DabEsTadhQxjy5l0iivtu039CZEIVIYM+Tg+eA1/T04=; b=uAHjvH5ak/q0Cyv04hU2og4/RD HeQk6Efk5ea8ZyqH1x1gsPaBJOFNh54yiE32FGfIkjxSOFRHoq7t/nh/Dli247dERND8/oHpunIsn 0sv0fxIhAzuB7qpjwjh017LEznjHtow93ZIiVqERpqu4mn8QTNLxesgBaj9ZQP1frXCN0C7tmI87G 5X3421T7KYkERxRsw5sh3KbrdTu0EQ+ORwf19gBzw6ELDUnAkAIRegxVFiIUiiYA3sHY2FB9czD8f sEUfi43cubRIt3Zj8z6f6667HPyYR86dgMT85ONknDdql7d0JNViDcTQJWTWqCgq14X7AMscLC0D6 femuk+Lw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qGjMM-009JrU-8j; Tue, 04 Jul 2023 16:58:38 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id C764F3002B1; Tue, 4 Jul 2023 18:58:36 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A1EBE2029A1AD; Tue, 4 Jul 2023 18:58:36 +0200 (CEST) Date: Tue, 4 Jul 2023 18:58:36 +0200 From: Peter Zijlstra To: Sean Christopherson Cc: Isaku Yamahata , 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" Subject: Re: [PATCH v12 07/22] x86/virt/tdx: Add skeleton to enable TDX on demand Message-ID: <20230704165836.GB462772@hirez.programming.kicks-ass.net> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 7A302120005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: yu6qew6k1k7ydr33s8ph8x15twgkuxap X-HE-Tag: 1688489929-390669 X-HE-Meta: U2FsdGVkX18QFuPGpiNr2Preeol92UXVs5tLJjt9OAPRlCcI8Bjt0Y/VTYTaWxdTglpHeDCSiEKT8WuPR0ImF6OpUJR3xExivsiB5tHv+8+mMB8n8zHXjIc/1zTX12K71aY4F9r5JKmb7aeHXv25mPgZMvTYSsGaCcFzG+cZqqm1HdjpJoobUdJdO47ZyYj4rXWrLXJLuMymV+NhqSZcaYg8H9/onKZ9sB3UAHb6OAPfl2fXdVDxAadv8qzTrIgWWltoDG34I4SNGG/autwr6JyIF3Da2cLIBEKgiGfBcspp/AOmK5lWngoTeicBE+AvMSgCa4NV2iuOFct7uT3J4EpmIVW7xLBai7ObNHNqAMShyGvfmcpKtY+8H2zttuCRP/HT09HjtWkrV4k5nY0Hg4ELliU46OvmDseCju3RWUJBf21Wwa/qcjVw5KYQIjSRlycCfXLEKRVshHZuCkBXsp6wj6VxiQMCJYj5OrmysdVJQs2xvHmOUC+vy0q9HhSveM5mTyBTz5hWksUnd2hyfWuKO+HyLIcInWbXUgA+SSIavd1M1VQjsYwsUnDIwFinK2Hyifn4EKuBkuUq9RAQHZoEPyN8TTIvVEh0hEAWmppEg6P0VtFTsJhYV46yUxjsvjOGrcP0qu9x3buiWTrqrDAeqx+DYnhjefVHbutCagCCNIS+803Oq2fUtYtKlR+7o6iMfWNaxBPA4/O6hivmfSz2vperI3qwmMqH5yqenKs/w4kM362yhp3Olzqid+cYYWxKif+FxphJnmfNzmIHboH2EgjWRhk94dAYDtXC+zed4zrTdUlHlnMXlQ0jxibfbmdZQ0b9El8ot66t+JRLMG6LEcXKxwB1gCmB2g07u4wkkfuwtJCcNZYC06yJnKZDamt6z3qveSM1bhjRo79JJYZdgOPsiyMTPLmxLvs2FnFc8bRlPF3VbYt+3FEM1WJuV5ghdmnpVIcu8RoIKrw 7cvy5ryO 56gFi/IMWAAy5Rz7gG1R8NjTg+qu90SEyW68oZWzm0iuCcVZ/wSOYTMPnZg249wLLP2ewIgV65svmR4xg7xOnE+HXWyGEFEaOmjm7oQXnjFs6SbOUQUP/LwYEyXGyjTBhheRWUt1AQkBe4/mHCZC5kNTBxUWFrizQ8Gh94FDn7IbqHOF5WTSFhC/9+zPEswCfGABhAdo/de1E62PSLS8YuO7C1NHKSq80BDpLgu2UQnOApDrZw9GINt9cmg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Jun 30, 2023 at 02:24:56PM -0700, Sean Christopherson wrote: > 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. .... People got poked and the following was suggested: On boot do: TDH.SYS.INIT TDH.SYS.LP.INIT TDH.SYS.CONFIG TDH.SYS.KEY.CONFIG This should get TDX mostly sorted, but doesn't consume much resources. Then later, when starting the first TDX guest, do the whole TDH.TDMR.INIT dance to set up the PAMT array -- which is what gobbles up memory. From what I understand the TDH.TDMR.INIT thing is not one of those excessively long calls. 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? Those TDH.SYS calls should be enough to ensure TDX is actually working, no?