mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-16 03:11:11 -04:00
arm64: Check DAIF (and PMR) at task-switch time
When __switch_to() switches from a 'prev' task to a 'next' task, various pieces of CPU state are expected to have specific values, such that these do not need to be saved/restored. If any of these hold an unexpected value when switching away from the prev task, they could lead to surprising behaviour in the context of the next task, and it would be difficult to determine where they were configured to their unexpected value. Add some checks for DAIF and PMR at task-switch time so that we can detect such issues. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Jinjie Ruan <ruanjinjie@huawei.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@kernel.org> Cc: Vladimir Murzin <vladimir.murzin@arm.com> Cc: Will Deacon <will@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
This commit is contained in:
committed by
Catalin Marinas
parent
ae654112ea
commit
8d13386c76
@@ -699,6 +699,29 @@ void update_sctlr_el1(u64 sctlr)
|
||||
isb();
|
||||
}
|
||||
|
||||
static inline void debug_switch_state(void)
|
||||
{
|
||||
if (system_uses_irq_prio_masking()) {
|
||||
unsigned long daif_expected = 0;
|
||||
unsigned long daif_actual = read_sysreg(daif);
|
||||
unsigned long pmr_expected = GIC_PRIO_IRQOFF;
|
||||
unsigned long pmr_actual = read_sysreg_s(SYS_ICC_PMR_EL1);
|
||||
|
||||
WARN_ONCE(daif_actual != daif_expected ||
|
||||
pmr_actual != pmr_expected,
|
||||
"Unexpected DAIF + PMR: 0x%lx + 0x%lx (expected 0x%lx + 0x%lx)\n",
|
||||
daif_actual, pmr_actual,
|
||||
daif_expected, pmr_expected);
|
||||
} else {
|
||||
unsigned long daif_expected = DAIF_PROCCTX_NOIRQ;
|
||||
unsigned long daif_actual = read_sysreg(daif);
|
||||
|
||||
WARN_ONCE(daif_actual != daif_expected,
|
||||
"Unexpected DAIF value: 0x%lx (expected 0x%lx)\n",
|
||||
daif_actual, daif_expected);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Thread switching.
|
||||
*/
|
||||
@@ -708,6 +731,8 @@ struct task_struct *__switch_to(struct task_struct *prev,
|
||||
{
|
||||
struct task_struct *last;
|
||||
|
||||
debug_switch_state();
|
||||
|
||||
fpsimd_thread_switch(next);
|
||||
tls_thread_switch(next);
|
||||
hw_breakpoint_thread_switch(next);
|
||||
|
||||
Reference in New Issue
Block a user