Skip to contentSkip to conversation

Add support for parsing per CPU Redistributor entry

PATCH Superseded Shanker Donthineni 2 participants 25 messages Jun 18, 2016 – Jun 22, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add support for parsing per CPU Redistributor entry

The current driver doesn't support parsing Redistributor entries that are described in the MADT GICC table. Not all the GIC implementors places the Redistributor regions in the always-on power domain. On systems, the UEFI firmware should describe Redistributor base address in the associated GIC CPU Interface (GICC) instead of GIC Redistributor (GICR) table.

The maximum number of mmio handlers and struct vgic_rdist_region that holds Redistributor addresses are allocated through a static array with hardcoded size. I don't think this is the right approach and is not scalable for implementing features like this. I have decided to convert static to dynamic allocation based on comments from the below link.

https://patchwork.kernel.org/patch/9163435/

Patches #1, #2 and #3 adds support for parsing not always-on power domain Redistributor regions.

Patches #4, #5, #6, #7 and #8 refactors the code and allocates the memory for mmio handlers and vgic_rdist_region based on the number of Redistributors required for dom0/domU instead of hardcoded values.

This pacthset is created on tip of Julien's branch http://xenbits.xen.org/gitweb/?p=people/julieng/xen-unstable.git;a=shortlog;h=refs/heads/irq-routing-acpi-rfc

Shanker Donthineni (8):
arm/gic-v3: Add a separate function for mapping GICD region arm/gic-v3: Fold GICR subtable parsing into a new function arm/gic-v3: Parse per-cpu redistributor entry in GICC subtable xen/arm: vgic: Use dynamic memory allocation for vgic_rdist_region arm/gic-v3: Remove an unused macro MAX_RDIST_COUNT
arm: vgic: Split vgic_domain_init() functionality into two functions arm/mmio: Use separate memory allocation for mmio handlers arm/vgic: Change fixed number of mmio handlers to variable number

 xen/arch/arm/domain.c             |  12 ++-
 xen/arch/arm/gic-v3.c             | 162 ++++++++++++++++++++++++++++----------
 xen/arch/arm/io.c                 |  14 +++-
 xen/arch/arm/vgic-v2.c            |  16 +++-
 xen/arch/arm/vgic-v3.c            |  65 ++++++++++-----
 xen/arch/arm/vgic.c               |   7 ++
 xen/include/asm-arm/domain.h      |  13 +--
 xen/include/asm-arm/gic.h         |   3 +-
 xen/include/asm-arm/gic_v3_defs.h |   1 +
 xen/include/asm-arm/mmio.h        |   6 +-
 xen/include/asm-arm/vgic.h        |   5 ++
 11 files changed, 226 insertions(+), 78 deletions(-)
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw

PATCH 1/8 arm/gic-v3: Add a separate function for mapping GICD region

Move the code that validates base address and does ioremap of GIC distributor region to a separate function. Later patches need to access the GICD region inside function gicv3_acpi_init() for finding per CPU Redistributor size.

---
 xen/arch/arm/gic-v3.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
xen/arch/arm/gic-v3.c +13 -10
index 8d3f149..ab1f380 100644
@@ -1169,6 +1169,17 @@ static void __init gicv3_init_v2(void)
     vgic_v2_setup_hw(dbase, cbase, csize, vbase, 0);
 }
 
+static void __init gicv3_ioremap_distributor(paddr_t dist_paddr)
+{
+    if ( (dist_paddr & ~PAGE_MASK) )
+        panic("GICv3:  Found unaligned distributor address %"PRIpaddr"",
+              dbase);
+
+    gicv3.map_dbase = ioremap_nocache(dist_paddr, SZ_64K);
+    if ( !gicv3.map_dbase )
+        panic("GICv3: Failed to ioremap for GIC distributor\n");
+}
+
 static void __init gicv3_dt_init(void)
 {
     struct rdist_region *rdist_regs;
@@ -1179,9 +1190,7 @@ static void __init gicv3_dt_init(void)
     if ( res )
         panic("GICv3: Cannot find a valid distributor address");
 
-    if ( (dbase & ~PAGE_MASK) )
-        panic("GICv3:  Found unaligned distributor address %"PRIpaddr"",
-              dbase);
+    gicv3_ioremap_distributor(dbase);
 
     if ( !dt_property_read_u32(node, "#redistributor-regions",
                 &gicv3.rdist_count) )
@@ -1415,9 +1424,7 @@ static void __init gicv3_acpi_init(void)
     if ( count <= 0 )
         panic("GICv3: No valid GICD entries exists");
 
-    if ( (dbase & ~PAGE_MASK) )
-        panic("GICv3: Found unaligned distributor address %"PRIpaddr"",
-              dbase);
+    gicv3_ioremap_distributor(dbase);
 
     /* Get number of redistributor */
     count = acpi_parse_entries(ACPI_SIG_MADT, sizeof(struct acpi_table_madt),
@@ -1491,10 +1498,6 @@ static int __init gicv3_init(void)
     else
         gicv3_acpi_init();
 
-    gicv3.map_dbase = ioremap_nocache(dbase, SZ_64K);
-    if ( !gicv3.map_dbase )
-        panic("GICv3: Failed to ioremap for GIC distributor\n");
-
     reg = readl_relaxed(GICD + GICD_PIDR2) & GIC_PIDR2_ARCH_MASK;
     if ( reg != GIC_PIDR2_ARCH_GICv3 && reg != GIC_PIDR2_ARCH_GICv4 )
          panic("GICv3: no distributor detected\n");
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH 1/8] arm/gic-v3: Add a separate function for mapping GICD region

Hello Shanker,

Quoted 4 lines · Shanker Donthineni

Move the code that validates base address and does ioremap of GIC distributor region to a separate function. Later patches need to access the GICD region inside function gicv3_acpi_init() for finding per CPU Redistributor size.

This patch contains two things:
- A clean up: I.e moving the validation/ioremap in a function
- Calling ioremap map earlier

The latter is the most important point of this patch, not the clean up. However based on your commit message/title, only the clean up matter.

Please reword the commit message/title to make clear what matters.

Quoted 11 lines
---
  xen/arch/arm/gic-v3.c | 23 +++++++++++++----------
  1 file changed, 13 insertions(+), 10 deletions(-)
xen/arch/arm/gic-v3.c +0 -0
index 8d3f149..ab1f380 100644

xen/arch/arm/gic-v3.c static void __init gicv3_init_v2(void) · line 1174

Quoted 6 lines
xen/arch/arm/gic-v3.c +3 -0
@@ -1169,6 +1169,17 @@ static void __init gicv3_init_v2(void)
      vgic_v2_setup_hw(dbase, cbase, csize, vbase, 0);
  }
 
+static void __init gicv3_ioremap_distributor(paddr_t dist_paddr)
+{
+    if ( (dist_paddr & ~PAGE_MASK) )

The second pair of brackets is pointless.

xen/arch/arm/gic-v3.c static void __init gicv3_init_v2(void) · line 1182

Quoted 8 lines
xen/arch/arm/gic-v3.c +8 -0
+        panic("GICv3:  Found unaligned distributor address %"PRIpaddr"",
+              dbase);
+
+    gicv3.map_dbase = ioremap_nocache(dist_paddr, SZ_64K);
+    if ( !gicv3.map_dbase )
+        panic("GICv3: Failed to ioremap for GIC distributor\n");
+}
+

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#3 lore raw

PATCH 2/8 arm/gic-v3: Fold GICR subtable parsing into a new function

In reply to Shanker Donthineni

Add a new function for parsing GICR subtable and move the code that is specific to GICR table to new function without changing the function gicv3_acpi_init() behavior.

---
 xen/arch/arm/gic-v3.c | 64 +++++++++++++++++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 22 deletions(-)
xen/arch/arm/gic-v3.c +42 -22
index ab1f380..af12ebc 100644
@@ -1387,6 +1387,36 @@ gic_acpi_parse_madt_distributor(struct acpi_subtable_header *header,
 
     return 0;
 }
+
+static int __init
+gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header,
+                                  const unsigned long end)
+{
+    struct acpi_madt_generic_redistributor *rdist;
+    struct rdist_region *region;
+
+    region = gicv3.rdist_regions + gicv3.rdist_count;
+    rdist = (struct acpi_madt_generic_redistributor *)header;
+    if ( BAD_MADT_ENTRY(rdist, end) )
+        return -EINVAL;
+
+    if ( !rdist->base_address || !rdist->length )
+        return -EINVAL;
+
+    region->base = rdist->base_address;
+    region->size = rdist->length;
+
+    region->map_base = ioremap_nocache(region->base, region->size);
+    if ( !region->map_base )
+    {
+        printk("Unable to map GICR registers\n");
+        return -ENOMEM;
+    }
+    gicv3.rdist_count++;
+
+    return 0;
+}
+
 static int __init
 gic_acpi_get_madt_redistributor_num(struct acpi_subtable_header *header,
                                     const unsigned long end)
@@ -1402,7 +1432,7 @@ static void __init gicv3_acpi_init(void)
     struct acpi_table_header *table;
     struct rdist_region *rdist_regs;
     acpi_status status;
-    int count, i;
+    int count;
 
     status = acpi_get_table(ACPI_SIG_MADT, 0, &table);
 
@@ -1433,37 +1463,27 @@ static void __init gicv3_acpi_init(void)
     if ( count <= 0 )
         panic("GICv3: No valid GICR entries exists");
 
-    gicv3.rdist_count = count;
-
-    if ( gicv3.rdist_count > MAX_RDIST_COUNT )
+    if ( count > MAX_RDIST_COUNT )
         panic("GICv3: Number of redistributor regions is more than"
               "%d (Increase MAX_RDIST_COUNT!!)\n", MAX_RDIST_COUNT);
 
-    rdist_regs = xzalloc_array(struct rdist_region, gicv3.rdist_count);
+    rdist_regs = xzalloc_array(struct rdist_region, count);
     if ( !rdist_regs )
         panic("GICv3: Failed to allocate memory for rdist regions\n");
 
