aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-12-31 14:23:11 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-12-31 14:23:11 -0500
commit88fa025d30ea97a2aae6394794bdfc31dc9423b7 (patch)
tree940e25f19adeaff91035954caec229e37576be77
parent31336ed90cdc866ac25d36851e91df532837c763 (diff)
parentbc976233a872c0f20f018fb1e89264a541584e25 (diff)
Merge branch 'irq-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull irq fixes from Thomas Gleixner: "A rather large update after the kaisered maintainer finally found time to handle regression reports. - The larger part addresses a regression caused by the x86 vector management rework. The reservation based model does not work reliably for MSI interrupts, if they cannot be masked (yes, yet another hw engineering trainwreck). The reason is that the reservation mode assigns a dummy vector when the interrupt is allocated and switches to a real vector when the interrupt is requested. If the MSI entry cannot be masked then the initialization might raise an interrupt before the interrupt is requested, which ends up as spurious interrupt and causes device malfunction and worse. The fix is to exclude MSI interrupts which do not support masking from reservation mode and assign a real vector right away. - Extend the extra lockdep class setup for nested interrupts with a class for the recently added irq_desc::request_mutex so lockdep can differeniate and does not emit false positive warnings. - A ratelimit guard for the bad irq printout so in case a bad irq comes back immediately the system does not drown in dmesg spam" * 'irq-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: genirq/msi, x86/vector: Prevent reservation mode for non maskable MSI genirq/irqdomain: Rename early argument of irq_domain_activate_irq() x86/vector: Use IRQD_CAN_RESERVE flag genirq: Introduce IRQD_CAN_RESERVE flag genirq/msi: Handle reactivation only on success gpio: brcmstb: Make really use of the new lockdep class genirq: Guard handle_bad_irq log messages kernel/irq: Extend lockdep class for request mutex
-rw-r--r--arch/powerpc/sysdev/fsl_msi.c4
-rw-r--r--arch/x86/include/asm/irqdomain.h2
-rw-r--r--arch/x86/include/asm/trace/irq_vectors.h16
-rw-r--r--arch/x86/kernel/apic/io_apic.c2
-rw-r--r--arch/x86/kernel/apic/vector.c20
-rw-r--r--arch/x86/platform/uv/uv_irq.c2
-rw-r--r--drivers/gpio/gpio-bcm-kona.c3
-rw-r--r--drivers/gpio/gpio-brcmstb.c4
-rw-r--r--drivers/gpio/gpio-tegra.c4
-rw-r--r--drivers/gpio/gpio-xgene-sb.c2
-rw-r--r--drivers/gpio/gpiolib.c27
-rw-r--r--drivers/iommu/amd_iommu.c2
-rw-r--r--drivers/iommu/intel_irq_remapping.c2
-rw-r--r--drivers/irqchip/irq-gic-v3-its.c4
-rw-r--r--drivers/irqchip/irq-renesas-intc-irqpin.c6
-rw-r--r--drivers/mfd/arizona-irq.c4
-rw-r--r--drivers/pinctrl/pinctrl-single.c5
-rw-r--r--drivers/pinctrl/stm32/pinctrl-stm32.c2
-rw-r--r--include/linux/gpio/driver.h33
-rw-r--r--include/linux/irq.h17
-rw-r--r--include/linux/irqdesc.h9
-rw-r--r--include/linux/irqdomain.h2
-rw-r--r--kernel/irq/debug.h5
-rw-r--r--kernel/irq/debugfs.c1
-rw-r--r--kernel/irq/generic-chip.c11
-rw-r--r--kernel/irq/internals.h2
-rw-r--r--kernel/irq/irqdomain.c13
-rw-r--r--kernel/irq/msi.c64
28 files changed, 196 insertions, 72 deletions
diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
index 44cbf4c12ea1..df95102e732c 100644
--- a/arch/powerpc/sysdev/fsl_msi.c
+++ b/arch/powerpc/sysdev/fsl_msi.c
@@ -354,6 +354,7 @@ static int fsl_of_msi_remove(struct platform_device *ofdev)
354} 354}
355 355
356static struct lock_class_key fsl_msi_irq_class; 356static struct lock_class_key fsl_msi_irq_class;
357static struct lock_class_key fsl_msi_irq_request_class;
357 358
358static int fsl_msi_setup_hwirq(struct fsl_msi *msi, struct platform_device *dev, 359static int fsl_msi_setup_hwirq(struct fsl_msi *msi, struct platform_device *dev,
359 int offset, int irq_index) 360 int offset, int irq_index)
@@ -373,7 +374,8 @@ static int fsl_msi_setup_hwirq(struct fsl_msi *msi, struct platform_device *dev,
373 dev_err(&dev->dev, "No memory for MSI cascade data\n"); 374 dev_err(&dev->dev, "No memory for MSI cascade data\n");
374 return -ENOMEM; 375 return -ENOMEM;
375 } 376 }
376 irq_set_lockdep_class(virt_msir, &fsl_msi_irq_class); 377 irq_set_lockdep_class(virt_msir, &fsl_msi_irq_class,
378 &fsl_msi_irq_request_class);
377 cascade_data->index = offset; 379 cascade_data->index = offset;
378 cascade_data->msi_data = msi; 380 cascade_data->msi_data = msi;
379 cascade_data->virq = virt_msir; 381 cascade_data->virq = virt_msir;
diff --git a/arch/x86/include/asm/irqdomain.h b/arch/x86/include/asm/irqdomain.h
index 139feef467f7..c066ffae222b 100644
--- a/arch/x86/include/asm/irqdomain.h
+++ b/arch/x86/include/asm/irqdomain.h
@@ -44,7 +44,7 @@ extern int mp_irqdomain_alloc(struct irq_domain *domain, unsigned int virq,
44extern void mp_irqdomain_free(struct irq_domain *domain, unsigned int virq, 44extern void mp_irqdomain_free(struct irq_domain *domain, unsigned int virq,
45 unsigned int nr_irqs); 45 unsigned int nr_irqs);
46extern int mp_irqdomain_activate(struct irq_domain *domain, 46extern int mp_irqdomain_activate(struct irq_domain *domain,
47 struct irq_data *irq_data, bool early); 47 struct irq_data *irq_data, bool reserve);
48extern void mp_irqdomain_deactivate(struct irq_domain *domain, 48extern void mp_irqdomain_deactivate(struct irq_domain *domain,
49 struct irq_data *irq_data); 49 struct irq_data *irq_data);
50extern int mp_irqdomain_ioapic_idx(struct irq_domain *domain); 50extern int mp_irqdomain_ioapic_idx(struct irq_domain *domain);
diff --git a/arch/x86/include/asm/trace/irq_vectors.h b/arch/x86/include/asm/trace/irq_vectors.h
index 84b9ec0c1bc0..22647a642e98 100644
--- a/arch/x86/include/asm/trace/irq_vectors.h
+++ b/arch/x86/include/asm/trace/irq_vectors.h
@@ -283,34 +283,34 @@ TRACE_EVENT(vector_alloc_managed,
283DECLARE_EVENT_CLASS(vector_activate, 283DECLARE_EVENT_CLASS(vector_activate,
284 284
285 TP_PROTO(unsigned int irq, bool is_managed, bool can_reserve, 285 TP_PROTO(unsigned int irq, bool is_managed, bool can_reserve,
286 bool early), 286 bool reserve),
287 287
288 TP_ARGS(irq, is_managed, can_reserve, early), 288 TP_ARGS(irq, is_managed, can_reserve, reserve),
289 289
290 TP_STRUCT__entry( 290 TP_STRUCT__entry(
291 __field( unsigned int, irq ) 291 __field( unsigned int, irq )
292 __field( bool, is_managed ) 292 __field( bool, is_managed )
293 __field( bool, can_reserve ) 293 __field( bool, can_reserve )
294 __field( bool, early ) 294 __field( bool, reserve )
295 ), 295 ),
296 296
297 TP_fast_assign( 297 TP_fast_assign(
298 __entry->irq = irq; 298 __entry->irq = irq;
299 __entry->is_managed = is_managed; 299 __entry->is_managed = is_managed;
300 __entry->can_reserve = can_reserve; 300 __entry->can_reserve = can_reserve;
301 __entry->early = early; 301 __entry->reserve = reserve;
302 ), 302 ),
303 303
304 TP_printk("irq=%u is_managed=%d can_reserve=%d early=%d", 304 TP_printk("irq=%u is_managed=%d can_reserve=%d reserve=%d",
305 __entry->irq, __entry->is_managed, __entry->can_reserve, 305 __entry->irq, __entry->is_managed, __entry->can_reserve,
306 __entry->early) 306 __entry->reserve)
307); 307);
308 308
309#define DEFINE_IRQ_VECTOR_ACTIVATE_EVENT(name) \ 309#define DEFINE_IRQ_VECTOR_ACTIVATE_EVENT(name) \
310DEFINE_EVENT_FN(vector_activate, name, \ 310DEFINE_EVENT_FN(vector_activate, name, \
311 TP_PROTO(unsigned int irq, bool is_managed, \ 311 TP_PROTO(unsigned int irq, bool is_managed, \
312 bool can_reserve, bool early), \ 312 bool can_reserve, bool reserve), \
313 TP_ARGS(irq, is_managed, can_reserve, early), NULL, NULL); \ 313 TP_ARGS(irq, is_managed, can_reserve, reserve), NULL, NULL); \
314 314
315DEFINE_IRQ_VECTOR_ACTIVATE_EVENT(vector_activate); 315DEFINE_IRQ_VECTOR_ACTIVATE_EVENT(vector_activate);
316DEFINE_IRQ_VECTOR_ACTIVATE_EVENT(vector_deactivate); 316DEFINE_IRQ_VECTOR_ACTIVATE_EVENT(vector_deactivate);
diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index 201579dc5242..8a7963421460 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -2988,7 +2988,7 @@ void mp_irqdomain_free(struct irq_domain *domain, unsigned int virq,
2988} 2988}
2989 2989
2990int mp_irqdomain_activate(struct irq_domain *domain, 2990int mp_irqdomain_activate(struct irq_domain *domain,
2991 struct irq_data *irq_data, bool early) 2991 struct irq_data *irq_data, bool reserve)
2992{ 2992{
2993 unsigned long flags; 2993 unsigned long flags;
2994 2994
diff --git a/arch/x86/kernel/apic/vector.c b/arch/x86/kernel/apic/vector.c
index 750449152b04..f8b03bb8e725 100644
--- a/arch/x86/kernel/apic/vector.c
+++ b/arch/x86/kernel/apic/vector.c
@@ -184,6 +184,7 @@ static void reserve_irq_vector_locked(struct irq_data *irqd)
184 irq_matrix_reserve(vector_matrix); 184 irq_matrix_reserve(vector_matrix);
185 apicd->can_reserve = true; 185 apicd->can_reserve = true;
186 apicd->has_reserved = true; 186 apicd->has_reserved = true;
187 irqd_set_can_reserve(irqd);
187 trace_vector_reserve(irqd->irq, 0); 188 trace_vector_reserve(irqd->irq, 0);
188 vector_assign_managed_shutdown(irqd); 189 vector_assign_managed_shutdown(irqd);
189} 190}
@@ -368,8 +369,18 @@ static int activate_reserved(struct irq_data *irqd)
368 int ret; 369 int ret;
369 370
370 ret = assign_irq_vector_any_locked(irqd); 371 ret = assign_irq_vector_any_locked(irqd);
371 if (!ret) 372 if (!ret) {
372 apicd->has_reserved = false; 373 apicd->has_reserved = false;
374 /*
375 * Core might have disabled reservation mode after
376 * allocating the irq descriptor. Ideally this should
377 * happen before allocation time, but that would require
378 * completely convoluted ways of transporting that
379 * information.
380 */
381 if (!irqd_can_reserve(irqd))
382 apicd->can_reserve = false;
383 }
373 return ret; 384 return ret;
374} 385}
375 386
@@ -398,21 +409,21 @@ static int activate_managed(struct irq_data *irqd)
398} 409}
399 410
400static int x86_vector_activate(struct irq_domain *dom, struct irq_data *irqd, 411static int x86_vector_activate(struct irq_domain *dom, struct irq_data *irqd,
401 bool early) 412 bool reserve)
402{ 413{
403 struct apic_chip_data *apicd = apic_chip_data(irqd); 414 struct apic_chip_data *apicd = apic_chip_data(irqd);
404 unsigned long flags; 415 unsigned long flags;
405 int ret = 0; 416 int ret = 0;
406 417
407 trace_vector_activate(irqd->irq, apicd->is_managed, 418 trace_vector_activate(irqd->irq, apicd->is_managed,
408 apicd->can_reserve, early); 419 apicd->can_reserve, reserve);
409 420
410 /* Nothing to do for fixed assigned vectors */ 421 /* Nothing to do for fixed assigned vectors */
411 if (!apicd->can_reserve && !apicd->is_managed) 422 if (!apicd->can_reserve && !apicd->is_managed)
412 return 0; 423 return 0;
413 424
414 raw_spin_lock_irqsave(&vector_lock, flags); 425 raw_spin_lock_irqsave(&vector_lock, flags);
415 if (early || irqd_is_managed_and_shutdown(irqd)) 426 if (reserve || irqd_is_managed_and_shutdown(irqd))
416 vector_assign_managed_shutdown(irqd); 427 vector_assign_managed_shutdown(irqd);
417 else if (apicd->is_managed) 428 else if (apicd->is_managed)
418 ret = activate_managed(irqd); 429 ret = activate_managed(irqd);
@@ -478,6 +489,7 @@ static bool vector_configure_legacy(unsigned int virq, struct irq_data *irqd,
478 } else { 489 } else {
479 /* Release the vector */ 490 /* Release the vector */
480 apicd->can_reserve = true; 491 apicd->can_reserve = true;
492 irqd_set_can_reserve(irqd);
481 clear_irq_vector(irqd); 493 clear_irq_vector(irqd);
482 realloc = true; 494 realloc = true;
483 } 495 }
diff --git a/arch/x86/platform/uv/uv_irq.c b/arch/x86/platform/uv/uv_irq.c
index 5f6fd860820a..e4cb9f4cde8a 100644
--- a/arch/x86/platform/uv/uv_irq.c
+++ b/arch/x86/platform/uv/uv_irq.c
@@ -128,7 +128,7 @@ static void uv_domain_free(struct irq_domain *domain, unsigned int virq,
128 * on the specified blade to allow the sending of MSIs to the specified CPU. 128 * on the specified blade to allow the sending of MSIs to the specified CPU.
129 */ 129 */
130static int uv_domain_activate(struct irq_domain *domain, 130static int uv_domain_activate(struct irq_domain *domain,
131 struct irq_data *irq_data, bool early) 131 struct irq_data *irq_data, bool reserve)
132{ 132{
133 uv_program_mmr(irqd_cfg(irq_data), irq_data->chip_data); 133 uv_program_mmr(irqd_cfg(irq_data), irq_data->chip_data);
134 return 0; 134 return 0;
diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c
index dfcf56ee3c61..76861a00bb92 100644
--- a/drivers/gpio/gpio-bcm-kona.c
+++ b/drivers/gpio/gpio-bcm-kona.c
@@ -522,6 +522,7 @@ static struct of_device_id const bcm_kona_gpio_of_match[] = {
522 * category than their parents, so it won't report false recursion. 522 * category than their parents, so it won't report false recursion.
523 */ 523 */
524static struct lock_class_key gpio_lock_class; 524static struct lock_class_key gpio_lock_class;
525static struct lock_class_key gpio_request_class;
525 526
526static int bcm_kona_gpio_irq_map(struct irq_domain *d, unsigned int irq, 527static int bcm_kona_gpio_irq_map(struct irq_domain *d, unsigned int irq,
527 irq_hw_number_t hwirq) 528 irq_hw_number_t hwirq)
@@ -531,7 +532,7 @@ static int bcm_kona_gpio_irq_map(struct irq_domain *d, unsigned int irq,
531 ret = irq_set_chip_data(irq, d->host_data); 532 ret = irq_set_chip_data(irq, d->host_data);
532 if (ret < 0) 533 if (ret < 0)
533 return ret; 534 return ret;
534 irq_set_lockdep_class(irq, &gpio_lock_class); 535 irq_set_lockdep_class(irq, &gpio_lock_class, &gpio_request_class);
535 irq_set_chip_and_handler(irq, &bcm_gpio_irq_chip, handle_simple_irq); 536 irq_set_chip_and_handler(irq, &bcm_gpio_irq_chip, handle_simple_irq);
536 irq_set_noprobe(irq); 537 irq_set_noprobe(irq);
537 538
diff --git a/drivers/gpio/gpio-brcmstb.c b/drivers/gpio/gpio-brcmstb.c
index 545d43a587b7..bb4f8cf18bd9 100644
--- a/drivers/gpio/gpio-brcmstb.c
+++ b/drivers/gpio/gpio-brcmstb.c
@@ -327,6 +327,7 @@ static struct brcmstb_gpio_bank *brcmstb_gpio_hwirq_to_bank(
327 * category than their parents, so it won't report false recursion. 327 * category than their parents, so it won't report false recursion.
328 */ 328 */
329static struct lock_class_key brcmstb_gpio_irq_lock_class; 329static struct lock_class_key brcmstb_gpio_irq_lock_class;
330static struct lock_class_key brcmstb_gpio_irq_request_class;
330 331
331 332
332static int brcmstb_gpio_irq_map(struct irq_domain *d, unsigned int irq, 333static int brcmstb_gpio_irq_map(struct irq_domain *d, unsigned int irq,
@@ -346,7 +347,8 @@ static int brcmstb_gpio_irq_map(struct irq_domain *d, unsigned int irq,
346 ret = irq_set_chip_data(irq, &bank->gc); 347 ret = irq_set_chip_data(irq, &bank->gc);
347 if (ret < 0) 348 if (ret < 0)
348 return ret; 349 return ret;
349 irq_set_lockdep_class(irq, &brcmstb_gpio_irq_lock_class); 350 irq_set_lockdep_class(irq, &brcmstb_gpio_irq_lock_class,
351 &brcmstb_gpio_irq_request_class);
350 irq_set_chip_and_handler(irq, &priv->irq_chip, handle_level_irq); 352 irq_set_chip_and_handler(irq, &priv->irq_chip, handle_level_irq);
351 irq_set_noprobe(irq); 353 irq_set_noprobe(irq);
352 return 0; 354 return 0;
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 8db47f671708..02fa8fe2292a 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -565,6 +565,7 @@ static const struct dev_pm_ops tegra_gpio_pm_ops = {
565 * than their parents, so it won't report false recursion. 565 * than their parents, so it won't report false recursion.
566 */ 566 */
567static struct lock_class_key gpio_lock_class; 567static struct lock_class_key gpio_lock_class;
568static struct lock_class_key gpio_request_class;
568 569
569static int tegra_gpio_probe(struct platform_device *pdev) 570static int tegra_gpio_probe(struct platform_device *pdev)
570{ 571{
@@ -670,7 +671,8 @@ static int tegra_gpio_probe(struct platform_device *pdev)
670 671
671 bank = &tgi->bank_info[GPIO_BANK(gpio)]; 672 bank = &tgi->bank_info[GPIO_BANK(gpio)];
672 673
673 irq_set_lockdep_class(irq, &gpio_lock_class); 674 irq_set_lockdep_class(irq, &gpio_lock_class,
675 &gpio_request_class);
674 irq_set_chip_data(irq, bank); 676 irq_set_chip_data(irq, bank);
675 irq_set_chip_and_handler(irq, &tgi->ic, handle_simple_irq); 677 irq_set_chip_and_handler(irq, &tgi->ic, handle_simple_irq);
676 } 678 }
diff --git a/drivers/gpio/gpio-xgene-sb.c b/drivers/gpio/gpio-xgene-sb.c
index 2313af82fad3..acd59113e08b 100644
--- a/drivers/gpio/gpio-xgene-sb.c
+++ b/drivers/gpio/gpio-xgene-sb.c
@@ -139,7 +139,7 @@ static int xgene_gpio_sb_to_irq(struct gpio_chip *gc, u32 gpio)
139 139
140static int xgene_gpio_sb_domain_activate(struct irq_domain *d, 140static int xgene_gpio_sb_domain_activate(struct irq_domain *d,
141 struct irq_data *irq_data, 141 struct irq_data *irq_data,
142 bool early) 142 bool reserve)
143{ 143{
144 struct xgene_gpio_sb *priv = d->host_data; 144 struct xgene_gpio_sb *priv = d->host_data;
145 u32 gpio = HWIRQ_TO_GPIO(priv, irq_data->hwirq); 145 u32 gpio = HWIRQ_TO_GPIO(priv, irq_data->hwirq);
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index aad84a6306c4..44332b793718 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -73,7 +73,8 @@ LIST_HEAD(gpio_devices);
73 73
74static void gpiochip_free_hogs(struct gpio_chip *chip); 74static void gpiochip_free_hogs(struct gpio_chip *chip);
75static int gpiochip_add_irqchip(struct gpio_chip *gpiochip, 75static int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
76 struct lock_class_key *key); 76 struct lock_class_key *lock_key,
77 struct lock_class_key *request_key);
77static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip); 78static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
78static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip); 79static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip);
79static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip); 80static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip);
@@ -1100,7 +1101,8 @@ static void gpiochip_setup_devs(void)
1100} 1101}
1101 1102
1102int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, 1103int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
1103 struct lock_class_key *key) 1104 struct lock_class_key *lock_key,
1105 struct lock_class_key *request_key)
1104{ 1106{
1105 unsigned long flags; 1107 unsigned long flags;
1106 int status = 0; 1108 int status = 0;
@@ -1246,7 +1248,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
1246 if (status) 1248 if (status)
1247 goto err_remove_from_list; 1249 goto err_remove_from_list;
1248 1250
1249 status = gpiochip_add_irqchip(chip, key); 1251 status = gpiochip_add_irqchip(chip, lock_key, request_key);
1250 if (status) 1252 if (status)
1251 goto err_remove_chip; 1253 goto err_remove_chip;
1252 1254
@@ -1632,7 +1634,7 @@ int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
1632 * This lock class tells lockdep that GPIO irqs are in a different 1634 * This lock class tells lockdep that GPIO irqs are in a different
1633 * category than their parents, so it won't report false recursion. 1635 * category than their parents, so it won't report false recursion.
1634 */ 1636 */
1635 irq_set_lockdep_class(irq, chip->irq.lock_key); 1637 irq_set_lockdep_class(irq, chip->irq.lock_key, chip->irq.request_key);
1636 irq_set_chip_and_handler(irq, chip->irq.chip, chip->irq.handler); 1638 irq_set_chip_and_handler(irq, chip->irq.chip, chip->irq.handler);
1637 /* Chips that use nested thread handlers have them marked */ 1639 /* Chips that use nested thread handlers have them marked */
1638 if (chip->irq.threaded) 1640 if (chip->irq.threaded)
@@ -1712,10 +1714,12 @@ static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset)
1712/** 1714/**
1713 * gpiochip_add_irqchip() - adds an IRQ chip to a GPIO chip 1715 * gpiochip_add_irqchip() - adds an IRQ chip to a GPIO chip
1714 * @gpiochip: the GPIO chip to add the IRQ chip to 1716 * @gpiochip: the GPIO chip to add the IRQ chip to
1715 * @lock_key: lockdep class 1717 * @lock_key: lockdep class for IRQ lock
1718 * @request_key: lockdep class for IRQ request
1716 */ 1719 */
1717static int gpiochip_add_irqchip(struct gpio_chip *gpiochip, 1720static int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
1718 struct lock_class_key *lock_key) 1721 struct lock_class_key *lock_key,
1722 struct lock_class_key *request_key)
1719{ 1723{
1720 struct irq_chip *irqchip = gpiochip->irq.chip; 1724 struct irq_chip *irqchip = gpiochip->irq.chip;
1721 const struct irq_domain_ops *ops; 1725 const struct irq_domain_ops *ops;
@@ -1753,6 +1757,7 @@ static int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
1753 gpiochip->to_irq = gpiochip_to_irq; 1757 gpiochip->to_irq = gpiochip_to_irq;
1754 gpiochip->irq.default_type = type; 1758 gpiochip->irq.default_type = type;
1755 gpiochip->irq.lock_key = lock_key; 1759 gpiochip->irq.lock_key = lock_key;
1760 gpiochip->irq.request_key = request_key;
1756 1761
1757 if (gpiochip->irq.domain_ops) 1762 if (gpiochip->irq.domain_ops)
1758 ops = gpiochip->irq.domain_ops; 1763 ops = gpiochip->irq.domain_ops;
@@ -1850,7 +1855,8 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
1850 * @type: the default type for IRQs on this irqchip, pass IRQ_TYPE_NONE 1855 * @type: the default type for IRQs on this irqchip, pass IRQ_TYPE_NONE
1851 * to have the core avoid setting up any default type in the hardware. 1856 * to have the core avoid setting up any default type in the hardware.
1852 * @threaded: whether this irqchip uses a nested thread handler 1857 * @threaded: whether this irqchip uses a nested thread handler
1853 * @lock_key: lockdep class 1858 * @lock_key: lockdep class for IRQ lock
1859 * @request_key: lockdep class for IRQ request
1854 * 1860 *
1855 * This function closely associates a certain irqchip with a certain 1861 * This function closely associates a certain irqchip with a certain
1856 * gpiochip, providing an irq domain to translate the local IRQs to 1862 * gpiochip, providing an irq domain to translate the local IRQs to
@@ -1872,7 +1878,8 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip,
1872 irq_flow_handler_t handler, 1878 irq_flow_handler_t handler,
1873 unsigned int type, 1879 unsigned int type,
1874 bool threaded, 1880 bool threaded,
1875 struct lock_class_key *lock_key) 1881 struct lock_class_key *lock_key,
1882 struct lock_class_key *request_key)
1876{ 1883{
1877 struct device_node *of_node; 1884 struct device_node *of_node;
1878 1885
@@ -1913,6 +1920,7 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip,
1913 gpiochip->irq.default_type = type; 1920 gpiochip->irq.default_type = type;
1914 gpiochip->to_irq = gpiochip_to_irq; 1921 gpiochip->to_irq = gpiochip_to_irq;
1915 gpiochip->irq.lock_key = lock_key; 1922 gpiochip->irq.lock_key = lock_key;
1923 gpiochip->irq.request_key = request_key;
1916 gpiochip->irq.domain = irq_domain_add_simple(of_node, 1924 gpiochip->irq.domain = irq_domain_add_simple(of_node,
1917 gpiochip->ngpio, first_irq, 1925 gpiochip->ngpio, first_irq,
1918 &gpiochip_domain_ops, gpiochip); 1926 &gpiochip_domain_ops, gpiochip);
@@ -1940,7 +1948,8 @@ EXPORT_SYMBOL_GPL(gpiochip_irqchip_add_key);
1940#else /* CONFIG_GPIOLIB_IRQCHIP */ 1948#else /* CONFIG_GPIOLIB_IRQCHIP */
1941 1949
1942static inline int gpiochip_add_irqchip(struct gpio_chip *gpiochip, 1950static inline int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
1943 struct lock_class_key *key) 1951 struct lock_class_key *lock_key,
1952 struct lock_class_key *request_key)
1944{ 1953{
1945 return 0; 1954 return 0;
1946} 1955}
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 7d5eb004091d..97baf88d9505 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -4184,7 +4184,7 @@ static void amd_ir_update_irte(struct irq_data *irqd, struct amd_iommu *iommu,
4184 struct irq_cfg *cfg); 4184 struct irq_cfg *cfg);
4185 4185
4186static int irq_remapping_activate(struct irq_domain *domain, 4186static int irq_remapping_activate(struct irq_domain *domain,
4187 struct irq_data *irq_data, bool early) 4187 struct irq_data *irq_data, bool reserve)
4188{ 4188{
4189 struct amd_ir_data *data = irq_data->chip_data; 4189 struct amd_ir_data *data = irq_data->chip_data;
4190 struct irq_2_irte *irte_info = &data->irq_2_irte; 4190 struct irq_2_irte *irte_info = &data->irq_2_irte;
diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c
index 76a193c7fcfc..66f69af2c219 100644
--- a/drivers/iommu/intel_irq_remapping.c
+++ b/drivers/iommu/intel_irq_remapping.c
@@ -1397,7 +1397,7 @@ static void intel_irq_remapping_free(struct irq_domain *domain,
1397} 1397}
1398 1398
1399static int intel_irq_remapping_activate(struct irq_domain *domain, 1399static int intel_irq_remapping_activate(struct irq_domain *domain,
1400 struct irq_data *irq_data, bool early) 1400 struct irq_data *irq_data, bool reserve)
1401{ 1401{
1402 intel_ir_reconfigure_irte(irq_data, true); 1402 intel_ir_reconfigure_irte(irq_data, true);
1403 return 0; 1403 return 0;
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 4039e64cd342..06f025fd5726 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -2303,7 +2303,7 @@ static int its_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
2303} 2303}
2304 2304
2305static int its_irq_domain_activate(struct irq_domain *domain, 2305static int its_irq_domain_activate(struct irq_domain *domain,
2306 struct irq_data *d, bool early) 2306 struct irq_data *d, bool reserve)
2307{ 2307{
2308 struct its_device *its_dev = irq_data_get_irq_chip_data(d); 2308 struct its_device *its_dev = irq_data_get_irq_chip_data(d);
2309 u32 event = its_get_event_id(d); 2309 u32 event = its_get_event_id(d);
@@ -2818,7 +2818,7 @@ static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virq
2818} 2818}
2819 2819
2820static int its_vpe_irq_domain_activate(struct irq_domain *domain, 2820static int its_vpe_irq_domain_activate(struct irq_domain *domain,
2821 struct irq_data *d, bool early) 2821 struct irq_data *d, bool reserve)
2822{ 2822{
2823 struct its_vpe *vpe = irq_data_get_irq_chip_data(d); 2823 struct its_vpe *vpe = irq_data_get_irq_chip_data(d);
2824 struct its_node *its; 2824 struct its_node *its;
diff --git a/drivers/irqchip/irq-renesas-intc-irqpin.c b/drivers/irqchip/irq-renesas-intc-irqpin.c
index 06f29cf5018a..cee59fe1321c 100644
--- a/drivers/irqchip/irq-renesas-intc-irqpin.c
+++ b/drivers/irqchip/irq-renesas-intc-irqpin.c
@@ -342,6 +342,9 @@ static irqreturn_t intc_irqpin_shared_irq_handler(int irq, void *dev_id)
342 */ 342 */
343static struct lock_class_key intc_irqpin_irq_lock_class; 343static struct lock_class_key intc_irqpin_irq_lock_class;
344 344
345/* And this is for the request mutex */
346static struct lock_class_key intc_irqpin_irq_request_class;
347
345static int intc_irqpin_irq_domain_map(struct irq_domain *h, unsigned int virq, 348static int intc_irqpin_irq_domain_map(struct irq_domain *h, unsigned int virq,
346 irq_hw_number_t hw) 349 irq_hw_number_t hw)
347{ 350{
@@ -352,7 +355,8 @@ static int intc_irqpin_irq_domain_map(struct irq_domain *h, unsigned int virq,
352 355
353 intc_irqpin_dbg(&p->irq[hw], "map"); 356 intc_irqpin_dbg(&p->irq[hw], "map");
354 irq_set_chip_data(virq, h->host_data); 357 irq_set_chip_data(virq, h->host_data);
355 irq_set_lockdep_class(virq, &intc_irqpin_irq_lock_class); 358 irq_set_lockdep_class(virq, &intc_irqpin_irq_lock_class,
359 &intc_irqpin_irq_request_class);
356 irq_set_chip_and_handler(virq, &p->irq_chip, handle_level_irq); 360 irq_set_chip_and_handler(virq, &p->irq_chip, handle_level_irq);
357 return 0; 361 return 0;
358} 362}
diff --git a/drivers/mfd/arizona-irq.c b/drivers/mfd/arizona-irq.c
index 09cf3699e354..a307832d7e45 100644
--- a/drivers/mfd/arizona-irq.c
+++ b/drivers/mfd/arizona-irq.c
@@ -184,6 +184,7 @@ static struct irq_chip arizona_irq_chip = {
184}; 184};
185 185
186static struct lock_class_key arizona_irq_lock_class; 186static struct lock_class_key arizona_irq_lock_class;
187static struct lock_class_key arizona_irq_request_class;
187 188
188static int arizona_irq_map(struct irq_domain *h, unsigned int virq, 189static int arizona_irq_map(struct irq_domain *h, unsigned int virq,
189 irq_hw_number_t hw) 190 irq_hw_number_t hw)
@@ -191,7 +192,8 @@ static int arizona_irq_map(struct irq_domain *h, unsigned int virq,
191 struct arizona *data = h->host_data; 192 struct arizona *data = h->host_data;
192 193
193 irq_set_chip_data(virq, data); 194 irq_set_chip_data(virq, data);
194 irq_set_lockdep_class(virq, &arizona_irq_lock_class); 195 irq_set_lockdep_class(virq, &arizona_irq_lock_class,
196 &arizona_irq_request_class);
195 irq_set_chip_and_handler(virq, &arizona_irq_chip, handle_simple_irq); 197 irq_set_chip_and_handler(virq, &arizona_irq_chip, handle_simple_irq);
196 irq_set_nested_thread(virq, 1); 198 irq_set_nested_thread(virq, 1);
197 irq_set_noprobe(virq); 199 irq_set_noprobe(virq);
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index e6cd8de793e2..3501491e5bfc 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -222,6 +222,9 @@ static enum pin_config_param pcs_bias[] = {
222 */ 222 */
223static struct lock_class_key pcs_lock_class; 223static struct lock_class_key pcs_lock_class;
224 224
225/* Class for the IRQ request mutex */
226static struct lock_class_key pcs_request_class;
227
225/* 228/*
226 * REVISIT: Reads and writes could eventually use regmap or something 229 * REVISIT: Reads and writes could eventually use regmap or something
227 * generic. But at least on omaps, some mux registers are performance 230 * generic. But at least on omaps, some mux registers are performance
@@ -1486,7 +1489,7 @@ static int pcs_irqdomain_map(struct irq_domain *d, unsigned int irq,
1486 irq_set_chip_data(irq, pcs_soc); 1489 irq_set_chip_data(irq, pcs_soc);
1487 irq_set_chip_and_handler(irq, &pcs->chip, 1490 irq_set_chip_and_handler(irq, &pcs->chip,
1488 handle_level_irq); 1491 handle_level_irq);
1489 irq_set_lockdep_class(irq, &pcs_lock_class); 1492 irq_set_lockdep_class(irq, &pcs_lock_class, &pcs_request_class);
1490 irq_set_noprobe(irq); 1493 irq_set_noprobe(irq);
1491 1494
1492 return 0; 1495 return 0;
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index a276c61be217..e62ab087bfd8 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -290,7 +290,7 @@ static int stm32_gpio_domain_translate(struct irq_domain *d,
290} 290}
291 291
292static int stm32_gpio_domain_activate(struct irq_domain *d, 292static int stm32_gpio_domain_activate(struct irq_domain *d,
293 struct irq_data *irq_data, bool early) 293 struct irq_data *irq_data, bool reserve)
294{ 294{
295 struct stm32_gpio_bank *bank = d->host_data; 295 struct stm32_gpio_bank *bank = d->host_data;
296 struct stm32_pinctrl *pctl = dev_get_drvdata(bank->gpio_chip.parent); 296 struct stm32_pinctrl *pctl = dev_get_drvdata(bank->gpio_chip.parent);
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 55e672592fa9..7258cd676df4 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -66,9 +66,10 @@ struct gpio_irq_chip {
66 /** 66 /**
67 * @lock_key: 67 * @lock_key:
68 * 68 *
69 * Per GPIO IRQ chip lockdep class. 69 * Per GPIO IRQ chip lockdep classes.
70 */ 70 */
71 struct lock_class_key *lock_key; 71 struct lock_class_key *lock_key;
72 struct lock_class_key *request_key;
72 73
73 /** 74 /**
74 * @parent_handler: 75 * @parent_handler:
@@ -323,7 +324,8 @@ extern const char *gpiochip_is_requested(struct gpio_chip *chip,
323 324
324/* add/remove chips */ 325/* add/remove chips */
325extern int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, 326extern int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
326 struct lock_class_key *lock_key); 327 struct lock_class_key *lock_key,
328 struct lock_class_key *request_key);
327 329
328/** 330/**
329 * gpiochip_add_data() - register a gpio_chip 331 * gpiochip_add_data() - register a gpio_chip
@@ -350,11 +352,13 @@ extern int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
350 */ 352 */
351#ifdef CONFIG_LOCKDEP 353#ifdef CONFIG_LOCKDEP
352#define gpiochip_add_data(chip, data) ({ \ 354#define gpiochip_add_data(chip, data) ({ \
353 static struct lock_class_key key; \ 355 static struct lock_class_key lock_key; \
354 gpiochip_add_data_with_key(chip, data, &key); \ 356 static struct lock_class_key request_key; \
357 gpiochip_add_data_with_key(chip, data, &lock_key, \
358 &request_key); \
355 }) 359 })
356#else 360#else
357#define gpiochip_add_data(chip, data) gpiochip_add_data_with_key(chip, data, NULL) 361#define gpiochip_add_data(chip, data) gpiochip_add_data_with_key(chip, data, NULL, NULL)
358#endif 362#endif
359 363
360static inline int gpiochip_add(struct gpio_chip *chip) 364static inline int gpiochip_add(struct gpio_chip *chip)
@@ -429,7 +433,8 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip,
429 irq_flow_handler_t handler, 433 irq_flow_handler_t handler,
430 unsigned int type, 434 unsigned int type,
431 bool threaded, 435 bool threaded,
432 struct lock_class_key *lock_key); 436 struct lock_class_key *lock_key,
437 struct lock_class_key *request_key);
433 438
434#ifdef CONFIG_LOCKDEP 439#ifdef CONFIG_LOCKDEP
435 440
@@ -445,10 +450,12 @@ static inline int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
445 irq_flow_handler_t handler, 450 irq_flow_handler_t handler,
446 unsigned int type) 451 unsigned int type)
447{ 452{
448 static struct lock_class_key key; 453 static struct lock_class_key lock_key;
454 static struct lock_class_key request_key;
449 455
450 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 456 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq,
451 handler, type, false, &key); 457 handler, type, false,
458 &lock_key, &request_key);
452} 459}
453 460
454static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip, 461static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip,
@@ -458,10 +465,12 @@ static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip,
458 unsigned int type) 465 unsigned int type)
459{ 466{
460 467
461 static struct lock_class_key key; 468 static struct lock_class_key lock_key;
469 static struct lock_class_key request_key;
462 470
463 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 471 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq,
464 handler, type, true, &key); 472 handler, type, true,
473 &lock_key, &request_key);
465} 474}
466#else 475#else
467static inline int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 476static inline int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
@@ -471,7 +480,7 @@ static inline int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
471 unsigned int type) 480 unsigned int type)
472{ 481{
473 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 482 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq,
474 handler, type, false, NULL); 483 handler, type, false, NULL, NULL);
475} 484}
476 485
477static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip, 486static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip,
@@ -481,7 +490,7 @@ static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip,
481 unsigned int type) 490 unsigned int type)
482{ 491{
483 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 492 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq,
484 handler, type, true, NULL); 493 handler, type, true, NULL, NULL);
485} 494}
486#endif /* CONFIG_LOCKDEP */ 495#endif /* CONFIG_LOCKDEP */
487 496
diff --git a/include/linux/irq.h b/include/linux/irq.h
index e140f69163b6..a0231e96a578 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -212,6 +212,7 @@ struct irq_data {
212 * mask. Applies only to affinity managed irqs. 212 * mask. Applies only to affinity managed irqs.
213 * IRQD_SINGLE_TARGET - IRQ allows only a single affinity target 213 * IRQD_SINGLE_TARGET - IRQ allows only a single affinity target
214 * IRQD_DEFAULT_TRIGGER_SET - Expected trigger already been set 214 * IRQD_DEFAULT_TRIGGER_SET - Expected trigger already been set
215 * IRQD_CAN_RESERVE - Can use reservation mode
215 */ 216 */
216enum { 217enum {
217 IRQD_TRIGGER_MASK = 0xf, 218 IRQD_TRIGGER_MASK = 0xf,
@@ -233,6 +234,7 @@ enum {
233 IRQD_MANAGED_SHUTDOWN = (1 << 23), 234 IRQD_MANAGED_SHUTDOWN = (1 << 23),
234 IRQD_SINGLE_TARGET = (1 << 24), 235 IRQD_SINGLE_TARGET = (1 << 24),
235 IRQD_DEFAULT_TRIGGER_SET = (1 << 25), 236 IRQD_DEFAULT_TRIGGER_SET = (1 << 25),
237 IRQD_CAN_RESERVE = (1 << 26),
236}; 238};
237 239
238#define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors) 240#define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors)
@@ -377,6 +379,21 @@ static inline bool irqd_is_managed_and_shutdown(struct irq_data *d)
377 return __irqd_to_state(d) & IRQD_MANAGED_SHUTDOWN; 379 return __irqd_to_state(d) & IRQD_MANAGED_SHUTDOWN;
378} 380}
379 381
382static inline void irqd_set_can_reserve(struct irq_data *d)
383{
384 __irqd_to_state(d) |= IRQD_CAN_RESERVE;
385}
386
387static inline void irqd_clr_can_reserve(struct irq_data *d)
388{
389 __irqd_to_state(d) &= ~IRQD_CAN_RESERVE;
390}
391
392static inline bool irqd_can_reserve(struct irq_data *d)
393{
394 return __irqd_to_state(d) & IRQD_CAN_RESERVE;
395}
396
380#undef __irqd_to_state 397#undef __irqd_to_state
381 398
382static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d) 399static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d)
diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
index 39fb3700f7a9..25b33b664537 100644
--- a/include/linux/irqdesc.h
+++ b/include/linux/irqdesc.h
@@ -255,12 +255,15 @@ static inline bool irq_is_percpu_devid(unsigned int irq)
255} 255}
256 256
257static inline void 257static inline void
258irq_set_lockdep_class(unsigned int irq, struct lock_class_key *class) 258irq_set_lockdep_class(unsigned int irq, struct lock_class_key *lock_class,
259 struct lock_class_key *request_class)
259{ 260{
260 struct irq_desc *desc = irq_to_desc(irq); 261 struct irq_desc *desc = irq_to_desc(irq);
261 262
262 if (desc) 263 if (desc) {
263 lockdep_set_class(&desc->lock, class); 264 lockdep_set_class(&desc->lock, lock_class);
265 lockdep_set_class(&desc->request_mutex, request_class);
266 }
264} 267}
265 268
266#ifdef CONFIG_IRQ_PREFLOW_FASTEOI 269#ifdef CONFIG_IRQ_PREFLOW_FASTEOI
diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index a34355d19546..48c7e86bb556 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -113,7 +113,7 @@ struct irq_domain_ops {
113 unsigned int nr_irqs, void *arg); 113 unsigned int nr_irqs, void *arg);
114 void (*free)(struct irq_domain *d, unsigned int virq, 114 void (*free)(struct irq_domain *d, unsigned int virq,
115 unsigned int nr_irqs); 115 unsigned int nr_irqs);
116 int (*activate)(struct irq_domain *d, struct irq_data *irqd, bool early); 116 int (*activate)(struct irq_domain *d, struct irq_data *irqd, bool reserve);
117 void (*deactivate)(struct irq_domain *d, struct irq_data *irq_data); 117 void (*deactivate)(struct irq_domain *d, struct irq_data *irq_data);
118 int (*translate)(struct irq_domain *d, struct irq_fwspec *fwspec, 118 int (*translate)(struct irq_domain *d, struct irq_fwspec *fwspec,
119 unsigned long *out_hwirq, unsigned int *out_type); 119 unsigned long *out_hwirq, unsigned int *out_type);
diff --git a/kernel/irq/debug.h b/kernel/irq/debug.h
index 17f05ef8f575..e4d3819a91cc 100644
--- a/kernel/irq/debug.h
+++ b/kernel/irq/debug.h
@@ -12,6 +12,11 @@
12 12
13static inline void print_irq_desc(unsigned int irq, struct irq_desc *desc) 13static inline void print_irq_desc(unsigned int irq, struct irq_desc *desc)
14{ 14{
15 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
16
17 if (!__ratelimit(&ratelimit))
18 return;
19
15 printk("irq %d, desc: %p, depth: %d, count: %d, unhandled: %d\n", 20 printk("irq %d, desc: %p, depth: %d, count: %d, unhandled: %d\n",
16 irq, desc, desc->depth, desc->irq_count, desc->irqs_unhandled); 21 irq, desc, desc->depth, desc->irq_count, desc->irqs_unhandled);
17 printk("->handle_irq(): %p, ", desc->handle_irq); 22 printk("->handle_irq(): %p, ", desc->handle_irq);
diff --git a/kernel/irq/debugfs.c b/kernel/irq/debugfs.c
index 7f608ac39653..acfaaef8672a 100644
--- a/kernel/irq/debugfs.c
+++ b/kernel/irq/debugfs.c
@@ -113,6 +113,7 @@ static const struct irq_bit_descr irqdata_states[] = {
113 BIT_MASK_DESCR(IRQD_SETAFFINITY_PENDING), 113 BIT_MASK_DESCR(IRQD_SETAFFINITY_PENDING),
114 BIT_MASK_DESCR(IRQD_AFFINITY_MANAGED), 114 BIT_MASK_DESCR(IRQD_AFFINITY_MANAGED),
115 BIT_MASK_DESCR(IRQD_MANAGED_SHUTDOWN), 115 BIT_MASK_DESCR(IRQD_MANAGED_SHUTDOWN),
116 BIT_MASK_DESCR(IRQD_CAN_RESERVE),
116 117
117 BIT_MASK_DESCR(IRQD_FORWARDED_TO_VCPU), 118 BIT_MASK_DESCR(IRQD_FORWARDED_TO_VCPU),
118 119
diff --git a/kernel/irq/generic-chip.c b/kernel/irq/generic-chip.c
index c26c5bb6b491..508c03dfef25 100644
--- a/kernel/irq/generic-chip.c
+++ b/kernel/irq/generic-chip.c
@@ -364,10 +364,11 @@ irq_get_domain_generic_chip(struct irq_domain *d, unsigned int hw_irq)
364EXPORT_SYMBOL_GPL(irq_get_domain_generic_chip); 364EXPORT_SYMBOL_GPL(irq_get_domain_generic_chip);
365 365
366/* 366/*
367 * Separate lockdep class for interrupt chip which can nest irq_desc 367 * Separate lockdep classes for interrupt chip which can nest irq_desc
368 * lock. 368 * lock and request mutex.
369 */ 369 */
370static struct lock_class_key irq_nested_lock_class; 370static struct lock_class_key irq_nested_lock_class;
371static struct lock_class_key irq_nested_request_class;
371 372
372/* 373/*
373 * irq_map_generic_chip - Map a generic chip for an irq domain 374 * irq_map_generic_chip - Map a generic chip for an irq domain
@@ -409,7 +410,8 @@ int irq_map_generic_chip(struct irq_domain *d, unsigned int virq,
409 set_bit(idx, &gc->installed); 410 set_bit(idx, &gc->installed);
410 411
411 if (dgc->gc_flags & IRQ_GC_INIT_NESTED_LOCK) 412 if (dgc->gc_flags & IRQ_GC_INIT_NESTED_LOCK)
412 irq_set_lockdep_class(virq, &irq_nested_lock_class); 413 irq_set_lockdep_class(virq, &irq_nested_lock_class,
414 &irq_nested_request_class);
413 415
414 if (chip->irq_calc_mask) 416 if (chip->irq_calc_mask)
415 chip->irq_calc_mask(data); 417 chip->irq_calc_mask(data);
@@ -479,7 +481,8 @@ void irq_setup_generic_chip(struct irq_chip_generic *gc, u32 msk,
479 continue; 481 continue;
480 482
481 if (flags & IRQ_GC_INIT_NESTED_LOCK) 483 if (flags & IRQ_GC_INIT_NESTED_LOCK)
482 irq_set_lockdep_class(i, &irq_nested_lock_class); 484 irq_set_lockdep_class(i, &irq_nested_lock_class,
485 &irq_nested_request_class);
483 486
484 if (!(flags & IRQ_GC_NO_MASK)) { 487 if (!(flags & IRQ_GC_NO_MASK)) {
485 struct irq_data *d = irq_get_irq_data(i); 488 struct irq_data *d = irq_get_irq_data(i);
diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h
index 07d08ca701ec..ab19371eab9b 100644
--- a/kernel/irq/internals.h
+++ b/kernel/irq/internals.h
@@ -440,7 +440,7 @@ static inline bool irq_fixup_move_pending(struct irq_desc *desc, bool fclear)
440#endif /* !CONFIG_GENERIC_PENDING_IRQ */ 440#endif /* !CONFIG_GENERIC_PENDING_IRQ */
441 441
442#if !defined(CONFIG_IRQ_DOMAIN) || !defined(CONFIG_IRQ_DOMAIN_HIERARCHY) 442#if !defined(CONFIG_IRQ_DOMAIN) || !defined(CONFIG_IRQ_DOMAIN_HIERARCHY)
443static inline int irq_domain_activate_irq(struct irq_data *data, bool early) 443static inline int irq_domain_activate_irq(struct irq_data *data, bool reserve)
444{ 444{
445 irqd_set_activated(data); 445 irqd_set_activated(data);
446 return 0; 446 return 0;
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 4f4f60015e8a..62068ad46930 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -1693,7 +1693,7 @@ static void __irq_domain_deactivate_irq(struct irq_data *irq_data)
1693 } 1693 }
1694} 1694}
1695 1695
1696static int __irq_domain_activate_irq(struct irq_data *irqd, bool early) 1696static int __irq_domain_activate_irq(struct irq_data *irqd, bool reserve)
1697{ 1697{
1698 int ret = 0; 1698 int ret = 0;
1699 1699
@@ -1702,9 +1702,9 @@ static int __irq_domain_activate_irq(struct irq_data *irqd, bool early)
1702 1702
1703 if (irqd->parent_data) 1703 if (irqd->parent_data)
1704 ret = __irq_domain_activate_irq(irqd->parent_data, 1704 ret = __irq_domain_activate_irq(irqd->parent_data,
1705 early); 1705 reserve);
1706 if (!ret && domain->ops->activate) { 1706 if (!ret && domain->ops->activate) {
1707 ret = domain->ops->activate(domain, irqd, early); 1707 ret = domain->ops->activate(domain, irqd, reserve);
1708 /* Rollback in case of error */ 1708 /* Rollback in case of error */
1709 if (ret && irqd->parent_data) 1709 if (ret && irqd->parent_data)
1710 __irq_domain_deactivate_irq(irqd->parent_data); 1710 __irq_domain_deactivate_irq(irqd->parent_data);
@@ -1716,17 +1716,18 @@ static int __irq_domain_activate_irq(struct irq_data *irqd, bool early)
1716/** 1716/**
1717 * irq_domain_activate_irq - Call domain_ops->activate recursively to activate 1717 * irq_domain_activate_irq - Call domain_ops->activate recursively to activate
1718 * interrupt 1718 * interrupt
1719 * @irq_data: outermost irq_data associated with interrupt 1719 * @irq_data: Outermost irq_data associated with interrupt
1720 * @reserve: If set only reserve an interrupt vector instead of assigning one
1720 * 1721 *
1721 * This is the second step to call domain_ops->activate to program interrupt 1722 * This is the second step to call domain_ops->activate to program interrupt
1722 * controllers, so the interrupt could actually get delivered. 1723 * controllers, so the interrupt could actually get delivered.
1723 */ 1724 */
1724int irq_domain_activate_irq(struct irq_data *irq_data, bool early) 1725int irq_domain_activate_irq(struct irq_data *irq_data, bool reserve)
1725{ 1726{
1726 int ret = 0; 1727 int ret = 0;
1727 1728
1728 if (!irqd_is_activated(irq_data)) 1729 if (!irqd_is_activated(irq_data))
1729 ret = __irq_domain_activate_irq(irq_data, early); 1730 ret = __irq_domain_activate_irq(irq_data, reserve);
1730 if (!ret) 1731 if (!ret)
1731 irqd_set_activated(irq_data); 1732 irqd_set_activated(irq_data);
1732 return ret; 1733 return ret;
diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index edb987b2c58d..2f3c4f5382cc 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -339,6 +339,40 @@ int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev,
339 return ret; 339 return ret;
340} 340}
341 341
342/*
343 * Carefully check whether the device can use reservation mode. If
344 * reservation mode is enabled then the early activation will assign a
345 * dummy vector to the device. If the PCI/MSI device does not support
346 * masking of the entry then this can result in spurious interrupts when
347 * the device driver is not absolutely careful. But even then a malfunction
348 * of the hardware could result in a spurious interrupt on the dummy vector
349 * and render the device unusable. If the entry can be masked then the core
350 * logic will prevent the spurious interrupt and reservation mode can be
351 * used. For now reservation mode is restricted to PCI/MSI.
352 */
353static bool msi_check_reservation_mode(struct irq_domain *domain,
354 struct msi_domain_info *info,
355 struct device *dev)
356{
357 struct msi_desc *desc;
358
359 if (domain->bus_token != DOMAIN_BUS_PCI_MSI)
360 return false;
361
362 if (!(info->flags & MSI_FLAG_MUST_REACTIVATE))
363 return false;
364
365 if (IS_ENABLED(CONFIG_PCI_MSI) && pci_msi_ignore_mask)
366 return false;
367
368 /*
369 * Checking the first MSI descriptor is sufficient. MSIX supports
370 * masking and MSI does so when the maskbit is set.
371 */
372 desc = first_msi_entry(dev);
373 return desc->msi_attrib.is_msix || desc->msi_attrib.maskbit;
374}
375
342/** 376/**
343 * msi_domain_alloc_irqs - Allocate interrupts from a MSI interrupt domain 377 * msi_domain_alloc_irqs - Allocate interrupts from a MSI interrupt domain
344 * @domain: The domain to allocate from 378 * @domain: The domain to allocate from
@@ -353,9 +387,11 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
353{ 387{
354 struct msi_domain_info *info = domain->host_data; 388 struct msi_domain_info *info = domain->host_data;
355 struct msi_domain_ops *ops = info->ops; 389 struct msi_domain_ops *ops = info->ops;
356 msi_alloc_info_t arg; 390 struct irq_data *irq_data;
357 struct msi_desc *desc; 391 struct msi_desc *desc;
392 msi_alloc_info_t arg;
358 int i, ret, virq; 393 int i, ret, virq;
394 bool can_reserve;
359 395
360 ret = msi_domain_prepare_irqs(domain, dev, nvec, &arg); 396 ret = msi_domain_prepare_irqs(domain, dev, nvec, &arg);
361 if (ret) 397 if (ret)
@@ -385,6 +421,8 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
385 if (ops->msi_finish) 421 if (ops->msi_finish)
386 ops->msi_finish(&arg, 0); 422 ops->msi_finish(&arg, 0);
387 423
424 can_reserve = msi_check_reservation_mode(domain, info, dev);
425
388 for_each_msi_entry(desc, dev) { 426 for_each_msi_entry(desc, dev) {
389 virq = desc->irq; 427 virq = desc->irq;
390 if (desc->nvec_used == 1) 428 if (desc->nvec_used == 1)
@@ -397,15 +435,25 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
397 * the MSI entries before the PCI layer enables MSI in the 435 * the MSI entries before the PCI layer enables MSI in the
398 * card. Otherwise the card latches a random msi message. 436 * card. Otherwise the card latches a random msi message.
399 */ 437 */
400 if (info->flags & MSI_FLAG_ACTIVATE_EARLY) { 438 if (!(info->flags & MSI_FLAG_ACTIVATE_EARLY))
401 struct irq_data *irq_data; 439 continue;
402 440
441 irq_data = irq_domain_get_irq_data(domain, desc->irq);
442 if (!can_reserve)
443 irqd_clr_can_reserve(irq_data);
444 ret = irq_domain_activate_irq(irq_data, can_reserve);
445 if (ret)
446 goto cleanup;
447 }
448
449 /*
450 * If these interrupts use reservation mode, clear the activated bit
451 * so request_irq() will assign the final vector.
452 */
453 if (can_reserve) {
454 for_each_msi_entry(desc, dev) {
403 irq_data = irq_domain_get_irq_data(domain, desc->irq); 455 irq_data = irq_domain_get_irq_data(domain, desc->irq);
404 ret = irq_domain_activate_irq(irq_data, true); 456 irqd_clr_activated(irq_data);
405 if (ret)
406 goto cleanup;
407 if (info->flags & MSI_FLAG_MUST_REACTIVATE)
408 irqd_clr_activated(irq_data);
409 } 457 }
410 } 458 }
411 return 0; 459 return 0;