Skip to content

Commit caa2769

Browse files
committed
x86/tdx: Add a wrapper to get TDREPORT0 from the TDX Module
Bugzilla: https://bugzilla.redhat.com/2076749 commit 51acfe8 Author: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Date: Wed Nov 16 14:38:18 2022 -0800 x86/tdx: Add a wrapper to get TDREPORT0 from the TDX Module To support TDX attestation, the TDX guest driver exposes an IOCTL interface to allow userspace to get the TDREPORT0 (a.k.a. TDREPORT subtype 0) from the TDX module via TDG.MR.TDREPORT TDCALL. In order to get the TDREPORT0 in the TDX guest driver, instead of using a low level function like __tdx_module_call(), add a tdx_mcall_get_report0() wrapper function to handle it. This is a preparatory patch for adding attestation support. Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Acked-by: Wander Lairson Costa <wander@redhat.com> Link: https://lore.kernel.org/all/20221116223820.819090-2-sathyanarayanan.kuppuswamy%40linux.intel.com Signed-off-by: Wander Lairson Costa <wander@redhat.com>
1 parent 61a5f34 commit caa2769

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

arch/x86/coco/tdx/tdx.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#define pr_fmt(fmt) "tdx: " fmt
66

77
#include <linux/cpufeature.h>
8+
#include <linux/export.h>
9+
#include <linux/io.h>
810
#include <asm/coco.h>
911
#include <asm/tdx.h>
1012
#include <asm/vmx.h>
@@ -15,6 +17,7 @@
1517
/* TDX module Call Leaf IDs */
1618
#define TDX_GET_INFO 1
1719
#define TDX_GET_VEINFO 3
20+
#define TDX_GET_REPORT 4
1821
#define TDX_ACCEPT_PAGE 6
1922

2023
/* TDX hypercall Leaf IDs */
@@ -36,6 +39,12 @@
3639

3740
#define ATTR_SEPT_VE_DISABLE BIT(28)
3841

42+
/* TDX Module call error codes */
43+
#define TDCALL_RETURN_CODE(a) ((a) >> 32)
44+
#define TDCALL_INVALID_OPERAND 0xc0000100
45+
46+
#define TDREPORT_SUBTYPE_0 0
47+
3948
/*
4049
* Wrapper for standard use of __tdx_hypercall with no output aside from
4150
* return code.
@@ -100,6 +109,37 @@ static inline void tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
100109
panic("TDCALL %lld failed (Buggy TDX module!)\n", fn);
101110
}
102111

112+
/**
113+
* tdx_mcall_get_report0() - Wrapper to get TDREPORT0 (a.k.a. TDREPORT
114+
* subtype 0) using TDG.MR.REPORT TDCALL.
115+
* @reportdata: Address of the input buffer which contains user-defined
116+
* REPORTDATA to be included into TDREPORT.
117+
* @tdreport: Address of the output buffer to store TDREPORT.
118+
*
119+
* Refer to section titled "TDG.MR.REPORT leaf" in the TDX Module
120+
* v1.0 specification for more information on TDG.MR.REPORT TDCALL.
121+
* It is used in the TDX guest driver module to get the TDREPORT0.
122+
*
123+
* Return 0 on success, -EINVAL for invalid operands, or -EIO on
124+
* other TDCALL failures.
125+
*/
126+
int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport)
127+
{
128+
u64 ret;
129+
130+
ret = __tdx_module_call(TDX_GET_REPORT, virt_to_phys(tdreport),
131+
virt_to_phys(reportdata), TDREPORT_SUBTYPE_0,
132+
0, NULL);
133+
if (ret) {
134+
if (TDCALL_RETURN_CODE(ret) == TDCALL_INVALID_OPERAND)
135+
return -EINVAL;
136+
return -EIO;
137+
}
138+
139+
return 0;
140+
}
141+
EXPORT_SYMBOL_GPL(tdx_mcall_get_report0);
142+
103143
static void tdx_parse_tdinfo(u64 *cc_mask)
104144
{
105145
struct tdx_module_output out;

arch/x86/include/asm/tdx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ void tdx_safe_halt(void);
6767

6868
bool tdx_early_handle_ve(struct pt_regs *regs);
6969

70+
int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport);
71+
7072
#else
7173

7274
static inline void tdx_early_init(void) { };

0 commit comments

Comments
 (0)