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 530DCC4332F for ; Tue, 22 Nov 2022 09:02:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 87DC16B0074; Tue, 22 Nov 2022 04:02:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 82D8B8E0002; Tue, 22 Nov 2022 04:02:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F6528E0001; Tue, 22 Nov 2022 04:02:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 615426B0074 for ; Tue, 22 Nov 2022 04:02:42 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 257CA120F9C for ; Tue, 22 Nov 2022 09:02:42 +0000 (UTC) X-FDA: 80160487764.27.484A024 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 57AC01C000F for ; Tue, 22 Nov 2022 09:02:40 +0000 (UTC) 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=I3JtwSpkdP77vSyM0WIL4jCtx94jec1H7+Vd7VeGsXg=; b=drj2W2DsQ3QoPR70ZVUerQCLR9 iwwS44zR/5xnF1e083im4QvkIwq09JUSe+ZPZq1PhvvcH/B7GNJIqgM5j/ItZ8ZDVgGWHbCx8WWZe /TRhG6IIP58JaLdPZR/hlgi+ryIJWJRKw2j+Dl+nYNl6ZkVaZ4SFsd7AhLfybs3CLvW7gzsQe1bhq EAon/0pXQGx3Enjkb2fiWkV14PFxmCC/DKz5Ynew2L1dtnVK38zOvMYwDiNm5OljEKvGNxMz1hUoC 80yTqq3/Jwe4mGRLMUm6t1Xi/sCrBeVHADkqdRM9Rc9hQHunPzOddSh5bcyJB2yZMzUTrNtmN/W35 zr0sDenQ==; 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 1oxPAu-0068jT-W7; Tue, 22 Nov 2022 09:02:41 +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 5E8E0300244; Tue, 22 Nov 2022 10:02:32 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 4353F2D65BCDB; Tue, 22 Nov 2022 10:02:32 +0100 (CET) Date: Tue, 22 Nov 2022 10:02:32 +0100 From: Peter Zijlstra To: Kai Huang Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, kirill.shutemov@linux.intel.com, ying.huang@intel.com, reinette.chatre@intel.com, len.brown@intel.com, tony.luck@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com Subject: Re: [PATCH v7 04/20] x86/virt/tdx: Add skeleton to initialize TDX on demand Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=drj2W2Ds; spf=none (imf20.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669107761; a=rsa-sha256; cv=none; b=t8KnSMHka6jRuk4mhvYPt9Cmjr5c7zhlVKYl4O/Z5v5Rog9VekfkAXnwulm210Y5YHHz6u 5wP3N0a/IeXtwLhaK2CofVcPRP/TCIeJWE4fFVoR1AuHvRnz24ecSse77LpeH/8uNyijRZ 3PlDoRT4L8tqyCjH5OUrtQ8iuw8fITY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669107761; 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=I3JtwSpkdP77vSyM0WIL4jCtx94jec1H7+Vd7VeGsXg=; b=aFygtX4SK0KS2fNgDnEn7FnIoGbFmmNvdu3W+5s2gpuPjrNEuRjCaD67/tpdBEunA9nKMB YBQpWBasRV0MDGa/YtU2Il9PkiS3EvcRFc9jbNGwButVblgpD7i0g06hkDD/i+lja4SXRJ c1U+kTJ7oo15jLHQe75pPY/mZmqTQ/4= X-Stat-Signature: kgifsq6rs8nnirhomgsdggg93do4zua4 X-Rspamd-Server: rspam08 X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=drj2W2Ds; spf=none (imf20.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none X-Rspamd-Queue-Id: 57AC01C000F X-HE-Tag: 1669107760-499760 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 Mon, Nov 21, 2022 at 01:26:26PM +1300, Kai Huang wrote: > +static int __tdx_enable(void) > +{ > + int ret; > + > + /* > + * Initializing the TDX module requires doing SEAMCALL on all > + * boot-time present CPUs. For simplicity temporarily disable > + * CPU hotplug to prevent any CPU from going offline during > + * the initialization. > + */ > + cpus_read_lock(); > + > + /* > + * Check whether all boot-time present CPUs are online and > + * return early with a message so the user can be aware. > + * > + * Note a non-buggy BIOS should never support physical (ACPI) > + * CPU hotplug when TDX is enabled, and all boot-time present > + * CPU should be enabled in MADT, so there should be no > + * disabled_cpus and num_processors won't change at runtime > + * either. > + */ > + if (disabled_cpus || num_online_cpus() != num_processors) { > + pr_err("Unable to initialize the TDX module when there's offline CPU(s).\n"); > + ret = -EINVAL; > + goto out; > + } > + > + ret = init_tdx_module(); > + if (ret == -ENODEV) { > + pr_info("TDX module is not loaded.\n"); > + tdx_module_status = TDX_MODULE_NONE; > + goto out; > + } > + > + /* > + * Shut down the TDX module in case of any error during the > + * initialization process. It's meaningless to leave the TDX > + * module in any middle state of the initialization process. > + * > + * Shutting down the module also requires doing SEAMCALL on all > + * MADT-enabled CPUs. Do it while CPU hotplug is disabled. > + * > + * Return all errors during the initialization as -EFAULT as the > + * module is always shut down. > + */ > + if (ret) { > + pr_info("Failed to initialize TDX module. Shut it down.\n"); > + shutdown_tdx_module(); > + tdx_module_status = TDX_MODULE_SHUTDOWN; > + ret = -EFAULT; > + goto out; > + } > + > + pr_info("TDX module initialized.\n"); > + tdx_module_status = TDX_MODULE_INITIALIZED; > +out: > + cpus_read_unlock(); > + > + return ret; > +} Uhm.. so if we've offlined all the SMT siblings because of some speculation fail or other, this TDX thing will fail to initialize? Because as I understand it; this TDX initialization happens some random time after boot, when the first (TDX using) KVM instance gets created, long after the speculation mitigations are enforced.