Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1482917rwi; Wed, 26 Oct 2022 16:20:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5AptF6dfxOVrj12eeHH5yQe+usMBxY+GopyHHKRnbU7YsKNz329VCvAY0JePlwwWLD45ft X-Received: by 2002:a17:907:1b0e:b0:72f:9b43:b98c with SMTP id mp14-20020a1709071b0e00b0072f9b43b98cmr39681221ejc.710.1666826430835; Wed, 26 Oct 2022 16:20:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666826430; cv=none; d=google.com; s=arc-20160816; b=nTzyC5jLmE9Qq280R75k5792p4FYldAsjA2dG2+rNDT7JhrcWkjMOvXjQH3zdpKXto /jfjc5oWdgNXI7dW70yHZc+U9DtVaSgREtoAlKvX5FRjJzN6En4YyZSSQcERysql8ibW S+ONv2Yq8hOcDLG0PFlSt78qO+oa2I/ahc0ATl8eSScCX8soISw6Ezh9nzeOXwV1VyLR DCAtLszG5NudPHolX0NZgM1Ref04LybKryCSer15dF/h+wgaw959VHOvPLIgxNnNLOH/ nDPHj4FfeUBDQwz5yrri4GlRrJ8w9iE8UgN/BJYsIWiK2St/tECEq1xA2E8ubXXSfgVS +oPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=b/R3tupK4d1K20FCpWpXUGVIkqoIderQCymLFD3hJzA=; b=XTC/kA4FVMkpCqRxcUMwJHlEsc2k0NvXdgNAc+j1j2IolrSd8PnwmJWySouMySBfgz NXzHuF6wnCD3gkBkXqI1Bv94XpVas9MTEIc5UXnjOmRpfH7vdoGwSR1OYnjpP1VZWnCu rhr1/MThpWXDbOkfTc4ypN5yyfunIfCxpZi+Cmh3z+1LFVs6xGNdCaIGGu+Pw26oE+Zh Yd/VGg9cU0JZWsrz4mKKwnJwfp/zbZfKrtVRShgRbJVKcgGVALZSJH2tTMpnzxFnz+kw XLVGhVaL/4P8KxS94HoE2EJYlbYhF4rhYVAJn9Vrv/EIGfAxcvf3UufiFcfG8oXzfFNk wMzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RZLd4Vgu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020a170906145000b0078cbe9d08c6si825528ejc.197.2022.10.26.16.20.05; Wed, 26 Oct 2022 16:20:30 -0700 (PDT) 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=@intel.com header.s=Intel header.b=RZLd4Vgu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233677AbiJZXST (ORCPT + 99 others); Wed, 26 Oct 2022 19:18:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234100AbiJZXRr (ORCPT ); Wed, 26 Oct 2022 19:17:47 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C7F4ACF62; Wed, 26 Oct 2022 16:17:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666826254; x=1698362254; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AnNqiBNPSUbWaB3MXTzWbDZrRWoVAeYEttaIkn2Vg/8=; b=RZLd4VguzbxWyM586ZOm5+vPEOOWS6quCFkxC88ubqWBxvoG5MXUWPZ9 LEkH0SOcsyIpds7eEXLynJhzQg18Z2Q4Yjs17SY7s3h2eXW62dW8PM2lu jOzc/TXoF7muOnA96rYXODmqQngWSEmu3VUJxCd7gIQR+RBhlkYDHJ3R1 N/e29HGg+xaOVRh5qhlRrYFoLY5Bo+FoFPnwjIb3WIHwR/ZNTb1AGPzn3 L2XI+YPPfHSjacV+yUt06iPA//iKtWXXe/DZz+QR4M9o8MKY3QjWTyWd3 Ji1nsS1d/FR/XPKPOdq5Yx20Y/vCQ1QyOHZddCaKnjsaqtUyDd+OFUFv3 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="309175521" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="309175521" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED 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 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 /* -- 2.37.3