From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5C6F51E424 for ; Mon, 7 Sep 2026 16:43:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799385; cv=none; b=QJoWn8PLn9PqUfKPX6f2MDz/SEmaHGtCMb3X2006miNkm0Um1BlfeEqdvJ+DqA4ZTxHAgHp2SK3Hdignlk0K4BJEeLwELXArETLNO2iCIN5h6/VRDTJNevfirjE49Mz9VvmZPVgYKU6Er+a1NkMYUG+R7Gq3GV6qw+zA/zKFxA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799385; c=relaxed/simple; bh=I37tdwCbyxz8G3tmjQ1A2M5m8afkD9e7j3Bfplyak00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HEaheeFf8gzJGku6djOkzTFJDVIpZ5AhykvJdX56b+GCVX46lcf5t69Jfa/Ec4K0nTsfCBuqZ7aRIUp0fiOZNC0nurS+QGeu7WTaCEnWwwZtS5ywRJ7fpwTHOhjyqrQzTxnc5CFDLPgxGf+QyvamokSu+FpXRx+fqtgsKUQpCUY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lHO2uhEz; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lHO2uhEz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C99671F00A3D; Mon, 7 Sep 2026 16:43:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799383; bh=8NFOZ9UXWL03ntqDDevZKuvrtl/Qqe7ilVWxlEVBa2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lHO2uhEzqxy4qgVWSWiELGcjhlyFvnigsnAxNJdFGqeZNGSSnZVSKG29p3NzqlCgq waLjheb0rScLKCAA/bCGNXIe6rDjZlcpun8YWywmQvqY/p1tHFliAVWK/RoNjkKyUO o880ohsYd9e3xXMe/jwmu3x/jzOuSUUwwLVgRKrHBFTgljI313KIZ+tPDyL7dYIXTa VYs6iknT9XWfIdNRgbgvs/xdpfLTTyChjkSag4LwlrJh389qgxy7pOvzAz/YarEkmJ SaH4NzPkUdwH0eNn5JTOsBsxorXVNwwRatXHfF+DdYXg2H+/QYLmPr7gP/vE8l0dPd ombtgEd85X3rg== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 01/21] arm64: entry: Defer setting of TPIDRRO_EL0 until exit to userspace Date: Mon, 7 Sep 2026 17:42:26 +0100 Message-ID: <20260907164247.17223-2-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for using TPIDRRO_EL0 to point at 'current' while running inside the kernel, defer its userspace initialisation from the context-switch patch to exception return. This has the added benefit of not having to worry about keeping the in-memory value and the register value in-sync during preemptible sections. Cc: Mark Rutland Signed-off-by: Will Deacon Reviewed-by: Jinjie Ruan --- arch/arm64/kernel/asm-offsets.c | 1 + arch/arm64/kernel/entry.S | 4 +++- arch/arm64/kernel/process.c | 16 +--------------- arch/arm64/kernel/sys_compat.c | 7 ------- 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offset= s.c index 9c853ed3ceab..6038ab3beb25 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -42,6 +42,7 @@ int main(void) #endif BLANK(); DEFINE(THREAD_CPU_CONTEXT, offsetof(struct task_struct, thread.cpu_conte= xt)); + DEFINE(THREAD_TP_VALUE, offsetof(struct task_struct, thread.uw.tp_value)= ); DEFINE(THREAD_SCTLR_USER, offsetof(struct task_struct, thread.sctlr_user= )); #ifdef CONFIG_ARM64_PTR_AUTH DEFINE(THREAD_KEYS_USER, offsetof(struct task_struct, thread.keys_user)); diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index f63049ac32dc..59f045e496ec 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -47,7 +47,6 @@ b .Lskip_tramp_vectors_cleanup\@ .if \regsize =3D=3D 64 mrs x30, tpidrro_el0 - msr tpidrro_el0, xzr .else mov x30, xzr .endif @@ -360,9 +359,12 @@ alternative_else_nop_endif .if \el =3D=3D 0 ldr x23, [sp, #S_SP] // load return stack pointer msr sp_el0, x23 + msr tpidrro_el0, xzr tst x22, #PSR_MODE32_BIT // native task? b.eq 3f =20 + ldr x0, [tsk, #THREAD_TP_VALUE] + msr tpidrro_el0, x0 #ifdef CONFIG_ARM64_ERRATUM_845719 alternative_if ARM64_WORKAROUND_845719 #ifdef CONFIG_PID_IN_CONTEXTIDR diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 581f80e9b9b7..bfdc12166895 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -256,17 +256,8 @@ static void tls_thread_flush(void) if (system_supports_tpidr2()) write_sysreg_s(0, SYS_TPIDR2_EL0); =20 - if (is_compat_task()) { + if (is_compat_task()) current->thread.uw.tp_value =3D 0; - - /* - * We need to ensure ordering between the shadow state and the - * hardware state, so that we don't corrupt the hardware state - * with a stale shadow state during context switch. - */ - barrier(); - write_sysreg(0, tpidrro_el0); - } } =20 static void flush_tagged_addr_state(void) @@ -531,11 +522,6 @@ static void tls_thread_switch(struct task_struct *next) { tls_preserve_current_state(); =20 - if (is_compat_thread(task_thread_info(next))) - write_sysreg(next->thread.uw.tp_value, tpidrro_el0); - else - write_sysreg(0, tpidrro_el0); - write_sysreg(*task_user_tls(next), tpidr_el0); if (system_supports_tpidr2()) write_sysreg_s(next->thread.tpidr2_el0, SYS_TPIDR2_EL0); diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c index 0451f96c2c3f..59eee301c6f4 100644 --- a/arch/arm64/kernel/sys_compat.c +++ b/arch/arm64/kernel/sys_compat.c @@ -89,13 +89,6 @@ long compat_arm_syscall(struct pt_regs *regs, int scno) =20 case __ARM_NR_compat_set_tls: current->thread.uw.tp_value =3D regs->regs[0]; - - /* - * Protect against register corruption from context switch. - * See comment in tls_thread_flush. - */ - barrier(); - write_sysreg(regs->regs[0], tpidrro_el0); return 0; =20 default: --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C9F351FCA4 for ; Mon, 7 Sep 2026 16:43:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799388; cv=none; b=E2Rbjbc/yn/TNmJVV0WJSbufuzGfl3Vm96PZ8urfM7A1+No0FZXDHKLLDwJkkdXUxD7OE2dyUjufRU6ymF7nUbDpXXC3n4L9SDTjDcg6Nqv6lB4L2kzIts0ZesWOmxdvO3Irmyfejg37rWvUo3Xu720pHEcpNb45nDJb2SUTiHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799388; c=relaxed/simple; bh=T0AGVyN1eYv+zr11+s5U3YSKlu3+XotRoLe2H25gaVY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qVXqCa7coWC+Mr+Eol+eps6wmLRTW1D/P6qPt9XNHNhyU4uejgrkjGn0b5HMC3UWd/Adth82p0bhf+Wu2JsrQXHvb57AgL3x7qnLuTesS+5QC4FSwe/HA9m5/qL1VcWj8fxpgMvHABp9A7Xo9UmqbJw8WrexA+6Dxrm6bMZAk0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cr7pWeK6; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cr7pWeK6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AE131F00A3A; Mon, 7 Sep 2026 16:43:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799387; bh=lMcv+fJIFUpeFRCmf9ya4J/neAxp4gqF2gal+tnA2+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Cr7pWeK6EldNr1h/xUgngyA4ZLJ0dgvByNM6MeAoptHgqtSNTGn291nm6gxD7VRXg M+jZxwgy4hu2Cyk1NOmEKWjcKJHdSBJ2YlP+H1eBCz78ruzLy2/8XIbRc6kGTBRpqw LC2K8CyxlDoQYI/j+ULq7KdTDdKep4tSElijKtOQQzNAIqNpY1pg4A2qJ+n3uVW3yf n/yXMGHOAJkMycYxkwGOGoysHB1zhQUfpomZiVAY2DKQT10cMLFoECo8ZDp0Ozque9 9mBnlbtRwC27zWvUlGOwPi5Fp0YAP/rNYk5Kye8CFPEUqlrW4wLeZy85Tgp0HYHMN1 wnaRaZVmL657Q== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 02/21] arm64: entry: Only check for stack overflow on exceptions from EL1 Date: Mon, 7 Sep 2026 17:42:27 +0100 Message-ID: <20260907164247.17223-3-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Checking for kernel stack overflow on entry from EL0 is largely pointless and gets in the way of using SPSel to switch to the overflow stack. If the kernel stack overflows on entry from userspace, that implies that it was unbalanced on the last exception return which means we can't sensibly reason about the state of the system given that we could've returned to an arbitrary virtual address in an arbitrary mode. Remove the stack overflow check from the EL0 exception entry path. Cc: Mark Rutland Signed-off-by: Will Deacon --- arch/arm64/kernel/entry.S | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 59f045e496ec..b5d8277f608a 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -54,6 +54,8 @@ .endif =20 sub sp, sp, #PT_REGS_SIZE + + .if \el =3D=3D 1 /* * Test whether the SP has overflowed, without corrupting a GPR. * Task and IRQ stacks are aligned so that SP & (1 << THREAD_SHIFT) @@ -64,8 +66,11 @@ tbnz x0, #THREAD_SHIFT, 0f sub x0, sp, x0 // x0'' =3D sp' - x0' =3D (sp + x0) - sp =3D x0 sub sp, sp, x0 // sp'' =3D sp' - x0 =3D (sp + x0) - x0 =3D sp + .endif + b el\el\ht\()_\regsize\()_\label =20 + .if \el =3D=3D 1 0: /* * Either we've just detected an overflow, or we've taken an exception @@ -96,6 +101,7 @@ sub sp, sp, x0 mrs x0, tpidrro_el0 b el\el\ht\()_\regsize\()_\label + .endif .org .Lventry_start\@ + 128 // Did we overflow the ventry slot? .endm =20 --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98AF451FCB1 for ; Mon, 7 Sep 2026 16:43:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799391; cv=none; b=p/EtCRwyoOtjaWb1NuM/8lg+aT8OSH0XuBM0IUDaSIq8I0LK8iF6ymgi1xvYDLQF9sU6f+1YXwD4QkPg+PHiecExbY7+F+GFdqhZt8GRuKShBb1jLSdpGJFSSLXjLuQdJocDror4QLhPXYotBA/cgQ2jpTngQOwSktGQ7WwTmyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799391; c=relaxed/simple; bh=2xoBQrYiLQhwyzzjlC/Rrs4JE7nEyMXez28Fj2eF4ag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IiX8DpAjtVIvHltMT1V1NgAdqOTdm2bEmdgVs/183t4XkfheKnF14bzYzefSznFzBl4cbNwzs590+lmcUpS5TtbpcQpP+LNoQ89Ggzk38d/YYiMCWveqa9P2XU70zjkksLL45k1jHHx5/J68lgD3kRaPnJ69rQQBCsp8gnrOsgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n7Tw5X7w; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="n7Tw5X7w" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C05A1F00A3D; Mon, 7 Sep 2026 16:43:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799390; bh=Fp1WUkxnhvJ5IR2eKQ3SMHt49du3trxxPvYQkmiNNK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=n7Tw5X7wmPClS1PfidWlMSSGzwE56Vyb+K07OW9TKFGgJ/1QxvCFZoKgfDEo4IsKp uPIWzntXgAWLL4aYjmXCXMiCzDQ9zEN+mQWDVqzPIqoYMhnVduceRNdLEq5GbWglKm 3wYOGEQcyfNEC0iyBdCqh3WErPszKpUEgaW/42wJmPP7KbFvHFB/k8kuRoAaYQyExa BsJekbPdn/amcdakWif/SD0mswbdTyZxn7YKG1MzCx/dMhvX6zof29YelMhynlQ+Yf jADdEkNMyKYC+WvGrt/bNz9WDlU8EM78l7YYkczXS4yQqEbsizmeYBNCrP6+T1obHs Gqwi/u4rn4gtw== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 03/21] arm64: stackprotector: Temporarily disable per-task stackprotector Date: Mon, 7 Sep 2026 17:42:28 +0100 Message-ID: <20260907164247.17223-4-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Per-task stackprotector relies on telling the compiler about the system register used to hold a pointer to the current task. As we're about to change that around, temporarily disable per-task stackprotector for now. Cc: Mark Rutland Signed-off-by: Will Deacon --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index b5a51b0ef944..b8270b301809 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -2455,6 +2455,7 @@ config CC_HAVE_STACKPROTECTOR_SYSREG config STACKPROTECTOR_PER_TASK def_bool y depends on STACKPROTECTOR && CC_HAVE_STACKPROTECTOR_SYSREG + depends on BROKEN =20 config UNWIND_PATCH_PAC_INTO_SCS bool "Enable shadow call stack dynamically using code patching" --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09557521226 for ; Mon, 7 Sep 2026 16:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799395; cv=none; b=gwmWq0fhKcPSMUL0uGXVYPeS7MmgPbFj52ZM0sRaa5SLVX8pyinQSQQbuc4/2W1QGjVeun1j1qHl74TzlcrCu9Q8aV4DY5SkHTl3F/gLN0sOEDcs8uB5fEsVcunmrXGpYD6dPECOppeILvtzneEbCLbLx88thWKfMnD2xJa2dlE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799395; c=relaxed/simple; bh=uLgf45738HTyKOGxONf2L12nrejh1+P0hDijSifdIKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UkzWI81qMxob+wJEL/pyGbzwF4RMQutCgyh0HtWjOKdDH40Shg2+mZjX/s/BaPiQ1NPcsBgXjk0XJhnmQ2viCR8M5ZmmH4+Bw/cZ00eTGIKqIfKhgCK0ppYLyfc3oi+/2zHqnOaaKwPqhy6Lcyz5Yj8rwynBi2k4WAiyAQTS4WI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CocsL0/a; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CocsL0/a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1832E1F00A3F; Mon, 7 Sep 2026 16:43:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799393; bh=VHSmidgSt8AbjYT2raXqIZZYXGrQJOWrMI3DNUPT/To=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CocsL0/aIfzLSNLpwpHRNrvHm73Fw4AxTaKa1B5XmrTYXs2CzVdSXLcHcOp+COqUY 29ibwMG4DS8UME1PQwp8zvZv/2x+NtEiqr0oEn0CpLBYqjXjvlcDvQRGZUp+ofcGYf 3VjlMrzyLNTmvw5JYTd6XM1ylg5FA1vlDmYxlB9x9et/IjlI5thJhC/5INjTfElgmn c7++bVGH+cQfjkEmRAOPFFn478E4rlNbDyNRVFtVSAAtq5Cj9o+6ThvZu3SN5aAAkx BqwSOoqJOq2sNHFJ/kZn6TWGgFep2pJrbeUxslZxvN/quGadOAcC5RPW6VLZalg2A0 53aV0tlsCEEow== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 04/21] arm64: bpf: Add support for generating reads of TPIDRRO_EL0 Date: Mon, 7 Sep 2026 17:42:29 +0100 Message-ID: <20260907164247.17223-5-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for storing 'current' in TPIDRRO_EL0, add support for the instruction encoding of "MRS Rt, TPIDRRO_EL0" to the BPF JIT. Cc: Mark Rutland Signed-off-by: Will Deacon --- arch/arm64/include/asm/insn.h | 1 + arch/arm64/net/bpf_jit.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h index 1ce75a442638..0e739740513d 100644 --- a/arch/arm64/include/asm/insn.h +++ b/arch/arm64/include/asm/insn.h @@ -136,6 +136,7 @@ enum aarch64_insn_special_register { }; =20 enum aarch64_insn_system_register { + AARCH64_INSN_SYSREG_TPIDRRO_EL0 =3D 0x5e83, AARCH64_INSN_SYSREG_TPIDR_EL1 =3D 0x4684, AARCH64_INSN_SYSREG_TPIDR_EL2 =3D 0x6682, AARCH64_INSN_SYSREG_SP_EL0 =3D 0x4208, diff --git a/arch/arm64/net/bpf_jit.h b/arch/arm64/net/bpf_jit.h index b2fe6e6dcf44..df469a005373 100644 --- a/arch/arm64/net/bpf_jit.h +++ b/arch/arm64/net/bpf_jit.h @@ -331,6 +331,8 @@ aarch64_insn_gen_adr(0, offset, Rd, AARCH64_INSN_ADR_TYPE_ADR) =20 /* MRS */ +#define A64_MRS_TPIDRRO_EL0(Rt) \ + aarch64_insn_gen_mrs(Rt, AARCH64_INSN_SYSREG_TPIDRRO_EL0) #define A64_MRS_TPIDR_EL1(Rt) \ aarch64_insn_gen_mrs(Rt, AARCH64_INSN_SYSREG_TPIDR_EL1) #define A64_MRS_TPIDR_EL2(Rt) \ --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD9A252123E for ; Mon, 7 Sep 2026 16:43:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799399; cv=none; b=mo9rieIhnwb+jLhlH3KYSqHmvc60wLd+ztxTXPyWTKNkYeefN+H4Mza8mbUHzXfonssQ705eeynatW6PSR1pDLMS3XkrN7erslveRVlruNQwPPyBuIn2sHh9FemXZ19Wo24JgD/TyffrniWW0MPFrhe2YbnkQGytR52H0LxQXlY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799399; c=relaxed/simple; bh=J95QtgnQ7XhVBfSKHeXgYt7eUkZu1uzLFvdFr68Ew24=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j1lvoKERcRCQR+EgPqBKih1XIxtzqCtC+HL3fDMSPyRvFmfWSaDjiT1hAs9CnWD8wPMIfLLIy0NlVl3FJ+KRH2omgvWFj2HKKgpN685wtKL7TYrXl5/D5EvAiaoMmqUAgoLdshwt/Mk+UsY98JAef9qjZ3wWHeirLrLqOi89GLU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XWa2uf4n; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XWa2uf4n" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E29A1F00A3A; Mon, 7 Sep 2026 16:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799397; bh=wz0SGej6Xy19EgAxic7KIK5EZGnRx2zg64G04W8Nxb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XWa2uf4nbXCN69odGjDi+sjEEMAUrlwe/0Q74DE9U7EC1fb0MPj9i0UlLQ8HmKB75 cERxTXlV6Swa83k14doSpGGHFg1q96UTcqfuB1tpnCY7HCbsLGzp0V7ovzgTCBae81 wMcj48jBXLpNLgSgXEMs4lPRpK5UTalx2XPuK41iVnxFOucDGEkhRxxylqquMUliI+ 6r8dVpzd0FQppi5SaaVsz92p4JeAWWgQ+dN9V5qXWsG0kzhY5SMwgE1qE2kbMdkq6L cc8DdBmwjPmsXmej41lrQbvC6ct498xLOaE/IeOtZLsduG3em6tEAqatDJ1RwLip6V t9iZUSlgJbHmw== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 05/21] KVM: arm64: Protect TPIDRRO_EL0 across guest entry/exit Date: Mon, 7 Sep 2026 17:42:30 +0100 Message-ID: <20260907164247.17223-6-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mostafa Saleh To prepare for using TPIDRRO_EL0 to hold 'current' and repurposing SP_EL0 as an overflow stack pointer, eagerly switch both registers when entering and exiting the guest. Signed-off-by: Mostafa Saleh Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_asm.h | 10 ++++++++++ arch/arm64/kernel/asm-offsets.c | 1 + arch/arm64/kvm/hyp/entry.S | 12 ++++++++---- arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 2 -- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_= asm.h index e5b92ac09e69..1cfe9216a2ff 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -408,6 +408,16 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr,= u64 spsr, u64 elr_virt, msr sp_el0, \tmp .endm =20 +.macro save_tpidrro_el0 ctxt, tmp + mrs \tmp, tpidrro_el0 + str \tmp, [\ctxt, #CPU_TPIDRRO_EL0_OFFSET] +.endm + +.macro restore_tpidrro_el0 ctxt, tmp + ldr \tmp, [\ctxt, #CPU_TPIDRRO_EL0_OFFSET] + msr tpidrro_el0, \tmp +.endm + #endif =20 #endif /* __ARM_KVM_ASM_H__ */ diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offset= s.c index 6038ab3beb25..cb8448cc5f51 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -108,6 +108,7 @@ int main(void) DEFINE(VCPU_HCR_EL2, offsetof(struct kvm_vcpu, arch.hcr_el2)); DEFINE(CPU_USER_PT_REGS, offsetof(struct kvm_cpu_context, regs)); DEFINE(CPU_ELR_EL2, offsetof(struct kvm_cpu_context, sys_regs[ELR_EL2])= ); + DEFINE(CPU_TPIDRRO_EL0_OFFSET, offsetof(struct kvm_cpu_context, sys_regs= [TPIDRRO_EL0])); DEFINE(CPU_RGSR_EL1, offsetof(struct kvm_cpu_context, sys_regs[RGSR_EL1= ])); DEFINE(CPU_GCR_EL1, offsetof(struct kvm_cpu_context, sys_regs[GCR_EL1])= ); DEFINE(CPU_APIAKEYLO_EL1, offsetof(struct kvm_cpu_context, sys_regs[APIA= KEYLO_EL1])); diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S index 308100ed25de..4c89931a6a92 100644 --- a/arch/arm64/kvm/hyp/entry.S +++ b/arch/arm64/kvm/hyp/entry.S @@ -30,8 +30,9 @@ SYM_FUNC_START(__guest_enter) // Store the hyp regs save_callee_saved_regs x1 =20 - // Save hyp's sp_el0 + // Save hyp's sp_el0 and tpidrro_el0 save_sp_el0 x1, x2 + save_tpidrro_el0 x1, x2 =20 // Now the hyp state is stored if we have a pending RAS SError it must // affect the host or hyp. If any asynchronous exception is pending we @@ -66,8 +67,9 @@ alternative_else_nop_endif // when this feature is enabled for kernel code. ptrauth_switch_to_guest x29, x0, x1, x2 =20 - // Restore the guest's sp_el0 + // Restore the guest's sp_el0 and tpidrro_el0 restore_sp_el0 x29, x0 + restore_tpidrro_el0 x29, x0 =20 // Restore guest regs x0-x17 ldp x0, x1, [x29, #CPU_XREG_OFFSET(0)] @@ -146,8 +148,9 @@ SYM_INNER_LABEL(__guest_exit, SYM_L_GLOBAL) // Store the guest regs x18-x29, lr save_callee_saved_regs x1 =20 - // Store the guest's sp_el0 + // Store the guest's sp_el0 and tpidrro_el0 save_sp_el0 x1, x2 + save_tpidrro_el0 x1, x2 =20 adr_this_cpu x2, kvm_hyp_ctxt, x3 =20 @@ -161,8 +164,9 @@ SYM_INNER_LABEL(__guest_exit, SYM_L_GLOBAL) // mte_switch_to_hyp(g_ctxt, h_ctxt, reg1) mte_switch_to_hyp x1, x2, x3 =20 - // Restore hyp's sp_el0 + // Restore hyp's sp_el0 and tpidrro_el0 restore_sp_el0 x2, x3 + restore_tpidrro_el0 x2, x3 =20 // Now restore the hyp regs restore_callee_saved_regs x2 diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hy= p/include/hyp/sysreg-sr.h index c382848d3194..b5f7ef8e6371 100644 --- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h @@ -66,7 +66,6 @@ static inline void __sysreg_save_common_state(struct kvm_= cpu_context *ctxt) static inline void __sysreg_save_user_state(struct kvm_cpu_context *ctxt) { ctxt_sys_reg(ctxt, TPIDR_EL0) =3D read_sysreg(tpidr_el0); - ctxt_sys_reg(ctxt, TPIDRRO_EL0) =3D read_sysreg(tpidrro_el0); } =20 static inline bool ctxt_has_mte(struct kvm_cpu_context *ctxt) @@ -209,7 +208,6 @@ static inline void __sysreg_restore_common_state(struct= kvm_cpu_context *ctxt) static inline void __sysreg_restore_user_state(struct kvm_cpu_context *ctx= t) { write_sysreg(ctxt_sys_reg(ctxt, TPIDR_EL0), tpidr_el0); - write_sysreg(ctxt_sys_reg(ctxt, TPIDRRO_EL0), tpidrro_el0); } =20 static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt, --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13B3B51D52E for ; Mon, 7 Sep 2026 16:43:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799402; cv=none; b=W2ilawIvVTZWS/HYZk0jjHT/2C2Jspsb8W2hjdRGdp0Fe21moBDubmrafRIDd3xeniQRCtPQZDSdSUKhWQTOLzfVPjco3hQ15QqhZegSbaRap1XVj8JYayYPbGt3d4owIaV7ryG96CGyhyzyvw4/J1Dl1gOSgU4fCqSqjdIOllI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799402; c=relaxed/simple; bh=gNq7ukmIJoPQSwBs3CsGHXVFqnWNHjdd6O7GHvTPPSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=omleJAGrcB5zuar0jKT+PVcY8KZnvcmmAWDM35ZAmGb0vspWrNij5wg2m7jB09gqlRErNhiVKLCROLrnmRNh9L2YkZdMdjVJtIKcocOGsTr6ZN6H+5IAh+tgblSwMV9NS1MgHh7MQSWAdLO99Yb8mIQKQIehUHvGOemsbD3IK4k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fmwb7lee; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fmwb7lee" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA2C11F00A3D; Mon, 7 Sep 2026 16:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799400; bh=1kY9llO1ddjYj+PbsySZjCHX+aU5qaY+2/JhMLmZtdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fmwb7lee5WbO4U7cz3lQLeX4aTrw177xHsxzKx9CiQ9CaU9yOTUKl80xS8XEyqnJE YS/LQdzwaA803OR+oXGwEhq1IWATzGJoW4kBa/PBE4z+3jtDO13pZNNjTV9egg2bPJ 17XsMpPwvuYkDrLHx3Y3eqg7a3NVHl3xN7CFQ1wIFm1M9awklUNO0yfReaHbAD7uTB O4Jc/1jucGjKgFpm2afN3+IpKDyqYCTy0CZienk/WJalK9COEXAc5ILYjZeSHSs3Kz c1HxAAtzPxpvDotNSzHdG6BGSgXgM1c7oJ2Edw1YbEXVuxPWRhe33qIA2PAYSCQzQw ZQglS+Avxbg0Q== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 06/21] arm64: Store 'current' in TPIDRRO_EL0 instead of SP_EL0 Date: Mon, 7 Sep 2026 17:42:31 +0100 Message-ID: <20260907164247.17223-7-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To make SP_EL0 available to point at the per-cpu kernel overflow stack, we must relocate 'current' elsewhere. With TPIDRRO_EL0 now restored late in the return-to-user path, we can otherwise use it to hold 'current' and update the various accessors accordingly. Move 'current' from SP_EL0 to TPIDRRO_EL0. Cc: Mark Rutland Signed-off-by: Will Deacon --- arch/arm64/include/asm/assembler.h | 2 +- arch/arm64/include/asm/current.h | 6 +++--- arch/arm64/kernel/entry.S | 20 ++++++++++---------- arch/arm64/kernel/head.S | 2 +- arch/arm64/kernel/process.c | 5 +++-- arch/arm64/net/bpf_jit_comp.c | 4 ++-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/as= sembler.h index 0b58b550e8dc..fd1ae5337935 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -587,7 +587,7 @@ alternative_else_nop_endif * Return the current task_struct. */ .macro get_current_task, rd - mrs \rd, sp_el0 + mrs \rd, tpidrro_el0 .endm =20 /* diff --git a/arch/arm64/include/asm/current.h b/arch/arm64/include/asm/curr= ent.h index c92912eaf186..8c7efac05394 100644 --- a/arch/arm64/include/asm/current.h +++ b/arch/arm64/include/asm/current.h @@ -14,11 +14,11 @@ struct task_struct; */ static __always_inline struct task_struct *get_current(void) { - unsigned long sp_el0; + unsigned long tpidrro_el0; =20 - asm ("mrs %0, sp_el0" : "=3Dr" (sp_el0)); + asm ("mrs %0, tpidrro_el0" : "=3Dr" (tpidrro_el0)); =20 - return (struct task_struct *)sp_el0; + return (struct task_struct *)tpidrro_el0; } =20 #define current get_current() diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index b5d8277f608a..a45be0a837c8 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -81,9 +81,9 @@ /* Stash the original SP (minus PT_REGS_SIZE) in tpidr_el0. */ msr tpidr_el0, x0 =20 - /* Recover the original x0 value and stash it in tpidrro_el0 */ + /* Recover the original x0 value and stash it in sp_el0 */ sub x0, sp, x0 - msr tpidrro_el0, x0 + msr sp_el0, x0 =20 /* Switch to the overflow stack */ adr_this_cpu sp, overflow_stack + OVERFLOW_STACK_SIZE, x0 @@ -99,7 +99,7 @@ =20 /* We were already on the overflow stack. Restore sp/x0 and carry on. */ sub sp, sp, x0 - mrs x0, tpidrro_el0 + mrs x0, sp_el0 b el\el\ht\()_\regsize\()_\label .endif .org .Lventry_start\@ + 128 // Did we overflow the ventry slot? @@ -226,7 +226,7 @@ alternative_cb_end clear_gp_regs mrs x21, sp_el0 ldr_this_cpu tsk, __entry_task, x20 - msr sp_el0, tsk + msr tpidrro_el0, tsk =20 /* * Ensure MDSCR_EL1.SS is clear, since we can unmask debug exceptions @@ -548,7 +548,7 @@ SYM_CODE_START_LOCAL(__bad_stack) */ =20 /* Restore the original x0 value */ - mrs x0, tpidrro_el0 + mrs x0, sp_el0 =20 /* * Store the original GPRs to the new stack. The orginal SP (minus @@ -843,7 +843,7 @@ SYM_FUNC_START(cpu_switch_to) ldp x29, x9, [x8], #16 ldr lr, [x8] mov sp, x9 - msr sp_el0, x1 + msr tpidrro_el0, x1 ptrauth_keys_install_kernel x1, x8, x9, x10 scs_save x0 scs_load_current @@ -1031,11 +1031,11 @@ SYM_CODE_START(__sdei_asm_handler) =20 /* * We may have interrupted userspace, or a guest, or exit-from or - * return-to either of these. We can't trust sp_el0, restore it. + * return-to either of these. We can't trust tpidrro_el0, restore it. */ - mrs x28, sp_el0 + mrs x28, tpidrro_el0 ldr_this_cpu dst=3Dx0, sym=3D__entry_task, tmp=3Dx1 - msr sp_el0, x0 + msr tpidrro_el0, x0 =20 /* If we interrupted the kernel point to the previous stack/frame. */ and x0, x3, #0xc @@ -1051,7 +1051,7 @@ SYM_CODE_START(__sdei_asm_handler) mov x1, x19 bl __sdei_handler =20 - msr sp_el0, x28 + msr tpidrro_el0, x28 /* restore regs >x17 that we clobbered */ mov x4, x19 // keep x4 for __sdei_asm_exit_trampoline ldp x28, x29, [x4, #SDEI_EVENT_INTREGS + 16 * 14] diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 87a822e5c4ca..c33551ee6572 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -193,7 +193,7 @@ SYM_CODE_END(preserve_boot_args) * for consistency with user tasks and kthreads. */ .macro init_cpu_task tsk, tmp1, tmp2 - msr sp_el0, \tsk + msr tpidrro_el0, \tsk =20 ldr \tmp1, [\tsk, #TSK_STACK] add sp, \tmp1, #THREAD_SIZE diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index bfdc12166895..79a19be88ced 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -551,8 +551,9 @@ static void ssbs_thread_switch(struct task_struct *next) } =20 /* - * We store our current task in sp_el0, which is clobbered by userspace. K= eep a - * shadow copy so that we can restore this upon entry from userspace. + * We store our current task in tpidrro_el0, which is clobbered when retur= ning + * to userspace. Keep a shadow copy so that we can restore this upon entry= from + * userspace. * * This is *only* for exception entry from EL0, and is not valid until we * __switch_to() a user task. diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index c18e005a41db..51d853b92443 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -1694,7 +1694,7 @@ static int build_insn(const struct bpf_verifier_env *= env, const struct bpf_insn if (insn->src_reg =3D=3D 0 && insn->imm =3D=3D BPF_FUNC_get_smp_processo= r_id) { cpu_offset =3D offsetof(struct thread_info, cpu); =20 - emit(A64_MRS_SP_EL0(tmp), ctx); + emit(A64_MRS_TPIDRRO_EL0(tmp), ctx); if (is_lsi_offset(cpu_offset, 2)) { emit(A64_LDR32I(r0, tmp, cpu_offset), ctx); } else { @@ -1707,7 +1707,7 @@ static int build_insn(const struct bpf_verifier_env *= env, const struct bpf_insn /* Implement helper call to bpf_get_current_task/_btf() inline */ if (insn->src_reg =3D=3D 0 && (insn->imm =3D=3D BPF_FUNC_get_current_tas= k || insn->imm =3D=3D BPF_FUNC_get_current_task_btf)) { - emit(A64_MRS_SP_EL0(r0), ctx); + emit(A64_MRS_TPIDRRO_EL0(r0), ctx); break; } =20 --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7488E5221E4 for ; Mon, 7 Sep 2026 16:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799405; cv=none; b=WzA5eRthiz4op9L8SQmBGoLZDfUmNm/D5Go/ytoFYkwjkVD1iiSKXiuRvIr5CUe1suMW1Mf3wkb6lrPk6NZ1oD4S2slWUXrZCqncMcrM34UBvpVYuG72RAE45ln8n/Dml79lTtYd12W2hTE5wAdK5Y2LZlf0iJb5+inek2QKccQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799405; c=relaxed/simple; bh=HLCshW8xxv6VsiacUYB6HYqss6+4m80cl5CLJJhEEoM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VkU4vMTgwkWrqX1DwwPf3xlRPDZdi/MFiDil39UsocFnZA+8noxDMzdrELodZTaBy0A3Jdx+KFyuYczqOHb5sdwSxQsp0IfvAdgegawIWZ4US81+RBS/+oV7ZJ6DWhV0vN6awQfzyE2BtgA2OJV7tNTQBQ09Kwcwmr47rLzFyDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CQjhS6Sh; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CQjhS6Sh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E4AB1F00A3A; Mon, 7 Sep 2026 16:43:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799404; bh=4ETxX+Ovhc6XcQfH1JJJPmgYMOVMu2SBJPq49n1St2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CQjhS6Sh5LSuVnGsWrDayRTZgrnPSjn/2w2PspnGGYU3yy8jYWr/hPpLTJIWqbeeY hfUqIVnGK2+URINnFL9/KY7CqBv/xbZJ9UEHqoowMEuiIDJSaJCpItwGvC6AefkS1Q sDxWiP8Y6kuHvD9HF+wCF9XNDjUXG+9B0gL4uQZothEMg/0npy6quZk7wEFsXZJKuR LfCCKrYX2cKijc3EhIih9HZ9nD3BaKmdYlhkoTkgc5M7IT9ZKMaTrY/TXEuxkIaZEK KA6SNzMyZeJIyqmAUWaJbpk5rDVwBsATbTc/CkqoXPeK7Em3cLjXr86OoBlSC6YWWS mvZlROZs55LqA== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 07/21] selftests/bpf: arm64: Use TPIDRRO_EL0 instead of SP_EL0 for 'current' Date: Mon, 7 Sep 2026 17:42:32 +0100 Message-ID: <20260907164247.17223-8-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The current task pointer now lives in TPIDRRO_EL0 instead of SP_EL0, so update the bpf selftests with the new register allocation. Cc: Mark Rutland Signed-off-by: Will Deacon --- tools/testing/selftests/bpf/progs/verifier_jit_inline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c b/tool= s/testing/selftests/bpf/progs/verifier_jit_inline.c index 02e562f56f9d..a3d6c095acc3 100644 --- a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c +++ b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c @@ -9,7 +9,7 @@ __success __retval(0) __arch_x86_64 __jited(" addq %gs:{{.*}}, %rax") __arch_arm64 -__jited(" mrs x8, SP_EL0") +__jited(" mrs x8, TPIDRRO_EL0") __arch_riscv64 __jited(" mv a5, tp") __arch_loongarch --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 931825221E8 for ; Mon, 7 Sep 2026 16:43:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799408; cv=none; b=dOX2VNSO/tdxEhwPPnDXfoufJGCiBnTdzP/BO9GYp9dcAeyGyZUzFIiY5JdOC+aCBdYdO0YgBc2uOXnesFKCoDVXERkXBI9jUygEo7eFdwNp9SAq+jbgCCAkE+LmbKJBXleFY8gPRcH2cX03WaoSBj5UJ2tXON8EtdhFbUOx7iQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799408; c=relaxed/simple; bh=CSw3oherBfoV6W/nK/rpDbfPplnba3UrQpfy3y7fThA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m82ZMLW7il9tUgW6ImIlVGROgo06FiEI2SbG1Vfdci7qknTVDHKA8eYDVpKX17xU1tG7yVfMY7hRtFy4fVggZl175YQ5s7wrupdn2YtfuHMoWlRocxfSMhRc5sXv1jdfUO5Fm7/IrG29pc8cJZBXPSsYE0loLQEBHQzIwRHYFjI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RO8n0Y94; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RO8n0Y94" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1AAA1F00A3D; Mon, 7 Sep 2026 16:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799407; bh=vkIZsSq4vjx3hJ16+mmGyusQF/k3JkgwGVYvd4qklvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RO8n0Y94Ybb/79WvENaLl9DQghw0X1NiY4ybTH8xat+u53ITYCRK0dbpkSmamMk8q RPGb9I1jub/Dv3IBGoZyCBVG+rh8cy5d0Wt27h25JsVN/Q5bM6InhzUFGB22Xfb+bL 9GfCG6YEXce16WUVp2ExiRt7S5mSbi6aswPjCBYHkfesRCDRvj75T9DYJrgQAIfvch OaYeUfZvcjP1twNG/jTB+p/SPVtKrnUAEbKIQg1zGr9HjWfjh+QAlSq/yBuhZ5QBzL HaGWk2IZl0DWAnH12JypO6GmsuzJaaNZzdmLdTHV/bosVKV9pEak2tqg1LOqm/dsVW MquJ6tAVTqg1A== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 08/21] scripts/gdb: arm64: Use TPIDRRO_EL0 instead of SP_EL0 for 'current' Date: Mon, 7 Sep 2026 17:42:33 +0100 Message-ID: <20260907164247.17223-9-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The current task pointer now lives in TPIDRRO_EL0 instead of SP_EL0, so update the gdb 'cpus.py' helper script with the new register allocation. Cc: Mark Rutland Signed-off-by: Will Deacon --- scripts/gdb/linux/cpus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py index 6edf4ef61636..547a623280ae 100644 --- a/scripts/gdb/linux/cpus.py +++ b/scripts/gdb/linux/cpus.py @@ -185,7 +185,7 @@ def get_current_task(cpu): var_ptr =3D gdb.parse_and_eval("¤t_task") return per_cpu(var_ptr, cpu).dereference() elif utils.is_target_arch("aarch64"): - current_task_addr =3D gdb.parse_and_eval("(unsigned long)$SP_EL0") + current_task_addr =3D gdb.parse_and_eval("(unsigned long)$TPIDRRO_= EL0") if (current_task_addr >> 63) !=3D 0: current_task =3D current_task_addr.cast(task_ptr_type) return current_task.dereference() --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B8945221E8 for ; Mon, 7 Sep 2026 16:43:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799412; cv=none; b=rJ/XGb4trjrzzlj9iQHZHmOVRs7T/VoNNEowVgbR7caL10UI+CBFyFgmYzazT4k6S2w4JxgvMjnsXXGtYysyD1T1rBcXhTAmFj/WToz50lUj0zqzmuDsfXaUmwHFw+rY1S0ucYxFsDSKKFsSDA0Jg0sVUppFF3XYY3UDC51I7gg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799412; c=relaxed/simple; bh=6RQZewVhm6Oiv8hNrNgoANtVVMSOgPWcOO8HlIfY+RM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K3yZ7rjK1eJG6EFGpLTaw+5bK282D9pEIKTBPNexc2k27ds1WPFUBYMWvckQCveEzrL2DjWy995q9RvojY98uY9GbvozYHOasfKwLlnoOLQEbGHiKbEcmFf6E8ffk3Hj+I/l0yovE9mY6Up1RiSyaQCrLdsESCdREy8cRZydnjw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NTWw5g9E; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NTWw5g9E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12ECB1F00A3A; Mon, 7 Sep 2026 16:43:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799410; bh=33ikSkJFX7Vey/KunqKuY1Z4p4KTCUzmgh5gA1LOfSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NTWw5g9EYJc4qx5bnJPDjgft6wRNu+H5aoJU2ti+7HObaCaoC+7/h4BrXra3BA0tL IGPDCHxwjGtg6yc1AnPO5SxXZCewBIU7aPPnHJ6WoRp49HQyOO7QBUui3geNafL4ht 5Qqcma/fvoVwt3ipbTrTz7QpMmQZey0QO0dPRDxigxBw8mVBwz1y0Uzt8OGaOECGXY nsdJtu7rPtzl2udDSFux6/TdsN7FgFwlIcXl191lBPX7J8I2JgqrwfKwmxAN14BKxn uvrP7n9a9k/Uz1/ATlMWSHXCjHSmIZ/LcyAOmUFpD8dt8Ln5U/EOMErPWOHaNO12Ir L7VoAuUET005w== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 09/21] arm64: stackprotector: Re-enable per-task stackprotector Date: Mon, 7 Sep 2026 17:42:34 +0100 Message-ID: <20260907164247.17223-10-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that 'current' resides in TPIDRRO_EL0, update the per-task stackprotector compiler invocation to use the new register. Note that this requires a very recent build of clang [1], as (unlike GCC), it historically rejected all registers other than SP_EL0. Cc: Mark Rutland Link: https://github.com/llvm/llvm-project/pull/188054 [1] Signed-off-by: Will Deacon --- arch/arm64/Kconfig | 3 +-- arch/arm64/Makefile | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index b8270b301809..020fcaf36b1b 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -2450,12 +2450,11 @@ config RANDOMIZE_MODULE_REGION_FULL exhaustion, modules might be able to fall back to a larger 2GB area. =20 config CC_HAVE_STACKPROTECTOR_SYSREG - def_bool $(cc-option,-mstack-protector-guard=3Dsysreg -mstack-protector-g= uard-reg=3Dsp_el0 -mstack-protector-guard-offset=3D0) + def_bool $(cc-option,-mstack-protector-guard=3Dsysreg -mstack-protector-g= uard-reg=3Dtpidrro_el0 -mstack-protector-guard-offset=3D0) =20 config STACKPROTECTOR_PER_TASK def_bool y depends on STACKPROTECTOR && CC_HAVE_STACKPROTECTOR_SYSREG - depends on BROKEN =20 config UNWIND_PATCH_PAC_INTO_SCS bool "Enable shadow call stack dynamically using code patching" diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 6b005c8fef70..a293ab67818f 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -72,7 +72,7 @@ ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y) prepare: stack_protector_prepare stack_protector_prepare: prepare0 $(eval KBUILD_CFLAGS +=3D -mstack-protector-guard=3Dsysreg \ - -mstack-protector-guard-reg=3Dsp_el0 \ + -mstack-protector-guard-reg=3Dtpidrro_el0 \ -mstack-protector-guard-offset=3D$(shell \ awk '{if ($$2 =3D=3D "TSK_STACK_CANARY") print $$3;}' \ $(objtree)/include/generated/asm-offsets.h)) --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A535852379A for ; Mon, 7 Sep 2026 16:43:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799415; cv=none; b=QCbOMUCmw2xJR9t7lT4ZSEF1aGujRZjDOiWVLr/A5bVLYoZhYR/HjoI9QNtZOp7sxGYcoADYv1RdsYt5fTRYIGjrs3AChB31PwDkdsSE+MxuCzUnZrvBtc5XYYdIQ9SnmstOTqlIAbcXg8Vuv1MNwsHmfoEKK/rXhcFW/RW3jVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799415; c=relaxed/simple; bh=2N8nd0cXwCV/jR6atgLgpj5ztGUmsdU3ASEQ9NE3Cz4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UmDe3uTZwCKBG0gBZmfcQmuT/j2W9oyQBERg65I02xWz6WRVqOdh3NxdC0Mfcv5mn4RJszy25t7iG+uUZaV/sthbRRSt/ecaLYOGkmSGE9jZuvF1rJo2wxhMUcAWa99ffgQRyXO98Ywiitgx0Eyb2Ry9qZmxUPVVJhfSWjJKAwg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MJsakp3J; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MJsakp3J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71F611F00A3D; Mon, 7 Sep 2026 16:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799414; bh=78u6/cdiAajizC2UEtK9pSOndLspTzAq4idBXXZU6iQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MJsakp3JTE0E9NczC3mLozwnQ0uVL1bPPUP2vjMxZibarZfLiFuYhqPs4NrVg/cEr ZMXR4MSgUSHA3OGEQVuspvdCkYPzfUCxSRhAUW09zshoGf1Qw//jWoUJKPJxydtYcM UizMQsblDGEYIqHVpR6XBIejHMZ6fb/AN57TrVYK7sja5F7Ev15q/mE+mGhfFasjN4 YcC4S/IYNc13MhGGgOFLphaqqqdDZEv5VvM6KSTHRu8VuryTSgh7z5M5wQNOgT1PqR XaJQcjgDVS/jJSeZTRCzOjHxOMYrrlXehtwRFkPTbi+QRiCmnd0llS4N4ASqlb9i/t XbyydTKPPaV5w== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 10/21] arm64: percpu: Specialise set_my_cpu_offset() for the primary CPU Date: Mon, 7 Sep 2026 17:42:35 +0100 Message-ID: <20260907164247.17223-11-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" set_my_cpu_offset() is only called from smp_prepare_boot_cpu() which runs once on the primary CPU and before alternatives have been applied. Rework the function so that it operates only on the boot CPU offset, drop the unused alternative code sequence and internalise it into smp.c alongside its only caller. Signed-off-by: Will Deacon --- arch/arm64/include/asm/percpu.h | 8 -------- arch/arm64/kernel/smp.c | 8 +++++++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/arm64/include/asm/percpu.h b/arch/arm64/include/asm/percp= u.h index b57b2bb00967..3dc7291b16e9 100644 --- a/arch/arm64/include/asm/percpu.h +++ b/arch/arm64/include/asm/percpu.h @@ -12,14 +12,6 @@ #include #include =20 -static inline void set_my_cpu_offset(unsigned long off) -{ - asm volatile(ALTERNATIVE("msr tpidr_el1, %0", - "msr tpidr_el2, %0", - ARM64_HAS_VIRT_HOST_EXTN) - :: "r" (off) : "memory"); -} - static inline unsigned long __hyp_my_cpu_offset(void) { /* diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index a61dc3016a11..702dee8d0db5 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -446,6 +446,12 @@ void __init smp_cpus_done(unsigned int max_cpus) mark_linear_text_alias_ro(); } =20 +static void __init set_boot_cpu_offset(void) +{ + asm volatile("msr tpidr_el1, %0" + :: "r" (per_cpu_offset(0)) : "memory"); +} + void __init smp_prepare_boot_cpu(void) { /* @@ -453,7 +459,7 @@ void __init smp_prepare_boot_cpu(void) * setup_per_cpu_areas(), and CPU0's boot time per-cpu area will be * freed shortly, so we must move over to the runtime per-cpu area. */ - set_my_cpu_offset(per_cpu_offset(smp_processor_id())); + set_boot_cpu_offset(); =20 cpuinfo_store_boot_cpu(); setup_boot_cpu_features(); --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23D8A5237A7 for ; Mon, 7 Sep 2026 16:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799419; cv=none; b=YMD9aZRWJdQH4GhDhdoLSoirw+OK84to0Q1s/AKsY1XSfsNh6CSWLCl3hSJ/HX5bVzyCluyiW0i3P1cD9H1+SiC46eJ/gxS9q7Cirhzc4CQF6MfGG3UKThgZlUDVKrnYd5cCei8Y11e9QcXYYQLZPFw+Ydmh2TrPa43ZhUP1pn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799419; c=relaxed/simple; bh=gTlx6is6XrvyjPhpwA9V1ozLMB+EJsZwN2tebLKC/H8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iD+kbFny1g4+umQOeE4oEoF3ix2XpigLxhwGRuqc3rO3FlyF9PRv+C19Udb53Gu6ddwjawnyzGOjOL4Yw3SPIrtkJ9hHlG5rw+Tjvmhd9BfYBEaPttP8NKfHXhRPLTNEigJo34PoUW1idr9Aa1BH57wR+ruihemjUGQ2camuvXw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dpz8P5fl; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Dpz8P5fl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D06851F00A3E; Mon, 7 Sep 2026 16:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799417; bh=n+K80nAxXhSm5NIt4T8l1ArolcUXrF2HTgu45U32pCw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Dpz8P5flXB+f/mwxgnYVOmBx3XGJ4U0LMXVV6eh377oHMDt3NQEZHqh3xMpVKJFqU 7ke0Vf52rXfj34OteLR6GA/ECF+K9jB5o1NzSwM3lCRsb05RwZkXbeDN0RfRSzdqZp D/vznvXSkPJe3edlXmBm2omlgTele7/zVMKnMo0lZCGFdThsZQe9SgcaaOUXS5bqT3 L+Qn0iHFlfUdLLpTHvPbav4gutLllDuIhlaoB9ROZy+GamkVzSOgh9lvEtamSIuXv2 sjN67/YA33G/e0TT1SwarAWb9U8WNAQ/8njsj7pPj1cB1gdIgeyfkq4OOVUQE9WjSR TgdujM6Q7XTew== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 11/21] arm64: percpu: Annotate __kern_my_cpu_offset() as '__always_inline' Date: Mon, 7 Sep 2026 17:42:36 +0100 Message-ID: <20260907164247.17223-12-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow the use of per-cpu variables from noinstr functions by marking __kern_my_cpu_offset() as '__always_inline'. This will later be relied upon to detect stack overflow of the overflow stack from noinstr C code. Signed-off-by: Will Deacon --- arch/arm64/include/asm/percpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/percpu.h b/arch/arm64/include/asm/percp= u.h index 3dc7291b16e9..cb9ae8a1ae87 100644 --- a/arch/arm64/include/asm/percpu.h +++ b/arch/arm64/include/asm/percpu.h @@ -21,7 +21,7 @@ static inline unsigned long __hyp_my_cpu_offset(void) return read_sysreg(tpidr_el2); } =20 -static inline unsigned long __kern_my_cpu_offset(void) +static __always_inline unsigned long __kern_my_cpu_offset(void) { unsigned long off; =20 --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DFB35237B4 for ; Mon, 7 Sep 2026 16:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799422; cv=none; b=qyePl9P2kQf2cweLbqiSFkHYMEnxALj7ZiWwMK2axpuOD3z/b/kontTNEUdqQfwBQXc6qpN+JqJTOA7kHPAoMXky5xbRrmi+AScOkECXGbGxgxXMkiAJ3CWS2e9k1itmFEIKVNnJgXw6Y3noN7REWe62dwOS7qHpwefbMm/Mdg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799422; c=relaxed/simple; bh=VPWowJvK15xsXi1SZkwQMJUYNAEQsBs1HUGpzkBeg/U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MjAiBCunoJKl6dvjLhlqog681yiUuiMBcC3JjD9XTk8j3/QFI9wwmqpnwqVg5yMHVzW7Knt8d1kvFYCzfQtAwl39MO5c4ahybqotOMaJZqEZp3xGzYRcPiLXd8pd3wHvNlXy4XELVT44Ai7Q+nRvfkQKvj6kqmeT9Hgey97XAYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jnfY20oN; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jnfY20oN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F6AC1F00A3D; Mon, 7 Sep 2026 16:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799421; bh=etbcsch4QcilvSyBQAF3RxNP3Gl+idZnVnuLeHsdrpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jnfY20oNgXj012V/khZlVSp+qpxna1T1uqFca5dEDuqQ4E8xQQrHqiiHTWssX7Umz plmSMPw/pb/GwkN/X2j8SpZSdHMug2c+CNLxMxG/sjqQ3NYrJptOmUK7rmQRXvvQPI qvTxufELRqMHo59cqDtmMXSVNgyYpPEtghSGOWYylSC68cJBaEgp32ZwWwhZsXlhvt y0M2QAX3PeVvcd39+6+byr8isG9sI0zYqFqbzWDyKNAZ/e/i+mZ2NZp4U8Gv7eXTv9 wilPNCyR3xIbgyx559xkbB9MAXXkh/lpwA/RdJ/hgChf+0Q0KCT63nBZcbQCB54xCo kimXZKgbO4gjQ== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 12/21] KVM: arm64: Preserve handler/thread bit of EL1 mode in __finalise_el2() Date: Mon, 7 Sep 2026 17:42:37 +0100 Message-ID: <20260907164247.17223-13-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __finalise_el2() unconditionally returns to EL2h when VHE is being used. In preparation for handling callers from both EL1h and EL1t, preserve the handler/thread bit of the calling mode when rewriting the exception level in the SPSR. Signed-off-by: Will Deacon --- arch/arm64/include/uapi/asm/ptrace.h | 1 + arch/arm64/kernel/hyp-stub.S | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi= /asm/ptrace.h index 15649a253a57..25d9d9a0a6f7 100644 --- a/arch/arm64/include/uapi/asm/ptrace.h +++ b/arch/arm64/include/uapi/asm/ptrace.h @@ -37,6 +37,7 @@ #define PSR_MODE_EL3t 0x0000000c #define PSR_MODE_EL3h 0x0000000d #define PSR_MODE_MASK 0x0000000f +#define PSR_MODE_h_BIT 0x00000001 =20 /* AArch32 CPSR bits */ #define PSR_MODE32_BIT 0x00000010 diff --git a/arch/arm64/kernel/hyp-stub.S b/arch/arm64/kernel/hyp-stub.S index 37c6976e44a4..f61778cccd3c 100644 --- a/arch/arm64/kernel/hyp-stub.S +++ b/arch/arm64/kernel/hyp-stub.S @@ -149,10 +149,11 @@ SYM_CODE_START_LOCAL(__finalise_el2) =20 isb =20 - // Hack the exception return to stay at EL2 + // Hack the exception return to stay at EL2 ... mrs x0, spsr_el1 - and x0, x0, #~PSR_MODE_MASK - mov x1, #PSR_MODE_EL2h + // ... preserving the 'h' bit so we don't swizzle SP. + and x0, x0, #(~PSR_MODE_MASK | PSR_MODE_h_BIT) + mov x1, #PSR_MODE_EL2t orr x0, x0, x1 msr spsr_el1, x0 =20 --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B955D524AE3 for ; Mon, 7 Sep 2026 16:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799425; cv=none; b=UFzB0Yqs0ygozT7246Tk8kPXko8Zet7uK4YLecwcb93NoQiuhCwOmeK+5D6DZt1ReSOGTnWCYUmD3n+PcoTh8XcpoXACuBsMgWNprD+4eLYBRHhnvgmyhL8HLjs6NmJInwa2bKu2uRnvTnh5geCvUmHcn5JIAKtiCQz6BhuwC+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799425; c=relaxed/simple; bh=x0XDDGaaWxHFdmMETaK1MfWAAjUcBaZjEM1PMLXBU0E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NAlfxMvrgG/9jEKqxsiWWDMVlEmCsW+jxV6byjms5brfudGnp7/u3tA8OWDfvPVEOHnlvFp+F2iugJqNDI13D9nhb95fN7iP6W1pamlbLKFLuDnEqSWSL0sIWfQ2bl1dwk1G+5hix/5QhEfOPARimpWJpQbc2T+rTvae9mcQQAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YZAOrzDF; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YZAOrzDF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F3631F00A3A; Mon, 7 Sep 2026 16:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799424; bh=BDzhVCGue3W4kwX6q3tsgotgwxJZX9yA0SsacigpNYw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YZAOrzDFErWk3qZZVEGDOIMnCekrj4170ZlGWStK7PD50ym+iC3IY3aj+kuuwp9IY B0avZObpJ/Y9ymL+p+BNseiK/9qb3m392BtWLOwUZXQDs/YReY54IZjdSRf84q26zX FcpMciaj7TZay4t7sVRKnAXiTDVIqMHa6HiSNY892+M3ptpl+K3ulEwwBYWLjzrE9s 4MBO08lLI5NPBV6UGitz7r4Qo2yagHRQVTJ0d5M3blebpb+dvFNrSr/+VnbsRuL7N5 D3vMW4c7Yw+QKY4Mva6xFM8DpaUY1eR2uZTBOmsltFx5sCVdSYwPsmGthjIQC/4nJz FxVi4mbwg3sSg== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier , kernel test robot Subject: [PATCH 13/21] arm64: sdei: Guard most of asm/sdei.h with CONFIG_ARM_SDE_INTERFACE Date: Mon, 7 Sep 2026 17:42:38 +0100 Message-ID: <20260907164247.17223-14-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The SDEI header includes are a bit of a mess: linux/arm_sdei.h only includes asm/sdei.h if CONFIG_ARM_SDE_INTERFACE=3Dy and then goes on to provide a definition of the sdei_arch_get_entry_point() macro if it hasn't already been defined. asm/sdei.h, however, defines the same macro unconditionally and so this breaks the build if CONFIG_ARM_SDE_INTERFACE is not set and asm/sdei.h is included after linux/arm_sdei.h. The kbuild robot ran into this situation with randconfig testing, thanks to the transitive inclusion of asm/sdei.h via asm/stacktrace.h. Guard most of asm/sdei.h with CONFIG_ARM_SDE_INTERFACE to avoid redefining macros provided by linux/arm_sdei.h. Reported-by: kernel test robot Signed-off-by: Will Deacon --- arch/arm64/include/asm/sdei.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/include/asm/sdei.h b/arch/arm64/include/asm/sdei.h index b2248bd3cb58..b96eb9e22d4b 100644 --- a/arch/arm64/include/asm/sdei.h +++ b/arch/arm64/include/asm/sdei.h @@ -9,6 +9,7 @@ =20 #define SDEI_STACK_SIZE IRQ_STACK_SIZE =20 +#ifdef CONFIG_ARM_SDE_INTERFACE #ifndef __ASSEMBLER__ =20 #include @@ -50,4 +51,5 @@ unsigned long sdei_arch_get_entry_point(int conduit); #define sdei_arch_get_entry_point(x) sdei_arch_get_entry_point(x) =20 #endif /* __ASSEMBLER__ */ +#endif /* CONFIG_ARM_SDE_INTERFACE */ #endif /* __ASM_SDEI_H */ --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF2DA51E43E for ; Mon, 7 Sep 2026 16:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799429; cv=none; b=PH9eyTxAg/ilTvahz9O5XcWXebrWfvzKjAwfXvwX+vQeunV4Uebx+keDkyM6mkyE7Lb7B5B/WlvAX+wKPaZMRu+ODjCooZvfjfOhvKLOsi9FG9nwyled9EKSQBtxy8NjvUlNPCRpeqs253bisDsC0PepHWmj8zUlcKvUmZNfNLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799429; c=relaxed/simple; bh=Ckombhrq0TS01O4gWB6HzwxlD8NKzPbgClG8LVbA0c8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xf9JZqgdPfHbmp6MtKi1tnwYqjIWOt6oKydHsgwpbfzk3oBP8KWzlXkV1ekg1obAsNMIsD3grUiUGIHjuaQfE2rbyi9dk5wiM/ySTHTzU9BNI4XDoIJNOvUTARTx7MAaBTvPqNk/2T/1XDDlzQpmmurWrLQWaCXjmuJ5NBtkgtY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HtrEthrk; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HtrEthrk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3714D1F00A3F; Mon, 7 Sep 2026 16:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799428; bh=jH28rU+mnq1lsgGFv5viipgfUPbuK680E/2q+gPKoGE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HtrEthrk4YJ570v367OewbhJ0OaY8Q3MQQOiNhFUQ0pKOzv6hqbvsIj2cS20df17d p70KKwJDAsqwem0At8drTuNpFNb57H9hcRnctyqCw8nyApJ72n7kHHobs4LxI4Rdq/ mc7W1qg+8b7pPlcDwkfBw3B+IxV7AuFqOUBtmNVOegoDgb7daeOGtSVfvVJUAnWL2Q 5jf7LPC5fWvVDHZ7kxQp7FvfVfRfQW3l+EzLe1HR8Hd6Fh3nrZBorujR/EuaNPWzz7 9pDf7VAhr1JDh1i+MQ7XVmdy1WmWw+t1I1gMunSyHxQ+lwZIkNHuYiBiGm6cU7lrnj Bpvc/hBGiAN/g== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 14/21] arm64: sdei: Support SDEI events from kernel handler and thread modes Date: Mon, 7 Sep 2026 17:42:39 +0100 Message-ID: <20260907164247.17223-15-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Section 5.2.2 ("Event resume context") of the SDEI specification states that, as a result of an SDEI_EVENT_COMPLETE_AND_RESUME call: | SPSR_ELc is set to the PSTATE when the event was taken In preparation for making use of both thread and handler modes in the kernel, adjust the SDEI event handler so that we return to the correct kernel vector for the interrupted mode. Signed-off-by: Will Deacon --- arch/arm64/kernel/sdei.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index 778f2a1faac8..6337ce905593 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -208,7 +208,7 @@ unsigned long __kprobes do_sdei_event(struct pt_regs *r= egs, int i, err =3D 0; int clobbered_registers =3D 4; u64 elr =3D read_sysreg(elr_el1); - u32 kernel_mode =3D read_sysreg(CurrentEL) | 1; /* +SPSel */ + u32 kernel_mode =3D read_sysreg(CurrentEL); unsigned long vbar =3D read_sysreg(vbar_el1); =20 if (arm64_kernel_unmapped_at_el0()) @@ -233,7 +233,7 @@ unsigned long __kprobes do_sdei_event(struct pt_regs *r= egs, pr_warn("unsafe: exception during handler\n"); } =20 - mode =3D regs->pstate & (PSR_MODE32_BIT | PSR_MODE_MASK); + mode =3D regs->pstate & (PSR_MODE32_BIT | PSR_MODE_MASK) & ~PSR_MODE_h_BI= T; =20 /* * If we interrupted the kernel with interrupts masked, we always go @@ -251,7 +251,7 @@ unsigned long __kprobes do_sdei_event(struct pt_regs *r= egs, * address'. */ if (mode =3D=3D kernel_mode) - return vbar + 0x280; + return vbar + (regs->pstate & PSR_MODE_h_BIT ? 0x280 : 0x80); else if (mode & PSR_MODE32_BIT) return vbar + 0x680; =20 --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86B2751E444 for ; Mon, 7 Sep 2026 16:43:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799432; cv=none; b=myers/ecZ0q3YagUuWuWeU3nf9OV+LklwSy41BAaRvuuT6v4q/HixVyc/7/nluymnjtBYL6+UNm5zoFUBf6JkKAN3MYAuTPzslqKiRK2Oo9sz8CYrXfcSI9k1cHC7UgAkohh+YWT9J7bookk5gENn2tVaGqAqfGAKWZ6RbDfihQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799432; c=relaxed/simple; bh=Te4DRSy4xtpWcqXZ88nRMIS+Kdm8FeBZqGLWgk+IODM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B2KquTu/WjSgDKDiUuc1yyejuliW639ycGBJOSeZIm7RLpgR79UcIzqNVfnhCZHK95gS88cf4azinxYAQMhjDKkqwu4mTp7cHgiWliImAzm2h5Argrh6f3srDZwdNvku3vUo/C4nLrAUX5eqWOoHbF5QNELMdwhK7W8V6NqbMuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GrxXhU06; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GrxXhU06" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9795D1F00A3E; Mon, 7 Sep 2026 16:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799431; bh=288+HAQJtG5VUtUXqsPB5v/Uwv9sAFZK9ElMT3/ktos=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GrxXhU06Oa0TvnY8YBCKujRY7bHLUC/gxIrBnOT95k66+ccDei5lUu2g7a20DIZB8 qb0M86tduW0HvBxJkhxlBmb/byxZoaXasJOJ8mh6m0rfZItt35sMlwaOk9/DiJDHvi rLlB5nNiFCBtVHuOWUmhCB92RHNuYFJDt+qFioS0arHQiELQeZ3yQbE3Ah6RX4WR93 RHNobZ8/EghVwtJPvnkgR0g3ei7GE1c5Lz01dwTEVUiE6aZtICBV57CZrqUVZjIArY hHlXbPilHMWGK3g9WITSJgcbYWUFddyRQUDY/6d0r9vT8QamNJ/VF4jdVQgGCe4Upu BKuQJ+sE6IzmQ== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 15/21] arm64: entry: Point SP_EL0 at the overflow stack Date: Mon, 7 Sep 2026 17:42:40 +0100 Message-ID: <20260907164247.17223-16-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With SP_EL0 now available for use in the kernel, point it at the overflow stack so that exception entry from EL1h will later be able to switch to the overflow stack by writing to SPSel. Cc: Mark Rutland Signed-off-by: Will Deacon --- arch/arm64/kernel/entry.S | 2 ++ arch/arm64/kernel/head.S | 3 +++ arch/arm64/kernel/smp.c | 12 ++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index a45be0a837c8..6958ee238649 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -227,6 +227,8 @@ alternative_cb_end mrs x21, sp_el0 ldr_this_cpu tsk, __entry_task, x20 msr tpidrro_el0, tsk + adr_this_cpu x19, overflow_stack + OVERFLOW_STACK_SIZE, x20 + msr sp_el0, x19 =20 /* * Ensure MDSCR_EL1.SS is clear, since we can unmask debug exceptions diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index c33551ee6572..27a19e1a0ee6 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -210,6 +210,9 @@ SYM_CODE_END(preserve_boot_args) ldr w\tmp2, [\tsk, #TSK_TI_CPU] ldr \tmp1, [\tmp1, \tmp2, lsl #3] set_this_cpu_offset \tmp1 + + adr_this_cpu \tmp1, overflow_stack + OVERFLOW_STACK_SIZE, \tmp2 + msr sp_el0, \tmp1 .endm =20 /* diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 702dee8d0db5..4c122d6598de 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -448,8 +449,15 @@ void __init smp_cpus_done(unsigned int max_cpus) =20 static void __init set_boot_cpu_offset(void) { - asm volatile("msr tpidr_el1, %0" - :: "r" (per_cpu_offset(0)) : "memory"); + u64 ovf_sp =3D (u64)raw_cpu_ptr(overflow_stack) + OVERFLOW_STACK_SIZE; + + asm volatile( + " msr tpidr_el1, %1\n" + " add %0, %0, %1\n" + " msr sp_el0, %0" /* Update the overflow stack pointer */ + : "+r" (ovf_sp) + : "r" (per_cpu_offset(0)) + : "memory"); } =20 void __init smp_prepare_boot_cpu(void) --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40EDE51FCA5 for ; Mon, 7 Sep 2026 16:43:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799436; cv=none; b=PhPnsbKvTjtE0J5snwqgpAaBj97AuSuuaduL7tc07NUTJq+qvP2FikC1fvK2BVGVtQkWdI+oCFa0Sry43EiVEU7eKV47tns8H7XxDEX7ZnNOvq8wh1RVAeQGM6Dk4EAAFED4ieFU+dS7oKLuEgs6zDuKcsGsmpPSZSuCygv5828= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799436; c=relaxed/simple; bh=OjwrxO+Yb3VNhrFuMQv9vy/22rWY6qBRMH79RZf/xZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ejnya2wV0eYU4Duavo9BCYSH4nGQO1IafchEKI3mWmCBCH+SIsF7QsGdcGpzUhCBDFXG9UW+0ZEB+OR1wXdyF2Cas5npDfe+UrURnhrjH43GKlLpqHULnIH/W7i0K1sG4cR9fiI7kUv+my27IOvASMnMt4zogM8SbtS12CJOe9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZoqkleTP; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZoqkleTP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 014211F00ACA; Mon, 7 Sep 2026 16:43:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799434; bh=4B7ig5JOoqM/sFSoDwiMA77B2+r7GUXRB2lSds3AJ1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZoqkleTPnHZFWHuFBC5xHFyP3BP9O1hjKw2d5rYkM2MLLe3ztBAyg38Gruwde31aS jWJRkAiHsf7M7fxkT743JrzWBtbXc7avZ6a3lIOMUjP+4MUWi/DF+pYEn87+RJxXTR CbmjaGIyGsemrCX2J59wRJx953ODDyyNCEvjMNyYdCBvbQztdnNuzYh1AEnN8cuzbI XZluHaDSekTuobMXbIG7FeQkQUliobvqTwa8p49dDI2DkKbphNiqxzhHMudrp6w1Dd lwTb+jrLO3mkW7qape3i59DZkmdj5UVmLv50Mp27xt6I8D9KttLFsOBPcEmpnD1dAZ 3+xisjdqBFSuA== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 16/21] arm64: entry: Implement EL1t exception handlers for overflow stack Date: Mon, 7 Sep 2026 17:42:41 +0100 Message-ID: <20260907164247.17223-17-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for using EL1t to handle exceptions taken whilst running on the overflow stack, implement some simple wrappers around the EL1h handlers which perform a best-effort stack overflow check before proceeding. Cc: Mark Rutland Signed-off-by: Will Deacon --- arch/arm64/kernel/entry-common.c | 43 +++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-com= mon.c index 72c03ccea59f..9738142780df 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -327,10 +327,45 @@ static void debug_exception_exit(struct pt_regs *regs) } NOKPROBE_SYMBOL(debug_exception_exit); =20 -UNHANDLED(el1t, 64, sync) -UNHANDLED(el1t, 64, irq) -UNHANDLED(el1t, 64, fiq) -UNHANDLED(el1t, 64, error) +static void noinstr el1t_64_check_overflow_stack(struct pt_regs *regs) +{ + unsigned long sp =3D kernel_stack_pointer(regs) - sizeof(*regs); + unsigned long ovf_stack =3D (unsigned long)this_cpu_ptr(overflow_stack); + + /* + * We're in big trouble if we've overflowed the overflow stack + * so perform a best-effort check before we proceed. If our SP + * is outside of the overflow stack for this CPU then presumably + * we're already corrupting memory, so park ourselves here in an + * attempt to contain the damage. + */ + if (sp < ovf_stack || sp > ovf_stack + OVERFLOW_STACK_SIZE) + cpu_park_loop(); +} + +asmlinkage void noinstr el1t_64_sync_handler(struct pt_regs *regs) +{ + el1t_64_check_overflow_stack(regs); + el1h_64_sync_handler(regs); +} + +asmlinkage void noinstr el1t_64_irq_handler(struct pt_regs *regs) +{ + el1t_64_check_overflow_stack(regs); + el1h_64_irq_handler(regs); +} + +asmlinkage void noinstr el1t_64_fiq_handler(struct pt_regs *regs) +{ + el1t_64_check_overflow_stack(regs); + el1h_64_fiq_handler(regs); +} + +asmlinkage void noinstr el1t_64_error_handler(struct pt_regs *regs) +{ + el1t_64_check_overflow_stack(regs); + el1h_64_error_handler(regs); +} =20 static void noinstr el1_abort(struct pt_regs *regs, unsigned long esr) { --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5738E525A68 for ; Mon, 7 Sep 2026 16:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799439; cv=none; b=Iy9n20FWzlq0lzlod8QHzJX7P01wYy+jPHvlvwGnkphHQ1prA1YHVMCRp2HTIqdc+2jXHiLaNom5RjqnipI0w5v+1nA7PpARYTqiWwOGkJ/QYBFOmERpOuMDiwzbT3nvZ6s6I2I7AGqQ8At3tTFPzrK+icpWBnmYXwU/ugsCQ5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799439; c=relaxed/simple; bh=8bLG3MWy6UpofcCZTd6kDNMLIzxlxwqk0wiGhy4GzCo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iKI1oD2GaMb2+H9XWdtiU4LFYj4XCzixby8M+Bo4FGpxvBmRnYDA81C6mGK5k2GDvxVwCiVZRdRtVu3pWRGPMKZWSJhu6PoizEyJ8Y2UJ8Q7v/h2l+zoYJDqJRILGzXa1Lg0SdybZXBCf6nxdjiv1sGw9mjHVaJt48YdZmn4dyk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RQclefwr; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RQclefwr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 640081F00A3E; Mon, 7 Sep 2026 16:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799438; bh=eo5Sa9KVTsh4ZkNOH8MgCszDssdClUqK2TyeGZf7Cxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RQclefwrM2t81YCtRm/pkVC8TLJSFPRfo+BeUP3sMMNiFHb8zhnENaEgHtRuf5bai ZK5FxHKaXc16ZMy3n/oYlcWXEsjaIHfMWNDputpCI3gQTOcL/FZ1wI//lc0+pm0giV YCjs4iXenw6pKaOrgKRiEbr8xURJzT/15iGe9d3dVcXf5n8STcTdfp3d2tRZL491p6 LMlTzUixjqvYrGZ2Mj3EMpUZCqkfSl82wCcD+FkxOk+K2G2C+cuaRqM8a46gEx8lmD YlEYCkXDvJYHovrMPGS3Cr95PkOGROAgJWgoE6gZyJkgYGtKmDfICJe3fvolu5uIh4 R3fDwGzEWKJaA== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 17/21] arm64: entry: Use SPSel to switch to overflow stack Date: Mon, 7 Sep 2026 17:42:42 +0100 Message-ID: <20260907164247.17223-18-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When detecting a stack overflow on exception entry from EL1, use SPSel to switch to the overflow stack without corrupting any GPRs. Not only is this simpler than the previous logic, but it also opens the door to more complicated overflow checks (for example, based on per-task stack sizes or stacks which are not aligned to a specific page order) as well as the possibility of returning from a stack fault if we were able to resolve it. Cc: Mark Rutland Signed-off-by: Will Deacon --- arch/arm64/kernel/entry.S | 69 ++++++++++++--------------------------- 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 6958ee238649..b4df2f23ebe7 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -51,11 +51,11 @@ mov x30, xzr .endif .Lskip_tramp_vectors_cleanup\@: - .endif - + sub sp, sp, #PT_REGS_SIZE + .else /* \el =3D=3D 1 */ + .ifc \ht, h sub sp, sp, #PT_REGS_SIZE =20 - .if \el =3D=3D 1 /* * Test whether the SP has overflowed, without corrupting a GPR. * Task and IRQ stacks are aligned so that SP & (1 << THREAD_SHIFT) @@ -63,45 +63,16 @@ */ add sp, sp, x0 // sp' =3D sp + x0 sub x0, sp, x0 // x0' =3D sp' - x0 =3D (sp + x0) - x0 =3D sp - tbnz x0, #THREAD_SHIFT, 0f + tbnz x0, #THREAD_SHIFT, __bad_stack sub x0, sp, x0 // x0'' =3D sp' - x0' =3D (sp + x0) - sp =3D x0 sub sp, sp, x0 // sp'' =3D sp' - x0 =3D (sp + x0) - x0 =3D sp + .else /* EL1t */ + msr spsel, #0 // Stay on the overflow stack + sub sp, sp, #PT_REGS_SIZE + .endif .endif =20 b el\el\ht\()_\regsize\()_\label - - .if \el =3D=3D 1 -0: - /* - * Either we've just detected an overflow, or we've taken an exception - * while on the overflow stack. Either way, we won't return to - * userspace, and can clobber EL0 registers to free up GPRs. - */ - - /* Stash the original SP (minus PT_REGS_SIZE) in tpidr_el0. */ - msr tpidr_el0, x0 - - /* Recover the original x0 value and stash it in sp_el0 */ - sub x0, sp, x0 - msr sp_el0, x0 - - /* Switch to the overflow stack */ - adr_this_cpu sp, overflow_stack + OVERFLOW_STACK_SIZE, x0 - - /* - * Check whether we were already on the overflow stack. This may happen - * after panic() re-enables interrupts. - */ - mrs x0, tpidr_el0 // sp of interrupted context - sub x0, sp, x0 // delta with top of overflow stack - tst x0, #~(OVERFLOW_STACK_SIZE - 1) // within range? - b.ne __bad_stack // no? -> bad stack pointer - - /* We were already on the overflow stack. Restore sp/x0 and carry on. */ - sub sp, sp, x0 - mrs x0, sp_el0 - b el\el\ht\()_\regsize\()_\label - .endif .org .Lventry_start\@ + 128 // Did we overflow the ventry slot? .endm =20 @@ -544,22 +515,24 @@ SYM_CODE_END(vectors) =20 SYM_CODE_START_LOCAL(__bad_stack) /* - * We detected an overflow in kernel_ventry, which switched to the - * overflow stack. Stash the exception regs, and head to our overflow - * handler. + * We detected an overflow in kernel_ventry. + * Restore SP and X0. */ + sub x0, sp, x0 + sub sp, sp, x0 + add sp, sp, #PT_REGS_SIZE =20 - /* Restore the original x0 value */ - mrs x0, sp_el0 + /* Switch to the overflow stack */ + msr spsel, #0 =20 - /* - * Store the original GPRs to the new stack. The orginal SP (minus - * PT_REGS_SIZE) was stashed in tpidr_el0 by kernel_ventry. - */ + /* Stash the exception regs */ sub sp, sp, #PT_REGS_SIZE kernel_entry 1 - mrs x0, tpidr_el0 - add x0, x0, #PT_REGS_SIZE + + /* Fix-up the saved SP */ + msr spsel, #1 + mov x0, sp + msr spsel, #0 str x0, [sp, #S_SP] =20 /* Stash the regs for handle_bad_stack */ --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1342525A7A for ; Mon, 7 Sep 2026 16:44:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799442; cv=none; b=UPdd1a+9QSd8d+T+rdJXB4EUXcxPJ1yGPlOnQeEjy7ZtMqRSSCHFard/qJPnwUKN2IZMULFDE5K5FAGYMjJxSHU/rOg4ZJ70X9ISKDvg1tuJNlEljXIzidgKbiwCwEPPBAegaKgxIbk+FZUoiUpo9xo1yZIF0kufvdiLH2cU8mI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799442; c=relaxed/simple; bh=/jSjLLBYOVhcCY2JUj/nCjGkMqAv9xO2ueg8OzHKbs4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lNJxJc/gHFlN2lYfwwfPTGIpy8IVk+856exrX4RfOQMyiZ+6j8xPQZCCnpIuZpK2j/Y79V77CJEI27LnE4xVKwHKtyByZt/1LMesQj29eXyu2IT7Gm0zODOnmK4ECBuAI0Gk1AK+rypC2DLFrWHieOyXhTQxFeXn5g5kOb+Ws4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OEyjscof; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OEyjscof" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0DFB1F00A3A; Mon, 7 Sep 2026 16:43:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799441; bh=dPLv7atneKjr+/YMYOQlH9/XXQJi2mlJ5aE6e63ccj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OEyjscofYI5R86Oh0seI25As1g9+YY580ZPfimzflmSM8LOzrpeyQ7ruzfrcqh11e /QmbcVdTMYQG99wzdTm2jhQ3B4ckLDGv/3/kclUhgFA9kFpFShihcPweyEz/KOh4U1 LHiCDkughJhbyZoI6THoqAAAOWar7UWhY3HV1CscULuekCbi7VPoiVw09w/xe9aMMs 51rSgLlQRemMDY2jCy9yl/fMBNsyvcPN4D+0Kofjg0q4DXheAJ+4pMeG2Aegj52M0F r1U1JZ5HDGw0tL0AI8wtWTlUGU3QuBbNGzxAFr7YZl/kWJBTYdNRdpT4aW6Tr4llHQ rFH99ISe3Q4NQ== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 18/21] arm64: entry: Split up kernel_ventry macro into separate helper macros Date: Mon, 7 Sep 2026 17:42:43 +0100 Message-ID: <20260907164247.17223-19-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Handling entry from EL0, EL1h and EL1t in the 'kernel_ventry' assembly macro is getting a bit unwieldy as the control flow becomes increasingly dependent on the macro arguments. Split 'kernel_ventry' into three leaf helper macros for EL0, EL1h and EL1t, which are then dispatched by simple wrappers. Signed-off-by: Will Deacon --- arch/arm64/kernel/entry.S | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index b4df2f23ebe7..38f9327e6a0a 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -36,10 +36,7 @@ .endr .endm =20 - .macro kernel_ventry, el:req, ht:req, regsize:req, label:req - .align 7 -.Lventry_start\@: - .if \el =3D=3D 0 + .macro kernel_ventry_el0, ht:req, regsize:req, label:req /* * This must be the first instruction of the EL0 vector entries. It is * skipped by the trampoline vectors, to trigger the cleanup. @@ -52,8 +49,10 @@ .endif .Lskip_tramp_vectors_cleanup\@: sub sp, sp, #PT_REGS_SIZE - .else /* \el =3D=3D 1 */ - .ifc \ht, h + b el0\ht\()_\regsize\()_\label + .endm + + .macro kernel_ventry_el1h, regsize:req, label:req sub sp, sp, #PT_REGS_SIZE =20 /* @@ -66,13 +65,23 @@ tbnz x0, #THREAD_SHIFT, __bad_stack sub x0, sp, x0 // x0'' =3D sp' - x0' =3D (sp + x0) - sp =3D x0 sub sp, sp, x0 // sp'' =3D sp' - x0 =3D (sp + x0) - x0 =3D sp - .else /* EL1t */ + b el1h_\regsize\()_\label + .endm + + .macro kernel_ventry_el1t, regsize:req, label:req msr spsel, #0 // Stay on the overflow stack sub sp, sp, #PT_REGS_SIZE - .endif - .endif + b el1t_\regsize\()_\label + .endm =20 - b el\el\ht\()_\regsize\()_\label + .macro kernel_ventry, el:req, ht:req, regsize:req, label:req + .align 7 +.Lventry_start\@: + .if \el =3D=3D 0 + kernel_ventry_el0 \ht, \regsize, \label + .else + kernel_ventry_el1\ht \regsize, \label + .endif .org .Lventry_start\@ + 128 // Did we overflow the ventry slot? .endm =20 --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 681CD51FCC4 for ; Mon, 7 Sep 2026 16:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799446; cv=none; b=dBVRwL7eKmm3HjcEWeX6eAknq1sRJ/A0FAz/mR9oCvT+5G3wn8IE8T7HTktwO+ztbXj0THb7sMFDK5w3MMSpZfY2B7CzrrihmOLH3x8lDdVUX6nDk8KQG5LR5WlBFhko0oa9sFrz9pKMBoXXkRT7A0xVzMHA5LaYEEEUNc8STe4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799446; c=relaxed/simple; bh=qLuWE6Sz9e913pdARFlFHICwOudf5IlaeyARdx2G6dI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gE9x5THrwJupmOT/Kstrj+fWfWC6XZozBl4UvJM7aOhOlTzujtZhCWrmi2uG0mc7vgftR+eUuTgdML+1TELjtGDJ8ZSsF+uFGRalfzmoJVCyoYoSO8YR7bEtQks3G8qhV781JWqUWwecakCCVk5/EoylbsH6qvno0Gpjg1MHx0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ak7fOXnu; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ak7fOXnu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E55C1F00A3E; Mon, 7 Sep 2026 16:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799445; bh=9g1fN8FJLnuuKj3mr19RmWJKqCpVinbgcxTQwmep0Ss=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ak7fOXnu9AX4KOzeG4jWcGJrozqD5Z0/rx7opjyEjeWH15uwYITGxgjRevzr3mRIC CKbH9cUT6zNFFAN8bfg8RZMww44HVTVuF02DDnfdgNYsHRao58bJ7dYV2F3Klv2/uH SC00qSXXGCWh+H0A7d6m6mRNMYxfqVyddDVKQ6WCkR+d5iVU+vojcXcAERn/Uf6INN B7cuHWYlxfpbRI5dLWmaSabQdGvBAOVyjF+D2HGIoGt3hnaKwiZJST/gxvO8Hkpf/u c4P7o2R+wGeVJGL5fgsrwhZa1K2+NN6MGOk+1d1DTouI1xKiF7/UswZVqx3tXZZe0s +3QR2C4asT1hQ== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 19/21] arm64: entry: The great stack switcheroo Date: Mon, 7 Sep 2026 17:42:44 +0100 Message-ID: <20260907164247.17223-20-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With the kernel stack pointer in SP_EL1 and the overflow stack pointer in SP_EL0, it is now straightforward to switch between the two on exception entry from EL1 by writing to SPSel. However, since exception entry sets PSTATE.SP to 1 (selecting SP_EL1 as the stack pointer), repurposing the overflow stack as a more general kernel exception stack would require writing to SPSel on every exception entry from the kernel. Switch things around so that the overflow stack resides in SP_EL1, with the kernel stack residing in SP_EL0. Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_asm.h | 16 +++++++++++++++ arch/arm64/kernel/entry-common.c | 34 ++++++++++++++++---------------- arch/arm64/kernel/entry.S | 26 +++++++++++++----------- arch/arm64/kernel/head.S | 5 ++++- arch/arm64/kernel/smp.c | 8 +++++--- arch/arm64/kvm/hyp/entry.S | 3 +++ arch/arm64/mm/proc.S | 3 +++ 7 files changed, 63 insertions(+), 32 deletions(-) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_= asm.h index 1cfe9216a2ff..bde046c3ca79 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -398,6 +398,22 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr,= u64 spsr, u64 elr_virt, ldp x29, lr, [\ctxt, #CPU_XREG_OFFSET(29)] .endm =20 +#ifdef __KVM_VHE_HYPERVISOR__ +.macro activate_exception_stack +msr spsel, #1 +.endm + +.macro deactivate_exception_stack +msr spsel, #0 +.endm +#else +.macro activate_exception_stack +.endm + +.macro deactivate_exception_stack +.endm +#endif + .macro save_sp_el0 ctxt, tmp mrs \tmp, sp_el0 str \tmp, [\ctxt, #CPU_SP_EL0_OFFSET] diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-com= mon.c index 9738142780df..9d734cd09f62 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -327,7 +327,7 @@ static void debug_exception_exit(struct pt_regs *regs) } NOKPROBE_SYMBOL(debug_exception_exit); =20 -static void noinstr el1t_64_check_overflow_stack(struct pt_regs *regs) +static void noinstr el1h_64_check_overflow_stack(struct pt_regs *regs) { unsigned long sp =3D kernel_stack_pointer(regs) - sizeof(*regs); unsigned long ovf_stack =3D (unsigned long)this_cpu_ptr(overflow_stack); @@ -343,28 +343,28 @@ static void noinstr el1t_64_check_overflow_stack(stru= ct pt_regs *regs) cpu_park_loop(); } =20 -asmlinkage void noinstr el1t_64_sync_handler(struct pt_regs *regs) +asmlinkage void noinstr el1h_64_sync_handler(struct pt_regs *regs) { - el1t_64_check_overflow_stack(regs); - el1h_64_sync_handler(regs); + el1h_64_check_overflow_stack(regs); + el1t_64_sync_handler(regs); } =20 -asmlinkage void noinstr el1t_64_irq_handler(struct pt_regs *regs) +asmlinkage void noinstr el1h_64_irq_handler(struct pt_regs *regs) { - el1t_64_check_overflow_stack(regs); - el1h_64_irq_handler(regs); + el1h_64_check_overflow_stack(regs); + el1t_64_irq_handler(regs); } =20 -asmlinkage void noinstr el1t_64_fiq_handler(struct pt_regs *regs) +asmlinkage void noinstr el1h_64_fiq_handler(struct pt_regs *regs) { - el1t_64_check_overflow_stack(regs); - el1h_64_fiq_handler(regs); + el1h_64_check_overflow_stack(regs); + el1t_64_fiq_handler(regs); } =20 -asmlinkage void noinstr el1t_64_error_handler(struct pt_regs *regs) +asmlinkage void noinstr el1h_64_error_handler(struct pt_regs *regs) { - el1t_64_check_overflow_stack(regs); - el1h_64_error_handler(regs); + el1h_64_check_overflow_stack(regs); + el1t_64_error_handler(regs); } =20 static void noinstr el1_abort(struct pt_regs *regs, unsigned long esr) @@ -494,7 +494,7 @@ static void noinstr el1_fpac(struct pt_regs *regs, unsi= gned long esr) arm64_exit_to_kernel_mode(regs, state); } =20 -asmlinkage void noinstr el1h_64_sync_handler(struct pt_regs *regs) +asmlinkage void noinstr el1t_64_sync_handler(struct pt_regs *regs) { unsigned long esr =3D read_sysreg(esr_el1); =20 @@ -578,17 +578,17 @@ static void noinstr el1_interrupt(struct pt_regs *reg= s, __el1_irq(regs, handler); } =20 -asmlinkage void noinstr el1h_64_irq_handler(struct pt_regs *regs) +asmlinkage void noinstr el1t_64_irq_handler(struct pt_regs *regs) { el1_interrupt(regs, handle_arch_irq); } =20 -asmlinkage void noinstr el1h_64_fiq_handler(struct pt_regs *regs) +asmlinkage void noinstr el1t_64_fiq_handler(struct pt_regs *regs) { el1_interrupt(regs, handle_arch_fiq); } =20 -asmlinkage void noinstr el1h_64_error_handler(struct pt_regs *regs) +asmlinkage void noinstr el1t_64_error_handler(struct pt_regs *regs) { unsigned long esr =3D read_sysreg(esr_el1); irqentry_state_t state; diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 38f9327e6a0a..afcd84510daf 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -54,6 +54,12 @@ =20 .macro kernel_ventry_el1h, regsize:req, label:req sub sp, sp, #PT_REGS_SIZE + b el1h_\regsize\()_\label + .endm + + .macro kernel_ventry_el1t, regsize:req, label:req + msr spsel, #0 // Stay on the kernel stack + sub sp, sp, #PT_REGS_SIZE =20 /* * Test whether the SP has overflowed, without corrupting a GPR. @@ -65,12 +71,6 @@ tbnz x0, #THREAD_SHIFT, __bad_stack sub x0, sp, x0 // x0'' =3D sp' - x0' =3D (sp + x0) - sp =3D x0 sub sp, sp, x0 // sp'' =3D sp' - x0 =3D (sp + x0) - x0 =3D sp - b el1h_\regsize\()_\label - .endm - - .macro kernel_ventry_el1t, regsize:req, label:req - msr spsel, #0 // Stay on the overflow stack - sub sp, sp, #PT_REGS_SIZE b el1t_\regsize\()_\label .endm =20 @@ -208,7 +208,10 @@ alternative_cb_end ldr_this_cpu tsk, __entry_task, x20 msr tpidrro_el0, tsk adr_this_cpu x19, overflow_stack + OVERFLOW_STACK_SIZE, x20 - msr sp_el0, x19 + mov x20, sp + msr sp_el0, x20 + mov sp, x19 + msr spsel, #0 =20 /* * Ensure MDSCR_EL1.SS is clear, since we can unmask debug exceptions @@ -346,6 +349,9 @@ alternative_else_nop_endif =20 .if \el =3D=3D 0 ldr x23, [sp, #S_SP] // load return stack pointer + mov x0, sp + msr spsel, #1 + mov sp, x0 msr sp_el0, x23 msr tpidrro_el0, xzr tst x22, #PSR_MODE32_BIT // native task? @@ -532,16 +538,14 @@ SYM_CODE_START_LOCAL(__bad_stack) add sp, sp, #PT_REGS_SIZE =20 /* Switch to the overflow stack */ - msr spsel, #0 + msr spsel, #1 =20 /* Stash the exception regs */ sub sp, sp, #PT_REGS_SIZE kernel_entry 1 =20 /* Fix-up the saved SP */ - msr spsel, #1 - mov x0, sp - msr spsel, #0 + mrs x0, sp_el0 str x0, [sp, #S_SP] =20 /* Stash the regs for handle_bad_stack */ diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 27a19e1a0ee6..7419e1d8b7ec 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -211,8 +211,11 @@ SYM_CODE_END(preserve_boot_args) ldr \tmp1, [\tmp1, \tmp2, lsl #3] set_this_cpu_offset \tmp1 =20 - adr_this_cpu \tmp1, overflow_stack + OVERFLOW_STACK_SIZE, \tmp2 + mov \tmp1, sp msr sp_el0, \tmp1 + adr_this_cpu \tmp1, overflow_stack + OVERFLOW_STACK_SIZE, \tmp2 + mov sp, \tmp1 + msr spsel, #0 .endm =20 /* diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 4c122d6598de..b2e778aae881 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -447,14 +447,16 @@ void __init smp_cpus_done(unsigned int max_cpus) mark_linear_text_alias_ro(); } =20 -static void __init set_boot_cpu_offset(void) +static void __init update_boot_cpu_offset_and_overflow_stack(void) { u64 ovf_sp =3D (u64)raw_cpu_ptr(overflow_stack) + OVERFLOW_STACK_SIZE; =20 asm volatile( " msr tpidr_el1, %1\n" " add %0, %0, %1\n" - " msr sp_el0, %0" /* Update the overflow stack pointer */ + " msr spsel, #1\n" + " mov sp, %0\n" /* Update the overflow stack pointer */ + " msr spsel, #0" : "+r" (ovf_sp) : "r" (per_cpu_offset(0)) : "memory"); @@ -467,7 +469,7 @@ void __init smp_prepare_boot_cpu(void) * setup_per_cpu_areas(), and CPU0's boot time per-cpu area will be * freed shortly, so we must move over to the runtime per-cpu area. */ - set_boot_cpu_offset(); + update_boot_cpu_offset_and_overflow_stack(); =20 cpuinfo_store_boot_cpu(); setup_boot_cpu_features(); diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S index 4c89931a6a92..4d1205d04383 100644 --- a/arch/arm64/kvm/hyp/entry.S +++ b/arch/arm64/kvm/hyp/entry.S @@ -31,6 +31,7 @@ SYM_FUNC_START(__guest_enter) save_callee_saved_regs x1 =20 // Save hyp's sp_el0 and tpidrro_el0 + activate_exception_stack save_sp_el0 x1, x2 save_tpidrro_el0 x1, x2 =20 @@ -50,6 +51,7 @@ alternative_else_nop_endif // that would usually be synchonized by the ERET. isb mov x0, #ARM_EXCEPTION_IRQ + deactivate_exception_stack ret =20 1: @@ -167,6 +169,7 @@ SYM_INNER_LABEL(__guest_exit, SYM_L_GLOBAL) // Restore hyp's sp_el0 and tpidrro_el0 restore_sp_el0 x2, x3 restore_tpidrro_el0 x2, x3 + deactivate_exception_stack =20 // Now restore the hyp regs restore_callee_saved_regs x2 diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 12aacc74f764..0811fa569100 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -98,6 +98,7 @@ SYM_FUNC_START(cpu_do_suspend) mrs x10, oslsr_el1 mrs x11, sctlr_el1 get_this_cpu_offset x12 + msr spsel, #1 mrs x13, sp_el0 stp x2, x3, [x0] stp x4, x5, [x0, #16] @@ -156,6 +157,8 @@ alternative_else_nop_endif msr sctlr_el1, x12 set_this_cpu_offset x13 msr sp_el0, x14 + msr spsel, #0 + /* * Restore oslsr_el1 by writing oslar_el1 */ --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BF63521216 for ; Mon, 7 Sep 2026 16:44:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799449; cv=none; b=NfRteHuQYoO25/XQ+qf+Ywn14+VnSyyb6PHK3BZGi1KT2xcTl3YgLecOe6OdAaq3FdULMu9bJz5+qlX/p4YMR8YmSd24Otn6ZKC+c8Zd7jws/GOk+C6riYoegKlmqTW6zUiCsdU2/S5HvgmwhwLuAaGLf7uxELblUjQuFhVlJ20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799449; c=relaxed/simple; bh=5w+w9N7qo/Kr9St2C3GcFvaWy+IiY4pdFryRAKuO59s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nAiobTQ/GU9UtBbNGHMLl5E6s3IckSQr6c5g2IkNtc0/yDe6vKGEQb4Cf/8xhWNNCzTnWAVAiz+PfzggdBiDTxXKEKD+QoWqGbQLatLNkein1VSDXzczFFhuf55teCWGJyzKJXKlNEL0oufEyExOZnifRVMd0kF6c0TlKZOzFuA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AV+pENzp; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AV+pENzp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8816F1F00A3A; Mon, 7 Sep 2026 16:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799448; bh=3E+XhQ30UlSW21cfmh1kLGlFL8sP6bIE+ExxMayVkkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AV+pENzpNe27jKIRoaSpGRhj+K6DyKrFuqwdK17SPFXT/5AnsIBfBSBdwOfMzKxpc fusF7opzvBzOf7cEAO6mmO7nv5qm4yVYIEcgBdRBcjlL31LxlCCQpO0WsjYxFTg13+ lVmir353ArSW6V665gZcFE65Gk3hwLNY+jUcI5V/6CsMsrd4+o9PmeowL3qS17szVs /Lxe197LqGIm0k6NR0uwjgf7XBhAoBlUoAoJZP98KSunln7jRO/oO3NtbJ/AN6HSf9 x1eGknKxlfOcI0XbD87xwF5z5nnEdEFNmeHbZyMYLYckUfcINTLyIZb1UYb0nhsJ37 hY9RTEhQGMqtg== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 20/21] arm64: tracing: Advertise a mode of EL1t in synthetic kernel regs Date: Mon, 7 Sep 2026 17:42:45 +0100 Message-ID: <20260907164247.17223-21-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When synthesising a kernel regs structure for ftrace or perf, advertise a mode of EL1t to reflect the mode in which the kernel runs for the vast majority of the time. Signed-off-by: Will Deacon --- arch/arm64/include/asm/ftrace.h | 4 ++-- arch/arm64/include/asm/perf_event.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrac= e.h index 1621c84f44b3..d55a019cdf0a 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -153,7 +153,7 @@ ftrace_partial_regs(const struct ftrace_regs *fregs, st= ruct pt_regs *regs) regs->pc =3D afregs->pc; regs->regs[29] =3D afregs->fp; regs->regs[30] =3D afregs->lr; - regs->pstate =3D PSR_MODE_EL1h; + regs->pstate =3D PSR_MODE_EL1t; return regs; } =20 @@ -161,7 +161,7 @@ ftrace_partial_regs(const struct ftrace_regs *fregs, st= ruct pt_regs *regs) (_regs)->pc =3D arch_ftrace_regs(fregs)->pc; \ (_regs)->regs[29] =3D arch_ftrace_regs(fregs)->fp; \ (_regs)->sp =3D arch_ftrace_regs(fregs)->sp; \ - (_regs)->pstate =3D PSR_MODE_EL1h; \ + (_regs)->pstate =3D PSR_MODE_EL1t; \ } while (0) =20 int ftrace_regs_query_register_offset(const char *name); diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/p= erf_event.h index ee45b4e77347..b3e7c24a5aab 100644 --- a/arch/arm64/include/asm/perf_event.h +++ b/arch/arm64/include/asm/perf_event.h @@ -17,7 +17,7 @@ (regs)->pc =3D (__ip); \ (regs)->regs[29] =3D (unsigned long) __builtin_frame_address(0); \ (regs)->sp =3D current_stack_pointer; \ - (regs)->pstate =3D PSR_MODE_EL1h; \ + (regs)->pstate =3D PSR_MODE_EL1t; \ } =20 #endif --=20 2.55.0.979.g7e5102b832-goog From nobody Fri Sep 25 23:08:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 244D4526A89 for ; Mon, 7 Sep 2026 16:44:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799453; cv=none; b=trEMCTZjYMoo6V1OcAYZuFB/BIYixxc9iaHxAwmhpf9fH2FhA1gXVWN/DSgjy2dr3jYsTRMWtu9gsy7+rrgqko53MbXQcdTDkoPbQBb+XCXRSnzK7Nm4E1oSyQibgrlMrGtULzDOMEF/Dyc9+kz9n3RVrURmDZDH3sEn5cBobqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788799453; c=relaxed/simple; bh=C+nN3yHW4vT3mRjDA1dZ5UglQQcR85NaJqlxCF71inw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JcubcU48Zjt3mSO5uJEyR5X7+KW/ejhD2NKjk9DMsA89ALNcClNdDXZ2B63SjbPwP6hsDyr6F8E8ljDmoYOnx7mTCVxSkw5YwJKsmbfXXz1/BySLxLO9282nR08QFtVdWqMt5IpMgWrLka8W2G4S1acpmDYpK68EExj9wLh2uJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HKs61XX8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HKs61XX8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA71C1F00A3F; Mon, 7 Sep 2026 16:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788799451; bh=mfGjPKgc3qx+td6ktkbm/INFRpZnkn57gpMaPuzTD/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HKs61XX8CvuVioaYlQwNc3JPB64PiPxs8yimoxDLgY5IRUr9JRYlmA1c3NE9BXgJy CsRlv02mVv2MxTH8r+iao1rmSmOujEERV+daw9RY0a91usOlxdui4l74b4/lejGuln Q/b2DYAc/KJVbrjtnFqPx0WbKJJN5dLCs62TLBl2Es6IE1eSHAoji9zTDz636IMXJh Qoui9EtI9x2/g81L9w8iq6qaGz8YAQ9SBhSUvfGnGNq78Nv3ANfUpMo7r0QFHTJW7u 1g6FVK8R/2nl9QM9ePMAWWYn8zDMqTm4ksPQ2MstetelZYfqyQvrwaEti8sWMTkrzk U47Iq45rbt+dg== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Will Deacon , Arnd Bergmann , Ard Biesheuvel , Ada Couprie Diaz , David Hildenbrand , Catalin Marinas , Vladimir Murzin , Mark Rutland , Mostafa Saleh , Lorenzo Stoakes , Oliver Upton , Linus Walleij , Marc Zyngier Subject: [PATCH 21/21] arm64: Rename 'overflow_stack' and OVERFLOW_STACK_SIZE Date: Mon, 7 Sep 2026 17:42:46 +0100 Message-ID: <20260907164247.17223-22-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260907164247.17223-1-will@kernel.org> References: <20260907164247.17223-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that the kernel "overflow" stack resides in SP_EL1, it is the active stack for any exception taken from the kernel. Even though we currently switch immediately to the kernel stack in the EL1t entry code, rename the "overflow_stack" to "kernel_exception_stack" to better reflect its usage. Introduce NVHE_OVERFLOW_STACK_SIZE to keep the EL2 overflow stack size distinct from the EL1 kernel exception stack size. Signed-off-by: Will Deacon --- arch/arm64/include/asm/memory.h | 10 ++++++---- arch/arm64/include/asm/stacktrace.h | 9 +++++---- arch/arm64/include/asm/stacktrace/nvhe.h | 3 +-- arch/arm64/kernel/entry-common.c | 18 +++++++++--------- arch/arm64/kernel/entry.S | 2 +- arch/arm64/kernel/head.S | 2 +- arch/arm64/kernel/smp.c | 9 +++++---- arch/arm64/kernel/stacktrace.c | 2 +- arch/arm64/kernel/traps.c | 14 +++++++------- arch/arm64/kvm/hyp/nvhe/host.S | 2 +- arch/arm64/kvm/hyp/nvhe/stacktrace.c | 4 ++-- arch/arm64/kvm/stacktrace.c | 4 ++-- 12 files changed, 41 insertions(+), 38 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memor= y.h index a2b7a33966ff..93ce6ef65573 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -139,10 +139,11 @@ =20 #define IRQ_STACK_SIZE THREAD_SIZE =20 -#define OVERFLOW_STACK_SIZE SZ_4K +#define KERNEL_EXC_STACK_SIZE SZ_4K =20 -#define NVHE_STACK_SHIFT PAGE_SHIFT -#define NVHE_STACK_SIZE (UL(1) << NVHE_STACK_SHIFT) +#define NVHE_OVERFLOW_STACK_SIZE SZ_4K +#define NVHE_STACK_SHIFT PAGE_SHIFT +#define NVHE_STACK_SIZE (UL(1) << NVHE_STACK_SHIFT) =20 /* * With the minimum frame size of [x29, x30], exactly half the combined @@ -150,7 +151,8 @@ * save the unwinded stacktrace; plus an additional entry to delimit the * end. */ -#define NVHE_STACKTRACE_SIZE ((OVERFLOW_STACK_SIZE + NVHE_STACK_SIZE) / 2 = + sizeof(long)) +#define NVHE_STACKTRACE_SIZE ((NVHE_OVERFLOW_STACK_SIZE + NVHE_STACK_SIZE)= \ + / 2 + sizeof(long)) =20 /* * Alignment of kernel segments (e.g. .text, .data). diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/s= tacktrace.h index 6d3280932bf5..eb18d7cee62f 100644 --- a/arch/arm64/include/asm/stacktrace.h +++ b/arch/arm64/include/asm/stacktrace.h @@ -59,12 +59,13 @@ static inline bool on_task_stack(const struct task_stru= ct *tsk, =20 #define on_thread_stack() (on_task_stack(current, current_stack_pointer, 1= )) =20 -DECLARE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow= _stack); +DECLARE_PER_CPU(unsigned long [KERNEL_EXC_STACK_SIZE/sizeof(long)], + kernel_exception_stack); =20 -static inline struct stack_info stackinfo_get_overflow(void) +static inline struct stack_info stackinfo_get_kernel_exception(void) { - unsigned long low =3D (unsigned long)raw_cpu_ptr(overflow_stack); - unsigned long high =3D low + OVERFLOW_STACK_SIZE; + unsigned long low =3D (unsigned long)raw_cpu_ptr(kernel_exception_stack); + unsigned long high =3D low + KERNEL_EXC_STACK_SIZE; =20 return (struct stack_info) { .low =3D low, diff --git a/arch/arm64/include/asm/stacktrace/nvhe.h b/arch/arm64/include/= asm/stacktrace/nvhe.h index 171f9edef49f..629dd2d2caa3 100644 --- a/arch/arm64/include/asm/stacktrace/nvhe.h +++ b/arch/arm64/include/asm/stacktrace/nvhe.h @@ -44,8 +44,7 @@ static inline void kvm_nvhe_unwind_init(struct unwind_sta= te *state, * In non-protected mode, the unwinding is done from kernel proper context * (by the host in EL1). */ - -DECLARE_KVM_NVHE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)],= overflow_stack); +DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_OVERFLOW_STACK_SIZE/sizeof(lo= ng)], overflow_stack); DECLARE_KVM_NVHE_PER_CPU(struct kvm_nvhe_stacktrace_info, kvm_stacktrace_i= nfo); DECLARE_PER_CPU(unsigned long, kvm_arm_hyp_stack_base); =20 diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-com= mon.c index 9d734cd09f62..7e9b26cf1bdc 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -327,43 +327,43 @@ static void debug_exception_exit(struct pt_regs *regs) } NOKPROBE_SYMBOL(debug_exception_exit); =20 -static void noinstr el1h_64_check_overflow_stack(struct pt_regs *regs) +static void noinstr el1h_64_check_exception_stack(struct pt_regs *regs) { unsigned long sp =3D kernel_stack_pointer(regs) - sizeof(*regs); - unsigned long ovf_stack =3D (unsigned long)this_cpu_ptr(overflow_stack); + unsigned long exc_stack =3D (unsigned long)this_cpu_ptr(kernel_exception_= stack); =20 /* - * We're in big trouble if we've overflowed the overflow stack + * We're in big trouble if we've overflowed the exception stack * so perform a best-effort check before we proceed. If our SP - * is outside of the overflow stack for this CPU then presumably + * is outside of the exceptoin stack for this CPU then presumably * we're already corrupting memory, so park ourselves here in an * attempt to contain the damage. */ - if (sp < ovf_stack || sp > ovf_stack + OVERFLOW_STACK_SIZE) + if (sp < exc_stack || sp > exc_stack + KERNEL_EXC_STACK_SIZE) cpu_park_loop(); } =20 asmlinkage void noinstr el1h_64_sync_handler(struct pt_regs *regs) { - el1h_64_check_overflow_stack(regs); + el1h_64_check_exception_stack(regs); el1t_64_sync_handler(regs); } =20 asmlinkage void noinstr el1h_64_irq_handler(struct pt_regs *regs) { - el1h_64_check_overflow_stack(regs); + el1h_64_check_exception_stack(regs); el1t_64_irq_handler(regs); } =20 asmlinkage void noinstr el1h_64_fiq_handler(struct pt_regs *regs) { - el1h_64_check_overflow_stack(regs); + el1h_64_check_exception_stack(regs); el1t_64_fiq_handler(regs); } =20 asmlinkage void noinstr el1h_64_error_handler(struct pt_regs *regs) { - el1h_64_check_overflow_stack(regs); + el1h_64_check_exception_stack(regs); el1t_64_error_handler(regs); } =20 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index afcd84510daf..a31ef890a2ee 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -207,7 +207,7 @@ alternative_cb_end mrs x21, sp_el0 ldr_this_cpu tsk, __entry_task, x20 msr tpidrro_el0, tsk - adr_this_cpu x19, overflow_stack + OVERFLOW_STACK_SIZE, x20 + adr_this_cpu x19, kernel_exception_stack + KERNEL_EXC_STACK_SIZE, x20 mov x20, sp msr sp_el0, x20 mov sp, x19 diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 7419e1d8b7ec..794cefaf8482 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -213,7 +213,7 @@ SYM_CODE_END(preserve_boot_args) =20 mov \tmp1, sp msr sp_el0, \tmp1 - adr_this_cpu \tmp1, overflow_stack + OVERFLOW_STACK_SIZE, \tmp2 + adr_this_cpu \tmp1, kernel_exception_stack + KERNEL_EXC_STACK_SIZE, \tmp2 mov sp, \tmp1 msr spsel, #0 .endm diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index b2e778aae881..5aaeda5362f7 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -447,9 +447,10 @@ void __init smp_cpus_done(unsigned int max_cpus) mark_linear_text_alias_ro(); } =20 -static void __init update_boot_cpu_offset_and_overflow_stack(void) +static void __init update_boot_cpu_offset_and_exception_stack(void) { - u64 ovf_sp =3D (u64)raw_cpu_ptr(overflow_stack) + OVERFLOW_STACK_SIZE; + u64 exc_sp =3D (u64)raw_cpu_ptr(kernel_exception_stack) + + KERNEL_EXC_STACK_SIZE; =20 asm volatile( " msr tpidr_el1, %1\n" @@ -457,7 +458,7 @@ static void __init update_boot_cpu_offset_and_overflow_= stack(void) " msr spsel, #1\n" " mov sp, %0\n" /* Update the overflow stack pointer */ " msr spsel, #0" - : "+r" (ovf_sp) + : "+r" (exc_sp) : "r" (per_cpu_offset(0)) : "memory"); } @@ -469,7 +470,7 @@ void __init smp_prepare_boot_cpu(void) * setup_per_cpu_areas(), and CPU0's boot time per-cpu area will be * freed shortly, so we must move over to the runtime per-cpu area. */ - update_boot_cpu_offset_and_overflow_stack(); + update_boot_cpu_offset_and_exception_stack(); =20 cpuinfo_store_boot_cpu(); setup_boot_cpu_features(); diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 3ebcf8c53fb0..8e65b81c7502 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -337,7 +337,7 @@ kunwind_stack_walk(kunwind_consume_fn consume_state, struct stack_info stacks[] =3D { stackinfo_get_task(task), STACKINFO_CPU(irq), - STACKINFO_CPU(overflow), + STACKINFO_CPU(kernel_exception), #if defined(CONFIG_ARM_SDE_INTERFACE) STACKINFO_SDEI(normal), STACKINFO_SDEI(critical), diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 914282016069..ce0e213d772d 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -897,14 +897,14 @@ void bad_el0_sync(struct pt_regs *regs, int reason, u= nsigned long esr) "Bad EL0 synchronous exception"); } =20 -DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_= stack) - __aligned(16); +DEFINE_PER_CPU(unsigned long [KERNEL_EXC_STACK_SIZE/sizeof(long)], + kernel_exception_stack) __aligned(16); =20 void __noreturn panic_bad_stack(struct pt_regs *regs, unsigned long esr, u= nsigned long far) { unsigned long tsk_stk =3D (unsigned long)current->stack; unsigned long irq_stk =3D (unsigned long)this_cpu_read(irq_stack_ptr); - unsigned long ovf_stk =3D (unsigned long)this_cpu_ptr(overflow_stack); + unsigned long exc_stk =3D (unsigned long)this_cpu_ptr(kernel_exception_st= ack); =20 console_verbose(); pr_emerg("Insufficient stack space to handle exception!"); @@ -912,12 +912,12 @@ void __noreturn panic_bad_stack(struct pt_regs *regs,= unsigned long esr, unsigne pr_emerg("ESR: 0x%016lx -- %s\n", esr, esr_get_class_string(esr)); pr_emerg("FAR: 0x%016lx\n", far); =20 - pr_emerg("Task stack: [0x%016lx..0x%016lx]\n", + pr_emerg("Task stack: [0x%016lx..0x%016lx]\n", tsk_stk, tsk_stk + THREAD_SIZE); - pr_emerg("IRQ stack: [0x%016lx..0x%016lx]\n", + pr_emerg("IRQ stack: [0x%016lx..0x%016lx]\n", irq_stk, irq_stk + IRQ_STACK_SIZE); - pr_emerg("Overflow stack: [0x%016lx..0x%016lx]\n", - ovf_stk, ovf_stk + OVERFLOW_STACK_SIZE); + pr_emerg("Exception stack: [0x%016lx..0x%016lx]\n", + exc_stk, exc_stk + KERNEL_EXC_STACK_SIZE); =20 __show_regs(regs); =20 diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S index 9393fe3ea6a1..b05211a55074 100644 --- a/arch/arm64/kvm/hyp/nvhe/host.S +++ b/arch/arm64/kvm/hyp/nvhe/host.S @@ -205,7 +205,7 @@ SYM_FUNC_END(__host_hvc) =20 .L__hyp_sp_overflow\@: /* Switch to the overflow stack */ - adr_this_cpu sp, overflow_stack + OVERFLOW_STACK_SIZE, x0 + adr_this_cpu sp, overflow_stack + NVHE_OVERFLOW_STACK_SIZE, x0 =20 b hyp_panic_bad_stack ASM_BUG() diff --git a/arch/arm64/kvm/hyp/nvhe/stacktrace.c b/arch/arm64/kvm/hyp/nvhe= /stacktrace.c index 7c832d60d22b..92fe8b6d4de0 100644 --- a/arch/arm64/kvm/hyp/nvhe/stacktrace.c +++ b/arch/arm64/kvm/hyp/nvhe/stacktrace.c @@ -9,7 +9,7 @@ #include #include =20 -DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_= stack) +DEFINE_PER_CPU(unsigned long [NVHE_OVERFLOW_STACK_SIZE/sizeof(long)], over= flow_stack) __aligned(16); =20 DEFINE_PER_CPU(struct kvm_nvhe_stacktrace_info, kvm_stacktrace_info); @@ -42,7 +42,7 @@ DEFINE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof= (long)], pkvm_stacktrac static struct stack_info stackinfo_get_overflow(void) { unsigned long low =3D (unsigned long)this_cpu_ptr(overflow_stack); - unsigned long high =3D low + OVERFLOW_STACK_SIZE; + unsigned long high =3D low + NVHE_OVERFLOW_STACK_SIZE; =20 return (struct stack_info) { .low =3D low, diff --git a/arch/arm64/kvm/stacktrace.c b/arch/arm64/kvm/stacktrace.c index 9724c320126b..e5b878f959fc 100644 --- a/arch/arm64/kvm/stacktrace.c +++ b/arch/arm64/kvm/stacktrace.c @@ -27,7 +27,7 @@ static struct stack_info stackinfo_get_overflow(void) struct kvm_nvhe_stacktrace_info *stacktrace_info =3D this_cpu_ptr_nvhe_sym(kvm_stacktrace_info); unsigned long low =3D (unsigned long)stacktrace_info->overflow_stack_base; - unsigned long high =3D low + OVERFLOW_STACK_SIZE; + unsigned long high =3D low + NVHE_OVERFLOW_STACK_SIZE; =20 return (struct stack_info) { .low =3D low, @@ -38,7 +38,7 @@ static struct stack_info stackinfo_get_overflow(void) static struct stack_info stackinfo_get_overflow_kern_va(void) { unsigned long low =3D (unsigned long)this_cpu_ptr_nvhe_sym(overflow_stack= ); - unsigned long high =3D low + OVERFLOW_STACK_SIZE; + unsigned long high =3D low + NVHE_OVERFLOW_STACK_SIZE; =20 return (struct stack_info) { .low =3D low, --=20 2.55.0.979.g7e5102b832-goog