Skip to contentSkip to conversation

irqchip/gic-v3-its: Allow GIC ITS number more than MAX_NUMNODES

PATCH Superseded Hanjun Guo 6 participants 14 messages Jul 22, 2017 – Jul 27, 2017

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Hanjun Guo

author
#0 lore raw

PATCH v2 1/1 irqchip/gic-v3-its: Allow GIC ITS number more than MAX_NUMNODES

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

 drivers/irqchip/irq-gic-v3-its.c | 39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +32 -7
index 3ccdf76..1d692aa 100644
@@ -1847,13 +1847,16 @@ struct its_srat_map {
 	u32	its_id;
 };
 
-static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata;
+static struct its_srat_map *its_srat_maps __initdata;
 static int its_in_srat __initdata;
 
 static int __init acpi_get_its_numa_node(u32 its_id)
 {
 	int i;
 
+	if (!its_srat_maps)
+		return NUMA_NO_NODE;
+
 	for (i = 0; i < its_in_srat; i++) {
 		if (its_id == its_srat_maps[i].its_id)
 			return its_srat_maps[i].numa_node;
@@ -1861,6 +1864,12 @@ static int __init acpi_get_its_numa_node(u32 its_id)
 	return NUMA_NO_NODE;
 }
 
+static int __init gic_acpi_match_srat_its(struct acpi_subtable_header *header,
+					  const unsigned long end)
+{
+	return 0;
+}
+
 static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 			 const unsigned long end)
 {
@@ -1877,12 +1886,6 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 		return -EINVAL;
 	}
 
-	if (its_in_srat >= MAX_NUMNODES) {
-		pr_err("SRAT: ITS affinity exceeding max count[%d]\n",
-				MAX_NUMNODES);
-		return -EINVAL;
-	}
-
 	node = acpi_map_pxm_to_node(its_affinity->proximity_domain);
 
 	if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) {
@@ -1901,14 +1904,35 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 
 static void __init acpi_table_parse_srat_its(void)
 {
+	int count;
+
+	count = acpi_table_parse_entries(ACPI_SIG_SRAT,
+			sizeof(struct acpi_table_srat),
+			ACPI_SRAT_TYPE_GIC_ITS_AFFINITY,
+			gic_acpi_match_srat_its, 0);
+	if (count <= 0)
+		return;
+
+	its_srat_maps = kmalloc(count * sizeof(struct its_srat_map),
+				GFP_KERNEL);
+	if (!its_srat_maps)
+		return;
+
 	acpi_table_parse_entries(ACPI_SIG_SRAT,
 			sizeof(struct acpi_table_srat),
 			ACPI_SRAT_TYPE_GIC_ITS_AFFINITY,
 			gic_acpi_parse_srat_its, 0);
 }
+
+/* free the its_srat_maps after ITS probing */
+static void __init acpi_its_srat_maps_free(void)
+{
+	kfree(its_srat_maps);
+}
 #else
 static void __init acpi_table_parse_srat_its(void)	{ }
 static int __init acpi_get_its_numa_node(u32 its_id) { return NUMA_NO_NODE; }
+static void __init acpi_its_srat_maps_free(void) { }
 #endif
 
 static int __init gic_acpi_parse_madt_its(struct acpi_subtable_header *header,
@@ -1955,6 +1979,7 @@ static void __init its_acpi_probe(void)
 	acpi_table_parse_srat_its();
 	acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR,
 			      gic_acpi_parse_madt_its, 0);
+	acpi_its_srat_maps_free();
 }
 #else
 static void __init its_acpi_probe(void) { }
Signature · 1 line
1.7.12.4
#1 lore raw
Quoted 80 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

 drivers/irqchip/irq-gic-v3-its.c | 39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +10 -1
index 3ccdf76..1d692aa 100644
@@ -1847,13 +1847,16 @@ struct its_srat_map {
 	u32	its_id;
 };
 
-static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata;
+static struct its_srat_map *its_srat_maps __initdata;
 static int its_in_srat __initdata;
 
 static int __init acpi_get_its_numa_node(u32 its_id)
 {
 	int i;
 
+	if (!its_srat_maps)
+		return NUMA_NO_NODE;
+
 	for (i = 0; i < its_in_srat; i++) {
 		if (its_id == its_srat_maps[i].its_id)
 			return its_srat_maps[i].numa_node;
@@ -1861,6 +1864,12 @@ static int __init acpi_get_its_numa_node(u32 its_id)
 	return NUMA_NO_NODE;
 }
 
+static int __init gic_acpi_match_srat_its(struct acpi_subtable_header *header,
+					  const unsigned long end)
+{
+	return 0;
+}
+
 static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 			 const unsigned long end)
 {

drivers/irqchip/irq-gic-v3-its.c static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header, · line 1885

Quoted 9 lines
drivers/irqchip/irq-gic-v3-its.c +0 -6
@@ -1877,12 +1886,6 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 		return -EINVAL;
 	}
 
