Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1958449rdb; Tue, 3 Oct 2023 06:27:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEw5sxPCSm6LKWd33niFTFHur0hsZ5GStdPaFSusbbbw1JYQsCIuiY98kuMJUHhv3CRV23h X-Received: by 2002:a05:6a00:148d:b0:68b:a137:3739 with SMTP id v13-20020a056a00148d00b0068ba1373739mr15103556pfu.4.1696339636582; Tue, 03 Oct 2023 06:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696339636; cv=none; d=google.com; s=arc-20160816; b=bpuClAlAB22fqt7jbD6yfUD/4OtuuXljdnyJCyoSN0ijogszyBCpfu12i4715T8vGm puRmsPmkRf7P6iN2sg+MMbvshSX5SRSzRa3rRKuD64QYUZPMld1B0Uoo0wmd+QDkAHJB F/ha1liZMXYcgpRImZj96W5aTtFAhCgGPcuUuuqxbNaiLpSgvBHuKk6jcKaSzcxVKRPd DpFINMKRtJzjXBv2SQ+5rm9VMUqcySpZFq28gIA96VClQ1Ed3SpHx6b5f25hsH9fYNtA Cy3EnjoYk0anQu6H2DLKk83If2y9409gdevlqYi/HW615WANN1WnMjjJt8dpgDLA40Xs JpHQ== 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=0rGlzgIa7R5qtNsRwXuDSuUmCVKvP+fPcY+nmSCacj0=; fh=CamRO3us3c86yUl0dy+WRuT0xYGa4SZGrS3TSCPFkMk=; b=yoVJ8J4/KdGxeiyPRlrukalQcqXCircj5eorAbK9jscOtYKRMzfhbvAfozHjtQIGmo sey3xZHIYqaG7ERwp3lJGXne8IYfYcEf3Pu+ORY0fSmeu7h9lS7o6H/BbNVxmrv8p80P IVEwE3x7N6ytLMy1ALWOyemR1FIWkMhHTBdrWyNoh9ZOs18FylDq6QgcONYRJtHENswV cnY88VMItKIm/Xwh5gb4vLBsxHKW4gcC8cd41XLXBNzey6VGfHns2Vu8DkQoja5JpYk8 b8GlawRZKbz7tg6OEfw7TGybc/9NYyShUzNMPj0LbhF4gB7eJadawl4bIDmSZbqG2PEF 5q7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="IqrX/JrS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id j184-20020a638bc1000000b005775e2a7951si1420452pge.345.2023.10.03.06.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 06:27:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="IqrX/JrS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id AC0058029C77; Tue, 3 Oct 2023 06:27:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232745AbjJCN0s (ORCPT + 99 others); Tue, 3 Oct 2023 09:26:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230437AbjJCN0s (ORCPT ); Tue, 3 Oct 2023 09:26:48 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB274A1 for ; Tue, 3 Oct 2023 06:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696339604; x=1727875604; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=KbgIEUN3KVqwnf1BzBp9QZHuTVKZ3J1u5/5OyhJsaEI=; b=IqrX/JrSc6zSXbWuihhz2nnDGuBmtyaNmiMbuqgl7VVeyuICOh3i/k6t 2Z9SZ2G/z+/CAP2FIQp1+WvnreJHDk3qaEME01EpnU2jtVECblF7AWN6z KkXNkGPi99jEqsv43EmDjXGtE48AoWNX2isah2eR0vaRmUhnAJ+5TTs2n Kw+DxdALN1dfkv1Umo1uhGoDsJ+GMPBZaIvf7a2+fF71U0Gm6X5GcwyJR X8HXWbTNhN90LX8sWUXgnenRe3PCSfoaKqgYIu7ed9v4yIRsnZbIwl6xE 1tTB4Zouq3VT+rZbsveyAJaauq4vJwoXIU/Fk3eYLZu6aaAfVlaNhrvt4 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10852"; a="381750602" X-IronPort-AV: E=Sophos;i="6.03,197,1694761200"; d="scan'208";a="381750602" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2023 06:26:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10852"; a="786091478" X-IronPort-AV: E=Sophos;i="6.03,197,1694761200"; d="scan'208";a="786091478" Received: from sknagara-mobl2.amr.corp.intel.com (HELO [10.209.121.241]) ([10.209.121.241]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2023 06:26:44 -0700 Message-ID: <483ee0eb-cc14-44a4-9c3b-77a6d0860359@linux.intel.com> Date: Tue, 3 Oct 2023 06:26:45 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] 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: <20230930161110.3251107-1-yi.sun@intel.com> From: Kuppuswamy Sathyanarayanan In-Reply-To: <20230930161110.3251107-1-yi.sun@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Tue, 03 Oct 2023 06:27:06 -0700 (PDT) On 9/30/2023 9:11 AM, 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 following the TDX Module ABI > specification, because there are significant differences between different > versions of TDX, as mentioned in the "IntelĀ® TDX Module Incompatibilities > between v1.0 and v1.5" reference. Here are a few examples: > > MSR Name Index Reason > ---------------------------------------------- > IA32_UARCH_MISC_CTL 0x1B01 From v1.5 > IA32_ARCH_CAPABILITIES 0x010A Changed in v1.5 > IA32_TSX_CTRL 0x0122 Changed in v1.5 > > CPUID Leaf Sub-leaf Reason > --------------------------------------- > 0x7 2 From v1.5 > 0x22 0 From v1.5 > 0x23 0~3 From v1.5 > 0x80000007 0 From v1.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..052376d521d1 100644 > --- a/arch/x86/coco/tdx/tdx.c > +++ b/arch/x86/coco/tdx/tdx.c > @@ -37,6 +37,24 @@ > > #define TDREPORT_SUBTYPE_0 0 > > +/* > + * TDX metadata base field id, used by TDCALL TDG.SYS.RD > + * See TDX ABI Spec section 3.3.2.3 Global Metadata Fields > + */ > +#define TDX_SYS_VENDOR_ID_FID 0x0800000200000000ULL > +#define TDX_SYS_MINOR_FID 0x0800000100000003ULL > +#define TDX_SYS_MAJOR_FID 0x0800000100000004ULL > +#define TDX_VENDOR_INTEL 0x8086 > + > +/* > + * The global-scope metadata field via TDG.SYS.RD TDCALL > + */ > +struct tdg_sys_info { > + u32 vendor_id; > + u16 major_version; > + u16 minor_version; > +}; > + > /* Called from __tdx_hypercall() for unrecoverable failure */ > noinstr void __tdx_hypercall_failed(void) > { > @@ -757,10 +775,54 @@ 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(struct tdg_sys_info *td_sys) > +{ > + struct tdx_module_output out; > + u64 ret; > + > + if (!td_sys) > + return -EINVAL; > + > + 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; For this failure case, do you want to reset tdg_sys_info to some value like zero or some constants to specify unknown? > + > + td_sys->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->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->minor_version = (u16)out.r8; > + > + return 0; > + > + /* TDX 1.0 does not have the TDCALL TDG.SYS.RD */ > +version_1_0: > + td_sys->vendor_id = TDX_VENDOR_INTEL; > + td_sys->major_version = 1; > + td_sys->minor_version = 0; > + > + return 0; > +} > + > void __init tdx_early_init(void) > { > u64 cc_mask; > u32 eax, sig[3]; > + struct tdg_sys_info td_sys_info; > > cpuid_count(TDX_CPUID_LEAF_ID, 0, &eax, &sig[0], &sig[2], &sig[1]); > > @@ -820,5 +882,9 @@ void __init tdx_early_init(void) > */ > x86_cpuinit.parallel_bringup = false; > > - pr_info("Guest detected\n"); > + tdg_get_sysinfo(&td_sys_info); Why not check the return value before dumping the info? > + > + 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..10ecb5dece84 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 -- Sathyanarayanan Kuppuswamy Linux Kernel Developer