From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C90D3382E8 for ; Tue, 7 Apr 2026 13:19:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775567943; cv=none; b=m+M53+Unym5Zh0oyzepKpjS92skumxgpbER5eA8GDx09MTrStVGRqrnsm03/QPWU4SWyyLreKU0KqsAjLxPLysX59SBzqKgEnQZKlMYwz+zIGwnNORyKn/Bq0HGnM9QNOj1oz9Eg/HkqpvTqGHyD01bUamrmBhG7KVLoxesliSQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775567943; c=relaxed/simple; bh=IyTqocNhQbVO47j3rlqKeekBesuxoAkVgsNZyMigNLA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nXaDHMuIMcUNGIOCBXQ4uJJJ7ZvwyanCuOi0plrs0Q+C36z6IgPylFZanwzTbnMpjqAJbTEaAABTB92W54C+Uuf9mK6g1OJCEmA2RBaNfZducF2Q4bGTsXD6elctMh17BUbiX4FjDgQT57bjVFemXyM90m+ix4CwvHqtHW6rv10= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=pCEi4gQ3; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="pCEi4gQ3" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AD79D1BB2; Tue, 7 Apr 2026 06:18:54 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 88BBA3F7D8; Tue, 7 Apr 2026 06:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1775567940; bh=IyTqocNhQbVO47j3rlqKeekBesuxoAkVgsNZyMigNLA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pCEi4gQ3nYGEvolTIcNKqrTlxR2q65E9GRSNuHbNRH4Gqj6fzxfvq5RbbOrOolA2q Et9UYSGZ+rdg8FKv5nHIZQJOnl8w6513BlXuO6BQoIqrNJ+Rsqo9sswWFDc81f5uhk gu6PLCqgsB6sXUvYTAuzCLof2iEEBdKgTmcF/coU= From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon Cc: ada.coupriediaz@arm.com, linux-kernel@vger.kernel.org, luto@kernel.org, mark.rutland@arm.com, peterz@infradead.org, ruanjinjie@huawei.com, tglx@kernel.org, vladimir.murzin@arm.com Subject: [PATCH 10/10] arm64: Check DAIF (and PMR) at task-switch time Date: Tue, 7 Apr 2026 14:16:50 +0100 Message-Id: <20260407131650.3813777-11-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20260407131650.3813777-1-mark.rutland@arm.com> References: <20260407131650.3813777-1-mark.rutland@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Andy Lutomirski Cc: Catalin Marinas Cc: Jinjie Ruan Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Vladimir Murzin Cc: Will Deacon --- arch/arm64/kernel/process.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 489554931231e..ba9038434d2fb 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -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); -- 2.30.2