Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2257242pxj; Sat, 19 Jun 2021 07:11:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGrRsB5gwxmHC75plpkMbw4zdzZ38OJMMVGRTC5SIuq4WmyyqjFZcWZHtIo5lxe0HXkURr X-Received: by 2002:a92:1a42:: with SMTP id z2mr10787264ill.223.1624111918900; Sat, 19 Jun 2021 07:11:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624111918; cv=none; d=google.com; s=arc-20160816; b=DGWUxEvMauzVgUMrbm8YxKDovnh9Nhzwp5T/XwOn6xYSA4WUiErzBH25M2flwC5QnW lAhYRqVeMQEpRoidyx5Tnh18VZFdYf39XV4KrNefRAXpVkAsZyHro31UVinH+0XOHtmV WxOJpkbcpItjQTQsg6oxxpUDwmfruMRsL+cXNu+6RM1W/wXQ79aPHuSi4SPlrB+EYDiM ceATzNd66Y/7euhkNB9SDKAV1bo8QsO6kikWmgQ4UtD1un7GCAlFe2rc4lpOtC0OK9bu RwkrzRfLaX0rRHErkuAyyDY83dMGkmutxaMBeT9g+vtSBXSf5Whmif7bqwUzf7dUMbAY YNWQ== 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=qZZ8WbCzDyeSAwVqDOeM4eWq1cu/rc56DN3c3gjZMVk=; b=CFUhzEaa0Uirp4LLA+Pjf0jwQKSQAL0eX6PKze/jCYhCrdtTYUAPNliRFKzn+CTyCj MhtW3fIDL4ZFp6OSmJiy4tB4yJWNz1FqRsUJObJoeLcKzzndibVEFFbGhieImVr7gjA2 wSuA/g9MzGhZekVXZMMnRlLk35wETwH+1rGXssl7O9Evqkz3s2sGOXk+ZMPOmAq+Omka k6783uD4A9MzH+tQGivmeMRQfrqHkzeIiXn4GoBgLVcct+ss6Uc3k+aukHfdVtNtox0R N1GAmk6YeCFHoMSBB5Z3b8IlSl+yQrEcHtVzVIGhct5Pmc7KPkJngrdBulMah4UWuX5x iTeA== 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 i17si12028462iog.70.2021.06.19.07.11.46; Sat, 19 Jun 2021 07:11:58 -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 S235236AbhFRXA5 (ORCPT + 99 others); Fri, 18 Jun 2021 19:00:57 -0400 Received: from mga02.intel.com ([134.134.136.20]:13196 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235182AbhFRXAu (ORCPT ); Fri, 18 Jun 2021 19:00:50 -0400 IronPort-SDR: PazSkuHpfesoXmULStX1e/wfTHNYiOHNB+MEdJhsdZMFugGPG67oucG+xjvLkSBDzBUx5UEaAn ZlamDQU/3JTw== X-IronPort-AV: E=McAfee;i="6200,9189,10019"; a="193763415" X-IronPort-AV: E=Sophos;i="5.83,284,1616482800"; d="scan'208";a="193763415" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jun 2021 15:58:40 -0700 IronPort-SDR: UNu4zuK7r2lH0OykgbY4DHttUTsBMpABlDyNiuzS4AcEN5ACxGBTIJf24Oi7pFRx+jIicPxIX3 B0jtFUu2YvlQ== X-IronPort-AV: E=Sophos;i="5.83,284,1616482800"; d="scan'208";a="554874179" Received: from shahdhav-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.6.127]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jun 2021 15:58:39 -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 , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 06/11] x86/tdx: Get TD execution environment information via TDINFO Date: Fri, 18 Jun 2021 15:57:50 -0700 Message-Id: <20210618225755.662725-7-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210618225755.662725-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210618225755.662725-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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index 9e846b0d7353..98778f44bbc6 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. @@ -58,6 +66,19 @@ bool tdx_protected_guest_has(unsigned long flag) } EXPORT_SYMBOL_GPL(tdx_protected_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()) @@ -65,5 +86,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