From aa1850df63aa40748fdb8230b4157ec9bcdf4393 Mon Sep 17 00:00:00 2001
From: Thomas Gleixner <tglx@linutronix.de>
Date: Fri, 24 Sep 2021 17:05:48 +0200
Subject: [PATCH 134/158] */softirq: Disable softirq stacks on PREEMPT_RT

PREEMPT_RT preempts softirqs and the current implementation avoids
do_softirq_own_stack() and only uses __do_softirq().

Disable the unused softirqs stacks on PREEMPT_RT to safe some memory and
ensure that do_softirq_own_stack() is not used which is not expected.

[bigeasy: commit description.]

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/powerpc/kernel/irq.c  | 4 ++++
 arch/sh/kernel/irq.c       | 2 ++
 arch/sparc/kernel/irq_64.c | 2 ++
 3 files changed, 8 insertions(+)

Index: linux-5.15.19-rt29/arch/powerpc/kernel/irq.c
===================================================================
@ linux-5.15.19-rt29/arch/powerpc/kernel/irq.c:693 @ static inline void check_stack_overflow(
 	}
 }
 
+#ifndef CONFIG_PREEMPT_RT
 static __always_inline void call_do_softirq(const void *sp)
 {
 	/* Temporarily switch r1 to sp, call __do_softirq() then restore r1. */
@ linux-5.15.19-rt29/arch/powerpc/kernel/irq.c:712 @ static __always_inline void call_do_soft
 		   "r11", "r12"
 	);
 }
+#endif
 
 static __always_inline void call_do_irq(struct pt_regs *regs, void *sp)
 {
@ linux-5.15.19-rt29/arch/powerpc/kernel/irq.c:825 @ void *mcheckirq_ctx[NR_CPUS] __read_most
 void *softirq_ctx[NR_CPUS] __read_mostly;
 void *hardirq_ctx[NR_CPUS] __read_mostly;
 
+#ifndef CONFIG_PREEMPT_RT
 void do_softirq_own_stack(void)
 {
 	call_do_softirq(softirq_ctx[smp_processor_id()]);
 }
+#endif
 
 irq_hw_number_t virq_to_hw(unsigned int virq)
 {
Index: linux-5.15.19-rt29/arch/sh/kernel/irq.c
===================================================================
--- linux-5.15.19-rt29.orig/arch/sh/kernel/irq.c
+++ linux-5.15.19-rt29/arch/sh/kernel/irq.c
@ linux-5.15.19-rt29/arch/powerpc/kernel/irq.c:152 @ void irq_ctx_exit(int cpu)
 	hardirq_ctx[cpu] = NULL;
 }
 
+#ifndef CONFIG_PREEMPT_RT
 void do_softirq_own_stack(void)
 {
 	struct thread_info *curctx;
@ linux-5.15.19-rt29/arch/powerpc/kernel/irq.c:180 @ void do_softirq_own_stack(void)
 		  "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
 	);
 }
+#endif
 #else
 static inline void handle_one_irq(unsigned int irq)
 {
Index: linux-5.15.19-rt29/arch/sparc/kernel/irq_64.c
===================================================================
--- linux-5.15.19-rt29.orig/arch/sparc/kernel/irq_64.c
+++ linux-5.15.19-rt29/arch/sparc/kernel/irq_64.c
@ linux-5.15.19-rt29/arch/powerpc/kernel/irq.c:858 @ void __irq_entry handler_irq(int pil, st
 	set_irq_regs(old_regs);
 }
 
+#ifndef CONFIG_PREEMPT_RT
 void do_softirq_own_stack(void)
 {
 	void *orig_sp, *sp = softirq_stack[smp_processor_id()];
@ linux-5.15.19-rt29/arch/powerpc/kernel/irq.c:873 @ void do_softirq_own_stack(void)
 	__asm__ __volatile__("mov %0, %%sp"
 			     : : "r" (orig_sp));
 }
+#endif
 
 #ifdef CONFIG_HOTPLUG_CPU
 void fixup_irqs(void)