Skip to content

Commit 3f88ca9

Browse files
binxingdjbw
authored andcommitted
x86/tdx: Add tdx_mcall_extend_rtmr() interface
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 <sathyanarayanan.kuppuswamy@linux.intel.com> Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Signed-off-by: Cedric Xing <cedric.xing@intel.com> Acked-by: Dionna Amalie Glaze <dionnaglaze@google.com> Acked-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://patch.msgid.link/20250506-tdx-rtmr-v6-3-ac6ff5e9d58a@intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent f6953f1 commit 3f88ca9

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

arch/x86/coco/tdx/tdx.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
/* TDX Module call error codes */
3737
#define TDCALL_RETURN_CODE(a) ((a) >> 32)
3838
#define TDCALL_INVALID_OPERAND 0xc0000100
39+
#define TDCALL_OPERAND_BUSY 0x80000200
3940

4041
#define TDREPORT_SUBTYPE_0 0
4142

@@ -136,6 +137,42 @@ int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport)
136137
}
137138
EXPORT_SYMBOL_GPL(tdx_mcall_get_report0);
138139

140+
/**
141+
* tdx_mcall_extend_rtmr() - Wrapper to extend RTMR registers using
142+
* TDG.MR.RTMR.EXTEND TDCALL.
143+
* @index: Index of RTMR register to be extended.
144+
* @data: Address of the input buffer with RTMR register extend data.
145+
*
146+
* Refer to section titled "TDG.MR.RTMR.EXTEND leaf" in the TDX Module v1.0
147+
* specification for more information on TDG.MR.RTMR.EXTEND TDCALL.
148+
*
149+
* It is used in the TDX guest driver module to allow user to extend the RTMR
150+
* registers.
151+
*
152+
* Return 0 on success, -ENXIO for invalid operands, -EBUSY for busy operation,
153+
* or -EIO on other TDCALL failures.
154+
*/
155+
int tdx_mcall_extend_rtmr(u8 index, u8 *data)
156+
{
157+
struct tdx_module_args args = {
158+
.rcx = virt_to_phys(data),
159+
.rdx = index,
160+
};
161+
u64 ret;
162+
163+
ret = __tdcall(TDG_MR_RTMR_EXTEND, &args);
164+
if (ret) {
165+
if (TDCALL_RETURN_CODE(ret) == TDCALL_INVALID_OPERAND)
166+
return -ENXIO;
167+
if (TDCALL_RETURN_CODE(ret) == TDCALL_OPERAND_BUSY)
168+
return -EBUSY;
169+
return -EIO;
170+
}
171+
172+
return 0;
173+
}
174+
EXPORT_SYMBOL_GPL(tdx_mcall_extend_rtmr);
175+
139176
/**
140177
* tdx_hcall_get_quote() - Wrapper to request TD Quote using GetQuote
141178
* hypercall.

arch/x86/include/asm/shared/tdx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/* TDX module Call Leaf IDs */
1414
#define TDG_VP_VMCALL 0
1515
#define TDG_VP_INFO 1
16+
#define TDG_MR_RTMR_EXTEND 2
1617
#define TDG_VP_VEINFO_GET 3
1718
#define TDG_MR_REPORT 4
1819
#define TDG_MEM_PAGE_ACCEPT 6

arch/x86/include/asm/tdx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ bool tdx_early_handle_ve(struct pt_regs *regs);
6464

6565
int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport);
6666

67+
int tdx_mcall_extend_rtmr(u8 index, u8 *data);
68+
6769
u64 tdx_hcall_get_quote(u8 *buf, size_t size);
6870

6971
void __init tdx_dump_attributes(u64 td_attr);

0 commit comments

Comments
 (0)