Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp204323pxj; Tue, 1 Jun 2021 19:23:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeT2f86Ob1wUmF029jKvbJ/pYrFP+eAVR4KW6pVw1P8zwVlw0dbroe1En/YlB1Y2d147EN X-Received: by 2002:a02:6c46:: with SMTP id w67mr27708132jab.41.1622600616493; Tue, 01 Jun 2021 19:23:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622600616; cv=none; d=google.com; s=arc-20160816; b=ohYF350UdV3rVW0MmAIyd46yxxZZ8Gn19AzUTpawHw+EmN5ybE/XRy2rSDx1w2J5VQ 3Qa43nTlsTNT0RneTFC8pxYGs28bRzBh2OZSpeM+o7l+5XzCG4Ql6pTakxdYubFbnpeT ajhVmThy+a7JbCyp2kpMt4P6+vtOJhQHu0q8Bc28HYtWQAeKpaD/GI5jHX+6HlmKzQX6 D64ZU1iGbWy+gB3+kOvBI7qriD9Y/UOkx2qoq/Vce1hshyB35zFeNvURkQZtUGtcffsB UGEssZzclc1VseSVwagnLws9Vd4Ps988asHWzZHgL973m2E9S10BfdsZSp9ov1bOxRA8 55AQ== 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 :ironport-sdr:ironport-sdr; bh=mSbDSc1pgToeJAYrKngXBsWndLzo4hFDFx8bJTKhKco=; b=MwBg6PYcn77BQGM7kNoa5ewsChaEhCMSJEKlLEBR9M1pxf1vDl2nOIVT4YYca6Za7X JPO5DK2M9p51DE0RLIkpREkRiVGKjF6laG9bu3+O+V20weWj1w4muUpagrXz6WW4LpNA LPh4vRno/pK+GOLv4BpqvS5ETVzjsUCM24QDp0LR+JjfASQLQEEo2BYvmV+sdR2/UTSG QwH7gCMtIi1PPLbS4qTaxrvvV4SqPVKWwwwwvNe3xmockKLKWiqVL55q2T0nvM6cZ8px lHn5tqCSqzl6Xhc5CossESHnuQvEbnIE6PDCoWWkt0p+DAm98vutz0gvoEbcbGaMSBIY lihg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o1si21120248jat.48.2021.06.01.19.23.23; Tue, 01 Jun 2021 19:23:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230342AbhFBCXr (ORCPT + 99 others); Tue, 1 Jun 2021 22:23:47 -0400 Received: from mga06.intel.com ([134.134.136.31]:19500 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230162AbhFBCXa (ORCPT ); Tue, 1 Jun 2021 22:23:30 -0400 IronPort-SDR: rZNJdNR7dGUETxC9E0rRx03kLkPqmuP7MC1K0DFRLTzo/OuGKmcspA8U64XVz21g3TWARFdzS1 vQVqGie0/ggg== X-IronPort-AV: E=McAfee;i="6200,9189,10002"; a="264865326" X-IronPort-AV: E=Sophos;i="5.83,241,1616482800"; d="scan'208";a="264865326" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2021 19:21:48 -0700 IronPort-SDR: daAaICWQ3rPOfD6C31TEsKygK+LZ3HpMKgm3FqR3Oi6w6XCg9j9O75x0Rc+6ypKsH+KaqXBB+B BI31ADb1d1Dw== X-IronPort-AV: E=Sophos;i="5.83,241,1616482800"; d="scan'208";a="633069211" Received: from mjdelaro-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.3.23]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2021 19:21:47 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski Cc: Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Sean Christopherson , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH v1 06/11] x86/tdx: Get TD execution environment information via TDINFO Date: Tue, 1 Jun 2021 19:21:31 -0700 Message-Id: <20210602022136.2186759-7-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602022136.2186759-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210602022136.2186759-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Kirill A. Shutemov" Per Guest-Host-Communication Interface (GHCI) for Intel Trust Domain Extensions (Intel TDX) specification, sec 2.4.2, TDCALL[TDINFO] provides basic TD execution environment information, not provided by CPUID. Call TDINFO during early boot to be used for following system initialization. The call provides info on which bit in pfn is used to indicate that the page is shared with the host and attributes of the TD, such as debug. Information about the number of CPUs need not be saved because there are no users so far for it. Signed-off-by: Kirill A. Shutemov Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/kernel/tdx.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index 97b54317f799..e4383b416ef3 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -4,6 +4,17 @@ #define pr_fmt(fmt) "TDX: " fmt #include +#include + +#include + +/* TDX Module call Leaf IDs */ +#define TDINFO 1 + +static struct { + unsigned int gpa_width; + unsigned long attributes; +} td_info __ro_after_init; /* * Wrapper for simple hypercalls that only return a success/error code. @@ -63,6 +74,19 @@ bool is_tdx_guest(void) } EXPORT_SYMBOL_GPL(is_tdx_guest); +static void tdg_get_info(void) +{ + u64 ret; + struct tdx_module_output out = {0}; + + ret = __tdx_module_call(TDINFO, 0, 0, 0, 0, &out); + + BUG_ON(ret); + + td_info.gpa_width = out.rcx & GENMASK(5, 0); + td_info.attributes = out.rdx; +} + void __init tdx_early_init(void) { if (!cpuid_has_tdx_guest()) @@ -70,5 +94,7 @@ void __init tdx_early_init(void) setup_force_cpu_cap(X86_FEATURE_TDX_GUEST); + tdg_get_info(); + pr_info("TDX guest is initialized\n"); } -- 2.25.1