2019-06-04 10:11:33 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-11-18 11:41:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 ARM Limited
|
|
|
|
*/
|
|
|
|
|
2014-11-18 11:41:26 +00:00
|
|
|
#include <linux/cpu.h>
|
2014-11-18 11:41:24 +00:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/list.h>
|
2014-11-18 11:41:25 +00:00
|
|
|
#include <linux/perf_event.h>
|
|
|
|
#include <linux/sched.h>
|
2014-11-18 11:41:24 +00:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/sysctl.h>
|
2018-04-13 15:44:35 +01:00
|
|
|
#include <linux/uaccess.h>
|
2014-11-18 11:41:24 +00:00
|
|
|
|
2015-07-22 19:05:54 +01:00
|
|
|
#include <asm/cpufeature.h>
|
2014-11-18 11:41:25 +00:00
|
|
|
#include <asm/insn.h>
|
2015-07-21 13:23:27 +01:00
|
|
|
#include <asm/sysreg.h>
|
2014-11-18 11:41:25 +00:00
|
|
|
#include <asm/system_misc.h>
|
2014-11-18 11:41:24 +00:00
|
|
|
#include <asm/traps.h>
|
|
|
|
|
2014-11-18 11:41:27 +00:00
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include "trace-events-emulation.h"
|
|
|
|
|
2014-11-18 11:41:24 +00:00
|
|
|
/*
|
|
|
|
* The runtime support for deprecated instruction support can be in one of
|
|
|
|
* following three states -
|
|
|
|
*
|
|
|
|
* 0 = undef
|
|
|
|
* 1 = emulate (software emulation)
|
|
|
|
* 2 = hw (supported in hardware)
|
|
|
|
*/
|
|
|
|
enum insn_emulation_mode {
|
|
|
|
INSN_UNDEF,
|
|
|
|
INSN_EMULATE,
|
|
|
|
INSN_HW,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum legacy_insn_status {
|
|
|
|
INSN_DEPRECATED,
|
|
|
|
INSN_OBSOLETE,
|
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
|
|
|
INSN_UNAVAILABLE,
|
2014-11-18 11:41:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct insn_emulation {
|
2022-10-19 15:41:20 +01:00
|
|
|
const char *name;
|
|
|
|
enum legacy_insn_status status;
|
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
|
|
|
bool (*try_emulate)(struct pt_regs *regs,
|
|
|
|
u32 insn);
|
2022-10-19 15:41:20 +01:00
|
|
|
int (*set_hw_mode)(bool enable);
|
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
|
|
|
|
2014-11-18 11:41:24 +00:00
|
|
|
int current_mode;
|
|
|
|
int min;
|
|
|
|
int max;
|
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
|
|
|
|
2023-10-02 13:30:37 +02:00
|
|
|
/* sysctl for this emulation */
|
|
|
|
struct ctl_table sysctl;
|
2014-11-18 11:41:24 +00:00
|
|
|
};
|
|
|
|
|
2022-10-19 15:41:22 +01:00
|
|
|
#define ARM_OPCODE_CONDTEST_FAIL 0
|
|
|
|
#define ARM_OPCODE_CONDTEST_PASS 1
|
|
|
|
#define ARM_OPCODE_CONDTEST_UNCOND 2
|
|
|
|
|
|
|
|
#define ARM_OPCODE_CONDITION_UNCOND 0xf
|
|
|
|
|
2022-11-24 02:24:29 +00:00
|
|
|
static unsigned int __maybe_unused aarch32_check_condition(u32 opcode, u32 psr)
|
2022-10-19 15:41:22 +01:00
|
|
|
{
|
|
|
|
u32 cc_bits = opcode >> 28;
|
|
|
|
|
|
|
|
if (cc_bits != ARM_OPCODE_CONDITION_UNCOND) {
|
|
|
|
if ((*aarch32_opcode_cond_checks[cc_bits])(psr))
|
|
|
|
return ARM_OPCODE_CONDTEST_PASS;
|
|
|
|
else
|
|
|
|
return ARM_OPCODE_CONDTEST_FAIL;
|
|
|
|
}
|
|
|
|
return ARM_OPCODE_CONDTEST_UNCOND;
|
|
|
|
}
|
|
|
|
|
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_SWP_EMULATION
|
2014-11-18 11:41:25 +00:00
|
|
|
/*
|
|
|
|
* Implement emulation of the SWP/SWPB instructions using load-exclusive and
|
|
|
|
* store-exclusive.
|
|
|
|
*
|
|
|
|
* Syntax of SWP{B} instruction: SWP{B}<c> <Rt>, <Rt2>, [<Rn>]
|
|
|
|
* Where: Rt = destination
|
|
|
|
* Rt2 = source
|
|
|
|
* Rn = address
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Error-checking SWP macros implemented using ldxr{b}/stxr{b}
|
|
|
|
*/
|
2016-07-04 16:59:43 +01:00
|
|
|
|
|
|
|
/* Arbitrary constant to ensure forward-progress of the LL/SC loop */
|
|
|
|
#define __SWP_LL_SC_LOOPS 4
|
|
|
|
|
|
|
|
#define __user_swpX_asm(data, addr, res, temp, temp2, B) \
|
2016-07-01 14:58:21 +01:00
|
|
|
do { \
|
arm64: uaccess: rename privileged uaccess routines
We currently have many uaccess_*{enable,disable}*() variants, which
subsequent patches will cut down as part of removing set_fs() and
friends. Once this simplification is made, most uaccess routines will
only need to ensure that the user page tables are mapped in TTBR0, as is
currently dealt with by uaccess_ttbr0_{enable,disable}().
The existing uaccess_{enable,disable}() routines ensure that user page
tables are mapped in TTBR0, and also disable PAN protections, which is
necessary to be able to use atomics on user memory, but also permit
unrelated privileged accesses to access user memory.
As preparatory step, let's rename uaccess_{enable,disable}() to
uaccess_{enable,disable}_privileged(), highlighting this caveat and
discouraging wider misuse. Subsequent patches can reuse the
uaccess_{enable,disable}() naming for the common case of ensuring the
user page tables are mapped in TTBR0.
There should be no functional change as a result of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20201202131558.39270-5-mark.rutland@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2020-12-02 13:15:50 +00:00
|
|
|
uaccess_enable_privileged(); \
|
2014-11-18 11:41:25 +00:00
|
|
|
__asm__ __volatile__( \
|
arm64: extable: add a dedicated uaccess handler
For inline assembly, we place exception fixups out-of-line in the
`.fixup` section such that these are out of the way of the fast path.
This has a few drawbacks:
* Since the fixup code is anonymous, backtraces will symbolize fixups as
offsets from the nearest prior symbol, currently
`__entry_tramp_text_end`. This is confusing, and painful to debug
without access to the relevant vmlinux.
* Since the exception handler adjusts the PC to execute the fixup, and
the fixup uses a direct branch back into the function it fixes,
backtraces of fixups miss the original function. This is confusing,
and violates requirements for RELIABLE_STACKTRACE (and therefore
LIVEPATCH).
* Inline assembly and associated fixups are generated from templates,
and we have many copies of logically identical fixups which only
differ in which specific registers are written to and which address is
branched to at the end of the fixup. This is potentially wasteful of
I-cache resources, and makes it hard to add additional logic to fixups
without significant bloat.
This patch address all three concerns for inline uaccess fixups by
adding a dedicated exception handler which updates registers in
exception context and subsequent returns back into the function which
faulted, removing the need for fixups specialized to each faulting
instruction.
Other than backtracing, there should be no functional change as a result
of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20211019160219.5202-12-mark.rutland@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2021-10-19 17:02:17 +01:00
|
|
|
" mov %w3, %w6\n" \
|
2016-07-04 16:59:43 +01:00
|
|
|
"0: ldxr"B" %w2, [%4]\n" \
|
|
|
|
"1: stxr"B" %w0, %w1, [%4]\n" \
|
2014-11-18 11:41:25 +00:00
|
|
|
" cbz %w0, 2f\n" \
|
2016-07-04 16:59:43 +01:00
|
|
|
" sub %w3, %w3, #1\n" \
|
|
|
|
" cbnz %w3, 0b\n" \
|
|
|
|
" mov %w0, %w5\n" \
|
2015-10-15 13:55:53 +01:00
|
|
|
" b 3f\n" \
|
2014-11-18 11:41:25 +00:00
|
|
|
"2:\n" \
|
2015-10-15 13:55:53 +01:00
|
|
|
" mov %w1, %w2\n" \
|
|
|
|
"3:\n" \
|
arm64: extable: add a dedicated uaccess handler
For inline assembly, we place exception fixups out-of-line in the
`.fixup` section such that these are out of the way of the fast path.
This has a few drawbacks:
* Since the fixup code is anonymous, backtraces will symbolize fixups as
offsets from the nearest prior symbol, currently
`__entry_tramp_text_end`. This is confusing, and painful to debug
without access to the relevant vmlinux.
* Since the exception handler adjusts the PC to execute the fixup, and
the fixup uses a direct branch back into the function it fixes,
backtraces of fixups miss the original function. This is confusing,
and violates requirements for RELIABLE_STACKTRACE (and therefore
LIVEPATCH).
* Inline assembly and associated fixups are generated from templates,
and we have many copies of logically identical fixups which only
differ in which specific registers are written to and which address is
branched to at the end of the fixup. This is potentially wasteful of
I-cache resources, and makes it hard to add additional logic to fixups
without significant bloat.
This patch address all three concerns for inline uaccess fixups by
adding a dedicated exception handler which updates registers in
exception context and subsequent returns back into the function which
faulted, removing the need for fixups specialized to each faulting
instruction.
Other than backtracing, there should be no functional change as a result
of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20211019160219.5202-12-mark.rutland@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2021-10-19 17:02:17 +01:00
|
|
|
_ASM_EXTABLE_UACCESS_ERR(0b, 3b, %w0) \
|
|
|
|
_ASM_EXTABLE_UACCESS_ERR(1b, 3b, %w0) \
|
2016-07-04 16:59:43 +01:00
|
|
|
: "=&r" (res), "+r" (data), "=&r" (temp), "=&r" (temp2) \
|
2017-05-03 16:09:36 +01:00
|
|
|
: "r" ((unsigned long)addr), "i" (-EAGAIN), \
|
2016-07-04 16:59:43 +01:00
|
|
|
"i" (__SWP_LL_SC_LOOPS) \
|
2016-07-01 14:58:21 +01:00
|
|
|
: "memory"); \
|
arm64: uaccess: rename privileged uaccess routines
We currently have many uaccess_*{enable,disable}*() variants, which
subsequent patches will cut down as part of removing set_fs() and
friends. Once this simplification is made, most uaccess routines will
only need to ensure that the user page tables are mapped in TTBR0, as is
currently dealt with by uaccess_ttbr0_{enable,disable}().
The existing uaccess_{enable,disable}() routines ensure that user page
tables are mapped in TTBR0, and also disable PAN protections, which is
necessary to be able to use atomics on user memory, but also permit
unrelated privileged accesses to access user memory.
As preparatory step, let's rename uaccess_{enable,disable}() to
uaccess_{enable,disable}_privileged(), highlighting this caveat and
discouraging wider misuse. Subsequent patches can reuse the
uaccess_{enable,disable}() naming for the common case of ensuring the
user page tables are mapped in TTBR0.
There should be no functional change as a result of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20201202131558.39270-5-mark.rutland@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2020-12-02 13:15:50 +00:00
|
|
|
uaccess_disable_privileged(); \
|
2016-07-01 14:58:21 +01:00
|
|
|
} while (0)
|
2014-11-18 11:41:25 +00:00
|
|
|
|
2016-07-04 16:59:43 +01:00
|
|
|
#define __user_swp_asm(data, addr, res, temp, temp2) \
|
|
|
|
__user_swpX_asm(data, addr, res, temp, temp2, "")
|
|
|
|
#define __user_swpb_asm(data, addr, res, temp, temp2) \
|
|
|
|
__user_swpX_asm(data, addr, res, temp, temp2, "b")
|
2014-11-18 11:41:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bit 22 of the instruction encoding distinguishes between
|
|
|
|
* the SWP and SWPB variants (bit set means SWPB).
|
|
|
|
*/
|
|
|
|
#define TYPE_SWPB (1 << 22)
|
|
|
|
|
|
|
|
static int emulate_swpX(unsigned int address, unsigned int *data,
|
|
|
|
unsigned int type)
|
|
|
|
{
|
|
|
|
unsigned int res = 0;
|
|
|
|
|
|
|
|
if ((type != TYPE_SWPB) && (address & 0x3)) {
|
|
|
|
/* SWP to unaligned address not permitted */
|
|
|
|
pr_debug("SWP instruction on unaligned pointer!\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
2016-07-04 16:59:43 +01:00
|
|
|
unsigned long temp, temp2;
|
2014-11-18 11:41:25 +00:00
|
|
|
|
|
|
|
if (type == TYPE_SWPB)
|
2016-07-04 16:59:43 +01:00
|
|
|
__user_swpb_asm(*data, address, res, temp, temp2);
|
2014-11-18 11:41:25 +00:00
|
|
|
else
|
2016-07-04 16:59:43 +01:00
|
|
|
__user_swp_asm(*data, address, res, temp, temp2);
|
2014-11-18 11:41:25 +00:00
|
|
|
|
|
|
|
if (likely(res != -EAGAIN) || signal_pending(current))
|
|
|
|
break;
|
|
|
|
|
|
|
|
cond_resched();
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* swp_handler logs the id of calling process, dissects the instruction, sanity
|
|
|
|
* checks the memory location, calls emulate_swpX for the actual operation and
|
|
|
|
* deals with fixup/error handling before returning
|
|
|
|
*/
|
|
|
|
static int swp_handler(struct pt_regs *regs, u32 instr)
|
|
|
|
{
|
|
|
|
u32 destreg, data, type, address = 0;
|
2018-02-19 13:38:00 +00:00
|
|
|
const void __user *user_ptr;
|
2014-11-18 11:41:25 +00:00
|
|
|
int rn, rt2, res = 0;
|
|
|
|
|
|
|
|
perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, regs->pc);
|
|
|
|
|
|
|
|
type = instr & TYPE_SWPB;
|
|
|
|
|
2016-07-08 12:35:47 -04:00
|
|
|
switch (aarch32_check_condition(instr, regs->pstate)) {
|
2014-11-18 11:41:25 +00:00
|
|
|
case ARM_OPCODE_CONDTEST_PASS:
|
|
|
|
break;
|
|
|
|
case ARM_OPCODE_CONDTEST_FAIL:
|
|
|
|
/* Condition failed - return to next instruction */
|
|
|
|
goto ret;
|
|
|
|
case ARM_OPCODE_CONDTEST_UNCOND:
|
|
|
|
/* If unconditional encoding - not a SWP, undef */
|
|
|
|
return -EFAULT;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rn = aarch32_insn_extract_reg_num(instr, A32_RN_OFFSET);
|
|
|
|
rt2 = aarch32_insn_extract_reg_num(instr, A32_RT2_OFFSET);
|
|
|
|
|
|
|
|
address = (u32)regs->user_regs.regs[rn];
|
|
|
|
data = (u32)regs->user_regs.regs[rt2];
|
|
|
|
destreg = aarch32_insn_extract_reg_num(instr, A32_RT_OFFSET);
|
|
|
|
|
|
|
|
pr_debug("addr in r%d->0x%08x, dest is r%d, source in r%d->0x%08x)\n",
|
|
|
|
rn, address, destreg,
|
|
|
|
aarch32_insn_extract_reg_num(instr, A32_RT2_OFFSET), data);
|
|
|
|
|
|
|
|
/* Check access in reasonable access range for both SWP and SWPB */
|
2018-02-19 13:38:00 +00:00
|
|
|
user_ptr = (const void __user *)(unsigned long)(address & ~3);
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-03 18:57:57 -08:00
|
|
|
if (!access_ok(user_ptr, 4)) {
|
2014-11-18 11:41:25 +00:00
|
|
|
pr_debug("SWP{B} emulation: access to 0x%08x not allowed!\n",
|
|
|
|
address);
|
|
|
|
goto fault;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = emulate_swpX(address, &data, type);
|
|
|
|
if (res == -EFAULT)
|
|
|
|
goto fault;
|
|
|
|
else if (res == 0)
|
|
|
|
regs->user_regs.regs[destreg] = data;
|
|
|
|
|
|
|
|
ret:
|
2014-11-18 11:41:27 +00:00
|
|
|
if (type == TYPE_SWPB)
|
|
|
|
trace_instruction_emulation("swpb", regs->pc);
|
|
|
|
else
|
|
|
|
trace_instruction_emulation("swp", regs->pc);
|
|
|
|
|
2014-11-18 11:41:25 +00:00
|
|
|
pr_warn_ratelimited("\"%s\" (%ld) uses obsolete SWP{B} instruction at 0x%llx\n",
|
|
|
|
current->comm, (unsigned long)current->pid, regs->pc);
|
|
|
|
|
2017-10-25 10:04:33 +01:00
|
|
|
arm64_skip_faulting_instruction(regs, 4);
|
2014-11-18 11:41:25 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fault:
|
2016-06-28 18:07:31 +01:00
|
|
|
pr_debug("SWP{B} emulation: access caused memory abort!\n");
|
2018-02-20 14:16:29 +00:00
|
|
|
arm64_notify_segfault(address);
|
2014-11-18 11:41:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static bool try_emulate_swp(struct pt_regs *regs, u32 insn)
|
|
|
|
{
|
|
|
|
/* SWP{B} only exists in ARM state and does not exist in Thumb */
|
|
|
|
if (!compat_user_mode(regs) || compat_thumb_mode(regs))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((insn & 0x0fb00ff0) != 0x01000090)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return swp_handler(regs, insn) == 0;
|
|
|
|
}
|
2014-11-18 11:41:25 +00:00
|
|
|
|
2022-10-19 15:41:20 +01:00
|
|
|
static struct insn_emulation insn_swp = {
|
2014-11-18 11:41:25 +00:00
|
|
|
.name = "swp",
|
|
|
|
.status = INSN_OBSOLETE,
|
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
|
|
|
.try_emulate = try_emulate_swp,
|
2014-11-18 11:41:25 +00:00
|
|
|
.set_hw_mode = NULL,
|
|
|
|
};
|
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
|
|
|
#endif /* CONFIG_SWP_EMULATION */
|
2014-11-18 11:41:25 +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_CP15_BARRIER_EMULATION
|
2014-11-18 11:41:26 +00:00
|
|
|
static int cp15barrier_handler(struct pt_regs *regs, u32 instr)
|
|
|
|
{
|
|
|
|
perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, regs->pc);
|
|
|
|
|
2016-07-08 12:35:47 -04:00
|
|
|
switch (aarch32_check_condition(instr, regs->pstate)) {
|
2014-11-18 11:41:26 +00:00
|
|
|
case ARM_OPCODE_CONDTEST_PASS:
|
|
|
|
break;
|
|
|
|
case ARM_OPCODE_CONDTEST_FAIL:
|
|
|
|
/* Condition failed - return to next instruction */
|
|
|
|
goto ret;
|
|
|
|
case ARM_OPCODE_CONDTEST_UNCOND:
|
|
|
|
/* If unconditional encoding - not a barrier instruction */
|
|
|
|
return -EFAULT;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aarch32_insn_mcr_extract_crm(instr)) {
|
|
|
|
case 10:
|
|
|
|
/*
|
|
|
|
* dmb - mcr p15, 0, Rt, c7, c10, 5
|
|
|
|
* dsb - mcr p15, 0, Rt, c7, c10, 4
|
|
|
|
*/
|
2014-11-18 11:41:27 +00:00
|
|
|
if (aarch32_insn_mcr_extract_opc2(instr) == 5) {
|
2014-11-18 11:41:26 +00:00
|
|
|
dmb(sy);
|
2014-11-18 11:41:27 +00:00
|
|
|
trace_instruction_emulation(
|
|
|
|
"mcr p15, 0, Rt, c7, c10, 5 ; dmb", regs->pc);
|
|
|
|
} else {
|
2014-11-18 11:41:26 +00:00
|
|
|
dsb(sy);
|
2014-11-18 11:41:27 +00:00
|
|
|
trace_instruction_emulation(
|
|
|
|
"mcr p15, 0, Rt, c7, c10, 4 ; dsb", regs->pc);
|
|
|
|
}
|
2014-11-18 11:41:26 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
/*
|
|
|
|
* isb - mcr p15, 0, Rt, c7, c5, 4
|
|
|
|
*
|
|
|
|
* Taking an exception or returning from one acts as an
|
|
|
|
* instruction barrier. So no explicit barrier needed here.
|
|
|
|
*/
|
2014-11-18 11:41:27 +00:00
|
|
|
trace_instruction_emulation(
|
|
|
|
"mcr p15, 0, Rt, c7, c5, 4 ; isb", regs->pc);
|
2014-11-18 11:41:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret:
|
|
|
|
pr_warn_ratelimited("\"%s\" (%ld) uses deprecated CP15 Barrier instruction at 0x%llx\n",
|
|
|
|
current->comm, (unsigned long)current->pid, regs->pc);
|
|
|
|
|
2017-10-25 10:04:33 +01:00
|
|
|
arm64_skip_faulting_instruction(regs, 4);
|
2014-11-18 11:41:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cp15_barrier_set_hw_mode(bool enable)
|
|
|
|
{
|
2015-01-21 12:43:10 +00:00
|
|
|
if (enable)
|
2018-07-11 14:56:38 +01:00
|
|
|
sysreg_clear_set(sctlr_el1, 0, SCTLR_EL1_CP15BEN);
|
2015-01-21 12:43:10 +00:00
|
|
|
else
|
2018-07-11 14:56:38 +01:00
|
|
|
sysreg_clear_set(sctlr_el1, SCTLR_EL1_CP15BEN, 0);
|
2015-01-21 12:43:10 +00:00
|
|
|
return 0;
|
2014-11-18 11:41:26 +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
|
|
|
static bool try_emulate_cp15_barrier(struct pt_regs *regs, u32 insn)
|
|
|
|
{
|
|
|
|
if (!compat_user_mode(regs) || compat_thumb_mode(regs))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((insn & 0x0fff0fdf) == 0x0e070f9a)
|
|
|
|
return cp15barrier_handler(regs, insn) == 0;
|
|
|
|
|
|
|
|
if ((insn & 0x0fff0fff) == 0x0e070f95)
|
|
|
|
return cp15barrier_handler(regs, insn) == 0;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-18 11:41:26 +00:00
|
|
|
|
2022-10-19 15:41:20 +01:00
|
|
|
static struct insn_emulation insn_cp15_barrier = {
|
2014-11-18 11:41:26 +00:00
|
|
|
.name = "cp15_barrier",
|
|
|
|
.status = INSN_DEPRECATED,
|
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
|
|
|
.try_emulate = try_emulate_cp15_barrier,
|
2014-11-18 11:41:26 +00:00
|
|
|
.set_hw_mode = cp15_barrier_set_hw_mode,
|
|
|
|
};
|
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
|
|
|
#endif /* CONFIG_CP15_BARRIER_EMULATION */
|
2014-11-18 11:41:26 +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_SETEND_EMULATION
|
2015-01-21 12:43:11 +00:00
|
|
|
static int setend_set_hw_mode(bool enable)
|
|
|
|
{
|
|
|
|
if (!cpu_supports_mixed_endian_el0())
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (enable)
|
2018-07-11 14:56:38 +01:00
|
|
|
sysreg_clear_set(sctlr_el1, SCTLR_EL1_SED, 0);
|
2015-01-21 12:43:11 +00:00
|
|
|
else
|
2018-07-11 14:56:38 +01:00
|
|
|
sysreg_clear_set(sctlr_el1, 0, SCTLR_EL1_SED);
|
2015-01-21 12:43:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compat_setend_handler(struct pt_regs *regs, u32 big_endian)
|
|
|
|
{
|
|
|
|
char *insn;
|
|
|
|
|
|
|
|
perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, regs->pc);
|
|
|
|
|
|
|
|
if (big_endian) {
|
|
|
|
insn = "setend be";
|
2018-07-05 15:16:52 +01:00
|
|
|
regs->pstate |= PSR_AA32_E_BIT;
|
2015-01-21 12:43:11 +00:00
|
|
|
} else {
|
|
|
|
insn = "setend le";
|
2018-07-05 15:16:52 +01:00
|
|
|
regs->pstate &= ~PSR_AA32_E_BIT;
|
2015-01-21 12:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trace_instruction_emulation(insn, regs->pc);
|
|
|
|
pr_warn_ratelimited("\"%s\" (%ld) uses deprecated setend instruction at 0x%llx\n",
|
|
|
|
current->comm, (unsigned long)current->pid, regs->pc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int a32_setend_handler(struct pt_regs *regs, u32 instr)
|
|
|
|
{
|
|
|
|
int rc = compat_setend_handler(regs, (instr >> 9) & 1);
|
2017-10-25 10:04:33 +01:00
|
|
|
arm64_skip_faulting_instruction(regs, 4);
|
2015-01-21 12:43:11 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int t16_setend_handler(struct pt_regs *regs, u32 instr)
|
|
|
|
{
|
|
|
|
int rc = compat_setend_handler(regs, (instr >> 3) & 1);
|
2017-10-25 10:04:33 +01:00
|
|
|
arm64_skip_faulting_instruction(regs, 2);
|
2015-01-21 12:43:11 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static bool try_emulate_setend(struct pt_regs *regs, u32 insn)
|
|
|
|
{
|
|
|
|
if (compat_thumb_mode(regs) &&
|
|
|
|
(insn & 0xfffffff7) == 0x0000b650)
|
|
|
|
return t16_setend_handler(regs, insn) == 0;
|
|
|
|
|
|
|
|
if (compat_user_mode(regs) &&
|
|
|
|
(insn & 0xfffffdff) == 0xf1010000)
|
|
|
|
return a32_setend_handler(regs, insn) == 0;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-21 12:43:11 +00:00
|
|
|
|
2022-10-19 15:41:20 +01:00
|
|
|
static struct insn_emulation insn_setend = {
|
2015-01-21 12:43:11 +00:00
|
|
|
.name = "setend",
|
|
|
|
.status = INSN_DEPRECATED,
|
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
|
|
|
.try_emulate = try_emulate_setend,
|
2015-01-21 12:43:11 +00:00
|
|
|
.set_hw_mode = setend_set_hw_mode,
|
|
|
|
};
|
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
|
|
|
#endif /* CONFIG_SETEND_EMULATION */
|
|
|
|
|
|
|
|
static struct insn_emulation *insn_emulations[] = {
|
|
|
|
#ifdef CONFIG_SWP_EMULATION
|
|
|
|
&insn_swp,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CP15_BARRIER_EMULATION
|
|
|
|
&insn_cp15_barrier,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SETEND_EMULATION
|
|
|
|
&insn_setend,
|
|
|
|
#endif
|
|
|
|
};
|
2015-01-21 12:43:11 +00:00
|
|
|
|
2022-10-19 15:41:21 +01:00
|
|
|
static DEFINE_MUTEX(insn_emulation_mutex);
|
|
|
|
|
|
|
|
static void enable_insn_hw_mode(void *data)
|
|
|
|
{
|
2023-03-03 10:50:47 +08:00
|
|
|
struct insn_emulation *insn = data;
|
2022-10-19 15:41:21 +01:00
|
|
|
if (insn->set_hw_mode)
|
|
|
|
insn->set_hw_mode(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void disable_insn_hw_mode(void *data)
|
|
|
|
{
|
2023-03-03 10:50:47 +08:00
|
|
|
struct insn_emulation *insn = data;
|
2022-10-19 15:41:21 +01:00
|
|
|
if (insn->set_hw_mode)
|
|
|
|
insn->set_hw_mode(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Run set_hw_mode(mode) on all active CPUs */
|
|
|
|
static int run_all_cpu_set_hw_mode(struct insn_emulation *insn, bool enable)
|
|
|
|
{
|
|
|
|
if (!insn->set_hw_mode)
|
|
|
|
return -EINVAL;
|
|
|
|
if (enable)
|
|
|
|
on_each_cpu(enable_insn_hw_mode, (void *)insn, true);
|
|
|
|
else
|
|
|
|
on_each_cpu(disable_insn_hw_mode, (void *)insn, true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run set_hw_mode for all insns on a starting CPU.
|
|
|
|
* Returns:
|
|
|
|
* 0 - If all the hooks ran successfully.
|
|
|
|
* -EINVAL - At least one hook is not supported by the CPU.
|
|
|
|
*/
|
|
|
|
static int run_all_insn_set_hw_mode(unsigned int cpu)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Disable IRQs to serialize against an IPI from
|
|
|
|
* run_all_cpu_set_hw_mode(), ensuring the HW is programmed to the most
|
|
|
|
* recent enablement state if the two race with one another.
|
|
|
|
*/
|
|
|
|
local_irq_save(flags);
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(insn_emulations); i++) {
|
|
|
|
struct insn_emulation *insn = insn_emulations[i];
|
|
|
|
bool enable = READ_ONCE(insn->current_mode) == INSN_HW;
|
2024-04-23 17:35:01 +08:00
|
|
|
if (insn->status == INSN_UNAVAILABLE)
|
|
|
|
continue;
|
|
|
|
|
2022-10-19 15:41:21 +01:00
|
|
|
if (insn->set_hw_mode && insn->set_hw_mode(enable)) {
|
|
|
|
pr_warn("CPU[%u] cannot support the emulation of %s",
|
|
|
|
cpu, insn->name);
|
|
|
|
rc = -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
local_irq_restore(flags);
|
|
|
|
|
2022-10-19 15:41:21 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int update_insn_emulation_mode(struct insn_emulation *insn,
|
|
|
|
enum insn_emulation_mode prev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (prev) {
|
|
|
|
case INSN_UNDEF: /* Nothing to be done */
|
|
|
|
break;
|
|
|
|
case INSN_EMULATE:
|
|
|
|
break;
|
|
|
|
case INSN_HW:
|
|
|
|
if (!run_all_cpu_set_hw_mode(insn, false))
|
|
|
|
pr_notice("Disabled %s support\n", insn->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (insn->current_mode) {
|
|
|
|
case INSN_UNDEF:
|
|
|
|
break;
|
|
|
|
case INSN_EMULATE:
|
|
|
|
break;
|
|
|
|
case INSN_HW:
|
|
|
|
ret = run_all_cpu_set_hw_mode(insn, true);
|
|
|
|
if (!ret)
|
|
|
|
pr_notice("Enabled %s support\n", insn->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
sysctl: treewide: constify the ctl_table argument of proc_handlers
const qualify the struct ctl_table argument in the proc_handler function
signatures. This is a prerequisite to moving the static ctl_table
structs into .rodata data which will ensure that proc_handler function
pointers cannot be modified.
This patch has been generated by the following coccinelle script:
```
virtual patch
@r1@
identifier ctl, write, buffer, lenp, ppos;
identifier func !~ "appldata_(timer|interval)_handler|sched_(rt|rr)_handler|rds_tcp_skbuf_handler|proc_sctp_do_(hmac_alg|rto_min|rto_max|udp_port|alpha_beta|auth|probe_interval)";
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int write, void *buffer, size_t *lenp, loff_t *ppos);
@r2@
identifier func, ctl, write, buffer, lenp, ppos;
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int write, void *buffer, size_t *lenp, loff_t *ppos)
{ ... }
@r3@
identifier func;
@@
int func(
- struct ctl_table *
+ const struct ctl_table *
,int , void *, size_t *, loff_t *);
@r4@
identifier func, ctl;
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int , void *, size_t *, loff_t *);
@r5@
identifier func, write, buffer, lenp, ppos;
@@
int func(
- struct ctl_table *
+ const struct ctl_table *
,int write, void *buffer, size_t *lenp, loff_t *ppos);
```
* Code formatting was adjusted in xfs_sysctl.c to comply with code
conventions. The xfs_stats_clear_proc_handler,
xfs_panic_mask_proc_handler and xfs_deprecated_dointvec_minmax where
adjusted.
* The ctl_table argument in proc_watchdog_common was const qualified.
This is called from a proc_handler itself and is calling back into
another proc_handler, making it necessary to change it as part of the
proc_handler migration.
Co-developed-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Co-developed-by: Joel Granados <j.granados@samsung.com>
Signed-off-by: Joel Granados <j.granados@samsung.com>
2024-07-24 20:59:29 +02:00
|
|
|
static int emulation_proc_handler(const struct ctl_table *table, int write,
|
2022-10-19 15:41:21 +01:00
|
|
|
void *buffer, size_t *lenp,
|
|
|
|
loff_t *ppos)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct insn_emulation *insn = container_of(table->data, struct insn_emulation, current_mode);
|
|
|
|
enum insn_emulation_mode prev_mode = insn->current_mode;
|
|
|
|
|
|
|
|
mutex_lock(&insn_emulation_mutex);
|
|
|
|
ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
|
|
|
|
|
|
|
|
if (ret || !write || prev_mode == insn->current_mode)
|
|
|
|
goto ret;
|
|
|
|
|
|
|
|
ret = update_insn_emulation_mode(insn, prev_mode);
|
|
|
|
if (ret) {
|
|
|
|
/* Mode change failed, revert to previous mode. */
|
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
|
|
|
WRITE_ONCE(insn->current_mode, prev_mode);
|
2022-10-19 15:41:21 +01:00
|
|
|
update_insn_emulation_mode(insn, INSN_UNDEF);
|
|
|
|
}
|
|
|
|
ret:
|
|
|
|
mutex_unlock(&insn_emulation_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static void __init register_insn_emulation(struct insn_emulation *insn)
|
2022-10-19 15:41:21 +01: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
|
|
|
struct ctl_table *sysctl;
|
2022-10-19 15:41:21 +01: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
|
|
|
insn->min = INSN_UNDEF;
|
2022-10-19 15:41:21 +01: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
|
|
|
switch (insn->status) {
|
|
|
|
case INSN_DEPRECATED:
|
|
|
|
insn->current_mode = INSN_EMULATE;
|
|
|
|
/* Disable the HW mode if it was turned on at early boot time */
|
|
|
|
run_all_cpu_set_hw_mode(insn, false);
|
|
|
|
insn->max = INSN_HW;
|
|
|
|
break;
|
|
|
|
case INSN_OBSOLETE:
|
|
|
|
insn->current_mode = INSN_UNDEF;
|
|
|
|
insn->max = INSN_EMULATE;
|
|
|
|
break;
|
|
|
|
case INSN_UNAVAILABLE:
|
|
|
|
insn->current_mode = INSN_UNDEF;
|
|
|
|
insn->max = INSN_UNDEF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Program the HW if required */
|
|
|
|
update_insn_emulation_mode(insn, INSN_UNDEF);
|
|
|
|
|
|
|
|
if (insn->status != INSN_UNAVAILABLE) {
|
2023-10-02 13:30:37 +02:00
|
|
|
sysctl = &insn->sysctl;
|
2022-10-19 15:41:21 +01:00
|
|
|
|
|
|
|
sysctl->mode = 0644;
|
|
|
|
sysctl->maxlen = sizeof(int);
|
|
|
|
|
|
|
|
sysctl->procname = insn->name;
|
|
|
|
sysctl->data = &insn->current_mode;
|
|
|
|
sysctl->extra1 = &insn->min;
|
|
|
|
sysctl->extra2 = &insn->max;
|
|
|
|
sysctl->proc_handler = emulation_proc_handler;
|
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
|
|
|
|
2023-08-09 12:49:58 +02:00
|
|
|
register_sysctl_sz("abi", sysctl, 1);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool try_emulate_armv8_deprecated(struct pt_regs *regs, u32 insn)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(insn_emulations); i++) {
|
|
|
|
struct insn_emulation *ie = insn_emulations[i];
|
|
|
|
|
|
|
|
if (ie->status == INSN_UNAVAILABLE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A trap may race with the mode being changed
|
|
|
|
* INSN_EMULATE<->INSN_HW. Try to emulate the instruction to
|
|
|
|
* avoid a spurious UNDEF.
|
|
|
|
*/
|
|
|
|
if (READ_ONCE(ie->current_mode) == INSN_UNDEF)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ie->try_emulate(regs, insn))
|
|
|
|
return true;
|
2022-10-19 15:41:21 +01: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
|
|
|
return false;
|
2022-10-19 15:41:21 +01:00
|
|
|
}
|
|
|
|
|
2014-11-18 11:41:24 +00:00
|
|
|
/*
|
2019-12-11 15:27:33 +08:00
|
|
|
* Invoked as core_initcall, which guarantees that the instruction
|
|
|
|
* emulation is ready for userspace.
|
2014-11-18 11:41:24 +00:00
|
|
|
*/
|
|
|
|
static int __init armv8_deprecated_init(void)
|
|
|
|
{
|
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_SETEND_EMULATION
|
|
|
|
if (!system_supports_mixed_endian_el0()) {
|
|
|
|
insn_setend.status = INSN_UNAVAILABLE;
|
|
|
|
pr_info("setend instruction emulation is not supported on this system\n");
|
|
|
|
}
|
2014-11-18 11:41:25 +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
|
|
|
#endif
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(insn_emulations); i++) {
|
|
|
|
struct insn_emulation *ie = insn_emulations[i];
|
2014-11-18 11:41:26 +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
|
|
|
if (ie->status == INSN_UNAVAILABLE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
register_insn_emulation(ie);
|
2015-01-21 12:43:11 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 17:16:56 +00:00
|
|
|
cpuhp_setup_state_nocalls(CPUHP_AP_ARM64_ISNDEP_STARTING,
|
2016-12-21 20:19:54 +01:00
|
|
|
"arm64/isndep:starting",
|
2016-07-13 17:16:56 +00:00
|
|
|
run_all_insn_set_hw_mode, NULL);
|
2014-11-18 11:41:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-06 14:16:52 +01:00
|
|
|
core_initcall(armv8_deprecated_init);
|