-    for ( i = 0; i < gicv3.rdist_count; i++ )
-    {
-        struct acpi_subtable_header *header;
-        struct acpi_madt_generic_redistributor *gic_rdist;
-
-        header = acpi_table_get_entry_madt(ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR,
-                                           i);
-        if ( !header )
-            panic("GICv3: Can't get GICR entry");
-
-        gic_rdist =
-           container_of(header, struct acpi_madt_generic_redistributor, header);
-        rdist_regs[i].base = gic_rdist->base_address;
-        rdist_regs[i].size = gic_rdist->length;
-    }
+    gicv3.rdist_regions = rdist_regs;
+
+    /* Parse always-on power domain Re-distributor entries */
+    count = acpi_parse_entries(ACPI_SIG_MADT,
+                               sizeof(struct acpi_table_madt),
+                               gic_acpi_parse_madt_redistributor, table,
+                               ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR, count);
+    if ( count <= 0 )
+        panic("GICv3: Can't get Redistributor entry");
 
     /* The vGIC code requires the region to be sorted */
     sort(rdist_regs, gicv3.rdist_count, sizeof(*rdist_regs), cmp_rdist, NULL);
 
-    gicv3.rdist_regions= rdist_regs;
-
     /* Collect CPU base addresses */
     count = acpi_parse_entries(ACPI_SIG_MADT, sizeof(struct acpi_table_madt),
                                gic_acpi_parse_madt_cpu, table,
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#4 lore raw

Re: [PATCH 2/8] arm/gic-v3: Fold GICR subtable parsing into a new function

Hello Shanker,

Quoted 27 lines · Shanker Donthineni

Add a new function for parsing GICR subtable and move the code that is specific to GICR table to new function without changing the function gicv3_acpi_init() behavior.

---
  xen/arch/arm/gic-v3.c | 64 +++++++++++++++++++++++++++++++++------------------
  1 file changed, 42 insertions(+), 22 deletions(-)
xen/arch/arm/gic-v3.c +10 -0
index ab1f380..af12ebc 100644
@@ -1387,6 +1387,36 @@ gic_acpi_parse_madt_distributor(struct acpi_subtable_header *header,
 
      return 0;
  }
+
+static int __init
+gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header,
+                                  const unsigned long end)
+{
+    struct acpi_madt_generic_redistributor *rdist;
+    struct rdist_region *region;
+
+    region = gicv3.rdist_regions + gicv3.rdist_count;
+    rdist = (struct acpi_madt_generic_redistributor *)header;

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_distributor(struct acpi_subtable_header *header, · line 1409

Quoted 10 lines
xen/arch/arm/gic-v3.c +10 -0
+    if ( BAD_MADT_ENTRY(rdist, end) )
+        return -EINVAL;
+
+    if ( !rdist->base_address || !rdist->length )
+        return -EINVAL;
+
+    region->base = rdist->base_address;
+    region->size = rdist->length;
+
+    region->map_base = ioremap_nocache(region->base, region->size);

In the commit message you said there is no functional change, however the remapping is not part of gicv3_acpi_init. So why did you add this line here?

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_distributor(struct acpi_subtable_header *header, · line 1419

Quoted 10 lines
xen/arch/arm/gic-v3.c +10 -0
+    if ( !region->map_base )
+    {
+        printk("Unable to map GICR registers\n");
+        return -ENOMEM;
+    }
+    gicv3.rdist_count++;
+
+    return 0;
+}
+

[...]

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#5 lore raw

Re: [PATCH 2/8] arm/gic-v3: Fold GICR subtable parsing into a new function

Quoted 36 lines · Julien Grall

Hello Shanker,

Quoted 7 lines · Shanker Donthineni

Add a new function for parsing GICR subtable and move the code that is specific to GICR table to new function without changing the function gicv3_acpi_init() behavior.

---
  xen/arch/arm/gic-v3.c | 64

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

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_distributor(struct

Quoted 7 lines
  1 file changed, 42 insertions(+), 22 deletions(-)
xen/arch/arm/gic-v3.c +0 -0
index ab1f380..af12ebc 100644
@@ -1387,6 +1387,36 @@ gic_acpi_parse_madt_distributor(struct

acpi_subtable_header *header,

Quoted 17 lines
xen/arch/arm/gic-v3.c +14 -0
      return 0;
  }
+
+static int __init
+gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header,
+                                  const unsigned long end)
+{
+    struct acpi_madt_generic_redistributor *rdist;
+    struct rdist_region *region;
+
+    region = gicv3.rdist_regions + gicv3.rdist_count;
+    rdist = (struct acpi_madt_generic_redistributor *)header;
+    if ( BAD_MADT_ENTRY(rdist, end) )
+        return -EINVAL;
+
+    if ( !rdist->base_address || !rdist->length )
Quoted 9 lines

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_distributor(struct acpi_subtable_header *header, · line 1409

Quoted 6 lines
xen/arch/arm/gic-v3.c +6 -0
+        return -EINVAL;
+
+    region->base = rdist->base_address;
+    region->size = rdist->length;
+
+    region->map_base = ioremap_nocache(region->base, region->size);

In the commit message you said there is no functional change, however the remapping is not part of gicv3_acpi_init. So why did you add this line here?

Thanks for catching coding bug, it was my mistake and this code should not be here.

Quoted 15 lines

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_distributor(struct acpi_subtable_header *header, · line 1419

Quoted 10 lines
xen/arch/arm/gic-v3.c +10 -0
+    if ( !region->map_base )
+    {
+        printk("Unable to map GICR registers\n");
+        return -ENOMEM;
+    }
+    gicv3.rdist_count++;
+
+    return 0;
+}
+

[...]

Regards,

Signature · 9 lines
Shanker Donthineni
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#6 lore raw

PATCH 3/8 arm/gic-v3: Parse per-cpu redistributor entry in GICC subtable

In reply to Shanker Donthineni

The redistributor address can be specified either as part of GICC or GICR subtable depending on the power domain. The current driver doesn't support parsing redistributor entry that is defined in GICC subtable. The GIC CPU subtable entry holds the associated Redistributor base address if it is not on always-on power domain.

This patch adds necessary code to handle both types of Redistributors base addresses.

---
 xen/arch/arm/gic-v3.c             | 97 ++++++++++++++++++++++++++++++++-------
 xen/include/asm-arm/gic.h         |  2 +
 xen/include/asm-arm/gic_v3_defs.h |  1 +
 3 files changed, 83 insertions(+), 17 deletions(-)
xen/arch/arm/gic-v3.c +80 -17
index af12ebc..42cf848 100644
@@ -659,6 +659,10 @@ static int __init gicv3_populate_rdist(void)
                         smp_processor_id(), i, ptr);
                 return 0;
             }
+
+            if ( gicv3.rdist_regions[i].single_rdist )
+                break;
+
             if ( gicv3.rdist_stride )
                 ptr += gicv3.rdist_stride;
             else
@@ -1282,6 +1286,11 @@ static int gicv3_iomem_deny_access(const struct domain *d)
 }
 
 #ifdef CONFIG_ACPI
+static bool gic_dist_supports_dvis(void)
+{
+    return !!(readl_relaxed(GICD + GICD_TYPER) & GICD_TYPER_DVIS);
+}
+
 static int gicv3_make_hwdom_madt(const struct domain *d, u32 offset)
 {
     struct acpi_subtable_header *header;
@@ -1393,18 +1402,39 @@ gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header,
                                   const unsigned long end)
 {
     struct acpi_madt_generic_redistributor *rdist;
+    struct acpi_madt_generic_interrupt *processor;
     struct rdist_region *region;
 
     region = gicv3.rdist_regions + gicv3.rdist_count;
-    rdist = (struct acpi_madt_generic_redistributor *)header;
-    if ( BAD_MADT_ENTRY(rdist, end) )
-        return -EINVAL;
+    if ( header->type == ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR )
+    {
+        rdist = (struct acpi_madt_generic_redistributor *)header;
+        if ( BAD_MADT_ENTRY(rdist, end) )
+            return -EINVAL;
 
-    if ( !rdist->base_address || !rdist->length )
-        return -EINVAL;
+        if ( !rdist->base_address || !rdist->length )
+            return -EINVAL;
+
+        region->base = rdist->base_address;
+        region->size = rdist->length;
+    }
+    else if ( header->type == ACPI_MADT_TYPE_GENERIC_INTERRUPT )
+    {
+        processor = (struct acpi_madt_generic_interrupt *)header;
+        if ( BAD_MADT_ENTRY(processor, end) )
+            return -EINVAL;
+
+        if ( !(processor->flags & ACPI_MADT_ENABLED) )
+            return 0;
+
+        if ( !processor->gicr_base_address )
+            return -EINVAL;
+
+        region->base = processor->gicr_base_address;
+        region->size = gic_dist_supports_dvis() ? SZ_256K : SZ_128K;
+	region->single_rdist = true;
+   }
 
-    region->base = rdist->base_address;
-    region->size = rdist->length;
 
     region->map_base = ioremap_nocache(region->base, region->size);
     if ( !region->map_base )
@@ -1412,6 +1442,7 @@ gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header,
         printk("Unable to map GICR registers\n");
         return -ENOMEM;
     }
+
     gicv3.rdist_count++;
 
     return 0;
@@ -1421,9 +1452,22 @@ static int __init
 gic_acpi_get_madt_redistributor_num(struct acpi_subtable_header *header,
                                     const unsigned long end)
 {
-    /* Nothing to do here since it only wants to get the number of GIC
-     * redistributors.
-     */
+    struct acpi_madt_generic_redistributor *rdist;
+    struct acpi_madt_generic_interrupt *cpuif;
+
+    if ( header->type == ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR )
+    {
+	 rdist = (struct acpi_madt_generic_redistributor *)header;
+	 if ( BAD_MADT_ENTRY(rdist, end) || !rdist->base_address )
+	     return -EINVAL;
+    }
+    else if ( header->type == ACPI_MADT_TYPE_GENERIC_INTERRUPT )
+    {
+	 cpuif = (struct acpi_madt_generic_interrupt *)header;
+	 if ( BAD_MADT_ENTRY(cpuif, end) || !cpuif->gicr_base_address )
+	     return -EINVAL;
+    }
+
     return 0;
 }
 
@@ -1431,6 +1475,7 @@ static void __init gicv3_acpi_init(void)
 {
     struct acpi_table_header *table;
     struct rdist_region *rdist_regs;
+    bool gicr_table = true;
     acpi_status status;
     int count;
 
@@ -1460,8 +1505,18 @@ static void __init gicv3_acpi_init(void)
     count = acpi_parse_entries(ACPI_SIG_MADT, sizeof(struct acpi_table_madt),
                                gic_acpi_get_madt_redistributor_num, table,
                                ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR, 0);
-    if ( count <= 0 )
-        panic("GICv3: No valid GICR entries exists");
+
+    /* Count the total number of CPU interface entries */
+    if (count <= 0) {
+        count = acpi_parse_entries(ACPI_SIG_MADT,
+                                   sizeof(struct acpi_table_madt),
+                                   gic_acpi_get_madt_redistributor_num,
+                                   table, ACPI_MADT_TYPE_GENERIC_INTERRUPT, 0);
+        if (count <= 0)
+            panic("GICv3: No valid GICR entries exists");
+
+        gicr_table = false;
+    }
 
     if ( count > MAX_RDIST_COUNT )
         panic("GICv3: Number of redistributor regions is more than"
@@ -1473,11 +1528,19 @@ static void __init gicv3_acpi_init(void)
 
     gicv3.rdist_regions = rdist_regs;
 
-    /* Parse always-on power domain Re-distributor entries */
-    count = acpi_parse_entries(ACPI_SIG_MADT,
-                               sizeof(struct acpi_table_madt),
-                               gic_acpi_parse_madt_redistributor, table,
-                               ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR, count);
+    if ( gicr_table )
+        /* Parse always-on power domain Re-distributor entries */
+        count = acpi_parse_entries(ACPI_SIG_MADT,
+                                   sizeof(struct acpi_table_madt),
+                                   gic_acpi_parse_madt_redistributor, table,
+                                   ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR, count);
+    else
+        /* Parse Re-distributor entries described in CPU interface table */
+        count = acpi_parse_entries(ACPI_SIG_MADT,
+                                   sizeof(struct acpi_table_madt),
+                                   gic_acpi_parse_madt_redistributor, table,
+                                   ACPI_MADT_TYPE_GENERIC_INTERRUPT, count);
+
     if ( count <= 0 )
         panic("GICv3: Can't get Redistributor entry");
 
xen/include/asm-arm/gic.h +2 -0
index 44b9ef6..7f9ad86 100644
@@ -101,6 +101,8 @@
 #define GICD_TYPE_CPUS_SHIFT 5
 #define GICD_TYPE_CPUS  0x0e0
 #define GICD_TYPE_SEC   0x400
+#define GICD_TYPER_LPIS (1U << 17)
+#define GICD_TYPER_DVIS (1U << 18)
 
 #define GICC_CTL_ENABLE 0x1
 #define GICC_CTL_EOI    (0x1 << 9)
xen/include/asm-arm/gic_v3_defs.h +1 -0
index 6d98491..6bd25a5 100644
@@ -141,6 +141,7 @@ struct rdist_region {
     paddr_t base;
     paddr_t size;
     void __iomem *map_base;
+    bool single_rdist;
 };
 
 #endif /* __ASM_ARM_GIC_V3_DEFS_H__ */
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#7 lore raw

Re: [PATCH 3/8] arm/gic-v3: Parse per-cpu redistributor entry in GICC subtable

Hello Shanker,

Quoted 32 lines · Shanker Donthineni

The redistributor address can be specified either as part of GICC or GICR subtable depending on the power domain. The current driver doesn't support parsing redistributor entry that is defined in GICC subtable. The GIC CPU subtable entry holds the associated Redistributor base address if it is not on always-on power domain.

This patch adds necessary code to handle both types of Redistributors base addresses.

---
  xen/arch/arm/gic-v3.c             | 97 ++++++++++++++++++++++++++++++++-------
  xen/include/asm-arm/gic.h         |  2 +
  xen/include/asm-arm/gic_v3_defs.h |  1 +
  3 files changed, 83 insertions(+), 17 deletions(-)
xen/arch/arm/gic-v3.c +4 -0
index af12ebc..42cf848 100644
@@ -659,6 +659,10 @@ static int __init gicv3_populate_rdist(void)
                          smp_processor_id(), i, ptr);
                  return 0;
              }
+
+            if ( gicv3.rdist_regions[i].single_rdist )
+                break;
+
              if ( gicv3.rdist_stride )
                  ptr += gicv3.rdist_stride;
              else

xen/arch/arm/gic-v3.c static int gicv3_iomem_deny_access(const struct domain *d) · line 1289

Quoted 4 lines
xen/arch/arm/gic-v3.c +1 -0
@@ -1282,6 +1286,11 @@ static int gicv3_iomem_deny_access(const struct domain *d)
  }
 
  #ifdef CONFIG_ACPI
