Skip to contentSkip to conversation

arm: Add GICv3 support to the New VGIC

PATCH New Mykyta Poturai 1 participant 26 messages Nov 10, 2023

lore
Share & tools
lore
#12 lore raw

PATCH v2 12/25 arm: new VGIC: Wire new GICv3 into the build system

In reply to Mykyta Poturai

Remove !NEW_VGIC dependency from GICV3 config and add new GICv3 files to the build system.

---
 xen/arch/arm/Kconfig       | 1 -
 xen/arch/arm/vgic/Makefile | 2 ++
 2 files changed, 2 insertions(+), 1 deletion(-)
xen/arch/arm/Kconfig +0 -1
index 2939db429b..c91011bc15 100644
@@ -82,7 +82,6 @@ config ARM_EFI
 
 config GICV3
 	bool "GICv3 driver"
-	depends on !NEW_VGIC
 	default n if ARM_32
 	default y if ARM_64
 	---help---
xen/arch/arm/vgic/Makefile +2 -0
index 806826948e..21a71d2502 100644
@@ -1,5 +1,7 @@
 obj-y += vgic.o
 obj-y += vgic-v2.o
+obj-$(CONFIG_GICV3) += vgic-v3.o
 obj-y += vgic-mmio.o
 obj-y += vgic-mmio-v2.o
+obj-$(CONFIG_GICV3) += vgic-mmio-v3.o
 obj-y += vgic-init.o
Signature · 1 line
2.34.1
#17 lore raw

PATCH v2 17/25 arm: new VGIC: its: Read initial LPI pending table

In reply to Mykyta Poturai

The LPI pending status for a GICv3 redistributor is held in a table in (guest) memory. To achieve reasonable performance, we cache the pending bit in our struct vgic_irq. The initial pending state must be read from guest memory upon enabling LPIs for this redistributor. As we can't access the guest memory while we hold the lpi_list spinlock, we create a snapshot of the LPI list and iterate over that.

Based on Linux commit 33d3bc9556a7d by Andre Przywara

---
 xen/arch/arm/include/asm/new_vgic.h |   5 ++
 xen/arch/arm/vgic/vgic-its.c        | 104 ++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
xen/arch/arm/include/asm/new_vgic.h +5 -0
index 3048f39844..d0fd15e154 100644
@@ -264,12 +264,17 @@ static inline paddr_t vgic_dist_base(const struct vgic_dist *vgic)
 }
 
 #ifdef CONFIG_HAS_ITS
+void vgic_enable_lpis(struct vcpu *vcpu);
 struct vgic_its_device *vgic_its_alloc_device(int nr_events);
 void vgic_its_free_device(struct vgic_its_device *its_dev);
 int vgic_its_add_device(struct domain *d, struct vgic_its_device *its_dev);
 void vgic_its_delete_device(struct domain *d, struct vgic_its_device *its_dev);
 struct vgic_its_device* vgic_its_get_device(struct domain *d, paddr_t vdoorbell,
                                          uint32_t vdevid);
+#else
+static inline void vgic_enable_lpis(struct vcpu *vcpu)
+{
+}
 #endif
 
 #endif /* __ASM_ARM_NEW_VGIC_H */
xen/arch/arm/vgic/vgic-its.c +104 -0

122 lines not on this page · raw message

Signature · 1 line
2.34.1
#11 lore raw

PATCH v2 11/25 arm: new VGIC: Add alternative redist region storage

In reply to Mykyta Poturai

Guests DT creation requires redist regions to be stored in the specific variables in struct vgic_dist. But in new VGIC a linked list is used for that. To not clutter the DT creation code with ifdefs, add alternative storage for redist regions in struct vgic_dist.

---
 xen/arch/arm/include/asm/new_vgic.h | 5 +++++
 xen/arch/arm/vgic/vgic-v3.c         | 8 ++++++++
 2 files changed, 13 insertions(+)
xen/arch/arm/include/asm/new_vgic.h +5 -0
index 11d8f71851..9eafab45ff 100644
@@ -21,6 +21,7 @@
 #include <xen/list.h>
 #include <xen/mm.h>
 #include <xen/spinlock.h>
+#include <asm/gic_v3_defs.h>
 
 #define VGIC_V3_MAX_CPUS        255
 #define VGIC_V2_MAX_CPUS        8
@@ -136,6 +137,10 @@ struct vgic_dist {
     paddr_t             csize; /* CPU interface size */
     paddr_t             vbase; /* virtual CPU interface base address */
 
+    /* for compatibility with guests DT creation*/
+    uint32_t nr_regions;
+    struct rdist_region *rdist_regions;
+
     /* distributor enabled */
     bool                enabled;
 
xen/arch/arm/vgic/vgic-v3.c +8 -0
index 682d57b476..8b700609f0 100644
@@ -257,6 +257,10 @@ int vgic_v3_map_resources(struct domain *d)
     /* Allocate memory for Re-distributor regions */
     rdist_count = vgic_v3_max_rdist_count(d);
 
+    /*For compatibility with hwdom dt node creation*/
+    d->arch.vgic.nr_regions = rdist_count;
+    d->arch.vgic.rdist_regions = xzalloc_array(struct rdist_region, rdist_count);
+
     /*
      * For domain using the host memory layout, it gets the hardware
      * address.
@@ -268,6 +272,8 @@ int vgic_v3_map_resources(struct domain *d)
 
         for ( i = 0; i < vgic_v3_hw_data.nr_rdist_regions; i++ )
         {
+            d->arch.vgic.rdist_regions[i].base = vgic_v3_hw_data.regions[i].base;
+            d->arch.vgic.rdist_regions[i].size = vgic_v3_hw_data.regions[i].size;
             vgic_v3_set_redist_base(d, i, vgic_v3_hw_data.regions[i].base,
                                     vgic_v3_hw_data.regions[i].size /
                                         GICV3_GICR_SIZE);
@@ -276,6 +282,8 @@ int vgic_v3_map_resources(struct domain *d)
     else
     {
         d->arch.vgic.dbase = GUEST_GICV3_GICD_BASE;
+        d->arch.vgic.rdist_regions[0].base = GUEST_GICV3_GICR0_BASE;
+        d->arch.vgic.rdist_regions[0].size = GUEST_GICV3_GICR0_SIZE;
 
         /* A single Re-distributor region is mapped for the guest. */
         BUILD_BUG_ON(GUEST_GICV3_RDIST_REGIONS != 1);
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/25 arm: new VGIC: Add GICv3 world switch backend

In reply to Mykyta Poturai

As the GICv3 virtual interface registers differ from their GICv2 siblings, we need different handlers for processing maintenance interrupts and reading/writing to the LRs.
Implement the respective handler functions and connect them to existing code to be called if the host is using a GICv3.

This is based on Linux commit 59529f69f5048e0 by Marc Zyngier

---
 xen/arch/arm/vgic/vgic-v3.c | 206 ++++++++++++++++++++++++++++++++++++
 xen/arch/arm/vgic/vgic.c    |  18 +++-
 xen/arch/arm/vgic/vgic.h    |  13 ++-
 3 files changed, 234 insertions(+), 3 deletions(-)
 create mode 100644 xen/arch/arm/vgic/vgic-v3.c
xen/arch/arm/vgic/vgic-v3.c new file +206 -0
new file mode 100644
index 0000000000..b018ee6040
@@ -0,0 +1,206 @@
+/*
+ * Imported from Linux ("new" KVM VGIC) and heavily adapted to Xen.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <asm/new_vgic.h>
+#include <asm/gic.h>
+#include <xen/sched.h>
+
+#include "vgic.h"
+
+/*
+ * transfer the content of the LRs back into the corresponding ap_list:
+ * - active bit is transferred as is
+ * - pending bit is
+ *   - transferred as is in case of edge sensitive IRQs
+ *   - set to the line-level (resample time) for level sensitive IRQs
+ */
+void vgic_v3_fold_lr_state(struct vcpu *vcpu)
+{
+    struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic;
+    unsigned int used_lrs     = vcpu->arch.vgic.used_lrs;
+    unsigned long flags;
+    unsigned int lr;
+
+    if ( !used_lrs ) /* No LRs used, so nothing to sync back here. */
+        return;
+
+    gic_hw_ops->update_hcr_status(GICH_HCR_UIE, false);
+
+    for ( lr = 0; lr < used_lrs; lr++ )
+    {
+        struct gic_lr lr_val;
+        uint32_t intid;
+        struct vgic_irq *irq;
+        struct irq_desc *desc = NULL;
+
+        gic_hw_ops->read_lr(lr, &lr_val);
+
+        /*
+         * TODO: Possible optimization to avoid reading LRs:
+         * Read the ELRSR to find out which of our LRs have been cleared
+         * by the guest. We just need to know the IRQ number for those, which
+         * we could save in an array when populating the LRs.
+         * This trades one MMIO access (ELRSR) for possibly more than one (LRs),
+         * but requires some more code to save the IRQ number and to handle
+         * those finished IRQs according to the algorithm below.
+         * We need some numbers to justify this: chances are that we don't
+         * have many LRs in use most of the time, so we might not save much.
+         */
+        gic_hw_ops->clear_lr(lr);
+
+        intid = lr_val.virq;
+        irq   = vgic_get_irq(vcpu->domain, vcpu, intid);
+
+        local_irq_save(flags);
+
+        /*
+         * We check this here without taking the lock, because the locking
+         * order forces us to do so. irq->hw is a "write-once" member, so
+         * whenever we read true, the associated hardware IRQ will not go
+         * away anymore.
+         * TODO: rework this if possible, either by using the desc pointer
+         * directly in struct vgic_irq or by changing the locking order.
+         * Especially if we ever drop the assumption above.
+         */
+        if ( irq->hw )
+        {
+            desc = irq_to_desc(irq->hwintid);
+            spin_lock(&desc->lock);
+        }
+
+        spin_lock(&irq->irq_lock);
+
+        /*
+         * If a hardware mapped IRQ has been handled for good, we need to
+         * clear the _IRQ_INPROGRESS bit to allow handling of new IRQs.
+         *
+         * TODO: This is probably racy, but is so already in the existing
+         * VGIC. A fix does not seem to be trivial.
+         */
+        if ( irq->hw && !lr_val.active && !lr_val.pending )
+            clear_bit(_IRQ_INPROGRESS, &desc->status);
+
+        /* Always preserve the active bit */
+        irq->active = lr_val.active;
+
+        /* Edge is the only case where we preserve the pending bit */
+        if ( irq->config == VGIC_CONFIG_EDGE && lr_val.pending )
+        {
+            irq->pending_latch = true;
+
+            if ( vgic_irq_is_sgi(intid) )
+                irq->source |= (1U << lr_val.virt.source);
+        }
+
+        /* Clear soft pending state when level irqs have been acked. */
+        if ( irq->config == VGIC_CONFIG_LEVEL && !lr_val.pending )
+            irq->pending_latch = false;
+
+        /*
+         * Level-triggered mapped IRQs are special because we only
+         * observe rising edges as input to the VGIC.
+         *
+         * If the guest never acked the interrupt we have to sample
+         * the physical line and set the line level, because the
+         * device state could have changed or we simply need to
+         * process the still pending interrupt later.
+         *
+         * If this causes us to lower the level, we have to also clear
+         * the physical active state, since we will otherwise never be
+         * told when the interrupt becomes asserted again.
+         */
+        if ( vgic_irq_is_mapped_level(irq) && lr_val.pending )
+        {
+            ASSERT(irq->hwintid >= VGIC_NR_PRIVATE_IRQS);
+
+            irq->line_level = gic_read_pending_state(desc);
+
+            if ( !irq->line_level )
+                gic_set_active_state(desc, false);
+        }
+
+        spin_unlock(&irq->irq_lock);
+        if ( desc )
+            spin_unlock(&desc->lock);
+        local_irq_restore(flags);
+
+        vgic_put_irq(vcpu->domain, irq);
+    }
+
+    gic_hw_ops->update_hcr_status(GICH_HCR_EN, false);
+    vgic_cpu->used_lrs = 0;
+}
+
+/* Requires the irq to be locked already */
+void vgic_v3_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr)
+{
+    struct gic_lr lr_val = { 0 };
+
+    lr_val.virq          = irq->intid;
+
+    if ( irq_is_pending(irq) )
+    {
+        lr_val.pending = true;
+
+        if ( irq->config == VGIC_CONFIG_EDGE )
+            irq->pending_latch = false;
+
+        if ( vgic_irq_is_sgi(irq->intid) &&
+             vcpu->domain->arch.vgic.version == VGIC_V2 )
+        {
+            uint32_t src = ffs(irq->source);
+
+            BUG_ON(!src);
+            lr_val.virt.source = (src - 1);
+            irq->source &= ~(1 << (src - 1));
+            if ( irq->source )
+                irq->pending_latch = true;
+        }
+    }
+
+    lr_val.active = irq->active;
+
+    if ( irq->hw )
+    {
+        lr_val.hw_status = true;
+        lr_val.hw.pirq   = irq->hwintid;
+        /*
+         * Never set pending+active on a HW interrupt, as the
+         * pending state is kept at the physical distributor
+         * level.
+         */
+        if ( irq->active && irq_is_pending(irq) )
+            lr_val.pending = false;
+    }
+    else
+    {
+        if ( irq->config == VGIC_CONFIG_LEVEL )
+            lr_val.virt.eoi = true;
+    }
+
+    /*
+     * Level-triggered mapped IRQs are special because we only observe
+     * rising edges as input to the VGIC.  We therefore lower the line
+     * level here, so that we can take new virtual IRQs.  See
+     * vgic_v2_fold_lr_state for more info.
+     */
+    if ( vgic_irq_is_mapped_level(irq) && lr_val.pending )
+        irq->line_level = false;
+
+    /* The GICv2 LR only holds five bits of priority. */
+    lr_val.priority = irq->priority >> 3;
+
+    gic_hw_ops->write_lr(lr, &lr_val);
+}
xen/arch/arm/vgic/vgic.c +16 -2
index b9463a5f27..97ca827fc4 100644
@@ -520,7 +520,14 @@ retry:
 
 static void vgic_fold_lr_state(struct vcpu *vcpu)
 {
-    vgic_v2_fold_lr_state(vcpu);
+    if ( vcpu->domain->arch.vgic.version == GIC_V2 )
+    {
+        vgic_v2_fold_lr_state(vcpu);
+    }
+    else
+    {
+        vgic_v3_fold_lr_state(vcpu);
+    }
 }
 
 /* Requires the irq_lock to be held. */
