Blob Blame History Raw
From 826da771291fc25a428e871f9e7fb465e390f852 Mon Sep 17 00:00:00 2001
From: Thomas Gleixner <tglx@linutronix.de>
Date: Thu, 29 Jul 2021 23:51:48 +0200
Subject: [PATCH] genirq: Provide IRQCHIP_AFFINITY_PRE_STARTUP
Git-commit: 826da771291fc25a428e871f9e7fb465e390f852
Patch-mainline: v5.14-rc6
References: bsc#1193231

X86 IO/APIC and MSI interrupts (when used without interrupts remapping)
require that the affinity setup on startup is done before the interrupt is
enabled for the first time as the non-remapped operation mode cannot safely
migrate enabled interrupts from arbitrary contexts. Provide a new irq chip
flag which allows affected hardware to request this.

This has to be opt-in because there have been reports in the past that some
interrupt chips cannot handle affinity setting before startup.

Fixes: 18404756765c ("genirq: Expose default irq affinity mask (take 3)")
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20210729222542.779791738@linutronix.de
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 include/linux/irq.h |    2 ++
 kernel/irq/chip.c   |    6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -477,6 +477,7 @@ struct irq_chip {
  * IRQCHIP_SKIP_SET_WAKE:	Skip chip.irq_set_wake(), for this irq chip
  * IRQCHIP_ONESHOT_SAFE:	One shot does not require mask/unmask
  * IRQCHIP_EOI_THREADED:	Chip requires eoi() on unmask in threaded mode
+ * IRQCHIP_AFFINITY_PRE_STARTUP:      Default affinity update before startup
  */
 enum {
 	IRQCHIP_SET_TYPE_MASKED		= (1 <<  0),
@@ -486,6 +487,7 @@ enum {
 	IRQCHIP_SKIP_SET_WAKE		= (1 <<  4),
 	IRQCHIP_ONESHOT_SAFE		= (1 <<  5),
 	IRQCHIP_EOI_THREADED		= (1 <<  6),
+	IRQCHIP_AFFINITY_PRE_STARTUP		= (1 << 7),
 };
 
 #include <linux/irqdesc.h>
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -214,6 +214,7 @@ static int __irq_startup(struct irq_desc
 
 int irq_startup(struct irq_desc *desc, bool resend)
 {
+	struct irq_data *d = irq_desc_get_irq_data(desc);
 	int ret = 0;
 
 	desc->depth = 0;
@@ -221,8 +222,11 @@ int irq_startup(struct irq_desc *desc, b
 	if (irqd_is_started(&desc->irq_data)) {
 		irq_enable(desc);
 	} else {
+		if (d->chip->flags & IRQCHIP_AFFINITY_PRE_STARTUP)
+			irq_setup_affinity(desc);
 		ret = __irq_startup(desc);
-		irq_setup_affinity(desc);
+		if (!(d->chip->flags & IRQCHIP_AFFINITY_PRE_STARTUP))
+			irq_setup_affinity(desc);
 	}
 	if (resend)
 		check_irq_resend(desc);