[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH] arm/gic: Optimize lr_mask type based on GIC version


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • Date: Thu, 5 Mar 2026 19:57:45 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uKWjP4xtpZIn1PAPpYWKkBRR1vEVbVaqpTc5je+0qvs=; b=mcocFVi/mYZZfIkWE6fTrn6SKPOxhRhDu5fuSSO7K8dMdwjPPxjj5ajqhCKxikQ2g05Wxl9Swu82kzaCFn4wb12d8J12m3qLTdRqretT0qkPisngc6/GuGlG0SxXEl3iNH2cJLjTq3sAFAVehufFdFkagDGQEIbqCN37P3ZxCP61woYa4FQ3+ogT1bv4xCJbVIqgFDdWfFqLqCVWMkn9EfmUJAqyBdLZTgXn6Gg+VDIt/N59q9HpB+8Q0diiNaqXvYwVeFotw8jU81tHYapFrI6Vx0H3rT5jRlE9qNyp4YXq30618xSnchiq+UC09OjHSZXm20456sS3CKYL+1OQ1Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nolg8v7daoe5QcxkD66iNmJAbVR4nYekC6JxGpPXvNKp5hjSFrCQlMwOLQYA569GcI/dTI8034BelXlXVqhzMThXjpAK8NCj9vnvLGpOzqfKbBv5j4yQjQ7FUGsW4JQZf8gbmzp7MUoz2n43QX3wg67eCiphsHHFmUEpQBpmCcv3Xtt5p3XtjqKi+CBM4NAgpyDeHkFif44qHJevHLXGjsKRmyrh500kmTKy/rGL0Efn46yTm/YWkxVJeiHrxHcNh50YFVpuwvrhMqoMc3cxiee9LEiVU67ygS4vGhYq9mL/kT4CytT4OzIhnvqxHkW2P/ZlYAGTQG3pSLjaPRVuYQ==
  • Cc: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, "Volodymyr Babchuk" <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 05 Mar 2026 19:58:11 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The lr_mask bitmap tracks which List Registers (LRs) are in use for
virtual interrupt injection. Previously, lr_mask always used uint64_t
(8 bytes) to support the maximum number of LRs across both GIC versions.

However, GICv2 and GICv3 have different hardware limits:
- GICv3: ICH_VTR_EL2[3:0] encodes LR count -> max 16 LRs (4 bits)
- GICv2: GICH_VTR[5:0] encodes LR count -> max 64 LRs (6 bits)

This patch introduces conditional compilation to optimize lr_mask size:
- CONFIG_GICV3=y: Use uint16_t (2 bytes) - sufficient for 16 LRs
- CONFIG_GICV3=n: Use uint64_t (8 bytes) - required for 64 LRs

With this, parameter 'lr' in gicv3_ich_read_lr(), gicv3_ich_write_lr()
cannot have a value > 15. Thus, it should not possible to hit the
BUG() in the default case.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
---
 xen/arch/arm/gic-vgic.c           | 11 ++++++++++-
 xen/arch/arm/gic.c                | 10 +++++++++-
 xen/arch/arm/include/asm/domain.h |  4 ++++
 xen/arch/arm/include/asm/gic.h    |  8 ++++++++
 4 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/xen/arch/arm/gic-vgic.c b/xen/arch/arm/gic-vgic.c
index ea48c5375a..80d3beb225 100644
--- a/xen/arch/arm/gic-vgic.c
+++ b/xen/arch/arm/gic-vgic.c
@@ -16,8 +16,13 @@
 #include <asm/gic.h>
 #include <asm/vgic.h>
 
+#ifdef CONFIG_GICV3
 #define lr_all_full()                                           \
-    (this_cpu(lr_mask) == (-1ULL >> (64 - gic_get_nr_lrs())))
+    (this_cpu(lr_mask) == ((uint16_t)-1 >> (16 - gic_get_nr_lrs())))
+#else
+#define lr_all_full()                                           \
+    (this_cpu(lr_mask) == ((uint64_t)-1 >> (64 - gic_get_nr_lrs())))
+#endif
 
 #undef GIC_DEBUG
 
@@ -102,7 +107,11 @@ static unsigned int gic_find_unused_lr(struct vcpu *v,
                                        struct pending_irq *p,
                                        unsigned int lr)
 {
+#ifdef CONFIG_GICV3
+    uint16_t *lr_mask = &this_cpu(lr_mask);
+#else
     uint64_t *lr_mask = &this_cpu(lr_mask);
+#endif
 
     ASSERT(spin_is_locked(&v->arch.vgic.lock));
 
diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c
index ee75258fc3..e1121a5bb3 100644
--- a/xen/arch/arm/gic.c
+++ b/xen/arch/arm/gic.c
@@ -29,7 +29,11 @@
 #include <asm/vgic.h>
 #include <asm/acpi.h>
 
+#ifdef CONFIG_GICV3
+DEFINE_PER_CPU(uint16_t, lr_mask);
+#else
 DEFINE_PER_CPU(uint64_t, lr_mask);
+#endif
 
 #undef GIC_DEBUG
 
@@ -48,7 +52,7 @@ void register_gic_ops(const struct gic_hw_operations *ops)
 
 static void clear_cpu_lr_mask(void)
 {
-    this_cpu(lr_mask) = 0ULL;
+    this_cpu(lr_mask) = 0;
 }
 
 enum gic_version gic_hw_version(void)
@@ -382,7 +386,11 @@ static void maintenance_interrupt(int irq, void *dev_id)
 
 void gic_dump_info(struct vcpu *v)
 {
+#ifdef CONFIG_GICV3
+    printk("GICH_LRs (vcpu %d) mask=%"PRIx16"\n", v->vcpu_id, v->arch.lr_mask);
+#else
     printk("GICH_LRs (vcpu %d) mask=%"PRIx64"\n", v->vcpu_id, v->arch.lr_mask);
+#endif
     gic_hw_ops->dump_state(v);
 }
 
diff --git a/xen/arch/arm/include/asm/domain.h 
b/xen/arch/arm/include/asm/domain.h
index 758ad807e4..8654ef89ef 100644
--- a/xen/arch/arm/include/asm/domain.h
+++ b/xen/arch/arm/include/asm/domain.h
@@ -228,7 +228,11 @@ struct arch_vcpu
 
     /* Holds gic context data */
     union gic_state_data gic;
+#ifdef CONFIG_GICV3
+    uint16_t lr_mask;
+#else
     uint64_t lr_mask;
+#endif
 
     struct vgic_cpu vgic;
 
diff --git a/xen/arch/arm/include/asm/gic.h b/xen/arch/arm/include/asm/gic.h
index 8e713aa477..e1559ec98c 100644
--- a/xen/arch/arm/include/asm/gic.h
+++ b/xen/arch/arm/include/asm/gic.h
@@ -237,7 +237,15 @@ enum gic_version {
     GIC_V3,
 };
 
+/*
+ * GICv3 supports up to 16 LRs (4 bits in ICH_VTR_EL2), can use uint16_t
+ * GICv2 supports up to 64 LRs (6 bits in GICH_VTR), requires uint64_t
+ */
+#ifdef CONFIG_GICV3
+DECLARE_PER_CPU(uint16_t, lr_mask);
+#else
 DECLARE_PER_CPU(uint64_t, lr_mask);
+#endif
 
 extern enum gic_version gic_hw_version(void);
 
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.