Skip to contentSkip to conversation

GIC fixes for 4.3-rc2

PATCH In review Marc Zyngier 3 participants 9 messages Sep 13, 2015 – Sep 24, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover GIC fixes for 4.3-rc2

Thomas, Jason,

This small collection of patches address a number of issues all over the GIC spectrum, ranging from boot issues, ITS corruption and compile warnings.

It would be good if these fixes could make it into 4.3-rc2.

Thanks,

	M.

Marc Zyngier (2):
irqchip/GIC: Add workaround for aliased GIC400
irqchip/gic-v3-its: Add missing cache flushes

Pavel Fedin (1):
irqchip/GICv2m: Fix GICv2m build warning on 32 bits

 drivers/irqchip/irq-gic-v2m.c    |  4 ++--
 drivers/irqchip/irq-gic-v3-its.c |  6 +++++-
 drivers/irqchip/irq-gic.c        | 44 +++++++++++++++++++++++++++++++++++-----
 3 files changed, 46 insertions(+), 8 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/3 irqchip/GIC: Add workaround for aliased GIC400

The GICv2 architecture mandates that the two 4kB GIC regions are contiguous, and on two separate physical pages (so that access to the second page can be trapped by a hypervisor). This doesn't work very well when PAGE_SIZE is 64kB.

A relatively common hack^Wway to work around this is to alias each 4kB region over its own 64kB page. Of course in this case, the base address you want to use is not really the begining of the region, but base + 60kB (so that you get a contiguous 8kB region over two distinct pages).

Normally, this would be described in DT with a new property, but some HW is already out there, and the firmware makes sure that it will override whatever you put in the GIC node. Duh. And of course, said firmware source code is not available, despite being based on u-boot.

The workaround is to detect the case where the CPU interface size is set to 128kB, and verify the aliasing by checking that the ID register for GIC400 (which is the only GIC wired this way so far) is the same at base and base + 0xF000. In this case, we update the GIC base address and let it roll.

And if you feel slightly sick by looking at this, rest assured that I do too...

---
 drivers/irqchip/irq-gic.c | 44 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 5 deletions(-)
