Move num-priority-bits property value check to arm_gic_common_realize.

Peter Maydell says:

  We check that in arm_gic_realize(), but the property is defined on
  the "common" superclass, so it is present also for TYPE_KVM_ARM_GIC.
  Most of the uses of gic_min_bpr() are in the emulated-GIC code,
  but the calls from arm_gic_common_reset_irq_state() will be
  used also if you have a KVM GICv2. So if the user sets a silly
  num-priority-bits value with KVM GICv2 they'll run into the assert.

  
https://lore.kernel.org/qemu-arm/cafeaca-efmvqz8hoegjb0hzagbejywr0_-9-c6ia75m7k1v...@mail.gmail.com/

Suggested-by: Peter Maydell <[email protected]>
Signed-off-by: Manos Pitsidianakis <[email protected]>
---
 hw/intc/arm_gic.c        | 10 ----------
 hw/intc/arm_gic_common.c | 10 ++++++++++
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c
index 
79a68a8648467c1f18dab69cf691f8e44ec2f011..0236f45c3d106a314dc8b3435ac87ce67b6f3f9a
 100644
--- a/hw/intc/arm_gic.c
+++ b/hw/intc/arm_gic.c
@@ -2117,16 +2117,6 @@ static void arm_gic_realize(DeviceState *dev, Error 
**errp)
         return;
     }
 
-    if (s->n_prio_bits > GIC_MAX_PRIORITY_BITS ||
-       (s->virt_extn ? s->n_prio_bits < GIC_VIRT_MAX_GROUP_PRIO_BITS :
-        s->n_prio_bits < GIC_MIN_PRIORITY_BITS)) {
-        error_setg(errp, "num-priority-bits cannot be greater than %d"
-                   " or less than %d", GIC_MAX_PRIORITY_BITS,
-                   s->virt_extn ? GIC_VIRT_MAX_GROUP_PRIO_BITS :
-                   GIC_MIN_PRIORITY_BITS);
-        return;
-    }
-
     /* This creates distributor, main CPU interface (s->cpuiomem[0]) and if
      * enabled, virtualization extensions related interfaces (main virtual
      * interface (s->vifaceiomem[0]) and virtual CPU interface).
diff --git a/hw/intc/arm_gic_common.c b/hw/intc/arm_gic_common.c
index 
7ffd94561202f49d767315893085df57a4f984d8..fec5662d695ab2f66feb4dcc6cb02f4692287a47
 100644
--- a/hw/intc/arm_gic_common.c
+++ b/hw/intc/arm_gic_common.c
@@ -233,6 +233,16 @@ static void arm_gic_common_realize(DeviceState *dev, Error 
**errp)
          */
         s->num_lrs = 4;
     }
+
+    if (s->n_prio_bits > GIC_MAX_PRIORITY_BITS ||
+       (s->virt_extn ? s->n_prio_bits < GIC_VIRT_MAX_GROUP_PRIO_BITS :
+        s->n_prio_bits < GIC_MIN_PRIORITY_BITS)) {
+        error_setg(errp, "num-priority-bits cannot be greater than %d"
+                   " or less than %d", GIC_MAX_PRIORITY_BITS,
+                   s->virt_extn ? GIC_VIRT_MAX_GROUP_PRIO_BITS :
+                   GIC_MIN_PRIORITY_BITS);
+        return;
+    }
 }
 
 static inline void arm_gic_common_reset_irq_state(GICState *s, int cidx,

-- 
2.43.0


Reply via email to