Re: [patch V6a 01/19] x86/cpu: Provide cpuid_read() et al.

From: Thomas Gleixner
Date: Thu Feb 15 2024 - 10:07:16 EST


On Thu, Feb 15 2024 at 10:49, Andy Shevchenko wrote:

> On Wed, Feb 14, 2024 at 10:29 PM Thomas Gleixner <tglx@linutronixde> wrote:
>>
>> Provide a few helper functions to read CPUID leafs or individual registers
>> into a data structure without requiring unions.
>
> ...
>
>> +#define cpuid_subleaf(leaf, subleaf, regs) { \
>> + BUILD_BUG_ON(sizeof(*(regs)) != 16); \
>> + __cpuid_read(leaf, subleaf, (u32 *)(regs)); \
>> +}
>> +
>> +#define cpuid_leaf(leaf, regs) { \
>> + BUILD_BUG_ON(sizeof(*(regs)) != 16); \
>> + __cpuid_read(leaf, 0, (u32 *)(regs)); \
>> +}
>
> ...
>
>> +#define cpuid_subleaf_reg(leaf, subleaf, regidx, reg) { \
>> + BUILD_BUG_ON(sizeof(*(reg)) != 4); \
>> + __cpuid_read_reg(leaf, subleaf, regidx, (u32 *)(reg)); \
>> +}
>> +
>> +#define cpuid_leaf_reg(leaf, regidx, reg) { \
>> + BUILD_BUG_ON(sizeof(*(reg)) != 4); \
>> + __cpuid_read_reg(leaf, 0, regidx, (u32 *)(reg)); \
>> +}
>
> I'm wondering if we can use static_assert() instead of BUILD_BUG_ON()
> in the above macros.

Probably.