[PATCH -next V12 1/3] riscv: stack: Support HAVE_IRQ_EXIT_ON_IRQ_STACK

Clément Léger cleger at rivosinc.com
Tue Jun 13 06:01:07 PDT 2023



On 29/05/2023 10:45, guoren at kernel.org wrote:
> From: Guo Ren <guoren at linux.alibaba.com>
> 
> Add independent irq stacks for percpu to prevent kernel stack overflows.
> It is also compatible with VMAP_STACK by arch_alloc_vmap_stack.
> 
> Tested-by: Jisheng Zhang <jszhang at kernel.org>
> Signed-off-by: Guo Ren <guoren at linux.alibaba.com>
> Signed-off-by: Guo Ren <guoren at kernel.org>
> Cc: Conor Dooley <conor.dooley at microchip.com>
> ---
>   arch/riscv/Kconfig                   |  7 ++++++
>   arch/riscv/include/asm/irq_stack.h   | 32 +++++++++++++++++++++++++
>   arch/riscv/include/asm/thread_info.h |  2 ++
>   arch/riscv/kernel/irq.c              | 33 ++++++++++++++++++++++++++
>   arch/riscv/kernel/traps.c            | 35 ++++++++++++++++++++++++++--
>   5 files changed, 107 insertions(+), 2 deletions(-)
>   create mode 100644 arch/riscv/include/asm/irq_stack.h
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index fa256f2e23c1..44b4c9690f94 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -588,6 +588,13 @@ config FPU
>   
>   	  If you don't know what to do here, say Y.
>   
> +config IRQ_STACKS
> +	bool "Independent irq stacks" if EXPERT
> +	default y
> +	select HAVE_IRQ_EXIT_ON_IRQ_STACK
> +	help
> +	  Add independent irq stacks for percpu to prevent kernel stack overflows.
> +
>   endmenu # "Platform type"
>   
>   menu "Kernel features"
> diff --git a/arch/riscv/include/asm/irq_stack.h b/arch/riscv/include/asm/irq_stack.h
> new file mode 100644
> index 000000000000..b0dcee9a3fa2
> --- /dev/null
> +++ b/arch/riscv/include/asm/irq_stack.h
> @@ -0,0 +1,32 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef _ASM_RISCV_IRQ_STACK_H
> +#define _ASM_RISCV_IRQ_STACK_H
> +
> +#include <linux/bug.h>
> +#include <linux/gfp.h>
> +#include <linux/kconfig.h>
> +#include <linux/vmalloc.h>
> +#include <linux/pgtable.h>
> +#include <asm/thread_info.h>
> +
> +DECLARE_PER_CPU(ulong *, irq_stack_ptr);
> +
> +#ifdef CONFIG_VMAP_STACK
> +/*
> + * To ensure that VMAP'd stack overflow detection works correctly, all VMAP'd
> + * stacks need to have the same alignment.
> + */
> +static inline unsigned long *arch_alloc_vmap_stack(size_t stack_size, int node)
> +{
> +	void *p;
> +
> +	BUILD_BUG_ON(!IS_ENABLED(CONFIG_VMAP_STACK));

Hi Guo,

Since this function is already guarded with #ifdef CONFIG_VMAP_STACK, I 
guess this BUILD_BUG_ON() is unnecessary).

Clément



More information about the linux-riscv mailing list