From patchwork Wed Oct 26 23:16:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Huang X-Patchwork-Id: 13021357 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 B5DBAC433FE for ; Wed, 26 Oct 2022 23:17:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 576AF8E0007; Wed, 26 Oct 2022 19:17:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 500EA8E0001; Wed, 26 Oct 2022 19:17:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 290A38E0007; Wed, 26 Oct 2022 19:17:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1A2458E0001 for ; Wed, 26 Oct 2022 19:17:51 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E78021A0ADC for ; Wed, 26 Oct 2022 23:17:50 +0000 (UTC) X-FDA: 80064665100.27.C76DB52 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf16.hostedemail.com (Postfix) with ESMTP id 740A2180002 for ; Wed, 26 Oct 2022 23:17:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666826270; x=1698362270; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BGweU50UTahVYU2MdgumkpFBV2AQXxV1CrnaJ1vi394=; b=jon15dkE9nuwqH/VO7N0cnJoHEbJm8kYdNpWG25bfeF51N6crfZpecpq anvbuNhw1zfoegrx0BwbvdNFzr6adsSLLcCplsiJuInEHZF1vtLVZG0BE YHfeIhf1u+rtzyoEgk4Mcob0rI4uHEfoNm0EuZ3GBqY+JpN6s1oEqx1KK bvrhaSqWLSJyMINN/jwHjsc4CVp9y7t20qvPJEluKaeEBpolk8Guzm6ar oor6VaBJFhYYhgrHhaTPS4FrLRugLWD7JOiw+KZyathgzG/9K4URPN1Op jAsYBl9MTxG0THrgOKJr7LjFQxMJzhRs8VVyMrxhHmW6cp7LZtsSu+1Mq A==; X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="394400342" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="394400342" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2022 16:17:37 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="737446332" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="737446332" Received: from fordon1x-mobl.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.212.24.177]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2022 16:17:33 -0700 From: Kai Huang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: 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, reinette.chatre@intel.com, len.brown@intel.com, tony.luck@intel.com, peterz@infradead.org, 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, kai.huang@intel.com Subject: [PATCH v6 09/21] x86/virt/tdx: Do logical-cpu scope TDX module initialization Date: Thu, 27 Oct 2022 12:16:08 +1300 Message-Id: <1d01bf0cffc558c408319bb3758a87d21fe655c2.1666824663.git.kai.huang@intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666826270; a=rsa-sha256; cv=none; b=HnAJER4x7Uog4s1brg+mSsUNq/TPGdZLXNVnoVal73FVQgh2N0FE/lb1Qmcsd0eidfwCkx fuSsWx0kM5HSPQdOGKXGGt9uHoZyvmEnydfVp3viMP+DUy3GkfHxIzyELqc1Pc79FO6ri6 0kmvcX8Xk61Zon72uWzwJdOuC68ph5U= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=jon15dkE; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf16.hostedemail.com: domain of kai.huang@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=kai.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666826270; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LWJ0gFMf+1EPFPFOKM3YfwlMovotGnWykhLApES9ghg=; b=d1KMZBjwd5On1BEH2mTp16UDiTV/BuG+MCSb5sghMcGyzXs61KZn7JrVfExiqnDeYYFtKr E+yfcgBqdlGktHnnNxpw6NxHPRJyIqpF1th2fPHIRz1BGcAZ/cq+guR5flQUd8XCSDMTC1 g7jvwumJ4sqmdIppEL45Wdds2b5kzMQ= X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=jon15dkE; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf16.hostedemail.com: domain of kai.huang@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=kai.huang@intel.com X-Rspamd-Server: rspam11 X-Stat-Signature: 1d335qzphphbpcac13c65ndujfxcmyyw X-Rspamd-Queue-Id: 740A2180002 X-HE-Tag: 1666826270-814385 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: After the global module initialization, the next step is logical-cpu scope module initialization. Logical-cpu initialization requires calling TDH.SYS.LP.INIT on all BIOS-enabled CPUs. This SEAMCALL can run concurrently on all CPUs. Use the helper introduced for shutting down the module to do logical-cpu scope initialization. Signed-off-by: Kai Huang --- arch/x86/virt/vmx/tdx/tdx.c | 15 +++++++++++++++ arch/x86/virt/vmx/tdx/tdx.h | 1 + 2 files changed, 16 insertions(+) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 68fb9bc201d6..8a1c98d961f3 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -342,6 +342,15 @@ static void seamcall_on_each_cpu(struct seamcall_ctx *sc) on_each_cpu(seamcall_smp_call_function, sc, true); } +static int tdx_module_init_cpus(void) +{ + struct seamcall_ctx sc = { .fn = TDH_SYS_LP_INIT }; + + seamcall_on_each_cpu(&sc); + + return atomic_read(&sc.err); +} + /* * Detect and initialize the TDX module. * @@ -361,6 +370,12 @@ static int init_tdx_module(void) if (ret) goto out; + /* Logical-cpu scope initialization */ + ret = tdx_module_init_cpus(); + if (ret) + goto out; + + /* * Return -EINVAL until all steps of TDX module initialization * process are done. diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index 0b415805c921..9ba11808bd45 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -16,6 +16,7 @@ * TDX module SEAMCALL leaf functions */ #define TDH_SYS_INIT 33 +#define TDH_SYS_LP_INIT 35 #define TDH_SYS_LP_SHUTDOWN 44 /*