Kai Huang wrote: > The TDX module provides "global metadata fields" for software to query. > Each metadata field is accessible by a unique "metadata field ID". TDX > supports 8/16/32/64 bits metadata element sizes. The size of each > metadata field is encoded in its associated metadata field ID. > > For now the kernel only reads "TD Memory Region" (TDMR) related global > metadata fields for module initialization. All these metadata fields > are 16-bit, and the kernel only supports reading 16-bit fields. > > Future changes will need to read more metadata fields with other element > sizes. To resolve this once for all, extend the existing metadata > reading code to support reading all element sizes. > > Signed-off-by: Kai Huang <kai.huang@xxxxxxxxx> > Reviewed-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> > --- > > v1 -> v2 (Nikolay): > - MD_FIELD_BYTES() -> MD_FIELD_ELE_SIZE(). > - 'bytes' -> 'size' in stbuf_read_sysmd_field(). > > --- > arch/x86/virt/vmx/tdx/tdx.c | 29 ++++++++++++++++------------- > arch/x86/virt/vmx/tdx/tdx.h | 3 ++- > 2 files changed, 18 insertions(+), 14 deletions(-) > > diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c > index 2ce03c3ea017..4644b324ff86 100644 > --- a/arch/x86/virt/vmx/tdx/tdx.c > +++ b/arch/x86/virt/vmx/tdx/tdx.c > @@ -270,23 +270,25 @@ static int read_sys_metadata_field(u64 field_id, u64 *data) > return 0; > } > > -static int read_sys_metadata_field16(u64 field_id, > - int offset, > - void *stbuf) > +/* > + * Read one global metadata field and store the data to a location of a > + * given buffer specified by the offset and size (in bytes). > + */ > +static int stbuf_read_sysmd_field(u64 field_id, void *stbuf, int offset, > + int size) > { > - u16 *member = stbuf + offset; > + void *member = stbuf + offset; > u64 tmp; > int ret; > > - if (WARN_ON_ONCE(MD_FIELD_ID_ELE_SIZE_CODE(field_id) != > - MD_FIELD_ID_ELE_SIZE_16BIT)) > + if (WARN_ON_ONCE(MD_FIELD_ELE_SIZE(field_id) != size)) > return -EINVAL; Per the last patch, re: unrolling @fields, it's unfortunate to have a runtime warning for something that could have been verified at compile time.