2019-06-03 07:44:50 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2012-03-05 11:49:27 +00:00
|
|
|
/*
|
|
|
|
* Based on arch/arm/include/asm/traps.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_TRAP_H
|
|
|
|
#define __ASM_TRAP_H
|
|
|
|
|
2014-11-18 11:41:22 +00:00
|
|
|
#include <linux/list.h>
|
2018-01-15 19:38:57 +00:00
|
|
|
#include <asm/esr.h>
|
2023-09-22 12:25:07 +01:00
|
|
|
#include <asm/ptrace.h>
|
2016-08-24 18:27:28 +01:00
|
|
|
#include <asm/sections.h>
|
2014-11-18 11:41:22 +00:00
|
|
|
|
arm64: armv8_deprecated: rework deprected instruction handling
Support for deprecated instructions can be enabled or disabled at
runtime. To handle this, the code in armv8_deprecated.c registers and
unregisters undef_hooks, and makes cross CPU calls to configure HW
support. This is rather complicated, and the synchronization required to
make this safe ends up serializing the handling of instructions which
have been trapped.
This patch simplifies the deprecated instruction handling by removing
the dynamic registration and unregistration, and changing the trap
handling code to determine whether a handler should be invoked. This
removes the need for dynamic list management, and simplifies the locking
requirements, making it possible to handle trapped instructions entirely
in parallel.
Where changing the emulation state requires a cross-call, this is
serialized by locally disabling interrupts, ensuring that the CPU is not
left in an inconsistent state.
To simplify sysctl management, each insn_emulation is given a separate
sysctl table, permitting these to be registered separately. The core
sysctl code will iterate over all of these when walking sysfs.
I've tested this with userspace programs which use each of the
deprecated instructions, and I've concurrently modified the support
level for each of the features back-and-forth between HW and emulated to
check that there are no spurious SIGILLs sent to userspace when the
support level is changed.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Joey Gouly <joey.gouly@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20221019144123.612388-10-mark.rutland@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2022-10-19 15:41:23 +01:00
|
|
|
#ifdef CONFIG_ARMV8_DEPRECATED
|
|
|
|
bool try_emulate_armv8_deprecated(struct pt_regs *regs, u32 insn);
|
|
|
|
#else
|
|
|
|
static inline bool
|
|
|
|
try_emulate_armv8_deprecated(struct pt_regs *regs, u32 insn)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ARMV8_DEPRECATED */
|
2014-11-18 11:41:22 +00:00
|
|
|
|
arm64: Treat ESR_ELx as a 64-bit register
In the initial release of the ARM Architecture Reference Manual for
ARMv8-A, the ESR_ELx registers were defined as 32-bit registers. This
changed in 2018 with version D.a (ARM DDI 0487D.a) of the architecture,
when they became 64-bit registers, with bits [63:32] defined as RES0. In
version G.a, a new field was added to ESR_ELx, ISS2, which covers bits
[36:32]. This field is used when the Armv8.7 extension FEAT_LS64 is
implemented.
As a result of the evolution of the register width, Linux stores it as
both a 64-bit value and a 32-bit value, which hasn't affected correctness
so far as Linux only uses the lower 32 bits of the register.
Make the register type consistent and always treat it as 64-bit wide. The
register is redefined as an "unsigned long", which is an unsigned
double-word (64-bit quantity) for the LP64 machine (aapcs64 [1], Table 1,
page 14). The type was chosen because "unsigned int" is the most frequent
type for ESR_ELx and because FAR_ELx, which is used together with ESR_ELx
in exception handling, is also declared as "unsigned long". The 64-bit type
also makes adding support for architectural features that use fields above
bit 31 easier in the future.
The KVM hypervisor will receive a similar update in a subsequent patch.
[1] https://github.com/ARM-software/abi-aa/releases/download/2021Q3/aapcs64.pdf
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220425114444.368693-4-alexandru.elisei@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2022-04-25 12:44:42 +01:00
|
|
|
void force_signal_inject(int signal, int code, unsigned long address, unsigned long err);
|
2018-02-20 14:16:29 +00:00
|
|
|
void arm64_notify_segfault(unsigned long addr);
|
2020-11-20 12:33:46 -08:00
|
|
|
void arm64_force_sig_fault(int signo, int code, unsigned long far, const char *str);
|
2024-08-22 16:10:59 +01:00
|
|
|
void arm64_force_sig_fault_pkey(unsigned long far, const char *str, int pkey);
|
2020-11-20 12:33:46 -08:00
|
|
|
void arm64_force_sig_mceerr(int code, unsigned long far, short lsb, const char *str);
|
|
|
|
void arm64_force_sig_ptrace_errno_trap(int errno, unsigned long far, const char *str);
|
2016-06-28 18:07:31 +01:00
|
|
|
|
2025-07-07 12:40:59 +01:00
|
|
|
int bug_brk_handler(struct pt_regs *regs, unsigned long esr);
|
|
|
|
int cfi_brk_handler(struct pt_regs *regs, unsigned long esr);
|
|
|
|
int reserved_fault_brk_handler(struct pt_regs *regs, unsigned long esr);
|
|
|
|
int kasan_brk_handler(struct pt_regs *regs, unsigned long esr);
|
|
|
|
int ubsan_brk_handler(struct pt_regs *regs, unsigned long esr);
|
|
|
|
|
2023-05-16 18:06:41 +02:00
|
|
|
int early_brk64(unsigned long addr, unsigned long esr, struct pt_regs *regs);
|
|
|
|
|
2017-10-25 10:04:33 +01:00
|
|
|
/*
|
|
|
|
* Move regs->pc to next instruction and do necessary setup before it
|
|
|
|
* is executed.
|
|
|
|
*/
|
|
|
|
void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size);
|
|
|
|
|
2015-08-12 15:16:19 +01:00
|
|
|
static inline int __in_irqentry_text(unsigned long ptr)
|
|
|
|
{
|
|
|
|
return ptr >= (unsigned long)&__irqentry_text_start &&
|
|
|
|
ptr < (unsigned long)&__irqentry_text_end;
|
|
|
|
}
|
|
|
|
|
arm64: unwind: reference pt_regs via embedded stack frame
As it turns out, the unwind code is slightly broken, and probably has
been for a while. The problem is in the dumping of the exception stack,
which is intended to dump the contents of the pt_regs struct at each
level in the call stack where an exception was taken and routed to a
routine marked as __exception (which means its stack frame is right
below the pt_regs struct on the stack).
'Right below the pt_regs struct' is ill defined, though: the unwind
code assigns 'frame pointer + 0x10' to the .sp member of the stackframe
struct at each level, and dump_backtrace() happily dereferences that as
the pt_regs pointer when encountering an __exception routine. However,
the actual size of the stack frame created by this routine (which could
be one of many __exception routines we have in the kernel) is not known,
and so frame.sp is pretty useless to figure out where struct pt_regs
really is.
So it seems the only way to ensure that we can find our struct pt_regs
when walking the stack frames is to put it at a known fixed offset of
the stack frame pointer that is passed to such __exception routines.
The simplest way to do that is to put it inside pt_regs itself, which is
the main change implemented by this patch. As a bonus, doing this allows
us to get rid of a fair amount of cruft related to walking from one stack
to the other, which is especially nice since we intend to introduce yet
another stack for overflow handling once we add support for vmapped
stacks. It also fixes an inconsistency where we only add a stack frame
pointing to ELR_EL1 if we are executing from the IRQ stack but not when
we are executing from the task stack.
To consistly identify exceptions regs even in the presence of exceptions
taken from entry code, we must check whether the next frame was created
by entry text, rather than whether the current frame was crated by
exception text.
To avoid backtracing using PCs that fall in the idmap, or are controlled
by userspace, we must explcitly zero the FP and LR in startup paths, and
must ensure that the frame embedded in pt_regs is zeroed upon entry from
EL0. To avoid these NULL entries showin in the backtrace, unwind_frame()
is updated to avoid them.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
[Mark: compare current frame against .entry.text, avoid bogus PCs]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
2017-07-22 18:45:33 +01:00
|
|
|
static inline int in_entry_text(unsigned long ptr)
|
|
|
|
{
|
|
|
|
return ptr >= (unsigned long)&__entry_text_start &&
|
|
|
|
ptr < (unsigned long)&__entry_text_end;
|
|
|
|
}
|
2018-01-15 19:38:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CPUs with the RAS extensions have an Implementation-Defined-Syndrome bit
|
|
|
|
* to indicate whether this ESR has a RAS encoding. CPUs without this feature
|
|
|
|
* have a ISS-Valid bit in the same position.
|
|
|
|
* If this bit is set, we know its not a RAS SError.
|
|
|
|
* If its clear, we need to know if the CPU supports RAS. Uncategorized RAS
|
|
|
|
* errors share the same encoding as an all-zeros encoding from a CPU that
|
|
|
|
* doesn't support RAS.
|
|
|
|
*/
|
arm64: Treat ESR_ELx as a 64-bit register
In the initial release of the ARM Architecture Reference Manual for
ARMv8-A, the ESR_ELx registers were defined as 32-bit registers. This
changed in 2018 with version D.a (ARM DDI 0487D.a) of the architecture,
when they became 64-bit registers, with bits [63:32] defined as RES0. In
version G.a, a new field was added to ESR_ELx, ISS2, which covers bits
[36:32]. This field is used when the Armv8.7 extension FEAT_LS64 is
implemented.
As a result of the evolution of the register width, Linux stores it as
both a 64-bit value and a 32-bit value, which hasn't affected correctness
so far as Linux only uses the lower 32 bits of the register.
Make the register type consistent and always treat it as 64-bit wide. The
register is redefined as an "unsigned long", which is an unsigned
double-word (64-bit quantity) for the LP64 machine (aapcs64 [1], Table 1,
page 14). The type was chosen because "unsigned int" is the most frequent
type for ESR_ELx and because FAR_ELx, which is used together with ESR_ELx
in exception handling, is also declared as "unsigned long". The 64-bit type
also makes adding support for architectural features that use fields above
bit 31 easier in the future.
The KVM hypervisor will receive a similar update in a subsequent patch.
[1] https://github.com/ARM-software/abi-aa/releases/download/2021Q3/aapcs64.pdf
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220425114444.368693-4-alexandru.elisei@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2022-04-25 12:44:42 +01:00
|
|
|
static inline bool arm64_is_ras_serror(unsigned long esr)
|
2018-01-15 19:38:57 +00:00
|
|
|
{
|
|
|
|
WARN_ON(preemptible());
|
|
|
|
|
|
|
|
if (esr & ESR_ELx_IDS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (this_cpu_has_cap(ARM64_HAS_RAS_EXTN))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the AET bits from a RAS SError's ESR.
|
|
|
|
*
|
|
|
|
* It is implementation defined whether Uncategorized errors are containable.
|
|
|
|
* We treat them as Uncontainable.
|
|
|
|
* Non-RAS SError's are reported as Uncontained/Uncategorized.
|
|
|
|
*/
|
arm64: Treat ESR_ELx as a 64-bit register
In the initial release of the ARM Architecture Reference Manual for
ARMv8-A, the ESR_ELx registers were defined as 32-bit registers. This
changed in 2018 with version D.a (ARM DDI 0487D.a) of the architecture,
when they became 64-bit registers, with bits [63:32] defined as RES0. In
version G.a, a new field was added to ESR_ELx, ISS2, which covers bits
[36:32]. This field is used when the Armv8.7 extension FEAT_LS64 is
implemented.
As a result of the evolution of the register width, Linux stores it as
both a 64-bit value and a 32-bit value, which hasn't affected correctness
so far as Linux only uses the lower 32 bits of the register.
Make the register type consistent and always treat it as 64-bit wide. The
register is redefined as an "unsigned long", which is an unsigned
double-word (64-bit quantity) for the LP64 machine (aapcs64 [1], Table 1,
page 14). The type was chosen because "unsigned int" is the most frequent
type for ESR_ELx and because FAR_ELx, which is used together with ESR_ELx
in exception handling, is also declared as "unsigned long". The 64-bit type
also makes adding support for architectural features that use fields above
bit 31 easier in the future.
The KVM hypervisor will receive a similar update in a subsequent patch.
[1] https://github.com/ARM-software/abi-aa/releases/download/2021Q3/aapcs64.pdf
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220425114444.368693-4-alexandru.elisei@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2022-04-25 12:44:42 +01:00
|
|
|
static inline unsigned long arm64_ras_serror_get_severity(unsigned long esr)
|
2018-01-15 19:38:57 +00:00
|
|
|
{
|
arm64: Treat ESR_ELx as a 64-bit register
In the initial release of the ARM Architecture Reference Manual for
ARMv8-A, the ESR_ELx registers were defined as 32-bit registers. This
changed in 2018 with version D.a (ARM DDI 0487D.a) of the architecture,
when they became 64-bit registers, with bits [63:32] defined as RES0. In
version G.a, a new field was added to ESR_ELx, ISS2, which covers bits
[36:32]. This field is used when the Armv8.7 extension FEAT_LS64 is
implemented.
As a result of the evolution of the register width, Linux stores it as
both a 64-bit value and a 32-bit value, which hasn't affected correctness
so far as Linux only uses the lower 32 bits of the register.
Make the register type consistent and always treat it as 64-bit wide. The
register is redefined as an "unsigned long", which is an unsigned
double-word (64-bit quantity) for the LP64 machine (aapcs64 [1], Table 1,
page 14). The type was chosen because "unsigned int" is the most frequent
type for ESR_ELx and because FAR_ELx, which is used together with ESR_ELx
in exception handling, is also declared as "unsigned long". The 64-bit type
also makes adding support for architectural features that use fields above
bit 31 easier in the future.
The KVM hypervisor will receive a similar update in a subsequent patch.
[1] https://github.com/ARM-software/abi-aa/releases/download/2021Q3/aapcs64.pdf
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220425114444.368693-4-alexandru.elisei@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2022-04-25 12:44:42 +01:00
|
|
|
unsigned long aet = esr & ESR_ELx_AET;
|
2018-01-15 19:38:57 +00:00
|
|
|
|
|
|
|
if (!arm64_is_ras_serror(esr)) {
|
|
|
|
/* Not a RAS error, we can't interpret the ESR. */
|
|
|
|
return ESR_ELx_AET_UC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AET is RES0 if 'the value returned in the DFSC field is not
|
|
|
|
* [ESR_ELx_FSC_SERROR]'
|
|
|
|
*/
|
|
|
|
if ((esr & ESR_ELx_FSC) != ESR_ELx_FSC_SERROR) {
|
|
|
|
/* No severity information : Uncategorized */
|
|
|
|
return ESR_ELx_AET_UC;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aet;
|
|
|
|
}
|
|
|
|
|
arm64: Treat ESR_ELx as a 64-bit register
In the initial release of the ARM Architecture Reference Manual for
ARMv8-A, the ESR_ELx registers were defined as 32-bit registers. This
changed in 2018 with version D.a (ARM DDI 0487D.a) of the architecture,
when they became 64-bit registers, with bits [63:32] defined as RES0. In
version G.a, a new field was added to ESR_ELx, ISS2, which covers bits
[36:32]. This field is used when the Armv8.7 extension FEAT_LS64 is
implemented.
As a result of the evolution of the register width, Linux stores it as
both a 64-bit value and a 32-bit value, which hasn't affected correctness
so far as Linux only uses the lower 32 bits of the register.
Make the register type consistent and always treat it as 64-bit wide. The
register is redefined as an "unsigned long", which is an unsigned
double-word (64-bit quantity) for the LP64 machine (aapcs64 [1], Table 1,
page 14). The type was chosen because "unsigned int" is the most frequent
type for ESR_ELx and because FAR_ELx, which is used together with ESR_ELx
in exception handling, is also declared as "unsigned long". The 64-bit type
also makes adding support for architectural features that use fields above
bit 31 easier in the future.
The KVM hypervisor will receive a similar update in a subsequent patch.
[1] https://github.com/ARM-software/abi-aa/releases/download/2021Q3/aapcs64.pdf
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220425114444.368693-4-alexandru.elisei@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2022-04-25 12:44:42 +01:00
|
|
|
bool arm64_is_fatal_ras_serror(struct pt_regs *regs, unsigned long esr);
|
|
|
|
void __noreturn arm64_serror_panic(struct pt_regs *regs, unsigned long esr);
|
2023-09-22 12:25:07 +01:00
|
|
|
|
|
|
|
static inline void arm64_mops_reset_regs(struct user_pt_regs *regs, unsigned long esr)
|
|
|
|
{
|
|
|
|
bool wrong_option = esr & ESR_ELx_MOPS_ISS_WRONG_OPTION;
|
|
|
|
bool option_a = esr & ESR_ELx_MOPS_ISS_OPTION_A;
|
|
|
|
int dstreg = ESR_ELx_MOPS_ISS_DESTREG(esr);
|
|
|
|
int srcreg = ESR_ELx_MOPS_ISS_SRCREG(esr);
|
|
|
|
int sizereg = ESR_ELx_MOPS_ISS_SIZEREG(esr);
|
2025-03-26 11:04:47 +00:00
|
|
|
unsigned long dst, size;
|
2023-09-22 12:25:07 +01:00
|
|
|
|
|
|
|
dst = regs->regs[dstreg];
|
|
|
|
size = regs->regs[sizereg];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the registers back in the original format suitable for a
|
|
|
|
* prologue instruction, using the generic return routine from the
|
|
|
|
* Arm ARM (DDI 0487I.a) rules CNTMJ and MWFQH.
|
|
|
|
*/
|
|
|
|
if (esr & ESR_ELx_MOPS_ISS_MEM_INST) {
|
|
|
|
/* SET* instruction */
|
|
|
|
if (option_a ^ wrong_option) {
|
|
|
|
/* Format is from Option A; forward set */
|
|
|
|
regs->regs[dstreg] = dst + size;
|
|
|
|
regs->regs[sizereg] = -size;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* CPY* instruction */
|
2025-03-26 11:04:47 +00:00
|
|
|
unsigned long src = regs->regs[srcreg];
|
2023-09-22 12:25:07 +01:00
|
|
|
if (!(option_a ^ wrong_option)) {
|
|
|
|
/* Format is from Option B */
|
|
|
|
if (regs->pstate & PSR_N_BIT) {
|
|
|
|
/* Backward copy */
|
|
|
|
regs->regs[dstreg] = dst - size;
|
|
|
|
regs->regs[srcreg] = src - size;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Format is from Option A */
|
|
|
|
if (size & BIT(63)) {
|
|
|
|
/* Forward copy */
|
|
|
|
regs->regs[dstreg] = dst + size;
|
|
|
|
regs->regs[srcreg] = src + size;
|
|
|
|
regs->regs[sizereg] = -size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esr & ESR_ELx_MOPS_ISS_FROM_EPILOGUE)
|
|
|
|
regs->pc -= 8;
|
|
|
|
else
|
|
|
|
regs->pc -= 4;
|
|
|
|
}
|
2012-03-05 11:49:27 +00:00
|
|
|
#endif
|