Add support for 32-bit tasks on asymmetric AArch32 systems
Subsystems (13)
Will Deacon
maintainerv6 cover Add support for 32-bit tasks on asymmetric AArch32 systems
Hi folks,
This is the long-awaited v6 of these patches which I last posted at the end of last year:
v1: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/r/[email protected]
v3: https://lore.kernel.org/r/[email protected]
v4: https://lore.kernel.org/r/[email protected]
v5: https://lore.kernel.org/r/[email protected]
There was also a nice LWN writeup in case you've forgotten what this is about:
https://lwn.net/Articles/838339/
It's taken me a while to get a v6 of this together, partly due to addressing the review feedback on v5, but also because this has now seen testing on real hardware which threw up some surprises in suspend/resume, SCHED_DEADLINE and compat hwcap reporting. Thanks to Quentin for helping me to debug those issues.
The aim of this series is to allow 32-bit ARM applications to run on arm64 SoCs where not all of the CPUs support the 32-bit instruction set. Unfortunately, such SoCs are real and will continue to be productised over the next few years at least. I can assure you that I'm not just doing this for fun.
Changes in v6 include:
* Save/restore the affinity mask across execve() to 32-bit and back to
64-bit again.
* Allow 32-bit deadline tasks, but skip straight to fallback path when determining new affinity mask on execve().
* Fixed resume-from-suspend path when the resuming CPU is 64-bit-only by deferring wake-ups for 32-bit tasks until the secondary CPUs are back online.
* Bug fixes (compat hwcaps, memory leak, cpuset fallback path).
* Documentation for arm64. It's in the divisive .rst format, but please take a look anyway!
I'm pretty happy with this now and it seems to do the right thing, although the new patches in this revision would certainly benefit from review. Series based on v5.13-rc1.
Cheers,
Will
--->8
Will Deacon (21):
arm64: cpuinfo: Split AArch32 registers out into a separate struct
arm64: Allow mismatched 32-bit EL0 support
KVM: arm64: Kill 32-bit vCPUs on systems with mismatched EL0 support
arm64: Kill 32-bit applications scheduled on 64-bit-only CPUs
arm64: Advertise CPUs capable of running 32-bit applications in sysfs
sched: Introduce task_cpu_possible_mask() to limit fallback rq
selection
cpuset: Don't use the cpu_possible_mask as a last resort for cgroup v1
cpuset: Honour task_cpu_possible_mask() in guarantee_online_cpus()
sched: Reject CPU affinity changes based on task_cpu_possible_mask()
sched: Introduce task_struct::user_cpus_ptr to track requested
affinity
sched: Split the guts of sched_setaffinity() into a helper function
sched: Allow task CPU affinity to be restricted on asymmetric systems
sched: Admit forcefully-affined tasks into SCHED_DEADLINE
freezer: Add frozen_or_skipped() helper function
sched: Defer wakeup in ttwu() for unschedulable frozen tasks
arm64: Implement task_cpu_possible_mask()
arm64: exec: Adjust affinity for compat tasks with mismatched 32-bit
EL0
arm64: Prevent offlining first CPU with 32-bit EL0 on mismatched
system
arm64: Hook up cmdline parameter to allow mismatched 32-bit EL0
arm64: Remove logic to kill 32-bit tasks on 64-bit-only cores
Documentation: arm64: describe asymmetric 32-bit support
.../ABI/testing/sysfs-devices-system-cpu | 9 + .../admin-guide/kernel-parameters.txt | 11 + Documentation/arm64/asymmetric-32bit.rst | 149 ++++++++ Documentation/arm64/index.rst | 1 + arch/arm64/include/asm/cpu.h | 44 +-- arch/arm64/include/asm/cpucaps.h | 3 +- arch/arm64/include/asm/cpufeature.h | 8 +- arch/arm64/include/asm/mmu_context.h | 13 + arch/arm64/kernel/cpufeature.c | 227 +++++++++--- arch/arm64/kernel/cpuinfo.c | 53 +-- arch/arm64/kernel/process.c | 21 +- arch/arm64/kvm/arm.c | 11 +- include/linux/cpuset.h | 3 +- include/linux/freezer.h | 6 + include/linux/mmu_context.h | 8 + include/linux/sched.h | 15 + init/init_task.c | 1 + kernel/cgroup/cpuset.c | 45 ++- kernel/fork.c | 2 + kernel/freezer.c | 10 +- kernel/hung_task.c | 4 +- kernel/sched/core.c | 323 ++++++++++++++---- kernel/sched/sched.h | 1 + 23 files changed, 781 insertions(+), 187 deletions(-) create mode 100644 Documentation/arm64/asymmetric-32bit.rst
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 1/21 arm64: cpuinfo: Split AArch32 registers out into a separate struct
In preparation for late initialisation of the "sanitised" AArch32 register state, move the AArch32 registers out of 'struct cpuinfo' and into their own struct definition.
--- arch/arm64/include/asm/cpu.h | 44 +++++++++++---------- arch/arm64/kernel/cpufeature.c | 71 ++++++++++++++++++---------------- arch/arm64/kernel/cpuinfo.c | 53 +++++++++++++------------ 3 files changed, 89 insertions(+), 79 deletions(-)
arch/arm64/include/asm/cpu.h +24 -20
@@ -12,26 +12,7 @@/* * Records attributes of an individual CPU. */ -struct cpuinfo_arm64 { -struct cpu cpu; -struct kobject kobj; -u32 reg_ctr; -u32 reg_cntfrq; -u32 reg_dczid; -u32 reg_midr; -u32 reg_revidr; - -u64 reg_id_aa64dfr0; -u64 reg_id_aa64dfr1; -u64 reg_id_aa64isar0; -u64 reg_id_aa64isar1; -u64 reg_id_aa64mmfr0; -u64 reg_id_aa64mmfr1; -u64 reg_id_aa64mmfr2; -u64 reg_id_aa64pfr0; -u64 reg_id_aa64pfr1; -u64 reg_id_aa64zfr0; - +struct cpuinfo_32bit {u32 reg_id_dfr0;u32 reg_id_dfr1;u32 reg_id_isar0;
@@ -54,6 +35,29 @@ struct cpuinfo_arm64 {u32 reg_mvfr0;u32 reg_mvfr1;u32 reg_mvfr2; +}; + +struct cpuinfo_arm64 { +struct cpu cpu; +struct kobject kobj; +u32 reg_ctr; +u32 reg_cntfrq; +u32 reg_dczid; +u32 reg_midr; +u32 reg_revidr; + +u64 reg_id_aa64dfr0; +u64 reg_id_aa64dfr1; +u64 reg_id_aa64isar0; +u64 reg_id_aa64isar1; +u64 reg_id_aa64mmfr0; +u64 reg_id_aa64mmfr1; +u64 reg_id_aa64mmfr2; +u64 reg_id_aa64pfr0; +u64 reg_id_aa64pfr1; +u64 reg_id_aa64zfr0; + +struct cpuinfo_32bit aarch32;/* pseudo-ZCR for recording maximum ZCR_EL1 LEN value: */ u64 reg_zcr;
arch/arm64/kernel/cpufeature.c +37 -34
102 lines not on this page · raw message
arch/arm64/kernel/cpuinfo.c +28 -25
65 lines not on this page · raw message
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 2/21 arm64: Allow mismatched 32-bit EL0 support
In reply to Will DeaconWhen confronted with a mixture of CPUs, some of which support 32-bit applications and others which don't, we quite sensibly treat the system as 64-bit only for userspace and prevent execve() of 32-bit binaries.
Unfortunately, some crazy folks have decided to build systems like this with the intention of running 32-bit applications, so relax our sanitisation logic to continue to advertise 32-bit support to userspace on these systems and track the real 32-bit capable cores in a cpumask instead. For now, the default behaviour remains but will be tied to a command-line option in a later patch.
--- arch/arm64/include/asm/cpucaps.h | 3 +- arch/arm64/include/asm/cpufeature.h | 8 +- arch/arm64/kernel/cpufeature.c | 114 ++++++++++++++++++++++++---- 3 files changed, 110 insertions(+), 15 deletions(-)
arch/arm64/include/asm/cpucaps.h +2 -1
@@ -18,7 +18,8 @@#define ARM64_HAS_NO_HW_PREFETCH 8#define ARM64_HAS_VIRT_HOST_EXTN 11#define ARM64_WORKAROUND_CAVIUM_27456 12 -#define ARM64_HAS_32BIT_EL0 13 +/* Unreliable: use system_supports_32bit_el0() instead. */ +#define ARM64_HAS_32BIT_EL0_DO_NOT_USE 13#define ARM64_SPECTRE_V3A 14#define ARM64_HAS_CNP 15#define ARM64_HAS_NO_FPSIMD 16
arch/arm64/include/asm/cpufeature.h +7 -1
@@ -630,9 +630,15 @@ static inline bool cpu_supports_mixed_endian_el0(void)return id_aa64mmfr0_mixed_endian_el0 (read_cpuid (ID_AA64MMFR0_EL1 )); } +const struct cpumask *system_32bit_el0_cpumask (void ); +DECLARE_STATIC_KEY_FALSE (arm64_mismatched_32bit_el0); +static inline bool system_supports_32bit_el0 (void ) { -return cpus_have_const_cap (ARM64_HAS_32BIT_EL0 ); +u64 pfr0 =read_sanitised_ftr_reg (SYS_ID_AA64PFR0_EL1 ); + +return static_branch_unlikely (&arm64_mismatched_32bit_el0) || +id_aa64pfr0_32bit_el0 (pfr0); }static inline bool system_supports_4kb_granule (void )
arch/arm64/kernel/cpufeature.c +101 -13
193 lines not on this page · raw message
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 3/21 KVM: arm64: Kill 32-bit vCPUs on systems with mismatched EL0 support
In reply to Will DeaconIf a vCPU is caught running 32-bit code on a system with mismatched support at EL0, then we should kill it.
--- arch/arm64/kvm/arm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/arm64/kvm/arm.c +10 -1
@@ -692,6 +692,15 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) } } +static bool vcpu_mode_is_bad_32bit (struct kvm_vcpu *vcpu) +{ +if (likely (!vcpu_mode_is_32bit (vcpu))) +return false; + +return !system_supports_32bit_el0 () || +static_branch_unlikely (&arm64_mismatched_32bit_el0); +} +/** * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code * @vcpu: The VCPU pointer
@@ -875,7 +884,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)* with the asymmetric AArch32 case), return to userspace with * a fatal error. */ -if (!system_supports_32bit_el0 () &&vcpu_mode_is_32bit (vcpu)) { +if (vcpu_mode_is_bad_32bit (vcpu)) {/* * As we have caught the guest red-handed, decide that * it isn't fit for purpose anymore by making the vcpu
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 4/21 arm64: Kill 32-bit applications scheduled on 64-bit-only CPUs
In reply to Will DeaconScheduling a 32-bit application on a 64-bit-only CPU is a bad idea.
Ensure that 32-bit applications always take the slow-path when returning to userspace on a system with mismatched support at EL0, so that we can avoid trying to run on a 64-bit-only CPU and force a SIGKILL instead.
--- arch/arm64/kernel/process.c | 19 ++++++++++++++++++- arch/arm64/kernel/signal.c | 26 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-)
arch/arm64/kernel/process.c +18 -1
@@ -527,6 +527,15 @@ static void erratum_1418040_thread_switch(struct task_struct *prev,write_sysreg (val, cntkctl_el1); } +static void compat_thread_switch (struct task_struct *next) +{ +if (!is_compat_thread (task_thread_info (next))) +return ; + +if (static_branch_unlikely (&arm64_mismatched_32bit_el0)) +set_tsk_thread_flag (next,TIF_NOTIFY_RESUME ); +} +static void update_sctlr_el1 (u64 sctlr) {/*
@@ -568,6 +577,7 @@ __notrace_funcgraph struct task_struct *__switch_to(struct task_struct *prev,ssbs_thread_switch (next);erratum_1418040_thread_switch (prev, next);ptrauth_thread_switch_user (next); +compat_thread_switch (next);/* * Complete any pending TLB or cache maintenance on this CPU in case
@@ -633,8 +643,15 @@ unsigned long arch_align_stack(unsigned long sp)*/ void arch_setup_new_exec (void ) { - current->mm->context.flags =is_compat_task () ?MMCF_AARCH32 :0 ; +unsigned long mmflags =0 ; + +if (is_compat_task ()) { + mmflags =MMCF_AARCH32 ; +if (static_branch_unlikely (&arm64_mismatched_32bit_el0)) +set_tsk_thread_flag (current,TIF_NOTIFY_RESUME ); + } + current->mm->context.flags = mmflags;ptrauth_thread_init_user ();mte_thread_init_user ();
arch/arm64/kernel/signal.c +26 -0
@@ -911,6 +911,19 @@ static void do_signal(struct pt_regs *regs)restore_saved_sigmask (); } +static bool cpu_affinity_invalid (struct pt_regs *regs) +{ +if (!compat_user_mode (regs)) +return false; + +/* +* We're preemptible, but a reschedule will cause us to check the +* affinity again. +*/ +return !cpumask_test_cpu (raw_smp_processor_id (), +system_32bit_el0_cpumask ()); +} + asmlinkage void do_notify_resume(struct pt_regs *regs,unsigned long thread_flags) {
@@ -938,6 +951,19 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,if (thread_flags & _TIF_NOTIFY_RESUME) {tracehook_notify_resume (regs);rseq_handle_notify_resume (NULL , regs); + +/* +* If we reschedule after checking the affinity +* then we must ensure that TIF_NOTIFY_RESUME +* is set so that we check the affinity again. +* Since tracehook_notify_resume() clears the +* flag, ensure that the compiler doesn't move +* it after the affinity check. +*/ +barrier (); + +if (cpu_affinity_invalid (regs)) +force_sig (SIGKILL ); }if (thread_flags & _TIF_FOREIGN_FPSTATE)
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 5/21 arm64: Advertise CPUs capable of running 32-bit applications in sysfs
In reply to Will DeaconSince 32-bit applications will be killed if they are caught trying to execute on a 64-bit-only CPU in a mismatched system, advertise the set of 32-bit capable CPUs to userspace in sysfs.
--- .../ABI/testing/sysfs-devices-system-cpu | 9 +++++++++ arch/arm64/kernel/cpufeature.c | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+)
Documentation/ABI/testing/sysfs-devices-system-cpu +9 -0
@@ -494,6 +494,15 @@ Description: AArch64 CPU registers 'identification' directory exposes the CPU ID registers for identifying model and revision of the CPU. +What: /sys/devices/system/cpu/aarch32_el0 +Date: May 2021 +Contact: Linux ARM Kernel Mailing list <[email protected]> +Description: Identifies the subset of CPUs in the system that can execute + AArch32 (32-bit ARM) applications. If present, the same format as + /sys/devices/system/cpu/{offline,online,possible,present} is used. + If absent, then all or none of the CPUs can execute AArch32 + applications and execve() will behave accordingly. + What: /sys/devices/system/cpu/cpu#/cpu_capacity Date: December 2016 Contact: Linux kernel mailing list <[email protected]>
arch/arm64/kernel/cpufeature.c +19 -0
@@ -67,6 +67,7 @@#include <linux/crash_dump.h> #include <linux/sort.h> #include <linux/stop_machine.h> +#include <linux/sysfs.h> #include <linux/types.h> #include <linux/minmax.h> #include <linux/mm.h>
@@ -1297,6 +1298,24 @@ const struct cpumask *system_32bit_el0_cpumask(void)return cpu_possible_mask; } +static ssize_t aarch32_el0_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +const struct cpumask *mask =system_32bit_el0_cpumask (); + +return sysfs_emit (buf,"%*pbl\n" ,cpumask_pr_args (mask)); +} +static const DEVICE_ATTR_RO (aarch32_el0); + +static int __init aarch32_el0_sysfs_init (void ) +{ +if (!allow_mismatched_32bit_el0) +return 0 ; + +return device_create_file (cpu_subsys.dev_root, &dev_attr_aarch32_el0); +} +device_initcall (aarch32_el0_sysfs_init); +static bool has_32bit_el0 (const struct arm64_cpu_capabilities *entry,int scope) {if (!has_cpuid_feature (entry, scope))
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 6/21 sched: Introduce task_cpu_possible_mask() to limit fallback rq selection
In reply to Will DeaconAsymmetric systems may not offer the same level of userspace ISA support across all CPUs, meaning that some applications cannot be executed by some CPUs. As a concrete example, upcoming arm64 big.LITTLE designs do not feature support for 32-bit applications on both clusters.
On such a system, we must take care not to migrate a task to an unsupported CPU when forcefully moving tasks in select_fallback_rq() in response to a CPU hot-unplug operation.
Introduce a task_cpu_possible_mask() hook which, given a task argument, allows an architecture to return a cpumask of CPUs that are capable of executing that task. The default implementation returns the cpu_possible_mask, since sane machines do not suffer from per-cpu ISA limitations that affect scheduling. The new mask is used when selecting the fallback runqueue as a last resort before forcing a migration to the first active CPU.
--- include/linux/mmu_context.h | 8 ++++++++ kernel/sched/core.c | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-)
include/linux/mmu_context.h +8 -0
@@ -14,4 +14,12 @@static inline void leave_mm (int cpu) { }#endif +/* +* CPUs that are capable of running task @p. By default, we assume a sane, +* homogeneous system. Must contain at least one active CPU. +*/ +#ifndef task_cpu_possible_mask +# define task_cpu_possible_mask (p) cpu_possible_mask +#endif +#endif
kernel/sched/core.c +6 -4
@@ -1813,8 +1813,11 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu)return cpu_online (cpu);/* Non kernel threads are not allowed during either online or offline. */ -if (!(p->flags &PF_KTHREAD )) -return cpu_active (cpu); +if (!(p->flags &PF_KTHREAD )) { +if (cpu_active (cpu)) +return cpumask_test_cpu (cpu,task_cpu_possible_mask (p)); +return false; + }/* KTHREAD_IS_PER_CPU is always allowed. */ if (kthread_is_per_cpu (p))
@@ -2792,10 +2795,9 @@ static int select_fallback_rq(int cpu, struct task_struct *p)* * More yuck to audit. */ -do_set_cpus_allowed (p, cpu_possible_mask); +do_set_cpus_allowed (p,task_cpu_possible_mask (p)); state = fail;break ; -case fail:BUG ();break ;
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 7/21 cpuset: Don't use the cpu_possible_mask as a last resort for cgroup v1
In reply to Will DeaconIf the scheduler cannot find an allowed CPU for a task, cpuset_cpus_allowed_fallback() will widen the affinity to cpu_possible_mask if cgroup v1 is in use.
In preparation for allowing architectures to provide their own fallback mask, just return early if we're either using cgroup v1 or we're using cgroup v2 with a mask that contains invalid CPUs. This will allow select_fallback_rq() to figure out the mask by itself.
--- include/linux/cpuset.h | 1 + kernel/cgroup/cpuset.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
include/linux/cpuset.h +1 -0
@@ -15,6 +15,7 @@#include <linux/cpumask.h> #include <linux/nodemask.h> #include <linux/mm.h> +#include <linux/mmu_context.h> #include <linux/jump_label.h> #ifdef CONFIG_CPUSETS
kernel/cgroup/cpuset.c +10 -2
@@ -3322,9 +3322,17 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)void cpuset_cpus_allowed_fallback (struct task_struct *tsk) { +const struct cpumask *cs_mask; +const struct cpumask *possible_mask =task_cpu_possible_mask (tsk); +rcu_read_lock (); -do_set_cpus_allowed (tsk,is_in_v2_mode () ? -task_cs (tsk)->cpus_allowed : cpu_possible_mask); + cs_mask =task_cs (tsk)->cpus_allowed; + +if (!is_in_v2_mode () || !cpumask_subset (cs_mask, possible_mask)) + goto unlock;/* select_fallback_rq will try harder */ + +do_set_cpus_allowed (tsk, cs_mask); +unlock:rcu_read_unlock ();/*
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 8/21 cpuset: Honour task_cpu_possible_mask() in guarantee_online_cpus()
In reply to Will DeaconAsymmetric systems may not offer the same level of userspace ISA support across all CPUs, meaning that some applications cannot be executed by some CPUs. As a concrete example, upcoming arm64 big.LITTLE designs do not feature support for 32-bit applications on both clusters.
Modify guarantee_online_cpus() to take task_cpu_possible_mask() into account when trying to find a suitable set of online CPUs for a given task. This will avoid passing an invalid mask to set_cpus_allowed_ptr() during ->attach() and will subsequently allow the cpuset hierarchy to be taken into account when forcefully overriding the affinity mask for a task which requires migration to a compatible CPU.
--- include/linux/cpuset.h | 2 +- kernel/cgroup/cpuset.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-)
include/linux/cpuset.h +1 -1
@@ -185,7 +185,7 @@ static inline void cpuset_read_unlock(void) { }static inline void cpuset_cpus_allowed (struct task_struct *p,struct cpumask *mask) { -cpumask_copy (mask, cpu_possible_mask); +cpumask_copy (mask,task_cpu_possible_mask (p)); }static inline void cpuset_cpus_allowed_fallback (struct task_struct *p)
kernel/cgroup/cpuset.c +19 -14
@@ -372,18 +372,26 @@ static inline bool is_in_v2_mode(void) }/* -* Return in pmask the portion of a cpusets's cpus_allowed that -* are online. If none are online, walk up the cpuset hierarchy -* until we find one that does have some online cpus. +* Return in pmask the portion of a task's cpusets's cpus_allowed that +* are online and are capable of running the task. If none are found, +* walk up the cpuset hierarchy until we find one that does have some +* appropriate cpus. * * One way or another, we guarantee to return some non-empty subset * of cpu_online_mask. * * Call with callback_lock or cpuset_mutex held. */ -static void guarantee_online_cpus (struct cpuset *cs,struct cpumask *pmask) +static void guarantee_online_cpus (struct task_struct *tsk, +struct cpumask *pmask) { -while (!cpumask_intersects (cs->effective_cpus, cpu_online_mask)) { +struct cpuset *cs =task_cs (tsk); +const struct cpumask *possible_mask =task_cpu_possible_mask (tsk); + +if (WARN_ON (!cpumask_and (pmask, possible_mask, cpu_online_mask))) +cpumask_copy (pmask, cpu_online_mask); + +while (!cpumask_intersects (cs->effective_cpus, pmask)) { cs =parent_cs (cs);if (unlikely (!cs)) {/*
@@ -393,11 +401,10 @@ static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask)* cpuset's effective_cpus is on its way to be * identical to cpu_online_mask. */ -cpumask_copy (pmask, cpu_online_mask);return ; } } -cpumask_and (pmask, cs->effective_cpus, cpu_online_mask); +cpumask_and (pmask, pmask, cs->effective_cpus); }/*
@@ -2199,15 +2206,13 @@ static void cpuset_attach(struct cgroup_taskset *tset)percpu_down_write (&cpuset_rwsem); -/* prepare for attach */ -if (cs == &top_cpuset) -cpumask_copy (cpus_attach, cpu_possible_mask); -else -guarantee_online_cpus (cs, cpus_attach); -guarantee_online_mems (cs, &cpuset_attach_nodemask_to);cgroup_taskset_for_each (task, css, tset) { +if (cs != &top_cpuset) +guarantee_online_cpus (task, cpus_attach); +else +cpumask_copy (cpus_attach,task_cpu_possible_mask (task));/* * can_attach beforehand should guarantee that this doesn't * fail. TODO: have a better way to handle failure here
@@ -3303,7 +3308,7 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)spin_lock_irqsave (&callback_lock, flags);rcu_read_lock (); -guarantee_online_cpus (task_cs (tsk), pmask); +guarantee_online_cpus (tsk, pmask);rcu_read_unlock ();spin_unlock_irqrestore (&callback_lock, flags); }
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 9/21 sched: Reject CPU affinity changes based on task_cpu_possible_mask()
In reply to Will DeaconReject explicit requests to change the affinity mask of a task via set_cpus_allowed_ptr() if the requested mask is not a subset of the mask returned by task_cpu_possible_mask(). This ensures that the 'cpus_mask' for a given task cannot contain CPUs which are incapable of executing it, except in cases where the affinity is forced.
--- kernel/sched/core.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/sched/core.c +4 -0
@@ -2350,6 +2350,7 @@ static int __set_cpus_allowed_ptr(struct task_struct *p, u32 flags) {const struct cpumask *cpu_valid_mask = cpu_active_mask; +const struct cpumask *cpu_allowed_mask =task_cpu_possible_mask (p);unsigned int dest_cpu;struct rq_flags rf;struct rq *rq;
@@ -2370,6 +2371,9 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,* set_cpus_allowed_common() and actually reset p->cpus_ptr. */ cpu_valid_mask = cpu_online_mask; + }else if (!cpumask_subset (new_mask, cpu_allowed_mask)) { + ret = -EINVAL ; + goto out; }/*
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 10/21 sched: Introduce task_struct::user_cpus_ptr to track requested affinity
In reply to Will DeaconIn preparation for saving and restoring the user-requested CPU affinity mask of a task, add a new cpumask_t pointer to 'struct task_struct'.
If the pointer is non-NULL, then the mask is copied across fork() and freed on task exit.
--- include/linux/sched.h | 13 +++++++++++++ init/init_task.c | 1 + kernel/fork.c | 2 ++ kernel/sched/core.c | 20 ++++++++++++++++++++ 4 files changed, 36 insertions(+)
include/linux/sched.h +13 -0
@@ -730,6 +730,7 @@ struct task_struct {unsigned int policy;int nr_cpus_allowed;const cpumask_t *cpus_ptr; +cpumask_t *user_cpus_ptr;cpumask_t cpus_mask;void *migration_pending;#ifdef CONFIG_SMP
@@ -1688,6 +1689,8 @@ extern int task_can_attach(struct task_struct *p, const struct cpumask *cs_cpus_#ifdef CONFIG_SMP extern void do_set_cpus_allowed (struct task_struct *p,const struct cpumask *new_mask);extern int set_cpus_allowed_ptr (struct task_struct *p,const struct cpumask *new_mask); +extern int dup_user_cpus_ptr (struct task_struct *dst,struct task_struct *src,int node); +extern void release_user_cpus_ptr (struct task_struct *p);#else static inline void do_set_cpus_allowed (struct task_struct *p,const struct cpumask *new_mask) {
@@ -1698,6 +1701,16 @@ static inline int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumareturn -EINVAL ; return 0; } +static inline int dup_user_cpus_ptr (struct task_struct *dst,struct task_struct *src,int node) +{ +if (src->user_cpus_ptr) +return -EINVAL ; +return 0 ; +} +static inline void release_user_cpus_ptr (struct task_struct *p) +{ +WARN_ON (p->user_cpus_ptr); +}#endif extern int yield_to (struct task_struct *p,bool preempt);
init/init_task.c +1 -0
@@ -80,6 +80,7 @@ struct task_struct init_task .normal_prio = MAX_PRIO - 20, .policy = SCHED_NORMAL, .cpus_ptr = &init_task.cpus_mask, + .user_cpus_ptr = NULL, .cpus_mask = CPU_MASK_ALL, .nr_cpus_allowed= NR_CPUS, .mm = NULL,
kernel/fork.c +2 -0
@@ -446,6 +446,7 @@ void put_task_stack(struct task_struct *tsk)void free_task (struct task_struct *tsk) { +release_user_cpus_ptr (tsk);scs_release (tsk);#ifndef CONFIG_THREAD_INFO_IN_TASK
@@ -918,6 +919,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)#endif if (orig->cpus_ptr == &orig->cpus_mask) tsk->cpus_ptr = &tsk->cpus_mask; +dup_user_cpus_ptr (tsk, orig, node);/* * One for the user space visible state that goes away when reaped.
kernel/sched/core.c +20 -0
@@ -2129,6 +2129,26 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)__do_set_cpus_allowed (p, new_mask,0 ); } +int dup_user_cpus_ptr (struct task_struct *dst,struct task_struct *src, +int node) +{ +if (!src->user_cpus_ptr) +return 0 ; + + dst->user_cpus_ptr =kmalloc_node (cpumask_size (),GFP_KERNEL , node); +if (!dst->user_cpus_ptr) +return -ENOMEM ; + +cpumask_copy (dst->user_cpus_ptr, src->user_cpus_ptr); +return 0 ; +} + +void release_user_cpus_ptr (struct task_struct *p) +{ +kfree (p->user_cpus_ptr); + p->user_cpus_ptr =NULL ; +} +/* * This function is wildly self concurrent; here be dragons. *
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 11/21 sched: Split the guts of sched_setaffinity() into a helper function
In reply to Will DeaconIn preparation for replaying user affinity requests using a saved mask, split sched_setaffinity() up so that the initial task lookup and security checks are only performed when the request is coming directly from userspace.
--- kernel/sched/core.c | 110 +++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 52 deletions(-)
kernel/sched/core.c +58 -52
@@ -6788,9 +6788,61 @@ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,return retval; } -long sched_setaffinity (pid_t pid,const struct cpumask *in_mask) +static int +__sched_setaffinity (struct task_struct *p,const struct cpumask *mask) { +int retval;cpumask_var_t cpus_allowed, new_mask; + +if (!alloc_cpumask_var (&cpus_allowed,GFP_KERNEL )) +return -ENOMEM ; + +if (!alloc_cpumask_var (&new_mask,GFP_KERNEL )) +return -ENOMEM ; + +cpuset_cpus_allowed (p, cpus_allowed); +cpumask_and (new_mask, mask, cpus_allowed); + +/* +* Since bandwidth control happens on root_domain basis, +* if admission test is enabled, we only admit -deadline +* tasks allowed to run on all the CPUs in the task's +* root_domain. +*/ +#ifdef CONFIG_SMP +if (task_has_dl_policy (p) &&dl_bandwidth_enabled ()) { +rcu_read_lock (); +if (!cpumask_subset (task_rq (p)->rd->span, new_mask)) { + retval = -EBUSY ; +rcu_read_unlock (); + goto out_free_masks; + } +rcu_read_unlock (); + } +#endif +again: + retval =__set_cpus_allowed_ptr (p, new_mask,SCA_CHECK ); +if (retval) + goto out_free_masks; + +cpuset_cpus_allowed (p, cpus_allowed); +if (!cpumask_subset (new_mask, cpus_allowed)) { +/* +* We must have raced with a concurrent cpuset update. +* Just reset the cpumask to the cpuset's cpus_allowed. +*/ +cpumask_copy (new_mask, cpus_allowed); + goto again; + } + +out_free_masks: +free_cpumask_var (new_mask); +free_cpumask_var (cpus_allowed); +return retval; +} + +long sched_setaffinity (pid_t pid,const struct cpumask *in_mask) +{struct task_struct *p;int retval;
@@ -6810,68 +6862,22 @@ long sched_setaffinity(pid_t pid, const struct cpumask *in_mask) retval = -EINVAL ; goto out_put_task; } -if (!alloc_cpumask_var (&cpus_allowed,GFP_KERNEL )) { - retval = -ENOMEM ; - goto out_put_task; - } -if (!alloc_cpumask_var (&new_mask,GFP_KERNEL )) { - retval = -ENOMEM ; - goto out_free_cpus_allowed; - } - retval = -EPERM ; +if (!check_same_owner (p)) {rcu_read_lock ();if (!ns_capable (__task_cred (p)->user_ns,CAP_SYS_NICE )) {rcu_read_unlock (); - goto out_free_new_mask; + retval = -EPERM ; + goto out_put_task; }rcu_read_unlock (); } retval =security_task_setscheduler (p);if (retval) - goto out_free_new_mask; - - -cpuset_cpus_allowed (p, cpus_allowed); -cpumask_and (new_mask, in_mask, cpus_allowed); - -/* -* Since bandwidth control happens on root_domain basis, -* if admission test is enabled, we only admit -deadline -* tasks allowed to run on all the CPUs in the task's -* root_domain. -*/ -#ifdef CONFIG_SMP -if (task_has_dl_policy (p) &&dl_bandwidth_enabled ()) { -rcu_read_lock (); -if (!cpumask_subset (task_rq (p)->rd->span, new_mask)) { - retval = -EBUSY ; -rcu_read_unlock (); - goto out_free_new_mask; - } -rcu_read_unlock (); - } -#endif -again: - retval =__set_cpus_allowed_ptr (p, new_mask,SCA_CHECK ); + goto out_put_task; -if (!retval) { -cpuset_cpus_allowed (p, cpus_allowed); -if (!cpumask_subset (new_mask, cpus_allowed)) { -/* -* We must have raced with a concurrent cpuset -* update. Just reset the cpus_allowed to the -* cpuset's cpus_allowed -*/ -cpumask_copy (new_mask, cpus_allowed); - goto again; - } - } -out_free_new_mask: -free_cpumask_var (new_mask); -out_free_cpus_allowed: -free_cpumask_var (cpus_allowed); + retval =__sched_setaffinity (p, in_mask); out_put_task:put_task_struct (p);return retval;
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 12/21 sched: Allow task CPU affinity to be restricted on asymmetric systems
In reply to Will DeaconAsymmetric systems may not offer the same level of userspace ISA support across all CPUs, meaning that some applications cannot be executed by some CPUs. As a concrete example, upcoming arm64 big.LITTLE designs do not feature support for 32-bit applications on both clusters.
Although userspace can carefully manage the affinity masks for such tasks, one place where it is particularly problematic is execve() because the CPU on which the execve() is occurring may be incompatible with the new application image. In such a situation, it is desirable to restrict the affinity mask of the task and ensure that the new image is entered on a compatible CPU. From userspace's point of view, this looks the same as if the incompatible CPUs have been hotplugged off in the task's affinity mask. Similarly, if a subsequent execve() reverts to a compatible image, then the old affinity is restored if it is still valid.
In preparation for restricting the affinity mask for compat tasks on arm64 systems without uniform support for 32-bit applications, introduce {force,relax}_compatible_cpus_allowed_ptr(), which respectively restrict and restore the affinity mask for a task based on the compatible CPUs.
--- include/linux/sched.h | 2 + kernel/sched/core.c | 165 ++++++++++++++++++++++++++++++++++++++---- kernel/sched/sched.h | 1 + 3 files changed, 152 insertions(+), 16 deletions(-)
include/linux/sched.h +2 -0
@@ -1691,6 +1691,8 @@ extern void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *newextern int set_cpus_allowed_ptr (struct task_struct *p,const struct cpumask *new_mask);extern int dup_user_cpus_ptr (struct task_struct *dst,struct task_struct *src,int node);extern void release_user_cpus_ptr (struct task_struct *p); +extern void force_compatible_cpus_allowed_ptr (struct task_struct *p); +extern void relax_compatible_cpus_allowed_ptr (struct task_struct *p);#else static inline void do_set_cpus_allowed (struct task_struct *p,const struct cpumask *new_mask) {
kernel/sched/core.c +149 -16
202 lines not on this page · raw message
kernel/sched/sched.h +1 -0
@@ -1956,6 +1956,7 @@ extern struct task_struct *pick_next_task_idle(struct rq *rq);#define SCA_CHECK 0x01#define SCA_MIGRATE_DISABLE 0x02#define SCA_MIGRATE_ENABLE 0x04 +#define SCA_USER 0x08#ifdef CONFIG_SMP
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 13/21 sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Will DeaconOn asymmetric systems where the affinity of a task is restricted to contain only the CPUs capable of running it, admission to the deadline scheduler is likely to fail because the span of the sched domain contains incompatible CPUs. Although this is arguably the right thing to do, it is inconsistent with the case where the affinity of a task is restricted after already having been admitted to the deadline scheduler.
For example, on an arm64 system where not all CPUs support 32-bit applications, a 64-bit deadline task can exec() a 32-bit image and have its affinity forcefully restricted.
Rather than reject these tasks altogether, favour the requested user affinity saved in 'task_struct::user_cpus_ptr' over the actual affinity of the task which has been restricted by the kernel.
--- kernel/sched/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/core.c +2 -1
@@ -6403,13 +6403,14 @@ static int __sched_setscheduler(struct task_struct *p,if (dl_bandwidth_enabled () &&dl_policy (policy) && !(attr->sched_flags &SCHED_FLAG_SUGOV )) {cpumask_t *span = rq->rd->span; +const cpumask_t *aff = p->user_cpus_ptr ?: p->cpus_ptr;/* * Don't allow tasks with an affinity mask smaller than * the entire root_domain to become SCHED_DEADLINE. We * will also fail if there's no bandwidth available. */ -if (!cpumask_subset (span, p->cpus_ptr) || +if (!cpumask_subset (span, aff) || rq->rd->dl_bw.bw ==0 ) { retval = -EPERM ; goto unlock;
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 14/21 freezer: Add frozen_or_skipped() helper function
In reply to Will DeaconOccasionally it is necessary to see if a task is either frozen or sleeping in the PF_FREEZER_SKIP state. In preparation for adding additional users of this check, introduce a frozen_or_skipped() helper function and convert the hung task detector over to using it.
--- include/linux/freezer.h | 6 ++++++ kernel/hung_task.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-)
include/linux/freezer.h +6 -0
@@ -27,6 +27,11 @@ static inline bool frozen(struct task_struct *p)return p->flags &PF_FROZEN ; } +static inline bool frozen_or_skipped (struct task_struct *p) +{ +return p->flags & (PF_FROZEN |PF_FREEZER_SKIP ); +} +extern bool freezing_slow_path (struct task_struct *p);/*
@@ -270,6 +275,7 @@ static inline int freezable_schedule_hrtimeout_range(ktime_t *expires,#else /* !CONFIG_FREEZER */ static inline bool frozen (struct task_struct *p) {return false; } +static inline bool frozen_or_skipped (struct task_struct *p) {return false; }static inline bool freezing (struct task_struct *p) {return false; }static inline void __thaw_task (struct task_struct *t) {}
kernel/hung_task.c +2 -2
@@ -92,8 +92,8 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)* Ensure the task is not frozen. * Also, skip vfork and any other user process that freezer should skip. */ -if (unlikely (t->flags & (PF_FROZEN |PF_FREEZER_SKIP ))) -return ; +if (unlikely (frozen_or_skipped (t))) +return ;/* * When a freshly created task is scheduled once, changes its state to
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 16/21 arm64: Implement task_cpu_possible_mask()
In reply to Will DeaconProvide an implementation of task_cpu_possible_mask() so that we can prevent 64-bit-only cores being added to the 'cpus_mask' for compat tasks on systems with mismatched 32-bit support at EL0,
--- arch/arm64/include/asm/mmu_context.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm64/include/asm/mmu_context.h +13 -0
@@ -231,6 +231,19 @@ switch_mm(struct mm_struct *prev, struct mm_struct *next,update_saved_ttbr0 (tsk, next); } +static inline const struct cpumask * +task_cpu_possible_mask (struct task_struct *p) +{ +if (!static_branch_unlikely (&arm64_mismatched_32bit_el0)) +return cpu_possible_mask; + +if (!is_compat_thread (task_thread_info (p))) +return cpu_possible_mask; + +return system_32bit_el0_cpumask (); +} +#define task_cpu_possible_mask task_cpu_possible_mask +void verify_cpu_asid_bits (void );void post_ttbr_update_workaround (void );
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 15/21 sched: Defer wakeup in ttwu() for unschedulable frozen tasks
In reply to Will DeaconAsymmetric systems may not offer the same level of userspace ISA support across all CPUs, meaning that some applications cannot be executed by some CPUs. As a concrete example, upcoming arm64 big.LITTLE designs do not feature support for 32-bit applications on both clusters.
Although we take care to prevent explicit hot-unplug of all 32-bit capable CPUs on such a system, this is required when suspending on some SoCs where the firmware mandates that the suspend/resume operation is handled by CPU 0, which may not be capable of running 32-bit tasks.
Consequently, there is a window on the resume path where no 32-bit capable CPUs are available for scheduling and waking up a 32-bit task will result in a scheduler BUG() due to failure of select_fallback_rq():
| kernel BUG at kernel/sched/core.c:2858! | Internal error: Oops - BUG: 0 [#1] PREEMPT SMP | ... | Call trace: | select_fallback_rq+0x4b0/0x4e4 | try_to_wake_up.llvm.4388853297126348405+0x460/0x5b0 | default_wake_function+0x1c/0x30 | autoremove_wake_function+0x1c/0x60 | __wake_up_common.llvm.11763074518265335900+0x100/0x1b8 | __wake_up+0x78/0xc4 | ep_poll_callback+0x20c/0x3fc
Prevent wakeups of unschedulable frozen tasks in ttwu() and instead defer the wakeup to __thaw_tasks(), which runs only once all the secondary CPUs are back online.
--- kernel/freezer.c | 10 +++++++++- kernel/sched/core.c | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
kernel/freezer.c +9 -1
@@ -11,6 +11,7 @@#include <linux/syscalls.h> #include <linux/freezer.h> #include <linux/kthread.h> +#include <linux/mmu_context.h> /* total number of freezing conditions in effect */ atomic_t system_freezing_cnt =ATOMIC_INIT (0 );
@@ -146,9 +147,16 @@ bool freeze_task(struct task_struct *p)void __thaw_task (struct task_struct *p) {unsigned long flags; +const struct cpumask *mask =task_cpu_possible_mask (p);spin_lock_irqsave (&freezer_lock, flags); -if (frozen (p)) +/* +* Wake up frozen tasks. On asymmetric systems where tasks cannot +* run on all CPUs, ttwu() may have deferred a wakeup generated +* before thaw_secondary_cpus() had completed so we generate +* additional wakeups here for tasks in the PF_FREEZER_SKIP state. +*/ +if (frozen (p) || (frozen_or_skipped (p) && mask != cpu_possible_mask))wake_up_process (p);spin_unlock_irqrestore (&freezer_lock, flags); }
kernel/sched/core.c +13 -0
@@ -3525,6 +3525,19 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)if (!(p->state & state)) goto unlock; +#ifdef CONFIG_FREEZER +/* +* If we're going to wake up a thread which may be frozen, then +* we can only do so if we have an active CPU which is capable of +* running it. This may not be the case when resuming from suspend, +* as the secondary CPUs may not yet be back online. See __thaw_task() +* for the actual wakeup. +*/ +if (unlikely (frozen_or_skipped (p)) && + !cpumask_intersects (cpu_active_mask,task_cpu_possible_mask (p))) + goto unlock; +#endif +trace_sched_waking (p);/* We're going to change ->state: */
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 17/21 arm64: exec: Adjust affinity for compat tasks with mismatched 32-bit EL0
In reply to Will DeaconWhen 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.
--- arch/arm64/kernel/process.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
arch/arm64/kernel/process.c +15 -1
@@ -647,8 +647,22 @@ void arch_setup_new_exec(void)if (is_compat_task ()) { mmflags =MMCF_AARCH32 ; -if (static_branch_unlikely (&arm64_mismatched_32bit_el0)) + +/* +* 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);set_tsk_thread_flag (current,TIF_NOTIFY_RESUME ); + } + }else if (static_branch_unlikely (&arm64_mismatched_32bit_el0)) { +relax_compatible_cpus_allowed_ptr (current); } current->mm->context.flags = mmflags;
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 18/21 arm64: Prevent offlining first CPU with 32-bit EL0 on mismatched system
In reply to Will DeaconIf we want to support 32-bit applications, then when we identify a CPU with mismatched 32-bit EL0 support we must ensure that we will always have an active 32-bit CPU available to us from then on. This is important for the scheduler, because is_cpu_allowed() will be constrained to 32-bit CPUs for compat tasks and forced migration due to a hotplug event will hang if no 32-bit CPUs are available.
On detecting a mismatch, prevent offlining of either the mismatching CPU if it is 32-bit capable, or find the first active 32-bit capable CPU otherwise.
--- arch/arm64/kernel/cpufeature.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
arch/arm64/kernel/cpufeature.c +19 -1
@@ -2896,15 +2896,33 @@ void __init setup_cpu_features(void)static int enable_mismatched_32bit_el0 (unsigned int cpu) { +static int lucky_winner =-1 ; +struct cpuinfo_arm64 *info = &per_cpu (cpu_data, cpu);bool cpu_32bit =id_aa64pfr0_32bit_el0 (info->reg_id_aa64pfr0);if (cpu_32bit) {cpumask_set_cpu (cpu, cpu_32bit_el0_mask);static_branch_enable_cpuslocked (&arm64_mismatched_32bit_el0); -setup_elf_hwcaps (compat_elf_hwcaps); } +if (cpumask_test_cpu (0 , cpu_32bit_el0_mask) == cpu_32bit) +return 0 ; + +if (lucky_winner >=0 ) +return 0 ; + +/* +* We've detected a mismatch. We need to keep one of our CPUs with +* 32-bit EL0 online so that is_cpu_allowed() doesn't end up rejecting +* every CPU in the system for a 32-bit task. +*/ + lucky_winner = cpu_32bit ? cpu :cpumask_any_and (cpu_32bit_el0_mask, + cpu_active_mask); +get_cpu_device (lucky_winner)->offline_disabled = true; +setup_elf_hwcaps (compat_elf_hwcaps); +pr_info ("Asymmetric 32-bit EL0 support detected on CPU %u; CPU hot-unplug disabled on CPU %u\n" , + cpu, lucky_winner);return 0 ; }
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 19/21 arm64: Hook up cmdline parameter to allow mismatched 32-bit EL0
In reply to Will DeaconAllow systems with mismatched 32-bit support at EL0 to run 32-bit applications based on a new kernel parameter.
--- Documentation/admin-guide/kernel-parameters.txt | 8 ++++++++ arch/arm64/kernel/cpufeature.c | 7 +++++++ 2 files changed, 15 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +8 -0
@@ -287,6 +287,14 @@ do not want to use tracing_snapshot_alloc() as it needs to be done where GFP_KERNEL allocations are allowed. + allow_mismatched_32bit_el0 [ARM64] + Allow execve() of 32-bit applications and setting of the + PER_LINUX32 personality on systems where only a strict + subset of the CPUs support 32-bit EL0. When this + parameter is present, the set of CPUs supporting 32-bit + EL0 is indicated by /sys/devices/system/cpu/aarch32_el0 + and hot-unplug operations may be restricted. + amd_iommu= [HW,X86-64] Pass parameters to the AMD IOMMU driver in the system. Possible values are:
arch/arm64/kernel/cpufeature.c +7 -0
@@ -1298,6 +1298,13 @@ const struct cpumask *system_32bit_el0_cpumask(void)return cpu_possible_mask; } +static int __init parse_32bit_el0_param (char *str) +{ + allow_mismatched_32bit_el0 = true; +return 0 ; +} +early_param ("allow_mismatched_32bit_el0" , parse_32bit_el0_param); +static ssize_t aarch32_el0_show (struct device *dev,struct device_attribute *attr,char *buf) {
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 20/21 arm64: Remove logic to kill 32-bit tasks on 64-bit-only cores
In reply to Will DeaconThe scheduler now knows enough about these braindead systems to place 32-bit tasks accordingly, so throw out the safety checks and allow the ret-to-user path to avoid do_notify_resume() if there is nothing to do.
--- arch/arm64/kernel/process.c | 14 +------------- arch/arm64/kernel/signal.c | 26 -------------------------- 2 files changed, 1 insertion(+), 39 deletions(-)
arch/arm64/kernel/process.c +1 -13
@@ -527,15 +527,6 @@ static void erratum_1418040_thread_switch(struct task_struct *prev,write_sysreg (val, cntkctl_el1); } -static void compat_thread_switch (struct task_struct *next) -{ -if (!is_compat_thread (task_thread_info (next))) -return ; - -if (static_branch_unlikely (&arm64_mismatched_32bit_el0)) -set_tsk_thread_flag (next,TIF_NOTIFY_RESUME ); -} -static void update_sctlr_el1 (u64 sctlr) {/*
@@ -577,7 +568,6 @@ __notrace_funcgraph struct task_struct *__switch_to(struct task_struct *prev,ssbs_thread_switch (next);erratum_1418040_thread_switch (prev, next);ptrauth_thread_switch_user (next); -compat_thread_switch (next);/* * Complete any pending TLB or cache maintenance on this CPU in case
@@ -657,10 +647,8 @@ void arch_setup_new_exec(void)* at the point of execve(), although we try a bit harder to * honour the cpuset hierarchy. */ -if (static_branch_unlikely (&arm64_mismatched_32bit_el0)) { +if (static_branch_unlikely (&arm64_mismatched_32bit_el0))force_compatible_cpus_allowed_ptr (current); -set_tsk_thread_flag (current,TIF_NOTIFY_RESUME ); - } }else if (static_branch_unlikely (&arm64_mismatched_32bit_el0)) {relax_compatible_cpus_allowed_ptr (current); }
arch/arm64/kernel/signal.c +0 -26
@@ -911,19 +911,6 @@ static void do_signal(struct pt_regs *regs)restore_saved_sigmask (); } -static bool cpu_affinity_invalid (struct pt_regs *regs) -{ -if (!compat_user_mode (regs)) -return false; - -/* -* We're preemptible, but a reschedule will cause us to check the -* affinity again. -*/ -return !cpumask_test_cpu (raw_smp_processor_id (), -system_32bit_el0_cpumask ()); -} - asmlinkage void do_notify_resume(struct pt_regs *regs,unsigned long thread_flags) {
@@ -951,19 +938,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,if (thread_flags & _TIF_NOTIFY_RESUME) {tracehook_notify_resume (regs);rseq_handle_notify_resume (NULL , regs); - -/* -* If we reschedule after checking the affinity -* then we must ensure that TIF_NOTIFY_RESUME -* is set so that we check the affinity again. -* Since tracehook_notify_resume() clears the -* flag, ensure that the compiler doesn't move -* it after the affinity check. -*/ -barrier (); - -if (cpu_affinity_invalid (regs)) -force_sig (SIGKILL ); }if (thread_flags & _TIF_FOREIGN_FPSTATE)
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Will Deacon
maintainerPATCH v6 21/21 Documentation: arm64: describe asymmetric 32-bit support
In reply to Will DeaconDocument support for running 32-bit tasks on asymmetric 32-bit systems and its impact on the user ABI when enabled.
--- .../admin-guide/kernel-parameters.txt | 3 + Documentation/arm64/asymmetric-32bit.rst | 149 ++++++++++++++++++ Documentation/arm64/index.rst | 1 + 3 files changed, 153 insertions(+) create mode 100644 Documentation/arm64/asymmetric-32bit.rst
Documentation/admin-guide/kernel-parameters.txt +3 -0
@@ -295,6 +295,9 @@ EL0 is indicated by /sys/devices/system/cpu/aarch32_el0 and hot-unplug operations may be restricted. + See Documentation/arm64/asymmetric-32bit.rst for more + information. + amd_iommu= [HW,X86-64] Pass parameters to the AMD IOMMU driver in the system. Possible values are:
Documentation/arm64/asymmetric-32bit.rst new file +149 -0
149 lines not on this page · raw message
Documentation/arm64/index.rst +1 -0
@@ -10,6 +10,7 @@ ARM64 Architecture acpi_object_usage amu arm-acpi + asymmetric-32bit booting cpu-feature-registers elf_hwcaps
Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Re: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Will DeaconQuoted 10 lines · Will Deacon
On asymmetric systems where the affinity of a task is restricted to contain only the CPUs capable of running it, admission to the deadline scheduler is likely to fail because the span of the sched domain contains incompatible CPUs. Although this is arguably the right thing to do, it is inconsistent with the case where the affinity of a task is restricted after already having been admitted to the deadline scheduler.
For example, on an arm64 system where not all CPUs support 32-bit applications, a 64-bit deadline task can
exec()a 32-bit image and have its affinity forcefully restricted.
So I guess the alternative would be to fail exec-ing into 32bit from a 64bit DL task, and then drop this patch?
The nice thing about your approach is that existing applications won't really notice a difference (execve would still 'work'), but on the cons side it breaks admission control, which is sad.
I don't expect this weird execve-to-32bit pattern from DL to be that common in practice (at the very least not in Android), so maybe we could start with the stricter version (fail the execve), and wait to see if folks complain? Making things stricter later will be harder.
Thoughts?
Thanks,
Quentin
Will Deacon
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
[Dropping Li Zefan as his mail is bouncing]
Quoted 12 lines · Quentin Perret
Quoted 10 lines · Will Deacon
On asymmetric systems where the affinity of a task is restricted to contain only the CPUs capable of running it, admission to the deadline scheduler is likely to fail because the span of the sched domain contains incompatible CPUs. Although this is arguably the right thing to do, it is inconsistent with the case where the affinity of a task is restricted after already having been admitted to the deadline scheduler.
For example, on an arm64 system where not all CPUs support 32-bit applications, a 64-bit deadline task can
exec()a 32-bit image and have its affinity forcefully restricted.
Quoted 6 lines
So I guess the alternative would be to fail exec-ing into 32bit from a 64bit DL task, and then drop this patch?
The nice thing about your approach is that existing applications won't really notice a difference (execve would still 'work'), but on the cons side it breaks admission control, which is sad.
Right, with your suggestion here we would forbid any 32-bit deadline tasks on an asymmetric system, even if you'd gone to the extraordinary effort to cater for that (e.g. by having a separate root domain).
Quoted 6 lines
I don't expect this weird execve-to-32bit pattern from DL to be that common in practice (at the very least not in Android), so maybe we could start with the stricter version (fail the execve), and wait to see if folks complain? Making things stricter later will be harder.
Thoughts?
I don't have strong opinions on this, but I _do_ want the admission via sched_setattr() to be consistent with execve(). What you're suggesting ticks that box, but how many applications are prepared to handle a failed execve()? I suspect it will be fatal.
Probably also worth pointing out that the approach here will at least warn in the execve() case when the affinity is overridden for a deadline task.
Will
Re: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Quoted 4 lines · Will Deacon
I don't have strong opinions on this, but I _do_ want the admission via
sched_setattr()to be consistent withexecve(). What you're suggesting ticks that box, but how many applications are prepared to handle a failedexecve()? I suspect it will be fatal.
Yep, probably.
Quoted 3 lines
Probably also worth pointing out that the approach here will at least warn in the
execve()case when the affinity is overridden for a deadline task.
Right so I think either way will be imperfect, so I agree with the above.
Maybe one thing though is that, IIRC, userspace _can_ disable admission control if it wants to. In this case I'd have no problem with allowing this weird behaviour when admission control is off -- the kernel won't provide any guarantees. But if it's left on, then it's a different story.
So what about we say, if admission control is off, we allow execve() and sched_setattr() with appropriate warnings as you suggest, but if admission control is on then we fail both?
We might still see random failures in the wild if admission control is left enabled on those devices but then I think these could qualify as a device misconfiguration, not as a kernel bug.
Thoughts?
Thanks,
Quentin
Will Deacon
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Quoted 21 lines · Quentin Perret
Quoted 4 lines · Will Deacon
I don't have strong opinions on this, but I _do_ want the admission via
sched_setattr()to be consistent withexecve(). What you're suggesting ticks that box, but how many applications are prepared to handle a failedexecve()? I suspect it will be fatal.Yep, probably.
Quoted 3 lines
Probably also worth pointing out that the approach here will at least warn in the
execve()case when the affinity is overridden for a deadline task.Right so I think either way will be imperfect, so I agree with the above.
Maybe one thing though is that, IIRC, userspace _can_ disable admission control if it wants to. In this case I'd have no problem with allowing this weird behaviour when admission control is off -- the kernel won't provide any guarantees. But if it's left on, then it's a different story.
Quoted 3 lines
So what about we say, if admission control is off, we allow
execve()andsched_setattr()with appropriate warnings as you suggest, but if admission control is on then we fail both?
That's an interesting idea. The part that I'm not super keen about is that it means admission control _also_ has an effect on the behaviour of execve(), so practically you'd have to have it disabled as long as you have the possibility of 32-bit deadline tasks anywhere in the system, which impacts 64-bit tasks which may well want admission control enabled.
So perhaps my initial position of trying to keep sched_setattr() and execve() consistent with each other is flawed and actually we can say:
* Disable admission control if you want to admit a 32-bit task explicitly via sched_setattr()
* If a 64-bit deadline task execve()s a 32-bit program then we warn and override the affinity (i.e. you should avoid doing this if you care about the deadlines).
That amounts to dropping this patch and tweaking the documentation.
Dunno, what do you think?
Will
Re: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Quoted 22 lines · Will Deacon
Quoted 21 lines · Quentin Perret
Quoted 4 lines · Will Deacon
I don't have strong opinions on this, but I _do_ want the admission via
sched_setattr()to be consistent withexecve(). What you're suggesting ticks that box, but how many applications are prepared to handle a failedexecve()? I suspect it will be fatal.Yep, probably.
Quoted 3 lines
Probably also worth pointing out that the approach here will at least warn in the
execve()case when the affinity is overridden for a deadline task.Right so I think either way will be imperfect, so I agree with the above.
Maybe one thing though is that, IIRC, userspace _can_ disable admission control if it wants to. In this case I'd have no problem with allowing this weird behaviour when admission control is off -- the kernel won't provide any guarantees. But if it's left on, then it's a different story.
Quoted 7 lines
Quoted 3 lines
So what about we say, if admission control is off, we allow
execve()andsched_setattr()with appropriate warnings as you suggest, but if admission control is on then we fail both?That's an interesting idea. The part that I'm not super keen about is that it means admission control _also_ has an effect on the behaviour of
execve()
Right, that's a good point. And it looks like fork() behaves the same regardless of admission control being enabled or not -- it is forbidden from DL either way. So I can't say there is a precedent :/
Quoted 3 lines
so practically you'd have to have it disabled as long as you have the possibility of 32-bit deadline tasks anywhere in the system, which impacts 64-bit tasks which may well want admission control enabled.
Indeed, this is a bit sad, but I don't know if the kernel should pretend it can guarantee to meet your deadlines and at the same time allow to do something that wrecks the underlying theory.
I'd personally be happy with saying that admission control should be disabled on these dumb systems (and have that documented), at least until DL gets proper support for affinities. ISTR there was work going in that direction, but some folks in the CC list will know better.
@Juri, maybe you would know if that's still planned?
Thanks,
Quentin
Juri Lelli
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Hi Quentin and Will,
Apologies for the delay in replying.
Quoted 43 lines · Quentin Perret
Quoted 22 lines · Will Deacon
Quoted 21 lines · Quentin Perret
Quoted 4 lines · Will Deacon
I don't have strong opinions on this, but I _do_ want the admission via
sched_setattr()to be consistent withexecve(). What you're suggesting ticks that box, but how many applications are prepared to handle a failedexecve()? I suspect it will be fatal.Yep, probably.
Quoted 3 lines
Probably also worth pointing out that the approach here will at least warn in the
execve()case when the affinity is overridden for a deadline task.Right so I think either way will be imperfect, so I agree with the above.
Maybe one thing though is that, IIRC, userspace _can_ disable admission control if it wants to. In this case I'd have no problem with allowing this weird behaviour when admission control is off -- the kernel won't provide any guarantees. But if it's left on, then it's a different story.
Quoted 7 lines
Quoted 3 lines
So what about we say, if admission control is off, we allow
execve()andsched_setattr()with appropriate warnings as you suggest, but if admission control is on then we fail both?That's an interesting idea. The part that I'm not super keen about is that it means admission control _also_ has an effect on the behaviour of
execve()Right, that's a good point. And it looks like
fork()behaves the same regardless of admission control being enabled or not -- it is forbidden from DL either way. So I can't say there is a precedent :/Quoted 3 lines
so practically you'd have to have it disabled as long as you have the possibility of 32-bit deadline tasks anywhere in the system, which impacts 64-bit tasks which may well want admission control enabled.
Indeed, this is a bit sad, but I don't know if the kernel should pretend it can guarantee to meet your deadlines and at the same time allow to do something that wrecks the underlying theory.
Quoted 6 lines
I'd personally be happy with saying that admission control should be disabled on these dumb systems (and have that documented), at least until DL gets proper support for affinities. ISTR there was work going in that direction, but some folks in the CC list will know better.
@Juri, maybe you would know if that's still planned?
I won't go as far as saying planned, but that is still under "our" radar for sure. Daniel was working on it, but I don't think he had any time to resume that bit of work lately.
So, until we have that, I think we have been as conservative as we could for this type of decisions. I'm a little afraid that allowing configuration to break admission control (even with a non fatal warning is emitted) is still risky. I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do). But I'm not familiar with the mixed 32/64 apps usecase you describe, so I might be missing details.
Best,
Juri
Will Deacon
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Hi Juri,
Quoted 1 line · Juri Lelli
Apologies for the delay in replying.
Not at all!
Quoted 55 lines · Quentin Perret
Quoted 43 lines · Will Deacon
Quoted 22 lines · Quentin Perret
Quoted 21 lines · Will Deacon
Quoted 4 lines
I don't have strong opinions on this, but I _do_ want the admission via
sched_setattr()to be consistent withexecve(). What you're suggesting ticks that box, but how many applications are prepared to handle a failedexecve()? I suspect it will be fatal.Yep, probably.
Quoted 3 lines
Probably also worth pointing out that the approach here will at least warn in the
execve()case when the affinity is overridden for a deadline task.Right so I think either way will be imperfect, so I agree with the above.
Maybe one thing though is that, IIRC, userspace _can_ disable admission control if it wants to. In this case I'd have no problem with allowing this weird behaviour when admission control is off -- the kernel won't provide any guarantees. But if it's left on, then it's a different story.
Quoted 7 lines
Quoted 3 lines
So what about we say, if admission control is off, we allow
execve()andsched_setattr()with appropriate warnings as you suggest, but if admission control is on then we fail both?That's an interesting idea. The part that I'm not super keen about is that it means admission control _also_ has an effect on the behaviour of
execve()Right, that's a good point. And it looks like
fork()behaves the same regardless of admission control being enabled or not -- it is forbidden from DL either way. So I can't say there is a precedent :/Quoted 3 lines
so practically you'd have to have it disabled as long as you have the possibility of 32-bit deadline tasks anywhere in the system, which impacts 64-bit tasks which may well want admission control enabled.
Indeed, this is a bit sad, but I don't know if the kernel should pretend it can guarantee to meet your deadlines and at the same time allow to do something that wrecks the underlying theory.
Quoted 6 lines
I'd personally be happy with saying that admission control should be disabled on these dumb systems (and have that documented), at least until DL gets proper support for affinities. ISTR there was work going in that direction, but some folks in the CC list will know better.
@Juri, maybe you would know if that's still planned?
I won't go as far as saying planned, but that is still under "our" radar for sure. Daniel was working on it, but I don't think he had any time to resume that bit of work lately.
Quoted 7 lines
So, until we have that, I think we have been as conservative as we could for this type of decisions. I'm a little afraid that allowing configuration to break admission control (even with a non fatal warning is emitted) is still risky. I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do). But I'm not familiar with the mixed 32/64 apps usecase you describe, so I might be missing details.
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled for sched_setattr() but allow execve() to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).
I'll update that for v8, and this patch will disappear.
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).
Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Juri Lelli
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Quoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
Yeah, this was my thinking as well.
Re: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Quentin PerretQuoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
If the cpumask of the 32-bit task is != of the 64-bit task that is executing it, the admission control needs to be re-executed, and it could fail. So I see this operation equivalent to sched_setaffinity(). This will likely be true for future schedulers that will allow arbitrary affinities (AC should run on affinity change, and could fail).
I would vote with Juri: "I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do)," (also hope nobody complains until we add better support for affinity, and use this as a motivation to get back on this front).
-- Daniel
Dietmar Eggemann
reviewerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Quoted 17 lines · Daniel Bristot de Oliveira
Quoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
If the cpumask of the 32-bit task is != of the 64-bit task that is executing it, the admission control needs to be re-executed, and it could fail. So I see this operation equivalent to
sched_setaffinity(). This will likely be true for future schedulers that will allow arbitrary affinities (AC should run on affinity change, and could fail).
Quoted 6 lines
I would vote with Juri: "I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do)," (also hope nobody complains until we add better support for affinity, and use this as a motivation to get back on this front).
-- Daniel
(1) # chrt -d -T 5000000 -P 16666666 0 ./32bit_app
(2) # ./32bit_app &
# chrt -d -T 5000000 -P 16666666 -p 0 pid_of(32bit_app)
Wouldn't the behaviour of (1) and (2) be different w/o this patch?
In (1) __sched_setscheduler() happens before execve so it operates on p->cpus_ptr equal span.
In (2) span != p->cpus_ptr so DL AC will fail.
Re: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Quoted 32 lines · Dietmar Eggemann
Quoted 17 lines · Daniel Bristot de Oliveira
Quoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
If the cpumask of the 32-bit task is != of the 64-bit task that is executing it, the admission control needs to be re-executed, and it could fail. So I see this operation equivalent to
sched_setaffinity(). This will likely be true for future schedulers that will allow arbitrary affinities (AC should run on affinity change, and could fail).Quoted 6 lines
I would vote with Juri: "I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do)," (also hope nobody complains until we add better support for affinity, and use this as a motivation to get back on this front).
-- Daniel
(1) # chrt -d -T 5000000 -P 16666666 0 ./32bit_app
(2) # ./32bit_app &
# chrt -d -T 5000000 -P 16666666 -p 0 pid_of(32bit_app)
Quoted 7 lines
Wouldn't the behaviour of (1) and (2) be different w/o this patch?
In (1)
__sched_setscheduler()happens before execve so it operates onp->cpus_ptrequal span.In (2) span !=
p->cpus_ptrso DL AC will fail.
As far as I got, the case (1) would be spitted in two steps:
- __sched_setscheduler() will work, then
- execv() would fail because (span != p->cpus_ptr)
So... at the end, both (1) and (2) would result in a failure...
am I missing something?
-- Daniel
Dietmar Eggemann
reviewerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Quoted 41 lines · Daniel Bristot de Oliveira
Quoted 32 lines · Dietmar Eggemann
Quoted 17 lines · Daniel Bristot de Oliveira
Quoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
If the cpumask of the 32-bit task is != of the 64-bit task that is executing it, the admission control needs to be re-executed, and it could fail. So I see this operation equivalent to
sched_setaffinity(). This will likely be true for future schedulers that will allow arbitrary affinities (AC should run on affinity change, and could fail).Quoted 6 lines
I would vote with Juri: "I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do)," (also hope nobody complains until we add better support for affinity, and use this as a motivation to get back on this front).
-- Daniel
(1) # chrt -d -T 5000000 -P 16666666 0 ./32bit_app
(2) # ./32bit_app &
# chrt -d -T 5000000 -P 16666666 -p 0 pid_of(32bit_app)Quoted 7 lines
Wouldn't the behaviour of (1) and (2) be different w/o this patch?
In (1)
__sched_setscheduler()happens before execve so it operates onp->cpus_ptrequal span.In (2) span !=
p->cpus_ptrso DL AC will fail.
Quoted 8 lines
As far as I got, the case (1) would be spitted in two steps:
-
__sched_setscheduler()will work, then
-execv()would fail because (span !=p->cpus_ptr)So... at the end, both (1) and (2) would result in a failure...
am I missing something?
Not sure. Reading this thread I was under the assumption that the only change would be the drop of this patch. But I assume there is also this 'if DL AC is on then let sched_setattr() fail for this 32bit task'.
IMHO, the current patch-stack w/o this patch should let (1) succeed with DL AC.
Will Deacon
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Daniel Bristot de OliveiraQuoted 17 lines · Daniel Bristot de Oliveira
Quoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
If the cpumask of the 32-bit task is != of the 64-bit task that is executing it, the admission control needs to be re-executed, and it could fail. So I see this operation equivalent to
sched_setaffinity(). This will likely be true for future schedulers that will allow arbitrary affinities (AC should run on affinity change, and could fail).
Quoted 4 lines
I would vote with Juri: "I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do)," (also hope nobody complains until we add better support for affinity, and use this as a motivation to get back on this front).
I can have a go at implementing it, but I don't think it's a great solution and here's why:
Failing an execve() is _very_ likely to be fatal to the application. It's also very likely that the task calling execve() doesn't know whether the program it's trying to execute is 32-bit or not. Consequently, if we go with failing execve() then all that will happen is that people will disable admission control altogether. That has a negative impact on "pure" 64-bit applications and so I think we end up with the tail wagging the dog because admission control will be disabled for everybody just because there is a handful of 32-bit programs which may get executed. I understand that it also means that RT throttling would be disabled.
Allowing the execve() to continue with a warning is very similar to the case in which all the 64-bit CPUs are hot-unplugged at the point of execve(), and this is much closer to the illusion that this patch series intends to provide.
So, personally speaking, I would prefer the behaviour where we refuse to admit 32-bit tasks vioa sched_set_attr() if the root domain contains 64-bit CPUs, but we _don't_ fail execve() of a 32-bit program from a 64-bit deadline task.
However, you're the deadline experts so ultimately I'll implement what you prefer. I just wanted to explain why I think it's a poor interface.
Have I changed anybody's mind?
Will
Will Deacon
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Dietmar EggemannHi Dietmar,
Quoted 24 lines · Dietmar Eggemann
Quoted 23 lines · Daniel Bristot de Oliveira
Quoted 7 lines · Dietmar Eggemann
(1) # chrt -d -T 5000000 -P 16666666 0 ./32bit_app
(2) # ./32bit_app &
# chrt -d -T 5000000 -P 16666666 -p 0 pid_of(32bit_app)Quoted 7 lines
Wouldn't the behaviour of (1) and (2) be different w/o this patch?
In (1)
__sched_setscheduler()happens before execve so it operates onp->cpus_ptrequal span.In (2) span !=
p->cpus_ptrso DL AC will fail.As far as I got, the case (1) would be spitted in two steps:
-
__sched_setscheduler()will work, then
-execv()would fail because (span !=p->cpus_ptr)So... at the end, both (1) and (2) would result in a failure...
Quoted 8 lines
Quoted 1 line
am I missing something?
Not sure. Reading this thread I was under the assumption that the only change would be the drop of this patch. But I assume there is also this 'if DL AC is on then let
sched_setattr()fail for this 32bit task'.IMHO, the current patch-stack w/o this patch should let (1) succeed with DL AC.
That's what I'm proposing, yes, but others (including Daniel) prefer to fail the execve(). See my other reply just now for a summary [1].
Thanks!
Will
[1] https://lore.kernel.org/lkml/20210520180138.GA10523@willie-the-truck/T/#u
Juri Lelli
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Will DeaconQuoted 26 lines · Will Deacon
Quoted 17 lines · Daniel Bristot de Oliveira
Quoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
If the cpumask of the 32-bit task is != of the 64-bit task that is executing it, the admission control needs to be re-executed, and it could fail. So I see this operation equivalent to
sched_setaffinity(). This will likely be true for future schedulers that will allow arbitrary affinities (AC should run on affinity change, and could fail).Quoted 4 lines
I would vote with Juri: "I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do)," (also hope nobody complains until we add better support for affinity, and use this as a motivation to get back on this front).
I can have a go at implementing it, but I don't think it's a great solution and here's why:
Quoted 9 lines
Failing an
execve()is _very_ likely to be fatal to the application. It's also very likely that the task callingexecve()doesn't know whether the program it's trying to execute is 32-bit or not. Consequently, if we go with failingexecve()then all that will happen is that people will disable admission control altogether. That has a negative impact on "pure" 64-bit applications and so I think we end up with the tail wagging the dog because admission control will be disabled for everybody just because there is a handful of 32-bit programs which may get executed. I understand that it also means that RT throttling would be disabled.
Completely understand your perplexity. But how can the kernel still give guarantees to "pure" 64-bit applications if there are 32-bit applications around that essentially broke admission control when they were restricted to a subset of cores?
Quoted 4 lines
Allowing the
execve()to continue with a warning is very similar to the case in which all the 64-bit CPUs are hot-unplugged at the point ofexecve(), and this is much closer to the illusion that this patch series intends to provide.
So, for hotplug we currently have a check that would make hotplug operations fail if removing a CPU would mean not enough bandwidth to run the currently admitted set of DEADLINE tasks.
Quoted 4 lines
So, personally speaking, I would prefer the behaviour where we refuse to admit 32-bit tasks vioa
sched_set_attr()if the root domain contains 64-bit CPUs, but we _don't_ failexecve()of a 32-bit program from a 64-bit deadline task.
OK, this is interesting and I guess a very valid alternative. That would force users to create exclusive domains for 32-bit tasks, right?
Quoted 4 lines
However, you're the deadline experts so ultimately I'll implement what you prefer. I just wanted to explain why I think it's a poor interface.
Have I changed anybody's mind?
Partly! :)
Thanks a lot for the discussion so far.
Juri
Re: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Quoted 24 lines · Juri Lelli
Quoted 23 lines · Will Deacon
Quoted 21 lines · Daniel Bristot de Oliveira
Quoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
If the cpumask of the 32-bit task is != of the 64-bit task that is executing it, the admission control needs to be re-executed, and it could fail. So I see this operation equivalent to
sched_setaffinity(). This will likely be true for future schedulers that will allow arbitrary affinities (AC should run on affinity change, and could fail).I would vote with Juri: "I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do)," (also hope nobody complains until we add better support for affinity, and use this as a motivation to get back on this front).
Quoted 8 lines
Quoted 8 lines
I can have a go at implementing it, but I don't think it's a great solution and here's why:
Failing an
execve()is _very_ likely to be fatal to the application. It's also very likely that the task callingexecve()doesn't know whether the program it's trying to execute is 32-bit or not. Consequently, if we go with failingexecve()then all that will happen is that people will disable admission control altogether.
Right, but only on these dumb 32bit asymmetric systems, and only if we care about running 32bits deadline tasks -- which I seriously doubt for the Android use-case.
Note that running deadline tasks is also a privileged operation, it can't be done by random apps.
Quoted 11 lines
Quoted 5 lines
That has a negative impact on "pure" 64-bit
applications and so I think we end up with the tail wagging the dog because admission control will be disabled for everybody just because there is a handful of 32-bit programs which may get executed. I understand that it also means that RT throttling would be disabled.Completely understand your perplexity. But how can the kernel still give guarantees to "pure" 64-bit applications if there are 32-bit applications around that essentially broke admission control when they were restricted to a subset of cores?
Quoted 8 lines
Quoted 4 lines
Allowing the
execve()to continue with a warning is very similar to the case in which all the 64-bit CPUs are hot-unplugged at the point ofexecve(), and this is much closer to the illusion that this patch series intends to provide.So, for hotplug we currently have a check that would make hotplug operations fail if removing a CPU would mean not enough bandwidth to run the currently admitted set of DEADLINE tasks.
Aha, wasn't aware. Any pointers to that check for my education?
Quoted 7 lines
Quoted 4 lines
So, personally speaking, I would prefer the behaviour where we refuse to admit 32-bit tasks vioa
sched_set_attr()if the root domain contains 64-bit CPUs, but we _don't_ failexecve()of a 32-bit program from a 64-bit deadline task.OK, this is interesting and I guess a very valid alternative. That would force users to create exclusive domains for 32-bit tasks, right?
FWIW this is not practical at all for our use-cases, the implications of splitting the system in independent root-domains are way too important for us to be able to recommend that. Disabling AC, OTOH, sounds simple enough. The RT throttling part is the only 'worrying' part, but even that may not be the end of the world.
Thanks!
Quentin
Juri Lelli
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
Quoted 57 lines · Quentin Perret
Quoted 24 lines · Juri Lelli
Quoted 23 lines · Will Deacon
Quoted 21 lines · Daniel Bristot de Oliveira
Quoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
If the cpumask of the 32-bit task is != of the 64-bit task that is executing it, the admission control needs to be re-executed, and it could fail. So I see this operation equivalent to
sched_setaffinity(). This will likely be true for future schedulers that will allow arbitrary affinities (AC should run on affinity change, and could fail).I would vote with Juri: "I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do)," (also hope nobody complains until we add better support for affinity, and use this as a motivation to get back on this front).
Quoted 8 lines
Quoted 8 lines
I can have a go at implementing it, but I don't think it's a great solution and here's why:
Failing an
execve()is _very_ likely to be fatal to the application. It's also very likely that the task callingexecve()doesn't know whether the program it's trying to execute is 32-bit or not. Consequently, if we go with failingexecve()then all that will happen is that people will disable admission control altogether.Right, but only on these dumb 32bit asymmetric systems, and only if we care about running 32bits deadline tasks -- which I seriously doubt for the Android use-case.
Note that running deadline tasks is also a privileged operation, it can't be done by random apps.
Quoted 16 lines
Quoted 5 lines
That has a negative impact on "pure" 64-bit
applications and so I think we end up with the tail wagging the dog because admission control will be disabled for everybody just because there is a handful of 32-bit programs which may get executed. I understand that it also means that RT throttling would be disabled.Completely understand your perplexity. But how can the kernel still give guarantees to "pure" 64-bit applications if there are 32-bit applications around that essentially broke admission control when they were restricted to a subset of cores?
Quoted 4 lines
Allowing the
execve()to continue with a warning is very similar to the case in which all the 64-bit CPUs are hot-unplugged at the point ofexecve(), and this is much closer to the illusion that this patch series intends to provide.
Quoted 5 lines
Quoted 3 lines
So, for hotplug we currently have a check that would make hotplug operations fail if removing a CPU would mean not enough bandwidth to run the currently admitted set of DEADLINE tasks.
Aha, wasn't aware. Any pointers to that check for my education?
Hotplug ends up calling dl_cpu_busy() (after the cpu being hotplugged out got removed), IIRC. So, if that fails the operation in undone.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
So, personally speaking, I would prefer the behaviour where we refuse to admit 32-bit tasks vioa
sched_set_attr()if the root domain contains 64-bit CPUs, but we _don't_ failexecve()of a 32-bit program from a 64-bit deadline task.
Quoted 8 lines
Quoted 2 lines
OK, this is interesting and I guess a very valid alternative. That would force users to create exclusive domains for 32-bit tasks, right?
FWIW this is not practical at all for our use-cases, the implications of splitting the system in independent root-domains are way too important for us to be able to recommend that. Disabling AC, OTOH, sounds simple enough. The RT throttling part is the only 'worrying' part, but even that may not be the end of the world.
Note that RT throttling (SCHED_{FIFO,RR}) is not handled by DEADLINE servers yet.
Best,
Juri
Catalin Marinas
maintainerRe: [PATCH v6 02/21] arm64: Allow mismatched 32-bit EL0 support
In reply to Will Deaconarch/arm64/kernel/cpufeature.c has_cpuid_feature(const struct arm64_cpu_capabilities *entry, int scope) · line 1309
Quoted 10 lines · Will Deacon
arch/arm64/kernel/cpufeature.c +10
-0+static bool has_32bit_el0 (const struct arm64_cpu_capabilities *entry,int scope) +{ +if (!has_cpuid_feature (entry, scope)) +return allow_mismatched_32bit_el0; + +if (scope ==SCOPE_SYSTEM ) +pr_info ("detected: 32-bit EL0 Support\n" ); + +return true; +}
We may have discussed this before: AFAICT this will print 32-bit EL0 detected even if there's no 32-bit EL0 on any CPU. Should we instead print 32-bit EL0 detected on CPU X when allow_mismatched_32bit_el0 is passed? It would also give us an indication of the system configuration when people start reporting bugs.
Signature · 1 line
Catalin
Will Deacon
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Juri LelliQuoted 58 lines · Juri Lelli
Quoted 57 lines · Quentin Perret
Quoted 24 lines · Juri Lelli
Quoted 23 lines · Will Deacon
Quoted 21 lines · Daniel Bristot de Oliveira
Quoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
If the cpumask of the 32-bit task is != of the 64-bit task that is executing it, the admission control needs to be re-executed, and it could fail. So I see this operation equivalent to
sched_setaffinity(). This will likely be true for future schedulers that will allow arbitrary affinities (AC should run on affinity change, and could fail).I would vote with Juri: "I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do)," (also hope nobody complains until we add better support for affinity, and use this as a motivation to get back on this front).
Quoted 8 lines
Quoted 8 lines
I can have a go at implementing it, but I don't think it's a great solution and here's why:
Failing an
execve()is _very_ likely to be fatal to the application. It's also very likely that the task callingexecve()doesn't know whether the program it's trying to execute is 32-bit or not. Consequently, if we go with failingexecve()then all that will happen is that people will disable admission control altogether.Right, but only on these dumb 32bit asymmetric systems, and only if we care about running 32bits deadline tasks -- which I seriously doubt for the Android use-case.
Note that running deadline tasks is also a privileged operation, it can't be done by random apps.
Quoted 16 lines
Quoted 5 lines
That has a negative impact on "pure" 64-bit
applications and so I think we end up with the tail wagging the dog because admission control will be disabled for everybody just because there is a handful of 32-bit programs which may get executed. I understand that it also means that RT throttling would be disabled.Completely understand your perplexity. But how can the kernel still give guarantees to "pure" 64-bit applications if there are 32-bit applications around that essentially broke admission control when they were restricted to a subset of cores?
Quoted 4 lines
Allowing the
execve()to continue with a warning is very similar to the case in which all the 64-bit CPUs are hot-unplugged at the point ofexecve(), and this is much closer to the illusion that this patch series intends to provide.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
So, for hotplug we currently have a check that would make hotplug operations fail if removing a CPU would mean not enough bandwidth to run the currently admitted set of DEADLINE tasks.
Aha, wasn't aware. Any pointers to that check for my education?
Hotplug ends up calling
dl_cpu_busy()(after the cpu being hotplugged out got removed), IIRC. So, if that fails the operation in undone.
Interesting, thanks. Thinking about this some more, it strikes me that with these silly asymmetric systems there could be an interesting additional problem with hotplug and deadline tasks. Imagine the following sequence of events:
1. All online CPUs are 32-bit-capable
2. sched_setattr() admits a 32-bit deadline task
3. A 64-bit-only CPU is onlined
4. Some of the 32-bit-capable CPUs are offlined
I wonder if we can get into a situation where we think we have enough bandwidth available, but in reality the 32-bit task is in trouble because it can't make use of the 64-bit-only CPU.
If so, then it seems to me that admission control is really just "best-effort" for 32-bit deadline tasks on these systems because it's based on a snapshot in time of the available resources.
Will
Catalin Marinas
maintainerRe: [PATCH v6 02/21] arm64: Allow mismatched 32-bit EL0 support
In reply to Will Deaconarch/arm64/kernel/cpufeature.c void __init setup_cpu_features(void) · line 2885
Quoted 8 lines · Will Deacon
arch/arm64/kernel/cpufeature.c +8
-0+static int enable_mismatched_32bit_el0 (unsigned int cpu) +{ +struct cpuinfo_arm64 *info = &per_cpu (cpu_data, cpu); +bool cpu_32bit =id_aa64pfr0_32bit_el0 (info->reg_id_aa64pfr0); + +if (cpu_32bit) { +cpumask_set_cpu (cpu, cpu_32bit_el0_mask); +static_branch_enable_cpuslocked (&arm64_mismatched_32bit_el0);
It may be worth only calling static_branch_enable_cpuslocked() if not already set, in case you try this on a system with lots of CPUs.
Signature · 1 line
Catalin
Re: [PATCH v6 01/21] arm64: cpuinfo: Split AArch32 registers out into a separate struct
In reply to Will DeaconQuoted 5 lines · Will Deacon
In preparation for late initialisation of the "sanitised" AArch32 register state, move the AArch32 registers out of 'struct cpuinfo' and into their own struct definition.
Signed-off-by Will Deacon <[email protected]>
Re: [PATCH v6 03/21] KVM: arm64: Kill 32-bit vCPUs on systems with mismatched EL0 support
In reply to Will DeaconQuoted 5 lines · Will Deacon
If a vCPU is caught running 32-bit code on a system with mismatched support at EL0, then we should kill it.
Acked-by Marc Zyngier <[email protected]>Signed-off-by Will Deacon <[email protected]>
Re: [PATCH v6 04/21] arm64: Kill 32-bit applications scheduled on 64-bit-only CPUs
In reply to Will DeaconQuoted 7 lines · Will Deacon
Scheduling a 32-bit application on a 64-bit-only CPU is a bad idea.
Ensure that 32-bit applications always take the slow-path when returning to userspace on a system with mismatched support at EL0, so that we can avoid trying to run on a 64-bit-only CPU and force a SIGKILL instead.
Signed-off-by Will Deacon <[email protected]>
Re: [PATCH v6 05/21] arm64: Advertise CPUs capable of running 32-bit applications in sysfs
In reply to Will DeaconQuoted 6 lines · Will Deacon
Since 32-bit applications will be killed if they are caught trying to execute on a 64-bit-only CPU in a mismatched system, advertise the set of 32-bit capable CPUs to userspace in sysfs.
Reviewed-by Greg Kroah-Hartman <[email protected]>Signed-off-by Will Deacon <[email protected]>
Dietmar Eggemann
reviewerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Will DeaconQuoted 78 lines · Will Deacon
Quoted 58 lines · Juri Lelli
Quoted 57 lines · Quentin Perret
Quoted 24 lines · Juri Lelli
Quoted 23 lines · Will Deacon
Quoted 21 lines · Daniel Bristot de Oliveira
Quoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
If the cpumask of the 32-bit task is != of the 64-bit task that is executing it, the admission control needs to be re-executed, and it could fail. So I see this operation equivalent to
sched_setaffinity(). This will likely be true for future schedulers that will allow arbitrary affinities (AC should run on affinity change, and could fail).I would vote with Juri: "I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do)," (also hope nobody complains until we add better support for affinity, and use this as a motivation to get back on this front).
Quoted 8 lines
Quoted 8 lines
I can have a go at implementing it, but I don't think it's a great solution and here's why:
Failing an
execve()is _very_ likely to be fatal to the application. It's also very likely that the task callingexecve()doesn't know whether the program it's trying to execute is 32-bit or not. Consequently, if we go with failingexecve()then all that will happen is that people will disable admission control altogether.Right, but only on these dumb 32bit asymmetric systems, and only if we care about running 32bits deadline tasks -- which I seriously doubt for the Android use-case.
Note that running deadline tasks is also a privileged operation, it can't be done by random apps.
Quoted 16 lines
Quoted 5 lines
That has a negative impact on "pure" 64-bit
applications and so I think we end up with the tail wagging the dog because admission control will be disabled for everybody just because there is a handful of 32-bit programs which may get executed. I understand that it also means that RT throttling would be disabled.Completely understand your perplexity. But how can the kernel still give guarantees to "pure" 64-bit applications if there are 32-bit applications around that essentially broke admission control when they were restricted to a subset of cores?
Quoted 4 lines
Allowing the
execve()to continue with a warning is very similar to the case in which all the 64-bit CPUs are hot-unplugged at the point ofexecve(), and this is much closer to the illusion that this patch series intends to provide.Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
So, for hotplug we currently have a check that would make hotplug operations fail if removing a CPU would mean not enough bandwidth to run the currently admitted set of DEADLINE tasks.
Aha, wasn't aware. Any pointers to that check for my education?
Hotplug ends up calling
dl_cpu_busy()(after the cpu being hotplugged out got removed), IIRC. So, if that fails the operation in undone.Interesting, thanks. Thinking about this some more, it strikes me that with these silly asymmetric systems there could be an interesting additional problem with hotplug and deadline tasks. Imagine the following sequence of events:
1. All online CPUs are 32-bit-capable
2.sched_setattr()admits a 32-bit deadline task
3. A 64-bit-only CPU is onlined
4. Some of the 32-bit-capable CPUs are offlined
Quoted 7 lines
I wonder if we can get into a situation where we think we have enough bandwidth available, but in reality the 32-bit task is in trouble because it can't make use of the 64-bit-only CPU.
If so, then it seems to me that admission control is really just "best-effort" for 32-bit deadline tasks on these systems because it's based on a snapshot in time of the available resources.
IMHO DL AC is per root domain (rd). So if we have e.g. an 8 CPU system with aarch32_el0 eq. [0-3] then we would need 2 exclusive cpusets ([0-3] and [4-7]) to admit 32-bit DL tasks into [0-3] (i.e. to pass the if (!cpumask_subset(span, p->cpus_ptr) ... test in __sched_setscheduler().
Trying to admit too many 32-bit DL tasks or trying to hp out a CPU[0-3] would lead to Device or resource busy in case the rd bw wouldn't be sufficient anymore for the set of admitted tasks. But the [0-3] DL AC wouldn't care about hp on CPU[4-7].
Dietmar Eggemann
reviewerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Will DeaconQuoted 33 lines · Will Deacon
Hi Dietmar,
Quoted 30 lines · Dietmar Eggemann
Quoted 16 lines · Daniel Bristot de Oliveira
Quoted 7 lines · Dietmar Eggemann
(1) # chrt -d -T 5000000 -P 16666666 0 ./32bit_app
(2) # ./32bit_app &
# chrt -d -T 5000000 -P 16666666 -p 0 pid_of(32bit_app)Quoted 7 lines
Wouldn't the behaviour of (1) and (2) be different w/o this patch?
In (1)
__sched_setscheduler()happens before execve so it operates onp->cpus_ptrequal span.In (2) span !=
p->cpus_ptrso DL AC will fail.Quoted 8 lines
As far as I got, the case (1) would be spitted in two steps:
-
__sched_setscheduler()will work, then
-execv()would fail because (span !=p->cpus_ptr)So... at the end, both (1) and (2) would result in a failure...
am I missing something?
Not sure. Reading this thread I was under the assumption that the only change would be the drop of this patch. But I assume there is also this 'if DL AC is on then let
sched_setattr()fail for this 32bit task'.
Quoted 5 lines
Quoted 2 lines
IMHO, the current patch-stack w/o this patch should let (1) succeed with DL AC.
That's what I'm proposing, yes, but others (including Daniel) prefer to fail the
execve(). See my other reply just now for a summary [1].
[...]
Thanks, Will ... Now I understand. Or at least I think I do ;-)
Re: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Will DeaconQuoted 8 lines · Will Deacon
Interesting, thanks. Thinking about this some more, it strikes me that with these silly asymmetric systems there could be an interesting additional problem with hotplug and deadline tasks. Imagine the following sequence of events:
1. All online CPUs are 32-bit-capable
2.sched_setattr()admits a 32-bit deadline task
3. A 64-bit-only CPU is onlined
At the point 3, the global scheduler assumption is broken. For instance, in a system with four CPUs and five ready 32-bit-capable tasks, when the fifth CPU as added, the working conserving rule is violated because the five highest priority thread are not running (only four are) :-(.
So, at this point, for us to keep to the current behavior, the addition should be.. blocked? :-((
Quoted 1 line
4. Some of the 32-bit-capable CPUs are offlined
Assuming that point 3 does not exist (i.e., all CPUs are 32-bit-capable). At this point, we will have an increase in the pressure on the 32-bit-capable CPUs.
This can also create bad effects for 64-bit tasks, as the "contended" 32-bit tasks will still be "queued" in a future time where they were supposed to be done (leaving time for the 64-bit tasks).
Quoted 3 lines
I wonder if we can get into a situation where we think we have enough bandwidth available, but in reality the 32-bit task is in trouble because it can't make use of the 64-bit-only CPU.
I would have to think more, but there might be a case where this contended 32-bit tasks could cause deadline misses for the 64-bit too.
Quoted 3 lines
If so, then it seems to me that admission control is really just "best-effort" for 32-bit deadline tasks on these systems because it's based on a snapshot in time of the available resources.
The admission test as is now is "best-effort" in the sense that it allows a workload higher than it could handle (it is necessary, but not sufficient AC). But it should not be considered "best-effort" because of violations in the working conserving property as a result of arbitrary affinities among tasks. Overall, we have been trying to close any "exception left" to this later case.
I know, it is a complex situation, I am just trying to illustrate our concerns, because, in the near future we might have a scheduler that handles arbitrary affinity correctly. But that might require us to stick to an AC. The AC is something precious for us.
(yeah, SP would not face this problem... now that I made progress on RV I can get back to it).
-- Daniel
Re: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Dietmar EggemannQuoted 92 lines · Dietmar Eggemann
Quoted 78 lines · Will Deacon
Quoted 58 lines · Juri Lelli
Quoted 57 lines · Quentin Perret
Quoted 24 lines · Juri Lelli
Quoted 23 lines · Will Deacon
Quoted 21 lines · Daniel Bristot de Oliveira
Quoted 9 lines · Quentin Perret
Quoted 4 lines · Will Deacon
Ok, thanks for the insight. In which case, I'll go with what we discussed:
require admission control to be disabled forsched_setattr()but allowexecve()to a 32-bit task from a 64-bit deadline task with a warning (this is probably similar to CPU hotplug?).Still not sure that we can let execve go through ... It will break AC all the same, so it should probably fail as well if AC is on IMO
If the cpumask of the 32-bit task is != of the 64-bit task that is executing it, the admission control needs to be re-executed, and it could fail. So I see this operation equivalent to
sched_setaffinity(). This will likely be true for future schedulers that will allow arbitrary affinities (AC should run on affinity change, and could fail).I would vote with Juri: "I'd go with fail hard if AC is on, let it pass if AC is off (supposedly the user knows what to do)," (also hope nobody complains until we add better support for affinity, and use this as a motivation to get back on this front).
Quoted 8 lines
Quoted 8 lines
I can have a go at implementing it, but I don't think it's a great solution and here's why:
Failing an
execve()is _very_ likely to be fatal to the application. It's also very likely that the task callingexecve()doesn't know whether the program it's trying to execute is 32-bit or not. Consequently, if we go with failingexecve()then all that will happen is that people will disable admission control altogether.Right, but only on these dumb 32bit asymmetric systems, and only if we care about running 32bits deadline tasks -- which I seriously doubt for the Android use-case.
Note that running deadline tasks is also a privileged operation, it can't be done by random apps.
Quoted 16 lines
Quoted 5 lines
That has a negative impact on "pure" 64-bit
applications and so I think we end up with the tail wagging the dog because admission control will be disabled for everybody just because there is a handful of 32-bit programs which may get executed. I understand that it also means that RT throttling would be disabled.Completely understand your perplexity. But how can the kernel still give guarantees to "pure" 64-bit applications if there are 32-bit applications around that essentially broke admission control when they were restricted to a subset of cores?
Quoted 4 lines
Allowing the
execve()to continue with a warning is very similar to the case in which all the 64-bit CPUs are hot-unplugged at the point ofexecve(), and this is much closer to the illusion that this patch series intends to provide.Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
So, for hotplug we currently have a check that would make hotplug operations fail if removing a CPU would mean not enough bandwidth to run the currently admitted set of DEADLINE tasks.
Aha, wasn't aware. Any pointers to that check for my education?
Hotplug ends up calling
dl_cpu_busy()(after the cpu being hotplugged out got removed), IIRC. So, if that fails the operation in undone.Interesting, thanks. Thinking about this some more, it strikes me that with these silly asymmetric systems there could be an interesting additional problem with hotplug and deadline tasks. Imagine the following sequence of events:
1. All online CPUs are 32-bit-capable
2.sched_setattr()admits a 32-bit deadline task
3. A 64-bit-only CPU is onlined
4. Some of the 32-bit-capable CPUs are offlinedQuoted 7 lines
I wonder if we can get into a situation where we think we have enough bandwidth available, but in reality the 32-bit task is in trouble because it can't make use of the 64-bit-only CPU.
If so, then it seems to me that admission control is really just "best-effort" for 32-bit deadline tasks on these systems because it's based on a snapshot in time of the available resources.
IMHO DL AC is per root domain (rd). So if we have e.g. an 8 CPU system with
aarch32_el0eq. [0-3] then we would need 2 exclusive cpusets ([0-3] and [4-7]) to admit 32-bit DL tasks into [0-3] (i.e. to pass theif (!cpumask_subset(span, p->cpus_ptr) ...test in__sched_setscheduler().
Quoted 4 lines
Trying to admit too many 32-bit DL tasks or trying to hp out a CPU[0-3] would lead to
Device or resource busyin case the rd bw wouldn't be sufficient anymore for the set of admitted tasks. But the [0-3] DL AC wouldn't care about hp on CPU[4-7].
So I think Will has a point since, IIRC, the root domains get rebuilt during hotplug. So you can imagine a case with a single root domain, but CPUs 4-7 are offline. In this case, sched_setattr() will happily promote a task to DL as long as its affinity mask is a superset of the rd span, but things may get ugly when CPUs are plugged back in later on.
This looks like an existing bug though. I just tried the following on a system with 4 CPUs:
// Create a task affined to CPU [0-2]
> while true; do echo "Hi" > /dev/null; done &
[1] 560
> mypid=$!
> taskset -p 7 $mypid
pid 560's current affinity mask: f
pid 560's new affinity mask: 7
// Try to move it DL, this should fail because of the affinity
> chrt -d -T 5000000 -P 16666666 -p 0 $mypid
chrt: failed to set pid 560's policy: Operation not permitted
// Offline CPU 3, so the rd now covers CPUs 0-2 only
> echo 0 > /sys/devices/system/cpu/cpu3/online
[ 400.843830] CPU3: shutdown
[ 400.844100] psci: CPU3 killed (polled 0 ms)
// Try to admit the task again, which now succeeds
> chrt -d -T 5000000 -P 16666666 -p 0 $mypid
// Plug CPU3 back online
> echo 1 > /sys/devices/system/cpu/cpu3/online
[ 408.819337] Detected PIPT I-cache on CPU3
[ 408.819642] GICv3: CPU3: found redistributor 3 region 0:0x0000000008100000
[ 408.820165] CPU3: Booted secondary processor 0x0000000003 [0x410fd083]I don't see any easy way to fix this w/o iterating over all deadline tasks in the rd when hotplugging a CPU back on, and blocking the hotplug operation if it'll cause affinity issues. Urgh.
Re: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Daniel Bristot de OliveiraQuoted 44 lines · Daniel Bristot de Oliveira
Quoted 8 lines · Will Deacon
Interesting, thanks. Thinking about this some more, it strikes me that with these silly asymmetric systems there could be an interesting additional problem with hotplug and deadline tasks. Imagine the following sequence of events:
1. All online CPUs are 32-bit-capable
2.sched_setattr()admits a 32-bit deadline task
3. A 64-bit-only CPU is onlinedAt the point 3, the global scheduler assumption is broken. For instance, in a system with four CPUs and five ready 32-bit-capable tasks, when the fifth CPU as added, the working conserving rule is violated because the five highest priority thread are not running (only four are) :-(.
So, at this point, for us to keep to the current behavior, the addition should be.. blocked? :-((
Quoted 1 line
4. Some of the 32-bit-capable CPUs are offlined
Assuming that point 3 does not exist (i.e., all CPUs are 32-bit-capable). At this point, we will have an increase in the pressure on the 32-bit-capable CPUs.
This can also create bad effects for 64-bit tasks, as the "contended" 32-bit tasks will still be "queued" in a future time where they were supposed to be done (leaving time for the 64-bit tasks).
Quoted 3 lines
I wonder if we can get into a situation where we think we have enough bandwidth available, but in reality the 32-bit task is in trouble because it can't make use of the 64-bit-only CPU.
I would have to think more, but there might be a case where this contended 32-bit tasks could cause deadline misses for the 64-bit too.
Quoted 3 lines
If so, then it seems to me that admission control is really just "best-effort" for 32-bit deadline tasks on these systems because it's based on a snapshot in time of the available resources.
The admission test as is now is "best-effort" in the sense that it allows a workload higher than it could handle (it is necessary, but not sufficient AC). But it should not be considered "best-effort" because of violations in the working conserving property as a result of arbitrary affinities among tasks. Overall, we have been trying to close any "exception left" to this later case.
Quoted 4 lines
I know, it is a complex situation, I am just trying to illustrate our concerns, because, in the near future we might have a scheduler that handles arbitrary affinity correctly. But that might require us to stick to an AC. The AC is something precious for us.
FWIW, I agree with the above. As pointed out in another reply, this looks like an existing bug and there is nothing specific to 32bits tasks here.
But I don't think the existence of this bug should be a reason for breaking AC even more than it is. So it still feels cleaner to block execve() into 32bit if AC is on until we have proper support for affinities in DL. And if folks want to use 32bit DL tasks on these systems they'll have to disable AC, but at least they know what they are getting ...
Thanks,
Quentin
Juri Lelli
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Quentin PerretOn 21/05/21 13:02, Quentin Perret wrote:
...
Quoted 35 lines
So I think Will has a point since, IIRC, the root domains get rebuilt during hotplug. So you can imagine a case with a single root domain, but CPUs 4-7 are offline. In this case,
sched_setattr()will happily promote a task to DL as long as its affinity mask is a superset of the rd span, but things may get ugly when CPUs are plugged back in later on.This looks like an existing bug though. I just tried the following on a system with 4 CPUs:
// Create a task affined to CPU [0-2] > while true; do echo "Hi" > /dev/null; done & [1] 560 > mypid=$! > taskset -p 7 $mypid pid 560's current affinity mask: f pid 560's new affinity mask: 7 // Try to move it DL, this should fail because of the affinity > chrt -d -T 5000000 -P 16666666 -p 0 $mypid chrt: failed to set pid 560's policy: Operation not permitted // Offline CPU 3, so the rd now covers CPUs 0-2 only > echo 0 > /sys/devices/system/cpu/cpu3/online [ 400.843830] CPU3: shutdown [ 400.844100] psci: CPU3 killed (polled 0 ms) // Try to admit the task again, which now succeeds > chrt -d -T 5000000 -P 16666666 -p 0 $mypid // Plug CPU3 back online > echo 1 > /sys/devices/system/cpu/cpu3/online [ 408.819337] Detected PIPT I-cache on CPU3 [ 408.819642] GICv3: CPU3: found redistributor 3 region 0:0x0000000008100000 [ 408.820165] CPU3: Booted secondary processor 0x0000000003 [0x410fd083]
Quoted 4 lines
I don't see any easy way to fix this w/o iterating over all deadline tasks in the rd when hotplugging a CPU back on, and blocking the hotplug operation if it'll cause affinity issues. Urgh.
Yeah this looks like a plain existing bug, joy. :)
We fixed a few around AC lately, but I guess work wasn't complete.
Thanks,
Juri
Re: [PATCH v6 02/21] arm64: Allow mismatched 32-bit EL0 support
In reply to Will DeaconQuoted 11 lines · Will Deacon
When confronted with a mixture of CPUs, some of which support 32-bit applications and others which don't, we quite sensibly treat the system as 64-bit only for userspace and prevent
execve()of 32-bit binaries.Unfortunately, some crazy folks have decided to build systems like this with the intention of running 32-bit applications, so relax our sanitisation logic to continue to advertise 32-bit support to userspace on these systems and track the real 32-bit capable cores in a cpumask instead. For now, the default behaviour remains but will be tied to a command-line option in a later patch.
Quoted 3 lines
Signed-off-by Will Deacon <[email protected]>--- arch/arm64/include/asm/cpucaps.h | 3 +-
Heads up. I just tried to apply this on 5.13-rc2 and it failed because cpucaps. was removed; it's autogenerated now.
See commit 0c6c2d3615ef: ()"arm64: Generate cpucaps.h")
Cheers
--
Qais Youesf
Peter Zijlstra
maintainerRe: [PATCH v6 06/21] sched: Introduce task_cpu_possible_mask() to limit fallback rq selection
In reply to Will DeaconQuoted 5 lines · Will Deacon
include/linux/mmu_context.h +0
-0
include/linux/mmu_context.h line 23
Quoted 10 lines
include/linux/mmu_context.h +7
-0@@ -14,4 +14,12 @@static inline void leave_mm (int cpu) { }#endif +/* +* CPUs that are capable of running task @p. By default, we assume a sane, +* homogeneous system. Must contain at least one active CPU. +*/ +#ifndef task_cpu_possible_mask +# define task_cpu_possible_mask (p) cpu_possible_mask +#endif
#ifndef task_cpu_possible_mask
# define task_cpu_possible_mask(p) cpu_possible_mask # define task_cpu_possible(cpu, p) true #else # define task_cpu_possible(cpu, p) cpumask_test_cpu((cpu), task_cpu_possible_mask(p)) #endif
kernel/sched/core.c static inline bool is_cpu_allowed(struct task_struct *p, int cpu) · line 1817
Quoted 12 lines
include/linux/mmu_context.h +1
-0+#endif kernel/sched/core.c +0
-1@@ -1813,8 +1813,11 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu)return cpu_online (cpu);/* Non kernel threads are not allowed during either online or offline. */ if (!(p->flags &PF_KTHREAD )) -return cpu_active (cpu);
+ return cpu_active(cpu) && task_cpu_possible(cpu, p);
kernel/sched/core.c static inline bool is_cpu_allowed(struct task_struct *p, int cpu) · line 1823
Quoted 2 lines
kernel/sched/core.c +0
-0/* KTHREAD_IS_PER_CPU is always allowed. */ if (kthread_is_per_cpu (p))
Would something like that make sense?
Re: [PATCH v6 08/21] cpuset: Honour task_cpu_possible_mask() in guarantee_online_cpus()
In reply to Will DeaconQuoted 51 lines · Will Deacon
Asymmetric systems may not offer the same level of userspace ISA support across all CPUs, meaning that some applications cannot be executed by some CPUs. As a concrete example, upcoming arm64 big.LITTLE designs do not feature support for 32-bit applications on both clusters.
Modify
guarantee_online_cpus()to taketask_cpu_possible_mask()into account when trying to find a suitable set of online CPUs for a given task. This will avoid passing an invalid mask toset_cpus_allowed_ptr()during ->attach() and will subsequently allow the cpuset hierarchy to be taken into account when forcefully overriding the affinity mask for a task which requires migration to a compatible CPU.Cc Li Zefan <[email protected]>Cc Tejun Heo <[email protected]>Cc Johannes Weiner <[email protected]>Signed-off-by Will Deacon <[email protected]>--- include/linux/cpuset.h | 2 +- kernel/cgroup/cpuset.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-)include/linux/cpuset.h +1
-1@@ -185,7 +185,7 @@ static inline void cpuset_read_unlock(void) { }static inline void cpuset_cpus_allowed (struct task_struct *p,struct cpumask *mask) { -cpumask_copy (mask, cpu_possible_mask); +cpumask_copy (mask,task_cpu_possible_mask (p)); }static inline void cpuset_cpus_allowed_fallback (struct task_struct *p)kernel/cgroup/cpuset.c +4
-3@@ -372,18 +372,26 @@ static inline bool is_in_v2_mode(void) }/* -* Return in pmask the portion of a cpusets's cpus_allowed that -* are online. If none are online, walk up the cpuset hierarchy -* until we find one that does have some online cpus. +* Return in pmask the portion of a task's cpusets's cpus_allowed that +* are online and are capable of running the task. If none are found, +* walk up the cpuset hierarchy until we find one that does have some +* appropriate cpus. * * One way or another, we guarantee to return some non-empty subset
kernel/cgroup/cpuset.c static inline bool is_in_v2_mode(void) · line 388
Quoted 10 lines
kernel/cgroup/cpuset.c +3
-2* of cpu_online_mask. * * Call with callback_lock or cpuset_mutex held. */ -static void guarantee_online_cpus (struct cpuset *cs,struct cpumask *pmask) +static void guarantee_online_cpus (struct task_struct *tsk, +struct cpumask *pmask) { -while (!cpumask_intersects (cs->effective_cpus, cpu_online_mask)) { +struct cpuset *cs =task_cs (tsk);
task_cs() requires rcu_read_lock(), but I can't see how the lock is obtained from cpuset_attach() path, did I miss it? Running with lockdep should spill suspicious RCU usage warning.
Maybe it makes more sense to move the rcu_read_lock() inside the function now with task_cs()?
Thanks
--
Qais Yousef
Quoted 54 lines
kernel/cgroup/cpuset.c +12
-9+const struct cpumask *possible_mask =task_cpu_possible_mask (tsk); + +if (WARN_ON (!cpumask_and (pmask, possible_mask, cpu_online_mask))) +cpumask_copy (pmask, cpu_online_mask); + +while (!cpumask_intersects (cs->effective_cpus, pmask)) { cs =parent_cs (cs);if (unlikely (!cs)) {/* @@ -393,11 +401,10 @@ static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask)* cpuset's effective_cpus is on its way to be * identical to cpu_online_mask. */ -cpumask_copy (pmask, cpu_online_mask);return ; } } -cpumask_and (pmask, cs->effective_cpus, cpu_online_mask); +cpumask_and (pmask, pmask, cs->effective_cpus); }/* @@ -2199,15 +2206,13 @@ static void cpuset_attach(struct cgroup_taskset *tset)percpu_down_write (&cpuset_rwsem); -/* prepare for attach */ -if (cs == &top_cpuset) -cpumask_copy (cpus_attach, cpu_possible_mask); -else -guarantee_online_cpus (cs, cpus_attach); -guarantee_online_mems (cs, &cpuset_attach_nodemask_to);cgroup_taskset_for_each (task, css, tset) { +if (cs != &top_cpuset) +guarantee_online_cpus (task, cpus_attach); +else +cpumask_copy (cpus_attach,task_cpu_possible_mask (task));/* * can_attach beforehand should guarantee that this doesn't * fail. TODO: have a better way to handle failure here @@ -3303,7 +3308,7 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)spin_lock_irqsave (&callback_lock, flags);rcu_read_lock (); -guarantee_online_cpus (task_cs (tsk), pmask); +guarantee_online_cpus (tsk, pmask);rcu_read_unlock ();spin_unlock_irqrestore (&callback_lock, flags); }Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Re: [PATCH v6 11/21] sched: Split the guts of sched_setaffinity() into a helper function
In reply to Will DeaconQuoted 20 lines · Will Deacon
In preparation for replaying user affinity requests using a saved mask, split
sched_setaffinity()up so that the initial task lookup and security checks are only performed when the request is coming directly from userspace.Signed-off-by Will Deacon <[email protected]>--- kernel/sched/core.c | 110 +++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 52 deletions(-)kernel/sched/core.c +1
-1@@ -6788,9 +6788,61 @@ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,return retval; } -long sched_setaffinity (pid_t pid,const struct cpumask *in_mask) +static int
kernel/sched/core.c SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, · line 6801
Quoted 10 lines
kernel/sched/core.c +8
-0+__sched_setaffinity(struct task_struct *p, const struct cpumask *mask) { + int retval;cpumask_var_t cpus_allowed, new_mask; + +if (!alloc_cpumask_var (&cpus_allowed,GFP_KERNEL )) +return -ENOMEM ; + +if (!alloc_cpumask_var (&new_mask,GFP_KERNEL )) +return -ENOMEM ;
Shouldn't we free cpus_allowed first?
Cheers
--
Qais Yousef
Quoted 124 lines
kernel/sched/core.c +49
-51+ +cpuset_cpus_allowed (p, cpus_allowed); +cpumask_and (new_mask, mask, cpus_allowed); + +/* +* Since bandwidth control happens on root_domain basis, +* if admission test is enabled, we only admit -deadline +* tasks allowed to run on all the CPUs in the task's +* root_domain. +*/ +#ifdef CONFIG_SMP +if (task_has_dl_policy (p) &&dl_bandwidth_enabled ()) { +rcu_read_lock (); +if (!cpumask_subset (task_rq (p)->rd->span, new_mask)) { + retval = -EBUSY ; +rcu_read_unlock (); + goto out_free_masks; + } +rcu_read_unlock (); + } +#endif +again: + retval =__set_cpus_allowed_ptr (p, new_mask,SCA_CHECK ); +if (retval) + goto out_free_masks; + +cpuset_cpus_allowed (p, cpus_allowed); +if (!cpumask_subset (new_mask, cpus_allowed)) { +/* +* We must have raced with a concurrent cpuset update. +* Just reset the cpumask to the cpuset's cpus_allowed. +*/ +cpumask_copy (new_mask, cpus_allowed); + goto again; + } + +out_free_masks: +free_cpumask_var (new_mask); +free_cpumask_var (cpus_allowed); +return retval; +} + +long sched_setaffinity (pid_t pid,const struct cpumask *in_mask) +{struct task_struct *p;int retval;@@ -6810,68 +6862,22 @@ long sched_setaffinity(pid_t pid, const struct cpumask *in_mask) retval = -EINVAL ; goto out_put_task; } -if (!alloc_cpumask_var (&cpus_allowed,GFP_KERNEL )) { - retval = -ENOMEM ; - goto out_put_task; - } -if (!alloc_cpumask_var (&new_mask,GFP_KERNEL )) { - retval = -ENOMEM ; - goto out_free_cpus_allowed; - } - retval = -EPERM ; +if (!check_same_owner (p)) {rcu_read_lock ();if (!ns_capable (__task_cred (p)->user_ns,CAP_SYS_NICE )) {rcu_read_unlock (); - goto out_free_new_mask; + retval = -EPERM ; + goto out_put_task; }rcu_read_unlock (); } retval =security_task_setscheduler (p);if (retval) - goto out_free_new_mask; - - -cpuset_cpus_allowed (p, cpus_allowed); -cpumask_and (new_mask, in_mask, cpus_allowed); - -/* -* Since bandwidth control happens on root_domain basis, -* if admission test is enabled, we only admit -deadline -* tasks allowed to run on all the CPUs in the task's -* root_domain. -*/ -#ifdef CONFIG_SMP -if (task_has_dl_policy (p) &&dl_bandwidth_enabled ()) { -rcu_read_lock (); -if (!cpumask_subset (task_rq (p)->rd->span, new_mask)) { - retval = -EBUSY ; -rcu_read_unlock (); - goto out_free_new_mask; - } -rcu_read_unlock (); - } -#endif -again: - retval =__set_cpus_allowed_ptr (p, new_mask,SCA_CHECK ); + goto out_put_task; -if (!retval) { -cpuset_cpus_allowed (p, cpus_allowed); -if (!cpumask_subset (new_mask, cpus_allowed)) { -/* -* We must have raced with a concurrent cpuset -* update. Just reset the cpus_allowed to the -* cpuset's cpus_allowed -*/ -cpumask_copy (new_mask, cpus_allowed); - goto again; - } - } -out_free_new_mask: -free_cpumask_var (new_mask); -out_free_cpus_allowed: -free_cpumask_var (cpus_allowed); + retval =__sched_setaffinity (p, in_mask); out_put_task:put_task_struct (p);return retval;Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Re: [PATCH v6 12/21] sched: Allow task CPU affinity to be restricted on asymmetric systems
In reply to Will DeaconQuoted 82 lines · Will Deacon
Asymmetric systems may not offer the same level of userspace ISA support across all CPUs, meaning that some applications cannot be executed by some CPUs. As a concrete example, upcoming arm64 big.LITTLE designs do not feature support for 32-bit applications on both clusters.
Although userspace can carefully manage the affinity masks for such tasks, one place where it is particularly problematic is
execve()because the CPU on which theexecve()is occurring may be incompatible with the new application image. In such a situation, it is desirable to restrict the affinity mask of the task and ensure that the new image is entered on a compatible CPU. From userspace's point of view, this looks the same as if the incompatible CPUs have been hotplugged off in the task's affinity mask. Similarly, if a subsequentexecve()reverts to a compatible image, then the old affinity is restored if it is still valid.In preparation for restricting the affinity mask for compat tasks on arm64 systems without uniform support for 32-bit applications, introduce {force,relax}_compatible_cpus_allowed_ptr(), which respectively restrict and restore the affinity mask for a task based on the compatible CPUs.
Reviewed-by Quentin Perret <[email protected]>Signed-off-by Will Deacon <[email protected]>--- include/linux/sched.h | 2 + kernel/sched/core.c | 165 ++++++++++++++++++++++++++++++++++++++---- kernel/sched/sched.h | 1 + 3 files changed, 152 insertions(+), 16 deletions(-)include/linux/sched.h +2
-0@@ -1691,6 +1691,8 @@ extern void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *newextern int set_cpus_allowed_ptr (struct task_struct *p,const struct cpumask *new_mask);extern int dup_user_cpus_ptr (struct task_struct *dst,struct task_struct *src,int node);extern void release_user_cpus_ptr (struct task_struct *p); +extern void force_compatible_cpus_allowed_ptr (struct task_struct *p); +extern void relax_compatible_cpus_allowed_ptr (struct task_struct *p);#else static inline void do_set_cpus_allowed (struct task_struct *p,const struct cpumask *new_mask) {kernel/sched/core.c +8
-13@@ -2357,26 +2357,21 @@ static int affine_move_task(struct rq *rq, struct task_struct *p, struct rq_flag }/* -* Change a given task's CPU affinity. Migrate the thread to a -* proper CPU and schedule it away if the CPU it's executing on -* is removed from the allowed bitmask. -* -* NOTE: the caller must have a valid reference to the task, the -* task must not exit() & deallocate itself prematurely. The -* call is not atomic; no spinlocks may be held. +* Called with both p->pi_lock and rq->lock held; drops both before returning. */ -static int __set_cpus_allowed_ptr (struct task_struct *p, -const struct cpumask *new_mask, -u32 flags) +static int __set_cpus_allowed_ptr_locked (struct task_struct *p, +const struct cpumask *new_mask, +u32 flags, +struct rq *rq, +struct rq_flags *rf) + __releases(rq->lock) + __releases(p->pi_lock) {const struct cpumask *cpu_valid_mask = cpu_active_mask;const struct cpumask *cpu_allowed_mask =task_cpu_possible_mask (p);unsigned int dest_cpu; -struct rq_flags rf; -struct rq *rq;int ret =0 ; - rq =task_rq_lock (p, &rf);update_rq_clock (rq);if (p->flags &PF_KTHREAD ||is_migration_disabled (p)) {
kernel/sched/core.c static int __set_cpus_allowed_ptr(struct task_struct *p, · line 2429
Quoted 6 lines
kernel/sched/core.c +2
-1@@ -2430,20 +2425,158 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,__do_set_cpus_allowed (p, new_mask, flags); -return affine_move_task (rq, p, &rf, dest_cpu, flags); +if (flags &SCA_USER ) +release_user_cpus_ptr (p);
Why do we need to release the pointer here?
Doesn't this mean if a 32bit task requests to change its affinity, then we'll lose this info and a subsequent execve() to a 64bit application means we won't be able to restore the original mask?
ie:
p0-64bit execve(32bit_app) // p1-32bit created p1-32bit.change_affinity() relase_user_cpus_ptr() execve(64bit_app) // lost info about p0 affinity?
Hmm I think this helped me to get the answer. p1 changed its affinity, then there's nothing to be inherited by a new execve(), so yes we no longer need this info.
Quoted 9 lines
kernel/sched/core.c +3
-1+ +return affine_move_task (rq, p, rf, dest_cpu, flags); out: -task_rq_unlock (rq, p, &rf); +task_rq_unlock (rq, p, rf);return ret; }
[...]
Quoted 28 lines
kernel/sched/core.c +28
-0+/* +* Change a given task's CPU affinity to the intersection of its current +* affinity mask and @subset_mask, writing the resulting mask to @new_mask +* and pointing @p->user_cpus_ptr to a copy of the old mask. +* If the resulting mask is empty, leave the affinity unchanged and return +* -EINVAL. +*/ +static int restrict_cpus_allowed_ptr (struct task_struct *p, +struct cpumask *new_mask, +const struct cpumask *subset_mask) +{ +struct rq_flags rf; +struct rq *rq; +int err; +struct cpumask *user_mask =NULL ; + +if (!p->user_cpus_ptr) + user_mask =kmalloc (cpumask_size (),GFP_KERNEL ); + + rq =task_rq_lock (p, &rf); + +/* +* We're about to butcher the task affinity, so keep track of what +* the user asked for in case we're able to restore it later on. +*/ +if (user_mask) { +cpumask_copy (user_mask, p->cpus_ptr); + p->user_cpus_ptr = user_mask;
kernel/sched/core.c static int __set_cpus_allowed_ptr(struct task_struct *p, · line 2501
Quoted 10 lines
kernel/sched/core.c +10
-0+ } + +/* +* Forcefully restricting the affinity of a deadline task is +* likely to cause problems, so fail and noisily override the +* mask entirely. +*/ +if (task_has_dl_policy (p) &&dl_bandwidth_enabled ()) { + err = -EPERM ; + goto err_unlock;
free(user_mark) first?
kernel/sched/core.c static int __set_cpus_allowed_ptr(struct task_struct *p, · line 2506
Quoted 5 lines
kernel/sched/core.c +5
-0+ } + +if (!cpumask_and (new_mask, &p->cpus_mask, subset_mask)) { + err = -EINVAL ; + goto err_unlock;
ditto
kernel/sched/core.c static int __set_cpus_allowed_ptr(struct task_struct *p, · line 2514
Quoted 8 lines
kernel/sched/core.c +8
-0+ } + +return __set_cpus_allowed_ptr_locked (p, new_mask, false, rq, &rf); + +err_unlock: +task_rq_unlock (rq, p, &rf); +return err; +}
Thanks
--
Qais Yousef
Re: [PATCH v6 21/21] Documentation: arm64: describe asymmetric 32-bit support
In reply to Will DeaconQuoted 11 lines · Will Deacon
Document support for running 32-bit tasks on asymmetric 32-bit systems and its impact on the user ABI when enabled.
Signed-off-by Will Deacon <[email protected]>--- .../admin-guide/kernel-parameters.txt | 3 + Documentation/arm64/asymmetric-32bit.rst | 149 ++++++++++++++++++ Documentation/arm64/index.rst | 1 + 3 files changed, 153 insertions(+) create mode 100644 Documentation/arm64/asymmetric-32bit.rst
[...]
Quoted 6 lines
Documentation/arm64/asymmetric-32bit.rst new file +6
-0+Cpusets +------- + +The affinity of a 32-bit task may include CPUs that are not explicitly +allowed by the cpuset to which it is attached. This can occur as a +result of the following two situations:
Documentation/arm64/asymmetric-32bit.rst line 132
Quoted 10 lines
Documentation/arm64/asymmetric-32bit.rst new file +10
-0+ + - A 64-bit task attached to a cpuset which allows only 64-bit CPUs + executes a 32-bit program. + + - All of the 32-bit-capable CPUs allowed by a cpuset containing a + 32-bit task are offlined. + +In both of these cases, the new affinity is calculated according to step +(2) of the process described in `execve(2)`_ and the cpuset hierarchy is +unchanged irrespective of the cgroup version.
nit: Should we call out that we're breaking cpuset-v1 behavior? Don't feel strongly about it.
Cheers
--
Qais Yousef
Re: [PATCH v6 07/21] cpuset: Don't use the cpu_possible_mask as a last resort for cgroup v1
In reply to Will DeaconQuoted 41 lines · Will Deacon
If the scheduler cannot find an allowed CPU for a task,
cpuset_cpus_allowed_fallback()will widen the affinity tocpu_possible_maskif cgroup v1 is in use.In preparation for allowing architectures to provide their own fallback mask, just return early if we're either using cgroup v1 or we're using cgroup v2 with a mask that contains invalid CPUs. This will allow
select_fallback_rq()to figure out the mask by itself.Cc Li Zefan <[email protected]>Cc Tejun Heo <[email protected]>Cc Johannes Weiner <[email protected]>Reviewed-by Quentin Perret <[email protected]>Signed-off-by Will Deacon <[email protected]>--- include/linux/cpuset.h | 1 + kernel/cgroup/cpuset.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)include/linux/cpuset.h +1
-0@@ -15,6 +15,7 @@#include <linux/cpumask.h> #include <linux/nodemask.h> #include <linux/mm.h> +#include <linux/mmu_context.h> #include <linux/jump_label.h> #ifdef CONFIG_CPUSETS kernel/cgroup/cpuset.c +2
-0@@ -3322,9 +3322,17 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)void cpuset_cpus_allowed_fallback (struct task_struct *tsk) { +const struct cpumask *cs_mask; +const struct cpumask *possible_mask =task_cpu_possible_mask (tsk);
kernel/cgroup/cpuset.c void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) · line 3334
Quoted 10 lines
kernel/cgroup/cpuset.c +7
-2+rcu_read_lock (); -do_set_cpus_allowed (tsk,is_in_v2_mode () ? -task_cs (tsk)->cpus_allowed : cpu_possible_mask); + cs_mask =task_cs (tsk)->cpus_allowed; + +if (!is_in_v2_mode () || !cpumask_subset (cs_mask, possible_mask)) + goto unlock;/* select_fallback_rq will try harder */ + +do_set_cpus_allowed (tsk, cs_mask);
Shouldn't we take the intersection with possible_mask like we discussed before?
https://lore.kernel.org/lkml/20201217145954.GA17881@willie-the-truck/
Thanks
--
Qais Yousef
Quoted 7 lines
kernel/cgroup/cpuset.c +1
-0+unlock:rcu_read_unlock ();/* Signature · 1 line
2.31.1.751.gd2f1c929bd-goog
Hi Will
Quoted 40 lines · Will Deacon
Hi folks,
This is the long-awaited v6 of these patches which I last posted at the end of last year:
v1: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/r/[email protected]
v3: https://lore.kernel.org/r/[email protected]
v4: https://lore.kernel.org/r/[email protected]
v5: https://lore.kernel.org/r/[email protected]There was also a nice LWN writeup in case you've forgotten what this is about:
https://lwn.net/Articles/838339/It's taken me a while to get a v6 of this together, partly due to addressing the review feedback on v5, but also because this has now seen testing on real hardware which threw up some surprises in suspend/resume,
SCHED_DEADLINEand compat hwcap reporting. Thanks to Quentin for helping me to debug those issues.The aim of this series is to allow 32-bit ARM applications to run on arm64 SoCs where not all of the CPUs support the 32-bit instruction set. Unfortunately, such SoCs are real and will continue to be productised over the next few years at least. I can assure you that I'm not just doing this for fun.
Changes in v6 include:
* Save/restore the affinity mask across
execve()to 32-bit and back to64-bit again.* Allow 32-bit deadline tasks, but skip straight to fallback path when determining new affinity mask on
execve().* Fixed resume-from-suspend path when the resuming CPU is 64-bit-only by deferring wake-ups for 32-bit tasks until the secondary CPUs are back online.
Quoted 8 lines
* Bug fixes (compat hwcaps, memory leak, cpuset fallback path).
* Documentation for arm64. It's in the divisive .rst format, but please take a look anyway!
I'm pretty happy with this now and it seems to do the right thing, although the new patches in this revision would certainly benefit from review. Series based on v5.13-rc1.
It's late Fri and I'm off next week (I'm starting to sense an omen here, it's the 2nd or 3rd time the post syncs with my holiday), so a bit of a rushed review but the series looks good to me. Feel free to stick my Reviewed-by for the series, except patch 13 where I skipped it, given the few comments I had are addressed.
I did test v5, but not this version. I think it had found better victims to test it now :-P
Thanks!
--
Qais Yousef
Dietmar Eggemann
reviewerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Juri LelliQuoted 9 lines · Juri Lelli
On 21/05/21 13:02, Quentin Perret wrote:
...
Quoted 5 lines
So I think Will has a point since, IIRC, the root domains get rebuilt during hotplug. So you can imagine a case with a single root domain, but CPUs 4-7 are offline. In this case,
sched_setattr()will happily promote a task to DL as long as its affinity mask is a superset of the rd span, but things may get ugly when CPUs are plugged back in later on.
Yeah, that's true. I understand the condition, that the task's affinity mask has to be a superset of the rd span, as that DL AC (i.e DL BW management) can only work correctly if all admitted tasks can run on every CPU in the rd.
Like you said, you can already today let tasks with reduced affinity mask pass the DL AC in case you hp out the other CPUs and then trick DL AC by hp in the remaining CPUs and admit more DL tasks. But these steps require a lot of effort to create this false setup.
The dedicated rd for 32-bit tasks matching aarch32_el0 in an exclusive cpuset env seems to be a feasible approach to me. But I also don't see an eminent use case for this.
Quoted 29 lines
Quoted 29 lines
This looks like an existing bug though. I just tried the following on a system with 4 CPUs:
// Create a task affined to CPU [0-2] > while true; do echo "Hi" > /dev/null; done & [1] 560 > mypid=$! > taskset -p 7 $mypid pid 560's current affinity mask: f pid 560's new affinity mask: 7 // Try to move it DL, this should fail because of the affinity > chrt -d -T 5000000 -P 16666666 -p 0 $mypid chrt: failed to set pid 560's policy: Operation not permitted // Offline CPU 3, so the rd now covers CPUs 0-2 only > echo 0 > /sys/devices/system/cpu/cpu3/online [ 400.843830] CPU3: shutdown [ 400.844100] psci: CPU3 killed (polled 0 ms) // Try to admit the task again, which now succeeds > chrt -d -T 5000000 -P 16666666 -p 0 $mypid // Plug CPU3 back online > echo 1 > /sys/devices/system/cpu/cpu3/online [ 408.819337] Detected PIPT I-cache on CPU3 [ 408.819642] GICv3: CPU3: found redistributor 3 region 0:0x0000000008100000 [ 408.820165] CPU3: Booted secondary processor 0x0000000003 [0x410fd083]
Quoted 3 lines
Quoted 3 lines
I don't see any easy way to fix this w/o iterating over all deadline tasks in the rd when hotplugging a CPU back on, and blocking the hotplug operation if it'll cause affinity issues. Urgh.
Something like dl_cpu_busy() in cpuset_cpu_inactive() but the other way around in cpuset_cpu_active().
We iterate over all DL tasks in partition_and_rebuild_sched_domains() -> rebuild_root_domains() -> update_tasks_root_domain() -> dl_add_task_root_domain(struct task_struct *p) to recreate DL BW information after CPU hp but this is asynchronously to cpuset_cpu_active().
Quoted 7 lines
Yeah this looks like a plain existing bug, joy. :)
We fixed a few around AC lately, but I guess work wasn't complete.
Thanks,
Juri
Will Deacon
maintainerRe: [PATCH v6 02/21] arm64: Allow mismatched 32-bit EL0 support
In reply to Catalin MarinasQuoted 17 lines · Catalin Marinas
arch/arm64/kernel/cpufeature.c has_cpuid_feature(const struct arm64_cpu_capabilities *entry, int scope) · line 1309
Quoted 10 lines · Will Deacon
arch/arm64/kernel/cpufeature.c +10
-0+static bool has_32bit_el0 (const struct arm64_cpu_capabilities *entry,int scope) +{ +if (!has_cpuid_feature (entry, scope)) +return allow_mismatched_32bit_el0; + +if (scope ==SCOPE_SYSTEM ) +pr_info ("detected: 32-bit EL0 Support\n" ); + +return true; +}We may have discussed this before: AFAICT this will print 32-bit EL0 detected even if there's no 32-bit EL0 on any CPU. Should we instead print 32-bit EL0 detected on CPU X when
allow_mismatched_32bit_el0is passed? It would also give us an indication of the system configuration when people start reporting bugs.
The function above only runs if we've detected 32-bit support via aa64pfr0_el1, so I think we're ok. We also have a print when we detect the mismatch (see enable_mismatched_32bit_el0()).
Will
Will Deacon
maintainerRe: [PATCH v6 02/21] arm64: Allow mismatched 32-bit EL0 support
In reply to Catalin MarinasQuoted 12 lines · Catalin Marinas
arch/arm64/kernel/cpufeature.c void __init setup_cpu_features(void) · line 2885
Quoted 8 lines · Will Deacon
arch/arm64/kernel/cpufeature.c +8
-0+static int enable_mismatched_32bit_el0 (unsigned int cpu) +{ +struct cpuinfo_arm64 *info = &per_cpu (cpu_data, cpu); +bool cpu_32bit =id_aa64pfr0_32bit_el0 (info->reg_id_aa64pfr0); + +if (cpu_32bit) { +cpumask_set_cpu (cpu, cpu_32bit_el0_mask); +static_branch_enable_cpuslocked (&arm64_mismatched_32bit_el0);It may be worth only calling
static_branch_enable_cpuslocked()if not already set, in case you try this on a system with lots of CPUs.
static_key_enable_cpuslocked() already checks this early on, so I don't think we need another check here (note that we're not calling stop_machine() here _anyway_; the '_cpuslocked' suffix just says that we're already holding cpu_hotplug_lock via the notifier).
Will
Will Deacon
maintainerRe: [PATCH v6 06/21] sched: Introduce task_cpu_possible_mask() to limit fallback rq selection
In reply to Peter ZijlstraQuoted 38 lines · Peter Zijlstra
Quoted 5 lines · Will Deacon
include/linux/mmu_context.h +0
-0include/linux/mmu_context.h line 23
Quoted 10 lines
include/linux/mmu_context.h +7
-0@@ -14,4 +14,12 @@static inline void leave_mm (int cpu) { }#endif +/* +* CPUs that are capable of running task @p. By default, we assume a sane, +* homogeneous system. Must contain at least one active CPU. +*/ +#ifndef task_cpu_possible_mask +# define task_cpu_possible_mask (p) cpu_possible_mask +#endif #ifndef
task_cpu_possible_mask# define task_cpu_possible_mask(p) cpu_possible_mask # define task_cpu_possible(cpu, p) true #else # define task_cpu_possible(cpu, p) cpumask_test_cpu((cpu), task_cpu_possible_mask(p)) #endifQuoted 12 lines
include/linux/mmu_context.h +1
-0+#endif kernel/sched/core.c +0
-1@@ -1813,8 +1813,11 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu)return cpu_online (cpu);/* Non kernel threads are not allowed during either online or offline. */ if (!(p->flags &PF_KTHREAD )) -return cpu_active (cpu);(quoted diff) +1
-0+ return cpu_active(cpu) && task_cpu_possible(cpu, p);
Quoted 4 lines
kernel/sched/core.c static inline bool is_cpu_allowed(struct task_struct *p, int cpu) · line 1823
Quoted 2 lines
kernel/sched/core.c +0
-0/* KTHREAD_IS_PER_CPU is always allowed. */ if (kthread_is_per_cpu (p))Would something like that make sense?
I think this is probably the only place that we could use the helper, but it's also one of the places where architectures that don't have to worry about asymmetry end up with the check so, yes, I'll do that for v7.
Will
Catalin Marinas
maintainerRe: [PATCH v6 02/21] arm64: Allow mismatched 32-bit EL0 support
In reply to Will DeaconQuoted 14 lines · Will Deacon
Quoted 12 lines · Catalin Marinas
arch/arm64/kernel/cpufeature.c void __init setup_cpu_features(void) · line 2885
Quoted 8 lines · Will Deacon
arch/arm64/kernel/cpufeature.c +8
-0+static int enable_mismatched_32bit_el0 (unsigned int cpu) +{ +struct cpuinfo_arm64 *info = &per_cpu (cpu_data, cpu); +bool cpu_32bit =id_aa64pfr0_32bit_el0 (info->reg_id_aa64pfr0); + +if (cpu_32bit) { +cpumask_set_cpu (cpu, cpu_32bit_el0_mask); +static_branch_enable_cpuslocked (&arm64_mismatched_32bit_el0);It may be worth only calling
static_branch_enable_cpuslocked()if not already set, in case you try this on a system with lots of CPUs.
Quoted 4 lines
static_key_enable_cpuslocked()already checks this early on, so I don't think we need another check here (note that we're not callingstop_machine()here _anyway_; the '_cpuslocked' suffix just says that we're already holdingcpu_hotplug_lockvia the notifier).
Ah, you are right, no need for an additional check.
Signature · 1 line
Catalin
Re: [PATCH v6 02/21] arm64: Allow mismatched 32-bit EL0 support
In reply to Will DeaconQuoted 19 lines · Will Deacon
Quoted 17 lines · Catalin Marinas
arch/arm64/kernel/cpufeature.c has_cpuid_feature(const struct arm64_cpu_capabilities *entry, int scope) · line 1309
Quoted 10 lines · Will Deacon
arch/arm64/kernel/cpufeature.c +10
-0+static bool has_32bit_el0 (const struct arm64_cpu_capabilities *entry,int scope) +{ +if (!has_cpuid_feature (entry, scope)) +return allow_mismatched_32bit_el0; + +if (scope ==SCOPE_SYSTEM ) +pr_info ("detected: 32-bit EL0 Support\n" ); + +return true; +}We may have discussed this before: AFAICT this will print 32-bit EL0 detected even if there's no 32-bit EL0 on any CPU. Should we instead print 32-bit EL0 detected on CPU X when
allow_mismatched_32bit_el0is passed? It would also give us an indication of the system configuration when people start reporting bugs.
Quoted 3 lines
The function above only runs if we've detected 32-bit support via
aa64pfr0_el1, so I think we're ok. We also have a print when we detect the mismatch (seeenable_mismatched_32bit_el0()).
It makes sense, you removed the .desc from the arm64_features entry as well.
Re: [PATCH v6 16/21] arm64: Implement task_cpu_possible_mask()
In reply to Will DeaconQuoted 5 lines · Will Deacon
Provide an implementation of
task_cpu_possible_mask()so that we can prevent 64-bit-only cores being added to the 'cpus_mask' for compat tasks on systems with mismatched 32-bit support at EL0,Signed-off-by Will Deacon <[email protected]>
Re: [PATCH v6 17/21] arm64: exec: Adjust affinity for compat tasks with mismatched 32-bit EL0
In reply to Will DeaconQuoted 9 lines · Will Deacon
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.
Reviewed-by Quentin Perret <[email protected]>Signed-off-by Will Deacon <[email protected]>
Catalin Marinas
maintainerRe: [PATCH v6 18/21] arm64: Prevent offlining first CPU with 32-bit EL0 on mismatched system
In reply to Will DeaconQuoted 11 lines · Will Deacon
arch/arm64/kernel/cpufeature.c +2
-0@@ -2896,15 +2896,33 @@ void __init setup_cpu_features(void)static int enable_mismatched_32bit_el0 (unsigned int cpu) { +static int lucky_winner =-1 ; +struct cpuinfo_arm64 *info = &per_cpu (cpu_data, cpu);
arch/arm64/kernel/cpufeature.c void __init setup_cpu_features(void) · line 2910
Quoted 10 lines
arch/arm64/kernel/cpufeature.c +2
-1bool cpu_32bit =id_aa64pfr0_32bit_el0 (info->reg_id_aa64pfr0);if (cpu_32bit) {cpumask_set_cpu (cpu, cpu_32bit_el0_mask);static_branch_enable_cpuslocked (&arm64_mismatched_32bit_el0); -setup_elf_hwcaps (compat_elf_hwcaps); } +if (cpumask_test_cpu (0 , cpu_32bit_el0_mask) == cpu_32bit) +return 0 ;
I don't fully understand this early return. AFAICT, we still call setup_elf_hwcaps() via setup_cpu_features() if the system supports 32-bit EL0 (mismatched or not) at boot. For CPU hotplug, we can add the compat hwcaps later if we didn't set them up at boot. So this part is fine.
However, if CPU0 is 32-bit-capable, it looks like we'd never disable the offlining on any of the 32-bit-capable CPUs and there's nothing that prevents offlining CPU0.
Signature · 1 line
Catalin
Re: [PATCH v6 19/21] arm64: Hook up cmdline parameter to allow mismatched 32-bit EL0
In reply to Will DeaconQuoted 4 lines · Will Deacon
Allow systems with mismatched 32-bit support at EL0 to run 32-bit applications based on a new kernel parameter.
Signed-off-by Will Deacon <[email protected]>
Re: [PATCH v6 20/21] arm64: Remove logic to kill 32-bit tasks on 64-bit-only cores
In reply to Will DeaconQuoted 5 lines · Will Deacon
The scheduler now knows enough about these braindead systems to place 32-bit tasks accordingly, so throw out the safety checks and allow the ret-to-user path to avoid
do_notify_resume()if there is nothing to do.Signed-off-by Will Deacon <[email protected]>
Re: [PATCH v6 21/21] Documentation: arm64: describe asymmetric 32-bit support
In reply to Will DeaconQuoted 4 lines · Will Deacon
Document support for running 32-bit tasks on asymmetric 32-bit systems and its impact on the user ABI when enabled.
Signed-off-by Will Deacon <[email protected]>
The logic looks alright to me but I suspect most arguments are around the scheduler behaviour.
Will Deacon
maintainerRe: [PATCH v6 07/21] cpuset: Don't use the cpu_possible_mask as a last resort for cgroup v1
In reply to Qais YousefHi Qais,
Quoted 24 lines · Qais Yousef
Quoted 10 lines · Will Deacon
kernel/cgroup/cpuset.c +2
-0@@ -3322,9 +3322,17 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)void cpuset_cpus_allowed_fallback (struct task_struct *tsk) { +const struct cpumask *cs_mask; +const struct cpumask *possible_mask =task_cpu_possible_mask (tsk);kernel/cgroup/cpuset.c void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) · line 3334
Quoted 10 lines
kernel/cgroup/cpuset.c +7
-2+rcu_read_lock (); -do_set_cpus_allowed (tsk,is_in_v2_mode () ? -task_cs (tsk)->cpus_allowed : cpu_possible_mask); + cs_mask =task_cs (tsk)->cpus_allowed; + +if (!is_in_v2_mode () || !cpumask_subset (cs_mask, possible_mask)) + goto unlock;/* select_fallback_rq will try harder */ + +do_set_cpus_allowed (tsk, cs_mask);Shouldn't we take the intersection with
possible_masklike we discussed before?
Yes, and that's what the '!cpumask_subset()' check is doing above. Either we use the valid subset of the cpuset mask (which is the intersection with the possible mask) or we bail if that set is empty.
Will
Will Deacon
maintainerRe: [PATCH v6 02/21] arm64: Allow mismatched 32-bit EL0 support
In reply to Qais YousefQuoted 12 lines · Qais Yousef
Quoted 11 lines · Will Deacon
When confronted with a mixture of CPUs, some of which support 32-bit applications and others which don't, we quite sensibly treat the system as 64-bit only for userspace and prevent
execve()of 32-bit binaries.Unfortunately, some crazy folks have decided to build systems like this with the intention of running 32-bit applications, so relax our sanitisation logic to continue to advertise 32-bit support to userspace on these systems and track the real 32-bit capable cores in a cpumask instead. For now, the default behaviour remains but will be tied to a command-line option in a later patch.
Quoted 8 lines
Quoted 3 lines
Signed-off-by Will Deacon <[email protected]>--- arch/arm64/include/asm/cpucaps.h | 3 +-Heads up. I just tried to apply this on 5.13-rc2 and it failed because cpucaps. was removed; it's autogenerated now.
See commit
0c6c2d3615ef: ()"arm64: Generatecpucaps.h")
Yup, cheers. I'll sort that out once we're at the stage where we're merging patches.
Will
Will Deacon
maintainerRe: [PATCH v6 18/21] arm64: Prevent offlining first CPU with 32-bit EL0 on mismatched system
In reply to Catalin MarinasHi Catalin,
Quoted 29 lines · Catalin Marinas
Quoted 11 lines · Will Deacon
arch/arm64/kernel/cpufeature.c +2
-0@@ -2896,15 +2896,33 @@ void __init setup_cpu_features(void)static int enable_mismatched_32bit_el0 (unsigned int cpu) { +static int lucky_winner =-1 ; +struct cpuinfo_arm64 *info = &per_cpu (cpu_data, cpu);arch/arm64/kernel/cpufeature.c void __init setup_cpu_features(void) · line 2910
Quoted 10 lines
arch/arm64/kernel/cpufeature.c +2
-1bool cpu_32bit =id_aa64pfr0_32bit_el0 (info->reg_id_aa64pfr0);if (cpu_32bit) {cpumask_set_cpu (cpu, cpu_32bit_el0_mask);static_branch_enable_cpuslocked (&arm64_mismatched_32bit_el0); -setup_elf_hwcaps (compat_elf_hwcaps); } +if (cpumask_test_cpu (0 , cpu_32bit_el0_mask) == cpu_32bit) +return 0 ;I don't fully understand this early return. AFAICT, we still call
setup_elf_hwcaps()viasetup_cpu_features()if the system supports 32-bit EL0 (mismatched or not) at boot. For CPU hotplug, we can add the compat hwcaps later if we didn't set them up at boot. So this part is fine.
Quoted 3 lines
However, if CPU0 is 32-bit-capable, it looks like we'd never disable the offlining on any of the 32-bit-capable CPUs and there's nothing that prevents offlining CPU0.
That is also deferred until we actually detect the mismatch. For example, if CPU0 is 32-bit capable but none of the others are, then when we online CPU1 we will print:
| CPU features: Asymmetric 32-bit EL0 support detected on CPU 1; CPU hot-unplug disabled on CPU 0
so the check above is really asking "Is the CPU being onlined mismatched wrt the boot CPU?". If yes, then we need to make sure that we're keeping a 32-bit-capable CPU around.
Will
Will Deacon
maintainerRe: [PATCH v6 13/21] sched: Admit forcefully-affined tasks into SCHED_DEADLINE
In reply to Daniel Bristot de OliveiraQuoted 18 lines · Daniel Bristot de Oliveira
Quoted 8 lines · Will Deacon
Interesting, thanks. Thinking about this some more, it strikes me that with these silly asymmetric systems there could be an interesting additional problem with hotplug and deadline tasks. Imagine the following sequence of events:
1. All online CPUs are 32-bit-capable
2.sched_setattr()admits a 32-bit deadline task
3. A 64-bit-only CPU is onlinedAt the point 3, the global scheduler assumption is broken. For instance, in a system with four CPUs and five ready 32-bit-capable tasks, when the fifth CPU as added, the working conserving rule is violated because the five highest priority thread are not running (only four are) :-(.
So, at this point, for us to keep to the current behavior, the addition should be.. blocked? :-((
Quoted 8 lines
Quoted 1 line
4. Some of the 32-bit-capable CPUs are offlined
Assuming that point 3 does not exist (i.e., all CPUs are 32-bit-capable). At this point, we will have an increase in the pressure on the 32-bit-capable CPUs.
This can also create bad effects for 64-bit tasks, as the "contended" 32-bit tasks will still be "queued" in a future time where they were supposed to be done (leaving time for the 64-bit tasks).
That's a really interesting point that I hadn't previously considered. It means that the effects of 32-bit tasks with forced affinity are far reaching when it comes to deadline tasks.
Quoted 17 lines
Quoted 3 lines
I wonder if we can get into a situation where we think we have enough bandwidth available, but in reality the 32-bit task is in trouble because it can't make use of the 64-bit-only CPU.
I would have to think more, but there might be a case where this contended 32-bit tasks could cause deadline misses for the 64-bit too.
Quoted 3 lines
If so, then it seems to me that admission control is really just "best-effort" for 32-bit deadline tasks on these systems because it's based on a snapshot in time of the available resources.
The admission test as is now is "best-effort" in the sense that it allows a workload higher than it could handle (it is necessary, but not sufficient AC). But it should not be considered "best-effort" because of violations in the working conserving property as a result of arbitrary affinities among tasks. Overall, we have been trying to close any "exception left" to this later case.
Quoted 4 lines
I know, it is a complex situation, I am just trying to illustrate our concerns, because, in the near future we might have a scheduler that handles arbitrary affinity correctly. But that might require us to stick to an AC. The AC is something precious for us.
I've implemented AC on execve() of a 32-bit program so we'll fail that system call with -ENOEXEC if the root domain contains 64-bit-only CPUs. As expected, the failure mode is awful because it seems as though the ELF binary is then treated like a shell script by userspace and passed to /bin/sh:
$ sudo chrt -d -T 5000000 -P 16666666 0 ./hello32 ./hello32: 1: Syntax error: word unexpected (expecting ")")
Anyway, I'll include this in v7.
Cheers,
Will
Will Deacon
maintainerRe: [PATCH v6 08/21] cpuset: Honour task_cpu_possible_mask() in guarantee_online_cpus()
In reply to Qais YousefQuoted 67 lines · Qais Yousef
Quoted 51 lines · Will Deacon
Asymmetric systems may not offer the same level of userspace ISA support across all CPUs, meaning that some applications cannot be executed by some CPUs. As a concrete example, upcoming arm64 big.LITTLE designs do not feature support for 32-bit applications on both clusters.
Modify
guarantee_online_cpus()to taketask_cpu_possible_mask()into account when trying to find a suitable set of online CPUs for a given task. This will avoid passing an invalid mask toset_cpus_allowed_ptr()during ->attach() and will subsequently allow the cpuset hierarchy to be taken into account when forcefully overriding the affinity mask for a task which requires migration to a compatible CPU.Cc Li Zefan <[email protected]>Cc Tejun Heo <[email protected]>Cc Johannes Weiner <[email protected]>Signed-off-by Will Deacon <[email protected]>--- include/linux/cpuset.h | 2 +- kernel/cgroup/cpuset.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-)include/linux/cpuset.h +1
-1@@ -185,7 +185,7 @@ static inline void cpuset_read_unlock(void) { }static inline void cpuset_cpus_allowed (struct task_struct *p,struct cpumask *mask) { -cpumask_copy (mask, cpu_possible_mask); +cpumask_copy (mask,task_cpu_possible_mask (p)); }static inline void cpuset_cpus_allowed_fallback (struct task_struct *p)kernel/cgroup/cpuset.c +4
-3@@ -372,18 +372,26 @@ static inline bool is_in_v2_mode(void) }/* -* Return in pmask the portion of a cpusets's cpus_allowed that -* are online. If none are online, walk up the cpuset hierarchy -* until we find one that does have some online cpus. +* Return in pmask the portion of a task's cpusets's cpus_allowed that +* are online and are capable of running the task. If none are found, +* walk up the cpuset hierarchy until we find one that does have some +* appropriate cpus. * * One way or another, we guarantee to return some non-empty subset kernel/cgroup/cpuset.c static inline bool is_in_v2_mode(void) · line 388
Quoted 10 lines
kernel/cgroup/cpuset.c +3
-2* of cpu_online_mask. * * Call with callback_lock or cpuset_mutex held. */ -static void guarantee_online_cpus (struct cpuset *cs,struct cpumask *pmask) +static void guarantee_online_cpus (struct task_struct *tsk, +struct cpumask *pmask) { -while (!cpumask_intersects (cs->effective_cpus, cpu_online_mask)) { +struct cpuset *cs =task_cs (tsk);
task_cs()requiresrcu_read_lock(), but I can't see how the lock is obtained fromcpuset_attach()path, did I miss it? Running with lockdep should spill suspicious RCU usage warning.
Quoted 2 lines
Maybe it makes more sense to move the
rcu_read_lock()inside the function now withtask_cs()?
Well spotted! I'll add the rcu_read_[un]lock() calls to guarantee_online_cpus().
Will
Will Deacon
maintainerRe: [PATCH v6 11/21] sched: Split the guts of sched_setaffinity() into a helper function
In reply to Qais YousefQuoted 19 lines · Qais Yousef
Quoted 18 lines · Will Deacon
In preparation for replaying user affinity requests using a saved mask, split
sched_setaffinity()up so that the initial task lookup and security checks are only performed when the request is coming directly from userspace.Signed-off-by Will Deacon <[email protected]>--- kernel/sched/core.c | 110 +++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 52 deletions(-)kernel/sched/core.c +0
-0@@ -6788,9 +6788,61 @@ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,return retval; }
Quoted 14 lines
kernel/sched/core.c SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, · line 6801
Quoted 12 lines
kernel/sched/core.c +9
-1-long sched_setaffinity (pid_t pid,const struct cpumask *in_mask) +static int +__sched_setaffinity (struct task_struct *p,const struct cpumask *mask) { +int retval;cpumask_var_t cpus_allowed, new_mask; + +if (!alloc_cpumask_var (&cpus_allowed,GFP_KERNEL )) +return -ENOMEM ; + +if (!alloc_cpumask_var (&new_mask,GFP_KERNEL )) +return -ENOMEM ;Shouldn't we free
cpus_allowedfirst?
Oops, yes. Now fixed.
Thanks,
Will
Will Deacon
maintainerRe: [PATCH v6 12/21] sched: Allow task CPU affinity to be restricted on asymmetric systems
In reply to Qais YousefQuoted 43 lines · Qais Yousef
Quoted 20 lines · Will Deacon
kernel/sched/core.c +7
-3+static int __set_cpus_allowed_ptr_locked (struct task_struct *p, +const struct cpumask *new_mask, +u32 flags, +struct rq *rq, +struct rq_flags *rf) + __releases(rq->lock) + __releases(p->pi_lock) {const struct cpumask *cpu_valid_mask = cpu_active_mask;const struct cpumask *cpu_allowed_mask =task_cpu_possible_mask (p);unsigned int dest_cpu; -struct rq_flags rf; -struct rq *rq;int ret =0 ; - rq =task_rq_lock (p, &rf);update_rq_clock (rq);if (p->flags &PF_KTHREAD ||is_migration_disabled (p)) {kernel/sched/core.c static int __set_cpus_allowed_ptr(struct task_struct *p, · line 2429
Quoted 6 lines
kernel/sched/core.c +2
-1@@ -2430,20 +2425,158 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,__do_set_cpus_allowed (p, new_mask, flags); -return affine_move_task (rq, p, &rf, dest_cpu, flags); +if (flags &SCA_USER ) +release_user_cpus_ptr (p);Why do we need to release the pointer here?
Doesn't this mean if a 32bit task requests to change its affinity, then we'll lose this info and a subsequent
execve()to a 64bit application means we won't be able to restore the original mask?ie:
p0-64bit execve(32bit_app) // p1-32bit created p1-32bit.change_affinity() relase_user_cpus_ptr() execve(64bit_app) // lost info about p0 affinity?
Quoted 3 lines
Hmm I think this helped me to get the answer. p1 changed its affinity, then there's nothing to be inherited by a new
execve(), so yes we no longer need this info.
Yup, you got it.
Quoted 34 lines
Quoted 21 lines
kernel/sched/core.c +21
-0+static int restrict_cpus_allowed_ptr (struct task_struct *p, +struct cpumask *new_mask, +const struct cpumask *subset_mask) +{ +struct rq_flags rf; +struct rq *rq; +int err; +struct cpumask *user_mask =NULL ; + +if (!p->user_cpus_ptr) + user_mask =kmalloc (cpumask_size (),GFP_KERNEL ); + + rq =task_rq_lock (p, &rf); + +/* +* We're about to butcher the task affinity, so keep track of what +* the user asked for in case we're able to restore it later on. +*/ +if (user_mask) { +cpumask_copy (user_mask, p->cpus_ptr); + p->user_cpus_ptr = user_mask;kernel/sched/core.c static int __set_cpus_allowed_ptr(struct task_struct *p, · line 2501
Quoted 10 lines
kernel/sched/core.c +10
-0+ } + +/* +* Forcefully restricting the affinity of a deadline task is +* likely to cause problems, so fail and noisily override the +* mask entirely. +*/ +if (task_has_dl_policy (p) &&dl_bandwidth_enabled ()) { + err = -EPERM ; + goto err_unlock;
free(user_mark)first?
Quoted 7 lines
kernel/sched/core.c static int __set_cpus_allowed_ptr(struct task_struct *p, · line 2506
Quoted 5 lines
kernel/sched/core.c +5
-0+ } + +if (!cpumask_and (new_mask, &p->cpus_mask, subset_mask)) { + err = -EINVAL ; + goto err_unlock;ditto
We free the mask when the task exits so we don't actually need to clean up here. I left it like this on the assumption that failing here means that it's very likely that either the task will exit or retry very soon.
However I agree that it would be clearer to free the thing anyway, so I'll rejig the code to do that.
Will
Will Deacon
maintainerRe: [PATCH v6 21/21] Documentation: arm64: describe asymmetric 32-bit support
In reply to Qais YousefQuoted 26 lines · Qais Yousef
Quoted 11 lines · Will Deacon
Document support for running 32-bit tasks on asymmetric 32-bit systems and its impact on the user ABI when enabled.
Signed-off-by Will Deacon <[email protected]>--- .../admin-guide/kernel-parameters.txt | 3 + Documentation/arm64/asymmetric-32bit.rst | 149 ++++++++++++++++++ Documentation/arm64/index.rst | 1 + 3 files changed, 153 insertions(+) create mode 100644 Documentation/arm64/asymmetric-32bit.rst[...]
Quoted 11 lines
Documentation/arm64/asymmetric-32bit.rst new file +11
-0+Cpusets +------- + +The affinity of a 32-bit task may include CPUs that are not explicitly +allowed by the cpuset to which it is attached. This can occur as a +result of the following two situations: + + - A 64-bit task attached to a cpuset which allows only 64-bit CPUs + executes a 32-bit program. + + - All of the 32-bit-capable CPUs allowed by a cpuset containing a
Quoted 8 lines
Documentation/arm64/asymmetric-32bit.rst line 132
Quoted 5 lines
Documentation/arm64/asymmetric-32bit.rst new file +5
-0+ 32-bit task are offlined. + +In both of these cases, the new affinity is calculated according to step +(2) of the process described in `execve(2)`_ and the cpuset hierarchy is +unchanged irrespective of the cgroup version.nit: Should we call out that we're breaking cpuset-v1 behavior? Don't feel strongly about it.
I think the text is pretty clear that the new behaviour documented here applies to cpuset-v1 and I wouldn't say we're breaking anything as we're not changing any of the existing behaviours.
Will
Will Deacon
maintainerQuoted 52 lines · Qais Yousef
Hi Will
Quoted 40 lines · Will Deacon
Hi folks,
This is the long-awaited v6 of these patches which I last posted at the end of last year:
v1: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/r/[email protected]
v3: https://lore.kernel.org/r/[email protected]
v4: https://lore.kernel.org/r/[email protected]
v5: https://lore.kernel.org/r/[email protected]There was also a nice LWN writeup in case you've forgotten what this is about:
https://lwn.net/Articles/838339/It's taken me a while to get a v6 of this together, partly due to addressing the review feedback on v5, but also because this has now seen testing on real hardware which threw up some surprises in suspend/resume,
SCHED_DEADLINEand compat hwcap reporting. Thanks to Quentin for helping me to debug those issues.The aim of this series is to allow 32-bit ARM applications to run on arm64 SoCs where not all of the CPUs support the 32-bit instruction set. Unfortunately, such SoCs are real and will continue to be productised over the next few years at least. I can assure you that I'm not just doing this for fun.
Changes in v6 include:
* Save/restore the affinity mask across
execve()to 32-bit and back to64-bit again.* Allow 32-bit deadline tasks, but skip straight to fallback path when determining new affinity mask on
execve().* Fixed resume-from-suspend path when the resuming CPU is 64-bit-only by deferring wake-ups for 32-bit tasks until the secondary CPUs are back online.
Quoted 8 lines
* Bug fixes (compat hwcaps, memory leak, cpuset fallback path).
* Documentation for arm64. It's in the divisive .rst format, but please take a look anyway!
I'm pretty happy with this now and it seems to do the right thing, although the new patches in this revision would certainly benefit from review. Series based on v5.13-rc1.
Quoted 5 lines
It's late Fri and I'm off next week (I'm starting to sense an omen here, it's the 2nd or 3rd time the post syncs with my holiday), so a bit of a rushed review but the series looks good to me. Feel free to stick my Reviewed-by for the series, except patch 13 where I skipped it, given the few comments I had are addressed.
Thanks, Qais. I'm planning a v7 with quite a few changes, so it's probably best if you offer your Reviewed-by on individual patches when you're happy with them rather than me adding it to code that I'm still tweaking. But thanks for the offer!
Have a good week off,
Will
Re: [PATCH v6 18/21] arm64: Prevent offlining first CPU with 32-bit EL0 on mismatched system
In reply to Will DeaconQuoted 38 lines · Will Deacon
Quoted 29 lines · Catalin Marinas
Quoted 11 lines · Will Deacon
arch/arm64/kernel/cpufeature.c +2
-0@@ -2896,15 +2896,33 @@ void __init setup_cpu_features(void)static int enable_mismatched_32bit_el0 (unsigned int cpu) { +static int lucky_winner =-1 ; +struct cpuinfo_arm64 *info = &per_cpu (cpu_data, cpu);arch/arm64/kernel/cpufeature.c void __init setup_cpu_features(void) · line 2910
Quoted 10 lines
arch/arm64/kernel/cpufeature.c +2
-1bool cpu_32bit =id_aa64pfr0_32bit_el0 (info->reg_id_aa64pfr0);if (cpu_32bit) {cpumask_set_cpu (cpu, cpu_32bit_el0_mask);static_branch_enable_cpuslocked (&arm64_mismatched_32bit_el0); -setup_elf_hwcaps (compat_elf_hwcaps); } +if (cpumask_test_cpu (0 , cpu_32bit_el0_mask) == cpu_32bit) +return 0 ;I don't fully understand this early return. AFAICT, we still call
setup_elf_hwcaps()viasetup_cpu_features()if the system supports 32-bit EL0 (mismatched or not) at boot. For CPU hotplug, we can add the compat hwcaps later if we didn't set them up at boot. So this part is fine.Quoted 3 lines
However, if CPU0 is 32-bit-capable, it looks like we'd never disable the offlining on any of the 32-bit-capable CPUs and there's nothing that prevents offlining CPU0.
That is also deferred until we actually detect the mismatch. For example, if CPU0 is 32-bit capable but none of the others are, then when we online CPU1 we will print:
Quoted 5 lines
| CPU features: Asymmetric 32-bit EL0 support detected on CPU 1; CPU hot-unplug disabled on CPU 0
so the check above is really asking "Is the CPU being onlined mismatched wrt the boot CPU?". If yes, then we need to make sure that we're keeping a 32-bit-capable CPU around.
Got it now, the offlining will only be disabled if we detected a mismatch. For this patch: