/* * Called by kexec, immediately prior to machine_kexec(). * * This must completely disable all secondary CPUs; simply causing those CPUs * to execute e.g. a RAM-based pin loop is not sufficient. This allows the * kexec'd kernel to use any and all RAM as it sees fit, without having to * avoid any code or data used by any SW CPU pin loop. The CPU hotplug * functionality embodied in smpt_shutdown_nonboot_cpus() to achieve this.
*/ void machine_shutdown(void)
{
smp_shutdown_nonboot_cpus(reboot_cpu);
}
/* * Halting simply requires that the secondary CPUs stop performing any * activity (executing tasks, handling interrupts). smp_send_stop() * achieves this.
*/ void machine_halt(void)
{
local_irq_disable();
smp_send_stop(); while (1);
}
/* * Power-off simply requires that the secondary CPUs stop performing any * activity (executing tasks, handling interrupts). smp_send_stop() * achieves this. When the system power is turned off, it will take all CPUs * with it.
*/ void machine_power_off(void)
{
local_irq_disable();
smp_send_stop();
do_kernel_power_off();
}
/* * Restart requires that the secondary CPUs stop performing any activity * while the primary CPU resets the system. Systems with multiple CPUs must * provide a HW restart implementation, to ensure that all CPUs reset at once. * This is required so that any code running after reset on the primary CPU * doesn't have to co-ordinate with other CPUs to ensure they aren't still * executing pre-reset code, and using RAM that the primary CPU's code wishes * to use. Implementing such co-ordination would be essentially impossible.
*/ void machine_restart(char *cmd)
{ /* Disable interrupts first */
local_irq_disable();
smp_send_stop();
/* * UpdateCapsule() depends on the system being reset via * ResetSystem().
*/ if (efi_enabled(EFI_RUNTIME_SERVICES))
efi_reboot(reboot_mode, NULL);
/* Now call the architecture specific reboot code. */
do_kernel_restart(cmd);
/* * Whoops - the architecture was unable to reboot.
*/
printk("Reboot failed -- System halted\n"); while (1);
}
staticvoid tls_thread_flush(void)
{
write_sysreg(0, tpidr_el0); if (system_supports_tpidr2())
write_sysreg_s(0, SYS_TPIDR2_EL0);
if (is_compat_task()) {
current->thread.uw.tp_value = 0;
/* * We need to ensure ordering between the shadow state and the * hardware state, so that we don't corrupt the hardware state * with a stale shadow state during context switch.
*/
barrier();
write_sysreg(0, tpidrro_el0);
}
}
staticvoid flush_tagged_addr_state(void)
{ if (IS_ENABLED(CONFIG_ARM64_TAGGED_ADDR_ABI))
clear_thread_flag(TIF_TAGGED_ADDR);
}
staticvoid flush_poe(void)
{ if (!system_supports_poe()) return;
write_sysreg_s(POR_EL0_INIT, SYS_POR_EL0);
}
#ifdef CONFIG_ARM64_GCS
staticvoid flush_gcs(void)
{ if (!system_supports_gcs()) return;
int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
{ /* * The current/src task's FPSIMD state may or may not be live, and may * have been altered by ptrace after entry to the kernel. Save the * effective FPSIMD state so that this will be copied into dst.
*/
fpsimd_save_and_flush_current_state();
fpsimd_sync_from_effective_state(src);
*dst = *src;
/* * Drop stale reference to src's sve_state and convert dst to * non-streaming FPSIMD mode.
*/
dst->thread.fp_type = FP_STATE_FPSIMD;
dst->thread.sve_state = NULL;
clear_tsk_thread_flag(dst, TIF_SVE);
task_smstop_sm(dst);
/* * Drop stale reference to src's sme_state and ensure dst has ZA * disabled. * * When necessary, ZA will be inherited later in copy_thread_za().
*/
dst->thread.sme_state = NULL;
clear_tsk_thread_flag(dst, TIF_SME);
dst->thread.svcr &= ~SVCR_ZA_MASK;
/* clear any pending asynchronous tag fault raised by the parent */
clear_tsk_thread_flag(dst, TIF_MTE_ASYNC_FAULT);
/* * In case p was allocated the same task_struct pointer as some * other recently-exited task, make sure p is disassociated from * any cpu that may have run that now-exited task recently. * Otherwise we could erroneously skip reloading the FPSIMD * registers for p.
*/
fpsimd_flush_task_state(p);
ptrauth_thread_init_kernel(p);
if (likely(!args->fn)) {
*childregs = *current_pt_regs();
childregs->regs[0] = 0;
/* * Read the current TLS pointer from tpidr_el0 as it may be * out-of-sync with the saved value.
*/
*task_user_tls(p) = read_sysreg(tpidr_el0);
if (system_supports_poe())
p->thread.por_el0 = read_sysreg_s(SYS_POR_EL0);
if (stack_start) { if (is_compat_thread(task_thread_info(p)))
childregs->compat_sp = stack_start; else
childregs->sp = stack_start;
}
/* * Due to the AAPCS64 "ZA lazy saving scheme", PSTATE.ZA and * TPIDR2 need to be manipulated as a pair, and either both * need to be inherited or both need to be reset. * * Within a process, child threads must not inherit their * parent's TPIDR2 value or they may clobber their parent's * stack at some later point. * * When a process is fork()'d, the child must inherit ZA and * TPIDR2 from its parent in case there was dormant ZA state. * * Use CLONE_VM to determine when the child will share the * address space with the parent, and cannot safely inherit the * state.
*/ if (system_supports_sme()) { if (!(clone_flags & CLONE_VM)) {
p->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0);
ret = copy_thread_za(p, current); if (ret) return ret;
} else {
p->thread.tpidr2_el0 = 0;
WARN_ON_ONCE(p->thread.svcr & SVCR_ZA_MASK);
}
}
/* * If a TLS pointer was passed to clone, use it for the new * thread.
*/ if (clone_flags & CLONE_SETTLS)
p->thread.uw.tp_value = tls;
ret = copy_thread_gcs(p, args); if (ret != 0) return ret;
} else { /* * A kthread has no context to ERET to, so ensure any buggy * ERET is treated as an illegal exception return. * * When a user task is created from a kthread, childregs will * be initialized by start_thread() or start_compat_thread().
*/
memset(childregs, 0, sizeof(struct pt_regs));
childregs->pstate = PSR_MODE_EL1h | PSR_IL_BIT;
childregs->stackframe.type = FRAME_META_TYPE_FINAL;
if (system_supports_poe())
p->thread.por_el0 = POR_EL0_INIT;
}
p->thread.cpu_context.pc = (unsignedlong)ret_from_fork;
p->thread.cpu_context.sp = (unsignedlong)childregs; /* * For the benefit of the unwinder, set up childregs->stackframe * as the final frame for the new task.
*/
p->thread.cpu_context.fp = (unsignedlong)&childregs->stackframe;
if (is_compat_thread(task_thread_info(next)))
write_sysreg(next->thread.uw.tp_value, tpidrro_el0); else
write_sysreg(0, tpidrro_el0);
write_sysreg(*task_user_tls(next), tpidr_el0); if (system_supports_tpidr2())
write_sysreg_s(next->thread.tpidr2_el0, SYS_TPIDR2_EL0);
}
/* * Force SSBS state on context-switch, since it may be lost after migrating * from a CPU which treats the bit as RES0 in a heterogeneous system.
*/ staticvoid ssbs_thread_switch(struct task_struct *next)
{ /* * Nothing to do for kernel threads, but 'regs' may be junk * (e.g. idle task) so check the flags and bail early.
*/ if (unlikely(next->flags & PF_KTHREAD)) return;
/* * If all CPUs implement the SSBS extension, then we just need to * context-switch the PSTATE field.
*/ if (alternative_has_cap_unlikely(ARM64_SSBS)) return;
spectre_v4_enable_task_mitigation(next);
}
/* * We store our current task in sp_el0, which is clobbered by userspace. Keep a * shadow copy so that we can restore this upon entry from userspace. * * This is *only* for exception entry from EL0, and is not valid until we * __switch_to() a user task.
*/
DEFINE_PER_CPU(struct task_struct *, __entry_task);
staticvoid gcs_thread_switch(struct task_struct *next)
{ if (!system_supports_gcs()) return;
/* GCSPR_EL0 is always readable */
gcs_preserve_current_state();
write_sysreg_s(next->thread.gcspr_el0, SYS_GCSPR_EL0);
if (current->thread.gcs_el0_mode != next->thread.gcs_el0_mode)
gcs_set_el0_mode(next);
/* * Ensure that GCS memory effects of the 'prev' thread are * ordered before other memory accesses with release semantics * (or preceded by a DMB) on the current PE. In addition, any * memory accesses with acquire semantics (or succeeded by a * DMB) are ordered before GCS memory effects of the 'next' * thread. This will ensure that the GCS memory effects are * visible to other PEs in case of migration.
*/ if (task_gcs_el0_enabled(current) || task_gcs_el0_enabled(next))
gcsb_dsync();
}
/* * Handle sysreg updates for ARM erratum 1418040 which affects the 32bit view of * CNTVCT, various other errata which require trapping all CNTVCT{,_EL0} * accesses and prctl(PR_SET_TSC). Ensure access is disabled iff a workaround is * required or PR_TSC_SIGSEGV is set.
*/ staticvoid update_cntkctl_el1(struct task_struct *next)
{ struct thread_info *ti = task_thread_info(next);
staticvoid permission_overlay_switch(struct task_struct *next)
{ if (!system_supports_poe()) return;
current->thread.por_el0 = read_sysreg_s(SYS_POR_EL0); if (current->thread.por_el0 != next->thread.por_el0) {
write_sysreg_s(next->thread.por_el0, SYS_POR_EL0); /* * No ISB required as we can tolerate spurious Overlay faults - * the fault handler will check again based on the new value * of POR_EL0.
*/
}
}
/* * __switch_to() checks current->thread.sctlr_user as an optimisation. Therefore * this function must be called with preemption disabled and the update to * sctlr_user must be made in the same preemption disabled block so that * __switch_to() does not see the variable update before the SCTLR_EL1 one.
*/ void update_sctlr_el1(u64 sctlr)
{ /* * EnIA must not be cleared while in the kernel as this is necessary for * in-kernel PAC. It will be cleared on kernel exit if needed.
*/
sysreg_clear_set(sctlr_el1, SCTLR_USER_MASK & ~SCTLR_ELx_ENIA, sctlr);
/* ISB required for the kernel uaccess routines when setting TCF0. */
isb();
}
/* * Complete any pending TLB or cache maintenance on this CPU in case the * thread migrates to a different CPU. This full barrier is also * required by the membarrier system call. Additionally it makes any * in-progress pgtable writes visible to the table walker; See * emit_pte_barriers().
*/
dsb(ish);
/* * MTE thread switching must happen after the DSB above to ensure that * any asynchronous tag check faults have been logged in the TFSR*_EL1 * registers.
*/
mte_thread_switch(next); /* avoid expensive SCTLR_EL1 accesses if no change */ if (prev->thread.sctlr_user != next->thread.sctlr_user)
update_sctlr_el1(next->thread.sctlr_user);
/* the actual thread switch */
last = cpu_switch_to(prev, next);
return last;
}
struct wchan_info { unsignedlong pc; int count;
};
#ifdef CONFIG_COMPAT int compat_elf_check_arch(conststruct elf32_hdr *hdr)
{ if (!system_supports_32bit_el0()) returnfalse;
if ((hdr)->e_machine != EM_ARM) returnfalse;
if (!((hdr)->e_flags & EF_ARM_EABI_MASK)) returnfalse;
/* * Prevent execve() of a 32-bit program from a deadline task * if the restricted affinity mask would be inadmissible on an * asymmetric system.
*/ return !static_branch_unlikely(&arm64_mismatched_32bit_el0) ||
!dl_task_check_affinity(current, system_32bit_el0_cpumask());
} #endif
/* * Called from setup_new_exec() after (COMPAT_)SET_PERSONALITY.
*/ void arch_setup_new_exec(void)
{ unsignedlong mmflags = 0;
if (is_compat_task()) {
mmflags = MMCF_AARCH32;
/* * Restrict the CPU affinity mask for a 32-bit task so that * it contains only 32-bit-capable CPUs. * * From the perspective of the task, this looks similar to * what would happen if the 64-bit-only CPUs were hot-unplugged * at the point of execve(), although we try a bit harder to * honour the cpuset hierarchy.
*/ if (static_branch_unlikely(&arm64_mismatched_32bit_el0))
force_compatible_cpus_allowed_ptr(current);
} elseif (static_branch_unlikely(&arm64_mismatched_32bit_el0)) {
relax_compatible_cpus_allowed_ptr(current);
}
if (task_spec_ssb_noexec(current)) {
arch_prctl_spec_ctrl_set(current, PR_SPEC_STORE_BYPASS,
PR_SPEC_ENABLE);
}
}
#ifdef CONFIG_ARM64_TAGGED_ADDR_ABI /* * Control the relaxed ABI allowing tagged user addresses into the kernel.
*/ staticunsignedint tagged_addr_disabled;
if (cpus_have_cap(ARM64_MTE_STORE_ONLY))
valid_mask |= PR_MTE_STORE_ONLY;
}
if (arg & ~valid_mask) return -EINVAL;
/* * Do not allow the enabling of the tagged address ABI if globally * disabled via sysctl abi.tagged_addr_disabled.
*/ if (arg & PR_TAGGED_ADDR_ENABLE && tagged_addr_disabled) return -EINVAL;
long get_tagged_addr_ctrl(struct task_struct *task)
{ long ret = 0; struct thread_info *ti = task_thread_info(task);
if (is_compat_thread(ti)) return -EINVAL;
if (test_ti_thread_flag(ti, TIF_TAGGED_ADDR))
ret = PR_TAGGED_ADDR_ENABLE;
ret |= get_mte_ctrl(task);
return ret;
}
/* * Global sysctl to disable the tagged user addresses support. This control * only prevents the tagged address ABI enabling via prctl() and does not * disable it for tasks that already opted in to the relaxed ABI.
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.