[Xenomai-git] Philippe Gerum : cobalt/x86: fpu: fixup for kernel 4.2+
Module: xenomai-3 Branch: stable-3.0.x Commit: eddbb24f651ee2b2594715099b638ae8cddf485d URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=eddbb24f651ee2b2594715099b638ae8cddf485d Author: Philippe GerumDate: Mon Sep 5 15:11:24 2016 +0200 cobalt/x86: fpu: fixup for kernel 4.2+ --- .../cobalt/arch/x86/include/asm/xenomai/fptest.h |2 +- .../cobalt/arch/x86/include/asm/xenomai/thread.h | 15 ++- .../cobalt/arch/x86/include/asm/xenomai/wrappers.h |7 +- kernel/cobalt/arch/x86/machine.c |9 +- kernel/cobalt/arch/x86/thread.c| 124 +++- kernel/cobalt/include/asm-generic/xenomai/thread.h |2 - 6 files changed, 119 insertions(+), 40 deletions(-) diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/fptest.h b/kernel/cobalt/arch/x86/include/asm/xenomai/fptest.h index a05d54e..f0ecd00 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/fptest.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/fptest.h @@ -20,8 +20,8 @@ #define _COBALT_X86_ASM_FPTEST_H #include -#include #include +#include #include static inline int fp_kernel_supported(void) diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h b/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h index bd39f5a..d8a6a78 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h @@ -23,11 +23,15 @@ #include #include +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,4,0) typedef union thread_xstate x86_fpustate; #define x86_fpustate_ptr(t) ((t)->fpu.state) +#else +typedef union fpregs_state x86_fpustate; +#define x86_fpustate_ptr(t) ((t)->fpu.active_state) +#endif struct xnarchtcb { - x86_fpustate i387; struct xntcb core; unsigned long sp; unsigned long *spp; @@ -36,17 +40,13 @@ struct xnarchtcb { x86_fpustate *fpup; unsigned int root_kfpu: 1; unsigned int root_used_math: 1; + x86_fpustate *kfpu_state; struct { unsigned long ip; unsigned long ax; } mayday; }; -static inline int xnarch_shadow_p(struct xnarchtcb *tcb, struct task_struct *task) -{ - return tcb->spp == >thread.sp; -} - #define xnarch_fpu_ptr(tcb) ((tcb)->fpup) #define xnarch_fault_regs(d) ((d)->regs) @@ -84,4 +84,7 @@ static inline int xnarch_escalate(void) return 0; } +int mach_x86_thread_init(void); +void mach_x86_thread_cleanup(void); + #endif /* !_COBALT_X86_ASM_THREAD_H */ diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h index bfff14b..5f9cff3 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h @@ -24,9 +24,14 @@ #define __get_user_inatomic __get_user #define __put_user_inatomic __put_user -#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0) #include #include +#else +#include +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0) static inline void kernel_fpu_disable(void) { diff --git a/kernel/cobalt/arch/x86/machine.c b/kernel/cobalt/arch/x86/machine.c index 14443e0..d9eb66d 100644 --- a/kernel/cobalt/arch/x86/machine.c +++ b/kernel/cobalt/arch/x86/machine.c @@ -17,10 +17,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ - #include #include #include +#include #include #include @@ -148,6 +148,12 @@ static unsigned long mach_x86_calibrate(void) static int mach_x86_init(void) { + int ret; + + ret = mach_x86_thread_init(); + if (ret) + return ret; + mach_x86_c1e_disable(); mach_x86_smi_init(); mach_x86_smi_disable(); @@ -158,6 +164,7 @@ static int mach_x86_init(void) static void mach_x86_cleanup(void) { mach_x86_smi_restore(); + mach_x86_thread_cleanup(); } static const char *const fault_labels[] = { diff --git a/kernel/cobalt/arch/x86/thread.c b/kernel/cobalt/arch/x86/thread.c index 0383f00..9e1dea2 100644 --- a/kernel/cobalt/arch/x86/thread.c +++ b/kernel/cobalt/arch/x86/thread.c @@ -21,10 +21,43 @@ #include #include #include +#include #include #include +#include + +static struct kmem_cache *xstate_cache; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0) #include #include +#define x86_fpregs_active(t) __thread_has_fpu(t) +#define x86_fpregs_deactivate(t) __thread_clear_has_fpu(t) +#define x86_fpregs_activate(t) __thread_set_has_fpu(t) +#define x86_xstate_alignment __alignof__(union thread_xstate) +#else +#include + +static inline int x86_fpregs_active(struct task_struct *t) +{ + return t->thread.fpu.fpregs_active; +} + +static inline void x86_fpregs_deactivate(struct task_struct *t) +{ + if (x86_fpregs_active(t)) +
[Xenomai-git] Philippe Gerum : cobalt/x86: fpu: fixup for kernel 4.2+
Module: xenomai-3 Branch: next Commit: d8fe5657a038ef8b735e70bc7cf57f528930ecba URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d8fe5657a038ef8b735e70bc7cf57f528930ecba Author: Philippe GerumDate: Mon Sep 5 15:11:24 2016 +0200 cobalt/x86: fpu: fixup for kernel 4.2+ --- .../cobalt/arch/x86/include/asm/xenomai/fptest.h |2 +- .../cobalt/arch/x86/include/asm/xenomai/thread.h | 15 ++- .../cobalt/arch/x86/include/asm/xenomai/wrappers.h |7 +- kernel/cobalt/arch/x86/machine.c |9 +- kernel/cobalt/arch/x86/thread.c| 124 +++- kernel/cobalt/include/asm-generic/xenomai/thread.h |2 - 6 files changed, 119 insertions(+), 40 deletions(-) diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/fptest.h b/kernel/cobalt/arch/x86/include/asm/xenomai/fptest.h index a05d54e..f0ecd00 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/fptest.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/fptest.h @@ -20,8 +20,8 @@ #define _COBALT_X86_ASM_FPTEST_H #include -#include #include +#include #include static inline int fp_kernel_supported(void) diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h b/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h index bd39f5a..d8a6a78 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h @@ -23,11 +23,15 @@ #include #include +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,4,0) typedef union thread_xstate x86_fpustate; #define x86_fpustate_ptr(t) ((t)->fpu.state) +#else +typedef union fpregs_state x86_fpustate; +#define x86_fpustate_ptr(t) ((t)->fpu.active_state) +#endif struct xnarchtcb { - x86_fpustate i387; struct xntcb core; unsigned long sp; unsigned long *spp; @@ -36,17 +40,13 @@ struct xnarchtcb { x86_fpustate *fpup; unsigned int root_kfpu: 1; unsigned int root_used_math: 1; + x86_fpustate *kfpu_state; struct { unsigned long ip; unsigned long ax; } mayday; }; -static inline int xnarch_shadow_p(struct xnarchtcb *tcb, struct task_struct *task) -{ - return tcb->spp == >thread.sp; -} - #define xnarch_fpu_ptr(tcb) ((tcb)->fpup) #define xnarch_fault_regs(d) ((d)->regs) @@ -84,4 +84,7 @@ static inline int xnarch_escalate(void) return 0; } +int mach_x86_thread_init(void); +void mach_x86_thread_cleanup(void); + #endif /* !_COBALT_X86_ASM_THREAD_H */ diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h index bfff14b..5f9cff3 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h @@ -24,9 +24,14 @@ #define __get_user_inatomic __get_user #define __put_user_inatomic __put_user -#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0) #include #include +#else +#include +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0) static inline void kernel_fpu_disable(void) { diff --git a/kernel/cobalt/arch/x86/machine.c b/kernel/cobalt/arch/x86/machine.c index 14443e0..d9eb66d 100644 --- a/kernel/cobalt/arch/x86/machine.c +++ b/kernel/cobalt/arch/x86/machine.c @@ -17,10 +17,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ - #include #include #include +#include #include #include @@ -148,6 +148,12 @@ static unsigned long mach_x86_calibrate(void) static int mach_x86_init(void) { + int ret; + + ret = mach_x86_thread_init(); + if (ret) + return ret; + mach_x86_c1e_disable(); mach_x86_smi_init(); mach_x86_smi_disable(); @@ -158,6 +164,7 @@ static int mach_x86_init(void) static void mach_x86_cleanup(void) { mach_x86_smi_restore(); + mach_x86_thread_cleanup(); } static const char *const fault_labels[] = { diff --git a/kernel/cobalt/arch/x86/thread.c b/kernel/cobalt/arch/x86/thread.c index 0383f00..9e1dea2 100644 --- a/kernel/cobalt/arch/x86/thread.c +++ b/kernel/cobalt/arch/x86/thread.c @@ -21,10 +21,43 @@ #include #include #include +#include #include #include +#include + +static struct kmem_cache *xstate_cache; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0) #include #include +#define x86_fpregs_active(t) __thread_has_fpu(t) +#define x86_fpregs_deactivate(t) __thread_clear_has_fpu(t) +#define x86_fpregs_activate(t) __thread_set_has_fpu(t) +#define x86_xstate_alignment __alignof__(union thread_xstate) +#else +#include + +static inline int x86_fpregs_active(struct task_struct *t) +{ + return t->thread.fpu.fpregs_active; +} + +static inline void x86_fpregs_deactivate(struct task_struct *t) +{ + if (x86_fpregs_active(t)) +