@@ -529,7 +536,14 @@ static void vgic_populate_lr(struct vcpu *vcpu,
 {
     ASSERT(spin_is_locked(&irq->irq_lock));
 
-    vgic_v2_populate_lr(vcpu, irq, lr);
+    if ( vcpu->domain->arch.vgic.version == GIC_V2 )
+    {
+        vgic_v2_populate_lr(vcpu, irq, lr);
+    }
+    else
+    {
+        vgic_v3_populate_lr(vcpu, irq, lr);
+    }
 }
 
 static void vgic_set_underflow(struct vcpu *vcpu)
xen/arch/arm/vgic/vgic.h +12 -1
index 534b24bcd3..2819569f30 100644
@@ -70,8 +70,19 @@ void vgic_v2_enable(struct vcpu *vcpu);
 int vgic_v2_map_resources(struct domain *d);
 int vgic_register_dist_iodev(struct domain *d, gfn_t dist_base_fn,
                              enum vgic_type);
+#ifdef CONFIG_GICV3
+void vgic_v3_fold_lr_state(struct vcpu *vcpu);
+void vgic_v3_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr);
+#else
+static inline void vgic_v3_fold_lr_state(struct vcpu *vcpu)
+{
+}
+static inline void vgic_v3_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr)
+{
+}
+#endif /* CONFIG_GICV3 */
 
-#endif
+#endif /* __XEN_ARM_VGIC_VGIC_H__ */
 
 /*
  * Local variables:
Signature · 1 line
2.34.1
#25 lore raw

PATCH v2 25/25 arm: new VGIC: Improve MMIO handling

In reply to Mykyta Poturai

Currently the full register address is used in VGIC MMIO handlers. This can cause issues when VGIC_ADDR_TO_IRQ_MASK overlaps with the base address. For example the current GUEST_GICV3_GICD_BASE overlaps with addr to irq mask for 64 bit registers, causing intids to be calculated incorrectly.

This patch fixes the issue by subtracting the base address from the full register address before passing it to the MMIO handlers. Thus giving the MMIO handler only the relevant offset.

---
 xen/arch/arm/vgic/vgic-mmio.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
xen/arch/arm/vgic/vgic-mmio.c +7 -7
index 7a28be53bc..abf7854af0 100644
@@ -540,7 +540,7 @@ vgic_get_mmio_region(struct vcpu *vcpu, struct vgic_io_device *iodev,
 
     region = vgic_find_mmio_region(iodev->regions, iodev->nr_regions,
                                    addr - gfn_to_gaddr(iodev->base_fn));
-    if ( !region || !check_region(vcpu->domain, region, addr, len) )
+    if ( !region || !check_region(vcpu->domain, region, addr - gfn_to_gaddr(iodev->base_fn), len) )
         return NULL;
 
     return region;
@@ -565,13 +565,13 @@ static int dispatch_mmio_read(struct vcpu *vcpu, mmio_info_t *info,
     switch (iodev->iodev_type)
     {
     case IODEV_DIST:
-        data = region->read(vcpu, addr, len);
+        data = region->read(vcpu, addr - gfn_to_gaddr(iodev->base_fn), len);
         break;
     case IODEV_REDIST:
-        data = region->read(iodev->redist_vcpu, addr, len);
+        data = region->read(iodev->redist_vcpu, addr - gfn_to_gaddr(iodev->base_fn), len);
         break;
     case IODEV_ITS:
-        data = region->its_read(vcpu->domain, iodev->its, addr, len);;
+        data = region->its_read(vcpu->domain, iodev->its, addr - gfn_to_gaddr(iodev->base_fn), len);;
         break;
     }
 
@@ -596,13 +596,13 @@ static int dispatch_mmio_write(struct vcpu *vcpu, mmio_info_t *info,
     switch (iodev->iodev_type)
     {
     case IODEV_DIST:
-        region->write(vcpu, addr, len, data);
+        region->write(vcpu, addr - gfn_to_gaddr(iodev->base_fn), len, data);
         break;
     case IODEV_REDIST:
-        region->write(iodev->redist_vcpu, addr, len, data);
+        region->write(iodev->redist_vcpu, addr - gfn_to_gaddr(iodev->base_fn), len, data);
         break;
     case IODEV_ITS:
-        region->its_write(vcpu->domain, iodev->its, addr, len, data);
+        region->its_write(vcpu->domain, iodev->its, addr - gfn_to_gaddr(iodev->base_fn), len, data);
         break;
     }
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/25 arm: vgic: its: Decouple HW and virtual ITS

In reply to Mykyta Poturai

HW its directly uses struct pending_irq which makes it hard to swich to a different VITS implementation if it doesn't use the same structure.

Rename struct its_device to struct vgic_its_device and move it to vgic.h, so it can be defined by the VITS implementation. Add helper functions to allow HW ITS to allocate/free and manage the instances this struct. This seems like a sane approach, since the instances are already stored in the struct vgic. Also move vgic_vcpu_inject_lpi to the vgic files for the same reasons.

---
 xen/arch/arm/gic-v3-its.c             | 208 ++++----------------------
 xen/arch/arm/gic-v3-lpi.c             |  20 ---
 xen/arch/arm/include/asm/gic_v3_its.h |   2 +
 xen/arch/arm/include/asm/vgic.h       |  29 ++++
 xen/arch/arm/vgic-v3-its.c            | 206 ++++++++++++++++++++++++-
 5 files changed, 258 insertions(+), 207 deletions(-)
xen/arch/arm/gic-v3-its.c +27 -181
index 8afcd9783b..cc3d82cde1 100644
@@ -13,7 +13,6 @@
 #include <xen/iocap.h>
 #include <xen/libfdt/libfdt.h>
 #include <xen/mm.h>
-#include <xen/rbtree.h>
 #include <xen/sched.h>
 #include <xen/sizes.h>
 #include <asm/gic.h>
@@ -30,25 +29,6 @@
  */
 LIST_HEAD(host_its_list);
 
-/*
- * Describes a device which is using the ITS and is used by a guest.
- * Since device IDs are per ITS (in contrast to vLPIs, which are per
- * guest), we have to differentiate between different virtual ITSes.
- * We use the doorbell address here, since this is a nice architectural
- * property of MSIs in general and we can easily get to the base address
- * of the ITS and look that up.
- */
-struct its_device {
-    struct rb_node rbnode;
-    struct host_its *hw_its;
-    void *itt_addr;
-    paddr_t guest_doorbell;             /* Identifies the virtual ITS */
-    uint32_t host_devid;
-    uint32_t guest_devid;
-    uint32_t eventids;                  /* Number of event IDs (MSIs) */
-    uint32_t *host_lpi_blocks;          /* Which LPIs are used on the host */
-    struct pending_irq *pend_irqs;      /* One struct per event */
-};
 
 bool gicv3_its_host_has_its(void)
 {
@@ -509,7 +489,7 @@ static int gicv3_its_init_single_its(struct host_its *hw_its)
  * TODO: Investigate the interaction when a guest removes a device while
  * some LPIs are still in flight.
  */
-static int remove_mapped_guest_device(struct its_device *dev)
+static int remove_mapped_guest_device(struct vgic_its_device *dev)
 {
     int ret = 0;
     unsigned int i;
@@ -530,10 +510,7 @@ static int remove_mapped_guest_device(struct its_device *dev)
         printk(XENLOG_WARNING "Can't unmap host ITS device 0x%x\n",
                dev->host_devid);
 
-    xfree(dev->itt_addr);
-    xfree(dev->pend_irqs);
-    xfree(dev->host_lpi_blocks);
-    xfree(dev);
+    vgic_its_free_device(dev);
 
     return 0;
 }
@@ -551,24 +528,6 @@ static struct host_its *gicv3_its_find_by_doorbell(paddr_t doorbell_address)
     return NULL;
 }
 
-static int compare_its_guest_devices(struct its_device *dev,
-                                     paddr_t vdoorbell, uint32_t vdevid)
-{
-    if ( dev->guest_doorbell < vdoorbell )
-        return -1;
-
-    if ( dev->guest_doorbell > vdoorbell )
-        return 1;
-
-    if ( dev->guest_devid < vdevid )
-        return -1;
-
-    if ( dev->guest_devid > vdevid )
-        return 1;
-
-    return 0;
-}
-
 /*
  * On the host ITS @its, map @nr_events consecutive LPIs.
  * The mapping connects a device @devid and event @eventid pair to LPI @lpi,
@@ -616,8 +575,7 @@ int gicv3_its_map_guest_device(struct domain *d,
 {
     void *itt_addr = NULL;
     struct host_its *hw_its;
-    struct its_device *dev = NULL;
-    struct rb_node **new = &d->arch.vgic.its_devices.rb_node, *parent = NULL;
+    struct vgic_its_device *temp, *dev = NULL;
     int i, ret = -ENOENT;      /* "i" must be signed to check for >= 0 below. */
 
     hw_its = gicv3_its_find_by_doorbell(host_doorbell);
