linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64/kernel/entry: refine comment of stack overflow check
@ 2019-12-02 11:37 Heyi Guo
  2019-12-02 12:33 ` Mark Rutland
  2019-12-06 13:58 ` Catalin Marinas
  0 siblings, 2 replies; 4+ messages in thread
From: Heyi Guo @ 2019-12-02 11:37 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: Heyi Guo, wanghaibin.wang, Will Deacon, Catalin Marinas

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.

Signed-off-by: Heyi Guo <guoheyi@huawei.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 arch/arm64/kernel/entry.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index cf3bd2976e57..9e8ba507090f 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -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
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] arm64/kernel/entry: refine comment of stack overflow check
  2019-12-02 11:37 [PATCH] arm64/kernel/entry: refine comment of stack overflow check Heyi Guo
@ 2019-12-02 12:33 ` Mark Rutland
  2019-12-03  0:55   ` Guoheyi
  2019-12-06 13:58 ` Catalin Marinas
  1 sibling, 1 reply; 4+ messages in thread
From: Mark Rutland @ 2019-12-02 12:33 UTC (permalink / raw)
  To: Heyi Guo
  Cc: wanghaibin.wang, Will Deacon, linux-kernel, linux-arm-kernel,
	Catalin Marinas

On Mon, Dec 02, 2019 at 07:37:02PM +0800, Heyi Guo wrote:
> 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.

> 
> Fix the code comment to avoid confusion.
> 
> Signed-off-by: Heyi Guo <guoheyi@huawei.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> ---
>  arch/arm64/kernel/entry.S | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index cf3bd2976e57..9e8ba507090f 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -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:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

>  	add	sp, sp, x0			// sp' = sp + x0
>  	sub	x0, sp, x0			// x0' = sp' - x0 = (sp + x0) - x0 = sp
> -- 
> 2.19.1
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] arm64/kernel/entry: refine comment of stack overflow check
  2019-12-02 12:33 ` Mark Rutland
@ 2019-12-03  0:55   ` Guoheyi
  0 siblings, 0 replies; 4+ messages in thread
From: Guoheyi @ 2019-12-03  0:55 UTC (permalink / raw)
  To: Mark Rutland
  Cc: wanghaibin.wang, Will Deacon, linux-kernel, linux-arm-kernel,
	Catalin Marinas


在 2019/12/2 20:33, Mark Rutland 写道:
> On Mon, Dec 02, 2019 at 07:37:02PM +0800, Heyi Guo wrote:
>> 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.
>
>> Fix the code comment to avoid confusion.
>>
>> Signed-off-by: Heyi Guo <guoheyi@huawei.com>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will@kernel.org>
>> ---
>>   arch/arm64/kernel/entry.S | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
>> index cf3bd2976e57..9e8ba507090f 100644
>> --- a/arch/arm64/kernel/entry.S
>> +++ b/arch/arm64/kernel/entry.S
>> @@ -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.

Sure :)

Thanks,

Heyi

>
> With that wording:
>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
>
> Mark.
>
>>   	add	sp, sp, x0			// sp' = sp + x0
>>   	sub	x0, sp, x0			// x0' = sp' - x0 = (sp + x0) - x0 = sp
>> -- 
>> 2.19.1
>>
> .


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] arm64/kernel/entry: refine comment of stack overflow check
  2019-12-02 11:37 [PATCH] arm64/kernel/entry: refine comment of stack overflow check Heyi Guo
  2019-12-02 12:33 ` Mark Rutland
@ 2019-12-06 13:58 ` Catalin Marinas
  1 sibling, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2019-12-06 13:58 UTC (permalink / raw)
  To: Heyi Guo
  Cc: Mark Rutland, wanghaibin.wang, Will Deacon, linux-kernel,
	linux-arm-kernel

On Mon, Dec 02, 2019 at 07:37:02PM +0800, Heyi Guo wrote:
> 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.
> 
> Signed-off-by: Heyi Guo <guoheyi@huawei.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>

Queued with Mark's suggested update.

-- 
Catalin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-06 14:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-02 11:37 [PATCH] arm64/kernel/entry: refine comment of stack overflow check Heyi Guo
2019-12-02 12:33 ` Mark Rutland
2019-12-03  0:55   ` Guoheyi
2019-12-06 13:58 ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).