From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19912279DC2 for ; Fri, 3 Apr 2026 14:27:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775226427; cv=none; b=CR1iGqwXamHgdtRH+Mgzty93v9GjIheNfsYiZJNzIVoRQ0codgJElv8RPsY3zoy8vDapKKHOkR5wU35Znz8NLSvEQmM0weJdxWY1oFUAe/+oVuPDZW2gTPS5ReGBG0Xu90wJoPDWF3++4wvzGJ6onVmBpdk2UZqPK0bFpqxuhbY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775226427; c=relaxed/simple; bh=vj+7faUo9ig2CQWYSc8sf+ZuZZunJlfwG4OSTwVxnyY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=a2Op1ztrJFG9eBqNjV+ajMOnBYHoAzreqZvOwusc6yULW7B9MkeffOlyIIYt/J5vH22bPk/VkLR9mCbnZ9Kn8YOmOsMqvVAUWC/OZBXSmZRyG6N8jSMeyhd+LLrlZZCPxHJMR4TnVsef+l5D/JmZ7akP356Rbbgpfc/g4+Ov7pQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RL2ClU7I; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RL2ClU7I" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-43d03db7f87so1083199f8f.3 for ; Fri, 03 Apr 2026 07:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775226424; x=1775831224; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=gumfKaSUZxmd7oNWXvA1epP8lqBwmQJ4csbA3kmi3dY=; b=RL2ClU7IOYw+KbzG821WSFoTPLox0A1ztQzvTaRnICBhl2rqw68dx8sj8yD0KuzyN7 le+qdBNBaHNgJ+7hmDsRxNCXniVw5q0GOBeq4SR/IB40KGBwQmCWxq0kAGQNfW6FeWQW JiKqrVU7iPRnHvyrj3Ad1vp+iuWAjem1cgafntaLPrpx1OZJrca95I6A8C6751p9gWsw pYHdDptpRg03a+18gOe0ooocygzNzNsBauEuhjV3CD6mdQuMOY/YB/aUTUQnVqSHSwbt O5UQyIbYcRVwE6LfnUuqZhGb75tH0/e/VZnNrtyP0nkLtl7VkGXYn8T+R0prwzv6SzkN NaHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775226424; x=1775831224; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gumfKaSUZxmd7oNWXvA1epP8lqBwmQJ4csbA3kmi3dY=; b=JopBShk46h28GXZRrKwHYu1Bm1OJ7kZd/Ju1tUhn9hs0TJR1h8klcALxYIqZ/IOd+D E5wJgApDyhU8CMaOKhF2y2xe4s8w41A/3SgZMQ4x0V27L1st9+XpjCBbLLmFV0sYLZTz F39fqEY4p+LmRQElgg01gS8j5L6zN4+I6VrYHzw5z2716n0+esPeY7+xemgZXIpLRF0B LwYYyvyeZoCqFTC/E3i13Gdk0P/OBUIFNf4bynRlCG0b1ixy8pnGYtuQAhjTC2qQtLL0 w95viXa58HkoY4rHEg9Ta2AGBQfdarVg/+SWJvFw1ierOzGIlVg4VNQLD0TJd4xvV74h jzFA== X-Forwarded-Encrypted: i=1; AJvYcCUaXTPm/cZD0gRfT7lZ2AAdDNu2UJ9gFSIs+6WtO2iYQWfJ8KQXAqgRget8rC6XJgDTSD1Mzfphck0Crcg=@vger.kernel.org X-Gm-Message-State: AOJu0YxRusM0h8xhOVlB4HDyFQ7H90diPtLAlNJS8/zy6eLH0CZ0W+xP 6DBJIbMmtU5eK5ELFyiNQlJVLy0I7JnBgDQ10CBvSdijV5F+7EHj70FQ X-Gm-Gg: AeBDieudzF1I4PF0t53+G7YyQQcQCif4Z08LG1l3MzRxm2rgN5Smzel9C0SvtGXz85R 5sP8GULWden+5mWKTwqeYpJLaJ+0JL7gyzM1+TtIgXbNyyCjIXI8F+jJzqB3bqxtvxpZyUSvf5h 9lKwbyRckfQEgxpJ5OfWTLkyrgwwDQp9ZW4BZCLuqppcYeICJEtyfr4kyWpVb6Dw6bV13UBNUKT FXTzMDeSlSCMnOTbXyj2i91fkWjDkx+eliBVrwtVMK/wbn6ma91gcfKlFK/+SMvaV3qNLKMongP oUWvWzqbs8fRQ/UrMVgbGuZ497Ja1DoNkEXHrVbj5sCVRbs6FhKCe19TnjSHrR9t8E9xcVdGry/ R++9lXqSuK4dDbhIch/vLCIvp/h8K+OcDKyci2czXpAo07nf5fNfTt1YzxICJwCi1knwpGrNvXW lBuHXDNg9Ed4yswfHa74kcRz5iXDG6U/P1nTYtVJ4Uv1DmDfCshB9zluo9tg== X-Received: by 2002:a5d:588c:0:b0:43d:1cec:4766 with SMTP id ffacd0b85a97d-43d292e3a26mr5254754f8f.23.1775226424063; Fri, 03 Apr 2026 07:27:04 -0700 (PDT) Received: from osama ([2a02:908:1b6:8980:a944:abe7:1177:5b7b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d1e2a6f5bsm15381498f8f.7.2026.04.03.07.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2026 07:27:03 -0700 (PDT) Date: Fri, 3 Apr 2026 16:27:01 +0200 From: Osama Abdelkader To: Paul Walmsley Cc: Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Thomas Gleixner , Vladimir Kondratiev , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] riscv: panic from init_IRQ if IRQ handler stacks cannot be allocated Message-ID: References: <20260326232335.60353-1-osama.abdelkader@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Hi Paul, On Thu, Apr 02, 2026 at 04:11:59PM -0600, Paul Walmsley wrote: > Hi, > > On Fri, 27 Mar 2026, 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 > > This patch appears to be written with AI assistance. If so, it should be > noted in the description. Please see > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-assistants.rst > This is actually riscv version of arm64 patch: [PATCH] arm64: panic if IRQ shadow call stack allocation fails https://lore.kernel.org/lkml/20260324161545.5441-1-osama.abdelkader@gmail.com/ where I initially used panic, but in review, returning -ENOMEM was suggested, and this patch also, so I submitted v2 there: [PATCH v2] arm64: panic from init_IRQ if IRQ handler stacks cannot be allocated https://lore.kernel.org/lkml/20260326225755.50297-1-osama.abdelkader@gmail.com/ > > --- > > arch/riscv/kernel/irq.c | 43 ++++++++++++++++++++++++++++++----------- > > 1 file changed, 32 insertions(+), 11 deletions(-) > > > > diff --git a/arch/riscv/kernel/irq.c b/arch/riscv/kernel/irq.c > > index b6af20bc300f..43392276f7f8 100644 > > --- a/arch/riscv/kernel/irq.c > > +++ b/arch/riscv/kernel/irq.c > > @@ -5,6 +5,7 @@ > > * Copyright (C) 2018 Christoph Hellwig > > */ > > > > +#include > > #include > > #include > > #include > > @@ -75,41 +76,53 @@ DECLARE_PER_CPU(ulong *, irq_shadow_call_stack_ptr); > > DEFINE_PER_CPU(ulong *, 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) > > - per_cpu(irq_shadow_call_stack_ptr, cpu) = > > - scs_alloc(cpu_to_node(cpu)); > > + for_each_possible_cpu(cpu) { > > + s = scs_alloc(cpu_to_node(cpu)); > > + if (!s) > > + return -ENOMEM; > > I don't see why this bothers to return an error value if the sole caller > is just going to panic. Best to panic here. Then no one reviewing this > patch needs to be concerned about memory leaks. > Okay, I'm going to use panic in place instead. > > + per_cpu(irq_shadow_call_stack_ptr, cpu) = s; > > + } > > + > > + return 0; > > } > > > > DEFINE_PER_CPU(ulong *, irq_stack_ptr); > > > > #ifdef CONFIG_VMAP_STACK > > -static void init_irq_stacks(void) > > +static int __init init_irq_stacks(void) > > { > > int cpu; > > ulong *p; > > > > for_each_possible_cpu(cpu) { > > p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, cpu_to_node(cpu)); > > + if (!p) > > + return -ENOMEM; > > Same comment as the above. > > > per_cpu(irq_stack_ptr, cpu) = p; > > } > > + > > + return 0; > > } > > #else > > /* irq stack only needs to be 16 byte aligned - not IRQ_STACK_SIZE aligned. */ > > DEFINE_PER_CPU_ALIGNED(ulong [IRQ_STACK_SIZE/sizeof(ulong)], irq_stack); > > > > -static void init_irq_stacks(void) > > +static int __init init_irq_stacks(void) > > { > > int cpu; > > > > for_each_possible_cpu(cpu) > > per_cpu(irq_stack_ptr, cpu) = per_cpu(irq_stack, cpu); > > + > > + return 0; > > Why? > > > } > > #endif /* CONFIG_VMAP_STACK */ > > > > @@ -129,8 +142,15 @@ void do_softirq_own_stack(void) > > #endif /* CONFIG_SOFTIRQ_ON_OWN_STACK */ > > > > #else > > -static void init_irq_scs(void) {} > > -static void init_irq_stacks(void) {} > > +static int __init init_irq_scs(void) > > +{ > > + return 0; > > +} > > + > > +static int __init init_irq_stacks(void) > > +{ > > + return 0; > > +} > > #endif /* CONFIG_IRQ_STACKS */ > > > > int arch_show_interrupts(struct seq_file *p, int prec) > > @@ -141,8 +161,9 @@ int arch_show_interrupts(struct seq_file *p, int prec) > > > > void __init init_IRQ(void) > > { > > - init_irq_scs(); > > - init_irq_stacks(); > > + if (init_irq_stacks() || init_irq_scs()) > > + panic("Failed to allocate IRQ stack resources\n"); > > Any reason why the initialization order is reversed? > It's a mistake, will reverse it back. Thanks, Osama > > + > > irqchip_init(); > > if (!handle_arch_irq) > > panic("No interrupt controller found."); > > -- > > 2.43.0 > > > - Paul