Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5630528rwb; Tue, 22 Nov 2022 02:44:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf75Pzc0cp0gdiw03r95yIv5IhKMkbj28NaRtGhbO5QiPNbeMtHMvBCpcqpMJ9u2C+ZlZCCW X-Received: by 2002:a17:907:9951:b0:7b2:7e7a:11c1 with SMTP id kl17-20020a170907995100b007b27e7a11c1mr4346384ejc.684.1669113892183; Tue, 22 Nov 2022 02:44:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669113892; cv=none; d=google.com; s=arc-20160816; b=BqC5NACelaBtSal3dTqAevl4UiuhSFFtQjFFTL+8AKSLfiLATd9NX1CZwhRB1kAor7 EFB7gf6yHE4LKvpyHdBPbs0KEbzdHIln7tv9Kq/6gwwf6XRWNiAmWVFUdgL2KWktRRJ+ kD7dOWI/UwIqho7Eas3te5TGwP5QL7IaNX4/u0QW8gPH4a3hRzGPmefzm8M1bKdn7xB8 qdBAicJpc4KwUTwXGucLyigR+FLFyDwvnQ6+5sQOxjWjZSSOuQLDpi8DZTh3ZCJI/VA2 SV1w51gaonPxqBRImCAEAUqiM0gYNKvX0BCQo85REmDXJCASKgnuBLVXRaEehO0kKnv7 qVMA== 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=I3JtwSpkdP77vSyM0WIL4jCtx94jec1H7+Vd7VeGsXg=; b=eqvD8j8pxZQa632alm6jm//LAnue/ChrFNgSfDXATFae9pW6z9xLgW1kKMwCYkvi5a KWAgCBQLx5AnwC3pwHe9s3TAXQNb4WNsbGvFpKqk5k7bEu45bJuLIlST7Te7FaigM60k 9l5BpuegGywu5qobZzByx4zpIOLYgWWewbUBovKrDwdi+TnQredtDRcjlmh0NqBsccLg SisTTU1Xe5IcDDjIoE6OkrBRqQ/ytqmpquptPaz90XXAvRL+A/2+CMXIHMClK7qZgcVs TA9LLwZnNKWk2st1i4WYhhud3uBAT0u6cvUyuW9n3G1nMnH4Do10UIGux/otEidKuqE2 /txg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=drj2W2Ds; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt42-20020a1709072daa00b007882936243fsi1760071ejc.772.2022.11.22.02.44.29; Tue, 22 Nov 2022 02:44:52 -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=@infradead.org header.s=casper.20170209 header.b=drj2W2Ds; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232523AbiKVJC5 (ORCPT + 91 others); Tue, 22 Nov 2022 04:02:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233009AbiKVJCt (ORCPT ); Tue, 22 Nov 2022 04:02:49 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 895B910BA; Tue, 22 Nov 2022 01:02:48 -0800 (PST) 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: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 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.