2012-03-29 01:30:02 +08:00
|
|
|
/*
|
|
|
|
* Copyright IBM Corp. 1999, 2009
|
|
|
|
*
|
|
|
|
* Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ASM_SWITCH_TO_H
|
|
|
|
#define __ASM_SWITCH_TO_H
|
|
|
|
|
|
|
|
#include <linux/thread_info.h>
|
2015-10-06 18:25:59 +08:00
|
|
|
#include <asm/fpu/api.h>
|
2013-08-20 16:24:12 +08:00
|
|
|
#include <asm/ptrace.h>
|
2016-01-26 21:10:34 +08:00
|
|
|
#include <asm/guarded_storage.h>
|
2012-03-29 01:30:02 +08:00
|
|
|
|
|
|
|
extern struct task_struct *__switch_to(void *, void *);
|
2013-07-03 04:58:26 +08:00
|
|
|
extern void update_cr_regs(struct task_struct *task);
|
2012-03-29 01:30:02 +08:00
|
|
|
|
|
|
|
static inline void save_access_regs(unsigned int *acrs)
|
|
|
|
{
|
2013-08-20 16:24:12 +08:00
|
|
|
typedef struct { int _[NUM_ACRS]; } acrstype;
|
|
|
|
|
|
|
|
asm volatile("stam 0,15,%0" : "=Q" (*(acrstype *)acrs));
|
2012-03-29 01:30:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void restore_access_regs(unsigned int *acrs)
|
|
|
|
{
|
2013-08-20 16:24:12 +08:00
|
|
|
typedef struct { int _[NUM_ACRS]; } acrstype;
|
|
|
|
|
|
|
|
asm volatile("lam 0,15,%0" : : "Q" (*(acrstype *)acrs));
|
2012-03-29 01:30:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define switch_to(prev,next,last) do { \
|
|
|
|
if (prev->mm) { \
|
2015-06-29 22:43:06 +08:00
|
|
|
save_fpu_regs(); \
|
2012-03-29 01:30:02 +08:00
|
|
|
save_access_regs(&prev->thread.acrs[0]); \
|
2012-07-31 16:52:05 +08:00
|
|
|
save_ri_cb(prev->thread.ri_cb); \
|
2016-01-26 21:10:34 +08:00
|
|
|
save_gs_cb(prev->thread.gs_cb); \
|
2012-03-29 01:30:02 +08:00
|
|
|
} \
|
|
|
|
if (next->mm) { \
|
2014-10-06 23:53:53 +08:00
|
|
|
update_cr_regs(next); \
|
s390/kernel: lazy restore fpu registers
Improve the save and restore behavior of FPU register contents to use the
vector extension within the kernel.
The kernel does not use floating-point or vector registers and, therefore,
saving and restoring the FPU register contents are performed for handling
signals or switching processes only. To prepare for using vector
instructions and vector registers within the kernel, enhance the save
behavior and implement a lazy restore at return to user space from a
system call or interrupt.
To implement the lazy restore, the save_fpu_regs() sets a CPU information
flag, CIF_FPU, to indicate that the FPU registers must be restored.
Saving and setting CIF_FPU is performed in an atomic fashion to be
interrupt-safe. When the kernel wants to use the vector extension or
wants to change the FPU register state for a task during signal handling,
the save_fpu_regs() must be called first. The CIF_FPU flag is also set at
process switch. At return to user space, the FPU state is restored. In
particular, the FPU state includes the floating-point or vector register
contents, as well as, vector-enablement and floating-point control. The
FPU state restore and clearing CIF_FPU is also performed in an atomic
fashion.
For KVM, the restore of the FPU register state is performed when restoring
the general-purpose guest registers before the SIE instructions is started.
Because the path towards the SIE instruction is interruptible, the CIF_FPU
flag must be checked again right before going into SIE. If set, the guest
registers must be reloaded again by re-entering the outer SIE loop. This
is the same behavior as if the SIE critical section is interrupted.
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2015-06-10 18:53:42 +08:00
|
|
|
set_cpu_flag(CIF_FPU); \
|
2012-03-29 01:30:02 +08:00
|
|
|
restore_access_regs(&next->thread.acrs[0]); \
|
2012-07-31 16:52:05 +08:00
|
|
|
restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb); \
|
2016-01-26 21:10:34 +08:00
|
|
|
restore_gs_cb(next->thread.gs_cb); \
|
2012-03-29 01:30:02 +08:00
|
|
|
} \
|
|
|
|
prev = __switch_to(prev,next); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#endif /* __ASM_SWITCH_TO_H */
|