@@ -643,36 +601,22 @@ int gicv3_its_map_guest_device(struct domain *d,
 
     /* check for already existing mappings */
     spin_lock(&d->arch.vgic.its_devices_lock);
-    while ( *new )
+    temp = vgic_its_get_device(d, guest_doorbell, guest_devid);
+    if ( temp )
     {
-        struct its_device *temp;
-        int cmp;
+        if ( !valid )
+            vgic_its_delete_device(d, temp);
 
-        temp = rb_entry(*new, struct its_device, rbnode);
+        spin_unlock(&d->arch.vgic.its_devices_lock);
 
-        parent = *new;
-        cmp = compare_its_guest_devices(temp, guest_doorbell, guest_devid);
-        if ( !cmp )
+        if ( valid )
         {
-            if ( !valid )
-                rb_erase(&temp->rbnode, &d->arch.vgic.its_devices);
-
-            spin_unlock(&d->arch.vgic.its_devices_lock);
-
-            if ( valid )
-            {
-                printk(XENLOG_G_WARNING "d%d tried to remap guest ITS device 0x%x to host device 0x%x\n",
-                        d->domain_id, guest_devid, host_devid);
-                return -EBUSY;
-            }
-
-            return remove_mapped_guest_device(temp);
+            printk(XENLOG_G_WARNING "d%d tried to remap guest ITS device 0x%x to host device 0x%x\n",
+                    d->domain_id, guest_devid, host_devid);
+            return -EBUSY;
         }
 
-        if ( cmp > 0 )
-            new = &((*new)->rb_left);
-        else
-            new = &((*new)->rb_right);
+        return remove_mapped_guest_device(temp);
     }
 
     if ( !valid )
@@ -688,7 +632,7 @@ int gicv3_its_map_guest_device(struct domain *d,
     clean_and_invalidate_dcache_va_range(itt_addr,
                                          nr_events * hw_its->itte_size);
 
-    dev = xzalloc(struct its_device);
+    dev = vgic_its_alloc_device(nr_events);
     if ( !dev )
         goto out_unlock;
 
@@ -704,13 +648,6 @@ int gicv3_its_map_guest_device(struct domain *d,
      * See the mailing list discussion for some background:
      * https://lists.xen.org/archives/html/xen-devel/2017-03/msg03645.html
      */
-    dev->pend_irqs = xzalloc_array(struct pending_irq, nr_events);
-    if ( !dev->pend_irqs )
-        goto out_unlock;
-
-    dev->host_lpi_blocks = xzalloc_array(uint32_t, nr_events);
-    if ( !dev->host_lpi_blocks )
-        goto out_unlock;
 
     ret = its_send_cmd_mapd(hw_its, host_devid, fls(nr_events - 1),
                             virt_to_maddr(itt_addr), true);
@@ -724,8 +661,7 @@ int gicv3_its_map_guest_device(struct domain *d,
     dev->host_devid = host_devid;
     dev->eventids = nr_events;
 
-    rb_link_node(&dev->rbnode, parent, new);
-    rb_insert_color(&dev->rbnode, &d->arch.vgic.its_devices);
+    vgic_its_add_device(d, dev);
 
     spin_unlock(&d->arch.vgic.its_devices_lock);
 
@@ -771,117 +707,27 @@ out_unlock:
 
 out:
     if ( dev )
-    {
-        xfree(dev->pend_irqs);
-        xfree(dev->host_lpi_blocks);
-    }
+        vgic_its_free_device(dev);
+
     xfree(itt_addr);
-    xfree(dev);
 
     return ret;
 }
 
-/* Must be called with the its_device_lock held. */
-static struct its_device *get_its_device(struct domain *d, paddr_t vdoorbell,
-                                         uint32_t vdevid)
-{
-    struct rb_node *node = d->arch.vgic.its_devices.rb_node;
-    struct its_device *dev;
-
-    ASSERT(spin_is_locked(&d->arch.vgic.its_devices_lock));
-
-    while (node)
-    {
-        int cmp;
-
-        dev = rb_entry(node, struct its_device, rbnode);
-        cmp = compare_its_guest_devices(dev, vdoorbell, vdevid);
-
-        if ( !cmp )
-            return dev;
-
-        if ( cmp > 0 )
-            node = node->rb_left;
-        else
-            node = node->rb_right;
-    }
-
-    return NULL;
-}
-
-static struct pending_irq *get_event_pending_irq(struct domain *d,
-                                                 paddr_t vdoorbell_address,
-                                                 uint32_t vdevid,
-                                                 uint32_t eventid,
-                                                 uint32_t *host_lpi)
-{
-    struct its_device *dev;
-    struct pending_irq *pirq = NULL;
-
-    spin_lock(&d->arch.vgic.its_devices_lock);
-    dev = get_its_device(d, vdoorbell_address, vdevid);
-    if ( dev && eventid < dev->eventids )
-    {
-        pirq = &dev->pend_irqs[eventid];
-        if ( host_lpi )
-            *host_lpi = dev->host_lpi_blocks[eventid / LPI_BLOCK] +
-                        (eventid % LPI_BLOCK);
-    }
-    spin_unlock(&d->arch.vgic.its_devices_lock);
-
-    return pirq;
-}
-
-struct pending_irq *gicv3_its_get_event_pending_irq(struct domain *d,
-                                                    paddr_t vdoorbell_address,
-                                                    uint32_t vdevid,
-                                                    uint32_t eventid)
-{
-    return get_event_pending_irq(d, vdoorbell_address, vdevid, eventid, NULL);
-}
-
-int gicv3_remove_guest_event(struct domain *d, paddr_t vdoorbell_address,
-                             uint32_t vdevid, uint32_t eventid)
+uint32_t gicv3_its_get_host_lpi(struct domain *d, paddr_t vdoorbell_address,
+                                     uint32_t vdevid, uint32_t eventid)
 {
+    struct vgic_its_device *dev;
     uint32_t host_lpi = INVALID_LPI;
 
-    if ( !get_event_pending_irq(d, vdoorbell_address, vdevid, eventid,
-                                &host_lpi) )
-        return -EINVAL;
-
-    if ( host_lpi == INVALID_LPI )
-        return -EINVAL;
-
-    gicv3_lpi_update_host_entry(host_lpi, d->domain_id, INVALID_LPI);
-
-    return 0;
-}
-
-/*
- * Connects the event ID for an already assigned device to the given VCPU/vLPI
- * pair. The corresponding physical LPI is already mapped on the host side
- * (when assigning the physical device to the guest), so we just connect the
- * target VCPU/vLPI pair to that interrupt to inject it properly if it fires.
- * Returns a pointer to the already allocated struct pending_irq that is
- * meant to be used by that event.
- */
-struct pending_irq *gicv3_assign_guest_event(struct domain *d,
-                                             paddr_t vdoorbell_address,
-                                             uint32_t vdevid, uint32_t eventid,
-                                             uint32_t virt_lpi)
-{
-    struct pending_irq *pirq;
-    uint32_t host_lpi = INVALID_LPI;
-
-    pirq = get_event_pending_irq(d, vdoorbell_address, vdevid, eventid,
-                                 &host_lpi);
-
-    if ( !pirq )
-        return NULL;
-
-    gicv3_lpi_update_host_entry(host_lpi, d->domain_id, virt_lpi);
+    spin_lock(&d->arch.vgic.its_devices_lock);
+    dev = vgic_its_get_device(d, vdoorbell_address, vdevid);
+    if ( dev )
+        host_lpi = dev->host_lpi_blocks[eventid / LPI_BLOCK] +
+                   (eventid % LPI_BLOCK);
 
-    return pirq;
+    spin_unlock(&d->arch.vgic.its_devices_lock);
+    return host_lpi;
 }
 
 int gicv3_its_deny_access(struct domain *d)
xen/arch/arm/gic-v3-lpi.c +0 -20
index eb0a5535e4..5f73b2b9f2 100644
@@ -128,26 +128,6 @@ uint64_t gicv3_get_redist_address(unsigned int cpu, bool use_pta)
         return per_cpu(lpi_redist, cpu).redist_id << 16;
 }
 
-void vgic_vcpu_inject_lpi(struct domain *d, unsigned int virq)
-{
-    /*
-     * TODO: this assumes that the struct pending_irq stays valid all of
-     * the time. We cannot properly protect this with the current locking
-     * scheme, but the future per-IRQ lock will solve this problem.
-     */
-    struct pending_irq *p = irq_to_pending(d->vcpu[0], virq);
-    unsigned int vcpu_id;
-
-    if ( !p )
-        return;
-
-    vcpu_id = ACCESS_ONCE(p->lpi_vcpu_id);
-    if ( vcpu_id >= d->max_vcpus )
-          return;
-
-    vgic_inject_irq(d, d->vcpu[vcpu_id], virq, true);
-}
-
 /*
  * Handle incoming LPIs, which are a bit special, because they are potentially
  * numerous and also only get injected into guests. Treat them specially here,
xen/arch/arm/include/asm/gic_v3_its.h +2 -0
index c24d4752d0..f61a37a8fa 100644
@@ -196,6 +196,8 @@ struct pending_irq *gicv3_assign_guest_event(struct domain *d,
                                              uint32_t virt_lpi);
 void gicv3_lpi_update_host_entry(uint32_t host_lpi, int domain_id,
                                  uint32_t virt_lpi);
+uint32_t gicv3_its_get_host_lpi(struct domain *d, paddr_t vdoorbell_address,
+                                     uint32_t vdevid, uint32_t eventid);
 
 #else
 
xen/arch/arm/include/asm/vgic.h +29 -0
index 922779ce14..56a3b6f828 100644
@@ -317,6 +317,35 @@ extern bool vgic_migrate_irq(struct vcpu *old, struct vcpu *new, unsigned int ir
 extern void vgic_check_inflight_irqs_pending(struct domain *d, struct vcpu *v,
                                              unsigned int rank, uint32_t r);
 
+#ifdef CONFIG_HAS_ITS
+/*
+ * Describes a device which is using the ITS and is used by a guest.
+ * Since device IDs are per ITS (in contrast to vLPIs, which are per
+ * guest), we have to differentiate between different virtual ITSes.
+ * We use the doorbell address here, since this is a nice architectural
+ * property of MSIs in general and we can easily get to the base address
+ * of the ITS and look that up.
+ */
+struct vgic_its_device {
+    struct rb_node rbnode;
+    struct host_its *hw_its;
+    void *itt_addr;
+    paddr_t guest_doorbell;             /* Identifies the virtual ITS */
+    uint32_t host_devid;
+    uint32_t guest_devid;
+    uint32_t eventids;                  /* Number of event IDs (MSIs) */
+    uint32_t *host_lpi_blocks;          /* Which LPIs are used on the host */
+    struct pending_irq *pend_irqs;      /* One struct per event */
+};
+
+struct vgic_its_device *vgic_its_alloc_device(int nr_events);
+void vgic_its_free_device(struct vgic_its_device *its_dev);
+int vgic_its_add_device(struct domain *d, struct vgic_its_device *its_dev);
+void vgic_its_delete_device(struct domain *d, struct vgic_its_device *its_dev);
+struct vgic_its_device* vgic_its_get_device(struct domain *d, paddr_t vdoorbell,
+                                         uint32_t vdevid);
+#endif /* CONFIG_HAS_ITS */
+
 #endif /* !CONFIG_NEW_VGIC */
 
 /*** Common VGIC functions used by Xen arch code ****/
xen/arch/arm/vgic-v3-its.c +200 -6

248 lines not on this page · raw message

Signature · 1 line
2.34.1
#9 lore raw

PATCH v2 9/25 arm: new VGIC: vgic_init: implement map_resources

In reply to Mykyta Poturai

map_resources is the last initialization step needed before the first VCPU is run. At that stage the code stores the MMIO base addresses used. Also it registers the respective register frames with the MMIO framework.

This is based on Linux commit b0442ee227e826af by Eric Auger

---
 xen/arch/arm/vgic/vgic-init.c |  2 +-
 xen/arch/arm/vgic/vgic-v3.c   | 85 +++++++++++++++++++++++++++++++++++
 xen/arch/arm/vgic/vgic.c      | 13 +-----
 xen/arch/arm/vgic/vgic.h      |  5 +++
 4 files changed, 93 insertions(+), 12 deletions(-)
xen/arch/arm/vgic/vgic-init.c +1 -1
index c3b34be192..ca13cf385c 100644
@@ -178,7 +178,7 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)
     if ( dist->version == GIC_V2 )
         ret = vgic_v2_map_resources(d);
     else
-        ret = -ENXIO;
+        ret = vgic_v3_map_resources(d);
 
     if ( ret )
         return ret;
xen/arch/arm/vgic/vgic-v3.c +85 -0

99 lines not on this page · raw message

xen/arch/arm/vgic/vgic.c +2 -11
index 946877bbac..2f9644dc18 100644
@@ -968,23 +968,14 @@ unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version)
     {
     case XEN_DOMCTL_CONFIG_GIC_V2:
         return VGIC_V2_MAX_CPUS;
+    case XEN_DOMCTL_CONFIG_GIC_V3:
+        return VGIC_V3_MAX_CPUS;
 
     default:
         return 0;
     }
 }
 
-#ifdef CONFIG_GICV3
-/* Dummy implementation to allow building without actual vGICv3 support. */
-void vgic_v3_setup_hw(paddr_t dbase,
-                      unsigned int nr_rdist_regions,
-                      const struct rdist_region *regions,
-                      unsigned int intid_bits)
-{
-    panic("New VGIC implementation does not yet support GICv3\n");
-}
-#endif
-
 /*
  * Local variables:
  * mode: C
xen/arch/arm/vgic/vgic.h +5 -0
index 0e0cf7b213..7dbadf7501 100644
@@ -74,6 +74,7 @@ int vgic_register_dist_iodev(struct domain *d, gfn_t dist_base_fn,
 #ifdef CONFIG_GICV3
 void vgic_v3_fold_lr_state(struct vcpu *vcpu);
 void vgic_v3_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr);
+int vgic_v3_map_resources(struct domain *d);
 bool vgic_v3_emulate_reg(struct cpu_user_regs *regs, union hsr hsr);
 unsigned int vgic_v3_init_dist_iodev(struct vgic_io_device *dev);
 int vgic_v3_set_redist_base(struct domain *d, u32 index, u64 addr, u32 count);
@@ -85,6 +86,10 @@ static inline void vgic_v3_fold_lr_state(struct vcpu *vcpu)
 static inline void vgic_v3_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr)
 {
 }
+static inline int vgic_v3_map_resources(struct domain *d)
+{
+    return 0;
+}
 static inline unsigned int vgic_v3_init_dist_iodev(struct vgic_io_device *dev)
 {
     return 0;
Signature · 1 line
2.34.1
#19 lore raw

PATCH v2 19/25 arm: new VGIC: its: Add LPI translation cache definition

In reply to Mykyta Poturai

Add the basic data structure that expresses an MSI to LPI translation as well as the allocation/release hooks.

Implement cache invalidation, lookup and storage.

The size of the cache is arbitrarily defined as 16*nr_vcpus.

This is based on Linux commits 24cab82c34aa6f, 7d825fd6eaa7467, 89489ee9ced8 and 86a7dae884f38 by Marc Zyngier

---
 xen/arch/arm/include/asm/new_vgic.h |   3 +
 xen/arch/arm/vgic/vgic-its.c        | 195 ++++++++++++++++++++++++++++
 2 files changed, 198 insertions(+)
xen/arch/arm/include/asm/new_vgic.h +3 -0
index d0fd15e154..b038fb7861 100644
@@ -212,6 +212,9 @@ struct vgic_dist {
     spinlock_t          lpi_list_lock;
     struct list_head    lpi_list_head;
     unsigned int        lpi_list_count;
+
+    /* LPI translation cache */
+    struct list_head	lpi_translation_cache;
 };
 
 struct vgic_cpu {
xen/arch/arm/vgic/vgic-its.c +195 -0

237 lines not on this page · raw message

Signature · 1 line
2.34.1
#21 lore raw

PATCH v2 21/25 arm: new VGIC: its: Implement MSI injection in ITS emulation

In reply to Mykyta Poturai

Implement handling of the ITS INT command.
With the help of the IO bus framework we learn the corresponding ITS from the doorbell address. We then use our wrapper functions to iterate the linked lists and find the proper Interrupt Translation Table Entry (ITTE) and thus the corresponding struct vgic_irq to finally set the pending bit.

Based on Linux commit 2891a7dfb6c4a by Andre Przywara

---
 xen/arch/arm/vgic/vgic-its.c | 112 +++++++++++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)
