Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2862913pxb; Fri, 8 Oct 2021 17:38:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzP9uMceMnnV/SJ3Syr3oH/VNqclG4Cyccv+KL324qdLwiaN6WpTnxqNWmEqlBYQhQCi6oe X-Received: by 2002:a63:6ac2:: with SMTP id f185mr22826pgc.326.1633739916133; Fri, 08 Oct 2021 17:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633739916; cv=none; d=google.com; s=arc-20160816; b=tF+8MGenETOCHOZqDDYJy0vl3DmNuO1GxZuSG8ajO4cyDHzF8xNEGzJBNjUDMvPXWs SWUDpXstis8EhrrQBXQ1NH7pPKdDkTCcPkuyrYkapF0/oMK1HNyS4xAnSTvEObSjEtqX SxVl3Eofx7ljcKM1DJo6O9KEHkqYmw+WEg8hbAWg4bzm7chmQm6t8lDV6nl7dzuk8K8I 276tC9zmFZkFscpGH8WFU2WF6ACmLTyiXzJMdSktBq8uDjwXoppaONSCyFXye4OHWCXl HbOenGspU21sNoEQN+TTadz3DvKwIQTP0dUQinVV6iI5pxYWhHa7+iqf6h8BAusCFI/a WKhQ== 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=AWhVDUfU6jHiVDwURet7Xj3E34GgWq96WXdPFEqBBqw=; b=hW2SWiW1bFDl2BqoJIYRMUO+x/NkECRoSnxMUtVc/Mf+ZWb/DocO4X9nZcmoLermwg xDYVlr0eHGmJuo5i+a+++jlGslVv0alFOeIcMdz+CxYYmZlNGZfo7zoJ86bnLOif+Orx w59wf4ZGGUXqL/krOcrD706TNmz9CY+runKdYHgq2uH5GR5bscvHjonMhhfhK6fnZAqj vwLVBD08I4SghsKjNpHUPacizzYWwUI1Cl9gTHuf0vEIVzJG4QzeILnZZQlRs8KlrULs 9awU2M0AtZV37ATbZjqitWLN7VGOFg/dXCprXsl/uuyO51tt9VHVOm1mIsJzF/jlia2Q 2AzA== 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 i189si1373693pfg.43.2021.10.08.17.38.23; Fri, 08 Oct 2021 17:38: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 S244076AbhJIAje (ORCPT + 99 others); Fri, 8 Oct 2021 20:39:34 -0400 Received: from mga02.intel.com ([134.134.136.20]:5242 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244042AbhJIAja (ORCPT ); Fri, 8 Oct 2021 20:39:30 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10131"; a="213756487" X-IronPort-AV: E=Sophos;i="5.85,358,1624345200"; d="scan'208";a="213756487" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 17:37:34 -0700 X-IronPort-AV: E=Sophos;i="5.85,358,1624345200"; d="scan'208";a="624905344" Received: from dmsojoza-mobl3.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.251.135.62]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2021 17:37:32 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , Bjorn Helgaas , Richard Henderson , Thomas Bogendoerfer , James E J Bottomley , Helge Deller , "David S . Miller" , Arnd Bergmann , Jonathan Corbet , "Michael S . Tsirkin" , Paolo Bonzini , David Hildenbrand , Andrea Arcangeli , Josh Poimboeuf 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, linux-pci@vger.kernel.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v5 02/16] x86/tdx: Get TD execution environment information via TDINFO Date: Fri, 8 Oct 2021 17:36:57 -0700 Message-Id: <20211009003711.1390019-3-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211009003711.1390019-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20211009003711.1390019-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 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index 79af9e78b300..bb237cf291e6 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -14,6 +14,7 @@ #include /* force_sig_fault() */ /* TDX Module call Leaf IDs */ +#define TDX_GET_INFO 1 #define TDX_GET_VEINFO 3 #define VE_IS_IO_OUT(exit_qual) (((exit_qual) & 8) ? 0 : 1) @@ -21,6 +22,11 @@ #define VE_GET_PORT_NUM(exit_qual) ((exit_qual) >> 16) #define VE_IS_IO_STRING(exit_qual) ((exit_qual) & 16 ? 1 : 0) +static struct { + unsigned int gpa_width; + unsigned long attributes; +} td_info __ro_after_init; + bool is_tdx_guest(void) { static int tdx_guest = -1; @@ -65,6 +71,31 @@ static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, return out->r10; } +static void tdx_get_info(void) +{ + struct tdx_module_output out; + u64 ret; + + /* + * TDINFO TDX Module call is used to get the TD + * execution environment information like GPA + * width, number of available vcpus, debug mode + * information, etc. More details about the ABI + * can be found in TDX Guest-Host-Communication + * Interface (GHCI), sec 2.4.2 TDCALL [TDG.VP.INFO]. + */ + ret = __tdx_module_call(TDX_GET_INFO, 0, 0, 0, 0, &out); + + /* + * Non zero return means buggy TDX module (which is + * fatal). So raise a BUG(). + */ + BUG_ON(ret); + + td_info.gpa_width = out.rcx & GENMASK(5, 0); + td_info.attributes = out.rdx; +} + static __cpuidle void _tdx_halt(const bool irq_disabled, const bool do_sti) { u64 ret; @@ -466,6 +497,8 @@ void __init tdx_early_init(void) setup_force_cpu_cap(X86_FEATURE_TDX_GUEST); + tdx_get_info(); + pv_ops.irq.safe_halt = tdx_safe_halt; pv_ops.irq.halt = tdx_halt; -- 2.25.1