2019-05-27 13:55:01 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-10-10 11:19:43 +07:00
|
|
|
#ifndef _ASM_POWERPC_PROCESSOR_H
|
|
|
|
#define _ASM_POWERPC_PROCESSOR_H
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
2005-10-10 11:19:43 +07:00
|
|
|
* Copyright (C) 2001 PPC 64 Team, IBM Corp
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
2005-10-10 11:19:43 +07:00
|
|
|
#include <asm/reg.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-06-25 11:07:18 +07:00
|
|
|
#ifdef CONFIG_VSX
|
|
|
|
#define TS_FPRWIDTH 2
|
2013-09-23 09:04:37 +07:00
|
|
|
|
|
|
|
#ifdef __BIG_ENDIAN__
|
|
|
|
#define TS_FPROFFSET 0
|
|
|
|
#define TS_VSRLOWOFFSET 1
|
|
|
|
#else
|
|
|
|
#define TS_FPROFFSET 1
|
|
|
|
#define TS_VSRLOWOFFSET 0
|
|
|
|
#endif
|
|
|
|
|
2008-06-25 11:07:18 +07:00
|
|
|
#else
|
2008-06-26 14:07:48 +07:00
|
|
|
#define TS_FPRWIDTH 1
|
2013-09-23 09:04:37 +07:00
|
|
|
#define TS_FPROFFSET 0
|
2008-06-25 11:07:18 +07:00
|
|
|
#endif
|
2008-06-26 14:07:48 +07:00
|
|
|
|
2012-12-07 04:49:56 +07:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
/* Default SMT priority is set to 3. Use 11- 13bits to save priority. */
|
|
|
|
#define PPR_PRIORITY 3
|
|
|
|
#ifdef __ASSEMBLY__
|
2018-10-12 20:15:16 +07:00
|
|
|
#define DEFAULT_PPR (PPR_PRIORITY << 50)
|
2012-12-07 04:49:56 +07:00
|
|
|
#else
|
2018-10-12 20:15:16 +07:00
|
|
|
#define DEFAULT_PPR ((u64)PPR_PRIORITY << 50)
|
2012-12-07 04:49:56 +07:00
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* CONFIG_PPC64 */
|
|
|
|
|
2005-10-10 11:19:43 +07:00
|
|
|
#ifndef __ASSEMBLY__
|
2018-07-05 23:25:09 +07:00
|
|
|
#include <linux/types.h>
|
2019-01-17 19:27:28 +07:00
|
|
|
#include <linux/thread_info.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/ptrace.h>
|
2012-12-20 21:06:44 +07:00
|
|
|
#include <asm/hw_breakpoint.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-11-10 09:37:51 +07:00
|
|
|
/* We do _not_ want to define new machine types at all, those must die
|
|
|
|
* in favor of using the device-tree
|
|
|
|
* -- BenH.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
2013-03-27 07:47:03 +07:00
|
|
|
/* PREP sub-platform types. Unused */
|
2005-04-17 05:20:36 +07:00
|
|
|
#define _PREP_Motorola 0x01 /* motorola prep */
|
|
|
|
#define _PREP_Firm 0x02 /* firmworks prep */
|
|
|
|
#define _PREP_IBM 0x00 /* ibm prep */
|
|
|
|
#define _PREP_Bull 0x03 /* bull prep */
|
|
|
|
|
2005-11-10 09:37:51 +07:00
|
|
|
/* CHRP sub-platform types. These are arbitrary */
|
2005-04-17 05:20:36 +07:00
|
|
|
#define _CHRP_Motorola 0x04 /* motorola chrp, the cobra */
|
|
|
|
#define _CHRP_IBM 0x05 /* IBM chrp, the longtrail and longtrail 2 */
|
|
|
|
#define _CHRP_Pegasos 0x06 /* Genesi/bplan's Pegasos and Pegasos2 */
|
2006-07-04 11:16:28 +07:00
|
|
|
#define _CHRP_briq 0x07 /* TotalImpact's briQ */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-03-28 19:15:54 +07:00
|
|
|
#if defined(__KERNEL__) && defined(CONFIG_PPC32)
|
|
|
|
|
|
|
|
extern int _chrp_type;
|
2005-11-10 09:37:51 +07:00
|
|
|
|
2006-03-28 19:15:54 +07:00
|
|
|
#endif /* defined(__KERNEL__) && defined(CONFIG_PPC32) */
|
|
|
|
|
2005-10-10 11:19:43 +07:00
|
|
|
/* Macros for adjusting thread priority (hardware multi-threading) */
|
|
|
|
#define HMT_very_low() asm volatile("or 31,31,31 # very low priority")
|
|
|
|
#define HMT_low() asm volatile("or 1,1,1 # low priority")
|
|
|
|
#define HMT_medium_low() asm volatile("or 6,6,6 # medium low priority")
|
|
|
|
#define HMT_medium() asm volatile("or 2,2,2 # medium priority")
|
|
|
|
#define HMT_medium_high() asm volatile("or 5,5,5 # medium high priority")
|
|
|
|
#define HMT_high() asm volatile("or 3,3,3 # high priority")
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC64
|
2019-01-31 17:08:48 +07:00
|
|
|
#include <asm/task_size_64.h>
|
2017-03-30 18:05:21 +07:00
|
|
|
#else
|
2019-01-31 17:08:48 +07:00
|
|
|
#include <asm/task_size_32.h>
|
2017-03-30 18:05:21 +07:00
|
|
|
#endif
|
|
|
|
|
2019-01-31 17:08:48 +07:00
|
|
|
struct task_struct;
|
|
|
|
void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
|
|
|
|
void release_thread(struct task_struct *);
|
2008-02-08 19:19:26 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
typedef struct {
|
|
|
|
unsigned long seg;
|
|
|
|
} mm_segment_t;
|
|
|
|
|
2013-09-10 17:20:42 +07:00
|
|
|
#define TS_FPR(i) fp_state.fpr[i][TS_FPROFFSET]
|
2016-09-23 13:18:25 +07:00
|
|
|
#define TS_CKFPR(i) ckfp_state.fpr[i][TS_FPROFFSET]
|
2013-09-10 17:20:42 +07:00
|
|
|
|
|
|
|
/* FP and VSX 0-31 register set */
|
|
|
|
struct thread_fp_state {
|
|
|
|
u64 fpr[32][TS_FPRWIDTH] __attribute__((aligned(16)));
|
|
|
|
u64 fpscr; /* Floating point status */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Complete AltiVec register set including VSCR */
|
|
|
|
struct thread_vr_state {
|
|
|
|
vector128 vr[32] __attribute__((aligned(16)));
|
|
|
|
vector128 vscr __attribute__((aligned(16)));
|
|
|
|
};
|
2008-06-26 14:07:48 +07:00
|
|
|
|
2013-07-04 13:15:46 +07:00
|
|
|
struct debug_reg {
|
2010-02-08 18:53:26 +07:00
|
|
|
#ifdef CONFIG_PPC_ADV_DEBUG_REGS
|
|
|
|
/*
|
|
|
|
* The following help to manage the use of Debug Control Registers
|
|
|
|
* om the BookE platforms.
|
|
|
|
*/
|
2013-05-22 11:20:58 +07:00
|
|
|
uint32_t dbcr0;
|
|
|
|
uint32_t dbcr1;
|
2010-02-08 18:53:26 +07:00
|
|
|
#ifdef CONFIG_BOOKE
|
2013-05-22 11:20:58 +07:00
|
|
|
uint32_t dbcr2;
|
2010-02-08 18:53:26 +07:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* The stored value of the DBSR register will be the value at the
|
|
|
|
* last debug interrupt. This register can only be read from the
|
|
|
|
* user (will never be written to) and has value while helping to
|
|
|
|
* describe the reason for the last debug trap. Torez
|
|
|
|
*/
|
2013-05-22 11:20:58 +07:00
|
|
|
uint32_t dbsr;
|
2010-02-08 18:53:26 +07:00
|
|
|
/*
|
|
|
|
* The following will contain addresses used by debug applications
|
|
|
|
* to help trace and trap on particular address locations.
|
|
|
|
* The bits in the Debug Control Registers above help define which
|
|
|
|
* of the following registers will contain valid data and/or addresses.
|
|
|
|
*/
|
|
|
|
unsigned long iac1;
|
|
|
|
unsigned long iac2;
|
|
|
|
#if CONFIG_PPC_ADV_DEBUG_IACS > 2
|
|
|
|
unsigned long iac3;
|
|
|
|
unsigned long iac4;
|
|
|
|
#endif
|
|
|
|
unsigned long dac1;
|
|
|
|
unsigned long dac2;
|
|
|
|
#if CONFIG_PPC_ADV_DEBUG_DVCS > 0
|
|
|
|
unsigned long dvc1;
|
|
|
|
unsigned long dvc2;
|
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
2013-07-04 13:15:46 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct thread_struct {
|
|
|
|
unsigned long ksp; /* Kernel stack pointer */
|
2013-06-26 12:42:22 +07:00
|
|
|
|
2013-07-04 13:15:46 +07:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
unsigned long ksp_vsid;
|
|
|
|
#endif
|
|
|
|
struct pt_regs *regs; /* Pointer to saved register state */
|
2018-05-14 20:03:15 +07:00
|
|
|
mm_segment_t addr_limit; /* for get_fs() validation */
|
2013-07-04 13:15:46 +07:00
|
|
|
#ifdef CONFIG_BOOKE
|
|
|
|
/* BookE base exception scratch space; align on cacheline */
|
|
|
|
unsigned long normsave[8] ____cacheline_aligned;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PPC32
|
|
|
|
void *pgdir; /* root of page-table tree */
|
|
|
|
unsigned long ksp_limit; /* if ksp <= ksp_limit stack overflow */
|
2019-02-21 17:37:54 +07:00
|
|
|
#ifdef CONFIG_PPC_RTAS
|
|
|
|
unsigned long rtas_sp; /* stack pointer for when in RTAS */
|
|
|
|
#endif
|
2019-03-11 15:30:38 +07:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP)
|
|
|
|
unsigned long kuap; /* opened segments for user access */
|
2013-07-04 13:15:46 +07:00
|
|
|
#endif
|
2013-06-26 12:42:22 +07:00
|
|
|
/* Debug Registers */
|
2013-07-04 13:15:46 +07:00
|
|
|
struct debug_reg debug;
|
2013-09-10 17:20:42 +07:00
|
|
|
struct thread_fp_state fp_state;
|
2013-09-10 17:21:10 +07:00
|
|
|
struct thread_fp_state *fp_save_area;
|
2005-10-10 11:19:43 +07:00
|
|
|
int fpexc_mode; /* floating-point exception mode */
|
2006-06-07 13:15:39 +07:00
|
|
|
unsigned int align_ctl; /* alignment handling control */
|
2010-06-15 13:05:19 +07:00
|
|
|
#ifdef CONFIG_HAVE_HW_BREAKPOINT
|
|
|
|
struct perf_event *ptrace_bps[HBP_NUM];
|
|
|
|
/*
|
|
|
|
* Helps identify source of single-step exception and subsequent
|
|
|
|
* hw-breakpoint enablement
|
|
|
|
*/
|
|
|
|
struct perf_event *last_hit_ubp;
|
|
|
|
#endif /* CONFIG_HAVE_HW_BREAKPOINT */
|
2012-12-20 21:06:44 +07:00
|
|
|
struct arch_hw_breakpoint hw_brk; /* info on the hardware breakpoint */
|
2012-08-24 04:27:09 +07:00
|
|
|
unsigned long trap_nr; /* last trap # on this thread */
|
powerpc/64s/hash: Add a SLB preload cache
When switching processes, currently all user SLBEs are cleared, and a
few (exec_base, pc, and stack) are preloaded. In trivial testing with
small apps, this tends to miss the heap and low 256MB segments, and it
will also miss commonly accessed segments on large memory workloads.
Add a simple round-robin preload cache that just inserts the last SLB
miss into the head of the cache and preloads those at context switch
time. Every 256 context switches, the oldest entry is removed from the
cache to shrink the cache and require fewer slbmte if they are unused.
Much more could go into this, including into the SLB entry reclaim
side to track some LRU information etc, which would require a study of
large memory workloads. But this is a simple thing we can do now that
is an obvious win for common workloads.
With the full series, process switching speed on the context_switch
benchmark on POWER9/hash (with kernel speculation security masures
disabled) increases from 140K/s to 178K/s (27%).
POWER8 does not change much (within 1%), it's unclear why it does not
see a big gain like POWER9.
Booting to busybox init with 256MB segments has SLB misses go down
from 945 to 69, and with 1T segments 900 to 21. These could almost all
be eliminated by preloading a bit more carefully with ELF binary
loading.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-09-14 22:30:56 +07:00
|
|
|
u8 load_slb; /* Ages out SLB preload cache entries */
|
2016-02-29 13:53:47 +07:00
|
|
|
u8 load_fp;
|
2005-04-17 05:20:36 +07:00
|
|
|
#ifdef CONFIG_ALTIVEC
|
2016-02-29 13:53:47 +07:00
|
|
|
u8 load_vec;
|
2013-09-10 17:20:42 +07:00
|
|
|
struct thread_vr_state vr_state;
|
2013-09-10 17:21:10 +07:00
|
|
|
struct thread_vr_state *vr_save_area;
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned long vrsave;
|
|
|
|
int used_vr; /* set if process has used altivec */
|
|
|
|
#endif /* CONFIG_ALTIVEC */
|
2008-06-25 11:07:18 +07:00
|
|
|
#ifdef CONFIG_VSX
|
|
|
|
/* VSR status */
|
2016-03-25 00:12:21 +07:00
|
|
|
int used_vsr; /* set if process has used VSX */
|
2008-06-25 11:07:18 +07:00
|
|
|
#endif /* CONFIG_VSX */
|
2005-04-17 05:20:36 +07:00
|
|
|
#ifdef CONFIG_SPE
|
|
|
|
unsigned long evr[32]; /* upper 32-bits of SPE regs */
|
|
|
|
u64 acc; /* Accumulator */
|
|
|
|
unsigned long spefscr; /* SPE & eFP status */
|
powerpc: fix exception clearing in e500 SPE float emulation
The e500 SPE floating-point emulation code clears existing exceptions
(__FPU_FPSCR &= ~FP_EX_MASK;) before ORing in the exceptions from the
emulated operation. However, these exception bits are the "sticky",
cumulative exception bits, and should only be cleared by the user
program setting SPEFSCR, not implicitly by any floating-point
instruction (whether executed purely by the hardware or emulated).
The spurious clearing of these bits shows up as missing exceptions in
glibc testing.
Fixing this, however, is not as simple as just not clearing the bits,
because while the bits may be from previous floating-point operations
(in which case they should not be cleared), the processor can also set
the sticky bits itself before the interrupt for an exception occurs,
and this can happen in cases when IEEE 754 semantics are that the
sticky bit should not be set. Specifically, the "invalid" sticky bit
is set in various cases with non-finite operands, where IEEE 754
semantics do not involve raising such an exception, and the
"underflow" sticky bit is set in cases of exact underflow, whereas
IEEE 754 semantics are that this flag is set only for inexact
underflow. Thus, for correct emulation the kernel needs to know the
setting of these two sticky bits before the instruction being
emulated.
When a floating-point operation raises an exception, the kernel can
note the state of the sticky bits immediately afterwards. Some
<fenv.h> functions that affect the state of these bits, such as
fesetenv and feholdexcept, need to use prctl with PR_GET_FPEXC and
PR_SET_FPEXC anyway, and so it is natural to record the state of those
bits during that call into the kernel and so avoid any need for a
separate call into the kernel to inform it of a change to those bits.
Thus, the interface I chose to use (in this patch and the glibc port)
is that one of those prctl calls must be made after any userspace
change to those sticky bits, other than through a floating-point
operation that traps into the kernel anyway. feclearexcept and
fesetexceptflag duly make those calls, which would not be required
were it not for this issue.
The previous EGLIBC port, and the uClibc code copied from it, is
fundamentally broken as regards any use of prctl for floating-point
exceptions because it didn't use the PR_FP_EXC_SW_ENABLE bit in its
prctl calls (and did various worse things, such as passing a pointer
when prctl expected an integer). If you avoid anything where prctl is
used, the clearing of sticky bits still means it will never give
anything approximating correct exception semantics with existing
kernels. I don't believe the patch makes things any worse for
existing code that doesn't try to inform the kernel of changes to
sticky bits - such code may get incorrect exceptions in some cases,
but it would have done so anyway in other cases.
Signed-off-by: Joseph Myers <joseph@codesourcery.com>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2013-12-11 06:07:45 +07:00
|
|
|
unsigned long spefscr_last; /* SPEFSCR value on last prctl
|
|
|
|
call or trap return */
|
2005-04-17 05:20:36 +07:00
|
|
|
int used_spe; /* set if process has used spe */
|
|
|
|
#endif /* CONFIG_SPE */
|
2013-02-13 23:21:31 +07:00
|
|
|
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
|
2016-09-14 15:02:16 +07:00
|
|
|
u8 load_tm;
|
2013-02-13 23:21:31 +07:00
|
|
|
u64 tm_tfhar; /* Transaction fail handler addr */
|
|
|
|
u64 tm_texasr; /* Transaction exception & summary */
|
|
|
|
u64 tm_tfiar; /* Transaction fail instr address reg */
|
|
|
|
struct pt_regs ckpt_regs; /* Checkpointed registers */
|
|
|
|
|
2013-08-09 14:29:31 +07:00
|
|
|
unsigned long tm_tar;
|
|
|
|
unsigned long tm_ppr;
|
|
|
|
unsigned long tm_dscr;
|
|
|
|
|
2013-02-13 23:21:31 +07:00
|
|
|
/*
|
2016-09-23 13:18:24 +07:00
|
|
|
* Checkpointed FP and VSX 0-31 register set.
|
2013-02-13 23:21:31 +07:00
|
|
|
*
|
|
|
|
* When a transaction is active/signalled/scheduled etc., *regs is the
|
|
|
|
* most recent set of/speculated GPRs with ckpt_regs being the older
|
|
|
|
* checkpointed regs to which we roll back if transaction aborts.
|
|
|
|
*
|
2016-09-23 13:18:24 +07:00
|
|
|
* These are analogous to how ckpt_regs and pt_regs work
|
2013-02-13 23:21:31 +07:00
|
|
|
*/
|
2016-09-23 13:18:25 +07:00
|
|
|
struct thread_fp_state ckfp_state; /* Checkpointed FP state */
|
|
|
|
struct thread_vr_state ckvr_state; /* Checkpointed VR state */
|
|
|
|
unsigned long ckvrsave; /* Checkpointed VRSAVE */
|
2013-02-13 23:21:31 +07:00
|
|
|
#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
|
2018-01-19 08:50:31 +07:00
|
|
|
#ifdef CONFIG_PPC_MEM_KEYS
|
|
|
|
unsigned long amr;
|
|
|
|
unsigned long iamr;
|
|
|
|
unsigned long uamor;
|
|
|
|
#endif
|
2010-04-16 05:11:51 +07:00
|
|
|
#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
|
|
|
|
void* kvm_shadow_vcpu; /* KVM internal data */
|
|
|
|
#endif /* CONFIG_KVM_BOOK3S_32_HANDLER */
|
2011-12-20 22:34:43 +07:00
|
|
|
#if defined(CONFIG_KVM) && defined(CONFIG_BOOKE)
|
|
|
|
struct kvm_vcpu *kvm_vcpu;
|
|
|
|
#endif
|
2011-03-02 22:18:48 +07:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
unsigned long dscr;
|
2015-10-29 07:43:55 +07:00
|
|
|
unsigned long fscr;
|
2015-05-21 13:43:04 +07:00
|
|
|
/*
|
|
|
|
* This member element dscr_inherit indicates that the process
|
|
|
|
* has explicitly attempted and changed the DSCR register value
|
|
|
|
* for itself. Hence kernel wont use the default CPU DSCR value
|
|
|
|
* contained in the PACA structure anymore during process context
|
|
|
|
* switch. Once this variable is set, this behaviour will also be
|
|
|
|
* inherited to all the children of this process from that point
|
|
|
|
* onwards.
|
|
|
|
*/
|
2011-03-02 22:18:48 +07:00
|
|
|
int dscr_inherit;
|
2017-11-08 09:23:53 +07:00
|
|
|
unsigned long tidr;
|
2011-03-02 22:18:48 +07:00
|
|
|
#endif
|
2013-02-07 22:46:58 +07:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_64
|
|
|
|
unsigned long tar;
|
2013-05-01 03:17:04 +07:00
|
|
|
unsigned long ebbrr;
|
|
|
|
unsigned long ebbhr;
|
|
|
|
unsigned long bescr;
|
2013-05-21 23:31:12 +07:00
|
|
|
unsigned long siar;
|
|
|
|
unsigned long sdar;
|
|
|
|
unsigned long sier;
|
|
|
|
unsigned long mmcr2;
|
2013-06-28 15:15:16 +07:00
|
|
|
unsigned mmcr0;
|
2017-11-08 09:23:54 +07:00
|
|
|
|
2013-06-28 15:15:16 +07:00
|
|
|
unsigned used_ebb;
|
2017-11-08 09:23:54 +07:00
|
|
|
unsigned int used_vas;
|
2013-02-07 22:46:58 +07:00
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ARCH_MIN_TASKALIGN 16
|
|
|
|
|
|
|
|
#define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack)
|
2019-01-31 17:09:00 +07:00
|
|
|
#define INIT_SP_LIMIT ((unsigned long)&init_stack)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-10-28 10:50:21 +07:00
|
|
|
#ifdef CONFIG_SPE
|
powerpc: fix exception clearing in e500 SPE float emulation
The e500 SPE floating-point emulation code clears existing exceptions
(__FPU_FPSCR &= ~FP_EX_MASK;) before ORing in the exceptions from the
emulated operation. However, these exception bits are the "sticky",
cumulative exception bits, and should only be cleared by the user
program setting SPEFSCR, not implicitly by any floating-point
instruction (whether executed purely by the hardware or emulated).
The spurious clearing of these bits shows up as missing exceptions in
glibc testing.
Fixing this, however, is not as simple as just not clearing the bits,
because while the bits may be from previous floating-point operations
(in which case they should not be cleared), the processor can also set
the sticky bits itself before the interrupt for an exception occurs,
and this can happen in cases when IEEE 754 semantics are that the
sticky bit should not be set. Specifically, the "invalid" sticky bit
is set in various cases with non-finite operands, where IEEE 754
semantics do not involve raising such an exception, and the
"underflow" sticky bit is set in cases of exact underflow, whereas
IEEE 754 semantics are that this flag is set only for inexact
underflow. Thus, for correct emulation the kernel needs to know the
setting of these two sticky bits before the instruction being
emulated.
When a floating-point operation raises an exception, the kernel can
note the state of the sticky bits immediately afterwards. Some
<fenv.h> functions that affect the state of these bits, such as
fesetenv and feholdexcept, need to use prctl with PR_GET_FPEXC and
PR_SET_FPEXC anyway, and so it is natural to record the state of those
bits during that call into the kernel and so avoid any need for a
separate call into the kernel to inform it of a change to those bits.
Thus, the interface I chose to use (in this patch and the glibc port)
is that one of those prctl calls must be made after any userspace
change to those sticky bits, other than through a floating-point
operation that traps into the kernel anyway. feclearexcept and
fesetexceptflag duly make those calls, which would not be required
were it not for this issue.
The previous EGLIBC port, and the uClibc code copied from it, is
fundamentally broken as regards any use of prctl for floating-point
exceptions because it didn't use the PR_FP_EXC_SW_ENABLE bit in its
prctl calls (and did various worse things, such as passing a pointer
when prctl expected an integer). If you avoid anything where prctl is
used, the clearing of sticky bits still means it will never give
anything approximating correct exception semantics with existing
kernels. I don't believe the patch makes things any worse for
existing code that doesn't try to inform the kernel of changes to
sticky bits - such code may get incorrect exceptions in some cases,
but it would have done so anyway in other cases.
Signed-off-by: Joseph Myers <joseph@codesourcery.com>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2013-12-11 06:07:45 +07:00
|
|
|
#define SPEFSCR_INIT \
|
|
|
|
.spefscr = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE, \
|
|
|
|
.spefscr_last = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE,
|
2008-10-28 10:50:21 +07:00
|
|
|
#else
|
|
|
|
#define SPEFSCR_INIT
|
|
|
|
#endif
|
2005-10-10 11:19:43 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_PPC32
|
2005-04-17 05:20:36 +07:00
|
|
|
#define INIT_THREAD { \
|
|
|
|
.ksp = INIT_SP, \
|
2008-04-28 13:21:22 +07:00
|
|
|
.ksp_limit = INIT_SP_LIMIT, \
|
2018-05-14 20:03:15 +07:00
|
|
|
.addr_limit = KERNEL_DS, \
|
2005-04-17 05:20:36 +07:00
|
|
|
.pgdir = swapper_pg_dir, \
|
|
|
|
.fpexc_mode = MSR_FE0 | MSR_FE1, \
|
2008-10-28 10:50:21 +07:00
|
|
|
SPEFSCR_INIT \
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2005-10-10 11:19:43 +07:00
|
|
|
#else
|
|
|
|
#define INIT_THREAD { \
|
|
|
|
.ksp = INIT_SP, \
|
|
|
|
.regs = (struct pt_regs *)INIT_SP - 1, /* XXX bogus, I think */ \
|
2018-05-14 20:03:15 +07:00
|
|
|
.addr_limit = KERNEL_DS, \
|
[POWERPC] disable floating point exceptions for init
Floating point exceptions should not be enabled by default,
as this setting impacts the performance on some CPUs, in
particular the Cell BE. Since the bits are inherited from
parent processes, the place to change the default is the
thread struct used for init.
glibc sets this up correctly per thread in its fesetenv
function, so user space should not be impacted by this
setting. None of the other common libc implementations
(uClibc, dietlibc, newlib, klibc) has support for fp
exceptions, so they are unlikely to be hit by this either.
There is a small risk that somebody wrote their own
application that manually sets the fpscr bits instead
of calling fesetenv, without changing the MSR bits as well.
Those programs will break with this change.
It probably makes sense to change glibc in the future
to be more clever about FE bits, so that when running
on a CPU where this is expensive, it disables exceptions
ASAP, while it keeps them enabled on CPUs where running
with exceptions on is cheaper than changing the state
often.
Signed-off-by: Arnd Bergmann <arnd.bergmann@de.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2006-06-20 07:30:33 +07:00
|
|
|
.fpexc_mode = 0, \
|
2016-06-09 09:31:08 +07:00
|
|
|
.fscr = FSCR_TAR | FSCR_EBB \
|
2005-10-10 11:19:43 +07:00
|
|
|
}
|
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-07-07 21:22:27 +07:00
|
|
|
#define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.regs)
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned long get_wchan(struct task_struct *p);
|
|
|
|
|
2005-10-10 11:19:43 +07:00
|
|
|
#define KSTK_EIP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
|
|
|
|
#define KSTK_ESP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->gpr[1]: 0)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Get/set floating-point exception mode */
|
2005-10-10 11:19:43 +07:00
|
|
|
#define GET_FPEXC_CTL(tsk, adr) get_fpexc_mode((tsk), (adr))
|
|
|
|
#define SET_FPEXC_CTL(tsk, val) set_fpexc_mode((tsk), (val))
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
extern int get_fpexc_mode(struct task_struct *tsk, unsigned long adr);
|
|
|
|
extern int set_fpexc_mode(struct task_struct *tsk, unsigned int val);
|
|
|
|
|
2006-06-07 13:14:40 +07:00
|
|
|
#define GET_ENDIAN(tsk, adr) get_endian((tsk), (adr))
|
|
|
|
#define SET_ENDIAN(tsk, val) set_endian((tsk), (val))
|
|
|
|
|
|
|
|
extern int get_endian(struct task_struct *tsk, unsigned long adr);
|
|
|
|
extern int set_endian(struct task_struct *tsk, unsigned int val);
|
|
|
|
|
2006-06-07 13:15:39 +07:00
|
|
|
#define GET_UNALIGN_CTL(tsk, adr) get_unalign_ctl((tsk), (adr))
|
|
|
|
#define SET_UNALIGN_CTL(tsk, val) set_unalign_ctl((tsk), (val))
|
|
|
|
|
|
|
|
extern int get_unalign_ctl(struct task_struct *tsk, unsigned long adr);
|
|
|
|
extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);
|
|
|
|
|
2013-09-10 17:21:10 +07:00
|
|
|
extern void load_fp_state(struct thread_fp_state *fp);
|
|
|
|
extern void store_fp_state(struct thread_fp_state *fp);
|
|
|
|
extern void load_vr_state(struct thread_vr_state *vr);
|
|
|
|
extern void store_vr_state(struct thread_vr_state *vr);
|
|
|
|
|
2005-10-10 11:19:43 +07:00
|
|
|
static inline unsigned int __unpack_fe01(unsigned long msr_bits)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
|
|
|
|
}
|
|
|
|
|
2005-10-10 11:19:43 +07:00
|
|
|
static inline unsigned long __pack_fe01(unsigned int fpmode)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
|
|
|
|
}
|
|
|
|
|
2005-10-10 11:19:43 +07:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
#define cpu_relax() do { HMT_low(); HMT_medium(); barrier(); } while (0)
|
2017-06-06 20:08:31 +07:00
|
|
|
|
|
|
|
#define spin_begin() HMT_low()
|
|
|
|
|
|
|
|
#define spin_cpu_relax() barrier()
|
|
|
|
|
|
|
|
#define spin_end() HMT_medium()
|
|
|
|
|
|
|
|
#define spin_until_cond(cond) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(!(cond))) { \
|
|
|
|
spin_begin(); \
|
|
|
|
do { \
|
|
|
|
spin_cpu_relax(); \
|
|
|
|
} while (!(cond)); \
|
|
|
|
spin_end(); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2005-10-10 11:19:43 +07:00
|
|
|
#else
|
2005-04-17 05:20:36 +07:00
|
|
|
#define cpu_relax() barrier()
|
2005-10-10 11:19:43 +07:00
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-03-27 07:46:18 +07:00
|
|
|
/* Check that a certain kernel stack pointer is valid in task_struct p */
|
|
|
|
int validate_sp(unsigned long sp, struct task_struct *p,
|
|
|
|
unsigned long nbytes);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Prefetch macros.
|
|
|
|
*/
|
|
|
|
#define ARCH_HAS_PREFETCH
|
|
|
|
#define ARCH_HAS_PREFETCHW
|
|
|
|
#define ARCH_HAS_SPINLOCK_PREFETCH
|
|
|
|
|
2005-10-10 11:19:43 +07:00
|
|
|
static inline void prefetch(const void *x)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-10-10 11:19:43 +07:00
|
|
|
if (unlikely(!x))
|
|
|
|
return;
|
|
|
|
|
|
|
|
__asm__ __volatile__ ("dcbt 0,%0" : : "r" (x));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2005-10-10 11:19:43 +07:00
|
|
|
static inline void prefetchw(const void *x)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-10-10 11:19:43 +07:00
|
|
|
if (unlikely(!x))
|
|
|
|
return;
|
|
|
|
|
|
|
|
__asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define spin_lock_prefetch(x) prefetchw(x)
|
|
|
|
|
2005-10-10 11:19:43 +07:00
|
|
|
#define HAVE_ARCH_PICK_MMAP_LAYOUT
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-03-25 13:23:59 +07:00
|
|
|
#ifdef CONFIG_PPC64
|
2013-05-27 01:09:41 +07:00
|
|
|
static inline unsigned long get_clean_sp(unsigned long sp, int is_32)
|
2009-03-25 13:23:59 +07:00
|
|
|
{
|
|
|
|
if (is_32)
|
2013-05-27 01:09:41 +07:00
|
|
|
return sp & 0x0ffffffffUL;
|
2009-03-25 13:23:59 +07:00
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
#else
|
2013-05-27 01:09:41 +07:00
|
|
|
static inline unsigned long get_clean_sp(unsigned long sp, int is_32)
|
2009-03-25 13:23:59 +07:00
|
|
|
{
|
2013-05-27 01:09:41 +07:00
|
|
|
return sp;
|
2009-03-25 13:23:59 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 21:30:52 +07:00
|
|
|
/* asm stubs */
|
|
|
|
extern unsigned long isa300_idle_stop_noloss(unsigned long psscr_val);
|
|
|
|
extern unsigned long isa300_idle_stop_mayloss(unsigned long psscr_val);
|
|
|
|
extern unsigned long isa206_idle_insn_mayloss(unsigned long type);
|
|
|
|
|
2011-11-30 09:47:03 +07:00
|
|
|
extern unsigned long cpuidle_disable;
|
2011-11-30 09:46:31 +07:00
|
|
|
enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};
|
|
|
|
|
2012-03-29 00:30:02 +07:00
|
|
|
extern int powersave_nap; /* set if nap mode can be used in idle loop */
|
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 21:30:52 +07:00
|
|
|
|
2017-06-13 20:05:45 +07:00
|
|
|
extern void power7_idle_type(unsigned long type);
|
|
|
|
extern void power9_idle_type(unsigned long stop_psscr_val,
|
|
|
|
unsigned long stop_psscr_mask);
|
2016-07-08 13:20:49 +07:00
|
|
|
|
2012-03-29 00:30:02 +07:00
|
|
|
extern void flush_instruction_cache(void);
|
|
|
|
extern void hard_reset_now(void);
|
|
|
|
extern void poweroff_now(void);
|
|
|
|
extern int fix_alignment(struct pt_regs *);
|
|
|
|
extern void cvt_fd(float *from, double *to);
|
|
|
|
extern void cvt_df(double *from, float *to);
|
|
|
|
extern void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val);
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
/*
|
|
|
|
* We handle most unaligned accesses in hardware. On the other hand
|
|
|
|
* unaligned DMA can be very expensive on some ppc64 IO chips (it does
|
|
|
|
* powers of 2 writes until it reaches sufficient alignment).
|
|
|
|
*
|
|
|
|
* Based on this we disable the IP header alignment in network drivers.
|
|
|
|
*/
|
|
|
|
#define NET_IP_ALIGN 0
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif /* __KERNEL__ */
|
2005-10-10 11:19:43 +07:00
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* _ASM_POWERPC_PROCESSOR_H */
|