linux-stable/drivers/irqchip
Mark Rutland 7179d484c7 irqchip/gic-v3: Fix priority mask handling
[ Upstream commit 614ab80c96 ]

When a kernel is built with CONFIG_ARM64_PSEUDO_NMI=y and pseudo-NMIs
are enabled at runtime, GICv3's gic_handle_irq() can leave DAIF and
ICC_PMR_EL1 in an unexpected state in some cases, breaking subsequent
usage of local_irq_enable() and resulting in softirqs being run with
IRQs erroneously masked (possibly resulting in deadlocks).

This can happen when an IRQ exception is taken from a context where
regular IRQs were unmasked, and either:

(1) ICC_IAR1_EL1 indicates a special INTID (e.g. as a result of an IRQ
    being withdrawn since the IRQ exception was taken).

(2) ICC_IAR1_EL1 and ICC_RPR_EL1 indicate an NMI was acknowledged.

When an NMI is taken from a context where regular IRQs were masked,
there is no problem.

When CONFIG_ARM64_DEBUG_PRIORITY_MASKING=y, this can be detected with
perf, e.g.

| # ./perf record -a -g -e cycles:k ls -alR / > /dev/null 2>&1
| ------------[ cut here ]------------
| WARNING: CPU: 0 PID: 14 at arch/arm64/include/asm/irqflags.h:32 arch_local_irq_enable+0x4c/0x6c
| Modules linked in:
| CPU: 0 PID: 14 Comm: ksoftirqd/0 Not tainted 5.18.0-rc5-00004-g876c38e3d20b #12
| Hardware name: linux,dummy-virt (DT)
| pstate: 204000c5 (nzCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
| pc : arch_local_irq_enable+0x4c/0x6c
| lr : __do_softirq+0x110/0x5d8
| sp : ffff8000080bbbc0
| pmr_save: 000000f0
| x29: ffff8000080bbbc0 x28: ffff316ac3a6ca40 x27: 0000000000000000
| x26: 0000000000000000 x25: ffffa04611c06008 x24: ffffa04611c06008
| x23: 0000000040400005 x22: 0000000000000200 x21: ffff8000080bbe20
| x20: ffffa0460fe10320 x19: 0000000000000009 x18: 0000000000000000
| x17: ffff91252dfa9000 x16: ffff800008004000 x15: 0000000000004000
| x14: 0000000000000028 x13: ffffa0460fe17578 x12: ffffa0460fed4294
| x11: ffffa0460fedc168 x10: ffffffffffffff80 x9 : ffffa0460fe10a70
| x8 : ffffa0460fedc168 x7 : 000000000000b762 x6 : 00000000057c3bdf
| x5 : ffff8000080bbb18 x4 : 0000000000000000 x3 : 0000000000000001
| x2 : ffff91252dfa9000 x1 : 0000000000000060 x0 : 00000000000000f0
| Call trace:
|  arch_local_irq_enable+0x4c/0x6c
|  __irq_exit_rcu+0x180/0x1ac
|  irq_exit_rcu+0x1c/0x44
|  el1_interrupt+0x4c/0xe4
|  el1h_64_irq_handler+0x18/0x24
|  el1h_64_irq+0x74/0x78
|  smpboot_thread_fn+0x68/0x2c0
|  kthread+0x124/0x130
|  ret_from_fork+0x10/0x20
| irq event stamp: 193241
| hardirqs last  enabled at (193240): [<ffffa0460fe10a9c>] __do_softirq+0x10c/0x5d8
| hardirqs last disabled at (193241): [<ffffa0461102ffe4>] el1_dbg+0x24/0x90
| softirqs last  enabled at (193234): [<ffffa0460fe10e00>] __do_softirq+0x470/0x5d8
| softirqs last disabled at (193239): [<ffffa0460fea9944>] __irq_exit_rcu+0x180/0x1ac
| ---[ end trace 0000000000000000 ]---

The necessary manipulation of DAIF and ICC_PMR_EL1 depends on the
interrupted context, but the structure of gic_handle_irq() makes this
also depend on whether the GIC reports an IRQ, NMI, or special INTID:

*  When the interrupted context had regular IRQs masked (and hence the
   interrupt must be an NMI), the entry code performs the NMI
   entry/exit and gic_handle_irq() should return with DAIF and
   ICC_PMR_EL1 unchanged.

   This is handled correctly today.

* When the interrupted context had regular IRQs unmasked, the entry code
  performs IRQ entry/exit, but expects gic_handle_irq() to always update
  ICC_PMR_EL1 and DAIF.IF to unmask NMIs (but not regular IRQs) prior to
  returning (which it must do prior to invoking any regular IRQ
  handler).

  This unbalanced calling convention is necessary because we don't know
  whether an NMI has been taken until acknowledged by a read from
  ICC_IAR1_EL1, and so we need to perform the read with NMI masked in
  case an NMI has been taken (and needs to be handled with NMIs masked).

  Unfortunately, this is not handled consistently:

  - When ICC_IAR1_EL1 reports a special INTID, gic_handle_irq() returns
    immediately without manipulating ICC_PMR_EL1 and DAIF.

  - When RPR_EL1 indicates an NMI, gic_handle_irq() calls
    gic_handle_nmi() to invoke the NMI handler, then returns without
    manipulating ICC_PMR_EL1 and DAIF.

  - For regular IRQs, gic_handle_irq() manipulates ICC_PMR_EL1 and DAIF
    prior to invoking the IRQ handler.

There were related problems with special INTID handling in the past,
where if an exception was taken from a context with regular IRQs masked
and ICC_IAR_EL1 reported a special INTID, gic_handle_irq() would
erroneously unmask NMIs in NMI context permitted an unexpected nested
NMI. That case specifically was fixed by commit:

  a97709f563 ("irqchip/gic-v3: Do not enable irqs when handling spurious interrups")

... but unfortunately that commit added an inverse problem, where if an
exception was taken from a context with regular IRQs *unmasked* and
ICC_IAR_EL1 reported a special INTID, gic_handle_irq() would erroneously
fail to  unmask NMIs (and consequently regular IRQs could not be
unmasked during softirq processing). Before and after that commit, if an
NMI was taken from a context with regular IRQs unmasked gic_handle_irq()
would not unmask NMIs prior to returning, leading to the same problem
with softirq handling.

This patch fixes this by restructuring gic_handle_irq(), splitting it
into separate irqson/irqsoff helper functions which consistently perform
the DAIF + ICC_PMR1_EL1 manipulation based upon the interrupted context,
regardless of the event indicated by ICC_IAR1_EL1.

The special INTID handling is moved into the low-level IRQ/NMI handler
invocation helper functions, so that early returns don't prevent the
required manipulation of DAIF + ICC_PMR_EL1.

Fixes: f32c926651 ("irqchip/gic-v3: Handle pseudo-NMIs")
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220513133038.226182-4-mark.rutland@arm.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-06-09 10:30:14 +02:00
..
alphascale_asm9260-icoll.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
exynos-combiner.c Merge branch irq/generic_handle_domain_irq-core into irq/irqchip-next 2021-06-11 14:32:12 +01:00
irq-al-fic.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-alpine-msi.c irqchip/alpine-msi: Switch to bitmap_zalloc() 2021-07-26 18:01:44 +01:00
irq-apple-aic.c Merge branch irq/aic-v2 into irq/irqchip-next 2022-03-11 09:10:12 +00:00
irq-armada-370-xp.c irqchip/armada-370-xp: Fix support for Multi-MSI interrupts 2021-11-25 16:49:50 +00:00
irq-aspeed-i2c-ic.c irqchip/aspeed-i2c-ic: Fix irq_of_parse_and_map() return value 2022-06-09 10:30:06 +02:00
irq-aspeed-scu-ic.c irqchip/aspeed-scu-ic: Fix irq_of_parse_and_map() return value 2022-06-09 10:30:06 +02:00
irq-aspeed-vic.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-ath79-cpu.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
irq-ath79-misc.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-atmel-aic-common.c
irq-atmel-aic-common.h
irq-atmel-aic.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-atmel-aic5.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-bcm2835.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-bcm2836.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-bcm6345-l1.c irq: mips: simplify bcm6345_l1_irq_handle() 2021-10-25 10:04:53 +01:00
irq-bcm7038-l1.c irqchip/irq-bcm7038-l1: Switch to IRQCHIP_PLATFORM_DRIVER 2021-10-20 20:06:33 +01:00
irq-bcm7120-l2.c irqchip/irq-bcm7120-l2: Add put_device() after of_find_device_by_node() 2021-12-10 13:23:13 +00:00
irq-brcmstb-l2.c irqchip/irq-brcmstb-l2: Switch to IRQCHIP_PLATFORM_DRIVER 2021-10-20 20:06:33 +01:00
irq-clps711x.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-crossbar.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
irq-csky-apb-intc.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-csky-mpintc.c irqchip/csky-mpintc: Fixup mask/unmask implementation 2021-11-12 16:09:50 +00:00
irq-davinci-aintc.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-davinci-cp-intc.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-digicolor.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-dw-apb-ictl.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-ftintc010.c irqchip/versatile-fpga: Switch to dynamic chip name output 2022-02-15 11:25:46 +00:00
irq-gic-common.c irqchip/gic: Split vGIC probing information from the GIC code 2021-06-01 10:45:58 +01:00
irq-gic-common.h irqchip/gic: Split vGIC probing information from the GIC code 2021-06-01 10:45:58 +01:00
irq-gic-pm.c irqchip: gic-pm: Remove redundant error log of clock bulk 2021-06-11 14:21:04 +01:00
irq-gic-realview.c
irq-gic-v2m.c Rework of the MSI interrupt infrastructure: 2022-01-13 09:05:29 -08:00
irq-gic-v3-its-fsl-mc-msi.c bus: fsl-mc: Add ACPI support for fsl-mc 2020-07-28 15:51:32 +01:00
irq-gic-v3-its-pci-msi.c PCI/MSI: Make pci_msi_domain_write_msg() static 2021-12-09 11:52:20 +01:00
irq-gic-v3-its-platform-msi.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
irq-gic-v3-its.c irqchip/gic-v4: Wait for GICR_VPENDBASER.Dirty to clear before descheduling 2022-04-05 16:33:13 +01:00
irq-gic-v3-mbi.c PCI/MSI: Make pci_msi_domain_write_msg() static 2021-12-09 11:52:20 +01:00
irq-gic-v3.c irqchip/gic-v3: Fix priority mask handling 2022-06-09 10:30:14 +02:00
irq-gic-v4.c irqchip/gic-v4.1: Disable vSGI upon (GIC CPUIF < v4.1) detection 2021-04-22 15:55:21 +01:00
irq-gic.c irqchip/gic, gic-v3: Prevent GSI to SGI translations 2022-04-05 16:33:47 +01:00
irq-goldfish-pic.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-hip04.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-i8259.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-idt3243x.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-imgpdc.c Merge branch irq/generic_handle_domain_irq-core into irq/irqchip-next 2021-06-11 14:32:12 +01:00
irq-imx-gpcv2.c irqchip/imx-gpcv2: Mark imx_gpcv2_instance with __ro_after_init 2021-12-16 15:19:43 +00:00
irq-imx-intmux.c irqchip/imx-intmux: Move PM device over to irq domain 2022-02-09 13:36:53 +00:00
irq-imx-irqsteer.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-ingenic-tcu.c irqchip/ingenic-tcu: Use correctly sized arguments for bit field 2021-12-16 15:19:52 +00:00
irq-ingenic.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-ixp4xx.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-jcore-aic.c irqchip/jcore-aic: Kill use of irq_create_strict_mappings() 2021-04-22 15:55:22 +01:00
irq-keystone.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-loongson-htpic.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-loongson-htvec.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-loongson-liointc.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-loongson-pch-msi.c irqchip/loongson-pch-ms: Use bitmap_free() to free bitmap 2022-01-17 13:16:26 +00:00
irq-loongson-pch-pic.c irqchip/loongson-pch-pic: Improve edge triggered interrupt support 2021-08-12 07:57:23 +01:00
irq-lpc32xx.c irqchip/lpc32xx: Switch to dynamic chip name output 2022-02-15 11:25:46 +00:00
irq-ls-extirq.c irqchip/ls-extirq: add IRQCHIP_SKIP_SET_WAKE to the irqchip flags 2021-01-29 11:06:38 +00:00
irq-ls-scfg-msi.c irqchip/ls-scfg-msi: Switch to devm_bitmap_zalloc() 2021-07-26 18:04:10 +01:00
irq-ls1x.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-madera.c irqchip/madera: Drop GPIO includes 2019-01-17 17:04:24 +00:00
irq-mbigen.c platform-msi: Rename functions and clarify comments 2021-12-16 22:16:39 +01:00
irq-mchp-eic.c irqchip/mchp-eic: Fix return value check in mchp_eic_init() 2021-10-25 09:02:18 +01:00
irq-meson-gpio.c irqchip/meson-gpio: Add support for meson s4 SoCs 2022-03-09 11:19:56 +00:00
irq-mips-cpu.c irqchip/mips: Fix RCU violation when using irqdomain lookup on interrupt entry 2021-07-09 10:18:58 +01:00
irq-mips-gic.c irqchip/mips-gic: Use bitfield helpers 2021-11-25 16:55:40 +00:00
irq-mmp.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-mscc-ocelot.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-mst-intc.c irqchip/irq-mst: Support polarity configuration 2021-04-07 13:26:00 +01:00
irq-mtk-cirq.c irq: Fix typos in comments 2021-03-22 04:23:14 +01:00
irq-mtk-sysirq.c irqchip/mtk-sysirq: Skip setting irq-wake 2021-08-12 08:15:15 +01:00
irq-mvebu-gicp.c irqchip/mvebu-gicp: Switch to devm_bitmap_zalloc() 2021-07-26 18:04:10 +01:00
irq-mvebu-icu.c platform-msi: Rename functions and clarify comments 2021-12-16 22:16:39 +01:00
irq-mvebu-odmi.c irqchip/mvebu-odmi: Switch to bitmap_zalloc() 2021-07-26 18:04:11 +01:00
irq-mvebu-pic.c irqchip/mvebu-pic: Switch to dynamic chip name output 2022-02-15 11:25:46 +00:00
irq-mvebu-sei.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-mxs.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-nvic.c ARM development updates for 5.18: 2022-03-23 17:35:57 -07:00
irq-omap-intc.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-ompic.c
irq-or1k-pic.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-orion.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-owl-sirq.c irqchip: Add Actions Semi Owl SIRQ controller 2020-09-25 16:57:33 +01:00
irq-partition-percpu.c irqchip/partitions: Switch to bitmap_zalloc() 2021-07-26 18:01:27 +01:00
irq-pic32-evic.c irqchip/mips: Fix RCU violation when using irqdomain lookup on interrupt entry 2021-07-09 10:18:58 +01:00
irq-pruss-intc.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-qcom-mpm.c irqchip/irq-qcom-mpm: fix return value check in qcom_mpm_init() 2022-04-05 16:33:13 +01:00
irq-rda-intc.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-realtek-rtl.c irqchip/realtek-rtl: Service all pending interrupts 2022-01-17 12:16:26 +00:00
irq-renesas-h8s.c genirq: Fix various typos in comments 2018-12-18 14:22:28 +01:00
irq-renesas-h8300h.c
irq-renesas-intc-irqpin.c irqchip/renesas-intc-irqpin: Move PM device over to irq domain 2022-02-09 13:36:44 +00:00
irq-renesas-irqc.c irqchip/renesas-irqc: Move PM device over to irq domain 2022-02-09 13:36:53 +00:00
irq-renesas-rza1.c irqchip/renesas-rza1: Use semicolons instead of commas 2021-09-22 14:37:59 +01:00
irq-riscv-intc.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-sa11x0.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-sifive-plic.c irqchip updates for 5.18 2022-03-14 10:23:22 +01:00
irq-sl28cpld.c irqchip/irq-sl28cpld: Convert comma to semicolon 2020-12-18 17:43:47 +00:00
irq-sni-exiu.c irqchip/exiu: Fix acknowledgment of edge triggered interrupts 2022-06-09 10:30:06 +02:00
irq-st.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
irq-stm32-exti.c irqchip/stm32-exti: Add STM32MP13 support 2022-02-09 13:43:07 +00:00
irq-sun4i.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-sun6i-r.c irqchip/sun6i-r: Add wakeup support 2021-01-21 20:21:49 +00:00
irq-sunxi-nmi.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-tb10x.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
irq-tegra.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 282 2019-06-05 17:36:37 +02:00
irq-ti-sci-inta.c soc: ti: ti_sci_inta_msi: Use msi_desc::msi_index 2021-12-16 22:16:40 +01:00
irq-ti-sci-intr.c irqchip/ti-sci-intr: Fix freeing of irqs 2020-12-11 14:47:50 +00:00
irq-ts4800.c irqchip/ts4800: Switch to dynamic chip name output 2022-02-15 11:25:46 +00:00
irq-uniphier-aidet.c irqchip/uniphier-aidet: Use devm_platform_ioremap_resource() 2019-09-05 09:28:13 +01:00
irq-versatile-fpga.c irqchip/versatile-fpga: Switch to dynamic chip name output 2022-02-15 11:25:46 +00:00
irq-vf610-mscm-ir.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
irq-vic.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-vt8500.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-wpcm450-aic.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irq-xilinx-intc.c irqchip/xilinx: Switch to GENERIC_IRQ_MULTI_HANDLER 2022-03-04 14:32:57 +00:00
irq-xtensa-mx.c drivers/irqchip: xtensa-mx: fix mask and unmask 2019-01-26 02:02:15 -08:00
irq-xtensa-pic.c drivers/irqchip: xtensa: add warning to irq_retrigger 2019-01-26 02:02:14 -08:00
irq-zevio.c irq: remove handle_domain_{irq,nmi}() 2021-10-26 10:13:31 +01:00
irqchip.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
Kconfig irq/qcom-mpm: Fix build error without MAILBOX 2022-04-05 16:33:13 +01:00
Makefile asm-generic updates for 5.18 2022-03-23 18:03:08 -07:00
qcom-irq-combiner.c irqchip: Bulk conversion to generic_handle_domain_irq() 2021-06-10 13:09:19 +01:00
qcom-pdc.c irqchip/qcom-pdc: Drop open coded version of __assign_bit() 2022-03-01 10:06:25 +00:00
spear-shirq.c irqchip/spear-shirq: Add support for IRQ 0..6 2021-12-16 13:29:44 +00:00