From patchwork Wed Oct 26 23:16:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Kai" X-Patchwork-Id: 13021356 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 D8FA6C38A2D for ; Wed, 26 Oct 2022 23:17:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80E698E0002; Wed, 26 Oct 2022 19:17:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 797A58E0001; Wed, 26 Oct 2022 19:17:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 638B58E0002; Wed, 26 Oct 2022 19:17:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 51AD08E0001 for ; Wed, 26 Oct 2022 19:17:50 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 26770AB644 for ; Wed, 26 Oct 2022 23:17:50 +0000 (UTC) X-FDA: 80064665100.05.AE1E0C7 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf16.hostedemail.com (Postfix) with ESMTP id AB5E2180002 for ; Wed, 26 Oct 2022 23:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666826269; x=1698362269; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AnNqiBNPSUbWaB3MXTzWbDZrRWoVAeYEttaIkn2Vg/8=; b=UOwaRS/zUQfgTvSlpd0jqEA03k7DOiOxED0UyaLPxPyQViMbTxKHGk5y d36ViZIVjZt/PT34sSxGBTuu7FlmOMQPQ/srPDgneSSTj3r5mLZreKkbi Q35l72NLhSElOqsuxapO7IaGTU8I4wm8GKhRRkvZyQklIWoQlNwoB9Csk POfNaVHUSlAMdvbkQx0GVVtUKx06A3bg4w0UoB/gSywdqhm4NFpiqUJE4 TMrvRDEPhl/JUSYooSieeDngGt/PZJZLl0f93gANsm0Snr90O9v8Ulhcf nHJLwGkIEcG8L+Hw3PoMiKcjWO47bkntMFdkky9+p8tfcXkwVx8AWH01b Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="394400332" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="394400332" 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:33 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="737446322" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="737446322" 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:29 -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 08/21] x86/virt/tdx: Do TDX module global initialization Date: Thu, 27 Oct 2022 12:16:07 +1300 Message-Id: <9ec7128604aa5e23542a60c86c74053bb197a722.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=1666826269; a=rsa-sha256; cv=none; b=I0sTJi096ySWQA7KVUt+7TXyL/UVu8FF4wUDWwugpX0XQoRMp0gPz6wwI/KsM0EBzY2I2n sFiwsSWh0CWCZQ9BC0ixEezoKPXsRPJtMWSV0qjzzyl8rQjy1SvJGrCo7PBOvXXw15WsnU Y84qlCJUq0G0ZwEyC3HB9heSDwtGo2U= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b="UOwaRS/z"; 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=1666826269; 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=b/R3tupK4d1K20FCpWpXUGVIkqoIderQCymLFD3hJzA=; b=yZZLi5wRd//J23oR+YcOPtxYZlRz9OCquBRURSI5YkgGbiT6bgtphrNUuxTQtEx2ahv/1u V+xVh/jraJMBh9Yi/p6wTXyGVSIAxcJba9/j8VyMr59xyT3WoicJhEsuZkpSeMDQ2y3RaU 38qocvoTHm5T9dq4fzBn9h/R+khULG8= X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b="UOwaRS/z"; 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: fupnohwe9z6ty94hg3baupbf7cmrmtmr X-Rspamd-Queue-Id: AB5E2180002 X-HE-Tag: 1666826269-36051 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: So far the TDX module hasn't been detected yet. __seamcall() returns TDX_SEAMCALL_VMFAILINVALID when the target SEAM software is not loaded. loaded. Just use __seamcall() to detect the TDX module. The first step of initializing the module is to call TDH.SYS.INIT once on any logical cpu to do module global initialization. Do the module global initialization and detect the TDX module. Signed-off-by: Kai Huang --- arch/x86/virt/vmx/tdx/tdx.c | 19 +++++++++++++++++-- arch/x86/virt/vmx/tdx/tdx.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 5246335abe07..68fb9bc201d6 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -351,8 +351,23 @@ static void seamcall_on_each_cpu(struct seamcall_ctx *sc) */ static int init_tdx_module(void) { - /* The TDX module hasn't been detected */ - return -ENODEV; + int ret; + + /* + * Call TDH.SYS.INIT to do the global initialization of + * the TDX module. It also detects the module. + */ + ret = seamcall(TDH_SYS_INIT, 0, 0, 0, 0, NULL, NULL); + if (ret) + goto out; + + /* + * Return -EINVAL until all steps of TDX module initialization + * process are done. + */ + ret = -EINVAL; +out: + return ret; } static void shutdown_tdx_module(void) diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index 215cc1065d78..0b415805c921 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -15,6 +15,7 @@ /* * TDX module SEAMCALL leaf functions */ +#define TDH_SYS_INIT 33 #define TDH_SYS_LP_SHUTDOWN 44 /*