From: Kalesh Singh <kaleshsingh@google.com>
Cc: kernel-team@android.com,
Catalin Marinas <catalin.marinas@arm.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
will@kernel.org, Peter Collingbourne <pcc@google.com>,
maz@kernel.org, linux-kernel@vger.kernel.org,
Joey Gouly <joey.gouly@arm.com>,
kvmarm@lists.cs.columbia.edu, Andrew Walbran <qwandor@google.com>,
Kalesh Singh <kaleshsingh@google.com>,
surenb@google.com, linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/7] arm64: asm: Introduce test_sp_overflow macro
Date: Thu, 10 Feb 2022 14:41:44 -0800 [thread overview]
Message-ID: <20220210224220.4076151-4-kaleshsingh@google.com> (raw)
In-Reply-To: <20220210224220.4076151-1-kaleshsingh@google.com>
From: Quentin Perret <qperret@google.com>
The asm entry code in the kernel uses a trick to check if VMAP'd stacks
have overflowed by aligning them at THREAD_SHIFT * 2 granularity and
checking the SP's THREAD_SHIFT bit.
Protected KVM will soon make use of a similar trick to detect stack
overflows, so factor out the asm code in a re-usable macro.
Signed-off-by: Quentin Perret <qperret@google.com>
[Kalesh - Resolve minor conflicts]
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
arch/arm64/include/asm/assembler.h | 11 +++++++++++
arch/arm64/kernel/entry.S | 9 ++-------
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
index e8bd0af0141c..ad40eb0eee83 100644
--- a/arch/arm64/include/asm/assembler.h
+++ b/arch/arm64/include/asm/assembler.h
@@ -850,4 +850,15 @@ alternative_endif
#endif /* GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT */
+/*
+ * Test whether the SP has overflowed, without corrupting a GPR.
+ */
+.macro test_sp_overflow shift, label
+ add sp, sp, x0 // sp' = sp + x0
+ sub x0, sp, x0 // x0' = sp' - x0 = (sp + x0) - x0 = sp
+ tbnz x0, #\shift, \label
+ sub x0, sp, x0 // x0'' = sp' - x0' = (sp + x0) - sp = x0
+ sub sp, sp, x0 // sp'' = sp' - x0 = (sp + x0) - x0 = sp
+.endm
+
#endif /* __ASM_ASSEMBLER_H */
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index 772ec2ecf488..2632bc47b348 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -53,16 +53,11 @@ alternative_else_nop_endif
sub sp, sp, #PT_REGS_SIZE
#ifdef CONFIG_VMAP_STACK
/*
- * Test whether the SP has overflowed, without corrupting a GPR.
* Task and IRQ stacks are aligned so that SP & (1 << THREAD_SHIFT)
* should always be zero.
*/
- add sp, sp, x0 // sp' = sp + x0
- sub x0, sp, x0 // x0' = sp' - x0 = (sp + x0) - x0 = sp
- tbnz x0, #THREAD_SHIFT, 0f
- sub x0, sp, x0 // x0'' = sp' - x0' = (sp + x0) - sp = x0
- sub sp, sp, x0 // sp'' = sp' - x0 = (sp + x0) - x0 = sp
- b el\el\ht\()_\regsize\()_\label
+ test_sp_overflow THREAD_SHIFT, 0f
+ b el\el\ht\()_\regsize\()_\label
0:
/*
--
2.35.1.265.g69c8d7142f-goog
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
next prev parent reply other threads:[~2022-02-11 9:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-10 22:41 [PATCH 0/7] KVM: arm64: Hypervisor stack enhancements Kalesh Singh
2022-02-10 22:41 ` [PATCH 1/7] KVM: arm64: Map the stack pages in the 'private' range Kalesh Singh
2022-02-10 22:41 ` [PATCH 2/7] KVM: arm64: Factor out private range VA allocation Kalesh Singh
2022-02-10 22:41 ` Kalesh Singh [this message]
2022-02-10 22:41 ` [PATCH 4/7] KVM: arm64: Allocate guard pages near hyp stacks Kalesh Singh
2022-02-14 14:06 ` Marc Zyngier
2022-02-14 22:03 ` Kalesh Singh
2022-02-10 22:41 ` [PATCH 5/7] KVM: arm64: Add Hyp overflow stack Kalesh Singh
2022-02-10 22:41 ` [PATCH 6/7] KVM: arm64: Unwind and dump nVHE HYP stacktrace Kalesh Singh
2022-02-10 22:41 ` [PATCH 7/7] KVM: arm64: Symbolize the nVHE HYP backtrace Kalesh Singh
2022-02-14 11:41 ` [PATCH 0/7] KVM: arm64: Hypervisor stack enhancements Marc Zyngier
2022-02-14 21:54 ` Kalesh Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220210224220.4076151-4-kaleshsingh@google.com \
--to=kaleshsingh@google.com \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--cc=kernel-team@android.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=pasha.tatashin@soleen.com \
--cc=pcc@google.com \
--cc=qwandor@google.com \
--cc=surenb@google.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox