From nobody Wed Dec 17 05:27:03 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 4716A1A3176 for ; Mon, 24 Feb 2025 03:21:59 +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=1740367321; cv=none; b=gxhAkKPiGYnQkJ2DOV/NY+w5GcPWx9Mw860515NOUUMO54RUVX36gL7luUQ7vH2ui1D7oTZ3qtanNQMKz7/Vptf0yE6TwbmP+igI3oh3bmYuHGw0k/dbF/3YICo/FYZrQQZQYO5fzWs6Tke5k+yxyW5K13j4jnVfefOwliayBFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740367321; c=relaxed/simple; bh=taadowUR5/58ys41IAsM9k+P+FmsnUdHVJhEU6NXOls=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cncd0EsEqCk5KkJ+RNTVOptiRX/xFYYpGCJ3FHo0PjhOkH4jlKDe6XLCFXz/xktTgwg1qG3PhWM0XJ3gL791kB9KZJqxMyJdBpcPM3V5OslvdeYYseXT5KRwS7pu1jGx5VfWR++DsPgOPz3YH9lbVzsq2sqSTNFa2aajyk/jzXg= 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=VuyPAp2I; 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="VuyPAp2I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1740367320; x=1771903320; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=taadowUR5/58ys41IAsM9k+P+FmsnUdHVJhEU6NXOls=; b=VuyPAp2IzNF7GYY13qCV4I3JRmy+FlE/21kozeQKq4vG/bwaEahNPV+o IdvRScHqwCYRSkFJxmlQuGEedbfHl5iiRKwntd0d9AomRJWu2GUeUKTaF 3wouNWIrKUWQnwAp3Yhru+VevYVZdVztNqOQ0qyc/sWP1RgrE91ymdPuR eVb+QRmmsT8MI4EdvJ3lDPd0BGMF4yxFQkOqee58b75LGz1pGdNsB7F6W WD6wkTVUZnghk73536qGHDFYd9nv2zMH89ghXDJA8aaf/UcQj5WJwHX1l qO8cLLix+8opmnKsnjZwO/pP5wHuXRBUW6hTWBJkVTcpEZ5A/Znii8fvz w==; X-CSE-ConnectionGUID: 91UgikEZSomvbyzWP1Z+sw== X-CSE-MsgGUID: plqFTYT3TACzm5PylDoWCg== X-IronPort-AV: E=McAfee;i="6700,10204,11354"; a="28706884" X-IronPort-AV: E=Sophos;i="6.13,309,1732608000"; d="scan'208";a="28706884" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2025 19:21:56 -0800 X-CSE-ConnectionGUID: dtwl4QAgROmEkAs/LCc1xQ== X-CSE-MsgGUID: DM3mpKcgSsygBmtDyZkTgQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,309,1732608000"; d="scan'208";a="116441904" Received: from shanagud-mobl.amr.corp.intel.com (HELO bxing-mobl1.clients.intel.com) ([10.246.117.251]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2025 19:21:16 -0800 From: Cedric Xing Date: Sun, 23 Feb 2025 21:20:14 -0600 Subject: [PATCH v2 3/4] 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: <20250223-tdx-rtmr-v2-3-f2d85b0a5f94@intel.com> References: <20250223-tdx-rtmr-v2-0-f2d85b0a5f94@intel.com> In-Reply-To: <20250223-tdx-rtmr-v2-0-f2d85b0a5f94@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 , 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 --- 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 32809a06dab4..f88e249e339a 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -35,6 +35,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 @@ -135,6 +136,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 fcbbef484a78..d0760c6160cc 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 b4b16dafd55e..6b98d7dc5207 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