Define apic_page construct to unionize apic register 32bit/64bit accesses and use it in apic_{get|set}*() to avoid using type casting. Also, change 'regs' parameter to void pointer for automatic pointer type conversion. One caveat of this change is that the generated code is slighly larger. Below is the code generation for apic_get_reg() using gcc-14.2: * Without change: apic_get_reg: 89 f6 mov esi,esi 8b 04 37 mov eax,DWORD PTR [rdi+rsi*1] c3 ret * With change: apic_get_reg: c1 ee 02 shr esi,0x2 8b 04 b7 mov eax,DWORD PTR [rdi+rsi*4] c3 ret Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@xxxxxxx> --- Changes since v5: - New change which is refactored out from v5 to apic.h. arch/x86/include/asm/apic.h | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index b377718d34d3..ea43e2f4c1c8 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -525,26 +525,43 @@ static inline int apic_find_highest_vector(void *bitmap) return -1; } -static inline u32 apic_get_reg(char *regs, unsigned int reg) +struct apic_page { + union { + u64 regs64[PAGE_SIZE / 8]; + u32 regs[PAGE_SIZE / 4]; + u8 bytes[PAGE_SIZE]; + }; +} __aligned(PAGE_SIZE); + +static inline u32 apic_get_reg(void *regs, unsigned int reg) { - return *((u32 *) (regs + reg)); + struct apic_page *ap = regs; + + return ap->regs[reg / 4]; } -static inline void apic_set_reg(char *regs, unsigned int reg, u32 val) +static inline void apic_set_reg(void *regs, unsigned int reg, u32 val) { - *((u32 *) (regs + reg)) = val; + struct apic_page *ap = regs; + + ap->regs[reg / 4] = val; } -static __always_inline u64 apic_get_reg64(char *regs, unsigned int reg) +static __always_inline u64 apic_get_reg64(void *regs, unsigned int reg) { + struct apic_page *ap = regs; + BUILD_BUG_ON(reg != APIC_ICR); - return *((u64 *) (regs + reg)); + + return ap->regs64[reg / 8]; } -static __always_inline void apic_set_reg64(char *regs, unsigned int reg, u64 val) +static __always_inline void apic_set_reg64(void *regs, unsigned int reg, u64 val) { + struct apic_page *ap = regs; + BUILD_BUG_ON(reg != APIC_ICR); - *((u64 *) (regs + reg)) = val; + ap->regs64[reg / 8] = val; } static inline void apic_clear_vector(unsigned int vec, void *bitmap) -- 2.34.1