Skip to contentSkip to conversation

arm64/kernel/entry: refine comment of stack overflow check

PATCH In review Heyi Guo 3 participants 4 messages Dec 2, 2019 – Dec 6, 2019 arm64

lore
Share & tools
lore

Heyi Guo

author
#0 lore raw

PATCH 1/1 arm64/kernel/entry: refine comment of stack overflow check

Stack overflow checking can be done by testing
sp & (1 << THREAD_SHIFT)
only for the stacks are aligned to (2 << THREAD_SHIFT) with size of (1 << THREAD_SIZE), and this is the case when CONFIG_VMAP_STACK is set.

Fix the code comment to avoid confusion.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/kernel/entry.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/entry.S +2 -1
index cf3bd2976e57..9e8ba507090f 100644
@@ -76,7 +76,8 @@ alternative_else_nop_endif
 #ifdef CONFIG_VMAP_STACK
 	/*
 	 * Test whether the SP has overflowed, without corrupting a GPR.
-	 * Task and IRQ stacks are aligned to (1 << THREAD_SHIFT).
+	 * Task and IRQ stacks are aligned to (2 << THREAD_SHIFT) with size of
+	 * (1 << THREAD_SHIFT).
 	 */
 	add	sp, sp, x0			// sp' = sp + x0
 	sub	x0, sp, x0			// x0' = sp' - x0 = (sp + x0) - x0 = sp
Signature · 1 line
2.19.1
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Heyi Guo

Stack overflow checking can be done by testing
sp & (1 << THREAD_SHIFT)
only for the stacks are aligned to (2 << THREAD_SHIFT) with size of (1 << THREAD_SIZE), and this is the case when CONFIG_VMAP_STACK is set.

Good point, I was sloppy with this comment.

Quoted 15 lines

Fix the code comment to avoid confusion.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/kernel/entry.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/entry.S +0 -0
index cf3bd2976e57..9e8ba507090f 100644

arch/arm64/kernel/entry.S alternative_else_nop_endif · line 81

Quoted 7 lines
arch/arm64/kernel/entry.S +2 -1
@@ -76,7 +76,8 @@ alternative_else_nop_endif
 #ifdef CONFIG_VMAP_STACK
 	/*
 	 * Test whether the SP has overflowed, without corrupting a GPR.
-	 * Task and IRQ stacks are aligned to (1 << THREAD_SHIFT).
+	 * Task and IRQ stacks are aligned to (2 << THREAD_SHIFT) with size of
+	 * (1 << THREAD_SHIFT).
 	 */

Can we make that:

Task and IRQ stacks are aligned so that SP & (1 << THREAD_SHIFT) should always be zero.

... which I think is a bit clearer.

With that wording:

Mark.

Quoted 5 lines
arch/arm64/kernel/entry.S +0 -0
 	add	sp, sp, x0			// sp' = sp + x0
 	sub	x0, sp, x0			// x0' = sp' - x0 = (sp + x0) - x0 = sp
Signature · 1 line
2.19.1
author
#2 lore raw
Quoted 31 lines · Mark Rutland
Quoted 5 lines · Heyi Guo

Stack overflow checking can be done by testing
sp & (1 << THREAD_SHIFT)
only for the stacks are aligned to (2 << THREAD_SHIFT) with size of (1 << THREAD_SIZE), and this is the case when CONFIG_VMAP_STACK is set.

Good point, I was sloppy with this comment.

Quoted 14 lines

Fix the code comment to avoid confusion.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
  arch/arm64/kernel/entry.S | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/entry.S +0 -0
index cf3bd2976e57..9e8ba507090f 100644

arch/arm64/kernel/entry.S alternative_else_nop_endif · line 81

Quoted 7 lines
arch/arm64/kernel/entry.S +2 -1
@@ -76,7 +76,8 @@ alternative_else_nop_endif
  #ifdef CONFIG_VMAP_STACK
  	/*
  	 * Test whether the SP has overflowed, without corrupting a GPR.
-	 * Task and IRQ stacks are aligned to (1 << THREAD_SHIFT).
+	 * Task and IRQ stacks are aligned to (2 << THREAD_SHIFT) with size of
+	 * (1 << THREAD_SHIFT).
  	 */

Can we make that:

Quoted 4 lines

Task and IRQ stacks are aligned so that SP & (1 << THREAD_SHIFT) should always be zero.

... which I think is a bit clearer.

Sure :)

Thanks,

Heyi

Quoted 13 lines

With that wording:

Mark.

Quoted 5 lines
arch/arm64/kernel/entry.S +0 -0
  	add	sp, sp, x0			// sp' = sp + x0
  	sub	x0, sp, x0			// x0' = sp' - x0 = (sp + x0) - x0 = sp
Signature · 1 line
2.19.1

.

maintainer
#3 lore raw
In reply to Heyi Guo
Quoted 11 lines · Heyi Guo

Stack overflow checking can be done by testing
sp & (1 << THREAD_SHIFT)
only for the stacks are aligned to (2 << THREAD_SHIFT) with size of (1 << THREAD_SIZE), and this is the case when CONFIG_VMAP_STACK is set.

Fix the code comment to avoid confusion.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>

Queued with Mark's suggested update.

Signature · 1 line
Catalin