From nobody Mon Apr 27 07:26:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45D0FC433EF for ; Thu, 7 Jul 2022 14:23:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235452AbiGGOX2 (ORCPT ); Thu, 7 Jul 2022 10:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235267AbiGGOX0 (ORCPT ); Thu, 7 Jul 2022 10:23:26 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7FE821E1F for ; Thu, 7 Jul 2022 07:23:21 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4LdzCq6PM7z9tGf; Thu, 7 Jul 2022 16:23:19 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g8uEF7phv1fN; Thu, 7 Jul 2022 16:23:19 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4LdzCq5XRRz9tGb; Thu, 7 Jul 2022 16:23:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id AE4DF8B79F; Thu, 7 Jul 2022 16:23:19 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 3zsjNxXH00Jn; Thu, 7 Jul 2022 16:23:19 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.233.174]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 724EC8B768; Thu, 7 Jul 2022 16:23:19 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 267ENB1a537062 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 7 Jul 2022 16:23:11 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 267EN9WS537057; Thu, 7 Jul 2022 16:23:09 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2] powerpc: Merge hardirq stack and softirq stack Date: Thu, 7 Jul 2022 16:23:03 +0200 Message-Id: <6cd9d8bb2258d8b51999c2584eac74423d2b5e29.1657203774.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1657203782; l=4880; s=20211009; h=from:subject:message-id; bh=BlBLt+cQJWmMavBMTU04gXXdsfd8eXA2BvSu7Z4YQ1c=; b=suEKQCrDr+Ise3R6cNF3nFYCedGfHliqGLwzAscPZZPspWGG+pNOcDpSD1TSgusC5qBWEZjJ/Ebd rIUUMdAjAsD7w/fCuSMWKx1n1RnyHhBc/sOHJl/M48x7xznZEHTD X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" __do_IRQ() doesn't switch on hardirq stack if we are on softirq stack. do_softirq() bail out early without doing anything when already in an interrupt. invoke_softirq() is on task_stack when it calls do_softirq_own_stack(). So there are neither situation where we switch from hardirq stack to softirq stack nor from softirq stack to hardirq stack. It is therefore not necessary to have two stacks because they are never used at the same time. Merge both stacks into a new one called normirq_ctx. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/irq.h | 3 +-- arch/powerpc/kernel/irq.c | 18 +++++++----------- arch/powerpc/kernel/process.c | 6 +----- arch/powerpc/kernel/setup_32.c | 6 ++---- arch/powerpc/kernel/setup_64.c | 6 ++---- 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/arch/powerpc/include/asm/irq.h b/arch/powerpc/include/asm/irq.h index 5c1516a5ba8f..137909a6e0c1 100644 --- a/arch/powerpc/include/asm/irq.h +++ b/arch/powerpc/include/asm/irq.h @@ -49,8 +49,7 @@ extern void *mcheckirq_ctx[NR_CPUS]; /* * Per-cpu stacks for handling hard and soft interrupts. */ -extern void *hardirq_ctx[NR_CPUS]; -extern void *softirq_ctx[NR_CPUS]; +extern void *normirq_ctx[NR_CPUS]; =20 void __do_IRQ(struct pt_regs *regs); extern void __init init_IRQ(void); diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c index d50a18888bd9..0ac0e7ddf8ac 100644 --- a/arch/powerpc/kernel/irq.c +++ b/arch/powerpc/kernel/irq.c @@ -274,15 +274,14 @@ static __always_inline void call_do_irq(struct pt_reg= s *regs, void *sp) void __do_IRQ(struct pt_regs *regs) { struct pt_regs *old_regs =3D set_irq_regs(regs); - void *cursp, *irqsp, *sirqsp; + void *cursp, *irqsp; =20 /* Switch to the irq stack to handle this */ cursp =3D (void *)(current_stack_pointer & ~(THREAD_SIZE - 1)); - irqsp =3D hardirq_ctx[raw_smp_processor_id()]; - sirqsp =3D softirq_ctx[raw_smp_processor_id()]; + irqsp =3D normirq_ctx[raw_smp_processor_id()]; =20 /* Already there ? If not switch stack and call */ - if (unlikely(cursp =3D=3D irqsp || cursp =3D=3D sirqsp)) + if (unlikely(cursp =3D=3D irqsp)) __do_irq(regs, current_stack_pointer); else call_do_irq(regs, irqsp); @@ -305,10 +304,8 @@ static void __init vmap_irqstack_init(void) { int i; =20 - for_each_possible_cpu(i) { - softirq_ctx[i] =3D alloc_vm_stack(); - hardirq_ctx[i] =3D alloc_vm_stack(); - } + for_each_possible_cpu(i) + normirq_ctx[i] =3D alloc_vm_stack(); } =20 =20 @@ -330,12 +327,11 @@ void *dbgirq_ctx[NR_CPUS] __read_mostly; void *mcheckirq_ctx[NR_CPUS] __read_mostly; #endif =20 -void *softirq_ctx[NR_CPUS] __read_mostly; -void *hardirq_ctx[NR_CPUS] __read_mostly; +void *normirq_ctx[NR_CPUS] __read_mostly; =20 void do_softirq_own_stack(void) { - call_do_softirq(softirq_ctx[smp_processor_id()]); + call_do_softirq(normirq_ctx[smp_processor_id()]); } =20 irq_hw_number_t virq_to_hw(unsigned int virq) diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 0fbda89cd1bb..c17c974e5723 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -2089,11 +2089,7 @@ static inline int valid_irq_stack(unsigned long sp, = struct task_struct *p, unsigned long stack_page; unsigned long cpu =3D task_cpu(p); =20 - stack_page =3D (unsigned long)hardirq_ctx[cpu]; - if (sp >=3D stack_page && sp <=3D stack_page + THREAD_SIZE - nbytes) - return 1; - - stack_page =3D (unsigned long)softirq_ctx[cpu]; + stack_page =3D (unsigned long)normirq_ctx[cpu]; if (sp >=3D stack_page && sp <=3D stack_page + THREAD_SIZE - nbytes) return 1; =20 diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c index 813261789303..cad0e4fbdd4b 100644 --- a/arch/powerpc/kernel/setup_32.c +++ b/arch/powerpc/kernel/setup_32.c @@ -158,10 +158,8 @@ void __init irqstack_early_init(void) =20 /* interrupt stacks must be in lowmem, we get that for free on ppc32 * as the memblock is limited to lowmem by default */ - for_each_possible_cpu(i) { - softirq_ctx[i] =3D alloc_stack(); - hardirq_ctx[i] =3D alloc_stack(); - } + for_each_possible_cpu(i) + normirq_ctx[i] =3D alloc_stack(); } =20 #ifdef CONFIG_VMAP_STACK diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index 2b2d0b0fbb30..2fe727e01937 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -717,10 +717,8 @@ void __init irqstack_early_init(void) * cannot afford to take SLB misses on them. They are not * accessed in realmode. */ - for_each_possible_cpu(i) { - softirq_ctx[i] =3D alloc_stack(limit, i); - hardirq_ctx[i] =3D alloc_stack(limit, i); - } + for_each_possible_cpu(i) + normirq_ctx[i] =3D alloc_stack(limit, i); } =20 #ifdef CONFIG_PPC_BOOK3E --=20 2.36.1