Re: [PATCH v4 3/8] x86/virt/tdx: Prepare to support reading other global metadata fields

Dave Hansen
2024-09-26T15:47:56Z

On 9/24/24 04:28, Kai Huang wrote:
> +#define build_sysmd_read(_size) \
> +static int __read_sys_metadata_field##_size(u64 field_id, u##_size *val) \
> +{ \
> + u64 tmp; \
> + int ret; \
> + \
> + ret = tdh_sys_rd(field_id, &tmp); \
> + if (ret) \
> + return ret; \
> + \
> + *val = tmp; \
> + \
> + return 0; \
> }

Why? What's so important about having the compiler do the copy?

#define read_sys_metadata_field(id, val) \
__read_sys_metadata_field(id, val, sizeof (*(val)))

static int __read_sys_metadata_field(u64 field_id, void *ptr, int size)
{
...
memcpy(ptr, &tmp, size);

return 0;
}

There's one simple #define there so that users don't have to do the
sizeof and can't screw it up.