Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2551007rdb; Fri, 22 Sep 2023 01:45:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjdpH+44KrPRkARXD9PNar87kREJY4GotDC2ijI2wF4K6jorNgKIHbjmxXNyDo0TGFDTNV X-Received: by 2002:a05:6808:1496:b0:3ab:8ae5:e7c6 with SMTP id e22-20020a056808149600b003ab8ae5e7c6mr9059105oiw.1.1695372312434; Fri, 22 Sep 2023 01:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695372312; cv=none; d=google.com; s=arc-20160816; b=eg0DyX9UTt1CmBbR4T5kSX1as3zGxmvEhfih5xqcMtxe/WR1yrmByos40h58xzCfL3 /HScTp1JYkhCW+jlNG5yw9QtVZt4KUSeuBRHM671+9wqDCd9zVzNFB7Mf8QC1jK5YgxT dBfJs+eI1ziVIue9YsVTcIyxYZ2Q7zm05nGO+9mbQcVhfpaduBDqV//65hEEpaqTt8IG +JvKQj9CcvNmQa4yLOr3uRho7r1eyT15FvMBQD3aG4YFnD8Kc6oT1BgJRPLDWmtHpqoM uxhxKtek/4hj2I2uSTdj+DDdjmtBz4719/XGI9nh9Tc4ca8bsj9/R/gx+ImuOU/Otx3r 8mgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=m1JC7z345qg19h4QkL2QsX/28yn066xUNziyuX/9lRI=; fh=CamRO3us3c86yUl0dy+WRuT0xYGa4SZGrS3TSCPFkMk=; b=dvo0sVxJifsvivSNKfR07coBInGwCiufgdWZ8LOm38euuKa+09GDO+v55lqAO4PVLN VOwzdMXmJf3Ot0ADEEKmr5TQhKVrKt8ew3gK9QxJPWY/twnZ0khA+J+Yg6Q1667Um8bR tvevHbiDsWn94ZAz3CzcdWsYhT7x12ZCW0mFKCzh4NzexbhFbF8UU4Yg+yhfR0yyWjBJ 4HY6l+5F/vg/c1aLg1tT5T00+VtkBhMopuXBlS2HHZ6JNYyU1txQnBefVcAnFJbxV5qT eF53BFdlcmZhN8D6jaI7xK5NJBHkvVn5IZFb6zttPfdvq2DbDgyvgdGeWY4wVnfT+Lei qVSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gOsHL8iU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id br9-20020a056a00440900b0068fc078b0casi3300544pfb.147.2023.09.22.01.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 01:45:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gOsHL8iU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id A6CD28310D1B; Thu, 21 Sep 2023 20:38:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229520AbjIVDih (ORCPT + 99 others); Thu, 21 Sep 2023 23:38:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjIVDie (ORCPT ); Thu, 21 Sep 2023 23:38:34 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD6EBE8 for ; Thu, 21 Sep 2023 20:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695353907; x=1726889907; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=w7WDOY81O35BxGWUpPxnqKijP+Vas6lybpB+8vZgOU8=; b=gOsHL8iUbT1utxplcM4PEFeTf6X8MoNxrNjw9ijKEfByehR49NP8dyJm wfqCixKrrGajvZmv1Kh9L/QyXoaYSOsmfi70UxAPlRon4i1SkuRq2ZGsC Mu3CtxgHukFTQHOF/2PdDK/FU0etg3uPpy4N6urOvTXJeEFBtXQNwOM+m 9hK9YMJQQXQt4uTVZnJslIFQXN+e81G/2dDPS+sB6zdsERvqzND3y/do7 hL/YmmemYzQ7cZnF2wDdiWDewOWs5mfluDFU9qvDIEsl26bO0pviKYfhH YmQzKDn8grU0LhcE5FRR1IAb3yURYEeE7PS/ey9WK/RHmT1HxCG+n6ZMz g==; X-IronPort-AV: E=McAfee;i="6600,9927,10840"; a="380634183" X-IronPort-AV: E=Sophos;i="6.03,167,1694761200"; d="scan'208";a="380634183" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 20:38:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10840"; a="740942384" X-IronPort-AV: E=Sophos;i="6.03,167,1694761200"; d="scan'208";a="740942384" Received: from lcrossan-mobl.amr.corp.intel.com (HELO [10.209.1.119]) ([10.209.1.119]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 20:38:26 -0700 Message-ID: <36d465ca-d69f-4d52-a2c1-1468ebd02340@linux.intel.com> Date: Thu, 21 Sep 2023 20:38:26 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] x86/tdx: Dump TDX version During the TD Bootup Content-Language: en-US To: Yi Sun , kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org Cc: heng.su@intel.com, yi.sun@linux.intel.com, Dongcheng Yan References: <20230922030648.2596711-1-yi.sun@intel.com> From: Kuppuswamy Sathyanarayanan In-Reply-To: <20230922030648.2596711-1-yi.sun@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 20:38:34 -0700 (PDT) Hi, On 9/21/2023 8:06 PM, Yi Sun wrote: > It is essential for TD users to be aware of the vendor and version of > the current TDX. Additionally, they can reference the TDX version when > reporting bugs or issues. > > Furthermore, the applications or device drivers running in TD can achieve > enhanced reliability and flexibility by adhering to the TDX Module ABI > specification, as there are significant differences between various > versions of TDX. You can list some examples for where it can be used. For example, verifyreport module call only exist in TDX 1.5 and it should not be allowed for version < 1.5. > > During TD initialization, the TDX version info can be obtained by calling > TDG.SYS.RD. This will fetch the current version of TDX, including the major > and minor version numbers and vendor ID. > > The TDCALL TDG.SYS.RD originates from TDX version 1.5. If the error > TDCALL_INVALID_OPERAND occurs, it should be treated as TDX version 1.0. > > Co-developed-by: Dongcheng Yan > Signed-off-by: Dongcheng Yan > Signed-off-by: Yi Sun > > diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c > index 1d6b863c42b0..acf298ebbfd8 100644 > --- a/arch/x86/coco/tdx/tdx.c > +++ b/arch/x86/coco/tdx/tdx.c > @@ -37,6 +37,9 @@ > > #define TDREPORT_SUBTYPE_0 0 > > +/* Caches TDX Module global-scope metadata field via TDG.SYS.RD TDCALL */ > +static struct tdg_sys_info td_sys_info; I think it is __ro_after_init > + > /* Called from __tdx_hypercall() for unrecoverable failure */ > noinstr void __tdx_hypercall_failed(void) > { > @@ -757,6 +760,46 @@ static bool tdx_enc_status_change_finish(unsigned long vaddr, int numpages, > return true; > } > > +/* > + * Parse the tdx module version info from the global-scope metadata fields. > + */ > +static int tdg_get_sysinfo(void) > +{ > + struct tdx_module_output out; > + u64 ret; > + > + ret = __tdx_module_call(TDX_SYS_RD, 0, TDX_SYS_VENDOR_ID_FID, 0, 0, > + &out); > + if (TDCALL_RETURN_CODE(ret) == TDCALL_INVALID_OPERAND) > + goto version_1_0; > + else if (ret) > + return ret; > + > + td_sys_info.vendor_id = (u32)(out).r8; > + > + ret = __tdx_module_call(TDX_SYS_RD, 0, TDX_SYS_MAJOR_FID, 0, 0, &out); > + if (ret) > + return ret; > + > + td_sys_info.major_version = (u16)(out).r8; > + > + ret = __tdx_module_call(TDX_SYS_RD, 0, TDX_SYS_MINOR_FID, 0, 0, &out); > + if (ret) > + return ret; > + > + td_sys_info.minor_version = (u16)(out).r8; > + > + return 0; > + > + /* TDX 1.0 does not have the TDCALL TDG.SYS.RD */ > +version_1_0: > + td_sys_info.vendor_id = 0x8086; macro TDX_VENDOR_INTEL? > + td_sys_info.major_version = 1; > + td_sys_info.minor_version = 0; > + > + return 0; > +} > + > void __init tdx_early_init(void) > { > u64 cc_mask; > @@ -820,5 +863,9 @@ void __init tdx_early_init(void) > */ > x86_cpuinit.parallel_bringup = false; > > - pr_info("Guest detected\n"); > + tdg_get_sysinfo(); > + > + pr_info("Guest detected. TDX version:%u.%u VendorID: %x\n", > + td_sys_info.major_version, td_sys_info.minor_version, > + td_sys_info.vendor_id); > } > diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/shared/tdx.h > index 7513b3bb69b7..20ab96114970 100644 > --- a/arch/x86/include/asm/shared/tdx.h > +++ b/arch/x86/include/asm/shared/tdx.h > @@ -16,6 +16,7 @@ > #define TDX_GET_REPORT 4 > #define TDX_ACCEPT_PAGE 6 > #define TDX_WR 8 > +#define TDX_SYS_RD 11 > > /* TDCS fields. To be used by TDG.VM.WR and TDG.VM.RD module calls */ > #define TDCS_NOTIFY_ENABLES 0x9100000000000010 > @@ -26,6 +27,11 @@ > > #ifndef __ASSEMBLY__ > > +/* TDX metadata base field id, used by TDCALL TDG.SYS.RD */ IMO, you can add some spec section reference for it. > +#define TDX_SYS_VENDOR_ID_FID 0x0800000200000000ULL > +#define TDX_SYS_MINOR_FID 0x0800000100000003ULL > +#define TDX_SYS_MAJOR_FID 0x0800000100000004ULL > + Since you have no usage outside tdx.c, you can move it there. > /* > * Used in __tdx_hypercall() to pass down and get back registers' values of > * the TDCALL instruction when requesting services from the VMM. > diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h > index 603e6d1e9d4a..108409f24d59 100644 > --- a/arch/x86/include/asm/tdx.h > +++ b/arch/x86/include/asm/tdx.h > @@ -40,6 +40,12 @@ struct ve_info { > > #ifdef CONFIG_INTEL_TDX_GUEST > > +struct tdg_sys_info { > + u32 vendor_id; > + u16 major_version; > + u16 minor_version; > +}; > + same as above. You can move it to tdx.c > void __init tdx_early_init(void); > > void tdx_get_ve_info(struct ve_info *ve); -- Sathyanarayanan Kuppuswamy Linux Kernel Developer