Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6536249ybl; Mon, 23 Dec 2019 07:27:28 -0800 (PST) X-Google-Smtp-Source: APXvYqy0Q+Y0zKP6KkHrU0jZkJvGlFgU85mczfmBc4gYOP6Axr4UzreduolIWQMX9xwhu8WE4i3F X-Received: by 2002:a05:6830:1607:: with SMTP id g7mr33244388otr.320.1577114848781; Mon, 23 Dec 2019 07:27:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577114848; cv=none; d=google.com; s=arc-20160816; b=eWjYpm7lhyUiLtCinjnT8QH9XFP9iuxELOoJAwTRG2iQpKWrJPmo5hW7Y1DNmt5oTI XwrlGUsOIHgKsB89Z4AflgIJckmcHkfoCO3n8mPifgCrs1/X0AxhNBfs96tF5zJOqcbx a2JwCEC7PWmmP4oPBwIMHP0NdZOpvys2d56CnNTdTqRe7POjLCSKfCaBBo34JPfROj8g O+zxjUzWstxLFeP9JoVN+4Df3CAxLiriP5sUZ1kBSuDzRPPXg04vT5pUtSDB253+b059 j0wgk8kQgB/w6hFwVYV+s27HSnALgrDH1/fnNUM6NuHDniZFCGeRUDN2jVEaPUxC+ZD4 757Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:dkim-signature; bh=CGg5lFjG79+f3AndFF6HVcEwxv4O9U6o4GFVGWYCcUM=; b=mMm/GjKzrsi9sRpJxxP8ZWQ6icZqXzcfoUU+bW+mb7lgo+pvh3eoZZ5nUuLpjRW+4M Jo/x4NlG0h/yiRtop3iVUvf7H4nItrD3+z4y9xEVWrHqvk+lhE02bve8WbBmWhjUJAQZ tJqkPkBPNIBhEC9/66RzWV4HLN18EVwbRO1Hhr/w6LvFIf4pxnmMeue7+6RVvzLCueq9 XYULYBD/889ZHGAYJ5xmuIBd0wH/5Tb0AIRrq1oggDViTpLjnVDtlDMdyK/9sDT6yE6f X2cX2WcIAU0+f7QL8EdcIgUhlGVp3SGuCHDe4e/OsCR5NhV2BDWOk/Dt1D6b8e7MBmEc fE3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=TpqudzOM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1si10290745otp.70.2019.12.23.07.27.15; Mon, 23 Dec 2019 07:27:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=TpqudzOM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727130AbfLWP0W (ORCPT + 99 others); Mon, 23 Dec 2019 10:26:22 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:4385 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbfLWP0U (ORCPT ); Mon, 23 Dec 2019 10:26:20 -0500 Received: from localhost (mailhub1-ext [192.168.12.233]) by localhost (Postfix) with ESMTP id 47hNVF12djz9vJyy; Mon, 23 Dec 2019 16:26:13 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=TpqudzOM; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id zIN-liUu8jfd; Mon, 23 Dec 2019 16:26:13 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 47hNVD6zPtz9vJyw; Mon, 23 Dec 2019 16:26:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1577114773; bh=CGg5lFjG79+f3AndFF6HVcEwxv4O9U6o4GFVGWYCcUM=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=TpqudzOMTrzBq6NdKEoT6ie4xE8cDofbv/TXPN8mm3jpmcvS9HGZ9rmIJDf8H2qn4 AlcfawkPHFYVGYFzJ0lHOyy94MW4kWjGWoHlrl2TsuNML9KyNvCGtrA0bg+DrYFqkE reBWPEeuMk/xDhJf2lp/RErt9oRP4/+nb9DD/jzE= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2120E8B7D1; Mon, 23 Dec 2019 16:26:18 +0100 (CET) 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 vWNFPbebVhiN; Mon, 23 Dec 2019 16:26:18 +0100 (CET) Received: from po16098vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.100]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EFBDF8B7A1; Mon, 23 Dec 2019 16:26:17 +0100 (CET) Received: by po16098vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 05519637D8; Mon, 23 Dec 2019 15:26:17 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [RFC PATCH 7/8] powerpc/32: use IRQ stack immediately on IRQ exception To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Mon, 23 Dec 2019 15:26:17 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Exception entries run of kernel thread stack, then do_IRQ() switches to the IRQ stack. Instead of doing a first step of the thread stack, increasing the risk of stack overflow and spending time switch stacks two times when coming from userspace, set the stack to IRQ stack immediately in the EXCEPTION entry. In the same way as ARM64, consider that when the stack pointer is not within the kernel thread stack, it means it is already on IRQ stack. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/head_32.S | 2 +- arch/powerpc/kernel/head_32.h | 32 +++++++++++++++++++++++++++++--- arch/powerpc/kernel/head_40x.S | 2 +- arch/powerpc/kernel/head_8xx.S | 2 +- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S index 4a24f8f026c7..0c36fba5b861 100644 --- a/arch/powerpc/kernel/head_32.S +++ b/arch/powerpc/kernel/head_32.S @@ -332,7 +332,7 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE) EXC_XFER_LITE(0x400, handle_page_fault) /* External interrupt */ - EXCEPTION(0x500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE) + EXCEPTION_IRQ(0x500, HardwareInterrupt, __do_irq, EXC_XFER_LITE) /* Alignment exception */ . = 0x600 diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h index 8abc7783dbe5..f9e77e51723e 100644 --- a/arch/powerpc/kernel/head_32.h +++ b/arch/powerpc/kernel/head_32.h @@ -11,21 +11,41 @@ * task's thread_struct. */ -.macro EXCEPTION_PROLOG +.macro EXCEPTION_PROLOG is_irq=0 mtspr SPRN_SPRG_SCRATCH0,r10 mtspr SPRN_SPRG_SCRATCH1,r11 mfcr r10 - EXCEPTION_PROLOG_1 + EXCEPTION_PROLOG_1 is_irq=\is_irq EXCEPTION_PROLOG_2 .endm -.macro EXCEPTION_PROLOG_1 +.macro EXCEPTION_PROLOG_1 is_irq=0 mfspr r11,SPRN_SRR1 /* check whether user or kernel */ andi. r11,r11,MSR_PR + .if \is_irq + bne 2f + mfspr r11, SPRN_SPRG_THREAD + lwz r11, TASK_STACK - THREAD(r11) + xor r11, r11, r1 + cmplwi cr7, r11, THREAD_SIZE - 1 + tophys(r11, r1) /* use tophys(r1) if not thread stack */ + bgt cr7, 1f +2: +#ifdef CONFIG_SMP + mfspr r11, SPRN_SPRG_THREAD + lwz r11, TASK_CPU - THREAD(r11) + slwi r11, r11, 3 + addis r11, r11, (hardirq_ctx - PAGE_OFFSET)@ha +#else + lis r11, (hardirq_ctx - PAGE_OFFSET)@ha +#endif + lwz r11, (hardirq_ctx - PAGE_OFFSET)@l(r11) + .else tophys(r11,r1) /* use tophys(r1) if kernel */ beq 1f mfspr r11,SPRN_SPRG_THREAD lwz r11,TASK_STACK-THREAD(r11) + .endif addi r11,r11,THREAD_SIZE tophys(r11,r11) 1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */ @@ -171,6 +191,12 @@ addi r3,r1,STACK_FRAME_OVERHEAD; \ xfer(n, hdlr) +#define EXCEPTION_IRQ(n, label, hdlr, xfer) \ + START_EXCEPTION(n, label) \ + EXCEPTION_PROLOG is_irq=1; \ + addi r3,r1,STACK_FRAME_OVERHEAD; \ + xfer(n, hdlr) + #define EXC_XFER_TEMPLATE(hdlr, trap, msr, tfer, ret) \ li r10,trap; \ stw r10,_TRAP(r11); \ diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S index 4511fc1549f7..dd236f596c0b 100644 --- a/arch/powerpc/kernel/head_40x.S +++ b/arch/powerpc/kernel/head_40x.S @@ -315,7 +315,7 @@ _ENTRY(crit_srr1) EXC_XFER_LITE(0x400, handle_page_fault) /* 0x0500 - External Interrupt Exception */ - EXCEPTION(0x0500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE) + EXCEPTION_IRQ(0x0500, HardwareInterrupt, __do_irq, EXC_XFER_LITE) /* 0x0600 - Alignment Exception */ START_EXCEPTION(0x0600, Alignment) diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S index 19f583e18402..5a6cdbc89e26 100644 --- a/arch/powerpc/kernel/head_8xx.S +++ b/arch/powerpc/kernel/head_8xx.S @@ -150,7 +150,7 @@ DataAccess: InstructionAccess: /* External interrupt */ - EXCEPTION(0x500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE) + EXCEPTION_IRQ(0x500, HardwareInterrupt, __do_irq, EXC_XFER_LITE) /* Alignment exception */ . = 0x600 -- 2.13.3