Skip to contentSkip to conversation

Patch "irqchip/gic: Ensure ordering between read of INTACK and shared data" has been added to the 4.5-stable tree

PATCH [email protected] 1 participant 1 message May 29, 2016

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

irqchip/gic: Ensure ordering between read of INTACK and shared data

to the 4.5-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
irqchip-gic-ensure-ordering-between-read-of-intack-and-shared-data.patch
and it can be found in the queue-4.5 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From f86c4fbd930ff6fecf3d8a1c313182bd0f49f496 Mon Sep 17 00:00:00 2001

From: Will Deacon <[email protected]>
Date: Tue, 26 Apr 2016 12:00:00 +0100
Subject: irqchip/gic: Ensure ordering between read of INTACK and shared data

From: Will Deacon <[email protected]>

commit f86c4fbd930ff6fecf3d8a1c313182bd0f49f496 upstream.

When an IPI is generated by a CPU, the pattern looks roughly like:

  <write shared data>
  smp_wmb();
  <write to GIC to signal SGI>

On the receiving CPU we rely on the fact that, once we've taken the interrupt, then the freshly written shared data must be visible to us. Put another way, the CPU isn't going to speculate taking an interrupt.

Unfortunately, this assumption turns out to be broken.

Consider that CPUx wants to send an IPI to CPUy, which will cause CPUy to read some shared_data. Before CPUx has done anything, a random peripheral raises an IRQ to the GIC and the IRQ line on CPUy is raised. CPUy then takes the IRQ and starts executing the entry code, heading towards gic_handle_irq. Furthermore, let's assume that a bunch of the previous interrupts handled by CPUy were SGIs, so the branch predictor kicks in and speculates that irqnr will be <16 and we're likely to head into handle_IPI. The prefetcher then grabs a speculative copy of shared_data which contains a stale value.

Meanwhile, CPUx gets round to updating shared_data and asking the GIC to send an SGI to CPUy. Internally, the GIC decides that the SGI is more important than the peripheral interrupt (which hasn't yet been ACKed) but doesn't need to do anything to CPUy, because the IRQ line is already raised.

CPUy then reads the ACK register on the GIC, sees the SGI value which confirms the branch prediction and we end up with a stale shared_data value.

This patch fixes the problem by adding an smp_rmb() to the IPI entry code in gic_handle_irq. As it turns out, the combination of a control dependency and an ISB instruction from the EOI in the GICv3 driver is enough to provide the ordering we need, so we add a comment there justifying the absence of an explicit smp_rmb().

---
 drivers/irqchip/irq-gic-v3.c |    7 +++++++
 drivers/irqchip/irq-gic.c    |    8 ++++++++
 2 files changed, 15 insertions(+)
drivers/irqchip/irq-gic-v3.c +7 -0
@@ -361,6 +361,13 @@ static asmlinkage void __exception_irq_e
 			if (static_key_true(&supports_deactivate))
 				gic_write_dir(irqnr);
 #ifdef CONFIG_SMP
+			/*
+			 * Unlike GICv2, we don't need an smp_rmb() here.
+			 * The control dependency from gic_read_iar to
+			 * the ISB in gic_write_eoir is enough to ensure
+			 * that any shared data read by handle_IPI will
+			 * be read after the ACK.
+			 */
 			handle_IPI(irqnr, regs);
 #else
 			WARN_ONCE(true, "Unexpected SGI received!\n");
drivers/irqchip/irq-gic.c +8 -0
@@ -344,6 +344,14 @@ static void __exception_irq_entry gic_ha
 			if (static_key_true(&supports_deactivate))
 				writel_relaxed(irqstat, cpu_base + GIC_CPU_DEACTIVATE);
 #ifdef CONFIG_SMP
+			/*
+			 * Ensure any shared data written by the CPU sending
+			 * the IPI is read after we've read the ACK register
+			 * on the GIC.
+			 *
+			 * Pairs with the write barrier in gic_raise_softirq
+			 */
+			smp_rmb();
 			handle_IPI(irqnr, regs);
 #endif
 			continue;

Patches currently in stable-queue which might be from [email protected] are

queue-4.5/arm64-cpuinfo-missing-null-terminator-in-compat_hwcap_str.patch queue-4.5/arm64-fix-typo-in-the-pmdp_huge_get_and_clear-definition.patch queue-4.5/irqchip-gic-ensure-ordering-between-read-of-intack-and-shared-data.patch queue-4.5/arm64-implement-ptep_set_access_flags-for-hardware-af-dbm.patch queue-4.5/arm64-implement-pmdp_set_access_flags-for-hardware-af-dbm.patch queue-4.5/arm64-ensure-pmd_present-returns-false-after-pmd_mknotpresent.patch