On 3/1/2024 7:20 PM, Kai Huang wrote:
KVM will need to read a bunch of non-TDMR related metadata to create and
run TDX guests. Export the metadata read infrastructure for KVM to use.
Specifically, export two helpers:
1) The helper which reads multiple metadata fields to a buffer of a
structure based on the "field ID -> structure member" mapping table.
2) The low level helper which just reads a given field ID.
How about introducing a helper to read a single metadata field comparing to 1) instead of the low level helper.
The low level helper tdx_sys_metadata_field_read() requires the data buf to be u64 *. So the caller needs to use a temporary variable and handle the memcpy when the field is less than 8 bytes.
so why not expose a high level helper to read single field, e.g.,
+int tdx_sys_metadata_read_single(u64 field_id, int bytes, void *buf)
+{
+ return stbuf_read_sys_metadata_field(field_id, 0, bytes, buf);
+}
+EXPORT_SYMBOL_GPL(tdx_sys_metadata_read_single);