x86, xsave: some code cleanups and reworks, -v2
cover x86, xsave: some code cleanups and reworks, -v2
Hans Peter, Suresh, and Cyrill, thanks for your feedback.
This is version 2 of the patch series.
Patches 2, 4, 7 are unchanged compared to -v1.
Patch 1 folds the initialization code into one patch. fpu_init() is now called before xsave_init(). xsave_init() can later overwrite xstate_size based on xstate features.
Patch 3 replaces all hardcoded XSTATE_CPUID values know. cpuid_level is now taken from boot_cpu_data.
Patches 5 and 6 are new:
* add __init attribute to setup_xstate_features()
* disable xsave in i387 emulation mode
-Robert
PATCH 1/7 x86, xsave: separate fpu and xsave initialization
As xsave also supports other than fpu features, it should be initialized independently of the fpu. This patch moves this out of fpu initialization.
There is also a lot of cross referencing between fpu and xsave code. This patch reduces this by making xsave_cntxt_init() and init_thread_xstate() static functions.
The patch moves the cpu_has_xsave check at the beginning of xsave_init(). All other checks may removed then.
--- arch/x86/include/asm/i387.h | 1 - arch/x86/include/asm/xsave.h | 1 - arch/x86/kernel/cpu/common.c | 2 ++ arch/x86/kernel/i387.c | 27 +++++++++++++++++++-------- arch/x86/kernel/xsave.c | 10 +++++----- 5 files changed, 26 insertions(+), 15 deletions(-)
arch/x86/include/asm/i387.h +0 -1
@@ -31,7 +31,6 @@ extern void mxcsr_feature_mask_init(void);extern int init_fpu (struct task_struct *child); extern asmlinkage void math_state_restore(void);extern void __math_state_restore (void ); -extern void init_thread_xstate (void );extern int dump_fpu (struct pt_regs *,struct user_i387_struct *);extern user_regset_active_fn fpregs_active, xfpregs_active;
arch/x86/include/asm/xsave.h +0 -1
@@ -28,7 +28,6 @@ extern u64 pcntxt_mask;extern struct xsave_struct *init_xstate_buf;extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS ]; -extern void xsave_cntxt_init (void );extern void xsave_init (void );extern void update_regset_xstate_info (unsigned int size,u64 xstate_mask);extern int init_fpu (struct task_struct *child);
arch/x86/kernel/cpu/common.c +2 -0
@@ -1210,6 +1210,7 @@ void __cpuinit cpu_init(void)dbg_restore_debug_regs ();fpu_init (); +xsave_init ();raw_local_save_flags (kernel_eflags);
@@ -1270,6 +1271,7 @@ void __cpuinit cpu_init(void)clear_used_math ();mxcsr_feature_mask_init (); +fpu_init (); xsave_init(); }#endif
arch/x86/kernel/i387.c +19 -8
@@ -59,18 +59,18 @@ void __cpuinit mxcsr_feature_mask_init(void)stts (); } -void __cpuinit init_thread_xstate (void ) +static void __cpuinit init_thread_xstate (void ) { +/* +* Note that xstate_size might be overwriten later during +* xsave_init(). +*/ +if (!HAVE_HWFP ) { xstate_size =sizeof (struct i387_soft_struct );return ; } -if (cpu_has_xsave) { -xsave_cntxt_init (); -return ; - } -if (cpu_has_fxsr) xstate_size =sizeof (struct i387_fxsave_struct );#ifdef CONFIG_X86_32
@@ -84,6 +84,7 @@ void __cpuinit init_thread_xstate(void)* Called at bootup to set up the initial FPU state that is later cloned * into all processes. */ +void __cpuinit fpu_init (void ) {unsigned long oldcr0 =read_cr0 ();
@@ -93,14 +94,24 @@ void __cpuinit fpu_init(void)write_cr0 (oldcr0 & ~(X86_CR0_TS |X86_CR0_EM ));/* clear TS and EM */ -xsave_init (); +if (!smp_processor_id ()) +init_thread_xstate ();mxcsr_feature_mask_init ();/* clean state in init */ current_thread_info ()->status =0 ; clear_used_math(); } -#endif /* CONFIG_X86_64 */ + +#else /* CONFIG_X86_64 */ + +void __cpuinit fpu_init (void ) +{ +if (!smp_processor_id ()) +init_thread_xstate (); +} + +#endif /* CONFIG_X86_32 */ static void fpu_finit (struct fpu *fpu) {
arch/x86/kernel/xsave.c +5 -5
@@ -362,9 +362,6 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);*/ static void __cpuinit __xsave_init (void ) { -if (!cpu_has_xsave) -return ; -set_in_cr4 (X86_CR4_OSXSAVE );/*
@@ -429,7 +426,7 @@ static void __init setup_xstate_init(void)/* * Enable and initialize the xsave feature. */ -void __ref xsave_cntxt_init (void ) +static void __cpuinit xsave_cntxt_init (void ) {unsigned int eax, ebx, ecx, edx;
@@ -466,10 +463,13 @@ void __ref xsave_cntxt_init(void)void __cpuinit xsave_init (void ) { +if (!cpu_has_xsave) +return ; +/* * Boot processor to setup the FP and extended state context info. */ if (!smp_processor_id ()) -init_thread_xstate (); +xsave_cntxt_init ();__xsave_init (); }
Signature · 1 line
1.7.1.1
[tip:x86/xsave] x86, xsave: Separate fpu and xsave initialization
Commit-ID: 0e49bf66d2ca649b167428adddbbbe9d9bd4894c Gitweb: http://git.kernel.org/tip/0e49bf66d2ca649b167428adddbbbe9d9bd4894c Author: Robert Richter <[email protected]> AuthorDate: Wed, 21 Jul 2010 19:03:52 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Wed, 21 Jul 2010 14:06:04 -0700
x86, xsave: Separate fpu and xsave initialization
As xsave also supports other than fpu features, it should be initialized independently of the fpu. This patch moves this out of fpu initialization.
There is also a lot of cross referencing between fpu and xsave code. This patch reduces this by making xsave_cntxt_init() and init_thread_xstate() static functions.
The patch moves the cpu_has_xsave check at the beginning of xsave_init(). All other checks may removed then.
LKML-Reference: <[email protected]>
--- arch/x86/include/asm/i387.h | 1 - arch/x86/include/asm/xsave.h | 1 - arch/x86/kernel/cpu/common.c | 2 ++ arch/x86/kernel/i387.c | 27 +++++++++++++++++++-------- arch/x86/kernel/xsave.c | 10 +++++----- 5 files changed, 26 insertions(+), 15 deletions(-)
arch/x86/include/asm/i387.h +0 -1
@@ -31,7 +31,6 @@ extern void mxcsr_feature_mask_init(void);extern int init_fpu (struct task_struct *child); extern asmlinkage void math_state_restore(void);extern void __math_state_restore (void ); -extern void init_thread_xstate (void );extern int dump_fpu (struct pt_regs *,struct user_i387_struct *);extern user_regset_active_fn fpregs_active, xfpregs_active;
arch/x86/include/asm/xsave.h +0 -1
@@ -28,7 +28,6 @@ extern u64 pcntxt_mask;extern struct xsave_struct *init_xstate_buf;extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS ]; -extern void xsave_cntxt_init (void );extern void xsave_init (void );extern void update_regset_xstate_info (unsigned int size,u64 xstate_mask);extern int init_fpu (struct task_struct *child);
arch/x86/kernel/cpu/common.c +2 -0
@@ -1210,6 +1210,7 @@ void __cpuinit cpu_init(void)dbg_restore_debug_regs ();fpu_init (); +xsave_init ();raw_local_save_flags (kernel_eflags);
@@ -1270,6 +1271,7 @@ void __cpuinit cpu_init(void)clear_used_math ();mxcsr_feature_mask_init (); +fpu_init (); xsave_init(); }#endif
arch/x86/kernel/i387.c +19 -8
@@ -59,18 +59,18 @@ void __cpuinit mxcsr_feature_mask_init(void)stts (); } -void __cpuinit init_thread_xstate (void ) +static void __cpuinit init_thread_xstate (void ) { +/* +* Note that xstate_size might be overwriten later during +* xsave_init(). +*/ +if (!HAVE_HWFP ) { xstate_size =sizeof (struct i387_soft_struct );return ; } -if (cpu_has_xsave) { -xsave_cntxt_init (); -return ; - } -if (cpu_has_fxsr) xstate_size =sizeof (struct i387_fxsave_struct );#ifdef CONFIG_X86_32
@@ -84,6 +84,7 @@ void __cpuinit init_thread_xstate(void)* Called at bootup to set up the initial FPU state that is later cloned * into all processes. */ +void __cpuinit fpu_init (void ) {unsigned long oldcr0 =read_cr0 ();
@@ -93,14 +94,24 @@ void __cpuinit fpu_init(void)write_cr0 (oldcr0 & ~(X86_CR0_TS |X86_CR0_EM ));/* clear TS and EM */ -xsave_init (); +if (!smp_processor_id ()) +init_thread_xstate ();mxcsr_feature_mask_init ();/* clean state in init */ current_thread_info ()->status =0 ; clear_used_math(); } -#endif /* CONFIG_X86_64 */ + +#else /* CONFIG_X86_64 */ + +void __cpuinit fpu_init (void ) +{ +if (!smp_processor_id ()) +init_thread_xstate (); +} + +#endif /* CONFIG_X86_32 */ static void fpu_finit (struct fpu *fpu) {
arch/x86/kernel/xsave.c +5 -5
@@ -362,9 +362,6 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);*/ static void __cpuinit __xsave_init (void ) { -if (!cpu_has_xsave) -return ; -set_in_cr4 (X86_CR4_OSXSAVE );/*
@@ -429,7 +426,7 @@ static void __init setup_xstate_init(void)/* * Enable and initialize the xsave feature. */ -void __ref xsave_cntxt_init (void ) +static void __cpuinit xsave_cntxt_init (void ) {unsigned int eax, ebx, ecx, edx;
@@ -466,10 +463,13 @@ void __ref xsave_cntxt_init(void)void __cpuinit xsave_init (void ) { +if (!cpu_has_xsave) +return ; +/* * Boot processor to setup the FP and extended state context info. */ if (!smp_processor_id ()) -init_thread_xstate (); +xsave_cntxt_init ();__xsave_init (); }
PATCH 2/7 x86, xsave: introduce xstate enable functions
In reply to Robert RichterThe patch renames xsave_cntxt_init() and __xsave_init() into xstate_enable_boot_cpu() and xstate_enable() as this names are more meaningful.
It also removes the duplicate xcr setup for the boot cpu.
--- arch/x86/kernel/xsave.c | 19 ++++++++----------- 1 files changed, 8 insertions(+), 11 deletions(-)
arch/x86/kernel/xsave.c +8 -11
@@ -360,15 +360,10 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);/* * Enable the extended processor state save/restore feature */ -static void __cpuinit __xsave_init (void ) +static inline void xstate_enable (u64 mask) {set_in_cr4 (X86_CR4_OSXSAVE ); - -/* -* Enable all the features that the HW is capable of -* and the Linux kernel is aware of. -*/ -xsetbv (XCR_XFEATURE_ENABLED_MASK , pcntxt_mask); +xsetbv (XCR_XFEATURE_ENABLED_MASK , mask); }/*
@@ -426,7 +421,7 @@ static void __init setup_xstate_init(void)/* * Enable and initialize the xsave feature. */ -static void __cpuinit xsave_cntxt_init (void ) +static void __cpuinit xstate_enable_boot_cpu (void ) {unsigned int eax, ebx, ecx, edx;
@@ -443,7 +438,8 @@ static void __cpuinit xsave_cntxt_init(void)* Support only the state known to OS. */ pcntxt_mask = pcntxt_mask &XCNTXT_MASK ; -__xsave_init (); + +xstate_enable (pcntxt_mask);/* * Recompute the context size for enabled features
@@ -470,6 +466,7 @@ void __cpuinit xsave_init(void)* Boot processor to setup the FP and extended state context info. */ if (!smp_processor_id ()) -xsave_cntxt_init (); -__xsave_init (); +xstate_enable_boot_cpu (); +else +xstate_enable (pcntxt_mask); }
Signature · 1 line
1.7.1.1
H. Peter Anvin
reviewerRe: [PATCH 2/7] x86, xsave: introduce xstate enable functions
Quoted 14 lines · Robert Richter
The patch renames
xsave_cntxt_init()and__xsave_init()intoxstate_enable_boot_cpu()andxstate_enable()as this names are more meaningful.It also removes the duplicate xcr setup for the boot cpu.
Signed-off-by Robert Richter <[email protected]>arch/x86/kernel/xsave.c +1
-1-static void __cpuinit xsave_cntxt_init (void ) +static void __cpuinit xstate_enable_boot_cpu (void ) {unsigned int eax, ebx, ecx, edx;
arch/x86/kernel/xsave.c static void __cpuinit xsave_cntxt_init(void) · line 445
Quoted 9 lines
arch/x86/kernel/xsave.c +2
-1@@ -443,7 +438,8 @@ static void __cpuinit xsave_cntxt_init(void)* Support only the state known to OS. */ pcntxt_mask = pcntxt_mask &XCNTXT_MASK ; -__xsave_init (); + +xstate_enable (pcntxt_mask);/* * Recompute the context size for enabled features
This one should be __init rather than __cpuinit, right? As written, I get:
WARNING: vmlinux.o(.cpuinit.text+0x824): Section mismatch in reference from the function xstate_enable_boot_cpu() to the function .init.text:__alloc_bootmem()
The function __cpuinit xstate_enable_boot_cpu() references a function __init __alloc_bootmem().
If __alloc_bootmem is only used by xstate_enable_boot_cpu then annotate __alloc_bootmem with a matching annotation.
[No need to resend the patch, but if either Suresh or Robert could ACK this change I'd appreciate it.]
-hpa
Re: [PATCH 2/7] x86, xsave: introduce xstate enable functions
Quoted 36 lines · H. Peter Anvin
Quoted 14 lines · Robert Richter
The patch renames
xsave_cntxt_init()and__xsave_init()intoxstate_enable_boot_cpu()andxstate_enable()as this names are more meaningful.It also removes the duplicate xcr setup for the boot cpu.
Signed-off-by Robert Richter <[email protected]>arch/x86/kernel/xsave.c +1
-1-static void __cpuinit xsave_cntxt_init (void ) +static void __cpuinit xstate_enable_boot_cpu (void ) {unsigned int eax, ebx, ecx, edx;arch/x86/kernel/xsave.c static void __cpuinit xsave_cntxt_init(void) · line 445
Quoted 9 lines
arch/x86/kernel/xsave.c +2
-1@@ -443,7 +438,8 @@ static void __cpuinit xsave_cntxt_init(void)* Support only the state known to OS. */ pcntxt_mask = pcntxt_mask &XCNTXT_MASK ; -__xsave_init (); + +xstate_enable (pcntxt_mask);/* * Recompute the context size for enabled features This one should be
__initrather than__cpuinit, right? As written, I get:WARNING:
vmlinux.o(.cpuinit.text+0x824): Section mismatch in reference from the functionxstate_enable_boot_cpu()to the function .init.text:__alloc_bootmem()
The function__cpuinitxstate_enable_boot_cpu()references a function__init__alloc_bootmem().
If__alloc_bootmemis only used byxstate_enable_boot_cputhen annotate__alloc_bootmemwith a matching annotation.
Quoted 2 lines
[No need to resend the patch, but if either Suresh or Robert could ACK this change I'd appreciate it.]
Yes, it should be __init.
thanks,
suresh
Re: [PATCH 2/7] x86, xsave: introduce xstate enable functions
Quoted 3 lines · Suresh Siddha
Yes, it should be
__init.
OK, here is the proposed fix for that. It's a bit uglier than I would have liked.
It also fixes the assumption that "we are on the boot CPU so we are early in the boot", which is true now but will not be true in the future when we can offline (and later re-online) the boot CPU.
Comments appreciated...
-hpa
Quoted 1 line
From
55b936c7a359a14d72bcba6c3fceba4cfbe3fedfMon Sep 17 00:00:00 2001
From: H. Peter Anvin <[email protected]>
Date: Wed, 21 Jul 2010 14:23:10 -0700
Subject: [PATCH] x86, xsave: Make xstate_enable_boot_cpu() __init, protect on CPU 0
xstate_enable_boot_cpu() is, as the name implies, only used on the boot CPU; furthermore, it invokes alloc_bootmem(), which is __init; hence it needs to be tagged __init rather than __cpuinit.
Furthermore, it is *not* safe in the long run to rely on CPU 0 only coming online during the early boot -- at some point we're going to support offlining (and re-onlining) the boot CPU, and at that point we must not call xstate_enable_boot_cpu() again.
The code is a fair bit more obscure than one would like, because the __ref overrides aren't quite powerful enough.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/xsave.c | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-)
arch/x86/kernel/xsave.c +17 -11
@@ -360,10 +360,10 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);/* * Enable the extended processor state save/restore feature */ -static inline void xstate_enable (u64 mask) +static inline void xstate_enable (void ) {set_in_cr4 (X86_CR4_OSXSAVE ); -xsetbv (XCR_XFEATURE_ENABLED_MASK , mask); +xsetbv (XCR_XFEATURE_ENABLED_MASK , pcntxt_mask); }/*
@@ -421,7 +421,7 @@ static void __init setup_xstate_init(void)/* * Enable and initialize the xsave feature. */ -static void __cpuinit xstate_enable_boot_cpu (void ) +static void __init xstate_enable_boot_cpu (void ) {unsigned int eax, ebx, ecx, edx;
@@ -444,7 +444,7 @@ static void __cpuinit xstate_enable_boot_cpu(void)*/ pcntxt_mask = pcntxt_mask &XCNTXT_MASK ; -xstate_enable (pcntxt_mask); +xstate_enable ();/* * Recompute the context size for enabled features
@@ -462,16 +462,22 @@ static void __cpuinit xstate_enable_boot_cpu(void) pcntxt_mask, xstate_size); } +/* +* For the very first instance, this calls xstate_enable_boot_cpu(); +* for all subsequent instances, this calls xstate_enable(). +* +* This is somewhat obfuscated due to the lack of powerful enough +* overrides for the section checks. +*/ void __cpuinit xsave_init (void ) { +static __refdata void (*next_func)(void ) = xstate_enable_boot_cpu; +void (*this_func)(void ); +if (!cpu_has_xsave)return ; -/* -* Boot processor to setup the FP and extended state context info. -*/ -if (!smp_processor_id ()) -xstate_enable_boot_cpu (); -else -xstate_enable (pcntxt_mask); + this_func = next_func; + next_func = xstate_enable; +this_func (); }
Signature · 1 line
1.7.0.1
Re: [PATCH 2/7] x86, xsave: introduce xstate enable functions
Quoted 5 lines · H. Peter Anvin
Quoted 3 lines · Suresh Siddha
Yes, it should be
__init.
Quoted 8 lines
OK, here is the proposed fix for that. It's a bit uglier than I would have liked.
It also fixes the assumption that "we are on the boot CPU so we are early in the boot", which is true now but will not be true in the future when we can offline (and later re-online) the boot CPU.
Comments appreciated...
I am ok with this fix. Thanks for taking a stab at this.
suresh
Re: [PATCH 2/7] x86, xsave: introduce xstate enable functions
In reply to H. Peter AnvinQuoted 14 lines · H. Peter Anvin
From
55b936c7a359a14d72bcba6c3fceba4cfbe3fedfMon Sep 17 00:00:00 2001
From: H. Peter Anvin <[email protected]>
Date: Wed, 21 Jul 2010 14:23:10 -0700
Subject: [PATCH] x86, xsave: Makexstate_enable_boot_cpu()__init, protect on CPU 0
xstate_enable_boot_cpu()is, as the name implies, only used on the boot CPU; furthermore, it invokesalloc_bootmem(), which is__init; hence it needs to be tagged__initrather than__cpuinit.Furthermore, it is *not* safe in the long run to rely on CPU 0 only coming online during the early boot -- at some point we're going to support offlining (and re-onlining) the boot CPU, and at that point we must not call
xstate_enable_boot_cpu()again.
Quoted 7 lines
The code is a fair bit more obscure than one would like, because the
__refoverrides aren't quite powerful enough.Signed-off-by H. Peter Anvin <[email protected]>Acked-by Suresh Siddha <[email protected]>Cc Robert Richter <[email protected]>LKML-Reference: <[email protected]>
I am fine with your changes.
Quoted 9 lines
void
__cpuinitxsave_init(void)
{arch/x86/kernel/xsave.c +3
-1+static __refdata void (*next_func)(void ) = xstate_enable_boot_cpu; +void (*this_func)(void ); +if (!cpu_has_xsave)return ; -/*
arch/x86/kernel/xsave.c static void __cpuinit xstate_enable_boot_cpu(void) · line 483
Quoted 10 lines
arch/x86/kernel/xsave.c +3
-6-* Boot processor to setup the FP and extended state context info. -*/ -if (!smp_processor_id ()) -xstate_enable_boot_cpu (); -else -xstate_enable (pcntxt_mask); + this_func = next_func; + next_func = xstate_enable; +this_func (); }
Just wondering why you are using this_func()? Instead, you could simply do:
next_func(); next_func = xstate_enable;
Do you see races when bringing up multiple cpus in parallel?
Thanks.
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
H. Peter Anvin
reviewerRe: [PATCH 2/7] x86, xsave: introduce xstate enable functions
Quoted 9 lines · Robert Richter
Just wondering why you are using
this_func()? Instead, you could simply do:next_func(); next_func = xstate_enable;Do you see races when bringing up multiple cpus in parallel?
It allows the compiler to turn it into a tailcall if frame pointers are disabled.
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Re: [PATCH 2/7] x86, xsave: introduce xstate enable functions
Quoted 5 lines · H. Peter Anvin
Quoted 4 lines · Robert Richter
Just wondering why you are using
this_func()? Instead, you could simply do:
Quoted 8 lines
Quoted 5 lines
next_func(); next_func = xstate_enable;Do you see races when bringing up multiple cpus in parallel?
It allows the compiler to turn it into a tailcall if frame pointers are disabled.
Yes, that makes sense.
Thanks.
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
[tip:x86/xsave] x86, xsave: Make xstate_enable_boot_cpu() __init, protect on CPU 0
In reply to H. Peter AnvinCommit-ID: 1cff92d8fdb27684308864d9cdb324bee43b40ab Gitweb: http://git.kernel.org/tip/1cff92d8fdb27684308864d9cdb324bee43b40ab Author: H. Peter Anvin <[email protected]> AuthorDate: Wed, 21 Jul 2010 14:23:10 -0700 Committer: H. Peter Anvin <[email protected]> CommitDate: Wed, 21 Jul 2010 15:33:54 -0700
x86, xsave: Make xstate_enable_boot_cpu() __init, protect on CPU 0
xstate_enable_boot_cpu() is, as the name implies, only used on the boot CPU; furthermore, it invokes alloc_bootmem(), which is __init; hence it needs to be tagged __init rather than __cpuinit.
Furthermore, it is *not* safe in the long run to rely on CPU 0 only coming online during the early boot -- at some point we're going to support offlining (and re-onlining) the boot CPU, and at that point we must not call xstate_enable_boot_cpu() again.
The code is a fair bit more obscure than one would like, because the __ref overrides aren't quite powerful enough.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/xsave.c | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-)
arch/x86/kernel/xsave.c +17 -11
@@ -360,10 +360,10 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);/* * Enable the extended processor state save/restore feature */ -static inline void xstate_enable (u64 mask) +static inline void xstate_enable (void ) {set_in_cr4 (X86_CR4_OSXSAVE ); -xsetbv (XCR_XFEATURE_ENABLED_MASK , mask); +xsetbv (XCR_XFEATURE_ENABLED_MASK , pcntxt_mask); }/*
@@ -421,7 +421,7 @@ static void __init setup_xstate_init(void)/* * Enable and initialize the xsave feature. */ -static void __cpuinit xstate_enable_boot_cpu (void ) +static void __init xstate_enable_boot_cpu (void ) {unsigned int eax, ebx, ecx, edx;
@@ -444,7 +444,7 @@ static void __cpuinit xstate_enable_boot_cpu(void)*/ pcntxt_mask = pcntxt_mask &XCNTXT_MASK ; -xstate_enable (pcntxt_mask); +xstate_enable ();/* * Recompute the context size for enabled features
@@ -462,16 +462,22 @@ static void __cpuinit xstate_enable_boot_cpu(void) pcntxt_mask, xstate_size); } +/* +* For the very first instance, this calls xstate_enable_boot_cpu(); +* for all subsequent instances, this calls xstate_enable(). +* +* This is somewhat obfuscated due to the lack of powerful enough +* overrides for the section checks. +*/ void __cpuinit xsave_init (void ) { +static __refdata void (*next_func)(void ) = xstate_enable_boot_cpu; +void (*this_func)(void ); +if (!cpu_has_xsave)return ; -/* -* Boot processor to setup the FP and extended state context info. -*/ -if (!smp_processor_id ()) -xstate_enable_boot_cpu (); -else -xstate_enable (pcntxt_mask); + this_func = next_func; + next_func = xstate_enable; +this_func (); }
[tip:x86/xsave] x86, xsave: Introduce xstate enable functions
In reply to Robert RichterCommit-ID: 97e80a70db689fb1e876df9f12305cc72f85ca53 Gitweb: http://git.kernel.org/tip/97e80a70db689fb1e876df9f12305cc72f85ca53 Author: Robert Richter <[email protected]> AuthorDate: Wed, 21 Jul 2010 19:03:53 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Wed, 21 Jul 2010 14:06:04 -0700
x86, xsave: Introduce xstate enable functions
The patch renames xsave_cntxt_init() and __xsave_init() into xstate_enable_boot_cpu() and xstate_enable() as this names are more meaningful.
It also removes the duplicate xcr setup for the boot cpu.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/xsave.c | 19 ++++++++----------- 1 files changed, 8 insertions(+), 11 deletions(-)
arch/x86/kernel/xsave.c +8 -11
@@ -360,15 +360,10 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);/* * Enable the extended processor state save/restore feature */ -static void __cpuinit __xsave_init (void ) +static inline void xstate_enable (u64 mask) {set_in_cr4 (X86_CR4_OSXSAVE ); - -/* -* Enable all the features that the HW is capable of -* and the Linux kernel is aware of. -*/ -xsetbv (XCR_XFEATURE_ENABLED_MASK , pcntxt_mask); +xsetbv (XCR_XFEATURE_ENABLED_MASK , mask); }/*
@@ -426,7 +421,7 @@ static void __init setup_xstate_init(void)/* * Enable and initialize the xsave feature. */ -static void __cpuinit xsave_cntxt_init (void ) +static void __cpuinit xstate_enable_boot_cpu (void ) {unsigned int eax, ebx, ecx, edx;
@@ -443,7 +438,8 @@ static void __cpuinit xsave_cntxt_init(void)* Support only the state known to OS. */ pcntxt_mask = pcntxt_mask &XCNTXT_MASK ; -__xsave_init (); + +xstate_enable (pcntxt_mask);/* * Recompute the context size for enabled features
@@ -470,6 +466,7 @@ void __cpuinit xsave_init(void)* Boot processor to setup the FP and extended state context info. */ if (!smp_processor_id ()) -xsave_cntxt_init (); -__xsave_init (); +xstate_enable_boot_cpu (); +else +xstate_enable (pcntxt_mask); }
PATCH 3/7 x86, xsave: check cpuid level for XSTATE_CPUID (0x0d)
In reply to Robert RichterThe patch introduces the XSTATE_CPUID macro and adds a check that tests if XSTATE_CPUID exists.
--- arch/x86/include/asm/xsave.h | 2 ++ arch/x86/kernel/xsave.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
arch/x86/include/asm/xsave.h +2 -0
@@ -4,6 +4,8 @@#include <linux/types.h> #include <asm/processor.h> +#define XSTATE_CPUID 0x0000000d +#define XSTATE_FP 0x1#define XSTATE_SSE 0x2#define XSTATE_YMM 0x4
arch/x86/kernel/xsave.c +8 -3
@@ -379,7 +379,7 @@ static void setup_xstate_features(void) xstate_sizes =alloc_bootmem (xstate_features *sizeof (int )); do { - cpuid_count(0xd, leaf, &eax, &ebx, &ecx, &edx); + cpuid_count(XSTATE_CPUID, leaf, &eax, &ebx, &ecx, &edx); if (eax == 0) break;
@@ -425,7 +425,12 @@ static void __cpuinit xstate_enable_boot_cpu(void) {unsigned int eax, ebx, ecx, edx; -cpuid_count (0xd ,0 , &eax, &ebx, &ecx, &edx); +if (boot_cpu_data.cpuid_level <XSTATE_CPUID ) { +WARN (1 ,KERN_ERR "XSTATE_CPUID missing\n" ); +return ; + } + +cpuid_count (XSTATE_CPUID ,0 , &eax, &ebx, &ecx, &edx); pcntxt_mask = eax + ((u64 )edx <<32 );if ((pcntxt_mask &XSTATE_FPSSE ) !=XSTATE_FPSSE ) {
@@ -444,7 +449,7 @@ static void __cpuinit xstate_enable_boot_cpu(void)/* * Recompute the context size for enabled features */ -cpuid_count (0xd ,0 , &eax, &ebx, &ecx, &edx); +cpuid_count (XSTATE_CPUID ,0 , &eax, &ebx, &ecx, &edx); xstate_size = ebx;update_regset_xstate_info (xstate_size, pcntxt_mask);
Signature · 1 line
1.7.1.1
[tip:x86/xsave] x86, xsave: Check cpuid level for XSTATE_CPUID (0x0d)
Commit-ID: ee813d53a8e980a3a28318efb8935d45723f5211 Gitweb: http://git.kernel.org/tip/ee813d53a8e980a3a28318efb8935d45723f5211 Author: Robert Richter <[email protected]> AuthorDate: Wed, 21 Jul 2010 19:03:54 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Wed, 21 Jul 2010 14:06:04 -0700
x86, xsave: Check cpuid level for XSTATE_CPUID (0x0d)
The patch introduces the XSTATE_CPUID macro and adds a check that tests if XSTATE_CPUID exists.
LKML-Reference: <[email protected]>
--- arch/x86/include/asm/xsave.h | 2 ++ arch/x86/kernel/xsave.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
arch/x86/include/asm/xsave.h +2 -0
@@ -4,6 +4,8 @@#include <linux/types.h> #include <asm/processor.h> +#define XSTATE_CPUID 0x0000000d +#define XSTATE_FP 0x1#define XSTATE_SSE 0x2#define XSTATE_YMM 0x4
arch/x86/kernel/xsave.c +8 -3
@@ -379,7 +379,7 @@ static void setup_xstate_features(void) xstate_sizes =alloc_bootmem (xstate_features *sizeof (int )); do { - cpuid_count(0xd, leaf, &eax, &ebx, &ecx, &edx); + cpuid_count(XSTATE_CPUID, leaf, &eax, &ebx, &ecx, &edx); if (eax == 0) break;
@@ -425,7 +425,12 @@ static void __cpuinit xstate_enable_boot_cpu(void) {unsigned int eax, ebx, ecx, edx; -cpuid_count (0xd ,0 , &eax, &ebx, &ecx, &edx); +if (boot_cpu_data.cpuid_level <XSTATE_CPUID ) { +WARN (1 ,KERN_ERR "XSTATE_CPUID missing\n" ); +return ; + } + +cpuid_count (XSTATE_CPUID ,0 , &eax, &ebx, &ecx, &edx); pcntxt_mask = eax + ((u64 )edx <<32 );if ((pcntxt_mask &XSTATE_FPSSE ) !=XSTATE_FPSSE ) {
@@ -444,7 +449,7 @@ static void __cpuinit xstate_enable_boot_cpu(void)/* * Recompute the context size for enabled features */ -cpuid_count (0xd ,0 , &eax, &ebx, &ecx, &edx); +cpuid_count (XSTATE_CPUID ,0 , &eax, &ebx, &ecx, &edx); xstate_size = ebx;update_regset_xstate_info (xstate_size, pcntxt_mask);
PATCH 4/7 x86, xsave: make init_xstate_buf static
In reply to Robert RichterThe pointer is only used in xsave.c. Making it static.
--- arch/x86/include/asm/xsave.h | 1 - arch/x86/kernel/xsave.c | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-)
arch/x86/include/asm/xsave.h +0 -1
@@ -27,7 +27,6 @@extern unsigned int xstate_size;extern u64 pcntxt_mask; -extern struct xsave_struct *init_xstate_buf;extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS ];extern void xsave_init (void );
arch/x86/kernel/xsave.c +5 -5
@@ -16,6 +16,11 @@*/ u64 pcntxt_mask; +/* +* Represents init state for the supported extended state. +*/ +static struct xsave_struct *init_xstate_buf; +struct _fpx_sw_bytes fx_sw_reserved;#ifdef CONFIG_IA32_EMULATION struct _fpx_sw_bytes fx_sw_reserved_ia32;
@@ -348,11 +353,6 @@ static void prepare_fx_sw_frame(void)#endif } -/* -* Represents init state for the supported extended state. -*/ -struct xsave_struct *init_xstate_buf; -#ifdef CONFIG_X86_64 unsigned int sig_xstate_size =sizeof (struct _fpstate );#endif
Signature · 1 line
1.7.1.1
[tip:x86/xsave] x86, xsave: Make init_xstate_buf static
Commit-ID: 45c2d7f46211a0b1f6b425c59575c53145afc4b4 Gitweb: http://git.kernel.org/tip/45c2d7f46211a0b1f6b425c59575c53145afc4b4 Author: Robert Richter <[email protected]> AuthorDate: Wed, 21 Jul 2010 19:03:55 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Wed, 21 Jul 2010 14:06:05 -0700
x86, xsave: Make init_xstate_buf static
The pointer is only used in xsave.c. Making it static.
LKML-Reference: <[email protected]>
--- arch/x86/include/asm/xsave.h | 1 - arch/x86/kernel/xsave.c | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-)
arch/x86/include/asm/xsave.h +0 -1
@@ -27,7 +27,6 @@extern unsigned int xstate_size;extern u64 pcntxt_mask; -extern struct xsave_struct *init_xstate_buf;extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS ];extern void xsave_init (void );
arch/x86/kernel/xsave.c +5 -5
@@ -16,6 +16,11 @@*/ u64 pcntxt_mask; +/* +* Represents init state for the supported extended state. +*/ +static struct xsave_struct *init_xstate_buf; +struct _fpx_sw_bytes fx_sw_reserved;#ifdef CONFIG_IA32_EMULATION struct _fpx_sw_bytes fx_sw_reserved_ia32;
@@ -348,11 +353,6 @@ static void prepare_fx_sw_frame(void)#endif } -/* -* Represents init state for the supported extended state. -*/ -struct xsave_struct *init_xstate_buf; -#ifdef CONFIG_X86_64 unsigned int sig_xstate_size =sizeof (struct _fpstate );#endif
PATCH 5/7 x86, xsave: add __init attribute to setup_xstate_features()
In reply to Robert RichterThis is called only from initialization code.
--- arch/x86/kernel/xsave.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/xsave.c +1 -1
@@ -370,7 +370,7 @@ static inline void xstate_enable(u64 mask)* Record the offsets and sizes of different state managed by the xsave * memory layout. */ -static void setup_xstate_features (void ) +static void __init setup_xstate_features (void ) {int eax, ebx, ecx, edx, leaf =0x2 ;
Signature · 1 line
1.7.1.1
[tip:x86/xsave] x86, xsave: Add __init attribute to setup_xstate_features()
Commit-ID: 4995b9dba908436c1611454f9bd2cb3ddf6babee Gitweb: http://git.kernel.org/tip/4995b9dba908436c1611454f9bd2cb3ddf6babee Author: Robert Richter <[email protected]> AuthorDate: Wed, 21 Jul 2010 19:03:56 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Wed, 21 Jul 2010 14:06:05 -0700
x86, xsave: Add __init attribute to setup_xstate_features()
This is called only from initialization code.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/xsave.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/xsave.c +1 -1
@@ -370,7 +370,7 @@ static inline void xstate_enable(u64 mask)* Record the offsets and sizes of different state managed by the xsave * memory layout. */ -static void setup_xstate_features (void ) +static void __init setup_xstate_features (void ) {int eax, ebx, ecx, edx, leaf =0x2 ;
PATCH 6/7 x86, xsave: disable xsave in i387 emulation mode
In reply to Robert Richterxsave is broken for (!HAVE_HWFP). This is the case if config MATH_EMULATION is enabled, 'no387' kernel parameter is set and xsave exists. xsave will not work because x86/math-emu and xsave share the same memory. As this case can be treated as corner case we simply disable xsave then.
--- arch/x86/kernel/i387.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/kernel/i387.c +6 -0
@@ -67,6 +67,12 @@ static void __cpuinit init_thread_xstate(void)*/ if (!HAVE_HWFP ) { +/* +* Disable xsave as we do not support it if i387 +* emulation is enabled. +*/ +setup_clear_cpu_cap (X86_FEATURE_XSAVE ); +setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); xstate_size =sizeof (struct i387_soft_struct );return ; }
Signature · 1 line
1.7.1.1
Re: [PATCH 6/7] x86, xsave: disable xsave in i387 emulation mode
Quoted 5 lines · Robert Richter
xsave is broken for (!HAVE_HWFP). This is the case if config
MATH_EMULATIONis enabled, 'no387' kernel parameter is set and xsave exists. xsave will not work because x86/math-emu and xsave share the same memory. As this case can be treated as corner case we simply disable xsave then.
I think it is cleaner to clear these cpu capabilities in the function which handles no387 boot parameter.
Otherwise Acked-by: Suresh Siddha <[email protected]>
thanks.
Quoted 23 lines
Signed-off-by Robert Richter <[email protected]>--- arch/x86/kernel/i387.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)arch/x86/kernel/i387.c +6
-0@@ -67,6 +67,12 @@ static void __cpuinit init_thread_xstate(void)*/ if (!HAVE_HWFP ) { +/* +* Disable xsave as we do not support it if i387 +* emulation is enabled. +*/ +setup_clear_cpu_cap (X86_FEATURE_XSAVE ); +setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); xstate_size =sizeof (struct i387_soft_struct );return ; }
Re: [PATCH 6/7] x86, xsave: disable xsave in i387 emulation mode
Quoted 2 lines · Suresh Siddha
I think it is cleaner to clear these cpu capabilities in the function which handles no387 boot parameter.
This does not cover all (of course weird but potentially existing) cases. Disabling xsave in the no387 setup would only work if an fpu exists. The implementation below disables it if the soft fpu is actual used. An artificial condition that would break your approach would be no fpu but xsave. There is no hardware like this but maybe virtual machines configurations.
So I think it does not hurt to deactivate xsave directly when enabling soft fpu. The only drawback here is if fpu and xsave initialization order changes. Hmm...
-Robert
Quoted 30 lines
Otherwise Acked-by: Suresh Siddha <[email protected]>
thanks.
Quoted 23 lines
Signed-off-by Robert Richter <[email protected]>--- arch/x86/kernel/i387.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)arch/x86/kernel/i387.c +6
-0@@ -67,6 +67,12 @@ static void __cpuinit init_thread_xstate(void)*/ if (!HAVE_HWFP ) { +/* +* Disable xsave as we do not support it if i387 +* emulation is enabled. +*/ +setup_clear_cpu_cap (X86_FEATURE_XSAVE ); +setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); xstate_size =sizeof (struct i387_soft_struct );return ; }
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
Re: [PATCH 6/7] x86, xsave: disable xsave in i387 emulation mode
Quoted 12 lines · Robert Richter
Quoted 2 lines · Suresh Siddha
I think it is cleaner to clear these cpu capabilities in the function which handles no387 boot parameter.
This does not cover all (of course weird but potentially existing) cases. Disabling xsave in the no387 setup would only work if an fpu exists. The implementation below disables it if the soft fpu is actual used. An artificial condition that would break your approach would be no fpu but xsave. There is no hardware like this but maybe virtual machines configurations.
Quoted 3 lines
So I think it does not hurt to deactivate xsave directly when enabling soft fpu. The only drawback here is if fpu and xsave initialization order changes. Hmm...
Then the more appropriate place for this is to check at the beginning of the xsave init code.
thanks,
suresh
Quoted 34 lines
-Robert
Quoted 30 lines
Otherwise Acked-by: Suresh Siddha <[email protected]>
thanks.
Quoted 23 lines
Signed-off-by Robert Richter <[email protected]>--- arch/x86/kernel/i387.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)arch/x86/kernel/i387.c +6
-0@@ -67,6 +67,12 @@ static void __cpuinit init_thread_xstate(void)*/ if (!HAVE_HWFP ) { +/* +* Disable xsave as we do not support it if i387 +* emulation is enabled. +*/ +setup_clear_cpu_cap (X86_FEATURE_XSAVE ); +setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); xstate_size =sizeof (struct i387_soft_struct );return ; }
Re: [PATCH 6/7] x86, xsave: disable xsave in i387 emulation mode
Quoted 2 lines · Suresh Siddha
Then the more appropriate place for this is to check at the beginning of the xsave init code.
No it isn't, HAVE_HWFP is an fpu implementation and the soft fpu check would be duplicate in xsave.c. Also, the HAVE_HWFP macro is local in i387.c and would have to be exported in a header file then, which somehow taints the api.
So I rather tend to this patch than implementing fpu code in xsave for a small or no benefit.
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
H. Peter Anvin
reviewerRe: [PATCH 6/7] x86, xsave: disable xsave in i387 emulation mode
In reply to Robert RichterQuoted 8 lines · Robert Richter
Quoted 2 lines · Suresh Siddha
I think it is cleaner to clear these cpu capabilities in the function which handles no387 boot parameter.
This does not cover all (of course weird but potentially existing) cases. Disabling xsave in the no387 setup would only work if an fpu exists.
If the fpu doesn't exist, then xsave can't exist, either.
-hpa
Re: [PATCH 6/7] x86, xsave: disable xsave in i387 emulation mode
Quoted 8 lines · H. Peter Anvin
Quoted 6 lines
Quoted 2 lines
I think it is cleaner to clear these cpu capabilities in the function which handles no387 boot parameter.
This does not cover all (of course weird but potentially existing) cases. Disabling xsave in the no387 setup would only work if an fpu exists.
If the fpu doesn't exist, then xsave can't exist, either.
It does not convince me to move it either to no387 setup or xsave_init(). There is no benefit with both of it. We should disable it where we decide to use the soft fpu. Otherwise we will not have the same underlying rules for it. In case of xsave_init() we need to duplicate fpu code and export it to xsave code. I want to avoid this as xsave and fpu code should be kept simple and only be shared where necessary.
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
[tip:x86/fpu] x86, xsave: Disable xsave in i387 emulation mode
In reply to Robert RichterCommit-ID: 1f999ab5a1360afc388868cc0ef9afe8edeef3be Gitweb: http://git.kernel.org/tip/1f999ab5a1360afc388868cc0ef9afe8edeef3be Author: Robert Richter <[email protected]> AuthorDate: Wed, 21 Jul 2010 19:03:57 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Thu, 12 Aug 2010 14:16:54 -0700
x86, xsave: Disable xsave in i387 emulation mode
xsave is broken for (!HAVE_HWFP). This is the case if config MATH_EMULATION is enabled, 'no387' kernel parameter is set and xsave exists. xsave will not work because x86/math-emu and xsave share the same memory. As this case can be treated as corner case we simply disable xsave then.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/i387.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/kernel/i387.c +6 -0
@@ -67,6 +67,12 @@ static void __cpuinit init_thread_xstate(void)*/ if (!HAVE_HWFP ) { +/* +* Disable xsave as we do not support it if i387 +* emulation is enabled. +*/ +setup_clear_cpu_cap (X86_FEATURE_XSAVE ); +setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); xstate_size =sizeof (struct i387_soft_struct );return ; }
PATCH 7/7 x86: removing boot_cpu_id variable
In reply to Robert Richterboot_cpu_id is there for historical reasons and was renamed to boot_cpu_physical_apicid in patch:
c70dcb7 x86: change boot_cpu_id to boot_cpu_physical_apicid
However, there are some remaining occurrences of boot_cpu_id that are never touched in the kernel and thus its value is always 0.
This patch removes boot_cpu_id at all.
--- arch/x86/include/asm/apb_timer.h | 1 - arch/x86/include/asm/cpu.h | 1 - arch/x86/kernel/apb_timer.c | 2 +- arch/x86/kernel/apic/io_apic.c | 12 ++++++------ arch/x86/kernel/cpu/amd.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/cpu/intel.c | 2 +- arch/x86/kernel/reboot.c | 2 +- arch/x86/kernel/setup.c | 1 - arch/x86/kernel/setup_percpu.c | 4 ++-- arch/x86/mm/k8topology_64.c | 6 +++--- 11 files changed, 16 insertions(+), 19 deletions(-)
arch/x86/include/asm/apb_timer.h +0 -1
@@ -54,7 +54,6 @@ extern struct clock_event_device *global_clock_event;extern unsigned long apbt_quick_calibrate (void );extern int arch_setup_apbt_irqs (int irq,int trigger,int mask,int cpu);extern void apbt_setup_secondary_clock (void ); -extern unsigned int boot_cpu_id;extern int disable_apbt_percpu;extern struct sfi_timer_table_entry *sfi_get_mtmr (int hint);
arch/x86/include/asm/cpu.h +0 -1
@@ -32,6 +32,5 @@ extern void arch_unregister_cpu(int);DECLARE_PER_CPU (int, cpu_state); -extern unsigned int boot_cpu_id;#endif /* _ASM_X86_CPU_H */
arch/x86/kernel/apb_timer.c +1 -1
@@ -367,7 +367,7 @@ void apbt_setup_secondary_clock(void)/* Don't register boot CPU clockevent */ cpu =smp_processor_id (); -if (cpu == boot_cpu_id) +if (!cpu)return ;/* * We need to calculate the scaled math multiplication factor for
arch/x86/kernel/apic/io_apic.c +6 -6
@@ -162,7 +162,7 @@ int __init arch_early_irq_init(void) cfg = irq_cfgx; count =ARRAY_SIZE (irq_cfgx); - node=cpu_to_node (boot_cpu_id); + node =cpu_to_node (0 );for (i =0 ; i < count; i++) { desc =irq_to_desc (i);
@@ -1483,7 +1483,7 @@ static void __init setup_IO_APIC_irqs(void)int notcon =0 ;struct irq_desc *desc;struct irq_cfg *cfg; -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );apic_printk (APIC_VERBOSE ,KERN_DEBUG "init IO_APIC IRQs\n" );
@@ -1548,7 +1548,7 @@ static void __init setup_IO_APIC_irqs(void)void setup_IO_APIC_irq_extra (u32 gsi) {int apic_id =0 , pin, idx, irq; -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );struct irq_desc *desc;struct irq_cfg *cfg;
@@ -2925,7 +2925,7 @@ static inline void __init check_timer(void) {struct irq_desc *desc =irq_to_desc (0 );struct irq_cfg *cfg = desc->chip_data; -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );int apic1, pin1, apic2, pin2;unsigned long flags;int no_pin1 =0 ;
@@ -3279,7 +3279,7 @@ unsigned int create_irq_nr(unsigned int irq_want, int node)int create_irq (void ) { -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );unsigned int irq_want;int irq;
@@ -3901,7 +3901,7 @@ static int __io_apic_set_pci_routing(struct device *dev, int irq,if (dev) node =dev_to_node (dev);else - node =cpu_to_node (boot_cpu_id); + node =cpu_to_node (0 ); desc =irq_to_desc_alloc_node (irq, node);if (!desc) {
arch/x86/kernel/cpu/amd.c +1 -1
@@ -148,7 +148,7 @@ static void __cpuinit amd_k7_smp_check(struct cpuinfo_x86 *c) {#ifdef CONFIG_SMP /* calling is from identify_secondary_cpu() ? */ -if (c->cpu_index == boot_cpu_id) +if (!c->cpu_index)return ;/*
arch/x86/kernel/cpu/common.c +1 -1
@@ -664,7 +664,7 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c) this_cpu->c_early_init (c);#ifdef CONFIG_SMP - c->cpu_index = boot_cpu_id; + c->cpu_index =0 ;#endif filter_cpuid_features (c, false); }
arch/x86/kernel/cpu/intel.c +1 -1
@@ -169,7 +169,7 @@ static void __cpuinit intel_smp_check(struct cpuinfo_x86 *c) {#ifdef CONFIG_SMP /* calling is from identify_secondary_cpu() ? */ -if (c->cpu_index == boot_cpu_id) +if (!c->cpu_index)return ;/*
arch/x86/kernel/reboot.c +1 -1
@@ -84,7 +84,7 @@ static int __init reboot_setup(char *str) }/* we will leave sorting out the final value when we are ready to reboot, since we might not -have set up boot_cpu_id or smp_num_cpu */ +have detected BSP APIC ID or smp_num_cpu */ break ;#endif /* CONFIG_SMP */
arch/x86/kernel/setup.c +0 -1
@@ -124,7 +124,6 @@ unsigned long max_pfn_mapped;RESERVE_BRK (dmi_alloc,65536 );#endif -unsigned int boot_cpu_id__read_mostly ;static __initdata unsigned long _brk_start = (unsigned long )__brk_base;unsigned long _brk_end = (unsigned long )__brk_base;
arch/x86/kernel/setup_percpu.c +2 -2
@@ -244,7 +244,7 @@ void __init setup_per_cpu_areas(void)* Up to this point, the boot CPU has been using .init.data * area. Reload any changed state for the boot CPU. */ -if (cpu == boot_cpu_id) +if (!cpu)switch_to_new_gdt (cpu); }
@@ -262,7 +262,7 @@ void __init setup_per_cpu_areas(void)* make sure boot cpu numa_node is right, when boot cpu is on the * node that doesn't have mem installed */ -set_cpu_numa_node (boot_cpu_id,early_cpu_to_node (boot_cpu_id)); +set_cpu_numa_node (0 ,early_cpu_to_node (0 ));#endif /* Setup node to cpumask map */
arch/x86/mm/k8topology_64.c +3 -3
@@ -54,8 +54,8 @@ static __init int find_northbridge(void)static __init void early_get_boot_cpu_id (void ) {/* -* need to get boot_cpu_id so can use that to create apicid_to_node -* in k8_scan_nodes() +* need to get the APIC ID of the BSP so can use that to +* create apicid_to_node in k8_scan_nodes() */ #ifdef CONFIG_X86_MPPARSE /*
@@ -212,7 +212,7 @@ int __init k8_scan_nodes(void) bits = boot_cpu_data.x86_coreid_bits; cores = (1 <<bits); apicid_base =0 ; -/* need to get boot_cpu_id early for system with apicid lifting */ +/* get the APIC ID of the BSP early for systems with apicid lifting */ early_get_boot_cpu_id ();if (boot_cpu_physical_apicid >0 ) {pr_info ("BSP APIC ID: %02x\n" , boot_cpu_physical_apicid);
Signature · 1 line
1.7.1.1
[tip:x86/cleanups] x86, cleanup: Remove obsolete boot_cpu_id variable
Commit-ID: f6e9456c9272bb570df6e217cdbe007e270b1c4e Gitweb: http://git.kernel.org/tip/f6e9456c9272bb570df6e217cdbe007e270b1c4e Author: Robert Richter <[email protected]> AuthorDate: Wed, 21 Jul 2010 19:03:58 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Thu, 12 Aug 2010 14:01:38 -0700
x86, cleanup: Remove obsolete boot_cpu_id variable
boot_cpu_id is there for historical reasons and was renamed to boot_cpu_physical_apicid in patch:
c70dcb7 x86: change boot_cpu_id to boot_cpu_physical_apicid
However, there are some remaining occurrences of boot_cpu_id that are never touched in the kernel and thus its value is always 0.
This patch removes boot_cpu_id completely.
LKML-Reference: <[email protected]>
--- arch/x86/include/asm/apb_timer.h | 1 - arch/x86/include/asm/cpu.h | 1 - arch/x86/kernel/apb_timer.c | 2 +- arch/x86/kernel/apic/io_apic.c | 12 ++++++------ arch/x86/kernel/cpu/amd.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/cpu/intel.c | 2 +- arch/x86/kernel/reboot.c | 2 +- arch/x86/kernel/setup.c | 1 - arch/x86/kernel/setup_percpu.c | 2 +- arch/x86/mm/k8topology_64.c | 6 +++--- 11 files changed, 15 insertions(+), 18 deletions(-)
arch/x86/include/asm/apb_timer.h +0 -1
@@ -54,7 +54,6 @@ extern struct clock_event_device *global_clock_event;extern unsigned long apbt_quick_calibrate (void );extern int arch_setup_apbt_irqs (int irq,int trigger,int mask,int cpu);extern void apbt_setup_secondary_clock (void ); -extern unsigned int boot_cpu_id;extern struct sfi_timer_table_entry *sfi_get_mtmr (int hint);extern void sfi_free_mtmr (struct sfi_timer_table_entry *mtmr);
arch/x86/include/asm/cpu.h +0 -1
@@ -32,6 +32,5 @@ extern void arch_unregister_cpu(int);DECLARE_PER_CPU (int, cpu_state); -extern unsigned int boot_cpu_id;#endif /* _ASM_X86_CPU_H */
arch/x86/kernel/apb_timer.c +1 -1
@@ -343,7 +343,7 @@ void apbt_setup_secondary_clock(void)/* Don't register boot CPU clockevent */ cpu =smp_processor_id (); -if (cpu == boot_cpu_id) +if (!cpu)return ;/* * We need to calculate the scaled math multiplication factor for
arch/x86/kernel/apic/io_apic.c +6 -6
@@ -162,7 +162,7 @@ int __init arch_early_irq_init(void) cfg = irq_cfgx; count =ARRAY_SIZE (irq_cfgx); - node=cpu_to_node (boot_cpu_id); + node =cpu_to_node (0 );for (i =0 ; i < count; i++) { desc =irq_to_desc (i);
@@ -1483,7 +1483,7 @@ static void __init setup_IO_APIC_irqs(void)int notcon =0 ;struct irq_desc *desc;struct irq_cfg *cfg; -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );apic_printk (APIC_VERBOSE ,KERN_DEBUG "init IO_APIC IRQs\n" );
@@ -1548,7 +1548,7 @@ static void __init setup_IO_APIC_irqs(void)void setup_IO_APIC_irq_extra (u32 gsi) {int apic_id =0 , pin, idx, irq; -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );struct irq_desc *desc;struct irq_cfg *cfg;
@@ -2925,7 +2925,7 @@ static inline void __init check_timer(void) {struct irq_desc *desc =irq_to_desc (0 );struct irq_cfg *cfg = desc->chip_data; -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );int apic1, pin1, apic2, pin2;unsigned long flags;int no_pin1 =0 ;
@@ -3279,7 +3279,7 @@ unsigned int create_irq_nr(unsigned int irq_want, int node)int create_irq (void ) { -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );unsigned int irq_want;int irq;
@@ -3901,7 +3901,7 @@ static int __io_apic_set_pci_routing(struct device *dev, int irq,if (dev) node =dev_to_node (dev);else - node =cpu_to_node (boot_cpu_id); + node =cpu_to_node (0 ); desc =irq_to_desc_alloc_node (irq, node);if (!desc) {
arch/x86/kernel/cpu/amd.c +1 -1
@@ -148,7 +148,7 @@ static void __cpuinit amd_k7_smp_check(struct cpuinfo_x86 *c) {#ifdef CONFIG_SMP /* calling is from identify_secondary_cpu() ? */ -if (c->cpu_index == boot_cpu_id) +if (!c->cpu_index)return ;/*
arch/x86/kernel/cpu/common.c +1 -1
@@ -665,7 +665,7 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c) this_cpu->c_early_init (c);#ifdef CONFIG_SMP - c->cpu_index = boot_cpu_id; + c->cpu_index =0 ;#endif filter_cpuid_features (c, false); }
arch/x86/kernel/cpu/intel.c +1 -1
@@ -169,7 +169,7 @@ static void __cpuinit intel_smp_check(struct cpuinfo_x86 *c) {#ifdef CONFIG_SMP /* calling is from identify_secondary_cpu() ? */ -if (c->cpu_index == boot_cpu_id) +if (!c->cpu_index)return ;/*
arch/x86/kernel/reboot.c +1 -1
@@ -84,7 +84,7 @@ static int __init reboot_setup(char *str) }/* we will leave sorting out the final value when we are ready to reboot, since we might not -have set up boot_cpu_id or smp_num_cpu */ +have detected BSP APIC ID or smp_num_cpu */ break ;#endif /* CONFIG_SMP */
arch/x86/kernel/setup.c +0 -1
@@ -125,7 +125,6 @@ unsigned long max_pfn_mapped;RESERVE_BRK (dmi_alloc,65536 );#endif -unsigned int boot_cpu_id__read_mostly ;static __initdata unsigned long _brk_start = (unsigned long )__brk_base;unsigned long _brk_end = (unsigned long )__brk_base;
arch/x86/kernel/setup_percpu.c +1 -1
@@ -253,7 +253,7 @@ void __init setup_per_cpu_areas(void)* Up to this point, the boot CPU has been using .init.data * area. Reload any changed state for the boot CPU. */ -if (cpu == boot_cpu_id) +if (!cpu)switch_to_new_gdt (cpu); }
arch/x86/mm/k8topology_64.c +3 -3
@@ -54,8 +54,8 @@ static __init int find_northbridge(void)static __init void early_get_boot_cpu_id (void ) {/* -* need to get boot_cpu_id so can use that to create apicid_to_node -* in k8_scan_nodes() +* need to get the APIC ID of the BSP so can use that to +* create apicid_to_node in k8_scan_nodes() */ #ifdef CONFIG_X86_MPPARSE /*
@@ -212,7 +212,7 @@ int __init k8_scan_nodes(void) bits = boot_cpu_data.x86_coreid_bits; cores = (1 <<bits); apicid_base =0 ; -/* need to get boot_cpu_id early for system with apicid lifting */ +/* get the APIC ID of the BSP early for systems with apicid lifting */ early_get_boot_cpu_id ();if (boot_cpu_physical_apicid >0 ) {pr_info ("BSP APIC ID: %02x\n" , boot_cpu_physical_apicid);
Quoted 10 lines · Robert Richter
Hans Peter, Suresh, and Cyrill, thanks for your feedback.
This is version 2 of the patch series.
Patches 2, 4, 7 are unchanged compared to -v1.
Patch 1 folds the initialization code into one patch.
fpu_init()is now called beforexsave_init().xsave_init()can later overwritexstate_sizebased on xstate features.
Quoted 6 lines
Patch 3 replaces all hardcoded
XSTATE_CPUIDvalues know.cpuid_levelis now taken fromboot_cpu_data.Patches 5 and 6 are new:
* add__initattribute tosetup_xstate_features()
* disable xsave in i387 emulation mode
Apart from the cleanup comments that I had for "[PATCH 6/7] x86, xsave:
disable xsave in i387 emulation mode", all other patches look good to me.
Thanks.
H. Peter Anvin
reviewerQuoted 10 lines · Robert Richter
Hans Peter, Suresh, and Cyrill, thanks for your feedback.
This is version 2 of the patch series.
Patches 2, 4, 7 are unchanged compared to -v1.
Patch 1 folds the initialization code into one patch.
fpu_init()is now called beforexsave_init().xsave_init()can later overwritexstate_sizebased on xstate features.
Quoted 7 lines
Patch 3 replaces all hardcoded
XSTATE_CPUIDvalues know.cpuid_levelis now taken fromboot_cpu_data.Patches 5 and 6 are new:
* add__initattribute tosetup_xstate_features()
* disable xsave in i387 emulation mode
Please note that I did integrate some of your patches already. I might need you to rebase; I'll know in a few minutes.
-hpa
H. Peter Anvin
reviewerQuoted 4 lines · H. Peter Anvin
Please note that I did integrate some of your patches already. I might need you to rebase; I'll know in a few minutes.
Nevermind, you had already seen that.
I'm going to hold off on 6/7 to let you address Suresh' comments, and will look for a sensible place to put 7/7.
-hpa
Quoted 1 line · Robert Richter
This is version 2 of the patch series.
Hans Peter,
I still have patch 6 and 7 in my queue, any opinions?
Thanks,
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center