Re: [RFC v2 03/17] x86/apic: Populate .read()/.write() callbacks of Secure AVIC driver

Neeraj Upadhyay
2025-03-21T14:00:51Z

On 3/21/2025 7:08 PM, Thomas Gleixner wrote:
> On Wed, Feb 26 2025 at 14:35, Neeraj Upadhyay wrote:
>
>> +static inline u32 get_reg(char *page, int reg)
>> +{
>> + return READ_ONCE(*((u32 *)(page + reg)));
>
> This type casting is disgusting. First you cast the void pointer of the
> per CPU backing page implicitely into a signed character pointer and
> then cast that to a u32 pointer. Seriously?
>
> struct apic_page {
> union {
> u32 regs[NR_APIC_REGS];
> u8 bytes[PAGE_SIZE];
> };
> };
>
> and the per CPU allocation of apic_page makes this:
>
> static __always_inline u32 get_reg(unsigned int offset)
> {
> return READ_ONCE(this_cpu_ptr(apic_page)->regs[offset >> 2]));
> }
>
> which avoids the whole pointer indirection of your backing page construct.
>

Thanks for suggesting this!

- Neeraj

> Thanks,
>
> tglx