drivers/irqchip/irq-gic.c +39 -5
index e6b7ed5..a947057 100644
@@ -1119,12 +1119,49 @@ void __init gic_init_bases(unsigned int gic_nr, int irq_start,
 #ifdef CONFIG_OF
 static int gic_cnt __initdata;
 
+static bool gic_check_eoimode(struct device_node *node, void __iomem **base)
+{
+	struct resource cpuif_res;
+
+	of_address_to_resource(node, 1, &cpuif_res);
+
+	if (!is_hyp_mode_available())
+		return false;
+	if (resource_size(&cpuif_res) < SZ_8K)
+		return false;
+	if (resource_size(&cpuif_res) == SZ_128K) {
+		u32 val_low, val_high;
+
+		/*
+		 * Verify that we have the first 4kB of a GIC400
+		 * aliased over the first 64kB by checking the
+		 * GICC_IIDR register on both ends.
+		 */
+		val_low = readl_relaxed(*base + GIC_CPU_IDENT);
+		val_high = readl_relaxed(*base + GIC_CPU_IDENT + 0xf000);
+		if ((val_low & 0xffff0fff) != 0x0202043B ||
+		    val_low != val_high)
+			return false;
+
+		/*
+		 * Move the base up by 60kB, so that we have a 8kB
+		 * contiguous region, which allows us to use GICC_DIR
+		 *@its normal offset. Please pass me that bucket.
+		 */
+		*base += 0xf000;
+		cpuif_res.start += 0xf000;
+		pr_warn("GIC: Adjusting CPU interface base to %pa",
+			&cpuif_res.start);
+	}
+
+	return true;
+}
+
 static int __init
 gic_of_init(struct device_node *node, struct device_node *parent)
 {
 	void __iomem *cpu_base;
 	void __iomem *dist_base;
-	struct resource cpu_res;
 	u32 percpu_offset;
 	int irq;
 
@@ -1137,14 +1174,11 @@ gic_of_init(struct device_node *node, struct device_node *parent)
 	cpu_base = of_iomap(node, 1);
 	WARN(!cpu_base, "unable to map gic cpu registers\n");
 
-	of_address_to_resource(node, 1, &cpu_res);
-
 	/*
 	 * Disable split EOI/Deactivate if either HYP is not available
 	 * or the CPU interface is too small.
 	 */
-	if (gic_cnt == 0 && (!is_hyp_mode_available() ||
-			     resource_size(&cpu_res) < SZ_8K))
+	if (gic_cnt == 0 && !gic_check_eoimode(node, &cpu_base))
 		static_key_slow_dec(&supports_deactivate);
 
 	if (of_property_read_u32(node, "cpu-offset", &percpu_offset))
Signature · 1 line
2.1.4
#2 lore raw

[tip:irq/urgent] irqchip/GIC: Add workaround for aliased GIC400

irqchip/GIC: Add workaround for aliased GIC400
Commit-ID:  12e14066f4835f5ee1ca795f0309415b54c067a9
Gitweb:     http://git.kernel.org/tip/12e14066f4835f5ee1ca795f0309415b54c067a9
Author:     Marc Zyngier <[email protected]>
AuthorDate: Sun, 13 Sep 2015 12:14:31 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 15 Sep 2015 17:06:29 +0200

irqchip/GIC: Add workaround for aliased GIC400

The GICv2 architecture mandates that the two 4kB GIC regions are contiguous, and on two separate physical pages (so that access to the second page can be trapped by a hypervisor). This doesn't work very well when PAGE_SIZE is 64kB.

A relatively common hack^Wway to work around this is to alias each 4kB region over its own 64kB page. Of course in this case, the base address you want to use is not really the begining of the region, but base + 60kB (so that you get a contiguous 8kB region over two distinct pages).

Normally, this would be described in DT with a new property, but some HW is already out there, and the firmware makes sure that it will override whatever you put in the GIC node. Duh. And of course, said firmware source code is not available, despite being based on u-boot.

The workaround is to detect the case where the CPU interface size is set to 128kB, and verify the aliasing by checking that the ID register for GIC400 (which is the only GIC wired this way so far) is the same at base and base + 0xF000. In this case, we update the GIC base address and let it roll.

And if you feel slightly sick by looking at this, rest assured that I do too...

---
 drivers/irqchip/irq-gic.c | 44 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 5 deletions(-)
drivers/irqchip/irq-gic.c +39 -5
index e6b7ed5..a947057 100644
@@ -1119,12 +1119,49 @@ void __init gic_init_bases(unsigned int gic_nr, int irq_start,
 #ifdef CONFIG_OF
 static int gic_cnt __initdata;
 
+static bool gic_check_eoimode(struct device_node *node, void __iomem **base)
+{
+	struct resource cpuif_res;
+
+	of_address_to_resource(node, 1, &cpuif_res);
+
+	if (!is_hyp_mode_available())
+		return false;
+	if (resource_size(&cpuif_res) < SZ_8K)
+		return false;
+	if (resource_size(&cpuif_res) == SZ_128K) {
+		u32 val_low, val_high;
+
+		/*
+		 * Verify that we have the first 4kB of a GIC400
+		 * aliased over the first 64kB by checking the
+		 * GICC_IIDR register on both ends.
+		 */
+		val_low = readl_relaxed(*base + GIC_CPU_IDENT);
+		val_high = readl_relaxed(*base + GIC_CPU_IDENT + 0xf000);
+		if ((val_low & 0xffff0fff) != 0x0202043B ||
+		    val_low != val_high)
+			return false;
+
+		/*
+		 * Move the base up by 60kB, so that we have a 8kB
+		 * contiguous region, which allows us to use GICC_DIR
+		 * at its normal offset. Please pass me that bucket.
+		 */
+		*base += 0xf000;
+		cpuif_res.start += 0xf000;
+		pr_warn("GIC: Adjusting CPU interface base to %pa",
+			&cpuif_res.start);
+	}
+
+	return true;
+}
+
 static int __init
 gic_of_init(struct device_node *node, struct device_node *parent)
 {
 	void __iomem *cpu_base;
 	void __iomem *dist_base;
-	struct resource cpu_res;
 	u32 percpu_offset;
 	int irq;
 
@@ -1137,14 +1174,11 @@ gic_of_init(struct device_node *node, struct device_node *parent)
 	cpu_base = of_iomap(node, 1);
 	WARN(!cpu_base, "unable to map gic cpu registers\n");
 
-	of_address_to_resource(node, 1, &cpu_res);
-
 	/*
 	 * Disable split EOI/Deactivate if either HYP is not available
 	 * or the CPU interface is too small.
 	 */
-	if (gic_cnt == 0 && (!is_hyp_mode_available() ||
-			     resource_size(&cpu_res) < SZ_8K))
+	if (gic_cnt == 0 && !gic_check_eoimode(node, &cpu_base))
 		static_key_slow_dec(&supports_deactivate);
 
 	if (of_property_read_u32(node, "cpu-offset", &percpu_offset))
#3 lore raw

PATCH 2/3 irqchip/gic-v3-its: Add missing cache flushes

In reply to Marc Zyngier

When the ITS is configured for non-cacheable transactions, make sure that the allocated, zeroed memory is flushed to the Point of Coherency, allowing the ITS to observe the zeros instead of random garbage (or even get its own data overwritten by zeros being evicted from the cache...).

This fixes an issue introduced by 241a386c7dbb ("irqchip:
gicv3-its: Use non-cacheable accesses when no shareability").

---
 drivers/irqchip/irq-gic-v3-its.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +5 -1
index 26b55c5..ac7ae2b 100644
@@ -898,8 +898,10 @@ retry_baser:
 			 * non-cacheable as well.
 			 */
 			shr = tmp & GITS_BASER_SHAREABILITY_MASK;
-			if (!shr)
+			if (!shr) {
 				cache = GITS_BASER_nC;
+				__flush_dcache_area(base, alloc_size);
+			}
 			goto retry_baser;
 		}
 
@@ -1140,6 +1142,8 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id,
 		return NULL;
 	}
 
+	__flush_dcache_area(itt, sz);
+
 	dev->its = its;
 	dev->itt = itt;
 	dev->nr_ites = nr_ites;
Signature · 1 line
2.1.4
#4 lore raw

[tip:irq/urgent] irqchip/gic-v3-its: Add missing cache flushes

irqchip/gic-v3-its: Add missing cache flushes
Commit-ID:  5a9a8915c8888b615521b17d70a4342187eae60b
Gitweb:     http://git.kernel.org/tip/5a9a8915c8888b615521b17d70a4342187eae60b
Author:     Marc Zyngier <[email protected]>
AuthorDate: Sun, 13 Sep 2015 12:14:32 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 15 Sep 2015 17:06:29 +0200

irqchip/gic-v3-its: Add missing cache flushes

When the ITS is configured for non-cacheable transactions, make sure that the allocated, zeroed memory is flushed to the Point of Coherency, allowing the ITS to observe the zeros instead of random garbage (or even get its own data overwritten by zeros being evicted from the cache...).

Fixes 241a386c7dbb "irqchip: gicv3-its: Use non-cacheable accesses when no shareability"
Reported-and-tested-by Stuart Yoder <[email protected]>
Cc Pavel Fedin <[email protected]>
Cc Jason Cooper <[email protected]>
---
 drivers/irqchip/irq-gic-v3-its.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +5 -1
index 26b55c5..ac7ae2b 100644
@@ -898,8 +898,10 @@ retry_baser:
 			 * non-cacheable as well.
 			 */
 			shr = tmp & GITS_BASER_SHAREABILITY_MASK;
-			if (!shr)
+			if (!shr) {
 				cache = GITS_BASER_nC;
+				__flush_dcache_area(base, alloc_size);
+			}
 			goto retry_baser;
 		}
 
@@ -1140,6 +1142,8 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id,
 		return NULL;
 	}
 
+	__flush_dcache_area(itt, sz);
+
 	dev->its = its;
 	dev->itt = itt;
 	dev->nr_ites = nr_ites;
#5 lore raw

PATCH 3/3 irqchip/GICv2m: Fix GICv2m build warning on 32 bits

In reply to Marc Zyngier

From: Pavel Fedin <[email protected]>

After GICv2m was enabled for 32-bit ARM kernel, a warning popped up:

drivers/irqchip/irq-gic-v2m.c: In function ?gicv2m_compose_msi_msg?:
drivers/irqchip/irq-gic-v2m.c:100:2: warning: right shift count >= width of type [enabled by default]
msg->address_hi = (u32) (addr >> 32);
^

This patch fixes it by using proper macros for splitting up the value.

---
 drivers/irqchip/irq-gic-v2m.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/irqchip/irq-gic-v2m.c +2 -2
index db04fc1..12985da 100644
@@ -95,8 +95,8 @@ static void gicv2m_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 	struct v2m_data *v2m = irq_data_get_irq_chip_data(data);
 	phys_addr_t addr = v2m->res.start + V2M_MSI_SETSPI_NS;
 
-	msg->address_hi = (u32) (addr >> 32);
-	msg->address_lo = (u32) (addr);
+	msg->address_hi = upper_32_bits(addr);
+	msg->address_lo = lower_32_bits(addr);
 	msg->data = data->hwirq;
 }
 