+static bool gic_dist_supports_dvis(void)

static inline and please use bool_t here.

Quoted 24 lines
xen/arch/arm/gic-v3.c +10 -3
+{
+    return !!(readl_relaxed(GICD + GICD_TYPER) & GICD_TYPER_DVIS);
+}
+
  static int gicv3_make_hwdom_madt(const struct domain *d, u32 offset)
  {
      struct acpi_subtable_header *header;
@@ -1393,18 +1402,39 @@ gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header,
                                    const unsigned long end)
  {
      struct acpi_madt_generic_redistributor *rdist;
+    struct acpi_madt_generic_interrupt *processor;
      struct rdist_region *region;
 
      region = gicv3.rdist_regions + gicv3.rdist_count;
-    rdist = (struct acpi_madt_generic_redistributor *)header;
-    if ( BAD_MADT_ENTRY(rdist, end) )
-        return -EINVAL;
+    if ( header->type == ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR )
+    {
+        rdist = (struct acpi_madt_generic_redistributor *)header;
+        if ( BAD_MADT_ENTRY(rdist, end) )
+            return -EINVAL;
 

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header, · line 1422

Quoted 10 lines
xen/arch/arm/gic-v3.c +8 -2
-    if ( !rdist->base_address || !rdist->length )
-        return -EINVAL;
+        if ( !rdist->base_address || !rdist->length )
+            return -EINVAL;
+
+        region->base = rdist->base_address;
+        region->size = rdist->length;
+    }
+    else if ( header->type == ACPI_MADT_TYPE_GENERIC_INTERRUPT )
+    {

Parsing the GICC and the redistributor is quite different. I would much prefer a function for parsing each table and an helper to add a new redistributor.

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header, · line 1434

Quoted 12 lines
xen/arch/arm/gic-v3.c +12 -0
+        processor = (struct acpi_madt_generic_interrupt *)header;
+        if ( BAD_MADT_ENTRY(processor, end) )
+            return -EINVAL;
+
+        if ( !(processor->flags & ACPI_MADT_ENABLED) )
+            return 0;
+
+        if ( !processor->gicr_base_address )
+            return -EINVAL;
+
+        region->base = processor->gicr_base_address;
+        region->size = gic_dist_supports_dvis() ? SZ_256K : SZ_128K;

Please explain in the commit message how you find the size. I would also prefer if you use (4 x SZ_64K) and (2 * SZ_64K) as we do in populate_rdist.

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header, · line 1435

Quoted 1 line
xen/arch/arm/gic-v3.c +1 -0
+	region->single_rdist = true;

The indentation looks wrong.

Quoted 10 lines
xen/arch/arm/gic-v3.c +1 -2
+   }
 
 
 
-    region->base = rdist->base_address;
-    region->size = rdist->length;
 
      region->map_base = ioremap_nocache(region->base, region->size);
      if ( !region->map_base )

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header, · line 1445

Quoted 4 lines
xen/arch/arm/gic-v3.c +1 -0
@@ -1412,6 +1442,7 @@ gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header,
          printk("Unable to map GICR registers\n");
          return -ENOMEM;
      }
+

Spurious change.

Quoted 16 lines
xen/arch/arm/gic-v3.c +6 -3
      gicv3.rdist_count++;
 
      return 0;
@@ -1421,9 +1452,22 @@ static int __init
  gic_acpi_get_madt_redistributor_num(struct acpi_subtable_header *header,
                                      const unsigned long end)
  {
-    /* Nothing to do here since it only wants to get the number of GIC
-     * redistributors.
-     */
+    struct acpi_madt_generic_redistributor *rdist;
+    struct acpi_madt_generic_interrupt *cpuif;
+
+    if ( header->type == ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR )
+    {
+	 rdist = (struct acpi_madt_generic_redistributor *)header;

xen/arch/arm/gic-v3.c static int __init · line 1470

Quoted 10 lines
xen/arch/arm/gic-v3.c +10 -0
+	 if ( BAD_MADT_ENTRY(rdist, end) || !rdist->base_address )
+	     return -EINVAL;
+    }
+    else if ( header->type == ACPI_MADT_TYPE_GENERIC_INTERRUPT )
+    {
+	 cpuif = (struct acpi_madt_generic_interrupt *)header;
+	 if ( BAD_MADT_ENTRY(cpuif, end) || !cpuif->gicr_base_address )
+	     return -EINVAL;
+    }
+

Ditto for the parsing.

Quoted 3 lines
xen/arch/arm/gic-v3.c +0 -0
      return 0;
  }
 

[...]

xen/include/asm-arm/gic.h line 104

Quoted 9 lines
xen/include/asm-arm/gic.h +1 -0
index 44b9ef6..7f9ad86 100644
@@ -101,6 +101,8 @@
  #define GICD_TYPE_CPUS_SHIFT 5
  #define GICD_TYPE_CPUS  0x0e0
  #define GICD_TYPE_SEC   0x400