-	if (its_in_srat >= MAX_NUMNODES) {
-		pr_err("SRAT: ITS affinity exceeding max count[%d]\n",
-				MAX_NUMNODES);
-		return -EINVAL;
-	}
-

So you're getting rid of that message when overflowing the array...

Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +3 -0
 	node = acpi_map_pxm_to_node(its_affinity->proximity_domain);
 
 	if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) {
@@ -1901,14 +1904,35 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 
 static void __init acpi_table_parse_srat_its(void)
 {
+	int count;
+
+	count = acpi_table_parse_entries(ACPI_SIG_SRAT,

drivers/irqchip/irq-gic-v3-its.c static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header, · line 1919

Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +10 -0
+			sizeof(struct acpi_table_srat),
+			ACPI_SRAT_TYPE_GIC_ITS_AFFINITY,
+			gic_acpi_match_srat_its, 0);
+	if (count <= 0)
+		return;
+
+	its_srat_maps = kmalloc(count * sizeof(struct its_srat_map),
+				GFP_KERNEL);
+	if (!its_srat_maps)
+		return;

and here silently returning when failing to allocate the memory. I think it'd be worth having a bit of a warning.

Quoted 21 lines
drivers/irqchip/irq-gic-v3-its.c +8 -0
+
 	acpi_table_parse_entries(ACPI_SIG_SRAT,
 			sizeof(struct acpi_table_srat),
 			ACPI_SRAT_TYPE_GIC_ITS_AFFINITY,
 			gic_acpi_parse_srat_its, 0);
 }
+
+/* free the its_srat_maps after ITS probing */
+static void __init acpi_its_srat_maps_free(void)
+{
+	kfree(its_srat_maps);
+}
 #else
 static void __init acpi_table_parse_srat_its(void)	{ }
 static int __init acpi_get_its_numa_node(u32 its_id) { return NUMA_NO_NODE; }
+static void __init acpi_its_srat_maps_free(void) { }
 #endif
 
 static int __init gic_acpi_parse_madt_its(struct acpi_subtable_header *header,

drivers/irqchip/irq-gic-v3-its.c static void __init its_acpi_probe(void) · line 1985

Quoted 7 lines
drivers/irqchip/irq-gic-v3-its.c +1 -0
@@ -1955,6 +1979,7 @@ static void __init its_acpi_probe(void)
 	acpi_table_parse_srat_its();
 	acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR,
 			      gic_acpi_parse_madt_its, 0);
+	acpi_its_srat_maps_free();
 }
 #else
 static void __init its_acpi_probe(void) { }

Otherwise looks good.

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#2 lore raw
Quoted 84 lines · Marc Zyngier
Quoted 83 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

  drivers/irqchip/irq-gic-v3-its.c | 39 ++++++++++++++++++++++++++++++++-------
  1 file changed, 32 insertions(+), 7 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +10 -1
index 3ccdf76..1d692aa 100644
@@ -1847,13 +1847,16 @@ struct its_srat_map {
  	u32	its_id;
  };
 
-static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata;
+static struct its_srat_map *its_srat_maps __initdata;
  static int its_in_srat __initdata;
 
  static int __init acpi_get_its_numa_node(u32 its_id)
  {
  	int i;
 
+	if (!its_srat_maps)
+		return NUMA_NO_NODE;
+
  	for (i = 0; i < its_in_srat; i++) {
  		if (its_id == its_srat_maps[i].its_id)
  			return its_srat_maps[i].numa_node;
@@ -1861,6 +1864,12 @@ static int __init acpi_get_its_numa_node(u32 its_id)
  	return NUMA_NO_NODE;
  }
 
+static int __init gic_acpi_match_srat_its(struct acpi_subtable_header *header,
+					  const unsigned long end)
+{
+	return 0;
+}
+
  static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
  			 const unsigned long end)
  {
@@ -1877,12 +1886,6 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
  		return -EINVAL;
  	}
 
Quoted 8 lines

drivers/irqchip/irq-gic-v3-its.c static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header, · line 1885

Quoted 6 lines
drivers/irqchip/irq-gic-v3-its.c +0 -6
-	if (its_in_srat >= MAX_NUMNODES) {
-		pr_err("SRAT: ITS affinity exceeding max count[%d]\n",
-				MAX_NUMNODES);
-		return -EINVAL;
-	}
-

So you're getting rid of that message when overflowing the array...

This overflowing will not happen, because I scan the SRAT to count the entry(ies) of ITS affinity first to alloc the array, and then parse the same SRAT again to setup the mapping of NUMA node to ITS, so is it fine for us to just remove the check here?

