From: Maninder Singh <maninder1.s@samsung.com>
To: linux@armlinux.org.uk, ndesaulniers@google.com,
caij2003@gmail.com, tglx@linutronix.de, bigeasy@linutronix.de,
maz@kernel.org, valentin.schneider@arm.com,
vincent.whitchurch@axis.com, nhuck@google.com,
akpm@linux-foundation.org, 0x7f454c46@gmail.com, will@kernel.org
Cc: a.sahrawat@samsung.com, v.narang@samsung.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Maninder Singh <maninder1.s@samsung.com>
Subject: [PATCH 2/3] arm: introduce IRQ stacks
Date: Thu, 8 Oct 2020 12:45:32 +0530 [thread overview]
Message-ID: <1602141333-17822-3-git-send-email-maninder1.s@samsung.com> (raw)
In-Reply-To: <1602141333-17822-1-git-send-email-maninder1.s@samsung.com>
This patch adds code for switching to IRQ stack.
IRQ stack and Kernel SVC stack have below design.
IRQ STACK:-
------------ IRQ stack top
| |
------------
. .
. .
. .
------------
| sp | <- irq_stack_base + 0x8
------------
| fp | <- irq_stack_base + 0x4
------------
|tinfo_ptr | /* pointer to thread info */
irq_stack_ptr --> ------------ IRQ stack base
Kernel SVC stack:-
------------ Kernel stack top
| |
------------
. .
. .
. .
------------
| |
| |
------------
|tinfo_ptr | /* pointer to thread info */
------------ Kernel stack base
Co-developed-by: Vaneet Narang <v.narang@samsung.com>
Signed-off-by: Vaneet Narang <v.narang@samsung.com>
Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
---
arch/arm/include/asm/assembler.h | 8 ++++++++
arch/arm/include/asm/irq.h | 6 ++++++
arch/arm/kernel/entry-armv.S | 41 +++++++++++++++++++++++++++++++++++++++-
arch/arm/kernel/irq.c | 24 +++++++++++++++++++++++
4 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 8512bdc..82ee6ee 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -212,6 +212,14 @@
#endif
.endm
+ .macro this_cpu_ptr, sym, reg, tmp
+ ldr \reg, =\sym
+#if defined(CONFIG_SMP) && !defined(CONFIG_CPU_V6)
+ mrc p15, 0, \tmp, cr13, c0, 4
+ add \reg, \reg, \tmp
+#endif
+ .endm
+
/*
* Increment/decrement the preempt count.
*/
diff --git a/arch/arm/include/asm/irq.h b/arch/arm/include/asm/irq.h
index 46d4114..f3299ab 100644
--- a/arch/arm/include/asm/irq.h
+++ b/arch/arm/include/asm/irq.h
@@ -22,10 +22,16 @@
#define NO_IRQ ((unsigned int)(-1))
#endif
+#define IRQ_STACK_SIZE THREAD_SIZE
+
#ifndef __ASSEMBLY__
struct irqaction;
struct pt_regs;
+#ifdef CONFIG_IRQ_STACK
+DECLARE_PER_CPU(unsigned long *, irq_stack_ptr);
+#endif
+
extern void asm_do_IRQ(unsigned int, struct pt_regs *);
void handle_IRQ(unsigned int, struct pt_regs *);
void init_IRQ(void);
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index 55a47df..13a5889 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -32,6 +32,43 @@
#include "entry-header.S"
#include <asm/entry-macro-multi.S>
#include <asm/probes.h>
+#ifdef CONFIG_IRQ_STACK
+#include <asm/irq.h>
+#endif
+
+ .macro irq_stack_entry
+#ifdef CONFIG_IRQ_STACK
+ mov r6, sp /* preserve sp */
+
+ this_cpu_ptr irq_stack_ptr, r7, r8
+ ldr r7, [r7]
+ mov r8, r7
+
+ /*
+ * Compare sp with base of IRQ stack.
+ * if the top ~(#THREAD_SIZE_ORDER + PAGE_SHIFT) bits match,
+ * we are on a irq stack.
+ */
+ eor r8, r8, sp
+ lsrs r8, #THREAD_SIZE_ORDER + PAGE_SHIFT
+ beq 9998f
+
+ /*
+ * store thread info pointer on IRQ stack and
+ * switch to the irq stack.
+ */
+ get_thread_info r8
+ stm r7, {r8, fp, sp}
+ add sp, r7, #IRQ_STACK_SIZE
+9998:
+#endif
+ .endm
+
+ .macro irq_stack_exit
+#ifdef CONFIG_IRQ_STACK
+ mov sp, r6 /* restore sp */
+#endif
+ .endm
/*
* Interrupt handling.
@@ -41,11 +78,13 @@
ldr r1, =handle_arch_irq
mov r0, sp
badr lr, 9997f
+ irq_stack_entry
ldr pc, [r1]
+9997:
+ irq_stack_exit
#else
arch_irq_handler_default
#endif
-9997:
.endm
.macro pabt_helper
diff --git a/arch/arm/kernel/irq.c b/arch/arm/kernel/irq.c
index 698b6f6..79872e5 100644
--- a/arch/arm/kernel/irq.c
+++ b/arch/arm/kernel/irq.c
@@ -43,6 +43,15 @@
unsigned long irq_err_count;
+#ifdef CONFIG_IRQ_STACK
+DEFINE_PER_CPU(unsigned long *, irq_stack_ptr);
+
+/*
+ * irq_stack must be IRQ_STACK_SIZE(THREAD_SIZE) aligned,
+ */
+DEFINE_PER_CPU(unsigned long [IRQ_STACK_SIZE/sizeof(long)], irq_stack) __aligned(IRQ_STACK_SIZE);
+#endif
+
int arch_show_interrupts(struct seq_file *p, int prec)
{
#ifdef CONFIG_FIQ
@@ -55,6 +64,20 @@ int arch_show_interrupts(struct seq_file *p, int prec)
return 0;
}
+#ifdef CONFIG_IRQ_STACK
+static void init_irq_stacks(void)
+{
+ int cpu;
+
+ for_each_possible_cpu(cpu)
+ per_cpu(irq_stack_ptr, cpu) = per_cpu(irq_stack, cpu);
+}
+#else
+static inline void init_irq_stacks(void)
+{
+}
+#endif
+
/*
* handle_IRQ handles all hardware IRQ's. Decoded IRQs should
* not come via this function. Instead, they should provide their
@@ -79,6 +102,7 @@ void __init init_IRQ(void)
{
int ret;
+ init_irq_stacks();
if (IS_ENABLED(CONFIG_OF) && !machine_desc->init_irq)
irqchip_init();
else
--
1.9.1
next prev parent reply other threads:[~2020-10-08 7:17 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20201008071628epcas5p24d196a6023a47a3b0bfa7b7f231ec811@epcas5p2.samsung.com>
2020-10-08 7:15 ` [PATCH 0/3] IRQ stack support for ARM Maninder Singh
[not found] ` <CGME20201008071633epcas5p20f5c533ac67ab235997e7e4a8ad3022b@epcas5p2.samsung.com>
2020-10-08 7:15 ` [PATCH 1/3] arm: introduce self pointer in thread info Maninder Singh
[not found] ` <CGME20201008071639epcas5p465f13d992a25936ba63436baf1fb6f83@epcas5p4.samsung.com>
2020-10-08 7:15 ` Maninder Singh [this message]
[not found] ` <CAK8P3a2RYeNiTy9QmwFVKtFifXxWc9XfAT6ThPoSH9wGYsKGpA@mail.gmail.com>
2020-10-21 12:42 ` [PATCH 2/3] arm: introduce IRQ stacks Arnd Bergmann
2020-10-21 12:45 ` Russell King - ARM Linux admin
2020-10-21 12:55 ` Arnd Bergmann
2020-10-21 12:57 ` Russell King - ARM Linux admin
2020-10-21 15:59 ` Arnd Bergmann
2020-11-09 14:45 ` Tony Lindgren
2020-11-09 19:10 ` Arnd Bergmann
2020-11-10 9:19 ` Tony Lindgren
2020-11-10 10:04 ` Arnd Bergmann
2020-11-10 12:04 ` Tony Lindgren
2020-11-10 13:35 ` Arnd Bergmann
2020-11-11 6:56 ` Tony Lindgren
[not found] ` <CGME20201008071639epcas5p465f13d992a25936ba63436baf1fb6f83@epcms5p7>
2020-10-21 13:46 ` Vaneet Narang
[not found] ` <CGME20201008071644epcas5p1f5c220b5f58fd4251695af147325b7c4@epcas5p1.samsung.com>
2020-10-08 7:15 ` [PATCH 3/3] arm: Modify stack trace and dump for use with irq stack Maninder Singh
2020-10-08 7:53 ` [PATCH 0/3] IRQ stack support for ARM Sebastian Andrzej Siewior
2020-10-08 8:30 ` Russell King - ARM Linux admin
2020-10-15 20:59 ` Nick Desaulniers
2020-10-15 21:16 ` Florian Fainelli
[not found] ` <CAK8P3a0h=D8_Kn_fpHbsik_jf4to2jayxj7K7B7=HaNFzKqNnw@mail.gmail.com>
2020-10-21 11:58 ` Arnd Bergmann
2020-10-21 12:34 ` Russell King - ARM Linux admin
2020-10-21 12:46 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1602141333-17822-3-git-send-email-maninder1.s@samsung.com \
--to=maninder1.s@samsung.com \
--cc=0x7f454c46@gmail.com \
--cc=a.sahrawat@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=bigeasy@linutronix.de \
--cc=caij2003@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maz@kernel.org \
--cc=ndesaulniers@google.com \
--cc=nhuck@google.com \
--cc=tglx@linutronix.de \
--cc=v.narang@samsung.com \
--cc=valentin.schneider@arm.com \
--cc=vincent.whitchurch@axis.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®