Signature · 1 line
2.1.4
#6 lore raw

[tip:irq/urgent] irqchip/GICv2m: Fix GICv2m build warning on 32 bits

irqchip/GICv2m: Fix GICv2m build warning on 32 bits
Commit-ID:  157add60cb35913b8a848a3d7e6456b8ed134796
Gitweb:     http://git.kernel.org/tip/157add60cb35913b8a848a3d7e6456b8ed134796
Author:     Pavel Fedin <[email protected]>
AuthorDate: Sun, 13 Sep 2015 12:14:33 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 15 Sep 2015 17:06:29 +0200

irqchip/GICv2m: Fix GICv2m build warning on 32 bits

After GICv2m was enabled for 32-bit ARM kernel, a warning popped up:

drivers/irqchip/irq-gic-v2m.c: In function gicv2m_compose_msi_msg:
drivers/irqchip/irq-gic-v2m.c:100:2: warning: right shift count >= width of type [enabled by default]
msg->address_hi = (u32) (addr >> 32);
^

This patch fixes it by using proper macros for splitting up the value.

---
 drivers/irqchip/irq-gic-v2m.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/irqchip/irq-gic-v2m.c +2 -2
index db04fc1..12985da 100644
@@ -95,8 +95,8 @@ static void gicv2m_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 	struct v2m_data *v2m = irq_data_get_irq_chip_data(data);
 	phys_addr_t addr = v2m->res.start + V2M_MSI_SETSPI_NS;
 
