From nobody Tue Dec 16 14:36:27 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (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 83A9121CC70 for ; Tue, 6 May 2025 22:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746572259; cv=none; b=evVq50F+7ll23OiyTzg5LtwxKwSR37SjJIjPeqcO157p4KUbuZn+oE9H4wTvdDYghU8nJUOX/6n72yRAyp1Be0WIes3Wkc/hKmD+4V+kZXqugQNk6arPD2hZViCRXni3EOl2FKUQ2Dve+PM7PTmYP3CVTO8gMQxeABUywiWoj1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746572259; c=relaxed/simple; bh=O/EQft+2QUIRW2zTISUf80MIDUhtKOyW3qY4DwmeI8Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FEcqz9FkuCTXBEvMsmCoQETnKyei7qYomCCd0WrRurfZbm7i47vKz6eg8qqkE+xtdj4TedYB3Wn3zTvYJB6A+okSbn7UXLpq1UcSjcCguEjBDu7K0Ap7/e7ga/wAYLEjKXGG5GrtkTku+mDdzQlyIlXzEsq2HTDnGHFUCQ4sQD8= 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=I29Sg40M; arc=none smtp.client-ip=192.198.163.16 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="I29Sg40M" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1746572257; x=1778108257; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=O/EQft+2QUIRW2zTISUf80MIDUhtKOyW3qY4DwmeI8Q=; b=I29Sg40MN9Y+4sO6FzO8P/cSfdU88Iid60iEikxm7308r34wDREXzdDx F6Y8TUZ9OzLGFZbKFWvAUjc7RfEWpBRw8dYJsF8sxCOIXpu5yIGNtoWzt HpSP+tYcyi3jlzZcE+FefJX8dM15SWtLxGWO+UXUwRPoziQohppAoFec7 wCYChSBYFkdYjdIGT3xpNWXKXpFufF1Bq7JONxDaP092t8hdmpjdPUSKP Ctf4nj0AfHBdYZyv7DRTGXMl3Lj0i28rRTrYFzNkShfh7QyCCRpF4M5sf PqL3xQ0KbC695FQhPalvQ5Fr2JSw4NcKQDcknk9kvE94wZCc1WuSATkoN g==; X-CSE-ConnectionGUID: upuQSD+sRkaESWzQU3hrAQ== X-CSE-MsgGUID: IDvAPD7hTU224xwSIjAhBA== X-IronPort-AV: E=McAfee;i="6700,10204,11425"; a="35898326" X-IronPort-AV: E=Sophos;i="6.15,267,1739865600"; d="scan'208";a="35898326" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2025 15:57:36 -0700 X-CSE-ConnectionGUID: saQnWxX6RAWxZ2naZuQIvA== X-CSE-MsgGUID: AgLvpHkqSJy3TAym+pvvQg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,267,1739865600"; d="scan'208";a="135477000" Received: from sjdobek-mobl3.amr.corp.intel.com (HELO bxing-mobl1.clients.intel.com) ([10.246.114.48]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2025 15:57:35 -0700 From: Cedric Xing Date: Tue, 06 May 2025 17:57:09 -0500 Subject: [PATCH v6 3/7] 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: <20250506-tdx-rtmr-v6-3-ac6ff5e9d58a@intel.com> References: <20250506-tdx-rtmr-v6-0-ac6ff5e9d58a@intel.com> In-Reply-To: <20250506-tdx-rtmr-v6-0-ac6ff5e9d58a@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 , Cedric Xing X-Mailer: b4 0.14.2 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. Co-developed-by: Kuppuswamy Sathyanarayanan Signed-off-by: Kuppuswamy Sathyanarayanan Signed-off-by: Cedric Xing Acked-by: Dionna Amalie Glaze Acked-by: Dave Hansen --- arch/x86/coco/tdx/tdx.c | 37 +++++++++++++++++++++++++++++++++++= ++ arch/x86/include/asm/shared/tdx.h | 1 + arch/x86/include/asm/tdx.h | 2 ++ 3 files changed, 40 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index edab6d6049bedfb8b7cb2cbb57ab0a670bb6a6c6..0b6804d2a5e14d3ccbee5d19ad8= ae6674527fb2f 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,42 @@ 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 to extend the R= TMR + * registers. + * + * Return 0 on success, -ENXIO for invalid operands, -EBUSY for busy opera= tion, + * 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 -ENXIO; + 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 a28ff6b141458b57e0bb333646328ea302678d3a..738f583f65cb00a12494b027a5b= 41347734b044e 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 4a1922ec80cf76ffb9662d0dd34eb02a7c66b4d4..12d17f3ca3016a1bfeb37f07d82= 721331826fd96 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