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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39612C636D4 for ; Mon, 13 Feb 2023 22:28:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbjBMW2v (ORCPT ); Mon, 13 Feb 2023 17:28:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbjBMW2r (ORCPT ); Mon, 13 Feb 2023 17:28:47 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3ED01CF56; Mon, 13 Feb 2023 14:28:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676327326; x=1707863326; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=314vpw90/2DwHi9JOkrC++51z0wYP6vtdKNmpuIX6Gc=; b=kjMnN3OFudXhRQ3rX7o+dcIcXgPzUdJMTuKwPgCohU2HC++l+5eMJmJi LJljc3gfxLYe7xA5iyz7tIzjo/JTvJJNykWyCWmNtNk1OQ45ym0j/7Czx NPF75T9+ZsXTU6MfQ1w9vC6D8vvikT4oS8yuLEeytd4Y0FecvB+ohHJ3I x5MyrwN+/oc12ExwzB4P9I1MsNflqLlP+D+uYeUNNgVuGSyxV/zb625qm lc5+IBzM37hrQowNZmVtCzlV6ZdMrjeboCuhWrPH9q4iPFZZpHMh89h8n PrYv/77mwpacNFwC8JcmMCspn56abr4CUY0n4oR2LznQ3VBS0nL34EfF+ g==; X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="358421214" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="358421214" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 14:28:46 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="737674268" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="737674268" Received: from mlswanso-mobl.amr.corp.intel.com (HELO [10.251.26.232]) ([10.251.26.232]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 14:28:44 -0800 Message-ID: <2d7141b1-1d76-4e67-60d2-471a524c372e@intel.com> Date: Mon, 13 Feb 2023 14:28:43 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v9 07/18] x86/virt/tdx: Do TDX module per-cpu initialization Content-Language: en-US To: "Huang, Kai" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" Cc: "linux-mm@kvack.org" , "peterz@infradead.org" , "tglx@linutronix.de" , "Christopherson,, Sean" , "pbonzini@redhat.com" , "Williams, Dan J" , "Wysocki, Rafael J" , "kirill.shutemov@linux.intel.com" , "Huang, Ying" , "Chatre, Reinette" , "Brown, Len" , "Luck, Tony" , "ak@linux.intel.com" , "Yamahata, Isaku" , "Gao, Chao" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "david@redhat.com" , "bagasdotme@gmail.com" , "Shahar, Sagi" , "imammedo@redhat.com" References: <557c526a1190903d11d67c4e2c76e01f67f6eb15.1676286526.git.kai.huang@intel.com> <2d9172c5-e1e7-bf94-c52b-0e9bc5b5b319@intel.com> From: Dave Hansen In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/13/23 13:13, Huang, Kai wrote: > Perhaps I didn't explain clearly in the comment. Below is the updated one: > > /* > * The previous call of __tdx_enable() may only have > * initialized part of present cpus during module > * initialization, and new cpus may have become online > * since then w/o doing per-cpu initialization. > * > * For example, a new CPU can become online when KVM is > * unloaded, in which case tdx_cpu_enable() is not called since > * KVM's CPU online callback has been removed. > * > * To make sure all online cpus are TDX-runnable, always > * do per-cpu initialization for all online cpus here > * even the module has been initialized. > */ This is voodoo. I want a TDX-specific hotplug CPU handler. Period. Please make that happen. Put that code in this patch. That handler should: 1. Run after the KVM handler (if present) 2. See if VMX is on 3. If VMX is on: 3a. Run smp_func_module_lp_init(), else 3b. Mark the CPU as needing smp_func_module_lp_init() Then, in the 'case TDX_MODULE_INITIALIZED:', you call a function to iterate over the cpumask that was generated in 3b. That makes the handoff *EXPLICIT*. You know exactly which CPUs need what done to them. A CPU hotplug either explicitly involves doing the work to make TDX work on the CPU, or explicitly defers the work to a specific later time in a specific later piece of code.