Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp381698pxt; Wed, 4 Aug 2021 13:46:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLer6PVjbKhp234o0TgRCvxqcqCBghFxisgx24f/Dr7oYy/GokhM7rguHe/JcWuYY9SCLl X-Received: by 2002:a05:6e02:1a28:: with SMTP id g8mr914024ile.128.1628109988758; Wed, 04 Aug 2021 13:46:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628109988; cv=none; d=google.com; s=arc-20160816; b=yzdG3jQEtOTvWelYCnozSrt4cQvl02wKqV/Q+h+h8v+9GsTehkHokQNam5lROKlWe9 YB6UqFVgZll3hhdsgpgGclRYqZ6Y+vLJ6icnSyupUSR4fDPZdbCruXSkLZUCDHO3oeeg WJR/5kH8Xwr+IGhO9c9c/p3/k1eqZ0dCM65emeiirkyNE84rym03qwn9CS+UdGU9JcbH YYY1YmJsEAIEPpIjBVWrl1Os7o4FMFg44dzvJ1IuB8F6j+PXzzVUdF0m3VNVdsc/6+U+ fs0ejNppe6Qkv+tMlh6+yY4EKlFNvx8SElKfJ82L28UNFlqspi6FbXhS7OiXEUNRhAuM lreQ== 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; bh=6a7QyN6hVakjKiPMa5A42KXtJkixkGgrpMJGw+Wbl4c=; b=okEj6Zyk04kjKy8Tiv+WHIOkjoEm+P0uvC4tD98SXu55Wqe4HooKcoDGczz06dqSzV ZEJm7A78cW1xJ2pQuXEOxbmv1gXpUORgZkiNwMn9z2UMGXkKgKRwi6udcafpF2s5HMno VAOLgKVTrVb4WtnwcmAL6wHAAc1jdLtrauXt2rF2LR3zUFF4xgToOmtScaGVpRr1wLHy qxkjKdTuu0of2F0wgYn+KNyNPhH8zorHIu3FtmPfeQ5dpYyvijQ3WJOv1dg9NvhH6GIq gwKVZtr+gSgcxr+t7zEZXsV/qW9zVc1KxyKU2hBNdvRGXR/nV5LniiW7rDfW6NjmCLlA 82rg== 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 x14si3184703jab.2.2021.08.04.13.46.16; Wed, 04 Aug 2021 13:46:28 -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 S240136AbhHDSPM (ORCPT + 99 others); Wed, 4 Aug 2021 14:15:12 -0400 Received: from mga02.intel.com ([134.134.136.20]:49808 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240103AbhHDSPC (ORCPT ); Wed, 4 Aug 2021 14:15:02 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10066"; a="201151101" X-IronPort-AV: E=Sophos;i="5.84,295,1620716400"; d="scan'208";a="201151101" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 11:14:49 -0700 X-IronPort-AV: E=Sophos;i="5.84,295,1620716400"; d="scan'208";a="503075851" Received: from mjkendri-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.17.117]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 11:14:48 -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 , Sean Christopherson , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 06/12] x86/tdx: Get TD execution environment information via TDINFO Date: Wed, 4 Aug 2021 11:13:23 -0700 Message-Id: <20210804181329.2899708-7-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210804181329.2899708-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210804181329.2899708-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 --- Changes since v4: * None Changes since v3: * None arch/x86/kernel/tdx.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index 287564990f21..3973e81751ba 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -8,6 +8,14 @@ #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 standard use of __tdx_hypercall with BUG_ON() check * for TDCALL error. @@ -54,6 +62,19 @@ bool tdx_prot_guest_has(unsigned long flag) } EXPORT_SYMBOL_GPL(tdx_prot_guest_has); +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()) @@ -61,5 +82,7 @@ void __init tdx_early_init(void) setup_force_cpu_cap(X86_FEATURE_TDX_GUEST); + tdg_get_info(); + pr_info("Guest initialized\n"); } -- 2.25.1