Skip to content

Commit fae43b2

Browse files
kaihuanghansendc
authored andcommitted
x86/virt/tdx: Switch to use auto-generated global metadata reading code
Continue the process to have a centralized solution for TDX global metadata reading. Now that the new autogenerated solution is ready for use, switch to it and remove the old one. Signed-off-by: Kai Huang <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Nikolay Borisov <[email protected]> Reviewed-by: Dan Williams <[email protected]> Link: https://lore.kernel.org/all/fc025d1e13b92900323f47cfe9aac3157bf08ee7.1734188033.git.kai.huang%40intel.com
1 parent 6bfb77f commit fae43b2

File tree

2 files changed

+2
-104
lines changed

2 files changed

+2
-104
lines changed

arch/x86/virt/vmx/tdx/tdx.c

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -270,66 +270,7 @@ static int read_sys_metadata_field(u64 field_id, u64 *data)
270270
return 0;
271271
}
272272

273-
static int read_sys_metadata_field16(u64 field_id,
274-
int offset,
275-
struct tdx_sys_info_tdmr *ts)
276-
{
277-
u16 *ts_member = ((void *)ts) + offset;
278-
u64 tmp;
279-
int ret;
280-
281-
if (WARN_ON_ONCE(MD_FIELD_ID_ELE_SIZE_CODE(field_id) !=
282-
MD_FIELD_ID_ELE_SIZE_16BIT))
283-
return -EINVAL;
284-
285-
ret = read_sys_metadata_field(field_id, &tmp);
286-
if (ret)
287-
return ret;
288-
289-
*ts_member = tmp;
290-
291-
return 0;
292-
}
293-
294-
struct field_mapping {
295-
u64 field_id;
296-
int offset;
297-
};
298-
299-
#define TD_SYSINFO_MAP(_field_id, _offset) \
300-
{ .field_id = MD_FIELD_ID_##_field_id, \
301-
.offset = offsetof(struct tdx_sys_info_tdmr, _offset) }
302-
303-
/* Map TD_SYSINFO fields into 'struct tdx_sys_info_tdmr': */
304-
static const struct field_mapping fields[] = {
305-
TD_SYSINFO_MAP(MAX_TDMRS, max_tdmrs),
306-
TD_SYSINFO_MAP(MAX_RESERVED_PER_TDMR, max_reserved_per_tdmr),
307-
TD_SYSINFO_MAP(PAMT_4K_ENTRY_SIZE, pamt_4k_entry_size),
308-
TD_SYSINFO_MAP(PAMT_2M_ENTRY_SIZE, pamt_2m_entry_size),
309-
TD_SYSINFO_MAP(PAMT_1G_ENTRY_SIZE, pamt_1g_entry_size),
310-
};
311-
312-
static int get_tdx_sys_info_tdmr(struct tdx_sys_info_tdmr *sysinfo_tdmr)
313-
{
314-
int ret;
315-
int i;
316-
317-
/* Populate 'sysinfo_tdmr' fields using the mapping structure above: */
318-
for (i = 0; i < ARRAY_SIZE(fields); i++) {
319-
ret = read_sys_metadata_field16(fields[i].field_id,
320-
fields[i].offset,
321-
sysinfo_tdmr);
322-
if (ret)
323-
return ret;
324-
}
325-
326-
return 0;
327-
}
328-
329-
static int get_tdx_sys_info(struct tdx_sys_info *sysinfo)
330-
{
331-
return get_tdx_sys_info_tdmr(&sysinfo->tdmr);
332-
}
273+
#include "tdx_global_metadata.c"
333274

334275
/* Calculate the actual TDMR size */
335276
static int tdmr_size_single(u16 max_reserved_per_tdmr)

arch/x86/virt/vmx/tdx/tdx.h

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef _X86_VIRT_TDX_H
33
#define _X86_VIRT_TDX_H
44

5-
#include <linux/bits.h>
5+
#include "tdx_global_metadata.h"
66

77
/*
88
* This file contains both macros and data structures defined by the TDX
@@ -26,35 +26,6 @@
2626
#define PT_NDA 0x0
2727
#define PT_RSVD 0x1
2828

29-
/*
30-
* Global scope metadata field ID.
31-
*
32-
* See Table "Global Scope Metadata", TDX module 1.5 ABI spec.
33-
*/
34-
#define MD_FIELD_ID_MAX_TDMRS 0x9100000100000008ULL
35-
#define MD_FIELD_ID_MAX_RESERVED_PER_TDMR 0x9100000100000009ULL
36-
#define MD_FIELD_ID_PAMT_4K_ENTRY_SIZE 0x9100000100000010ULL
37-
#define MD_FIELD_ID_PAMT_2M_ENTRY_SIZE 0x9100000100000011ULL
38-
#define MD_FIELD_ID_PAMT_1G_ENTRY_SIZE 0x9100000100000012ULL
39-
40-
/*
41-
* Sub-field definition of metadata field ID.
42-
*
43-
* See Table "MD_FIELD_ID (Metadata Field Identifier / Sequence Header)
44-
* Definition", TDX module 1.5 ABI spec.
45-
*
46-
* - Bit 33:32: ELEMENT_SIZE_CODE -- size of a single element of metadata
47-
*
48-
* 0: 8 bits
49-
* 1: 16 bits
50-
* 2: 32 bits
51-
* 3: 64 bits
52-
*/
53-
#define MD_FIELD_ID_ELE_SIZE_CODE(_field_id) \
54-
(((_field_id) & GENMASK_ULL(33, 32)) >> 32)
55-
56-
#define MD_FIELD_ID_ELE_SIZE_16BIT 1
57-
5829
struct tdmr_reserved_area {
5930
u64 offset;
6031
u64 size;
@@ -80,20 +51,6 @@ struct tdmr_info {
8051
DECLARE_FLEX_ARRAY(struct tdmr_reserved_area, reserved_areas);
8152
} __packed __aligned(TDMR_INFO_ALIGNMENT);
8253

83-
/* Class "TDMR info" */
84-
struct tdx_sys_info_tdmr {
85-
u16 max_tdmrs;
86-
u16 max_reserved_per_tdmr;
87-
u16 pamt_4k_entry_size;
88-
u16 pamt_2m_entry_size;
89-
u16 pamt_1g_entry_size;
90-
};
91-
92-
/* Kernel used global metadata fields */
93-
struct tdx_sys_info {
94-
struct tdx_sys_info_tdmr tdmr;
95-
};
96-
9754
/*
9855
* Do not put any hardware-defined TDX structure representations below
9956
* this comment!

0 commit comments

Comments
 (0)