Skip to content

Commit 08cd8f4

Browse files
willdeaconPeter Zijlstra
authored andcommitted
arm64: exec: Adjust affinity for compat tasks with mismatched 32-bit EL0
When exec'ing a 32-bit task on a system with mismatched support for 32-bit EL0, try to ensure that it starts life on a CPU that can actually run it. Similarly, when exec'ing a 64-bit task on such a system, try to restore the old affinity mask if it was previously restricted. Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Daniel Bristot de Oliveira <[email protected]> Reviewed-by: Quentin Perret <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d82158f commit 08cd8f4

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

arch/arm64/include/asm/elf.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,8 @@ typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
213213

214214
/* AArch32 EABI. */
215215
#define EF_ARM_EABI_MASK 0xff000000
216-
#define compat_elf_check_arch(x) (system_supports_32bit_el0() && \
217-
((x)->e_machine == EM_ARM) && \
218-
((x)->e_flags & EF_ARM_EABI_MASK))
219-
216+
int compat_elf_check_arch(const struct elf32_hdr *);
217+
#define compat_elf_check_arch compat_elf_check_arch
220218
#define compat_start_thread compat_start_thread
221219
/*
222220
* Unlike the native SET_PERSONALITY macro, the compat version maintains

arch/arm64/kernel/process.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/mman.h>
2222
#include <linux/mm.h>
2323
#include <linux/nospec.h>
24+
#include <linux/sched.h>
2425
#include <linux/stddef.h>
2526
#include <linux/sysctl.h>
2627
#include <linux/unistd.h>
@@ -579,6 +580,28 @@ unsigned long arch_align_stack(unsigned long sp)
579580
return sp & ~0xf;
580581
}
581582

583+
#ifdef CONFIG_COMPAT
584+
int compat_elf_check_arch(const struct elf32_hdr *hdr)
585+
{
586+
if (!system_supports_32bit_el0())
587+
return false;
588+
589+
if ((hdr)->e_machine != EM_ARM)
590+
return false;
591+
592+
if (!((hdr)->e_flags & EF_ARM_EABI_MASK))
593+
return false;
594+
595+
/*
596+
* Prevent execve() of a 32-bit program from a deadline task
597+
* if the restricted affinity mask would be inadmissible on an
598+
* asymmetric system.
599+
*/
600+
return !static_branch_unlikely(&arm64_mismatched_32bit_el0) ||
601+
!dl_task_check_affinity(current, system_32bit_el0_cpumask());
602+
}
603+
#endif
604+
582605
/*
583606
* Called from setup_new_exec() after (COMPAT_)SET_PERSONALITY.
584607
*/
@@ -588,8 +611,22 @@ void arch_setup_new_exec(void)
588611

589612
if (is_compat_task()) {
590613
mmflags = MMCF_AARCH32;
591-
if (static_branch_unlikely(&arm64_mismatched_32bit_el0))
614+
615+
/*
616+
* Restrict the CPU affinity mask for a 32-bit task so that
617+
* it contains only 32-bit-capable CPUs.
618+
*
619+
* From the perspective of the task, this looks similar to
620+
* what would happen if the 64-bit-only CPUs were hot-unplugged
621+
* at the point of execve(), although we try a bit harder to
622+
* honour the cpuset hierarchy.
623+
*/
624+
if (static_branch_unlikely(&arm64_mismatched_32bit_el0)) {
625+
force_compatible_cpus_allowed_ptr(current);
592626
set_tsk_thread_flag(current, TIF_NOTIFY_RESUME);
627+
}
628+
} else if (static_branch_unlikely(&arm64_mismatched_32bit_el0)) {
629+
relax_compatible_cpus_allowed_ptr(current);
593630
}
594631

595632
current->mm->context.flags = mmflags;

0 commit comments

Comments
 (0)