+#define GICD_TYPER_LPIS (1U << 17)

This is not used by this patch. So please drop it.

Quoted 10 lines
xen/include/asm-arm/gic.h +1 -0
+#define GICD_TYPER_DVIS (1U << 18)
 
  #define GICC_CTL_ENABLE 0x1
  #define GICC_CTL_EOI    (0x1 << 9)
xen/include/asm-arm/gic_v3_defs.h +0 -0
index 6d98491..6bd25a5 100644

xen/include/asm-arm/gic_v3_defs.h struct rdist_region { · line 147

Quoted 7 lines
xen/include/asm-arm/gic_v3_defs.h +1 -0
@@ -141,6 +141,7 @@ struct rdist_region {
      paddr_t base;
      paddr_t size;
      void __iomem *map_base;
+    bool single_rdist;
  };
 
  #endif /* __ASM_ARM_GIC_V3_DEFS_H__ */

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#8 lore raw

Re: [PATCH 3/8] arm/gic-v3: Parse per-cpu redistributor entry in GICC subtable

Quoted 37 lines · Julien Grall

Hello Shanker,

Quoted 6 lines · Shanker Donthineni

The redistributor address can be specified either as part of GICC or GICR subtable depending on the power domain. The current driver doesn't support parsing redistributor entry that is defined in GICC subtable. The GIC CPU subtable entry holds the associated Redistributor base address if it is not on always-on power domain.

Quoted 6 lines

This patch adds necessary code to handle both types of Redistributors base addresses.

---
  xen/arch/arm/gic-v3.c             | 97

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

xen/arch/arm/gic-v3.c static int gicv3_iomem_deny_access(const struct

Quoted 20 lines
  xen/include/asm-arm/gic.h         |  2 +
  xen/include/asm-arm/gic_v3_defs.h |  1 +
  3 files changed, 83 insertions(+), 17 deletions(-)
xen/arch/arm/gic-v3.c +4 -0
index af12ebc..42cf848 100644
@@ -659,6 +659,10 @@ static int __init gicv3_populate_rdist(void)
                          smp_processor_id(), i, ptr);
                  return 0;
              }
+
+            if ( gicv3.rdist_regions[i].single_rdist )
+                break;
+
              if ( gicv3.rdist_stride )
                  ptr += gicv3.rdist_stride;
              else
@@ -1282,6 +1286,11 @@ static int gicv3_iomem_deny_access(const struct

domain *d)

Quoted 7 lines

xen/arch/arm/gic-v3.c static int gicv3_iomem_deny_access(const struct domain *d) · line 1289

Quoted 4 lines
xen/arch/arm/gic-v3.c +1 -0
  }
 
  #ifdef CONFIG_ACPI
+static bool gic_dist_supports_dvis(void)

static inline and please use bool_t here.

Still learning XEN coding style, I'll fix it.

