public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] arm64: panic from init_IRQ if IRQ handler stacks cannot be allocated
@ 2026-03-26 22:57 Osama Abdelkader
  2026-04-14 10:14 ` Osama Abdelkader
  0 siblings, 1 reply; 2+ messages in thread
From: Osama Abdelkader @ 2026-03-26 22:57 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Ard Biesheuvel, Ryo Takakura,
	Breno Leitao, Mark Rutland, Osama Abdelkader, linux-arm-kernel,
	linux-kernel

init_irq_stacks() and init_irq_scs() may fail when arch_alloc_vmap_stack
or scs_alloc return NULL. Return -ENOMEM from both and call panic() once
from init_IRQ(), covering per-CPU IRQ stacks and shadow IRQ stacks
consistently.

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
---
v2:
- Add return -ENOMEM from both init_irq_stacks() and init_irq_scs()
- Call panic() once from init_IRQ() if either init_irq_stacks() or
  init_irq_scs() returns -ENOMEM
---
 arch/arm64/kernel/irq.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/kernel/irq.c b/arch/arm64/kernel/irq.c
index 15dedb385b9e..9fafd826002b 100644
--- a/arch/arm64/kernel/irq.c
+++ b/arch/arm64/kernel/irq.c
@@ -10,6 +10,7 @@
  * Copyright (C) 2012 ARM Ltd.
  */
 
+#include <linux/errno.h>
 #include <linux/hardirq.h>
 #include <linux/init.h>
 #include <linux/irq.h>
@@ -32,34 +33,43 @@ DEFINE_PER_CPU(struct nmi_ctx, nmi_contexts);
 
 DEFINE_PER_CPU(unsigned long *, irq_stack_ptr);
 
-
 DECLARE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr);
 
 #ifdef CONFIG_SHADOW_CALL_STACK
 DEFINE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr);
 #endif
 
-static void init_irq_scs(void)
+static int __init init_irq_scs(void)
 {
 	int cpu;
+	void *s;
 
 	if (!scs_is_enabled())
-		return;
+		return 0;
+
+	for_each_possible_cpu(cpu) {
+		s = scs_alloc(early_cpu_to_node(cpu));
+		if (!s)
+			return -ENOMEM;
+		per_cpu(irq_shadow_call_stack_ptr, cpu) = s;
+	}
 
-	for_each_possible_cpu(cpu)
-		per_cpu(irq_shadow_call_stack_ptr, cpu) =
-			scs_alloc(early_cpu_to_node(cpu));
+	return 0;
 }
 
-static void __init init_irq_stacks(void)
+static int __init init_irq_stacks(void)
 {
 	int cpu;
 	unsigned long *p;
 
 	for_each_possible_cpu(cpu) {
 		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, early_cpu_to_node(cpu));
+		if (!p)
+			return -ENOMEM;
 		per_cpu(irq_stack_ptr, cpu) = p;
 	}
+
+	return 0;
 }
 
 #ifdef CONFIG_SOFTIRQ_ON_OWN_STACK
@@ -109,8 +119,9 @@ int __init set_handle_fiq(void (*handle_fiq)(struct pt_regs *))
 
 void __init init_IRQ(void)
 {
-	init_irq_stacks();
-	init_irq_scs();
+	if (init_irq_stacks() || init_irq_scs())
+		panic("Failed to allocate IRQ stack resources\n");
+
 	irqchip_init();
 
 	if (system_uses_irq_prio_masking()) {
-- 
2.43.0


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

* Re: [PATCH v2] arm64: panic from init_IRQ if IRQ handler stacks cannot be allocated
  2026-03-26 22:57 [PATCH v2] arm64: panic from init_IRQ if IRQ handler stacks cannot be allocated Osama Abdelkader
@ 2026-04-14 10:14 ` Osama Abdelkader
  0 siblings, 0 replies; 2+ messages in thread
