From nobody Mon Feb 9 13:58:04 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 394BC259C83 for ; Mon, 7 Apr 2025 18:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744052392; cv=none; b=DW0e54NrAwSj/u3KTKjPEzG8shas+ZdqwnNm9G02bG55rjm+ecn63i0kTjbcyaVgehbqz9VhhJ5xSDFu/e4BZK5HT/ceM1g0axdmepiH2kM6pdewVs3Vb5Uuh9fEnT4CZOOW/oeo5zGjZH+FisiQNb8+b+QgxruLeWzvMc+2rjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744052392; c=relaxed/simple; bh=9Y5DnEYEwH1nz6mcqdGkg38W01G5BExqAvl0dZDCh/M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OgtPFOWFnzbp+TWTXlqnh6KVxAgPMClJO17mtEJHTlEZDD/PY+MoWMeYKQMBGKGKN2fqkHY0qYeSRk5ZhspCFAgfgyc8EDMbaWOR+vhVBxYtJpxQwBuf0jWQkcZhVc22Z2BLPabvcsoow4i3FyZtU1AI9knQ/R1sF65+pmRG4bk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Nyponodm; arc=none smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Nyponodm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744052390; x=1775588390; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=9Y5DnEYEwH1nz6mcqdGkg38W01G5BExqAvl0dZDCh/M=; b=NyponodmZZu3zyar/wd4JgOy5U3Bx8k8CXJlIPIafIyWavQjNbk9PNNC S9SfyNcCyveLN4dlU92gvPN2zlJFmYD0Gks11qp+r0xxC7r20MdrWDJcz naaysNm/ep2ADy4QjJ3rRQWJg1ZqPof78Y+RjbAGfVOJOTPXM9arv6GKi HbTq44wxtrb1Piongtk9RPxWODkFNDuvCl8K8VdpQTAGMgatczFOc4Ock jBlW3kC07p7e58gf3IjIZvD776gw9G/OnT3vtofcSnuYY/m/YkJPzmnxq MQGqnt+WRv8WzJBGxVcTbx0Jmv/o/byNU4r/ECZ1j5s7Mq5jELs78hTq7 A==; X-CSE-ConnectionGUID: hSu5+blkTHaBa11J75I/9A== X-CSE-MsgGUID: puGvmEJiT2iYfKhs9/pWbA== X-IronPort-AV: E=McAfee;i="6700,10204,11397"; a="62999710" X-IronPort-AV: E=Sophos;i="6.15,194,1739865600"; d="scan'208";a="62999710" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2025 11:59:50 -0700 X-CSE-ConnectionGUID: fRoB4Om7SACkBB/cGEpqkg== X-CSE-MsgGUID: vfmKSEoJR0+S3bunBCiJ0w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,194,1739865600"; d="scan'208";a="128899320" Received: from trung68x-mobl.amr.corp.intel.com (HELO bxing-mobl1.clients.intel.com) ([10.246.115.210]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2025 11:59:48 -0700 From: Cedric Xing Date: Mon, 07 Apr 2025 13:59:30 -0500 Subject: [PATCH v3 3/5] x86/tdx: Add tdx_mcall_extend_rtmr() interface Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250407-tdx-rtmr-v3-3-54f17bc65228@intel.com> References: <20250407-tdx-rtmr-v3-0-54f17bc65228@intel.com> In-Reply-To: <20250407-tdx-rtmr-v3-0-54f17bc65228@intel.com> To: Dan Williams , "Kirill A. Shutemov" , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Cc: linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, Dionna Amalie Glaze , Guorui Yu , James Bottomley , Dan Middleton , Mikko Ylinen , Sathyanarayanan Kuppuswamy X-Mailer: b4 0.13.0 The TDX guest exposes one MRTD (Build-time Measurement Register) and four RTMR (Run-time Measurement Register) registers to record the build and boot measurements of a virtual machine (VM). These registers are similar to PCR (Platform Configuration Register) registers in the TPM (Trusted Platform Module) space. This measurement data is used to implement security features like attestation and trusted boot. To facilitate updating the RTMR registers, the TDX module provides support for the `TDG.MR.RTMR.EXTEND` TDCALL which can be used to securely extend the RTMR registers. Add helper function to update RTMR registers. It will be used by the TDX guest driver in enabling RTMR extension support. Signed-off-by: Kuppuswamy Sathyanarayanan Signed-off-by: Cedric Xing Reviewed-by: Dan Williams --- arch/x86/coco/tdx/tdx.c | 36 ++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/shared/tdx.h | 1 + arch/x86/include/asm/tdx.h | 2 ++ 3 files changed, 39 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index edab6d6049be..b042ca74bcd3 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -36,6 +36,7 @@ /* TDX Module call error codes */ #define TDCALL_RETURN_CODE(a) ((a) >> 32) #define TDCALL_INVALID_OPERAND 0xc0000100 +#define TDCALL_OPERAND_BUSY 0x80000200 =20 #define TDREPORT_SUBTYPE_0 0 =20 @@ -136,6 +137,41 @@ int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport) } EXPORT_SYMBOL_GPL(tdx_mcall_get_report0); =20 +/** + * tdx_mcall_extend_rtmr() - Wrapper to extend RTMR registers using + * TDG.MR.RTMR.EXTEND TDCALL. + * @index: Index of RTMR register to be extended. + * @data: Address of the input buffer with RTMR register extend data. + * + * Refer to section titled "TDG.MR.RTMR.EXTEND leaf" in the TDX Module + * v1.0 specification for more information on TDG.MR.RTMR.EXTEND TDCALL. + * It is used in the TDX guest driver module to allow user extend the + * RTMR registers (index > 1). + * + * Return 0 on success, -EINVAL for invalid operands, -EBUSY for busy + * operation or -EIO on other TDCALL failures. + */ +int tdx_mcall_extend_rtmr(u8 index, u8 *data) +{ + struct tdx_module_args args =3D { + .rcx =3D virt_to_phys(data), + .rdx =3D index, + }; + u64 ret; + + ret =3D __tdcall(TDG_MR_RTMR_EXTEND, &args); + if (ret) { + if (TDCALL_RETURN_CODE(ret) =3D=3D TDCALL_INVALID_OPERAND) + return -EINVAL; + if (TDCALL_RETURN_CODE(ret) =3D=3D TDCALL_OPERAND_BUSY) + return -EBUSY; + return -EIO; + } + + return 0; +} +EXPORT_SYMBOL_GPL(tdx_mcall_extend_rtmr); + /** * tdx_hcall_get_quote() - Wrapper to request TD Quote using GetQuote * hypercall. diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/share= d/tdx.h index a28ff6b14145..738f583f65cb 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -13,6 +13,7 @@ /* TDX module Call Leaf IDs */ #define TDG_VP_VMCALL 0 #define TDG_VP_INFO 1 +#define TDG_MR_RTMR_EXTEND 2 #define TDG_VP_VEINFO_GET 3 #define TDG_MR_REPORT 4 #define TDG_MEM_PAGE_ACCEPT 6 diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 4a1922ec80cf..12d17f3ca301 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -64,6 +64,8 @@ bool tdx_early_handle_ve(struct pt_regs *regs); =20 int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport); =20 +int tdx_mcall_extend_rtmr(u8 index, u8 *data); + u64 tdx_hcall_get_quote(u8 *buf, size_t size); =20 void __init tdx_dump_attributes(u64 td_attr); --=20 2.43.0