Quoted 36 lines

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_redistributor(struct

Quoted 8 lines
xen/arch/arm/gic-v3.c +4 -0
+{
+    return !!(readl_relaxed(GICD + GICD_TYPER) & GICD_TYPER_DVIS);
+}
+
  static int gicv3_make_hwdom_madt(const struct domain *d, u32 offset)
  {
      struct acpi_subtable_header *header;
@@ -1393,18 +1402,39 @@ gic_acpi_parse_madt_redistributor(struct

acpi_subtable_header *header,

Quoted 16 lines
xen/arch/arm/gic-v3.c +6 -3
                                    const unsigned long end)
  {
      struct acpi_madt_generic_redistributor *rdist;
+    struct acpi_madt_generic_interrupt *processor;
      struct rdist_region *region;
 
      region = gicv3.rdist_regions + gicv3.rdist_count;
-    rdist = (struct acpi_madt_generic_redistributor *)header;
-    if ( BAD_MADT_ENTRY(rdist, end) )
-        return -EINVAL;
+    if ( header->type == ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR )
+    {
+        rdist = (struct acpi_madt_generic_redistributor *)header;
+        if ( BAD_MADT_ENTRY(rdist, end) )
+            return -EINVAL;
 

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header, · line 1422

Quoted 10 lines
xen/arch/arm/gic-v3.c +8 -2
-    if ( !rdist->base_address || !rdist->length )
-        return -EINVAL;
+        if ( !rdist->base_address || !rdist->length )
+            return -EINVAL;
+
+        region->base = rdist->base_address;
+        region->size = rdist->length;
+    }
+    else if ( header->type == ACPI_MADT_TYPE_GENERIC_INTERRUPT )
+    {
Quoted 2 lines

Parsing the GICC and the redistributor is quite different. I would much prefer a function for parsing each table and an helper to add a new redistributor.

I'll do.

Quoted 74 lines

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header, · line 1434

Quoted 12 lines
xen/arch/arm/gic-v3.c +12 -0
+        processor = (struct acpi_madt_generic_interrupt *)header;
+        if ( BAD_MADT_ENTRY(processor, end) )
+            return -EINVAL;
+
+        if ( !(processor->flags & ACPI_MADT_ENABLED) )
+            return 0;
+
+        if ( !processor->gicr_base_address )
+            return -EINVAL;
+
+        region->base = processor->gicr_base_address;
+        region->size = gic_dist_supports_dvis() ? SZ_256K : SZ_128K;

Please explain in the commit message how you find the size. I would also prefer if you use (4 x SZ_64K) and (2 * SZ_64K) as we do in populate_rdist.

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header, · line 1435

Quoted 1 line
xen/arch/arm/gic-v3.c +1 -0
+    region->single_rdist = true;

The indentation looks wrong.

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_redistributor(struct

Quoted 10 lines
xen/arch/arm/gic-v3.c +1 -2
+   }
 
 
 
-    region->base = rdist->base_address;
-    region->size = rdist->length;
 
      region->map_base = ioremap_nocache(region->base, region->size);
      if ( !region->map_base )
xen/arch/arm/gic-v3.c +0 -0
@@ -1412,6 +1442,7 @@ gic_acpi_parse_madt_redistributor(struct

acpi_subtable_header *header,

xen/arch/arm/gic-v3.c gic_acpi_parse_madt_redistributor(struct acpi_subtable_header *header, · line 1445

Quoted 4 lines
xen/arch/arm/gic-v3.c +1 -0
          printk("Unable to map GICR registers\n");
          return -ENOMEM;
      }
+

Spurious change.

xen/arch/arm/gic-v3.c static int __init · line 1452

Quoted 5 lines
xen/arch/arm/gic-v3.c +0 -0
      gicv3.rdist_count++;
 
      return 0;
@@ -1421,9 +1452,22 @@ static int __init
  gic_acpi_get_madt_redistributor_num(struct acpi_subtable_header

*header,

Quoted 11 lines
xen/arch/arm/gic-v3.c +6 -3
 const unsigned long end)
  {
-    /* Nothing to do here since it only wants to get the number of GIC
-     * redistributors.
-     */
+    struct acpi_madt_generic_redistributor *rdist;
+    struct acpi_madt_generic_interrupt *cpuif;
+
+    if ( header->type == ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR )
+    {
+     rdist = (struct acpi_madt_generic_redistributor *)header;

xen/arch/arm/gic-v3.c static int __init · line 1470

Quoted 10 lines
xen/arch/arm/gic-v3.c +10 -0
+     if ( BAD_MADT_ENTRY(rdist, end) || !rdist->base_address )
+         return -EINVAL;
+    }
+    else if ( header->type == ACPI_MADT_TYPE_GENERIC_INTERRUPT )
+    {
+     cpuif = (struct acpi_madt_generic_interrupt *)header;
+     if ( BAD_MADT_ENTRY(cpuif, end) || !cpuif->gicr_base_address )
+         return -EINVAL;
+    }
+

Ditto for the parsing.

Quoted 3 lines
xen/arch/arm/gic-v3.c +0 -0
      return 0;
  }
 

[...]

Quoted 12 lines

xen/include/asm-arm/gic.h line 104

Quoted 9 lines
xen/include/asm-arm/gic.h +1 -0
index 44b9ef6..7f9ad86 100644
@@ -101,6 +101,8 @@
  #define GICD_TYPE_CPUS_SHIFT 5
  #define GICD_TYPE_CPUS  0x0e0
  #define GICD_TYPE_SEC   0x400
+#define GICD_TYPER_LPIS (1U << 17)

This is not used by this patch. So please drop it.

I'll drop it.

Quoted 21 lines

Review

Quoted 5 lines
xen/include/asm-arm/gic.h +1 -0
+#define GICD_TYPER_DVIS (1U << 18)
 
  #define GICC_CTL_ENABLE 0x1
  #define GICC_CTL_EOI    (0x1 << 9)
(quoted diff) +0 -0

b/xen/include/asm-arm/gic_v3_defs.h

xen/include/asm-arm/gic_v3_defs.h struct rdist_region { · line 147

Quoted 12 lines

index 6d98491..6bd25a5 100644

xen/include/asm-arm/gic_v3_defs.h +1 -0
@@ -141,6 +141,7 @@ struct rdist_region {
      paddr_t base;
      paddr_t size;
      void __iomem *map_base;
+    bool single_rdist;
  };
 
  #endif /* __ASM_ARM_GIC_V3_DEFS_H__ */

Regards,

Signature · 9 lines
Shanker Donthineni
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#9 lore raw

Re: [PATCH 3/8] arm/gic-v3: Parse per-cpu redistributor entry in GICC subtable

Hello Shanker,

Quoted 38 lines · Shanker Donthineni
Quoted 37 lines · Julien Grall

Hello Shanker,

Quoted 6 lines · Shanker Donthineni

The redistributor address can be specified either as part of GICC or GICR subtable depending on the power domain. The current driver doesn't support parsing redistributor entry that is defined in GICC subtable. The GIC CPU subtable entry holds the associated Redistributor base address if it is not on always-on power domain.

Quoted 6 lines

This patch adds necessary code to handle both types of Redistributors base addresses.

---
  xen/arch/arm/gic-v3.c             | 97

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

xen/arch/arm/gic-v3.c static int gicv3_iomem_deny_access(const struct

Quoted 20 lines
  xen/include/asm-arm/gic.h         |  2 +
  xen/include/asm-arm/gic_v3_defs.h |  1 +
  3 files changed, 83 insertions(+), 17 deletions(-)
xen/arch/arm/gic-v3.c +4 -0
index af12ebc..42cf848 100644
@@ -659,6 +659,10 @@ static int __init gicv3_populate_rdist(void)
                          smp_processor_id(), i, ptr);
                  return 0;
              }
+
+            if ( gicv3.rdist_regions[i].single_rdist )
+                break;
+
              if ( gicv3.rdist_stride )
                  ptr += gicv3.rdist_stride;
              else
@@ -1282,6 +1286,11 @@ static int gicv3_iomem_deny_access(const struct

domain *d)

Quoted 8 lines
Quoted 7 lines

xen/arch/arm/gic-v3.c static int gicv3_iomem_deny_access(const struct domain *d) · line 1289

Quoted 4 lines
xen/arch/arm/gic-v3.c +1 -0
  }
 
  #ifdef CONFIG_ACPI
+static bool gic_dist_supports_dvis(void)

static inline and please use bool_t here.

Still learning XEN coding style, I'll fix it.

It looks like Xen is moving towards bool (see [1]). So you can keep bool here.

Regards,

[1] http://lists.xenproject.org/archives/html/xen-devel/2016-06/msg02807.html

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#10 lore raw

PATCH 4/8 xen/arm: vgic: Use dynamic memory allocation for vgic_rdist_region

In reply to Shanker Donthineni

The number of Re-distributor regions allowed for dom0 is hardcoded to a compile time macro MAX_RDIST_COUNT which is 4. On some systems, especially latest server chips might have more than 4 redistributors. Either we have to increase MAX_RDIST_COUNT to a bigger number or allocate memory based on number of redistributors that are found in MADT table. In the worst case scenario, the macro MAX_RDIST_COUNT should be equal to CONFIG_NR_CPUS in order to support per CPU Redistributors.

Increasing MAX_RDIST_COUNT has side effect, it blows 'struct domain' size and hits BUILD_BUG_ON() in domain build code path.

struct domain *alloc_domain_struct(void)

{
    struct domain *d;
    BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
    d = alloc_xenheap_pages(0, 0);
    if ( d == NULL )
        return NULL;

...

This patch uses the second approach to fix the BUILD_BUG().

---
 xen/arch/arm/vgic-v2.c       |  6 ++++++
 xen/arch/arm/vgic-v3.c       | 22 +++++++++++++++++++---
 xen/arch/arm/vgic.c          |  1 +
 xen/include/asm-arm/domain.h | 12 +++++++-----
 xen/include/asm-arm/vgic.h   |  2 ++
 5 files changed, 35 insertions(+), 8 deletions(-)
xen/arch/arm/vgic-v2.c +6 -0
index 9adb4a9..f5778e6 100644
@@ -699,9 +699,15 @@ static int vgic_v2_domain_init(struct domain *d)
     return 0;
 }
 
+static void vgic_v2_domain_free(struct domain *d)
+{
+    /* Nothing to be cleanup for this driver */
+}
+
 static const struct vgic_ops vgic_v2_ops = {
     .vcpu_init   = vgic_v2_vcpu_init,
     .domain_init = vgic_v2_domain_init,
+    .domain_free = vgic_v2_domain_free,
     .max_vcpus = 8,
 };
 
xen/arch/arm/vgic-v3.c +19 -3
index b37a7c0..e877e9e 100644
@@ -1393,7 +1393,19 @@ static int vgic_v3_vcpu_init(struct vcpu *v)
 
 static int vgic_v3_domain_init(struct domain *d)
 {
-    int i;
+    struct vgic_rdist_region *rdist_regions;
+    int rdist_count, i;
+
+    /* Allocate memory for Re-distributor regions */
+    rdist_count = is_hardware_domain(d) ? vgic_v3_hw.nr_rdist_regions :
+                   GUEST_GICV3_RDIST_REGIONS;
+
+    rdist_regions = xzalloc_array(struct vgic_rdist_region, rdist_count);
+    if ( !rdist_regions )
+        return -ENOMEM;
+
+    d->arch.vgic.nr_regions = rdist_count;
+    d->arch.vgic.rdist_regions = rdist_regions;
 
     /*
      * Domain 0 gets the hardware address.
@@ -1426,7 +1438,6 @@ static int vgic_v3_domain_init(struct domain *d)
 
             first_cpu += size / d->arch.vgic.rdist_stride;
         }
-        d->arch.vgic.nr_regions = vgic_v3_hw.nr_rdist_regions;
     }
     else
     {
@@ -1435,7 +1446,6 @@ static int vgic_v3_domain_init(struct domain *d)
         /* XXX: Only one Re-distributor region mapped for the guest */
         BUILD_BUG_ON(GUEST_GICV3_RDIST_REGIONS != 1);
 
-        d->arch.vgic.nr_regions = GUEST_GICV3_RDIST_REGIONS;
         d->arch.vgic.rdist_stride = GUEST_GICV3_RDIST_STRIDE;
 
         /* The first redistributor should contain enough space for all CPUs */
@@ -1467,9 +1477,15 @@ static int vgic_v3_domain_init(struct domain *d)
     return 0;
 }
 
+static void vgic_v3_domain_free(struct domain *d)
+{
+    xfree(d->arch.vgic.rdist_regions);
+}
+
 static const struct vgic_ops v3_ops = {
     .vcpu_init   = vgic_v3_vcpu_init,
     .domain_init = vgic_v3_domain_init,
+    .domain_free = vgic_v3_domain_free,
     .emulate_sysreg  = vgic_v3_emulate_sysreg,
     /*
      * We use both AFF1 and AFF0 in (v)MPIDR. Thus, the max number of CPU
xen/arch/arm/vgic.c +1 -0
index 3e1c572..5df5f01 100644
@@ -177,6 +177,7 @@ void domain_vgic_free(struct domain *d)
         }
     }
 
+    d->arch.vgic.handler->domain_free(d);
     xfree(d->arch.vgic.shared_irqs);
     xfree(d->arch.vgic.pending_irqs);
     xfree(d->arch.vgic.allocated_irqs);
xen/include/asm-arm/domain.h +7 -5
index 370cdeb..9492727 100644
@@ -40,6 +40,12 @@ struct vtimer {
         uint64_t cval;
 };
 
+struct vgic_rdist_region {
+    paddr_t base;		    /* Base address */
+    paddr_t size;		    /* Size */
+    unsigned int first_cpu;	    /* First CPU handled */
+};
+
 struct arch_domain
 {
 #ifdef CONFIG_ARM_64
@@ -103,11 +109,7 @@ struct arch_domain
 #ifdef CONFIG_HAS_GICV3
         /* GIC V3 addressing */
         /* List of contiguous occupied by the redistributors */
-        struct vgic_rdist_region {
-            paddr_t base;                   /* Base address */
-            paddr_t size;                   /* Size */
-            unsigned int first_cpu;         /* First CPU handled */
-        } rdist_regions[MAX_RDIST_COUNT];
+        struct vgic_rdist_region *rdist_regions;
         int nr_regions;                     /* Number of rdist regions */
         uint32_t rdist_stride;              /* Re-Distributor stride */
 #endif
xen/include/asm-arm/vgic.h +2 -0
index a2fccc0..fbb763a 100644
@@ -128,6 +128,8 @@ struct vgic_ops {
     int (*vcpu_init)(struct vcpu *v);
     /* Domain specific initialization of vGIC */
     int (*domain_init)(struct domain *d);
+    /* Release resources that are allocated by domain_init */
+    void (*domain_free)(struct domain *d);
     /* vGIC sysreg emulation */
     int (*emulate_sysreg)(struct cpu_user_regs *regs, union hsr hsr);
     /* Maximum number of vCPU supported */
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#11 lore raw

Re: [PATCH 4/8] xen/arm: vgic: Use dynamic memory allocation for vgic_rdist_region

Hello Shanker,

Quoted 18 lines · Shanker Donthineni
xen/include/asm-arm/domain.h +6 -0
index 370cdeb..9492727 100644
@@ -40,6 +40,12 @@ struct vtimer {
          uint64_t cval;
  };
 
+struct vgic_rdist_region {
+    paddr_t base;		    /* Base address */
+    paddr_t size;		    /* Size */
+    unsigned int first_cpu;	    /* First CPU handled */
+};
+
  struct arch_domain
  {
  #ifdef CONFIG_ARM_64

xen/include/asm-arm/domain.h struct arch_domain · line 112

Quoted 9 lines
xen/include/asm-arm/domain.h +1 -5
@@ -103,11 +109,7 @@ struct arch_domain
  #ifdef CONFIG_HAS_GICV3
          /* GIC V3 addressing */
          /* List of contiguous occupied by the redistributors */
-        struct vgic_rdist_region {
-            paddr_t base;                   /* Base address */
-            paddr_t size;                   /* Size */
-            unsigned int first_cpu;         /* First CPU handled */
-        } rdist_regions[MAX_RDIST_COUNT];
+        struct vgic_rdist_region *rdist_regions;

I don't think it is necessary to move the definition of vgic_rdist_region outside.

Quoted 9 lines
xen/include/asm-arm/domain.h +0 -0
          int nr_regions;                     /* Number of rdist regions */
          uint32_t rdist_stride;              /* Re-Distributor stride */
  #endif
xen/include/asm-arm/vgic.h +0 -0
index a2fccc0..fbb763a 100644

xen/include/asm-arm/vgic.h struct vgic_ops { · line 135

Quoted 8 lines
xen/include/asm-arm/vgic.h +2 -0
@@ -128,6 +128,8 @@ struct vgic_ops {
      int (*vcpu_init)(struct vcpu *v);
      /* Domain specific initialization of vGIC */
      int (*domain_init)(struct domain *d);
+    /* Release resources that are allocated by domain_init */
+    void (*domain_free)(struct domain *d);
      /* vGIC sysreg emulation */
      int (*emulate_sysreg)(struct cpu_user_regs *regs, union hsr hsr);
      /* Maximum number of vCPU supported */

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#12 lore raw

PATCH 5/8 arm/gic-v3: Remove an unused macro MAX_RDIST_COUNT

In reply to Shanker Donthineni

The macro MAX_RDIST_COUNT is not being used after converting code to handle number of redistributor dynamically. So remove it from header file and the two other panic() messages that are not valid anymore.

---
 xen/arch/arm/gic-v3.c     | 8 --------
 xen/include/asm-arm/gic.h | 1 -
 2 files changed, 9 deletions(-)
xen/arch/arm/gic-v3.c +0 -8
index 42cf848..28c00cf 100644
@@ -1200,10 +1200,6 @@ static void __init gicv3_dt_init(void)
                 &gicv3.rdist_count) )
         gicv3.rdist_count = 1;
 
-    if ( gicv3.rdist_count > MAX_RDIST_COUNT )
-        panic("GICv3: Number of redistributor regions is more than"
-              "%d (Increase MAX_RDIST_COUNT!!)\n", MAX_RDIST_COUNT);
-
     rdist_regs = xzalloc_array(struct rdist_region, gicv3.rdist_count);
     if ( !rdist_regs )
         panic("GICv3: Failed to allocate memory for rdist regions\n");
@@ -1518,10 +1514,6 @@ static void __init gicv3_acpi_init(void)
         gicr_table = false;
     }
 
-    if ( count > MAX_RDIST_COUNT )
-        panic("GICv3: Number of redistributor regions is more than"
-              "%d (Increase MAX_RDIST_COUNT!!)\n", MAX_RDIST_COUNT);
-
     rdist_regs = xzalloc_array(struct rdist_region, count);
     if ( !rdist_regs )
         panic("GICv3: Failed to allocate memory for rdist regions\n");
xen/include/asm-arm/gic.h +0 -1
index 7f9ad86..3694e07 100644
@@ -20,7 +20,6 @@
 
 #define NR_GIC_LOCAL_IRQS  NR_LOCAL_IRQS
 #define NR_GIC_SGI         16
-#define MAX_RDIST_COUNT    4
 
 #define GICD_CTLR       (0x000)
 #define GICD_TYPER      (0x004)
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#13 lore raw

PATCH 6/8 arm: vgic: Split vgic_domain_init() functionality into two functions

In reply to Shanker Donthineni

Split code that installs mmio handlers for GICD and Re-distributor regions to a new function. The intension of this separation is to defer steps that registers vgic_v2/v3 mmio handlers.

---
 xen/arch/arm/vgic-v2.c     | 10 +++++++---
 xen/arch/arm/vgic-v3.c     | 40 +++++++++++++++++++++++-----------------
 xen/arch/arm/vgic.c        |  3 +++
 xen/include/asm-arm/vgic.h |  2 ++
 4 files changed, 35 insertions(+), 20 deletions(-)
xen/arch/arm/vgic-v2.c +7 -3
index f5778e6..d42b408 100644
@@ -645,6 +645,12 @@ static int vgic_v2_vcpu_init(struct vcpu *v)
     return 0;
 }
 
+static void vgic_v2_domain_register_mmio(struct domain *d)
+{
+    register_mmio_handler(d, &vgic_v2_distr_mmio_handler, d->arch.vgic.dbase,
+			  PAGE_SIZE, NULL);
+}
+
 static int vgic_v2_domain_init(struct domain *d)
 {
     int ret;
@@ -693,9 +699,6 @@ static int vgic_v2_domain_init(struct domain *d)
     if ( ret )
         return ret;
 
-    register_mmio_handler(d, &vgic_v2_distr_mmio_handler, d->arch.vgic.dbase,
-                          PAGE_SIZE, NULL);
-
     return 0;
 }
 
@@ -708,6 +711,7 @@ static const struct vgic_ops vgic_v2_ops = {
     .vcpu_init   = vgic_v2_vcpu_init,
     .domain_init = vgic_v2_domain_init,
     .domain_free = vgic_v2_domain_free,
+    .domain_register_mmio = vgic_v2_domain_register_mmio,
     .max_vcpus = 8,
 };
 
xen/arch/arm/vgic-v3.c +23 -17
index e877e9e..3a5aeb6 100644
@@ -1391,6 +1391,28 @@ static int vgic_v3_vcpu_init(struct vcpu *v)
     return 0;
 }
 
+static void vgic_v3_domain_register_mmio(struct domain *d)
+{
+    int i;
+
+    /* Register mmio handle for the Distributor */
+    register_mmio_handler(d, &vgic_distr_mmio_handler, d->arch.vgic.dbase,
+		          SZ_64K, NULL);
+
+    /*
+     * Register mmio handler per contiguous region occupied by the
+     * redistributors. The handler will take care to choose which
+     * redistributor is targeted.
+     */
+    for ( i = 0; i < d->arch.vgic.nr_regions; i++ )
+    {
+        struct vgic_rdist_region *region = &d->arch.vgic.rdist_regions[i];
+
+        register_mmio_handler(d, &vgic_rdistr_mmio_handler,
+			  region->base, region->size, region);
+    }
+}
+
 static int vgic_v3_domain_init(struct domain *d)
 {
     struct vgic_rdist_region *rdist_regions;
@@ -1455,23 +1477,6 @@ static int vgic_v3_domain_init(struct domain *d)
         d->arch.vgic.rdist_regions[0].first_cpu = 0;
     }
 
-    /* Register mmio handle for the Distributor */
-    register_mmio_handler(d, &vgic_distr_mmio_handler, d->arch.vgic.dbase,
-                          SZ_64K, NULL);
-
-    /*
-     * Register mmio handler per contiguous region occupied by the
-     * redistributors. The handler will take care to choose which
-     * redistributor is targeted.
-     */
-    for ( i = 0; i < d->arch.vgic.nr_regions; i++ )
-    {
-        struct vgic_rdist_region *region = &d->arch.vgic.rdist_regions[i];
-
-        register_mmio_handler(d, &vgic_rdistr_mmio_handler,
-                              region->base, region->size, region);
-    }
-
     d->arch.vgic.ctlr = VGICD_CTLR_DEFAULT;
 
     return 0;
@@ -1487,6 +1492,7 @@ static const struct vgic_ops v3_ops = {
     .domain_init = vgic_v3_domain_init,
     .domain_free = vgic_v3_domain_free,
     .emulate_sysreg  = vgic_v3_emulate_sysreg,
+    .domain_register_mmio = vgic_v3_domain_register_mmio,
     /*
      * We use both AFF1 and AFF0 in (v)MPIDR. Thus, the max number of CPU
      * that can be supported is up to 4096(==256*16) in theory.
xen/arch/arm/vgic.c +3 -0
index 5df5f01..5b39e0d 100644
@@ -151,9 +151,12 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)
     for ( i = 0; i < NR_GIC_SGI; i++ )
         set_bit(i, d->arch.vgic.allocated_irqs);
 
+    d->arch.vgic.handler->domain_register_mmio(d);
+
     return 0;
 }
 
+
 void register_vgic_ops(struct domain *d, const struct vgic_ops *ops)
 {
    d->arch.vgic.handler = ops;
xen/include/asm-arm/vgic.h +2 -0
index fbb763a..8fe65b4 100644
@@ -132,6 +132,8 @@ struct vgic_ops {
     void (*domain_free)(struct domain *d);
     /* vGIC sysreg emulation */
     int (*emulate_sysreg)(struct cpu_user_regs *regs, union hsr hsr);
+    /* Register mmio handlers */
+    void (*domain_register_mmio)(struct domain *d);
     /* Maximum number of vCPU supported */
     const unsigned int max_vcpus;
 };
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#14 lore raw

Re: [PATCH 6/8] arm: vgic: Split vgic_domain_init() functionality into two functions

Hello Shanker,

Quoted 3 lines · Shanker Donthineni

Split code that installs mmio handlers for GICD and Re-distributor regions to a new function. The intension of this separation is to defer steps that registers vgic_v2/v3 mmio handlers.

Looking at this patch and the follow-up ones, I don't think this is the right way to go. You differ the registration of the IO handlers just because you are unable to find the size of the handlers array.

I am wondering if the array for the handlers is the best solution here. On another side, it would be possible to find the maximum of handlers before hand.

Quoted 5 lines
xen/arch/arm/vgic.c +0 -0
index 5df5f01..5b39e0d 100644

xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d, unsigned int nr_spis) · line 159

Quoted 9 lines
xen/arch/arm/vgic.c +3 -0
@@ -151,9 +151,12 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)
      for ( i = 0; i < NR_GIC_SGI; i++ )
          set_bit(i, d->arch.vgic.allocated_irqs);
 
+    d->arch.vgic.handler->domain_register_mmio(d);
+
      return 0;
  }
 
+

Spurious change.

Quoted 9 lines
xen/arch/arm/vgic.c +0 -0
  void register_vgic_ops(struct domain *d, const struct vgic_ops *ops)
  {
     d->arch.vgic.handler = ops;
xen/include/asm-arm/vgic.h +0 -0
index fbb763a..8fe65b4 100644

xen/include/asm-arm/vgic.h struct vgic_ops { · line 139

Quoted 8 lines
xen/include/asm-arm/vgic.h +2 -0
@@ -132,6 +132,8 @@ struct vgic_ops {
      void (*domain_free)(struct domain *d);
      /* vGIC sysreg emulation */
      int (*emulate_sysreg)(struct cpu_user_regs *regs, union hsr hsr);
+    /* Register mmio handlers */
+    void (*domain_register_mmio)(struct domain *d);
      /* Maximum number of vCPU supported */
      const unsigned int max_vcpus;
  };

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#15 lore raw

Re: [PATCH 6/8] arm: vgic: Split vgic_domain_init() functionality into two functions

Quoted 9 lines · Julien Grall

Hello Shanker,

Quoted 3 lines · Shanker Donthineni

Split code that installs mmio handlers for GICD and Re-distributor regions to a new function. The intension of this separation is to defer steps that registers vgic_v2/v3 mmio handlers.

Looking at this patch and the follow-up ones, I don't think this is the right way to go. You differ the registration of the IO handlers just because you are unable to find the size of the handlers array.

Is there any better approach?

Quoted 2 lines

I am wondering if the array for the handlers is the best solution here. On another side, it would be possible to find the maximum of handlers before hand.

The purpose of this change is to limit size of 'struct domain' less than PAGE_SIZE. I can think of second approach split vgic_init() into two stages, one for vgic registration and the second one for vgic_init(). This also requires a few lines of code changes to vgic_v2/v3_init() and vgic_init().

int arch_domain_create(struct domain *d, unsigned int domcr_flags,
struct xen_arch_domainconfig *config)
...
domain_vgic_register(d));

   domain_io_init(d, mmio_count);

   domain_vgic_init(d, config->nr_spis));
Quoted 38 lines

xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d, unsigned int

Quoted 5 lines
xen/arch/arm/vgic.c +0 -0
index 5df5f01..5b39e0d 100644
@@ -151,9 +151,12 @@ int domain_vgic_init(struct domain *d, unsigned int

nr_spis)

xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d, unsigned int nr_spis) · line 159