From: Osama Abdelkader @ 2026-04-14 10:14 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Ard Biesheuvel, Ryo Takakura,
	Breno Leitao, Mark Rutland, linux-arm-kernel, linux-kernel

On Thu, Mar 26, 2026 at 11:57:52PM +0100, Osama Abdelkader wrote:
> init_irq_stacks() and init_irq_scs() may fail when arch_alloc_vmap_stack
> or scs_alloc return NULL. Return -ENOMEM from both and call panic() once
> from init_IRQ(), covering per-CPU IRQ stacks and shadow IRQ stacks
> consistently.
> 
> Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
> ---
> v2:
> - Add return -ENOMEM from both init_irq_stacks() and init_irq_scs()
> - Call panic() once from init_IRQ() if either init_irq_stacks() or
>   init_irq_scs() returns -ENOMEM
> ---
>  arch/arm64/kernel/irq.c | 29 ++++++++++++++++++++---------
>  1 file changed, 20 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm64/kernel/irq.c b/arch/arm64/kernel/irq.c
> index 15dedb385b9e..9fafd826002b 100644
> --- a/arch/arm64/kernel/irq.c
> +++ b/arch/arm64/kernel/irq.c
> @@ -10,6 +10,7 @@
>   * Copyright (C) 2012 ARM Ltd.
>   */
>  
> +#include <linux/errno.h>
>  #include <linux/hardirq.h>
>  #include <linux/init.h>
>  #include <linux/irq.h>
> @@ -32,34 +33,43 @@ DEFINE_PER_CPU(struct nmi_ctx, nmi_contexts);
>  
>  DEFINE_PER_CPU(unsigned long *, irq_stack_ptr);
>  
> -
>  DECLARE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr);
>  
>  #ifdef CONFIG_SHADOW_CALL_STACK
>  DEFINE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr);
>  #endif
>  
> -static void init_irq_scs(void)
> +static int __init init_irq_scs(void)
>  {
>  	int cpu;
> +	void *s;
>  
>  	if (!scs_is_enabled())
> -		return;
> +		return 0;
> +
> +	for_each_possible_cpu(cpu) {
> +		s = scs_alloc(early_cpu_to_node(cpu));
> +		if (!s)
> +			return -ENOMEM;
> +		per_cpu(irq_shadow_call_stack_ptr, cpu) = s;
> +	}
>  
> -	for_each_possible_cpu(cpu)
> -		per_cpu(irq_shadow_call_stack_ptr, cpu) =
> -			scs_alloc(early_cpu_to_node(cpu));
> +	return 0;
>  }
>  
> -static void __init init_irq_stacks(void)
> +static int __init init_irq_stacks(void)
>  {
>  	int cpu;
>  	unsigned long *p;
>  
>  	for_each_possible_cpu(cpu) {
>  		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, early_cpu_to_node(cpu));
> +		if (!p)
> +			return -ENOMEM;
>  		per_cpu(irq_stack_ptr, cpu) = p;
>  	}
> +
> +	return 0;
>  }
>  
>  #ifdef CONFIG_SOFTIRQ_ON_OWN_STACK
> @@ -109,8 +119,9 @@ int __init set_handle_fiq(void (*handle_fiq)(struct pt_regs *))
>  
>  void __init init_IRQ(void)
>  {
> -	init_irq_stacks();
> -	init_irq_scs();
> +	if (init_irq_stacks() || init_irq_scs())
> +		panic("Failed to allocate IRQ stack resources\n");
> +
>  	irqchip_init();
>  
>  	if (system_uses_irq_prio_masking()) {
> -- 
> 2.43.0
> 

Hi All,

Can you please review?

Best regards,
Osama

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

end of thread, other threads:[~2026-04-14 10:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26 22:57 [PATCH v2] arm64: panic from init_IRQ if IRQ handler stacks cannot be allocated Osama Abdelkader
2026-04-14 10:14 ` Osama Abdelkader

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox