Re: [PATCH v2 02/10] x86/virt/tdx: Unbind global metadata read with 'struct tdx_tdmr_sysinfo'
From: Huang, Kai
Date: Tue Aug 27 2024 - 03:22:53 EST
On Tue, 2024-08-27 at 07:54 +0300, Adrian Hunter wrote:
> > >
> > > BUILD_BUG_ON() requires a function, but it is still
> > > be possible to add a build time check in TD_SYSINFO_MAP
> > > e.g.
> > >
> > > #define TD_SYSINFO_CHECK_SIZE(_field_id, _size) \
> > > __builtin_choose_expr(MD_FIELD_ELE_SIZE(_field_id) == _size, _size, (void)0)
> > >
> > > #define _TD_SYSINFO_MAP(_field_id, _offset, _size) \
> > > { .field_id = _field_id, \
> > > .offset = _offset, \
> > > .size = TD_SYSINFO_CHECK_SIZE(_field_id, _size) }
> > >
> > > #define TD_SYSINFO_MAP(_field_id, _struct, _member) \
> > > _TD_SYSINFO_MAP(MD_FIELD_ID_##_field_id, \
> > > offsetof(_struct, _member), \
> > > sizeof(typeof(((_struct *)0)->_member)))
> > >
> > >
> >
> > Thanks for the comment, but I don't think this meets for our purpose.
> >
> > We want a build time "error" when the "MD_FIELD_ELE_SIZE(_field_id) == _size"
> > fails, but not "still initializing the size to 0".
>
> FWIW, it isn't 0, it is void. Assignment to void is an error. Could use
> anything that is correct syntax but would produce a compile-time error
> e.g. (1 / 0).
Ah I missed the '(void)'. I didn't thought this way (and yet to try out).
Thanks for the insight.
I already sent out the v3 based on Dan's suggestion. Besides the pros
mentioned by Dan, I also found Dan's suggestion yields less LoC of the final
tdx.c despite it is trivial. So let's continue on the v3.