LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] irqchip: GICv3: ITS: Allocate enough memory for the full range of DeviceID
@ 2015-01-27  3:06 Chen Baozi
  2015-01-27 11:15 ` Chen Baozi
  0 siblings, 1 reply; 2+ messages in thread
From: Chen Baozi @ 2015-01-27  3:06 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: linux-kernel, Marc Zyngier, Chen Baozi

The ITS table allocator is only allocating a single page per table.
This works fine for most things, but leads to silent lack of
interrupt delivery if we end-up with a device that has an ID that is
out of the range defined by a single page of memory. Even worse, depending
on the page size, behaviour changes, which is not a very good experience.

A solution is actually to allocate memory for the full range of ID that
the ITS supports. A massive waste memory wise, but at least a safe bet.

This patch has been tested on the Phytium SoC.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Chen Baozi <chenbaozi@kylinos.com.cn>
---
 drivers/irqchip/irq-gic-v3-its.c   | 25 +++++++++++++++++++++----
 include/linux/irqchip/arm-gic-v3.h |  2 ++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 86e4684..d7a3d36 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -806,14 +806,31 @@ static int its_alloc_tables(struct its_node *its)
 		u64 val = readq_relaxed(its->base + GITS_BASER + i * 8);
 		u64 type = GITS_BASER_TYPE(val);
 		u64 entry_size = GITS_BASER_ENTRY_SIZE(val);
+		int order = 0;
+		int alloc_size;
 		u64 tmp;
 		void *base;
 
 		if (type == GITS_BASER_TYPE_NONE)
 			continue;
 
-		/* We're lazy and only allocate a single page for now */
-		base = (void *)get_zeroed_page(GFP_KERNEL);
+		/*
+		 * Allocate as many entries as required to fit the
+		 * range of device IDs that the ITS can grok... The ID
+		 * space being incredibly sparse, this results in a
+		 * massive waste of memory.
+		 *
+		 * For other tables, only allocate a single page.
+		 */
+		if (type == GITS_BASER_TYPE_DEVICE) {
+			u64 typer = readq_relaxed(its->base + GITS_TYPER);
+			u32 ids = GITS_TYPER_DEVBITS(typer);
+
+			order = get_order((1UL << ids) * entry_size);
+		}
+
+		alloc_size = (1 << order) * PAGE_SIZE;
+		base = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
 		if (!base) {
 			err = -ENOMEM;
 			goto out_free;
@@ -841,7 +858,7 @@ retry_baser:
 			break;
 		}
 
-		val |= (PAGE_SIZE / psz) - 1;
+		val |= (alloc_size / psz) - 1;
 
 		writeq_relaxed(val, its->base + GITS_BASER + i * 8);
 		tmp = readq_relaxed(its->base + GITS_BASER + i * 8);
@@ -882,7 +899,7 @@ retry_baser:
 		}
 
 		pr_info("ITS: allocated %d %s @%lx (psz %dK, shr %d)\n",
-			(int)(PAGE_SIZE / entry_size),
+			(int)(alloc_size / entry_size),
 			its_base_type_string[type],
 			(unsigned long)virt_to_phys(base),
 			psz / SZ_1K, (int)shr >> GITS_BASER_SHAREABILITY_SHIFT);
diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
index 1e8b0cf..7cf8d40 100644
--- a/include/linux/irqchip/arm-gic-v3.h
+++ b/include/linux/irqchip/arm-gic-v3.h
@@ -132,6 +132,8 @@
 #define GITS_BASER			0x0100
 #define GITS_PIDR2			GICR_PIDR2
 
+#define GITS_TYPER_DEVBITS_SHIFT	13
+#define GITS_TYPER_DEVBITS(r)		((((r) >> GITS_TYPER_DEVBITS_SHIFT) & 0x1f) + 1)
 #define GITS_TRANSLATER			0x10040
 
 #define GITS_TYPER_PTA			(1UL << 19)
-- 
2.1.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] irqchip: GICv3: ITS: Allocate enough memory for the full range of DeviceID
  2015-01-27  3:06 [PATCH] irqchip: GICv3: ITS: Allocate enough memory for the full range of DeviceID Chen Baozi
@ 2015-01-27 11:15 ` Chen Baozi
  0 siblings, 0 replies; 2+ messages in thread
From: Chen Baozi @ 2015-01-27 11:15 UTC (permalink / raw)
  To: 陈鲍孜; +Cc: linux-arm-kernel, linux-kernel, Marc Zyngier

[-- Attachment #1: Type: text/plain, Size: 784 bytes --]

On Jan 27, 2015, at 11:06, Chen Baozi <baozich@gmail.com> wrote:
> 
> The ITS table allocator is only allocating a single page per table.
> This works fine for most things, but leads to silent lack of
> interrupt delivery if we end-up with a device that has an ID that is
> out of the range defined by a single page of memory. Even worse, depending
> on the page size, behaviour changes, which is not a very good experience.
> 
> A solution is actually to allocate memory for the full range of ID that
> the ITS supports. A massive waste memory wise, but at least a safe bet.
> 
> This patch has been tested on the Phytium SoC.
> 
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>

Failed to clarify that Marc is the author of this patch.

Sorry for the mistake.

Cheers,

Baozi.


[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 842 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-01-27 11:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-27  3:06 [PATCH] irqchip: GICv3: ITS: Allocate enough memory for the full range of DeviceID Chen Baozi
2015-01-27 11:15 ` Chen Baozi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).