xen/arch/arm/vgic/vgic-its.c +112 -0
index 9a30087d3d..9534b26334 100644
@@ -557,6 +557,81 @@ static u32 max_lpis_propbaser(u64 propbaser)
     return 1U << min(nr_idbits, INTERRUPT_ID_BITS_ITS);
 }
 
+int vgic_its_resolve_lpi(struct domain *d, struct vgic_its *its, u32 devid,
+                         u32 eventid, struct vgic_irq **irq)
+{
+    struct vcpu *vcpu;
+    struct its_ite *ite;
+
+    if ( !its->enabled )
+        return -EBUSY;
+
+    ite = find_ite(its, devid, eventid);
+    if ( !ite || !its_is_collection_mapped(ite->collection) )
+        return E_ITS_INT_UNMAPPED_INTERRUPT;
+
+    vcpu = d->vcpu[ite->collection->target_addr];
+    if ( !vcpu )
+        return E_ITS_INT_UNMAPPED_INTERRUPT;
+
+    if ( !vgic_lpis_enabled(vcpu) )
+        return -EBUSY;
+
+    vgic_its_cache_translation(d, its, devid, eventid, ite->irq);
+
+    *irq = ite->irq;
+    return 0;
+}
+
+int vgic_its_inject_cached_translation(struct domain *d, struct vgic_its *its, u32 devid, u32 eventid)
+{
+	struct vgic_irq *irq;
+	unsigned long flags;
+	paddr_t db;
+
+	db = its->vgic_its_base + GITS_TRANSLATER;
+	irq = vgic_its_check_cache(d, db, devid, eventid);
+	if (!irq)
+		return -EWOULDBLOCK;
+
+	spin_lock_irqsave(&irq->irq_lock, flags);
+	irq->pending_latch = true;
+	vgic_queue_irq_unlock(d, irq, flags);
+
+	return 0;
+}
+
+/*
+ * Find the target VCPU and the LPI number for a given devid/eventid pair
+ * and make this IRQ pending, possibly injecting it.
+ * Must be called with the its_lock mutex held.
+ * Returns 0 on success, a positive error value for any ITS mapping
+ * related errors and negative error values for generic errors.
+ */
+static int vgic_its_trigger_msi(struct domain *d, struct vgic_its *its,
+                                u32 devid, u32 eventid)
+{
+    struct vgic_irq *irq = NULL;
+    unsigned long flags;
+    int err;
+
+	if (!vgic_its_inject_cached_translation(d, its, devid, eventid))
+		return 1;
+
+    err = vgic_its_resolve_lpi(d, its, devid, eventid, &irq);
+    if ( err )
+        return err;
+
+    /* GICv4 style VLPIS are not yet supported */
+    WARN_ON(irq->hw);
+
+    spin_lock_irqsave(&irq->irq_lock, flags);
+    irq->pending_latch = true;
+    vgic_queue_irq_unlock(d, irq, flags);
+
+    return 0;
+}
+
 static u64 its_cmd_mask_field(u64 *its_cmd, int word, int shift, int size)
 {
     return (le64_to_cpu(its_cmd[word]) >> shift) & (BIT(size, ULL) - 1);
@@ -868,6 +943,27 @@ void vgic_its_delete_device(struct domain *d, struct vgic_its_device *its_dev)
     list_del(&its_dev->dev_list);
 }
 