-	msg->address_hi = (u32) (addr >> 32);
-	msg->address_lo = (u32) (addr);
+	msg->address_hi = upper_32_bits(addr);
+	msg->address_lo = lower_32_bits(addr);
 	msg->data = data->hwirq;
 }
 
#7 lore raw

RE: [PATCH 3/3] irqchip/GICv2m: Fix GICv2m build warning on 32 bits

In reply to Marc Zyngier

Hello!

Quoted 3 lines

From: Pavel Fedin <[email protected]>

After GICv2m was enabled for 32-bit ARM kernel, a warning popped up:

Thank you for the cooperation, i'm now back from my vacation.
What about the first patch in the series, which actually enables GICv2m on 32 bits? I don't see it anywhere, neither there are reviews.

Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia

#8 lore raw

Re: [PATCH 3/3] irqchip/GICv2m: Fix GICv2m build warning on 32 bits

Quoted 9 lines · On Thu, 24 Sep 2015 11:19:33 +0300 Pavel Fedin <[email protected]> wrote:

Hello!

Quoted 3 lines

From: Pavel Fedin <[email protected]>

After GICv2m was enabled for 32-bit ARM kernel, a warning popped up:

Thank you for the cooperation, i'm now back from my vacation. What about the first patch in the series, which actually enables
GICv2m on 32 bits? I don't see it anywhere, neither there are reviews.

This is a patch that touches arch/arm, so this is Russell that you have to convince, not me.

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny.