Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3844577pxy; Mon, 26 Apr 2021 11:04:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZZfSEn1I/VK66Y/8yx4iyS4GrgGLKe0zw06qBF8oWgqRmm3w4hBEPJpxFI4OcAaKyziJr X-Received: by 2002:a05:6402:4405:: with SMTP id y5mr22524017eda.149.1619460297460; Mon, 26 Apr 2021 11:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619460297; cv=none; d=google.com; s=arc-20160816; b=p4eRCU9bMgeO3S2fXt/vfSujsgol7eWAXd68ba3NSoniwIE9UA84VKryI22RMw2WY2 4E42vHybmWqLPWA2bMh5zmU583y4cAOprVj5BQMGyF8mSg8N9vX0cMGRTHfwZOV0Qr8z jSLkbiyVqYJucLXTgw51QJDFjfxDXjR7P8OuUZThU6xSPwZeLDggNy9tP4Upn+H66hlE SqWmeez+6A7aMKZajKx5eEjVkdx8y6B1FqGyPL1pKyi+EZEreFsPrj2jb2yUk27ghsaM 4d3/2c5LIl51QkI7X0NKzBnEObkEZ7qIqAt6FeVSx45QLwt+5Zq8fwUE7SJGDR1nKsQX EC/g== 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=jV9NWq3cprQKsb6PMkafpK6JBPs6IdB1Ksbz4UYT8wU=; b=G+bawAwQWVRztOfDJMnFyLYFrlIwv/ygzKC5PEGp+xkw/zeikosKEbbAQT5Y1xW1lx flyZgogc6D/1PSfuxlzfhwl3s3+Q6sHLfKIPH4IW25TJLlPIEw5ree192LUArY2w+jgx pQDpVzfnl9UlBvoqYotoJxXTu2q8WqJjm0HnzduTAhmvVv5U5AQZQLa6658yKPxWIAnA 4BQrbnHc0cWUrONulp5ZAPSUhBrIhYwytBMcwS/5HGODGIsU5haXG2DiEewzrFQElo3j V6g7GGKqL/uM9I2gdh/6sAa+39+NdLvxA+W+tWbM1G7D4YpNrXNgdZSBkozScEks/JGR 1WyA== 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 v7si515413edd.352.2021.04.26.11.04.33; Mon, 26 Apr 2021 11:04:57 -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 S234423AbhDZSDp (ORCPT + 99 others); Mon, 26 Apr 2021 14:03:45 -0400 Received: from mga14.intel.com ([192.55.52.115]:31731 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234253AbhDZSDZ (ORCPT ); Mon, 26 Apr 2021 14:03:25 -0400 IronPort-SDR: P0fxBA2nhGMJai/yrHCly/vKj6yXC8KBqoZQSHJxU3cjxXU/cE4g3jxM5HuN5+9EUAj6wnv7UV eM/WPJDHPMWg== X-IronPort-AV: E=McAfee;i="6200,9189,9966"; a="195934028" X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="195934028" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 11:02:43 -0700 IronPort-SDR: Xvmcw8Mk+YpE2jfSj1VRmh8UdnmmtQLmXrQCfp9YXc3AnR5r9hZQhsUS6RdMNNqe49KwAiguJy mPfUNGKsPv9A== X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="447353349" Received: from ssumanpx-mobl.amr.corp.intel.com (HELO skuppusw-mobl5.amr.corp.intel.com) ([10.254.34.197]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 11:02:42 -0700 From: Kuppuswamy Sathyanarayanan To: Peter Zijlstra , Andy Lutomirski , Dave Hansen , Dan Williams , Tony Luck Cc: Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Raj Ashok , Sean Christopherson , linux-kernel@vger.kernel.org, Kuppuswamy Sathyanarayanan Subject: [RFC v2 06/32] x86/tdx: Get TD execution environment information via TDINFO Date: Mon, 26 Apr 2021 11:01:33 -0700 Message-Id: <867d88656607d2f572d382e158318dc19d44564c.1619458733.git.sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: 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. We don't save information about the number of cpus as there's no users so far. Signed-off-by: Kirill A. Shutemov Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/include/asm/tdx.h | 2 ++ arch/x86/kernel/tdx.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 6c3c71bb57a0..c5a870cef0ae 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -10,6 +10,8 @@ #include #include +#define TDINFO 1 + struct tdcall_output { u64 rcx; u64 rdx; diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index 29c52128b9c0..b63275db1db9 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -4,6 +4,14 @@ #define pr_fmt(fmt) "TDX: " fmt #include +#include + +#include + +static struct { + unsigned int gpa_width; + unsigned long attributes; +} td_info __ro_after_init; /* * Wrapper for use case that checks for error code and print warning message. @@ -61,6 +69,19 @@ bool is_tdx_guest(void) } EXPORT_SYMBOL_GPL(is_tdx_guest); +static void tdg_get_info(void) +{ + u64 ret; + struct tdcall_output out = {0}; + + ret = __tdcall(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()) @@ -68,5 +89,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