Quoted 16 lines
Quoted 16 lines
drivers/irqchip/irq-gic-v3-its.c +8 -0
  	node = acpi_map_pxm_to_node(its_affinity->proximity_domain);
 
  	if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) {
@@ -1901,14 +1904,35 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 
  static void __init acpi_table_parse_srat_its(void)
  {
+	int count;
+
+	count = acpi_table_parse_entries(ACPI_SIG_SRAT,
+			sizeof(struct acpi_table_srat),
+			ACPI_SRAT_TYPE_GIC_ITS_AFFINITY,
+			gic_acpi_match_srat_its, 0);
+	if (count <= 0)
+		return;
Quoted 8 lines

drivers/irqchip/irq-gic-v3-its.c static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header, · line 1919

Quoted 5 lines
drivers/irqchip/irq-gic-v3-its.c +5 -0
+
+	its_srat_maps = kmalloc(count * sizeof(struct its_srat_map),
+				GFP_KERNEL);
+	if (!its_srat_maps)
+		return;

and here silently returning when failing to allocate the memory. I think it'd be worth having a bit of a warning.

Will do.

Quoted 19 lines
Quoted 19 lines
drivers/irqchip/irq-gic-v3-its.c +8 -0
+
  	acpi_table_parse_entries(ACPI_SIG_SRAT,
  			sizeof(struct acpi_table_srat),
  			ACPI_SRAT_TYPE_GIC_ITS_AFFINITY,
  			gic_acpi_parse_srat_its, 0);
  }
+
+/* free the its_srat_maps after ITS probing */
+static void __init acpi_its_srat_maps_free(void)
+{
+	kfree(its_srat_maps);
+}
  #else
  static void __init acpi_table_parse_srat_its(void)	{ }
  static int __init acpi_get_its_numa_node(u32 its_id) { return NUMA_NO_NODE; }
+static void __init acpi_its_srat_maps_free(void) { }
  #endif
 
Quoted 12 lines

drivers/irqchip/irq-gic-v3-its.c static void __init its_acpi_probe(void) · line 1985

Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +1 -0
  static int __init gic_acpi_parse_madt_its(struct acpi_subtable_header *header,
@@ -1955,6 +1979,7 @@ static void __init its_acpi_probe(void)
  	acpi_table_parse_srat_its();
  	acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR,
  			      gic_acpi_parse_madt_its, 0);
+	acpi_its_srat_maps_free();
  }
  #else
  static void __init its_acpi_probe(void) { }

Otherwise looks good.

Thanks
Hanjun

#3 lore raw
Quoted 94 lines · Hanjun Guo
Quoted 84 lines · Marc Zyngier
Quoted 83 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

  drivers/irqchip/irq-gic-v3-its.c | 39 ++++++++++++++++++++++++++++++++-------
  1 file changed, 32 insertions(+), 7 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +10 -1
index 3ccdf76..1d692aa 100644
@@ -1847,13 +1847,16 @@ struct its_srat_map {
  	u32	its_id;
  };
 
-static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata;
+static struct its_srat_map *its_srat_maps __initdata;
  static int its_in_srat __initdata;
 
  static int __init acpi_get_its_numa_node(u32 its_id)
  {
  	int i;
 
+	if (!its_srat_maps)
+		return NUMA_NO_NODE;
+
  	for (i = 0; i < its_in_srat; i++) {
  		if (its_id == its_srat_maps[i].its_id)
  			return its_srat_maps[i].numa_node;
@@ -1861,6 +1864,12 @@ static int __init acpi_get_its_numa_node(u32 its_id)
  	return NUMA_NO_NODE;
  }
 
+static int __init gic_acpi_match_srat_its(struct acpi_subtable_header *header,
+					  const unsigned long end)
+{
+	return 0;
+}
+
  static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
  			 const unsigned long end)
  {
@@ -1877,12 +1886,6 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
  		return -EINVAL;
  	}
 
Quoted 8 lines

drivers/irqchip/irq-gic-v3-its.c static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header, · line 1885

Quoted 6 lines
drivers/irqchip/irq-gic-v3-its.c +0 -6
-	if (its_in_srat >= MAX_NUMNODES) {
-		pr_err("SRAT: ITS affinity exceeding max count[%d]\n",
-				MAX_NUMNODES);
-		return -EINVAL;
-	}
-

So you're getting rid of that message when overflowing the array...

Quoted 5 lines

This overflowing will not happen, because I scan the SRAT to count the entry(ies) of ITS affinity first to alloc the array, and then parse the same SRAT again to setup the mapping of NUMA node to ITS, so is it fine for us to just remove the check here?