Quoted 9 lines
xen/arch/arm/vgic.c +3 -0
      for ( i = 0; i < NR_GIC_SGI; i++ )
          set_bit(i, d->arch.vgic.allocated_irqs);
 
+    d->arch.vgic.handler->domain_register_mmio(d);
+
      return 0;
  }
 
+

Spurious change.

Quoted 9 lines
xen/arch/arm/vgic.c +0 -0
  void register_vgic_ops(struct domain *d, const struct vgic_ops *ops)
  {
     d->arch.vgic.handler = ops;
xen/include/asm-arm/vgic.h +0 -0
index fbb763a..8fe65b4 100644

xen/include/asm-arm/vgic.h struct vgic_ops { · line 139

Quoted 8 lines
xen/include/asm-arm/vgic.h +2 -0
@@ -132,6 +132,8 @@ struct vgic_ops {
      void (*domain_free)(struct domain *d);
      /* vGIC sysreg emulation */
      int (*emulate_sysreg)(struct cpu_user_regs *regs, union hsr hsr);
+    /* Register mmio handlers */
+    void (*domain_register_mmio)(struct domain *d);
      /* Maximum number of vCPU supported */
      const unsigned int max_vcpus;
  };

Regards,

Signature · 9 lines
Shanker Donthineni
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#16 lore raw

Re: [PATCH 6/8] arm: vgic: Split vgic_domain_init() functionality into two functions

Quoted 10 lines · Shanker Donthineni
Quoted 7 lines · Julien Grall

Hello Shanker,

Quoted 3 lines · Shanker Donthineni

Split code that installs mmio handlers for GICD and Re-distributor regions to a new function. The intension of this separation is to defer steps that registers vgic_v2/v3 mmio handlers.

Quoted 5 lines
Quoted 4 lines

Looking at this patch and the follow-up ones, I don't think this is the right way to go. You differ the registration of the IO handlers just because you are unable to find the size of the handlers array.

Is there any better approach?

Possibly using a different data structure.

Quoted 9 lines
Quoted 4 lines

I am wondering if the array for the handlers is the best solution here. On another side, it would be possible to find the maximum of handlers before hand.

The purpose of this change is to limit size of 'struct domain' less than PAGE_SIZE. I can think of second approach split vgic_init() into two stages, one for vgic registration and the second one for vgic_init(). This also requires a few lines of code changes to vgic_v2/v3_init() and vgic_init().

I am fine as long as vgic_register_ does not do more than counting the number of IO handlers. You could re-use vgic_init_v{2,3} for this purpose.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#17 lore raw

Re: [PATCH 6/8] arm: vgic: Split vgic_domain_init() functionality into two functions

Hi Julien,

Quoted 25 lines · Julien Grall
Quoted 10 lines · Shanker Donthineni
Quoted 7 lines · Julien Grall

Hello Shanker,

Quoted 3 lines · Shanker Donthineni

Split code that installs mmio handlers for GICD and Re-distributor regions to a new function. The intension of this separation is to defer steps that registers vgic_v2/v3 mmio handlers.

Quoted 5 lines
Quoted 4 lines

Looking at this patch and the follow-up ones, I don't think this is the right way to go. You differ the registration of the IO handlers just because you are unable to find the size of the handlers array.

Is there any better approach?

Possibly using a different data structure.

Quoted 4 lines
Quoted 4 lines

I am wondering if the array for the handlers is the best solution here. On another side, it would be possible to find the maximum of handlers before hand.

Quoted 8 lines
Quoted 5 lines

The purpose of this change is to limit size of 'struct domain' less than PAGE_SIZE. I can think of second approach split vgic_init() into two stages, one for vgic registration and the second one for vgic_init(). This also requires a few lines of code changes to vgic_v2/v3_init() and vgic_init().

I am fine as long as vgic_register_ does not do more than counting the number of IO handlers. You could re-use vgic_init_v{2,3} for this purpose.

The way we are doing vgic_init() initialization has to be cleaned-up and rearrange a few lines of code for retrieving the number mmio handlers that are required dom0/domU domain.

Quoted 2 lines

Regards,

Signature · 9 lines
Shanker Donthineni
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#18 lore raw

PATCH 7/8 arm/mmio: Use separate memory allocation for mmio handlers

In reply to Shanker Donthineni

The number of mmio handlers are limited to a compile time macro MAX_IO_HANDLER which is 16. This number is not at all sufficient to support per CPU distributor regions. Either it needs to be increased to a bigger number, at least CONFIG_NR_CPUS+16, or allocate a separate memory for mmio handlers dynamically during domain build.

This patch uses the dynamic allocation strategy to reduce memory footprint for 'struct domain' instead of static allocation.

---
 xen/arch/arm/domain.c      |  6 ++++--
 xen/arch/arm/io.c          | 14 ++++++++++++--
 xen/include/asm-arm/mmio.h |  6 ++++--
 3 files changed, 20 insertions(+), 6 deletions(-)
xen/arch/arm/domain.c +4 -2
index 1365b4a..4010ff2 100644
@@ -527,7 +527,7 @@ void vcpu_destroy(struct vcpu *v)
 int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                        struct xen_arch_domainconfig *config)
 {
-    int rc;
+    int rc, count;
 
     d->arch.relmem = RELMEM_not_started;
 
@@ -550,7 +550,8 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     share_xen_page_with_guest(
         virt_to_page(d->shared_info), d, XENSHARE_writable);
 
-    if ( (rc = domain_io_init(d)) != 0 )
+    count = MAX_IO_HANDLER;
+    if ( (rc = domain_io_init(d, count)) != 0 )
         goto fail;
 
     if ( (rc = p2m_alloc_table(d)) != 0 )
@@ -644,6 +645,7 @@ void arch_domain_destroy(struct domain *d)
     free_xenheap_pages(d->arch.efi_acpi_table,
                        get_order_from_bytes(d->arch.efi_acpi_len));
 #endif
+    domain_io_free(d);
 }
 
 void arch_domain_shutdown(struct domain *d)
xen/arch/arm/io.c +12 -2
index 0156755..a5b2c2d 100644
@@ -102,7 +102,7 @@ void register_mmio_handler(struct domain *d,
     struct vmmio *vmmio = &d->arch.vmmio;
     struct mmio_handler *handler;
 
-    BUG_ON(vmmio->num_entries >= MAX_IO_HANDLER);
+    BUG_ON(vmmio->num_entries >= vmmio->max_num_entries);
 
     spin_lock(&vmmio->lock);
 
@@ -125,14 +125,24 @@ void register_mmio_handler(struct domain *d,
     spin_unlock(&vmmio->lock);
 }
 
-int domain_io_init(struct domain *d)
+int domain_io_init(struct domain *d, int max_count)
 {
    spin_lock_init(&d->arch.vmmio.lock);
    d->arch.vmmio.num_entries = 0;
 
+   d->arch.vmmio.max_num_entries = max_count;
+   d->arch.vmmio.handlers = xzalloc_array(struct mmio_handler, max_count);
+   if ( !d->arch.vmmio.handlers )
+       return -ENOMEM;
+
    return 0;
 }
 
+void domain_io_free(struct domain *d)
+{
+    xfree(d->arch.vmmio.handlers);
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/asm-arm/mmio.h +4 -2
index da1cc2e..276b263 100644
@@ -51,15 +51,17 @@ struct mmio_handler {
 
 struct vmmio {
     int num_entries;
+    int max_num_entries;
     spinlock_t lock;
-    struct mmio_handler handlers[MAX_IO_HANDLER];
+    struct mmio_handler *handlers;
 };
 
 extern int handle_mmio(mmio_info_t *info);
 void register_mmio_handler(struct domain *d,
                            const struct mmio_handler_ops *ops,
                            paddr_t addr, paddr_t size, void *priv);
-int domain_io_init(struct domain *d);
+int domain_io_init(struct domain *d, int max_count);
+void domain_io_free(struct domain *d);
 
 #endif  /* __ASM_ARM_MMIO_H__ */
 
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#19 lore raw

PATCH 8/8 arm/vgic: Change fixed number of mmio handlers to variable number

In reply to Shanker Donthineni

Record the number of mmio handlers that are required for vGICv3/2 in variable 'arch_domain.vgic.mmio_count' in vgic_domain_init(). Augment this variable number to a fixed number MAX_IO_HANDLER and pass it to domain_io_init() to allocate enough memory for handlers.

New code path:
domain_vgic_init()
count = MAX_IO_HANDLER + d->arch.vgic.mmio_count; domain_io_init(count)
domain_vgic_register_mmio()

---
 xen/arch/arm/domain.c        | 10 ++++++----
 xen/arch/arm/vgic-v2.c       |  2 ++
 xen/arch/arm/vgic-v3.c       |  3 +++
 xen/arch/arm/vgic.c          |  7 +++++--
 xen/include/asm-arm/domain.h |  1 +
 xen/include/asm-arm/vgic.h   |  1 +
 6 files changed, 18 insertions(+), 6 deletions(-)
xen/arch/arm/domain.c +6 -4
index 4010ff2..ef567c8 100644
@@ -550,10 +550,6 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     share_xen_page_with_guest(
         virt_to_page(d->shared_info), d, XENSHARE_writable);
 
-    count = MAX_IO_HANDLER;
-    if ( (rc = domain_io_init(d, count)) != 0 )
-        goto fail;
-
     if ( (rc = p2m_alloc_table(d)) != 0 )
         goto fail;
 
@@ -593,6 +589,12 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     if ( (rc = domain_vgic_init(d, config->nr_spis)) != 0 )
         goto fail;
 
+    count = MAX_IO_HANDLER + d->arch.vgic.mmio_count;
+    if ( (rc = domain_io_init(d, count)) != 0 )
+        goto fail;
+
+    domain_vgic_register_mmio(d);
+
     if ( (rc = domain_vtimer_init(d, config)) != 0 )
         goto fail;
 
xen/arch/arm/vgic-v2.c +2 -0
index d42b408..7ed7d32 100644
@@ -699,6 +699,8 @@ static int vgic_v2_domain_init(struct domain *d)
     if ( ret )
         return ret;
 
+    d->arch.vgic.mmio_count = 1; /* Only GICD region */
+
     return 0;
 }
 
xen/arch/arm/vgic-v3.c +3 -0
index 3a5aeb6..6a5f333 100644
@@ -1479,6 +1479,9 @@ static int vgic_v3_domain_init(struct domain *d)
 
     d->arch.vgic.ctlr = VGICD_CTLR_DEFAULT;
 
+    /* GICD region + number of Re-distributors */
+    d->arch.vgic.mmio_count = d->arch.vgic.nr_regions + 1;
+
     return 0;
 }
 
xen/arch/arm/vgic.c +5 -2
index 5b39e0d..7d34942 100644
@@ -88,6 +88,11 @@ static void vgic_rank_init(struct vgic_irq_rank *rank, uint8_t index,
         rank->vcpu[i] = vcpu;
 }
 
+void domain_vgic_register_mmio(struct domain *d)
+{
+    d->arch.vgic.handler->domain_register_mmio(d);
+}
+
 int domain_vgic_init(struct domain *d, unsigned int nr_spis)
 {
     int i;
@@ -151,8 +156,6 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)
     for ( i = 0; i < NR_GIC_SGI; i++ )
         set_bit(i, d->arch.vgic.allocated_irqs);
 
-    d->arch.vgic.handler->domain_register_mmio(d);
-
     return 0;
 }
 
xen/include/asm-arm/domain.h +1 -0
index 9492727..974cf93 100644
@@ -113,6 +113,7 @@ struct arch_domain
         int nr_regions;                     /* Number of rdist regions */
         uint32_t rdist_stride;              /* Re-Distributor stride */
 #endif
+        uint32_t mmio_count;		/* Number of mmio handlers */
     } vgic;
 
     struct vuart {
xen/include/asm-arm/vgic.h +1 -0
index 8fe65b4..0032633 100644
@@ -309,6 +309,7 @@ extern void register_vgic_ops(struct domain *d, const struct vgic_ops *ops);
 int vgic_v2_init(struct domain *d);
 int vgic_v3_init(struct domain *d);
 
+extern void domain_vgic_register_mmio(struct domain *d);
 extern int vcpu_vgic_free(struct vcpu *v);
 extern int vgic_to_sgi(struct vcpu *v, register_t sgir,
                        enum gic_sgi_mode irqmode, int virq,
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#20 lore raw
In reply to Shanker Donthineni

Hello Shanker,

Quoted 7 lines · Shanker Donthineni

The current driver doesn't support parsing Redistributor entries that are described in the MADT GICC table. Not all the GIC implementors places the Redistributor regions in the always-on power domain. On systems, the UEFI firmware should describe Redistributor base address in the associated GIC CPU Interface (GICC) instead of GIC Redistributor (GICR) table.

Quoted 8 lines

The maximum number of mmio handlers and struct vgic_rdist_region that holds Redistributor addresses are allocated through a static array with hardcoded size. I don't think this is the right approach and is not scalable for implementing features like this. I have decided to convert static to dynamic allocation based on comments from the below link.

https://patchwork.kernel.org/patch/9163435/

You addressed only one part of my comment. This series increases the number of I/O handlers but the lookup is still linear (see handle_mmio in arch/arm/io.c).

After this series, the maximum number of I/O handlers is 160. So in the worst case, we have to do 160 iterations before finding an handler or concluding the I/O cannot be emulated.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#21 lore raw
Quoted 17 lines · Julien Grall

Hello Shanker,

Quoted 14 lines · Shanker Donthineni

The current driver doesn't support parsing Redistributor entries that are described in the MADT GICC table. Not all the GIC implementors places the Redistributor regions in the always-on power domain. On systems, the UEFI firmware should describe Redistributor base address in the associated GIC CPU Interface (GICC) instead of GIC Redistributor (GICR) table.

The maximum number of mmio handlers and struct vgic_rdist_region that holds Redistributor addresses are allocated through a static array with hardcoded size. I don't think this is the right approach and is not scalable for implementing features like this. I have decided to convert static to dynamic allocation based on comments from the below link.

Quoted 4 lines
Quoted 1 line

https://patchwork.kernel.org/patch/9163435/

You addressed only one part of my comment. This series increases the number of I/O handlers but the lookup is still linear (see handle_mmio in arch/arm/io.c).

I agree with you, we need to bring binary search algorithm similar to Linux KVM code. I want to keep it this change outside of this patchset.

Quoted 4 lines

After this series, the maximum number of I/O handlers is 160. So in the worst case, we have to do 160 iterations before finding an handler or concluding the I/O cannot be emulated.

Regards,

Signature · 9 lines
Shanker Donthineni
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#22 lore raw
Quoted 16 lines · Shanker Donthineni
Quoted 15 lines · Julien Grall
Quoted 14 lines · Shanker Donthineni

The current driver doesn't support parsing Redistributor entries that are described in the MADT GICC table. Not all the GIC implementors places the Redistributor regions in the always-on power domain. On systems, the UEFI firmware should describe Redistributor base address in the associated GIC CPU Interface (GICC) instead of GIC Redistributor (GICR) table.

The maximum number of mmio handlers and struct vgic_rdist_region that holds Redistributor addresses are allocated through a static array with hardcoded size. I don't think this is the right approach and is not scalable for implementing features like this. I have decided to convert static to dynamic allocation based on comments from the below link.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

https://patchwork.kernel.org/patch/9163435/

You addressed only one part of my comment. This series increases the number of I/O handlers but the lookup is still linear (see handle_mmio in arch/arm/io.c).

I agree with you, we need to bring binary search algorithm similar to Linux KVM code. I want to keep it this change outside of this patchset.

This should be a prerequisite of this series then, not a follow-up.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#23 lore raw
Quoted 22 lines · Julien Grall
Quoted 7 lines · Shanker Donthineni
Quoted 6 lines · Julien Grall
Quoted 5 lines · Shanker Donthineni

The current driver doesn't support parsing Redistributor entries that are described in the MADT GICC table. Not all the GIC implementors places the Redistributor regions in the always-on power domain. On systems, the UEFI firmware should describe Redistributor base address in the associated GIC CPU Interface (GICC) instead of GIC

Redistributor

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

(GICR) table.

The maximum number of mmio handlers and struct vgic_rdist_region that holds Redistributor addresses are allocated through a static array with hardcoded size. I don't think this is the right approach and is not scalable for implementing features like this. I have decided to convert static to dynamic allocation based on comments from the below link.

https://patchwork.kernel.org/patch/9163435/

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

You addressed only one part of my comment. This series increases the number of I/O handlers but the lookup is still linear (see handle_mmio in arch/arm/io.c).

I agree with you, we need to bring binary search algorithm similar to Linux KVM code. I want to keep it this change outside of this patchset.

This should be a prerequisite of this series then, not a follow-up.

For the functionality and correctness purpose we don't need this change immediately. We are not able to boot XEN on Qualcomm Technologies because of not supporting GICC table parsing for GICR address.

I am okay to wait for my patchset if someone adding bseach look ups for mmio handlers.

Quoted 2 lines

Regards,

Signature · 9 lines
Shanker Donthineni
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#24 lore raw
Quoted 30 lines · Shanker Donthineni
Quoted 20 lines · Julien Grall
Quoted 7 lines · Shanker Donthineni
Quoted 6 lines · Julien Grall
Quoted 5 lines · Shanker Donthineni

The current driver doesn't support parsing Redistributor entries that are described in the MADT GICC table. Not all the GIC implementors places the Redistributor regions in the always-on power domain. On systems, the UEFI firmware should describe Redistributor base address in the associated GIC CPU Interface (GICC) instead of GIC

Redistributor

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

(GICR) table.

The maximum number of mmio handlers and struct vgic_rdist_region that holds Redistributor addresses are allocated through a static array with hardcoded size. I don't think this is the right approach and is not scalable for implementing features like this. I have decided to convert static to dynamic allocation based on comments from the below link.

https://patchwork.kernel.org/patch/9163435/

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

You addressed only one part of my comment. This series increases the number of I/O handlers but the lookup is still linear (see handle_mmio in arch/arm/io.c).

I agree with you, we need to bring binary search algorithm similar to Linux KVM code. I want to keep it this change outside of this patchset.

This should be a prerequisite of this series then, not a follow-up.

Quoted 8 lines

For the functionality and correctness purpose we don't need this change immediately.
We are not able to boot XEN on Qualcomm Technologies because of not supporting
GICC table parsing for GICR address.

I am okay to wait for my patchset if someone adding bseach look ups for mmio handlers.

I am not aware of anyone planning to add bsearch.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel