From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 172C6C433ED for ; Mon, 26 Apr 2021 18:03:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D020960FE5 for ; Mon, 26 Apr 2021 18:03:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234441AbhDZSDr (ORCPT ); Mon, 26 Apr 2021 14:03:47 -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