Skip to content

Commit

Permalink
x86/apic: Avoid open coded x2apic detection
Browse files Browse the repository at this point in the history
enable_IR_x2apic() grew a open coded x2apic detection. Implement a
proper helper function which shares the code with the already existing
x2apic_enabled().

Made it use rdmsrl_safe as suggested by Boris.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Jiang Liu <jiang.liu@linux.intel.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Tony Luck <tony.luck@intel.com>
Link: http://lkml.kernel.org/r/20150115211702.285038186@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Thomas Gleixner committed Jan 22, 2015
1 parent e901176 commit 8d80696
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
19 changes: 10 additions & 9 deletions arch/x86/include/asm/apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ extern u64 native_apic_icr_read(void);

extern int x2apic_mode;

static inline bool apic_is_x2apic_enabled(void)
{
u64 msr;

if (rdmsrl_safe(MSR_IA32_APICBASE, &msr))
return false;
return msr & X2APIC_ENABLE;
}

#ifdef CONFIG_X86_X2APIC
/*
* Make previous memory operations globally visible before
Expand Down Expand Up @@ -175,15 +184,7 @@ extern void check_x2apic(void);
extern void enable_x2apic(void);
static inline int x2apic_enabled(void)
{
u64 msr;

if (!cpu_has_x2apic)
return 0;

rdmsrl(MSR_IA32_APICBASE, msr);
if (msr & X2APIC_ENABLE)
return 1;
return 0;
return cpu_has_x2apic && apic_is_x2apic_enabled();
}

#define x2apic_supported() (cpu_has_x2apic)
Expand Down
5 changes: 1 addition & 4 deletions arch/x86/kernel/apic/apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1625,10 +1625,7 @@ void __init enable_IR_x2apic(void)
int ret, ir_stat;

if (!IS_ENABLED(CONFIG_X86_X2APIC)) {
u64 msr;

rdmsrl(MSR_IA32_APICBASE, msr);
if (msr & X2APIC_ENABLE)
if (apic_is_x2apic_enabled())
panic("BIOS has enabled x2apic but kernel doesn't support x2apic, please disable x2apic in BIOS.\n");
}

Expand Down

0 comments on commit 8d80696

Please sign in to comment.