+void vgic_vcpu_inject_lpi(struct domain *d, unsigned int virq)
+{
+    /*
+     * TODO: this assumes that the struct pending_irq stays valid all of
+     * the time. We cannot properly protect this with the current locking
+     * scheme, but the future per-IRQ lock will solve this problem.
+     */
+    struct vgic_irq *p = vgic_get_irq(d, d->vcpu[0], virq);
+    unsigned int vcpu_id;
+
+    if ( !p )
+        return;
+
+    vcpu_id = ACCESS_ONCE(p->target_vcpu->vcpu_id);
+    if ( vcpu_id >= d->max_vcpus )
+          return;
+
+    vgic_put_irq(d, p);
+    vgic_inject_irq(d, d->vcpu[vcpu_id], virq, true);
+}
+
 /*
  * MAPD maps or unmaps a device ID to Interrupt Translation Tables (ITTs).
  * Must be called with the its_lock mutex held.
@@ -1173,6 +1269,19 @@ static int vgic_its_cmd_handle_movall(struct domain *d, struct vgic_its *its,
     return 0;
 }
 
+/*
+ * The INT command injects the LPI associated with that DevID/EvID pair.
+ * Must be called with the its_lock mutex held.
+ */
+static int vgic_its_cmd_handle_int(struct domain *d, struct vgic_its *its,
+                                   u64 *its_cmd)
+{
+    u32 msi_data  = its_cmd_get_id(its_cmd);
+    u64 msi_devid = its_cmd_get_deviceid(its_cmd);
+
+    return vgic_its_trigger_msi(d, its, msi_devid, msi_data);
+}
+
 int vgic_its_inv_lpi(struct domain *d, struct vgic_irq *irq)
 {
     return update_lpi_config(d, irq, NULL, true);
@@ -1288,6 +1397,9 @@ static int vgic_its_handle_command(struct domain *d, struct vgic_its *its,
     case GITS_CMD_MOVALL:
         ret = vgic_its_cmd_handle_movall(d, its, its_cmd);
         break;
+    case GITS_CMD_INT:
+        ret = vgic_its_cmd_handle_int(d, its, its_cmd);
+        break;
     case GITS_CMD_INV:
         ret = vgic_its_cmd_handle_inv(d, its, its_cmd);
         break;
Signature · 1 line
2.34.1
#22 lore raw

PATCH v2 22/25 arm: new VGIC: its: Implement MMIO-based LPI invalidation

In reply to Mykyta Poturai

Since GICv4.1, it has become legal for an implementation to advertise GICR_{INVLPIR,INVALLR,SYNCR} while having an ITS, allowing for a more efficient invalidation scheme (no guest command queue contention when multiple CPUs are generating invalidations).

Provide the invalidation registers as a primitive to their ITS counterpart. Note that we don't advertise them to the guest yet.

Based on Linux commit 4645d11f4a553 by Marc Zyngier

---
 xen/arch/arm/include/asm/new_vgic.h |  1 +
 xen/arch/arm/vgic/vgic-mmio-v3.c    | 65 +++++++++++++++++++++++++++--
 xen/arch/arm/vgic/vgic-mmio.h       | 15 +++++++
 3 files changed, 78 insertions(+), 3 deletions(-)
xen/arch/arm/include/asm/new_vgic.h +1 -0
index b038fb7861..dfc434ab41 100644
@@ -239,6 +239,7 @@ struct vgic_cpu {
     struct vgic_io_device   rd_iodev;
     struct vgic_redist_region *rdreg;
     uint32_t rdreg_index;
+    atomic_t syncr_busy;
     struct vgic_io_device   sgi_iodev;
 
     /* Contains the attributes and gpa of the LPI pending tables. */
xen/arch/arm/vgic/vgic-mmio-v3.c +62 -3

81 lines not on this page · raw message

xen/arch/arm/vgic/vgic-mmio.h +15 -0
index edf8665cda..12f4d690f6 100644
@@ -153,4 +153,19 @@ unsigned long extract_bytes(uint64_t data, unsigned int offset,
 uint64_t update_64bit_reg(u64 reg, unsigned int offset, unsigned int len,
 		     unsigned long val);
 
+#ifdef CONFIG_HAS_ITS
+int vgic_its_inv_lpi(struct domain *d, struct vgic_irq *irq);
+int vgic_its_invall(struct vcpu *vcpu);
+#else
+static inline int vgic_its_inv_lpi(struct domain *d, struct vgic_irq *irq)
+{
+    return 0;
+}
+
+static inline int vgic_its_invall(struct vcpu *vcpu)
+{
+    return 0;
+}
+#endif
+
 #endif
Signature · 1 line
2.34.1
#23 lore raw

PATCH v2 23/25 arm: new VGIC: its: Enable ITS emulation as a virtual MSI controller

In reply to Mykyta Poturai

Now that all ITS emulation functionality is in place, we advertise the ITS device to the guest.

Based on Linux commit 0e4e82f154e38 by Andre Przywara

---
 xen/arch/arm/vgic/vgic-init.c    |  7 +++++
 xen/arch/arm/vgic/vgic-its.c     |  2 +-
 xen/arch/arm/vgic/vgic-mmio-v3.c | 44 ++++++++++++++++++++++++++++++--
 xen/arch/arm/vgic/vgic-mmio.h    |  5 ++++
 4 files changed, 55 insertions(+), 3 deletions(-)
xen/arch/arm/vgic/vgic-init.c +7 -0
index 96f6669d38..fb27e440fc 100644
@@ -18,6 +18,7 @@
 #include <xen/lib.h>
 #include <xen/sched.h>
 #include <asm/new_vgic.h>
+#include <asm/gic_v3_its.h>
 
 #include "vgic.h"
 
@@ -173,8 +174,14 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)
     }
 
     INIT_LIST_HEAD(&dist->lpi_list_head);
+    INIT_LIST_HEAD(&dist->lpi_translation_cache);
+    dist->lpi_list_count=0;
     spin_lock_init(&dist->lpi_list_lock);
 
+    ret = vgic_v3_its_init_domain(d);
+    if ( ret )
+        return ret;
+
     if ( dist->version == GIC_V2 )
         ret = vgic_v2_map_resources(d);
     else
xen/arch/arm/vgic/vgic-its.c +1 -1
index 9534b26334..3b097bd0c4 100644
@@ -168,7 +168,7 @@ static int update_lpi_config(struct domain *d, struct vgic_irq *irq,
     return 0;
 }
 
-static int vgic_v3_lpi_sync_pending_status(struct domain *d, struct vgic_irq *irq)
+int vgic_v3_lpi_sync_pending_status(struct domain *d, struct vgic_irq *irq)
 {
     struct vcpu *vcpu;
     int byte_offset, bit_nr;
xen/arch/arm/vgic/vgic-mmio-v3.c +42 -2

80 lines not on this page · raw message

xen/arch/arm/vgic/vgic-mmio.h +5 -0
index 12f4d690f6..32fc7a6ba2 100644
@@ -156,6 +156,7 @@ uint64_t update_64bit_reg(u64 reg, unsigned int offset, unsigned int len,
 #ifdef CONFIG_HAS_ITS
 int vgic_its_inv_lpi(struct domain *d, struct vgic_irq *irq);
 int vgic_its_invall(struct vcpu *vcpu);
+void vgic_its_invalidate_cache(struct domain *d);
 #else
 static inline int vgic_its_inv_lpi(struct domain *d, struct vgic_irq *irq)
 {
@@ -166,6 +167,10 @@ static inline int vgic_its_invall(struct vcpu *vcpu)
 {
     return 0;
 }
+
+static inline void vgic_its_invalidate_cache(struct domain *d)
+{
+}
 #endif
 
 #endif
Signature · 1 line
2.34.1
#14 lore raw

PATCH v2 14/25 arm: new VGIC: its: Introduce ITS emulation file with MMIO framework

In reply to Mykyta Poturai

The ARM GICv3 ITS emulation code goes into a separate file, but needs to be connected to the GICv3 emulation, of which it is an option. The ITS MMIO handlers require the respective ITS pointer to be passed in, so we amend the existing VGIC MMIO framework to let it cope with that. Also we introduce the basic ITS data structure and initialize it, but don't return any success yet, as we are not yet ready for the show.

Based on Linux commit 59c5ab40989afa by 59c5ab40989afa

---
 xen/arch/arm/include/asm/gic_v3_defs.h |   3 +
 xen/arch/arm/include/asm/gic_v3_its.h  |   1 +
 xen/arch/arm/include/asm/new_vgic.h    |  13 ++
 xen/arch/arm/vgic/vgic-its.c           | 160 +++++++++++++++++++++++++
 xen/arch/arm/vgic/vgic-mmio-v3.c       |  52 +++++++-
 xen/arch/arm/vgic/vgic-mmio.c          |   6 +
 xen/arch/arm/vgic/vgic-mmio.h          |  11 ++
 7 files changed, 245 insertions(+), 1 deletion(-)
 create mode 100644 xen/arch/arm/vgic/vgic-its.c
xen/arch/arm/include/asm/gic_v3_defs.h +3 -0
index 1e81687818..3f1f59d1c7 100644
@@ -112,6 +112,9 @@
 #define GICR_NSACR                   (0x0E00)
 
 #define GICR_CTLR_ENABLE_LPIS        (1U << 0)
+#define GICR_CTLR_CES                (1UL << 1)
+#define GICR_CTLR_IR                 (1UL << 2)
+#define GICR_CTLR_RWP                (1UL << 3)
 
 #define GICR_TYPER_PLPIS             (1U << 0)
 #define GICR_TYPER_VLPIS             (1U << 1)
xen/arch/arm/include/asm/gic_v3_its.h +1 -0
index f61a37a8fa..4e857cac1a 100644
@@ -35,6 +35,7 @@
 #define GITS_BASER5                     0x128
 #define GITS_BASER6                     0x130
 #define GITS_BASER7                     0x138
+#define GITS_IDREGS_BASE                0xffd0
 #define GITS_PIDR2                      GICR_PIDR2
 
 /* Register bits */
xen/arch/arm/include/asm/new_vgic.h +13 -0
index b037b6cf61..ec2882dcf1 100644
@@ -34,6 +34,7 @@
 #define VGIC_MIN_LPI            8192
 #define VGIC_V3_DIST_SIZE       SZ_64K
 #define VGIC_V3_REDIST_SIZE     (2 * SZ_64K)
+#define VGIC_V3_ITS_SIZE        (2 * SZ_64K)
 
 #define irq_is_ppi(irq) ((irq) >= VGIC_NR_SGIS && (irq) < VGIC_NR_PRIVATE_IRQS)
 #define irq_is_spi(irq) ((irq) >= VGIC_NR_PRIVATE_IRQS && \
@@ -95,6 +96,7 @@ struct vgic_irq {
 enum iodev_type {
     IODEV_DIST,
     IODEV_REDIST,
+    IODEV_ITS,
 };
 
 struct vgic_redist_region {
@@ -111,6 +113,16 @@ struct vgic_io_device {
     const struct vgic_register_region *regions;
     enum iodev_type iodev_type;
     unsigned int nr_regions;
+    struct vgic_its *its;
+};
+
+struct vgic_its {
+    /* The base address of the ITS control register frame */
+    paddr_t vgic_its_base;
+
+    bool enabled;
+    struct vgic_io_device iodev;
+    paddr_t doorbell_address;
 };
 
 struct vgic_dist {
@@ -150,6 +162,7 @@ struct vgic_dist {
     struct vgic_io_device   dist_iodev;
 
     bool                has_its;
+    struct vgic_its     *its;
 
     /*
      * Contains the attributes and gpa of the LPI configuration table.
xen/arch/arm/vgic/vgic-its.c new file +160 -0

160 lines not on this page · raw message

xen/arch/arm/vgic/vgic-mmio-v3.c +51 -1

70 lines not on this page · raw message

xen/arch/arm/vgic/vgic-mmio.c +6 -0
index 1c3f861887..7a28be53bc 100644
@@ -570,6 +570,9 @@ static int dispatch_mmio_read(struct vcpu *vcpu, mmio_info_t *info,
     case IODEV_REDIST:
         data = region->read(iodev->redist_vcpu, addr, len);
         break;
+    case IODEV_ITS:
+        data = region->its_read(vcpu->domain, iodev->its, addr, len);;
+        break;
     }
 
     memcpy(r, &data, len);
@@ -598,6 +601,9 @@ static int dispatch_mmio_write(struct vcpu *vcpu, mmio_info_t *info,
     case IODEV_REDIST:
         region->write(iodev->redist_vcpu, addr, len, data);
         break;
+    case IODEV_ITS:
+        region->its_write(vcpu->domain, iodev->its, addr, len, data);
+        break;
     }
 
     return 1;
xen/arch/arm/vgic/vgic-mmio.h +11 -0
index 3566cf237c..0a8deb46ba 100644
@@ -21,10 +21,21 @@ struct vgic_register_region {
     unsigned int len;
     unsigned int bits_per_irq;
     unsigned int access_flags;
+
+    union {
     unsigned long (*read)(struct vcpu *vcpu, paddr_t addr,
                           unsigned int len);
+    unsigned long (*its_read)(struct domain *d, struct vgic_its *its,
+                    paddr_t addr, unsigned int len);
+    };
+
+    union {
     void (*write)(struct vcpu *vcpu, paddr_t addr,
                   unsigned int len, unsigned long val);
+    void (*its_write)(struct domain *d, struct vgic_its *its,
+                paddr_t addr, unsigned int len,
+                unsigned long val);
+    };
 };
 
 extern struct mmio_handler_ops vgic_io_ops;
Signature · 1 line
2.34.1
#16 lore raw

PATCH v2 16/25 arm: new VGIC: its: Implement basic ITS register handlers

In reply to Mykyta Poturai

Add emulation for some basic MMIO registers used in the ITS emulation. This includes:
- GITS_{CTLR,TYPER,IIDR}
- ID registers
- GITS_{CBASER,CREADR,CWRITER}
(which implement the ITS command buffer handling)
- GITS_BASER<n>

The registers holding base addresses and attributes are sanitised before storing them.

Base on Linux commit 424c33830f53f2 by Andre Przywara

---
 xen/arch/arm/include/asm/gic_v3_defs.h |   4 +
 xen/arch/arm/include/asm/gic_v3_its.h  |  60 ++++
 xen/arch/arm/include/asm/new_vgic.h    |  18 +
 xen/arch/arm/vgic/vgic-its.c           | 465 ++++++++++++++++++++++++-
 xen/arch/arm/vgic/vgic-mmio.h          |   7 +
 xen/arch/arm/vgic/vgic.h               |   5 +
 6 files changed, 546 insertions(+), 13 deletions(-)
xen/arch/arm/include/asm/gic_v3_defs.h +4 -0
index 3f1f59d1c7..e4e4696de3 100644
@@ -138,7 +138,11 @@
 #define GIC_BASER_NonShareable       0ULL
 #define GIC_BASER_InnerShareable     1ULL
 #define GIC_BASER_OuterShareable     2ULL
+#define GIC_BASER_SHAREABILITY_MASK  3ULL
 
+#define GICR_PROPBASER_IDBITS_MASK   (0x1f)
+#define GICR_PROPBASER_ADDRESS(x)    ((x) & GENMASK_ULL(51, 12))
+#define GICR_PENDBASER_ADDRESS(x)    ((x) & GENMASK_ULL(51, 16))
 #define GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT         56
 #define GICR_PROPBASER_OUTER_CACHEABILITY_MASK               \
         (7ULL << GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT)
xen/arch/arm/include/asm/gic_v3_its.h +60 -0

102 lines not on this page · raw message

xen/arch/arm/include/asm/new_vgic.h +18 -0
index 00a5557921..3048f39844 100644
@@ -122,7 +122,25 @@ struct vgic_its {
 
     bool enabled;
     struct vgic_io_device iodev;
+    struct domain *domain;
+
+    /* These registers correspond to GITS_BASER{0,1} */
+    u64 baser_device_table;
+    u64 baser_coll_table;
+
+    /* Protects the command queue */
+    struct spinlock cmd_lock;
+    u64 cbaser;
+    u32 creadr;
+    u32 cwriter;
+
+    /* migration ABI revision in use */
+    u32 abi_rev;
+
+    /* Protects the device and collection lists */
+    struct spinlock its_lock;
     struct list_head device_list;
+    struct list_head collection_list;
     paddr_t doorbell_address;
 };
 
xen/arch/arm/vgic/vgic-its.c +452 -13

536 lines not on this page · raw message

xen/arch/arm/vgic/vgic-mmio.h +7 -0
index 0a8deb46ba..edf8665cda 100644
@@ -146,4 +146,11 @@ void vgic_mmio_write_config(struct vcpu *vcpu,
 
 unsigned int vgic_v2_init_dist_iodev(struct vgic_io_device *dev);
 
+/* extract @num bytes at @offset bytes offset in data */
+unsigned long extract_bytes(uint64_t data, unsigned int offset,
+			    unsigned int num);
+
+uint64_t update_64bit_reg(u64 reg, unsigned int offset, unsigned int len,
+		     unsigned long val);
+
 #endif
xen/arch/arm/vgic/vgic.h +5 -0
index 791c91ebb3..a14b519f77 100644
@@ -80,6 +80,11 @@ bool vgic_v3_emulate_reg(struct cpu_user_regs *regs, union hsr hsr);
 unsigned int vgic_v3_init_dist_iodev(struct vgic_io_device *dev);
 int vgic_v3_set_redist_base(struct domain *d, u32 index, u64 addr, u32 count);
 int vgic_register_redist_iodev(struct vcpu *vcpu);
+u64 vgic_sanitise_field(u64 reg, u64 field_mask, int field_shift,
+			u64 (*sanitise_fn)(u64));
+u64 vgic_sanitise_shareability(u64 field);
+u64 vgic_sanitise_inner_cacheability(u64 field);
+u64 vgic_sanitise_outer_cacheability(u64 field);
 #else
 static inline void vgic_v3_fold_lr_state(struct vcpu *vcpu)
 {
Signature · 1 line
2.34.1
#6 lore raw

PATCH v2 6/25 arm: new VGIC: Add GICv3 IDREGS register handler

In reply to Mykyta Poturai

We implement the only one ID register that is required by the architecture, also this is the one that Linux actually checks.

Based on Linux commit 54f59d2b3a0a3d by Andre Przywara

---
 xen/arch/arm/vgic/vgic-mmio-v3.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/vgic/vgic-mmio-v3.c +15 -2
index 707a38c727..ccdf3b9456 100644
@@ -152,6 +152,19 @@ static unsigned long vgic_mmio_read_v3r_iidr(struct vcpu *vcpu, paddr_t addr,
            (IMPLEMENTER_ARM << 0);
 }
 
+static unsigned long vgic_mmio_read_v3_idregs(struct vcpu *vcpu, paddr_t addr,
+                                              unsigned int len)
+{
+    switch ( addr & 0xfff )
+    {
+    case GICD_ICPIDR2:
+        /* report a GICv3 compliant implementation */
+        return 0x3b;
+    }
+
+    return 0;
+}
+
 static const struct vgic_register_region vgic_v3_dist_registers[] = {
     REGISTER_DESC_WITH_LENGTH(GICD_CTLR,
         vgic_mmio_read_v3_misc, vgic_mmio_write_v3_misc,
@@ -196,7 +209,7 @@ static const struct vgic_register_region vgic_v3_dist_registers[] = {
         vgic_mmio_read_raz, vgic_mmio_write_wi, 64,
         VGIC_ACCESS_64bit | VGIC_ACCESS_32bit),
     REGISTER_DESC_WITH_LENGTH(GICD_IDREGS,
-        vgic_mmio_read_raz, vgic_mmio_write_wi, 48,
+        vgic_mmio_read_v3_idregs, vgic_mmio_write_wi, 48,
         VGIC_ACCESS_32bit),
 };
 
@@ -233,7 +246,7 @@ static const struct vgic_register_region vgic_v3_rd_registers[] = {
         vgic_mmio_read_raz, vgic_mmio_write_wi, 4,
         VGIC_ACCESS_32bit),
     REGISTER_DESC_WITH_LENGTH(GICR_IDREGS,
-        vgic_mmio_read_raz, vgic_mmio_write_wi, 48,
+        vgic_mmio_read_v3_idregs, vgic_mmio_write_wi, 48,
         VGIC_ACCESS_32bit),
     /* SGI_base registers */
     REGISTER_DESC_WITH_LENGTH(SZ_64K + GICR_IGROUPR0,
Signature · 1 line
2.34.1
#15 lore raw

PATCH v2 15/25 arm: new VGIC: its: Introduce ITS device list

In reply to Mykyta Poturai

Add the vgic_its_device structure and the list of devices to the vgic_its. Implement the functions to allocate, free, add and delete the device from the list. Add the function to find the device in the list by the device id. And make them avaliable to the HW ITS code.

---
 xen/arch/arm/include/asm/new_vgic.h | 27 +++++++++
 xen/arch/arm/vgic/vgic-its.c        | 86 +++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)
xen/arch/arm/include/asm/new_vgic.h +27 -0
index ec2882dcf1..00a5557921 100644
@@ -122,9 +122,26 @@ struct vgic_its {
 
     bool enabled;
     struct vgic_io_device iodev;
+    struct list_head device_list;
     paddr_t doorbell_address;
 };
 
+struct vgic_its_device {
+    struct list_head dev_list;
+    struct domain *d;
+
+    /* the head for the list of ITTEs */
+    struct list_head itt_head;
+    u32 num_eventid_bits;
+    void* itt_addr;
+    struct host_its *hw_its;
+    paddr_t guest_doorbell;             /* Identifies the virtual ITS */
+    uint32_t host_devid;
+    uint32_t guest_devid;
+    uint32_t eventids;                  /* Number of event IDs (MSIs) */
+    uint32_t *host_lpi_blocks;          /* Which LPIs are used on the host */
+};
+
 struct vgic_dist {
     bool                ready;
     bool                initialized;
@@ -171,6 +188,7 @@ struct vgic_dist {
      * GICv3 spec: 6.1.2 "LPI Configuration tables"
      */
     uint64_t            propbaser;
+    spinlock_t          its_devices_lock; /* Protects the its_devices list */
 
     /* Protects the lpi_list and the count value below. */
     spinlock_t          lpi_list_lock;
@@ -227,6 +245,15 @@ static inline paddr_t vgic_dist_base(const struct vgic_dist *vgic)
     return vgic->dbase;
 }
 
+#ifdef CONFIG_HAS_ITS
+struct vgic_its_device *vgic_its_alloc_device(int nr_events);
+void vgic_its_free_device(struct vgic_its_device *its_dev);
+int vgic_its_add_device(struct domain *d, struct vgic_its_device *its_dev);
+void vgic_its_delete_device(struct domain *d, struct vgic_its_device *its_dev);
+struct vgic_its_device* vgic_its_get_device(struct domain *d, paddr_t vdoorbell,
+                                         uint32_t vdevid);
+#endif
+
 #endif /* __ASM_ARM_NEW_VGIC_H */
 
 /*
xen/arch/arm/vgic/vgic-its.c +86 -0

92 lines not on this page · raw message

Signature · 1 line
2.34.1
#18 lore raw

PATCH v2 18/25 arm: new VGIC: its: Allow updates of LPI configuration table

In reply to Mykyta Poturai

The (system-wide) LPI configuration table is held in a table in (guest) memory. To achieve reasonable performance, we cache this data in our struct vgic_irq. If the guest updates the configuration data (which consists of the enable bit and the priority value), it issues an INV or INVALL command to allow us to update our information. Provide functions that update that information for one LPI or all LPIs mapped to a specific collection.

Based on Linux commit f9f77af9e2a551 by Andre Przywara

---
 xen/arch/arm/vgic/vgic-its.c | 48 ++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
xen/arch/arm/vgic/vgic-its.c +48 -0
index af19cf4414..6c726dde3a 100644
@@ -63,6 +63,54 @@ static struct vgic_its_device *find_its_device(struct vgic_its *its, u32 device_
 #define VGIC_ITS_TYPER_DEVBITS          16
 #define VGIC_ITS_TYPER_ITE_SIZE         8
 
+#define GIC_LPI_OFFSET              8192
+
+#define LPI_PROP_ENABLE_BIT(p) ((p)&LPI_PROP_ENABLED)
+#define LPI_PROP_PRIORITY(p)   ((p)&0xfc)
+
+/*
+ * Reads the configuration data for a given LPI from guest memory and
+ * updates the fields in struct vgic_irq.
+ * If filter_vcpu is not NULL, applies only if the IRQ is targeting this
+ * VCPU. Unconditionally applies if filter_vcpu is NULL.
+ */
+static int update_lpi_config(struct domain *d, struct vgic_irq *irq,
+                             struct vcpu *filter_vcpu, bool needs_inv)
+{
+    u64 propbase = GICR_PROPBASER_ADDRESS(d->arch.vgic.propbaser);
+    u8 prop;
+    int ret;
+    unsigned long flags;
+
+    ret = access_guest_memory_by_gpa(d, propbase + irq->intid - GIC_LPI_OFFSET,
+                                     &prop, 1, false);
+
+    if ( ret )
+        return ret;
+
+    spin_lock_irqsave(&irq->irq_lock, flags);
+
+    if ( !filter_vcpu || filter_vcpu == irq->target_vcpu )
+    {
+        irq->priority = LPI_PROP_PRIORITY(prop);
+        irq->enabled  = LPI_PROP_ENABLE_BIT(prop);
+
+        if ( !irq->hw )
+        {
+            vgic_queue_irq_unlock(d, irq, flags);
+            return 0;
+        }
+    }
+
+    spin_unlock_irqrestore(&irq->irq_lock, flags);
+
+    /* GICv4 style VLPIS are not yet supported */
+    WARN_ON(irq->hw);
+
+    return 0;
+}
+
+
 /*
  * Create a snapshot of the current LPIs targeting @vcpu, so that we can
  * enumerate those LPIs without holding any lock.
Signature · 1 line
2.34.1
#8 lore raw

PATCH v2 8/25 arm: new VGIC: Add GICv3 SGI system register trap handler

In reply to Mykyta Poturai

In contrast to GICv2 SGIs in a GICv3 implementation are not triggered by a MMIO write, but with a system register write. Xen knows about that register already, we just need to implement the handler and wire it up to the core Xen/ARM code.

Base on Linux commit 621ecd8d2123bc13 by Andre Przywara

---
 xen/arch/arm/include/asm/gic_v3_defs.h |   2 +-
 xen/arch/arm/vgic/vgic-mmio-v3.c       | 147 +++++++++++++++++++++++++
 xen/arch/arm/vgic/vgic.c               |  10 +-
 xen/arch/arm/vgic/vgic.h               |   5 +
 4 files changed, 160 insertions(+), 4 deletions(-)
xen/arch/arm/include/asm/gic_v3_defs.h +1 -1
index e0d536e887..1e81687818 100644
@@ -204,7 +204,7 @@
 #define ICH_SGI_IRQ_SHIFT            24
 #define ICH_SGI_IRQ_MASK             0xf
 #define ICH_SGI_TARGETLIST_MASK      0xffff
-#define ICH_SGI_AFFx_MASK            0xff
+#define ICH_SGI_AFFx_MASK            0xffULL
 #define ICH_SGI_AFFINITY_LEVEL(x)    (16 * (x))
 
 struct rdist_region {
xen/arch/arm/vgic/vgic-mmio-v3.c +147 -0

153 lines not on this page · raw message

xen/arch/arm/vgic/vgic.c +7 -3
index 97ca827fc4..946877bbac 100644
@@ -865,9 +865,13 @@ struct irq_desc *vgic_get_hw_irq_desc(struct domain *d, struct vcpu *v,
 
 bool vgic_emulate(struct cpu_user_regs *regs, union hsr hsr)
 {
-    ASSERT(current->domain->arch.vgic.version == GIC_V3);
-
-    return false;
+    switch ( current->domain->arch.vgic.version )
+    {
+    case GIC_V3:
+        return vgic_v3_emulate_reg(regs, hsr);
+    default:
+        return false;
+    }
 }
 
 /*
xen/arch/arm/vgic/vgic.h +5 -0
index b3bba7b5f3..0e0cf7b213 100644
@@ -74,6 +74,7 @@ int vgic_register_dist_iodev(struct domain *d, gfn_t dist_base_fn,
 #ifdef CONFIG_GICV3
 void vgic_v3_fold_lr_state(struct vcpu *vcpu);
 void vgic_v3_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr);
+bool vgic_v3_emulate_reg(struct cpu_user_regs *regs, union hsr hsr);
 unsigned int vgic_v3_init_dist_iodev(struct vgic_io_device *dev);
 int vgic_v3_set_redist_base(struct domain *d, u32 index, u64 addr, u32 count);
 int vgic_register_redist_iodev(struct vcpu *vcpu);
@@ -88,6 +89,10 @@ static inline unsigned int vgic_v3_init_dist_iodev(struct vgic_io_device *dev)
 {
     return 0;
 }
+static inline bool vgic_v3_emulate_reg(struct cpu_user_regs *regs, union hsr hsr)
+{
+    return false;
+}
 static inline int vgic_v3_set_redist_base(struct domain *d, u32 index, u64 addr, u32 count)
 {
     return 0;
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/25 arm: new VGIC: Add GICv3 MMIO handling framework

In reply to Mykyta Poturai

Create a new file called vgic-mmio-v3.c and describe the GICv3 distributor and redistributor registers there.
Also we provide a function to deal with the registration of the separate redistributor frames per VCPU and allocation of redistributor regions.

Based on Linux commits:
ed9b8cefa91695 by Andre Przywara
1aab6f468c10a1 by Christoffer Dall
ccc27bf5be7b78 by Eric Auger

---
 xen/arch/arm/include/asm/gic_v3_defs.h |   2 +
 xen/arch/arm/include/asm/new_vgic.h    |  18 +-
 xen/arch/arm/vgic/vgic-init.c          |  10 +-
 xen/arch/arm/vgic/vgic-mmio-v3.c       | 435 +++++++++++++++++++++++++
 xen/arch/arm/vgic/vgic-mmio.c          |   3 +
 xen/arch/arm/vgic/vgic.h               |  15 +
 6 files changed, 475 insertions(+), 8 deletions(-)
 create mode 100644 xen/arch/arm/vgic/vgic-mmio-v3.c
xen/arch/arm/include/asm/gic_v3_defs.h +2 -0
index 227533868f..b7059635d7 100644
@@ -35,6 +35,7 @@
 #define GICD_IROUTER                 (0x6000)
 #define GICD_IROUTER32               (0x6100)
 #define GICD_IROUTER1019             (0x7FD8)
+#define GICD_IDREGS                  (0xFFD0)
 #define GICD_PIDR2                   (0xFFE8)
 
 /* Common between GICD_PIDR2 and GICR_PIDR2 */
@@ -89,6 +90,7 @@
 #define GICR_INVLPIR                 (0x00A0)
 #define GICR_INVALLR                 (0x00B0)
 #define GICR_SYNCR                   (0x00C0)
+#define GICR_IDREGS                  GICD_IDREGS
 #define GICR_PIDR2                   GICD_PIDR2
 
 /* GICR for SGI's & PPI's */
xen/arch/arm/include/asm/new_vgic.h +13 -5
index 1e76213893..11d8f71851 100644
@@ -31,6 +31,8 @@
 #define VGIC_MAX_SPI            1019
 #define VGIC_MAX_RESERVED       1023
 #define VGIC_MIN_LPI            8192
+#define VGIC_V3_DIST_SIZE       SZ_64K
+#define VGIC_V3_REDIST_SIZE     (2 * SZ_64K)
 
 #define irq_is_ppi(irq) ((irq) >= VGIC_NR_SGIS && (irq) < VGIC_NR_PRIVATE_IRQS)
 #define irq_is_spi(irq) ((irq) >= VGIC_NR_PRIVATE_IRQS && \
@@ -94,6 +96,14 @@ enum iodev_type {
     IODEV_REDIST,
 };
 
+struct vgic_redist_region {
+    uint32_t index;
+    paddr_t base;
+    uint32_t count; /* number of redistributors or 0 if single region */
+    uint32_t free_index; /* index of the next free redistributor */
+    struct list_head list;
+};
+
 struct vgic_io_device {
     gfn_t base_fn;
     struct vcpu *redist_vcpu;
@@ -121,11 +131,7 @@ struct vgic_dist {
         /* either a GICv2 CPU interface */
         paddr_t         cbase;
         /* or a number of GICv3 redistributor regions */
-        struct
-        {
-            paddr_t     vgic_redist_base;
-            paddr_t     vgic_redist_free_offset;
-        };
+        struct list_head rd_regions;
     };
     paddr_t             csize; /* CPU interface size */
     paddr_t             vbase; /* virtual CPU interface base address */
@@ -174,6 +180,8 @@ struct vgic_cpu {
      * parts of the redistributor.
      */
     struct vgic_io_device   rd_iodev;
+    struct vgic_redist_region *rdreg;
+    uint32_t rdreg_index;
     struct vgic_io_device   sgi_iodev;
 
     /* Contains the attributes and gpa of the LPI pending tables. */
xen/arch/arm/vgic/vgic-init.c +7 -3
index f8d7d3a226..c3b34be192 100644
@@ -107,14 +107,18 @@ int domain_vgic_register(struct domain *d, unsigned int *mmio_count)
     {
     case GIC_V2:
         *mmio_count = 1;
+        d->arch.vgic.cbase = VGIC_ADDR_UNDEF;
         break;
+    case GIC_V3:
+        *mmio_count = 2;
+        INIT_LIST_HEAD(&d->arch.vgic.rd_regions);
+        break;
+
     default:
         BUG();
     }
 
     d->arch.vgic.dbase = VGIC_ADDR_UNDEF;
-    d->arch.vgic.cbase = VGIC_ADDR_UNDEF;
-    d->arch.vgic.vgic_redist_base = VGIC_ADDR_UNDEF;
 
     return 0;
 }
@@ -207,7 +211,7 @@ int vcpu_vgic_init(struct vcpu *v)
     if ( gic_hw_version() == GIC_V2 )
         vgic_v2_enable(v);
     else
-        ret = -ENXIO;
+        vgic_register_redist_iodev(v);
 
     return ret;
 }
xen/arch/arm/vgic/vgic-mmio-v3.c new file +435 -0

435 lines not on this page · raw message

xen/arch/arm/vgic/vgic-mmio.c +3 -0
index 5d935a7301..1c3f861887 100644
@@ -619,6 +619,9 @@ int vgic_register_dist_iodev(struct domain *d, gfn_t dist_base_fn,
     case VGIC_V2:
         len = vgic_v2_init_dist_iodev(io_device);
         break;
+    case VGIC_V3:
+        len = vgic_v3_init_dist_iodev(io_device);
+        break;
     default:
         BUG();
     }
xen/arch/arm/vgic/vgic.h +15 -0
index 2819569f30..a8e3ef5970 100644
@@ -73,6 +73,9 @@ int vgic_register_dist_iodev(struct domain *d, gfn_t dist_base_fn,
 #ifdef CONFIG_GICV3
 void vgic_v3_fold_lr_state(struct vcpu *vcpu);
 void vgic_v3_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr);
+unsigned int vgic_v3_init_dist_iodev(struct vgic_io_device *dev);
+int vgic_v3_set_redist_base(struct domain *d, u32 index, u64 addr, u32 count);
+int vgic_register_redist_iodev(struct vcpu *vcpu);
 #else
 static inline void vgic_v3_fold_lr_state(struct vcpu *vcpu)
 {
@@ -80,6 +83,18 @@ static inline void vgic_v3_fold_lr_state(struct vcpu *vcpu)
 static inline void vgic_v3_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr)
 {
 }
+static inline unsigned int vgic_v3_init_dist_iodev(struct vgic_io_device *dev)
+{
+    return 0;
+}
+static inline int vgic_v3_set_redist_base(struct domain *d, u32 index, u64 addr, u32 count)
+{
+    return 0;
+}
+static inline int vgic_register_redist_iodev(struct vcpu *vcpu)
+{
+    return 0;
+}
 #endif /* CONFIG_GICV3 */
 
 #endif /* __XEN_ARM_VGIC_VGIC_H__ */
Signature · 1 line
2.34.1
#7 lore raw

PATCH v2 7/25 arm: new VGIC: Add GICv3 IROUTER register handlers

In reply to Mykyta Poturai

Since GICv3 supports much more than the 8 CPUs the GICv2 ITARGETSR register can handle, the new IROUTER register covers the whole range of possible target (V)CPUs by using the same MPIDR that the cores report themselves.
In addition to translating this MPIDR into a vcpu pointer we store the originally written value as well. The architecture allows to write any values into the register, which must be read back as written.

Since we don't support affinity level 3, we don't need to take care about the upper word of this 64-bit register, which simplifies the handling a bit.

Based on Linux commit 78a714aba03039 by Andre Przywara

---
 xen/arch/arm/vgic/vgic-mmio-v3.c | 59 +++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)
xen/arch/arm/vgic/vgic-mmio-v3.c +58 -1
index ccdf3b9456..3d892a68cb 100644
@@ -22,6 +22,19 @@
 #include "vgic.h"
 #include "vgic-mmio.h"
 
+static struct vcpu *mpidr_to_vcpu(struct domain *d, unsigned long mpidr)
+{
+    struct vcpu *vcpu;
+
+    mpidr &= MPIDR_HWID_MASK;
+    for_each_vcpu(d, vcpu)
+    {
+        if ( mpidr == vcpuid_to_vaffinity(vcpu->vcpu_id) )
+            return vcpu;
+    }
+    return NULL;
+}
+
 /* extract @num bytes at @offset bytes offset in data */
 unsigned long extract_bytes(uint64_t data, unsigned int offset,
                             unsigned int num)
@@ -98,6 +111,50 @@ static void vgic_mmio_write_v3_misc(struct vcpu *vcpu, paddr_t addr,
     }
 }
 
+static unsigned long vgic_mmio_read_irouter(struct vcpu *vcpu, paddr_t addr,
+                                            unsigned int len)
+{
+    int intid            = VGIC_ADDR_TO_INTID(addr, 64);
+    struct vgic_irq *irq = vgic_get_irq(vcpu->domain, NULL, intid);
+    unsigned long ret    = 0;
+
+    if ( !irq )
+        return 0;
+
+    /* The upper word is RAZ for us. */
+    if ( !(addr & 4) )
+        ret = extract_bytes(irq->mpidr, addr & 7, len);
+
+    vgic_put_irq(vcpu->domain, irq);
+    return ret;
+}
+
+static void vgic_mmio_write_irouter(struct vcpu *vcpu, paddr_t addr,
+                                    unsigned int len, unsigned long val)
+{
+    int intid = VGIC_ADDR_TO_INTID(addr, 64);
+    struct vgic_irq *irq;
+    unsigned long flags;
+
+    /* The upper word is WI for us since we don't implement Aff3. */
+    if ( addr & 4 )
+        return;
+
+    irq = vgic_get_irq(vcpu->domain, NULL, intid);
+
+    if ( !irq )
+        return;
+
+    spin_lock_irqsave(&irq->irq_lock, flags);
+
+    /* We only care about and preserve Aff0, Aff1 and Aff2. */
+    irq->mpidr       = val & GENMASK(23, 0);
+    irq->target_vcpu = mpidr_to_vcpu(vcpu->domain, irq->mpidr);
+
+    spin_unlock_irqrestore(&irq->irq_lock, flags);
+    vgic_put_irq(vcpu->domain, irq);
+}
+
 static bool vgic_mmio_vcpu_rdist_is_last(struct vcpu *vcpu)
 {
     struct vgic_dist *vgic    = &vcpu->domain->arch.vgic;
@@ -206,7 +263,7 @@ static const struct vgic_register_region vgic_v3_dist_registers[] = {
         vgic_mmio_read_raz, vgic_mmio_write_wi, 1,
         VGIC_ACCESS_32bit),
     REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_IROUTER,
-        vgic_mmio_read_raz, vgic_mmio_write_wi, 64,
+        vgic_mmio_read_irouter, vgic_mmio_write_irouter, 64,
         VGIC_ACCESS_64bit | VGIC_ACCESS_32bit),
     REGISTER_DESC_WITH_LENGTH(GICD_IDREGS,
         vgic_mmio_read_v3_idregs, vgic_mmio_write_wi, 48,
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 5/25 arm: new VGIC: Add GICv3 redistributor IIDR and TYPER handler

In reply to Mykyta Poturai

The redistributor TYPER tells the OS about the associated MPIDR, also the LAST bit is crucial to determine the number of redistributors.

Based on Linux commit 741972d8a69ce74 by Andre Przywara

---
 xen/arch/arm/vgic/vgic-mmio-v3.c | 65 +++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 2 deletions(-)
xen/arch/arm/vgic/vgic-mmio-v3.c +63 -2
index beb3d6ad2a..707a38c727 100644
@@ -22,6 +22,13 @@
 #include "vgic.h"
 #include "vgic-mmio.h"
 
+/* extract @num bytes at @offset bytes offset in data */
+unsigned long extract_bytes(uint64_t data, unsigned int offset,
+                            unsigned int num)
+{
+    return (data >> (offset * 8)) & GENMASK_ULL(num * 8 - 1, 0);
+}
+
 /*
  * The Revision field in the IIDR have the following meanings:
  *
@@ -91,6 +98,60 @@ static void vgic_mmio_write_v3_misc(struct vcpu *vcpu, paddr_t addr,
     }
 }
 
+static bool vgic_mmio_vcpu_rdist_is_last(struct vcpu *vcpu)
+{
+    struct vgic_dist *vgic    = &vcpu->domain->arch.vgic;
+    struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic;
+    struct vgic_redist_region *iter, *rdreg = vgic_cpu->rdreg;
+
+    if ( !rdreg )
+        return false;
+
+    if ( vgic_cpu->rdreg_index < rdreg->free_index - 1 )
+    {
+        return false;
+    }
+    else if ( rdreg->count && vgic_cpu->rdreg_index == (rdreg->count - 1) )
+    {
+        struct list_head *rd_regions = &vgic->rd_regions;
+        paddr_t end = rdreg->base + rdreg->count * VGIC_V3_REDIST_SIZE;
+
+        /*
+         * the rdist is the last one of the redist region,
+         * check whether there is no other contiguous rdist region
+         */
+        list_for_each_entry(iter, rd_regions, list)
+        {
+            if ( iter->base == end && iter->free_index > 0 )
+                return false;
+        }
+    }
+    return true;
+}
+
+static unsigned long vgic_mmio_read_v3r_typer(struct vcpu *vcpu, paddr_t addr,
+                                              unsigned int len)
+{
+    unsigned long mpidr = vcpuid_to_vaffinity(vcpu->vcpu_id);
+    int target_vcpu_id  = vcpu->vcpu_id;
+    u64 value;
+
+    value = (u64)(mpidr & GENMASK(23, 0)) << 32;
+    value |= ((target_vcpu_id & 0xffff) << 8);
+
+    if ( vgic_mmio_vcpu_rdist_is_last(vcpu) )
+        value |= GICR_TYPER_LAST;
+
+    return extract_bytes(value, addr & 7, len);
+}
+
+static unsigned long vgic_mmio_read_v3r_iidr(struct vcpu *vcpu, paddr_t addr,
+                                             unsigned int len)
+{
+    return (PRODUCT_ID_KVM << 24) | (VARIANT_ID_XEN << 16) |
+           (IMPLEMENTER_ARM << 0);
+}
+
 static const struct vgic_register_region vgic_v3_dist_registers[] = {
     REGISTER_DESC_WITH_LENGTH(GICD_CTLR,
         vgic_mmio_read_v3_misc, vgic_mmio_write_v3_misc,
@@ -148,10 +209,10 @@ static const struct vgic_register_region vgic_v3_rd_registers[] = {
         vgic_mmio_read_raz, vgic_mmio_write_wi, 4,
         VGIC_ACCESS_32bit),
     REGISTER_DESC_WITH_LENGTH(GICR_IIDR,
-        vgic_mmio_read_raz, vgic_mmio_write_wi, 4,
+        vgic_mmio_read_v3r_iidr, vgic_mmio_write_wi, 4,
         VGIC_ACCESS_32bit),
     REGISTER_DESC_WITH_LENGTH(GICR_TYPER,
-        vgic_mmio_read_raz, vgic_mmio_write_wi, 8,
+        vgic_mmio_read_v3r_typer, vgic_mmio_write_wi, 8,
         VGIC_ACCESS_64bit | VGIC_ACCESS_32bit),
     REGISTER_DESC_WITH_LENGTH(GICR_WAKER,
         vgic_mmio_read_raz, vgic_mmio_write_wi, 4,
Signature · 1 line
2.34.1
#24 lore raw

PATCH v2 24/25 arm: new VGIC: its: Wire new ITS into the build system

In reply to Mykyta Poturai

Add vgic-its.o to the build system.
Remove the dependency on !NEW_VGIC from CONFIG_HAS_ITS.

---
 xen/arch/arm/Kconfig       | 4 ++--
 xen/arch/arm/vgic/Makefile | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)
xen/arch/arm/Kconfig +2 -2
index c91011bc15..d803793b09 100644
@@ -90,8 +90,8 @@ config GICV3
 	  If unsure, use the default setting.
 
 config HAS_ITS
-        bool "GICv3 ITS MSI controller support (UNSUPPORTED)" if UNSUPPORTED
-        depends on GICV3 && !NEW_VGIC && !ARM_32
+        bool "GICv3 ITS MSI controller support (UNSUPPORTED on old VGIC)" if UNSUPPORTED || NEW_VGIC
+        depends on GICV3 && !ARM_32
 
 config OVERLAY_DTB
 	bool "DTB overlay support (UNSUPPORTED)" if UNSUPPORTED
xen/arch/arm/vgic/Makefile +1 -0
index 21a71d2502..fe6821c724 100644
@@ -5,3 +5,4 @@ obj-y += vgic-mmio.o
 obj-y += vgic-mmio-v2.o
 obj-$(CONFIG_GICV3) += vgic-mmio-v3.o
 obj-y += vgic-init.o
+obj-$(CONFIG_HAS_ITS) += vgic-its.o
Signature · 1 line
2.34.1
#0 lore raw

v2 cover arm: Add GICv3 support to the New VGIC

Hi All.

This series aims to add GICv3 support to the New VGIC. It adds support for the GICv3 distributor, redistributor, sysreg and ITS interfaces. This will allow Xen to emulate level-triggered interrupts with GICv3 and will make the NEW_VGIC more complete and usable.

The series also introduces some refactoring of the ITS code to allow for easier VITS implementation switching.

The bulk of the code is taken from the Linux Kernel v6.0 and adapted to the existing Xen codebase.

Changes in v2:
- Split changes into smaller pieces similar to new VGIC v2 patches
- Refactor some common code to remove ifdefs
- Remove the "move get/put irq" change as it is no longer needed
- Replace GICD base change with proper offset calculation
- Fixed Kconfig dependencies

Mykyta Poturai (25):
arm: vgic: its: Decouple HW and virtual ITS
arm: new VGIC: Add GICv3 world switch backend
arm: new VGIC: Add GICv3 MMIO handling framework
arm: new VGIC: Add GICv3 CTLR, IIDR, TYPER handlers
arm: new VGIC: Add GICv3 redistributor IIDR and TYPER handler
arm: new VGIC: Add GICv3 IDREGS register handler
arm: new VGIC: Add GICv3 IROUTER register handlers
arm: new VGIC: Add GICv3 SGI system register trap handler
arm: new VGIC: vgic_init: implement map_resources
arm: new VGIC: Add vgic_v3_enable
arm: new VGIC: Add alternative redist region storage
arm: new VGIC: Wire new GICv3 into the build system
arm: new VGIC: Handle ITS related GICv3 redistributor registers
arm: new VGIC: its: Introduce ITS emulation file with MMIO framework
arm: new VGIC: its: Introduce ITS device list
arm: new VGIC: its: Implement basic ITS register handlers
arm: new VGIC: its: Read initial LPI pending table
arm: new VGIC: its: Allow updates of LPI configuration table
arm: new VGIC: its: Add LPI translation cache definition
arm: new VGIC: its: Implement ITS command queue command handlers
arm: new VGIC: its: Implement MSI injection in ITS emulation
arm: new VGIC: its: Implement MMIO-based LPI invalidation
arm: new VGIC: its: Enable ITS emulation as a virtual MSI controller
arm: new VGIC: its: Wire new ITS into the build system
arm: new VGIC: Improve MMIO handling

 xen/arch/arm/Kconfig                   |    5 +-
 xen/arch/arm/gic-v3-its.c              |  208 +--
 xen/arch/arm/gic-v3-lpi.c              |   20 -
 xen/arch/arm/include/asm/gic_v3_defs.h |   13 +-
 xen/arch/arm/include/asm/gic_v3_its.h  |   82 +
 xen/arch/arm/include/asm/new_vgic.h    |   93 +-
 xen/arch/arm/include/asm/vgic.h        |   29 +
 xen/arch/arm/vgic-v3-its.c             |  206 ++-
 xen/arch/arm/vgic/Makefile             |    3 +
 xen/arch/arm/vgic/vgic-init.c          |   24 +-
 xen/arch/arm/vgic/vgic-its.c           | 2022 ++++++++++++++++++++++++
 xen/arch/arm/vgic/vgic-mmio-v3.c       | 1095 +++++++++++++
 xen/arch/arm/vgic/vgic-mmio.c          |   19 +-
 xen/arch/arm/vgic/vgic-mmio.h          |   38 +
 xen/arch/arm/vgic/vgic-v3.c            |  305 ++++
 xen/arch/arm/vgic/vgic.c               |   41 +-
 xen/arch/arm/vgic/vgic.h               |   54 +-
 17 files changed, 4015 insertions(+), 242 deletions(-)
 create mode 100644 xen/arch/arm/vgic/vgic-its.c
 create mode 100644 xen/arch/arm/vgic/vgic-mmio-v3.c
 create mode 100644 xen/arch/arm/vgic/vgic-v3.c
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 4/25 arm: new VGIC: Add GICv3 CTLR, IIDR, TYPER handlers

As in the GICv2 emulation we handle those three registers in one function.

Based on Linux commit fd59ed3be17e41 by Andre Przywara

---
 xen/arch/arm/include/asm/gic_v3_defs.h |  2 +
 xen/arch/arm/vgic/vgic-mmio-v3.c       | 71 +++++++++++++++++++++++++-
 xen/arch/arm/vgic/vgic.h               |  1 +
 3 files changed, 73 insertions(+), 1 deletion(-)
xen/arch/arm/include/asm/gic_v3_defs.h +2 -0
index b7059635d7..e0d536e887 100644
@@ -25,6 +25,7 @@
  * Common GICD registers are defined in gic.h
  */
 
+#define GICD_TYPER2                  (0x00C)
 #define GICD_STATUSR                 (0x010)
 #define GICD_SETSPI_NSR              (0x040)
 #define GICD_CLRSPI_NSR              (0x048)
@@ -57,6 +58,7 @@
 #define GICD_TYPE_LPIS               (1U << 17)
 
 #define GICD_CTLR_RWP                (1UL << 31)
+#define GICD_CTLR_DS                 (1U << 6)
 #define GICD_CTLR_ARE_NS             (1U << 4)
 #define GICD_CTLR_ENABLE_G1A         (1U << 1)
 #define GICD_CTLR_ENABLE_G1          (1U << 0)
xen/arch/arm/vgic/vgic-mmio-v3.c +70 -1

79 lines not on this page · raw message

xen/arch/arm/vgic/vgic.h +1 -0
index a8e3ef5970..b3bba7b5f3 100644
@@ -28,6 +28,7 @@
 #define VGIC_ADDR_UNDEF     INVALID_PADDR
 #define IS_VGIC_ADDR_UNDEF(_x)  ((_x) == VGIC_ADDR_UNDEF)
 
+#define INTERRUPT_ID_BITS_SPIS  10
 #define VGIC_PRI_BITS       5
 
 #define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS)
Signature · 1 line
2.34.1
#20 lore raw

PATCH v2 20/25 arm: new VGIC: its: Implement ITS command queue command handlers

In reply to Mykyta Poturai

The connection between a device, an event ID, the LPI number and the associated CPU is stored in in-memory tables in a GICv3, but their format is not specified by the spec. Instead software uses a command queue in a ring buffer to let an ITS implementation use its own format.
Implement handlers for the various ITS commands and let them store the requested relation into our own data structures. Those data structures are protected by the its_lock mutex.
Error handling is very basic at the moment, as we don't have a good way of communicating errors to the guest (usually an SError). The INT command handler is missing from this patch, as we gain the capability of actually injecting MSIs into the guest only later on.

Based on Linux commit df9f58fbea9b by Andre Przywara

---
 xen/arch/arm/include/asm/gic_v3_its.h |  19 +
 xen/arch/arm/vgic/vgic-its.c          | 888 +++++++++++++++++++++++++-
 xen/arch/arm/vgic/vgic.h              |   6 +
 3 files changed, 908 insertions(+), 5 deletions(-)
xen/arch/arm/include/asm/gic_v3_its.h +19 -0
index b408441c6e..cbfd854af6 100644
@@ -160,6 +160,25 @@
 #define GITS_CMD_MOVALL                 0x0e
 #define GITS_CMD_DISCARD                0x0f
 
+/*
+ * ITS error numbers
+ */
+#define E_ITS_MOVI_UNMAPPED_INTERRUPT       0x010107
+#define E_ITS_MOVI_UNMAPPED_COLLECTION      0x010109
+#define E_ITS_INT_UNMAPPED_INTERRUPT        0x010307
+#define E_ITS_CLEAR_UNMAPPED_INTERRUPT      0x010507
+#define E_ITS_MAPD_DEVICE_OOR               0x010801
+#define E_ITS_MAPD_ITTSIZE_OOR              0x010802
+#define E_ITS_MAPC_PROCNUM_OOR              0x010902
+#define E_ITS_MAPC_COLLECTION_OOR           0x010903
+#define E_ITS_MAPTI_UNMAPPED_DEVICE         0x010a04
+#define E_ITS_MAPTI_ID_OOR                  0x010a05
+#define E_ITS_MAPTI_PHYSICALID_OOR          0x010a06
+#define E_ITS_INV_UNMAPPED_INTERRUPT        0x010c07
+#define E_ITS_INVALL_UNMAPPED_COLLECTION    0x010d09
+#define E_ITS_MOVALL_PROCNUM_OOR            0x010e01
+#define E_ITS_DISCARD_UNMAPPED_INTERRUPT    0x010f07
+
 #define ITS_DOORBELL_OFFSET             0x10040
 #define GICV3_ITS_SIZE                  SZ_128K
 #define ITS_TRANSLATION_OFFSET          0x10000
xen/arch/arm/vgic/vgic-its.c +883 -5

951 lines not on this page · raw message

xen/arch/arm/vgic/vgic.h +6 -0
index a14b519f77..2bcc62432a 100644
@@ -29,6 +29,7 @@
 #define IS_VGIC_ADDR_UNDEF(_x)  ((_x) == VGIC_ADDR_UNDEF)
 
 #define INTERRUPT_ID_BITS_SPIS  10
+#define INTERRUPT_ID_BITS_ITS   16
 #define VGIC_PRI_BITS       5
 
 #define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS)
@@ -77,6 +78,7 @@ void vgic_v3_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr);
 void vgic_v3_enable(struct vcpu *vcpu);
 int vgic_v3_map_resources(struct domain *d);
 bool vgic_v3_emulate_reg(struct cpu_user_regs *regs, union hsr hsr);
+bool vgic_lpis_enabled(struct vcpu *vcpu);
 unsigned int vgic_v3_init_dist_iodev(struct vgic_io_device *dev);
 int vgic_v3_set_redist_base(struct domain *d, u32 index, u64 addr, u32 count);
 int vgic_register_redist_iodev(struct vcpu *vcpu);
@@ -111,6 +113,10 @@ static inline int vgic_v3_set_redist_base(struct domain *d, u32 index, u64 addr,
 {
     return 0;
 }
+static inline bool vgic_lpis_enabled(struct vcpu *vcpu)
+{
+    return false;
+}
 static inline int vgic_register_redist_iodev(struct vcpu *vcpu)
 {
     return 0;
Signature · 1 line
2.34.1
#13 lore raw

PATCH v2 13/25 arm: new VGIC: Handle ITS related GICv3 redistributor registers

In reply to Mykyta Poturai

In the GICv3 redistributor there are the PENDBASER and PROPBASER registers which we did not emulate so far, as they only make sense when having an ITS. In preparation for that emulate those MMIO accesses by storing the 64-bit data written into it into a variable which we later read in the ITS emulation.
We also sanitise the registers, making sure RES0 regions are respected and checking for valid memory attributes.

Based on Linux commit 0aa1de57319c4 by Andre Przywara

---
 xen/arch/arm/include/asm/new_vgic.h |   3 +
 xen/arch/arm/vgic/vgic-mmio-v3.c    | 168 +++++++++++++++++++++++++++-
 2 files changed, 169 insertions(+), 2 deletions(-)
xen/arch/arm/include/asm/new_vgic.h +3 -0
index 9eafab45ff..b037b6cf61 100644
@@ -199,6 +199,9 @@ struct vgic_cpu {
 
     /* Cache guest interrupt ID bits */
     uint32_t num_id_bits;
+
+    /* GICR_CTLR.{ENABLE_LPIS,RWP} */
+    atomic_t ctlr;
 };
 
 static inline paddr_t vgic_cpu_base(const struct vgic_dist *vgic)
xen/arch/arm/vgic/vgic-mmio-v3.c +166 -2

188 lines not on this page · raw message

Signature · 1 line
2.34.1
#10 lore raw

PATCH v2 10/25 arm: new VGIC: Add vgic_v3_enable

In reply to Mykyta Poturai

Enable the VGIC operation by properly initialising the registers in the hypervisor GIC interface.

This is based on Linux commit f7b6985cc3d0f by Eric Auger

---
 xen/arch/arm/vgic/vgic-init.c | 5 +++++
 xen/arch/arm/vgic/vgic-v3.c   | 6 ++++++
 xen/arch/arm/vgic/vgic.h      | 4 ++++
 3 files changed, 15 insertions(+)
xen/arch/arm/vgic/vgic-init.c +5 -0
index ca13cf385c..96f6669d38 100644
@@ -209,9 +209,14 @@ int vcpu_vgic_init(struct vcpu *v)
     vgic_vcpu_early_init(v);
 
     if ( gic_hw_version() == GIC_V2 )
+    {
         vgic_v2_enable(v);
+    }
     else
+    {
         vgic_register_redist_iodev(v);
+        vgic_v3_enable(v);
+    }
 
     return ret;
 }
xen/arch/arm/vgic/vgic-v3.c +6 -0
index 470bb63147..682d57b476 100644
@@ -244,6 +244,12 @@ unsigned int vgic_v3_max_rdist_count(const struct domain *d)
                                      : GUEST_GICV3_RDIST_REGIONS;
 }
 
+void vgic_v3_enable(struct vcpu *vcpu)
+{
+    /* Get the show on the road... */
+    gic_hw_ops->update_hcr_status(GICH_HCR_EN, true);
+}
+
 int vgic_v3_map_resources(struct domain *d)
 {
     int rdist_count, i, ret;
xen/arch/arm/vgic/vgic.h +4 -0
index 7dbadf7501..791c91ebb3 100644
@@ -74,6 +74,7 @@ int vgic_register_dist_iodev(struct domain *d, gfn_t dist_base_fn,
 #ifdef CONFIG_GICV3
 void vgic_v3_fold_lr_state(struct vcpu *vcpu);
 void vgic_v3_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr);
+void vgic_v3_enable(struct vcpu *vcpu);
 int vgic_v3_map_resources(struct domain *d);
 bool vgic_v3_emulate_reg(struct cpu_user_regs *regs, union hsr hsr);
 unsigned int vgic_v3_init_dist_iodev(struct vgic_io_device *dev);
@@ -86,6 +87,9 @@ static inline void vgic_v3_fold_lr_state(struct vcpu *vcpu)
 static inline void vgic_v3_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr)
 {
 }
+static inline void vgic_v3_enable(struct vcpu *vcpu)
+{
+}
 static inline int vgic_v3_map_resources(struct domain *d)
 {
     return 0;
Signature · 1 line
2.34.1