Removing that check is fine, as long as you make sure the allocation hasn't failed.

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
drivers/irqchip/irq-gic-v3-its.c +8 -0
  	node = acpi_map_pxm_to_node(its_affinity->proximity_domain);
 
  	if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) {
@@ -1901,14 +1904,35 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 
  static void __init acpi_table_parse_srat_its(void)
  {
+	int count;
+
+	count = acpi_table_parse_entries(ACPI_SIG_SRAT,
+			sizeof(struct acpi_table_srat),
+			ACPI_SRAT_TYPE_GIC_ITS_AFFINITY,
+			gic_acpi_match_srat_its, 0);
+	if (count <= 0)
+		return;
Quoted 8 lines

drivers/irqchip/irq-gic-v3-its.c static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header, · line 1919

Quoted 5 lines
drivers/irqchip/irq-gic-v3-its.c +5 -0
+
+	its_srat_maps = kmalloc(count * sizeof(struct its_srat_map),
+				GFP_KERNEL);
+	if (!its_srat_maps)
+		return;

and here silently returning when failing to allocate the memory. I think it'd be worth having a bit of a warning.

Quoted 1 line

Will do.

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#4 lore raw
Quoted 95 lines · Marc Zyngier
Quoted 94 lines · Hanjun Guo
Quoted 92 lines · Marc Zyngier
Quoted 80 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

   drivers/irqchip/irq-gic-v3-its.c | 39 ++++++++++++++++++++++++++++++++-------
   1 file changed, 32 insertions(+), 7 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +10 -1
index 3ccdf76..1d692aa 100644
@@ -1847,13 +1847,16 @@ struct its_srat_map {
   	u32	its_id;
   };
 
-static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata;
+static struct its_srat_map *its_srat_maps __initdata;
   static int its_in_srat __initdata;
 
   static int __init acpi_get_its_numa_node(u32 its_id)
   {
   	int i;
 
+	if (!its_srat_maps)
+		return NUMA_NO_NODE;
+
   	for (i = 0; i < its_in_srat; i++) {
   		if (its_id == its_srat_maps[i].its_id)
   			return its_srat_maps[i].numa_node;
@@ -1861,6 +1864,12 @@ static int __init acpi_get_its_numa_node(u32 its_id)
   	return NUMA_NO_NODE;
   }
 
+static int __init gic_acpi_match_srat_its(struct acpi_subtable_header *header,
+					  const unsigned long end)
+{
+	return 0;
+}
+
   static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
   			 const unsigned long end)
   {

drivers/irqchip/irq-gic-v3-its.c static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header, · line 1885

Quoted 9 lines
drivers/irqchip/irq-gic-v3-its.c +0 -6
@@ -1877,12 +1886,6 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
   		return -EINVAL;
   	}
 
-	if (its_in_srat >= MAX_NUMNODES) {
-		pr_err("SRAT: ITS affinity exceeding max count[%d]\n",
-				MAX_NUMNODES);
-		return -EINVAL;
-	}
-

So you're getting rid of that message when overflowing the array...

Quoted 8 lines
Quoted 5 lines

This overflowing will not happen, because I scan the SRAT to count the entry(ies) of ITS affinity first to alloc the array, and then parse the same SRAT again to setup the mapping of NUMA node to ITS, so is it fine for us to just remove the check here?

Removing that check is fine, as long as you make sure the allocation hasn't failed.

Sorry, just want to make sure I understand correctly. This function will not be called if allocation failure, so do you mean we can keep the code as it is?

Thanks
Hanjun

#5 lore raw
Quoted 102 lines · Hanjun Guo
Quoted 101 lines · Marc Zyngier
Quoted 99 lines · Hanjun Guo
Quoted 84 lines · Marc Zyngier
Quoted 83 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

   drivers/irqchip/irq-gic-v3-its.c | 39 ++++++++++++++++++++++++++++++++-------
   1 file changed, 32 insertions(+), 7 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +10 -1
index 3ccdf76..1d692aa 100644
@@ -1847,13 +1847,16 @@ struct its_srat_map {
   	u32	its_id;
   };
 
-static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata;
+static struct its_srat_map *its_srat_maps __initdata;
   static int its_in_srat __initdata;
 
   static int __init acpi_get_its_numa_node(u32 its_id)
   {
   	int i;
 
+	if (!its_srat_maps)
+		return NUMA_NO_NODE;
+
   	for (i = 0; i < its_in_srat; i++) {
   		if (its_id == its_srat_maps[i].its_id)
   			return its_srat_maps[i].numa_node;
@@ -1861,6 +1864,12 @@ static int __init acpi_get_its_numa_node(u32 its_id)
   	return NUMA_NO_NODE;
   }
 
+static int __init gic_acpi_match_srat_its(struct acpi_subtable_header *header,
+					  const unsigned long end)
+{
+	return 0;
+}
+
   static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
   			 const unsigned long end)
   {
@@ -1877,12 +1886,6 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
   		return -EINVAL;
   	}
 
Quoted 8 lines

drivers/irqchip/irq-gic-v3-its.c static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header, · line 1885

Quoted 6 lines
drivers/irqchip/irq-gic-v3-its.c +0 -6
-	if (its_in_srat >= MAX_NUMNODES) {
-		pr_err("SRAT: ITS affinity exceeding max count[%d]\n",
-				MAX_NUMNODES);
-		return -EINVAL;
-	}
-

So you're getting rid of that message when overflowing the array...

This overflowing will not happen, because I scan the SRAT to count the entry(ies) of ITS affinity first to alloc the array, and then parse the same SRAT again to setup the mapping of NUMA node to ITS, so is it fine for us to just remove the check here?

Quoted 6 lines
Quoted 2 lines

Removing that check is fine, as long as you make sure the allocation hasn't failed.

Sorry, just want to make sure I understand correctly. This function will not be called if allocation failure, so do you mean we can keep the code as it is?

No. I mean adding this warning when the allocation fails, so that we know that our NUMA topology is screwed.

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#6 lore raw
Quoted 106 lines · Marc Zyngier
Quoted 105 lines · Hanjun Guo
Quoted 103 lines · Marc Zyngier
Quoted 94 lines · Hanjun Guo
Quoted 84 lines · Marc Zyngier
Quoted 83 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

drivers/irqchip/irq-gic-v3-its.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-)

drivers/irqchip/irq-gic-v3-its.c +10 -1
index 3ccdf76..1d692aa 100644
@@ -1847,13 +1847,16 @@ struct its_srat_map {
    	u32	its_id;
    };
 
-static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata;
+static struct its_srat_map *its_srat_maps __initdata;
    static int its_in_srat __initdata;
 
    static int __init acpi_get_its_numa_node(u32 its_id)
    {
    	int i;
 
+	if (!its_srat_maps)
+		return NUMA_NO_NODE;
+
    	for (i = 0; i < its_in_srat; i++) {
    		if (its_id == its_srat_maps[i].its_id)
    			return its_srat_maps[i].numa_node;
@@ -1861,6 +1864,12 @@ static int __init acpi_get_its_numa_node(u32 its_id)
    	return NUMA_NO_NODE;
    }
 
+static int __init gic_acpi_match_srat_its(struct acpi_subtable_header *header,
+					  const unsigned long end)
+{
+	return 0;
+}
+
    static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
    			 const unsigned long end)
    {
@@ -1877,12 +1886,6 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
    		return -EINVAL;
    	}
 
Quoted 8 lines

drivers/irqchip/irq-gic-v3-its.c static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header, · line 1885

Quoted 6 lines
drivers/irqchip/irq-gic-v3-its.c +0 -6
-	if (its_in_srat >= MAX_NUMNODES) {
-		pr_err("SRAT: ITS affinity exceeding max count[%d]\n",
-				MAX_NUMNODES);
-		return -EINVAL;
-	}
-

So you're getting rid of that message when overflowing the array...

Quoted 5 lines

This overflowing will not happen, because I scan the SRAT to count the entry(ies) of ITS affinity first to alloc the array, and then parse the same SRAT again to setup the mapping of NUMA node to ITS, so is it fine for us to just remove the check here?

Removing that check is fine, as long as you make sure the allocation hasn't failed.

Quoted 6 lines
Quoted 3 lines

Sorry, just want to make sure I understand correctly. This function will not be called if allocation failure, so do you mean we can keep the code as it is?

No. I mean adding this warning when the allocation fails, so that we know that our NUMA topology is screwed.

OK, thanks!

Hanjun

Reviewed-by on v2 1/1
#7 lore raw
In reply to Hanjun Guo
Quoted 3 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

Nit: You should stick to what the problem is and why you need to solve it, "Fixes:" tag gives the commit history you need, the rest (eg "When running 4.13-rc1") does not belong in the commit log.

Quoted 17 lines
[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

Quoted 8 lines
[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3

Question (unrelated): how are PCI devices (or better PCI host bridges) mapped to ITSs ? I ask because in IORT we currently ignore the notion of ITS groups - so it is just out of curiosity (I suspect you have a static 1:1 mapping PCI-host-bridge->ITS).

Quoted 5 lines
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>
Quoted 7 lines

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

 drivers/irqchip/irq-gic-v3-its.c | 39 ++++++++++++++++++++++++++++++++-------
Quoted 97 lines
 1 file changed, 32 insertions(+), 7 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +32 -7
index 3ccdf76..1d692aa 100644
@@ -1847,13 +1847,16 @@ struct its_srat_map {
 	u32	its_id;
 };
 
-static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata;
+static struct its_srat_map *its_srat_maps __initdata;
 static int its_in_srat __initdata;
 
 static int __init acpi_get_its_numa_node(u32 its_id)
 {
 	int i;
 
+	if (!its_srat_maps)
+		return NUMA_NO_NODE;
+
 	for (i = 0; i < its_in_srat; i++) {
 		if (its_id == its_srat_maps[i].its_id)
 			return its_srat_maps[i].numa_node;
@@ -1861,6 +1864,12 @@ static int __init acpi_get_its_numa_node(u32 its_id)
 	return NUMA_NO_NODE;
 }
 
+static int __init gic_acpi_match_srat_its(struct acpi_subtable_header *header,
+					  const unsigned long end)
+{
+	return 0;
+}
+
 static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 			 const unsigned long end)
 {
@@ -1877,12 +1886,6 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 		return -EINVAL;
 	}
 
-	if (its_in_srat >= MAX_NUMNODES) {
-		pr_err("SRAT: ITS affinity exceeding max count[%d]\n",
-				MAX_NUMNODES);
-		return -EINVAL;
-	}
-
 	node = acpi_map_pxm_to_node(its_affinity->proximity_domain);
 
 	if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) {
@@ -1901,14 +1904,35 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 
 static void __init acpi_table_parse_srat_its(void)
 {
+	int count;
+
+	count = acpi_table_parse_entries(ACPI_SIG_SRAT,
+			sizeof(struct acpi_table_srat),
+			ACPI_SRAT_TYPE_GIC_ITS_AFFINITY,
+			gic_acpi_match_srat_its, 0);
+	if (count <= 0)
+		return;
+
+	its_srat_maps = kmalloc(count * sizeof(struct its_srat_map),
+				GFP_KERNEL);
+	if (!its_srat_maps)
+		return;
+
 	acpi_table_parse_entries(ACPI_SIG_SRAT,
 			sizeof(struct acpi_table_srat),
 			ACPI_SRAT_TYPE_GIC_ITS_AFFINITY,
 			gic_acpi_parse_srat_its, 0);
 }
+
+/* free the its_srat_maps after ITS probing */
+static void __init acpi_its_srat_maps_free(void)
+{
+	kfree(its_srat_maps);
+}
 #else
 static void __init acpi_table_parse_srat_its(void)	{ }
 static int __init acpi_get_its_numa_node(u32 its_id) { return NUMA_NO_NODE; }
+static void __init acpi_its_srat_maps_free(void) { }
 #endif
 
 static int __init gic_acpi_parse_madt_its(struct acpi_subtable_header *header,
@@ -1955,6 +1979,7 @@ static void __init its_acpi_probe(void)
 	acpi_table_parse_srat_its();
 	acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR,
 			      gic_acpi_parse_madt_its, 0);
+	acpi_its_srat_maps_free();
 }
 #else
 static void __init its_acpi_probe(void) { }
Signature · 1 line
1.7.12.4
#8 lore raw
Quoted 8 lines · Lorenzo Pieralisi
Quoted 3 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

Nit: You should stick to what the problem is and why you need to solve it, "Fixes:" tag gives the commit history you need, the rest (eg "When running 4.13-rc1") does not belong in the commit log.

Updated as "After enabling the ITS NUMA support on D05, I got the boot log:"

Quoted 27 lines
Quoted 18 lines
[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

Quoted 8 lines
[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Quoted 4 lines

Question (unrelated): how are PCI devices (or better PCI host bridges) mapped to ITSs ? I ask because in IORT we currently ignore the notion of ITS groups - so it is just out of curiosity (I suspect you have a static 1:1 mapping PCI-host-bridge->ITS).

Yes, on D05 we enabled 8 ITSs, and also have 8 PCI hostbridges, here is the IORT for D05:

https://github.com/hisilicon/OpenPlatformPkg/blob/bb17676e6c529732af8adf438fc2c8ceeb9b3271/Chips/Hisilicon/Hi1616/D05AcpiTables/D05Iort.asl

Quoted 8 lines
Quoted 8 lines
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

Quoted 7 lines
Quoted 5 lines

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

  drivers/irqchip/irq-gic-v3-its.c | 39 ++++++++++++++++++++++++++++++++-------

Thanks!

Hanjun

#9 lore raw
Quoted 45 lines · Hanjun Guo
Quoted 8 lines · Lorenzo Pieralisi
Quoted 3 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

Nit: You should stick to what the problem is and why you need to solve it, "Fixes:" tag gives the commit history you need, the rest (eg "When running 4.13-rc1") does not belong in the commit log.

Updated as "After enabling the ITS NUMA support on D05, I got the boot log:"

Quoted 27 lines
Quoted 18 lines
[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

Quoted 8 lines
[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Quoted 4 lines

Question (unrelated): how are PCI devices (or better PCI host bridges) mapped to ITSs ? I ask because in IORT we currently ignore the notion of ITS groups - so it is just out of curiosity (I suspect you have a static 1:1 mapping PCI-host-bridge->ITS).

Quoted 4 lines

Yes, on D05 we enabled 8 ITSs, and also have 8 PCI hostbridges, here is the IORT for D05:

https://github.com/hisilicon/OpenPlatformPkg/blob/bb17676e6c529732af8adf438fc2c8ceeb9b3271/Chips/Hisilicon/Hi1616/D05AcpiTables/D05Iort.asl

On a further side note, do the SMMUs really have no interrupts, or is that just a hack to avoid MBIgen-related problems? Now that we have working probe-deferral for IOMMU masters, it ought to be possible to address any dependency by deferring the SMMU itself until the IRQs are available. At a glance I guess ACPI doesn't make it as easy as of_irq_get() does, but it might be worth looking into.

Robin.

Quoted 25 lines
Quoted 12 lines
Quoted 12 lines
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity
case;
- Free the its_srat_maps after ITS probing.

Quoted 4 lines
Quoted 2 lines
  drivers/irqchip/irq-gic-v3-its.c | 39

++++++++++++++++++++++++++++++++-------

Thanks!

Hanjun

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#10 lore raw

Hi Robin,

Quoted 49 lines · Robin Murphy
Quoted 48 lines · Hanjun Guo
Quoted 8 lines · Lorenzo Pieralisi
Quoted 3 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

Nit: You should stick to what the problem is and why you need to solve it, "Fixes:" tag gives the commit history you need, the rest (eg "When running 4.13-rc1") does not belong in the commit log.

Updated as "After enabling the ITS NUMA support on D05, I got the boot log:"

Quoted 27 lines
Quoted 18 lines
[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

Quoted 8 lines
[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Quoted 4 lines

Question (unrelated): how are PCI devices (or better PCI host bridges) mapped to ITSs ? I ask because in IORT we currently ignore the notion of ITS groups - so it is just out of curiosity (I suspect you have a static 1:1 mapping PCI-host-bridge->ITS).

Yes, on D05 we enabled 8 ITSs, and also have 8 PCI hostbridges, here is the IORT for D05:

Quoted 8 lines
Quoted 1 line

https://github.com/hisilicon/OpenPlatformPkg/blob/bb17676e6c529732af8adf438fc2c8ceeb9b3271/Chips/Hisilicon/Hi1616/D05AcpiTables/D05Iort.asl

On a further side note, do the SMMUs really have no interrupts, or is that just a hack to avoid MBIgen-related problems? Now that we have working probe-deferral for IOMMU masters, it ought to be possible to address any dependency by deferring the SMMU itself until the IRQs are available. At a glance I guess ACPI doesn't make it as easy as of_irq_get() does, but it might be worth looking into.

SMMUs on D05 have interrupts as SMMU spec defined, but as you said they are routed to MBIgen.

For now, IORT can support two types of interrupt for SMMU, one is SPI which connect to GICD, the other one is using MSI which describing the mapping of smmu dev id to ITS.

So interrupts connecting to MBIgen or other interrupt controller are not supported, but I investigated that for a while and I think we can update the IORT table to support other interrupt controllers by introducing "ACPI device object full path name" in the IORT that the SMMU interrupts are referring.

Thanks
Hanjun

#11 lore raw
In reply to Hanjun Guo
Quoted 52 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

 drivers/irqchip/irq-gic-v3-its.c | 39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +0 -0
index 3ccdf76..1d692aa 100644
@@ -1847,13 +1847,16 @@ struct its_srat_map {
 	u32	its_id;
 };
 

drivers/irqchip/irq-gic-v3-its.c struct its_srat_map { · line 1858

Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +3 -1
-static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata;
+static struct its_srat_map *its_srat_maps __initdata;
 static int its_in_srat __initdata;
 
 static int __init acpi_get_its_numa_node(u32 its_id)
 {
 	int i;
 
+	if (!its_srat_maps)
+		return NUMA_NO_NODE;

Question: Does !its_srat_maps always imply its_in_srat == 0, so we could just fall through the for loop and return NUMA_NO_NODE without this check?

Or should we be safe/explicit/or falling through loops is a bad coding style?

Cheers,
John

Quoted 75 lines
drivers/irqchip/irq-gic-v3-its.c +29 -6
+
 	for (i = 0; i < its_in_srat; i++) {
 		if (its_id == its_srat_maps[i].its_id)
 			return its_srat_maps[i].numa_node;
@@ -1861,6 +1864,12 @@ static int __init acpi_get_its_numa_node(u32 its_id)
 	return NUMA_NO_NODE;
 }
 
+static int __init gic_acpi_match_srat_its(struct acpi_subtable_header *header,
+					  const unsigned long end)
+{
+	return 0;
+}
+
 static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 			 const unsigned long end)
 {
@@ -1877,12 +1886,6 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 		return -EINVAL;
 	}
 
-	if (its_in_srat >= MAX_NUMNODES) {
-		pr_err("SRAT: ITS affinity exceeding max count[%d]\n",
-				MAX_NUMNODES);
-		return -EINVAL;
-	}
-
 	node = acpi_map_pxm_to_node(its_affinity->proximity_domain);
 
 	if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) {
@@ -1901,14 +1904,35 @@ static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header,
 
 static void __init acpi_table_parse_srat_its(void)
 {
+	int count;
+
+	count = acpi_table_parse_entries(ACPI_SIG_SRAT,
+			sizeof(struct acpi_table_srat),
+			ACPI_SRAT_TYPE_GIC_ITS_AFFINITY,
+			gic_acpi_match_srat_its, 0);
+	if (count <= 0)
+		return;
+
+	its_srat_maps = kmalloc(count * sizeof(struct its_srat_map),
+				GFP_KERNEL);
+	if (!its_srat_maps)
+		return;
+
 	acpi_table_parse_entries(ACPI_SIG_SRAT,
 			sizeof(struct acpi_table_srat),
 			ACPI_SRAT_TYPE_GIC_ITS_AFFINITY,
 			gic_acpi_parse_srat_its, 0);
 }
+
+/* free the its_srat_maps after ITS probing */
+static void __init acpi_its_srat_maps_free(void)
+{
+	kfree(its_srat_maps);
+}
 #else
 static void __init acpi_table_parse_srat_its(void)	{ }
 static int __init acpi_get_its_numa_node(u32 its_id) { return NUMA_NO_NODE; }
+static void __init acpi_its_srat_maps_free(void) { }
 #endif
 
 static int __init gic_acpi_parse_madt_its(struct acpi_subtable_header *header,
@@ -1955,6 +1979,7 @@ static void __init its_acpi_probe(void)
 	acpi_table_parse_srat_its();
 	acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR,
 			      gic_acpi_parse_madt_its, 0);
+	acpi_its_srat_maps_free();
 }
 #else
 static void __init its_acpi_probe(void) { }
#12 lore raw
Quoted 63 lines · John Garry
Quoted 62 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

 drivers/irqchip/irq-gic-v3-its.c | 39 
++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +1 -1
index 3ccdf76..1d692aa 100644
@@ -1847,13 +1847,16 @@ struct its_srat_map {
     u32    its_id;
 };
 
-static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata;
+static struct its_srat_map *its_srat_maps __initdata;
 static int its_in_srat __initdata;
 
 static int __init acpi_get_its_numa_node(u32 its_id)
 {
     int i;
 
Quoted 8 lines

drivers/irqchip/irq-gic-v3-its.c struct its_srat_map { · line 1858

Quoted 2 lines
drivers/irqchip/irq-gic-v3-its.c +2 -0
+    if (!its_srat_maps)
+        return NUMA_NO_NODE;

Question: Does !its_srat_maps always imply its_in_srat == 0, so we could just fall through the for loop and return NUMA_NO_NODE without this check?

Or should we be safe/explicit/or falling through loops is a bad coding style?

Hmm, you are right, I missed that point, its_in_srat will always be 0 if its_srat_maps be NULL, removed the NULL check and tested it on D03 (without ITS NUMA) and D03 boots OK, will remove the check in the new version.

Thanks
Hanjun

#13 lore raw
In reply to John Garry
Quoted 63 lines · John Garry
Quoted 62 lines · Hanjun Guo

From: Hanjun Guo <[email protected]>

When running 4.13-rc1 on top of D05, I got the boot log:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: ITS affinity exceeding max count[4]

This is wrong on D05 as we have 8 ITSes with 4 NUMA nodes.

So dynamically alloc the memory needed instead of using its_srat_maps[MAX_NUMNODES], which count the number of ITS entry(ies) in SRAT and alloc its_srat_maps as needed, then build the mapping of numa node to ITS ID. Of course, its_srat_maps will be freed after ITS probing because we don't need that after boot.

After doing this, I got what I wanted:

[    0.000000] SRAT: PXM 0 -> ITS 0 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 1 -> Node 0
[    0.000000] SRAT: PXM 0 -> ITS 2 -> Node 0
[    0.000000] SRAT: PXM 1 -> ITS 3 -> Node 1
[    0.000000] SRAT: PXM 2 -> ITS 4 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 5 -> Node 2
[    0.000000] SRAT: PXM 2 -> ITS 6 -> Node 2
[    0.000000] SRAT: PXM 3 -> ITS 7 -> Node 3
Fixes dbd2b8267233 ("irqchip/gic-v3-its: Add ACPI NUMA node mapping")
Cc Ganapatrao Kulkarni <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Marc Zyngier <[email protected]>

---

v1->v2:
- Add NULL check in acpi_get_its_numa_node() for no ITS affinity case;
- Free the its_srat_maps after ITS probing.

 drivers/irqchip/irq-gic-v3-its.c | 39 
++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +1 -1
index 3ccdf76..1d692aa 100644
@@ -1847,13 +1847,16 @@ struct its_srat_map {
     u32    its_id;
 };
 
-static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata;
+static struct its_srat_map *its_srat_maps __initdata;
 static int its_in_srat __initdata;
 
 static int __init acpi_get_its_numa_node(u32 its_id)
 {
     int i;
 
Quoted 8 lines

drivers/irqchip/irq-gic-v3-its.c struct its_srat_map { · line 1858

Quoted 2 lines
drivers/irqchip/irq-gic-v3-its.c +2 -0
+    if (!its_srat_maps)
+        return NUMA_NO_NODE;

Question: Does !its_srat_maps always imply its_in_srat == 0, so we could just fall through the for loop and return NUMA_NO_NODE without this check?

Or should we be safe/explicit/or falling through loops is a bad coding style?

Hmm, you are right, I missed that point, its_in_srat will always be 0 if its_srat_maps be NULL, removed the NULL check and tested it on D03 (without ITS NUMA) and D03 boots OK, will remove the check in the new version.

Thanks
Hanjun